grub2: bring back build of aros-side grub2 tools
[AROS.git] / rom / intuition / getdrawinfoattr.c
blob8c54acf496194ba4e9167c0b0d171c4a710e001c
1 /*
2 Copyright © 2013, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <intuition/diattr.h>
7 #include <proto/graphics.h>
9 #include "intuition_intern.h"
11 #define ARG_MASK 0x0000000F
13 #define SetResult(x) if (resultPtr) *resultPtr = x;
15 /*****************************************************************************
17 NAME */
18 #include <proto/intuition.h>
20 AROS_LH3(ULONG, GetDrawInfoAttr,
22 /* SYNOPSIS */
23 AROS_LHA(struct DrawInfo *, drawInfo, A0),
24 AROS_LHA(ULONG , attrID, D0),
25 AROS_LHA(IPTR * , resultPtr, A1),
27 /* LOCATION */
28 struct IntuitionBase *, IntuitionBase, 156, Intuition)
30 /* FUNCTION
31 Gets value of the specified attribute from DrawInfo object, or
32 system default value (for some attributes).
34 INPUTS
35 drawInfo - an object pointer to query. It is possible to set this
36 argument to NULL when querying GDIA_Color or GDIA_Pen
37 attributes. In this case values will be retrieved from
38 system preferences.
39 attrID - ID of the attribute you want. The following IDs are
40 currently defined:
42 GDIA_Color - 0RGB value of the color corresponding to a given pen.
43 It is possible to retrieve these values only from
44 DrawInfos belonging to direct-color screens. Pen ID
45 should be ORed with attribute ID.
46 GDIA_Pen - LUT color number corresponding to a given pen.
47 GDIA_Version - Version number of the DrawInfo object.
48 GDIA_DirectColor - TRUE if the DrawInfo belongs to direct-color screen. Note
49 that in case of failure it also sets success indicator to
50 FALSE.
51 GDIA_NumPens - Number of pens or colors defined in this DrawInfo object.
52 GDIA_Font - Font specified in this DrawInfo.
53 GDIA_Depth - Depth of this DrawInfo. Note that this attribute will
54 return real depth of DrawInfo's screen, however dri_Depth
55 member will contain 8 for AmigaOS(tm) compatibility.
56 GDIA_ResolutionX - X resolution in ticks
57 GDIA_ResolutionY - Y resolution in ticks
58 GDIA_CheckMark - A pointer to CheckMark image object for the menu.
59 GDIA_MenuKey - A pointer to Menu (Amiga) key image object for the menu.
61 resultPtr - an optional storage area for success indicator. You
62 can set this parameter to NULL.
64 RESULT
65 A value of the specified attribute. resultPtr, if supplied, gets
66 TRUE for success and FALSE for failure.
68 NOTES
69 This function is compatible with MorphOS
71 EXAMPLE
73 BUGS
75 SEE ALSO
77 INTERNALS
79 *****************************************************************************/
82 * MorphOS (as of v2.6) quirks which are intentionally not reproduced in this
83 * implementation:
85 * 1. MorphOS implementation does not accept struct DrawInfo with version
86 different from OS own number.
87 * 2. MorphOS implementation does not check dri_NumPens when reading dri_Pens,
88 * this is clearly a bug.
89 * 3. In MorphOS GDIA_DirectColor and GDIA_Depth work only if DrawInfo has
90 * attached screen, consequently returning failure with handmade DrawInfos.
94 AROS_LIBFUNC_INIT
96 struct GfxBase *GfxBase = GetPrivIBase(IntuitionBase)->GfxBase;
97 ULONG pen;
99 SetResult(TRUE);
101 if (drawInfo)
103 /* Most of IDs make sense only with nonzero DrawInfo */
104 switch (attrID)
106 case GDIA_Version:
107 return drawInfo->dri_Version;
109 case GDIA_DirectColor:
110 return (drawInfo->dri_Flags & DRIF_DIRECTCOLOR) ? TRUE : FALSE;
112 case GDIA_NumPens:
113 return drawInfo->dri_NumPens;
115 case GDIA_Font:
116 return (IPTR)drawInfo->dri_Font;
118 case GDIA_Depth:
119 return (drawInfo->dri_Version < 3) ? drawInfo->dri_Depth :
120 GetPrivScreen(drawInfo->dri_Screen)->realdepth;
122 case GDIA_CheckMark:
123 if (drawInfo->dri_Version < 2)
125 SetResult(FALSE);
126 return 0;
128 return (IPTR)drawInfo->dri_CheckMark;
130 case GDIA_MenuKey:
131 if (drawInfo->dri_Version < 2)
133 SetResult(FALSE);
134 return 0;
136 return (IPTR)drawInfo->dri_AmigaKey;
138 case GDIA_ResolutionX:
139 return drawInfo->dri_Resolution.X;
141 case GDIA_ResolutionY:
142 return drawInfo->dri_Resolution.Y;
146 * If we are here, this should be GDIA_Color or GDIA_Pen.
147 * First we need to extract pen ID.
149 pen = attrID & ARG_MASK;
150 if (pen < drawInfo->dri_NumPens)
152 switch (attrID & ~ARG_MASK)
154 case GDIA_Color:
156 * According to original MorphOS semantics we return RGB colors
157 * only for direct-color screens.
159 if (drawInfo->dri_Flags & DRIF_DIRECTCOLOR)
161 ULONG col[3];
163 GetRGB32(drawInfo->dri_Screen->ViewPort.ColorMap, drawInfo->dri_Pens[pen], 1, col);
164 return ((col[0] & 0xFF000000) >> 8) |
165 ((col[1] & 0xFF000000) >> 16) |
166 (col[2] >> 24);
168 break;
170 case GDIA_Pen:
171 return drawInfo->dri_Pens[pen];
175 else
178 * No DrawInfo supplied.
179 * In this case we return only default colors/pens from our preferences.
181 pen = attrID & ARG_MASK;
182 if (pen < NUMDRIPENS)
184 struct Color32 *col;
186 /* Extract color number corresponding to the pen */
187 pen = GetPrivIBase(IntuitionBase)->DriPens8[pen];
189 switch (attrID & ~ARG_MASK)
191 case GDIA_Color:
193 * In AROS we don't have separate preferences for direct-color
194 * screens. So we now decode color number into its RGB representation
195 * according to system palette.
197 if (pen < 4)
199 /* First 4 colors */
200 col = &GetPrivIBase(IntuitionBase)->Colors[pen];
202 else if ((pen > 16) && (pen < 20))
204 /* These are pointer colors, indexes 8...10 in system palette */
205 col = &GetPrivIBase(IntuitionBase)->Colors[pen - 17 + 8];
207 else
210 * There's no known color value for other pens.
211 * We also have 4 last colors defined, however we don't know which
212 * pens correspond to them, because this depends on screen depth.
213 * Well, after all, we are not MOS. :)
215 break;
218 return ((col->red & 0xFF000000) >> 8) |
219 ((col->green & 0xFF000000) >> 16) |
220 ( col->blue >> 24);
222 case GDIA_Pen:
223 return pen;
229 * Unknown IDs as well as failed conditions end up here.
230 * Report error and return zero.
232 SetResult(FALSE);
233 return 0;
235 AROS_LIBFUNC_EXIT