27#include <glibmm/i18n.h>
28#include <gtkmm/gesturezoom.h>
29#include <sigc++/adaptors/bind.h>
81 : namedview(namedview_)
86 _selection = std::make_unique<Inkscape::Selection>(
this);
96 }, Glib::PRIORITY_HIGH);
101 current = prefs->getStyle(
"/desktop/style");
106 canvas = std::make_unique<Inkscape::UI::Widget::Canvas>();
107 canvas->set_desktop(
this);
113 _snapindicator = std::make_unique<Inkscape::Display::SnapIndicator>(
this);
118 auto const zoom = Gtk::GestureZoom::create();
119 zoom->set_propagation_phase(Gtk::PropagationPhase::CAPTURE);
123 canvas->add_controller(zoom);
144 auto const canvas_item_root =
canvas->get_canvas_item_root();
194 canvas->set_drawing(
nullptr);
195 canvas->set_desktop(
nullptr);
231 if (move_to_bottom) {
232 item->lower_to_bottom();
260 return viewport.intersects(*bbox);
283 g_return_if_fail(theDocument);
312 _tool->switching_away(toolName);
316 if (!toolName.empty()) {
319 if (!
_tool->is_ready()) {
345 g_return_val_if_fail (
doc() !=
nullptr, NULL);
354 g_return_val_if_fail (
doc() !=
nullptr, NULL);
370 g_return_val_if_fail (
doc() !=
nullptr, NULL);
380 auto ret =
canvas->get_last_mouse();
393 std::cerr <<
"SPDesktop::prev_transform: current transform missing!" << std::endl;
463 boxtool->_vpdrag->updateLines();
506 zoom =
w.width() / r.
width();
508 zoom =
w.height() / r.
height();
573 double correction = prefs->
getDouble(
"/options/zoomcorrection/value", 1.0);
582 if (rect.
width() < 1.0)
604 g_return_if_fail (
doc() !=
nullptr);
606 g_return_if_fail (docitem !=
nullptr);
614 if ( !d || d->minExtent() < 0.1 ) {
629 if ( !d || d->minExtent() < 0.1 ) {
683 if (!nt->_selected_nodes->empty()) {
684 Geom::Rect nodes = *nt->_selected_nodes->bounds();
685 double area = nodes.
area();
744 auto const w =
d2w(
c);
757 auto const w =
d2w(
c);
771 auto const viewbox =
canvas->get_area_world();
784 auto const viewbox =
canvas->get_area_world();
861 boxtool->_vpdrag->updateLines();
899 double const autoscrolldistance = prefs->getIntLimited(
"/options/autoscrolldistance/value", 0, -1000, 10000);
902 w.expandBy(-autoscrolldistance);
904 auto const c =
d2w(p);
905 if (!
w.contains(
c)) {
906 auto const c2 =
w.clamp(
c);
1098 Gdk::Toplevel::State
const new_state)
1115 if (prefs->
getBool(tool_path +
"/usecurrent") && css_current) {
1116 obj->
setCSS(css_current,
"style");
1157 canvas->set_cursor(
"wait");
1168 _tool->use_tool_cursor();
1286 if (!tool)
return false;
1290 tool->is_space_panning())
1296 return tool->start_item_handler(drawing_item->
getItem(), event);
1299 return tool->start_root_handler(event);
1315 g_debug(
"Desktop, finishing reconstruction\n");
1323 g_debug(
"Desktop, finishing reconstruction end\n");
1385 std::cerr <<
"on_zoom_scale: Missed on_zoom_begin event" << std::endl;
1388 auto const widget_point =
canvas->get_last_mouse().value_or(
canvas->get_dimensions() / 2);
1389 auto const world_point =
canvas->canvas_to_world(widget_point);
void apply_preferences_canvas_mode(SPDesktop *dt)
void view_set_gui(InkscapeWindow *win)
Authors: Sushant A A sushant.co19@gmail.com
Rewrite of code originally in desktop-widget.cpp.
3x3 matrix representing an affine transformation.
C area() const
Compute the rectangle's area.
CPoint midpoint() const
Get the point in the geometric center of the rectangle.
C left() const
Return leftmost coordinate of the rectangle (+X is to the right).
C height() const
Get the vertical extent of the rectangle.
C width() const
Get the horizontal extent of the rectangle.
CPoint min() const
Get the corner of the rectangle with smallest coordinate values.
Two-dimensional point with integer coordinates.
Axis-aligned rectangle that can be empty.
Paralellogram, representing a linear transformation of a rectangle.
Two-dimensional point that doubles as a vector.
constexpr Coord y() const noexcept
Axis aligned, non-empty rectangle.
bool isFullscreen() const
void change_document(SPDocument *document)
Inkscape::Drawing * get_drawing()
sigc::connection connect_drawing_event(sigc::slot< bool(CanvasEvent const &, Inkscape::DrawingItem *)> slot)
virtual void set_visible(bool visible)
void set_name(std::string &&name)
sigc::connection connect_event(sigc::slot< bool(CanvasEvent const &)> const &slot)
void set_pickable(bool pickable)
Provides a class to put a canvasitem temporarily on-canvas.
RAII-style mechanism for creating a temporary undo-insensitive context.
SVG drawing item for display.
void prependChild(DrawingItem *item)
void setCurrentLayer(SPObject *object, bool clear=false)
Sets the current layer of the desktop.
SPGroup * currentLayer() const
Returns current top layer.
void reset()
Resets the bottom layer to the current root.
MessageId flash(MessageType type, char const *message)
Temporarily pushes a message onto the stack.
void clear()
Unselects all selected objects.
Preference storage class.
bool getBool(Glib::ustring const &pref_path, bool def=false)
Retrieve a Boolean value.
double getDouble(Glib::ustring const &pref_path, double def=0.0, Glib::ustring const &unit="")
Retrieve a floating point value.
static Preferences * get()
Access the singleton Preferences object.
SPCSSAttr * getInheritedStyle(Glib::ustring const &pref_path)
Retrieve an inherited CSS style.
void setBool(Glib::ustring const &pref_path, bool value)
Set a Boolean value.
Group of selected control points.
A widget that manages DialogNotebook's and other widgets inside a horizontal DialogMultipaned contain...
void set_inkscape_window(InkscapeWindow *inkscape_window)
void setRotate(Geom::Rotate rotate)
Geom::Affine const & w2d() const
bool isFlipped(CanvasFlip flip)
void addFlip(CanvasFlip flip)
void setOffset(Geom::Point offset)
void setScale(Geom::Scale scale)
void addRotate(Geom::Rotate rotate)
Geom::Point const & getOffset()
void addOffset(Geom::Point offset)
void setFlip(CanvasFlip flip)
Geom::Affine const & d2w() const
Inkscape::CanvasItemGroup * _canvas_group_grids
Grids.
double current_zoom() const
sigc::signal< void(SPDesktop *)> _destroy_signal
Geom::Point current_center() const
void setTool(std::string const &toolName)
Replaces the currently active tool with a new one.
Geom::Parallelogram get_display_area() const
Return canvas viewbox in desktop coordinates.
std::unique_ptr< Inkscape::Display::TemporaryItemList > _temporary_item_list
void toggleToolbar(char const *toolbar_name)
void emit_control_point_selected(Inkscape::UI::ControlPointSelection *selection)
void focusMode(bool mode=true)
Changes whether the user is in focus mode or not.
std::vector< SPItem * > getItemsAtPoints(std::vector< Geom::Point > ps, bool all_layers=true, bool topmost_only=true, size_t limit=0, bool active_only=true) const
void emit_text_cursor_moved(Inkscape::UI::Tools::TextTool *tool)
Inkscape::Display::TemporaryItem * add_temporary_canvasitem(Inkscape::CanvasItem *item, int lifetime_msecs, bool move_to_bottom=true)
One should not keep a reference to the SPCanvasItem, the temporary item code will delete the object f...
void setRenderMode(Inkscape::RenderMode mode)
bool _focusMode
Whether we're focused working or general working.
bool itemIsHidden(SPItem const *item) const
void zoom_grab_focus()
Tell widget to let zoom widget grab keyboard focus.
Inkscape::CanvasItemGroup * _canvas_group_drawing
SVG Drawing.
void rotate_relative_center_point(Geom::Point const &c, double rotate)
Rotate aligning the point 'c' to the center of desktop window.
void setToolboxFocusTo(char const *label)
std::list< DesktopAffine > transforms_past
std::optional< double > _begin_zoom
InkscapeWindow const * getInkscapeWindow() const
void flip_relative_center_point(Geom::Point const &c, CanvasFlip flip)
Flip direction, aligning the point 'c' to the center of desktop window.
void set_display_area(bool log=true)
Does all the dirty work in setting the display area.
bool is_darktheme() const
Inkscape::MessageStack * messageStack() const
DesktopAffine _quick_zoom_affine
The transform of the screen before quick zoom.
Inkscape::CanvasItemCatchall * _canvas_catchall
The bottom item for unclaimed events.
SPCSSAttr * current
Current style.
void handle_y_axis_flip(double yshift)
Geom::Affine const & dt2doc() const
Geom::Affine const & d2w() const
Transformation from desktop to window coordinates.
sigc::scoped_connection _message_changed_connection
void rotate_relative_keep_point(Geom::Point const &c, double rotate)
Rotate keeping the point 'c' fixed in the desktop window.
void on_zoom_scale(double scale)
Geom::Point point() const
Returns the mouse point in desktop coordinates; if mouse is outside the canvas, returns the center of...
bool isWithinViewport(SPItem const *item) const
True if desktop viewport intersects item's bbox.
void zoom_quick(bool enable=true)
Performs a quick zoom into what the user is working on.
bool drawing_handler(Inkscape::CanvasEvent const &event, Inkscape::DrawingItem *item)
Calls event handler of current event context.
Inkscape::CanvasItemGroup * _canvas_group_guides
Guide lines.
void scroll_relative_in_svg_coords(double dx, double dy)
Scroll canvas by specific coordinate amount in svg coordinates.
SPItem * getItemAtPoint(Geom::Point const &p, bool into_groups, SPItem *upto=nullptr) const
Gtk::Widget * get_toolbar_by_name(Glib::ustring const &name)
void scroll_relative(Geom::Point const &delta)
Scroll canvas by specific coordinate amount (window coordinates).
void rotate_grab_focus()
Tell widget to let rotate widget grab keyboard focus.
SPItem * getItemFromListAtPointBottom(std::vector< SPItem * > const &list, Geom::Point const &p) const
std::unique_ptr< Inkscape::MessageStack > _message_stack
void flip_absolute_keep_point(Geom::Point const &c, CanvasFlip flip)
Set new flip direction, keeping the point 'c' fixed in the desktop window.
std::unique_ptr< Inkscape::Selection > _selection
current selection; will never generally be NULL
void rotate_absolute_center_point(Geom::Point const &c, double rotate)
Set new rotation, aligning the point 'c' to the center of desktop window.
std::unique_ptr< Inkscape::UI::Tools::ToolBase > _tool
sigc::scoped_connection _reconstruction_finish_connection
void showInfoDialog(Glib::ustring const &message)
void flip_relative_keep_point(Geom::Point const &c, CanvasFlip flip)
Flip direction, keeping the point 'c' fixed in the desktop window.
sigc::signal< void(SPDesktop *, Inkscape::UI::Tools::ToolBase *)> _event_context_changed_signal
bool isToolboxButtonActive(char const *id) const
bool is_fullscreen() const
void prev_transform()
Revert back to previous transform if possible.
std::unique_ptr< Inkscape::Display::SnapIndicator > _snapindicator
SPNamedView * getNamedView() const
void zoom_realworld(Geom::Point const &c, double ratio)
Zoom in to an absolute realworld ratio, e.g.
bool _overlays_visible
Whether the overlays are temporarily hidden.
void quick_preview(bool activate)
sigc::connection connect_gradient_stop_selected(sigc::slot< void(SPStop *)> const &slot)
void setWindowSize(Geom::IntPoint const &size)
void set_display_center(Geom::Rect const &a)
Centre Rect, without zooming.
std::unique_ptr< Inkscape::MessageContext > _tips_message_context
Inkscape::UI::Dialog::DialogContainer * getContainer()
void change_document(SPDocument *document)
Make desktop switch documents.
SPItem * getGroupAtPoint(Geom::Point const &p) const
Inkscape::Selection * getSelection() const
sigc::scoped_connection _reconstruction_start_connection
Inkscape::CanvasItemGroup * _canvas_group_pages_bg
Page background.
SPDesktopWidget * _widget
void remove_temporary_canvasitem(Inkscape::Display::TemporaryItem *tempitem)
It is perfectly safe to call this function while the object has already been deleted due to a timeout...
void on_zoom_end(Gdk::EventSequence *sequence)
DesktopAffine _current_affine
sigc::connection connect_text_cursor_moved(sigc::slot< void(Inkscape::UI::Tools::TextTool *)> const &slot)
sigc::signal< void(SPDesktop *, SPDocument *)> _document_replaced_signal
sigc::signal< void(double)> signal_zoom_changed
Emitted when the zoom factor changes (not emitted when scrolling).
Inkscape::UI::Tools::ToolBase * getTool() const
std::unique_ptr< Inkscape::LayerManager > _layer_manager
void rotate_absolute_keep_point(Geom::Point const &c, double rotate)
Set new rotation, keeping the point 'c' fixed in the desktop window.
sigc::scoped_connection _schedule_zoom_from_document_connection
sigc::connection connect_control_point_selected(sigc::slot< void(Inkscape::UI::ControlPointSelection *)> const &slot)
void set_coordinate_status(Geom::Point const &p)
Sets the coordinate status to a given point.
Inkscape::CanvasItemGroup * _canvas_group_pages_fg
Page border + shadow.
void clearWaitingCursor()
void applyCurrentOrToolStyle(SPObject *obj, Glib::ustring const &tool_path, bool with_text)
Apply the desktop's current style or the tool style to the object.
void zoom_selection()
Zoom to selection.
bool scroll_to_point(Geom::Point const &s_dt, double autoscrollspeed=0)
Scroll screen so as to keep point 'p' visible in window.
void setWindowTransient(Gtk::Window &window, int transient_policy=1)
sigc::signal< void(Inkscape::UI::ControlPointSelection *)> _control_point_selected
void emit_gradient_stop_selected(SPStop *stop)
Geom::IntPoint getWindowSize() const
Glib::ustring _reconstruction_old_layer_id
SPDesktop(SPNamedView *nv)
bool _saved_guides_visible
Remembers guides' visibility when hiding overlays.
bool is_maximized() const
sigc::connection _saved_or_modified_conn
bool is_flipped(CanvasFlip flip)
sigc::signal< void(Inkscape::UI::Tools::TextTool *)> _text_cursor_moved
std::unique_ptr< Inkscape::UI::Widget::Canvas > canvas
std::unique_ptr< Inkscape::Display::TranslucencyGroup > _translucency_group
std::unique_ptr< Inkscape::MessageContext > _guides_message_context
Inkscape::CanvasItemDrawing * _canvas_drawing
The actual SVG drawing (a.k.a. arena).
Inkscape::CanvasItemGroup * _canvas_group_controls
Handles, knots, nodes, etc.
void setDesktopWidget(SPDesktopWidget *dtw)
sigc::scoped_connection _message_idle_connection
void schedule_zoom_from_document()
Schedule the zoom/view settings from the document to be applied to the desktop just after the canvas ...
bool _quick_zoom_enabled
Signifies that currently we're in quick zoom mode.
void clear_transform_history()
Clear transform lists.
void showNotice(Glib::ustring const &msg, int timeout=0)
sigc::scoped_connection _y_axis_flipped
void reconstruction_finish()
Called when document rebuild is finished.
void reconstruction_start()
Called when document is starting to be rebuilt.
void setToolboxAdjustmentValue(char const *id, double val)
void flip_absolute_center_point(Geom::Point const &c, CanvasFlip flip)
Set new flip direction, aligning the point 'c' to the center of desktop window.
sigc::signal< void(SPStop *)> _gradient_stop_selected
bool is_focusMode() const
Checks to see if the user is working in focused mode.
void zoom_relative(Geom::Point const &c, double zoom, bool keep_point=true)
Zoom in or out relatively to the current zoom.
Inkscape::LayerManager & layerManager()
void scroll_absolute(Geom::Point const &point)
Scroll canvas by to a particular point (window coordinates).
void set_display_width(Geom::Rect const &a, Geom::Coord border)
Set display area in only the width dimension.
void setDocument(SPDocument *doc)
Associate document with desktop.
void zoom_absolute(Geom::Point const &c, double zoom, bool keep_point=true)
Zoom to the given absolute zoom level.
void setColorMode(Inkscape::ColorMode mode)
Inkscape::CanvasItemGroup * _canvas_group_sketch
Temporary items before becoming permanent.
Geom::Affine const & doc2dt() const
std::list< DesktopAffine > transforms_future
void next_transform()
Set transform to next in list.
void setTempHideOverlays(bool hide)
Shows or hides the on-canvas overlays and controls, such as grids, guides, manipulation handles,...
bool warnDialog(Glib::ustring const &text)
void toggleCommandPalette()
void onStatusMessage(Inkscape::MessageType type, char const *message)
Inkscape::CanvasItemGroup * _canvas_group_temp
Temporary items that self-destruct.
void zoom_drawing()
Zoom to whole drawing.
sigc::connection _document_uri_set_connection
void onWindowStateChanged(Gdk::Toplevel::State changed, Gdk::Toplevel::State new_toplevel_state)
onWindowStateChanged
void on_zoom_begin(Gdk::EventSequence *sequence)
Geom::Affine const & w2d() const
Transformation from window to desktop coordinates (zoom/rotate).
void activate_guides(bool activate)
Set activate status of current desktop's named view.
Typed SVG document implementation.
const Geom::Affine & doc2dt() const
Document to desktop coordinate transformation.
std::vector< SPItem * > getItemsAtPoints(unsigned const key, std::vector< Geom::Point > points, bool all_layers=true, bool topmost_only=true, size_t limit=0, bool active_only=true) const
SPRoot * getRoot()
Returns our SPRoot.
static SPItem * getItemFromListAtPointBottom(unsigned int dkey, SPGroup *group, const std::vector< SPItem * > &list, Geom::Point const &p, bool take_insensitive=false)
Returns the bottommost item from the list which is at the point, or NULL if none.
const Geom::Affine & dt2doc() const
Desktop to document coordinate transformation.
SPObject * getObjectById(std::string const &id) const
sigc::connection connectSavedOrModified(sigc::slot< void()> &&slot)
sigc::signal< void(double)> get_y_axis_flipped()
sigc::connection connectReconstructionFinish(ReconstructionFinish::slot_type slot)
sigc::connection connectFilenameSet(FilenameSetSignal::slot_type slot)
int ensureUpToDate(unsigned int object_modified_tag=0)
Repeatedly works on getting the document updated, since sometimes it takes more than one pass to get ...
sigc::connection connectReconstructionStart(ReconstructionStart::slot_type slot, bool first=false)
SPNamedView * getNamedView()
Get the namedview for this document, creates it if it's not found.
SPItem * getGroupAtPoint(unsigned int key, Geom::Point const &p) const
SPItem * getItemAtPoint(unsigned int key, Geom::Point const &p, bool into_groups, SPItem *upto=nullptr) const
Base class for visual SVG elements.
Inkscape::DrawingItem * invoke_show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags)
void invoke_hide(unsigned int key)
Geom::OptRect desktopVisualBounds() const
Get item's visual bbox in desktop coordinate system.
static unsigned int display_key_new(unsigned numkeys)
Allocates unique integer keys.
void show(SPDesktop *desktop)
void temporarily_show_guides(bool show)
void activateGuides(void *desktop, bool active)
void setShowGrids(bool v)
void set_desk_color(SPDesktop *desktop)
void hide(SPDesktop const *desktop)
SPObject is an abstract base class of all of the document nodes at the SVG document level.
char const * getId() const
Returns the objects current ID string.
void setCSS(SPCSSAttr *css, char const *attr)
Control point selection - stores a set of control points and applies transformations to them.
std::shared_ptr< Css const > css
sigc::scoped_connection timeout
bool sp_desktop_root_handler(Inkscape::CanvasEvent const &event, SPDesktop *desktop)
SPCSSAttr * sp_desktop_get_style(SPDesktop *desktop, bool with_text)
Return the desktop's current style.
static void delete_then_null(std::unique_ptr< T > &uptr)
Editable view implementation.
constexpr double SP_DESKTOP_ZOOM_MIN
constexpr double SP_DESKTOP_ZOOM_MAX
A widget that manages DialogNotebook's and other widgets inside a horizontal DialogMultipaned.
TODO: insert short description here.
double Coord
Floating point type used to store coordinates.
Inkscape - An SVG editor.
Glib::ustring getLayoutPrefPath(SPDesktop *desktop)
Interface for locally managing a current status message.
Raw stack of active status messages.
bool are_near(Affine const &a1, Affine const &a2, Coord eps=EPSILON)
constexpr bool has_flag(T test, T flag)
MessageType
A hint about the meaning of a message; is it an ordinary message, a message advising the user of some...
Piecewise< SBasis > log(Interval in)
void sp_repr_css_attr_unref(SPCSSAttr *css)
Unreferences an SPCSSAttr (will be garbage collected if no references remain).
Provides a class that shows a temporary indicator on the canvas of where the snap was,...
void sp_namedview_zoom_and_view_from_document(SPDesktop *desktop)
void sp_namedview_update_layers_from_document(SPDesktop *desktop)
SPRoot: SVG <svg> implementation.
Abstract base class for events.
virtual EventType type() const =0
Return the dynamic type of the CanvasEvent.
static void activate(GApplication *app, gpointer)
Render some items as translucent in a document rendering stack.