WIP: Restructured track headers for more refined drag support

This commit is contained in:
Joel Holdsworth 2009-01-14 23:20:43 +00:00
parent 34c7cfd3c3
commit 4a8f5629f6
9 changed files with 80 additions and 261 deletions

View file

@ -125,6 +125,8 @@ libgui_la_SOURCES = \
$(lumigui_srcdir)/widgets/timeline-widget.hpp \
$(lumigui_srcdir)/widgets/timeline/timeline-view-window.cpp \
$(lumigui_srcdir)/widgets/timeline/timeline-view-window.hpp \
$(lumigui_srcdir)/widgets/timeline/timeline-header-widget.cpp \
$(lumigui_srcdir)/widgets/timeline/timeline-header-widget.hpp \
$(lumigui_srcdir)/widgets/timeline/timeline-header-container.cpp \
$(lumigui_srcdir)/widgets/timeline/timeline-header-container.hpp \
$(lumigui_srcdir)/widgets/timeline/timeline-body.cpp \

View file

@ -151,13 +151,14 @@ style "timeline_ruler" = "default_base"
gtkmm__CustomObject_TimelineRuler::playback_period_arrow_stem_size = 3
}
style "timeline_header_container" = "default_base"
style "timeline_header_widget" = "default_base"
{
gtkmm__CustomObject_HeaderContainer::heading_margin = 4
gtkmm__CustomObject_TimelineHeaderWidget::margin = 4
gtkmm__CustomObject_TimelineHeaderWidget::expand_button_size = 12
}
class "gtkmm__CustomObject_TimelineBody" style:highest "timeline_body"
class "gtkmm__CustomObject_TimelineRuler" style:highest "timeline_ruler"
class "gtkmm__CustomObject_TimelineHeaderContainer" style:highest "timeline_header_container"
class "gtkmm__CustomObject_TimelineHeaderWidget" style:highest "timeline_header_widget"

View file

@ -314,6 +314,7 @@ protected:
friend class timeline::TimelineViewWindow;
friend class timeline::TimelineBody;
friend class timeline::TimelineHeaderContainer;
friend class timeline::TimelineHeaderWidget;
friend class timeline::TimelineLayoutHelper;
friend class timeline::TimelineRuler;
friend class timeline::Tool;

View file

