summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2015-02-24 08:31:52 +0000
committerDavid Robillard <d@drobilla.net>2015-02-24 08:31:52 +0000
commit1b169cbe8955e5df9cd1c6d27d14fc2d8fb2c113 (patch)
tree73ad9701f40897bbe3f61f51bf587c6f94cbf648 /src
parent0f60c61b0d7424005385c5687377b48ceb0c0c9b (diff)
downloadganv-1b169cbe8955e5df9cd1c6d27d14fc2d8fb2c113.tar.gz
ganv-1b169cbe8955e5df9cd1c6d27d14fc2d8fb2c113.tar.bz2
ganv-1b169cbe8955e5df9cd1c6d27d14fc2d8fb2c113.zip
Add light theme for typesettable canvas export.
Don't show edge handles on export. Fix port control drawing to be pixel perfect. git-svn-id: http://svn.drobilla.net/lad/trunk/ganv@5605 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r--src/Canvas.cpp20
-rw-r--r--src/Port.cpp2
-rw-r--r--src/box.c29
-rw-r--r--src/color.h18
-rw-r--r--src/edge.c7
-rw-r--r--src/ganv-private.h6
-rw-r--r--src/node.c2
-rw-r--r--src/port.c32
-rw-r--r--src/text.c2
9 files changed, 77 insertions, 41 deletions
diff --git a/src/Canvas.cpp b/src/Canvas.cpp
index 6b9c25c..1c8410b 100644
--- a/src/Canvas.cpp
+++ b/src/Canvas.cpp
@@ -247,6 +247,7 @@ struct GanvCanvasImpl {
this->left_grabbed_item = FALSE;
this->in_repick = FALSE;
this->locked = FALSE;
+ this->exporting = FALSE;
#ifdef GANV_FDGL
this->layout_idle_id = 0;
@@ -453,6 +454,9 @@ struct GanvCanvasImpl {
/* Disable changes to canvas */
gboolean locked;
+ /* True if the current draw is an export */
+ gboolean exporting;
+
#ifdef GANV_FDGL
guint layout_idle_id;
gdouble layout_energy;
@@ -2606,9 +2610,11 @@ ganv_canvas_export_image(GanvCanvas* canvas,
// Draw to recording surface
cairo_t* cr = cairo_create(rec_surface);
+ canvas->impl->exporting = TRUE;
(*GANV_ITEM_GET_CLASS(canvas->impl->root)->draw)(
canvas->impl->root, cr,
0, 0, canvas->impl->width, canvas->impl->height);
+ canvas->impl->exporting = FALSE;
cairo_destroy(cr);
// Get draw extent
@@ -2634,7 +2640,9 @@ ganv_canvas_export_image(GanvCanvas* canvas,
// Draw recording to image surface
cr = cairo_create(img);
if (draw_background) {
- cairo_set_source_rgba(cr, 0, 0, 0, 1.0);
+ double r, g, b, a;
+ color_to_rgba(DEFAULT_BACKGROUND_COLOR, &r, &g, &b, &a);
+ cairo_set_source_rgba(cr, r, g, b, a);
cairo_rectangle(cr, 0, 0, w + 2 * pad, h + 2 * pad);
cairo_fill(cr);
}
@@ -3664,7 +3672,9 @@ ganv_canvas_paint_rect(GanvCanvas* canvas, gint x0, gint y0, gint x1, gint y1)
ganv_canvas_c2w(canvas, draw_width, draw_height, &ww, &wh);
// Draw background
- cairo_set_source_rgba(cr, 0, 0, 0, 1.0);
+ double r, g, b, a;
+ color_to_rgba(DEFAULT_BACKGROUND_COLOR, &r, &g, &b, &a);
+ cairo_set_source_rgba(cr, r, g, b, a);
cairo_rectangle(cr, wx1, wy1, ww, wh);
cairo_fill(cr);
@@ -4138,4 +4148,10 @@ ganv_canvas_get_port_order(GanvCanvas* canvas)
return canvas->impl->_port_order;
}
+gboolean
+ganv_canvas_exporting(GanvCanvas* canvas)
+{
+ return canvas->impl->exporting;
+}
+
} // extern "C"
diff --git a/src/Port.cpp b/src/Port.cpp
index 2ecbf36..7cf960f 100644
--- a/src/Port.cpp
+++ b/src/Port.cpp
@@ -39,7 +39,7 @@ Port::Port(Module& module,
: Box(module.canvas(),
GANV_BOX(ganv_port_new(module.gobj(), is_input,
"fill-color", color,
- "border-color", highlight_color(color, 0x20),
+ "border-color", PORT_BORDER_COLOR(color),
"border-width", 2.0,
"label", name.c_str(),
NULL)))
diff --git a/src/box.c b/src/box.c
index a1a9315..c5206e1 100644
--- a/src/box.c
+++ b/src/box.c
@@ -201,7 +201,8 @@ ganv_box_update(GanvItem* item, int flags)
void
ganv_box_path(GanvBox* box,
- cairo_t* cr, double x1, double y1, double x2, double y2)
+ cairo_t* cr, double x1, double y1, double x2, double y2,
+ double dr)
{
static const double degrees = G_PI / 180.0;
@@ -215,18 +216,18 @@ ganv_box_path(GanvBox* box,
// Rounded rectangle
cairo_new_sub_path(cr);
cairo_arc(cr,
- x2 - impl->radius_tr,
- y1 + impl->radius_tr,
- impl->radius_tr, -90 * degrees, 0 * degrees);
+ x2 - impl->radius_tr - dr,
+ y1 + impl->radius_tr + dr,
+ impl->radius_tr + dr, -90 * degrees, 0 * degrees);
cairo_arc(cr,
- x2 - impl->radius_br, y2 - impl->radius_br,
- impl->radius_br, 0 * degrees, 90 * degrees);
+ x2 - impl->radius_br - dr, y2 - impl->radius_br - dr,
+ impl->radius_br + dr, 0 * degrees, 90 * degrees);
cairo_arc(cr,
- x1 + impl->radius_bl, y2 - impl->radius_bl,
- impl->radius_bl, 90 * degrees, 180 * degrees);
+ x1 + impl->radius_bl + dr, y2 - impl->radius_bl - dr,
+ impl->radius_bl + dr, 90 * degrees, 180 * degrees);
cairo_arc(cr,
- x1 + impl->radius_tl, y1 + impl->radius_tl,
- impl->radius_tl, 180 * degrees, 270 * degrees);
+ x1 + impl->radius_tl + dr, y1 + impl->radius_tl + dr,
+ impl->radius_tl + dr, 180 * degrees, 270 * degrees);
cairo_close_path(cr);
}
}
@@ -255,15 +256,15 @@ ganv_box_draw(GanvItem* item,
const double y = 0.0 - (STACKED_OFFSET * i);
// Trace basic box path
- ganv_box_path(box, cr, x1 - x, y1 - y, x2 - x, y2 - y);
+ ganv_box_path(box, cr, x1 - x, y1 - y, x2 - x, y2 - y, 0.0);
// Fill
color_to_rgba(fill_color, &r, &g, &b, &a);
cairo_set_source_rgba(cr, r, g, b, a);
- cairo_fill_preserve(cr);
// Border
if (impl->coords.border_width > 0.0) {
+ cairo_fill_preserve(cr);
color_to_rgba(border_color, &r, &g, &b, &a);
cairo_set_source_rgba(cr, r, g, b, a);
cairo_set_line_width(cr, impl->coords.border_width);
@@ -272,8 +273,10 @@ ganv_box_draw(GanvItem* item,
} else {
cairo_set_dash(cr, &dash_length, 0, 0);
}
+ cairo_stroke(cr);
+ } else {
+ cairo_fill(cr);
}
- cairo_stroke(cr);
}
GanvItemClass* item_class = GANV_ITEM_CLASS(parent_class);
diff --git a/src/color.h b/src/color.h
index 26cd7ea..d96bb2a 100644
--- a/src/color.h
+++ b/src/color.h
@@ -18,9 +18,21 @@
#include <glib.h>
-#define DEFAULT_TEXT_COLOR 0xFFFFFFFF
-#define DEFAULT_FILL_COLOR 0x1E2224FF
-#define DEFAULT_BORDER_COLOR 0x3E4244FF
+#ifdef GANV_USE_LIGHT_THEME
+# define DEFAULT_BACKGROUND_COLOR 0xFFFFFFFF
+# define DEFAULT_TEXT_COLOR 0x000000FF
+# define DEFAULT_FILL_COLOR 0xEEEEEEFF
+# define DEFAULT_BORDER_COLOR 0x000000FF
+# define PORT_BORDER_COLOR(fill) 0x000000FF
+# define EDGE_COLOR(base) highlight_color(tail_color, -48)
+#else
+# define DEFAULT_BACKGROUND_COLOR 0x000000FF
+# define DEFAULT_TEXT_COLOR 0xFFFFFFFF
+# define DEFAULT_FILL_COLOR 0x1E2224FF
+# define DEFAULT_BORDER_COLOR 0x3E4244FF
+# define PORT_BORDER_COLOR(fill) highlight_color(fill, 0x20)
+# define EDGE_COLOR(base) highlight_color(tail_color, 48)
+#endif
static inline void
color_to_rgba(guint color, double* r, double* g, double* b, double* a)
diff --git a/src/edge.c b/src/edge.c
index 6b91d97..89da897 100644
--- a/src/edge.c
+++ b/src/edge.c
@@ -26,9 +26,9 @@
#include "./color.h"
#include "./gettext.h"
+#include "color.h"
#include "ganv-private.h"
-// TODO: Very sloppy clipping for arrow heads
#define ARROW_DEPTH 32
#define ARROW_BREADTH 32
@@ -443,7 +443,8 @@ ganv_edge_draw(GanvItem* item,
}
}
- if (impl->coords.handle_radius > 0.0) {
+ if (!ganv_canvas_exporting(item->impl->canvas) &&
+ impl->coords.handle_radius > 0.0) {
cairo_move_to(cr, join_x, join_y);
cairo_arc(cr, join_x, join_y, impl->coords.handle_radius, 0, 2 * G_PI);
cairo_fill(cr);
@@ -635,7 +636,7 @@ ganv_edge_new(GanvCanvas* canvas,
if (!edge->impl->color) {
const guint tail_color = GANV_NODE(tail)->impl->fill_color;
g_object_set(G_OBJECT(edge),
- "color", highlight_color(tail_color, 48),
+ "color", EDGE_COLOR(tail_color),
NULL);
}
diff --git a/src/ganv-private.h b/src/ganv-private.h
index 4d892d9..29b2e61 100644
--- a/src/ganv-private.h
+++ b/src/ganv-private.h
@@ -354,6 +354,9 @@ ganv_canvas_request_redraw_w(GanvCanvas* canvas,
PortOrderCtx
ganv_canvas_get_port_order(GanvCanvas* canvas);
+gboolean
+ganv_canvas_exporting(GanvCanvas* canvas);
+
/* Edge */
void
@@ -373,7 +376,8 @@ ganv_edge_tick(GanvEdge* edge, double seconds);
void
ganv_box_path(GanvBox* box,
- cairo_t* cr, double x1, double y1, double x2, double y2);
+ cairo_t* cr, double x1, double y1, double x2, double y2,
+ double dr);
void
ganv_box_request_redraw(GanvItem* item,
diff --git a/src/node.c b/src/node.c
index e77ded3..6309f97 100644
--- a/src/node.c
+++ b/src/node.c
@@ -331,7 +331,7 @@ ganv_node_set_label(GanvNode* node, const char* str)
impl->label = GANV_TEXT(ganv_item_new(GANV_ITEM(node),
ganv_text_get_type(),
"text", str,
- "color", 0xFFFFFFFF,
+ "color", DEFAULT_TEXT_COLOR,
"managed", TRUE,
NULL));
}
diff --git a/src/port.c b/src/port.c
index 801b26e..ecdbe90 100644
--- a/src/port.c
+++ b/src/port.c
@@ -131,15 +131,13 @@ ganv_port_update(GanvItem* item, int flags)
GanvPortImpl* impl = port->impl;
if (impl->control) {
- const double border_width = GANV_NODE(item)->impl->border_width;
- impl->control->rect->impl->coords.border_width = border_width;
ganv_item_invoke_update(GANV_ITEM(impl->control->rect), flags);
}
if (impl->value_label) {
ganv_item_invoke_update(GANV_ITEM(port->impl->value_label), flags);
}
-
+
GanvItemClass* item_class = GANV_ITEM_CLASS(parent_class);
item_class->update(item, flags);
}
@@ -163,8 +161,9 @@ ganv_port_draw(GanvItem* item,
ganv_item_i2w_pair(GANV_ITEM(port),
&coords.x1, &coords.y1, &coords.x2, &coords.y2);
ganv_box_path(GANV_BOX(port), cr,
- coords.x1 - pad, coords.y1 - pad,
- coords.x2 + pad, coords.y2 + pad);
+ coords.x1 + pad, coords.y1 + pad,
+ coords.x2 - pad, coords.y2 - pad,
+ -pad);
cairo_clip(cr);
GanvItem* const rect = GANV_ITEM(port->impl->control->rect);
@@ -362,10 +361,9 @@ ganv_port_set_height(GanvBox* box,
GanvPort* port = GANV_PORT(box);
parent_class->set_height(box, height);
if (port->impl->control) {
- double control_y1;
- g_object_get(port->impl->control->rect, "y1", &control_y1, NULL);
ganv_item_set(GANV_ITEM(port->impl->control->rect),
- "y2", control_y1 + height,
+ "y1", box->impl->coords.border_width / 2.0,
+ "y2", height - box->impl->coords.border_width / 2.0,
NULL);
}
ganv_port_place_labels(port);
@@ -497,9 +495,8 @@ ganv_port_set_direction(GanvPort* port,
void
ganv_port_show_control(GanvPort* port)
{
- GanvNode* node = GANV_NODE(port);
-
- guint color = highlight_color(node->impl->fill_color, 0x40);
+ const guint color = 0xFFFFFF66;
+ const double border_width = GANV_NODE(port)->impl->border_width;
GanvPortControl* control = (GanvPortControl*)malloc(sizeof(GanvPortControl));
port->impl->control = control;
@@ -512,10 +509,10 @@ ganv_port_show_control(GanvPort* port)
control->rect = GANV_BOX(
ganv_item_new(GANV_ITEM(port),
ganv_box_get_type(),
- "x1", 0.0,
- "y1", 0.0,
+ "x1", border_width / 2.0,
+ "y1", border_width / 2.0,
"x2", 0.0,
- "y2", ganv_box_get_height(&port->box),
+ "y2", ganv_box_get_height(&port->box) - border_width / 2.0,
"fill-color", color,
"border-color", color,
"border-width", 0.0,
@@ -554,7 +551,7 @@ ganv_port_set_value_label(GanvPort* port,
ganv_text_get_type(),
"text", str,
"font-size", points,
- "color", 0xFFFFFFAA,
+ "color", DEFAULT_TEXT_COLOR,
"managed", TRUE,
NULL));
}
@@ -591,9 +588,12 @@ ganv_port_update_control_slider(GanvPort* port, float value, gboolean force)
return; // No change, do nothing
}
+ const double span = (ganv_box_get_width(&port->box) -
+ GANV_NODE(port)->impl->border_width);
+
const double w = (value - impl->control->min)
/ (impl->control->max - impl->control->min)
- * ganv_box_get_width(&port->box);
+ * span;
if (isnan(w)) {
return; // Shouldn't happen, but ignore crazy values
diff --git a/src/text.c b/src/text.c
index 04c991c..b8c3a39 100644
--- a/src/text.c
+++ b/src/text.c
@@ -59,7 +59,7 @@ ganv_text_init(GanvText* text)
impl->layout = NULL;
impl->text = NULL;
impl->font_size = 0.0;
- impl->color = 0xFFFFFFFF;
+ impl->color = DEFAULT_TEXT_COLOR;
impl->needs_layout = FALSE;
}