Question on Morphic drawOn: method.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
18 messages Options
Reply | Threaded
Open this post in threaded view
|

Question on Morphic drawOn: method.

nacho
Hi,
I have the following question:
I want to draw a bouncing ball.
First thing I do is create a class:

EllipseMorph subclass: #Ball
        instanceVariableNames: 'position'
        classVariableNames: ''
        category: 'PBE-BouncingBall'


Then an initialization method that mostly do a super initialize.
Then the drawOn:  
 
drawOn: aCanvas
        aCanvas borderWidth:10; borderColor: Color green.


And finally a position method:

position: aPoint
        super position: aPoint.

position
        ^ position.


Finally in a Playground I do:

| aBall |

aBall := Ball new.
aBall position: ( 10@10 ).
aBall openInWorld.

But I get a red box with two crossing yellow lines.
What I'm missing?

Thanks in advance.
Nacho
Nacho Smalltalker apprentice. Buenos Aires, Argentina.
Reply | Threaded
Open this post in threaded view
|

Re: Question on Morphic drawOn: method.

Ricardo Moran
Hi Nacho, 

The red box with two crossing yellow lines indicates that you made a mistake in the drawOn: method.
Whenever that happens, here is a tip that might help you. If you can't easily spot your error, you can debug it by evaluating:

aBall drawOn: Display getCanvas.

This will bring up the debugger and hopefully give you more information.

Best regards,
Richo

On Wed, Feb 4, 2015 at 3:00 PM, nacho <[hidden email]> wrote:
Hi,
I have the following question:
I want to draw a bouncing ball.
First thing I do is create a class:

EllipseMorph subclass: #Ball
        instanceVariableNames: 'position'
        classVariableNames: ''
        category: 'PBE-BouncingBall'


Then an initialization method that mostly do a super initialize.
Then the drawOn:

drawOn: aCanvas
        aCanvas borderWidth:10; borderColor: Color green.


And finally a position method:

position: aPoint
        super position: aPoint.

position
        ^ position.


Finally in a Playground I do:

| aBall |

aBall := Ball new.
aBall position: ( 10@10 ).
aBall openInWorld.

But I get a red box with two crossing yellow lines.
What I'm missing?

Thanks in advance.
Nacho




-----
Nacho
Smalltalker apprentice.
Buenos Aires, Argentina.
--
View this message in context: http://forum.world.st/Question-on-Morphic-drawOn-method-tp4803695.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: Question on Morphic drawOn: method.

HilaireFernandes
In reply to this post by nacho
Hello Nacho,

It is even simpler as you seems to imagine.
First you don't need to subclass EllipseMorph if all you want is a ball, then you don't need the position attribute, Morph always knows about positionning.
Then, the #drawOn: method is to do the drawing, you don't need to subclass as long as you don't need a different drawing. Color, border should be set elsewhere.

The redbox with the cross appears in a Morph area when its drawing gets wrong, here your override in drawOn:

For inspiration you can copy and paste the code example bellow; as you mentioned animation, it shows you a few tips on that matter.

Good exploration

Hilaire


| aBall |
aBall := EllipseMorph  new.
aBall borderWidth: 10;
    borderColor: Color green;
    color: Color white;
    extent: 100@100.
aBall position: ( 10@100 ).
aBall openInWorld.
100 to: 50 by: -1 do: [ :x |
    aBall
        height: x;
        bottom: 200 - x.
    World doOneCycle]


Le 04/02/2015 19:00, nacho a écrit :
Hi,
I have the following question:
I want to draw a bouncing ball.
First thing I do is create a class:

EllipseMorph subclass: #Ball
	instanceVariableNames: 'position'
	classVariableNames: ''
	category: 'PBE-BouncingBall'


Then an initialization method that mostly do a super initialize.
Then the drawOn:  
  
drawOn: aCanvas
	aCanvas borderWidth:10; borderColor: Color green.


And finally a position method:

