pharo-users@lists.pharo.org

Any question about pharo is welcome

View all threads

How to get dimensions (extent) of a SpPresenter

K
kmo
Mon, May 24, 2021 3:18 PM

I'm porting a little Morphic geometry program from Morphic to a Spec 2
application using GTK.

I need to draw a shape in an SpAthensPresenter but to draw it I need to know
the current dimensions (extent) of the presenter so it can still work OK
even when the  window is resized.

The old Morphic version also used An Athens canvas but I had no problem then
as a morph has an extent method that provides this information. But now that
I can't use a morph I find that the extent method of an SpPresenter always
seems to answer nil.

Is that right? How d you get the current size of a presenter? Is it a bug?

I'm using a very recent Pharo 9 image and headless VM on Linux.

Image

/home/kmp/Pharo/images/gtkRoses/gtkRoses.image
Pharo9.0.0
Build information:
Pharo-9.0.0+build.1399.sha.9ae8329dedfbad7915b7b2cdc4accc7ce8109ce0 (64 Bit)
Unnamed

Virtual Machine

/home/kmp/Pharo/vms/90-x64-headless/lib/pharo
CoInterpreter VMMaker-tonel.1 uuid: 286e9806-8e7d-0d00-ab06-4e280faf8631 Apr
30 2021
StackToRegisterMappingCogit VMMaker-tonel.1 uuid:
286e9806-8e7d-0d00-ab06-4e280faf8631 Apr 30 2021
5125110 - Commit: 5125110 - Date: 2021-04-30 10:05:04 +0200

Pharo 9.0.0 built on Apr 30 2021 10:22:47 Compiler: 5.4.0 20160609
VMMaker versionString 5125110 - Commit: 5125110 - Date: 2021-04-30 10:05:04
+0200
CoInterpreter VMMaker-tonel.1 uuid: 286e9806-8e7d-0d00-ab06-4e280faf8631 Apr
30 2021
StackToRegisterMappingCogit VMMaker-tonel.1 uuid:
286e9806-8e7d-0d00-ab06-4e280faf8631 Apr 30 2021

Any help woudl be appreciated.

--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

I'm porting a little Morphic geometry program from Morphic to a Spec 2 application using GTK. I need to draw a shape in an SpAthensPresenter but to draw it I need to know the current dimensions (extent) of the presenter so it can still work OK even when the window is resized. The old Morphic version also used An Athens canvas but I had no problem then as a morph has an extent method that provides this information. But now that I can't use a morph I find that the extent method of an SpPresenter always seems to answer nil. Is that right? How d you get the current size of a presenter? Is it a bug? I'm using a very recent Pharo 9 image and headless VM on Linux. Image ----- /home/kmp/Pharo/images/gtkRoses/gtkRoses.image Pharo9.0.0 Build information: Pharo-9.0.0+build.1399.sha.9ae8329dedfbad7915b7b2cdc4accc7ce8109ce0 (64 Bit) Unnamed Virtual Machine --------------- /home/kmp/Pharo/vms/90-x64-headless/lib/pharo CoInterpreter VMMaker-tonel.1 uuid: 286e9806-8e7d-0d00-ab06-4e280faf8631 Apr 30 2021 StackToRegisterMappingCogit VMMaker-tonel.1 uuid: 286e9806-8e7d-0d00-ab06-4e280faf8631 Apr 30 2021 5125110 - Commit: 5125110 - Date: 2021-04-30 10:05:04 +0200 Pharo 9.0.0 built on Apr 30 2021 10:22:47 Compiler: 5.4.0 20160609 VMMaker versionString 5125110 - Commit: 5125110 - Date: 2021-04-30 10:05:04 +0200 CoInterpreter VMMaker-tonel.1 uuid: 286e9806-8e7d-0d00-ab06-4e280faf8631 Apr 30 2021 StackToRegisterMappingCogit VMMaker-tonel.1 uuid: 286e9806-8e7d-0d00-ab06-4e280faf8631 Apr 30 2021 Any help woudl be appreciated. -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
EL
Esteban Lorenzano
Mon, May 24, 2021 4:13 PM

