EDIT: SORRY! I found the bug! I copied and pasted BSize and forgot to replace it with "ind", nowonder... I was after spelling issues heh. I'll leave the code for anyone who wants it, but I'll be posting the full working version up later anyway, seems like something useful.
I'm rewriting a GUI for buttons 'cause I don't like sprites... anyway after trying to load 3 at a time I get an error. Search for "buggy" to get to the bug itself.
rem button header file, functions without sprites
sync on
sync rate 45
remstart
TYPE simpleButton
x as int
y as int
width as int
height as int
rem filename is for the image, if used, for the button
filename as string
rem buttonname is a value in case you want to test strings instead of
rem array indexes.
buttonname as string
rem I'm not using ButtonText but have it in here so you can make simpler
rem ones later.
rem buttontext as string
endtype
remend
rem setting transparent color to white
set image colorkey 255,255,255
global BSize as integer
BSize = 100
rem since this is meant to be used added on to your program
rem you can make it use any starting value for image numbers
rem so it doesn't get in the way of your own image numbers
rem also, needed to index 3 different starting points due to highlighted button
rem images. If you create more than 999 buttons, remember to change
rem these numbers so not to overlap
global ImageNumStartValue as integer
ImageNumStartValue = 3000
global ImageNumStartValueH as integer
ImageNumStartValueH = 4000
global ImageNumStartValueC as integer
ImageNumStartValueC = 5000
rem set this to 0 to turn it off, but it does so for every button lest you edit
rem the BDisplay() command.
global transparencyOn as integer
transparencyOn = 1
rem the following is because UDT's don't work
rem x y width height, self explanatory
rem active is whether the button shows or not
rem FileName is the image's name string
rem ButtonName is the internal reference, you can leave blank
rem or use for complex systems of buttons later
rem HighFileName is for when the button is highlighted
rem ClickedFileName is for when the button is clicked
rem SButtonHighlighted is whether or not the button is highlighted
rem SButtonClicked is the same for clicked
global dim SButton(BSize) as integer
global dim SButtonX(BSize) as integer
global dim SButtonY(BSize) as integer
global dim SButtonWidth(BSize) as integer
global dim SButtonHeight(BSize) as integer
global dim SButtonHighlighted(BSize) as integer
global dim SButtonClicked(BSize) as integer
global dim SButtonActive(BSize) as integer
global dim SButtonSimpleFileName(BSize) as string
global dim SButtonHighFileName(BSize) as string
global dim SButtonClickedFileName(BSize) as string
global dim SButtonName(BSize) as string
BMakeButtonBox(1, "h", 0, 200, 300,24, 1)
BMakeButtonPictureBox(2, "but", "but.bmp", "buthigh.bmp", "butclick.bmp", 30, 250,120,60, 0)
do
cls
`if spacekey()
` if SButtonActive(1) = 1 then BDestroyButton(1)
`endif
BDisplay()
sync
loop
rem this function takes any active buttons and displays them onscreen
rem transparency is set on for paste image initially
function BDisplay()
for countB = 1 to BSize
if SButtonActive(countB) > 0
SButtonClicked(countB) = 0
SButtonHighlighted(countB) = 0
if Mousex() > SButtonX(countB) AND MouseX() < SButtonX(countB) + SButtonWidth(countB) AND MouseY() > SButtonY(countB) AND MouseY() < SButtonY(countB) + SButtonHeight(countB) then SButtonHighlighted(countB) = 1
if MouseClick() > 0
if Mousex() > SButtonX(countB) AND MouseX() < SButtonX(countB) + SButtonWidth(countB) AND MouseY() > SButtonY(countB) AND MouseY() < SButtonY(countB) + SButtonHeight(countB) then SButtonClicked(countB) = 1
endif
if LEN( SButtonSimpleFileName(countB)) < 4
Box SButtonX(countB), SButtonY(countB), SButtonX(countB) + SButtonWidth(countB), SButtonY(countB) + SButtonHeight(countB)
else
rem remember to add AND IF CLICKED <> 0
paste image ImageNumStartValue + countB, SButtonX(countB), SButtonY(countB), transparencyOn
if SButtonHighlighted(countB) > 0 then paste image ImageNumStartValueH + countB, SButtonX(countB), SButtonY(countB), transparencyOn
if SButtonClicked(countB) = 1 then paste image ImageNumStartValueC + countB, SButtonX(countB), SButtonY(countB), transparencyOn
endif
endif
next countB
endfunction
rem BMakeButtonBox takes the indexed array, places it,
rem and if centered is 0 it does not center the box, otherwise
rem nomatter what x value, it will put it in the center
rem this function is for PICTURELESS buttons, for testing mostly
function BMakeButtonBox(ind, name$, x, y, width, height,centered)
if centered > 0 then x = BGetCenterX(width)
SButtonX(ind) = x
SButtonY(ind) = y
SButtonWidth(ind) = width
SButtonHeight(ind) = height
SButtonName(ind) = name$
SButtonActive(ind) = 1
endfunction
rem same as above, but with an image
function BMakeButtonPictureBox(ind, name$, picturefile$, highlighted$, clicked$, x, y, width, height,centered)
if centered > 0 then x = BGetCenterX(width)
SButtonX(ind) = x
SButtonY(ind) = y
SButtonWidth(ind) = width
SButtonHeight(ind) = height
SButtonName(ind) = name$
SButtonSimpleFileName(ind) = picturefile$
SButtonHighFileName(ind) = highlighted$
SButtonClickedFileName(ind) = clicked$
SButtonActive(ind) = 1
Load Image SButtonSimpleFileName(ind), ImageNumStartValue + ind
Load Image SButtonHighFileName(ind), ImageNumStartValueH + ind
Load Image SButtonClickedFileName(ind), ImageNumStartValueC + ind
endfunction
rem BGetCenterX returns the X value to place a button if you want the button
rem to be centered.
function BGetCenterX(buttonwidth)
CenterStartXPosition = Screen Width()/2 - buttonwidth/2
endfunction CenterStartXPosition
function BDestroyButton(ind)
SButtonActive(ind) = 0
endfunction
rem ***********************************************************************************************************************************************************************************
TO RUN! Create a bitmap called but.bmp (the easy way), and replace "buthigh.bmp" and "butclick.bmp" names with that, it can be any size.
I initially thought it was my large index, so I tried different numbers, didn't work... checked spelling a lot, that didn't do it either. Also I only had one image to load multiple times initially, so I created more images, but nope, it still crashed, wasn't rewriting that...
I'm posting here asking for a 2nd opinion, but if you guys are stumped too, I'll bug report it. The code works fine if you REM out the two buggy lines. But then it wouldn't be much of a GUI.
Thanks
Signed
------