<div dir="ltr"><span style="font-size:12.8000001907349px">Hi (sorry the message wasn't finished....),</span><span class="im" style="font-size:12.8000001907349px"><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></span><div style="font-size:12.8000001907349px"><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><span class="im" style="font-size:12.8000001907349px"><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></span><div style="font-size:12.8000001907349px"><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><span class="im" style="font-size:12.8000001907349px"><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></span><div style="font-size:12.8000001907349px"><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 style="font-size:12.8000001907349px"><font face="arial, helvetica, sans-serif"><br></font></div><div style="font-size:12.8000001907349px"><font face="arial, helvetica, sans-serif">There's no "redraw", "invalidate", "state" method so</font></div><div style="font-size:12.8000001907349px"><span style="font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap;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-wrap">(c, (method) wavesel_invalidate,  </span><span style="font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap;color:rgb(24,54,145)">"invalidate"</span><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap">,  A_SYMBOL, </span><span style="font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap;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-wrap">);</span><font face="arial, helvetica, sans-serif"><br></font></div><div style="font-size:12.8000001907349px"><span style="font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap;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-wrap">(c, (method) wavesel_state,     </span><span style="font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap;color:rgb(24,54,145)">"state"</span><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap">,     A_NULL, </span><span style="font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap;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-wrap">);</span><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap"><br></span></div><div style="font-size:12.8000001907349px"><span style="font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap;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-wrap">(c, (method) wavesel_redraw,    </span><span style="font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap;color:rgb(24,54,145)">"redraw"</span><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap">,    A_NULL, </span><span style="font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap;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-wrap">);</span></div><div style="font-size:12.8000001907349px"><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap">are useless methods. </span><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap"><br></span></div><div style="font-size:12.8000001907349px"><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap">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 style="font-size:12.8000001907349px"><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap"><br></span></div><div style="font-size:12.8000001907349px"><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap">Now I'll try to explain everything better : </span></div><div style="font-size:12.8000001907349px"><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap"><br></span></div><div style=""><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">static void wavesel_paint(t_wavesel *x, t_object *view)</span></div><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">{</span></div><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">    t_rect bg_rect;</span></div><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">    ebox_get_rect_for_view((t_ebox *)x, &bg_rect);</span></div><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px"><br></span></div><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">  // Background layer</span></div><div style="font-size:12.8000001907349px"><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 style="font-size:12.8000001907349px">   if (g)</div><div style="font-size:12.8000001907349px">  {</div><div style="font-size:12.8000001907349px">      Here you can draw what you want in the "bg_layer_name" layer.</div><div style="font-size:12.8000001907349px">     Then you finish your layer with :</div><div style="font-size:12.8000001907349px">     ebox_end_layer((t_ebox*)x, <span style="font-size:12.8000001907349px">bg_layer_name</span>);</div><div style="font-size:12.8000001907349px">  }</div><div style="font-size:12.8000001907349px">  ebox_paint_layer((t_ebox *)x, bg_layer_name, 0.f, 0.f); // The box paint the layer</div><div style="font-size:12.8000001907349px"><br></div><div style="font-size:12.8000001907349px"><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px"> // Waveform layer</span></div><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">    </span>t_elayer *g = ebox_start_layer((t_ebox *)x, <span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:16.7999992370605px;white-space:pre">fg_layer_name</span>, rect->width, rect->height);</div><div style="font-size:12.8000001907349px">   if (g)</div><div style="font-size:12.8000001907349px">  {</div><div style="font-size:12.8000001907349px">      Here you can draw what you want in the "<span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:16.7999992370605px;white-space:pre">fg_layer_name</span>" layer.</div><div style="font-size:12.8000001907349px">     Then you finish your layer with :</div><div style="font-size:12.8000001907349px">     ebox_end_layer((t_ebox*)x, <span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:16.7999992370605px;white-space:pre">fg_layer_name</span>);</div><div style="font-size:12.8000001907349px">  }</div><div style="font-size:12.8000001907349px">  ebox_paint_layer((t_ebox *)x, <span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:16.7999992370605px;white-space:pre">fg_layer_name</span>, 0.f, 0.f); <span style="font-size:12.8000001907349px"> //</span><span style="font-size:12.8000001907349px"> The box paint the layer</span></div></div><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">}</span></div><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px"><br></span></div><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">Now you want to change the "fg_layer_name" layer when the buffer has changed for example :</span></div><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px"><br></span></div><div style=""><span style="font-size:12.8000001907349px">static void wavesel_setarray(t_wavesel *x, t_symbol *s)</span><br></div><div style=""><span style="font-size:12.8000001907349px">{</span></div><div style=""><span style="font-size:12.8000001907349px">    // Load the new buffer</span></div><div style=""><span style="font-size:12.8000001907349px">    </span><span style="font-size:12.8000001907349px">ebox_invalidate_layer((t_ebox *)x, </span><span style="font-size:12.8000001907349px">fg_layer_name</span><span style="font-size:12.8000001907349px">); << invalidate </span><span style="font-size:12.8000001907349px">"fg_layer_name" </span><span style="font-size:12.8000001907349px">the layer (the </span><span style="font-size:12.8000001907349px">"bg_layer_name" doesn't change so you don't have to invalidate the layer)</span></div><div style=""><span style="font-size:12.8000001907349px">  ebox_redraw((t_ebox *)x); // the function calls the paint method of the object (and some other stuff)</span></div><div style=""><span style="font-size:12.8000001907349px">  // </span></div><div style=""><span style="font-size:12.8000001907349px"> // You don't have to call wavesel_paint(x, 0);</span></div><div style=""><span style="font-size:12.8000001907349px">}</span></div><div style=""><span style="font-size:12.8000001907349px"><br></span></div><div style=""><span style="font-size:12.8000001907349px">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 :</span></div><div style=""><span style="font-size:12.8000001907349px"><a href="http://cicm.github.io/CicmWrapper/a00002.html">http://cicm.github.io/CicmWrapper/a00002.html</a></span><br></div><div style=""><span style="font-size:12.8000001907349px"><br></span></div><div style=""><span style="font-size:12.8000001907349px">Cheers</span></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-07-11 16:18 GMT+02:00 Pierre Guillot <span dir="ltr"><<a href="mailto:guillotpierre6@gmail.com" target="_blank">guillotpierre6@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<span class=""><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></span><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><span class=""><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></span><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><span class=""><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></span><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 style="font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap;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-wrap">(c, (method) wavesel_invalidate,  </span><span style="font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap;color:rgb(24,54,145)"><span>"</span>invalidate<span>"</span></span><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap">,  A_SYMBOL, </span><span style="font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap;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-wrap">);</span><font face="arial, helvetica, sans-serif"><br></font></div><div><span style="font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap;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-wrap">(c, (method) wavesel_state,     </span><span style="font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap;color:rgb(24,54,145)"><span>"</span>state<span>"</span></span><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap">,     A_NULL, </span><span style="font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap;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-wrap">);</span><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap"><br></span></div><div><span style="font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap;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-wrap">(c, (method) wavesel_redraw,    </span><span style="font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap;color:rgb(24,54,145)"><span>"</span>redraw<span>"</span></span><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap">,    A_NULL, </span><span style="font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap;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-wrap">);</span></div><div><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap">are useless methods. </span><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap"><br></span></div><div><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap">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-wrap"><br></span></div><div><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:18.2000007629395px;white-space:pre-wrap">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><span style="font-size:12.8000001907349px">static void wavesel_paint(t_wavesel *x, t_object *view)</span></div><div><span style="font-size:12.8000001907349px">{</span></div><div><span style="font-size:12.8000001907349px">    t_rect bg_rect;</span></div><div><span style="font-size:12.8000001907349px">    ebox_get_rect_for_view((t_ebox *)x, &bg_rect);</span></div><div><span style="font-size:12.8000001907349px"><br></span></div><div><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><span style="font-size:12.8000001907349px">}</span></div></div><div><span style="font-size:12.8000001907349px"><br></span></div></div><div class="HOEnZb"><div class="h5"><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>
</div></div></blockquote></div><br></div>