Hi,

short answer: you can't (and you shouldn't) :)
long answer: conceptually, a presenter does not has an extent because it is not a component by itself, is just a set of other presenters arranged into a layout.

However, that does not means you can't know the extent where your athens component will be drawn!
Basically, you cannot know the presenter size (or position), but you can know the extent assigned to your athens canvas because the renderer will call your drawBlock with a canvas already initialized.
So, you can do something like:

athensPresenter := self newAthens
drawBlock: [ :aCanvas | | extent |
extent := aCanvas surface extent.
... etc ... ].

But! This is poorly documented and even less used, so there may be missing parts (both bugs and things I didn't think on when I implemented the component).
Please let me know if this is working for you :)

cheers!
Esteban

On May 24 2021, at 5:18 pm, kmo voxkmp@gmail.com wrote:

I'm porting a little Morphic geometry program from Morphic to a Spec 2
application using GTK.

I need to draw a shape in an SpAthensPresenter but to draw it I need to know
the current dimensions (extent) of the presenter so it can still work OK
even when the window is resized.

The old Morphic version also used An Athens canvas but I had no problem then
as a morph has an extent method that provides this information. But now that
I can't use a morph I find that the extent method of an SpPresenter always
seems to answer nil.

Is that right? How d you get the current size of a presenter? Is it a bug?
I'm using a very recent Pharo 9 image and headless VM on Linux.
Image

/home/kmp/Pharo/images/gtkRoses/gtkRoses.image
Pharo9.0.0
Build information:
Pharo-9.0.0+build.1399.sha.9ae8329dedfbad7915b7b2cdc4accc7ce8109ce0 (64 Bit)
Unnamed

Virtual Machine

/home/kmp/Pharo/vms/90-x64-headless/lib/pharo
CoInterpreter VMMaker-tonel.1 uuid: 286e9806-8e7d-0d00-ab06-4e280faf8631 Apr
30 2021
StackToRegisterMappingCogit VMMaker-tonel.1 uuid:
286e9806-8e7d-0d00-ab06-4e280faf8631 Apr 30 2021
5125110 - Commit: 5125110 - Date: 2021-04-30 10:05:04 +0200

Pharo 9.0.0 built on Apr 30 2021 10:22:47 Compiler: 5.4.0 20160609
VMMaker versionString 5125110 - Commit: 5125110 - Date: 2021-04-30 10:05:04
+0200
CoInterpreter VMMaker-tonel.1 uuid: 286e9806-8e7d-0d00-ab06-4e280faf8631 Apr
30 2021
StackToRegisterMappingCogit VMMaker-tonel.1 uuid:
286e9806-8e7d-0d00-ab06-4e280faf8631 Apr 30 2021

Any help woudl be appreciated.

--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

