Commit Graph

624 Commits

Author SHA1 Message Date
Emmanuele Bassi
9a66392d49 actor: Add new methods for changing the paint sequence
ClutterActor provides four methods for changing the paint sequence order
of its children:

  raise_top()
  raise()
  lower()
  lower_bottom()

The first and last one being just wrappers around raise() and lower(),
respectively. These methods have various issues: they omit the parent,
preferring to retrieve it from the actor passed as the first argument;
this does not match the new style of API introduced to operate on the
list of children of an actor.

Additionally, the raise() and lower() methods of ClutterActor call into
the Container interface, and are not really aptly named (raise() in
particular collides with the completely unrelated 'raise' keyword in
Python, and usually needs to be wrapped in order to be used at all).

Furthermore, we need public methods that Container can call from its
default implementation, as well as methods to port current Container
implementations.

Finally, since we have insert_child_at_index(), we should also have an
equivalent set_child_at_index() as well.
2012-01-16 23:37:13 +00:00
Emmanuele Bassi
fa1792c394 actor: Use flags to control add/remove child
The internal versions of add_child() and remove_child() currently use
boolean arguments to control things like the ChildMeta instances and
the emissions of signals; using more than one boolean argument is an
indication that you need flags to avoid readability issues, as well as
providing a way to add new behaviours without a combinatorial explosion
of arguments, later on.
2012-01-16 23:37:13 +00:00
Emmanuele Bassi
72fa75c034 actor: Remove automagic "expand" flag
I don't feel comfortable with this feature, and its implementation
still has too many rough edges. We can safely punt it for now, and
introduce it at a later point, as it doesn't block existing features
or API.
2012-01-16 23:37:13 +00:00
Emmanuele Bassi
508f09f0a0 actor: Ask the LayoutManager to compute the expansion flags
If an actor has a layout manager, we want to involve the delegate object
into the lazy computation of the expansion flags state.
2012-01-16 23:37:13 +00:00
Emmanuele Bassi
fd5e422b9f actor: Paint the background color in the paint class handler
We need to paint the background color in the default class handler for
two reasons: it's logically appropriate, and we don't want actor
subclasses overriding the ::paint class handler to change behaviour only
because somebody decided to set the background color.
2012-01-16 23:37:12 +00:00
Emmanuele Bassi
477c60c185 container: Provide default implementation of vfuncs
Instead of making ClutterActor implement the basic add/remove/foreach
virtual functions of ClutterContainer, we can simply do that from
within the ClutterContainer implementation.
2012-01-16 23:37:12 +00:00
Emmanuele Bassi
425ead5bd7 actor: Add some debug spew 2012-01-16 23:37:12 +00:00
Emmanuele Bassi
86152f478d docs: Update the Actor API reference
Given the size and scope of the changes in ClutterActor, we ought to
rewrite the overall description of what an actor is, what it does, and
how are you supposed to use it and subclass it.
2012-01-16 23:37:11 +00:00
Emmanuele Bassi
5959099473 Deprecate Container add() and remove() methods
This will make things interesting.

We have better replacements in ClutterActor, that do The Right Thing™
instead of deferring control and requiring reimplementation in every
single container actor.
2012-01-16 23:37:11 +00:00
Emmanuele Bassi
f61916fc5e actor: Add remove_all_children()
A simple method for removing all children of an actor in one fell swoop.
2012-01-16 23:37:11 +00:00
Emmanuele Bassi
673961f40c docs: Clarify the Actor's iterator API behaviour
It should be noted in the documentation that it is not safe to operate
on the list of children of an Actor while iterating over it.
2012-01-16 23:37:11 +00:00
Emmanuele Bassi
4f470b9231 actor: Provide a proper implementation of replace_child()
The correct sequence of actions should be remove(old) → insert(new), not
insert(new) → remove(old). We can implement a simple delegate insertion
functions to insert the new child between the previous and next siblings
of the old child.

