Advertisement
thecplusplusguy

GTK+ tutorial 10

Jun 27th, 2012
1,116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. //http://www.youtube.com/user/thecplusplusguy
  2. //Thanks for the typed in code to Tapit85
  3. #include <gtk/gtk.h>
  4. #include <cstring>
  5.  
  6. static float percent = 0.0;
  7.  
  8. static gboolean inc_progress(gpointer data)
  9. {
  10.     percent += 0.05;
  11.     if(percent > 1.0)
  12.         percent = 0.0;
  13.     gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(data), percent);
  14.     char c[3];
  15.     sprintf(c, "%d%%", static_cast<int>(percent*100));
  16.     gtk_progress_bar_set_text(GTK_PROGRESS_BAR(data), c);
  17. }
  18.  
  19. int main(int argc, char* argv[])
  20. {
  21.     gtk_init(&argc, &argv);
  22.     GtkWidget *window, *progress;
  23.     window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  24.     g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
  25.  
  26.     progress = gtk_progress_bar_new();
  27.  
  28. //  gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress), "50%");
  29.  
  30. //  gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(progress), GTK_PROGRESS_TOP_TO_BOTTOM);
  31.  
  32.     g_timeout_add(200, inc_progress, progress); // 300 ms
  33.  
  34.     gtk_container_add(GTK_CONTAINER(window), progress);
  35.  
  36.     gtk_widget_show_all(window);
  37.     gtk_main();
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement