1 /* vim: set et sts=4 sw=4 fdm=indent fdn=1 fo+=t tw=80 fileencoding=utf-8:
3 * Taller de Programación (75.42).
6 * Graficador de figuras.
8 * Copyleft 2003 - Leandro Lucarella <llucare@fi.uba.ar>
9 * Puede copiar, modificar y distribuir este programa bajo los términos de
10 * la licencia GPL (http://www.gnu.org/).
12 * Creado: mié oct 1 23:31:40 ART 2003
17 #include "callbacks.h"
18 #include "interface.h"
21 //#include <sys/types.h>
22 //#include <sys/stat.h>
27 //#include <gdk/gdkkeysyms.h>
30 TP5Window::TP5Window(void) {
32 GtkWidget *hbox_botones;
33 GtkWidget *frame_dibujo;
34 GtkWidget *label_dibujo;
35 GtkWidget *vbuttonbox_botones;
37 GtkWidget *frame_figura;
38 GtkWidget *vbox_figura;
39 GSList *radiobutton_group = NULL;
40 GtkWidget *label_figura;
41 GtkWidget *vbox_comun;
42 GtkWidget *table_comun;
43 GtkWidget *label_nombre;
44 GtkWidget *label_color;
45 GtkWidget *label_grosor;
46 GList *combo_color_items = NULL;
47 GtkWidget *combo_entry;
48 GtkObject *spinbutton_grosor_adj;
49 GtkWidget *vbox_otros;
50 GtkWidget *table_puntos;
51 GtkWidget *label_centro;
52 GtkWidget *label_inicio;
54 GtkWidget *label_puntos;
57 GtkObject *spinbutton_centro_x_adj;
58 GtkObject *spinbutton_centro_y_adj;
59 GtkObject *spinbutton_inicio_x_adj;
60 GtkObject *spinbutton_inicio_y_adj;
61 GtkObject *spinbutton_fin_x_adj;
62 GtkObject *spinbutton_fin_y_adj;
63 GtkWidget *table_otros;
64 GtkWidget *label_alto;
65 GtkWidget *label_ancho;
66 GtkWidget *label_radio;
67 GtkObject *spinbutton_alto_adj;
68 GtkObject *spinbutton_ancho_adj;
69 GtkObject *spinbutton_radio_adj;
71 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
72 gtk_container_set_border_width (GTK_CONTAINER (window), 5);
73 gtk_window_set_title (GTK_WINDOW (window), "Trabajo Práctico V");
75 vbox = gtk_vbox_new (FALSE, 0);
76 gtk_container_add (GTK_CONTAINER (window), vbox);
78 hbox_botones = gtk_hbox_new (FALSE, 5);
79 gtk_box_pack_start (GTK_BOX (vbox), hbox_botones, TRUE, TRUE, 0);
81 frame_dibujo = gtk_frame_new (NULL);
82 gtk_box_pack_start (GTK_BOX (hbox_botones), frame_dibujo, TRUE, TRUE, 0);
84 drawingarea = gtk_drawing_area_new ();
85 gtk_container_add (GTK_CONTAINER (frame_dibujo), drawingarea);
86 gtk_widget_set_size_request (drawingarea, 200, 200);
88 label_dibujo = gtk_label_new ("Dibujo");
89 gtk_frame_set_label_widget (GTK_FRAME (frame_dibujo), label_dibujo);
90 gtk_label_set_justify (GTK_LABEL (label_dibujo), GTK_JUSTIFY_LEFT);
92 vbuttonbox_botones = gtk_vbutton_box_new ();
93 gtk_box_pack_start (GTK_BOX (hbox_botones), vbuttonbox_botones, FALSE, TRUE, 0);
94 gtk_container_set_border_width (GTK_CONTAINER (vbuttonbox_botones), 5);
95 gtk_button_box_set_layout (GTK_BUTTON_BOX (vbuttonbox_botones), GTK_BUTTONBOX_SPREAD);
97 button_limpiar = gtk_button_new_from_stock ("gtk-clear");
98 gtk_container_add (GTK_CONTAINER (vbuttonbox_botones), button_limpiar);
99 GTK_WIDGET_SET_FLAGS (button_limpiar, GTK_CAN_DEFAULT);
101 button_actualizar = gtk_button_new_from_stock ("gtk-refresh");
102 gtk_container_add (GTK_CONTAINER (vbuttonbox_botones), button_actualizar);
103 GTK_WIDGET_SET_FLAGS (button_actualizar, GTK_CAN_DEFAULT);
105 button_salir = gtk_button_new_from_stock ("gtk-quit");
106 gtk_container_add (GTK_CONTAINER (vbuttonbox_botones), button_salir);
107 GTK_WIDGET_SET_FLAGS (button_salir, GTK_CAN_DEFAULT);
109 hbox = gtk_hbox_new (FALSE, 0);
110 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
112 frame_figura = gtk_frame_new (NULL);
113 gtk_box_pack_start (GTK_BOX (hbox), frame_figura, FALSE, FALSE, 0);
115 vbox_figura = gtk_vbox_new (FALSE, 0);
116 gtk_container_add (GTK_CONTAINER (frame_figura), vbox_figura);
118 radiobutton_linea = gtk_radio_button_new_with_mnemonic (NULL, "LÃnea");
119 gtk_box_pack_start (GTK_BOX (vbox_figura), radiobutton_linea, FALSE, FALSE, 0);
120 gtk_radio_button_set_group (GTK_RADIO_BUTTON (radiobutton_linea), radiobutton_group);
121 radiobutton_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radiobutton_linea));
122 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radiobutton_linea), TRUE);
124 radiobutton_cuadrado = gtk_radio_button_new_with_mnemonic (NULL, "_Cuadrado");
125 gtk_box_pack_start (GTK_BOX (vbox_figura), radiobutton_cuadrado, FALSE, FALSE, 0);
126 gtk_radio_button_set_group (GTK_RADIO_BUTTON (radiobutton_cuadrado), radiobutton_group);
127 radiobutton_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radiobutton_cuadrado));
129 radiobutton_rectangulo = gtk_radio_button_new_with_mnemonic (NULL, "_Rectángulo");
130 gtk_box_pack_start (GTK_BOX (vbox_figura), radiobutton_rectangulo, FALSE, FALSE, 0);
131 gtk_radio_button_set_group (GTK_RADIO_BUTTON (radiobutton_rectangulo), radiobutton_group);
132 radiobutton_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radiobutton_rectangulo));
134 radiobutton_circulo = gtk_radio_button_new_with_mnemonic (NULL, "CÃrc_ulo");
135 gtk_box_pack_start (GTK_BOX (vbox_figura), radiobutton_circulo, FALSE, FALSE, 0);
136 gtk_radio_button_set_group (GTK_RADIO_BUTTON (radiobutton_circulo), radiobutton_group);
137 radiobutton_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radiobutton_circulo));
139 label_figura = gtk_label_new ("Figura");
140 gtk_frame_set_label_widget (GTK_FRAME (frame_figura), label_figura);
141 gtk_label_set_justify (GTK_LABEL (label_figura), GTK_JUSTIFY_LEFT);
143 vbox_comun = gtk_vbox_new (FALSE, 0);
144 gtk_box_pack_start (GTK_BOX (hbox), vbox_comun, TRUE, TRUE, 0);
146 table_comun = gtk_table_new (3, 2, FALSE);
147 gtk_box_pack_start (GTK_BOX (vbox_comun), table_comun, TRUE, TRUE, 0);
148 gtk_container_set_border_width (GTK_CONTAINER (table_comun), 5);
149 gtk_table_set_row_spacings (GTK_TABLE (table_comun), 3);
150 gtk_table_set_col_spacings (GTK_TABLE (table_comun), 5);
152 label_nombre = gtk_label_new ("Nombre");
153 gtk_table_attach (GTK_TABLE (table_comun), label_nombre, 0, 1, 0, 1,
154 (GtkAttachOptions) (GTK_FILL),
155 (GtkAttachOptions) (0), 0, 0);
156 gtk_label_set_justify (GTK_LABEL (label_nombre), GTK_JUSTIFY_LEFT);
157 gtk_misc_set_alignment (GTK_MISC (label_nombre), 0, 0.5);
159 label_color = gtk_label_new ("Color");
160 gtk_table_attach (GTK_TABLE (table_comun), label_color, 0, 1, 1, 2,
161 (GtkAttachOptions) (GTK_FILL),
162 (GtkAttachOptions) (0), 0, 0);
163 gtk_label_set_justify (GTK_LABEL (label_color), GTK_JUSTIFY_LEFT);
164 gtk_misc_set_alignment (GTK_MISC (label_color), 0, 0.5);
166 label_grosor = gtk_label_new ("Grosor");
167 gtk_table_attach (GTK_TABLE (table_comun), label_grosor, 0, 1, 2, 3,
168 (GtkAttachOptions) (GTK_FILL),
169 (GtkAttachOptions) (0), 0, 0);
170 gtk_label_set_justify (GTK_LABEL (label_grosor), GTK_JUSTIFY_LEFT);
171 gtk_misc_set_alignment (GTK_MISC (label_grosor), 0, 0.5);
173 entry_nombre = gtk_entry_new ();
174 gtk_table_attach (GTK_TABLE (table_comun), entry_nombre, 1, 2, 0, 1,
175 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
176 (GtkAttachOptions) (GTK_EXPAND), 0, 0);
177 gtk_widget_set_size_request (entry_nombre, 100, -1);
179 combo_color = gtk_combo_new ();
180 g_object_set_data (G_OBJECT (GTK_COMBO (combo_color)->popwin),
181 "GladeParentKey", combo_color);
182 gtk_table_attach (GTK_TABLE (table_comun), combo_color, 1, 2, 1, 2,
183 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
184 (GtkAttachOptions) (GTK_EXPAND), 0, 0);
185 gtk_widget_set_size_request (combo_color, 150, -1);
186 gtk_combo_set_value_in_list (GTK_COMBO (combo_color), TRUE, FALSE);
187 combo_color_items = g_list_append (combo_color_items, (gpointer) "Negro");
188 combo_color_items = g_list_append (combo_color_items, (gpointer) "Blanco");
189 combo_color_items = g_list_append (combo_color_items, (gpointer) "Rojo");
190 combo_color_items = g_list_append (combo_color_items, (gpointer) "Verde");
191 combo_color_items = g_list_append (combo_color_items, (gpointer) "Azul");
192 combo_color_items = g_list_append (combo_color_items, (gpointer) "Cian");
193 combo_color_items = g_list_append (combo_color_items, (gpointer) "Magenta");
194 combo_color_items = g_list_append (combo_color_items, (gpointer) "Amarillo");
195 combo_color_items = g_list_append (combo_color_items, (gpointer) "Gris");
196 combo_color_items = g_list_append (combo_color_items, (gpointer) "Rojo Oscuro");
197 combo_color_items = g_list_append (combo_color_items, (gpointer) "Verde Oscuro");
198 combo_color_items = g_list_append (combo_color_items, (gpointer) "Azul Oscuro");
199 combo_color_items = g_list_append (combo_color_items, (gpointer) "Cian Oscuro");
200 combo_color_items = g_list_append (combo_color_items, (gpointer) "Magenta Oscuro");
201 combo_color_items = g_list_append (combo_color_items, (gpointer) "Amarillo Oscuro");
202 combo_color_items = g_list_append (combo_color_items, (gpointer) "Naranja");
203 gtk_combo_set_popdown_strings (GTK_COMBO (combo_color), combo_color_items);
204 g_list_free (combo_color_items);
206 combo_entry = GTK_COMBO (combo_color)->entry;
207 gtk_editable_set_editable (GTK_EDITABLE (combo_entry), FALSE);
208 gtk_entry_set_text (GTK_ENTRY (combo_entry), "Negro");
210 spinbutton_grosor_adj = gtk_adjustment_new (1, 1, 10, 1, 10, 10);
211 spinbutton_grosor = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton_grosor_adj), 1, 0);
212 gtk_table_attach (GTK_TABLE (table_comun), spinbutton_grosor, 1, 2, 2, 3,
213 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
214 (GtkAttachOptions) (GTK_EXPAND), 0, 0);
215 gtk_widget_set_size_request (spinbutton_grosor, 48, -1);
217 button_agregar = gtk_button_new_from_stock ("gtk-add");
218 gtk_box_pack_start (GTK_BOX (vbox_comun), button_agregar, FALSE, FALSE, 0);
220 vbox_otros = gtk_vbox_new (FALSE, 5);
221 gtk_box_pack_start (GTK_BOX (hbox), vbox_otros, FALSE, FALSE, 0);
222 gtk_container_set_border_width (GTK_CONTAINER (vbox_otros), 5);
224 table_puntos = gtk_table_new (4, 3, FALSE);
225 gtk_box_pack_start (GTK_BOX (vbox_otros), table_puntos, FALSE, FALSE, 0);
226 gtk_table_set_col_spacings (GTK_TABLE (table_puntos), 2);
228 label_centro = gtk_label_new ("Centro");
229 gtk_table_attach (GTK_TABLE (table_puntos), label_centro, 0, 1, 1, 2,
230 (GtkAttachOptions) (GTK_FILL),
231 (GtkAttachOptions) (0), 0, 0);
232 gtk_label_set_justify (GTK_LABEL (label_centro), GTK_JUSTIFY_LEFT);
233 gtk_misc_set_alignment (GTK_MISC (label_centro), 0, 0.5);
235 label_inicio = gtk_label_new ("Inicio");
236 gtk_table_attach (GTK_TABLE (table_puntos), label_inicio, 0, 1, 2, 3,
237 (GtkAttachOptions) (GTK_FILL),
238 (GtkAttachOptions) (0), 0, 0);
239 gtk_label_set_justify (GTK_LABEL (label_inicio), GTK_JUSTIFY_LEFT);
240 gtk_misc_set_alignment (GTK_MISC (label_inicio), 0, 0.5);
242 label_fin = gtk_label_new ("Fin");
243 gtk_table_attach (GTK_TABLE (table_puntos), label_fin, 0, 1, 3, 4,
244 (GtkAttachOptions) (GTK_FILL),
245 (GtkAttachOptions) (0), 0, 0);
246 gtk_label_set_justify (GTK_LABEL (label_fin), GTK_JUSTIFY_LEFT);
247 gtk_misc_set_alignment (GTK_MISC (label_fin), 0, 0.5);
249 label_puntos = gtk_label_new ("");
250 gtk_table_attach (GTK_TABLE (table_puntos), label_puntos, 0, 1, 0, 1,
251 (GtkAttachOptions) (GTK_FILL),
252 (GtkAttachOptions) (0), 0, 0);
253 gtk_label_set_justify (GTK_LABEL (label_puntos), GTK_JUSTIFY_LEFT);
254 gtk_misc_set_alignment (GTK_MISC (label_puntos), 0, 0.5);
256 label_x = gtk_label_new ("X");
257 gtk_table_attach (GTK_TABLE (table_puntos), label_x, 1, 2, 0, 1,
258 (GtkAttachOptions) (0),
259 (GtkAttachOptions) (0), 0, 0);
260 gtk_misc_set_alignment (GTK_MISC (label_x), 0, 0.5);
262 label_y = gtk_label_new ("Y");
263 gtk_table_attach (GTK_TABLE (table_puntos), label_y, 2, 3, 0, 1,
264 (GtkAttachOptions) (GTK_EXPAND),
265 (GtkAttachOptions) (0), 0, 0);
266 gtk_misc_set_alignment (GTK_MISC (label_y), 0, 0.5);
268 spinbutton_centro_x_adj = gtk_adjustment_new (0, 0, 1000, 1, 10, 10);
269 spinbutton_centro_x = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton_centro_x_adj), 1, 0);
270 gtk_table_attach (GTK_TABLE (table_puntos), spinbutton_centro_x, 1, 2, 1, 2,
271 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
272 (GtkAttachOptions) (0), 0, 0);
274 spinbutton_centro_y_adj = gtk_adjustment_new (0, 0, 1000, 1, 10, 10);
275 spinbutton_centro_y = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton_centro_y_adj), 1, 0);
276 gtk_table_attach (GTK_TABLE (table_puntos), spinbutton_centro_y, 2, 3, 1, 2,
277 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
278 (GtkAttachOptions) (0), 0, 0);
280 spinbutton_inicio_x_adj = gtk_adjustment_new (0, 0, 1000, 1, 10, 10);
281 spinbutton_inicio_x = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton_inicio_x_adj), 1, 0);
282 gtk_table_attach (GTK_TABLE (table_puntos), spinbutton_inicio_x, 1, 2, 2, 3,
283 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
284 (GtkAttachOptions) (0), 0, 0);
286 spinbutton_inicio_y_adj = gtk_adjustment_new (0, 0, 1000, 1, 10, 10);
287 spinbutton_inicio_y = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton_inicio_y_adj), 1, 0);
288 gtk_table_attach (GTK_TABLE (table_puntos), spinbutton_inicio_y, 2, 3, 2, 3,
289 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
290 (GtkAttachOptions) (0), 0, 0);
292 spinbutton_fin_x_adj = gtk_adjustment_new (0, 0, 1000, 1, 10, 10);
293 spinbutton_fin_x = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton_fin_x_adj), 1, 0);
294 gtk_table_attach (GTK_TABLE (table_puntos), spinbutton_fin_x, 1, 2, 3, 4,
295 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
296 (GtkAttachOptions) (0), 0, 0);
298 spinbutton_fin_y_adj = gtk_adjustment_new (0, 0, 1000, 1, 10, 10);
299 spinbutton_fin_y = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton_fin_y_adj), 1, 0);
300 gtk_table_attach (GTK_TABLE (table_puntos), spinbutton_fin_y, 2, 3, 3, 4,
301 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
302 (GtkAttachOptions) (0), 0, 0);
304 table_otros = gtk_table_new (3, 2, FALSE);
305 gtk_box_pack_start (GTK_BOX (vbox_otros), table_otros, FALSE, FALSE, 0);
306 gtk_table_set_col_spacings (GTK_TABLE (table_otros), 2);
308 label_alto = gtk_label_new ("Alto");
309 gtk_table_attach (GTK_TABLE (table_otros), label_alto, 0, 1, 0, 1,
310 (GtkAttachOptions) (GTK_FILL),
311 (GtkAttachOptions) (0), 0, 0);
312 gtk_label_set_justify (GTK_LABEL (label_alto), GTK_JUSTIFY_LEFT);
313 gtk_misc_set_alignment (GTK_MISC (label_alto), 0, 0.5);
315 label_ancho = gtk_label_new ("Ancho");
316 gtk_table_attach (GTK_TABLE (table_otros), label_ancho, 0, 1, 1, 2,
317 (GtkAttachOptions) (GTK_FILL),
318 (GtkAttachOptions) (0), 0, 0);
319 gtk_label_set_justify (GTK_LABEL (label_ancho), GTK_JUSTIFY_LEFT);
320 gtk_misc_set_alignment (GTK_MISC (label_ancho), 0, 0.5);
322 label_radio = gtk_label_new ("Radio");
323 gtk_table_attach (GTK_TABLE (table_otros), label_radio, 0, 1, 2, 3,
324 (GtkAttachOptions) (GTK_FILL),
325 (GtkAttachOptions) (0), 0, 0);
326 gtk_label_set_justify (GTK_LABEL (label_radio), GTK_JUSTIFY_LEFT);
327 gtk_misc_set_alignment (GTK_MISC (label_radio), 0, 0.5);
329 spinbutton_alto_adj = gtk_adjustment_new (1, 1, 1000, 1, 10, 10);
330 spinbutton_alto = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton_alto_adj), 1, 0);
331 gtk_table_attach (GTK_TABLE (table_otros), spinbutton_alto, 1, 2, 0, 1,
332 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
333 (GtkAttachOptions) (0), 0, 0);
334 gtk_widget_set_sensitive (spinbutton_alto, FALSE);
336 spinbutton_ancho_adj = gtk_adjustment_new (1, 1, 1000, 1, 10, 10);
337 spinbutton_ancho = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton_ancho_adj), 1, 0);
338 gtk_table_attach (GTK_TABLE (table_otros), spinbutton_ancho, 1, 2, 1, 2,
339 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
340 (GtkAttachOptions) (0), 0, 0);
341 gtk_widget_set_sensitive (spinbutton_ancho, FALSE);
343 spinbutton_radio_adj = gtk_adjustment_new (1, 1, 1000, 1, 10, 10);
344 spinbutton_radio = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton_radio_adj), 1, 0);
345 gtk_table_attach (GTK_TABLE (table_otros), spinbutton_radio, 1, 2, 2, 3,
346 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
347 (GtkAttachOptions) (0), 0, 0);
348 gtk_widget_set_sensitive (spinbutton_radio, FALSE);
350 g_signal_connect((gpointer) window, "delete_event",
351 G_CALLBACK (on_window_delete_event),
353 g_signal_connect((gpointer) drawingarea, "expose_event",
354 G_CALLBACK (on_drawingarea_expose_event),
356 g_signal_connect((gpointer) button_limpiar, "clicked",
357 G_CALLBACK (on_button_borrar_clicked),
359 g_signal_connect((gpointer) button_actualizar, "clicked",
360 G_CALLBACK (on_button_graficar_clicked),
362 g_signal_connect((gpointer) button_salir, "clicked",
363 G_CALLBACK (on_button_salir_clicked),
365 g_signal_connect((gpointer) button_agregar, "clicked",
366 G_CALLBACK (on_button_agregar_clicked),
368 g_signal_connect((gpointer) radiobutton_linea, "toggled",
369 G_CALLBACK (on_radiobutton_linea_toggled),
371 g_signal_connect((gpointer) radiobutton_cuadrado, "toggled",
372 G_CALLBACK (on_radiobutton_cuadrado_toggled),
374 g_signal_connect((gpointer) radiobutton_rectangulo, "toggled",
375 G_CALLBACK (on_radiobutton_rectangulo_toggled),
377 g_signal_connect((gpointer) radiobutton_circulo, "toggled",
378 G_CALLBACK (on_radiobutton_circulo_toggled),
381 // Muestro la ventana principal y todos sus componentes.
382 gtk_widget_show_all(window);
385 TP5Window::~TP5Window(void) {
386 dibujo.borrar_todo();