From 46de693afcd74154ed8b4f6bf6e81221e18a0f97 Mon Sep 17 00:00:00 2001 From: Ricardo Markiewicz Date: Sun, 12 Oct 2003 18:15:24 +0000 Subject: [PATCH] =?utf8?q?Agrego=20ejemplo=20que=20hace=20drag=20and=20dro?= =?utf8?q?p=20de=20elementos=20como=20ca=C3=B1os,=20bifurcaciones=20y=20co?= =?utf8?q?dos,=20que=20ajusta=20a=20la=20cuadricula=20los=20elementos.=20F?= =?utf8?q?alta=20agregar=20el=20dibujo=20de=20la=20grilla=20sobre=20el=20G?= =?utf8?q?tk::Fixed=20y=20la=20habilidad=20de=20mover=20los=20elementos.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- tests/GUI/.xvpics/ejemplo_de_gui.xcf | Bin 3668 -> 0 bytes tests/GUI/Makefile.am | 18 ++++ tests/GUI/canio.png | Bin 0 -> 334 bytes tests/GUI/codo.png | Bin 0 -> 1001 bytes tests/GUI/configure.in | 23 +++++ tests/GUI/dndwindow.cc | 122 +++++++++++++++++++++++++++ tests/GUI/dndwindow.h | 55 ++++++++++++ tests/GUI/item.cc | 28 ++++++ tests/GUI/item.h | 20 +++++ tests/GUI/main.cc | 30 +++++++ tests/GUI/y.png | Bin 0 -> 721 bytes 11 files changed, 296 insertions(+) delete mode 100644 tests/GUI/.xvpics/ejemplo_de_gui.xcf create mode 100644 tests/GUI/Makefile.am create mode 100644 tests/GUI/canio.png create mode 100644 tests/GUI/codo.png create mode 100644 tests/GUI/configure.in create mode 100644 tests/GUI/dndwindow.cc create mode 100644 tests/GUI/dndwindow.h create mode 100644 tests/GUI/item.cc create mode 100644 tests/GUI/item.h create mode 100644 tests/GUI/main.cc create mode 100644 tests/GUI/y.png diff --git a/tests/GUI/.xvpics/ejemplo_de_gui.xcf b/tests/GUI/.xvpics/ejemplo_de_gui.xcf deleted file mode 100644 index 36a53f1f63e52abe7941cd57619c74be720022ee..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3668 zcmWGAS1>j<;!^hXb@%jh^S3fGHLCz(g&=n)1q};B3nPW3%97M#O)h0uKbLraw|HlN zUtd?hkYFw|0|g*5GBxG;KMF=eU^D~* zHc*5Ch|z>m6@hsmy}5b06Z3L`c!)2klx$>Z~ec0``_*VKn!F9Mc{4*vUM=*g9(82!q^ZRDV!$(CDEl( z6=UJS;s~r6i#$<6WY`Ngmwde-oge@=iUbBk=g`voACyBu5b93|hlMy_gHjF%KvhFH zFdhLT21;+Bfu?|ffKDLPd4W6vJOVz31RRTy_C$F1KPY+kA*2YiRN$I70a>|(H6W`1 z*|rTRunkC0LY5$g4buFZJgxu#gPjdDAd?uI(A9tfjAXw;4GH7`MwJFEs?bfw&j(uz ZPn!7EqRS4HUUYYi@<&5pGz6#>0syczzVQG6 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 0000000000000000000000000000000000000000..903fb67ded9d14a5aa87346db968db280f93525e GIT binary patch literal 334 zcmeAS@N?(olHy`uVBq!ia0vp^3P2pk!2~4F8Z-(4DYhhUcNd2LAh=-f^2tCE&H|6f zVg?3ope(l#K;XTk;hCfUKFLh-1ehRMgczrVW-6c1pxW8(_p;Q0wDPH$_ zm(6+gZ`-elxlU9$>2BMX+`Di~ZuGRLU%uB(OFeAB68-nTDl^CsbWkJN@oLw%)#rBZ zd%xPsz?}bBT+U^agAaFH^s}n4ekS#P{*mhuKs^nXNz?vSK4U!^y3oKpzP1`00006VoOIv0RI60 z0RN!9r;`8x010qNS#tmY3labT3lag+-G2N4000McNliru(+Ug)6$XF>;_?6h19nM7 zK~#90?U~O@B2gT`zh(>7DB*yJZd((Y(^L*w6c$8Cw+v4rbP4v_A?Q$lhS&BI40(vi zOVZbOi~#jNA20Kl)o0w^-kzSG@;skPrE0a>(9jUevMkGbJf6Y9 zL0KmcAd7%F@kBh8O7T2@baa%<5% zLPn!e`q=+q2SCzW3s%4yPEJlJiYk>#S``2U z9LEKNK@AH4f|;3_#_NL`1+v+!%jJ4}d~8HOjmK%1(=|3W7K_Ci3s>I?0D@#PIXXJ3 z)fE7M5$^~=5Qm3{Z$_$A006?_a3jAW+~af`bXmJdlC)SX7K?=>NvqX5H8nLCn8TRs zi(LJ<^85YibXq(N_ex1ZE|)8nN|j2bTrO8Cl|rGgwY6paYIQoDe!qWVVS(vqFgphT z0EgW%K~AL8>HhwH(LlUSY=_r&RVI^(L?SkuZE7&RrvSeJ X5aN>)L6m>>00000NkvXXu0mjf?~KNM literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..52585cfeee96cd37bb58838bd1ef3b444c7d92a6 GIT binary patch literal 721 zcmeAS@N?(olHy`uVBq!ia0vp^2|({XE)7O>#G8Yf4C`%r9^F0OzrZ`U*$B>FSZ*Ohv5)KqO_ECRQ zUi8Jh?g-u69XvYSEW0JVzcaqMB;~P_e?$HTj@@C5(a{I3PTbJRQEb%JNpaY)G3xZs zZI_g0-YiakHqY3+=%3G2X+OUGdWU5b_$^w(_7@aZ8O}aC!zm!OD9BJtdDV5+mqSCvi^ae*qr=;YI4VnUz4L4m(T2_i7@Zbrbb~A^btdy0`#tLpmM%Naq3Rp|ue0@QpL$;^t zqN1h3&41rIuVihNs+Y*GtKzO<@|zX&@F(9NmU-cGKFodekD+bVmdKI;Vst0AOA*Y5)KL literal 0 HcmV?d00001 -- 2.43.0