position: aPoint
	super position: aPoint.

position
	^ position.


Finally in a Playground I do:

| aBall |

aBall := Ball new.
aBall position: ( 10@10 ).
aBall openInWorld.

But I get a red box with two crossing yellow lines.
What I'm missing?

Thanks in advance.
Nacho




-----
Nacho
Smalltalker apprentice.
Buenos Aires, Argentina.
--
View this message in context: http://forum.world.st/Question-on-Morphic-drawOn-method-tp4803695.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.




-- 
Dr. Geo - http://drgeo.eu
iStoa - http://istoa.drgeo.eu
Reply | Threaded
Open this post in threaded view
|

Re: Question on Morphic drawOn: method.

nacho
Thank you both of you!
I will continue with my Morphic explorations....

Nacho
Nacho Smalltalker apprentice. Buenos Aires, Argentina.
Reply | Threaded
Open this post in threaded view
|

Re: Question on Morphic drawOn: method.

kilon.alios
alt+shift+left click should bring on the halo , the claw like icon has a menu with the debuger as an entry you can trigger to see whats wrong. You can also inspect the morph too and play around with it, very useful even when you got no errors.

On Wed, Feb 4, 2015 at 9:33 PM, nacho <[hidden email]> wrote:
Thank you both of you!
I will continue with my Morphic explorations....

Nacho



-----
Nacho
Smalltalker apprentice.
Buenos Aires, Argentina.
--
View this message in context: http://forum.world.st/Question-on-Morphic-drawOn-method-tp4803695p4803734.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: Question on Morphic drawOn: method.

Sean P. DeNigris
Administrator
In reply to this post by HilaireFernandes
HilaireFernandes wrote
First you don't need to subclass EllipseMorph...
100 to: 50 by: -1 do: [ :x |
    aBall
        height: x;
        bottom: 200 - x.
    World doOneCycle]
Of course you can have the best of both worlds by using Morphic stepping in your subclass, like:

EllipseMorph subclass: #Ball
...
Ball>>#step
    self
                bottom: 200 - self nextHeight;
                height: self nextHeight.
               
        self bottom = 100 ifTrue: [ increment := -1 ].
        self bottom = 150 ifTrue: [ increment := 1 ].

For full code:
    Gofer it
        smalltalkhubUser: 'SeanDeNigris' project: 'SeansPlayground';
        package: 'Ball';
        load.
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Question on Morphic drawOn: method.

nacho
Great! Thanks.
It works perfectly in Pharo 3 but not in Pharo 4.
I thought that the drawOn: aCanvas was mandatory.
I'm so lost in morphic.
Trying to understand the logic of it slowly.
Unfortunately there seems to be little documentation and a lot of what is there does not work in Pharo 3 or 4.
Thanks again for taking the time!
Best
Nacho


Lic. Ignacio Sniechowski, MBA
Prosavic SRL

Tel: (011) 4542-6714





















On Wed, Feb 4, 2015 at 5:30 PM, Sean P. DeNigris [via Smalltalk] <[hidden email]> wrote:
HilaireFernandes wrote
First you don't need to subclass EllipseMorph...
100 to: 50 by: -1 do: [ :x |
    aBall
        height: x;
        bottom: 200 - x.
    World doOneCycle]
Of course you can have the best of both worlds by using Morphic stepping in your subclass, like:

EllipseMorph subclass: #Ball
...
Ball>>#step
    self
                bottom: 200 - self nextHeight;
                height: self nextHeight.
               
        self bottom = 100 ifTrue: [ increment := -1 ].
        self bottom = 150 ifTrue: [ increment := 1 ].

For full code:
    Gofer it
        smalltalkhubUser: 'SeanDeNigris' project: 'SeansPlayground';
        package: 'Ball';
        load.
Cheers,
Sean



If you reply to this email, your message will be added to the discussion below:
http://forum.world.st/Question-on-Morphic-drawOn-method-tp4803695p4803743.html
To unsubscribe from Question on Morphic drawOn: method., click here.
NAML

