|
|
2fb9fd |
|
|
|
2fb9fd |
|
|
|
2fb9fd |
#include "activearea.h"
|
|
|
2fb9fd |
|
|
|
2fb9fd |
|
|
|
2fb9fd |
ActiveArea::ActiveArea() {
|
|
|
2fb9fd |
add_events( Gdk::BUTTON_PRESS_MASK
|
|
|
2fb9fd |
| Gdk::BUTTON_RELEASE_MASK
|
|
|
2fb9fd |
| Gdk::POINTER_MOTION_MASK );
|
|
|
2fb9fd |
}
|
|
|
2fb9fd |
|
|
|
2fb9fd |
bool ActiveArea::is_point_added(const ActivePoint::Handle &point) const {
|
|
|
2fb9fd |
for(PointList::const_iterator i = points.begin(); i != points.end(); ++i)
|
|
|
2fb9fd |
if (*i == point) return true;
|
|
|
2fb9fd |
return false;
|
|
|
2fb9fd |
}
|
|
|
2fb9fd |
|
|
|
2fb9fd |
void ActiveArea::add_point(const ActivePoint::Handle &point) {
|
|
|
2fb9fd |
if (point && !is_point_added(point)) {
|
|
|
2fb9fd |
points.push_back(point);
|
|
|
2fb9fd |
queue_draw();
|
|
|
2fb9fd |
}
|
|
|
2fb9fd |
}
|
|
|
2fb9fd |
|
|
|
2fb9fd |
void ActiveArea::remove_point(const ActivePoint::Handle &point) {
|
|
|
2fb9fd |
ActivePoint::Handle p = point;
|
|
|
2fb9fd |
for(PointList::iterator i = points.begin(); i != points.end();)
|
|
|
2fb9fd |
if (*i == p) { i = points.erase(i); queue_draw(); } else ++i;
|
|
|
2fb9fd |
if (drag_point == p)
|
|
|
2fb9fd |
hover_point.reset();
|
|
|
2fb9fd |
if (hover_point == p)
|
|
|
2fb9fd |
{ hover_point->active = false; hover_point.reset(); }
|
|
|
2fb9fd |
}
|
|
|
2fb9fd |
|
|
|
2fb9fd |
void ActiveArea::bring_to_front(const ActivePoint::Handle &point) {
|
|
|
2fb9fd |
ActivePoint::Handle p = point;
|
|
|
2fb9fd |
for(PointList::iterator i = points.begin(); i != points.end(); ++i)
|
|
|
2fb9fd |
if (*i == p)
|
|
|
2fb9fd |
{ i = points.erase(i); points.push_back(p); break; }
|
|
|
2fb9fd |
}
|
|
|
2fb9fd |
|
|
|
2fb9fd |
ActivePoint::Handle ActiveArea::get_point_at(const Vector &position) const {
|
|
|
2fb9fd |
for(PointList::const_reverse_iterator ri = points.rbegin(); ri != points.rend(); ++ri)
|
|
|
2fb9fd |
if ((*ri)->enabled && (*ri)->visible && (*ri)->is_inside(position))
|
|
|
2fb9fd |
return *ri;
|
|
|
2fb9fd |
return nohandle;
|
|
|
2fb9fd |
}
|
|
|
2fb9fd |
|
|
|
2fb9fd |
bool ActiveArea::on_button_press_event(GdkEventButton* event) {
|
|
|
2fb9fd |
if (event->button == 1) {
|
|
|
2fb9fd |
Vector position(event->x, event->y);
|
|
|
2fb9fd |
ActivePoint::Handle old_point = drag_point;
|
|
|
2fb9fd |
drag_point = get_point_at(position);
|
|
|
2fb9fd |
if (drag_point) {
|
|
|
2fb9fd |
if (hover_point) hover_point->active = false;
|
|
|
2fb9fd |
hover_point = drag_point;
|
|
|
2fb9fd |
hover_point->active = true;
|
|
|
2fb9fd |
bring_to_front(drag_point);
|
|
|
2fb9fd |
drag_offset = drag_point->position - position;
|
|
|
2fb9fd |
}
|
|
|
2fb9fd |
if (old_point != drag_point) queue_draw();
|
|
|
2fb9fd |
return true;
|
|
|
2fb9fd |
}
|
|
|
2fb9fd |
return false;
|
|
|
2fb9fd |
}
|
|
|
2fb9fd |
|
|
|
2fb9fd |
bool ActiveArea::on_button_release_event(GdkEventButton* event) {
|
|
|
2fb9fd |
if (event->button == 1) {
|
|
|
2fb9fd |
if (drag_point) {
|
|
|
2fb9fd |
drag_point.reset();
|
|
|
2fb9fd |
if (hover_point) hover_point->active = false;
|
|
|
2fb9fd |
hover_point = get_point_at(Vector(event->x, event->y));
|
|
|
2fb9fd |
if (hover_point) hover_point->active = true;
|
|
|
2fb9fd |
queue_draw();
|
|
|
2fb9fd |
}
|
|
|
2fb9fd |
return true;
|
|
|
2fb9fd |
}
|
|
|
2fb9fd |
return false;
|
|
|
2fb9fd |
}
|
|
|
2fb9fd |
|
|
|
2fb9fd |
bool ActiveArea::on_motion_notify_event(GdkEventMotion* event) {
|
|
|
2fb9fd |
Vector position(event->x, event->y);
|
|
|
2fb9fd |
if (drag_point) {
|
|
|
2fb9fd |
Vector oldposition = drag_point->position;
|
|
|
2fb9fd |
Vector newposition = position + drag_offset;
|
|
|
2fb9fd |
if (newposition != oldposition) {
|
|
|
2fb9fd |
drag_point->position = newposition;
|
|
|
6b4ca4 |
on_point_move(drag_point, oldposition, newposition);
|
|
|
2fb9fd |
queue_draw();
|
|
|
2fb9fd |
}
|
|
|
2fb9fd |
} else {
|
|
|
2fb9fd |
ActivePoint::Handle old_point = hover_point;
|
|
|
2fb9fd |
if (hover_point) hover_point->active = false;
|
|
|
2fb9fd |
hover_point = get_point_at(position);
|
|
|
2fb9fd |
if (hover_point) hover_point->active = true;
|
|
|
2fb9fd |
if (old_point != hover_point) queue_draw();
|
|
|
2fb9fd |
}
|
|
|
2fb9fd |
return true;
|
|
|
2fb9fd |
}
|
|
|
2fb9fd |
|
|
|
2fb9fd |
bool ActiveArea::on_draw(const Cairo::RefPtr<cairo::context> &context) {</cairo::context>
|
|
|
2fb9fd |
on_draw(Context(context));
|
|
|
2fb9fd |
return true;
|
|
|
2fb9fd |
}
|
|
|
2fb9fd |
|
|
|
2fb9fd |
void ActiveArea::on_draw(const Context &context) {
|
|
|
2fb9fd |
// fill background
|
|
|
2fb9fd |
context->save();
|
|
|
2fb9fd |
context->rectangle(0, 0, get_width(), get_height());
|
|
|
2fb9fd |
context->set_source_rgba(1, 1, 1, 1);
|
|
|
2fb9fd |
context->fill();
|
|
|
2fb9fd |
context->restore();
|
|
|
2fb9fd |
|
|
|
2fb9fd |
on_draw_content(context);
|
|
|
2fb9fd |
|
|
|
2fb9fd |
// draw points
|
|
|
2fb9fd |
for(PointList::const_iterator i = points.begin(); i != points.end(); ++i)
|
|
|
2fb9fd |
context.point(**i);
|
|
|
2fb9fd |
}
|
|
|
2fb9fd |
|
|
|
6b4ca4 |
void ActiveArea::on_point_move(const ActivePoint::Handle &/*point*/, const Vector &/*oldposition*/, const Vector &/*newposition*/)
|
|
|
2fb9fd |
{ }
|
|
|
2fb9fd |
|
|
|
2fb9fd |
void ActiveArea::on_draw_content(const Context &/*context*/)
|
|
|
2fb9fd |
{ }
|