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 SimpleGadgetActions(refgad as Gadget ptr,action as integer) 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
  function=0
  dim as Gadget ptr tmpgad
  tmpgad=new Gadget
  if tmpgad then
    tmpgad->event=event
    tmpgad->nextGadget=0
  	tmpgad->sel=0
    tmpgad->act=0
    tmpgad->posx=x
    tmpgad->posy=y
    tmpgad->gadw=w
    tmpgad->gadh=h

    tmpgad->caption=txt

    tmpgad->DoDraw     =@DrawSimpleGadget
    tmpgad->DoAction   =@SimpleGadgetActions
    tmpgad->DoUpdate   =@DrawSimpleGadget

		SaveBackGround(tmpgad)
    event->ChainGadget (tmpgad)

		function=tmpgad
  end if
end function



function SimpleGadgetActions(refgad as Gadget ptr,action as integer) as integer
  function=0
  select case action
      
      case GADGET_HIT        'Control grad frisch gedrückt
        SetSelect (refgad,1)
      
      case GADGET_HOLD       'Control wird gehalten, Maus über dem Control
        SetSelect (refgad,1)
      
      case GADGET_HOLDOFF    'Control wird gehalten, Maus neben dem Control
        SetSelect (refgad,0)
      
      case GADGET_RELEASE    'Control regulär losgelassen
        SetSelect (refgad,0)
        function=1           'Ping!!!! Control meldet sich: bei mir ist was passiert!!!
      
      case GADGET_RELEASEOFF 'Control losgelassen, dabei ist Maus neben dem Control
        SetSelect (refgad,0)
  
  end select
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->Images(0),pset
  else
    FrameB x, y, w, h,1'gad->sel
    FillA x+1,y+1,w-2,h-2,GadgetColor,gad->sel
    draw string ( x+(w-len(gad->caption)*8)/2 , y+(h-fontheight)/2 ),gad->caption,GadgetTextColor
    if gad->act=2 then put(x,y),gad->Images(0),alpha,SleepShade
  end if
  screenunlock
end sub
