Code

Updated Russian translation
[inkscape.git] / src / display / sodipodi-ctrlrect.cpp
index be3b8dc4537be37402111cad419b6ddeabb5498a..dcd6dc0a618708173bfa029cab532d0bd24f23c6 100644 (file)
@@ -31,7 +31,7 @@ static void sp_ctrlrect_class_init(SPCtrlRectClass *c);
 static void sp_ctrlrect_init(CtrlRect *ctrlrect);
 static void sp_ctrlrect_destroy(GtkObject *object);
 
-static void sp_ctrlrect_update(SPCanvasItem *item, NR::Matrix const &affine, unsigned int flags);
+static void sp_ctrlrect_update(SPCanvasItem *item, Geom::Matrix const &affine, unsigned int flags);
 static void sp_ctrlrect_render(SPCanvasItem *item, SPCanvasBuf *buf);
 
 static SPCanvasItemClass *parent_class;
@@ -100,14 +100,14 @@ static void sp_ctrlrect_hline(SPCanvasBuf *buf, gint y, gint xs, gint xe, guint3
         guint const a = RGBA_A(rgba);
         gint const x0 = MAX(buf->rect.x0, xs);
         gint const x1 = MIN(buf->rect.x1, xe + 1);
-        guchar *p = buf->buf + (y - buf->rect.y0) * buf->buf_rowstride + (x0 - buf->rect.x0) * 3;
+        guchar *p = buf->buf + (y - buf->rect.y0) * buf->buf_rowstride + (x0 - buf->rect.x0) * 4;
         for (gint x = x0; x < x1; x++) {
             if (!dashed || ((x / DASH_LENGTH) % 2)) {
                 p[0] = INK_COMPOSE(r, a, p[0]);
                 p[1] = INK_COMPOSE(g, a, p[1]);
                 p[2] = INK_COMPOSE(b, a, p[2]);
             }
-            p += 3;
+            p += 4;
         }
     }
 }
