/* Sort drop action targets */ static gint _xfdashboard_drag_action_sort_targets_callback(gconstpointer inLeft, gconstpointer inRight) { ClutterActor *actor1, *actor2; gfloat depth1, depth2; gfloat x1, y1, w1, h1; gfloat x2, y2, w2, h2; ClutterActorBox *box1, *box2; gint numberPoint1, numberPoint2; g_return_val_if_fail(XFDASHBOARD_IS_DROP_ACTION(inLeft) && XFDASHBOARD_IS_DROP_ACTION(inRight), 0); actor1=clutter_actor_meta_get_actor(CLUTTER_ACTOR_META(inLeft)); actor2=clutter_actor_meta_get_actor(CLUTTER_ACTOR_META(inRight)); /* Return -1 if actor in inLeft should be inserted before actor in inRight * and return 1 if otherwise. If both actors can be handled equal then * return 0. But how to decide? * The actor with higher z-depth should be inserted before. If both actors * have equal z-depth then the actor with the most edge points within the * other actor (overlap) should be inserted before. Edge points are: * [left,top], [right,top], [left,bottom] and [right, bottom]. */ depth1=clutter_actor_get_z_position(actor1); depth2=clutter_actor_get_z_position(actor2); if(depth1>depth2) return(-1); else if(depth1<depth2) return(1); clutter_actor_get_transformed_position(actor1, &x1, &y1); clutter_actor_get_transformed_size(actor1, &w1, &h1); box1=clutter_actor_box_new(x1, y1, x1+w1, y1+h1); clutter_actor_get_transformed_position(actor2, &x2, &y2); clutter_actor_get_transformed_size(actor2, &w2, &h2); box2=clutter_actor_box_new(x2, y2, x2+w2, y2+h2); numberPoint1 =(clutter_actor_box_contains(box1, x2, y2) ? 1 : 0); numberPoint1+=(clutter_actor_box_contains(box1, x2+w2, y2) ? 1 : 0); numberPoint1+=(clutter_actor_box_contains(box1, x2, y2+h2) ? 1 : 0); numberPoint1+=(clutter_actor_box_contains(box1, x2+w2, y2+h2) ? 1 : 0); numberPoint2 =(clutter_actor_box_contains(box2, x1, y1) ? 1 : 0); numberPoint2+=(clutter_actor_box_contains(box2, x1+w1, y1) ? 1 : 0); numberPoint2+=(clutter_actor_box_contains(box2, x1, y1+h1) ? 1 : 0); numberPoint2+=(clutter_actor_box_contains(box2, x1+w1, y1+h1) ? 1 : 0); clutter_actor_box_free(box1); clutter_actor_box_free(box2); /* Return result */ if(numberPoint1>numberPoint2) return(1); else if(numberPoint2>numberPoint1) return(-1); return(0); }
static void gmc_button_allocate (ClutterActor *actor, const ClutterActorBox *box, ClutterAllocationFlags flags) { GmcButtonPrivate *priv; ClutterActorBox *actor_box; gfloat width, height; gfloat icon_w_min = 0, icon_h_min = 0, icon_w_nat = 0, icon_h_nat = 0; gfloat label_w_min = 0, label_h_min = 0, label_w_nat = 0, label_h_nat = 0; gfloat spacing = 0; priv = GMC_BUTTON_GET_PRIVATE (actor); CLUTTER_ACTOR_CLASS (gmc_button_parent_class)->allocate (actor, box, flags); clutter_actor_box_get_size (box, &width, &height); // TODO if icon_h < label_h, center icon // if icon_h > label_h, center label if (priv->icon) { clutter_actor_get_preferred_width (priv->icon, height, &icon_w_min, &icon_w_nat); clutter_actor_get_preferred_height (priv->icon, width, &icon_h_min, &icon_h_nat); actor_box = clutter_actor_box_new (0, 0, icon_w_min, icon_h_min); clutter_actor_allocate (priv->icon, actor_box, flags); clutter_actor_box_free (actor_box); spacing = priv->spacing; } if (priv->label) { clutter_actor_get_preferred_width (priv->label, height, &label_w_min, &label_w_nat); clutter_actor_get_preferred_height (priv->label, width, &label_h_min, &label_h_nat); actor_box = clutter_actor_box_new (icon_w_min + spacing, 0, label_w_min, 25); clutter_actor_allocate (priv->label, actor_box, flags); clutter_actor_box_free (actor_box); } }
/* 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); } }
void IoClutterActorBox_free(IoClutterActorBox *self) { if(IOCABOX(self) != NULL) clutter_actor_box_free(IOCABOX(self)); }
/* 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]); } }