2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
6 #include <aros/debug.h>
7 #include <workbench/icon.h>
8 #include <intuition/imageclass.h>
10 #include "icon_intern.h"
12 /* Define this in order to simulate LUT screen on hi- and truecolor displays.
14 #define FORCE_LUT_ICONS */
16 /*****************************************************************************
19 #include <proto/icon.h>
21 AROS_LH7(void, DrawIconStateA
,
24 AROS_LHA(struct RastPort
*, rp
, A0
),
25 AROS_LHA(struct DiskObject
*, icon
, A1
),
26 AROS_LHA(STRPTR
, label
, A2
),
27 AROS_LHA(LONG
, leftEdge
, D0
),
28 AROS_LHA(LONG
, topEdge
, D1
),
29 AROS_LHA(ULONG
, state
, D2
),
30 AROS_LHA(struct TagItem
*, tags
, A3
),
33 struct IconBase
*, IconBase
, 27, Icon
)
36 Draw an icon like an image.
39 rp - rastport to draw into
43 topEdge - drawing position
44 state - drawing state, see intuition/imageclass.h
49 Only very limited implemented.
56 intuition/imageclass.h
62 *****************************************************************************/
65 LONG wDelta
,textTop
,textLeft
;
66 struct NativeIcon
*ni
;
67 struct Rectangle rect
= { };
68 struct DrawInfo
*DrawInfo
;
72 BOOL selected
= (state
== IDS_SELECTED
);
73 UWORD Pens
[NUMDRIPENS
];
77 /* No GfxBase? No RastPort? Then we can't draw anything. */
81 ni
= GetNativeIcon(icon
, LB(IconBase
));
83 Frameless
= GetTagData(ICONDRAWA_Frameless
, IconBase
->ib_Frameless
|| (ni
&& ni
->ni_Frameless
), tags
);
84 Borderless
= GetTagData(ICONDRAWA_Borderless
, FALSE
, tags
);
85 EraseBackground
= GetTagData(ICONDRAWA_EraseBackground
, !(IconBase
->ib_Frameless
|| (ni
&& ni
->ni_Frameless
)), tags
);
86 DrawInfo
= (struct DrawInfo
*)GetTagData(ICONDRAWA_DrawInfo
, (IPTR
)NULL
, tags
);
88 for (i
= 0; i
< NUMDRIPENS
; i
++) {
89 if (DrawInfo
&& DrawInfo
->dri_NumPens
> i
)
90 Pens
[i
] = DrawInfo
->dri_Pens
[i
];
92 Pens
[i
] = ni
->ni_Pens
[i
];
96 rect
= IconBase
->ib_EmbossRectangle
;
98 EraseBackground
= TRUE
;
112 if (ni
&& ni
->ni_Screen
) {
113 Width
= ni
->ni_Width
;
114 Height
= ni
->ni_Height
;
116 Width
= icon
->do_Gadget
.Width
;
117 Height
= icon
->do_Gadget
.Height
;
121 struct TextExtent extent
;
122 LONG txtlen
= strlen(label
);
124 if (txtlen
> IconBase
->ib_MaxNameLength
)
125 txtlen
= IconBase
->ib_MaxNameLength
;
127 wDelta
= Width
+ (rect
.MaxX
- rect
.MinX
);
128 textTop
= Height
+ (rect
.MaxY
- rect
.MinY
);
130 TextExtent(rp
, label
, txtlen
, &extent
);
132 /* wDelta will be the centering offset for the icon */
133 /* textLeft is the horiz offset for the text */
135 if (extent
.te_Width
> wDelta
) {
136 wDelta
= (extent
.te_Width
- wDelta
) / 2;
139 textLeft
= (wDelta
- extent
.te_Width
) / 2;
143 SetAPen(rp
, Pens
[FILLTEXTPEN
]);
144 SetOutlinePen(rp
, selected
? Pens
[HIGHLIGHTTEXTPEN
] : Pens
[TEXTPEN
]);
145 SetBPen(rp
, Pens
[BACKGROUNDPEN
]);
147 Move(rp
, leftEdge
+ textLeft
, topEdge
+ textTop
- extent
.te_Extent
.MinY
);
148 Text(rp
, label
, txtlen
);
151 topEdge
-= rect
.MinY
;
152 leftEdge
-= rect
.MinX
;
156 if (EraseBackground
) {
157 SetAPen(rp
, Pens
[BACKGROUNDPEN
]);
158 RectFill(rp
, leftEdge
+ rect
.MinX
, topEdge
+ rect
.MinY
,
159 leftEdge
+ Width
+ rect
.MaxX
- 1, topEdge
+ Height
+ rect
.MaxY
- 1);
162 D(bug("[%s] Render %ldx%ld icon %p at %ldx%ld\n", __func__
, Width
, Height
, icon
, leftEdge
, topEdge
));
166 struct NativeIconImage
*image
;
171 id
= selected
? 1 : 0;
172 image
= &ni
->ni_Image
[id
];
174 if (image
->ARGBMap
) {
175 WritePixelArrayAlpha(image
->ARGBMap
, 0, 0, ni
->ni_Width
* sizeof(ULONG
),
176 rp
, leftEdge
, topEdge
,
177 ni
->ni_Width
, ni
->ni_Height
, 0);
181 /* If we don't have selected bitmap,
182 * use the normal bitmap
185 mask
= image
->BitMask
;
187 bm
= ni
->ni_Image
[0].BitMap
;
188 mask
= ni
->ni_Image
[0].BitMask
;
190 #ifdef __mc68000 /* AGA support */
191 /* Get the 64 bit aligned mask */
192 mask
= (APTR
)(((IPTR
)mask
+ 7) & ~7);
201 bug("[%s] Using Bitmap: 0x%p, BitMask 0x%p\n", __func__
, bm
, mask
);
202 for (i
= 0; i
< bm
->Depth
; i
++)
203 bug("[%s] Planes[%d] = %p\n", __func__
, i
, bm
->Planes
[i
]);
207 BltMaskBitMapRastPort(bm
, 0, 0,
208 rp
, leftEdge
, topEdge
,
209 Width
, Height
, ABC
|ABNC
|ANBC
, mask
);
211 BltBitMapRastPort(bm
, 0, 0,
212 rp
, leftEdge
, topEdge
,
213 Width
, Height
, ABC
|ABNC
);
219 /* Uh. No layout? Just draw a square.
221 D(bug("[Icon] No image present\n"));
222 SetAPen(rp
, selected
? Pens
[SHINEPEN
] : Pens
[SHADOWPEN
]);
223 RectFill(rp
, leftEdge
, topEdge
,
224 leftEdge
+ Width
- 1,
225 topEdge
+ Height
- 1);
228 /* Draw the 3D border */
230 D(bug("[Icon] Embossing\n"));
232 rect
.MinX
+= leftEdge
;
233 rect
.MaxX
+= leftEdge
+ Width
- 1;
234 rect
.MinY
+= topEdge
;
235 rect
.MaxY
+= topEdge
+ Height
- 1;
237 /* Draw the left and top lines */
238 SetAPen(rp
, selected
? Pens
[SHADOWPEN
] : Pens
[SHINEPEN
]);
239 Move(rp
, rect
.MinX
, rect
.MaxY
- 1);
240 Draw(rp
, rect
.MinX
, rect
.MinY
);
241 Draw(rp
, rect
.MaxX
- 1, rect
.MinY
);
243 /* Draw the right and bottom lines */
244 SetAPen(rp
, selected
? Pens
[SHINEPEN
] : Pens
[SHADOWPEN
]);
245 Move(rp
, rect
.MaxX
, rect
.MinY
+ 1);
246 Draw(rp
, rect
.MaxX
, rect
.MaxY
);
247 Draw(rp
, rect
.MinX
+ 1, rect
.MaxY
);
249 SetAPen(rp
, Pens
[BACKGROUNDPEN
]);
250 WritePixel(rp
, rect
.MinX
, rect
.MaxY
);
251 WritePixel(rp
, rect
.MaxX
, rect
.MinY
);
256 } /* DrawIconStateA() */