[REBOL] Re: Counter measures
From: carl:cybercraft at: 5-Sep-2002 23:08
On 05-Sep-02, [SunandaDH--aol--com] wrote:
> I'm trying to create a little board game, mainly as a way of
> improving my VID/View skills.
> I can draw the board using a combination of the draw dialect and VID
> elements.
> But I'm stuck at drawing a *circular* counter that can be dragged
> and dropped anywhere on the board:
> -- If I wanted square counters I could use a layout [box 50x50]
> -- If I wanted a circular counter that doesn't move, I could use
> layout [draw box effect [[circle 10x10 30x30]]]
> I thought of using radio buttons. But they are fixed-sized images in
> a *square* box. I want the counters to be user-resizable and
> user-colorable.
> And ideas about how I can render a movable circular counter on the
> sample layout below would be greatly received.
> rebol []
> Board-elements: Stylize [
> black-square: box 100.100.100 50x50
> white-square: box white 50x50
> die: box 30x30 "6"
> ]
> unview/all
> view layout [
> styles board-elements
> space 0x0
> across
> black-square
> white-square
> black-square
> return
> white-square
> black-square
> white-square
> return
> black-square
> white-square
> black-square
> return
> die blue
> die red
> ]
Try this...
rebol []
; This function just makes an image from a layout...
make-die: func [color [tuple!] /local image][
layout [
image: box 30x30 effect [draw [
pen none
fill-pen color none
circle 14x14 15
]]
]
to-image image
]
Board-elements: Stylize [
black-square: box 100.100.100 50x50
white-square: box white 50x50
; 'die is now an image - note the 'key effect used
; to make the black in the image transparent.
die: image make-die red effect [key 0.0.0]
]
unview/all
view layout [
styles board-elements
space 0x0
across
black-square
white-square
black-square
return
white-square
black-square
white-square
return
black-square
white-square
black-square
return
; The 'feels here are just a copy of the drag & drop
; example from the 'feel how-to example on the REBOL
; site. Your dice can now be picked up and moved...
d1: die feel [engage: func [face action event] [
if action = 'down [start: event/offset]
if find [over away] action [
face/offset: face/offset + event/offset - start
show face
]
]]
d2: die feel [engage: func [face action event] [
if action = 'down [start: event/offset]
if find [over away] action [
face/offset: face/offset + event/offset - start
show face
]
]]
; Set original colors...
do [
d1/image: make-die red
d2/image: make-die blue
]
; Button for user-defined color. (;
button "Change" [
d1/image: make-die random 255.255.255
show d1
]
]
--
Carl Read