Attached file canvas-pane.lisp is a work-in-progress. clim-patch.lisp provides MEDIUM-DRAW-PIXELS* it depends on, based on Andy Hefner's code that he posted a while back.
I use it in my raytracer's CLIM frontend to put up the pretty pictures as they are drawn, and to provide a selection area on already rendered images.
There are (currently) three major behaviours that it provides for me:
(SETF (CANVAS-RGBA CANVAS) <RGBA-AS-UB32>)
allows me to quickly assign color to a pixel.
(REPAINT-SHEET CANVAS (CANVAS-DIRTY-REGION CANVAS))
allows me to refresh the screen during rendering, updating only those portions where pixel colors have changed.
(CANVAS-SELECTION CANVAS)
gives me the bounding rectangle of the selected area. (A region is selected at any time by clicking and dragging on the canvas.)
There may be any number of dubious things in there, but the things that most confuse me are:
* What to subclass? I currently subclass APPLICATION-PANE. I don't know if I should subclass something else instead.
* Unintended overriding. I seem to accidentally override the border-building stuff from APPLICATION-PANE. It is not obvious to me why this happens, nor do I know how to avoid this should I want to.
* Event handling: to get pointer events I define a method on DISPATCH-EVENT that calls HANDLE-EVENT. Is this the way it is supposed to be done?
* Event handling & coordinates: to get coordinates relative to canvas when the pointer is outside the canvas area during the click-and-drag selection I transform coordinates through a common ancestor. This seems a bit awkward -- is there a better way?
Any comments would be most welcome.
Cheers,
-- Nikodemus