Added pt_in_rect function

This commit is contained in:
Joel Holdsworth 2009-01-10 21:43:24 +00:00
parent 542af7cc80
commit d2d27abe4a
5 changed files with 98 additions and 18 deletions

View file

@ -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 \

View file

@ -0,0 +1,40 @@
/*
timeline-layout-helper.cpp - Implements utility functions for
GDK rects
Copyright (C) Lumiera.org
2008, Joel Holdsworth <joel@airwebreathe.org.uk>
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

View file

@ -0,0 +1,48 @@
/*
timeline-layout-helper.hpp - Declares utility functions for
GDK rects
Copyright (C) Lumiera.org
2008, Joel Holdsworth <joel@airwebreathe.org.uk>
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

View file

@ -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();

View file

@ -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<weak_ptr<timeline::Track>, 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<timeline::Track>(pair.first);
}
@ -181,12 +177,8 @@ TimelineLayoutHelper::drag_to_point(Gdk::Point point)
// Hit test the rectangle
const weak_ptr<timeline::Track> 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(