graphics in dolphin

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

graphics in dolphin

Gary  Kelly
is there a good section or source somewhere that explains the use of the
graphics. for example if I could even see a simple program which just graphs
the sin function that would be sufficient. I am new to Smalltalk and have
downloaded the version 6.
respectfully: Gary Kelly


Reply | Threaded
Open this post in threaded view
|

Re: graphics in dolphin

Bruno Brasesco
Gary Kelly escribió:
> is there a good section or source somewhere that explains the use of the
> graphics. for example if I could even see a simple program which just graphs
> the sin function that would be sufficient. I am new to Smalltalk and have
> downloaded the version 6.
> respectfully: Gary Kelly
>
>

Gdiplus packages has a lot of grapchis functions.

Browse GdiplusBase and subclasses and search in class side for
exampleXXX methods.

Evaluate this:
GdiplusGraphics exampleGdipGDrawingShapes showExample

Regards Bruno


Reply | Threaded
Open this post in threaded view
|

Re: graphics in dolphin

Andy Bower-3
In reply to this post by Gary Kelly
Gary,

> is there a good section or source somewhere that explains the use of
> the graphics. for example if I could even see a simple program which
> just graphs the sin function that would be sufficient. I am new to
> Smalltalk and have downloaded the version 6.

Here (below) is a sample package that will allow you to plot simple
functions in a window. Save the code between (not including) the ===
marks to a file called "Graph Drawing.pac" (or similar). Then use the
Package Browser to load in the package and follow the instructions in
the Comment pane.

The code can be found in a class called GraphPlotShell although the
actual drawing within the window is done by the Canvas class that is
built into the base Dolphin system. A Canvas is basicallly an
abstraction of a Windows Device Context.

I hope this gets you started.

PS: Don't try to read the code in situ in this message. It'll be much
easier once it has been loaded into your image as a package. You can
then just user the Class Browser to find the GraphPlotShell class and
browse the methods from there.

--
Andy Bower
Dolphin Support
www.object-arts.com

===
| package |
package := Package name: 'GraphDrawing'.
package paxVersion: 1;
        basicComment: ''.


package classNames
        add: #GraphPlotShell;
        yourself.

package binaryGlobalNames: (Set new
        yourself).

package globalAliases: (Set new
        yourself).

package setPrerequisites: (IdentitySet new
        add: '..\..\..\Dolphin\MVP\Base\Dolphin MVP Base';
        yourself).

package!

"Class Definitions"!

ShellView subclass: #GraphPlotShell
        instanceVariableNames: 'xRange yRange functionBlock'
        classVariableNames: ''
        poolDictionaries: ''
        classInstanceVariableNames: ''!

"Global Aliases"!


"Loose Methods"!

"End of package definition"!

"Source Globals"!

"Classes"!

GraphPlotShell guid: (GUID fromString:
'{8DF31025-B456-4C43-A9CE-D15BB9E30796}')!
GraphPlotShell comment: ''!
!GraphPlotShell categoriesForClass!MVP-Views! !
!GraphPlotShell methodsFor!

functionBlock
        ^functionBlock!

functionBlock: aMonadicValuable
        functionBlock := aMonadicValuable.
        self invalidate!

functionPointForXPixel: x
        "Private - Answer a function Point to plot for a given x pixel
coordinate.
        Performs all scaling based on the xRange and yRange aspects of the
receiver"

        | y |
        y := ((self functionBlock value: x * self xScale + self xRange start)
- self yRange start)
                                / self yScale.
        ^(x @ (self clientHeight + y negated)) rounded!

initialize
        super initialize.
        functionBlock := [:x | x degreesToRadians sin ].
        xRange := 0 to: 360.
        yRange := -1 to: 1.!

onPaintRequired: aPaintEvent
        "Private - A portion of the receiver window has been exposed and needs
repainting.
        The supplied aPaintEvent holds details about the exposed area.
        Within #onPaintRequired: you MUST ask for a Canvas from aPaintEvent
        (not the receiver window) to paint the contents on."

        | canvas |
        canvas := aPaintEvent canvas.
        canvas pen: (Pen withStyle: PS_DOT width: 1 color: Color red).
        canvas moveTo: (self functionPointForXPixel: 0).
        1 to: self clientWidth
                do:
                        [:x |
                        | pt |
                        pt := self functionPointForXPixel: x.
                        canvas lineTo: pt]!

