Restored from previous forum. Originally posted by Roxxler.
Hi,
here a procedure which draws an image from a given icon to the rastport of the
actual window. Just use UseWindow(winnumber) before calling the procedure to
draw the image into the window you want. The procedure uses the intuition
function DrawImage() for this. The icon must be loaded via icon.library, of
course. So the intuition.library and the icon.library must be open for that.
Procedure.l DrawIconImage(icon.l,xpos.w,ypos.w,selected.b)
; parameter: icon.l = pointer to a DiskObject structure
; xpos.w + ypos.w = the position where to draw
; selected.b = FALSE (0) =draw the normal image
; TRUE (0) =draw the selected image (if available)
If icon0
gadget.l=icon+4 ; gadget struct. at offset 4 of diskobject struct.
If selected And PeekL(gadget+22) ; draw the second image -> check if the second image is available
image.l=PeekL(gadget+22) ; pointer to the selected image (offset 22 of gadget struct.)
Else
image.l=PeekL(gadget+18) ; pointer to the normal image (offset 18 of gadget struct.)
EndIf
DrawImage_(WindowRastPort(),image,xpos,ypos) ; draw the image to the rastport of the actual window
ProcedureReturn -1 ; return MyTRUE
EndIf
ProcedureReturn 0 ; return FALSE if there is no icon
EndProcedure
OpenIconLibrary_(36) ; use OpenIconLibrary_(44) if you want to use GlowIcons
; Have a look at 'Glowicons as ImageGadgets' i posted a few days
; before for some notes
OpenIntuitionLibrary_(36)
If OpenWindow(0, 10, 10, 300, 130, #WFLG_CLOSEGADGET|#WFLG_DEPTHGADGET|#WFLG_DRAGBAR, "DrawIconImage")
icon$="sys:Disk" ; the icon, hope you have one at this place
icon.l=GetDiskObject_(icon$) ; load the icon
; icon-l=GetIconTagList_(@icon$,0) ; use this instead the line before if you want to use a Glowicon
If icon
DrawIconImage(icon,20,20,0) ; draw the normal image of the icon
DrawIconImage(icon,150,20,-1) ; draw the selected image of the icon (if available, if not the normal one)
EndIf
Repeat
IDCMP.l = WaitWindowEvent()
Until IDCMP = #IDCMP_CLOSEWINDOW
If icon
FreeDiskObject_(icon) ; unload the icon
EndIf
EndIf
End
Greetings ..
Roxxler
Procedure DrawIconImage()
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Roxxler.
Jooh, little error. If you use Glowicons use the following line.
It must be 'icon.l' and not 'icon-l' :-\ My fault, sorry.
icon.l=GetIconTagList_(@icon$,0)
Works fine then and no crashes. Note that you need the icon lib from
OS35 or OS39 if you want to compile it. Just convert the icon_lib.fd
with the FDConvertor and copy it to the AmigaOS dir.
Greetings ..
Roxxler
Hi.its me or with glowicons it crashes ?
(p.s. i use offcourse icon.l= .... not icon-l= .. the compiler doesn;t undestand the wrong )
Christos
Jooh, little error. If you use Glowicons use the following line.
It must be 'icon.l' and not 'icon-l' :-\ My fault, sorry.
icon.l=GetIconTagList_(@icon$,0)
Works fine then and no crashes. Note that you need the icon lib from
OS35 or OS39 if you want to compile it. Just convert the icon_lib.fd
with the FDConvertor and copy it to the AmigaOS dir.
Greetings ..
Roxxler