26 #ifndef MPBLOCKS_GTK_PAN_ZOOM_VIEW_H_
27 #define MPBLOCKS_GTK_PAN_ZOOM_VIEW_H_
29 #include <Eigen/Dense>
42 Glib::RefPtr<Gtk::Adjustment>
scale_;
62 sigc::signal<void, const Cairo::RefPtr<Cairo::Context>&>
sig_draw;
71 add_events(Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_MOTION_MASK |
72 Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK |
74 offset_x_ = Gtk::Adjustment::create(0, -1e9, 1e9);
75 offset_y_ = Gtk::Adjustment::create(0, -1e9, 1e9);
76 scale_ = Gtk::Adjustment::create(1, 1e-9, 1e9);
84 Glib::RefPtr<Gtk::Adjustment> offset_y) {
87 offset_x_->signal_value_changed().connect(
88 sigc::mem_fun(
this, &Gtk::DrawingArea::queue_draw));
89 offset_y_->signal_value_changed().connect(
90 sigc::mem_fun(
this, &Gtk::DrawingArea::queue_draw));
94 Glib::RefPtr<Gtk::Adjustment> scale_rate) {
97 scale_->signal_value_changed().connect(
98 sigc::mem_fun(
this, &Gtk::DrawingArea::queue_draw));
136 return std::max(get_allocated_width(), get_allocated_height());
152 template <
typename Event>
155 event->x = transformed_point[0];
156 event->y = transformed_point[1];
168 Gtk::DrawingArea::on_motion_notify_event(event);
169 GdkEventMotion transformed = *event;
178 if (
active_ && (event->button == 3)) {
181 Gtk::DrawingArea::on_button_press_event(event);
182 GdkEventButton transformed = *event;
196 if (event->direction == GDK_SCROLL_UP) {
200 }
else if (event->direction == GDK_SCROLL_DOWN) {
205 Gtk::DrawingArea::on_scroll_event(event);
216 virtual bool on_draw(
const Cairo::RefPtr<Cairo::Context>& ctx) {
218 ctx->rectangle(0, 0, get_allocated_width(), get_allocated_height());
219 ctx->set_source_rgb(1, 1, 1);
220 ctx->fill_preserve();
221 ctx->set_source_rgb(0, 0, 0);
232 ctx->set_line_width(0.001);
244 #endif // MPBLOCKS_GTK_PAN_ZOOM_VIEW_H_
void SetScaleAdjustments(Glib::RefPtr< Gtk::Adjustment > scale, Glib::RefPtr< Gtk::Adjustment > scale_rate)
void SetScale(double scale)
sigc::signal< void, const Cairo::RefPtr< Cairo::Context > & > sig_draw
Signal is emitted by the on_draw handler, and sends out the context with appropriate scaling and...
void SetOffsetAdjustments(Glib::RefPtr< Gtk::Adjustment > offset_x, Glib::RefPtr< Gtk::Adjustment > offset_y)
Glib::RefPtr< Gtk::Adjustment > scale_
Size (in virtual units) of the largest dimension of the widget.
void SetOffset(const Eigen::Vector2d &offset)
sigc::signal< void, GdkEventButton * > sig_button
button event with transformed coordinates
bool active_
If true, controls are enabled, if false, controls are disabled and events are passed through...
Eigen::Vector2d last_pos_
The last mouse position (used during pan)
virtual bool on_scroll_event(GdkEventScroll *event)
virtual bool on_draw(const Cairo::RefPtr< Cairo::Context > &ctx)
A drawing area with built in mouse handlers for pan-zoom control.
double GetMaxDim()
return the maximum dimension of the
Eigen::Vector2d TransformPoint(double x, double y)
Return a point in the virtual cartesian plane by applying the offset and scaling of the viewport...
void SetScaleRate(double scale_rate)
Eigen::Vector2d GetOffset()
sigc::signal< void, GdkEventMotion * > sig_motion
motion event with transformed coordinates
Matrix< double, 2, 1 > Vector2d
int pan_button_
Which mouse button is used for pan.
virtual bool on_motion_notify_event(GdkEventMotion *event)
virtual bool on_button_press_event(GdkEventButton *event)
Eigen::Vector2d RawPoint(double x, double y)
Convert the point (x,y) in GTK coordinates, with the origin at the top left, to a point in traditiona...
void TransformEvent(Event *event)
Glib::RefPtr< Gtk::Adjustment > offset_x_
offset of viewport
Glib::RefPtr< Gtk::Adjustment > scale_rate_
When the mouse wheel is turned multiply or divide the scale by this much.
Glib::RefPtr< Gtk::Adjustment > offset_y_
offset of viewport