[squeak-dev] morph selector x: x and y: y

Nicolai Hess nicolaihess at gmail.com
Tue Mar 5 10:05:03 UTC 2013


2013/3/5 Casey Ransberger <casey.obrien.r at gmail.com>

> I don't have access to an image often enough. Sounds like you might have
> an interesting bug. Would you post the two implementations, if they aren't
> long?
>
>
> On Mon, Mar 4, 2013 at 11:46 PM, Nicolai Hess <nicolaihess at gmail.com>wrote:
>
>> Hi,
>>
>> someone knows why Morphs selector x x: and y y: are
>> implemented differently?
>>
>> Morph y and y: testing wether self world is nil
>> whereas x and x: doesn't.
>>
>> Btw. what is the preferred way to position morphs relative
>> to the bounds of its owner. It seems morph positions are always
>> absolute coordinates.
>>
>> regards
>>  Nicolai
>>
>>
>>
>>
>
>
> --
> Casey Ransberger
>
>
>

x: aNumber
    "Set my horizontal position relative to the cartesian origin of the
playfield or the world."

    | offset aPlayfield newX |
    aPlayfield := self referencePlayfield.
    offset := self left - self referencePosition x.
    newX := aPlayfield isNil
                ifTrue: [aNumber + offset]
                ifFalse: [aPlayfield cartesianOrigin x + aNumber + offset].
    self position: newX @ bounds top


y: aNumber
    "Set my vertical position relative to the cartesian origin of the
playfield or the world. Note that larger y values are closer to the top of
the screen."

    | w offset newY aPlayfield |
    w := self world.
    w ifNil: [^self position: bounds left @ aNumber].
    aPlayfield := self referencePlayfield.
    offset := self top - self referencePosition y.
    newY := aPlayfield isNil
                ifTrue: [w bottom - aNumber + offset]
                ifFalse: [aPlayfield cartesianOrigin y - aNumber + offset].
    self position: bounds left @ newY
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20130305/6120bcf7/attachment.htm


More information about the Squeak-dev mailing list