[plt-scheme] setting background color/image for a text field

From: Robby Findler (robby at cs.uchicago.edu)
Date: Fri Nov 9 08:50:52 EST 2007

Also, you might find this code snippet helpful.

(require (lib "mred.ss" "mred")
         (lib "class.ss"))

(define bitmap (make-object bitmap%
                 (build-path (collection-path "icons") "plt.jpg")))

(define background-text%
  (class text%
    (inherit get-dc position-location)
    (define/override (on-paint before? dc left top right bottom dx dy
draw-caret)
      (when before?
        (let ([bx (box 0)]
              [by (box 0)])
          (position-location 0 bx by)
          (send dc draw-bitmap bitmap
                (+ (unbox bx) dx)
                (+ (unbox by) dy))))
      (super on-paint before? dc left top right bottom dx dy draw-caret))
    (super-new)))

(define t (new background-text%))
(define f (new frame%
               [label ""]
               [width 400]
               [height 500]))
(define ec (new editor-canvas%
                [parent f]
                [editor t]))
(let loop ([n 10])
  (unless (zero? n)
    (send t insert "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\n")
    (loop (- n 1))))
(send f show #t)

Robby

On Nov 8, 2007 5:06 PM, Matthew Flatt <mflatt at cs.utah.edu> wrote:
> The editor-snip% class includes a `use-style-background' method.
> Calling it with #t causes the snip to pay attention to the
> background-color information associated in the snip's style (which
> would have been the right idea in the first place, but the default to
> ignore it is there for backward compatibility).
>
> The style can be configured for transparent backing or a particular
> color. I think that transparent is the default.
>
> Matthew
>
>
> At Thu, 8 Nov 2007 16:58:16 -0600, "Robby Findler" wrote:
> > I'm not sure if transparency is possible, but you can use a solid
> > color or an image but overriding the on-paint method of the text%
> > object and drawing it there.
> >
> > hth,
> > Robby
> >
> > On 11/8/07, Leslie Gerhat <thoroughbred_phoenix at yahoo.com> wrote:
> > >
> > >
> > >
> > >
> > > We are working with a set of text% objects in Mr.Ed, specifically two large
> > > text boxes. Right now, we are displaying a string of text in these objects.
> > > We would like to be able to change the background on which this text is
> > > written. We know that the entire canvas color may be changed using (send
> > > an-editor-canvas% set-canvas-background color%-object). However, the text
> > > fields remain white using this method. We would like to change the
> > > background of the text fields to an image, or possibly make the text fields
> > > transparent except for the text, so whatever is in the canvas background
> > > shows through the text fields. Additionally, we would also like to end-user
> > > to be able to choose between 3 different images for this background, which
> > > adds an additional complexity to the problem.
> > >
> > >
> > >
> > >
> > > Does anyone know of a way to do this? Or has anyone created a similar
> > > application and is able to give us some direction? We would greatly
> > > appreciate this. Thank you.
> > >
> > > __________________________________________________
> > > Do You Yahoo!?
> > > Tired of spam? Yahoo! Mail has the best spam protection around
> > > http://mail.yahoo.com
> > > _________________________________________________
> > >   For list-related administrative tasks:
> > >   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> > >
> > >
> > _________________________________________________
> >   For list-related administrative tasks:
> >   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>


Posted on the users mailing list.