onPositionChanged: aPositionEvent
        "Private - Handle a window position change event (move or resize)."

        aPositionEvent isResize ifTrue: [self invalidate].
        ^super onPositionChanged: aPositionEvent!

xRange
        ^xRange!

xRange: anIntervalOfInteger
        xRange := anIntervalOfInteger.
        self invalidate!

xScale
        ^(self xRange size - 1) / self clientWidth!

yRange
        ^yRange!

yRange: anIntervalOfInteger
        yRange := anIntervalOfInteger.
        self invalidate!

yScale
        ^(self yRange size - 1) / self clientHeight! !
!GraphPlotShell categoriesFor: #functionBlock!public! !
!GraphPlotShell categoriesFor: #functionBlock:!public! !
!GraphPlotShell categoriesFor: #functionPointForXPixel:!event
handling!helpers!private! !
!GraphPlotShell categoriesFor: #initialize!private! !
!GraphPlotShell categoriesFor: #onPaintRequired:!event
handling!private! !
!GraphPlotShell categoriesFor: #onPositionChanged:!event
handling!private! !
!GraphPlotShell categoriesFor: #xRange!public! !
!GraphPlotShell categoriesFor: #xRange:!public! !
!GraphPlotShell categoriesFor: #xScale!event handling!helpers!private! !
!GraphPlotShell categoriesFor: #yRange!public! !
!GraphPlotShell categoriesFor: #yRange:!public! !
!GraphPlotShell categoriesFor: #yScale!event handling!helpers!private! !

"Binary Globals"!
===


Reply | Threaded
Open this post in threaded view
|

Re: graphics in dolphin

Andy Bower-3
Gary,

> Here (below) is a sample package that will allow you to plot simple
> functions in a window. Save the code between (not including) the ===
> marks to a file called "Graph Drawing.pac" (or similar). Then use the
> Package Browser to load in the package and follow the instructions in
> the Comment pane.

Sorry, I forgot to save out the package Comment instructions in my
previous post. Please try the following version instead:

Best regards

--
Andy Bower
Dolphin Support
www.object-arts.com


===
| package |
package := Package name: 'GraphDrawing'.
package paxVersion: 1;
        basicComment: 'A sample package that demonstrates how to plot simple
functions within a window.

Evaluate each of the following lines individually:

graph := GraphPlotShell show.
graph xRange: (0 to: 720).
graph yRange: (-2 to: 2).

Now let''s try a different function.
graph xRange: (-10 to: 10).
graph yRange: (0 to: 150).
graph functionBlock: [:x | x*x].

and another...
graph functionBlock: [:x | (x**3) - (6*x*x) + 2].
graph yRange: (-1000 to: 1000)'.


package classNames
        add: #GraphPlotShell;
        yourself.

package binaryGlobalNames: (Set new
        yourself).

package globalAliases: (Set new
        yourself).

package setPrerequisites: (IdentitySet new
        add: '..\..\..\Dolphin\MVP\Base\Dolphin MVP Base';
        yourself).

package!

"Class Definitions"!

ShellView subclass: #GraphPlotShell
        instanceVariableNames: 'xRange yRange functionBlock'
        classVariableNames: ''
        poolDictionaries: ''
        classInstanceVariableNames: ''!

"Global Aliases"!


"Loose Methods"!

"End of package definition"!

"Source Globals"!

"Classes"!

GraphPlotShell guid: (GUID fromString:
'{8DF31025-B456-4C43-A9CE-D15BB9E30796}')!
GraphPlotShell comment: ''!
!GraphPlotShell categoriesForClass!MVP-Views! !
!GraphPlotShell methodsFor!

functionBlock
        ^functionBlock!

functionBlock: aMonadicValuable
        functionBlock := aMonadicValuable.
        self invalidate!

functionPointForXPixel: x
        "Private - Answer a function Point to plot for a given x pixel
coordinate.
        Performs all scaling and offsetting based on the xRange and yRange
aspects of the receiver"

        | y |
        y := ((self functionBlock value: x * self xScale + self xRange start)
- self yRange start)
                                / self yScale.

        "Note that a canvas uses an inverted coordinate system where 0@0 is at
top left.
        Hence we invert the y axis here and offset by the window height"
        ^(x @ (self clientHeight + y negated)) rounded!

initialize
        super initialize.
        functionBlock := [:x | x degreesToRadians sin ].
        xRange := 0 to: 360.
        yRange := -1 to: 1.!

onPaintRequired: aPaintEvent
        "Private - A portion of the receiver window has been exposed and needs
repainting.
        The supplied aPaintEvent holds details about the exposed area.
        Within #onPaintRequired: you MUST ask for a Canvas from aPaintEvent
        (not the receiver window) to paint the contents on."

        | canvas |
        canvas := aPaintEvent canvas.
        canvas pen: (Pen withStyle: PS_DOT width: 1 color: Color red).
        canvas moveTo: (self functionPointForXPixel: 0).
        1 to: self clientWidth
                do:
                        [:x |
                        | pt |
                        pt := self functionPointForXPixel: x.
                        canvas lineTo: pt]!

onPositionChanged: aPositionEvent
        "Private - Handle a window position change event (move or resize)."

        aPositionEvent isResize ifTrue: [self invalidate].
        ^super onPositionChanged: aPositionEvent!

xRange
        ^xRange!

xRange: anIntervalOfInteger
        xRange := anIntervalOfInteger.
        self invalidate!

xScale
        ^(self xRange size - 1) / self clientWidth!

yRange
        ^yRange!

yRange: anIntervalOfInteger
        yRange := anIntervalOfInteger.
        self invalidate!

yScale
        ^(self yRange size - 1) / self clientHeight! !
!GraphPlotShell categoriesFor: #functionBlock!public! !
!GraphPlotShell categoriesFor: #functionBlock:!public! !
!GraphPlotShell categoriesFor: #functionPointForXPixel:!event
handling!helpers!private! !
!GraphPlotShell categoriesFor: #initialize!private! !
!GraphPlotShell categoriesFor: #onPaintRequired:!event
handling!private! !
!GraphPlotShell categoriesFor: #onPositionChanged:!event
handling!private! !
!GraphPlotShell categoriesFor: #xRange!public! !
!GraphPlotShell categoriesFor: #xRange:!public! !
!GraphPlotShell categoriesFor: #xScale!event handling!helpers!private! !
!GraphPlotShell categoriesFor: #yRange!public! !
!GraphPlotShell categoriesFor: #yRange:!public! !
!GraphPlotShell categoriesFor: #yScale!event handling!helpers!private! !

"Binary Globals"!
===


Reply | Threaded
Open this post in threaded view
|

Re: graphics in dolphin

Andy Bower-3
Gary,

> > Here (below) is a sample package that will allow you to plot simple
> > functions in a window. Save the code between (not including) the ===
> > marks to a file called "Graph Drawing.pac" (or similar). Then use
> > the Package Browser to load in the package and follow the
> > instructions in the Comment pane.

If you're new to Smalltalk, one of the things (hopefully amongst many)
that you might find fun is the ability to shutdown and restart the IDE
whilst leaving a an application up and running and (even) being
debugged.

Whilst you have one of those GraphPlotShells open, try closing Dolphin
and saving the image. When you later go back into Dolphin, the graph
window will still be there exactly as you left it without any need to
re-open it from scratch.

I like to call this the "messy bedroom paradigm" :-) When your Mum
(mom) used to tell you to tidy your bedroom before going to bed it was
always really annoying (well it was to me, anyway). What you really
wanted to do was to leave all your toys out so you could get straight
back into playing where you left off as soon as you woke up again in
the morning. Smalltalk allows you to do this; you can keep everything
open (including debuggers) when you shutdown the system so that it's
all ready to go when you restart your image the next day.

Best regards,

--
Andy Bower
Dolphin Support
www.object-arts.com


Reply | Threaded
Open this post in threaded view
|

Re: graphics in dolphin

Janos Kazsoki
Andy,

Wow! Very elegant and impressive.
Janos