2 Copyright © 2003-2015, The AROS Development Team. All rights reserved.
10 #include <proto/graphics.h>
12 /* #define MYDEBUG 1 */
15 #include "muimaster_intern.h"
19 extern struct Library
*MUIMasterBase
;
21 /* From ASCII to internal representation */
22 BOOL
zune_pen_spec_to_intern(const struct MUI_PenSpec
*spec
,
23 struct MUI_PenSpec_intern
*intern
)
28 memset(intern
, 0, sizeof(*intern
));
30 D(bug("zune_pen_spec_to_intern: parsing %s\n", spec
->buf
));
34 if (!StrToLong(spec
->buf
+ 1, &intern
->p_mui
))
36 intern
->p_type
= PST_MUI
;
40 if (!StrToLong(spec
->buf
+ 1, &intern
->p_cmap
))
42 intern
->p_type
= PST_CMAP
;
46 if (!StrToLong(spec
->buf
+ 1, &intern
->p_sys
))
48 intern
->p_type
= PST_SYS
;
63 intern
->p_rgb
.red
= strtoul(s
, (char **)&s
, 16);
69 intern
->p_rgb
.green
= strtoul(s
, (char **)&s
, 16);
75 intern
->p_rgb
.blue
= strtoul(s
, (char **)&s
, 16);
79 intern
->p_type
= PST_RGB
;
86 BOOL
zune_pen_string_to_intern(CONST_STRPTR spec
,
87 struct MUI_PenSpec_intern
*intern
)
89 return zune_pen_spec_to_intern((const struct MUI_PenSpec
*)spec
,
93 BOOL
zune_pen_intern_to_spec(const struct MUI_PenSpec_intern
*intern
,
94 struct MUI_PenSpec
*spec
)
99 switch (intern
->p_type
)
103 sprintf(spec
->buf
+ 1, "%ld", (long)intern
->p_mui
);
108 sprintf(spec
->buf
+ 1, "%ld", (long)intern
->p_cmap
);
113 sprintf(spec
->buf
+ 1, "%08lx,%08lx,%08lx",
114 (long)intern
->p_rgb
.red
, (long)intern
->p_rgb
.green
,
115 (long)intern
->p_rgb
.blue
);
120 sprintf(spec
->buf
+ 1, "%ld", (long)intern
->p_sys
);
129 void zune_penspec_fill_muipen(struct MUI_PenSpec_intern
*psi
, LONG muipen
)
133 psi
->p_type
= PST_MUI
;
138 void zune_penspec_fill_rgb(struct MUI_PenSpec_intern
*psi
, ULONG r
, ULONG g
,
143 psi
->p_type
= PST_RGB
;
145 psi
->p_rgb
.green
= g
;
150 static void set_pen_from_rgb(struct MUI_PenSpec_intern
*psi
,
151 struct ColorMap
*cm
, ULONG r
, ULONG g
, ULONG b
)
154 struct TagItem obp_tags
[] = {
155 {OBP_FailIfBad
, FALSE
},
159 pen
= ObtainBestPenA(cm
, r
, g
, b
, obp_tags
);
162 psi
->p_is_allocated
= FALSE
;
163 psi
->p_pen
= FindColor(cm
, r
, g
, b
, -1);
167 psi
->p_is_allocated
= TRUE
;
172 BOOL
zune_penspec_setup(struct MUI_PenSpec_intern
*psi
,
173 struct MUI_RenderInfo
*mri
)
178 D(bug("zune_penspec_setup(%lx) type=%ld\n", psi
, psi
->p_type
));
184 if ((psi
->p_mui
>= 0) && (psi
->p_mui
< MPEN_COUNT
))
185 psi
->p_pen
= mri
->mri_Pens
[psi
->p_mui
];
192 psi
->p_pen
= (psi
->p_cmap
>= 0) ?
193 psi
->p_cmap
: mri
->mri_Colormap
->Count
+ psi
->p_cmap
;
194 if ((psi
->p_pen
>= 0)
195 && (psi
->p_pen
< mri
->mri_Colormap
->Count
))
196 psi
->p_is_allocated
= FALSE
;
202 set_pen_from_rgb(psi
, mri
->mri_Colormap
,
203 psi
->p_rgb
.red
, psi
->p_rgb
.green
, psi
->p_rgb
.blue
);
204 D(bug("zune_penspec_setup(%lx)=%ld RGB(%lx,%lx,%lx)\n", psi
,
205 psi
->p_pen
, psi
->p_rgb
.red
, psi
->p_rgb
.green
,
218 BOOL
zune_penspec_cleanup(struct MUI_PenSpec_intern
*psi
)
220 if (!psi
|| !psi
->p_mri
)
229 if (psi
->p_is_allocated
)
230 ReleasePen(psi
->p_mri
->mri_Colormap
, psi
->p_pen
);
234 if (psi
->p_is_allocated
)
235 ReleasePen(psi
->p_mri
->mri_Colormap
, psi
->p_pen
);
247 void zune_penspec_drawdirect(struct MUI_PenSpec_intern
*psi
,
248 struct RastPort
*rp
, struct MUI_RenderInfo
*mri
, LONG left
, LONG top
,
249 LONG right
, LONG bottom
)
251 if (!psi
|| !mri
|| !rp
)
254 if (psi
->p_type
== PST_RGB
)
256 D(bug("drawing with %lx, pen=%ld, at %ld, %ld => %ld, %ld\n",
257 psi
, psi
->p_pen
, left
, top
, right
, bottom
));
259 SetAPen(rp
, psi
->p_pen
);
260 RectFill(rp
, left
, top
, right
, bottom
);
263 void zune_penspec_draw(struct MUI_PenSpec_intern
*psi
,
264 struct MUI_RenderInfo
*mri
, LONG left
, LONG top
, LONG right
,
267 zune_penspec_drawdirect(psi
, mri
->mri_RastPort
, mri
, left
, top
, right
,