Challenge: 
Winner?: 
No
Code Snippet: 
Rem Created: 6/25/2006 5:27:40 PM

Rem ***** Main Source File *****
set display mode 1024,768,32
sync on

global cim
global csp

gosub _makebackground `creates the background for the program

gosub _defineTwindowVars `creates the variables for the tools window

gosub _makeTwindow `creates tools window

draw sprites first
cls
Do

   gosub _controlMenu

   gosub _controlTwindow

   sync
Loop

_controlTwindow:

   if mouseover(sprite x(tTopsprite),sprite y(tTopsprite),sprite x(tTopsprite)+sprite width(tTopsprite),sprite y(tTopsprite)+sprite height(tTopsprite))=1
      mxdif=mousex()-twinx
      mydif=mousey()-twiny
      while mouseclick()=1
         twinx=mousex()-mxdif
         twiny=mousey()-mydif
         for x=1 to tButN
            sprite tButton(x,4),tButton(x,1)+twinx+(tbackx/2),tButton(x,2)+twiny+tTopy,tButton(x,3)
         next x
         sprite tbacksprite,twinx,twiny+tTopy,tBin
         sprite tTopsprite,twinx,twiny,tTin
         sync
      endwhile
   endif

   for x=1 to tButN
   if mouseover(tButton(x,1)+twinx+(tbackx/2),tButton(x,2)+twiny+tTopy,tButton(x,1)+20+twinx+(tbackx/2),tButton(x,2)+20+twiny+tTopy)=1
      if tButton(x,3)=unselIM then tButton(x,3)=unsoverIM
      if tButton(x,3)=selIM then tButton(x,3)=soverIM
      if mouseclick()=1
         while mouseclick()=1:endwhile
         selectButton(x)
      endif
   else
      if tButton(x,3)=unsoverIM then tButton(x,3)=unselIM
      if tButton(x,3)=soverIM then tButton(x,3)=selIM
   endif

   sprite tButton(x,4),tButton(x,1)+twinx+(tbackx/2),tButton(x,2)+twiny+tTopy,tButton(x,3)
   next x

   sprite tbacksprite,twinx,twiny+tTopy,tBin
   sprite tTopsprite,twinx,twiny,tTin

return

_makeTwindow:

   `make the background for the tools window
   cls
   ink rgb(211,211,211),0
   Box 0,0,42+tbackx,((tButN/2)*20)+tbacky
   ebox((tbackx/2)+1,1,43,((tButN/2)*20)+1,rgb(0,0,0))
   ebox(0,-1,42+tbackx-1,((tButN/2)*20)+tbacky-1,rgb(0,0,0))
   get image tBin,0,0,42+tbackx,((tButN/2)*20)+tbacky,3
   sprite tbacksprite,twinx,twiny+tTopy,tBin

   `make the top "moving" bar for the tools window
   cls
   Box 0,0,42+tbackx,tTopy,rgb(211,211,211),rgb(100,100,100),rgb(211,211,211),rgb(100,100,100)
   ebox(0,0,42+tbackx-1,tTopy-1,rgb(0,0,0))
   get image tTin,0,0,42+tbackx,tTopy,3
   sprite tTopsprite,twinx,twiny,tTin

   `unselected button back
   cls
   Box 0,0,20,20,rgb(211,211,211),rgb(211,211,211),rgb(100,100,100),rgb(100,100,100)
   ebox(0,0,20,20,rgb(0,0,0))
   get image unselIM,0,0,20,20,3

   `selected button back
   cls
   Box 0,0,20,20,rgb(100,100,100),rgb(100,100,100),rgb(211,211,211),rgb(211,211,211)
   ebox(0,0,20,20,rgb(0,0,0))
   get image selIM,0,0,20,20,3

   `unselected over button back
   cls
   Box 0,0,20,20,RGB(255,187,168),RGB(255,187,168),RGB(200,40,0),RGB(200,40,0)
   ebox(0,0,20,20,rgb(0,0,0))
   get image unsoverIM,0,0,20,20,3

   `selected over button back
   cls
   Box 0,0,20,20,RGB(200,40,0),RGB(200,40,0),RGB(255,187,168),RGB(255,187,168)
   ebox(0,0,20,20,rgb(0,0,0))
   get image soverIM,0,0,20,20,3

   cb=0
   for x=1 to 2
      for y=1 to tButN/2
         inc cb,1
         tButton(cb,1)=((x-1)*20)+1 `calculate x pos of button
         tButton(cb,2)=((y-1)*20)+1 `calculate y pos of button
         tButton(cb,3)=unselIM `set background image to unselected
         tButton(cb,4)=nsn()
         sprite tButton(cb,4),((x-1)*20)+1,((y-1)*20)+1,unselIM `create the sprite
      next y
   next x

return

_defineTwindowVars:

global unselIM
global selIM
global unsoverIM
global soverIM
global tBin
global tTin

global tButN=20 `total number of tool buttons
global slct=0 `number of selected tool button
global twinx=100 `x position of tools window
global twiny=250 `y position of tools window
global tbacksprite `sprite number for tools window background
global tbackx=5 `x buffer for background of tools window (total, buf on either side is half)
global tbacky=5 `y buffer for background of tools window (on bottom)
global tTopsprite `sprite number for tools top moving bar
global tTopx=42+tbackx `width of the top "moving" bar on the tools window
global tTopy=10 `height of the top "moving" bar on the tools window
global Dim tButton(tButN,4) `(x,1)=x position,(x,2)=y position,(x,3)=image number for sprite

