[Cuis-dev] VectorGraphics and Morph

Juan Vuletich juan at jvuletich.org
Fri Jun 19 08:30:25 PDT 2020


On 6/19/2020 10:55 AM, Mariano Montone via Cuis-dev wrote:
> El 19/6/20 a las 07:41, Hilaire Fernandes via Cuis-dev escribió:
>
>> It is the vector rendering, specific to the Morph.
>>
>> *isOrthoRectangularMorph*     ^ false
>>
>> Inform it is not rectangular, Juan already prepare this.
>>
>> *morphContainsPoint: aLocalPoint*     | polarPoint min max |     (self
>> morphLocalBounds containsPoint: aLocalPoint) ifFalse: [^ false].    
>> polarPoint _ (aLocalPoint + bounds topLeft - radius asPoint) * (1 @ -1).
>>      min _  Float halfPi - (aperture / 2) - shift.     max _ Float halfPi
>> + (aperture / 2) - shift.     ^ (polarPoint r         between:
>> innerRadius         and: radius)             and: ["Deal when crossing
>> zero"                 (polarPoint theta                     between: min
>>                      and:  max)                 or: [polarPoint theta    
>>                      between: min + Float twoPi                        
>> and:  max + Float twoPi                     ]                 ]
>>
>> Then you can have Morph detection/selecting really matching the vector
>> shape.
> I've been developing a Diagrams tool in Cuis using Cairo, and needed
> this for shapes and connectors there.
>
> And used the hit canvas technique:
> https://www.w3.org/wiki/Canvas_hit_testing
>
> The interesting thing about it is that you get precise
> morphContainsPoint implementation, without having to do any calculations
> at all! You just let the morph draw (both on vector canvas and hit
> canvas, then use hit canvas for point containment detection).
>
> Implementation is here at the moment:
> https://bitbucket.org/mmontone/mold/src/master/Dia.pck.st
>
> Cheers!
>
> Mariano

VectorEngine already does this. It includes an extra buffer, ivar 
'morphIds' in VectorEngine classes. Recently I also added ivar 'id' to 
Morph. For every pixel the engine draws in the context of a Morph, its 
id is stored at pixel position in morphIds. Then, it is just a matter of 
querying morphIds.

For Cairo, the technique you wrote can be used. For regular, 
orthorectangular morhps in BitBlt canvas, the simple existing code can 
still be used. For morphs that use VectorGraphics to build cached Forms, 
as developed by Hilaire, it is just a matter of querying the form for 
transparency.

All this means that soon no morph will need to include geometry specific 
code for hit detection (#morphContainsPoint:) at all.

All we need to do is to make all this work consistently in a framework.

Thank you Hilaire and Mariano! You are really helping Morphic3 / 
VectorGraphics in Cuis become a reality.

Cheers,

-- 
Juan Vuletich
www.cuis-smalltalk.org
https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev
https://github.com/jvuletich
https://www.linkedin.com/in/juan-vuletich-75611b3
@JuanVuletich



More information about the Cuis-dev mailing list