Are canvases stackable?

71 views
Skip to first unread message

David Alkire

unread,
Feb 23, 2018, 11:08:28 PM2/23/18
to Racket Users
Is it possible to stack two (or more) canvases on top of one another. I'm working on a chess app and I don't want to draw individual squares under each piece. I would prefer to have a board canvas that doesn't change and a transparent canvas with pieces overlaying it. Is that possible? Is that the right approach or are there better alternatives?

Thanks,
David

Alex Harsanyi

unread,
Feb 23, 2018, 11:24:32 PM2/23/18
to Racket Users
You want to use a pasteboard% for the chess table and snip% objects for the pieces. You can draw the board as the pasteboard background in the on-draw method.

You will have to implement snip management in the pasteboard though because by default snips can just be dragged around and placed anywhere.

There’s a racket game collection which might provide useful classes, but I have no experience with those.

Best regards,
Alex

David Alkire

unread,
Feb 25, 2018, 6:13:03 AM2/25/18
to Alex Harsanyi, Racket Users
That's interesting. Thanks, I'll give it a try.

--
You received this message because you are subscribed to a topic in the Google Groups "Racket Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/racket-users/BPM0bb-MpnM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to racket-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Alkire

unread,
Feb 28, 2018, 6:28:29 AM2/28/18
to Alex Harsanyi, Racket Users
How could I set the style of my piece snips so that they don't have the selected bounding box as I select and drag them?

Alex Harsanyi

unread,
Feb 28, 2018, 6:48:23 AM2/28/18
to Racket Users

Try this:

     (send a-pasteboard set-selection-visible #f)

Normally, you would create your own class derived from `pasteboard%`, to add the specialized snip management code.  In that case, you can add the following line to your class declaration, right after the `(super-new)` call.

    (send this set-selection-visible #f)

Cheers,
Alex.

David Alkire

unread,
Feb 28, 2018, 6:51:50 AM2/28/18
to Alex Harsanyi, Racket Users
Ha. I don't know how I missed that in the docs. Thanks. Also, is this the best venue for some questions like this or would the IRC channel be a better fit?

-David

Alex Harsanyi

unread,
Feb 28, 2018, 7:47:34 AM2/28/18
to Racket Users


On Wednesday, February 28, 2018 at 7:51:50 PM UTC+8, David Alkire wrote:
Also, is this the best venue for some questions like this or would the IRC channel be a better fit?


I don't know, as I don't use IRC.

If you want to look at a non-trivial pasteboard use case, I implemented a calendar view, which draws the calendar background in the editor-canvas% and uses snips for the calendar items.  It is not a chess board, but might be close enough, as it illustrates how draw a grid and place snips in it. I attached a screenshot and you can look at the implementation here: https://github.com/alex-hhh/ActivityLog2/blob/master/rkt/view-calendar.rkt 

I also wrote a fun little application which draws a map as a pasteboard background (together with zooming and panning) and allows placing various telemetry snips on it which fetch real time data from a bike trainer.  I wrote about that here: https://alex-hhh.github.io/2017/11/bike-trainer.html, might be useful as an inspiration on what you can do with pasteboards.

Best Regards,
Alex.




Auto Generated Inline Image 1
Auto Generated Inline Image 2

David Alkire

unread,
Feb 28, 2018, 8:12:19 AM2/28/18
to Alex Harsanyi, Racket Users
This is incredibly helpful. Thank you.

Reply all
Reply to author
Forward
0 new messages