`for some reason DBP will not let global variables be defined using other variables OR functions as they themselves are defined
tbacksprite=nsn()
tTopsprite=nsn()

unselIM=nin()
selIM=nin()
unsoverIM=nin()
soverIM=nin()
tBin=nin()
tTin=nin()

return

_makebackground:

`make a solid neutral gray background
ink rgb(255/2,255/2,255/2),0
box 0,0,screen width(),screen height()

`create the main menu at the top and draw a border
box 0,0,screen width(),20,rgb(211,211,211),rgb(255/2,255/2,255/2),rgb(211,211,211),rgb(255/2,255/2,255/2)
ebox(0,0,screen width()-1,20,rgb(0,0,0))
set text font "arial"
set text size 14
text 0,2,"  New  Open  Save  Save as "

global backIM
global backSP
backIM=nin()
backSP=nsn()
get image backIM,0,0,screen width(),screen height(),3
sprite backSP,0,0,backIM

return

_controlMenu:

if mouseover(text width(" ")-1,2,text width("  New "),text height("New")+2)=1
ebox(text width(" ")-1,2,text width("  New "),text height("New")+2,rgb(0,0,0))
endif

if mouseover(text width("  New ")-1,2,text width("  New  Open "),text height("Open")+2)=1
ebox(text width("  New ")-1,2,text width("  New  Open "),text height("Open")+2,rgb(0,0,0))
endif

if mouseover(text width("  New  Open ")-1,2,text width("  New  Open  Save "),text height("Save")+2)=1
ebox(text width("  New  Open ")-1,2,text width("  New  Open  Save "),text height("Save")+2,rgb(0,0,0))
endif

if mouseover(text width("  New  Open Save  ")-1,2,text width("  New  Open  Save  Save as "),text height("Save as")+2)=1
ebox(text width("  New  Open Save  ")-1,2,text width("  New  Open  Save  Save as "),text height("Save as")+2,rgb(0,0,0))
endif

return

Function nin()
inc cim,1
endfunction cim

function nsn()
inc csp
endfunction csp

Function eBox(x1,y1,x2,y2,clr)
ink clr,0
line x1,y1,x1,y2
line x1,y2,x2,y2
line x2,y2,x2,y1
line x2,y1,x1,y1
endfunction

Function selectButton(b)
if tButton(b,3)=soverIM
tButton(b,3)=unsoverIM
slct=0
endif

if tButton(b,3)=unsoverIM
tButton(b,3)=soverIM
if slct>0
tButton(slct,3)=unselIM
endif
slct=b
endif

endfunction

Function mouseover(x1,y1,x2,y2)
   over=0
   if mousex()>=x1 and mousex()<=x2 and mousey()>=y1 and mousey()<=y2 then over=1
endfunction over