Nacho Smalltalker apprentice. Buenos Aires, Argentina.
Reply | Threaded
Open this post in threaded view
|

Re: Question on Morphic drawOn: method.

Sean P. DeNigris
Administrator
nacho wrote
I'm so lost in morphic.
Trying to understand the logic of it slowly.
Unfortunately there seems to be little documentation and a lot of what is
there does not work in Pharo 3 or 4.
I use Pharo By Example for most straightforward Morphic questions. It shows the nuts-and-bolts very clearly and I haven't found it out of date through Pharo 3.0. For the principles behind Morphic to really grok how magical it could be, the original Self Morphic papers can't be beat. HTH
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Question on Morphic drawOn: method.

Trygve
In reply to this post by nacho
I think you left out a super drawOn: aCanvas in  your method. Interesting to hear if this works:
   
drawOn: aCanvas
   aCanvas borderWidth:10; borderColor: Color green.
   super drawOn: aCanvas.
 
The rest should work AFAICS, but it could be simplified.
(I haven't Pharo available so that I can test it)
--Trygve

On 04.02.2015 19:00, nacho wrote:
Hi,
I have the following question:
I want to draw a bouncing ball.
First thing I do is create a class:

EllipseMorph subclass: #Ball
	instanceVariableNames: 'position'
	classVariableNames: ''
	category: 'PBE-BouncingBall'


Then an initialization method that mostly do a super initialize.
Then the drawOn:  
  
drawOn: aCanvas
	aCanvas borderWidth:10; borderColor: Color green.


And finally a position method:

position: aPoint
	super position: aPoint.

position
	^ position.


Finally in a Playground I do:

| aBall |

aBall := Ball new.
aBall position: ( 10@10 ).
aBall openInWorld.

But I get a red box with two crossing yellow lines.
What I'm missing?

Thanks in advance.
Nacho




-----
Nacho
Smalltalker apprentice.
Buenos Aires, Argentina.
--
View this message in context: http://forum.world.st/Question-on-Morphic-drawOn-method-tp4803695.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.




--

The essence of object orientation is that
objects collaborate  to achieve a goal.
---
Trygve Reenskaug      
[hidden email]
Morgedalsvn. 5A       
http://folk.uio.no/trygver/
N-0378 Oslo             
http://fullOO.info
Norway                     Tel: (+47) 22 49 57 27

Reply | Threaded
Open this post in threaded view
|

Re: Question on Morphic drawOn: method.

nacho
@Trygve
I've checked and it doesn't work. I can't even bring the halo on to delete the morph. The debugger keeps popping.
Thanks anyway to all
Nacho
Nacho Smalltalker apprentice. Buenos Aires, Argentina.
Reply | Threaded
Open this post in threaded view
|

Re: Question on Morphic drawOn: method.

kilon.alios
upload your code to smalltalkhub or github and lets take a look at it. Sharing your image is also a viable option


On Thu, Feb 5, 2015 at 12:56 PM, nacho <[hidden email]> wrote:
@Trygve
I've checked and it doesn't work. I can't even bring the halo on to delete
the morph. The debugger keeps popping.
Thanks anyway to all
Nacho




-----
Nacho
Smalltalker apprentice.
Buenos Aires, Argentina.
--
View this message in context: http://forum.world.st/Question-on-Morphic-drawOn-method-tp4803695p4803895.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: Question on Morphic drawOn: method.

Trygve
In reply to this post by nacho
I've tested your code in Squeak and found another bug (I should have been more careful when I read your code. Shame on me.)

In class Ball you have the methods
	position: aPoint
		super position: aPoint.
This does not set a value to your position variable in class Ball, but actually sets the upper-left corner of the bounds.
You should have said position := aPoint.
--------------------------------	 
The following now works in mySqueak image:
EllipseMorph subclass: #Ball
	instanceVariableNames: 'position'
	classVariableNames: ''
	poolDictionaries: '' "this part is needed in Squeak"
	category: 'ZZZtesting'

drawOn: aCanvas
	self borderWidth:10; borderColor: Color green.
	super drawOn: aCanvas.

position
	^ position.

position: aPoint
	position := aPoint.

I then execute the following in a workspace
    | aBall |
    aBall := Ball new.
    aBall position: ( 10@10 ).
    aBall openInWorld.

and it seems to work. But closer scrutiny shows that it ignores your instance variable (position). when I move the ball around.
The reason is that EllipseMorph  is a superclass of your Ball and cannot possibly know about an instance variable (position) that is defined in the subclass (Ball).

I ignored Ball>position since the EllipseMorph doesn't use it:

EllipseMorph subclass: #Ball
    instanceVariableNames: ''
    classVariableNames: ''
    poolDictionaries: ''
    category: 'ZZZtesting'

    position
        ^ super position.

    position: aPoint
       super position: aPoint.
This looks better.
I you really want to replace the EllipseMorph>position you must go deeper into how the EllipseMorph handles its position and bounds . This will not be trivial. Much easier to invent a new instance variable and use it in the drawOn: method.

Good luck with your apprenticeship









On 05.02.2015 11:56, nacho wrote:
@Trygve
I've checked and it doesn't work. I can't even bring the halo on to delete
the morph. The debugger keeps popping.
Thanks anyway to all
Nacho




-----
Nacho
Smalltalker apprentice.
Buenos Aires, Argentina.
--
View this message in context: http://forum.world.st/Question-on-Morphic-drawOn-method-tp4803695p4803895.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.




--

The essence of object orientation is that objects collaborate  to achieve a goal.
Trygve Reenskaug      
[hidden email]
Morgedalsvn. 5A       
http://folk.uio.no/trygver/
N-0378 Oslo             
http://fullOO.info
Norway                     Tel: (+47) 22 49 57 27

Reply | Threaded
Open this post in threaded view
|

Re: Question on Morphic drawOn: method.

nacho
That work perfectly. What a silly mistake!!!
Of course it should have been position := aPoint.
Now, is it possible write the drawOn: method without calling super drawOn: a Canvas?
I don't completely get it why I should call super drawOn: aCanvas
thanks
nacho


Lic. Ignacio Sniechowski, MBA
Prosavic SRL

Tel: (011) 4542-6714





















On Thu, Feb 5, 2015 at 11:28 AM, Trygve Reenskaug [via Smalltalk] <[hidden email]> wrote:
I've tested your code in Squeak and found another bug (I should have been more careful when I read your code. Shame on me.)

In class Ball you have the methods
	position: aPoint
		super position: aPoint.
This does not set a value to your position variable in class Ball, but actually sets the upper-left corner of the bounds.
You should have said position := aPoint.
--------------------------------	 
The following now works in mySqueak image:
EllipseMorph subclass: #Ball
	instanceVariableNames: 'position'
	classVariableNames: ''
	poolDictionaries: '' "this part is needed in Squeak"
	category: 'ZZZtesting'

drawOn: aCanvas
	self borderWidth:10; borderColor: Color green.
	super drawOn: aCanvas.

position
	^ position.

position: aPoint
	position := aPoint.

I then execute the following in a workspace
    | aBall |
    aBall := Ball new.
    aBall position: ( 10@10 ).
    aBall openInWorld.

and it seems to work. But closer scrutiny shows that it ignores your instance variable (position). when I move the ball around.
The reason is that EllipseMorph  is a superclass of your Ball and cannot possibly know about an instance variable (position) that is defined in the subclass (Ball).

I ignored Ball>position since the EllipseMorph doesn't use it:

EllipseMorph subclass: #Ball
    instanceVariableNames: ''
    classVariableNames: ''
    poolDictionaries: ''
    category: 'ZZZtesting'

    position
        ^ super position.

    position: aPoint
       super position: aPoint.
This looks better.
I you really want to replace the EllipseMorph>position you must go deeper into how the EllipseMorph handles its position and bounds . This will not be trivial. Much easier to invent a new instance variable and use it in the drawOn: method.

Good luck with your apprenticeship









On 05.02.2015 11:56, nacho wrote:
@Trygve
I've checked and it doesn't work. I can't even bring the halo on to delete
the morph. The debugger keeps popping.
Thanks anyway to all
Nacho




-----
Nacho
Smalltalker apprentice.
Buenos Aires, Argentina.
--
View this message in context: http://forum.world.st/Question-on-Morphic-drawOn-method-tp4803695p4803895.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.




--

The essence of object orientation is that objects collaborate  to achieve a goal.
Trygve Reenskaug      
[hidden email]
Morgedalsvn. 5A       
http://folk.uio.no/trygver/
N-0378 Oslo             
http://fullOO.info
Norway                     Tel: (+47) 22 49 57 27




If you reply to this email, your message will be added to the discussion below:
http://forum.world.st/Question-on-Morphic-drawOn-method-tp4803695p4803964.html
To unsubscribe from Question on Morphic drawOn: method., click here.
NAML

Nacho Smalltalker apprentice. Buenos Aires, Argentina.
Reply | Threaded
Open this post in threaded view
|

Re: Question on Morphic drawOn: method.

Trygve

Because your drawOn: method doesn't draw anything and needs help from super.
It seems to me that you need to read more documentation :-)

