|
|
fdabb2 |
#include "view.h"
|
|
|
fdabb2 |
|
|
|
fdabb2 |
#include <gtkmm container.h=""></gtkmm>
|
|
|
fdabb2 |
|
|
|
fdabb2 |
|
|
|
fdabb2 |
void
|
|
|
fdabb2 |
View::Point::draw(
|
|
|
fdabb2 |
const Cairo::RefPtr<cairo::context>& context,</cairo::context>
|
|
|
fdabb2 |
View &view )
|
|
|
fdabb2 |
{
|
|
|
fdabb2 |
const Real scale = 1.0/sqrt(fabs(view.transform.m00*view.transform.m11));
|
|
|
fdabb2 |
context->save();
|
|
|
fdabb2 |
context->arc(position.x, position.y, radius*scale, 0.0, 2.0*M_PI);
|
|
|
fdabb2 |
context->set_source_rgba(color.r, color.g, color.b, color.a);
|
|
|
fdabb2 |
context->fill_preserve();
|
|
|
fdabb2 |
context->set_source_rgba(0.0, 0.0, 0.0, color.a);
|
|
|
fdabb2 |
context->set_line_width(selected ? 2.0*scale : scale);
|
|
|
fdabb2 |
context->stroke();
|
|
|
fdabb2 |
context->restore();
|
|
|
fdabb2 |
}
|
|
|
fdabb2 |
|
|
|
fdabb2 |
|
|
|
fdabb2 |
void
|
|
|
fdabb2 |
View::Layer::draw(const Cairo::RefPtr<cairo::context>&, View&)</cairo::context>
|
|
|
fdabb2 |
{ }
|
|
|
fdabb2 |
|
|
|
fdabb2 |
|
|
|
fdabb2 |
View::View():
|
|
|
fdabb2 |
dragging()
|
|
|
fdabb2 |
{
|
|
|
fdabb2 |
set_events(
|
|
|
fdabb2 |
Gdk::POINTER_MOTION_MASK
|
|
|
fdabb2 |
| Gdk::BUTTON_PRESS_MASK
|
|
|
fdabb2 |
| Gdk::BUTTON_RELEASE_MASK );
|
|
|
fdabb2 |
}
|
|
|
fdabb2 |
|
|
|
fdabb2 |
View::~View() { }
|
|
|
fdabb2 |
|
|
|
fdabb2 |
bool
|
|
|
fdabb2 |
View::on_draw(const Cairo::RefPtr<cairo::context>& context) {</cairo::context>
|
|
|
fdabb2 |
context->save();
|
|
|
fdabb2 |
|
|
|
fdabb2 |
const Real border_size = 1.0;
|
|
|
fdabb2 |
const Real border_margin = 2.0;
|
|
|
fdabb2 |
|
|
|
fdabb2 |
context->save();
|
|
|
fdabb2 |
context->rectangle(0, 0, get_width(), get_height());
|
|
|
fdabb2 |
context->set_source_rgba(0, 0, 0, 1);
|
|
|
fdabb2 |
context->fill();
|
|
|
fdabb2 |
context->rectangle(
|
|
|
fdabb2 |
border_margin, border_margin,
|
|
|
fdabb2 |
get_width() - 2*border_margin,
|
|
|
fdabb2 |
get_height() - 2*border_margin );
|
|
|
fdabb2 |
context->set_line_width(border_size);
|
|
|
fdabb2 |
context->set_source_rgba(1, 1, 0, 1);
|
|
|
fdabb2 |
context->stroke();
|
|
|
fdabb2 |
context->restore();
|
|
|
fdabb2 |
|
|
|
fdabb2 |
context->translate(0.5*get_width(), 0.5*get_height());
|
|
|
fdabb2 |
context->transform(Cairo::Matrix(transform.m00, transform.m10, transform.m01, transform.m11, transform.m30, transform.m31));
|
|
|
fdabb2 |
for(LayerList::const_iterator i = layers.begin(); i != layers.end(); ++i)
|
|
|
fdabb2 |
(*i)->draw(context, *this);
|
|
|
fdabb2 |
for(PointList::const_iterator i = foreign_points.begin(); i != foreign_points.end(); ++i)
|
|
|
fdabb2 |
(*i)->draw(context, *this);
|
|
|
fdabb2 |
for(PointList::const_iterator i = own_points.begin(); i != own_points.end(); ++i)
|
|
|
fdabb2 |
(*i)->draw(context, *this);
|
|
|
fdabb2 |
context->restore();
|
|
|
fdabb2 |
return true;
|
|
|
fdabb2 |
}
|
|
|
fdabb2 |
|
|
|
fdabb2 |
bool
|
|
|
fdabb2 |
View::on_motion_notify_event(GdkEventMotion *event) {
|
|
|
fdabb2 |
Vector2 position = Vector2(event->x - 0.5*get_width(), event->y - 0.5*get_height());
|
|
|
fdabb2 |
if (dragging) {
|
|
|
fdabb2 |
if (selected_point) {
|
|
|
fdabb2 |
selected_point->position = Vector2(transform.invert()*Vector4(position + selected_point_offset));
|
|
|
fdabb2 |
selected_point->motion();
|
|
|
fdabb2 |
queue_draw();
|
|
|
fdabb2 |
}
|
|
|
fdabb2 |
} else {
|
|
|
fdabb2 |
PointPtr point;
|
|
|
fdabb2 |
for(PointList::iterator i = own_points.begin(); i != own_points.end(); ++i) {
|
|
|
fdabb2 |
(*i)->selected = false;
|
|
|
fdabb2 |
Vector2 point_position = Vector2(transform * Vector4((*i)->position));
|
|
|
fdabb2 |
Vector2 offset = point_position - position;
|
|
|
fdabb2 |
if (offset.square() <= (*i)->radius * (*i)->radius)
|
|
|
fdabb2 |
point = *i;
|
|
|
fdabb2 |
}
|
|
|
fdabb2 |
if (point)
|
|
|
fdabb2 |
point->selected = true;
|
|
|
fdabb2 |
if (selected_point != point) {
|
|
|
fdabb2 |
selected_point = point;
|
|
|
fdabb2 |
queue_draw();
|
|
|
fdabb2 |
}
|
|
|
fdabb2 |
}
|
|
|
fdabb2 |
return true;
|
|
|
fdabb2 |
}
|
|
|
fdabb2 |
|
|
|
fdabb2 |
bool
|
|
|
fdabb2 |
View::on_button_press_event(GdkEventButton *event) {
|
|
|
fdabb2 |
if (event->button == 1)
|
|
|
fdabb2 |
dragging = true;
|
|
|
fdabb2 |
return true;
|
|
|
fdabb2 |
}
|
|
|
fdabb2 |
|
|
|
fdabb2 |
bool
|
|
|
fdabb2 |
View::on_button_release_event(GdkEventButton *event) {
|
|
|
fdabb2 |
if (event->button == 1) {
|
|
|
fdabb2 |
dragging = false;
|
|
|
fdabb2 |
if (selected_point) selected_point->changed();
|
|
|
fdabb2 |
}
|
|
|
fdabb2 |
return true;
|
|
|
fdabb2 |
}
|