summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Canvas.cpp68
-rw-r--r--src/module.c23
-rw-r--r--src/node.c16
-rw-r--r--src/text.c2
4 files changed, 76 insertions, 33 deletions
diff --git a/src/Canvas.cpp b/src/Canvas.cpp
index f42997c..2303ee4 100644
--- a/src/Canvas.cpp
+++ b/src/Canvas.cpp
@@ -164,6 +164,8 @@ struct GanvCanvasImpl {
void resize(double width, double height);
+ void set_zoom_and_font_size(double zoom, double points);
+
void for_each_node(GanvNodeFunction f, void* data);
void for_each_edge_from(const GanvNode* tail, GanvEdgeFunction f);
void for_each_edge_to(const GanvNode* head, GanvEdgeFunction f);
@@ -1371,6 +1373,27 @@ GanvCanvasImpl::resize(double width, double height)
}
}
+void
+GanvCanvasImpl::set_zoom_and_font_size(double zoom, double points)
+{
+ points = std::max(points, 1.0);
+ zoom = std::max(zoom, 0.01);
+
+ if (zoom == _zoom && points == _font_size)
+ return;
+
+ if (zoom != _zoom) {
+ _zoom = zoom;
+ ganv_canvas_base_set_pixels_per_unit(GANV_CANVAS_BASE(_gcanvas), zoom);
+ }
+
+ _font_size = points;
+
+ FOREACH_ITEM(_items, i) {
+ ganv_node_redraw_text(*i);
+ }
+}
+
namespace Ganv {
static gboolean
@@ -1432,24 +1455,7 @@ Canvas::set_font_size(double points)
void
Canvas::set_zoom_and_font_size(double zoom, double points)
{
- points = std::max(points, 1.0);
- zoom = std::max(zoom, 0.01);
-
- if (zoom == impl()->_zoom && points == impl()->_font_size)
- return;
-
- if (zoom != impl()->_zoom) {
- impl()->_zoom = zoom;
- ganv_canvas_base_set_pixels_per_unit(GANV_CANVAS_BASE(impl()->_gcanvas), zoom);
- }
-
- impl()->_font_size = points;
-
-#if 0
- FOREACH_ITEM(impl()->_items, i) {
- (*i)->redraw_text();
- }
-#endif
+ impl()->set_zoom_and_font_size(zoom, points);
}
void
@@ -1773,6 +1779,7 @@ enum {
PROP_WIDTH,
PROP_HEIGHT,
PROP_DIRECTION,
+ PROP_FONT_SIZE,
PROP_LOCKED
};
@@ -1805,14 +1812,12 @@ ganv_canvas_set_property(GObject* object,
case PROP_DIRECTION:
ganv_canvas_set_direction(canvas, (GanvDirection)g_value_get_enum(value));
break;
- case PROP_LOCKED: {
- const gboolean tmp = g_value_get_boolean(value);
- if (canvas->locked != tmp) {
- // TODO: change background color
- canvas->locked = tmp;
- }
+ case PROP_FONT_SIZE:
+ ganv_canvas_set_font_size(canvas, g_value_get_double(value));
+ break;
+ case PROP_LOCKED:
+ canvas->locked = g_value_get_boolean(value);
break;
- }
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
@@ -1887,6 +1892,15 @@ ganv_canvas_class_init(GanvCanvasClass* klass)
(GParamFlags)G_PARAM_READWRITE));
g_object_class_install_property(
+ gobject_class, PROP_FONT_SIZE, g_param_spec_double(
+ "font-size",
+ _("Font size"),
+ _("The default font size for the canvas"),
+ 0.0, G_MAXDOUBLE,
+ 12.0,
+ (GParamFlags)G_PARAM_READWRITE));
+
+ g_object_class_install_property(
gobject_class, PROP_LOCKED, g_param_spec_boolean(
"locked",
_("Locked"),
@@ -1952,13 +1966,13 @@ ganv_canvas_get_default_font_size(const GanvCanvas* canvas)
double
ganv_canvas_get_font_size(const GanvCanvas* canvas)
{
- return ganv_canvas_get_default_font_size(canvas);
+ return canvas->impl->_font_size;
}
void
ganv_canvas_set_font_size(GanvCanvas* canvas, double points)
{
- g_object_set(canvas, "font-size", points, NULL);
+ canvas->impl->set_zoom_and_font_size(canvas->impl->_zoom, points);
}
static void
diff --git a/src/module.c b/src/module.c
index 3dfcd13..bb1e832 100644
--- a/src/module.c
+++ b/src/module.c
@@ -76,8 +76,8 @@ ganv_module_destroy(GtkObject* object)
GanvModuleImpl* impl = module->impl;
if (impl->ports) {
- FOREACH_PORT(impl->ports, p) {
- g_object_unref(GTK_OBJECT(*p));
+ FOREACH_PORT(impl->ports, p) {
+ g_object_unref(GTK_OBJECT(*p));
}
g_ptr_array_free(impl->ports, TRUE);
impl->ports = NULL;
@@ -476,6 +476,18 @@ ganv_module_resize(GanvNode* self)
}
static void
+ganv_module_redraw_text(GanvNode* self)
+{
+ FOREACH_PORT(GANV_MODULE(self)->impl->ports, p) {
+ ganv_node_redraw_text(GANV_NODE(*p));
+ }
+
+ if (parent_class->parent_class.redraw_text) {
+ parent_class->parent_class.redraw_text(self);
+ }
+}
+
+static void
ganv_module_add_port(GanvModule* module,
GanvPort* port)
{
@@ -696,9 +708,10 @@ ganv_module_class_init(GanvModuleClass* class)
item_class->draw = ganv_module_draw;
item_class->point = ganv_module_point;
- node_class->move = ganv_module_move;
- node_class->move_to = ganv_module_move_to;
- node_class->resize = ganv_module_resize;
+ node_class->move = ganv_module_move;
+ node_class->move_to = ganv_module_move_to;
+ node_class->resize = ganv_module_resize;
+ node_class->redraw_text = ganv_module_redraw_text;
}
GanvModule*
diff --git a/src/node.c b/src/node.c
index 25afd90..7c4b0d1 100644
--- a/src/node.c
+++ b/src/node.c
@@ -362,6 +362,15 @@ ganv_node_default_resize(GanvNode* node)
}
}
+static void
+ganv_node_default_redraw_text(GanvNode* node)
+{
+ if (node->impl->label) {
+ ganv_text_layout(node->impl->label);
+ ganv_node_resize(node);
+ }
+}
+
static gboolean
ganv_node_default_event(GanvItem* item,
GdkEvent* event)
@@ -631,6 +640,7 @@ ganv_node_class_init(GanvNodeClass* class)
class->move = ganv_node_default_move;
class->move_to = ganv_node_default_move_to;
class->resize = ganv_node_default_resize;
+ class->redraw_text = ganv_node_default_redraw_text;
class->tick = ganv_node_default_tick;
class->tail_vector = ganv_node_default_tail_vector;
class->head_vector = ganv_node_default_head_vector;
@@ -728,6 +738,12 @@ ganv_node_resize(GanvNode* node)
}
void
+ganv_node_redraw_text(GanvNode* node)
+{
+ GANV_NODE_GET_CLASS(node)->redraw_text(node);
+}
+
+void
ganv_node_disconnect(GanvNode* node)
{
GANV_NODE_GET_CLASS(node)->disconnect(node);
diff --git a/src/text.c b/src/text.c
index 9d70051..06a29bc 100644
--- a/src/text.c
+++ b/src/text.c
@@ -86,7 +86,7 @@ ganv_text_destroy(GtkObject* object)
}
}
-static void
+void
ganv_text_layout(GanvText* text)
{
GanvTextImpl* impl = text->impl;