icon.library: Implement LayoutIconA()
[AROS.git] / workbench / libs / icon / layouticon.c
blob935ae8d065191479bc286cc8f93c0952ef5e19f1
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/debug.h>
8 #include <exec/types.h>
9 #include <workbench/icon.h>
10 #include <utility/tagitem.h>
11 #include <proto/icon.h>
13 #include "icon_intern.h"
15 /*****************************************************************************
17 NAME */
19 AROS_LH3(BOOL, LayoutIconA,
21 /* SYNOPSIS */
22 AROS_LHA(struct DiskObject *, icon, A0),
23 AROS_LHA(struct Screen *, screen, A1),
24 AROS_LHA(struct TagItem *, tags, A2),
26 /* LOCATION */
27 struct IconBase *, IconBase, 32, Icon)
29 /* FUNCTION
30 Adapt a palette-mapped icon for display.
32 INPUTS
34 RESULT
36 NOTES
37 Not implemented.
39 EXAMPLE
41 BUGS
43 SEE ALSO
45 INTERNALS
47 *****************************************************************************/
49 AROS_LIBFUNC_INIT
51 struct NativeIcon *nativeicon;
52 struct RastPort rp;
53 struct DrawInfo *dri;
54 BOOL ret;
55 ULONG sizex = 0, sizey = 0;
56 const ULONG bflags = BMF_CLEAR | BMF_DISPLAYABLE | BMF_MINPLANES | BMF_INTERLEAVED;
58 nativeicon = GetNativeIcon(icon, LB(IconBase));
59 if (!nativeicon)
60 return TRUE;
62 /* Already mapped to this screen?
64 if (screen == nativeicon->iconscr)
65 return TRUE;
67 if (nativeicon->iconbm1) {
68 FreeBitMap(nativeicon->iconbm1);
69 nativeicon->iconbm1 = NULL;
71 if (nativeicon->iconbm2) {
72 FreeBitMap(nativeicon->iconbm2);
73 nativeicon->iconbm2 = NULL;
75 nativeicon->iconscr = NULL;
77 if (screen == NULL)
78 screen = GetDefaultPubScreen(NULL);
80 dri = GetScreenDrawInfo(screen);
81 if (dri == NULL)
82 return FALSE;
84 ret = FALSE;
86 /* Get the sizex and sizey */
87 IconControl(icon, ICONCTRLA_GetWidth, (IPTR)&sizex,
88 ICONCTRLA_GetHeight, (IPTR)&sizey,
89 TAG_DONE);
91 D(bug("%s: Screen %p, Depth %d\n", __func__, screen, dri->dri_Depth));
92 nativeicon->iconbm1 = AllocBitMap(sizex, sizey, dri->dri_Depth, bflags, screen->RastPort.BitMap);
93 if (nativeicon->iconbm1) {
94 nativeicon->iconbm2 = AllocBitMap(sizex, sizey, dri->dri_Depth, bflags, screen->RastPort.BitMap);
95 if (nativeicon->iconbm2) {
97 /* Draw the normal state */
98 InitRastPort(&rp);
99 rp.BitMap = nativeicon->iconbm1;
100 DrawIconStateA(&rp, icon, NULL, 0, 0, IDS_NORMAL, tags);
102 /* Draw the selected state */
103 InitRastPort(&rp);
104 rp.BitMap = nativeicon->iconbm2;
105 DrawIconStateA(&rp, icon, NULL, 0, 0, IDS_SELECTED, tags);
107 nativeicon->iconscr = screen;
109 ret = TRUE;
110 } else {
111 FreeBitMap(nativeicon->iconbm1);
112 nativeicon->iconbm1 = NULL;
116 FreeScreenDrawInfo(screen, dri);
118 return ret;
120 AROS_LIBFUNC_EXIT
121 } /* LayoutIconA() */