[Cuis-dev] custom morph confusion

Juan Vuletich juan at cuis.st
Fri Jul 12 09:03:47 PDT 2024


It looks ok to me, except for the missing $] at the end of #drawOn:

Cheers,

On 7/11/2024 8:50 PM, Mark Volkmann via Cuis-dev wrote:
> On Thu, Jul 11, 2024 at 5:51 PM Juan Vuletich <juan at cuis.st 
> <mailto:juan at cuis.st>> wrote:
>
>     On 7/11/2024 4:39 PM, Mark Volkmann via Cuis-dev wrote:
>>     When creating a custom morph it's not clear to me whether I
>>     should subclass PlacedMorph or BoxedMorph.
>>
>>     I see that PlacedMorph doesn't hold the size of the morph, but
>>     BoxedMorph does. BoxedMorph has the instance variable extent and
>>     the accessors morphExtent and morphExtent:. I want to be able to
>>     set the extent of my custom morph instances and utilize that size
>>     information in my drawOn: method.
>>
>>     However, the drawOn: method in PlaceMorph uses a VectorCanvas and
>>     BoxedMorph uses a HybridCanvas. HybridCanvas doesn't have the
>>     strokeWidth:color:fillColor:do: method and I want to use that.
>>
>>     I could add my own extent instance variable to my PlacedMorph
>>     subclass, but that feels wrong.
>>
>>     I need some advice on this.
>>
>>     -- 
>>     R. Mark Volkmann
>>     Object Computing, Inc.
>     BoxedMorph are a Hierarchy for morphs that are rectangle like, and
>     that occupy an area that can be specified as a Rectangle. This
>     means that, besides being of rectangular shape, sides are aligned
>     with local coordinate axes. Including rectangles with rounded
>     corners and such. The idea is that the 'extent' ivar is all that's
>     needed to establish our dimensions and shape.
>
>     They are used, for example, for common widgets.
>
>     If your morph is not in the shape of a rectangle, it is better to
>     make it a PlacedMorph. See `PlacedMorph subclasses`, and play with
>     instances of them in your Morphic World to see some of the things
>     that can be done.
>
>     See #requiresVectorCanvas and #knowsOwnLocalBounds. You can
>     redefine #requiresVectorCanvas in a subclass of BoxedMorph if
>     desired. But see, in the other subclasses of PlacedMorph, the kind
>     of freedom you get when you can make #knowsOwnLocalBounds answer
>     false.
>
>     Finally, you can add whatever instance variable you need to any of
>     your classes. You're the master. Why would adding 'extent' to your
>     own PlacedMorph feel wrong, if that happens to be what you need /
>     want? Don't be shy. You're just playing.
>
>     Happy explorations!
>
>
> Thanks Juan! I suppose the reason I thought that adding an `extent` 
> instance variable to my class was suspect is that I would get that 
> automatically if I subclass BoxedMorph instead of PlacedMorph.
>
> Here is my latest code that subclasses PlacedMorph and does add an 
> `extent` instance variable. I'm curious if anyone sees anything 
> suspect in this code.
>
> PlacedMorph subclass: #CanvasDemo
>     instanceVariableNames: 'extent'
>     classVariableNames: ''
>     poolDictionaries: ''
>     category: 'Volkmann'
>
> extent
>     ^ extent
>
> extent: aPoint
>     extent := aPoint
>
> initialize
>     super initialize.
>     extent := 100 @ 100
>
> drawOn: aCanvas
>     | x1 x2 y1 y2 |
> x1 := 0.
> y1 := 0.
> x2 := extent x.
> y2 := extent y.
> aCanvas strokeWidth: 10 color: Color red fillColor: Color green do: [
> aCanvas
> moveTo: x1 @ y1;
> lineTo: x2 @ y2;
> lineTo: x2 @ y1;
> lineTo: x1 @ y1;
> lineTo: x1 @ y2;
> lineTo: x2 @ y2
>
> Here's an example of using this class:
>
> cd := CanvasDemo new extent: 300 at 400.
> cd openInHand.
>
> -- 
> R. Mark Volkmann
> Object Computing, Inc.


-- 
Juan Vuletich
cuis.st
github.com/jvuletich
researchgate.net/profile/Juan-Vuletich
independent.academia.edu/JuanVuletich
patents.justia.com/inventor/juan-manuel-vuletich
linkedin.com/in/juan-vuletich-75611b3
twitter.com/JuanVuletich

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20240712/867da7c8/attachment.htm>


More information about the Cuis-dev mailing list