[plt-scheme] drawing in MrEd's pasteboards

From: Robby Findler (robby at cs.uchicago.edu)
Date: Fri Sep 8 13:24:04 EDT 2006

At Fri, 08 Sep 2006 17:20:24 +0200, nik gaffney wrote:
> >> from the description of a pasteboard% it looks like it should be possible
> >> to do similar path based drawing in a within an editor-canvas% as in a 
> >> canvas% draw context. however, i cant seem to find an obvious way to get
> >> this working with out resorting to creating bitmaps, then using
> >> image-clip%, is there a more straightforward method of drawing into a
> >> pasteboard ?+
> >
> > You should be able to do the same things in a canvas% and in an
> > editor-canvas% (the second has more going on, so you may need to be a
> > little more careful about ordering of drawing, tho). In particular, they
> > both draw into a canvas-dc, so you should be able to use all the same
> > path stuff in both places.
> > 
> > What's going wrong?
> 
> to perhaps clarify, i would like to be able to draw a path based object into an
> editor-canvas, and be able to move or resize it.
> 
> so, from what i understand of how the editor canvas works, id like to know an
> idiomatic way to get a function such as the following to draw into an
> image-snip%  ->
> 
> (a-drawing-function (send an-editor-canvas get-dc))
> 
> what im currently doing is something like ->
> 
> (define offscreen (make-object bitmap% 16 100 100))
> (define bdc (make-object bitmap-dc% offscreen))
> 
> (a-drawing-function bdc)
> (send bdc set-bitmap #f)
> 
> (define img (make-object image-snip% offscreen #f))
> (send p insert img)
> 
> which looks rather awkward, especially for redrawing and scaling. so im just
> wondering if im going about this in the wrong way?

Oh, I see. You probably want to override the on-paint method of the
editor canvas and do your drawing there. Also you can avoid the bitmap
entirely and get some memory savings (unless your drawing needs to do
that for some reason). Something like this:

(define my-editor-canvas%
  (class editor-canvas%
    (inherit get-dc)
    (define/override (on-paint before? dc left top right bottom dx dy draw-caret)
      (a-drawing-function (get-dc))
      (super on-paint before? dc left top right bottom dx dy draw-caret))
    (super-new)))

You'll want to read the docs for on-paint (just put your caret next to
"on-paint" in the above code, and hit f1 from inside drscheme, or
search in help desk).

hth,
Robby



Posted on the users mailing list.