X-Git-Url: https://git.llucax.com/z.facultad/75.42/figuras.git/blobdiff_plain/63c4f8d442e865cbd7a14de696930a484cceaf71..e3908a19f8ddc8d37cb2d93e8fae1e61af8487de:/callbacks.cpp 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); }