@ -40,9 +40,7 @@ namespace timeline {
TimelineHeaderContainer::TimelineHeaderContainer(
gui::widgets::TimelineWidget &timeline_widget) :
Glib::ObjectBase("TimelineHeaderContainer"),
timelineWidget(timeline_widget),
margin(-1),
expand_button_size(12)
timelineWidget(timeline_widget)
{
// This widget will not have a window at first
set_flags(Gtk::NO_WINDOW);
@ -65,12 +63,6 @@ TimelineHeaderContainer::TimelineHeaderContainer(
menu_list.push_back( Menu_Helpers::MenuElem(_("_Add Track"),
sigc::mem_fun(timelineWidget,
&TimelineWidget::on_add_track_command) ) );
// Install style properties
register_styles();
// Load the styles up
read_styles();
}
void
@ -148,19 +140,7 @@ bool TimelineHeaderContainer::on_button_press_event (
switch(event->button)
{
case 1: // Left Click
// Did the user press the button on an expander?
if(hoveringExpander)
{
// Yes? The prime for a release event
clickedExpander = hoveringExpander;
queue_draw();
}
else if(hoveringTrack) // Is the user hovering on a track
{
}
case 1: // Left Click
break;
case 3: // Right Click
@ -194,17 +174,6 @@ bool TimelineHeaderContainer::on_button_release_event (
{
TimelineLayoutHelper &layout = timelineWidget.layoutHelper;
// Did the user release the button on an expander?
if(clickedExpander != NULL)
{
// Yes? The toggle the expanding
clickedExpander->expand_collapse(
clickedExpander->get_expanded() ? Track::Collapse : Track::Expand);
clickedExpander.reset();
layout.update_layout();
}
// Has the user been dragging?
if(layout.get_dragging_track())
layout.end_dragging_track();
@ -216,45 +185,35 @@ bool TimelineHeaderContainer::on_motion_notify_event (
GdkEventMotion* event)
{
REQUIRE(event != NULL);
REQUIRE(gdkWindow);
const bool result = Container::on_motion_notify_event(event);
const Gdk::Point point(event->x, event->y);
TimelineLayoutHelper &layout = timelineWidget.layoutHelper;
TimelineLayoutHelper &layout = timelineWidget.layoutHelper;
// Get the mouse point
int window_x = 0, window_y = 0;
gdkWindow->get_origin(window_x, window_y);
mousePoint = Gdk::Point(event->x_root - window_x,
event->y_root - window_y);
// Are we beginning to drag a header?
if((event->state & GDK_BUTTON1_MASK) && hoveringTrack &&
!hoveringExpander && !layout.get_dragging_track())
!layout.get_dragging_track())
{
layout.begin_dragging_track(hoveringTrack);
layout.begin_dragging_track(mousePoint);
return result;
}
// Are we currently dragging?
if(layout.get_dragging_track())
{
layout.drag_to_point(point);
layout.drag_to_point(mousePoint);
return result;
}
// Hit test the rectangle
hoveringTrack = layout.header_from_point(point);
if(hoveringTrack)
{
const optional<Gdk::Rectangle> rect =
get_expander_button_rectangle(hoveringTrack);
REQUIRE(rect);
// Are we hovering on the expander?
if(util::pt_in_rect(point, *rect))
{
hoveringExpander = hoveringTrack;
queue_draw();
}
else hoveringExpander.reset();
}
hoveringTrack = layout.header_from_point(mousePoint);
return result;
}
@ -295,8 +254,7 @@ TimelineHeaderContainer::on_size_allocate (Allocation& allocation)
// Resize the widget's window
if(gdkWindow)
{
gdkWindow->move(allocation.get_x(), allocation.get_y());
gdkWindow->resize(
gdkWindow->move_resize(allocation.get_x(), allocation.get_y(),
allocation.get_width(), allocation.get_height());
}
@ -330,35 +288,6 @@ TimelineHeaderContainer::on_layout_changed()
layout_headers();
}
bool
TimelineHeaderContainer::on_expose_event(GdkEventExpose *event)
{
if(gdkWindow)
{
const Allocation container_allocation = get_allocation();
// Paint a border underneath all the headers
const TimelineLayoutHelper::TrackTree &layout_tree =
timelineWidget.layoutHelper.get_layout_tree();
TimelineLayoutHelper::TrackTree::pre_order_iterator iterator;
for(iterator = ++layout_tree.begin(); // ++ so that we skip the sequence root
iterator != layout_tree.end();
iterator++)
{
shared_ptr<model::Track> model_track = *iterator;
REQUIRE(model_track);
draw_header_decoration(model_track,
Gdk::Rectangle(0, 0,
container_allocation.get_width(),
container_allocation.get_height()));
}
}
return Container::on_expose_event(event);
}
void
TimelineHeaderContainer::on_scroll()
{
@ -373,15 +302,12 @@ TimelineHeaderContainer::on_hovering_track_changed(
{
(void)hovering_track;
// The hovering track has changed, redraw so we can light the header
queue_draw();
}
void
TimelineHeaderContainer::layout_headers()
{
REQUIRE(margin >= 0); // read_styles must have been called before now
// We can't layout before the widget has been set up
if(!gdkWindow)
return;
@ -390,6 +316,9 @@ TimelineHeaderContainer::layout_headers()
timelineWidget.layoutHelper;
const TimelineLayoutHelper::TrackTree &layout_tree =
layout_helper.get_layout_tree();
shared_ptr<timeline::Track> dragging_track =
layout_helper.get_dragging_track();
TimelineLayoutHelper::TrackTree::pre_order_iterator iterator;
for(iterator = ++layout_tree.begin(); // ++ so that we skip the sequence root
@ -408,17 +337,9 @@ TimelineHeaderContainer::layout_headers()
{
REQUIRE(header_rect->get_width() >= 0);
REQUIRE(header_rect->get_height() >= 0);
// Calculate the allocation of the header widget
Allocation header_allocation(
header_rect->get_x() + margin + expand_button_size, // x
header_rect->get_y() + margin, // y
max( header_rect->get_width() - expand_button_size -
margin * 2, 0 ), // width
header_rect->get_height() - margin * 2); // height
// Apply the allocation to the header
widget.size_allocate (header_allocation);
widget.size_allocate (*header_rect);
if(!widget.is_visible())
widget.show();
}
@ -426,78 +347,9 @@ TimelineHeaderContainer::layout_headers()
if(widget.is_visible())
widget.hide();
}
// Repaint the background of our parenting
queue_draw ();
}
void
TimelineHeaderContainer::draw_header_decoration(
shared_ptr<model::Track> model_track,
const Gdk::Rectangle &clip_rect)
{
REQUIRE(model_track != NULL);
REQUIRE(clip_rect.get_width() > 0);
REQUIRE(clip_rect.get_height() > 0);
Glib::RefPtr<Style> style = get_style();
REQUIRE(style);
shared_ptr<timeline::Track> timeline_track =
lookup_timeline_track(model_track);
// Get the header box
const optional<Gdk::Rectangle> &optional_box =
timelineWidget.layoutHelper.get_track_header_rect(timeline_track);
if(!optional_box)
return;
const Gdk::Rectangle box = *optional_box;
// Don't paint the box, if it won't be visible
if(box.get_x() >= clip_rect.get_width() ||
box.get_height() <= 0 ||
box.get_y() + box.get_height() <= clip_rect.get_y() ||
box.get_y() >= clip_rect.get_y() + clip_rect.get_height())
return;
// Use paint_box to draw a themed bevel around the header
style->paint_box(gdkWindow, STATE_NORMAL,
SHADOW_OUT, clip_rect, *this, "",
box.get_x(), box.get_y(),
box.get_width(), box.get_height());
// Paint the expander if there are child tracks
StateType state_type = STATE_NORMAL;
if(clickedExpander == timeline_track)
state_type = STATE_SELECTED;
else if(hoveringExpander == timeline_track)
state_type = STATE_PRELIGHT;
if(!model_track->get_child_tracks().empty())
style->paint_expander (gdkWindow,
state_type,
clip_rect, *this, "",
box.get_x() + expand_button_size / 2 + margin,
box.get_y() + box.get_height() / 2,
timeline_track->get_expander_style());
}
const optional<Gdk::Rectangle>
TimelineHeaderContainer::get_expander_button_rectangle(
shared_ptr<Track> track)
{
REQUIRE(track != NULL);
optional<Gdk::Rectangle> box =
timelineWidget.layoutHelper.get_track_header_rect(track);
if(box)
{
return optional<Gdk::Rectangle>(Gdk::Rectangle(
margin + box->get_x(), margin + box->get_y(),
expand_button_size, box->get_height() - margin * 2));
}
return optional<Gdk::Rectangle>();
queue_draw();
}
shared_ptr<timeline::Track>
@ -513,35 +365,6 @@ TimelineHeaderContainer::lookup_timeline_track(
return timeline_track;
}
void
TimelineHeaderContainer::register_styles() const
{
static bool registered = false;
if(registered) return;
registered = true;
GtkWidgetClass *klass = GTK_WIDGET_CLASS(G_OBJECT_GET_CLASS(gobj()));
gtk_widget_class_install_style_property(klass,
g_param_spec_int("heading_margin",
"Heading Margin",
"The amount of padding around each header pixels.",
0, G_MAXINT, 4, G_PARAM_READABLE));
}
void
TimelineHeaderContainer::read_styles()
{
if(margin <= 0)
{
get_style_property("heading_margin", margin);
margin = max(margin, 0);
}
else
WARN(gui, "TimelineHeaderContainer::read_styles()"
" should only be called once");
}
} // namespace timeline
} // namespace widgets
} // namespace gui

View file

@ -131,11 +131,6 @@ private:
void on_layout_changed();
/**
* An event handler for when the window must be redrawn.
*/
bool on_expose_event(GdkEventExpose *event);
/**
* This event is called when the scroll bar moves.
*/
@ -165,15 +160,6 @@ private:
boost::shared_ptr<model::Track> model_track,
const Gdk::Rectangle &clip_rect);
/**
* Gets the rectangular hit-target area of a track header's expander
* button.
* @param track The track to get the expander button rectangle of.
* @return Returns the rectangle of the expander button of track.
**/
const boost::optional<Gdk::Rectangle> get_expander_button_rectangle(
boost::shared_ptr<timeline::Track> track);
/**
* A helper function which calls lookup_timeline_track within the
* parent timeline widget, but also applies lots of data consistency
@ -187,16 +173,6 @@ private:
boost::shared_ptr<timeline::Track> lookup_timeline_track(
boost::shared_ptr<model::Track> model_track);
/**
* Registers all the styles that this class will respond to.
*/
void register_styles() const;
/**
* Reads styles from the present stylesheet.
*/
void read_styles();
private:
/**
@ -220,27 +196,11 @@ private:
**/
Gtk::Menu contextMenu;
//----- User Interaction State -----//
//----- User Interaction State -----//
boost::shared_ptr<timeline::Track> hoveringTrack;
boost::shared_ptr<timeline::Track> hoveringExpander;
boost::shared_ptr<timeline::Track> clickedExpander;
//----- Style Values -----//
/**
* The style value which indicates the amount of padding around each
* header pixels.
**/
int margin;
/**
* The style value which indicates the size to draw the expand button
* in pixels.
**/
int expand_button_size;
Gdk::Point mousePoint;
friend class gui::widgets::TimelineWidget;
friend class timeline::Track;
};

View file

@ -128,16 +128,22 @@ TimelineLayoutHelper::track_from_y(int y)
return shared_ptr<timeline::Track>();
}
void
bool
TimelineLayoutHelper::begin_dragging_track(
boost::shared_ptr<timeline::Track> track)
const Gdk::Point &mouse_point)
{
REQUIRE(track);
draggingTrack = track;
g_message("begin_dragging_track");
draggingTrack = header_from_point(mouse_point);
if(!draggingTrack)
return false;
const Gdk::Rectangle &rect = headerBoxes[draggingTrack];
dragStartOffset = Gdk::Point(
mouse_point.get_x() - rect.get_x(),
mouse_point.get_y() - rect.get_y());
// Find the track in the tree
const shared_ptr<model::Track> model_track = track->get_model_track();
const shared_ptr<model::Track> model_track =
draggingTrack->get_model_track();
REQUIRE(model_track);
for(draggingTrackIter = layoutTree.begin();
draggingTrackIter != layoutTree.end();
@ -146,6 +152,8 @@ TimelineLayoutHelper::begin_dragging_track(
if(*draggingTrackIter == model_track)
break;
}
return true;
}
void
@ -163,10 +171,11 @@ TimelineLayoutHelper::get_dragging_track() const
}
void
TimelineLayoutHelper::drag_to_point(Gdk::Point point)
TimelineLayoutHelper::drag_to_point(const Gdk::Point &point)
{
// Apply the scroll offset
point.set_y(point.get_y() + timelineWidget.get_y_scroll_offset());
dragPoint = Gdk::Point(point.get_x(),
point.get_y() + timelineWidget.get_y_scroll_offset());
// Search the headers
TrackTree::pre_order_iterator iterator;
@ -240,12 +249,13 @@ TimelineLayoutHelper::layout_headers_recursive(
iterator != layoutTree.end(parent_iterator);
iterator++)
{
Gdk::Rectangle rect;
const shared_ptr<model::Track> &model_track = *iterator;
REQUIRE(model_track);
shared_ptr<timeline::Track> timeline_track =
lookup_timeline_track(model_track);
// Is the track going to be shown?
if(parent_expanded)
{
@ -253,7 +263,7 @@ TimelineLayoutHelper::layout_headers_recursive(
const int track_height = timeline_track->get_height();
const int indent = depth * indent_width;
headerBoxes[timeline_track] = Gdk::Rectangle(
rect = Gdk::Rectangle(
indent, // x
branch_offset + child_offset, // y
max( header_width - indent, 0 ), // width
@ -261,8 +271,18 @@ TimelineLayoutHelper::layout_headers_recursive(
// Offset for the next header
child_offset += track_height + TimelineWidget::TrackPadding;
// Is this header being dragged?
if(timeline_track == draggingTrack)
{
rect.set_y(dragPoint.get_y() - dragStartOffset.get_y());
}
headerBoxes[timeline_track] = rect;
}
// Is the track animating?
const bool is_track_animating =
timeline_track->is_expand_animating();

View file

@ -127,13 +127,13 @@ public:
**/
boost::shared_ptr<timeline::Track> track_from_y(int y);
void begin_dragging_track(boost::shared_ptr<timeline::Track> track);
bool begin_dragging_track(const Gdk::Point &mouse_point);
void end_dragging_track();
boost::shared_ptr<timeline::Track> get_dragging_track() const;
void drag_to_point(Gdk::Point point);
void drag_to_point(const Gdk::Point &point);
/**
* Returns the total height in pixels of the layout tree.
@ -240,6 +240,10 @@ protected:
boost::shared_ptr<timeline::Track> draggingTrack;
Gdk::Point dragStartOffset;
Gdk::Point dragPoint;
/**
* The connection to the animation timer.
* @see begin_animation()

View file

@ -44,6 +44,7 @@ Track::Track(TimelineWidget &timeline_widget,
model_track(track),
expanded(true),
expandDirection(None),
headerWidget(*this),
enableButton(Gtk::StockID("track_enabled")),
lockButton(Gtk::StockID("track_unlocked"))
{
@ -65,9 +66,11 @@ Track::Track(TimelineWidget &timeline_widget,
gtk_toolbar_set_icon_size (buttonBar.gobj(),
(GtkIconSize)(int)WindowManager::MenuIconSize);
#endif
headerWidget.set_child_widget(headerBox);
headerWidget.pack_start(titleMenuButton, PACK_SHRINK);
headerWidget.pack_start(buttonBar, PACK_SHRINK);
headerBox.pack_start(titleMenuButton, PACK_SHRINK);
headerBox.pack_start(buttonBar, PACK_SHRINK);
// Setup the title menu button
Menu::MenuList& title_list = titleMenuButton.get_menu().items();

View file

@ -27,6 +27,7 @@
#include "../../model/track.hpp"
#include "../menu-button.hpp"
#include "timeline-header-container.hpp"
#include "timeline-header-widget.hpp"
#ifndef TIMELINE_TRACK_HPP
#define TIMELINE_TRACK_HPP
@ -176,7 +177,9 @@ private:
//----- Header Widgets ------//
Gtk::VBox headerWidget;
timeline::TimelineHeaderWidget headerWidget;
Gtk::VBox headerBox;
MenuButton titleMenuButton;
@ -187,6 +190,8 @@ private:
Gtk::Toolbar buttonBar;
Gtk::Menu contextMenu;
friend class TimelineHeaderWidget;
};