Simple image buttons
Posted: Sun Nov 11, 2007 6:20 pm
Have been trying to get some sort of image button to work. This is a very simple try that seems to work good. Maybe it could be expanded further. CodeArchive had some examples but they didn't work as as well.
Replace up.bmp and down.bmp with your own images:
Replace up.bmp and down.bmp with your own images:
Code: Select all
enumeration
#window
#imgbutton
#btn_up
#btn_down
endenumeration
openwindow(#window, 100, 100, 300, 300, "test")
creategadgetlist(windowid(#window))
loadimage(#btn_up, "up.bmp")
loadimage(#btn_down, "down.bmp")
imagegadget(#imgbutton, 10, 10, 100, 30, imageid(#btn_up))
disablegadget(#imgbutton, #true)
repeat
event = waitwindowevent()
win_width = windowwidth(#window)
win_height = windowheight(#window)
mouse_x = windowmousex(#window)
mouse_y = windowmousey(#window)
button_x = gadgetx(#imgbutton)
button_y = gadgetx(#imgbutton)
button_h = gadgetheight(#imgbutton)
button_w = gadgetwidth(#imgbutton)
select event
case #WM_LBUTTONDOWN
if mouse_x >= button_x and mouse_x <= button_x+button_w and mouse_y >= button_y and mouse_y <= button_y+button_h
setgadgetstate(#imgbutton, imageid(#btn_down))
endif
case #WM_LBUTTONUP
setgadgetstate(#imgbutton, imageid(#btn_up))
endselect
until event = #pb_event_closewindow
end