From f99047dc399877ef24826e40d38d5b5b9f8d0b6b Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 14 Feb 2015 09:26:46 +0000 Subject: Show type tags for more port types. git-svn-id: http://svn.drobilla.net/lad/trunk/ganv@5567 a436a847-0d15-0410-975c-d299462d15a1 --- src/ganv-private.h | 3 +- src/port.c | 101 ++++++++++++++++++++++++++++++----------------------- src/text.c | 27 ++++++++++---- 3 files changed, 81 insertions(+), 50 deletions(-) (limited to 'src') diff --git a/src/ganv-private.h b/src/ganv-private.h index a682dbb..eefeaa8 100644 --- a/src/ganv-private.h +++ b/src/ganv-private.h @@ -211,7 +211,6 @@ ganv_node_get_draw_properties(const GanvNode* node, typedef struct { GanvBox* rect; - GanvText* label; float value; float min; float max; @@ -221,6 +220,7 @@ typedef struct { struct _GanvPortImpl { GanvPortControl* control; + GanvText* value_label; gboolean is_input; gboolean is_controllable; }; @@ -241,6 +241,7 @@ struct _GanvTextImpl char* text; GanvTextCoords coords; GanvTextCoords old_coords; + double font_size; guint color; gboolean needs_layout; }; diff --git a/src/port.c b/src/port.c index 108dc45..4a4fcd2 100644 --- a/src/port.c +++ b/src/port.c @@ -25,7 +25,7 @@ #include "./ganv-private.h" #include "./gettext.h" -static const double PORT_LABEL_HPAD = 4.0; +static const double PORT_LABEL_HPAD = 2.0; static const double PORT_LABEL_VPAD = 1.0; static const guchar check_off[] = { 0xE2, 0x98, 0x90, 0 }; @@ -57,6 +57,8 @@ ganv_port_init(GanvPort* port) port->impl = G_TYPE_INSTANCE_GET_PRIVATE( port, GANV_TYPE_PORT, GanvPortImpl); + port->impl->control = NULL; + port->impl->value_label = NULL; port->impl->is_input = TRUE; port->impl->is_controllable = FALSE; } @@ -176,7 +178,7 @@ ganv_port_draw(GanvItem* item, GanvItem* labels[2] = { GANV_ITEM(GANV_NODE(item)->impl->label), - port->impl->control ? GANV_ITEM(port->impl->control->label) : NULL + port->impl->value_label ? GANV_ITEM(port->impl->value_label) : NULL }; for (int i = 0; i < 2; ++i) { if (labels[i] && (labels[i]->object.flags & GANV_ITEM_VISIBLE)) { @@ -255,23 +257,34 @@ ganv_port_head_vector(const GanvNode* self, } static void -ganv_port_place_value_label(GanvPort* port) -{ - GanvPortControl* control = port->impl->control; - if (control && control->label) { - GanvCanvas* canvas = ganv_item_get_canvas(GANV_ITEM(port)); - const double port_w = ganv_box_get_width(&port->box); - const double label_w = control->label->impl->coords.width; +ganv_port_place_labels(GanvPort* port) +{ + GanvCanvas* canvas = ganv_item_get_canvas(GANV_ITEM(port)); + GanvPortImpl* impl = port->impl; + GanvText* label = GANV_NODE(port)->impl->label; + const double port_w = ganv_box_get_width(&port->box); + const double port_h = ganv_box_get_height(&port->box); + double vlabel_w = 0.0; + if (impl->value_label) { + const double vlabel_h = impl->value_label->impl->coords.height; + vlabel_w = impl->value_label->impl->coords.width; if (ganv_canvas_get_direction(canvas) == GANV_DIRECTION_RIGHT) { - ganv_item_set(GANV_ITEM(control->label), - "x", port_w - label_w - PORT_LABEL_HPAD, - "y", PORT_LABEL_VPAD, + ganv_item_set(GANV_ITEM(impl->value_label), + "x", PORT_LABEL_HPAD, + "y", (port_h - vlabel_h) / 2.0, NULL); } else { - const double port_h = ganv_box_get_height(&port->box); - const double label_h = control->label->impl->coords.height; - ganv_item_set(GANV_ITEM(control->label), - "x", (port_w - label_w) / 2.0, + ganv_item_set(GANV_ITEM(impl->value_label), + "x", (port_w - vlabel_w) / 2.0, + "y", (port_h - vlabel_h) / 2.0, + NULL); + } + } + if (label) { + const double label_h = label->impl->coords.height; + if (ganv_canvas_get_direction(canvas) == GANV_DIRECTION_RIGHT) { + ganv_item_set(GANV_ITEM(label), + "x", vlabel_w + 2 * PORT_LABEL_HPAD, "y", (port_h - label_h) / 2.0, NULL); } @@ -284,7 +297,7 @@ ganv_port_resize(GanvNode* self) GanvPort* port = GANV_PORT(self); GanvNode* node = GANV_NODE(self); GanvText* label = node->impl->label; - GanvText* vlabel = port->impl->control ? port->impl->control->label : NULL; + GanvText* vlabel = port->impl->value_label; double label_w = 0.0; double label_h = 0.0; @@ -298,8 +311,11 @@ ganv_port_resize(GanvNode* self) } if (label || vlabel) { - ganv_box_set_width(&port->box, - label_w + vlabel_w + (PORT_LABEL_HPAD * 2.0)); + double labels_w = label_w + PORT_LABEL_HPAD * 2.0; + if (vlabel_w != 0.0) { + labels_w += vlabel_w + PORT_LABEL_HPAD; + } + ganv_box_set_width(&port->box, labels_w); ganv_box_set_height(&port->box, MAX(label_h, vlabel_h) + (PORT_LABEL_VPAD * 2.0)); ganv_item_set(GANV_ITEM(node->impl->label), @@ -317,13 +333,13 @@ static void ganv_port_redraw_text(GanvNode* node) { GanvPort* port = GANV_PORT(node); - if (port->impl->control && port->impl->control->label) { - ganv_text_layout(port->impl->control->label); - ganv_port_place_value_label(port); + if (port->impl->value_label) { + ganv_text_layout(port->impl->value_label); } if (GANV_NODE_CLASS(parent_class)->redraw_text) { (*GANV_NODE_CLASS(parent_class)->redraw_text)(node); } + ganv_port_place_labels(port); } static void @@ -334,8 +350,8 @@ ganv_port_set_width(GanvBox* box, parent_class->set_width(box, width); if (port->impl->control) { ganv_port_update_control_slider(port, port->impl->control->value, TRUE); - ganv_port_place_value_label(port); } + ganv_port_place_labels(port); } static void @@ -350,8 +366,8 @@ ganv_port_set_height(GanvBox* box, ganv_item_set(GANV_ITEM(port->impl->control->rect), "y2", control_y1 + height, NULL); - ganv_port_place_value_label(port); } + ganv_port_place_labels(port); } static gboolean @@ -490,7 +506,6 @@ ganv_port_show_control(GanvPort* port) control->max = 0.0f; control->is_toggle = FALSE; control->is_integer = FALSE; - control->label = NULL; control->rect = GANV_BOX( ganv_item_new(GANV_ITEM(port), ganv_box_get_type(), @@ -519,26 +534,26 @@ ganv_port_set_value_label(GanvPort* port, const char* str) { GanvPortImpl* impl = port->impl; - if (!impl->control) { - return; - } if (!str || str[0] == '\0') { - if (impl->control->label) { - gtk_object_destroy(GTK_OBJECT(impl->control->label)); - impl->control->label = NULL; + if (impl->value_label) { + gtk_object_destroy(GTK_OBJECT(impl->value_label)); + impl->value_label = NULL; } - } else if (impl->control->label) { - ganv_item_set(GANV_ITEM(impl->control->label), + } else if (impl->value_label) { + ganv_item_set(GANV_ITEM(impl->value_label), "text", str, NULL); } else { - impl->control->label = GANV_TEXT(ganv_item_new(GANV_ITEM(port), - ganv_text_get_type(), - "text", str, - "color", 0xFFFFFFFF, - "managed", TRUE, - NULL)); + GanvCanvas* canvas = GANV_ITEM(port)->impl->canvas; + const double points = lrint(ganv_canvas_get_font_size(canvas) * 0.8); + impl->value_label = GANV_TEXT(ganv_item_new(GANV_ITEM(port), + ganv_text_get_type(), + "text", str, + "font-size", points, + "color", 0xFFFFFFAA, + "managed", TRUE, + NULL)); ganv_port_resize(GANV_NODE(port)); } } @@ -678,12 +693,12 @@ ganv_port_get_natural_width(const GanvPort* port) } else { w = ganv_module_get_empty_port_depth(ganv_port_get_module(port)); } - if (port->impl->control && port->impl->control->label && - (GANV_ITEM(port->impl->control->label)->object.flags + if (port->impl->value_label && + (GANV_ITEM(port->impl->value_label)->object.flags & GANV_ITEM_VISIBLE)) { double label_w; - g_object_get(port->impl->control->label, "width", &label_w, NULL); - w += (PORT_LABEL_HPAD * 4.0); + g_object_get(port->impl->value_label, "width", &label_w, NULL); + w += label_w + PORT_LABEL_HPAD; } return w; } diff --git a/src/text.c b/src/text.c index 6dda2e1..bfc7d0b 100644 --- a/src/text.c +++ b/src/text.c @@ -39,7 +39,8 @@ enum { PROP_Y, PROP_WIDTH, PROP_HEIGHT, - PROP_COLOR + PROP_COLOR, + PROP_FONT_SIZE }; static void @@ -53,10 +54,11 @@ ganv_text_init(GanvText* text) memset(&impl->coords, '\0', sizeof(GanvTextCoords)); impl->coords.width = 1.0; impl->coords.height = 1.0; - impl->old_coords = impl->coords; + impl->old_coords = impl->coords; impl->layout = NULL; impl->text = NULL; + impl->font_size = 0.0; impl->color = 0xFFFFFFFF; impl->needs_layout = FALSE; } @@ -92,9 +94,13 @@ ganv_text_layout(GanvText* text) GanvItem* item = GANV_ITEM(text); GanvCanvas* canvas = ganv_item_get_canvas(item); GtkWidget* widget = GTK_WIDGET(canvas); - double points = ganv_canvas_get_font_size(canvas); + double points = impl->font_size; GtkStyle* style = gtk_rc_get_style(widget); + if (impl->font_size == 0.0) { + points = ganv_canvas_get_font_size(canvas); + } + if (impl->layout) { g_object_unref(impl->layout); } @@ -139,6 +145,7 @@ ganv_text_set_property(GObject* object, SET_CASE(WIDTH, double, impl->coords.width); SET_CASE(HEIGHT, double, impl->coords.height); SET_CASE(COLOR, uint, impl->color) + SET_CASE(FONT_SIZE, double, impl->font_size) case PROP_TEXT: free(impl->text); impl->text = g_value_dup_string(value); @@ -272,10 +279,8 @@ ganv_text_draw(GanvItem* item, ganv_text_layout(text); } - guint color = 0xFFFFFFFF; - double r, g, b, a; - color_to_rgba(color, &r, &g, &b, &a); + color_to_rgba(impl->color, &r, &g, &b, &a); cairo_set_source_rgba(cr, r, g, b, a); cairo_move_to(cr, wx, wy); @@ -349,6 +354,16 @@ ganv_text_class_init(GanvTextClass* klass) DEFAULT_TEXT_COLOR, G_PARAM_READWRITE)); + g_object_class_install_property( + gobject_class, PROP_FONT_SIZE, g_param_spec_double( + "font-size", + _("Font size"), + _("The font size in points."), + -G_MAXDOUBLE, G_MAXDOUBLE, + 0.0, + G_PARAM_READWRITE)); + + object_class->destroy = ganv_text_destroy; item_class->update = ganv_text_update; -- cgit v1.2.1