src/view.cpp in reflexion-0.1.21 vs src/view.cpp in reflexion-0.1.22

- old
+ new

@@ -1277,27 +1277,45 @@ to->positions[i] = pos - offset; ++to->size; } } + static void + scroll_and_zoom_positions (PointerEvent* e, const Point* scroll, float zoom) + { + static const Point ZERO = 0; + + assert(zoom != 0); + + if (!scroll) scroll = &ZERO; + if (*scroll == 0 && zoom == 1) + return; + + for (size_t i = 0; i < e->size; ++i) + { + e->position(i) -= *scroll; + e->position(i) /= zoom; + } + } + void View_call_pointer_event (View* view, const PointerEvent& event) { if (!view) argument_error(__FILE__, __LINE__); bool capturing = view->capture() & View::CAPTURE_POINTER; if (capturing != event.capture) return; - const Bounds& frame = view->frame(); - PointerEvent e = event; - filter_pointer_event(&e, event, frame); + filter_pointer_event(&e, event, view->frame()); if (!capturing && e.size == 0) return; + scroll_and_zoom_positions(&e, view->self->pscroll.get(), view->zoom()); + view->on_pointer(&e); switch (e.type) { case PointerEvent::DOWN: view->on_pointer_down(&e); break; @@ -1987,22 +2005,27 @@ static const Point ZERO_SCROLL; void View::scroll_to (coord x, coord y, coord z) { - Point old = self->scroll(); - self->scroll().reset(x, y, z); - ScrollEvent e(x, y, z, x - old.x, y - old.y, z - old.z); - on_scroll(&e); - - redraw(); + scroll_to(Point(x, y, z)); } void View::scroll_to (const Point& scroll) { - scroll_to(scroll.x, scroll.y, scroll.z); + if (scroll == this->scroll()) return; + + Point old = self->scroll(); + self->scroll() = scroll; + + ScrollEvent e( + scroll.x, scroll.y, scroll.z, + scroll.x - old.x, scroll.y - old.y, scroll.z - old.z); + on_scroll(&e); + + redraw(); } void View::scroll_by (coord x, coord y, coord z) { @@ -2026,9 +2049,14 @@ } void View::set_zoom (float zoom) { + if (zoom == self->zoom) return; + + if (zoom == 0) + argument_error(__FILE__, __LINE__); + self->zoom = zoom; redraw(); } float