Hi (sorry the message wasn't finished....),> Currently I invalidate a layer and start by
> greating a new one. Is this the correct way, or are they reusable in a way?
Yes, in fact when you create a layer for the 1st time, the function allocates a layer. If the layer already exists but has been invalidated the function returns the old pointer with empty paths. Otherwise, the function returns NULL. If you have a "circle_layer" and a "rectangle_layer" and you want to change the color or the size of the "circle_layer", you have to invalidate the "circle_layer" then when you call ebox_draw, you have to redraw the "circle_layer" but you don't have to redraw the "rectangle_layer".
> The paint function is called at startup from the framework (via
> eclass_guiinit?).
No, eclass_guiinit initializes the class for GUI behavior (the paint function can't be called because there isn't any object allocated).
> The redraw function is called when the waveform is changed (manual at
> the moment).
Yes, when you want to change a layer, you have to invalidate this layer (you don't have to invalidate all the layers if some of themdon't need to be redrawn) and then call ebox_redraw().
There's no "redraw", "invalidate", "state" method so
eclass_addmethod(c, (method) wavesel_invalidate, "invalidate", A_SYMBOL, 0);
eclass_addmethod(c, (method) wavesel_state, "state", A_NULL, 0);
eclass_addmethod(c, (method) wavesel_redraw, "redraw", A_NULL, 0);
are useless methods.
I think you use the c.blackboard as a template but you should prefer to use c.bang or something simpler. c.blackboard is a little bit tricky.
Now I'll try to explain everything better :
static void wavesel_paint(t_wavesel *x, t_object *view)
{
t_rect bg_rect;
ebox_get_rect_for_view((t_ebox *)x, &bg_rect);
// Background layer
t_elayer *g = ebox_start_layer((t_ebox *)x, bg_layer_name, rect->width, rect->height);
if (g)
{
Here you can draw what you want in the "bg_layer_name" layer.
Then you finish your layer with :
ebox_end_layer((t_ebox*)x, bg_layer_name);
}
ebox_paint_layer((t_ebox *)x, bg_layer_name, 0.f, 0.f); // The box paint the layer
// Waveform layer
t_elayer *g = ebox_start_layer((t_ebox *)x, fg_layer_name, rect->width, rect->height);
if (g)
{
Here you can draw what you want in the "fg_layer_name" layer.
Then you finish your layer with :
ebox_end_layer((t_ebox*)x, fg_layer_name);
}
ebox_paint_layer((t_ebox *)x, fg_layer_name, 0.f, 0.f); // The box paint the layer
}
Now you want to change the "fg_layer_name" layer when the buffer has changed for example :
static void wavesel_setarray(t_wavesel *x, t_symbol *s)
{
// Load the new buffer
ebox_invalidate_layer((t_ebox *)x, fg_layer_name); << invalidate "fg_layer_name" the layer (the "bg_layer_name" doesn't change so you don't have to invalidate the layer)
ebox_redraw((t_ebox *)x); // the function calls the paint method of the object (and some other stuff)
//
// You don't have to call wavesel_paint(x, 0);
}
The Graphic API is very similar to the Max's Graphical API so you can also have a look at it but a lot of thing are explained here :
Cheers