diff --git a/src/gui/Makefile.am b/src/gui/Makefile.am index 70e8264fb..b6dab4049 100644 --- a/src/gui/Makefile.am +++ b/src/gui/Makefile.am @@ -164,8 +164,10 @@ libgui_la_SOURCES = \ $(lumigui_srcdir)/output/displayer.hpp \ $(lumigui_srcdir)/output/gdkdisplayer.cpp \ $(lumigui_srcdir)/output/gdkdisplayer.hpp \ - $(lumigui_srcdir)/output/xvdisplayer.cpp \ - $(lumigui_srcdir)/output/xvdisplayer.hpp + $(lumigui_srcdir)/output/xvdisplayer.cpp \ + $(lumigui_srcdir)/output/xvdisplayer.hpp \ + $(lumigui_srcdir)/util/rectangle.cpp \ + $(lumigui_srcdir)/util/rectangle.hpp libgui_la_LIBADD = \ liblumieracommon.la \ diff --git a/src/gui/util/rectangle.cpp b/src/gui/util/rectangle.cpp new file mode 100644 index 000000000..6e2b2c8f1 --- /dev/null +++ b/src/gui/util/rectangle.cpp @@ -0,0 +1,40 @@ +/* + timeline-layout-helper.cpp - Implements utility functions for + GDK rects + + Copyright (C) Lumiera.org + 2008, Joel Holdsworth + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +* *****************************************************/ + +#include "rectangle.hpp" + +namespace gui { +namespace util { + +bool +pt_in_rect(const Gdk::Point &point, const Gdk::Rectangle &rect) +{ + return (point.get_x() >= rect.get_x() && + point.get_x() < rect.get_x() + rect.get_width() && + point.get_y() >= rect.get_y() && + point.get_y() < rect.get_y() + rect.get_height()); +} + +} // namespace util +} // namespace gui + diff --git a/src/gui/util/rectangle.hpp b/src/gui/util/rectangle.hpp new file mode 100644 index 000000000..74feedbb5 --- /dev/null +++ b/src/gui/util/rectangle.hpp @@ -0,0 +1,48 @@ +/* + timeline-layout-helper.hpp - Declares utility functions for + GDK rects + + Copyright (C) Lumiera.org + 2008, Joel Holdsworth + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +* *****************************************************/ +/** @file timeline-layout-helper.hpp + ** This file contains the declaration of the utility functions for + ** GDK rects + */ + +#ifndef RECTANGLE_HPP +#define RECTANGLE_HPP + +#include "../gtk-lumiera.hpp" + +namespace gui { +namespace util { + +/** + * Tests whether point is within the bounding box of a rectangle. + * @param point The point to test. + * @param rect The rect to test. + * @return Returns true if the point is within the rectangle, false if + * not. + **/ +bool pt_in_rect(const Gdk::Point &point, const Gdk::Rectangle &rect); + +} // util +} // gui + +#endif // RECTANGLE_HPP diff --git a/src/gui/widgets/timeline/timeline-header-container.cpp b/src/gui/widgets/timeline/timeline-header-container.cpp index 78a479412..4d311721d 100644 --- a/src/gui/widgets/timeline/timeline-header-container.cpp +++ b/src/gui/widgets/timeline/timeline-header-container.cpp @@ -26,6 +26,7 @@ #include "timeline-header-container.hpp" #include "timeline-track.hpp" #include "../timeline-widget.hpp" +#include "../../util/rectangle.hpp" using namespace Gtk; using namespace std; @@ -247,10 +248,7 @@ bool TimelineHeaderContainer::on_motion_notify_event ( REQUIRE(rect); // Are we hovering on the expander? - if(event->x >= rect->get_x() && - event->x < rect->get_x() + rect->get_width() && - event->y >= rect->get_y() && - event->y < rect->get_y() + rect->get_height()) + if(util::pt_in_rect(point, *rect)) { hoveringExpander = hoveringTrack; queue_draw(); diff --git a/src/gui/widgets/timeline/timeline-layout-helper.cpp b/src/gui/widgets/timeline/timeline-layout-helper.cpp index e82f8f422..0ca058bc1 100644 --- a/src/gui/widgets/timeline/timeline-layout-helper.cpp +++ b/src/gui/widgets/timeline/timeline-layout-helper.cpp @@ -26,6 +26,7 @@ #include "timeline-layout-helper.hpp" #include "../timeline-widget.hpp" #include "../../model/sequence.hpp" +#include "../../util/rectangle.hpp" using namespace Gtk; using namespace std; @@ -98,13 +99,8 @@ TimelineLayoutHelper::header_from_point(Gdk::Point point) std::pair, Gdk::Rectangle> pair; BOOST_FOREACH( pair, headerBoxes ) { - // Hit test the rectangle - const Gdk::Rectangle &rect = pair.second; - - if(point.get_x() >= rect.get_x() && - point.get_x() < rect.get_x() + rect.get_width() && - point.get_y() >= rect.get_y() && - point.get_y() < rect.get_y() + rect.get_height()) + // Hit test the rectangle + if(util::pt_in_rect(point, pair.second)) return shared_ptr(pair.first); } @@ -181,12 +177,8 @@ TimelineLayoutHelper::drag_to_point(Gdk::Point point) // Hit test the rectangle const weak_ptr track = lookup_timeline_track(*iterator); - const Gdk::Rectangle &rect = headerBoxes[track]; - if(point.get_x() >= rect.get_x() && - point.get_x() < rect.get_x() + rect.get_width() && - point.get_y() >= rect.get_y() && - point.get_y() < rect.get_y() + rect.get_height()) + if(util::pt_in_rect(point, headerBoxes[track])) { // Relocate the header draggingTrackIter = layoutTree.move_after(