I ran into a need to have a view displayed at different scales based on the room it was displayed in. Making things more difficult, it wasn't just one view, I needed logic for N views. No way I was going to make 20+ different versions of the same view cel for all my views to accommodate all the different scales that I needed.
I started by creating views that were 'full size', meaning either 320 on the x-axis or 190 on the y. Then I assigned relative 'scale values' or 'sizes' between them so they would sized appropriately when displayed with any other views. For example:
(define SWORD_SCALE 80)
(define LAMP_SCALE 65) ; the lamp is 80% the size of the sword
(define CLOVE_OF_GARLIC_SCALE 5) ; the clove of garlic is 6% the size of the sword
Then determine what your room scale value should be, 1 being a 'zoomed in' room and larger values get you 'further away' from them, effectively making them scaled down.
I added this procedure in the Actor.sc script:
;;;
;;; Calculates what the scale should be based on the relative room scale (current room) and relative view scale
;;; viewScale - a relative scaling value between ~5 (smallest) to ~100 (largest).
;;; roomScale - value between 1 ('closest' or 'largest views') to ~50 ('furthest' or 'smallest views')
;;;
(procedure (calcRelativeScale view loop cel viewScale roomScale &tmp width height dim tmpScale)
(= width (CelWide view loop cel))
(= height (CelHigh view loop cel))
(if (> width height)
(= dim width)
else
(= dim height)
)
(= tmpScale (/ (/ (* dim viewScale) 100) roomScale))
(if (< tmpScale 3)
(= tmpScale 3) ; smallest possible scale with full-screen views
)
(if (> tmpScale 100)
(= tmpScale 100) ; full size
)
(return tmpScale)
)
Then prior to initing your view, calculate the scale by passing in the view, loop, cel and your viewScale and roomScale. Just to be safe, make sure that the computed value is sane.
(= view 10) ; the sword view
(= loop 4)
(= cel 0)
(= viewScale SWORD_SCALE)
(= roomScale 50) ; I actually added a new property to the Room object and set the scales for the rooms there
(= tmpScale (calcRelativeScale view loop cel viewScale roomScale))
; don't attempt to scale if we have no scale value defined
(if (> tmpScale 0)
(myView init: show: setScale: Scaler tmpScale tmpScale)
else
(myView init: show:)
)
The scaled views that I generated from a 'full size' seemed pretty good at any size but this code could be improved by having more than just one view to choose from. We could make a 'half-size' view with max dimensions of 160x85 and perhaps another 'quarter-size' one. Compute the scales against all 3 views and choose the one that has a resulting scale nearest to 100 - this may help with any visual degradation when the scale size gets too small.
I've attached a screenshot of 3 different views, scaled at 5 different 'room sizes' using this process: