Esempio n. 1
0
static void
copy_property_cb (RutProperty *property,
                  void *user_data)
{
  CopyPropertiesState *state = user_data;
  RutObject *dst = state->dst;
  RutProperty *dst_property =
    rut_introspectable_lookup_property (dst, property->spec->name);

  g_return_if_fail (dst_property != NULL);

  rut_property_copy_value (state->property_ctx, dst_property, property);
}
Esempio n. 2
0
RigTransitionPropData *
rig_transition_get_prop_data (RigTransition *transition,
                              RutObject *object,
                              const char *property_name)
{
  RutProperty *property =
    rut_introspectable_lookup_property (object, property_name);

  if (!property)
    return NULL;

  return rig_transition_get_prop_data_for_property (transition, property);
}
Esempio n. 3
0
void
rut_property_set_binding_by_name (RutObject *object,
                                  const char *name,
                                  RutBindingCallback callback,
                                  void *user_data,
                                  ...)
{
    RutProperty *property = rut_introspectable_lookup_property (object, name);
    va_list ap;

    g_return_if_fail (property);

    va_start (ap, user_data);
    _rut_property_set_binding_full_valist (property,
                                           callback,
                                           user_data,
                                           NULL,
                                           ap);
    va_end (ap);
}
Esempio n. 4
0
static RutObject *
create_widget_for_property (RutContext *context,
                            RutProperty *prop,
                            RutProperty **control_prop,
                            const char **label_text)
{
  const RutPropertySpec *spec = prop->spec;
  const char *name;
  RutText *label;

  *label_text = NULL;

  if (spec->nick)
    name = spec->nick;
  else
    name = spec->name;

  switch ((RutPropertyType) spec->type)
    {
    case RUT_PROPERTY_TYPE_BOOLEAN:
      {
        char *unselected_icon = rut_find_data_file ("toggle-unselected.png");
        char *selected_icon = rut_find_data_file ("toggle-selected.png");
        RutToggle *toggle = rut_toggle_new_with_icons (context,
                                                       unselected_icon,
                                                       selected_icon,
                                                       name);

        *control_prop = rut_introspectable_lookup_property (toggle, "state");
        return toggle;
      }

    case RUT_PROPERTY_TYPE_VEC3:
      {
        RutVec3Slider *slider = rut_vec3_slider_new (context);
        float min = -G_MAXFLOAT, max = G_MAXFLOAT;

        if ((spec->flags & RUT_PROPERTY_FLAG_VALIDATE))
          {
            const RutPropertyValidationVec3 *validation =
              &spec->validation.vec3_range;

            min = validation->min;
            max = validation->max;
          }

        rut_vec3_slider_set_min_value (slider, min);
        rut_vec3_slider_set_max_value (slider, max);

        rut_vec3_slider_set_decimal_places (slider, 2);

        *control_prop = rut_introspectable_lookup_property (slider, "value");

        return slider;
      }

    case RUT_PROPERTY_TYPE_QUATERNION:
      {
        RutRotationInspector *inspector = rut_rotation_inspector_new (context);

        *control_prop = rut_introspectable_lookup_property (inspector, "value");

        return inspector;
      }

    case RUT_PROPERTY_TYPE_DOUBLE:
    case RUT_PROPERTY_TYPE_FLOAT:
    case RUT_PROPERTY_TYPE_INTEGER:
      {
        RutNumberSlider *slider = rut_number_slider_new (context);
        float min = -G_MAXFLOAT, max = G_MAXFLOAT;
        char *label = g_strconcat (name, ": ", NULL);

        rut_number_slider_set_markup_label (slider, label);
        g_free (label);

        if (spec->type == RUT_PROPERTY_TYPE_INTEGER)
          {
            rut_number_slider_set_decimal_places (slider, 0);
            rut_number_slider_set_step (slider, 1.0);

            if ((spec->flags & RUT_PROPERTY_FLAG_VALIDATE))
              {
                const RutPropertyValidationInteger *validation =
                  &spec->validation.int_range;

                min = validation->min;
                max = validation->max;
              }
          }
        else
          {
            rut_number_slider_set_decimal_places (slider, 2);
            rut_number_slider_set_step (slider, 0.1);

            if ((spec->flags & RUT_PROPERTY_FLAG_VALIDATE))
              {
                const RutPropertyValidationFloat *validation =
                  &spec->validation.float_range;

                min = validation->min;
                max = validation->max;
              }
          }

        rut_number_slider_set_min_value (slider, min);
        rut_number_slider_set_max_value (slider, max);

        *control_prop = rut_introspectable_lookup_property (slider, "value");

        return slider;
      }

    case RUT_PROPERTY_TYPE_ENUM:
      /* If the enum isn't validated then we can't get the value
       * names so we can't make a useful control */
      if ((spec->flags & RUT_PROPERTY_FLAG_VALIDATE))
        {
          RutDropDown *drop = rut_drop_down_new (context);
          int n_values, i;
          const RutUIEnum *ui_enum = spec->validation.ui_enum;
          RutDropDownValue *values;

          for (n_values = 0; ui_enum->values[n_values].nick; n_values++);

          values = g_alloca (sizeof (RutDropDownValue) * n_values);

          for (i = 0; i < n_values; i++)
            {
              values[i].name = (ui_enum->values[i].blurb ?
                                ui_enum->values[i].blurb :
                                ui_enum->values[i].nick);
              values[i].value = ui_enum->values[i].value;
            }

          rut_drop_down_set_values_array (drop, values, n_values);

          *control_prop = rut_introspectable_lookup_property (drop, "value");
          *label_text = name;

          return drop;
        }
      break;

    case RUT_PROPERTY_TYPE_TEXT:
      {
        RutEntry *entry = rut_entry_new (context);
        RutText *text = rut_entry_get_text (entry);

        rut_text_set_single_line_mode (text, TRUE);
        *control_prop = rut_introspectable_lookup_property (text, "text");
        *label_text = name;

        return entry;
      }
      break;

    case RUT_PROPERTY_TYPE_COLOR:
      {
        RutColorButton *button = rut_color_button_new (context);

        *control_prop = rut_introspectable_lookup_property (button, "color");
        *label_text = name;

        return button;
      }
      break;

    case RUT_PROPERTY_TYPE_ASSET:
      {
        RutAssetInspector *asset_inspector =
          rut_asset_inspector_new (context, spec->validation.asset.type);

        *control_prop = rut_introspectable_lookup_property (asset_inspector, "asset");
        *label_text = name;

        return asset_inspector;
      }
      break;

    default:
      break;
    }

  label = rut_text_new (context);

  rut_text_set_text (label, name);

  *control_prop = NULL;

  return label;
}