]> git.llucax.com Git - z.facultad/75.42/plaqui.git/commitdiff
puse un boton que simula unos layers, en realidad desactiva el dnd, miren lo del...
authorNicolás Dimov <ndimov@gmail.com>
Thu, 6 Nov 2003 15:59:48 +0000 (15:59 +0000)
committerNicolás Dimov <ndimov@gmail.com>
Thu, 6 Nov 2003 15:59:48 +0000 (15:59 +0000)
Constructor/constructor.cpp
Constructor/constructor.glade
Constructor/constructor.h
Constructor/item.cpp
Constructor/splitter.cpp
Constructor/workplace.cpp
Constructor/workplace.h

index 2f1122177f0a6a3b635d52ea0b49e25fc3b2c252..e2fddbff09e18b607f3cf2ad745ce88dc4418279 100644 (file)
@@ -18,6 +18,7 @@ Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glad
        refGlade->get_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::RefPtr<Gnome::Glad
        btn_y->signal_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::RefPtr<Gnome::Glad
        workplace->drag_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<Gdk::DragContext>& 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<Gdk::DragContext>& context)
 {
        context->set_icon(ico_canio, 5, 5); 
@@ -127,16 +136,16 @@ void Constructor::on_item_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& 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<CItem*>::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<Gdk::DragContext>& 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 = "<<a->get_id()<<std::endl;
-       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;
+               // 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);
 }
index fd59385020247b0dd161407fcb2a9f600d482c5b..56a51496060b1662a23a5be3547b9eb366f700e0 100644 (file)
              <property name="fill">False</property>
            </packing>
          </child>
+
+         <child>
+           <widget class="GtkCheckButton" id="chk_btn_logica">
+             <property name="visible">True</property>
+             <property name="can_focus">True</property>
+             <property name="label" translatable="yes">Lógica</property>
+             <property name="use_underline">True</property>
+             <property name="relief">GTK_RELIEF_NORMAL</property>
+             <property name="active">False</property>
+             <property name="inconsistent">False</property>
+             <property name="draw_indicator">True</property>
+           </widget>
+           <packing>
+             <property name="padding">0</property>
+             <property name="expand">False</property>
+             <property name="fill">True</property>
+           </packing>
+         </child>
        </widget>
        <packing>
          <property name="padding">0</property>
index 08cd3e21842eab4667048b9c9e6d0edd3ad9153e..a0de6bc9ead67f7ea23fae28acd42c0cdeffc656 100644 (file)
@@ -10,6 +10,7 @@
 #include <gtkmm/button.h>
 #include <gtkmm/fixed.h>
 #include <gtkmm/scrolledwindow.h>
+#include <gtkmm/checkbutton.h>
 #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<Gdk::Pixbuf> ico_canio, ico_y, ico_codo, ico_tanque;
        std::list<Gtk::TargetEntry> listTargets;
        Glib::RefPtr<Gdk::Pixbuf> ico_last;
        std::list<CItem *> 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<Gdk::DragContext>& 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<Gdk::DragContext>& context);
index b526867890891e50c9de4a3cfe2eab53b3f188d5..b4a42fe9bba9371bc4f9a76c39fbca0f1fcde74e 100644 (file)
@@ -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()
index f5c96fb4c0129dd1e0e137684970a8ea17bf91ce..d017bc61564911edbe8bbcdcf086bbdda78f2dff 100644 (file)
@@ -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);
index 519dcd48ac2e17c3da23779804575e048ef7953e..11a98d1a3b54f5e15679871a0d4b33c3a2873f33 100644 (file)
@@ -3,6 +3,7 @@
 WorkPlace::WorkPlace( BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml> &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<<"    "<<temp.y<< std::endl;
+       if ( (event->type == GDK_BUTTON_PRESS) && (event->button == 1) ) {
+               get_pointer(temp.x,temp.y);
+               std::cout<< temp.x<<"    "<<temp.y<< std::endl;
+       }
+       return true;
+}
+
+bool WorkPlace::on_button_release_event(GdkEventButton *event)
+{
+       if ( (event->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<CItem*>::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;
index 7054a354e43afdbc6c6bf1afa658ce5ed8aa3d28..67ba45ec2fac202e42f50196d16700d612a4300d 100644 (file)
@@ -8,17 +8,23 @@
 #include <libglademm.h>
 #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<Gnome::Glade::Xml> &refGlade);
-       virtual ~WorkPlace() {}
-       virtual bool on_expose_event(GdkEventExpose *);
-       virtual bool on_button_pressed(GdkEventButton *);
-       void delete_item(int);  
-               
-       std::list<CItem *> *listaItems;
+       public:
+               WorkPlace(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml> &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<CItem *> *listaItems;
+               std::list<t_line> lista_lineas;
+               t_line temp;
 };
 
 #endif