/** * mx_tooltip_set_tip_area_from_actor: * @tooltip: A #MxTooltip * @actor: A #ClutterActor * * Utility function to set the geometry of the tooltip area * from an existing actor. * See also mx_tooltip_set_tip_area * */ void mx_tooltip_set_tip_area_from_actor (MxTooltip *tooltip, ClutterActor *actor) { ClutterVertex verts[4]; ClutterGeometry area; gfloat x, y, x2, y2; gint i; /* Work out the bounding box */ clutter_actor_get_abs_allocation_vertices (actor, verts); x = y = G_MAXFLOAT; x2 = y2 = -G_MAXFLOAT; for (i = 0; i < G_N_ELEMENTS (verts); i++) { if (verts[i].x < x) x = verts[i].x; if (verts[i].x > x2) x2 = verts[i].x; if (verts[i].y < y) y = verts[i].y; if (verts[i].y > y2) y2 = verts[i].y; } area.x = x; area.y = y; area.width = x2 - x; area.height = y2 - y; mx_tooltip_set_tip_area (tooltip, &area); }
/* We can only (easily) apply our logic for figuring out what a window * obscures if is not transformed. This function does that check and * as a side effect gets the position of the upper-left corner of the * actors. * * (We actually could handle scaled and non-integrally positioned actors * too as long as they weren't shaped - no filtering is done at the * edges so a rectangle stays a rectangle. But the gain from that is * small, especally since most of our windows are shaped. The simple * case we handle here is the case that matters when the user is just * using the desktop normally.) * * If we assume that the window group is untransformed (it better not * be!) then we could also make this determination by checking directly * if the actor itself is rotated, scaled, or at a non-integral position. * However, the criterion for "close enough" in that case get trickier, * since, for example, the allowed rotation depends on the size of * actor. The approach we take here is to just require everything * to be within 1/256th of a pixel. */ static gboolean actor_is_untransformed (ClutterActor *actor, int *x_origin, int *y_origin) { gfloat widthf, heightf; int width, height; ClutterVertex verts[4]; int v0x, v0y, v1x, v1y, v2x, v2y, v3x, v3y; int x, y; clutter_actor_get_size (actor, &widthf, &heightf); width = round_to_fixed (widthf); height = round_to_fixed (heightf); clutter_actor_get_abs_allocation_vertices (actor, verts); v0x = round_to_fixed (verts[0].x); v0y = round_to_fixed (verts[0].y); v1x = round_to_fixed (verts[1].x); v1y = round_to_fixed (verts[1].y); v2x = round_to_fixed (verts[2].x); v2y = round_to_fixed (verts[2].y); v3x = round_to_fixed (verts[3].x); v3y = round_to_fixed (verts[3].y); /* Using shifting for converting fixed => int, gets things right for * negative values. / 256. wouldn't do the same */ x = v0x >> 8; y = v0y >> 8; /* At integral coordinates? */ if (x * 256 != v0x || y * 256 != v0y) return FALSE; /* Not scaled? */ if (v1x - v0x != width || v2y - v0y != height) return FALSE; /* Not rotated/skewed? */ if (v0x != v2x || v0y != v1y || v3x != v1x || v3y != v2y) return FALSE; *x_origin = x; *y_origin = y; return TRUE; }
void cs_selected_paint (void) { ClutterVertex verts[4]; /* draw outlines for actors */ GHashTableIter iter; gpointer key, value; { { if (cs->fake_stage) { cogl_set_source_color4ub (0, 255, 0, 255); cs_draw_actor_outline (cs->fake_stage, NULL); } } } cogl_set_source_color4ub (255, 0, 0, 128); cs_selected_foreach (G_CALLBACK (cs_draw_actor_outline), NULL); g_hash_table_iter_init (&iter, selection); while (g_hash_table_iter_next (&iter, &key, &value)) { clutter_actor_get_abs_allocation_vertices (key, verts); cogl_set_source_color4ub (0, 0, 25, 50); { { gfloat coords[]={ verts[0].x, verts[0].y, verts[1].x, verts[1].y, verts[3].x, verts[3].y, verts[2].x, verts[2].y, verts[0].x, verts[0].y }; cogl_path_polyline (coords, 5); cogl_set_source_color4ub (0, 0, 255, 128); cogl_path_stroke (); } } } }
/** * shell_util_get_transformed_allocation: * @actor: a #ClutterActor * @box: (out): location to store returned box in stage coordinates * * This function is similar to a combination of clutter_actor_get_transformed_position(), * and clutter_actor_get_transformed_size(), but unlike * clutter_actor_get_transformed_size(), it always returns a transform * of the current allocation, while clutter_actor_get_transformed_size() returns * bad values (the transform of the requested size) if a relayout has been * queued. * * This function is more convenient to use than * clutter_actor_get_abs_allocation_vertices() if no transformation is in effect * and also works around limitations in the GJS binding of arrays. */ void shell_util_get_transformed_allocation (ClutterActor *actor, ClutterActorBox *box) { /* Code adapted from clutter-actor.c: * Copyright 2006, 2007, 2008 OpenedHand Ltd */ ClutterVertex v[4]; gfloat x_min, x_max, y_min, y_max; gint i; g_return_if_fail (CLUTTER_IS_ACTOR (actor)); clutter_actor_get_abs_allocation_vertices (actor, v); x_min = x_max = v[0].x; y_min = y_max = v[0].y; for (i = 1; i < G_N_ELEMENTS (v); ++i) { if (v[i].x < x_min) x_min = v[i].x; if (v[i].x > x_max) x_max = v[i].x; if (v[i].y < y_min) y_min = v[i].y; if (v[i].y > y_max) y_max = v[i].y; } box->x1 = x_min; box->y1 = y_min; box->x2 = x_max; box->y2 = y_max; }
static void st_scroll_view_fade_paint_target (ClutterOffscreenEffect *effect) { StScrollViewFade *self = ST_SCROLL_VIEW_FADE (effect); ClutterOffscreenEffectClass *parent; CoglHandle material; gdouble value, lower, upper, page_size; ClutterActor *vscroll = st_scroll_view_get_vscroll_bar (ST_SCROLL_VIEW (self->actor)); ClutterActor *hscroll = st_scroll_view_get_hscroll_bar (ST_SCROLL_VIEW (self->actor)); gboolean h_scroll_visible, v_scroll_visible; ClutterActorBox allocation, content_box, paint_box; /* * Used to pass the fade area to the shader * * [0][0] = x1 * [0][1] = y1 * [1][0] = x2 * [1][1] = y2 * */ float fade_area[2][2]; ClutterVertex verts[4]; if (self->program == COGL_INVALID_HANDLE) goto out; clutter_actor_get_paint_box (self->actor, &paint_box); clutter_actor_get_abs_allocation_vertices (self->actor, verts); clutter_actor_get_allocation_box (self->actor, &allocation); st_theme_node_get_content_box (st_widget_get_theme_node (ST_WIDGET (self->actor)), (const ClutterActorBox *)&allocation, &content_box); /* * The FBO is based on the paint_volume's size which can be larger then the actual * allocation, so we have to account for that when passing the positions */ fade_area[0][0] = content_box.x1 + (verts[0].x - paint_box.x1); fade_area[0][1] = content_box.y1 + (verts[0].y - paint_box.y1); fade_area[1][0] = content_box.x2 + (verts[3].x - paint_box.x2); fade_area[1][1] = content_box.y2 + (verts[3].y - paint_box.y2); g_object_get (ST_SCROLL_VIEW (self->actor), "hscrollbar-visible", &h_scroll_visible, "vscrollbar-visible", &v_scroll_visible, NULL); if (v_scroll_visible) { if (st_widget_get_direction (ST_WIDGET (self->actor)) == ST_TEXT_DIRECTION_RTL) fade_area[0][0] += clutter_actor_get_width (vscroll); fade_area[1][0] -= clutter_actor_get_width (vscroll); } if (h_scroll_visible) fade_area[1][1] -= clutter_actor_get_height (hscroll); st_adjustment_get_values (self->vadjustment, &value, &lower, &upper, NULL, NULL, &page_size); if (self->offset_top_uniform > -1) { if (value > lower + 0.1) cogl_program_set_uniform_1f (self->program, self->offset_top_uniform, self->fade_offset); else cogl_program_set_uniform_1f (self->program, self->offset_top_uniform, 0.0f); } if (self->offset_bottom_uniform > -1) { if (value < upper - page_size - 0.1) cogl_program_set_uniform_1f (self->program, self->offset_bottom_uniform, self->fade_offset); else cogl_program_set_uniform_1f (self->program, self->offset_bottom_uniform, 0.0f); } if (self->tex_uniform > -1) cogl_program_set_uniform_1i (self->program, self->tex_uniform, 0); if (self->height_uniform > -1) cogl_program_set_uniform_1f (self->program, self->height_uniform, clutter_actor_get_height (self->actor)); if (self->width_uniform > -1) cogl_program_set_uniform_1f (self->program, self->width_uniform, clutter_actor_get_width (self->actor)); if (self->fade_area_uniform > -1) cogl_program_set_uniform_matrix (self->program, self->fade_area_uniform, 2, 1, FALSE, (const float *)fade_area); material = clutter_offscreen_effect_get_target (effect); cogl_material_set_user_program (material, self->program); out: parent = CLUTTER_OFFSCREEN_EFFECT_CLASS (st_scroll_view_fade_parent_class); parent->paint_target (effect); }