Advertisement
bretjoseph

Dragging Widgets

Jan 25th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include <gtkmm.h>
  2.  
  3. class ButtonManager
  4. {
  5. public :
  6.     ButtonManager();
  7.     Gtk::Widget* make_button(const Glib::ustring&);
  8.     bool button_press_event(GdkEventButton*);
  9.  
  10. };
  11.  
  12. ButtonManager::ButtonManager()
  13. {
  14.  
  15. }
  16.  
  17. bool ButtonManager::button_press_event(GdkEventButton* event)
  18. {
  19.     if (event->button == 1) {
  20.        
  21.     }
  22.     return 1;
  23. }
  24.  
  25. Gtk::Widget* ButtonManager::make_button(const Glib::ustring& text)
  26. {
  27.     Gtk::Widget *button = new Gtk::Button(text);
  28.     button->add_events(Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON1_MOTION_MASK);
  29.     button->signal_button_press_event().connect(sigc::mem_fun(*this, &ButtonManager::button_press_event));
  30.  
  31.     return button;
  32. }
  33.  
  34. int main(int argc, char *argv[])
  35. {
  36.     auto application = Gtk::Application::create(argc, argv, "org.gktmm.drag");
  37.     Gtk::Window *window = new Gtk::Window;
  38.     Gtk::Fixed *fixed = new Gtk::Fixed;
  39.     ButtonManager manager;
  40.     fixed->put(*manager.make_button("A Button"), 50, 50);
  41.     fixed->put(*manager.make_button("Another Button"), 250, 100);
  42.     window->add(*fixed);
  43.     window->show_all_children();
  44.     application->run(*window);
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement