static void create_width_for_height_table (GooCanvasItem *root, gdouble x, gdouble y, gdouble width, gdouble height, gdouble rotation) { GooCanvasItem *table, *item; gchar *text = "This is a long paragraph that will have to be split over a few lines so we can see if its allocated height changes when its allocated width is changed."; table = goo_canvas_table_new (root, #if 1 "width", width, "height", height, #endif NULL); goo_canvas_item_translate (table, x, y); goo_canvas_item_rotate (table, rotation, 0, 0); item = goo_canvas_rect_new (table, 0.0, 0.0, width - 2, 10.0, "fill-color", "red", NULL); goo_canvas_item_set_child_properties (table, item, "row", 0, "column", 0, "x-shrink", TRUE, NULL); #if 1 item = goo_canvas_text_new (table, text, 0, 0, -1, GOO_CANVAS_ANCHOR_NW, NULL); goo_canvas_item_set_child_properties (table, item, "row", 1, "column", 0, "x-expand", TRUE, "x-fill", TRUE, "x-shrink", TRUE, "y-expand", TRUE, "y-fill", TRUE, NULL); g_object_set_data (G_OBJECT (item), "id", "Text Item"); g_signal_connect (item, "button_press_event", G_CALLBACK (on_button_press), NULL); #endif item = goo_canvas_rect_new (table, 0.0, 0.0, width - 2, 10.0, "fill-color", "red", NULL); goo_canvas_item_set_child_properties (table, item, "row", 2, "column", 0, "x-shrink", TRUE, NULL); }
static void create_demo_table (GooCanvasItem *root, gdouble x, gdouble y, gdouble width, gdouble height) { GooCanvasItem *table, *square, *circle, *triangle; table = goo_canvas_table_new (root, "row-spacing", 4.0, "column-spacing", 4.0, "width", width, "height", height, NULL); goo_canvas_item_translate (table, x, y); square = goo_canvas_rect_new (table, 0.0, 0.0, 50.0, 50.0, "fill-color", "red", NULL); goo_canvas_item_set_child_properties (table, square, "row", 0, "column", 0, "x-shrink", TRUE, NULL); g_object_set_data (G_OBJECT (square), "id", "Red square"); g_signal_connect (square, "button_press_event", G_CALLBACK (on_button_press), NULL); circle = goo_canvas_ellipse_new (table, 0.0, 0.0, 25.0, 25.0, "fill-color", "blue", NULL); goo_canvas_item_set_child_properties (table, circle, "row", 0, "column", 1, "x-shrink", TRUE, NULL); g_object_set_data (G_OBJECT (circle), "id", "Blue circle"); g_signal_connect (circle, "button_press_event", G_CALLBACK (on_button_press), NULL); triangle = goo_canvas_polyline_new (table, TRUE, 3, 25.0, 0.0, 0.0, 50.0, 50.0, 50.0, "fill-color", "yellow", NULL); goo_canvas_item_set_child_properties (table, triangle, "row", 0, "column", 2, "x-shrink", TRUE, NULL); g_object_set_data (G_OBJECT (triangle), "id", "Yellow triangle"); g_signal_connect (triangle, "button_press_event", G_CALLBACK (on_button_press), NULL); }
static VALUE rg_set_child_property(VALUE self, VALUE child, VALUE prop_name, VALUE val) { GParamSpec* pspec; const char* name; if (SYMBOL_P(prop_name)) { name = rb_id2name(SYM2ID(prop_name)); } else { StringValue(prop_name); name = StringValuePtr(prop_name); } pspec = goo_canvas_item_class_find_child_property(G_OBJECT_GET_CLASS(RVAL2GOBJ(self)), name); if (!pspec) rb_raise(rb_eRuntimeError, "No such child property: %s", name); #define _SET_PROP_FOR_TYPE(gtype, ctype, val) \ case gtype: \ goo_canvas_item_set_child_properties(SELF(self), SELF(child), name, (ctype)(val), NULL); \ break; switch (G_TYPE_FUNDAMENTAL(G_PARAM_SPEC_VALUE_TYPE(pspec))) { _SET_PROP_FOR_TYPE(G_TYPE_CHAR, gchar, NUM2INT(val)); _SET_PROP_FOR_TYPE(G_TYPE_UCHAR, guchar, NUM2INT(val)); _SET_PROP_FOR_TYPE(G_TYPE_BOOLEAN, gboolean, RTEST(val)); _SET_PROP_FOR_TYPE(G_TYPE_INT, gint, NUM2INT(val)); _SET_PROP_FOR_TYPE(G_TYPE_UINT, guint, NUM2UINT(val)); _SET_PROP_FOR_TYPE(G_TYPE_LONG, glong, NUM2LONG(val)); _SET_PROP_FOR_TYPE(G_TYPE_ULONG, gulong, NUM2ULONG(val)); _SET_PROP_FOR_TYPE(G_TYPE_INT64, gint64, rbglib_num_to_int64(val)); _SET_PROP_FOR_TYPE(G_TYPE_UINT64, guint64, rbglib_num_to_uint64(val)); _SET_PROP_FOR_TYPE(G_TYPE_ENUM, gint, rbgobj_get_enum(val, G_PARAM_SPEC_VALUE_TYPE(pspec))); _SET_PROP_FOR_TYPE(G_TYPE_FLAGS, guint, rbgobj_get_flags(val, G_PARAM_SPEC_VALUE_TYPE(pspec))); _SET_PROP_FOR_TYPE(G_TYPE_FLOAT, gfloat, NUM2DBL(val)); _SET_PROP_FOR_TYPE(G_TYPE_DOUBLE, gdouble, NUM2DBL(val)); case G_TYPE_STRING: { if (SYMBOL_P(val)) val = rb_funcall(val, rb_intern("to_s"), 0); goo_canvas_item_set_child_properties(SELF(self), SELF(child), name, StringValuePtr(val), NULL); break; } default: g_warning("rb_goo_canvas_item_set_child_property: unsupported type: %s\n", g_type_name(G_PARAM_SPEC_VALUE_TYPE(pspec))); return Qnil; } #undef _SET_PROP_FOR_TYPE G_CHILD_ADD(child, val); return self; }
/** * ppg_instrument_view_visualizer_added: * @view: (in): A #PpgInstrumentView. * * Handle the "visualizer-added" event for the #PpgInstrument. Add the * visualizer to our table of visualizers. * * Returns: None. * Side effects: None. */ static void ppg_instrument_view_visualizer_added (PpgInstrumentView *view, PpgVisualizer *visualizer, PpgInstrument *instrument) { PpgInstrumentViewPrivate *priv; GooCanvasItem *item = (GooCanvasItem *)visualizer; gdouble width; g_return_if_fail(PPG_IS_INSTRUMENT_VIEW(view)); g_return_if_fail(PPG_IS_VISUALIZER(visualizer)); g_return_if_fail(PPG_IS_INSTRUMENT(instrument)); priv = view->priv; g_object_get(view, "width", &width, NULL); width = MAX(200.0, width - HEADER_WIDTH); g_object_set(item, "parent", priv->table, "width", width, "visibility", GOO_CANVAS_ITEM_VISIBLE, NULL); g_object_bind_property_full(view, "width", item, "width", 0, ppg_instrument_view_transform_width, NULL, NULL, NULL); goo_canvas_item_set_child_properties(priv->table, item, "bottom-padding", ROW_SPACING, "column", 0, "row", priv->visualizers->len, NULL); g_ptr_array_add(priv->visualizers, visualizer); g_signal_connect_swapped(visualizer, "notify::natural-height", G_CALLBACK(ppg_instrument_view_notify_natural_height), view); ppg_instrument_view_relayout(view); }
static void create_demo_item (GooCanvasItem *table, gint demo_item_type, gint row, gint column, gint rows, gint columns, gchar *text, gdouble width, gdouble xalign, gdouble yalign, PangoAlignment text_alignment) { GooCanvasItem *item = NULL; GtkWidget *widget; GValue value = { 0 }; guint new_row; switch (demo_item_type) { case DEMO_RECT_ITEM: item = goo_canvas_rect_new (table, 0, 0, 38, 19, "fill-color", "red", NULL); break; case DEMO_TEXT_ITEM: case DEMO_TEXT_ITEM_2: case DEMO_TEXT_ITEM_3: item = goo_canvas_text_new (table, text, 0, 0, width, GOO_CANVAS_ANCHOR_NW, "alignment", text_alignment, NULL); break; case DEMO_WIDGET_ITEM: widget = gtk_button_new_with_label (text); item = goo_canvas_widget_new (table, widget, 0, 0, -1, -1, NULL); break; } g_value_init (&value, G_TYPE_UINT); g_value_set_uint (&value, row); goo_canvas_item_set_child_property (table, item, "row", &value); g_value_set_uint (&value, column); goo_canvas_item_set_child_property (table, item, "column", &value); g_value_set_uint (&value, rows); goo_canvas_item_set_child_property (table, item, "rows", &value); g_value_set_uint (&value, columns); goo_canvas_item_set_child_property (table, item, "columns", &value); goo_canvas_item_set_child_properties (table, item, "x-expand", TRUE, "y-expand", TRUE, "x-align", xalign, "y-align", yalign, NULL); /* Test the get function. */ goo_canvas_item_get_child_property (table, item, "row", &value); new_row = g_value_get_uint (&value); if (new_row != row) g_warning ("Got bad row setting: %i should be: %i\n", new_row, row); /* If we make the item's fill the cells then alignment can't be used. */ #if 0 goo_canvas_item_set_child_properties (table, item, "x-fill", TRUE, "y-fill", TRUE, NULL); #endif g_object_set_data (G_OBJECT (item), "id", text); g_signal_connect (item, "button_press_event", G_CALLBACK (on_button_press), NULL); }
static GooCanvasItem* create_table (GooCanvasItem *parent, gint row, gint column, gint embedding_level, gdouble x, gdouble y, gdouble rotation, gdouble scale, gint demo_item_type, gboolean show_grid_lines) { GooCanvasItem *table; /* Add a few simple items. */ table = goo_canvas_table_new (parent, "row-spacing", 4.0, "column-spacing", 4.0, NULL); if (show_grid_lines) g_object_set (table, "horz-grid-line-width", 1.0f, "vert-grid-line-width", 1.0f, NULL); goo_canvas_item_translate (table, x, y); #if 1 goo_canvas_item_rotate (table, rotation, 0, 0); #endif #if 1 goo_canvas_item_scale (table, scale, scale); #endif if (row != -1) goo_canvas_item_set_child_properties (parent, table, "row", row, "column", column, #if 1 "x-expand", TRUE, "x-fill", TRUE, #endif #if 0 "y-expand", TRUE, "y-fill", TRUE, #endif NULL); if (embedding_level) { gint level = embedding_level - 1; create_table (table, 0, 0, level, 50, 50, 0, 0.7, demo_item_type, show_grid_lines); create_table (table, 0, 1, level, 50, 50, 45, 1.0, demo_item_type, show_grid_lines); create_table (table, 0, 2, level, 50, 50, 90, 1.0, demo_item_type, show_grid_lines); create_table (table, 1, 0, level, 50, 50, 135, 1.0, demo_item_type, show_grid_lines); create_table (table, 1, 1, level, 50, 50, 180, 1.5, demo_item_type, show_grid_lines); create_table (table, 1, 2, level, 50, 50, 225, 1.0, demo_item_type, show_grid_lines); create_table (table, 2, 0, level, 50, 50, 270, 1.0, demo_item_type, show_grid_lines); create_table (table, 2, 1, level, 50, 50, 315, 1.0, demo_item_type, show_grid_lines); create_table (table, 2, 2, level, 50, 50, 360, 2.0, demo_item_type, show_grid_lines); } else if (demo_item_type == DEMO_TEXT_ITEM_2) { create_demo_item (table, demo_item_type, 0, 0, 1, 1, "(0.0,0.0)\nleft\naligned", -1, 0, 0, PANGO_ALIGN_LEFT); create_demo_item (table, demo_item_type, 0, 1, 1, 1, "(0.5,0.0)\ncenter\naligned", -1, 0.5, 0, PANGO_ALIGN_CENTER); create_demo_item (table, demo_item_type, 0, 2, 1, 1, "(1.0,0.0)\nright\naligned", -1, 1, 0, PANGO_ALIGN_RIGHT); /* The layout width shouldn't really make any difference in this test. */ create_demo_item (table, demo_item_type, 1, 0, 1, 1, "(0.5,0.5)\ncenter\naligned", 50, 0.5, 0.5, PANGO_ALIGN_CENTER); create_demo_item (table, demo_item_type, 1, 1, 1, 1, "(0.0,1.0)\nright\naligned", 100, 0, 1.0, PANGO_ALIGN_RIGHT); create_demo_item (table, demo_item_type, 1, 2, 1, 1, "(0.0,0.5)\nleft\naligned", 200, 0, 0.5, PANGO_ALIGN_LEFT); create_demo_item (table, demo_item_type, 2, 0, 1, 1, "(1.0,1.0)\ncenter\naligned", -1, 1, 1, PANGO_ALIGN_CENTER); create_demo_item (table, demo_item_type, 2, 1, 1, 1, "(1,0.5)\nright\naligned", -1, 1.0, 0.5, PANGO_ALIGN_RIGHT); create_demo_item (table, demo_item_type, 2, 2, 1, 1, "(0.0,0.0)\nleft\naligned", -1, 0, 0, PANGO_ALIGN_LEFT); } else if (demo_item_type == DEMO_TEXT_ITEM_3) { create_demo_item (table, demo_item_type, 0, 0, 1, 1, "width 50 align 0.0, 0.0 text left aligned", 50, 0, 0, PANGO_ALIGN_LEFT); create_demo_item (table, demo_item_type, 0, 1, 1, 1, "width 100 align 0.5, 0.0 text center aligned", 100, 0.5, 0, PANGO_ALIGN_CENTER); create_demo_item (table, demo_item_type, 0, 2, 1, 1, "width 150 align 1.0, 0.0 text right aligned", 150, 1, 0, PANGO_ALIGN_RIGHT); create_demo_item (table, demo_item_type, 1, 0, 1, 1, "width 50 align 0.5, 0.5 text center aligned", 50, 0.5, 0.5, PANGO_ALIGN_CENTER); create_demo_item (table, demo_item_type, 1, 1, 1, 1, "width 100 align 0.0, 1.0 text right aligned", 100, 0, 1.0, PANGO_ALIGN_RIGHT); create_demo_item (table, demo_item_type, 1, 2, 1, 1, "width 200 align 0.0, 0.5 text left aligned", 200, 0, 0.5, PANGO_ALIGN_LEFT); create_demo_item (table, demo_item_type, 2, 0, 1, 1, "width 50 align 1.0, 1.0 text center aligned", 50, 1, 1, PANGO_ALIGN_CENTER); create_demo_item (table, demo_item_type, 2, 1, 1, 1, "width 100 align 1, 0.5 text right aligned", 100, 1.0, 0.5, PANGO_ALIGN_RIGHT); create_demo_item (table, demo_item_type, 2, 2, 1, 1, "width 50 align 0.0, 0.0 text left aligned", 50, 0, 0, PANGO_ALIGN_LEFT); } else { create_demo_item (table, demo_item_type, 0, 0, 1, 1, "(0,0)", -1, 0, 0.5, PANGO_ALIGN_LEFT); create_demo_item (table, demo_item_type, 0, 1, 1, 1, "(1,0)", -1, 0, 0.5, PANGO_ALIGN_LEFT); create_demo_item (table, demo_item_type, 0, 2, 1, 1, "(2,0)", -1, 0, 0.5, PANGO_ALIGN_LEFT); create_demo_item (table, demo_item_type, 1, 0, 1, 1, "(0,1)", -1, 0, 0.5, PANGO_ALIGN_LEFT); create_demo_item (table, demo_item_type, 1, 1, 1, 1, "(1,1)", -1, 0, 0.5, PANGO_ALIGN_LEFT); create_demo_item (table, demo_item_type, 1, 2, 1, 1, "(2,1)", -1, 0, 0.5, PANGO_ALIGN_LEFT); create_demo_item (table, demo_item_type, 2, 0, 1, 1, "(0,2)", -1, 0, 0.5, PANGO_ALIGN_LEFT); create_demo_item (table, demo_item_type, 2, 1, 1, 1, "(1,2)", -1, 0, 0.5, PANGO_ALIGN_LEFT); create_demo_item (table, demo_item_type, 2, 2, 1, 1, "(2,2)", -1, 0, 0.5, PANGO_ALIGN_LEFT); } return table; }
/** * ppg_instrument_view_relayout: * @view: (in): A #PpgInstrumentView. * * Relayout the visualizer items within the instrument view, taking into * account zooms and natural-heights as well as our minimum heights. * * Returns: None. * Side effects: None. */ static void ppg_instrument_view_relayout (PpgInstrumentView *view) { PpgInstrumentViewPrivate *priv; GooCanvasItemVisibility visibility; GooCanvasBounds b; PpgVisualizer *visualizer; gdouble natural_height; gdouble height = 0.0; gdouble extra; gint n_visible = 0; gint i; g_return_if_fail(PPG_IS_INSTRUMENT_VIEW(view)); priv = view->priv; /* * Determine how much vertical space we think we need. */ for (i = 0; i < priv->visualizers->len; i++) { visualizer = g_ptr_array_index(priv->visualizers, i); g_object_get(visualizer, "visibility", &visibility, NULL); if (visibility != GOO_CANVAS_ITEM_HIDDEN) { n_visible++; natural_height = ppg_visualizer_get_natural_height(visualizer); natural_height *= priv->zoom; height += natural_height + 1.0; g_object_set(visualizer, "height", natural_height, NULL); } } if (height == 0.0) { /* * No more items to visualize, lets shrink down extra small. */ goo_canvas_item_get_bounds(priv->header_text, &b); natural_height = b.y2 - b.y1; g_object_set(view, "height", natural_height + 2.0, NULL); g_object_set(priv->header_bg, "height", natural_height + 2.0, NULL); } else if (height < DEFAULT_HEIGHT) { /* * We need less than the header column requires, so lets grow to space * them all out evenly. */ extra = (DEFAULT_HEIGHT - height) / (gdouble)n_visible; for (i = 0; i < priv->visualizers->len; i++) { visualizer = g_ptr_array_index(priv->visualizers, i); natural_height = ppg_visualizer_get_natural_height(visualizer); natural_height *= priv->zoom; natural_height += extra; g_object_set(visualizer, "height", natural_height, NULL); } g_object_set(view, "height", DEFAULT_HEIGHT, NULL); } else { g_object_set(view, "height", height, NULL); } goo_canvas_item_set_child_properties(GOO_CANVAS_ITEM(view), priv->header_text, "top-padding", height == 0.0 ? 1.0 : 15.0, NULL); g_object_notify(G_OBJECT(view), "height"); }
/** * ppg_instrument_view_init: * @view: (in): A #PpgInstrumentView. * * Initializes the newly created #PpgInstrumentView instance. * * Returns: None. * Side effects: None. */ static void ppg_instrument_view_init (PpgInstrumentView *view) { PpgInstrumentViewPrivate *priv; GooCanvasItem *parent = (GooCanvasItem *)view; priv = G_TYPE_INSTANCE_GET_PRIVATE(view, PPG_TYPE_INSTRUMENT_VIEW, PpgInstrumentViewPrivate); view->priv = priv; g_object_set(view, "height", DEFAULT_HEIGHT, NULL); priv->state = GTK_STATE_NORMAL; priv->visualizers = g_ptr_array_new(); priv->zoom = 1; priv->header_bg = g_object_new(GOO_TYPE_CANVAS_IMAGE, "width", HEADER_WIDTH - 1.0, "height", DEFAULT_HEIGHT, "parent", parent, NULL); goo_canvas_item_set_child_properties(parent, priv->header_bg, "row", 0, "column", 0, NULL); g_object_bind_property(view, "height", priv->header_bg, "height", 0); priv->header_text = g_object_new(GOO_TYPE_CANVAS_TEXT, "alignment", PANGO_ALIGN_LEFT, "font", "Sans 10", "parent", parent, "text", "XXX", NULL); goo_canvas_item_set_child_properties(parent, priv->header_text, "left-padding", 15.0, "column", 0, "row", 0, "top-padding", 15.0, "x-fill", TRUE, "y-fill", TRUE, NULL); priv->bar = g_object_new(GOO_TYPE_CANVAS_RECT, "fill-color", "#000000", "height", DEFAULT_HEIGHT, "line-width", 0.0, "parent", parent, "width", 1.0, NULL); goo_canvas_item_set_child_properties(parent, priv->bar, "column", 1, "row", 0, NULL); g_object_bind_property(view, "height", priv->bar, "height", 0); priv->table = g_object_new(GOO_TYPE_CANVAS_TABLE, "parent", parent, "width", 200.0, NULL); goo_canvas_item_set_child_properties(parent, priv->table, "row", 0, "column", 2, "y-expand", TRUE, "y-fill", TRUE, NULL); g_object_bind_property_full(view, "width", priv->table, "width", 0, ppg_instrument_view_transform_width, NULL, NULL, NULL); }