#include "dndwindow.h"
#include <iostream>
+Glib::RefPtr<Gdk::Pixbuf> ico_canio, ico_y, ico_codo;
+
DnDWindow::DnDWindow()
: m_Button_Canio("Drag Canio\n"),
m_Button_Y("Drop Y\n"),
{
set_title("Editor");
+ ico_canio = Gdk::Pixbuf::create_from_file("canio.png");
+ ico_y = Gdk::Pixbuf::create_from_file("y.png");
+ ico_codo = Gdk::Pixbuf::create_from_file("codo.png");
+
add(m_HBox);
m_HBox.pack_start(m_VBox);
+
+ m_VBox.pack_start(m_Button_Canio);
+ m_VBox.pack_start(m_Button_Y);
+ m_VBox.pack_start(m_Button_Codo);
+
m_HBox.pack_start(m_WorkPlace);
- m_WorkPlace.set_size_request(300, 300);
+ m_WorkPlace.set_size_request(600, 600);
//Targets:
std::list<Gtk::TargetEntry> listTargets;
m_Button_Y.signal_drag_begin().connect( SigC::slot(*this, &DnDWindow::on_y_drag_begin));
m_Button_Codo.signal_drag_begin().connect( SigC::slot(*this, &DnDWindow::on_codo_drag_begin));
- 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:
+
+ //Connect signals:
m_WorkPlace.signal_drag_data_received().connect( SigC::slot(*this, &DnDWindow::on_label_drop_drag_data_received) );
-
show_all();
}
std::cout << "boton abajo" << std::endl;
}
+void DnDWindow::on_canio_drag_begin(const Glib::RefPtr<Gdk::DragContext> &context)
+{
+ context->set_icon(ico_canio, 0, 0); //ico_canio->get_width(), ico_canio->get_height());
+}
+
+void DnDWindow::on_y_drag_begin(const Glib::RefPtr<Gdk::DragContext> &context)
+{
+ context->set_icon(ico_y, 0, 0); //ico_canio->get_width(), ico_canio->get_height());
+}
+
+void DnDWindow::on_codo_drag_begin(const Glib::RefPtr<Gdk::DragContext> &context)
+{
+ context->set_icon(ico_codo, 0, 0); //ico_canio->get_width(), ico_canio->get_height());
+}
+
+
+
void DnDWindow::on_canio_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, 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.
- Glib::RefPtr<Gdk::Pixbuf> image;
- image = Gdk::Pixbuf::create_from_file("canio.png");
- // Cambio el icono de DND seteando el "hot spot" en el centro.
- context->set_icon(image, image->get_width() / 2, image->get_height() / 2);
gtk_selection_data_set (selection_data, selection_data->target, 8, (const guchar*)"canio.png", 9);
}
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);
+ 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;
+ // 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;
+ m_WorkPlace.put(*a, i*32, j*32);
+ a->show();
+ //listaItems.push_back(a);
}
context->drag_finish(false, false, time);
}
-void DnDWindow::on_canio_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
-{
- Glib::RefPtr<Gdk::Pixbuf> image;
- image = Gdk::Pixbuf::create_from_file("canio.png");
- context->set_icon(image, image->get_width() / 2, image->get_height() / 4);
-}
-
-void DnDWindow::on_y_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
-{
- Glib::RefPtr<Gdk::Pixbuf> image;
- image = Gdk::Pixbuf::create_from_file("y.png");
- context->set_icon(image, image->get_width() / 4, image->get_height() / 4);
-}
-
-void DnDWindow::on_codo_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
-{
- Glib::RefPtr<Gdk::Pixbuf> image;
- image = Gdk::Pixbuf::create_from_file("codo.png");
- context->set_icon(image, 0, 0);//image->get_width() / 2, image->get_height() / 2);
-}