[squeak-dev] ENC: How to draw a 2D line

Jakob Reschke jakob.reschke at student.hpi.de
Mon Jun 26 20:20:46 UTC 2017


All morphs are freely positionable in the world and can be stacked
like the windows themselves (which are morphs, too). So you could
create/draw a morph with the necessary dimensions and place it such
that it overlaps with the windows as desired.

    (LineMorph from: 100 at 100 to: 200 at 300 color: Color yellow width: 5)
openInWorld

    window1 := ToolBuilder open: Browser new.
    window2 := ToolBuilder open: Workspace new.
    line := LineMorph
        from: (window1 findDeeplyA: SystemWindowButton) center
        to: (window2 findDeeplyA: TextMorph) positionInWorld
        color: Color red
        width: 3.
    line openInWorld.

2017-06-26 21:28 GMT+02:00 Kjell Godo <squeaklist at gmail.com>:
>
> is there a way to draw lines over top of all the open windows?
> like a line from inside of one window to inside of another window?
> like arrows from a help window to graphical elements in some other windows?
>
> On Sat, Jun 24, 2017 at 06:00 Jakob Reschke <jakob.reschke at student.hpi.de>
> wrote:
>>
>> Hi Lorenzo,
>>
>> Are you familiar with browsing existing code in Squeak already? If
>> not, I advise you have a look at the Squeak by Example book:
>> https://hal.inria.fr/inria-00441576/file/SBE.pdf
>> It also contains a chapter on drawing your own morphs.
>>
>> Otherwise you probably want to have a look at the classes Canvas and
>> Form. A Form contains pixels and a Canvas can be used to draw things
>> like points, lines, and other images to a graphical medium. A
>> FormCanvas (a subclass of Canvas) can be used to draw on a Form. To
>> display a Form in the world you can use an ImageMorph.
>>
>> The following creates a 32-Bit Form of 200x200 pixels, draws two lines
>> on it and attaches the image to the mouse cursor (hand).
>>
>> form := Form extent: 200 at 200 depth: 32.
>> canvas := FormCanvas on: form.
>> canvas line: 0 at 0 to: 200 at 200 color: Color red.
>> canvas line: 200 at 0 to: 0 at 200 color: Color blue.
>> morph := ImageMorph new.
>> morph image: form.
>> morph openInHand.
>>
>> You can then draw further stuff with the canvas and the morph will be
>> updated accordingly.
>>
>> Does this help you?
>>
>> Best regards,
>> Jakob
>>
>> 2017-06-23 22:43 GMT+02:00 Lorenzo Berendsen
>> <lorenzoberendsen at hotmail.com>:
>> > Hi All,
>> >
>> >
>> >
>> > I am trying to draw a simples 2D Line in months.
>> >
>> > I can’t understand what to do.
>> >
>> >
>> >
>> > Could someone help me with this?
>> >
>> > I have C, Pascal, VBA background, but none of these knowledge is helping
>> > me…
>> >
>> >
>> >
>> > Regards,
>> >
>> > Lorenzo.
>>
>


More information about the Squeak-dev mailing list