'##############################################################################
'##############################################################################
'Begin CheckmarkGadget.bas
declare function AddCheckmarkGadget (event as EventHandle ptr,x as integer,y as integer,s as integer,txt as string="") as Gadget ptr

declare function CmGHit(hitgad as Gadget ptr,junk as Gadget ptr) as integer
declare function CmGHold(hitgad as Gadget ptr,holdgad as Gadget ptr) as integer
declare function CmGRelease(hitgad as Gadget ptr,relgad as Gadget ptr) as integer

declare sub DrawCheckmarkGadget (gad as Gadget ptr)

function AddCheckmarkGadget (event as EventHandle ptr,x as integer,y as integer,s 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=s
    tmpgad->act=0
    tmpgad->posx=x
    tmpgad->posy=y
    if txt="" then
      tmpgad->gadw=16
    else
      tmpgad->gadw=20 + len(txt)*8
    end if
    if fontheight=8 then
      tmpgad->gadh=12
    else
      tmpgad->gadh=fontheight
    end if
    tmpgad->text=txt

    tmpgad->event=event

    tmpgad->DoDraw     =@DrawCheckmarkGadget
    tmpgad->DoHit      =@CmGHit
    tmpgad->DoHold     =@CmGHold
    tmpgad->DoRelease  =@CmGRelease
    tmpgad->DoKeyStream=0
		
		SaveBackGround(tmpgad)
    event->ChainGadget (tmpgad)
    function=tmpgad
  end if
end function



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



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



function CmGRelease(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 DrawCheckmarkGadget (gad as gadget ptr)
	dim as integer x,y,w,h,txtv,boxv
  x   =gad->posx
	y   =gad->posy
	w		=gad->gadw
	h		=gad->gadh
  txtv=(h-fontheight)\2
  boxv=(h-12)\2

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

  if gad->act=1 then
    FillB x+boxv,y+boxv,12,12,GadgetColor,gad->sel
    if gad->sel then Tick (x+boxv+2,y+boxv+2,GadgetTextColor)
    draw string (x+20,y+txtv),gad->text,TextColor
  end if

  if gad->act=2 then
    FillB x+boxv,y+boxv,12,12,BackGroundColor,0
    if gad->sel then Tick (x+boxv+2,y+boxv+2,ShiftRGB(BackGroundColor,-contrast\2))
    draw string (x+20,y+txtv),gad->text,ShiftRGB(BackGroundColor,-contrast\2)
  end if
  screenunlock
end sub
'End CheckmarkGadget.bas
'##############################################################################
'##############################################################################
