diff options
| author | Jabier Arraiza <jabier.arraiza@marker.es> | 2018-11-11 23:54:54 +0000 |
|---|---|---|
| committer | Jabier Arraiza <jabier.arraiza@marker.es> | 2018-12-01 16:17:15 +0000 |
| commit | 7fcdbf91b9d06dffea0591699c8474408b3d02ab (patch) | |
| tree | 992df2f68baf55a0f9ee99c58a1cb4e5c176a0e6 /src | |
| parent | Adding line to move outline (diff) | |
| download | inkscape-7fcdbf91b9d06dffea0591699c8474408b3d02ab.tar.gz inkscape-7fcdbf91b9d06dffea0591699c8474408b3d02ab.zip | |
Improve spliter and add outline mode functionality
Diffstat (limited to 'src')
| -rw-r--r-- | src/desktop.cpp | 4 | ||||
| -rw-r--r-- | src/display/drawing-image.cpp | 2 | ||||
| -rw-r--r-- | src/display/drawing-item.cpp | 4 | ||||
| -rw-r--r-- | src/display/drawing-item.h | 5 | ||||
| -rw-r--r-- | src/display/drawing-shape.cpp | 2 | ||||
| -rw-r--r-- | src/display/drawing-text.cpp | 2 | ||||
| -rw-r--r-- | src/display/drawing.cpp | 7 | ||||
| -rw-r--r-- | src/display/drawing.h | 4 | ||||
| -rw-r--r-- | src/display/sp-canvas.cpp | 108 | ||||
| -rw-r--r-- | src/display/sp-canvas.h | 5 | ||||
| -rw-r--r-- | src/document.cpp | 1 |
11 files changed, 88 insertions, 56 deletions
diff --git a/src/desktop.cpp b/src/desktop.cpp index 7cb90ebb2..ad9c2efbd 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -1607,6 +1607,10 @@ void SPDesktop::toggleSplitMode() Gtk::Window *parent = getToplevel(); if (parent) { _split_canvas = !_split_canvas; + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setBool("/window/splitcanvas/vertical", true); + prefs->setBool("/window/splitcanvas/inverse", false); + prefs->setDouble("/window/splitcanvas/value", 0.5); SPDesktopWidget *dtw = static_cast<SPDesktopWidget *>(parent->get_data("desktopwidget")); dtw->splitCanvas(_split_canvas); GtkAllocation allocation; diff --git a/src/display/drawing-image.cpp b/src/display/drawing-image.cpp index a575cc7d0..81fb5b44b 100644 --- a/src/display/drawing-image.cpp +++ b/src/display/drawing-image.cpp @@ -188,7 +188,7 @@ DrawingImage::_pickItem(Geom::Point const &p, double delta, unsigned /*sticky*/) { if (!_pixbuf) return nullptr; - bool outline = _drawing.outline(); + bool outline = _drawing.outline() || _drawing.getOutlineSensitive(); if (outline) { Geom::Rect r = bounds(); diff --git a/src/display/drawing-item.cpp b/src/display/drawing-item.cpp index 59a486d52..d3729da94 100644 --- a/src/display/drawing-item.cpp +++ b/src/display/drawing-item.cpp @@ -998,9 +998,9 @@ DrawingItem::pick(Geom::Point const &p, double delta, unsigned flags) if (!(flags & PICK_STICKY) && !(_visible && _sensitive)) return nullptr; - bool outline = _drawing.outline(); + bool outline = _drawing.outline() || _drawing.getOutlineSensitive(); - if (!_drawing.outline()) { + if (!_drawing.outline() && !_drawing.getOutlineSensitive()) { // pick inside clipping path; if NULL, it means the object is clipped away there if (_clip) { DrawingItem *cpick = _clip->pick(p, delta, flags | PICK_AS_CLIP); diff --git a/src/display/drawing-item.h b/src/display/drawing-item.h index 155551f6a..2481a01a1 100644 --- a/src/display/drawing-item.h +++ b/src/display/drawing-item.h @@ -131,8 +131,9 @@ public: void setKey(unsigned key) { _key = key; } unsigned key() const { return _key; } - void setItem(SPItem *item) { _item = item; } - SPItem* getItem() const { return _item; } // SPItem + + void setData(void *data) { _user_data = data; } + void *data() const { return _user_data; } void update(Geom::IntRect const &area = Geom::IntRect::infinite(), UpdateContext const &ctx = UpdateContext(), unsigned flags = STATE_ALL, unsigned reset = 0); unsigned render(DrawingContext &dc, Geom::IntRect const &area, unsigned flags = 0, DrawingItem *stop_at = nullptr); diff --git a/src/display/drawing-shape.cpp b/src/display/drawing-shape.cpp index c3b41ac1e..e1379a884 100644 --- a/src/display/drawing-shape.cpp +++ b/src/display/drawing-shape.cpp @@ -338,7 +338,7 @@ DrawingShape::_pickItem(Geom::Point const &p, double delta, unsigned flags) if (!_curve) return nullptr; if (!_style) return nullptr; - bool outline = _drawing.outline(); + bool outline = _drawing.outline() || _drawing.getOutlineSensitive(); bool pick_as_clip = flags & PICK_AS_CLIP; if (SP_SCALE24_TO_FLOAT(_style->opacity.value) == 0 && !outline && !pick_as_clip) diff --git a/src/display/drawing-text.cpp b/src/display/drawing-text.cpp index 34af7452e..e1e9fecc5 100644 --- a/src/display/drawing-text.cpp +++ b/src/display/drawing-text.cpp @@ -187,7 +187,7 @@ DrawingItem *DrawingGlyphs::_pickItem(Geom::Point const &p, double /*delta*/, un bool invisible = (ggroup->_nrstyle.fill.type == NRStyle::PAINT_NONE) && (ggroup->_nrstyle.stroke.type == NRStyle::PAINT_NONE); - if (_font && _bbox && (_drawing.outline() || !invisible) ) { + if (_font && _bbox && (_drawing.outline() || _drawing.getOutlineSensitive() || !invisible) ) { // With text we take a simple approach: pick if the point is in a character bbox Geom::Rect expanded(_pick_bbox); // FIXME, why expand by delta? When is the next line needed? diff --git a/src/display/drawing.cpp b/src/display/drawing.cpp index 6bce7c12b..ceb43a876 100644 --- a/src/display/drawing.cpp +++ b/src/display/drawing.cpp @@ -36,6 +36,7 @@ Drawing::Drawing(SPCanvasArena *arena) , outlinecolor(0x000000ff) , delta(0) , _exact(false) + , _outline_sensitive(true) , _rendermode(RENDERMODE_NORMAL) , _colormode(COLORMODE_NORMAL) , _blur_quality(BLUR_QUALITY_BEST) @@ -134,6 +135,12 @@ Drawing::setExact(bool e) _exact = e; } +void +Drawing::setOutlineSensitive(bool e) +{ + _outline_sensitive = e; +}; + Geom::OptIntRect const & Drawing::cacheLimit() const { diff --git a/src/display/drawing.h b/src/display/drawing.h index ecef4d8ee..079843dc6 100644 --- a/src/display/drawing.h +++ b/src/display/drawing.h @@ -61,6 +61,8 @@ public: void setFilterQuality(int q); void setExact(bool e); bool getExact() const {return _exact;}; + void setOutlineSensitive(bool e); + bool getOutlineSensitive() const {return _outline_sensitive;}; Geom::OptIntRect const &cacheLimit() const; void setCacheLimit(Geom::OptIntRect const &r); @@ -82,7 +84,7 @@ private: void _pickItemsForCaching(); typedef std::list<CacheRecord> CandidateList; - + bool _outline_sensitive; DrawingItem *_root; std::set<DrawingItem *> _cached_items; // modified by DrawingItem::setCached() CacheList _candidate_items; diff --git a/src/display/sp-canvas.cpp b/src/display/sp-canvas.cpp index f5d9e20c9..67d136f1f 100644 --- a/src/display/sp-canvas.cpp +++ b/src/display/sp-canvas.cpp @@ -617,10 +617,6 @@ int sp_canvas_item_grab(SPCanvasItem *item, guint event_mask, GdkCursor *cursor, return -1; } - /* if (item->canvas->_oversplit) { - return -1; - } */ - // This test disallows grabbing events by an invisible item, which may be useful // sometimes. An example is the hidden control point used for the selector component, // where it is used for object selection and rubberbanding. There seems to be nothing @@ -1458,9 +1454,7 @@ int SPCanvas::pickCurrentItem(GdkEvent *event) gint SPCanvas::handle_doubleclick(GtkWidget *widget, GdkEventButton *event) { SPCanvas *canvas = SP_CANVAS (widget); - std::cout << "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" << std::endl; if(canvas->_oversplit) { - std::cout << "aaaaaaaaaaaaaaaaaaaaa" << std::endl; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); bool inverse = prefs->getBool("/window/splitcanvas/inverse", false); bool vertical = prefs->getBool("/window/splitcanvas/vertical", true); @@ -1475,6 +1469,7 @@ gint SPCanvas::handle_doubleclick(GtkWidget *widget, GdkEventButton *event) { prefs->setBool("/window/splitcanvas/vertical", true); prefs->setBool("/window/splitcanvas/inverse", false); } + prefs->setDouble("/window/splitcanvas/value", 0.5); canvas->dirtyAll(); canvas->addIdle();; } @@ -1602,7 +1597,7 @@ int SPCanvas::handle_motion(GtkWidget *widget, GdkEventMotion *event) { int status; SPCanvas *canvas = SP_CANVAS (widget); - + SPDesktop * desktop = SP_ACTIVE_DESKTOP; trackLatency((GdkEvent *)event); if (event->window != getWindow(canvas)) { @@ -1616,6 +1611,7 @@ int SPCanvas::handle_motion(GtkWidget *widget, GdkEventMotion *event) GdkDisplay *display = gdk_display_get_default(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); bool vertical = prefs->getBool("/window/splitcanvas/vertical", true); + bool inverse = prefs->getBool("/window/splitcanvas/inverse", true); if (canvas->_spliter && (*canvas->_spliter).contains(cursor_pos) && !canvas->_is_dragging) { if (!canvas->_oversplit) { @@ -1629,15 +1625,19 @@ int SPCanvas::handle_motion(GtkWidget *widget, GdkEventMotion *event) gdk_window_set_cursor (gtk_widget_get_window(widget), cursor); g_object_unref (cursor); } + canvas->_oversplit = true; + canvas->paintSpliter(); + (*canvas->_spliter).expandBy(2); } canvas->_oversplit = true; - std::cout << *canvas->_spliter << "----" << canvas->_splitpressed << "overoverover" << std::endl; } else { - if (canvas->_oversplit && !canvas->_splitpressed) { - SPDesktop * desktop = SP_ACTIVE_DESKTOP; - if (desktop && desktop->event_context) { + if (canvas->_oversplit) { + if (desktop && desktop->event_context && !canvas->_splitpressed) { desktop->event_context->sp_event_context_update_cursor(); } + canvas->_oversplit = false; + canvas->paintSpliter(); + (*canvas->_spliter).expandBy(-2); } canvas->_oversplit = false; } @@ -1645,16 +1645,17 @@ int SPCanvas::handle_motion(GtkWidget *widget, GdkEventMotion *event) GtkAllocation allocation; gtk_widget_get_allocation(GTK_WIDGET(canvas), &allocation); double value = vertical ? 1/(allocation.width/(double)cursor_pos[Geom::X]) : 1/(allocation.height/(double)cursor_pos[Geom::Y]); - std::cout << value << "----" << allocation.width << "----" << cursor_pos[Geom::X] << std::endl; - if (value < 0.05 || value > 0.95) { - prefs->setDouble("/window/splitcanvas/value", 0.5); - prefs->setBool("/window/splitcanvas/split", false); - prefs->setBool("/window/splitcanvas/vertical", true); - SP_ACTIVE_DESKTOP->toggleSplitMode(); + if (value < 0.03 || value > 0.97) { + SPDesktop * desktop = SP_ACTIVE_DESKTOP; + if (desktop && desktop->event_context) { + desktop->event_context->sp_event_context_update_cursor(); + desktop->toggleSplitMode(); + canvas->_splitpressed = false; + canvas->_oversplit = false; + } } else { prefs->setDouble("/window/splitcanvas/value", value); } - std::cout << "loolololololo" << std::endl; canvas->dirtyAll(); canvas->addIdle(); status = 1; @@ -1666,7 +1667,17 @@ int SPCanvas::handle_motion(GtkWidget *widget, GdkEventMotion *event) request_motions(gtk_widget_get_window (widget), event); } } - + + if (desktop) { + SPCanvasArena *arena = SP_CANVAS_ARENA (desktop->drawing); + if (desktop->splitMode()) { + bool contains = canvas->_spliter_area.contains(cursor_pos); + bool setoutline = inverse ? !contains : contains; + arena->drawing.setOutlineSensitive(setoutline); + } else { + arena->drawing.setOutlineSensitive(false); + } + } return status; } @@ -1778,41 +1789,39 @@ void SPCanvas::paintSpliter() return; SPCanvas *canvas = SP_CANVAS(this); Geom::IntRect linerect = (*canvas->_spliter); + Geom::IntPoint c0 = Geom::IntPoint(linerect.corner(0)); + Geom::IntPoint c1 = Geom::IntPoint(linerect.corner(1)); + Geom::IntPoint c2 = Geom::IntPoint(linerect.corner(2)); + Geom::IntPoint c3 = Geom::IntPoint(linerect.corner(3)); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + bool inverse = prefs->getBool("/window/splitcanvas/inverse", false); bool vertical = prefs->getBool("/window/splitcanvas/vertical", true); - bool inverse = prefs->getBool("/window/splitcanvas/inversel", false); - guint gapx = 0; - guint gapy = 0; - if (vertical) { - if(inverse) { - gapx = 3; - } else { - gapx = 0; - } + // We need to draw the line in middle of pixel + // https://developer.gnome.org/gtkmm-tutorial/stable/sec-cairo-drawing-lines.html.en:17.2.3 + double gapx = vertical ? 0.5 : 0; + double gapy = vertical ? 0 : 0.5; + Geom::Point start = vertical ? Geom::middle_point(c0, c1) : Geom::middle_point(c0, c3) ; + Geom::Point end = vertical ? Geom::middle_point(c2, c3) : Geom::middle_point(c1, c2) ; + cairo_t *ct = cairo_create(_backing_store); + cairo_set_source_rgba (ct, 1, 1, 1, 1); + cairo_set_line_width (ct, 1.0); + cairo_line_to (ct, start[0] + gapx, start[1] + gapy); + cairo_line_to (ct, end[0] + gapx, end[1] + gapy); + cairo_stroke (ct); + if (canvas->_oversplit) { + cairo_set_source_rgba (ct, 0.05, 0.05, 0.05, 0.8); } else { - if(inverse) { - gapy = 3; - } else { - gapy = 0; - } + cairo_set_source_rgba (ct, 0.05, 0.05, 0.05, 0.4); } - Geom::IntRect linerectint = linerect; - Geom::IntPoint c0 = Geom::IntPoint(linerectint.corner(0)); - Geom::IntPoint c1 = Geom::IntPoint(linerectint.corner(1)); - Geom::IntPoint c2 = Geom::IntPoint(linerectint.corner(2)); - Geom::IntPoint c3 = Geom::IntPoint(linerectint.corner(3)); - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - Geom::IntPoint start = c0; - Geom::IntPoint end = vertical ? c3 : c2; - cairo_t *ct = cairo_create(_backing_store); - cairo_set_source_rgba (ct, 0.05, 0.05, 0.05, 1); cairo_set_line_width (ct, 1.0); cairo_line_to (ct, start[0] + gapx, start[1] + gapy); cairo_line_to (ct, end[0] + gapx, end[1] + gapy); cairo_stroke (ct); cairo_restore(ct); cairo_destroy(ct); - gtk_widget_queue_draw_area(GTK_WIDGET(this), c0[0] + gapx, c0[1] + gapy, linerect.width() + 1 , linerect.height() + 1); + double updwidth = vertical ? 4 : linerect.width(); + double updheight = vertical ? linerect.height() : 4; + gtk_widget_queue_draw_area(GTK_WIDGET(this), start[0] - 2, start[1] - 2, updwidth, updheight); } struct PaintRectSetup { @@ -2129,7 +2138,6 @@ int SPCanvas::paint() bool inverse = prefs->getBool("/window/splitcanvas/inverse", false); bool vertical = prefs->getBool("/window/splitcanvas/vertical", true); double value = prefs->getDoubleLimited("/window/splitcanvas/value", 0.5, 0, 1); - std::cout << "mmmm" << prefs->getDoubleLimited("/window/splitcanvas/value", 0.5, 0, 1) << std::endl; double split_x = 1; double split_y = 1; if (desktop && desktop->splitMode()) { @@ -2146,8 +2154,18 @@ int SPCanvas::paint() Geom::IntCoord coord2x = allocation.x + (int(allocation.width * split_x)) + 1 - vruler_gap; Geom::IntCoord coord2y = allocation.y + (int(allocation.height * split_y)) + 1 - hruler_gap; _spliter = Geom::OptIntRect(coord1x, coord1y, coord2x, coord2y); + split_x = !vertical ? 0 : value; + split_y = vertical ? 0 : value; + coord1x = allocation.x + (int(allocation.width * split_x)) + 1 - vruler_gap; + coord1y = allocation.y + (int(allocation.height * split_y)) + 1 - hruler_gap; + split_x = !vertical ? 1 : value; + split_y = vertical ? 1 : value; + coord2x = allocation.x + allocation.width - vruler_gap; + coord2y = allocation.y + allocation.height - hruler_gap; + _spliter_area = Geom::OptIntRect(coord1x, coord1y, coord2x, coord2y); } else { _spliter = Geom::OptIntRect(); + _spliter_area = Geom::OptIntRect(); } cairo_rectangle_int_t crect = { _x0, _y0, int(allocation.width * split_x), int(allocation.height * split_y)}; split_x = !vertical ? 0 : value; diff --git a/src/display/sp-canvas.h b/src/display/sp-canvas.h index 05b37db7f..f1dde19c6 100644 --- a/src/display/sp-canvas.h +++ b/src/display/sp-canvas.h @@ -174,11 +174,12 @@ public: guint _idle_id; SPCanvasItem *_root; - + + Geom::OptIntRect _spliter; + Geom::OptIntRect _spliter_area; bool _is_dragging; bool _oversplit; bool _splitpressed; - Geom::OptIntRect _spliter; double _dx0; double _dy0; int _x0; ///< World coordinate of the leftmost pixels of window diff --git a/src/document.cpp b/src/document.cpp index 603241506..a351957fd 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -1481,7 +1481,6 @@ void SPDocument::build_flat_item_list(unsigned int dkey, SPGroup *group, gboolea build_flat_item_list(dkey, SP_GROUP(&o), into_groups); } else { SPItem *child = SP_ITEM(&o); - if (child->isVisibleAndUnlocked(dkey)) { _node_cache.push_front(child); } |
