From 8689d0dcedbea04de34599565d8fbbf2dd530508 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Thu, 17 Jul 2008 19:07:38 +0100 Subject: [PATCH] Refactored widget mouse movement handling, removed some Glib::RefPtrs, and tidied a few things --- src/gui/widgets/timeline-widget.cpp | 18 +- src/gui/widgets/timeline-widget.hpp | 2 +- src/gui/widgets/timeline/timeline-body.cpp | 10 +- src/gui/workspace/actions.cpp | 20 +- src/gui/workspace/workspace-window.cpp | 218 +++++++++++---------- src/gui/workspace/workspace-window.hpp | 74 +++---- 6 files changed, 179 insertions(+), 163 deletions(-) diff --git a/src/gui/widgets/timeline-widget.cpp b/src/gui/widgets/timeline-widget.cpp index 7c9e761b8..5011103ac 100644 --- a/src/gui/widgets/timeline-widget.cpp +++ b/src/gui/widgets/timeline-widget.cpp @@ -52,10 +52,12 @@ TimelineWidget::TimelineWidget() : headerContainer = new HeaderContainer(this); ENSURE(headerContainer != NULL); - horizontalAdjustment.signal_value_changed().connect( - sigc::mem_fun(this, &TimelineWidget::on_scroll) ); - verticalAdjustment.signal_value_changed().connect( - sigc::mem_fun(this, &TimelineWidget::on_scroll) ); + horizontalAdjustment.signal_value_changed().connect( sigc::mem_fun( + this, &TimelineWidget::on_scroll) ); + verticalAdjustment.signal_value_changed().connect( sigc::mem_fun( + this, &TimelineWidget::on_scroll) ); + body->signal_motion_notify_event().connect( sigc::mem_fun( + this, &TimelineWidget::on_motion_in_body_notify_event) ); set_time_scale(GAVL_TIME_SCALE / 200); @@ -214,10 +216,12 @@ TimelineWidget::get_y_scroll_offset() const return (int)verticalAdjustment.get_value(); } -void -TimelineWidget::on_mouse_move_in_body(int x, int y) +bool +TimelineWidget::on_motion_in_body_notify_event(GdkEventMotion *event) { - ruler.set_mouse_chevron_offset(x); + REQUIRE(event != NULL); + ruler.set_mouse_chevron_offset(event->x); + return true; } } // namespace widgets diff --git a/src/gui/widgets/timeline-widget.hpp b/src/gui/widgets/timeline-widget.hpp index 3bbf90184..669060038 100644 --- a/src/gui/widgets/timeline-widget.hpp +++ b/src/gui/widgets/timeline-widget.hpp @@ -111,7 +111,7 @@ protected: int get_y_scroll_offset() const; - void on_mouse_move_in_body(int x, int y); + bool on_motion_in_body_notify_event(GdkEventMotion *event); protected: gavl_time_t timeOffset; diff --git a/src/gui/widgets/timeline/timeline-body.cpp b/src/gui/widgets/timeline/timeline-body.cpp index 922496d2e..d2e711638 100644 --- a/src/gui/widgets/timeline/timeline-body.cpp +++ b/src/gui/widgets/timeline/timeline-body.cpp @@ -148,12 +148,9 @@ TimelineBody::on_button_release_event(GdkEventButton* event) bool TimelineBody::on_motion_notify_event(GdkEventMotion *event) -{ +{ REQUIRE(event != NULL); - REQUIRE(timelineWidget != NULL); - - timelineWidget->on_mouse_move_in_body(event->x, event->y); - + switch(dragType) { case Shift: @@ -169,7 +166,8 @@ TimelineBody::on_motion_notify_event(GdkEventMotion *event) } } - return true; + // false so that the message is passed up to the owner TimelineWidget + return false; } bool diff --git a/src/gui/workspace/actions.cpp b/src/gui/workspace/actions.cpp index 1cabe1c1f..deade71fa 100644 --- a/src/gui/workspace/actions.cpp +++ b/src/gui/workspace/actions.cpp @@ -108,14 +108,14 @@ Actions::add_stock_item(const Glib::RefPtr& factory, { Gtk::IconSource source; try - { - //This throws an exception if the file is not found: - source.set_pixbuf( Gdk::Pixbuf::create_from_file(filepath) ); - } + { + //This throws an exception if the file is not found: + source.set_pixbuf( Gdk::Pixbuf::create_from_file(filepath) ); + } catch(const Glib::Exception& ex) - { - g_message(ex.what().c_str()); - } + { + g_message(ex.what().c_str()); + } source.set_size(Gtk::ICON_SIZE_SMALL_TOOLBAR); source.set_size_wildcarded(); //Icon may be scaled. @@ -131,9 +131,9 @@ Actions::add_stock_item(const Glib::RefPtr& factory, void Actions::update_action_state() { - REQUIRE(workspaceWindow.assets_panel); - REQUIRE(workspaceWindow.timeline_panel); - REQUIRE(workspaceWindow.viewer_panel); + REQUIRE(workspaceWindow.assets_panel != NULL); + REQUIRE(workspaceWindow.timeline_panel != NULL); + REQUIRE(workspaceWindow.viewer_panel != NULL); is_updating_action_state = true; assetsPanelAction->set_active(workspaceWindow.assets_panel->is_shown()); diff --git a/src/gui/workspace/workspace-window.cpp b/src/gui/workspace/workspace-window.cpp index 1bab85431..027677bbb 100644 --- a/src/gui/workspace/workspace-window.cpp +++ b/src/gui/workspace/workspace-window.cpp @@ -45,126 +45,140 @@ namespace workspace { WorkspaceWindow::WorkspaceWindow(Project *source_project) : project(source_project), actions(*this) - { - REQUIRE(source_project != NULL); - - layout = NULL; +{ + REQUIRE(source_project != NULL); + + layout = NULL; + assets_panel = NULL; + viewer_panel = NULL; + timeline_panel = NULL; - create_ui(); - } + create_ui(); +} WorkspaceWindow::~WorkspaceWindow() - { - if(layout != NULL) g_object_unref(layout); - } +{ + REQUIRE(layout != NULL); + g_object_unref(layout); + + REQUIRE(assets_panel != NULL); + assets_panel->unreference(); + REQUIRE(viewer_panel != NULL); + viewer_panel->unreference(); + REQUIRE(timeline_panel != NULL); + timeline_panel->unreference(); +} void WorkspaceWindow::create_ui() - { - //----- Configure the Window -----// - set_title(AppTitle); - set_default_size(1024, 768); +{ + //----- Configure the Window -----// + set_title(AppTitle); + set_default_size(1024, 768); - //----- Set up the UI Manager -----// - // The UI will be nested within a VBox - add(base_container); + //----- Set up the UI Manager -----// + // The UI will be nested within a VBox + add(base_container); - uiManager = Gtk::UIManager::create(); - uiManager->insert_action_group(actions.actionGroup); + uiManager = Gtk::UIManager::create(); + uiManager->insert_action_group(actions.actionGroup); - add_accel_group(uiManager->get_accel_group()); + add_accel_group(uiManager->get_accel_group()); - //Layout the actions in a menubar and toolbar: - Glib::ustring ui_info = - "" - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - ""; + //Layout the actions in a menubar and toolbar: + Glib::ustring ui_info = + "" + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + ""; - try - { - uiManager->add_ui_from_string(ui_info); - } - catch(const Glib::Error& ex) - { - ERROR(gui, "Building menus failed: %s", ex.what().data()); - return; - } + try + { + uiManager->add_ui_from_string(ui_info); + } + catch(const Glib::Error& ex) + { + ERROR(gui, "Building menus failed: %s", ex.what().data()); + return; + } - //----- Set up the Menu Bar -----// - Gtk::Widget* menu_bar = uiManager->get_widget("/MenuBar"); - ASSERT(menu_bar != NULL); - base_container.pack_start(*menu_bar, Gtk::PACK_SHRINK); - - //----- Set up the Tool Bar -----// - Gtk::Toolbar* toolbar = dynamic_cast(uiManager->get_widget("/ToolBar")); - ASSERT(toolbar != NULL); - toolbar->set_toolbar_style(TOOLBAR_ICONS); - base_container.pack_start(*toolbar, Gtk::PACK_SHRINK); - - //----- Create the Panels -----// - assets_panel = Glib::RefPtr(new AssetsPanel()); - viewer_panel = Glib::RefPtr(new ViewerPanel()); - timeline_panel = Glib::RefPtr(new TimelinePanel()); + //----- Set up the Menu Bar -----// + Gtk::Widget* menu_bar = uiManager->get_widget("/MenuBar"); + ASSERT(menu_bar != NULL); + base_container.pack_start(*menu_bar, Gtk::PACK_SHRINK); + + //----- Set up the Tool Bar -----// + Gtk::Toolbar* toolbar = dynamic_cast(uiManager->get_widget("/ToolBar")); + ASSERT(toolbar != NULL); + toolbar->set_toolbar_style(TOOLBAR_ICONS); + base_container.pack_start(*toolbar, Gtk::PACK_SHRINK); + + //----- Create the Panels -----// + assets_panel = new AssetsPanel(); + ENSURE(assets_panel != NULL); + viewer_panel = new ViewerPanel(); + ENSURE(viewer_panel != NULL); + timeline_panel = new TimelinePanel(); + ENSURE(timeline_panel != NULL); - //----- Create the Dock -----// - dock = Glib::wrap(gdl_dock_new()); - - layout = gdl_dock_layout_new((GdlDock*)dock->gobj()); - - dockbar = Glib::wrap(gdl_dock_bar_new ((GdlDock*)dock->gobj())); + //----- Create the Dock -----// + dock = Glib::wrap(gdl_dock_new()); + + layout = gdl_dock_layout_new((GdlDock*)dock->gobj()); + + dockbar = Glib::wrap(gdl_dock_bar_new ((GdlDock*)dock->gobj())); - dock_container.pack_start(*dockbar, PACK_SHRINK); - dock_container.pack_end(*dock, PACK_EXPAND_WIDGET); - base_container.pack_start(dock_container, PACK_EXPAND_WIDGET); + dock_container.pack_start(*dockbar, PACK_SHRINK); + dock_container.pack_end(*dock, PACK_EXPAND_WIDGET); + base_container.pack_start(dock_container, PACK_EXPAND_WIDGET); - gdl_dock_add_item ((GdlDock*)dock->gobj(), assets_panel->get_dock_item(), GDL_DOCK_LEFT); - gdl_dock_add_item ((GdlDock*)dock->gobj(), viewer_panel->get_dock_item(), GDL_DOCK_RIGHT); - gdl_dock_add_item ((GdlDock*)dock->gobj(), timeline_panel->get_dock_item(), GDL_DOCK_BOTTOM); + gdl_dock_add_item ((GdlDock*)dock->gobj(), assets_panel->get_dock_item(), GDL_DOCK_LEFT); + gdl_dock_add_item ((GdlDock*)dock->gobj(), viewer_panel->get_dock_item(), GDL_DOCK_RIGHT); + gdl_dock_add_item ((GdlDock*)dock->gobj(), timeline_panel->get_dock_item(), GDL_DOCK_BOTTOM); - // Manually dock and move around some of the items - gdl_dock_item_dock_to (timeline_panel->get_dock_item(), - assets_panel->get_dock_item(), GDL_DOCK_BOTTOM, -1); - gdl_dock_item_dock_to (viewer_panel->get_dock_item(), - assets_panel->get_dock_item(), GDL_DOCK_RIGHT, -1); + // Manually dock and move around some of the items + gdl_dock_item_dock_to (timeline_panel->get_dock_item(), + assets_panel->get_dock_item(), GDL_DOCK_BOTTOM, -1); + gdl_dock_item_dock_to (viewer_panel->get_dock_item(), + assets_panel->get_dock_item(), GDL_DOCK_RIGHT, -1); - show_all_children(); + show_all_children(); - gchar ph1[] = "ph1"; - gdl_dock_placeholder_new (ph1, (GdlDockObject*)dock->gobj(), GDL_DOCK_TOP, FALSE); - gchar ph2[] = "ph2"; - gdl_dock_placeholder_new (ph2, (GdlDockObject*)dock->gobj(), GDL_DOCK_BOTTOM, FALSE); - gchar ph3[] = "ph3"; - gdl_dock_placeholder_new (ph3, (GdlDockObject*)dock->gobj(), GDL_DOCK_LEFT, FALSE); - gchar ph4[] = "ph4"; - gdl_dock_placeholder_new (ph4, (GdlDockObject*)dock->gobj(), GDL_DOCK_RIGHT, FALSE); - } + gchar ph1[] = "ph1"; + gdl_dock_placeholder_new (ph1, (GdlDockObject*)dock->gobj(), GDL_DOCK_TOP, FALSE); + gchar ph2[] = "ph2"; + gdl_dock_placeholder_new (ph2, (GdlDockObject*)dock->gobj(), GDL_DOCK_BOTTOM, FALSE); + gchar ph3[] = "ph3"; + gdl_dock_placeholder_new (ph3, (GdlDockObject*)dock->gobj(), GDL_DOCK_LEFT, FALSE); + gchar ph4[] = "ph4"; + gdl_dock_placeholder_new (ph4, (GdlDockObject*)dock->gobj(), GDL_DOCK_RIGHT, FALSE); +} } // namespace workspace } // namespace gui diff --git a/src/gui/workspace/workspace-window.hpp b/src/gui/workspace/workspace-window.hpp index 86e3dd68a..86f56a2bf 100644 --- a/src/gui/workspace/workspace-window.hpp +++ b/src/gui/workspace/workspace-window.hpp @@ -49,47 +49,47 @@ namespace model { namespace workspace { - /** - * The main lumiera workspace window - */ - class WorkspaceWindow : public Gtk::Window - { - public: - WorkspaceWindow(lumiera::gui::model::Project *source_project); - virtual ~WorkspaceWindow(); - - private: - void create_ui(); +/** +* The main lumiera workspace window +*/ +class WorkspaceWindow : public Gtk::Window +{ +public: + WorkspaceWindow(lumiera::gui::model::Project *source_project); + virtual ~WorkspaceWindow(); - /* ===== Model ===== */ - private: - lumiera::gui::model::Project *project; +private: + void create_ui(); - /* ===== UI ===== */ - private: - Glib::RefPtr uiManager; - Gtk::VBox base_container; - Gtk::HBox dock_container; - - Gtk::Widget *dock; - Gtk::Widget *dockbar; - GdlDockLayout *layout; + /* ===== Model ===== */ +private: + lumiera::gui::model::Project *project; - /* ===== Panels ===== */ - private: - Glib::RefPtr assets_panel; - Glib::RefPtr viewer_panel; - Glib::RefPtr timeline_panel; - - /* ===== Helpers ===== */ - private: - /** - * The instantiation of the actions helper class, which - * registers and handles user action events */ - Actions actions; + /* ===== UI ===== */ +private: + Glib::RefPtr uiManager; + Gtk::VBox base_container; + Gtk::HBox dock_container; + + Gtk::Widget *dock; + Gtk::Widget *dockbar; + GdlDockLayout *layout; - friend class Actions; - }; + /* ===== Panels ===== */ +private: + AssetsPanel *assets_panel; + ViewerPanel *viewer_panel; + TimelinePanel *timeline_panel; + + /* ===== Helpers ===== */ +private: + /** + * The instantiation of the actions helper class, which + * registers and handles user action events */ + Actions actions; + + friend class Actions; +}; } // namespace workspace } // namespace gui