On 05.02.2015 15:53, nacho wrote:
That work perfectly. What a silly mistake!!!
Of course it should have been position := aPoint.
Now, is it possible write the drawOn: method without calling super drawOn: a Canvas?
I don't completely get it why I should call super drawOn: aCanvas
thanks
nacho


Lic. Ignacio Sniechowski, MBA
Prosavic SRL

Tel: (011) 4542-6714





















On Thu, Feb 5, 2015 at 11:28 AM, Trygve Reenskaug [via Smalltalk] <[hidden email]> wrote:
I've tested your code in Squeak and found another bug (I should have been more careful when I read your code. Shame on me.)

In class Ball you have the methods
	position: aPoint
		super position: aPoint.
This does not set a value to your position variable in class Ball, but actually sets the upper-left corner of the bounds.
You should have said position := aPoint.
--------------------------------	 
The following now works in mySqueak image:
EllipseMorph subclass: #Ball
	instanceVariableNames: 'position'
	classVariableNames: ''
	poolDictionaries: '' "this part is needed in Squeak"
	category: 'ZZZtesting'

drawOn: aCanvas
	self borderWidth:10; borderColor: Color green.
	super drawOn: aCanvas.

position
	^ position.

position: aPoint
	position := aPoint.

I then execute the following in a workspace
    | aBall |
    aBall := Ball new.
    aBall position: ( 10@10 ).
    aBall openInWorld.

