Alas, one last affirmation. After flicking through some threads and the source of your ViewGUI (which has helped loads, by the way, thanks), I think I've finally gotten my head round stuff. This is what I've come out with:
sync on
sync rate 0
global mx as integer = 0
global my as integer = 0
rem create function pointer array, and add first index (index 0)
global dim ptr( -1 ) as integer : array insert at bottom ptr(0)
add_ptr( get_ptr_drawbox() ) : #CONSTANT PTR_INDEX_DRAWBOX 1
add_ptr( get_ptr_swidth() ) : #CONSTANT PTR_INDEX_SWIDTH 2
add_ptr( get_ptr_sheight() ) : #CONSTANT PTR_INDEX_SHEIGHT 3
#CONSTANT MEM_X 0
#CONSTANT MEM_Y 4
#CONSTANT MEM_EVENT 8
#CONSTANT EVENT_MOUSEOVER 0
#CONSTANT EVENT_DRAW 4
global dim square( 10 ) as integer
for n = 1 to 10
temp = alloc zeroed( 12 )
square( n ) = temp
poke integer square( n ) + MEM_X, n * 64
poke integer square( n ) + MEM_Y, 4
poke integer square( n ) + MEM_EVENT + EVENT_DRAW, ptr( PTR_INDEX_DRAWBOX )
next n
do
mx = mousex()
my = mousey()
for n = 1 to 10
x = peek integer( square( n ) + MEM_X )
y = peek integer( square( n ) + MEM_Y )
poke integer square( n ) + MEM_EVENT + EVENT_MOUSEOVER, inarea( mx, my, x, y, x + 60, y + 64 )
next n
for n = 1 to 10
raiseevent( n, square( n ) + MEM_EVENT + EVENT_DRAW )
`call function ptr ptr( PTR_INDEX_DRAWBOX ), x - ( m * 2 ), y, x + 60 + ( m * 2 ), y + 64 + ( m * 8 )
next n
sync
cls 0
loop
function add_ptr( ptr as integer )
array insert at bottom ptr(0)
ptr( array count( ptr(0) ) ) = ptr
endfunction
function get_ptr_drawbox()
temp = get ptr to next function()
endfunction temp
function drawbox( index )
x = peek integer( square( index ) + MEM_X )
y = peek integer( square( index ) + MEM_Y )
m = peek integer( square( index ) + MEM_EVENT + EVENT_MOUSEOVER )
d3d_color 255, 255, 255, 128 + ( m * 127 )
d3d_box x - ( m * 2 ), y, x + 60 + ( m * 2 ), y + 64 + ( m * 8 )
endfunction
function get_ptr_swidth()
temp = get ptr to next function()
endfunction temp
function swidth()
temp = screen width()
endfunction temp
function get_ptr_sheight()
temp = get ptr to next function()
endfunction temp
function sheight()
temp = screen height()
endfunction temp
function inarea( tx, ty, x1, y1, x2, y2 )
if tx => x1 and tx =< x2
if ty => y1 and ty =< y2
exitfunction 1
endif
endif
endfunction 0
function raiseevent( index, offset )
if index > 0
ptr = peek integer( offset )
if function ptr is valid( ptr )
call function ptr ptr, index
endif
endif
endfunction
In a nutshell, the program gets the pointer of a couple of functions, sets up an array of squares, allocates memory for them, sets the draw event to point to the drawbox function, and then raises it to draw each box (they also change when you hover over them).
EDIT: Whey, some events. This tasty delight will get the mouse up/down/move events and visualises them a little (It waits 50 each loop so you can see the events pass).
sync on
sync rate 0
type event
active as boolean rem on/off event flag
sender as integer rem affected entity
endtype
global omx as integer
global omy as integer
global mx as integer : mx = mousex()
global my as integer : my = mousey()
global mmx as integer
global mmy as integer
global mc as integer
global mh as integer
global MOUSEDOWN as event
global MOUSEUP as event
global MOUSEMOVE as event
do
rem mouse data input
omx = mx
omy = my
mx = mousex()
my = mousey()
mmx = mx - omx
mmy = my - omy
mh = mc > 0
mc = mouseclick()
rem mouse event handling
MOUSEMOVE.ACTIVE = mmx <> 0 or mmy <> 0
if mc > 0
if mh = 0
MOUSEDOWN.ACTIVE = 1
MOUSEUP.ACTIVE = 0
else
MOUSEDOWN.ACTIVE = 0
MOUSEUP.ACTIVE = 0
endif
else
if mh > 0
MOUSEDOWN.ACTIVE = 0
MOUSEUP.ACTIVE = 1
else
MOUSEDOWN.ACTIVE = 0
MOUSEUP.ACTIVE = 0
endif
endif
rem statistic-o's
print "COORDS: ", mx, ", ", my
print "CLICK: ", mc
print "HELD: ", mh
print ""
print "MOUSEUP: ", MOUSEUP.ACTIVE
print "MOUSEDOWN: ", MOUSEDOWN.ACTIVE
print ""
print "MOUSEMOVE: ", MOUSEMOVE.ACTIVE
d3d_color 255 - ( MOUSEMOVE.ACTIVE * 255 ), MOUSEMOVE.ACTIVE * 255, 0, 223 + ( MOUSEMOVE.ACTIVE * 32 )
d3d_box 15, 201, 85, 204
d3d_color 255, 255, 255, 255
if MOUSEUP.ACTIVE then d3d_box 20, 180, 80, 200
if MOUSEDOWN.ACTIVE then d3d_box 20, 205, 80, 225
wait 50
sync
cls 0
loop
Thanks for the help, I'll look into getting this implemented in FUI.
COMING SOON: WIP updates.
Garghlebleurgh. Night.
EBA;
FUI; Mario Land Ripoff.
Every time you post a joke in the form of code, mace yourself.