From: Ricardo Markiewicz Date: Sun, 12 Oct 2003 18:15:24 +0000 (+0000) Subject: Agrego ejemplo que hace drag and drop de elementos como caños, bifurcaciones y X-Git-Tag: svn_import~445 X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/commitdiff_plain/46de693afcd74154ed8b4f6bf6e81221e18a0f97?ds=inline Agrego ejemplo que hace drag and drop de elementos como caños, bifurcaciones y codos, que ajusta a la cuadricula los elementos. Falta agregar el dibujo de la grilla sobre el Gtk::Fixed y la habilidad de mover los elementos. --- diff --git a/tests/GUI/.xvpics/ejemplo_de_gui.xcf b/tests/GUI/.xvpics/ejemplo_de_gui.xcf deleted file mode 100644 index 36a53f1..0000000 Binary files a/tests/GUI/.xvpics/ejemplo_de_gui.xcf and /dev/null differ diff --git a/tests/GUI/Makefile.am b/tests/GUI/Makefile.am new file mode 100644 index 0000000..6365795 --- /dev/null +++ b/tests/GUI/Makefile.am @@ -0,0 +1,18 @@ +## Process this file with automake to produce Makefile.in + +INCLUDES = \ + -DPACKAGE_DATA_DIR=\""$(datadir)"\" \ + -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \ + @PACKAGE_CFLAGS@ + +bin_PROGRAMS = drag_and_drop + +drag_and_drop_SOURCES = main.cc \ + dndwindow.cc \ + dndwindow.h \ + item.cc \ + item.h + +drag_and_drop_LDADD = @PACKAGE_LIBS@ + + diff --git a/tests/GUI/canio.png b/tests/GUI/canio.png new file mode 100644 index 0000000..903fb67 Binary files /dev/null and b/tests/GUI/canio.png differ diff --git a/tests/GUI/codo.png b/tests/GUI/codo.png new file mode 100644 index 0000000..f1d1e45 Binary files /dev/null and b/tests/GUI/codo.png differ diff --git a/tests/GUI/configure.in b/tests/GUI/configure.in new file mode 100644 index 0000000..1d759ac --- /dev/null +++ b/tests/GUI/configure.in @@ -0,0 +1,23 @@ +dnl Process this file with autoconf to produce a configure script. + +AC_INIT(configure.in) +AM_INIT_AUTOMAKE(drag_and_drop, 0.1) +AM_MAINTAINER_MODE + +GNOME_COMMON_INIT + +AC_ISC_POSIX +AC_PROG_CXX +AM_PROG_CC_STDC +AC_HEADER_STDC + +pkg_modules="libgnomeui-2.0" +PKG_CHECK_MODULES(PACKAGE, + gtkmm-2.0 >= 2.0.0 ) +AC_SUBST(PACKAGE_CFLAGS) +AC_SUBST(PACKAGE_LIBS) + +AC_OUTPUT([ +Makefile +]) + diff --git a/tests/GUI/dndwindow.cc b/tests/GUI/dndwindow.cc new file mode 100644 index 0000000..fea04dc --- /dev/null +++ b/tests/GUI/dndwindow.cc @@ -0,0 +1,122 @@ +//$Id: dndwindow.cc 5 2003-10-10 04:31:35Z luca $ -*- c++ -*- + +/* gtkmm example Copyright (C) 2002 gtkmm development team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "dndwindow.h" +#include + +DnDWindow::DnDWindow() +: m_Button_Canio("Drag Canio\n"), + m_Button_Y("Drop Y\n"), + m_Button_Codo("Drag Codo\n") +{ + set_title("Editor"); + + add(m_HBox); + + m_HBox.pack_start(m_VBox); + m_HBox.pack_start(m_WorkPlace); + m_WorkPlace.set_size_request(300, 300); + + //Targets: + std::list listTargets; + listTargets.push_back( Gtk::TargetEntry("STRING") ); + listTargets.push_back( Gtk::TargetEntry("text/plain") ); + + //Drag site: + + //Make m_Button_Drag a DnD drag source: + m_Button_Canio.drag_source_set(listTargets); + m_Button_Y.drag_source_set(listTargets); + m_Button_Codo.drag_source_set(listTargets); + + //Connect signals: + m_Button_Canio.signal_drag_data_get().connect( SigC::slot(*this, &DnDWindow::on_canio_drag_data_get)); + m_Button_Y.signal_drag_data_get().connect( SigC::slot(*this, &DnDWindow::on_y_drag_data_get)); + m_Button_Codo.signal_drag_data_get().connect( SigC::slot(*this, &DnDWindow::on_codo_drag_data_get)); + + + m_VBox.pack_start(m_Button_Canio); + m_VBox.pack_start(m_Button_Y); + m_VBox.pack_start(m_Button_Codo); + + + //Drop site: + + //Make m_Label_Drop a DnD drop destination: + m_WorkPlace.drag_dest_set(listTargets); + + //Connect signals: + m_WorkPlace.signal_drag_data_received().connect( SigC::slot(*this, &DnDWindow::on_label_drop_drag_data_received) ); + + + show_all(); +} + +DnDWindow::~DnDWindow() +{ +} + +// Boton presionado en el codo +void DnDWindow::on_item_button_down() +{ + std::cout << "boton abajo" << std::endl; +} + + +void DnDWindow::on_canio_drag_data_get(const Glib::RefPtr&, GtkSelectionData* selection_data, guint, guint) +{ + //TODO: The gtkmm API needs to change to use a Gtk::SelectionData instead of a GtkSelectionData. + //That should happen for gtkmm 2.4. + gtk_selection_data_set (selection_data, selection_data->target, 8, (const guchar*)"canio.png", 9); +} + +void DnDWindow::on_y_drag_data_get(const Glib::RefPtr&, GtkSelectionData* selection_data, guint, guint) +{ + //TODO: The gtkmm API needs to change to use a Gtk::SelectionData instead of a GtkSelectionData. + //That should happen for gtkmm 2.4. + gtk_selection_data_set (selection_data, selection_data->target, 8, (const guchar*)"y.png", 5); +} + +void DnDWindow::on_codo_drag_data_get(const Glib::RefPtr&, GtkSelectionData* selection_data, guint, guint) +{ + //TODO: The gtkmm API needs to change to use a Gtk::SelectionData instead of a GtkSelectionData. + //That should happen for gtkmm 2.4. + gtk_selection_data_set (selection_data, selection_data->target, 8, (const guchar*)"codo.png", 8); +} + +void DnDWindow::on_label_drop_drag_data_received(const Glib::RefPtr& context, int x, int y, GtkSelectionData* selection_data, guint, guint time) +{ + //TODO: The gtkmm API needs to change to use a Gtk::SelectionData instead of a GtkSelectionData. + //That should happen for gtkmm 2.4. + + if ((selection_data->length >= 0) && (selection_data->format == 8)) + { + CItem *a = Gtk::manage( new CItem((const char *)selection_data->data) ); + /* Ajusto coordenada x e y para que caigan en un lugar de una cuadricula de + * 32x32 */ + int i,j; + i = x/32; + j = y/32; + m_WorkPlace.put(*a, i*32, j*32); + a->show(); + //listaItems.push_back(a); + } + + context->drag_finish(false, false, time); +} + diff --git a/tests/GUI/dndwindow.h b/tests/GUI/dndwindow.h new file mode 100644 index 0000000..2f0d09c --- /dev/null +++ b/tests/GUI/dndwindow.h @@ -0,0 +1,55 @@ +//$Id: dndwindow.h 5 2003-10-10 04:31:35Z luca $ -*- c++ -*- + +/* gtkmm example Copyright (C) 2002 gtkmm development team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef GTKMM_EXAMPLE_DNDWINDOW_H +#define GTKMM_EXAMPLE_DNDWINDOW_H + +#include +#include +#include +#include +#include +#include "item.h" + +class DnDWindow : public Gtk::Window +{ + +public: + DnDWindow(); + virtual ~DnDWindow(); + +protected: + //Signal handlers: + virtual void on_canio_drag_data_get(const Glib::RefPtr& context, GtkSelectionData* selection_data, guint info, guint time); + virtual void on_y_drag_data_get(const Glib::RefPtr& context, GtkSelectionData* selection_data, guint info, guint time); + virtual void on_codo_drag_data_get(const Glib::RefPtr& context, GtkSelectionData* selection_data, guint info, guint time); + virtual void on_label_drop_drag_data_received(const Glib::RefPtr& context, int x, int y, GtkSelectionData* selection_data, guint info, guint time); + + + void on_item_button_down(); + //Member widgets: + Gtk::HBox m_HBox; + Gtk::VBox m_VBox; + Gtk::Button m_Button_Canio; + Gtk::Button m_Button_Y; + Gtk::Button m_Button_Codo; + Gtk::Fixed m_WorkPlace; + std::list listaItems; +}; + +#endif // GTKMM_EXAMPLE_DNDWINDOW_H diff --git a/tests/GUI/item.cc b/tests/GUI/item.cc new file mode 100644 index 0000000..25ca9f3 --- /dev/null +++ b/tests/GUI/item.cc @@ -0,0 +1,28 @@ + + +#include "item.h" +#include + +CItem::CItem(const char *filename):Gtk::DrawingArea() +{ + std::cout << "CItem::CItem() -> Usando " << filename << std::endl; + image = Gdk::Pixbuf::create_from_file(filename); + + std::cout << "CItem::CItem() -> w = " << image->get_width() << " h = " << image->get_height() << std::endl; + set_size_request(image->get_width(), image->get_height()); +} + +CItem::~CItem() +{ +} + +bool CItem::on_expose_event(GdkEventExpose* event) +{ + 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); + + Gtk::DrawingArea::on_expose_event(event); + return true; +} + + diff --git a/tests/GUI/item.h b/tests/GUI/item.h new file mode 100644 index 0000000..616b942 --- /dev/null +++ b/tests/GUI/item.h @@ -0,0 +1,20 @@ + + +#ifndef GTKMM_EXAMPLE_DRAWINGAREALINES_H +#define GTKMM_EXAMPLE_DRAWINGAREALINES_H + +#include +#include + +//Custom drawing area with modified expose_event. +class CItem:public Gtk::DrawingArea { +public: + CItem(const char *filename); + ~CItem(); + bool on_expose_event(GdkEventExpose* event); +private: + Glib::RefPtr image; +}; + +#endif //GTKMM_EXAMPLE_DRAWINGAREALINES_H + diff --git a/tests/GUI/main.cc b/tests/GUI/main.cc new file mode 100644 index 0000000..fb6deba --- /dev/null +++ b/tests/GUI/main.cc @@ -0,0 +1,30 @@ +//$Id: main.cc 5 2003-10-10 04:31:35Z luca $ -*- c++ -*- + +/* gtkmm example Copyright (C) 2002 gtkmm development team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include "dndwindow.h" + +int main (int argc, char *argv[]) +{ + Gtk::Main kit(argc, argv); + + DnDWindow dndWindow; + Gtk::Main::run(dndWindow); //Shows the window and returns when it is closed. + + return 0; +} diff --git a/tests/GUI/y.png b/tests/GUI/y.png new file mode 100644 index 0000000..52585cf Binary files /dev/null and b/tests/GUI/y.png differ