and it seems to work. But closer scrutiny shows that it ignores your instance variable (position). when I move the ball around.
The reason is that EllipseMorph  is a superclass of your Ball and cannot possibly know about an instance variable (position) that is defined in the subclass (Ball).

I ignored Ball>position since the EllipseMorph doesn't use it:

EllipseMorph subclass: #Ball
    instanceVariableNames: ''
    classVariableNames: ''
    poolDictionaries: ''
    category: 'ZZZtesting'

    position
        ^ super position.

    position: aPoint
       super position: aPoint.
This looks better.
I you really want to replace the EllipseMorph>position you must go deeper into how the EllipseMorph handles its position and bounds . This will not be trivial. Much easier to invent a new instance variable and use it in the drawOn: method.

Good luck with your apprenticeship









On 05.02.2015 11:56, nacho wrote:
@Trygve
I've checked and it doesn't work. I can't even bring the halo on to delete
the morph. The debugger keeps popping.
Thanks anyway to all
Nacho




-----
Nacho
Smalltalker apprentice.
Buenos Aires, Argentina.
--
View this message in context: http://forum.world.st/Question-on-Morphic-drawOn-method-tp4803695p4803895.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.




--

The essence of object orientation is that objects collaborate  to achieve a goal.
Trygve Reenskaug      
[hidden email]
Morgedalsvn. 5A       
http://folk.uio.no/trygver/
N-0378 Oslo             
http://fullOO.info
Norway                     Tel: (+47) 22 49 57 27




