From 09eee1993f5b3310f6695639433fdf2d9e319db2 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Thu, 2 Oct 2003 05:07:37 +0000 Subject: [PATCH 1/1] =?utf8?q?Primera=20versi=C3=B3n=20que=20compila.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- callbacks.cpp | 70 +++++++ callbacks.h | 31 +++ circulo.cpp | 18 +- circulo.h | 2 +- dibujo.cpp | 6 +- dibujo.h | 4 +- figura.cpp | 9 +- figura.h | 4 +- interface.cpp | 501 +++++++++++++++++++++++++++++++++++++++++++++++++ interface.h | 21 +++ linea.cpp | 13 +- linea.h | 2 +- rectangulo.cpp | 6 +- rectangulo.h | 2 +- tp5.cpp | 48 +++++ 15 files changed, 701 insertions(+), 36 deletions(-) create mode 100644 callbacks.cpp create mode 100644 callbacks.h create mode 100644 interface.cpp create mode 100644 interface.h create mode 100644 tp5.cpp diff --git a/callbacks.cpp b/callbacks.cpp new file mode 100644 index 0000000..9b9172d --- /dev/null +++ b/callbacks.cpp @@ -0,0 +1,70 @@ +/* vim: set et sts=4 sw=4 fdm=indent fdn=1 fo+=t tw=80: + * + * Taller de Programación (75.42). + * + * Ejercicio Número 5: + * Graficador de figuras. + * + * Copyleft 2003 - Leandro Lucarella + * Puede copiar, modificar y distribuir este programa bajo los términos de + * la licencia GPL (http://www.gnu.org/). + * + * Creado: mié oct 1 23:24:12 ART 2003 + * + * $Id$ + */ + +#include "dibujo.h" +#include "linea.h" +#include "cuadrado.h" +#include "rectangulo.h" +#include "circulo.h" +#include "callbacks.h" +#include "interface.h" +#include + +#include + +gboolean on_drawingarea_expose_event(GtkWidget *widget, GdkEventExpose *event, + gpointer user_data) { + std::cerr << "En expose_event." << std::endl; + // Dibujo. + static_cast(user_data)->dibujar(widget); + return FALSE; +} + +void on_button_borrar_clicked(GtkButton *button, gpointer user_data) { + std::cerr << "En borrar event." << std::endl; + // Borro dibujo. + static_cast(user_data)->borrar_todo(); +} + +void on_button_graficar_clicked(GtkButton *button, gpointer user_data) { + std::cerr << "En graficar event." << std::endl; + // Indica que hay que redibujar el widget user_data, que será el área de + // dibujo. + gtk_widget_queue_draw(GTK_WIDGET(user_data)); +} + +void on_button_salir_clicked(GtkButton *button, gpointer user_data) { + std::cerr << "En salir event." << std::endl; + // Termina el loop principal. + gtk_main_quit(); +} + +void on_button_agregar_clicked(GtkButton *button, gpointer user_data) { + std::cerr << "En agregar event." << std::endl; + // FIXME + Figura* figura = new Circulo(1, 1, Punto(50, 50), "Lala", 50); + static_cast(user_data)->agregar_figura(figura); +} + +gboolean on_window_delete_event(GtkWidget *widget, GdkEvent *event, + gpointer user_data) { + std::cerr << "En delete_event." << std::endl; + // Termina el loop principal. + gtk_main_quit(); + // Al devolver FALSE se indica que se debe ocultar la ventana FIXME. + return FALSE; +} + diff --git a/callbacks.h b/callbacks.h new file mode 100644 index 0000000..508bf24 --- /dev/null +++ b/callbacks.h @@ -0,0 +1,31 @@ +/* vim: set et sts=4 sw=4 fdm=marker fmr={,} fdn=1 fo+=t tw=80: + * + * Taller de Programación (75.42). + * + * Ejercicio Número 5: + * Graficador de figuras. + * + * Copyleft 2003 - Leandro Lucarella + * Puede copiar, modificar y distribuir este programa bajo los términos de + * la licencia GPL (http://www.gnu.org/). + * + * Creado: mié oct 1 23:36:08 ART 2003 + * + * $Id$ + */ + +#include + +gboolean on_drawingarea_expose_event(GtkWidget *widget, GdkEventExpose *event, + gpointer user_data); + +void on_button_borrar_clicked(GtkButton *button, gpointer user_data); + +void on_button_graficar_clicked(GtkButton *button, gpointer user_data); + +void on_button_salir_clicked(GtkButton *button, gpointer user_data); + +void on_button_agregar_clicked(GtkButton *button, gpointer user_data); + +gboolean on_window_delete_event(GtkWidget *widget, GdkEvent *event, + gpointer user_data); diff --git a/circulo.cpp b/circulo.cpp index e0ae212..d0f2b97 100644 --- a/circulo.cpp +++ b/circulo.cpp @@ -34,17 +34,19 @@ Circulo::~Circulo(void) { #endif } -void Circulo::dibujar(std::ostream& out) const { +void Circulo::dibujar(GtkWidget* widget) const { //void Circulo::dibujar(GdkGC* gc, GdkDrawable *window) const { #ifdef DEBUG std::cerr << "En dibujar de Círculo." << std::endl; #endif - // Valores a cambiar del graphic context. - //GdkGCValues values; - //values.foreground - //gdk_gc_set_line_attributes( - out << "Circulo("; - Figura::dibujar(out); - out << ", radio(" << radio << "))"; + gdk_draw_arc(widget->window, + widget->style->fg_gc[GTK_WIDGET_STATE (widget)], + FALSE, + 5, 5, + widget->allocation.width - 10, + widget->allocation.height - 10, + 0, 64 * 360); + + //Figura::dibujar(out); } diff --git a/circulo.h b/circulo.h index 9b12ca9..c3d2b01 100644 --- a/circulo.h +++ b/circulo.h @@ -43,7 +43,7 @@ class Circulo: public Figura { * * \param out Stream de salida en donde dibujar. */ - virtual void dibujar(std::ostream& out) const; + virtual void dibujar(GtkWidget* widget) const; }; diff --git a/dibujo.cpp b/dibujo.cpp index 4a9dc40..3c2187e 100644 --- a/dibujo.cpp +++ b/dibujo.cpp @@ -43,13 +43,11 @@ void Dibujo::borrar_todo(void) { } } -void Dibujo::dibujar(std::ostream& out) { +void Dibujo::dibujar(GtkWidget* widget) { // Dibujo cada elemento. for (Figura* f = static_cast(figuras.begin()); figuras.have_more(); f = static_cast(figuras.next())) { - out << "Dibujando: "; - f->dibujar(out); - out << std::endl; + f->dibujar(widget); } } diff --git a/dibujo.h b/dibujo.h index 8bd0fb3..d0f4b81 100644 --- a/dibujo.h +++ b/dibujo.h @@ -19,7 +19,7 @@ #include "dllist.h" #include "figura.h" -#include +#include /// Representa un conjunto de figuras. class Dibujo { @@ -59,7 +59,7 @@ class Dibujo { * * \param out Stream de salida donde dibujar. */ - virtual void dibujar(std::ostream& out); + virtual void dibujar(GtkWidget* widget); }; diff --git a/figura.cpp b/figura.cpp index 92df1d9..c6ad541 100644 --- a/figura.cpp +++ b/figura.cpp @@ -49,10 +49,9 @@ Figura::~Figura(void) { #endif } -void Figura::dibujar(std::ostream& out) const { - out << "color(" << color << "), grosor(" << grosor - << "), nombre(" << nombre << "), centro("; - centro.dibujar(out); - out << ")"; +void Figura::dibujar(GtkWidget* widget) const { + //out << "color(" << color << "), grosor(" << grosor + // << "), nombre(" << nombre << "), centro("; + //centro.dibujar(out); } diff --git a/figura.h b/figura.h index e5eeb2f..d7c027a 100644 --- a/figura.h +++ b/figura.h @@ -19,7 +19,7 @@ #include "punto.h" #include -#include +#include /** * Figura dibujable. @@ -58,7 +58,7 @@ class Figura { * * \param out Stream de salida en donde dibujar. */ - virtual void dibujar(std::ostream& out) const; + virtual void dibujar(GtkWidget* widget) const; }; diff --git a/interface.cpp b/interface.cpp new file mode 100644 index 0000000..6ed9f3f --- /dev/null +++ b/interface.cpp @@ -0,0 +1,501 @@ +/* vim: set et sts=4 sw=4 fdm=indent fdn=1 fo+=t tw=80 fileencoding=utf-8: + * + * Taller de Programación (75.42). + * + * Ejercicio Número 5: + * Graficador de figuras. + * + * Copyleft 2003 - Leandro Lucarella + * Puede copiar, modificar y distribuir este programa bajo los términos de + * la licencia GPL (http://www.gnu.org/). + * + * Creado: mié oct 1 23:31:40 ART 2003 + * + * $Id$ + */ + +#include "callbacks.h" +#include "interface.h" +#include "dibujo.h" + +#include +#include +#include +#include +#include + +#include +#include + +#define GLADE_HOOKUP_OBJECT(component,widget,name) \ + g_object_set_data_full (G_OBJECT (component), name, \ + gtk_widget_ref (widget), (GDestroyNotify) gtk_widget_unref) + +#define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \ + g_object_set_data (G_OBJECT (component), name, widget) + +GtkWidget* +create_window (Dibujo* dibujo) +{ + GtkWidget *window; + GtkWidget *vbox; + GtkWidget *hbox_botones; + GtkWidget *frame_dibujo; + GtkWidget *drawingarea; + GtkWidget *label_dibujo; + GtkWidget *vbuttonbox_botones; + GtkWidget *button_limpiar; + GtkWidget *button_actualizar; + GtkWidget *button_salir; + GtkWidget *hbox; + GtkWidget *frame_figura; + GtkWidget *vbox_figura; + GtkWidget *radiobutton_linea; + GSList *radiobutton_linea_group = NULL; + GtkWidget *radiobutton_cuadrado; + GtkWidget *radiobutton_rectangulo; + GtkWidget *radiobutton_circulo; + GtkWidget *label_figura; + GtkWidget *vbox_comun; + GtkWidget *table_comun; + GtkWidget *label_nombre; + GtkWidget *label_color; + GtkWidget *label_grosor; + GtkWidget *entry_nombre; + GtkWidget *combo_color; + GList *combo_color_items = NULL; + GtkWidget *combo_entry; + GtkObject *spinbutton_grosor_adj; + GtkWidget *spinbutton_grosor; + GtkWidget *button_agregar; + GtkWidget *vbox_otros; + GtkWidget *table_puntos; + GtkWidget *label_centro; + GtkWidget *label_inicio; + GtkWidget *label_fin; + GtkWidget *label_puntos; + GtkWidget *label_x; + GtkWidget *label_y; + GtkObject *spinbutton_centro_x_adj; + GtkWidget *spinbutton_centro_x; + GtkObject *spinbutton_centro_y_adj; + GtkWidget *spinbutton_centro_y; + GtkObject *spinbutton_inicio_x_adj; + GtkWidget *spinbutton_inicio_x; + GtkObject *spinbutton_inicio_y_adj; + GtkWidget *spinbutton_inicio_y; + GtkObject *spinbutton_fin_x_adj; + GtkWidget *spinbutton_fin_x; + GtkObject *spinbutton_fin_y_adj; + GtkWidget *spinbutton_fin_y; + GtkWidget *table_otros; + GtkWidget *label_alto; + GtkWidget *label_ancho; + GtkWidget *label_radio; + GtkObject *spinbutton_alto_adj; + GtkWidget *spinbutton_alto; + GtkObject *spinbutton_ancho_adj; + GtkWidget *spinbutton_ancho; + GtkObject *spinbutton_radio_adj; + GtkWidget *spinbutton_radio; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_container_set_border_width (GTK_CONTAINER (window), 5); + gtk_window_set_title (GTK_WINDOW (window), "Trabajo Práctico V"); + + vbox = gtk_vbox_new (FALSE, 0); + gtk_widget_show (vbox); + gtk_container_add (GTK_CONTAINER (window), vbox); + + hbox_botones = gtk_hbox_new (FALSE, 5); + gtk_widget_show (hbox_botones); + gtk_box_pack_start (GTK_BOX (vbox), hbox_botones, TRUE, TRUE, 0); + + frame_dibujo = gtk_frame_new (NULL); + gtk_widget_show (frame_dibujo); + gtk_box_pack_start (GTK_BOX (hbox_botones), frame_dibujo, TRUE, TRUE, 0); + + drawingarea = gtk_drawing_area_new (); + gtk_widget_show (drawingarea); + gtk_container_add (GTK_CONTAINER (frame_dibujo), drawingarea); + gtk_widget_set_size_request (drawingarea, 200, 200); + + label_dibujo = gtk_label_new ("Dibujo"); + gtk_widget_show (label_dibujo); + gtk_frame_set_label_widget (GTK_FRAME (frame_dibujo), label_dibujo); + gtk_label_set_justify (GTK_LABEL (label_dibujo), GTK_JUSTIFY_LEFT); + + vbuttonbox_botones = gtk_vbutton_box_new (); + gtk_widget_show (vbuttonbox_botones); + gtk_box_pack_start (GTK_BOX (hbox_botones), vbuttonbox_botones, FALSE, TRUE, 0); + gtk_container_set_border_width (GTK_CONTAINER (vbuttonbox_botones), 5); + gtk_button_box_set_layout (GTK_BUTTON_BOX (vbuttonbox_botones), GTK_BUTTONBOX_SPREAD); + + button_limpiar = gtk_button_new_from_stock ("gtk-clear"); + gtk_widget_show (button_limpiar); + gtk_container_add (GTK_CONTAINER (vbuttonbox_botones), button_limpiar); + GTK_WIDGET_SET_FLAGS (button_limpiar, GTK_CAN_DEFAULT); + + button_actualizar = gtk_button_new_from_stock ("gtk-refresh"); + gtk_widget_show (button_actualizar); + gtk_container_add (GTK_CONTAINER (vbuttonbox_botones), button_actualizar); + GTK_WIDGET_SET_FLAGS (button_actualizar, GTK_CAN_DEFAULT); + + button_salir = gtk_button_new_from_stock ("gtk-quit"); + gtk_widget_show (button_salir); + gtk_container_add (GTK_CONTAINER (vbuttonbox_botones), button_salir); + GTK_WIDGET_SET_FLAGS (button_salir, GTK_CAN_DEFAULT); + + hbox = gtk_hbox_new (FALSE, 0); + gtk_widget_show (hbox); + gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0); + + frame_figura = gtk_frame_new (NULL); + gtk_widget_show (frame_figura); + gtk_box_pack_start (GTK_BOX (hbox), frame_figura, FALSE, FALSE, 0); + + vbox_figura = gtk_vbox_new (FALSE, 0); + gtk_widget_show (vbox_figura); + gtk_container_add (GTK_CONTAINER (frame_figura), vbox_figura); + + radiobutton_linea = gtk_radio_button_new_with_mnemonic (NULL, "Línea"); + gtk_widget_show (radiobutton_linea); + gtk_box_pack_start (GTK_BOX (vbox_figura), radiobutton_linea, FALSE, FALSE, 0); + gtk_radio_button_set_group (GTK_RADIO_BUTTON (radiobutton_linea), radiobutton_linea_group); + radiobutton_linea_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radiobutton_linea)); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radiobutton_linea), TRUE); + + radiobutton_cuadrado = gtk_radio_button_new_with_mnemonic (NULL, "_Cuadrado"); + gtk_widget_show (radiobutton_cuadrado); + gtk_box_pack_start (GTK_BOX (vbox_figura), radiobutton_cuadrado, FALSE, FALSE, 0); + gtk_radio_button_set_group (GTK_RADIO_BUTTON (radiobutton_cuadrado), radiobutton_linea_group); + radiobutton_linea_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radiobutton_cuadrado)); + + radiobutton_rectangulo = gtk_radio_button_new_with_mnemonic (NULL, "_Rectángulo"); + gtk_widget_show (radiobutton_rectangulo); + gtk_box_pack_start (GTK_BOX (vbox_figura), radiobutton_rectangulo, FALSE, FALSE, 0); + gtk_radio_button_set_group (GTK_RADIO_BUTTON (radiobutton_rectangulo), radiobutton_linea_group); + radiobutton_linea_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radiobutton_rectangulo)); + + radiobutton_circulo = gtk_radio_button_new_with_mnemonic (NULL, "Círc_ulo"); + gtk_widget_show (radiobutton_circulo); + gtk_box_pack_start (GTK_BOX (vbox_figura), radiobutton_circulo, FALSE, FALSE, 0); + gtk_radio_button_set_group (GTK_RADIO_BUTTON (radiobutton_circulo), radiobutton_linea_group); + radiobutton_linea_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radiobutton_circulo)); + + label_figura = gtk_label_new ("Figura"); + gtk_widget_show (label_figura); + gtk_frame_set_label_widget (GTK_FRAME (frame_figura), label_figura); + gtk_label_set_justify (GTK_LABEL (label_figura), GTK_JUSTIFY_LEFT); + + vbox_comun = gtk_vbox_new (FALSE, 0); + gtk_widget_show (vbox_comun); + gtk_box_pack_start (GTK_BOX (hbox), vbox_comun, TRUE, TRUE, 0); + + table_comun = gtk_table_new (3, 2, FALSE); + gtk_widget_show (table_comun); + gtk_box_pack_start (GTK_BOX (vbox_comun), table_comun, TRUE, TRUE, 0); + gtk_container_set_border_width (GTK_CONTAINER (table_comun), 5); + gtk_table_set_row_spacings (GTK_TABLE (table_comun), 3); + gtk_table_set_col_spacings (GTK_TABLE (table_comun), 5); + + label_nombre = gtk_label_new ("Nombre"); + gtk_widget_show (label_nombre); + gtk_table_attach (GTK_TABLE (table_comun), label_nombre, 0, 1, 0, 1, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_label_set_justify (GTK_LABEL (label_nombre), GTK_JUSTIFY_LEFT); + gtk_misc_set_alignment (GTK_MISC (label_nombre), 0, 0.5); + + label_color = gtk_label_new ("Color"); + gtk_widget_show (label_color); + gtk_table_attach (GTK_TABLE (table_comun), label_color, 0, 1, 1, 2, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_label_set_justify (GTK_LABEL (label_color), GTK_JUSTIFY_LEFT); + gtk_misc_set_alignment (GTK_MISC (label_color), 0, 0.5); + + label_grosor = gtk_label_new ("Grosor"); + gtk_widget_show (label_grosor); + gtk_table_attach (GTK_TABLE (table_comun), label_grosor, 0, 1, 2, 3, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_label_set_justify (GTK_LABEL (label_grosor), GTK_JUSTIFY_LEFT); + gtk_misc_set_alignment (GTK_MISC (label_grosor), 0, 0.5); + + entry_nombre = gtk_entry_new (); + gtk_widget_show (entry_nombre); + gtk_table_attach (GTK_TABLE (table_comun), entry_nombre, 1, 2, 0, 1, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (GTK_EXPAND), 0, 0); + gtk_widget_set_size_request (entry_nombre, 100, -1); + + combo_color = gtk_combo_new (); + g_object_set_data (G_OBJECT (GTK_COMBO (combo_color)->popwin), + "GladeParentKey", combo_color); + gtk_widget_show (combo_color); + gtk_table_attach (GTK_TABLE (table_comun), combo_color, 1, 2, 1, 2, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (GTK_EXPAND), 0, 0); + gtk_widget_set_size_request (combo_color, 150, -1); + gtk_combo_set_value_in_list (GTK_COMBO (combo_color), TRUE, FALSE); + combo_color_items = g_list_append (combo_color_items, (gpointer) "Negro"); + combo_color_items = g_list_append (combo_color_items, (gpointer) "Blanco"); + combo_color_items = g_list_append (combo_color_items, (gpointer) "Rojo"); + combo_color_items = g_list_append (combo_color_items, (gpointer) "Verde"); + combo_color_items = g_list_append (combo_color_items, (gpointer) "Azul"); + combo_color_items = g_list_append (combo_color_items, (gpointer) "Cian"); + combo_color_items = g_list_append (combo_color_items, (gpointer) "Magenta"); + combo_color_items = g_list_append (combo_color_items, (gpointer) "Amarillo"); + combo_color_items = g_list_append (combo_color_items, (gpointer) "Gris"); + combo_color_items = g_list_append (combo_color_items, (gpointer) "Rojo Oscuro"); + combo_color_items = g_list_append (combo_color_items, (gpointer) "Verde Oscuro"); + combo_color_items = g_list_append (combo_color_items, (gpointer) "Azul Oscuro"); + combo_color_items = g_list_append (combo_color_items, (gpointer) "Cian Oscuro"); + combo_color_items = g_list_append (combo_color_items, (gpointer) "Magenta Oscuro"); + combo_color_items = g_list_append (combo_color_items, (gpointer) "Amarillo Oscuro"); + combo_color_items = g_list_append (combo_color_items, (gpointer) "Naranja"); + gtk_combo_set_popdown_strings (GTK_COMBO (combo_color), combo_color_items); + g_list_free (combo_color_items); + + combo_entry = GTK_COMBO (combo_color)->entry; + gtk_widget_show (combo_entry); + gtk_editable_set_editable (GTK_EDITABLE (combo_entry), FALSE); + gtk_entry_set_text (GTK_ENTRY (combo_entry), "Negro"); + + spinbutton_grosor_adj = gtk_adjustment_new (1, 1, 10, 1, 10, 10); + spinbutton_grosor = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton_grosor_adj), 1, 0); + gtk_widget_show (spinbutton_grosor); + gtk_table_attach (GTK_TABLE (table_comun), spinbutton_grosor, 1, 2, 2, 3, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (GTK_EXPAND), 0, 0); + gtk_widget_set_size_request (spinbutton_grosor, 48, -1); + + button_agregar = gtk_button_new_from_stock ("gtk-add"); + gtk_widget_show (button_agregar); + gtk_box_pack_start (GTK_BOX (vbox_comun), button_agregar, FALSE, FALSE, 0); + + vbox_otros = gtk_vbox_new (FALSE, 5); + gtk_widget_show (vbox_otros); + gtk_box_pack_start (GTK_BOX (hbox), vbox_otros, FALSE, FALSE, 0); + gtk_container_set_border_width (GTK_CONTAINER (vbox_otros), 5); + + table_puntos = gtk_table_new (4, 3, FALSE); + gtk_widget_show (table_puntos); + gtk_box_pack_start (GTK_BOX (vbox_otros), table_puntos, FALSE, FALSE, 0); + gtk_table_set_col_spacings (GTK_TABLE (table_puntos), 2); + + label_centro = gtk_label_new ("Centro"); + gtk_widget_show (label_centro); + gtk_table_attach (GTK_TABLE (table_puntos), label_centro, 0, 1, 1, 2, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_label_set_justify (GTK_LABEL (label_centro), GTK_JUSTIFY_LEFT); + gtk_misc_set_alignment (GTK_MISC (label_centro), 0, 0.5); + + label_inicio = gtk_label_new ("Inicio"); + gtk_widget_show (label_inicio); + gtk_table_attach (GTK_TABLE (table_puntos), label_inicio, 0, 1, 2, 3, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_label_set_justify (GTK_LABEL (label_inicio), GTK_JUSTIFY_LEFT); + gtk_misc_set_alignment (GTK_MISC (label_inicio), 0, 0.5); + + label_fin = gtk_label_new ("Fin"); + gtk_widget_show (label_fin); + gtk_table_attach (GTK_TABLE (table_puntos), label_fin, 0, 1, 3, 4, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_label_set_justify (GTK_LABEL (label_fin), GTK_JUSTIFY_LEFT); + gtk_misc_set_alignment (GTK_MISC (label_fin), 0, 0.5); + + label_puntos = gtk_label_new (""); + gtk_widget_show (label_puntos); + gtk_table_attach (GTK_TABLE (table_puntos), label_puntos, 0, 1, 0, 1, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_label_set_justify (GTK_LABEL (label_puntos), GTK_JUSTIFY_LEFT); + gtk_misc_set_alignment (GTK_MISC (label_puntos), 0, 0.5); + + label_x = gtk_label_new ("X"); + gtk_widget_show (label_x); + gtk_table_attach (GTK_TABLE (table_puntos), label_x, 1, 2, 0, 1, + (GtkAttachOptions) (0), + (GtkAttachOptions) (0), 0, 0); + gtk_misc_set_alignment (GTK_MISC (label_x), 0, 0.5); + + label_y = gtk_label_new ("Y"); + gtk_widget_show (label_y); + gtk_table_attach (GTK_TABLE (table_puntos), label_y, 2, 3, 0, 1, + (GtkAttachOptions) (GTK_EXPAND), + (GtkAttachOptions) (0), 0, 0); + gtk_misc_set_alignment (GTK_MISC (label_y), 0, 0.5); + + spinbutton_centro_x_adj = gtk_adjustment_new (0, 0, 1000, 1, 10, 10); + spinbutton_centro_x = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton_centro_x_adj), 1, 0); + gtk_widget_show (spinbutton_centro_x); + gtk_table_attach (GTK_TABLE (table_puntos), spinbutton_centro_x, 1, 2, 1, 2, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + + spinbutton_centro_y_adj = gtk_adjustment_new (0, 0, 1000, 1, 10, 10); + spinbutton_centro_y = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton_centro_y_adj), 1, 0); + gtk_widget_show (spinbutton_centro_y); + gtk_table_attach (GTK_TABLE (table_puntos), spinbutton_centro_y, 2, 3, 1, 2, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + + spinbutton_inicio_x_adj = gtk_adjustment_new (0, 0, 1000, 1, 10, 10); + spinbutton_inicio_x = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton_inicio_x_adj), 1, 0); + gtk_widget_show (spinbutton_inicio_x); + gtk_table_attach (GTK_TABLE (table_puntos), spinbutton_inicio_x, 1, 2, 2, 3, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + + spinbutton_inicio_y_adj = gtk_adjustment_new (0, 0, 1000, 1, 10, 10); + spinbutton_inicio_y = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton_inicio_y_adj), 1, 0); + gtk_widget_show (spinbutton_inicio_y); + gtk_table_attach (GTK_TABLE (table_puntos), spinbutton_inicio_y, 2, 3, 2, 3, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + + spinbutton_fin_x_adj = gtk_adjustment_new (0, 0, 1000, 1, 10, 10); + spinbutton_fin_x = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton_fin_x_adj), 1, 0); + gtk_widget_show (spinbutton_fin_x); + gtk_table_attach (GTK_TABLE (table_puntos), spinbutton_fin_x, 1, 2, 3, 4, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + + spinbutton_fin_y_adj = gtk_adjustment_new (0, 0, 1000, 1, 10, 10); + spinbutton_fin_y = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton_fin_y_adj), 1, 0); + gtk_widget_show (spinbutton_fin_y); + gtk_table_attach (GTK_TABLE (table_puntos), spinbutton_fin_y, 2, 3, 3, 4, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + + table_otros = gtk_table_new (3, 2, FALSE); + gtk_widget_show (table_otros); + gtk_box_pack_start (GTK_BOX (vbox_otros), table_otros, FALSE, FALSE, 0); + gtk_table_set_col_spacings (GTK_TABLE (table_otros), 2); + + label_alto = gtk_label_new ("Alto"); + gtk_widget_show (label_alto); + gtk_table_attach (GTK_TABLE (table_otros), label_alto, 0, 1, 0, 1, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_label_set_justify (GTK_LABEL (label_alto), GTK_JUSTIFY_LEFT); + gtk_misc_set_alignment (GTK_MISC (label_alto), 0, 0.5); + + label_ancho = gtk_label_new ("Ancho"); + gtk_widget_show (label_ancho); + gtk_table_attach (GTK_TABLE (table_otros), label_ancho, 0, 1, 1, 2, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_label_set_justify (GTK_LABEL (label_ancho), GTK_JUSTIFY_LEFT); + gtk_misc_set_alignment (GTK_MISC (label_ancho), 0, 0.5); + + label_radio = gtk_label_new ("Radio"); + gtk_widget_show (label_radio); + gtk_table_attach (GTK_TABLE (table_otros), label_radio, 0, 1, 2, 3, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_label_set_justify (GTK_LABEL (label_radio), GTK_JUSTIFY_LEFT); + gtk_misc_set_alignment (GTK_MISC (label_radio), 0, 0.5); + + spinbutton_alto_adj = gtk_adjustment_new (1, 1, 1000, 1, 10, 10); + spinbutton_alto = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton_alto_adj), 1, 0); + gtk_widget_show (spinbutton_alto); + gtk_table_attach (GTK_TABLE (table_otros), spinbutton_alto, 1, 2, 0, 1, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_widget_set_sensitive (spinbutton_alto, FALSE); + + spinbutton_ancho_adj = gtk_adjustment_new (1, 1, 1000, 1, 10, 10); + spinbutton_ancho = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton_ancho_adj), 1, 0); + gtk_widget_show (spinbutton_ancho); + gtk_table_attach (GTK_TABLE (table_otros), spinbutton_ancho, 1, 2, 1, 2, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_widget_set_sensitive (spinbutton_ancho, FALSE); + + spinbutton_radio_adj = gtk_adjustment_new (1, 1, 1000, 1, 10, 10); + spinbutton_radio = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton_radio_adj), 1, 0); + gtk_widget_show (spinbutton_radio); + gtk_table_attach (GTK_TABLE (table_otros), spinbutton_radio, 1, 2, 2, 3, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_widget_set_sensitive (spinbutton_radio, FALSE); + + g_signal_connect ((gpointer) window, "delete_event", + G_CALLBACK (on_window_delete_event), + NULL); + g_signal_connect ((gpointer) drawingarea, "expose_event", + G_CALLBACK (on_drawingarea_expose_event), + dibujo); + g_signal_connect ((gpointer) button_limpiar, "clicked", + G_CALLBACK (on_button_borrar_clicked), + dibujo); + g_signal_connect ((gpointer) button_actualizar, "clicked", + G_CALLBACK (on_button_graficar_clicked), + drawingarea); + g_signal_connect ((gpointer) button_salir, "clicked", + G_CALLBACK (on_button_salir_clicked), + NULL); + g_signal_connect ((gpointer) button_agregar, "clicked", + G_CALLBACK (on_button_agregar_clicked), + dibujo); + + /* Store pointers to all widgets, for use by lookup_widget(). */ + GLADE_HOOKUP_OBJECT_NO_REF (window, window, "window"); + GLADE_HOOKUP_OBJECT (window, vbox, "vbox"); + GLADE_HOOKUP_OBJECT (window, hbox_botones, "hbox_botones"); + GLADE_HOOKUP_OBJECT (window, frame_dibujo, "frame_dibujo"); + GLADE_HOOKUP_OBJECT (window, drawingarea, "drawingarea"); + GLADE_HOOKUP_OBJECT (window, label_dibujo, "label_dibujo"); + GLADE_HOOKUP_OBJECT (window, vbuttonbox_botones, "vbuttonbox_botones"); + GLADE_HOOKUP_OBJECT (window, button_limpiar, "button_limpiar"); + GLADE_HOOKUP_OBJECT (window, button_actualizar, "button_actualizar"); + GLADE_HOOKUP_OBJECT (window, button_salir, "button_salir"); + GLADE_HOOKUP_OBJECT (window, hbox, "hbox"); + GLADE_HOOKUP_OBJECT (window, frame_figura, "frame_figura"); + GLADE_HOOKUP_OBJECT (window, vbox_figura, "vbox_figura"); + GLADE_HOOKUP_OBJECT (window, radiobutton_linea, "radiobutton_linea"); + GLADE_HOOKUP_OBJECT (window, radiobutton_cuadrado, "radiobutton_cuadrado"); + GLADE_HOOKUP_OBJECT (window, radiobutton_rectangulo, "radiobutton_rectangulo"); + GLADE_HOOKUP_OBJECT (window, radiobutton_circulo, "radiobutton_circulo"); + GLADE_HOOKUP_OBJECT (window, label_figura, "label_figura"); + GLADE_HOOKUP_OBJECT (window, vbox_comun, "vbox_comun"); + GLADE_HOOKUP_OBJECT (window, table_comun, "table_comun"); + GLADE_HOOKUP_OBJECT (window, label_nombre, "label_nombre"); + GLADE_HOOKUP_OBJECT (window, label_color, "label_color"); + GLADE_HOOKUP_OBJECT (window, label_grosor, "label_grosor"); + GLADE_HOOKUP_OBJECT (window, entry_nombre, "entry_nombre"); + GLADE_HOOKUP_OBJECT (window, combo_color, "combo_color"); + GLADE_HOOKUP_OBJECT (window, combo_entry, "combo_entry"); + GLADE_HOOKUP_OBJECT (window, spinbutton_grosor, "spinbutton_grosor"); + GLADE_HOOKUP_OBJECT (window, button_agregar, "button_agregar"); + GLADE_HOOKUP_OBJECT (window, vbox_otros, "vbox_otros"); + GLADE_HOOKUP_OBJECT (window, table_puntos, "table_puntos"); + GLADE_HOOKUP_OBJECT (window, label_centro, "label_centro"); + GLADE_HOOKUP_OBJECT (window, label_inicio, "label_inicio"); + GLADE_HOOKUP_OBJECT (window, label_fin, "label_fin"); + GLADE_HOOKUP_OBJECT (window, label_puntos, "label_puntos"); + GLADE_HOOKUP_OBJECT (window, label_x, "label_x"); + GLADE_HOOKUP_OBJECT (window, label_y, "label_y"); + GLADE_HOOKUP_OBJECT (window, spinbutton_centro_x, "spinbutton_centro_x"); + GLADE_HOOKUP_OBJECT (window, spinbutton_centro_y, "spinbutton_centro_y"); + GLADE_HOOKUP_OBJECT (window, spinbutton_inicio_x, "spinbutton_inicio_x"); + GLADE_HOOKUP_OBJECT (window, spinbutton_inicio_y, "spinbutton_inicio_y"); + GLADE_HOOKUP_OBJECT (window, spinbutton_fin_x, "spinbutton_fin_x"); + GLADE_HOOKUP_OBJECT (window, spinbutton_fin_y, "spinbutton_fin_y"); + GLADE_HOOKUP_OBJECT (window, table_otros, "table_otros"); + GLADE_HOOKUP_OBJECT (window, label_alto, "label_alto"); + GLADE_HOOKUP_OBJECT (window, label_ancho, "label_ancho"); + GLADE_HOOKUP_OBJECT (window, label_radio, "label_radio"); + GLADE_HOOKUP_OBJECT (window, spinbutton_alto, "spinbutton_alto"); + GLADE_HOOKUP_OBJECT (window, spinbutton_ancho, "spinbutton_ancho"); + GLADE_HOOKUP_OBJECT (window, spinbutton_radio, "spinbutton_radio"); + + return window; +} + diff --git a/interface.h b/interface.h new file mode 100644 index 0000000..1ec9e29 --- /dev/null +++ b/interface.h @@ -0,0 +1,21 @@ +/* vim: set et sts=4 sw=4 fdm=marker fmr={,} fdn=1 fo+=t tw=80: + * + * Taller de Programación (75.42). + * + * Ejercicio Número 5: + * Graficador de figuras. + * + * Copyleft 2003 - Leandro Lucarella + * Puede copiar, modificar y distribuir este programa bajo los términos de + * la licencia GPL (http://www.gnu.org/). + * + * Creado: mié oct 1 23:39:55 ART 2003 + * + * $Id$ + */ + +#include "dibujo.h" +#include + +GtkWidget* create_window(Dibujo* dibujo); + diff --git a/linea.cpp b/linea.cpp index f584a0f..2a933bd 100644 --- a/linea.cpp +++ b/linea.cpp @@ -34,13 +34,10 @@ Linea::~Linea(void) { #endif } -void Linea::dibujar(std::ostream& out) const { - out << "Linea("; - Figura::dibujar(out); - out << ", ini("; - ini.dibujar(out); - out << "), fin("; - fin.dibujar(out); - out << "))"; +void Linea::dibujar(GtkWidget* widget) const { + gdk_draw_line(widget->window, + widget->style->fg_gc[GTK_WIDGET_STATE (widget)], + ini.x, ini.y, fin.x, fin.y); + //Figura::dibujar(out); } diff --git a/linea.h b/linea.h index 9397b9e..8e94965 100644 --- a/linea.h +++ b/linea.h @@ -46,7 +46,7 @@ class Linea: public Figura { * * \param out Stream de salida en donde dibujar. */ - virtual void dibujar(std::ostream& out) const; + virtual void dibujar(GtkWidget* widget) const; }; diff --git a/rectangulo.cpp b/rectangulo.cpp index 7a7cb04..3b1112a 100644 --- a/rectangulo.cpp +++ b/rectangulo.cpp @@ -34,9 +34,7 @@ Rectangulo::~Rectangulo(void) { #endif } -void Rectangulo::dibujar(std::ostream& out) const { - out << "Rectangulo("; - Figura::dibujar(out); - out << ", ancho(" << ancho << "), alto(" << alto << "))"; +void Rectangulo::dibujar(GtkWidget* widget) const { + //Figura::dibujar(out); } diff --git a/rectangulo.h b/rectangulo.h index 22f7959..47da206 100644 --- a/rectangulo.h +++ b/rectangulo.h @@ -46,7 +46,7 @@ class Rectangulo: public Figura { * * \param out Stream de salida en donde dibujar. */ - virtual void dibujar(std::ostream& out) const; + virtual void dibujar(GtkWidget* widget) const; }; diff --git a/tp5.cpp b/tp5.cpp new file mode 100644 index 0000000..be518c3 --- /dev/null +++ b/tp5.cpp @@ -0,0 +1,48 @@ +/* vim: set et sts=4 sw=4 fdm=indent fdn=1 fo+=t tw=80: + * + * Taller de Programación (75.42). + * + * Ejercicio Número 5: + * Graficador de figuras. + * + * Copyleft 2003 - Leandro Lucarella + * Puede copiar, modificar y distribuir este programa bajo los términos de + * la licencia GPL (http://www.gnu.org/). + * + * Creado: sáb sep 20 19:52:13 ART 2003 + * + * $Id$ + */ + +#include "dibujo.h" +#include "rectangulo.h" +#include "cuadrado.h" +#include "linea.h" +#include "circulo.h" +#include "interface.h" +#include + +/** + * Programa principal del \ref main "Trabajo Práctico". + * + * \return EXIT_SUCCESS si terminó correctamente. + */ +int main(int argc, char* argv[]) { + Dibujo dibujo; + + GtkWidget* window; + + gtk_set_locale(); + gtk_init (&argc, &argv); + + window = create_window(&dibujo); + gtk_widget_show(window); + + gtk_main (); + + // Limpio el dibujo (para liberar las figuras. + dibujo.borrar_todo(); + + return EXIT_SUCCESS; +} + -- 2.43.0