Hi...
The appended view repaint code works fine but produces some unpainted vertical lines when the commented section is added. Adding only the first line produces no artifacts so it seems to happen whenexecuting two Canvas>>lineFrom:to: with different pens. Any idea how to come around this? Ah yes, ín addtion I get spurious unrepainted areas always (also with the otherwise working code) when I invalidate tall rectangles in rapid sucession (e.g. 10@0 extent: 1@self height). This is used with mouseMoved: events to hilite the position of the mouse. Ciao ...Jochen --------- onPaintRequired: aPaintEvent "Handler for paint event. Show the histogam as a bar chart scaled appropriately." | histogram scale | histogram := self histogram. histogram ifNil: [^self]. scale := (self width / histogram size) @ (self height / self histogramMaxValue). histogram keysAndValuesDo: [:idx :h | | x y hilite | x := (idx * scale x - (scale x / 2)) rounded. y := (self height - (h * scale y)) rounded. hilite := idx = self hiliteIndex. "aPaintEvent canvas pen: (hilite ifTrue: [Pen blue] ifFalse: [Pen black]). aPaintEvent canvas lineFrom: x @ 0 to: x @ (y - 1)." aPaintEvent canvas pen: (hilite ifTrue: [Pen white] ifFalse: [Pen green]). aPaintEvent canvas lineFrom: x @ y to: x @ (self height - 1)] |
Seems to be a strange timing problem?! A possible fix is to assign
aPaintEvent canvas to a local var before entering the loop. It looks like as if sometimes the actual line is painted BEFORE the pen is set in the canvas although the order in the code is the other way around. Very strange, I hope it does not come back to me on different systems... Any idea what the cause is? Ciao ...Jochen |
In reply to this post by Jochen Riekhof
Jochen Riekhof wrote:
> The appended view repaint code works fine but produces some unpainted > vertical lines when the commented section is added. I tried this out on W2K. I saw some repaint problems but not exacty the ones you described. I'm not sure exactly what is going wrong, but you are creating a succession of new Canvas objects each refering to the same DC. Changing the repaint method to read: ================= onPaintRequired: aPaintEvent "Handler for paint event. Show the histogam as a bar chart scaled appropriately." | histogram scale canvas | histogram := self histogram. histogram ifNil: [^self]. scale := self width / histogram size @ (self height / self histogramMaxValue). canvas := aPaintEvent canvas. histogram keysAndValuesDo: [:idx :h | | x y hilite | x := (idx * scale x - (scale x / 2)) rounded. y := (self height - (h * scale y)) rounded. hilite := idx = self hiliteIndex. canvas pen: (hilite ifTrue: [Pen blue] ifFalse: [Pen black]). canvas lineFrom: x @ 0 to: x @ (y - 1). canvas pen: (hilite ifTrue: [Pen red] ifFalse: [Pen green]). canvas lineFrom: x @ y to: x @ (self height - 1)]. ================= fixes the problems on my machine. The difference is that it creates just one Canvas object, and then uses it for all the GDI stuff. My best guess is that the problems were something to do with the transient Canvases' internal Pen objects sometimes being garbage collected while they were still selected into the DC. -- chris |
> I'm not sure exactly what is going wrong, but you are creating a
succession of > new Canvas objects each refering to the same DC. Changing the repaint method > to read: fixes the problems on my machine. The difference is that it creates just one > Canvas object, and then uses it for all the GDI stuff. Yes, this fix I found also (see other post). Well, I never expected that a new canvas is created on each send of Event>>canvas. As I believe this canvas is almost always used on send of a repaint anyway, it should be cached. The gc-ed pen is reasonable. Here as well I learned that a new Pen is indeed greated for Pen class>green instead of using a precreated stock pen. Oh well... (I will cache the needed pens anyway in the final version) Ciao ...Jochen |
> The gc-ed pen is reasonable. Here as well I learned that a new Pen is
indeed > greated for Pen class>green instead of using a precreated stock pen. Oh > well... (I will cache the needed pens anyway in the final version) FYI Now that I have cached pens for painting, I temporarily switched back to aPaintEvent canvas calls to test the gc theory. No problems now, so it were VERY likly gc'ed pens that caused the problem. Ciao ...Jochen |
Free forum by Nabble | Edit this page |