[Pharo-dev] Coordinates problem with Athens and Morphic while coding Hyperion

Igor Stasenko siguctua at gmail.com
Thu Nov 28 05:29:44 EST 2013


well, by default the athens canvas coordinate system matches morphic one..
but you know, it always hard to be sure, especially if you perform any
local coordinate transformations before that morph has any chance to draw
itself..

You can figure this out easily: draw something at 0 at 0 and see where it is.
then draw something at morph's x at y position and see it too.

btw, you know you don't have to create same paths over and over.
you can easily put static parts out of regularly (and costly) evaluated
code:

shape := canvas cacheAt: self "morph" ifAbsentPut: [
                aCanvas createPath: [:path |
path relative.
" no move-to here ***  path moveTo: ((self position x )+5)@(self position
y);"
lineTo: 20 at 0;
cwArcTo: 5 at 5 angle: 45;
lineTo: 0 at 20;
 cwArcTo: (-5)@5 angle: 45;
lineTo: (-20)@0;
cwArcTo: (-5)@(-5) angle: 45;
 lineTo: 0@(-20);
cwArcTo: 5@(-5) angle: 45.
  ].
].

"and here we're using coordinate transform to translate origin point to
given position, so it will be the starting point (0 at 0) of our shape"

canvas pathTransform restoreAfter: [
   canvas pathTransform translateBy:((self position x )+5)@(self position
y).
   canvas drawShape: shape.
]

by analogy you can cache all static pieces, just do something:

shapes := canvas cacheAt: self ifAbsentPut: [ self constructStaticShapesOn:
aCanvas ]

where #constructStaticShapesOn: must answer an array of them.


On 28 November 2013 11:12, kilon alios <kilon.alios at gmail.com> wrote:

