[Cuis-dev] VectorGraphics and Morph

Hilaire Fernandes hilaire at drgeo.eu
Fri Jun 19 03:41:42 PDT 2020


Hello,

I will resume my understanding of the situation and I will make an 
hopefully small request to Juan.

VectorGraphics canvas long time objective is to move from bitmap canvas 
to vector canvas. Then, the whole Cuis display content will be defined 
with vector operations. When needed, to display the whole screen or to 
refresh a damaged area, a rasterizing will occur. I think this part is 
pretty tricky with vector canvas.

As long as the Cuis world relies on the bitmap canvas, it is not 
directly possible to use vector operations to draw a morph because the 
canvas argument in the drawOn: is bitmap based and therefore does not 
understand the vector operations

Nevertheless, as shown with the circular toolbar, with a small hack, it 
is possible to draw a morph with vector operations. You needs to 
instantiate an intermediate vector canvas and a form where rasterization 
will take place. If you remember, Juan did some recent changes to make 
this work smoothly with transparent Form (a ticket was open to make the 
change hopefully permanent in the BitBlt plugin, for faster rendering). 
As a side benefit, the form instances are kept as cache for quick Morph 
rendering. As long as the Morph size does not change, no more vectors 
and rasterization operations are needed.

So all in all, although the Cuis canvas is still defined with Bitmap 
operations, it is now possible to have nice looking vector Morphs.

The typical code of such a Morph will look like this:

*drawOn: aCanvas*     aCanvas         image: (self mouseIsOver ifTrue:[ 
self buttonOverForm] ifFalse: [self buttonNormalForm])         at: `0 at 0`.

You can have two form caches, one for mouse over rendering.

*buttonOverForm*

     ^ buttonOverForm ifNil: [

         buttonOverForm _ self drawMyShapeWith: (Color white alpha: 
color alpha).

         icon ifNotNil: [icon displayOn: buttonOverForm at: center - 
(icon extent // 2) rule: Form blend].

         buttonOverForm]

You can compose the vector rendered part with other bitmap operation, ie 
to add an icon here.

*drawMyShapeWith: background*     | vectorCanvas aLocation aForm |     
aForm _ Form extent: extent depth: Display depth.     aForm fillColor: 
Color transparent.     vectorCanvas _ VectorCanvas onForm: aForm.     
aLocation _ AffineTransformation withTranslation: bounds topLeft 
negated.     vectorCanvas engine geometryTransformation: aLocation.     
vectorCanvas strokeWidth: 2 color: color muchDarker fillColor: 
background  do: [: engine |         engine abs_MoveToX: (corners 
floatAt: 1) y: (corners floatAt: 2);             abs_LineToX: (corners 
floatAt: 3) y: (corners floatAt: 4);             abs_ArcToX: (corners 
floatAt: 5) y: (corners floatAt: 6)                 radiusX: radius 
radiusY: radius angleOfXAxis: aperture largeFlag: false sweepFlag: 
false;             abs_LineToX: (corners floatAt: 7) y: (corners 
floatAt: 8);             abs_ArcToX: (corners floatAt: 1) y: (corners 
floatAt: 2)                 radiusX: innerRadius radiusY: innerRadius 
angleOfXAxis: aperture largeFlag: false sweepFlag: true].     ^ aForm

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.

If you are interested in graphics/morph sutff, I encourage you to take a 
look and have fun with your creativity.

Juan, about my request. An intermediate step to the whole Vector things 
for the Cuis display is a kind of PasteUpMorph accepting sub morphs 
directly rendered with vectorCanvas instance. I will be the first client 
with DrGeo to test  and to use it. It could be a next step to Dyanbook 
display too.

Hilaire

-- 
GNU Dr. Geo
http://drgeo.eu
https://pouet.chapril.org/@hilaire

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20200619/6e0382c7/attachment.htm>


More information about the Cuis-dev mailing list