Creating movable Fonts on a Canvas

38 views
Skip to first unread message

Amir Teymuri

unread,
Jun 23, 2019, 4:40:34 PM6/23/19
to Racket Users
If i want to use fonts on a canvas in a way that each single Glyph/Font is movable around the canvas by mouse, is it a good idea to have a class drivative of canvas% for each new font and then override the on-event method of them to update its coordinates on the main canvas? Or is there a better more effiicient way for doing this?

Greetings,
Amir

Alex Harsanyi

unread,
Jun 23, 2019, 8:52:35 PM6/23/19
to Racket Users
Have a look at the `snip%` and `pasteboard%` classes: you can represent each glyph using a `snip%` and the pasteboard will handle the moving it with the mouse.  You can derive the `snip%` and `pasteboard%` objects to add new functionality -- this is easier than implementing a mouse move operation using the `canvas%`  `on-event` method.

While not exactly what you need, I wrote a blog post about using `snip%` objects, and in the first example, the chess pieces themselves are actually Unicode Glyphs, so you could easily modify it to have different Glyphs/Letters that can be moved around in a canvas:

Amir Teymuri

unread,
Jun 24, 2019, 3:12:36 AM6/24/19
to Racket Users
Wow, this is a great blog! Many Thanks!
Reply all
Reply to author
Forward
0 new messages