If you reply to this email, your message will be added to the discussion below:
http://forum.world.st/Question-on-Morphic-drawOn-method-tp4803695p4803964.html
To unsubscribe from Question on Morphic drawOn: method., click here.
NAML

Nacho Smalltalker apprentice. Buenos Aires, Argentina.


View this message in context: Re: Question on Morphic drawOn: method.
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.

--

The essence of object orientation is that objects collaborate  to achieve a goal.
Trygve Reenskaug      
[hidden email]
Morgedalsvn. 5A       
http://folk.uio.no/trygver/
N-0378 Oslo             
http://fullOO.info
Norway                     Tel: (+47) 22 49 57 27

Reply | Threaded
Open this post in threaded view
|

Re: Question on Morphic drawOn: method.

nacho
Yes! Point me to those documents and I will love to read them!!!
thanks in advance


Lic. Ignacio Sniechowski, MBA
Prosavic SRL

Tel: (011) 4542-6714





















On Thu, Feb 5, 2015 at 1:02 PM, Trygve Reenskaug [via Smalltalk] <[hidden email]> wrote:

Because your drawOn: method doesn't draw anything and needs help from super.
It seems to me that you need to read more documentation :-)

On 05.02.2015 15:53, nacho wrote:
That work perfectly. What a silly mistake!!!
Of course it should have been position := aPoint.
Now, is it possible write the drawOn: method without calling super drawOn: a Canvas?
I don't completely get it why I should call super drawOn: aCanvas
thanks
nacho


Lic. Ignacio Sniechowski, MBA
Prosavic SRL

Tel: (011) 4542-6714





















On Thu, Feb 5, 2015 at 11:28 AM, Trygve Reenskaug [via Smalltalk] <[hidden email]> wrote:
I've tested your code in Squeak and found another bug (I should have been more careful when I read your code. Shame on me.)

In class Ball you have the methods
	position: aPoint
		super position: aPoint.
This does not set a value to your position variable in class Ball, but actually sets the upper-left corner of the bounds.
You should have said position := aPoint.
--------------------------------	 
The following now works in mySqueak image:
EllipseMorph subclass: #Ball
	instanceVariableNames: 'position'
	classVariableNames: ''
	poolDictionaries: '' "this part is needed in Squeak"
	category: 'ZZZtesting'

drawOn: aCanvas
	self borderWidth:10; borderColor: Color green.
	super drawOn: aCanvas.

position
	^ position.

position: aPoint
	position := aPoint.

I then execute the following in a workspace
    | aBall |
    aBall := Ball new.
    aBall position: ( 10@10 ).
    aBall openInWorld.

and it seems to work. But closer scrutiny shows that it ignores your instance variable (position). when I move the ball around.
The reason is that EllipseMorph  is a superclass of your Ball and cannot possibly know about an instance variable (position) that is defined in the subclass (Ball).

I ignored Ball>position since the EllipseMorph doesn't use it:

EllipseMorph subclass: #Ball
    instanceVariableNames: ''
    classVariableNames: ''
    poolDictionaries: ''
    category: 'ZZZtesting'

    position
        ^ super position.

    position: aPoint
       super position: aPoint.
This looks better.
I you really want to replace the EllipseMorph>position you must go deeper into how the EllipseMorph handles its position and bounds . This will not be trivial. Much easier to invent a new instance variable and use it in the drawOn: method.

Good luck with your apprenticeship









