static void mx_toggle_get_preferred_height (ClutterActor *actor, gfloat for_width, gfloat *min_height_p, gfloat *pref_height_p) { ClutterActor *background; gfloat pref_h; background = mx_widget_get_background_image (MX_WIDGET (actor)); if (!background) { if (min_height_p) *min_height_p = 0; if (pref_height_p) *pref_height_p = 0; return; } clutter_actor_get_preferred_height (background, -1, NULL, &pref_h); if (min_height_p) *min_height_p = pref_h; if (pref_height_p) *pref_height_p = pref_h; }
static void mnb_spinner_paint (ClutterActor *self) { MnbSpinnerPrivate *priv = MNB_SPINNER (self)->priv; MxWidget *widget = MX_WIDGET (self); ClutterTexture *background; /* * This paints border-image. */ CLUTTER_ACTOR_CLASS (mnb_spinner_parent_class)->paint (self); if ((background = (ClutterTexture *) mx_widget_get_background_image (widget))) { gint tx_w, tx_h; gfloat tf_x, tf_y, tf_w, tf_h; guint8 opacity; ClutterActorBox box = { 0, }; CoglHandle material; if (!CLUTTER_IS_TEXTURE (background)) return; opacity = clutter_actor_get_paint_opacity (self); if (opacity == 0) return; clutter_texture_get_base_size (background, &tx_w, &tx_h); material = clutter_texture_get_cogl_material (background); cogl_material_set_color4ub (material, opacity, opacity, opacity, opacity); clutter_actor_get_allocation_box (self, &box); tf_x = (gfloat)priv->frame / (gfloat) priv->n_frames; tf_y = 0.0; tf_w = tf_x + 1.0 / priv->n_frames; tf_h = 1.0; /* Paint will have translated us */ cogl_set_source (material); cogl_rectangle_with_texture_coords (0.0, 0.0, box.x2 - box.x1, box.y2 - box.y1, tf_x, tf_y, tf_w, tf_h); } }
static void mx_toggle_allocate (ClutterActor *actor, const ClutterActorBox *box, ClutterAllocationFlags flags) { MxTogglePrivate *priv = MX_TOGGLE (actor)->priv; ClutterActorBox handle_box, child_box; ClutterActor *background; gfloat handle_w; gfloat toggle_pos; CLUTTER_ACTOR_CLASS (mx_toggle_parent_class)->allocate (actor, box, flags); mx_widget_get_available_area (MX_WIDGET (actor), box, &child_box); /* background-image don't get stretched, so adjust the child box so that the * handle appears in the correct place. */ background = mx_widget_get_background_image (MX_WIDGET (actor)); if (background) { gfloat width; MxPadding padding; mx_widget_get_padding (MX_WIDGET (actor), &padding); clutter_actor_get_preferred_width (background, -1, NULL, &width); width -= padding.left + padding.right; child_box.x1 += (child_box.x2 - child_box.x1) / 2.f; child_box.x1 -= width / 2.f; child_box.x2 = child_box.x1 + width; } clutter_actor_get_preferred_width (priv->handle, -1, NULL, &handle_w); toggle_pos = child_box.x2 - handle_w - child_box.x1; priv->slide_length = toggle_pos; toggle_pos = toggle_pos * priv->position; handle_box.x1 = (gint) (child_box.x1 + toggle_pos); handle_box.y1 = child_box.y1; handle_box.x2 = handle_box.x1 + handle_w; handle_box.y2 = child_box.y2; clutter_actor_allocate (priv->handle, &handle_box, flags); }
static void mnb_spinner_get_preferred_height (ClutterActor *self, gfloat for_width, gfloat *min_height_p, gfloat *natural_height_p) { MxWidget *widget = MX_WIDGET (self); ClutterTexture *background; if ((background = (ClutterTexture *) mx_widget_get_background_image (widget))) { gint tx_w, tx_h; if (!CLUTTER_IS_TEXTURE (background)) return; /* * The background texture is a strip of squares making up the individual * frames in the animation, so the width matches the height of the * texture. */ clutter_texture_get_base_size (background, &tx_w, &tx_h); if (min_height_p) *min_height_p = tx_h; if (natural_height_p) *natural_height_p = tx_h; return; } if (min_height_p) *min_height_p = 0.0; if (natural_height_p) *natural_height_p = 0.0; }
static void mnb_spinner_constructed (GObject *self) { MnbSpinnerPrivate *priv = MNB_SPINNER (self)->priv; MxWidget *widget = MX_WIDGET (self); ClutterTexture *background; ClutterTimeline *timeline; /* * Mx does not seem to load the style info until the first show, but we want * to get hold of the background asset here to work out the frame count, so * we need to force the style loading. * * NB: mx_widget_ensure_style() does not work here, because the MxWidget * is_style_dirty flag is cleared at this point. */ mx_stylable_style_changed (MX_STYLABLE (widget), MX_STYLE_CHANGED_FORCE); if ((background = (ClutterTexture *) mx_widget_get_background_image (widget))) { gint tx_w, tx_h; guint duration; if (!CLUTTER_IS_TEXTURE (background)) { g_critical ("Expected ClutterTexture, but got %s", G_OBJECT_TYPE_NAME (background)); return; } /* * The background texture is a strip of squares making up the individual * frames in the animation, so the width matches the height of the * texture. */ clutter_texture_get_base_size (background, &tx_w, &tx_h); priv->n_frames = tx_w / tx_h; if (tx_w % tx_h) g_warning (G_STRLOC ": Expected texture size %d x %d, got %d x %d", tx_h * priv->n_frames, tx_h, tx_w, tx_h); /* * Setup a looped timeline with a marker that fires everytime we should * advance to a new frame. * * Assume the whole animation is to last 1s. */ duration = 1000/ priv->n_frames; timeline = priv->timeline = clutter_timeline_new (duration); clutter_timeline_set_loop (timeline, TRUE); clutter_timeline_add_marker_at_time (timeline, "next", duration); clutter_timeline_stop (timeline); g_signal_connect (timeline, "marker-reached", G_CALLBACK (mnb_spinner_marker_reached_cb), self); } else g_warning ("%s did not have background-image set in style !!!", G_OBJECT_TYPE_NAME (self)); }