From 3e385dbab78eb0336e82855d829a76a111514a38 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Sun, 12 Oct 2003 19:18:33 +0000 Subject: [PATCH] Le puse el icono de lo que se esta drageando cuando se draguea... Va tomando forma :). Tuve que hacer un par de maniobras con el "hot spot" para que caiga donde tenia que caer porque no vi bien el algoritmo que acomoda en la grilla. --- tests/GUI/dndwindow.cc | 32 ++++++++++++++++++++++++++++++-- tests/GUI/dndwindow.h | 4 ++++ tests/GUI/item.cc | 9 ++++++--- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/tests/GUI/dndwindow.cc b/tests/GUI/dndwindow.cc index fea04dc..e365208 100644 --- a/tests/GUI/dndwindow.cc +++ b/tests/GUI/dndwindow.cc @@ -48,7 +48,10 @@ DnDWindow::DnDWindow() 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)); - + // Señales para cambiar el icono cuando empieza el drag. + m_Button_Canio.signal_drag_begin().connect( SigC::slot(*this, &DnDWindow::on_canio_drag_begin)); + 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); @@ -78,10 +81,14 @@ void DnDWindow::on_item_button_down() } -void DnDWindow::on_canio_drag_data_get(const Glib::RefPtr&, GtkSelectionData* selection_data, guint, guint) +void DnDWindow::on_canio_drag_data_get(const Glib::RefPtr& 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 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); } @@ -120,3 +127,24 @@ void DnDWindow::on_label_drop_drag_data_received(const Glib::RefPtrdrag_finish(false, false, time); } +void DnDWindow::on_canio_drag_begin(const Glib::RefPtr& context) +{ + Glib::RefPtr 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& context) +{ + Glib::RefPtr 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& context) +{ + Glib::RefPtr image; + image = Gdk::Pixbuf::create_from_file("codo.png"); + context->set_icon(image, 0, 0);//image->get_width() / 2, image->get_height() / 2); +} + diff --git a/tests/GUI/dndwindow.h b/tests/GUI/dndwindow.h index 2f0d09c..8c59028 100644 --- a/tests/GUI/dndwindow.h +++ b/tests/GUI/dndwindow.h @@ -39,6 +39,10 @@ protected: 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); + // Señales para cambiar el icono cuando empieza el drag. + virtual void on_canio_drag_begin(const Glib::RefPtr& context); + virtual void on_y_drag_begin(const Glib::RefPtr& context); + virtual void on_codo_drag_begin(const Glib::RefPtr& context); void on_item_button_down(); diff --git a/tests/GUI/item.cc b/tests/GUI/item.cc index 25ca9f3..907b435 100644 --- a/tests/GUI/item.cc +++ b/tests/GUI/item.cc @@ -18,10 +18,13 @@ 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); + 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); + // XXX Esto no deberia ser necesario! en todo caso devolves false en + // vez de true para que siga llamando a los otros handlers :) + //Gtk::DrawingArea::on_expose_event(event); return true; } -- 2.43.0