diff options
Diffstat (limited to 'src/desktop.h')
| -rw-r--r-- | src/desktop.h | 134 |
1 files changed, 103 insertions, 31 deletions
diff --git a/src/desktop.h b/src/desktop.h index 3652d4a97..3dc11b557 100644 --- a/src/desktop.h +++ b/src/desktop.h @@ -29,6 +29,7 @@ #include <sigc++/sigc++.h> #include <2geom/affine.h> +#include <2geom/transforms.h> #include <2geom/rect.h> #include "ui/view/view.h" @@ -179,11 +180,6 @@ public: SPCSSAttr *current; ///< current style bool _focusMode; ///< Whether we're focused working or general working - std::list<Geom::Rect> zooms_past; - std::list<Geom::Rect> zooms_future; - - bool _quick_zoom_enabled; ///< Signifies that currently we're in quick zoom mode - Geom::Rect _quick_zoom_stored_area; ///< The area of the screen before quick zoom unsigned int dkey; unsigned int number; guint window_state; @@ -323,38 +319,42 @@ public: SPItem *getGroupAtPoint(Geom::Point const &p) const; Geom::Point point() const; + void prev_transform(); + void next_transform(); + void clear_transform_history(); + + void set_display_area (bool log = true); + void set_display_area (Geom::Point const &c, Geom::Point const &w, bool log = true); + void set_display_area (Geom::Rect const &a, Geom::Coord border, bool log = true); Geom::Rect get_display_area() const; - void set_display_area (double x0, double y0, double x1, double y1, double border, bool log = true); - void set_display_area(Geom::Rect const &a, Geom::Coord border, bool log = true); - void zoom_absolute (double cx, double cy, double zoom); - void zoom_relative (double cx, double cy, double zoom); - void zoom_absolute_keep_point (double cx, double cy, double px, double py, double zoom); - void zoom_relative_keep_point (double cx, double cy, double zoom); - void zoom_relative_keep_point (Geom::Point const &c, double const zoom) - { - zoom_relative_keep_point (c[Geom::X], c[Geom::Y], zoom); - } + + void zoom_absolute_keep_point (Geom::Point const &c, double const zoom); + void zoom_relative_keep_point (Geom::Point const &c, double const zoom); + void zoom_absolute_center_point (Geom::Point const &c, double const zoom); + void zoom_relative_center_point (Geom::Point const &c, double const zoom); void zoom_page(); void zoom_page_width(); void zoom_drawing(); void zoom_selection(); - void zoom_grab_focus(); - double current_zoom() const { return _d2w.descrim(); } - void prev_zoom(); - void next_zoom(); - void zoom_quick(bool enable = true); + double current_zoom() const { return _current_affine.getZoom(); } + + void zoom_quick(bool enable = true); /** \brief Returns whether the desktop is in quick zoom mode or not */ bool quick_zoomed(void) { return _quick_zoom_enabled; } + void zoom_grab_focus(); + + void rotate_absolute_keep_point (Geom::Point const &c, double const rotate); + void rotate_relative_keep_point (Geom::Point const &c, double const rotate); + void rotate_absolute_center_point (Geom::Point const &c, double const rotate); + void rotate_relative_center_point (Geom::Point const &c, double const rotate); + + void scroll_absolute (Geom::Point const &point, bool is_scrolling = false); + void scroll_relative (Geom::Point const &delta, bool is_scrolling = false); + void scroll_relative_in_svg_coords (double dx, double dy, bool is_scrolling = false); bool scroll_to_point (Geom::Point const &s_dt, gdouble autoscrollspeed = 0); - void scroll_world (double dx, double dy, bool is_scrolling = false); - void scroll_world (Geom::Point const &scroll, bool is_scrolling = false) - { - scroll_world(scroll[Geom::X], scroll[Geom::Y], is_scrolling); - } - void scroll_world_in_svg_coords (double dx, double dy, bool is_scrolling = false); void getWindowGeometry (gint &x, gint &y, gint &w, gint &h); void setWindowPosition (Geom::Point p); @@ -407,7 +407,7 @@ public: */ void show_dialogs(); - Geom::Affine w2d() const; //transformation from window to desktop coordinates (used for zooming) + Geom::Affine w2d() const; //transformation from window to desktop coordinates (zoom/rotate). Geom::Point w2d(Geom::Point const &p) const; Geom::Point d2w(Geom::Point const &p) const; Geom::Affine doc2dt() const; @@ -430,8 +430,82 @@ private: Inkscape::UI::View::EditWidgetInterface *_widget; Inkscape::MessageContext *_guides_message_context; bool _active; - Geom::Affine _w2d; - Geom::Affine _d2w; + + // This simple class ensures that _w2d is always in sync with _rotation and _scale + // We keep rotation and scale separate to avoid having to extract them from the affine. + // With offset, this describes fully how to map the drawing to the window. + // Future: merge offset as a translation in w2d. + class DesktopAffine { + public: + Geom::Affine w2d() const { return _w2d; }; + Geom::Affine d2w() const { return _d2w; }; + + void setScale( Geom::Scale scale ) { + _scale = scale; + _update(); + } + void setScale( double scale ) { + _scale = Geom::Scale(scale, -scale); // Y flip + _update(); + } + void addScale( Geom::Scale scale) { + _scale *= scale; + _update(); + } + void addScale( double scale ) { + _scale *= Geom::Scale(scale, -scale); // Y flip?? Check + _update(); + } + + void setRotate( Geom::Rotate rotate ) { + _rotate = rotate; + _update(); + } + void setRotate( double rotate ) { + _rotate = Geom::Rotate( rotate ); + _update(); + } + void addRotate( Geom::Rotate rotate ) { + _rotate *= rotate; + _update(); + } + void addRotate( double rotate ) { + _rotate *= Geom::Rotate( rotate ); + _update(); + } + + double getZoom() const { + return _d2w.descrim(); + } + + void setOffset( Geom::Point offset ) { + _offset = offset; + } + void addOffset( Geom::Point offset ) { + _offset += offset; + } + Geom::Point getOffset() { + return _offset; + } + + private: + void _update() { + _d2w = _rotate * _scale; + _w2d = _d2w.inverse(); + } + Geom::Affine _w2d; // Window to desktop + Geom::Affine _d2w; // Desktop to window + Geom::Rotate _rotate; // Rotate part of _w2d + Geom::Scale _scale; // Scale part of _w2d + Geom::Point _offset; // Point on canvas to align to (0,0) of window + }; + + DesktopAffine _current_affine; + std::list<DesktopAffine> transforms_past; + std::list<DesktopAffine> transforms_future; + bool _quick_zoom_enabled; ///< Signifies that currently we're in quick zoom mode + DesktopAffine _quick_zoom_affine; ///< The transform of the screen before quick zoom + Geom::Affine _doc2dt; /* @@ -457,8 +531,6 @@ private: bool grids_visible; /* don't set this variable directly, use the method below */ void set_grids_visible(bool visible); - void push_current_zoom(std::list<Geom::Rect> &); - sigc::signal<void, SPDesktop*> _destroy_signal; sigc::signal<void,SPDesktop*,SPDocument*> _document_replaced_signal; sigc::signal<void> _activate_signal; |