Hi, short answer: you can't (and you shouldn't) :) long answer: conceptually, a presenter does not has an extent because it is not a component by itself, is just a set of other presenters arranged into a layout. However, that does not means you can't know the extent where your athens component will be drawn! Basically, you cannot know the presenter size (or position), but you can know the extent assigned to your athens canvas because the renderer will call your drawBlock with a canvas already initialized. So, you can do something like: athensPresenter := self newAthens drawBlock: [ :aCanvas | | extent | extent := aCanvas surface extent. ... etc ... ]. But! This is poorly documented and even less used, so there may be missing parts (both bugs and things I didn't think on when I implemented the component). Please let me know if this is working for you :) cheers! Esteban On May 24 2021, at 5:18 pm, kmo <voxkmp@gmail.com> wrote: > I'm porting a little Morphic geometry program from Morphic to a Spec 2 > application using GTK. > > I need to draw a shape in an SpAthensPresenter but to draw it I need to know > the current dimensions (extent) of the presenter so it can still work OK > even when the window is resized. > > The old Morphic version also used An Athens canvas but I had no problem then > as a morph has an extent method that provides this information. But now that > I can't use a morph I find that the extent method of an SpPresenter always > seems to answer nil. > > Is that right? How d you get the current size of a presenter? Is it a bug? > I'm using a very recent Pharo 9 image and headless VM on Linux. > Image > ----- > /home/kmp/Pharo/images/gtkRoses/gtkRoses.image > Pharo9.0.0 > Build information: > Pharo-9.0.0+build.1399.sha.9ae8329dedfbad7915b7b2cdc4accc7ce8109ce0 (64 Bit) > Unnamed > > Virtual Machine > --------------- > /home/kmp/Pharo/vms/90-x64-headless/lib/pharo > CoInterpreter VMMaker-tonel.1 uuid: 286e9806-8e7d-0d00-ab06-4e280faf8631 Apr > 30 2021 > StackToRegisterMappingCogit VMMaker-tonel.1 uuid: > 286e9806-8e7d-0d00-ab06-4e280faf8631 Apr 30 2021 > 5125110 - Commit: 5125110 - Date: 2021-04-30 10:05:04 +0200 > > Pharo 9.0.0 built on Apr 30 2021 10:22:47 Compiler: 5.4.0 20160609 > VMMaker versionString 5125110 - Commit: 5125110 - Date: 2021-04-30 10:05:04 > +0200 > CoInterpreter VMMaker-tonel.1 uuid: 286e9806-8e7d-0d00-ab06-4e280faf8631 Apr > 30 2021 > StackToRegisterMappingCogit VMMaker-tonel.1 uuid: > 286e9806-8e7d-0d00-ab06-4e280faf8631 Apr 30 2021 > > > Any help woudl be appreciated. > > > > > -- > Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html >
K
kmo
Mon, May 24, 2021 5:59 PM

I'm afraid it still doesn't work for me.

If I have a drawBlock like this:

drawBlock

^ [ :aCanvas |
| paint surface |
surface := aCanvas surface.
paint := surface
createLinearGradient: {
(0 -> Color blue).
(1 -> Color black) }
start: 0 @ 0
stop: aCanvas surface extent.
surface clear.
aCanvas setPaint: paint.
aCanvas drawShape: (0 @ 0 corner: aCanvas surface extent) ]

I get just a blank canvas.- nothing is drawn.

If I replace the aCanvas surface extent with a fixed size like this:

drawBlock

^ [ :aCanvas | 
  | paint surface |
  surface := aCanvas surface.

  paint := surface
	           createLinearGradient: { 
			           (0 -> Color red).
			           (1 -> Color green) }
	           start: 0 @ 0
	           stop: 300 @ 300.
  surface clear.
  aCanvas setPaint: paint.
  aCanvas drawShape: (0 @ 0 corner: 300 @ 300) ]

then it works.

Any ideas what i might be doing wrong?

--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

I'm afraid it still doesn't work for me. If I have a drawBlock like this: drawBlock ^ [ :aCanvas | | paint surface | surface := aCanvas surface. paint := surface createLinearGradient: { (0 -> Color blue). (1 -> Color black) } start: 0 @ 0 stop: aCanvas surface extent. surface clear. aCanvas setPaint: paint. aCanvas drawShape: (0 @ 0 corner: aCanvas surface extent) ] I get just a blank canvas.- nothing is drawn. If I replace the aCanvas surface extent with a fixed size like this: drawBlock ^ [ :aCanvas | | paint surface | surface := aCanvas surface. paint := surface createLinearGradient: { (0 -> Color red). (1 -> Color green) } start: 0 @ 0 stop: 300 @ 300. surface clear. aCanvas setPaint: paint. aCanvas drawShape: (0 @ 0 corner: 300 @ 300) ] then it works. Any ideas what i might be doing wrong? -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
K
kmo
Mon, May 24, 2021 6:06 PM

I should also point out that nothing works unless I also set a surfaceExtent
when the presenter is set up -

initializePresenters

