[Pharo-dev] [bloc] shape size?

Tudor Girba tudor at tudorgirba.com
Sun Apr 3 03:18:05 EDT 2016


Hi Igor,

Thanks for this nice description :).

Indeed, the Shape in Bloc is primarily a clipping shape that knows how to draw the path around and to fill itself. Of course, it also handles the interaction.

When you want to have a composition, you are encouraged to create multiple elements (morphs). This is a way to handle both more complicated interaction and more complicated drawing. Of course, you can still override the drawing method and draw whatever you want on it, but we would rather have a simple composition.

The disadvantage of this design is that indeed, is that it is not sophisticated. The advantage of this design is that it is not sophisticated :) and you get only one tree of compositions for the elements without another level of composition at the shape level. The main reason we went this route is because we want Bloc to pose as little constraints for the things built on top as possible without losing power.

Does this make sense for you?

Cheers,
Doru


> On Apr 3, 2016, at 6:38 AM, Igor Stasenko <siguctua at gmail.com> wrote:
> 
> Oh, yeah.. i missed one more kind of shape, you may want to introduce:
>  - clipping shape.
> 
> For optimizing drawing operations, you may want to define a region, which guarantees, that anything you paint, nothing outside defined region will affect the screen. Because else, you will allow morph to render anywhere and therefore, it is really hard for UI subsystem to account damage on the screen.
> But once you define such shape, then you can clearly tell, which portion of the screen may or may not be damaged and therefore act accordingly.
> 
> So, overall when we talking about shapes, we need to talk about three different kinds of them:
> 
> - UI interaction shape
> - clipping shape
> - shape(s) used to draw
> 
> those three may or may not coincide into single one, depending on complexity and what you wanna do.. 
> But they can be completely different from each other and in order to avoid confusion and frustration, i would really introduce them in such manner, that users have clear vision on what happens with their morphs and how to achieve what they want.
> 
> Clearly, a single #shape: is not enough, if you want a non-conflicting representation of these concepts in UI.
> 
> 
> On 3 April 2016 at 07:15, Igor Stasenko <siguctua at gmail.com> wrote:
> 
> 
> On 2 April 2016 at 20:59, stepharo <stepharo at free.fr> wrote:
> 
> 
> Le 2/4/16 17:31, Aliaksei Syrel a écrit :
>> You don't want to draw a shape, you configure it. Shape can not be drawn, it is not an AthensPath.
>> 
>> cell shape: (BlShape new
>>   path: BlCirclePath new;
>>   strokePaint: (BlStrokePaint new
>>      paint: Color blue;
>>      width: 1)).
>> cell extent: 50 at 50.
>> 
> 
> But this is not what I want! As I mentioned in a mail that was sent but never arrived. 
> I want a square and this is why I did
> 
> BlCell>>initialize
>     super initialize.
>     self
>         shape:
>             (BlShape new
>                 fillPaint: (BlColorPaint new color: (Color yellow));
>                 path: BlRectanglePath new);
>         extent: self extent
> 
> 
> then I want to draw something extra this is why I overrode drawOnAthensCanvas: aCanvas
> 
> Now I stop but I find bloc too complex. 
> 
> Sorry but I cannot lose time like that and just get frustrated at the end. 
> I will use the athens canvas directly and stay in morph for now. 
> 
> 
> I think there's a bit of misconception.
> In Athens, shape representing any area you wanna fill with paint. Period.
> It can be of any complexity, self-intersecting yadda yadda.. the main point is that it defines a region(s), that going to be filled with chosen paint during draw operation.
> From perspective of morphs, as UI elements, most of them require some shape(s) to represent themselves on the screen. But there are morphs, that while still taking part in UI, don't need any shapes since they never drawn on the screen.
> Another point is that nowhere said that morph can be represented by a one and only one shape period. Because as in your case, you want to, say, draw rectangle with paint A, and circle with paint B, then you basically need two different shapes (overlapping or not - not really matters) to represent morph on the screen.
> 
> So, the first point in misconception comes from 'self shape:'.. 
> It is wrong from that perspective, because it is all fine, when morph using only single shape to represent itself.. but when you need multiple shapes, you are in trouble. It at least misleading, because provoking you to think that there can be only one.
> 
> Then you need to invent a 'composite shape' that basically a collection of shapes for a single morph, that will represent it on the screen.
>  
> A tangent to that, is that since most of morphs has mostly static geometry/topology and changing it very rarely and much less often comparing to drawing same shape(s) over and over again, it is right thing to define and initialize shape(s) and reuse them later in #draw method. Since you don't change shape(s), you don't have to generate new object(s).
> From that perspective, this is nice, resource saving, approach.
> But let us not forget, that this is just a 'statistical observation' and hence good to be a default setup. But it should not dictate you the rule(s).
> You should still be able to define shape(s) on the fly or change it on the fly, dynamically.
> 
> Another problematic is that you may want to use different shapes for
> a) painting morph on screen
> b) defining geometry of the morph for UI interactions.
> As an example, let say, you want a rectangle with circle in centre on the screen, but also want morph to react on mouse over/clicks only if mouse cursor is inside a circle, but not when it's over an area covered by rectangle.
> 
> What it means, that from UI perspective, you want from morph to define its shape, lets call it 'UI interaction shape'.. and from that perspective 'self shape:' is a good choice. But as example says, it has nothing to do with 'drawing shape(s)', which may or may not coincide with shape you using for UI interaction(s).
> 
> Because it defines an area, where UI stuff could happen. And indeed, you really need one, and only one. You don't need multiple shapes there, since it serves to answer a simple question: 'are my mouse in interesting region or not'?.
> Like in your case, when you having box with circle inside , which is two shapes, but only one shape that can define an interesting region, it could be: 
> - intersection of 
> - union 
> - subtraction 
> 
> And that could be completely different from shape(s) you may need to draw it on the screen.
> 
> Stef
> 
>> On Apr 2, 2016 4:57 PM, "stepharo" <stepharo at free.fr> wrote:
>> Hi
>> 
>> I want a square morph with a circle or a line at 45 degree inside
>> Now I do not get it.
>> 
>> I thought that I needed to specialize drawOnAthensCanvas: so I did
>> 
>> BlCell >> drawOnAthensCanvas: aCanvas
>> 
>>     super drawOnAthensCanvas: aCanvas.
>>     aCanvas
>>         drawShape: (BlShape new
>>                                 strokePaint:
>>                                    (BlStrokePaint new
>>                                         paint: (BlColorPaint new color: (Color blue));
>>                                           width: 15);
>>                             path: BlCirclePath new).
>> 
>> Now I do not know how I can specify a shape size
>> 
>> So I will use another API than drawShape:
>> 
>> Stef
>> 
> 
> 
> 
> 
> -- 
> Best regards,
> Igor Stasenko.
> 
> 
> 
> -- 
> Best regards,
> Igor Stasenko.

--
www.tudorgirba.com
www.feenk.com

"Reasonable is what we are accustomed with."




More information about the Pharo-dev mailing list