'##############################################################################
'##############################################################################
'Begin ToggleGadget. bas

declare function AddToggleGadget (event as EventHandle ptr,x as integer,y as integer,w as integer,h as integer,s as integer,txt as string,txta as string="") as Gadget ptr

declare function ToGHit(hitgad as Gadget ptr,junk as Gadget ptr) as integer
declare function ToGHold(hitgad as Gadget ptr,holdgad as Gadget ptr) as integer
declare function ToGRelease(hitgad as Gadget ptr,relgad as Gadget ptr) as integer

declare sub DrawToggleGadget (gad as Gadget ptr)

function AddToggleGadget (event as EventHandle ptr,x as integer,y as integer,w as integer,h as integer,s as integer,txt as string,txta as string="") as Gadget ptr
  if txta="" then txta=txt
  dim as Gadget ptr tmpgad

  function=0
  tmpgad=new Gadget
  if tmpgad then
    tmpgad->nextGadget=0
  	tmpgad->sel=s
    tmpgad->act=0
    tmpgad->posx=x
    tmpgad->posy=y
    tmpgad->gadw=w
    tmpgad->gadh=h
    tmpgad->text=txt
    tmpgad->textalt=txta
    
    tmpgad->event=event
    
    tmpgad->DoDraw     =@DrawToggleGadget
    tmpgad->DoHit      =@ToGHit
    tmpgad->DoHold     =@ToGHold
    tmpgad->DoRelease  =@ToGRelease
    tmpgad->DoKeyStream=0

		SaveBackGround(tmpgad)
    event->ChainGadget (tmpgad)
    function=tmpgad
  end if
end function



function ToGHit(hitgad as Gadget ptr,junk as Gadget ptr) as integer
  function=0
end function



function ToGHold(hitgad as Gadget ptr,holdgad as Gadget ptr) as integer
  function=0
end function



function ToGRelease(hitgad as Gadget ptr,relgad as Gadget ptr) as integer
  function=0
  if hitgad=relgad then
    if GetSelect(hitgad)=1 then SetSelect(hitgad,0) else SetSelect(hitgad,1)
    function=-1
  end if
end function



sub DrawToggleGadget (gad as Gadget ptr)
	dim as integer x,y,w,h
  x   =gad->posx
	y   =gad->posy
	w		=gad->gadw
	h		=gad->gadh

  screenlock
  if gad->act=0 then put(x,y),gad->BackGroundImage,pset

  if gad->act=1 then
    FrameB x, y, w, h,gad->sel
    FillA x+1,y+1,w-2,h-2,GadgetColor,gad->sel
    if gad->sel then
      draw string ( x+(w-len(gad->textalt)*8)/2 +1, y+(h-fontheight)/2 ),gad->textalt,GadgetTextColor
			draw string ( x+(w-len(gad->textalt)*8)/2 , y+(h-fontheight)/2 ),gad->textalt,GadgetTextColor
    else
      draw string ( x+(w-len(gad->text)*8)/2 , y+(h-fontheight)/2 ),gad->text,GadgetTextColor
    end if
  end if

  if gad->act=2 then
    FrameB x, y, w, h,gad->sel
    FillA x+1,y+1,w-2,h-2,BackGroundColor,gad->sel
    if gad->sel then
      draw string ( x+(w-len(gad->textalt)*8)/2 +1, y+(h-fontheight)/2),gad->textalt,ShiftRGB(BackGroundColor,-contrast\2)
      draw string ( x+(w-len(gad->textalt)*8)/2 , y+(h-fontheight)/2),gad->textalt,ShiftRGB(BackGroundColor,-contrast\2)
    else
      draw string ( x+(w-len(gad->text)*8)/2 , y+(h-fontheight)/2 ),gad->text,ShiftRGB(BackGroundColor,-contrast\2)
    end if
  end if
  screenunlock
end sub
'End ToggleGadget.bas
'##############################################################################
'##############################################################################
