Exemple #1
0
static VALUE
rbclt_script_get_object (int argc, VALUE *argv, VALUE self)
{
  ClutterScript *script = CLUTTER_SCRIPT (RVAL2GOBJ (self));
  GObject *object;

  if (argc == 1)
    {
      object = clutter_script_get_object (script, StringValuePtr (argv[0]));
      return GOBJ2RVAL (object);
    }
  else if (argc > 1)
    {
      VALUE ary = rb_ary_new ();
      int i;

      for (i = 0; i < argc; i++)
        {
          object = clutter_script_get_object (script, StringValuePtr (argv[i]));
          rb_ary_push (ary, GOBJ2RVAL (object));
        }

      return ary;
    }
  else
    {
      rb_raise (rb_eArgError, "wrong number of arguments "
                "(at least one required)");

      return Qnil;
    }
}
Exemple #2
0
static void
mex_info_bar_init (MexInfoBar *self)
{
  ClutterScript *script;
  ClutterActor *notification_area;
  GError *err = NULL;
  gchar *tmp;

  MexInfoBarPrivate *priv = self->priv = INFO_BAR_PRIVATE (self);

  priv->script = script = clutter_script_new ();

  tmp = g_build_filename (mex_get_data_dir (), "json", "info-bar.json", NULL);
  clutter_script_load_from_file (script, tmp, &err);
  g_free (tmp);

  if (err)
    g_error ("Could not load info bar: %s", err->message);

  priv->group =
    CLUTTER_ACTOR (clutter_script_get_object (script, "main-group"));

  clutter_actor_set_parent (priv->group, CLUTTER_ACTOR (self));


  priv->settings_button =
    CLUTTER_ACTOR (clutter_script_get_object (script, "settings-button"));

  priv->power_button =
    CLUTTER_ACTOR (clutter_script_get_object (script, "power-button"));

  priv->back_button =
    CLUTTER_ACTOR (clutter_script_get_object (script, "back-button"));

  priv->notification_source = mex_generic_notification_source_new ();

  notification_area =
    CLUTTER_ACTOR (clutter_script_get_object (priv->script,
                                              "notification-area"));

  mex_notification_area_add_source (MEX_NOTIFICATION_AREA (notification_area),
                                    MEX_NOTIFICATION_SOURCE (priv->notification_source));

  g_signal_connect (priv->settings_button,
                    "clicked",
                    G_CALLBACK (_show_settings_dialog_cb), self);

  g_signal_connect (priv->power_button,
                    "clicked",
                    G_CALLBACK (_show_power_dialog_cb), self);

  g_signal_connect (priv->back_button,
                    "clicked",
                    G_CALLBACK (_back_button_cb), self);

  _create_power_dialog (MEX_INFO_BAR (self));
  _create_settings_dialog (MEX_INFO_BAR (self));
}
static void
mex_media_controls_show_description (MexMediaControls *self,
                                     gboolean          show)
{
    MexMediaControlsPrivate *priv = self->priv;
    MxLabel *label;
    ClutterActor *play_pause_button, *stop_button, *placeholder,
                 *add_to_queue_button;
    const gchar *text;

    label = (MxLabel*) clutter_script_get_object (priv->script, "progress-label");

    play_pause_button =
        (ClutterActor*) clutter_script_get_object (priv->script,
                "play-pause-button");
    stop_button =
        (ClutterActor*) clutter_script_get_object (priv->script,
                "stop-button");

    add_to_queue_button =
        (ClutterActor*) clutter_script_get_object (priv->script,
                "add-to-queue-button");

    /* the placeholder actor will accept focus so that the title and description
     * become visible as the user navigates up and down */
    placeholder =
        (ClutterActor*) clutter_script_get_object (priv->script, "placeholder");

    if (show)
    {
        clutter_actor_hide (priv->slider);
        clutter_actor_hide (play_pause_button);
        clutter_actor_hide (stop_button);
        clutter_actor_hide (add_to_queue_button);
        clutter_actor_show (placeholder);

        if (priv->content)
            text = mex_content_get_metadata (priv->content,
                                             MEX_CONTENT_METADATA_SYNOPSIS);
        else
            text = NULL;

        mx_label_set_text (label, (text) ? text : "");
    }
    else
    {
        mx_label_set_text (label, "");
        clutter_actor_show (priv->slider);
        clutter_actor_show (play_pause_button);
        clutter_actor_show (stop_button);
        clutter_actor_show (add_to_queue_button);
        clutter_actor_hide (placeholder);
    }

    priv->show_description = show;
}
G_MODULE_EXPORT int
test_state_script_main (int argc, char *argv[])
{
  ClutterActor *stage, *button;
  ClutterScript *script;
  GError *error = NULL;

  if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
    return EXIT_FAILURE;

  script = clutter_script_new ();
  clutter_script_load_from_file (script, TEST_STATE_SCRIPT_FILE, &error);
  if (error != NULL)
    g_error ("Unable to load '%s': %s\n",
             TEST_STATE_SCRIPT_FILE,
             error->message);

  stage = clutter_stage_new ();
  clutter_stage_set_title (CLUTTER_STAGE (stage), "State Script");
  clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE);
  g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
  clutter_actor_show (stage);

  button = CLUTTER_ACTOR (clutter_script_get_object (script, "button"));
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), button);
  clutter_actor_add_constraint (button, clutter_align_constraint_new (stage, CLUTTER_ALIGN_BOTH, 0.5));

  clutter_script_connect_signals (script, NULL);

  clutter_main ();

  g_object_unref (script);

  return EXIT_SUCCESS;
}
static void
mex_media_controls_replace_content (MexMediaControls *self,
                                    MexContent       *content)
{
    MexPlayer *player;
    MxScrollable *related_box;
    MxAdjustment *adjustment;
    gdouble upper;

    MexMediaControlsPrivate *priv = self->priv;

    if (priv->content == content)
        return;

    player = mex_player_get_default ();

    mex_content_view_set_content (MEX_CONTENT_VIEW (player), content);

    if (priv->content)
        g_object_unref (priv->content);
    priv->content = g_object_ref_sink (content);
    mex_media_controls_update_header (self);
    mex_content_view_set_content (MEX_CONTENT_VIEW (priv->queue_button),
                                  content);

    mex_push_focus ((MxFocusable*) clutter_script_get_object (priv->script,
                    "play-pause-button"));

    related_box = (MxScrollable *)clutter_script_get_object (priv->script,
                  "related-box");
    mx_scrollable_get_adjustments (MX_SCROLLABLE (related_box),
                                   &adjustment, NULL);

    mx_adjustment_get_values (adjustment, NULL, NULL, &upper,
                              NULL, NULL, NULL);

    mx_adjustment_set_value (adjustment, upper);
    mx_scrollable_set_adjustments (MX_SCROLLABLE (related_box),
                                   adjustment,
                                   NULL);
}
Exemple #6
0
gboolean
foo_button_pressed_cb (ClutterActor *actor,
                       ClutterEvent *event,
                       gpointer      user_data)
{
  ClutterScript *ui = CLUTTER_SCRIPT (user_data);
  ClutterStage *stage = CLUTTER_STAGE (clutter_script_get_object (ui, "stage"));

  ClutterScript *script;
  ClutterActor *rig;
  ClutterAnimator *animator;

  /* load the rig and its animator from a JSON file */
  script = clutter_script_new ();

  /* use a function defined statically in this source file to load the JSON */
  load_script_from_file (script, ANIMATION_FILE);

  clutter_script_get_objects (script,
                              "rig", &rig,
                              "animator", &animator,
                              NULL);

  /* remove the button press handler from the rectangle */
  g_signal_handlers_disconnect_matched (actor,
                                        G_SIGNAL_MATCH_FUNC,
                                        0,
                                        0,
                                        NULL,
                                        foo_button_pressed_cb,
                                        NULL);

  /* add a callback to clean up the script when the rig is destroyed */
  g_object_set_data_full (G_OBJECT (rig), "script", script, g_object_unref);

  /* add the rig to the stage */
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), rig);

  /* place the rig at the same coordinates on the stage as the rectangle */
  clutter_actor_set_position (rig,
                              clutter_actor_get_x (actor),
                              clutter_actor_get_y (actor));

  /* put the rectangle into the top-left corner of the rig */
  clutter_actor_reparent (actor, rig);

  clutter_actor_set_position (actor, 0, 0);

  /* animate the rig */
  clutter_animator_start (animator);

  return TRUE;
}
Exemple #7
0
void
mex_info_bar_show_notifications (MexInfoBar *self, gboolean visible)
{
  MexInfoBarPrivate *priv = self->priv;
  ClutterActor *notification_area;

  notification_area =
    CLUTTER_ACTOR (clutter_script_get_object (priv->script,
                                              "notification-area"));
  if (!visible)
    clutter_actor_set_opacity (notification_area, 0x00);
  else
    clutter_actor_set_opacity (notification_area, 0xff);
}
static void
mex_media_controls_update_header (MexMediaControls *self)
{
    MexMediaControlsPrivate *priv = self->priv;
    ClutterActor *label, *image;
    const gchar *logo_url;
    GError *err = NULL;

    label = (ClutterActor*) clutter_script_get_object (priv->script,
            "title-label");
    image = (ClutterActor*) clutter_script_get_object (priv->script, "logo");

    mx_label_set_text (MX_LABEL (label),
                       mex_content_get_metadata (priv->content,
                               MEX_CONTENT_METADATA_TITLE));

    logo_url = mex_content_get_metadata (priv->content,
                                         MEX_CONTENT_METADATA_STATION_LOGO);
    if (!logo_url)
    {
        clutter_actor_hide (image);
    }
    else
    {
        clutter_actor_show (image);

        if (g_str_has_prefix (logo_url, "file://"))
            logo_url = logo_url + 7;

        mx_image_set_from_file (MX_IMAGE (image), logo_url, &err);
        if (err)
        {
            g_warning ("Could not load logo: %s", err->message);
            g_clear_error (&err);
        }
    }
}
Exemple #9
0
bool StageManager::initStage()
{
    stage_ = clutter_stage_get_default();

    float width = (float) getAttribute("size").getInt(0);
    float height =(float) getAttribute("size").getInt(1);
    clutter_actor_set_size(stage_, width, height);
    clutter_stage_set_color(CLUTTER_STAGE(stage_), &black);
    g_signal_connect(stage_, "destroy", G_CALLBACK(on_stage_destroyed), (gpointer) this);

    std::string filename = getAttribute("script").getString(0);

    GError *error = NULL;
    /* load JSON from a file */
    ClutterScript *script = clutter_script_new();
    clutter_script_load_from_file(script, filename.c_str(), &error);

    if (error != NULL)
    {
        std::cerr << "Unable to read file: " <<  error->message << std::endl;
        g_error_free(error);
        // TODO: fail
        g_critical("Could not load GUI");
        return false;
    }
    ClutterActor *group0 = CLUTTER_ACTOR(clutter_script_get_object(script, "group0")); // TODO: rename to root
    clutter_container_add_actor(CLUTTER_CONTAINER(stage_), group0);
    //clutter_script_connect_signals(script, this);
    clutter_script_connect_signals_full(script, tempi_clutter_connect_signals, this);

    // timeline to attach a callback for each frame that is rendered
    ClutterTimeline *timeline;
    timeline = clutter_timeline_new(60); // ms
    clutter_timeline_set_loop(timeline, TRUE);
    clutter_timeline_start(timeline);
    g_signal_connect(timeline, "new-frame", G_CALLBACK(on_frame_cb), this);
    g_signal_connect(stage_, "key-press-event", G_CALLBACK(key_event_cb), this);
    g_object_unref(script); // avoid memory leak

    clutter_actor_show(stage_);

    if (CLUTTER_IS_ACTOR(stage_))
        return true;
    else
        return false;
}
static void
mex_media_controls_notify_progress_cb (ClutterMedia     *media,
                                       GParamSpec       *pspec,
                                       MexMediaControls *self)
{
    MexMediaControlsPrivate *priv = self->priv;
    MxLabel *label;
    gchar *text;
    gdouble length, progress_s;
    gfloat progress;
    gint len_h, len_m, len_s, pos_h, pos_m, pos_s;

    if (priv->show_description)
        return;

    progress = clutter_media_get_progress (media);
    length = clutter_media_get_duration (media);

    len_h = length / 3600;
    len_m = (length - (len_h * 3600)) / 60;
    len_s = (length - (len_h * 3600) - (len_m * 60));

    progress_s = length * progress;

    pos_h = progress_s / 3600;
    pos_m = (progress_s - (pos_h * 3600)) / 60;
    pos_s = (progress_s - (pos_h * 3600) - (pos_m * 60));

    g_signal_handlers_block_by_func (priv->slider, slider_value_changed_cb, self);
    mx_slider_set_value (MX_SLIDER (priv->slider), progress);
    g_signal_handlers_unblock_by_func (priv->slider, slider_value_changed_cb,
                                       self);

    if (len_h > 0)
        text = g_strdup_printf ("%02d:%02d:%02d / %02d:%02d:%02d",
                                pos_h, pos_m, pos_s, len_h, len_m, len_s);
    else
        text = g_strdup_printf ("%02d:%02d / %02d:%02d",
                                pos_m, pos_s, len_m, len_s);

    label = (MxLabel*) clutter_script_get_object (priv->script, "progress-label");
    mx_label_set_text (label, text);
    g_free (text);
}
static gboolean
red_button_press (ClutterActor *actor,
                  ClutterButtonEvent *event,
                  gpointer            data)
{
  GObject *timeline;

  g_print ("[*] Pressed `%s'\n", clutter_get_script_id (G_OBJECT (actor)));

  timeline = clutter_script_get_object (script, "main-timeline");
  g_assert (CLUTTER_IS_TIMELINE (timeline));

  if (!clutter_timeline_is_playing (CLUTTER_TIMELINE (timeline)))
    clutter_timeline_start (CLUTTER_TIMELINE (timeline));
  else
    clutter_timeline_pause (CLUTTER_TIMELINE (timeline));

  return TRUE;
}
static void
mex_media_controls_notify_playing_cb (ClutterMedia     *media,
                                      GParamSpec       *pspec,
                                      MexMediaControls *self)
{
    MexMediaControlsPrivate *priv = self->priv;
    MxStylable *button;
    const gchar *name;

    if (clutter_media_get_playing (media))
        name = "MediaPause";
    else
        name = "MediaPlay";

    button = MX_STYLABLE (clutter_script_get_object (priv->script,
                          "play-pause-button"));

    mx_stylable_set_style_class (button, name);
}
Exemple #13
0
static MxFocusable *
mex_info_bar_accept_focus (MxFocusable *focusable,
                           MxFocusHint  hint)
{
  MexInfoBarPrivate *priv = MEX_INFO_BAR (focusable)->priv;

  MxFocusable *result;

  ClutterActor *buttons_area;

 buttons_area =
    CLUTTER_ACTOR (clutter_script_get_object (priv->script, "buttons-area"));

  /* try the previous focusable first */
  result = mx_focusable_accept_focus (MX_FOCUSABLE (buttons_area),
                                      MX_FOCUS_HINT_PRIOR);

  if (!result)
    result = mx_focusable_accept_focus (MX_FOCUSABLE (buttons_area),
                                        MX_FOCUS_HINT_FIRST);

  return result;
}
void
mex_media_controls_focus_content (MexMediaControls *self,
                                  MexContent       *content)
{
    MexMediaControlsPrivate *priv = self->priv;
    ClutterContainer *container;
    GList *children, *l;

    container = CLUTTER_CONTAINER (clutter_script_get_object (priv->script,
                                   "related-box"));

    children = clutter_container_get_children (container);

    for (l = children; l; l = g_list_next (l))
    {
        if (mex_content_view_get_content (l->data) == content)
        {
            mex_push_focus (l->data);
            return;
        }
    }

    return;
}
Exemple #15
0
static void
mex_info_bar_init (MexInfoBar *self)
{
  ClutterScript *script;
  ClutterActor *notification_area;
  GError *err = NULL;
  gchar *tmp;
  GSettings *settings;

  MexInfoBarPrivate *priv = self->priv = INFO_BAR_PRIVATE (self);

  priv->script = script = clutter_script_new ();

  tmp = g_build_filename (mex_get_data_dir (), "json", "info-bar.json", NULL);
  clutter_script_load_from_file (script, tmp, &err);
  g_free (tmp);

  if (err)
    g_error ("Could not load info bar: %s", err->message);

  priv->group =
    CLUTTER_ACTOR (clutter_script_get_object (script, "main-group"));

  clutter_actor_set_parent (priv->group, CLUTTER_ACTOR (self));


  priv->settings_button =
    CLUTTER_ACTOR (clutter_script_get_object (script, "settings-button"));

  priv->power_button =
    CLUTTER_ACTOR (clutter_script_get_object (script, "power-button"));

  priv->back_button =
    CLUTTER_ACTOR (clutter_script_get_object (script, "back-button"));

  priv->notification_source = mex_generic_notification_source_new ();

  notification_area =
    CLUTTER_ACTOR (clutter_script_get_object (priv->script,
                                              "notification-area"));

  /* ensure the notification area is above any other actors */
  clutter_actor_set_child_above_sibling (clutter_actor_get_parent (notification_area),
                                         notification_area, NULL);

  mex_notification_area_add_source (MEX_NOTIFICATION_AREA (notification_area),
                                    MEX_NOTIFICATION_SOURCE (priv->notification_source));

  g_signal_connect (priv->settings_button,
                    "clicked",
                    G_CALLBACK (_show_settings_dialog_cb), self);

  g_signal_connect (priv->power_button,
                    "clicked",
                    G_CALLBACK (_close_request_cb), self);

  g_signal_connect (priv->back_button,
                    "clicked",
                    G_CALLBACK (_back_button_cb), self);

  _create_settings_dialog (MEX_INFO_BAR (self));

  settings = g_settings_new ("org.media-explorer.Shell");
  if (!g_settings_get_boolean (settings, "close-button-visible"))
    clutter_actor_hide (priv->power_button);
  g_clear_object (&settings);
}
static void
mex_media_controls_init (MexMediaControls *self)
{
    ClutterActor *actor;
    ClutterScript *script;
    GError *err = NULL;
    MxAdjustment *adjustment;
    ClutterActor *related_box;
    gchar *tmp;

    MexMediaControlsPrivate *priv = self->priv = MEDIA_CONTROLS_PRIVATE (self);

    priv->script = script = clutter_script_new ();

    tmp = g_build_filename (mex_get_data_dir (), "json", "media-controls.json",
                            NULL);
    clutter_script_load_from_file (script, tmp, &err);
    g_free (tmp);

    if (err)
        g_error ("Could not load media controls interface: %s", err->message);

    priv->vbox =
        (ClutterActor*) clutter_script_get_object (script, "media-controls");
    clutter_actor_set_parent (priv->vbox, CLUTTER_ACTOR (self));

    /* add shadow to media controls box */
    actor = (ClutterActor *) clutter_script_get_object (script,
            "media-controls-box");
    clutter_actor_add_effect (actor, CLUTTER_EFFECT (mex_shadow_new ()));


    /* vertical fade effect */
    priv->vertical_effect = mx_fade_effect_new ();
    clutter_actor_add_effect (priv->vbox, priv->vertical_effect);
    mx_scrollable_get_adjustments (MX_SCROLLABLE (mx_bin_get_child (MX_BIN (priv->vbox))),
                                   NULL, &adjustment);
    g_signal_connect (adjustment, "changed",
                      G_CALLBACK (notify_vertical_changed_cb), self);
    g_signal_connect (adjustment, "notify::value",
                      G_CALLBACK (notify_vertical_value_cb), self);

    /* horizontal fade effect */
    priv->horizontal_effect = mx_fade_effect_new ();
    related_box = (ClutterActor *) clutter_script_get_object (priv->script,
                  "related-box");
    clutter_actor_add_effect (related_box, priv->horizontal_effect);
    mx_scrollable_get_adjustments (MX_SCROLLABLE (related_box), &adjustment,
                                   NULL);
    g_signal_connect (adjustment, "changed",
                      G_CALLBACK (notify_horizontal_changed_cb), self);
    g_signal_connect (adjustment, "notify::value",
                      G_CALLBACK (notify_horizontal_value_cb), self);


    /* slider setup */
    priv->slider = (ClutterActor*) clutter_script_get_object (script, "slider");
    g_signal_connect (priv->slider, "notify::value",
                      G_CALLBACK (slider_value_changed_cb), self);
    g_signal_connect (priv->slider, "captured-event",
                      G_CALLBACK (slider_captured_event), self);

    priv->play_pause_action =
        (MxAction*) clutter_script_get_object (script, "play-pause-action");

    priv->stop_action =
        (MxAction*) clutter_script_get_object (script, "stop-action");

    priv->add_to_queue_action =
        (MxAction*) clutter_script_get_object (script, "add-to-queue-action");

    priv->queue_button =
        (ClutterActor *) clutter_script_get_object (script, "add-to-queue-button");

    g_signal_connect (priv->play_pause_action, "activated",
                      G_CALLBACK (mex_media_controls_play_cb), self);
    g_signal_connect (priv->stop_action, "activated",
                      G_CALLBACK (mex_media_controls_stop_cb), self);
#if 0
    g_signal_connect (priv->add_to_queue_action, "activated",
                      G_CALLBACK (mex_media_controls_add_to_queue_cb), self);
#endif

    /* proxy setup */

    priv->proxy_model = MEX_VIEW_MODEL (mex_view_model_new (NULL));
    /* FIXME: Set an arbitrary 200-item limit as we can't handle large
     *        amounts of actors without massive slow-down.
     */
    mex_view_model_set_limit (priv->proxy_model, 200);

    priv->proxy = mex_content_proxy_new (MEX_MODEL (priv->proxy_model),
                                         CLUTTER_CONTAINER (related_box),
                                         MEX_TYPE_CONTENT_TILE);

    g_signal_connect (priv->proxy, "object-created", G_CALLBACK (tile_created_cb),
                      self);

    priv->is_disabled = TRUE;
}