;
; Example of NewIcons GT shape gadget! STANDARD ICON VERSION...
; (C) Robert Hutchinson 1999!
; Satanic Dreams Software 1999! [Loki^SD]
;
; Thanks to David McMinn for the GTShape example,.. TA!
; Feel free to use this example any way you like ;)
;
; Please email me with any bug reports or changes please:
;
;   loki@sds.in2home.co.uk
;
; Requirements:
;
;   o BlitzLibs:AmigaLibs.RES (Resident in the compiler menu)
;   o NewIconsBlitz installed correctly (see docs)
;   o The NIB_Single_Include.BB2 include (provided)
;   o newicon.library (V4 preferably!)
;

WbToScreen 0
WBenchToFront_

  ;--- A constant for the Icon number:
  ;
  #NIB_OurIcon=0

  ;--- Our include...
  ;
  XINCLUDE "/NIBIncludes/NIB_Include.BB2"

  ;###################################################################
  ;--- The following function is due to be added to the NIB Include:
  ;    Seen as though there are no docs for this function, I`ll
  ;    Explain, .. This function returns the number if the given
  ;    #Icon`s `Type'.. So that you can find I certain Image.. IE,
  ;    Say you wanted to find the mem location of Icon#: 5 `s selected
  ;    Image, you would use:
  ;
  ;       SelectedIMemLoc.l=*NIBImage(NIBFindImageNum{5,#NIB_SELECTED})
  ;
  ;    NIcon = Icon#
  ;
  ;    NType can be one of the following:
  ;           #NIB_NORMAL
  ;           #NIB_SELECTED

  ;--- Function returns a .Images number for an Icon#.
  ;
  Function.w NIBFindImageNum{NIcon,NType}
    Function Return ((NIcon*2)+NType)
  End Function
  ;####################################################################

  ;--- Check our libraries
  ;
  If NIBCheckLibs{}=False
    NPrint "Incorrect or non-present newicon.library/icon.library!"
    End
  EndIf

  ;--- Load files
  ;
  If NIBOpenIcon{#NIB_OurIcon,"YAM:YAM"}=False
    NPrint "Cant load file!"
    End
  EndIf

  ;--- Check the loaded data..
  ;
  imgs0.b=STDCheckStruct{#NIB_OurIcon}
  If imgs0=0
    NIBFreeIcon{#NIB_OurIcon}
    NPrint "No STD data!"
    End
  EndIf

  ;--- Setup the STD icon images
  ;
  STDToImages{#NIB_OurIcon}

  ;--- Find the dimensions...
  ;
  DefHeight1.w = STDFindHeight{#NIB_OurIcon}
  DefWidth1.w  = STDFindWidth{#NIB_OurIcon}

  ;--- Dummy shape...
  ;
  InitShape 0,DefWidth1,DefHeight1,*STDImage(NIBFindImageNum{#NIB_OurIcon,#NIB_NORMAL})\Depth

  ;--- Heres how we open a colour-fixed GTShape gadget!
  ;
  GTShape 0,0,0,0,0,0,0        ;Setup the gadget (Just a starting point)
  *OurGTS.Gadget=GTGadPtr(0,0) ;Get pointer to the shape gadget

  ;--- Store the original memory locations for the GTShape`s .Image
  ;    pointers. This is so we can replace them later on, when we
  ;    free things up :)
  ;
  NormMem.l = *OurGTS\GadgetRender
  SeleMem.l = *OurGTS\SelectRender

  ;--- Set our pointer to the images in the GTShape structure.
  ;
  *OurGTS\GadgetRender = *STDImage(NIBFindImageNum{#NIB_OurIcon,#NIB_NORMAL})
  *OurGTS\SelectRender = *STDImage(NIBFindImageNum{#NIB_OurIcon,#NIB_SELECTED})
  *OurGTS\LeftEdge     = 5
  *OurGTS\TopEdge      = 5
  *OurGTS\Width        = DefWidth1
  *OurGTS\Height       = DefHeight1

  ;--- Our window....
  ;
  Window 0,50,50,(DefWidth1+10),(DefHeight1+10),$1000,"",0,1
  DefaultOutput

  ;--- Attach our gadget...
  ;
  AttachGTList 0,0

  ;--- Wait for the gtshape to be hit
  ;
  Repeat
    EV.l=WaitEvent
    If EV=#IDCMP_GADGETUP
      If GadgetHit=0
        QuitFLG=1
      EndIf
    EndIf
  Until QuitFLG=1

  ;--- Cleanup and exit...
  ;
  DetachGTList 0

  ;--- Put the Original .Image pointers back, this is so that
  ;    Blitz can free its original .Images .
  ;
  *OurGTS\GadgetRender = NormMem.l
  *OurGTS\SelectRender = SeleMem.l

  Free GTList 0
  NIBFreeIcon{0}
  CloseWindow 0

End



