15 years ago I did a lot in Smalltalk, and have done some recreational meta programming along the way. However, I now wanted to do something where I was in need of drawing a diagram with x and y axes on what I presume might be called a Canvas.
I lack a simple tutorial to get me started. I have looked at many, but they seem to presume I want to draw on the world "openInWorld". I should like not to scatter my world with line fragments and points, but keep it inside a "normal" window with borders, a background color (i.e. not a see through window). I have gone dead in two approaches. First attempt is to use a SystemWindow, and then draw on the canvas I presume is there somewhere. I have just not been able to figure out how to find the canvas of that SystemWindow, nor what method presumeable does the painting. Second attempt is to use a SystemWindow, and then add (addMorph:) line and circle morphs for my diagram. But it seems something is missing in my understanding there as well. While it is fun that I can open circles and other stuff in "world", it is not what I need. Small hits or direct solutions more than welcome. -- Kasper |
Hi,
You should make your own Morph subclass, override the #drawOn: method which receives a canvas as its parameter, and use this canvas to make your diagram. Then, if you want it to be inside a window, you can send #openInWindow to your morph instead of #openInWorld.
A very simple example is attached. Open it by doing: ExampleMorph new openInWindow Best regards, Richo
On Tue, Dec 13, 2011 at 1:59 PM, KasperOsterbye <[hidden email]> wrote: 15 years ago I did a lot in Smalltalk, and have done some recreational meta MorphExample.st (536 bytes) Download Attachment |
In reply to this post by Kasper Osterbye
Kasper,
"Canvas" is a good name, and is (IMHO at least) exactly what want, on a bitmap, aka a Form. Look at Form class>>dotOfSize: for an example of drawing. #getCanvas produces what you want. My default image is littered with messages called #show, such as Form>>show | shell | shell := StandardWindow new. shell addMorph:( shell newImage:self ) fullFrame:(LayoutFrame fractions:(0@0 corner: 1@1)). shell openInWorld. With the above compiled in Form, you can use ( ColorForm dotOfSize:50 ) show. (note the use of ColorForm vs. Form) to display the dot in a window. Also, check out Painter (Archetype Polymorph Application) in http://book.pharo-project.org/book. Bill ________________________________________ From: [hidden email] [[hidden email]] on behalf of KasperOsterbye [[hidden email]] Sent: Tuesday, December 13, 2011 11:59 AM To: [hidden email] Subject: [Pharo-project] Old smalltalker is slightly lost 15 years ago I did a lot in Smalltalk, and have done some recreational meta programming along the way. However, I now wanted to do something where I was in need of drawing a diagram with x and y axes on what I presume might be called a Canvas. I lack a simple tutorial to get me started. I have looked at many, but they seem to presume I want to draw on the world "openInWorld". I should like not to scatter my world with line fragments and points, but keep it inside a "normal" window with borders, a background color (i.e. not a see through window). I have gone dead in two approaches. First attempt is to use a SystemWindow, and then draw on the canvas I presume is there somewhere. I have just not been able to figure out how to find the canvas of that SystemWindow, nor what method presumeable does the painting. Second attempt is to use a SystemWindow, and then add (addMorph:) line and circle morphs for my diagram. But it seems something is missing in my understanding there as well. While it is fun that I can open circles and other stuff in "world", it is not what I need. Small hits or direct solutions more than welcome. -- Kasper -- View this message in context: http://forum.world.st/Old-smalltalker-is-slightly-lost-tp4191137p4191137.html Sent from the Pharo Smalltalk mailing list archive at Nabble.com. |
In reply to this post by Ricardo Moran
I respectfully disagree with the presumption that a morph subclass is desirable. It *might* be the correct solution, but IMHO, often one is better off with something knows how
to draw on a canvas with an arbitrary resolution. One thing I actually miss from Windows is its printer device contexts. Yes, you may quote me in a registered letter to Bill Gates<g>. If you do, please tell him that I think pretty highly of COM too, but
that he botched almost everything else, especially DCOM :)
Back on topic, this is an old debate. In another Smalltalk that will remain nameless, it wasn't Moprhs, it was View subclasses. Same argument: follow Kent Beck's "lots of little pieces" advice, make something that draws on a canvas, and use it to create a morph or whatever else you want. Test using a bitmap (Form in Pharo) as I showed in my other message. Just my 2 asCents. Bill From: [hidden email] [[hidden email]] on behalf of Ricardo Moran [[hidden email]]
Sent: Tuesday, December 13, 2011 3:49 PM To: [hidden email] Subject: Re: [Pharo-project] Old smalltalker is slightly lost Hi,
You should make your own Morph subclass, override the #drawOn: method which receives a canvas as its parameter, and use this canvas to make your diagram.
Then, if you want it to be inside a window, you can send #openInWindow to your morph instead of #openInWorld.
A very simple example is attached. Open it by doing:
ExampleMorph new openInWindow Best regards,
Richo
On Tue, Dec 13, 2011 at 1:59 PM, KasperOsterbye
<[hidden email]> wrote:
15 years ago I did a lot in Smalltalk, and have done some recreational meta |
In reply to this post by Kasper Osterbye
On 13.12.2011 17:59, KasperOsterbye wrote:
> 15 years ago I did a lot in Smalltalk, and have done some recreational meta > programming along the way. However, I now wanted to do something where I was > in need of drawing a diagram with x and y axes on what I presume might be > called a Canvas. > > I lack a simple tutorial to get me started. I have looked at many, but they > seem to presume I want to draw on the world "openInWorld". I should like not > to scatter my world with line fragments and points, but keep it inside a > "normal" window with borders, a background color (i.e. not a see through > window). > I have gone dead in two approaches. > > First attempt is to use a SystemWindow, and then draw on the canvas I > presume is there somewhere. I have just not been able to figure out how to > find the canvas of that SystemWindow, nor what method presumeable does the > painting. > > Second attempt is to use a SystemWindow, and then add (addMorph:) line and > circle morphs for my diagram. But it seems something is missing in my > understanding there as well. > > While it is fun that I can open circles and other stuff in "world", it is > not what I need. > > Small hits or direct solutions more than welcome. > > -- Kasper elegant graphing morph. Best one I know of at least. http://squeaksource.com/MemoryMonitor/ Cheers, Henry |
In reply to this post by Kasper Osterbye
Hi kasper
Welcome :) I hope you are going well. Do you need interaction with the forms you will draw? Do you want to define your own interaction? Do you just want to draw on the canvas? to get a canvas Display getCanvas fillRectangle: (0@0 corner: 100@100) color: Color red Have a look at Canvas Api (it is vintage but works). We are about to release a new canvas to support vector graphics Stef On Dec 13, 2011, at 5:59 PM, KasperOsterbye wrote: > 15 years ago I did a lot in Smalltalk, and have done some recreational meta > programming along the way. However, I now wanted to do something where I was > in need of drawing a diagram with x and y axes on what I presume might be > called a Canvas. > > I lack a simple tutorial to get me started. I have looked at many, but they > seem to presume I want to draw on the world "openInWorld". I should like not > to scatter my world with line fragments and points, but keep it inside a > "normal" window with borders, a background color (i.e. not a see through > window). > I have gone dead in two approaches. > > First attempt is to use a SystemWindow, and then draw on the canvas I > presume is there somewhere. I have just not been able to figure out how to > find the canvas of that SystemWindow, nor what method presumeable does the > painting. > > Second attempt is to use a SystemWindow, and then add (addMorph:) line and > circle morphs for my diagram. But it seems something is missing in my > understanding there as well. > > While it is fun that I can open circles and other stuff in "world", it is > not what I need. > > Small hits or direct solutions more than welcome. > > -- Kasper > > -- > View this message in context: http://forum.world.st/Old-smalltalker-is-slightly-lost-tp4191137p4191137.html > Sent from the Pharo Smalltalk mailing list archive at Nabble.com. > |
In reply to this post by Kasper Osterbye
Depending on your needs you might like
http://squeak.preeminent.org/tut2007/html/index.html KasperOsterbye wrote: > 15 years ago I did a lot in Smalltalk, and have done some recreational meta > programming along the way. However, I now wanted to do something where I was > in need of drawing a diagram with x and y axes on what I presume might be > called a Canvas. > > I lack a simple tutorial to get me started. I have looked at many, but they > seem to presume I want to draw on the world "openInWorld". I should like not > to scatter my world with line fragments and points, but keep it inside a > "normal" window with borders, a background color (i.e. not a see through > window). > I have gone dead in two approaches. > > First attempt is to use a SystemWindow, and then draw on the canvas I > presume is there somewhere. I have just not been able to figure out how to > find the canvas of that SystemWindow, nor what method presumeable does the > painting. > > Second attempt is to use a SystemWindow, and then add (addMorph:) line and > circle morphs for my diagram. But it seems something is missing in my > understanding there as well. > > While it is fun that I can open circles and other stuff in "world", it is > not what I need. > > Small hits or direct solutions more than welcome. > > -- Kasper > > -- > View this message in context: http://forum.world.st/Old-smalltalker-is-slightly-lost-tp4191137p4191137.html > Sent from the Pharo Smalltalk mailing list archive at Nabble.com. > > > |
Thanks all,
It was in essence the drawOn: method I had not been able to figure out as the key, and some misunderstandings on the corners specifications of nested morphs. All your hints summarized to me getting going (and of cause the browsing of all the stuff in the image). Best, Kasper |
pay attention morph position is doomed (global instead of local).
Stef On Dec 16, 2011, at 9:16 AM, Kasper Østerbye wrote: > Thanks all, > > It was in essence the drawOn: method I had not been able to figure out as the key, and some misunderstandings on the corners specifications of nested morphs. All your hints summarized to me getting going (and of cause the browsing of all the stuff in the image). > > Best, > > Kasper |
Free forum by Nabble | Edit this page |