1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
#include <gtk/gtk.h>
gint t=0;
gint time1;
GtkWidget *window;
GtkWidget *aspect_frame;
GtkWidget *drawing_area;
GtkWidget *vbox1, *toggle1;
gboolean
expose_event_callback (GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
//g_object_ref_sink (widget->window);
// gdk_drawable_ref (widget->window);
gdk_draw_arc (widget->window,
widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
TRUE,
0, 0, widget->allocation.width, widget->allocation.height,
0, 64 * 18*t);
//gdk_drawable_unref (widget->window);
return TRUE;
}
static gboolean
time_handler(GtkWidget *widget)
{
gtk_widget_queue_draw(GTK_WIDGET(widget));
if (t<20)
{ t++; }
else if (t >=20)
{ t=0; }
printf("hello %d\n",t);
return TRUE;
}
void toggle_button_callback (GtkWidget *widget, gpointer data)
{
if (GTK_TOGGLE_BUTTON (widget)->active)
{
g_print("The button %d pressed\n", GPOINTER_TO_INT( g_object_get_data( G_OBJECT( widget),
"id" ) ) );
/* If control reaches here, the toggle button is down */
g_source_remove(time1);
} else {
g_print("The button %d released\n", GPOINTER_TO_INT( g_object_get_data( G_OBJECT( widget),
"id" ) ) );
time1 = g_timeout_add(100, (GSourceFunc) time_handler, (gpointer)drawing_area);
/* If control reaches here, the toggle button is up */
}
}
int main( int argc,
char *argv[] )
{
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Aspect Frame");
g_signal_connect (G_OBJECT (window), "destroy",
G_CALLBACK (gtk_main_quit), NULL);
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
vbox1 = gtk_vbox_new(TRUE,0);
/* Create an aspect_frame and add it to our toplevel window */
aspect_frame = gtk_aspect_frame_new ("2x1", /* label */
0.5, /* center x */
0.5, /* center y */
2, /* xsize/ysize = 2 */
FALSE /* ignore child's aspect */);
gtk_container_add( GTK_CONTAINER( window ), vbox1 );
toggle1 = gtk_toggle_button_new_with_label ("Hold");
g_signal_connect( toggle1, "toggled", G_CALLBACK( toggle_button_callback ), NULL );
gtk_box_pack_start(GTK_BOX(vbox1), toggle1, TRUE, TRUE,0);
gtk_box_pack_start(GTK_BOX(vbox1), aspect_frame, TRUE, TRUE,0);
gtk_widget_show (aspect_frame);
gtk_widget_show (vbox1);
/* Now add a child widget to the aspect frame */
drawing_area = gtk_drawing_area_new ();
/* Ask for a 200x200 window, but the AspectFrame will give us a 200x100
* window since we are forcing a 2x1 aspect ratio */
gtk_widget_set_size_request (drawing_area, 200, 200);
gtk_container_add (GTK_CONTAINER (aspect_frame), drawing_area);
gtk_widget_show (drawing_area);
g_signal_connect (G_OBJECT (drawing_area), "expose_event",
G_CALLBACK (expose_event_callback), NULL);
time1 = g_timeout_add(100, (GSourceFunc) time_handler, (gpointer)drawing_area);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
|