[ALLY] "Circonfine" - or how to skin a cat
From: ven::telia::com at: 28-Oct-2000 2:50
Hello allies!
Check out this one! It's the result of some hard hours trying to make a
round boundary for GUI-making (I'm not really a die-hard programmer).
I think it turned out pretty good. Now we can make these neat volume-
knobs for MP3-skins or whatever comes first..
Any comments are welcome..
--
Magnus Lundström
-- Attached file included as plaintext by Listar --
-- File: circonfine.r
rebol[]
circonfine: func [
{Return the correct offset to keep circular area in-bounds.}
offset [pair!] "Initial offset"
origin [pair!] "Area offset"
asize [pair!] "Size of area"
size [pair!] "Size of object to confine"
][
origin: origin + (asize / 2) - (size / 2)
offset: offset - origin
rmax: to-integer (asize/x / 2) - (size/x / 2)
r: square-root ((power offset/x 2) + (power offset/y 2))
if r > rmax [offset/x: to-integer offset/x * (rmax / r)
offset/y: to-integer offset/y * (rmax / r)]
offset: offset + origin
offset
]
;--------- example -----------
circle: make face [
offset: 100x100
size: 100x100
color: 175.185.188
effect: [gradcol 1x1 200.200.200 0.0.0 oval 0.0.0 key]
edge: make edge [size: 0x0]
]
dragger: make face [
size: 28x28
offset: circle/offset + (circle/size / 2) - 14x14
color: -1
edge: make edge [size: 0x0]
effect: [gradcol -1x-1 255.255.255 0.0.0 oval 0.0.0 key]
feel: make feel [
engage: func [face action event index][
either none? face/data [
face/data: event/offset
][
face/offset: circonfine face/offset + (event/offset - face/data) circle/offset circle/size
dragger/size
show face
]
if action = 'up [face/data: none]
]
]
]
fence: make face [
offset: 0x0
size: 300x300
color: 50.100.150
pane: [circle dragger]
]
view fence