1. Usemaps
Bonn wrote:
> How do I assign a part of a bitmap to a routine? (sorta like Usemaps
> in HTML) like:
>
> x = rect(240, 383, 373, 230)
> y = rect(220, 363, 353, 210)
Here's a simple (untested) example:
sequence buttons
buttons = {}
procedure xPushed()
position( 1, 1 )
puts( 1, "X was pushed!" )
end procedure
procedure yPushed()
position( 1, 1 )
puts( 1, "Y was pushed!" )
end procedure
buttons = append( 240, 383, 373, 230, routine_id("xPushed") )
buttons = append( 220, 363, 353, 210, routine_id("yPushed") )
constant
MouseEvent = 1
MouseX = 2,
MouseY = 3,
X1 = 1,
Y1 = 2,
X2 = 3,
Y2 = 4,
Code = 5
object mouse
-- loop forever, watching for mouse clicks
while 1 do
-- check the mouse
mouse = get_mouse()
-- mouse event?
if sequence( mouse ) do
-- left click?
if and_bits( mouse[MouseEvent], LEFT_DOWN ) then
-- check each "button"
for i = 1 to length( buttons ) do
-- inside a "button"?
if mouse[MouseX] >= buttons[i][X1]
and mouse[MouseY] >= buttons[i][Y1]
and mouse[MouseX] <= buttons[i][X2]
and mouse[MouseY] >= buttons[i][Y2] then
-- run the code
call_proc( buttons[i][Code], {} )
-- exit loop
exit
end if
end for
end if
end if
end while
If you wanted to include the *whole* bitmap, you could include create a
helper routine like this to make your life easier:
procedure addButton( integer x, integer y, sequence bitmap, integer
id )
integer x2, y2
-- calculate size
x2 = x + length( bitmap[1] )
y2 = y + length( bitmap )
-- add to buttons
buttons = append( buttons, { x, y, x2, y2, id } )
end procedure
You could call it like this:
addButton( 10, 20, bitmap1, routine_id( "bitmap1Pressed" ) )
The routine_id() in the function is a bit awkward, but necessary for the
moment.
Hope this helps.
-- David Cuny