/* use the actor's allocation for the ClutterBox */ static void cb_button_allocate (ClutterActor *actor, const ClutterActorBox *box, ClutterAllocationFlags flags) { CbButtonPrivate *priv = CB_BUTTON (actor)->priv; ClutterActorBox child_box = { 0, }; /* set the allocation for the whole button */ CLUTTER_ACTOR_CLASS (cb_button_parent_class)->allocate (actor, box, flags); /* make the child (the ClutterBox) fill the parent; * note that this allocation box is relative to the * coordinates of the whole button actor, so we can't just * use the box passed into this function; instead, it * is adjusted to span the whole of the actor, from its * top-left corner (0,0) to its bottom-right corner * (width,height) */ child_box.x1 = 0.0; child_box.y1 = 0.0; child_box.x2 = clutter_actor_box_get_width (box); child_box.y2 = clutter_actor_box_get_height (box); clutter_actor_allocate (priv->child, &child_box, flags); }
static void clutter_bin_layout_allocate (ClutterLayoutManager *manager, ClutterContainer *container, const ClutterActorBox *allocation, ClutterAllocationFlags flags) { GList *children = clutter_container_get_children (container); GList *l; gfloat available_w, available_h; available_w = clutter_actor_box_get_width (allocation); available_h = clutter_actor_box_get_height (allocation); for (l = children; l != NULL; l = l->next) { ClutterActor *child = l->data; ClutterLayoutMeta *meta; ClutterBinLayer *layer; ClutterActorBox child_alloc = { 0, }; gdouble x_align, y_align; gboolean x_fill, y_fill; meta = clutter_layout_manager_get_child_meta (manager, container, child); layer = CLUTTER_BIN_LAYER (meta); if (layer->x_align == CLUTTER_BIN_ALIGNMENT_FIXED) child_alloc.x1 = clutter_actor_get_x (child); else child_alloc.x1 = 0.0f; if (layer->y_align == CLUTTER_BIN_ALIGNMENT_FIXED) child_alloc.y1 = clutter_actor_get_y (child); else child_alloc.y1 = 0.0f; child_alloc.x2 = available_w; child_alloc.y2 = available_h; x_fill = (layer->x_align == CLUTTER_BIN_ALIGNMENT_FILL); y_fill = (layer->y_align == CLUTTER_BIN_ALIGNMENT_FILL); x_align = get_bin_alignment_factor (layer->x_align); y_align = get_bin_alignment_factor (layer->y_align); clutter_actor_allocate_align_fill (child, &child_alloc, x_align, y_align, x_fill, y_fill, flags); } g_list_free (children); }
static void ckd_slide_allocate (ClutterActor *actor, const ClutterActorBox *box, ClutterAllocationFlags flags) { CkdSlide *self = CKD_SLIDE (actor); CkdSlidePriv *priv = CKD_SLIDE_GET_PRIVATE (self); CLUTTER_ACTOR_CLASS (ckd_slide_parent_class)->allocate (actor, box, flags); gfloat w = clutter_actor_box_get_width (box); gfloat h = clutter_actor_box_get_height (box); ClutterActorBox content_box = { 0, 0, w, h }; clutter_actor_allocate (priv->content, &content_box, flags); }
/** * clutter_actor_get_allocation_geometry: * @self: A #ClutterActor * @geom: (out): allocation geometry in pixels * * Gets the layout box an actor has been assigned. The allocation can * only be assumed valid inside a paint() method; anywhere else, it * may be out-of-date. * * An allocation does not incorporate the actor's scale or anchor point; * those transformations do not affect layout, only rendering. * * The returned rectangle is in pixels. * * Since: 0.8 * * Deprecated: 1.12: Use clutter_actor_get_allocation_box() instead. */ void clutter_actor_get_allocation_geometry (ClutterActor *self, ClutterGeometry *geom) { ClutterActorBox box; g_return_if_fail (CLUTTER_IS_ACTOR (self)); g_return_if_fail (geom != NULL); clutter_actor_get_allocation_box (self, &box); geom->x = CLUTTER_NEARBYINT (clutter_actor_box_get_x (&box)); geom->y = CLUTTER_NEARBYINT (clutter_actor_box_get_y (&box)); geom->width = CLUTTER_NEARBYINT (clutter_actor_box_get_width (&box)); geom->height = CLUTTER_NEARBYINT (clutter_actor_box_get_height (&box)); }
static void slider_allocate( ClutterActor *actor, const ClutterActorBox *box, ClutterAllocationFlags flags) { CLUTTER_ACTOR_CLASS(slider_parent_class)->allocate(actor, box, flags); SliderPrivate *priv = SLIDER(actor)->priv; const gfloat box_height = clutter_actor_box_get_height(box); ClutterActorBox child_box = { .x1 = 0.0, .y1 = 0.0, .x2=clutter_actor_box_get_width(box), .y2=box_height}; clutter_actor_allocate(priv->box, &child_box, flags); child_box.y1 = box_height * (priv->pos - 0.05); child_box.y2 = box_height * (priv->pos + 0.05); clutter_actor_allocate(priv->handle, &child_box, flags); } static void slider_paint(ClutterActor *actor) { SliderPrivate *priv = SLIDER(actor)->priv; clutter_actor_paint(priv->box); clutter_actor_paint(priv->handle); }
static void clutter_align_constraint_update_allocation (ClutterConstraint *constraint, ClutterActor *actor, ClutterActorBox *allocation) { ClutterAlignConstraint *align = CLUTTER_ALIGN_CONSTRAINT (constraint); gfloat source_width, source_height; gfloat actor_width, actor_height; gfloat source_x, source_y; if (align->source == NULL) return; clutter_actor_get_position (align->source, &source_x, &source_y); clutter_actor_get_size (align->source, &source_width, &source_height); switch (align->align_axis) { case CLUTTER_ALIGN_X_AXIS: actor_width = clutter_actor_box_get_width (allocation); allocation->x1 = ((source_width - actor_width) * align->factor) + source_x; allocation->x1 = floorf (allocation->x1 + 0.5); allocation->x2 = allocation->x1 + actor_width; break; case CLUTTER_ALIGN_Y_AXIS: actor_height = clutter_actor_box_get_height (allocation); allocation->y1 = ((source_height - actor_height) * align->factor) + source_y; allocation->x1 = floorf (allocation->x1 + 0.5); allocation->y2 = allocation->y1 + actor_height; break; default: g_assert_not_reached (); break; } }
//doc ClutterActorBox with(x1, y1, x2, y2) IO_METHOD(IoClutterActorBox, with) { float x1 = IoMessage_locals_floatArgAt_(m, locals, 0), y1 = IoMessage_locals_floatArgAt_(m, locals, 1), x2 = IoMessage_locals_floatArgAt_(m, locals, 2), y2 = IoMessage_locals_floatArgAt_(m, locals, 3); ClutterActorBox *actorBox = clutter_actor_box_new(x1, y1, x2, y2); IoClutterActorBox *klone = IoClutterActorBox_newWithActorBox(IOSTATE, actorBox); IoObject_setSlot_to_(klone, IOSYMBOL("x1"), IoMessage_locals_numberArgAt_(m, locals, 0) ); IoObject_setSlot_to_(klone, IOSYMBOL("y1"), IoMessage_locals_numberArgAt_(m, locals, 1) ); IoObject_setSlot_to_(klone, IOSYMBOL("x2"), IoMessage_locals_numberArgAt_(m, locals, 2) ); IoObject_setSlot_to_(klone, IOSYMBOL("y2"), IoMessage_locals_numberArgAt_(m, locals, 3) ); IoObject_setSlot_to_(klone, IOSYMBOL("width"), IONUMBER(clutter_actor_box_get_width(actorBox)) ); IoObject_setSlot_to_(klone, IOSYMBOL("height"), IONUMBER(clutter_actor_box_get_height(actorBox)) ); IoObject_setSlot_to_(klone, IOSYMBOL("area"), IONUMBER(clutter_actor_box_get_area(actorBox)) ); return klone; }
static void mex_shell_allocate (ClutterActor *actor, const ClutterActorBox *box, ClutterAllocationFlags flags) { GList *c; MxPadding padding; gfloat width, height; MexShellPrivate *priv = MEX_SHELL (actor)->priv; CLUTTER_ACTOR_CLASS (mex_shell_parent_class)->allocate (actor, box, flags); mx_widget_get_padding (MX_WIDGET (actor), &padding); width = clutter_actor_box_get_width (box) - padding.left - padding.right; height = clutter_actor_box_get_height (box) - padding.top - padding.bottom; for (c = priv->children; c; c = c->next) { MexShellChildData *data = c->data; /* By animating this, we avoid an allocation cycle * and it also looks kinda cool. */ clutter_actor_animate (data->child, CLUTTER_EASE_OUT_QUAD, 250, "natural-width", width, "natural-height", height, NULL); data->target_width = width; data->target_height = height; clutter_actor_allocate_preferred_size (data->child, flags); } }
/* Allocate position and size of actor and its children */ static void _xfdashboard_text_box_allocate(ClutterActor *self, const ClutterActorBox *inBox, ClutterAllocationFlags inFlags) { XfdashboardTextBoxPrivate *priv=XFDASHBOARD_TEXT_BOX(self)->priv; ClutterActorBox *box=NULL; gfloat left, right, top, bottom; gfloat iconWidth, iconHeight; /* Chain up to store the allocation of the actor */ CLUTTER_ACTOR_CLASS(xfdashboard_text_box_parent_class)->allocate(self, inBox, inFlags); /* Initialize bounding box of allocation used in actors */ left=top=priv->padding; right=clutter_actor_box_get_width(inBox)-priv->padding; bottom=clutter_actor_box_get_height(inBox)-priv->padding; /* Set allocation of primary icon if visible */ if(CLUTTER_ACTOR_IS_VISIBLE(priv->actorPrimaryIcon)) { gfloat childRight; /* Get scale size of primary icon */ iconWidth=iconHeight=0.0f; clutter_actor_get_size(priv->actorPrimaryIcon, &iconWidth, &iconHeight); if(iconHeight>0.0f) iconWidth=(bottom-top)*(iconWidth/iconHeight); /* Set allocation */ childRight=left+iconWidth; box=clutter_actor_box_new(floor(left), floor(top), floor(childRight), floor(bottom)); clutter_actor_allocate(CLUTTER_ACTOR(priv->actorPrimaryIcon), box, inFlags); clutter_actor_box_free(box); /* Adjust bounding box for next actor */ left=childRight+priv->spacing; } /* Set allocation of secondary icon if visible */ if(CLUTTER_ACTOR_IS_VISIBLE(priv->actorSecondaryIcon)) { gfloat childLeft; /* Get scale size of secondary icon */ iconWidth=0.0f; clutter_actor_get_size(priv->actorSecondaryIcon, &iconWidth, &iconHeight); if(iconHeight>0.0f) iconWidth=(bottom-top)*(iconWidth/iconHeight); /* Set allocation */ childLeft=right-iconWidth; box=clutter_actor_box_new(floor(childLeft), floor(top), floor(right), floor(bottom)); clutter_actor_allocate(CLUTTER_ACTOR(priv->actorSecondaryIcon), box, inFlags); clutter_actor_box_free(box); /* Adjust bounding box for next actor */ right=childLeft-priv->spacing; } /* Set allocation of editable text box if visible */ if(CLUTTER_ACTOR_IS_VISIBLE(priv->actorTextBox)) { gfloat textHeight; /* Get height of text */ clutter_actor_get_preferred_size(CLUTTER_ACTOR(priv->actorTextBox), NULL, NULL, NULL, &textHeight); /* Set allocation */ box=clutter_actor_box_new(floor(left), floor(bottom-textHeight), floor(right), floor(bottom)); clutter_actor_allocate(CLUTTER_ACTOR(priv->actorTextBox), box, inFlags); clutter_actor_box_free(box); } /* Set allocation of hint label if visible */ if(CLUTTER_ACTOR_IS_VISIBLE(priv->actorHintLabel)) { gfloat textHeight; /* Get height of label */ clutter_actor_get_preferred_size(CLUTTER_ACTOR(priv->actorHintLabel), NULL, NULL, NULL, &textHeight); /* Set allocation */ box=clutter_actor_box_new(floor(left), floor(bottom-textHeight), floor(right), floor(bottom)); clutter_actor_allocate(CLUTTER_ACTOR(priv->actorHintLabel), box, inFlags); clutter_actor_box_free(box); } }
/* Re-layout and allocate children of container we manage */ static void _xfdashboard_fill_box_layout_allocate(ClutterLayoutManager *inLayoutManager, ClutterContainer *inContainer, const ClutterActorBox *inAllocation, ClutterAllocationFlags inFlags) { XfdashboardFillBoxLayout *self; XfdashboardFillBoxLayoutPrivate *priv; ClutterActor *child; ClutterActorIter iter; gfloat parentWidth, parentHeight; gfloat homogeneousSize; gfloat x, y, w, h; gfloat aspectRatio; ClutterActorBox childAllocation; g_return_if_fail(XFDASHBOARD_IS_FILL_BOX_LAYOUT(inLayoutManager)); g_return_if_fail(CLUTTER_IS_CONTAINER(inContainer)); self=XFDASHBOARD_FILL_BOX_LAYOUT(inLayoutManager); priv=self->priv; /* Get dimension of allocation */ parentWidth=clutter_actor_box_get_width(inAllocation); parentHeight=clutter_actor_box_get_height(inAllocation); /* If homogeneous determine sizes for all children */ if(priv->isHomogeneous==TRUE) { if(priv->orientation==CLUTTER_ORIENTATION_HORIZONTAL) { _xfdashboard_fill_box_layout_get_largest_sizes(self, inContainer, NULL, &homogeneousSize, NULL, NULL); } else { _xfdashboard_fill_box_layout_get_largest_sizes(self, inContainer, NULL, NULL, NULL, &homogeneousSize); } } /* Iterate through children and set their sizes */ x=y=0.0f; clutter_actor_iter_init(&iter, CLUTTER_ACTOR(inContainer)); while(clutter_actor_iter_next(&iter, &child)) { /* Only set sizes on visible children */ if(!clutter_actor_is_visible(child)) continue; /* Calculate and set new allocation of child */ if(priv->isHomogeneous==FALSE) { clutter_actor_get_size(CLUTTER_ACTOR(inContainer), &w, &h); if(priv->orientation==CLUTTER_ORIENTATION_HORIZONTAL) { aspectRatio=w/h; h=parentHeight; w=h*aspectRatio; } else { aspectRatio=h/w; w=parentWidth; h=w*aspectRatio; } } else { if(priv->orientation==CLUTTER_ORIENTATION_HORIZONTAL) { w=homogeneousSize; h=parentHeight; } else { w=parentWidth; h=homogeneousSize; } } /* Set new allocation of child */ childAllocation.x1=ceil(x); childAllocation.y1=ceil(y); childAllocation.x2=ceil(childAllocation.x1+w); childAllocation.y2=ceil(childAllocation.y1+h); clutter_actor_allocate(child, &childAllocation, inFlags); /* Set up for next child */ if(priv->orientation==CLUTTER_ORIENTATION_HORIZONTAL) x+=(w+priv->spacing); else y+=(h+priv->spacing); } }
/* Allocate position and size of actor and its children */ static void _xfdashboard_viewpad_allocate(ClutterActor *self, const ClutterActorBox *inBox, ClutterAllocationFlags inFlags) { XfdashboardViewpadPrivate *priv=XFDASHBOARD_VIEWPAD(self)->priv; ClutterActorClass *actorClass=CLUTTER_ACTOR_CLASS(xfdashboard_viewpad_parent_class); gfloat viewWidth, viewHeight; gfloat vScrollbarWidth, vScrollbarHeight; gfloat hScrollbarWidth, hScrollbarHeight; gboolean hScrollbarVisible, vScrollbarVisible; ClutterActorBox *box; gfloat x, y, w, h; /* Chain up to store the allocation of the actor */ if(actorClass->allocate) actorClass->allocate(self, inBox, inFlags); /* Initialize largest possible allocation for view and determine * real size of view to show. The real size is used to determine * scroll bar visibility if policy is automatic */ viewWidth=clutter_actor_box_get_width(inBox); viewHeight=clutter_actor_box_get_height(inBox); /* Determine visibility of scroll bars */ hScrollbarVisible=FALSE; if(priv->hScrollbarPolicy==XFDASHBOARD_POLICY_ALWAYS || (priv->hScrollbarPolicy==XFDASHBOARD_POLICY_AUTOMATIC && xfdashboard_scrollbar_get_range(XFDASHBOARD_SCROLLBAR(priv->hScrollbar))>viewWidth)) { hScrollbarVisible=TRUE; } if(xfdashboard_view_get_fit_mode(XFDASHBOARD_VIEW(priv->activeView))==XFDASHBOARD_FIT_MODE_HORIZONTAL || xfdashboard_view_get_fit_mode(XFDASHBOARD_VIEW(priv->activeView))==XFDASHBOARD_FIT_MODE_BOTH) { hScrollbarVisible=FALSE; } vScrollbarVisible=FALSE; if(priv->vScrollbarPolicy==XFDASHBOARD_POLICY_ALWAYS || (priv->vScrollbarPolicy==XFDASHBOARD_POLICY_AUTOMATIC && xfdashboard_scrollbar_get_range(XFDASHBOARD_SCROLLBAR(priv->vScrollbar))>viewHeight)) { vScrollbarVisible=TRUE; } if(xfdashboard_view_get_fit_mode(XFDASHBOARD_VIEW(priv->activeView))==XFDASHBOARD_FIT_MODE_VERTICAL || xfdashboard_view_get_fit_mode(XFDASHBOARD_VIEW(priv->activeView))==XFDASHBOARD_FIT_MODE_BOTH) { vScrollbarVisible=FALSE; } /* Set allocation for visible scroll bars */ vScrollbarWidth=0.0f; vScrollbarHeight=viewHeight; clutter_actor_get_preferred_width(priv->vScrollbar, -1, NULL, &vScrollbarWidth); hScrollbarWidth=viewWidth; hScrollbarHeight=0.0f; clutter_actor_get_preferred_height(priv->hScrollbar, -1, NULL, &hScrollbarHeight); if(hScrollbarVisible && vScrollbarVisible) { vScrollbarHeight-=hScrollbarHeight; hScrollbarWidth-=vScrollbarWidth; } if(vScrollbarVisible==FALSE) box=clutter_actor_box_new(0, 0, 0, 0); else box=clutter_actor_box_new(viewWidth-vScrollbarWidth, 0, viewWidth, vScrollbarHeight); clutter_actor_allocate(priv->vScrollbar, box, inFlags); clutter_actor_box_free(box); if(hScrollbarVisible==FALSE) box=clutter_actor_box_new(0, 0, 0, 0); else box=clutter_actor_box_new(0, viewHeight-hScrollbarHeight, hScrollbarWidth, viewHeight); clutter_actor_allocate(priv->hScrollbar, box, inFlags); clutter_actor_box_free(box); /* Reduce allocation for view by any visible scroll bar * and set allocation and clipping of view */ if(priv->activeView) { /* Set allocation */ if(vScrollbarVisible) viewWidth-=vScrollbarWidth; if(hScrollbarVisible) viewHeight-=hScrollbarHeight; x=y=0.0f; if(clutter_actor_has_clip(CLUTTER_ACTOR(priv->activeView))) { clutter_actor_get_clip(CLUTTER_ACTOR(priv->activeView), &x, &y, NULL, NULL); } switch(xfdashboard_view_get_fit_mode(XFDASHBOARD_VIEW(priv->activeView))) { case XFDASHBOARD_FIT_MODE_BOTH: w=viewWidth; h=viewHeight; break; case XFDASHBOARD_FIT_MODE_HORIZONTAL: w=viewWidth; clutter_actor_get_preferred_height(CLUTTER_ACTOR(priv->activeView), w, NULL, &h); break; case XFDASHBOARD_FIT_MODE_VERTICAL: h=viewHeight; clutter_actor_get_preferred_width(CLUTTER_ACTOR(priv->activeView), h, NULL, &w); break; default: clutter_actor_get_preferred_size(CLUTTER_ACTOR(priv->activeView), NULL, NULL, &w, &h); break; } box=clutter_actor_box_new(0, 0, w, h); clutter_actor_allocate(CLUTTER_ACTOR(priv->activeView), box, inFlags); clutter_actor_box_free(box); clutter_actor_set_clip(CLUTTER_ACTOR(priv->activeView), x, y, viewWidth, viewHeight); } /* Only set value if it changes */ if(priv->hScrollbarVisible!=hScrollbarVisible) { /* Set new value */ priv->hScrollbarVisible=hScrollbarVisible; /* Notify about property change */ g_object_notify_by_pspec(G_OBJECT(self), XfdashboardViewpadProperties[PROP_HSCROLLBAR_VISIBLE]); } if(priv->vScrollbarVisible!=vScrollbarVisible) { /* Set new value */ priv->vScrollbarVisible=vScrollbarVisible; /* Notify about property change */ g_object_notify_by_pspec(G_OBJECT(self), XfdashboardViewpadProperties[PROP_VSCROLLBAR_VISIBLE]); } }