Skip to content

Instantly share code, notes, and snippets.

@toomasv
Last active September 5, 2019 16:32
Show Gist options
  • Save toomasv/64f8dd8d142de4bc859ecd411cdb2d2e to your computer and use it in GitHub Desktop.
Save toomasv/64f8dd8d142de4bc859ecd411cdb2d2e to your computer and use it in GitHub Desktop.
Zooming function
Red [
Date: 4-Sep-2019
Description: {Mouse sensitive zooming function}
Author: "Toomas Vooglaid"
Licence: "Public domain"
]
zooming: function [face event][
;face's draw-block needs to have matrix defined
mx: face/draw/matrix
ev: event/offset
;zooming in or out?
op: get pick [/ *] 0 > event/picked
;scaling factor
sc: mx/1 op 1.1
;see https://doc.red-lang.org/en/draw.html#_matrix
;and https://en.wikipedia.org/wiki/Transformation_matrix#/media/File:2D_affine_transformation_matrix.svg
face/draw/matrix: reduce [
sc 0 0 sc ;scaling
mx/5 - ev/x op 1.1 + ev/x ;new center of coordinates (COC):
mx/6 - ev/y op 1.1 + ev/y ;scaled diff of mouse pos from COC + mouse pos
]
]
e.g.: :comment
e.g. [
view/tight [
box 500x300 draw [ ;NB! no face color or alpha > 0
line-width 1
matrix [1 0 0 1 0 0]
;fill-pen snow
;box -1000x-1000 1500x1300
fill-pen linen
box 50x100 150x130 5
text 75x105 "zooming"
] on-wheel [zooming face event]
]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment