From 2695534342641710721ae3d842915094b384f9db Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nicol=C3=A1s=20Dimov?= Date: Thu, 6 Nov 2003 15:59:48 +0000 Subject: [PATCH 1/1] puse un boton que simula unos layers, en realidad desactiva el dnd, miren lo del workplace si pueden --- Constructor/constructor.cpp | 129 ++++++++++++++++++---------------- Constructor/constructor.glade | 18 +++++ Constructor/constructor.h | 5 +- Constructor/item.cpp | 14 ++-- Constructor/splitter.cpp | 8 +-- Constructor/workplace.cpp | 24 ++++++- Constructor/workplace.h | 22 +++--- 7 files changed, 137 insertions(+), 83 deletions(-) diff --git a/Constructor/constructor.cpp b/Constructor/constructor.cpp index 2f11221..e2fddbf 100644 --- a/Constructor/constructor.cpp +++ b/Constructor/constructor.cpp @@ -18,6 +18,7 @@ Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtrget_widget("btn_tanque",btn_tanque); refGlade->get_widget("main_menu_quit",main_menu_quit); refGlade->get_widget("edit_menu_del",edit_menu_del); + refGlade->get_widget("chk_btn_logica",chk_btn_logica); refGlade->get_widget_derived("workplace", workplace); //fixed @@ -38,6 +39,7 @@ Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtrsignal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_y_drag_get)); btn_codo->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_codo_drag_get)); btn_tanque->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_tanque_drag_get)); + chk_btn_logica->signal_clicked().connect(SigC::slot(*this, &Constructor::on_chk_btn_clicked)); main_menu_quit->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_quit)); edit_menu_del->signal_activate().connect(SigC::slot(*this,&Constructor::on_edit_menu_del)); @@ -52,6 +54,7 @@ Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtrdrag_dest_set(listTargets); workplace->signal_drag_data_received().connect( SigC::slot(*this, &Constructor::on_item_drop_drag_received) ); workplace->listaItems = &listaItems; + logica = false; } Constructor::~Constructor() @@ -89,14 +92,20 @@ void Constructor::on_btn_tanque_drag_get(const Glib::RefPtr& c void Constructor::on_main_menu_quit() { - //Gtk::Main::quit(); - hide(); + Gtk::Main::quit(); + //hide(); } void Constructor::on_edit_menu_del() { // hay que meter algo aca. } + +void Constructor::on_chk_btn_clicked() +{ + logica = !logica; +} + void Constructor::on_canio_drag_begin(const Glib::RefPtr& context) { context->set_icon(ico_canio, 5, 5); @@ -127,16 +136,16 @@ void Constructor::on_item_drag_data_get(const Glib::RefPtr& co gtk_selection_data_set (selection_data, selection_data->target, 10, (const guchar*)"item_codo.png", 13); } -bool Constructor::can_drop(CItem *item, int x, int y) +bool Constructor::can_drop(CItem *item, int _x, int _y) { std::list::iterator i = listaItems.begin(); while( i != listaItems.end() ) { CItem *temp = *i; if ( temp->get_id() != item->get_id() ) { - if ( (temp->is_occupied_area(x, y)) || - ( temp->is_occupied_area(x+item->get_image()->get_width()-1, y+item->get_image()->get_height()-1)) || - ( temp->is_occupied_area(x, y+item->get_image()->get_height()-1)) || - ( temp->is_occupied_area(x+item->get_image()->get_width()-1, y) ) ) + if ( (temp->is_occupied_area(_x, _y)) || + ( temp->is_occupied_area(_x+item->get_image()->get_width()-1, _y+item->get_image()->get_height()-1)) || + ( temp->is_occupied_area(_x, _y+item->get_image()->get_height()-1)) || + ( temp->is_occupied_area(_x+item->get_image()->get_width()-1, _y) ) ) return false; else i++; } @@ -147,61 +156,61 @@ bool Constructor::can_drop(CItem *item, int x, int y) void Constructor::on_item_drop_drag_received(const Glib::RefPtr& context, int x, int y, GtkSelectionData* selection_data, guint info, guint time) { + if ( !logica ) { /* Ajusto coordenada x e y para que caigan en un lugar de una cuadricula de 32x32 */ - int i,j; - // el +1 es para evitar un bug cuando se selecciona muy cerce de la - // separacion de 2 cuadritos - i = (x+1)/32; - j = (y+1)/32; - // El drag es de un item - if (selection_data->format == 10) { - if (can_drop(((CItem*)drag_get_source_widget(context)),i*32, j*32)){ - ((CItem*)drag_get_source_widget(context))->set_position(i*32, j*32); - workplace->move(*drag_get_source_widget(context), i*32, j*32); + int i,j; + // el +1 es para evitar un bug cuando se selecciona muy cerce de la + // separacion de 2 cuadritos + i = (x+1)/32; + j = (y+1)/32; + // El drag es de un item + if (selection_data->format == 10) { + if (can_drop(((CItem*)drag_get_source_widget(context)),i*32, j*32)){ + ((CItem*)drag_get_source_widget(context))->set_position(i*32, j*32); + workplace->move(*drag_get_source_widget(context), i*32, j*32); + } } - } - // El Drag es desde la barra de tareas - if ((selection_data->length >= 0) && (selection_data->format == 8)) - { - CItem *a; - if (strcmp((const char *)selection_data->data, "item_codo.png")==0) - a = new Splitter();//Gtk::manage( new Splitter() ); - else if (strcmp((const char *)selection_data->data, "item_canio.png")==0) - a = new Conduct();//Gtk::manage( new Conduct() ); - else if (strcmp((const char *)selection_data->data, "item_y.png")==0) - a = new Union();//Gtk::manage( new Union() ); - else if (strcmp((const char *)selection_data->data, "item_tanque.png")==0) - a = new Cistern();//Gtk::manage( new Cistern() ); - else - a = new CItem();//Gtk::manage( new CItem((const char *)selection_data->data) ); - //Seteo el ID del item - a->set_id(++id); - std::cout << can_drop(a, i*32, j*32) <<" --- tamanio lista = "<< listaItems.size()<< "item = "<get_id()<put(*a, i*32, j*32); - //Apunto al workplace - a->workplace= workplace; - //Seteo la posicion del item - a->set_position(i*32,j*32); - // Seteo la lista de tipos de drags - a->drag_source_set(listTargets); - // Conecto las señales - a->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_item_drag_data_get)); - - // Utilizo el SigC::bind para que el callback on_drag_begin acepte un - // parametro extra, en este caso un CItem *. Esto se hace para - // que cuando el usuario quiera mover un item, saber que item es - // y pedirle su ícono para mostrar cono icono durante la operacion, - // Esto va a permitir, que si un widget tiene una imagen rotara o algo - // raro se vea el widget tal cual. - a->signal_drag_begin().connect(SigC::bind( SigC::slot(*this, &Constructor::on_item_drag_begin), a)); - a->show(); - listaItems.push_back(a); - } else { - id--; - delete a; + // El Drag es desde la barra de tareas + if ((selection_data->length >= 0) && (selection_data->format == 8)) { + CItem *a; + if (strcmp((const char *)selection_data->data, "item_codo.png")==0) + a = new Splitter();//Gtk::manage( new Splitter() ); + else if (strcmp((const char *)selection_data->data, "item_canio.png")==0) + a = new Conduct();//Gtk::manage( new Conduct() ); + else if (strcmp((const char *)selection_data->data, "item_y.png")==0) + a = new Union();//Gtk::manage( new Union() ); + else if (strcmp((const char *)selection_data->data, "item_tanque.png")==0) + a = new Cistern();//Gtk::manage( new Cistern() ); + else + a = new CItem();//Gtk::manage( new CItem((const char *)selection_data->data) ); + //Seteo el ID del item + a->set_id(++id); + if ( can_drop(a, i*32, j*32) ) { + workplace->put(*a, i*32, j*32); + //Apunto al workplace + a->workplace= workplace; + //Seteo la posicion del item + a->set_position(i*32,j*32); + // Seteo la lista de tipos de drags + a->drag_source_set(listTargets); + // Conecto las señales + a->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_item_drag_data_get)); + + // Utilizo el SigC::bind para que el callback on_drag_begin acepte un + // parametro extra, en este caso un CItem *. Esto se hace para + // que cuando el usuario quiera mover un item, saber que item es + // y pedirle su ícono para mostrar cono icono durante la operacion, + // Esto va a permitir, que si un widget tiene una imagen rotara o algo + // raro se vea el widget tal cual. + a->signal_drag_begin().connect(SigC::bind( SigC::slot(*this, &Constructor::on_item_drag_begin), a)); + a->show(); + listaItems.push_back(a); + } else { + id--; + delete a; + } + } + context->drag_finish(false, false, time); } - } - context->drag_finish(false, false, time); } diff --git a/Constructor/constructor.glade b/Constructor/constructor.glade index fd59385..56a5149 100644 --- a/Constructor/constructor.glade +++ b/Constructor/constructor.glade @@ -246,6 +246,24 @@ False + + + + True + True + Lógica + True + GTK_RELIEF_NORMAL + False + False + True + + + 0 + False + True + + 0 diff --git a/Constructor/constructor.h b/Constructor/constructor.h index 08cd3e2..a0de6bc 100644 --- a/Constructor/constructor.h +++ b/Constructor/constructor.h @@ -10,6 +10,7 @@ #include #include #include +#include #include "workplace.h" #include "item.h" #include "splitter.h" @@ -26,12 +27,13 @@ class Constructor : public Gtk::Window { // / defino los elementos de la ventana. Gtk::Button *btn_canio, *btn_codo, *btn_y, *btn_tanque; Gtk::ImageMenuItem *main_menu_quit, *edit_menu_del; + Gtk::CheckButton *chk_btn_logica; WorkPlace *workplace; Glib::RefPtr ico_canio, ico_y, ico_codo, ico_tanque; std::list listTargets; Glib::RefPtr ico_last; std::list listaItems; - + bool logica; bool can_drop(CItem *, int , int); // /señales de control para los elementos de la ventana. @@ -41,6 +43,7 @@ class Constructor : public Gtk::Window { virtual void on_btn_tanque_drag_get(const Glib::RefPtr& context, GtkSelectionData* selection_data, guint info, guint time); virtual void on_main_menu_quit(); virtual void on_edit_menu_del(); + virtual void on_chk_btn_clicked(); // señales para cambiar el icono. virtual void on_canio_drag_begin(const Glib::RefPtr& context); diff --git a/Constructor/item.cpp b/Constructor/item.cpp index b526867..b4a42fe 100644 --- a/Constructor/item.cpp +++ b/Constructor/item.cpp @@ -54,10 +54,10 @@ void CItem::on_menu_popup_conectar() { } -void CItem::set_position(int x, int y) +void CItem::set_position(int _x, int _y) { - this->x = x; - this->y = y; + this->x = _x; + this->y = _y; } int CItem::get_position_x() @@ -70,16 +70,16 @@ int CItem::get_position_y() return y; } -bool CItem::is_occupied_area(int a, int b) +bool CItem::is_occupied_area(int _a, int _b) { - if ( (a >= x ) && ( a < x+image->get_width()) && (b >= y) && (b < y+image->get_height()) ) + if ( ( _a >= x ) && ( _a < x+image->get_width()) && (_b >= y) && (_b < y+image->get_height()) ) return true; else return false; } -void CItem::set_id(int id) +void CItem::set_id(int _id) { - ID = id; + ID = _id; } int CItem::get_id() diff --git a/Constructor/splitter.cpp b/Constructor/splitter.cpp index f5c96fb..d017bc6 100644 --- a/Constructor/splitter.cpp +++ b/Constructor/splitter.cpp @@ -24,17 +24,17 @@ bool Splitter::on_button_press_event(GdkEventButton *event) imgActual++; switch (imgActual) { case 1: - image = imageE; + image = imageN; break; case 2: - image = imageS; + image = imageE; break; case 3: - image = imageO; + image = imageS; break; default: imgActual = 0; - image = imageN; + image = imageO; } set_size_request(image->get_width(),image->get_height()); image->render_to_drawable(get_window(),get_style()->get_black_gc(),0,0,0,0,image->get_width(),image->get_height(),Gdk::RGB_DITHER_NONE,0,0); diff --git a/Constructor/workplace.cpp b/Constructor/workplace.cpp index 519dcd4..11a98d1 100644 --- a/Constructor/workplace.cpp +++ b/Constructor/workplace.cpp @@ -3,6 +3,7 @@ WorkPlace::WorkPlace( BaseObjectType* cobject, const Glib::RefPtr &refGlade):Gtk::Fixed(cobject) { } + bool WorkPlace::on_expose_event(GdkEventExpose *e) { int x, y; @@ -14,21 +15,38 @@ bool WorkPlace::on_expose_event(GdkEventExpose *e) get_window()->draw_point (get_style()->get_black_gc(), x+1,y); get_window()->draw_point (get_style()->get_black_gc(), x-1,y); } + //TODO recorer la lista_lineas y dibujar todas + get_window()->draw_line (get_style()->get_black_gc(), temp.x,temp.y,temp.w,temp.z); return true; } -bool WorkPlace::on_button_pressed(GdkEventButton *e) +bool WorkPlace::on_button_press_event(GdkEventButton *event) { + std::cout<< temp.x<<" "<type == GDK_BUTTON_PRESS) && (event->button == 1) ) { + get_pointer(temp.x,temp.y); + std::cout<< temp.x<<" "<type == GDK_BUTTON_PRESS) && (event->button == 1) ) { + get_pointer(temp.w,temp.z); + lista_lineas.push_back(temp); + get_window()->draw_line (get_style()->get_black_gc(), temp.x,temp.y,temp.w,temp.z); + } return true; } -void WorkPlace::delete_item(int id) +void WorkPlace::delete_item(int _id) { std::list::iterator i = listaItems->begin(); while ( i != listaItems->end() ){ CItem *temp = *i; - if ( temp->get_id() == id ){ + if ( temp->get_id() == _id ){ listaItems->erase(i); delete temp; break; diff --git a/Constructor/workplace.h b/Constructor/workplace.h index 7054a35..67ba45e 100644 --- a/Constructor/workplace.h +++ b/Constructor/workplace.h @@ -8,17 +8,23 @@ #include #include "item.h" +typedef struct { + int x,y,w,z; +}t_line; + class CItem; class WorkPlace:public Gtk::Fixed { -public: - WorkPlace(BaseObjectType* cobject, const Glib::RefPtr &refGlade); - virtual ~WorkPlace() {} - virtual bool on_expose_event(GdkEventExpose *); - virtual bool on_button_pressed(GdkEventButton *); - void delete_item(int); - - std::list *listaItems; + public: + WorkPlace(BaseObjectType* cobject, const Glib::RefPtr &refGlade); + virtual ~WorkPlace() {} + virtual bool on_expose_event(GdkEventExpose *); + virtual bool on_button_press_event(GdkEventButton *event); + virtual bool on_button_release_event(GdkEventButton *event); + void delete_item(int); + std::list *listaItems; + std::list lista_lineas; + t_line temp; }; #endif -- 2.43.0