TGC Codebase Backup



Function for button by Atreides

27th Oct 2003 11:57
Summary

It draws the button and give back a result of one if the player click on it.



Description

This code makes a button (but I think you already know it). I tried to make it as much as possible like a windows' button, but I think you'll see what it does when you'll test it.
What can I say about this button ? Nothing more, it's just a button ;)



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    function button(x as integer,y as integer,txt as string,r as float,g as float,b as float)
   ` code made by Atreides (I don't mind if you don't add me to your credits ^^)
   ` X ans Y are the center of the button
   ` txt is the text of the button
   ` r, g and b is the color of the button
   mob as boolean
   if mousex()>x-text width(txt)/2-6 and mousex()<x+text width(txt)/2+6
      if mousey()>y-text height(txt)/2-2 and mousey()<y+text height(txt)/2+2
         if mouseclick()=1 then mob=1
      endif
   endif
   if mob=0
      ink rgb(r*0.7,g*0.7,b*0.7),0
      box x-text width(txt)/2-6,y-text height(txt)/2-2,x+text width(txt)/2+6,y+text height(txt)/2+4
      ink rgb(r,g,b),0
      box x-text width(txt)/2-3,y-text height(txt)/2,x+text width(txt)/2+3,y+text height(txt)/2+2
      if (r+g+b)/3>=128
         ink rgb(0,0,0),0
      else
         ink rgb(255,255,255),0
      endif
      text x-text width(txt)/2,y-text height(txt)/2,txt
   else
      repeat
         ink rgb(r,g,b),0
         box x-text width(txt)/2-6,y-text height(txt)/2-2,x+text width(txt)/2+6,y+text height(txt)/2+4
         ink rgb(r*0.7,g*0.7,b*0.7),0
         box x-text width(txt)/2-3,y-text height(txt)/2,x+text width(txt)/2+3,y+text height(txt)/2+2
         if (r*0.7+g*0.7+b*0.7)/3>=128
            ink rgb(0,0,0),0
         else
            ink rgb(255,255,255),0
         endif
         text x-text width(txt)/2,y-text height(txt)/2,txt
         sync
      until mouseclick()=0
      if mousex()>x-text width(txt)/2-6 and mousex()<x+text width(txt)/2+6 and mousey()>y-text height(txt)/2-2 and mousey()<y+text height(txt)/2+2
         if mouseclick()=1 then mob=1
      else
         mob = 0
      endif
   endif
   ink rgb(255,255,255),0
endfunction mob