Iulius Curt
Iulius Curt

Reputation: 5114

GUI elements in (Dr) Racket

I need some basic stuff for working with the GUI library in Racket.

  1. How do I set the callback function to a button like this:

    (define next (new button% [parent frame] [label "Next ->"]))
    
  2. How do I draw something on a canvas after it's been created like this:

    (define canvas (new canvas% [parent frame]  
        [paint-callback canvasdc]))
    
    (define canvasdc (lambda (canvas dc)  
        (send dc set-text-foreground "black")  
        (send dc draw-text "Some title!" 0 0)  
    ))
    

    I would need to draw (rescaled jpegs or, if not able) compound shapes and repaint with something else on every button pressed event

Upvotes: 1

Views: 1958

Answers (1)

Gareth McCaughan
Gareth McCaughan

Reputation: 19981

  1. There's an optional callback argument to the button constructor.

  2. See http://docs.racket-lang.org/draw/overview.html. But I'm confused by your question since the code you've posted includes drawing to the canvas. For images, specifically, read-bitmap will read a bitmap from a file; draw-bitmap will draw a bitmap into a DC. You can get it (along with all other drawing to that DC) scaled by calling set-scale. If the DC you're drawing into is a bitmap-dc (I don't think a canvas-dc is, but I am not a Racket expert and could be wrong) then you can do it directly using draw-bitmap-section-smooth.

Upvotes: 1

Related Questions