FLOWER.C

xiaoxiao2021-03-05  21

// Flower.c // Copyright (c) 2005 benbear // Flower 0.2 // This Program Is Free Software; You Can Redistribute it and /// MODIFY IT Under The Terms of the gnu general public license as // Published by the Free Software Foundation; either version 2, or (at // your option) any later version.// This program is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of / . / MERCHANTABILITY or FITNESS fOR A PARTICULAR PURPOSE See the GNU // General Public License for more details.// You should have received a copy of the GNU General Public License // along with GNU Emacs;. see the file COPYING If not, Write to the // Free Software Foundation, Inc., 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA.//. t p g n g g 2 2 #include < Math.h> #ifndef m_pi # define m_pi 3.1415926535898 # endifgtkwidget * BIG; // a widget for big circlegtkwidget * small; // a widget for small circlegtkwidget * pen; // position of the penGtkWidget * outer; // check if small out bigGtkWidget * fill; // check if fill all drawareaGtkWidget * drawarea; // the client will drawing // "value-changed" event of the big circle, small circle and penvoid value_changed (GtkSpinButton * spinbutton, gpointer data) {GdkRectangle rect; rect.x = 0; rect.y = 0; rect.width = drawarea-> allocation.width; rect.height = drawarea-> allocation.height; gdk_window_invalidate_rect (Drawarea-> Window, & Rect, False);} // "Toggled" Event of the Outer and Fillvoid Toggled (gpointer data) {gdkRectangle Rect; Rect.x = 0; Rect.y =

0; rect.width = drawarea-> allocation.width; rect.height = drawarea-> allocation.height; gdk_window_invalidate_rect (drawarea-> window, & rect, FALSE);} GtkWidget * create_adjustment_entry (float cur, float min, float max) {GtkAdjustment * adj; GtkWidget * entry; adj = (GtkAdjustment *) gtk_adjustment_new (cur, min, max, 1.0, 5.0, 0.0); entry = gtk_spin_button_new (adj, 0, 0); g_signal_connect (G_OBJECT (entry), "value -changed ", G_CALLBACK (value_changed), entry); gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (entry), FALSE); return entry;} void show_adjustment_entry (GtkWidget * entry, const char * str, GtkWidget * vbox) {GtkWidget * label; GtkWidget * hbox ; label = gtk_label_new (str); hbox = gtk_hbox_new (TRUE, 0); gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (VBOX), HBOX, TRUE, TRUE, 0); GTK_WIDGET_SHOW (Label); gtk_widget_show (entry); gtk_widget_show (hbox);} // redraw event of drawing area // draw the flowergbooleanexpose_event_callback (GtkWidget * widget, GdkEventExpose * event, gpointer data) {int b, s, p; // big, small and pen INT ns; // -small or small int w, h, x, y; // width and height int d; int A, f; // outer and fill double t; gdkgc * gc; gdkdrawable * canvas; gdkcolor color; b = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (big)); s = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (small)); p = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (pen)); canvas = widget-> window; gc =

widget-> style-> fg_gc [GTK_WIDGET_STATE (widget)]; w = widget-> allocation.width; h = widget-> allocation.height; a = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (outer)); f = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fill) ); If (f) {// zoom double r, m; m = (w

GtkWidget * vbox; GtkWidget * hbox; GtkWidget * align; gtk_init (& argc, & argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_container_set_border_width (GTK_CONTAINER (window), 5); gtk_window_set_title (GTK_WINDOW (window), "Flower"); g_signal_connect ( G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), 0); g_signal_connect_swapped (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_widget_destroy), window); vbox = gtk_vbox_new (FALSE, 0); // create big circle big = create_adjustment_entry (100, 1.0, 1000.0); show_adjustment_entry (big, "big", vbox); // create small circle small = create_adjustment_entry (60, 1.0, 1000.0); show_adjustment_entry (small, "small", vbox); / / create pen pen = create_adjustment_entry (40, 0.0, 1000.0); show_adjustment_entry (pen, "pen", vbox); // create check outer outer = gtk_toggle_button_new_with_label ( "small outer of big"); gtk_box_pack_start (GTK_BOX (vbox), outer , True, True, 5 ); G_signal_connect (G_OBJECT (outer), "toggled", G_CALLBACK (toggled), outer); gtk_widget_show (outer); // create check fill fill = gtk_toggle_button_new_with_label ( "auto zoom"); gtk_box_pack_start (GTK_BOX (vbox), fill, TRUE, TRUE, 0); g_signal_connect (G_OBJECT (fill), "toggled", G_CALLBACK (toggled), fill); gtk_widget_show (fill); align = gtk_alignment_new (1.0, 0.0, 0.0, 0.0); gtk_container_add (GTK_CONTAINER (align) , vbox; Drawarea = gtk_drawing_area_new (); gtk_widget_set_size_request (Drawarea, 200, 200); g_signal_connect (g_object (drawarea), "expose_event"

, G_CALLBACK (expose_event_callback), NULL); hbox = gtk_hbox_new (FALSE, 10); gtk_box_pack_start (GTK_BOX (hbox), drawarea, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (hbox), align, FALSE, FALSE, 0); gtk_container_add (GTK_CONTAINER (window), hbox); gtk_widget_show (drawarea); gtk_widget_show (vbox); gtk_widget_show (align); gtk_widget_show (hbox); gtk_widget_show (window); gtk_main (); return 0;} The following is Makefile:

# Makefile for Flowerflower: Flower.c GCC Flower.c -o Flower `Pkg-Config - CFLAGS - Libs GTK -2.0`

转载请注明原文地址:https://www.9cbs.com/read-36754.html

New Post(0)