On 05.02.2015 11:56, nacho wrote:
@Trygve
I've checked and it doesn't work. I can't even bring the halo on to delete
the morph. The debugger keeps popping.
Thanks anyway to all
Nacho




-----
Nacho
Smalltalker apprentice.
Buenos Aires, Argentina.
--
View this message in context: http://forum.world.st/Question-on-Morphic-drawOn-method-tp4803695p4803895.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.




--

The essence of object orientation is that objects collaborate  to achieve a goal.
Trygve Reenskaug      
[hidden email]
Morgedalsvn. 5A       
http://folk.uio.no/trygver/
N-0378 Oslo             
http://fullOO.info
Norway                     Tel: (+47) 22 49 57 27




If you reply to this email, your message will be added to the discussion below:
http://forum.world.st/Question-on-Morphic-drawOn-method-tp4803695p4803964.html
To unsubscribe from Question on Morphic drawOn: method., click here.
NAML

Nacho Smalltalker apprentice. Buenos Aires, Argentina.


View this message in context: Re: Question on Morphic drawOn: method.
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.

--

The essence of object orientation is that objects collaborate  to achieve a goal.
Trygve Reenskaug      
[hidden email]
Morgedalsvn. 5A       
http://folk.uio.no/trygver/
N-0378 Oslo             
http://fullOO.info
Norway                     Tel: (+47) 22 49 57 27




If you reply to this email, your message will be added to the discussion below:
http://forum.world.st/Question-on-Morphic-drawOn-method-tp4803695p4804005.html
To unsubscribe from Question on Morphic drawOn: method., click here.
NAML

Nacho Smalltalker apprentice. Buenos Aires, Argentina.
Reply | Threaded
Open this post in threaded view
|

Re: Question on Morphic drawOn: method.

Trygve
http://pharo.org/

On 05.02.2015 17:14, nacho wrote:
Yes! Point me to those documents and I will love to read them!!!
thanks in advance


Lic. Ignacio Sniechowski, MBA
Prosavic SRL

Tel: (011) 4542-6714





















On Thu, Feb 5, 2015 at 1:02 PM, Trygve Reenskaug [via Smalltalk] <[hidden email]> wrote:

Because your drawOn: method doesn't draw anything and needs help from super.
It seems to me that you need to read more documentation :-)

On 05.02.2015 15:53, nacho wrote:
That work perfectly. What a silly mistake!!!
Of course it should have been position := aPoint.
Now, is it possible write the drawOn: method without calling super drawOn: a Canvas?
I don't completely get it why I should call super drawOn: aCanvas
thanks
nacho


Lic. Ignacio Sniechowski, MBA
Prosavic SRL

Tel: (011) 4542-6714





















On Thu, Feb 5, 2015 at 11:28 AM, Trygve Reenskaug [via Smalltalk] <[hidden email]> wrote:
I've tested your code in Squeak and found another bug (I should have been more careful when I read your code. Shame on me.)

In class Ball you have the methods
	position: aPoint
		super position: aPoint.
This does not set a value to your position variable in class Ball, but actually sets the upper-left corner of the bounds.
You should have said position := aPoint.
--------------------------------	 
The following now works in mySqueak image:
EllipseMorph subclass: #Ball
	instanceVariableNames: 'position'
	classVariableNames: ''
	poolDictionaries: '' "this part is needed in Squeak"
	category: 'ZZZtesting'

drawOn: aCanvas
	self borderWidth:10; borderColor: Color green.
	super drawOn: aCanvas.

position
	^ position.

position: aPoint
	position := aPoint.

I then execute the following in a workspace
    | aBall |
    aBall := Ball new.
    aBall position: ( 10@10 ).
    aBall openInWorld.

and it seems to work. But closer scrutiny shows that it ignores your instance variable (position). when I move the ball around.
The reason is that EllipseMorph  is a superclass of your Ball and cannot possibly know about an instance variable (position) that is defined in the subclass (Ball).

