Пример #1
0
static void
add_controlled_toggle (RutPropInspector *inspector,
                       RutProperty *prop)
{
  RutBin *bin;
  RutIconToggle *toggle;

  bin = rut_bin_new (inspector->context);
  rut_bin_set_right_padding (bin, 5);
  rut_box_layout_add (inspector->top_hbox, false, bin);
  rut_refable_unref (bin);

  toggle = rut_icon_toggle_new (inspector->context,
                                "record-button-selected.png",
                                "record-button.png");

  rut_icon_toggle_set_state (toggle, false);

  rut_icon_toggle_add_on_toggle_callback (toggle,
                                          controlled_toggle_cb,
                                          inspector,
                                          NULL /* destroy_cb */);

  rut_bin_set_child (bin, toggle);
  rut_refable_unref (toggle);

  inspector->controlled_toggle = toggle;
}
Пример #2
0
static void
add_control (RutPropInspector *inspector,
             RutProperty *prop,
             bool with_label)
{
  RutProperty *widget_prop;
  RutObject *widget;
  const char *label_text;

  widget = create_widget_for_property (inspector->context,
                                       prop,
                                       &widget_prop,
                                       &label_text);

  if (!widget)
    return;

  if (with_label && label_text)
    {
      RutText *label =
        rut_text_new_with_text (inspector->context,
                                NULL, /* font_name */
                                label_text);
      rut_text_set_selectable (label, FALSE);
      rut_box_layout_add (inspector->widget_hbox, false, label);
      rut_refable_unref (label);
    }

  if (!(inspector->target_prop->spec->flags & RUT_PROPERTY_FLAG_WRITABLE))
    set_disabled (inspector, DISABLED_STATE_WIDGET);

  rut_box_layout_add (inspector->widget_hbox, true, widget);
  rut_refable_unref (widget);

  if (widget_prop)
    {
      inspector->inspector_prop_closure =
        rut_property_connect_callback (widget_prop,
                                       inspector_property_changed_cb,
                                       inspector);
      inspector->widget_prop = widget_prop;
    }
}
Пример #3
0
void
rut_fold_set_header_child(rut_fold_t *fold, rut_object_t *child)
{
    c_return_if_fail(rut_object_get_type(fold) == &rut_fold_type);

    if (child)
        rut_object_claim(child, fold);

    if (fold->header_child) {
        rut_box_layout_remove(fold->header_hbox_right, fold->header_child);
        rut_object_release(fold->header_child, fold);
    }

    fold->header_child = child;
    rut_box_layout_add(fold->header_hbox_right, true, child);
}
Пример #4
0
void
rut_fold_set_header_child (RutFold *fold, RutObject *child)
{
  g_return_if_fail (rut_object_get_type (fold) == &rut_fold_type);

  if (child)
    rut_refable_claim (child, fold);

  if (fold->header_child)
    {
      rut_box_layout_remove (fold->header_hbox_right, fold->header_child);
      rut_refable_release (fold->header_child, fold);
    }

  fold->header_child = child;
  rut_box_layout_add (fold->header_hbox_right, TRUE, child);
}
Пример #5
0
void
rut_fold_set_child(rut_fold_t *fold, rut_object_t *child)
{
    c_return_if_fail(rut_object_get_type(fold) == &rut_fold_type);

    if (child)
        rut_object_claim(child, fold);

    if (fold->child) {
        if (!fold->folded)
            rut_box_layout_remove(fold->vbox, fold->child);
        rut_object_release(fold->child, fold);
    }

    fold->child = child;
    if (child && !fold->folded)
        rut_box_layout_add(fold->vbox, true, child);
}
Пример #6
0
void
rut_fold_set_child (RutFold *fold, RutObject *child)
{
  g_return_if_fail (rut_object_get_type (fold) == &rut_fold_type);

  if (child)
    rut_refable_claim (child, fold);

  if (fold->child)
    {
      if (!fold->folded)
        rut_box_layout_remove (fold->vbox, fold->child);
      rut_refable_release (fold->child, fold);
    }

  fold->child = child;
  if (child && !fold->folded)
    rut_box_layout_add (fold->vbox, TRUE, child);
}
Пример #7
0
void
rut_fold_set_folded(rut_fold_t *fold, bool folded)
{
    if (fold->folded == folded || fold->child == NULL)
        return;

    if (folded) {
        rut_fixed_remove_child(fold->fold_icon_shim, fold->fold_down_icon);
        rut_fixed_add_child(fold->fold_icon_shim, fold->fold_up_icon);
        rut_box_layout_remove(fold->vbox, fold->child);
    } else {
        rut_fixed_remove_child(fold->fold_icon_shim, fold->fold_up_icon);
        rut_fixed_add_child(fold->fold_icon_shim, fold->fold_down_icon);
        rut_box_layout_add(fold->vbox, true, fold->child);
    }

    fold->folded = folded;

    rut_shell_queue_redraw(fold->shell);
}
Пример #8
0
void
rut_fold_set_folded (RutFold *fold, CoglBool folded)
{
  if (fold->folded == folded || fold->child == NULL)
    return;

  if (folded)
    {
      rut_fixed_remove_child (fold->fold_icon_shim, fold->fold_down_icon);
      rut_fixed_add_child (fold->fold_icon_shim, fold->fold_up_icon);
      rut_box_layout_remove (fold->vbox, fold->child);
    }
  else
    {
      rut_fixed_remove_child (fold->fold_icon_shim, fold->fold_up_icon);
      rut_fixed_add_child (fold->fold_icon_shim, fold->fold_down_icon);
      rut_box_layout_add (fold->vbox, TRUE, fold->child);
    }

  fold->folded = folded;

  rut_shell_queue_redraw (fold->context->shell);
}
Пример #9
0
RutIconButton *
rut_icon_button_new (RutContext *ctx,
                     const char *label,
                     RutIconButtonPosition label_position,
                     const char *normal_icon,
                     const char *hover_icon,
                     const char *active_icon,
                     const char *disabled_icon)
{
  RutIconButton *button = g_slice_new0 (RutIconButton);
  float natural_width, natural_height;
  static CoglBool initialized = FALSE;

  if (initialized == FALSE)
    {
      _rut_icon_button_init_type ();
      initialized = TRUE;
    }

  rut_object_init (RUT_OBJECT (button), &rut_icon_button_type);

  button->ref_count = 1;

  rut_list_init (&button->on_click_cb_list);

  rut_graphable_init (RUT_OBJECT (button));
  rut_paintable_init (RUT_OBJECT (button));

  button->ctx = ctx;

  button->state = ICON_BUTTON_STATE_NORMAL;

  button->stack = rut_stack_new (ctx, 100, 100);

  button->layout = rut_box_layout_new (ctx, RUT_BOX_LAYOUT_PACKING_TOP_TO_BOTTOM);
  rut_stack_add (button->stack, button->layout);
  rut_refable_unref (button->layout);

  button->bin = rut_bin_new (ctx);
  rut_box_layout_add (button->layout, TRUE, button->bin);
  rut_refable_unref (button->bin);

  button->label_position = label_position;

  if (label)
    {
      RutBin *bin = rut_bin_new (ctx);

      rut_bin_set_x_position (bin, RUT_BIN_POSITION_CENTER);

      button->label = rut_text_new_with_text (ctx, NULL, label);
      rut_bin_set_child (bin, button->label);

      rut_box_layout_add (button->layout, FALSE, bin);
      rut_refable_unref (bin);

      update_layout (button);
    }

  rut_icon_button_set_normal (button, normal_icon);
  rut_icon_button_set_hover (button, hover_icon);
  rut_icon_button_set_active (button, active_icon);
  rut_icon_button_set_disabled (button, disabled_icon);

  button->input_region =
    rut_input_region_new_rectangle (0, 0, 100, 100,
                                    _rut_icon_button_input_cb,
                                    button);
  rut_stack_add (button->stack, button->input_region);
  rut_refable_unref (button->input_region);

  rut_sizable_get_preferred_width (button->stack, -1, NULL,
                                   &natural_width);
  rut_sizable_get_preferred_height (button->stack, natural_width, NULL,
                                    &natural_height);
  rut_sizable_set_size (button->stack, natural_width, natural_height);

  rut_graphable_add_child (button, button->stack);

  return button;
}
Пример #10
0
RutPropInspector *
rut_prop_inspector_new (RutContext *ctx,
                        RutProperty *property,
                        RutPropInspectorCallback inspector_property_changed_cb,
                        RutPropInspectorControlledCallback inspector_controlled_cb,
                        bool with_label,
                        void *user_data)
{
  RutPropInspector *inspector =
    rut_object_alloc0 (RutPropInspector,
                       &rut_prop_inspector_type,
                       _rut_prop_inspector_init_type);
  RutBin *grab_padding;

  inspector->ref_count = 1;
  inspector->context = ctx;

  rut_graphable_init (inspector);

  inspector->target_prop = property;
  inspector->inspector_property_changed_cb = inspector_property_changed_cb;
  inspector->controlled_changed_cb = inspector_controlled_cb;
  inspector->user_data = user_data;

  inspector->top_stack = rut_stack_new (ctx, 1, 1);
  rut_graphable_add_child (inspector, inspector->top_stack);
  rut_refable_unref (inspector->top_stack);

  inspector->top_hbox = rut_box_layout_new (ctx, RUT_BOX_LAYOUT_PACKING_LEFT_TO_RIGHT);
  rut_stack_add (inspector->top_stack, inspector->top_hbox);
  rut_refable_unref (inspector->top_hbox);

  /* XXX: Hack for now, to make sure its possible to drag and drop any
   * property without inadvertanty manipulating the property value...
   */
  grab_padding = rut_bin_new (inspector->context);
  rut_bin_set_right_padding (grab_padding, 15);
  rut_box_layout_add (inspector->top_hbox, false, grab_padding);
  rut_refable_unref (grab_padding);

  if (inspector->controlled_changed_cb && property->spec->animatable)
    add_controlled_toggle (inspector, property);

  inspector->widget_stack = rut_stack_new (ctx, 1, 1);
  rut_box_layout_add (inspector->top_hbox, true, inspector->widget_stack);
  rut_refable_unref (inspector->widget_stack);

  inspector->widget_hbox =
    rut_box_layout_new (inspector->context, RUT_BOX_LAYOUT_PACKING_LEFT_TO_RIGHT);
  rut_stack_add (inspector->widget_stack, inspector->widget_hbox);
  rut_refable_unref (inspector->widget_hbox);

  inspector->disabled_overlay =
    rut_rectangle_new4f (ctx, 1, 1, 0.5, 0.5, 0.5, 0.5);
  inspector->input_region =
    rut_input_region_new_rectangle (0, 0, 1, 1, block_input_cb, NULL);

  add_control (inspector, property, with_label);

  rut_prop_inspector_reload_property (inspector);

  rut_sizable_set_size (inspector, 10, 10);

  inspector->target_prop_closure =
    rut_property_connect_callback (property,
                                   target_property_changed_cb,
                                   inspector);

  return inspector;
}
Пример #11
0
rut_fold_t *
rut_fold_new(rut_shell_t *shell, const char *label)
{
    rut_fold_t *fold =
        rut_object_alloc0(rut_fold_t, &rut_fold_type, _rut_fold_init_type);
    rut_box_layout_t *header_hbox;
    rut_stack_t *left_header_stack;
    rut_box_layout_t *left_header_hbox;
    rut_bin_t *label_bin;
    rut_bin_t *fold_icon_align;
    cg_texture_t *texture;
    cg_color_t black;

    fold->shell = shell;

    rut_graphable_init(fold);

    rig_introspectable_init(fold, _rut_fold_prop_specs, fold->properties);

    fold->vbox = rut_box_layout_new(shell,
                                    RUT_BOX_LAYOUT_PACKING_TOP_TO_BOTTOM);

    header_hbox = rut_box_layout_new(shell,
                                     RUT_BOX_LAYOUT_PACKING_LEFT_TO_RIGHT);
    rut_box_layout_add(fold->vbox, false, header_hbox);
    rut_object_unref(header_hbox);

    left_header_stack = rut_stack_new(shell, 0, 0);
    rut_box_layout_add(header_hbox, true, left_header_stack);
    rut_object_unref(left_header_stack);

    left_header_hbox =
        rut_box_layout_new(shell, RUT_BOX_LAYOUT_PACKING_LEFT_TO_RIGHT);
    rut_stack_add(left_header_stack, left_header_hbox);
    rut_object_unref(left_header_hbox);

    fold_icon_align = rut_bin_new(shell);
    rut_bin_set_x_position(fold_icon_align, RUT_BIN_POSITION_BEGIN);
    rut_bin_set_y_position(fold_icon_align, RUT_BIN_POSITION_CENTER);
    rut_bin_set_right_padding(fold_icon_align, 10);
    rut_box_layout_add(left_header_hbox, false, fold_icon_align);
    rut_object_unref(fold_icon_align);

    texture = rut_load_texture_from_data_file(shell, "tri-fold-up.png", NULL);
    fold->fold_up_icon = rut_nine_slice_new(shell,
                                            texture,
                                            0,
                                            0,
                                            0,
                                            0,
                                            cg_texture_get_width(texture),
                                            cg_texture_get_height(texture));
    cg_object_unref(texture);

    texture = rut_load_texture_from_data_file(shell, "tri-fold-down.png",
                                              NULL);
    fold->fold_down_icon = rut_nine_slice_new(shell,
                                              texture,
                                              0,
                                              0,
                                              0,
                                              0,
                                              cg_texture_get_width(texture),
                                              cg_texture_get_height(texture));
    cg_object_unref(texture);

    fold->fold_icon_shim = rut_fixed_new(shell, cg_texture_get_width(texture),
                                         cg_texture_get_height(texture));
    rut_bin_set_child(fold_icon_align, fold->fold_icon_shim);
    rut_object_unref(fold->fold_icon_shim);

    rut_graphable_add_child(fold->fold_icon_shim, fold->fold_down_icon);

    /* NB: we keep references to the icons so they can be swapped
     * without getting disposed. */

    label_bin = rut_bin_new(shell);
    rut_bin_set_y_position(label_bin, RUT_BIN_POSITION_CENTER);
    rut_box_layout_add(left_header_hbox, false, label_bin);
    rut_object_unref(label_bin);

    fold->label = rut_text_new_with_text(shell, NULL, label);
    rut_bin_set_child(label_bin, fold->label);
    rut_object_unref(fold->label);

    fold->header_hbox_right =
        rut_box_layout_new(shell, RUT_BOX_LAYOUT_PACKING_RIGHT_TO_LEFT);
    rut_box_layout_add(header_hbox, true, fold->header_hbox_right);
    rut_object_unref(fold->header_hbox_right);

    cg_color_init_from_4f(&black, 0, 0, 0, 1);
    rut_fold_set_folder_color(fold, &black);
    rut_fold_set_label_color(fold, &black);

    rut_graphable_add_child(fold, fold->vbox);
    rut_object_unref(fold->vbox);

    fold->input_region =
        rut_input_region_new_rectangle(0, 0, 0, 0, input_cb, fold);
    rut_stack_add(left_header_stack, fold->input_region);
    rut_object_unref(fold->input_region);

    fold->folded = false;

    return fold;
}
Пример #12
0
RutFold *
rut_fold_new (RutContext *ctx,
              const char *label)
{
  RutFold *fold = g_slice_new0 (RutFold);
  static CoglBool initialized = FALSE;
  RutBoxLayout *header_hbox;
  RutStack *left_header_stack;
  RutBoxLayout *left_header_hbox;
  RutBin *label_bin;
  RutBin *fold_icon_align;
  CoglTexture *texture;
  CoglColor black;

  if (initialized == FALSE)
    {
      _rut_fold_init_type ();

      initialized = TRUE;
    }

  fold->ref_count = 1;
  fold->context = ctx;

  rut_object_init (&fold->_parent, &rut_fold_type);

  rut_graphable_init (fold);

  rut_simple_introspectable_init (fold,
                                  _rut_fold_prop_specs,
                                  fold->properties);

  fold->vbox = rut_box_layout_new (ctx, RUT_BOX_LAYOUT_PACKING_TOP_TO_BOTTOM);

  header_hbox =
    rut_box_layout_new (ctx, RUT_BOX_LAYOUT_PACKING_LEFT_TO_RIGHT);
  rut_box_layout_add (fold->vbox, FALSE, header_hbox);
  rut_refable_unref (header_hbox);

  left_header_stack = rut_stack_new (ctx, 0, 0);
  rut_box_layout_add (header_hbox, TRUE, left_header_stack);
  rut_refable_unref (left_header_stack);

  left_header_hbox =
    rut_box_layout_new (ctx, RUT_BOX_LAYOUT_PACKING_LEFT_TO_RIGHT);
  rut_stack_add (left_header_stack, left_header_hbox);
  rut_refable_unref (left_header_hbox);

  fold_icon_align = rut_bin_new (ctx);
  rut_bin_set_x_position (fold_icon_align, RUT_BIN_POSITION_BEGIN);
  rut_bin_set_y_position (fold_icon_align, RUT_BIN_POSITION_CENTER);
  rut_bin_set_right_padding (fold_icon_align, 10);
  rut_box_layout_add (left_header_hbox, FALSE, fold_icon_align);
  rut_refable_unref (fold_icon_align);

  texture = rut_load_texture_from_data_file (ctx, "tri-fold-up.png", NULL);
  fold->fold_up_icon = rut_nine_slice_new (ctx, texture,
                                           0, 0, 0, 0,
                                           cogl_texture_get_width (texture),
                                           cogl_texture_get_height (texture));
  cogl_object_unref (texture);

  texture = rut_load_texture_from_data_file (ctx, "tri-fold-down.png", NULL);
  fold->fold_down_icon = rut_nine_slice_new (ctx, texture,
                                             0, 0, 0, 0,
                                             cogl_texture_get_width (texture),
                                             cogl_texture_get_height (texture));
  cogl_object_unref (texture);

  fold->fold_icon_shim = rut_fixed_new (ctx,
                                        cogl_texture_get_width (texture),
                                        cogl_texture_get_height (texture));
  rut_bin_set_child (fold_icon_align, fold->fold_icon_shim);
  rut_refable_unref (fold->fold_icon_shim);

  rut_graphable_add_child (fold->fold_icon_shim, fold->fold_down_icon);

  /* NB: we keep references to the icons so they can be swapped
   * without getting disposed. */

  label_bin = rut_bin_new (ctx);
  rut_bin_set_y_position (label_bin, RUT_BIN_POSITION_CENTER);
  rut_box_layout_add (left_header_hbox, FALSE, label_bin);
  rut_refable_unref (label_bin);

  fold->label = rut_text_new_with_text (ctx, NULL, label);
  rut_bin_set_child (label_bin, fold->label);
  rut_refable_unref (fold->label);

  fold->header_hbox_right =
    rut_box_layout_new (ctx, RUT_BOX_LAYOUT_PACKING_RIGHT_TO_LEFT);
  rut_box_layout_add (header_hbox, TRUE, fold->header_hbox_right);
  rut_refable_unref (fold->header_hbox_right);

  cogl_color_init_from_4f (&black, 0, 0, 0, 1);
  rut_fold_set_folder_color (fold, &black);
  rut_fold_set_label_color (fold, &black);

  rut_graphable_add_child (fold, fold->vbox);
  rut_refable_unref (fold->vbox);

  fold->input_region = rut_input_region_new_rectangle (0, 0, 0, 0,
                                                       input_cb,
                                                       fold);
  rut_stack_add (left_header_stack, fold->input_region);
  rut_refable_unref (fold->input_region);

  fold->folded = FALSE;

  return fold;
}