Skip to content

Commit

Permalink
view,image: avoid performing unnecessary work
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogdanp committed Feb 16, 2024
1 parent 66f8be4 commit c1b81bf
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions gui-easy-lib/gui/easy/private/view/image.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,38 @@
(let ([bmp (send self get-context 'bmp/scaled bmp/scaled)])
(send dc draw-bitmap bmp 0 0)))]))
(begin0 the-canvas
(send the-canvas set-context* 'image image 'bmp bmp 'bmp/scaled bmp/scaled)))
(send the-canvas set-context*
'image image
'size size
'mode mode
'bmp bmp
'bmp/scaled bmp/scaled)))

(define/public (update v what val)
(case/dep what
[@props
(define last-image
(send v get-context 'image))
(define last-image (send v get-context 'image))
(define last-size (send v get-context 'size))
(define last-mode (send v get-context 'mode))
(define last-bmp (send v get-context 'bmp))
(define last-bmp/scaled (send v get-context 'bmp/scaled))
(match-define (props image size mode) val)
(define bmp
(if (equal? image last-image)
(send v get-context 'bmp)
(read-bitmap image)))
(define bmp/scaled
(scale bmp size mode))
(send v set-context* 'image image 'bmp bmp 'bmp/scaled bmp/scaled)
(if (and (equal? bmp last-bmp)
(equal? size last-size)
(equal? mode last-mode))
last-bmp/scaled
(scale bmp size mode)))
(send v set-context*
'image image
'size size
'mode mode
'bmp bmp
'bmp/scaled bmp/scaled)
(send v min-width (send bmp/scaled get-width))
(send v min-height (send bmp/scaled get-height))
(send v refresh-now)]))
Expand Down

0 comments on commit c1b81bf

Please sign in to comment.