View+ Forum Index View+
Review http://mypsion.ru/viewplus.php
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   Join! (free) Join! (free)
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

gBUTTON code snippet

 
Post new topic   Reply to topic    View+ Forum Index -> ER5 OPL corner
View previous topic :: View next topic  
Author Message
Please Register and Login to this forum to stop seeing this advertsing.






Posted:     Post subject:

Back to top
Edo



Joined: 10 Aug 2005
Posts: 390


Location: Prismen - Vis

PostPosted: Thu Sep 22, 2005 12:12 pm    Post subject: Re: gBUTTON code snippet Reply with quote

Hi,
I wrote this snippet just for this special ocasion Wink
There are two versions. Second is a bit more advanced.
Just copy and paste into your OPL Editor Smile

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

CONST buttonheight%=40
CONST LRborder%=200
CONST buttons_per_row%=4
CONST rows%=5

INCLUDE "const.oph"

PROC Main:
   REM Caption$(rows% * buttons_per_row%, caption_length%)
   GLOBAL Caption$(20, 8), buttonwidth%,Win%, Font&
   LOCAL Ev&(16), i%, startpos%

   Font&=KFontArialNormal15&
   buttonwidth%=INT((gWIDTH - LRborder%) / buttons_per_row%)

   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

   DO
      i%=i%+1
      Caption$(i%)="Button"+NUM$(i%,2)
   UNTIL i%=rows%*buttons_per_row%

REM Or just like this
REM    Caption$(1)="Text1"
REM    Caption$(2)="Text2"
REM    Caption$(3)="Text3"
REM etc... until you fill all button captions

   gVISIBLE OFF
   Win%=gCREATE(LRborder%/2, startpos%,gWIDTH - LRborder%, buttonheight% * rows%,0, 1)
   Draw_buttons:

   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

               BREAK
            ELSE
               BREAK
            ENDIF
         ENDIF
      ENDIF
   UNTIL 0
ENDP

PROC Button_press:(but%, row%, style% )
   gUSE Win%
   gFONT Font&
   gAT (buttonwidth%*but%), buttonheight%*row% : gBUTTON Caption$(row%*buttons_per_row%+but%+1), 2, buttonwidth%, buttonheight%, style%
ENDP


And second version:

Code:

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)

   Font&=KFontArialNormal15&
   buttonwidth%=INT((gWIDTH - LRborder%) / buttons_per_row%)

   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%

   gVISIBLE OFF
   Win%=gCREATE(LRborder%/2, startpos%,gWIDTH - LRborder%, buttonheight% * rows%,0, 1)
   Draw_buttons:

   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

               BREAK
            ELSE
               BREAK
            ENDIF
         ENDIF
      ENDIF
   UNTIL 0
ENDP

PROC Button_press:(but%, row%, style% )
   gUSE Win%
   gFONT Font&
   gAT (buttonwidth%*but%), buttonheight%*row% : gBUTTON PEEK$(PEEKL(Captionlist&+4*(row%*buttons_per_row%+but%+1)-4)), 2, buttonwidth%, buttonheight%, style%
ENDP
 
Back to top
View user's profile Send private message Send e-mail
Jonas



Joined: 10 Aug 2005
Posts: 74


Location: Stuttgart, Germany

PostPosted: Thu Sep 22, 2005 3:56 pm    Post subject: Reply with quote

Very cool!
Tried it out and used it for running sounds (from a very funny Counterstrike-Talk Laughing )

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 Razz)

Many thanks, Edo!

Jonas


Last edited by Jonas on Thu Sep 22, 2005 4:18 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Edo



Joined: 10 Aug 2005
Posts: 390


Location: Prismen - Vis

PostPosted: Thu Sep 22, 2005 4:09 pm    Post subject: Reply with quote

Jonas wrote:
Very cool!
Tried it out and used it for running sounds (from a very funny Counterstrike-Talk Laughing )
Many thanks, Edo!


Show us a screenshot, at least Laughing

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 Cool

Edo
Back to top
View user's profile Send private message Send e-mail
Jonas



Joined: 10 Aug 2005
Posts: 74


Location: Stuttgart, Germany

PostPosted: Thu Sep 22, 2005 4:22 pm    Post subject: Reply with quote

Erm, why screenshot? (Only sounds)

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 Razz)

Jonas
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Edo



Joined: 10 Aug 2005
Posts: 390


Location: Prismen - Vis

PostPosted: Thu Sep 22, 2005 4:33 pm    Post subject: Reply with quote

Jonas wrote:
Erm, why screenshot? (Only sounds)

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 Razz)

Jonas


You obviously use 1st, simple code snippet Wink
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
Very Happy

Edo
Back to top
View user's profile Send private message Send e-mail
Jonas



Joined: 10 Aug 2005
Posts: 74


Location: Stuttgart, Germany

PostPosted: Thu Sep 22, 2005 4:49 pm    Post subject: Reply with quote

Edo wrote:
You obviously use 1st, simple code snippet Wink
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 Smile
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" Laughing )

Nah, joke Smile
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Edo



Joined: 10 Aug 2005
Posts: 390


Location: Prismen - Vis

PostPosted: Thu Sep 22, 2005 4:55 pm    Post subject: Reply with quote

Jonas wrote:
Edo wrote:
You obviously use 1st, simple code snippet Wink
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 Smile
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" Laughing )

Nah, joke Smile


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, Cool




Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    View+ Forum Index -> ER5 OPL corner All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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

Card File  Gallery  Forum Archive
Powered by phpBB © 2001, 2005 phpBB Group
Create your own free forum | Buy a domain to use with your forum
Free Web Counter