Subject: RE : windows copy and lines display
From: Christophe Le Page (christophe.l@chula.ac.th)
Date: Wed Apr 12 2006 - 13:37:29 CEST
Salut Géraldine!
> -----Message d'origine-----
> De : owner-cormas@cirad.cirad.fr [mailto:owner-cormas@cirad.cirad.fr] De
> la part de Geraldine Abrami
> Envoyé : mercredi 12 avril 2006 01:03
> À : cormas@cirad.fr
> Objet : windows copy and lines display
>
> Dear Cormas users,
>
> I need 2 informations :
>
> - I know there is a shortcut to copy and paste Cormas windows as images,
> but I can't remember.
>
[clp]
To do it “manually”, on Windows, <Shift><Alt><PrtScreen> will copy in the
buffer memory the active window. You can then paste it <Crtl-V> where you
want (Word, PowerPoint, etc…) and then if you need to create an image file
from it, you can select it from there and save it as image.
In a Cormas model, if you wish to programmatically save a GUI window as a
jpeg image, you can add this method to your custom GUI class:
saveAsJpegFile: aFilename
| window image jpegStream |
window := self builder window.
window expand; raise.
image := Screen default completeContentsOfArea: window displayBox.
jpegStream := JunJpegImageStream on: aFilename writeStream.
[JunCursors cameraCursor showWhile: [jpegStream nextPutImage: image]]
valueNowOrOnUnwindDo: [jpegStream close]
An example of how to use it from your model is given in the following
method:
showAndSaveCustomGUI
| chart |
chart := MyCustomGUI new.
chart model: self.
chart open.
chart saveAsJpegFile: ((Cormas dataPath: self class name) construct:
'test’, self timeStep printString, '.jpg')
> - Is there a generic method to draw a (ploy)line between cells of the
> Cormas grid?
>
>
[clp]
As far as I know, it has never been set as a generic method. Here is an
example taken from the SylvoPastJeu Cormas model, where the circuit of the
shepherd is saved as a collection of visited cells. To display it on the
spatial grid with white thick line segments, the following method is used:
showVisitedCells
| gc start end |
self visitedCells isEmpty ifFalse:
[gc := self visitedCells first view graphicsContext.
gc paint: (ColorValue perform: #white).
gc lineWidth: 3.
1 to: self visitedCells size – 1 do:
[:i |
start := self visitedCells at: i.
end := self visitedCells at: i + 1.
gc displayLineFrom: start center to: end center]]
Cheers !
Clp