rosesAthensPresenter := RosesAthensPresenter new.
rosesAthensPresenter surfaceExtent: 400 @ 400.
rosesAthensPresenter drawBlock: [ :aCanvas | 
	| paint surface |
	surface := aCanvas surface.
	paint := surface
		         createLinearGradient: { 
				         (0 -> Color blue).
				         (1 -> Color black) }
		         start: 0 @ 0
		         stop: 300 @ 300.
	surface clear.
	aCanvas setPaint: paint.
	aCanvas drawShape: (0 @ 0 corner: 300 @ 300) ].

--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

I should also point out that nothing works unless I also set a surfaceExtent when the presenter is set up - initializePresenters rosesAthensPresenter := RosesAthensPresenter new. rosesAthensPresenter surfaceExtent: 400 @ 400. rosesAthensPresenter drawBlock: [ :aCanvas | | paint surface | surface := aCanvas surface. paint := surface createLinearGradient: { (0 -> Color blue). (1 -> Color black) } start: 0 @ 0 stop: 300 @ 300. surface clear. aCanvas setPaint: paint. aCanvas drawShape: (0 @ 0 corner: 300 @ 300) ]. -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
EL
Esteban Lorenzano
Mon, May 24, 2021 8:22 PM

Well, I noticed that it was working on gtk backend but not in morphic

this works perfect:
exampleResizing
| extent |
extent := 350@300.
SpAthensPresenter new
application: (SpApplication new useBackend: #Gtk);
surfaceExtent: extent;
drawBlock: [ :aCanvas | | paint surface |
surface := aCanvas surface.
paint := surface
createLinearGradient: {
0->Color red.
1->Color green }
start: 0@0
stop: surface extent.
surface clear.
aCanvas setPaint: paint.
aCanvas drawShape: (0@0 corner: surface extent) ];
openWithSpec.

but it does not work if you change the backend for morphic.
Anyway, I submit a fix:
https://github.com/pharo-spec/Spec/pull/1075
It will be in image soon :)
Esteban
On May 24 2021, at 8:06 pm, kmo voxkmp@gmail.com wrote:

I should also point out that nothing works unless I also set a surfaceExtentwhen the presenter is set up -

initializePresenters
rosesAthensPresenter := RosesAthensPresenter new.
rosesAthensPresenter surfaceExtent: 400 @ 400.
rosesAthensPresenter drawBlock: [ :aCanvas |
| paint surface |
surface := aCanvas surface.
paint := surface
createLinearGradient: {
(0 -> Color blue).
(1 -> Color black) }
start: 0 @ 0
stop: 300 @ 300.
surface clear.
aCanvas setPaint: paint.
aCanvas drawShape: (0 @ 0 corner: 300 @ 300) ].

--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

