Hi,
I wrote this snippet just for this special ocasion
There are two versions. Second is a bit more advanced.
Just copy and paste into your OPL Editor
Edo
Code:
REM Code snippet gBUTTON
REM 19.09.05 ŠEdo
REM With slight changes it can be used to start your apps, docs, macros etc...
REM Insert your commands in the procedure Button_exec:
REM You can also change the no. of buttons per line, no. of rows, buttonheight,border size...
REM Take care to adjust the Caption$(%,%) variable in Main: procedure
BUSY "Press ESC to close",0
DO
GETEVENT32 Ev&()
IF Ev&(KEvAType%)=KEvPtr&
Pointer:(Ev&(KEvAPtrWindowId%),Ev&(KEvAPtrPositionX%),Ev&(KEvAPtrPositionY%))
REM Break here if you want to close after the button is pressed!
REM BREAK
ENDIF
UNTIL Ev&(KEvAType%)=kKeyEsc%
gCLOSE Win%
ENDP
PROC Draw_buttons:
LOCAL i%, row%, pos%
gFONT Font&
gUSE Win%
gVISIBLE OFF
DO
DO
gAT buttonwidth%*i%, pos% : gBUTTON Caption$(row%*buttons_per_row%+i%+1), 2, buttonwidth%, buttonheight%, 0
i%=i%+1
UNTIL i%=buttons_per_row%
i%=0
row%=row%+1
pos%=pos%+buttonheight%
UNTIL row%=rows%
gVISIBLE ON
ENDP
PROC Pointer:(win&,posX&,posY&)
LOCAL but%,row%
IF win&=Win%
but%=INT(posX&/buttonwidth%)
row%=INT(posY&/buttonheight%)
Button_exec:(but%, row%)
ENDIF
ENDP
PROC Button_exec:(but%, row%)
LOCAL Ev&(16)
Button_press:(but%, row%,1)
DO
GETEVENT32 Ev&()
IF ev&(KEvAType%)=KEvPtr&
IF ev&(KEvAPtrType%)=KEvPtrPenUp&
Button_press:(but%, row%,0)
IF INT(Ev&(KEvAPtrPositionX%)/(buttonwidth%)) = but% AND INT(Ev&(KEvAPtrPositionY%)/(buttonheight%)) = row%
REM Remove this line
ALERT("Button"+NUM$(row%*buttons_per_row%+but%+1,3)+" pressed","Replace with your command")
REM And insert your commands here...
REM VECTOR (row%*buttons_per_row%+but%+1)
REM Button1, Button2, Button3 REM etc... until all buttons used
REM ENDV
REM Button1:: : ALERT("Command1") : BREAK
REM Button2:: : ALERT("Command2") : BREAK
REM Button3:: : ALERT("Command3") : BREAK
REM etc... until all buttons used
REM Or you can do commands like this
REM IF (row%*buttons_per_row%+but%+1) = 1
REM ALERT("Command1")
REM ELSEIF (row%*buttons_per_row%+but%+1) = 2
REM ALERT("Command2")
REM ENDIF
REM Code snippet gBUTTON_advanced
REM 19.09.05 ŠEdo
REM Advanced code - just play and change CONST values to whatever you like ;)
REM With slight changes it can be used to start your apps, docs, macros etc...
REM Insert your commands in the procedure Button_exec:
REM You can also change the no. of buttons per line, no. of rows, buttonheight,border size...
CONST buttonheight%=30
CONST LRborder%=200 REM border on left and right / 2
CONST buttons_per_row%=4
CONST rows%=8
INCLUDE "const.oph"
PROC Main:
GLOBAL Captionlist&, buttonwidth%,Win%, Font&
LOCAL Ev&(16), i%, startpos%, Buf&, text$(255)
REM buttons at the bottom of screen
REM startpos% = gHEIGHT - (buttonheight% * rows%)
REM buttons on top of screen
REM startpos%=0
REM buttons in the middle of screen
startpos% = (gHEIGHT - buttonheight% * rows%)/2
REM Let's fill the button captions
DO
i%=i%+1
IF Captionlist&=0
Captionlist&=ALLOC(256)
ELSEIF 4*i%>=LENALLOC(Captionlist&)
Buf&=REALLOC(Captionlist&,LENALLOC(Captionlist&)+256)
IF Buf&=0
RAISE $FFF6
ENDIF
Captionlist&=Buf&
ENDIF
REM Place your caption text here...
text$="Button"+NUM$(i%,3)
Buf&=ALLOC(LEN(text$)+1)
POKEL Captionlist&+4*(i%-1),Buf&
POKE$ Buf&, text$
UNTIL i%=rows%*buttons_per_row%
BUSY "Press ESC to close",0
DO
GETEVENT32 Ev&()
IF Ev&(KEvAType%)=KEvPtr&
Pointer:(Ev&(KEvAPtrWindowId%),Ev&(KEvAPtrPositionX%),Ev&(KEvAPtrPositionY%))
ENDIF
UNTIL Ev&(KEvAType%)=kKeyEsc%
gCLOSE Win%
i%=rows%*buttons_per_row%
WHILE i%>0
i%=i%-1
FREEALLOC PEEKL(Captionlist&+4*i%)
ENDWH
FREEALLOC Captionlist&
ENDP
PROC Draw_buttons:
LOCAL i%, row%, pos%
gFONT Font&
gUSE Win%
gVISIBLE OFF
DO
DO
gAT buttonwidth%*i%, pos% : gBUTTON PEEK$(PEEKL(Captionlist&+4*(row%*buttons_per_row%+i%+1)-4)), 2, buttonwidth%, buttonheight%, 0
i%=i%+1
UNTIL i%=buttons_per_row%
i%=0
row%=row%+1
pos%=pos%+buttonheight%
UNTIL row%=rows%
gVISIBLE ON
ENDP
PROC Pointer:(win&,posX&,posY&)
LOCAL but%,row%
IF win&=Win%
but%=INT(posX&/buttonwidth%)
row%=INT(posY&/buttonheight%)
Button_exec:(but%, row%)
ENDIF
ENDP
PROC Button_exec:(but%, row%)
LOCAL Ev&(16)
Button_press:(but%, row%,1)
DO
GETEVENT32 Ev&()
IF ev&(KEvAType%)=KEvPtr&
IF ev&(KEvAPtrType%)=KEvPtrPenUp&
Button_press:(but%, row%,0)
IF INT(Ev&(KEvAPtrPositionX%)/(buttonwidth%)) = but% AND INT(Ev&(KEvAPtrPositionY%)/(buttonheight%)) = row%
REM Remove this line
ALERT("Button"+NUM$(row%*buttons_per_row%+but%+1,3)+" pressed","Replace with your command")
REM And insert your commands here...
REM VECTOR row%*buttons_per_row%+but%+1
REM Button1, Button2, Button3 REM etc... until all buttons used
REM ENDV
REM Button1:: : ALERT("Command1") : BREAK
REM Button2:: : ALERT("Command2") : BREAK
REM Button3:: : ALERT("Command3") : BREAK
REM etc... until all buttons used
Very cool!
Tried it out and used it for running sounds (from a very funny Counterstrike-Talk )
But could you tell me, how to do more buttons (I need 30) on the simple code?
If I change one of the CONSTs it gives me an error and jumps to Caption$(i%) (you know, my programming is not that forwarded yet )
Many thanks, Edo!
Jonas
Last edited by Jonas on Thu Sep 22, 2005 4:18 pm; edited 1 time in total
Very cool!
Tried it out and used it for running sounds (from a very funny Counterstrike-Talk )
Many thanks, Edo!
Show us a screenshot, at least
BTW, you can place buttons on top or at the bottom and make only one row.
Also, you can assign commands for specific App when it is in foreground and use buttons to send command to it
Could you tell me, how to do more buttons (I need 30) on the simple code?
If I change one of the CONSTs it gives me an error and jumps to Caption$(i%) (you know, my programming is not that forwarded yet )
Could you tell me, how to do more buttons (I need 30) on the simple code?
If I change one of the CONSTs it gives me an error and jumps to Caption$(i%) (you know, my programming is not that forwarded yet )
Jonas
You obviously use 1st, simple code snippet
Have a look into REMmed line above the Caption$ variable.
It says that first value must be rows%*buttons_per_row% and second value is the length of the (longest) button caption.
So, if you want to set 30 buttons, Caption$ variable should be declared:
Caption$(30, 15) provided that your longest caption is 15 chars!
Edit: In second code snippet you can change all constants value to whatever you like.
You can set 100 buttons in 10 rows, for instance!
In both snippets you can change button size, position on the screen (top, bottom, middle) etc...
Just play with it
You obviously use 1st, simple code snippet
Have a look into REMmed line above the Caption$ variable.
It says that first value must be rows%*buttons_per_row% and second value is the length of the (longest) button caption.
So, if you want to set 30 buttons, Caption$ variable should be declared:
Caption$(30, 15) provided that your longest caption is 15 chars!
OK, got it
It seems you need to calculate with the Caption$ global. So I will give up OPL, since my Math grades are the second badest possible ("amateurish" )
You obviously use 1st, simple code snippet
Have a look into REMmed line above the Caption$ variable.
It says that first value must be rows%*buttons_per_row% and second value is the length of the (longest) button caption.
So, if you want to set 30 buttons, Caption$ variable should be declared:
Caption$(30, 15) provided that your longest caption is 15 chars!
OK, got it
It seems you need to calculate with the Caption$ global. So I will give up OPL, since my Math grades are the second badest possible ("amateurish" )
Nah, joke
Here is the screenshot of simple code used to produce 50 buttons on full nB screen.
Values are:
buttonheight% = 48
buttons_per_row% = 5
rows% = 10
Caption$(50,
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum