Skip to content

Commit

Permalink
Merge pull request #1196 from vindarel/main
Browse files Browse the repository at this point in the history
image: fit to screen also for smaller images
  • Loading branch information
cxxxr authored Dec 20, 2023
2 parents c309775 + dc6734d commit 7aadfce
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions frontends/sdl2/image-buffer.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
(scale-buffer-image buffer (* -1 (/ percent 100))))))

(defun fit-to-screen (buffer)
"If the image is bigger that the display, shrink it."
"Change the image dimensions so it fits in the screen."
(let* ((image (buffer-image buffer))
(width (image-width image))
(height (image-height image))
Expand All @@ -121,14 +121,11 @@
(1-
(window-height (current-window)))))
(ratio-image (/ height width))
(ratio-display (/ display-height display-width))
(needs-resizing-p (or (> width display-width)
(> height display-height))))
(ratio-display (/ display-height display-width)))

(when needs-resizing-p
(if (>= ratio-image ratio-display)
(fit-to-height buffer)
(fit-to-width buffer)))))
(if (>= ratio-image ratio-display)
(fit-to-height buffer)
(fit-to-width buffer))))

(define-command image-zoom-in () ()
(scale-buffer-image (current-buffer) 0.1))
Expand All @@ -137,15 +134,19 @@
(scale-buffer-image (current-buffer) -0.1))

(define-command image-zoom-reset () ()
"Set the image to its original size."
(reset-buffer-scale (current-buffer)))

(define-command image-fit-to-width () ()
"Make the image as large as the display width."
(fit-to-width (current-buffer)))

(define-command image-fit-to-height () ()
"Make the image as big as the display height."
(fit-to-height (current-buffer)))

(define-command image-fit-to-screen () ()
"Enlarge or shrink the image to fit the display."
(fit-to-screen (current-buffer)))

(defclass sdl2-find-file-executor (lem:find-file-executor) ())
Expand Down

0 comments on commit 7aadfce

Please sign in to comment.