Well, I noticed that it was working on gtk backend but not in morphic this works perfect: exampleResizing | extent | extent := 350@300. SpAthensPresenter new application: (SpApplication new useBackend: #Gtk); surfaceExtent: extent; drawBlock: [ :aCanvas | | paint surface | surface := aCanvas surface. paint := surface createLinearGradient: { 0->Color red. 1->Color green } start: 0@0 stop: surface extent. surface clear. aCanvas setPaint: paint. aCanvas drawShape: (0@0 corner: surface extent) ]; openWithSpec. but it does not work if you change the backend for morphic. Anyway, I submit a fix: https://github.com/pharo-spec/Spec/pull/1075 It will be in image soon :) Esteban On May 24 2021, at 8:06 pm, kmo <voxkmp@gmail.com> wrote: > I should also point out that nothing works unless I also set a surfaceExtentwhen the presenter is set up - > > initializePresenters > rosesAthensPresenter := RosesAthensPresenter new. > rosesAthensPresenter surfaceExtent: 400 @ 400. > rosesAthensPresenter drawBlock: [ :aCanvas | > | paint surface | > surface := aCanvas surface. > paint := surface > createLinearGradient: { > (0 -> Color blue). > (1 -> Color black) } > start: 0 @ 0 > stop: 300 @ 300. > surface clear. > aCanvas setPaint: paint. > aCanvas drawShape: (0 @ 0 corner: 300 @ 300) ]. > > > > > -- > Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html >
K
kmo
Tue, May 25, 2021 9:43 AM

Hi Estaban.

Thank you for your helpful and prompt replies to my problem. Unfortunately,
your code does not work for me.

I pasted your code into a playground. When it runs I get no errors but I get
a completely blank window - no sign of the colour gradient.

If I change the backend to #Morphic, I get the gradient but, as you say, it
does not resize.

I just seem to be very unlucky with Gtk.

Ken

--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

Hi Estaban. Thank you for your helpful and prompt replies to my problem. Unfortunately, your code does not work for me. I pasted your code into a playground. When it runs I get no errors but I get a completely blank window - no sign of the colour gradient. If I change the backend to #Morphic, I get the gradient but, as you say, it does not resize. I just seem to be very unlucky with Gtk. Ken -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
EL
Esteban Lorenzano
Tue, May 25, 2021 10:12 AM

Hi again,

Mmm.... that should not be possible. Can you tell me how are you installing and running your gtk backend?
Also, not today and not tomorrow (because I am busy), but you can contact me from thursday in discord and I can try to help you pair programming with you.

Esteban
On May 25 2021, at 11:43 am, kmo voxkmp@gmail.com wrote:

Hi Estaban.

Thank you for your helpful and prompt replies to my problem. Unfortunately,
your code does not work for me.

I pasted your code into a playground. When it runs I get no errors but I get
a completely blank window - no sign of the colour gradient.

If I change the backend to #Morphic, I get the gradient but, as you say, it
does not resize.

I just seem to be very unlucky with Gtk.
Ken

--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

Hi again, Mmm.... that should not be possible. Can you tell me how are you installing and running your gtk backend? Also, not today and not tomorrow (because I am busy), but you can contact me from thursday in discord and I can try to help you pair programming with you. Esteban On May 25 2021, at 11:43 am, kmo <voxkmp@gmail.com> wrote: > Hi Estaban. > > Thank you for your helpful and prompt replies to my problem. Unfortunately, > your code does not work for me. > > I pasted your code into a playground. When it runs I get no errors but I get > a completely blank window - no sign of the colour gradient. > > If I change the backend to #Morphic, I get the gradient but, as you say, it > does not resize. > > I just seem to be very unlucky with Gtk. > Ken > > > -- > Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html >
K
kmo
Tue, May 25, 2021 10:43 AM

I'm running Xubuntu 20.04. I didn't install Gtk - it comes with the OS.

I'm using the Nvidia video driver. Perhaps that has an effect.

--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

I'm running Xubuntu 20.04. I didn't install Gtk - it comes with the OS. I'm using the Nvidia video driver. Perhaps that has an effect. -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
EL
Esteban Lorenzano
Tue, May 25, 2021 11:43 AM

x11 ?

On May 25 2021, at 12:43 pm, kmo voxkmp@gmail.com wrote:

I'm running Xubuntu 20.04. I didn't install Gtk - it comes with the OS.

I'm using the Nvidia video driver. Perhaps that has an effect.

--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

x11 ? On May 25 2021, at 12:43 pm, kmo <voxkmp@gmail.com> wrote: > I'm running Xubuntu 20.04. I didn't install Gtk - it comes with the OS. > > I'm using the Nvidia video driver. Perhaps that has an effect. > > > -- > Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html >
EL
Esteban Lorenzano
Tue, May 25, 2021 11:44 AM

and which vm?
On May 25 2021, at 1:43 pm, Esteban Lorenzano estebanlm@netc.eu wrote:

x11 ?

On May 25 2021, at 12:43 pm, kmo voxkmp@gmail.com wrote:

I'm running Xubuntu 20.04. I didn't install Gtk - it comes with the OS.

I'm using the Nvidia video driver. Perhaps that has an effect.

--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

and which vm? On May 25 2021, at 1:43 pm, Esteban Lorenzano <estebanlm@netc.eu> wrote: > x11 ? > > On May 25 2021, at 12:43 pm, kmo <voxkmp@gmail.com> wrote: > > I'm running Xubuntu 20.04. I didn't install Gtk - it comes with the OS. > > > > I'm using the Nvidia video driver. Perhaps that has an effect. > > > > > > -- > > Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html > > >