On Monday, June 24, 2019 at 6:25:05 PM UTC+8, Nickolay Ilyushin wrote: > > While checking racket's gui possibilities, I've noticed that widgets (in > both amount and config) are limited - yes, they can do much enough, but > using somewhat different (yet minimalistic) style we can do way more while > dropping most of those widgets. > > Please note that this is only an idea which seems (at least for me) nice > enough to be implemented when you see such frameworks as Qt Quick or > Flutter. > > 1. Canvas/DC changes > > 1.1: Canvas clipping > Currently, if we want to limit our drawing to a square, we use bitmap-dc% > class, which creates a new bitmap which will be then blitted to the canvas > or another bitmap. > This can be simplified (for users though) by making a clip operation > similar to the one found in nanovg. > Ideally it would use opengl stencil buffer or similar techniques, so we > could clip non-square shapes, but as I can see, racket/gui's canvas does > not use low-level graphics APIs directly. > Although it is probably possible to allow non-rectangular shapes in other > way. >
The draw context for a canvas (which you can get via the `get-dc` canvas% method) has a `set-clipping-rect` and `set-clipping-region` methods to clip to a rectangle or an arbitrary path. > Ideally clip operations should be stored in a stack (aka list (push=cons, > peek=car, pop=cdr) in terms of lisp) so you could restore previous clip > state - that would allow making multiple widgets which clip their drawing > context. > There is no stack for the clipping regions, but each function that does some drawing could save the old clipping region, install a new one, than restore the old one once done: (let ((old-region (send dc get-clipping-region))) (send dc set-clipping-region new-region) ;; do the drawing here (send dc set-clipping-region old-region)) A similar approach can be used to set pens, brushes and other drawing resources and a lot of higher level drawing libraries already use this technique. Alex. -- You received this message because you are subscribed to the Google Groups "Racket Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-dev/b0bd24bb-2802-45bd-9403-6fe108bcb11f%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
