From e3908a19f8ddc8d37cb2d93e8fae1e61af8487de Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Sat, 4 Oct 2003 04:10:07 +0000 Subject: [PATCH] =?utf8?q?Implementado=20el=20dibujo=20parcialmente.=20Los?= =?utf8?q?=20botones=20ya=20responden=20a=20la=20selecci=C3=B3n=20de=20los?= =?utf8?q?=20radio=20buttons.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- callbacks.cpp | 124 +++++++++++++++++++++++++++++++++++++++++--------- interface.cpp | 12 ++--- interface.h | 2 +- punto.h | 16 ++++--- 4 files changed, 119 insertions(+), 35 deletions(-) diff --git a/callbacks.cpp b/callbacks.cpp index bf38a5a..eced183 100644 --- a/callbacks.cpp +++ b/callbacks.cpp @@ -27,7 +27,7 @@ # include #endif -gboolean on_drawingarea_expose_event(GtkWidget *widget, GdkEventExpose *event, +gboolean on_drawingarea_expose_event(GtkWidget* widget, GdkEventExpose* event, gpointer user_data) { #ifdef DEBUG std::cerr << "En expose_event." << std::endl; @@ -37,7 +37,7 @@ gboolean on_drawingarea_expose_event(GtkWidget *widget, GdkEventExpose *event, return FALSE; } -void on_button_borrar_clicked(GtkButton *button, gpointer user_data) { +void on_button_borrar_clicked(GtkButton* button, gpointer user_data) { #ifdef DEBUG std::cerr << "En borrar event." << std::endl; #endif @@ -45,7 +45,7 @@ void on_button_borrar_clicked(GtkButton *button, gpointer user_data) { static_cast(user_data)->borrar_todo(); } -void on_button_graficar_clicked(GtkButton *button, gpointer user_data) { +void on_button_graficar_clicked(GtkButton* button, gpointer user_data) { #ifdef DEBUG std::cerr << "En graficar event." << std::endl; #endif @@ -54,7 +54,7 @@ void on_button_graficar_clicked(GtkButton *button, gpointer user_data) { gtk_widget_queue_draw(GTK_WIDGET(user_data)); } -void on_button_salir_clicked(GtkButton *button, gpointer user_data) { +void on_button_salir_clicked(GtkButton* button, gpointer user_data) { #ifdef DEBUG std::cerr << "En salir event." << std::endl; #endif @@ -62,7 +62,7 @@ void on_button_salir_clicked(GtkButton *button, gpointer user_data) { gtk_main_quit(); } -void on_button_agregar_clicked(GtkButton *button, gpointer user_data) { +void on_button_agregar_clicked(GtkButton* button, gpointer user_data) { #ifdef DEBUG std::cerr << "En agregar event." << std::endl; #endif @@ -71,16 +71,61 @@ void on_button_agregar_clicked(GtkButton *button, gpointer user_data) { // más, tal vez, el drawingarea. TP5Window* win = static_cast(user_data); Figura* figura = new Circulo(1, 1, Punto(50, 50), "Lala", 50); - static_cast(user_data)->agregar_figura(figura); - static_cast(user_data)->agregar_figura( - new Linea(1, 2, Punto(50, 50), "", Punto(0, 0), Punto(100, 50))); - static_cast(user_data)->agregar_figura( - new Rectangulo(2, 1, Punto(100, 100), "", 20, 80)); - static_cast(user_data)->agregar_figura( - new Cuadrado(5, 5, Punto(150, 120), "", 100)); + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(win->radiobutton_linea))) { + figura = new Linea( + 1, // Color FIXME + gtk_spin_button_get_value_as_int( + GTK_SPIN_BUTTON(win->spinbutton_grosor)), + Punto(GTK_SPIN_BUTTON(win->spinbutton_centro_x), + GTK_SPIN_BUTTON(win->spinbutton_centro_y)), + gtk_entry_get_text(GTK_ENTRY(win->entry_nombre)), + Punto(GTK_SPIN_BUTTON(win->spinbutton_inicio_x), + GTK_SPIN_BUTTON(win->spinbutton_inicio_y)), + Punto(GTK_SPIN_BUTTON(win->spinbutton_fin_x), + GTK_SPIN_BUTTON(win->spinbutton_fin_y)) + ); + } else if (gtk_toggle_button_get_active( + GTK_TOGGLE_BUTTON(win->radiobutton_cuadrado))) { + figura = new Cuadrado( + 1, // Color FIXME + gtk_spin_button_get_value_as_int( + GTK_SPIN_BUTTON(win->spinbutton_grosor)), + Punto(GTK_SPIN_BUTTON(win->spinbutton_centro_x), + GTK_SPIN_BUTTON(win->spinbutton_centro_y)), + gtk_entry_get_text(GTK_ENTRY(win->entry_nombre)), + gtk_spin_button_get_value_as_int( + GTK_SPIN_BUTTON(win->spinbutton_alto)) + ); + } else if (gtk_toggle_button_get_active( + GTK_TOGGLE_BUTTON(win->radiobutton_rectangulo))) { + figura = new Rectangulo( + 1, // Color FIXME + gtk_spin_button_get_value_as_int( + GTK_SPIN_BUTTON(win->spinbutton_grosor)), + Punto(GTK_SPIN_BUTTON(win->spinbutton_centro_x), + GTK_SPIN_BUTTON(win->spinbutton_centro_y)), + gtk_entry_get_text(GTK_ENTRY(win->entry_nombre)), + gtk_spin_button_get_value_as_int( + GTK_SPIN_BUTTON(win->spinbutton_alto)), + gtk_spin_button_get_value_as_int( + GTK_SPIN_BUTTON(win->spinbutton_ancho)) + ); + } else { + figura = new Circulo( + 1, // Color FIXME + gtk_spin_button_get_value_as_int( + GTK_SPIN_BUTTON(win->spinbutton_grosor)), + Punto(GTK_SPIN_BUTTON(win->spinbutton_centro_x), + GTK_SPIN_BUTTON(win->spinbutton_centro_y)), + gtk_entry_get_text(GTK_ENTRY(win->entry_nombre)), + gtk_spin_button_get_value_as_int( + GTK_SPIN_BUTTON(win->spinbutton_radio)) + ); + } + win->dibujo.agregar_figura(figura); } -gboolean on_window_delete_event(GtkWidget *widget, GdkEvent *event, +gboolean on_window_delete_event(GtkWidget* widget, GdkEvent* event, gpointer user_data) { #ifdef DEBUG std::cerr << "En delete_event." << std::endl; @@ -91,32 +136,67 @@ gboolean on_window_delete_event(GtkWidget *widget, GdkEvent *event, return FALSE; } -#include // FIXME -void on_radiobutton_linea_toggled(GtkToggleButton *togglebutton, +void on_radiobutton_linea_toggled(GtkToggleButton* togglebutton, gpointer user_data) { - // TODO +#ifdef DEBUG std::cerr << "En linea event." << std::endl; +#endif + // TODO TP5Window* win = static_cast(user_data); + gtk_widget_set_sensitive(win->spinbutton_inicio_x, true); + gtk_widget_set_sensitive(win->spinbutton_inicio_y, true); + gtk_widget_set_sensitive(win->spinbutton_fin_x, true); + gtk_widget_set_sensitive(win->spinbutton_fin_y, true); + gtk_widget_set_sensitive(win->spinbutton_alto, false); + gtk_widget_set_sensitive(win->spinbutton_ancho, false); + gtk_widget_set_sensitive(win->spinbutton_radio, false); } -void on_radiobutton_cuadrado_toggled(GtkToggleButton *togglebutton, +void on_radiobutton_cuadrado_toggled(GtkToggleButton* togglebutton, gpointer user_data) { - // TODO +#ifdef DEBUG std::cerr << "En cuadrado event." << std::endl; +#endif + // TODO TP5Window* win = static_cast(user_data); + gtk_widget_set_sensitive(win->spinbutton_inicio_x, false); + gtk_widget_set_sensitive(win->spinbutton_inicio_y, false); + gtk_widget_set_sensitive(win->spinbutton_fin_x, false); + gtk_widget_set_sensitive(win->spinbutton_fin_y, false); + gtk_widget_set_sensitive(win->spinbutton_alto, true); + gtk_widget_set_sensitive(win->spinbutton_ancho, false); + gtk_widget_set_sensitive(win->spinbutton_radio, false); } -void on_radiobutton_rectangulo_toggled(GtkToggleButton *togglebutton, +void on_radiobutton_rectangulo_toggled(GtkToggleButton* togglebutton, gpointer user_data) { - // TODO +#ifdef DEBUG std::cerr << "En rectangulo event." << std::endl; +#endif + // TODO TP5Window* win = static_cast(user_data); + gtk_widget_set_sensitive(win->spinbutton_inicio_x, false); + gtk_widget_set_sensitive(win->spinbutton_inicio_y, false); + gtk_widget_set_sensitive(win->spinbutton_fin_x, false); + gtk_widget_set_sensitive(win->spinbutton_fin_y, false); + gtk_widget_set_sensitive(win->spinbutton_alto, true); + gtk_widget_set_sensitive(win->spinbutton_ancho, true); + gtk_widget_set_sensitive(win->spinbutton_radio, false); } -void on_radiobutton_circulo_toggled(GtkToggleButton *togglebutton, +void on_radiobutton_circulo_toggled(GtkToggleButton* togglebutton, gpointer user_data) { - // TODO +#ifdef DEBUG std::cerr << "En circulo event." << std::endl; +#endif + // TODO TP5Window* win = static_cast(user_data); + gtk_widget_set_sensitive(win->spinbutton_inicio_x, false); + gtk_widget_set_sensitive(win->spinbutton_inicio_y, false); + gtk_widget_set_sensitive(win->spinbutton_fin_x, false); + gtk_widget_set_sensitive(win->spinbutton_fin_y, false); + gtk_widget_set_sensitive(win->spinbutton_alto, false); + gtk_widget_set_sensitive(win->spinbutton_ancho, false); + gtk_widget_set_sensitive(win->spinbutton_radio, true); } diff --git a/interface.cpp b/interface.cpp index 6fd52bc..26d0a52 100644 --- a/interface.cpp +++ b/interface.cpp @@ -70,7 +70,7 @@ TP5Window::TP5Window(void) { 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"); + gtk_window_set_title (GTK_WINDOW (window), "Trabajo Práctico V"); vbox = gtk_vbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (window), vbox); @@ -115,7 +115,7 @@ TP5Window::TP5Window(void) { vbox_figura = gtk_vbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (frame_figura), vbox_figura); - radiobutton_linea = gtk_radio_button_new_with_mnemonic (NULL, "Línea"); + radiobutton_linea = gtk_radio_button_new_with_mnemonic (NULL, "Línea"); gtk_box_pack_start (GTK_BOX (vbox_figura), radiobutton_linea, FALSE, FALSE, 0); gtk_radio_button_set_group (GTK_RADIO_BUTTON (radiobutton_linea), radiobutton_group); radiobutton_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radiobutton_linea)); @@ -126,12 +126,12 @@ TP5Window::TP5Window(void) { gtk_radio_button_set_group (GTK_RADIO_BUTTON (radiobutton_cuadrado), radiobutton_group); radiobutton_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radiobutton_cuadrado)); - radiobutton_rectangulo = gtk_radio_button_new_with_mnemonic (NULL, "_Rectángulo"); + radiobutton_rectangulo = gtk_radio_button_new_with_mnemonic (NULL, "_Rectángulo"); gtk_box_pack_start (GTK_BOX (vbox_figura), radiobutton_rectangulo, FALSE, FALSE, 0); gtk_radio_button_set_group (GTK_RADIO_BUTTON (radiobutton_rectangulo), radiobutton_group); radiobutton_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radiobutton_rectangulo)); - radiobutton_circulo = gtk_radio_button_new_with_mnemonic (NULL, "Círc_ulo"); + radiobutton_circulo = gtk_radio_button_new_with_mnemonic (NULL, "Círc_ulo"); gtk_box_pack_start (GTK_BOX (vbox_figura), radiobutton_circulo, FALSE, FALSE, 0); gtk_radio_button_set_group (GTK_RADIO_BUTTON (radiobutton_circulo), radiobutton_group); radiobutton_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radiobutton_circulo)); @@ -352,10 +352,10 @@ TP5Window::TP5Window(void) { NULL); g_signal_connect((gpointer) drawingarea, "expose_event", G_CALLBACK (on_drawingarea_expose_event), - dibujo); + &dibujo); g_signal_connect((gpointer) button_limpiar, "clicked", G_CALLBACK (on_button_borrar_clicked), - dibujo); + &dibujo); g_signal_connect((gpointer) button_actualizar, "clicked", G_CALLBACK (on_button_graficar_clicked), drawingarea); diff --git a/interface.h b/interface.h index 5e7372c..9c7c957 100644 --- a/interface.h +++ b/interface.h @@ -75,5 +75,5 @@ struct TP5Window { TP5Window(void); /// Destructor. virtual ~TP5Window(void); -} +}; diff --git a/punto.h b/punto.h index 5b02726..5c3d7d8 100644 --- a/punto.h +++ b/punto.h @@ -17,7 +17,7 @@ #ifndef PUNTO_H #define PUNTO_H -#include +#include #ifdef DEBUG # include @@ -39,6 +39,15 @@ struct Punto { #endif } + /// Constructor a partir de punteros a dos spinbuttons. + Punto(GtkSpinButton* x, GtkSpinButton* y): + x(gtk_spin_button_get_value_as_int(x)), + y(gtk_spin_button_get_value_as_int(y)) { +#ifdef DEBUG + std::cerr << "En constructor de Punto." << std::endl; +#endif + } + /// Constructor de copia. Punto(const Punto& p): x(p.x), y(p.y) { #ifdef DEBUG @@ -53,11 +62,6 @@ struct Punto { #endif } - /// Dibuja un punto. - virtual void dibujar(std::ostream& out) const { - out << "Punto(" << x << ", " << y << ")"; - } - }; #endif // PUNTO_H -- 2.43.0