index 05449f2bb146aeb6a572ad940f3c70afbdb7bf1d..28c76e7045e1f869dc529b74c233b02f47b10a65 100644 (file)
#include "display-forward.h"
#include "sp-canvas-util.h"
#include "sodipodi-ctrlrect.h"
+#include "libnr/nr-pixops.h"
/*
* Currently we do not have point method, as it should always be painted
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)
#define RGBA_G(v) (((v) >> 16) & 0xff)
#define RGBA_B(v) (((v) >> 8) & 0xff)
#define RGBA_A(v) ((v) & 0xff)
-#define COMPOSE(b,f,a) ( ( ((guchar) b) * ((guchar) (0xff - a)) + ((guchar) ((b ^ ~f) + b/4 - (b>127? 63 : 0))) * ((guchar) a) ) / 0xff )
static void sp_ctrlrect_hline(SPCanvasBuf *buf, gint y, gint xs, gint xe, guint32 rgba, guint dashed)
{
@@ -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] = COMPOSE(p[0], r, a);
- p[1] = COMPOSE(p[1], g, a);
- p[2] = COMPOSE(p[2], b, a);
+ 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,12 +121,12 @@ 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] = COMPOSE(p[0], r, a);
- p[1] = COMPOSE(p[1], g, a);
- p[2] = COMPOSE(p[2], b, a);
+ 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 += buf->buf_rowstride;
}
@@ -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] = COMPOSE(p[0], r, a);
- p[1] = COMPOSE(p[1], g, a);
- p[2] = COMPOSE(p[2], b, a);
- p += 3;
+ 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 += 4;
}
}
}
_shadow = 0;
_area.x0 = _area.y0 = 0;
- _area.x1 = _area.y1 = -1;
+ _area.x1 = _area.y1 = 0;
+
+ _rect = NR::Rect(NR::Point(0,0),NR::Point(0,0));
_shadow_size = 0;
void CtrlRect::render(SPCanvasBuf *buf)
{
- if ((_area.x0 < buf->rect.x1) &&
+ if ((_area.x0 != 0 || _area.x1 != 0 || _area.y0 != 0 || _area.y1 != 0) &&
+ (_area.x0 < buf->rect.x1) &&
(_area.y0 < buf->rect.y1) &&
((_area.x1 + _shadow_size) >= buf->rect.x0) &&
((_area.y1 + _shadow_size) >= buf->rect.y0)) {
sp_canvas_item_reset_bounds(this);
- /* 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);
+ 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);
+ }
}
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);
-
+
_shadow_size = _shadow;
-
- /* 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 */
- 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);
+
+ 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 */
+ 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);
+ }
+
+ x1 = _area.x0 - 1;
+ y1 = _area.y0 - 1;
+ x2 = _area.x1 + _shadow_size + 1;
+ y2 = _area.y1 + _shadow_size + 1;
}
-
- x1 = _area.x0 - 1;
- y1 = _area.y0 - 1;
- x2 = _area.x1 + _shadow_size + 1;
- y2 = _area.y1 + _shadow_size + 1;
}