While we're at it, let's also add a unit test for replace_child().
2012-01-16 23:37:11 +00:00
Emmanuele Bassi
5cba801207 actor: Fix get_paint_volume() default implementation
Providing a default get_paint_volume() that takes into account the
children of an actor was a goal of the whole First Apocalypse; if we
make all the containers rely on it, and yet we return a FALSE value
(meaning: we don't have a valid paint volume) even when we do have it,
then we are going to break the whole machinery, though.
2012-01-16 23:37:11 +00:00
Emmanuele Bassi
62535bdc73 actor: Simplify first/last child updates 2012-01-16 23:37:11 +00:00
Emmanuele Bassi
bd58694678 actor: Add replace_child() method
A simple method that atomically replaces a child actor with another one.
2012-01-16 23:37:10 +00:00
Emmanuele Bassi
238a6eb03d actor: Deprecate the old parent modifiers
The old API should not be used in newly written code; we have better
methods for setting up and modifying the scene graph, now.
2012-01-16 23:37:10 +00:00
Emmanuele Bassi
813eef4325 actor: Fix child insertion issues
The insert_child_at_index, insert_below and insert_above messed up the
first and last child pointers in various cases. This commit fixes all
the instances of first and last child pointers being stale or set to
NULL.
2012-01-16 23:37:10 +00:00
Emmanuele Bassi
8b430507b5 actor: Add children iteration methods
Instead of requiring every consumer of the ClutterActor API that wishes
to iterate over the children of an actor to use the get_children()
method, we should provide an iteration API directly inside ClutterActor
itself.
2012-01-16 23:37:09 +00:00
Emmanuele Bassi
22259e0965 actor: Define the scene structure inside Actor
Instead of storing the list of children, let's turn Actor inside a
proper node of a tree.

This change adds the following members to the Actor private data
structure:

  first_child
  last_child
  prev_sibling
  next_sibling

and removes the "children" GList from it; iteration is performed through
the direct pointers to the siblings and children.

This change makes removal, insertion before a sibling, and insertion
after a sibling constant time operations, but it still retains the
feature of ClutterActor.add_child() to build the list of children while
taking into account the depth set on the newly added child, to allow the
default painter's algorithm we employ inside the paint() implementation
to at least try and cope with the :depth property (albeit in a fairly
naïve way). Changes in the :depth property will not change the paint
sequence any more: this functionality will be restored later.
2012-01-16 23:37:09 +00:00
Emmanuele Bassi
71545ae56f actor: Use a cairo_rectangle_t instead of a ridiculous array
Make the code maintainable and readable.
2012-01-16 23:35:17 +00:00
Emmanuele Bassi
ea7111333b actor: Document fields of ClutterActorPrivate
The private data structure members could do with more comments
documenting what they do.
2012-01-16 23:35:17 +00:00
Emmanuele Bassi
9eed2f58a6 actor: Add TransformInfo
ClutterTransformInfo is a (private) ancillary data structure that
contains all the decomposed transformation data, i.e. rotation angles
and centers, scale factors and centers, and anchor point. This data
structure is stored in the GData of the actor instance instead of the
actor's private data. This change gives us:

  • a smaller, cleaner private data structure;
  • no size penalty for untransformed actors;
  • static constant storage for the defaults, shared across all
    instances;
  • cache locality for all the decomposed transformation data,
    given that the structure size is smaller.

At the end of the day, the only authoritative piece of information for
actor transformation is the CoglMatrix that we initialize in
apply_transform() from all the decomposed parameters, and that can stay
inside the private data structure of ClutterActor.
2012-01-16 23:35:17 +00:00
Emmanuele Bassi
376bf4a990 actor: Tweak the underallocation warning
There are only two kinds of actors that allow underallocations,
according to the API contract:

  • ClutterStage, as it is a viewport and it doesn't have an implicit
    minimum size;

  • Actors using the CLUTTER_ACTOR_NO_LAYOUT escape hatch, which allows
    them to bail out from our layout management policies.

The warning about underallocations should take these two exceptions
under consideration.
2012-01-16 23:35:17 +00:00
Emmanuele Bassi
7fd35edd3f actor: Make Actor instantiatable
ClutterActor now has all the API and capabilities for being a concrete
class:

  - layout management, through delegation
  - container implementation and API
  - background color

This means that a simple scene can be built straight out of actors
without using subclasses except for the Stage.

This is the first step towards the deprecation of most of the Actor
subclasses provided by Clutter.
2012-01-16 23:35:16 +00:00
Emmanuele Bassi
4acf8de8b4 actor: Provide more children methods
Add a getter for the number of children, as well as a method to retrieve
the child at a given index.
2012-01-16 23:35:16 +00:00
Emmanuele Bassi
e62536fad6 actor: Provide a better get_paint_volume() implementation
ClutterActor can do better by default than just giving up immediately.

An actor can check for the clip region, and for its children's paint
volume, for instance.

Just these two should give us a better default implementation for newly
written code.
2012-01-16 23:35:16 +00:00
Emmanuele Bassi
98a8feae64 actor: Background color
Each actor should have a background color property, disabled by default.

This property allows us to cover 99% of the use cases for
ClutterRectangle, and brings us one step closer to being able to
instantiate ClutterActor directly.
2012-01-16 23:35:15 +00:00
Emmanuele Bassi
7d88a70b78 actor: Cosmetic fixes to internal add/remove child
Avoid code duplication all over the place.
2012-01-16 23:35:15 +00:00
Emmanuele Bassi
ef3dc2d1ba actor: Make Actor.add_child and Container.add_actor idempotent
And make sure that overriding Container and calling
clutter_actor_add_child() will result in the same sequence of operations
as the current set_parent()+queue_relayout()+signal_emit pattern.

Existing containers can continue using:

        clutter_actor_set_parent (child, CLUTTER_ACTOR (container));
        clutter_actor_queue_relayout (CLUTTER_ACTOR (container));
        g_signal_emit_by_name (container, "actor-added", child);

and newly written containers overriding Container.add() can simply call:

        clutter_actor_add_child (CLUTTER_ACTOR (container), child);

instead.
2012-01-16 23:35:15 +00:00
Emmanuele Bassi
2894587b22 actor: Do not leak the layout manager 2012-01-16 23:35:15 +00:00
Emmanuele Bassi
b773785533 actor: Implement Container::sort_depth_order
There's no reason this vfunc should be left out.
2012-01-16 23:35:15 +00:00
Emmanuele Bassi
86ec629776 actor: Add child insertion methods
We should allow inserting children at given indices, and at given
stacking positions (relative or not to other children).
2012-01-16 23:35:14 +00:00
Emmanuele Bassi
37d46649ce actor: Adjust the preferred size too
Don't adjust just the allocation: we need to adjust the preferred size
of the actor to account for the margin.
2012-01-16 23:35:14 +00:00
Emmanuele Bassi
bf27575187 actor: Maintain invariants in add_child/remove_child
We need to queue a relayout when removing a visible child from a visible
parent.

We also need to insert the child at the right position (depending on the
depth) so that newly added actors will be painted on top.
2012-01-16 23:35:14 +00:00
Emmanuele Bassi
9d9e98968f actor: More cleanups to the Private data structure
Try to document it properly. We can also remove some things that are
properly encapsulated through functions, like the redraw clip volume.
2012-01-16 23:35:14 +00:00
Emmanuele Bassi
9132769767 actor: Store the fixed sizes into LayoutInfo
Remove four more floats from ClutterActorPrivate.

The fixed minimum and natural sizes should be stored inside the
ClutterLayoutInfo structure, along with the fixed position.
2012-01-16 23:35:14 +00:00
Emmanuele Bassi
b4d3b52b62 actor: Update the underallocations check
Add a failsafe against a NULL parent, to avoid a segfault when calling
clutter_actor_allocate() on the Stage.

We also need to deal with floating point values: straight comparison is
not going to cut it.
2012-01-16 23:35:14 +00:00
Emmanuele Bassi
409c3ed8ff actor: Adjust the allocation prior to call allocate()
ClutterActor has various properties controlling the allocation:

  - x-align, y-align
  - margin-top, margin-bottom, margin-left, margin-right

These properties should adjust the ClutterActorBox passed from the
parent actor to its children when calling clutter_actor_allocate(),
so that the child can just allocate its children at the right origin
with the right available size.
2012-01-16 23:35:14 +00:00
Emmanuele Bassi
a85c53ea0b actor: Clean up property installation 2012-01-16 23:35:14 +00:00
Emmanuele Bassi
a2a38ee797 actor: Add margin properties
The actor class should be able to hold the margin offsets like it does
for expand and alignment flags.

Instead of filling the private data structure with data, we should be
able to use an ancillary data structure, given that all this data is
optional and might never be set in the first place.
2012-01-16 23:35:13 +00:00
Emmanuele Bassi
c8659b6ca5 actor: Add [xy]-align
Allow an actor to define how it should occupy the extra space given to
by its parent during the allocation.
2012-01-16 23:35:13 +00:00
Emmanuele Bassi
4453ee7266 actor: Provide Container::raise/lower implementations 2012-01-16 23:35:13 +00:00
Emmanuele Bassi
752151bc97 actor: Remove is-a(Container) checks
All actors are now Container implementations, so there's no need to add
a type check.
2012-01-16 23:35:13 +00:00
Emmanuele Bassi
f2609dcca4 actor: Add [xy]-expand properties 2012-01-16 23:35:13 +00:00
Emmanuele Bassi
1c40151d0e actor: Default to a fixed layout manager
In case no layout manager was set during construction, we fall back to a
FixedLayout. The FixedLayout has the property of making the fixed
positioning and sizing API, as well as the various Constraints, work
out of the box.
2012-01-16 23:35:13 +00:00
Emmanuele Bassi
11e876c86b actor: Add :layout-manager
Now that ClutterActor implements the Container contract we can actually
defer the size negotiation to a ClutterLayoutManager directly from the
default implementation of the Actor's virtual functions.
2012-01-16 23:35:13 +00:00
Emmanuele Bassi
b45d78e6a1 actor: Provide a default Container implementation
We can provide most of the ClutterContainer implementation directly
within ClutterActor — basically removing the need of having the
Container interface in the first place. For backward compatibility
reasons we can keep the interface, but let Actor implement it directly.
2012-01-16 23:35:13 +00:00
Emmanuele Bassi
8462b5ba45 Do not use set_parent()/unparent() internally
Use add_child()/remove_child() instead.
2012-01-16 23:35:13 +00:00
Emmanuele Bassi
53aa64aeb9 actor: Provide add/remove child and get children methods
Let's try and move away from the reverse implicit scene graph build API,
which we mutuated from GTK+, towards a more traditional node/child API.

The set_parent()/unparent() API is confusing, unless you know the
history; having a add_child()/remove_child() methods pair makes it more
explicit.

We can easily implement the old set_parent()/unparent() pair in terms of
the newly add_child()/remove_child() one.
2012-01-16 23:35:13 +00:00
Emmanuele Bassi
7c14ba7d37 actor: Clean up the debug node for out-of-band transforms
Enclose the check inside a #ifdef CLUTTER_ENABLE_DEBUG ... #endif, so
that we can compile it out; also, use g_string_append() instead of the
g_string_append_printf() function, given that we're just concatenating
strings.
2012-01-16 11:04:44 +00:00