To illustrate my problem, compare the result of the two code fragments, the upper one provided by Boris, the second one illustrating what I have been doing. I would really like to have the result of the first fragment, but not on the Display but on a morph...
Hans
| bc fs ramp | ramp := (0 to: 360 by: 60) collect: [:h | h / 360.0 -> (Color h: h s: 0.7 v: 0.8 alpha: 0.2)]. fs := GradientFillStyle ramp: ramp. fs origin: (10@10).
fs direction: 600@300. fs radial: false. bc := BalloonCanvas on: Display. bc aaLevel: 2. bc drawPolygon: (Array with: 10@10 with: 500@300 with: 300 @500 with: 50 @ 300) fillStyle: fs borderWidth: 2 borderColor: ((Color red) alpha: 0.3).
| bc fs ramp form | form := Form extent: 600@600 depth: Display depth. ramp := (0 to: 360 by: 60) collect: [:h | h / 360.0 -> (Color h: h s: 0.7 v: 0.8 alpha: 0.2)]. fs := GradientFillStyle ramp: ramp. fs origin: (10@10).
fs direction: 600@300. fs radial: false. bc := BalloonCanvas on: form "Display" . bc aaLevel: 2. bc drawPolygon: (Array with: 10@10 with: 500@300 with: 300 @500 with: 50 @ 300) fillStyle: fs borderWidth: 2 borderColor: ((Color red) alpha: 0.3). ^form asMorph openInWorld
On Friday 25 February 2005 7:26 am, Baveco, Hans wrote:
When displaying polygons on a BalloonCanvas, setting the alpha of the fill-color apparently does not work. It changes the color though: when alpha approaches 1.0 the original color shows, when alpha approaches 0.0 the resulting color approaches black/opaque. Is this a known limitation, or a bug.... (the code looks like transparency should be handled). The final drawing is done in primitives, so a bit difficult to check..
I think the problem is more in the way that you displayed the contents of the BalloonCanvas. Was there an intermediate canvas?
If you look at (for instance) the fill in the inside of Connectors (which are rendered with Balloon2D) you will see that they can have translucency.
-- Ned Konz
On Friday 25 February 2005 1:41 pm, Hans Baveco wrote:
To illustrate my problem, compare the result of the two code fragments, the
upper one provided by Boris, the second one illustrating what I have been doing. I would really like to have the result of the first fragment, but not on the Display but on a morph... [snip]
fs direction: 600@300.
fs radial: false. bc := BalloonCanvas on: form "Display" . bc aaLevel: 2. bc drawPolygon: (Array with: 10@10 with: 500@300 with: 300 @500 with: 50 @ 300) fillStyle: fs borderWidth: 2 borderColor: ((Color red) alpha: 0.3). ^form asMorph openInWorld
The problem is that "form asMorph" makes a Morph that doesn't know how to be translucent. Look at ImageMorph>>drawOn:
drawOn: aCanvas | style | (style _ self borderStyle) ifNotNil:[ style frameRectangle: bounds on: aCanvas. ]. self isOpaque ifTrue:[aCanvas drawImage: image at: self innerBounds origin] ifFalse:[aCanvas translucentImage: image at: self innerBounds origin]
So what's the definition of isOpaque?
I don't understand, though, what the distinction between "on the Display" and "on a morph" is.
From the graphical point of view, all a Morph does is to draw itself on canvases when asked.
So all you need to do is:
drawOn: aCanvas aCanvas asBalloonCanvas drawPolygon: ...
or something similar.
As long as "asBalloonCanvas" returns a BalloonCanvas (which FormCanvas does), you get the same thing whether the Morph is being rendered to the Display, to a form, or is being rendered some other way.
However, because some canvases (notablly the ShadowCanvas used to draw drop shadows) don't actually respond to asBalloonCanvas, or return a BalloonCanvas when asked, you have to be a little more careful sometimes: either you stick to the guaranteed Canvas operations, or you test for whether you got a canvas that supports your desired operations. In Connectors (which sometimes draw themselves using Bezier curves) I had to test the resultant canvas and use a different drawing strategy for shadows.
squeak-dev@lists.squeakfoundation.org