<div dir="ltr">Hi,<div><span style="font-size:12.8000001907349px">> Currently I invalidate a layer and start by</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">> greating a new one. Is this the correct way, or are they reusable in a way?</span><br></div><div><span style="font-size:12.8000001907349px"><br></span></div><div><span style="font-size:12.8000001907349px">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 "</span><span style="font-size:12.8000001907349px">circle_layer" then when you call ebox_draw, you have to redraw the </span><span style="font-size:12.8000001907349px">"circle_layer" but you don't have to redraw the </span><span style="font-size:12.8000001907349px">"rectangle_layer".</span></div><div><span style="font-size:12.8000001907349px"><br></span></div><div><span style="font-size:12.8000001907349px">> The paint function is called at startup from the framework (via</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">> eclass_guiinit?).</span><span style="font-size:12.8000001907349px"><br></span></div><div><span style="font-size:12.8000001907349px"><br></span></div><div><span style="font-size:12.8000001907349px">No, </span><span style="font-size:12.8000001907349px">eclass_guiinit initializes the class for GUI behavior (the paint function can't be called because there isn't any object allocated).</span></div><div><span style="font-size:12.8000001907349px"><br></span></div><div><span style="font-size:12.8000001907349px">> The redraw function is called when the waveform is changed (manual at</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">> the moment).</span><span style="font-size:12.8000001907349px"><br></span></div><div><span style="font-size:12.8000001907349px"><br></span></div><div><span style="font-size:12.8000001907349px">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 them </span><font face="arial, helvetica, sans-serif">don't need to be redrawn) and then call </font><font face="arial, helvetica, sans-serif">ebox_redraw(). </font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">There's no "redraw", "invalidate", "state" method so</font></div><div><span class="" style="font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre;color:rgb(0,134,179)">eclass_addmethod</span><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre">(c, (method) wavesel_invalidate,  </span><span class="" style="font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre;color:rgb(24,54,145)"><span class="">"</span>invalidate<span class="">"</span></span><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre">,  A_SYMBOL, </span><span class="" style="font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre;color:rgb(0,134,179)">0</span><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre">);</span><font face="arial, helvetica, sans-serif"><br></font></div><div><span class="" style="font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre;color:rgb(0,134,179)">eclass_addmethod</span><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre">(c, (method) wavesel_state,     </span><span class="" style="font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre;color:rgb(24,54,145)"><span class="">"</span>state<span class="">"</span></span><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre">,     A_NULL, </span><span class="" style="font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre;color:rgb(0,134,179)">0</span><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre">);</span><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre"><br></span></div><div><span class="" style="font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre;color:rgb(0,134,179)">eclass_addmethod</span><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre">(c, (method) wavesel_redraw,    </span><span class="" style="font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre;color:rgb(24,54,145)"><span class="">"</span>redraw<span class="">"</span></span><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre">,    A_NULL, </span><span class="" style="font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre;color:rgb(0,134,179)">0</span><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre">);</span></div><div><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre">are useless methods. </span><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre"><br></span></div><div><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre">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. </span></div><div><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre"><br></span></div><div><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre">Now I'll try to explain everything better : </span></div><div><span style="font-size:12.8000001907349px">When the object is allocated in the patch, the method paint is called :</span></div><div><span style="font-size:12.8000001907349px"><br></span></div><div><div style=""><span style="font-size:12.8000001907349px">static void wavesel_paint(t_wavesel *x, t_object *view)</span></div><div style=""><span style="font-size:12.8000001907349px">{</span></div><div style=""><span style="font-size:12.8000001907349px">    t_rect bg_rect;</span></div><div style=""><span style="font-size:12.8000001907349px">    ebox_get_rect_for_view((t_ebox *)x, &bg_rect);</span></div><div style=""><span style="font-size:12.8000001907349px"><br></span></div><div style=""><span style="font-size:12.8000001907349px">    </span>t_elayer *g = ebox_start_layer((t_ebox *)x, bg_layer_name, rect->width, rect->height);</div><div>   if (g)</div><div>  {</div><div>      Here you can draw what you want in the "bg_layer_name" layer.</div><div>     Then you finish your layer with </div><div><br></div><div>  }</div><div>  ebox_paint_layer((t_ebox *)x, bg_layer_name, 0.f, 0.f);</div><div style=""><span style="font-size:12.8000001907349px">}</span></div></div><div><span style="font-size:12.8000001907349px"><br></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-07-10 14:33 GMT+02:00 Fred Jan Kraan <span dir="ltr"><<a href="mailto:fjkraan@xs4all.nl" target="_blank">fjkraan@xs4all.nl</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Pierre,<br>
<br>
Currently, graphics data is drawn to the canvas, but nothing is erased.<br>
If I specify a new waveform, it is drawn over the previous one, instead<br>
of removing it first.<br>
<br>
The real code is a bit messy due to the implementation details, but<br>
below is the skeleton, containing the framework interactions and key<br>
data. The paint function is called at startup from the framework (via<br>
eclass_guiinit?).<br>
The redraw function is called when the waveform is changed (manual at<br>
the moment).<br>
<br>
draw_background function:<br>
- ebox_start_layer(background_layer)<br>
- ebox_paint_layer()<br>
<br>
draw_waveform function:<br>
- ebox_start_layer(waveform_layer)<br>
- egraphics_line_fast(... here the waveform is defined ...)<br>
- ebox_end_layer()<br>
- ebox_paint_layer()<br>
<br>
paint function:<br>
- draw_background()<br>
- draw_waveform()<br>
<br>
redraw function:<br>
- ebox_invalidate_layer(background_layer)<br>
- ebox_invalidate_layer(waveform_layer)<br>
- paint()<br>
- ebox_redraw()<br>
<br>
<br>
You can look at the current code in my toy github repository:<br>
<a href="https://github.com/electrickery/pd-playground/tree/cicm/cicm-wavesel" rel="noreferrer" target="_blank">https://github.com/electrickery/pd-playground/tree/cicm/cicm-wavesel</a><br>
<br>
Greetings,<br>
<br>
Fred Jan<br>
</blockquote></div><br></div>