GlowIcons as ImageGadgets

AmigaOS specific forum
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Roxxler.

Hi,

now here an example how to use ImageGadgets with the newstyle GlowIcons comming
with OS3.5 and higher. So you need as minimum OS3.5 ! You can also use NewIcons,
this is depending on your preferences (see Prefs/Workbench where you can enable
the use of NewIcons or not).
There is only one change in the example: instead of using GetDiskObject(nameicon$) from
icon.library we use GetIconTagList(@nameicon$,taglist.l). This is one of the new
functions coming in the icon.library of OS3.5. Note that the new function needs
a pointer to the string with the name of the icon (without ".info"), not the string
itselfs. It is possible to control the function with a taglist (e.g. a name under the
icon or for drawing a border around the icon or override the preferences for icons
(Prefs/Workbench)). For that you can find further informations in the includes and
autodocs of OS3.5 or OS3.9. In the example we use no taglists.
All other is the same like the example i post already. So you need of course all the
procedures regarding ImageGadgets (see there).

To compile this example you need the fd-file "icon_lib.fd" from the NDK3.5 or NDK3.9
(NativeDevelopmentKit). You have to transform it with the PureBasic-Tool "FDConvertor"
and copy the converted file to "PureBasic:PureLibraries/AmigaOS/". Overwrite the already
existing file or move it to another place (don't rename it for backup and keep it in the
same dir ! The old one must be removed!) After that (re)start PureBasic and you can
compile it.

The NDK3.5 is e.g. found on the DeveloperCD2.1 from Haage&Partner.
The NDK3.9 you can download from http://www.amiga.com.

This because PureBasic comes with the includes and also libs from OS3.1. To use or for
easier use of available tags in taglists you can also convert the file "icon.h" found
in the dir "include/include.h/workbench" with the Tool "OpenPureBasic" and copy it to
the dir "PureBasic:PureInclude/Workbench". Note that "OpenPureBasic" will not convert
every file as "ready for use" ! Maybe you have to rework the output by yourself !
One Note regarding this: do this only for testing !! Don't mix OS3.1 includes/libs with
other versions. This can cause many troubles !!! You will be warned !!

Maybe there is someone of you who converts the complete libs and includes of OS3.5
and/or OS3.9 :)) Many work, perhaps i will do it in future if i have many time and
no other better things to do, which means it is rainy and my girlfriend is away and
i am not looking "ALIEN" part 1-4 and ... and ... :)))


Requirements: OS 3.5, NDK3.5, the ImageGadget procedures

And now a special thanx to Stephan Rupprecht, without his tip to use GlowIcons i were
still on the search for it. Sometimes i don't see the forest because there are so many
trees ....

NOTE: again a strange thing. If i compile the example program with the procedures
the first created executable crashes !! After compiling a second or more time it will
run without any probs. Note that the first executable is about 20 bytes bigger than
the second one. So just compile it twice. I have already informed Fred about this.
Let me know if the same happens on your machine.


WBStartup() ; you know
If InitGadget(1) And OpenIntuitionLibrary_(36) And OpenIconLibrary_(44) ; open needed libs, min v44=OS3.5 for the icon.library !!!!
If OpenWindow(0,20,20,400,150,#WFLG_DRAGBAR|#WFLG_CLOSEGADGET,"ImageGadget Example") ; open window
UseWindow(0) ; we use our window 0
ActivateWindow() ; what ???
If CreateGadgetList() ; for creating Gadtools (PureBasic) gadgets, if you only use
; Imagegadget you don't need this and the InitGadget()

icon1.l=GetIconTagList_(@"ram:test1",0) ; here ist the different ! For using GlowIcons we have to use
; GetIconTagList() instead of GetDiskObject() ! The is a new function
; available from v44(OS35) and higher. Note that this function
; needs a pointer to the name of the icon and not the name itself!
; Also we can control this function with a taglist (eg. for a text
; under the icon or draw a border around it, for further infos have
; a look to the autodocs where you can find all available tags).
; for this example we use no taglist, therefore the second parameter
; is 0.
; the first parameter is a pointer to the name of the icon, but without
; the ".info".
icon2.l=GetIconTagList_(@"ram:test2",0) ;the second icon we load
If icon1 And icon2
ImageGadget(0,icon1,30,30,0,0) ;we install imagegadget 0 at xpos 30 and ypos 10, no togglegadget
ImageGadget(1,icon2,30,80,-1,-1) ;imagegadget 1 at xpos 30,ypos 60, it is a togglegadget and it is selected

Else ;the icons are not loaded -> exit
EasyRequester("Error!","Cannot install ImageGadgets!","Exit")
If icon1
FreeDiskObject_(icon1)
EndIf
If icon2
FreeDiskObject_(icon1)
EndIf
End
EndIf

ButtonGadget(0,200,10,180,14,"PureBasic Gadget") ; we install a gadtools button gadget
ButtonGadget(1,200,30,180,14,"Disable ImageGadget") ; we install another to show how to disable the
; ImageGadgets
disable.b=0 ; just a flag so that we can switch the imagegadgets on and off

RefreshImageGadget(WindowID()) ; Now we refresh the installed gadgets to display them, works also for the
; PureBasicgadgets, so we don't need "RefreshGadget(-1)"

Repeat
Event.l = WaitWindowEvent()
If Event = #IDCMP_GADGETDOWN OR Event = #IDCMP_GADGETUP
EventGadget.l=EventGadgetID()
Select EventGadget
Case 0
EasyRequester("Info","You have clicked on the PureBasic Gadget","Correct")
Case 1
If disable=0 ; we use the flag, gadgets are on
DisableImageGadget(icon1,-1) ; so we can disable them
DisableImageGadget(icon2,-1)
disable=-1 ; set the flag that the gadget are off
Else ; the imagegadgets are already off
DisableImageGadget(icon1,0) ; so we switch them on
DisableImageGadget(icon2,0)
disable=0 ; set flag that the gadgets are on
EndIf
Case 65476
EasyRequester("Info","You have clicked on the ImageGadget 0","Correct")
Case 65477
EasyRequester("Info","You have clicked on the ImageGadget 1, which is a ToggleGadget","Correct")
EndSelect
Endif
Until Event = #IDCMP_CLOSEWINDOW
Else
EasyRequester("Error!","Cannot create Gadtool gadgets!","Exit")
EndIf
Else
EasyRequester("Error!","Cannot open window!","Exit")
Endif
Else
EasyRequester("Error!","Cannot initialize program!","Exit")
EndIf

; before the program ends we first have to free the gadgets and THEN to unload the
; icons, logical !!

FreeImageGadget(icon1) ; we free the first one
FreeImageGadget(icon2) ; the second one

; and now we free the loaded icons
FreeDiskObject_(icon1)
FreeDiskObject_(icon2)
; the icon and intuition.library is closed by PureBasic, we can do it, but it will be done
End


Greetings ..
Roxxler
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by plouf.

Very nice examples & procedures :)

the prog crashes with the fisrt exe (normaly ?? :wink:)




Christos
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Roxxler.
Very nice examples & procedures :)
the prog crashes with the fisrt exe (normaly ?? :wink:)

Christos
Hi

and thanx :) On my machine the first executable crashes.
If we know we can avoid this :))

Greetings ..
Roxxler
Post Reply