> wow you guys are fast at replying :)
>
> I did
>
>
> self changeProportionalLayout.
> editButton := HypEditButton new .
>  editButton position: 0 at 0.
> self addMorph: editButton fullFrame: #(0 0 0 0 0 0 100 100).
>
> I am afraid Igor I still see no change with your code.
>
> I like to note here, that when I first created the editButton as morph ,
> it indeed placed it in correct place. A 0 at 0 placed it in top left corner
> as expected. But I did overide its DrawOn:  with an empty method and used
> my own method to render it with Athens. So it looks like the problem is
> Athens related and not Morphic related or maybe a disagreement between
> Morphic and Athens.
>
> just for the record here is the code I use to render the HypEditButton
> morph
>
> render:aCanvas
> |shape1 shape2 shape3 editButtonColor |
> shape1 := aCanvas createPath: [:path |
> path relative .
>  path moveTo: ((self position x )+5)@(self position y);
>  lineTo: 20 at 0;
> cwArcTo: 5 at 5 angle: 45;
> lineTo: 0 at 20;
>  cwArcTo: (-5)@5 angle: 45;
> lineTo: (-20)@0;
> cwArcTo: (-5)@(-5) angle: 45;
>  lineTo: 0@(-20);
> cwArcTo: 5@(-5) angle: 45.
>   ].
>  shape2 := aCanvas createPath: [:path |
> path relative .
>  path moveTo: ((self position x +7))@((self position y +3));
> lineTo: 18 at 0;
>  cwArcTo: 2 at 2 angle: 45;
> lineTo: 0 at 20;
> cwArcTo: (-2)@2 angle: 45;
>    lineTo: (-20)@0;
> cwArcTo: (-2)@(-2) angle: 45;
> lineTo: 0@(-20);
>  cwArcTo: 4@(-2) angle: 45.
>   ].
> shape3 := aCanvas createPath: [:path |
>  path relative .
>  path moveTo: ((self position x +15))@((self position y +10));
>  cwArcTo: 5 at 5 angle: 90;
> cwArcTo: (-5)@5 angle: 90;
>  cwArcTo: (-5)@(-5) angle: 90;
> cwArcTo: 5@(-5) angle: 90.
>    ].
> ( editMode = true) ifTrue: [ editButtonColor := Color green] ifFalse: [
> editButtonColor := Color red ].
> (aCanvas setStrokePaint: editButtonColor) width: 1.
>
> aCanvas drawShape: shape1 .
> aCanvas drawShape: shape2.
> aCanvas setPaint: (editButtonColor alpha: 0.3 ).
> aCanvas drawShape: shape3.
>
>
>
>
>
>
> On Thu, Nov 28, 2013 at 12:03 PM, Igor Stasenko <siguctua at gmail.com>wrote:
>
>>
>>
>>
>> On 28 November 2013 10:59, kilon alios <kilon.alios at gmail.com> wrote:
>>
>>> just tried it, I see no change
>>>
>>> try:
>>  self changeProportionalLayout
>>
>> editButton := HypEditButton new .
>>       self addMorph: editButton fullFrame: #(0 0 0 0 0 0 100 100).
>>
>>>
>>>
>>> On Thu, Nov 28, 2013 at 11:54 AM, Benjamin <
>>> Benjamin.VanRyseghem.Pharo at gmail.com> wrote:
>>>
>>>> Can you try to do something like
>>>>
>>>> self changeProportionalLayout
>>>> before adding the morph ?
>>>>
>>>> Ben
>>>>
>>>> On 28 Nov 2013, at 10:51, kilon alios <kilon.alios at gmail.com> wrote:
>>>>
>>>> So I have found some strange problems with my vector editor , Hyperion.
>>>>
>>>> Hyperion is a Morph openInWindow. Code can be found in the class side
>>>> of Hyperion>>open.
>>>>
>>>>  The coordinate system when detecting events (mouseOver, mouseUp and
>>>> mouseDown events of the Hyperion instance) looks like it takes to account
>>>> also beyond the morph as coordinates as a result events happening at the
>>>> top right edge of the morph where Hyperion is rendered is 6 at 30( which
>>>> is the size of the window's title bar plus its borders). Thats ok, I have
>>>> taken these offsets to account when computing the position of the mouse. I
>>>> guess it uses the global coordinated and not the local coordinates of the
>>>> morph.
>>>>
>>>> I am adding a button to control the edit mode of a line, when in edit
>>>> mode handles for line's control points are shown and those handles can be
>>>> dragged around to control the shape of the line , when off edit mode, the
>>>> line will be able to be drag around (not implemented yet).
>>>>
>>>> My problem is that when I add that button as morph to the existing
>>>> morph of Hyperion in 0 at 0 , it actually appears in 0 at 30 in local
>>>> coordinated of the Hyperion moprh which in global coordinates it 6 at 60( 0 at 0+ 6 at 30+ 0 at 30= 6 at 60).
>>>> Why is that ?
>>>>
>>>> I have no clue why I am getting an offset of 0 at 30 in local coordinates
>>>> of the Hyperion morph.
>>>>
>>>> here is the picture showing a) how it looks like b) the code that set
>>>> the position c) transcript showing mouse coordinates when clicked in the
>>>> top left corner of Hyperion morph
>>>>   Hyperion coordinates problem.JPG<https://docs.google.com/file/d/0B1L74rM985aqVTZleHlmb3RmbWs/edit?usp=drive_web>
>>>>
>>>> if anyone wants to try the code himself the repo is here
>>>>
>>>> http://www.smalltalkhub.com/#!/~kilon/Hyperion
>>>>
>>>> To sum up, to place that button on top left, I will have to position it
>>>> 0@(-30) which for me makes no sense at all.
>>>>
>>>> Please note that everything is rendered with Athens.
>>>>
>>>>  Maybe I have messed up the code myself somewhere but I have looked it
>>>> again and again I cant find a problem with my code.
>>>>
>>>>
>>>>
>>>
>>
>>
>> --
>> Best regards,
>> Igor Stasenko.
>>
>
>


-- 
Best regards,
Igor Stasenko.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20131128/f95574cc/attachment-0002.html>


More information about the Pharo-dev mailing list