2 Copyright 2003, The AROS Development Team.
10 #include <proto/dos.h>
11 #include <proto/graphics.h>
13 /* #define MYDEBUG 1 */
16 #include "muimaster_intern.h"
20 extern struct Library
*MUIMasterBase
;
22 /* From ASCII to internal representation */
23 BOOL
zune_pen_spec_to_intern (const struct MUI_PenSpec
*spec
,
24 struct MUI_PenSpec_intern
*intern
)
29 memset(intern
, 0, sizeof(*intern
));
31 D(bug("zune_pen_spec_to_intern: parsing %s\n", spec
->ps_buf
));
32 switch (spec
->ps_buf
[0])
35 if (!StrToLong(spec
->ps_buf
+ 1, &intern
->p_mui
))
37 intern
->p_type
= PST_MUI
;
41 if (!StrToLong(spec
->ps_buf
+ 1, &intern
->p_cmap
))
43 intern
->p_type
= PST_CMAP
;
47 if (!StrToLong(spec
->ps_buf
+ 1, &intern
->p_sys
))
49 intern
->p_type
= PST_SYS
;
64 intern
->p_rgb
.red
= strtoul(s
, (char **)&s
, 16);
70 intern
->p_rgb
.green
= strtoul(s
, (char **)&s
, 16);
76 intern
->p_rgb
.blue
= strtoul(s
, (char **)&s
, 16);
80 intern
->p_type
= PST_RGB
;
87 BOOL
zune_pen_string_to_intern (CONST_STRPTR spec
,
88 struct MUI_PenSpec_intern
*intern
)
90 return zune_pen_spec_to_intern((const struct MUI_PenSpec
*)spec
, intern
);
93 BOOL
zune_pen_intern_to_spec (const struct MUI_PenSpec_intern
*intern
,
94 struct MUI_PenSpec
*spec
)
99 switch (intern
->p_type
)
102 spec
->ps_buf
[0] = 'm';
103 sprintf(spec
->ps_buf
+ 1, "%ld", intern
->p_mui
);
107 spec
->ps_buf
[0] = 'p';
108 sprintf(spec
->ps_buf
+ 1, "%ld", intern
->p_cmap
);
112 spec
->ps_buf
[0] = 'r';
113 sprintf(spec
->ps_buf
+ 1, "%08lx,%08lx,%08lx",
114 intern
->p_rgb
.red
, intern
->p_rgb
.green
, intern
->p_rgb
.blue
);
118 spec
->ps_buf
[0] = 's';
119 sprintf(spec
->ps_buf
+ 1, "%ld", intern
->p_sys
);
128 void zune_penspec_fill_muipen(struct MUI_PenSpec_intern
*psi
, LONG muipen
)
132 psi
->p_type
= PST_MUI
;
137 void zune_penspec_fill_rgb(struct MUI_PenSpec_intern
*psi
, ULONG r
, ULONG g
, ULONG b
)
141 psi
->p_type
= PST_RGB
;
143 psi
->p_rgb
.green
= g
;
148 static void set_pen_from_rgb (struct MUI_PenSpec_intern
*psi
, struct ColorMap
*cm
,
149 ULONG r
, ULONG g
, ULONG b
)
152 struct TagItem obp_tags
[] =
154 { OBP_FailIfBad
, FALSE
},
158 pen
= ObtainBestPenA(cm
, r
, g
, b
, obp_tags
);
161 psi
->p_is_allocated
= FALSE
;
162 psi
->p_pen
= FindColor(cm
, r
, g
, b
, -1);
166 psi
->p_is_allocated
= TRUE
;
171 BOOL
zune_penspec_setup(struct MUI_PenSpec_intern
*psi
, struct MUI_RenderInfo
*mri
)
176 D(bug("zune_penspec_setup(%lx) type=%ld\n", psi
, psi
->p_type
));
182 if ((psi
->p_mui
>= 0) && (psi
->p_mui
< MPEN_COUNT
))
183 psi
->p_pen
= mri
->mri_Pens
[psi
->p_mui
];
190 psi
->p_pen
= (psi
->p_cmap
>= 0) ?
192 mri
->mri_Colormap
->Count
+ psi
->p_cmap
;
193 if ((psi
->p_pen
>= 0) && (psi
->p_pen
< mri
->mri_Colormap
->Count
))
194 psi
->p_is_allocated
= FALSE
;
200 set_pen_from_rgb(psi
, mri
->mri_Colormap
,
201 psi
->p_rgb
.red
, psi
->p_rgb
.green
, psi
->p_rgb
.blue
);
202 D(bug("zune_penspec_setup(%lx)=%ld RGB(%lx,%lx,%lx)\n", psi
,
203 psi
->p_pen
, psi
->p_rgb
.red
, psi
->p_rgb
.green
, psi
->p_rgb
.blue
));
215 BOOL
zune_penspec_cleanup(struct MUI_PenSpec_intern
*psi
)
217 if (!psi
|| !psi
->p_mri
)
226 if (psi
->p_is_allocated
)
227 ReleasePen(psi
->p_mri
->mri_Colormap
, psi
->p_pen
);
231 if (psi
->p_is_allocated
)
232 ReleasePen(psi
->p_mri
->mri_Colormap
, psi
->p_pen
);
244 void zune_penspec_drawdirect(struct MUI_PenSpec_intern
*psi
, struct RastPort
*rp
, struct MUI_RenderInfo
*mri
,
245 LONG left
, LONG top
, LONG right
, LONG bottom
)
247 if (!psi
|| !mri
|| !rp
)
250 if ( psi
->p_type
== PST_RGB
)
252 D(bug("drawing with %lx, pen=%ld, at %ld, %ld => %ld, %ld\n",
253 psi
, psi
->p_pen
, left
, top
, right
, bottom
));
255 SetAPen(rp
, psi
->p_pen
);
256 RectFill(rp
, left
, top
, right
, bottom
);
259 void zune_penspec_draw(struct MUI_PenSpec_intern
*psi
, struct MUI_RenderInfo
*mri
,
260 LONG left
, LONG top
, LONG right
, LONG bottom
)
262 zune_penspec_drawdirect(psi
, mri
->mri_RastPort
, mri
, left
, top
, right
, bottom
);