index 0e4887f59608547f50c9f07cf9b8253cc14ce377..dcd6dc0a618708173bfa029cab532d0bd24f23c6 100644 (file)
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;
static const guint DASH_LENGTH = 4;
-GtkType sp_ctrlrect_get_type()
+GType sp_ctrlrect_get_type()
{
- static GtkType ctrlrect_type = 0;
-
- if (!ctrlrect_type) {
- GtkTypeInfo ctrlrect_info = {
- "SPCtrlRect",
- sizeof(CtrlRect),
+ static GType type = 0;
+
+ if (!type) {
+ GTypeInfo info = {
sizeof(SPCtrlRectClass),
- (GtkClassInitFunc) sp_ctrlrect_class_init,
- (GtkObjectInitFunc) sp_ctrlrect_init,
- NULL, NULL, NULL
+ 0, // base_init
+ 0, // base_finalize
+ (GClassInitFunc)sp_ctrlrect_class_init,
+ 0, // class_finalize
+ 0, // class_data
+ sizeof(CtrlRect),
+ 0, // n_preallocs
+ (GInstanceInitFunc)sp_ctrlrect_init,
+ 0 // value_table
};
- ctrlrect_type = gtk_type_unique(SP_TYPE_CANVAS_ITEM, &ctrlrect_info);
+ type = g_type_register_static(SP_TYPE_CANVAS_ITEM, "SPCtrlRect", &info, static_cast<GTypeFlags>(0));
}
- return ctrlrect_type;
+ return type;
}
static void sp_ctrlrect_class_init(SPCtrlRectClass *c)
@@ -95,15 +99,15 @@ static void sp_ctrlrect_hline(SPCanvasBuf *buf, gint y, gint xs, gint xe, guint3
guint const b = RGBA_B(rgba);
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;
+ gint const x1 = MIN(buf->rect.x1, xe + 1);
+ 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;
}
}
}
@@ -117,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]);
@@ -141,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;
}
}
}
}
-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);
}
_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;
}
-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);
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;
+
+ Geom::Rect bbox(_rect.min() * affine, _rect.max() * affine);
+
+ _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);
- NR::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);
-
+ 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 */
- sp_canvas_request_redraw(canvas,
- _area.x0 - 1, _area.y0 - 1,
- _area.x1 + 1, _area.y0 + 1);
- /* Left */
+ // 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.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;
y2 = _area.y1 + _shadow_size + 1;
}
-
}
_requestUpdate();
}
-void CtrlRect::setRectangle(NR::Rect const &r)
+void CtrlRect::setRectangle(Geom::Rect const &r)
{
_rect = r;
_requestUpdate();