'##############################################################################
'##############################################################################
'Begin SimpleGadget.bas

declare function AddSimpleGadget (event as EventHandle ptr,x as integer,y as integer,w as integer,h as integer,txt as string) as Gadget ptr

declare function SimpleGadgetHit(hitgad as Gadget ptr,junk as Gadget ptr) as integer
declare function SimpleGadgetHold(hitgad as Gadget ptr,holdgad as Gadget ptr) as integer
declare function SimpleGadgetRelease(hitgad as Gadget ptr,relgad as Gadget ptr) as integer

declare sub DrawSimpleGadget (gad as Gadget ptr)

function AddSimpleGadget (event as EventHandle ptr,x as integer,y as integer,w as integer,h as integer,txt as string) as Gadget ptr
  dim as Gadget ptr tmpgad
  function=0
  tmpgad=new Gadget
  if tmpgad then
    tmpgad->nextGadget=0
  	tmpgad->sel=0
    tmpgad->act=0
    tmpgad->posx=x
    tmpgad->posy=y
    tmpgad->gadw=w
    tmpgad->gadh=h
    tmpgad->text=txt

    tmpgad->event=event

    tmpgad->DoDraw     =@DrawSimpleGadget
    tmpgad->DoHit      =@SimpleGadgetHit
    tmpgad->DoHold     =@SimpleGadgetHold
    tmpgad->DoRelease  =@SimpleGadgetRelease
    tmpgad->DoKeyStream=0

		SaveBackGround(tmpgad)
    event->ChainGadget (tmpgad)

		function=tmpgad
  end if
end function



function SimpleGadgetHit(hitgad as Gadget ptr,junk as Gadget ptr) as integer
  SetSelect (hitgad,1)
  function=0
end function



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



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



sub DrawSimpleGadget (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
    draw string ( x+(w-len(gad->text)*8)/2 , y+(h-fontheight)/2 ),gad->text,GadgetTextColor
  end if

  if gad->act=2 then
      FrameB x, y, w, h,0
      FillA x+1,y+1,w-2,h-2,BackGroundColor,0
    draw string ( x+(w-len(gad->text)*8)/2 , y+(h-fontheight)/2 ),gad->text,ShiftRGB(BackGroundColor,-contrast\2)
  end if
  screenunlock
end sub

'End SimpleGadget.bas
'##############################################################################
'##############################################################################