I ignored Ball>position since the EllipseMorph doesn't use it:

EllipseMorph subclass: #Ball
    instanceVariableNames: ''
    classVariableNames: ''
    poolDictionaries: ''
    category: 'ZZZtesting'

    position
        ^ super position.

    position: aPoint
       super position: aPoint.
This looks better.
I you really want to replace the EllipseMorph>position you must go deeper into how the EllipseMorph handles its position and bounds . This will not be trivial. Much easier to invent a new instance variable and use it in the drawOn: method.

Good luck with your apprenticeship









On 05.02.2015 11:56, nacho wrote:
@Trygve
I've checked and it doesn't work. I can't even bring the halo on to delete
the morph. The debugger keeps popping.
Thanks anyway to all
Nacho




-----
Nacho
Smalltalker apprentice.
Buenos Aires, Argentina.
--
View this message in context: http://forum.world.st/Question-on-Morphic-drawOn-method-tp4803695p4803895.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.




--

The essence of object orientation is that objects collaborate  to achieve a goal.
Trygve Reenskaug      
[hidden email]
Morgedalsvn. 5A       
http://folk.uio.no/trygver/
N-0378 Oslo             
http://fullOO.info
Norway                     Tel: (+47) 22 49 57 27




If you reply to this email, your message will be added to the discussion below:
http://forum.world.st/Question-on-Morphic-drawOn-method-tp4803695p4803964.html
To unsubscribe from Question on Morphic drawOn: method., click here.
NAML

Nacho Smalltalker apprentice. Buenos Aires, Argentina.


View this message in context: Re: Question on Morphic drawOn: method.
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.

--

The essence of object orientation is that objects collaborate  to achieve a goal.
Trygve Reenskaug      
[hidden email]
Morgedalsvn. 5A       
http://folk.uio.no/trygver/
N-0378 Oslo             
http://fullOO.info
Norway                     Tel: (+47) 22 49 57 27




If you reply to this email, your message will be added to the discussion below:
http://forum.world.st/Question-on-Morphic-drawOn-method-tp4803695p4804005.html
To unsubscribe from Question on Morphic drawOn: method., click here.
NAML

Nacho Smalltalker apprentice. Buenos Aires, Argentina.


View this message in context: Re: Question on Morphic drawOn: method.
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.

--

The essence of object orientation is that objects collaborate  to achieve a goal.
Trygve Reenskaug      
[hidden email]
Morgedalsvn. 5A       
http://folk.uio.no/trygver/
N-0378 Oslo             
http://fullOO.info
Norway                     Tel: (+47) 22 49 57 27

Reply | Threaded
Open this post in threaded view
|

Re: Question on Morphic drawOn: method.

HilaireFernandes
In reply to this post by nacho
Le 05/02/2015 17:14, nacho a écrit :
> Yes! Point me to those documents and I will love to read them!!!
> thanks in advance
>

Read the Pharo by example Morphic chapter, it is written for beginner

Hilaire

--
Dr. Geo - http://drgeo.eu
iStoa - http://istoa.drgeo.eu



Reply | Threaded
Open this post in threaded view
|

Re: Question on Morphic drawOn: method.

Stephan Eggermont-3
In reply to this post by nacho
Hilaire wrote
>Read the Pharo by example Morphic chapter, it is written for beginner

The chapter is a good introduction. Also read the LaserGame Tutorial.

The problems come after that. What is a good way of distributing
responsibilities? How do I find which Morph already does (nearly)
what I need. There are 347 Morph subClasses in my currently
open image.

When I want to resize my Morph, should I be looking
at one of the AbstractResizerMorph subClasses, at  Halo or
perhaps at Handle? Or should I do it like PolygonMorph?
In the LaserGame, the whole game is one Morph (embedded in a
window with a few buttons).

I find it is possible to create very elegant solutions using
Morphic, and finding the right approach is difficult.

Stephan