@@ -121,7 +121,7 @@ static void sp_ctrlrect_vline(SPCanvasBuf *buf, gint x, gint ys, gint ye, guint3
         guint const a = RGBA_A(rgba);
         gint const y0 = MAX(buf->rect.y0, ys);
         gint const y1 = MIN(buf->rect.y1, ye + 1);
-        guchar *p = buf->buf + (y0 - buf->rect.y0) * buf->buf_rowstride + (x - buf->rect.x0) * 3;
+        guchar *p = buf->buf + (y0 - buf->rect.y0) * buf->buf_rowstride + (x - buf->rect.x0) * 4;
         for (gint y = y0; y < y1; y++) {
             if (!dashed || ((y / DASH_LENGTH) % 2)) {
                 p[0] = INK_COMPOSE(r, a, p[0]);
@@ -145,12 +145,12 @@ static void sp_ctrlrect_area(SPCanvasBuf *buf, gint xs, gint ys, gint xe, gint y
     gint const y0 = MAX(buf->rect.y0, ys);
     gint const y1 = MIN(buf->rect.y1, ye + 1);
     for (gint y = y0; y < y1; y++) {
-        guchar *p = buf->buf + (y - buf->rect.y0) * buf->buf_rowstride + (x0 - buf->rect.x0) * 3;
+        guchar *p = buf->buf + (y - buf->rect.y0) * buf->buf_rowstride + (x0 - buf->rect.x0) * 4;
         for (gint x = x0; x < x1; x++) {
             p[0] = INK_COMPOSE(r, a, p[0]);
             p[1] = INK_COMPOSE(g, a, p[1]);
             p[2] = INK_COMPOSE(b, a, p[2]);
-            p += 3;
+            p += 4;
         }
     }
 }
@@ -161,7 +161,7 @@ static void sp_ctrlrect_render(SPCanvasItem *item, SPCanvasBuf *buf)
 }
 
 
-static void sp_ctrlrect_update(SPCanvasItem *item, NR::Matrix const &affine, unsigned int flags)
+static void sp_ctrlrect_update(SPCanvasItem *item, Geom::Matrix const &affine, unsigned int flags)
 {
     SP_CTRLRECT(item)->update(affine, flags);
 }
@@ -177,7 +177,7 @@ void CtrlRect::init()
     _area.x0 = _area.y0 = 0;
     _area.x1 = _area.y1 = 0;
 
-    _rect = NR::Rect(NR::Point(0,0),NR::Point(0,0));
+    _rect = Geom::Rect(Geom::Point(0,0),Geom::Point(0,0));
 
     _shadow_size = 0;
 
@@ -221,7 +221,7 @@ void CtrlRect::render(SPCanvasBuf *buf)
 }
 
 
-void CtrlRect::update(NR::Matrix const &affine, unsigned int flags)
+void CtrlRect::update(Geom::Matrix const &affine, unsigned int flags)
 {
     if (((SPCanvasItemClass *) parent_class)->update) {
         ((SPCanvasItemClass *) parent_class)->update(this, affine, flags);
@@ -229,66 +229,135 @@ void CtrlRect::update(NR::Matrix const &affine, unsigned int flags)
 
     sp_canvas_item_reset_bounds(this);
 
-    if (_area.x0 != 0 || _area.x1 != 0 || _area.y0 != 0 || _area.y1 != 0) {
-        /* Request redraw old */
-        if (!_has_fill) {
-            /* Top */
-            sp_canvas_request_redraw(canvas,
-                                     _area.x0 - 1, _area.y0 - 1,
-                                     _area.x1 + 1, _area.y0 + 1);
-            /* Left */
-            sp_canvas_request_redraw(canvas,
-                                     _area.x0 - 1, _area.y0 - 1,
-                                     _area.x0 + 1, _area.y1 + 1);
-            /* Right */
-            sp_canvas_request_redraw(canvas,
-                                     _area.x1 - 1, _area.y0 - 1,
-                                     _area.x1 + _shadow_size + 1, _area.y1 + _shadow_size + 1);
-            /* Bottom */
-            sp_canvas_request_redraw(canvas,
-                                     _area.x0 - 1, _area.y1 - 1,
-                                     _area.x1 + _shadow_size + 1, _area.y1 + _shadow_size + 1);
-        } else {
-            sp_canvas_request_redraw(canvas,
-                                     _area.x0 - 1, _area.y0 - 1,
-                                     _area.x1 + _shadow_size + 1, _area.y1 + _shadow_size + 1);
-        }
-    }
+    NRRectL _area_old;
+    _area_old.x0 = _area.x0;
+    _area_old.x1 = _area.x1;
+    _area_old.y0 = _area.y0;
+    _area_old.y1 = _area.y1;
 
-    NR::Rect bbox(_rect.min() * affine, _rect.max() * affine);
+    Geom::Rect bbox(_rect.min() * affine, _rect.max() * affine);
 
-    _area.x0 = (int) floor(bbox.min()[NR::X] + 0.5);
-    _area.y0 = (int) floor(bbox.min()[NR::Y] + 0.5);
-    _area.x1 = (int) floor(bbox.max()[NR::X] + 0.5);
-    _area.y1 = (int) floor(bbox.max()[NR::Y] + 0.5);
+    _area.x0 = (int) floor(bbox.min()[Geom::X] + 0.5);
+    _area.y0 = (int) floor(bbox.min()[Geom::Y] + 0.5);
+    _area.x1 = (int) floor(bbox.max()[Geom::X] + 0.5);
+    _area.y1 = (int) floor(bbox.max()[Geom::Y] + 0.5);
 
+    gint _shadow_size_old = _shadow_size;
     _shadow_size = _shadow;
 
-    if (_area.x0 != 0 || _area.x1 != 0 || _area.y0 != 0 || _area.y1 != 0) {
-        /* Request redraw new */
-        if (!_has_fill) {
-            /* Top */
+    // FIXME: we don't process a possible change in _has_fill
+    if (_has_fill) {
+        if (_area_old.x0 != 0 || _area_old.x1 != 0 || _area_old.y0 != 0 || _area_old.y1 != 0) {
             sp_canvas_request_redraw(canvas,
-                                     _area.x0 - 1, _area.y0 - 1,
-                                     _area.x1 + 1, _area.y0 + 1);
-            /* Left */
-            sp_canvas_request_redraw(canvas,
-                                     _area.x0 - 1, _area.y0 - 1,
-                                     _area.x0 + 1, _area.y1 + 1);
-            /* Right */
-            sp_canvas_request_redraw(canvas,
-                                     _area.x1 - 1, _area.y0 - 1,
-                                     _area.x1 + _shadow_size + 1, _area.y1 + _shadow_size + 1);
-            /* Bottom */
-            sp_canvas_request_redraw(canvas,
-                                     _area.x0 - 1, _area.y1 - 1,
-                                     _area.x1 + _shadow_size + 1, _area.y1 + _shadow_size + 1);
-        } else {
+                                 _area_old.x0 - 1, _area_old.y0 - 1,
+                                 _area_old.x1 + _shadow_size + 1, _area_old.y1 + _shadow_size + 1);
+        }
+        if (_area.x0 != 0 || _area.x1 != 0 || _area.y0 != 0 || _area.y1 != 0) {
             sp_canvas_request_redraw(canvas,
-                                     _area.x0 - 1, _area.y0 - 1,
-                                     _area.x1 + _shadow_size + 1, _area.y1 + _shadow_size + 1);
+                                 _area.x0 - 1, _area.y0 - 1,
+                                 _area.x1 + _shadow_size + 1, _area.y1 + _shadow_size + 1);
+        }
+    } else { // clear box, be smart about what part of the frame to redraw
+
+        /* Top */
+        if (_area.y0 != _area_old.y0) { // different level, redraw fully old and new
+            if (_area_old.x0 != _area_old.x1)
+                sp_canvas_request_redraw(canvas,
+                                         _area_old.x0 - 1, _area_old.y0 - 1,
+                                         _area_old.x1 + 1, _area_old.y0 + 1);
+
+            if (_area.x0 != _area.x1)
+                sp_canvas_request_redraw(canvas,
+                                         _area.x0 - 1, _area.y0 - 1,
+                                         _area.x1 + 1, _area.y0 + 1);
+        } else { // same level, redraw only the ends
+            if (_area.x0 != _area_old.x0) {
+                sp_canvas_request_redraw(canvas,
+                                         MIN(_area_old.x0,_area.x0) - 1, _area.y0 - 1,
+                                         MAX(_area_old.x0,_area.x0) + 1, _area.y0 + 1);
+            }
+            if (_area.x1 != _area_old.x1) {
+                sp_canvas_request_redraw(canvas,
+                                         MIN(_area_old.x1,_area.x1) - 1, _area.y0 - 1,
+                                         MAX(_area_old.x1,_area.x1) + 1, _area.y0 + 1);
+            }
         }
 
+        /* Left */
+        if (_area.x0 != _area_old.x0) { // different level, redraw fully old and new
+            if (_area_old.y0 != _area_old.y1)
+                sp_canvas_request_redraw(canvas,
+                                         _area_old.x0 - 1, _area_old.y0 - 1,
+                                         _area_old.x0 + 1, _area_old.y1 + 1);
+
+            if (_area.y0 != _area.y1)
+                sp_canvas_request_redraw(canvas,
+                                         _area.x0 - 1, _area.y0 - 1,
+                                         _area.x0 + 1, _area.y1 + 1);
+        } else { // same level, redraw only the ends
+            if (_area.y0 != _area_old.y0) {
+                sp_canvas_request_redraw(canvas,
+                                         _area.x0 - 1, MIN(_area_old.y0,_area.y0) - 1, 
+                                         _area.x0 + 1, MAX(_area_old.y0,_area.y0) + 1);
+            }
+            if (_area.y1 != _area_old.y1) {
+                sp_canvas_request_redraw(canvas,
+                                         _area.x0 - 1, MIN(_area_old.y1,_area.y1) - 1, 
+                                         _area.x0 + 1, MAX(_area_old.y1,_area.y1) + 1);
+            }
+        }
+
+        /* Right */
+        if (_area.x1 != _area_old.x1 || _shadow_size_old != _shadow_size) { 
+            if (_area_old.y0 != _area_old.y1)
+                sp_canvas_request_redraw(canvas,
+                                         _area_old.x1 - 1, _area_old.y0 - 1,
+                                         _area_old.x1 + _shadow_size + 1, _area_old.y1 + _shadow_size + 1);
+
+            if (_area.y0 != _area.y1)
+                sp_canvas_request_redraw(canvas,
+                                         _area.x1 - 1, _area.y0 - 1,
+                                         _area.x1 + _shadow_size + 1, _area.y1 + _shadow_size + 1);
+        } else { // same level, redraw only the ends
+            if (_area.y0 != _area_old.y0) {
+                sp_canvas_request_redraw(canvas,
+                                         _area.x1 - 1, MIN(_area_old.y0,_area.y0) - 1, 
+                                         _area.x1 + _shadow_size + 1, MAX(_area_old.y0,_area.y0) + _shadow_size + 1);
+            }
+            if (_area.y1 != _area_old.y1) {
+                sp_canvas_request_redraw(canvas,
+                                         _area.x1 - 1, MIN(_area_old.y1,_area.y1) - 1, 
+                                         _area.x1 + _shadow_size + 1, MAX(_area_old.y1,_area.y1) + _shadow_size + 1);
+            }
+        }
+
+        /* Bottom */
+        if (_area.y1 != _area_old.y1 || _shadow_size_old != _shadow_size) { 
+            if (_area_old.x0 != _area_old.x1)
+                sp_canvas_request_redraw(canvas,
+                                         _area_old.x0 - 1, _area_old.y1 - 1,
+                                         _area_old.x1 + _shadow_size + 1, _area_old.y1 + _shadow_size + 1);
+
+            if (_area.x0 != _area.x1)
+                sp_canvas_request_redraw(canvas,
+                                         _area.x0 - 1, _area.y1 - 1,
+                                         _area.x1 + _shadow_size + 1, _area.y1 + _shadow_size + 1);
+        } else { // same level, redraw only the ends
+            if (_area.x0 != _area_old.x0) {
+                sp_canvas_request_redraw(canvas,
+                                         MIN(_area_old.x0,_area.x0) - 1, _area.y1 - 1,
+                                         MAX(_area_old.x0,_area.x0) + _shadow_size + 1, _area.y1 + _shadow_size + 1);
+            }
+            if (_area.x1 != _area_old.x1) {
+                sp_canvas_request_redraw(canvas,
+                                         MIN(_area_old.x1,_area.x1) - 1, _area.y1 - 1,
+                                         MAX(_area_old.x1,_area.x1) + _shadow_size + 1, _area.y1 + _shadow_size + 1);
+            }
+        }
+    }
+
+    // update SPCanvasItem box
+    if (_area.x0 != 0 || _area.x1 != 0 || _area.y0 != 0 || _area.y1 != 0) {
         x1 = _area.x0 - 1;
         y1 = _area.y0 - 1;
         x2 = _area.x1 + _shadow_size + 1;
@@ -312,7 +381,7 @@ void CtrlRect::setShadow(int s, guint c)
     _requestUpdate();
 }
 
-void CtrlRect::setRectangle(NR::Rect const &r)
+void CtrlRect::setRectangle(Geom::Rect const &r)
 {
     _rect = r;
     _requestUpdate();