grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / muimaster / imspec.c
blob3c541b0d43a14bdc6f860665dda1579bb1c1fda5
1 /*
2 Copyright 1999, David Le Corfec.
3 Copyright 2002-2007, The AROS Development Team.
4 All rights reserved.
6 $Id$
7 */
9 /* This is the implementation of a MUI-like image engine
10 * (see MUIA_Image_Spec for more information about MUI image specs)
11 * Their external form is a string "<type>:<parameters>"
12 * with type being a single char. See zune_image_spec_to_structure().
14 * Basically an ImageSpec can be anything which can be displayed:
15 * gfx datas, drawing code, ...
16 * See ImageSpecType for the known types.
19 #include <string.h>
20 #include <stdio.h>
21 #include <stdlib.h>
23 #include <exec/types.h>
24 #include <exec/memory.h>
26 #include <graphics/gfxmacros.h>
28 #include <proto/exec.h>
29 #include <proto/graphics.h>
30 #include <proto/intuition.h>
31 #include <proto/dos.h>
32 #include <clib/alib_protos.h>
34 //#define MYDEBUG 1
35 #include "debug.h"
37 #include "mui.h"
39 #include "datatypescache.h"
40 #include "imspec.h"
41 #include "support.h"
43 #include "muimaster_intern.h"
44 #include "prefs.h"
45 #include "penspec.h"
46 #include "imspec_intern.h"
48 extern struct Library *MUIMasterBase;
50 static struct MUI_ImageSpec_intern *get_brush_imspec(CONST_STRPTR filename);
52 const static UWORD gridpattern1[] = {
53 0x5555,
54 0xaaaa,
57 const static UWORD gridpattern2[] = {
58 0x4444,
59 0x1111,
62 typedef struct
64 MPen bg;
65 MPen fg;
66 const UWORD *pattern;
67 } MPattern;
69 const static MPattern patternPens[] = {
70 {MPEN_SHADOW, MPEN_BACKGROUND, gridpattern1}, /* MUII_SHADOWBACK */
71 {MPEN_SHADOW, MPEN_FILL, gridpattern1}, /* MUII_SHADOWFILL */
72 {MPEN_SHADOW, MPEN_SHINE, gridpattern1}, /* MUII_SHADOWSHINE */
73 {MPEN_FILL, MPEN_BACKGROUND, gridpattern1}, /* MUII_FILLBACK */
74 {MPEN_FILL, MPEN_SHINE, gridpattern1}, /* MUII_FILLSHINE */
75 {MPEN_SHINE, MPEN_BACKGROUND, gridpattern1}, /* MUII_SHINEBACK */
76 {MPEN_FILL, MPEN_BACKGROUND, gridpattern2}, /* MUII_FILLBACK2 */
77 {MPEN_HALFSHINE, MPEN_BACKGROUND, gridpattern1}, /* MUII_HSHINEBACK */
78 {MPEN_HALFSHADOW, MPEN_BACKGROUND, gridpattern1}, /* MUII_HSHADOWBACK */
79 {MPEN_HALFSHINE, MPEN_SHINE, gridpattern1}, /* MUII_HSHINESHINE */
80 {MPEN_HALFSHADOW, MPEN_SHADOW, gridpattern1}, /* MUII_HSHADOWSHADOW */
81 {MPEN_MARK, MPEN_SHINE, gridpattern1}, /* MUII_MARKSHINE */
82 {MPEN_MARK, MPEN_HALFSHINE, gridpattern1}, /* MUII_MARKHALFSHINE */
83 {MPEN_MARK, MPEN_BACKGROUND, gridpattern1}, /* MUII_MARKBACKGROUND */
86 #define PATTERN_COUNT (MUII_LASTPAT - MUII_BACKGROUND + 1)
88 static struct MUI_ImageSpec_intern *get_pattern_imspec(LONG in)
90 struct MUI_ImageSpec_intern *spec = NULL;
92 if (in >= MUII_BACKGROUND && in <= MUII_FILL)
94 if ((spec = mui_alloc_struct(struct MUI_ImageSpec_intern)))
96 UWORD color;
97 if (in == MUII_BACKGROUND)
98 color = MPEN_BACKGROUND;
99 else if (in == MUII_SHADOW)
100 color = MPEN_SHADOW;
101 else if (in == MUII_SHINE)
102 color = MPEN_SHINE;
103 else
104 color = MPEN_FILL;
106 spec->type = IST_COLOR;
107 zune_penspec_fill_muipen(&spec->u.penspec, color);
109 return spec;
111 else if (in >= MUII_SHADOWBACK && in <= MUII_MARKBACKGROUND)
113 if ((spec = mui_alloc_struct(struct MUI_ImageSpec_intern)))
115 spec->type = IST_PATTERN;
116 spec->u.pattern = in - MUII_SHADOWBACK;
118 return spec;
120 return NULL;
124 static struct MUI_ImageSpec_intern *get_pen_imspec(CONST_STRPTR str)
126 struct MUI_ImageSpec_intern *spec;
128 if ((spec = mui_alloc_struct(struct MUI_ImageSpec_intern)))
130 if (!zune_pen_string_to_intern(str, &spec->u.penspec))
132 D(bug("*** zune_pen_string_to_intern failed\n"));
133 mui_free(spec);
134 return NULL;
136 spec->type = IST_COLOR;
137 return spec;
139 return NULL;
142 static struct MUI_ImageSpec_intern *get_scaled_gradient_imspec(CONST_STRPTR
143 str)
145 struct MUI_ImageSpec_intern *spec;
147 if ((spec = mui_alloc_struct(struct MUI_ImageSpec_intern)))
149 if (!zune_gradient_string_to_intern(str, spec))
151 D(bug("*** zune_gradient_string_to_intern failed\n"));
152 mui_free(spec);
153 return NULL;
155 spec->type = IST_SCALED_GRADIENT;
156 return spec;
158 return NULL;
161 static struct MUI_ImageSpec_intern *get_tiled_gradient_imspec(CONST_STRPTR
162 str)
164 struct MUI_ImageSpec_intern *spec;
166 if ((spec = mui_alloc_struct(struct MUI_ImageSpec_intern)))
168 if (!zune_gradient_string_to_intern(str, spec))
170 D(bug("*** zune_gradient_string_to_intern failed\n"));
171 mui_free(spec);
172 return NULL;
174 spec->type = IST_TILED_GRADIENT;
175 return spec;
177 return NULL;
180 static struct MUI_ImageSpec_intern *get_boopsi_imspec(CONST_STRPTR filename)
182 struct MUI_ImageSpec_intern *spec;
184 if (!filename)
185 return NULL;
186 if (!strstr(filename, ".image"))
187 return get_brush_imspec(filename);
189 if ((spec = mui_alloc_struct(struct MUI_ImageSpec_intern)))
191 spec->u.boopsi.filename = StrDup(filename);
192 if (!spec->u.boopsi.filename)
193 return NULL;
194 spec->u.boopsi.obj = NULL;
195 spec->type = IST_BOOPSI;
196 return spec;
198 return NULL;
202 static struct MUI_ImageSpec_intern *get_brush_imspec(CONST_STRPTR filename)
204 struct MUI_ImageSpec_intern *spec;
205 if ((spec = mui_alloc_struct(struct MUI_ImageSpec_intern)))
207 size_t last_idx;
208 spec->u.brush.filename[0] = StrDup(filename);
209 if (!spec->u.brush.filename[0])
210 return NULL;
211 last_idx = strlen(spec->u.brush.filename[0]) - 1;
212 if (spec->u.brush.filename[0][last_idx] == '0')
214 char *tmpstr;
215 tmpstr = StrDup(filename);
216 if (!tmpstr)
218 FreeVec((APTR) spec->u.brush.filename[0]);
219 return NULL;
221 tmpstr[last_idx] = '1';
222 spec->u.brush.filename[1] = tmpstr;
224 spec->u.brush.dt[0] = NULL;
225 spec->u.brush.dt[1] = NULL;
226 spec->type = IST_BRUSH;
227 return spec;
229 return NULL;
233 static struct MUI_ImageSpec_intern *get_bitmap_imspec(CONST_STRPTR filename)
235 struct MUI_ImageSpec_intern *spec;
236 if ((spec = mui_alloc_struct(struct MUI_ImageSpec_intern)))
238 spec->u.bitmap.filename = StrDup(filename);
239 if (!spec->u.bitmap.filename)
240 return NULL;
241 spec->u.bitmap.dt = NULL;
242 spec->type = IST_BITMAP;
243 return spec;
245 return NULL;
249 static struct MUI_ImageSpec_intern *get_config_imspec(LONG img)
251 if ((img >= MUII_WindowBack) && (img <= MUII_ReadListBack))
253 struct MUI_ImageSpec_intern *spec;
254 if ((spec = mui_alloc_struct(struct MUI_ImageSpec_intern)))
256 spec->u.cfg.muiimg = img;
257 spec->type = IST_CONFIG;
258 return spec;
261 return NULL;
265 #ifdef MYDEBUG
266 static const char *zune_imspec_to_string(struct MUI_ImageSpec_intern *spec)
268 static char buf[64];
270 if (!spec)
272 buf[0] = 0;
273 return buf;
275 switch (spec->type)
277 case IST_PATTERN:
278 sprintf(buf, "0:%ld", spec->u.pattern);
279 break;
281 case IST_VECTOR:
282 sprintf(buf, "1:%ld", spec->u.vect.type);
283 break;
285 case IST_COLOR:
286 zune_pen_intern_to_spec(&spec->u.penspec,
287 (struct MUI_PenSpec *)buf);
288 break;
290 case IST_BOOPSI:
291 sprintf(buf, "3:%s", spec->u.boopsi.filename);
292 break;
294 case IST_BRUSH: /* this is really 3: too */
295 sprintf(buf, "3:%s", spec->u.brush.filename[0]);
296 break;
298 case IST_BITMAP:
299 sprintf(buf, "5:%s", spec->u.bitmap.filename);
300 break;
302 case IST_CONFIG:
303 sprintf(buf, "6:%ld", spec->u.cfg.muiimg);
304 break;
306 case IST_SCALED_GRADIENT:
307 zune_scaled_gradient_intern_to_string(spec, buf);
308 break;
310 case IST_TILED_GRADIENT:
311 zune_tiled_gradient_intern_to_string(spec, buf);
312 break;
314 return buf;
316 #endif
318 /**************************************************************************
319 Create a image spec from a string or a magic value.
320 in : contains magic or string
321 obj: is a AreaObject. It is used to access the config data.
323 TODO: merge this with zune_imspec_setup() because this function should
324 be called in MUIM_Setup (configdata)
325 **************************************************************************/
326 static struct MUI_ImageSpec_intern *zune_image_spec_to_structure(IPTR in)
328 struct MUI_ImageSpec_intern *spec = NULL;
329 CONST_STRPTR s;
331 if (in >= MUII_WindowBack && in <= MUII_ReadListBack)
333 D(bug("zune_image_spec_to_structure [config] : in=%ld\n", in));
334 spec = get_config_imspec(in);
336 else if (in >= MUII_BACKGROUND && in <= MUII_MARKBACKGROUND)
338 D(bug("zune_image_spec_to_structure [pattern] : in=%ld\n", in));
339 spec = get_pattern_imspec(in);
341 else
343 s = (CONST_STRPTR) in;
344 D(bug("zune_image_spec_to_structure [string] : in=%s\n", s));
346 switch (*s)
348 case '0': /* builtin pattern */
350 LONG pat;
351 StrToLong(s + 2, &pat);
352 spec = get_pattern_imspec(pat);
353 break;
356 case '1': /* builtin standard image, obsoleted by 6: */
358 LONG vect;
359 StrToLong(s + 2, &vect);
360 spec = zune_imspec_create_vector(vect);
361 break;
364 case '2': /* a penspec */
365 spec = get_pen_imspec(s + 2);
366 D(bug("zune_image_spec_to_structure : penspec %lx\n",
367 &spec->u.penspec));
368 break;
370 case '3': /* BOOPSI image class name */
371 spec = get_boopsi_imspec(s + 2);
372 break;
374 case '4': /* external MUI brush name */
375 spec = get_brush_imspec(s + 2);
376 break;
378 case '5': /* external bitmap loaded with datatypes */
379 spec = get_bitmap_imspec(s + 2);
380 break;
382 case '6': /* preconfigured image or background */
384 LONG img;
385 StrToLong(s + 2, &img);
387 if (img >= MUII_WindowBack && img <= MUII_ReadListBack)
388 spec = get_config_imspec(img);
389 break;
392 case '7': /* scaled gradient */
393 spec = get_scaled_gradient_imspec(s + 2);
394 break;
396 case '8': /* tiled gradient */
397 spec = get_tiled_gradient_imspec(s + 2);
398 break;
400 } /* switch(*s) */
402 D(bug("zune_image_spec_to_structure : out=0x%lx [%s]\n",
403 spec, zune_imspec_to_string(spec)));
404 return spec;
407 #if 0
408 static struct MUI_ImageSpec_intern *zune_imspec_copy(struct
409 MUI_ImageSpec_intern *spec)
411 struct MUI_ImageSpec_intern *nspec;
413 if (!spec)
414 return NULL;
416 nspec = mui_alloc_struct(struct MUI_ImageSpec_intern);
417 if (nspec)
418 memcpy(nspec, spec, sizeof(struct MUI_ImageSpec_intern));
419 return nspec;
421 #endif
425 static void zune_imspec_free(struct MUI_ImageSpec_intern *spec)
427 if (!spec)
428 return;
429 D(bug("zune_imspec_free(0x%lx) [%s]\n",
430 spec, zune_imspec_to_string(spec)));
432 switch (spec->type)
434 case IST_BOOPSI:
435 if (spec->u.boopsi.filename)
436 FreeVec((APTR) spec->u.boopsi.filename);
437 break;
439 case IST_BRUSH:
440 if (spec->u.brush.filename[0])
441 FreeVec((APTR) spec->u.brush.filename[0]);
442 if (spec->u.brush.filename[1])
443 FreeVec((APTR) spec->u.brush.filename[1]);
444 break;
446 case IST_BITMAP:
447 if (spec->u.bitmap.filename)
448 FreeVec((APTR) spec->u.bitmap.filename);
449 break;
451 default:
452 break;
455 mui_free(spec);
458 struct MUI_ImageSpec_intern *zune_imspec_setup(IPTR s,
459 struct MUI_RenderInfo *mri)
461 struct MUI_ImageSpec_intern *spec;
463 if (!mri)
465 D(bug("zune_imspec_setup: param error: mri=%p\n", mri));
466 return NULL;
469 spec = zune_image_spec_to_structure(s);
471 D(bug("zune_imspec_setup(%lx) [%s]\n",
472 spec, zune_imspec_to_string(spec)));
473 if (!spec)
474 return NULL;
476 switch (spec->type)
478 case IST_PATTERN:
479 break;
481 case IST_VECTOR:
482 break;
484 case IST_COLOR:
485 zune_penspec_setup(&spec->u.penspec, mri);
486 break;
488 case IST_BOOPSI:
489 break;
491 case IST_BRUSH:
493 int i;
495 for (i = 0; i < 2; i++)
497 if (spec->u.brush.filename[i])
499 spec->u.brush.dt[i] = dt_load_picture
500 (spec->u.brush.filename[i], mri->mri_Screen);
502 if (!spec->u.brush.dt[i]
503 && !strchr(spec->u.brush.filename[i], ':'))
505 int size;
506 STRPTR fullpath;
508 size = strlen(IMSPEC_EXTERNAL_PREFIX)
509 + strlen(spec->u.brush.filename[i]) + 1;
510 fullpath = (STRPTR) AllocVec(size, MEMF_ANY);
512 if (fullpath != NULL)
514 strcpy(fullpath, IMSPEC_EXTERNAL_PREFIX);
515 strcat(fullpath, spec->u.brush.filename[i]);
516 fullpath[size - 1] = 0;
517 spec->u.brush.dt[i] = dt_load_picture
518 (fullpath, mri->mri_Screen);
519 FreeVec(fullpath);
523 else
525 spec->u.brush.dt[i] = spec->u.brush.dt[0];
529 break;
531 case IST_BITMAP:
532 if (spec->u.bitmap.filename)
534 spec->u.bitmap.dt = dt_load_picture
535 (spec->u.bitmap.filename, mri->mri_Screen);
537 break;
539 case IST_CONFIG:
541 Object *win = mri->mri_WindowObject;
542 struct ZunePrefsNew *prefs = muiGlobalInfo(win)->mgi_Prefs;
543 /* potential for deadloop if Zune prefs images contain a 6: */
544 CONST_STRPTR spec_desc = prefs->imagespecs[spec->u.cfg.muiimg];
545 zune_imspec_free(spec);
546 spec = NULL;
548 if (spec_desc && (spec_desc[0] == '6'))
550 D(bug("*** zune_imspec_setup (%s recursive config)\n",
551 zune_imspec_to_string(spec)));
553 else
555 spec = zune_imspec_setup((IPTR) spec_desc, mri);
557 break;
560 case IST_SCALED_GRADIENT:
561 case IST_TILED_GRADIENT:
562 zune_gradientspec_setup(spec, mri);
563 break;
565 return spec;
568 void zune_imspec_cleanup(struct MUI_ImageSpec_intern *spec)
570 if (!spec)
571 return;
573 D(bug("zune_imspec_cleanup(0x%lx) [%s]\n",
574 spec, zune_imspec_to_string(spec)));
576 switch (spec->type)
578 case IST_PATTERN:
579 break;
581 case IST_VECTOR:
582 break;
584 case IST_COLOR:
585 zune_penspec_cleanup(&spec->u.penspec);
586 break;
588 case IST_BOOPSI:
589 break;
591 case IST_BRUSH:
593 int i;
595 for (i = 0; i < 2; i++)
597 if (spec->u.brush.filename[i])
599 dt_dispose_picture(spec->u.brush.dt[i]);
601 spec->u.brush.dt[i] = NULL;
603 break;
605 case IST_BITMAP:
606 if (spec->u.bitmap.dt)
608 dt_dispose_picture(spec->u.bitmap.dt);
609 spec->u.bitmap.dt = NULL;
611 break;
613 case IST_CONFIG:
614 D(bug("*** zune_imspec_cleanup : IST_CONFIG\n"));
615 break;
617 case IST_SCALED_GRADIENT:
618 case IST_TILED_GRADIENT:
619 zune_gradientspec_cleanup(spec);
620 break;
624 zune_imspec_free(spec);
628 BOOL zune_imspec_askminmax(struct MUI_ImageSpec_intern *spec,
629 struct MUI_MinMax *minmax)
631 if ((!spec) || (!minmax))
632 return FALSE;
634 switch (spec->type)
636 case IST_PATTERN:
637 case IST_SCALED_GRADIENT:
638 case IST_TILED_GRADIENT:
639 case IST_COLOR:
640 minmax->MinWidth = 3;
641 minmax->MinHeight = 3;
642 minmax->DefWidth = 8;
643 minmax->DefHeight = 8;
644 minmax->MaxWidth = MUI_MAXMAX;
645 minmax->MaxHeight = MUI_MAXMAX;
646 break;
648 case IST_VECTOR:
649 return zune_imspec_vector_get_minmax(spec, minmax);
650 break;
652 case IST_BOOPSI:
653 /* ??? */
654 break;
656 case IST_BRUSH:
657 if (spec->u.brush.dt[0])
659 const char *straddr;
660 long len;
661 straddr = *(spec->u.brush.filename);
662 len = strlen(straddr);
663 if (len > 4)
665 if (strcmp(&straddr[len - 4], ".mim") == 0)
667 minmax->MinWidth = dt_width(spec->u.brush.dt[0]) >> 1;
668 minmax->MinHeight = dt_height(spec->u.brush.dt[0]);
669 minmax->DefWidth = minmax->MinWidth;
670 minmax->DefHeight = minmax->MinHeight;
671 minmax->MaxWidth = minmax->MinWidth;
672 minmax->MaxHeight = minmax->MinHeight;
673 break;
676 minmax->MinWidth = dt_width(spec->u.brush.dt[0]);
677 minmax->MinHeight = dt_height(spec->u.brush.dt[0]);
678 minmax->DefWidth = minmax->MinWidth;
679 minmax->DefHeight = minmax->MinHeight;
680 minmax->MaxWidth = minmax->MinWidth;
681 minmax->MaxHeight = minmax->MinHeight;
683 else
685 minmax->MinWidth = 3;
686 minmax->MinHeight = 3;
687 minmax->DefWidth = 8;
688 minmax->DefHeight = 8;
689 minmax->MaxWidth = MUI_MAXMAX;
690 minmax->MaxHeight = MUI_MAXMAX;
691 return FALSE;
693 break;
695 case IST_BITMAP:
696 minmax->MinWidth = 3;
697 minmax->MinHeight = 3;
698 minmax->DefWidth = dt_width(spec->u.bitmap.dt);
699 minmax->DefHeight = dt_height(spec->u.bitmap.dt);
700 minmax->MaxWidth = MUI_MAXMAX;
701 minmax->MaxHeight = MUI_MAXMAX;
702 if (!spec->u.bitmap.dt)
703 return FALSE;
704 break;
706 case IST_CONFIG:
707 D(bug("*** zune_imspec_askminmax : IST_CONFIG\n"));
708 break;
710 return TRUE;
714 void zune_imspec_show(struct MUI_ImageSpec_intern *spec, Object *obj)
716 if ((!spec) || (!obj))
717 return;
719 D(bug("zune_imspec_show(0x%lx) [%s]\n", spec,
720 zune_imspec_to_string(spec)));
722 /* scaled gradient generation made here */
723 switch (spec->type)
725 case IST_CONFIG:
726 D(bug("*** zune_imspec_show : IST_CONFIG\n"));
727 break;
729 case IST_SCALED_GRADIENT:
730 case IST_TILED_GRADIENT:
731 spec->u.gradient.obj = obj;
732 break;
734 default:
735 break;
740 void zune_imspec_hide(struct MUI_ImageSpec_intern *spec)
742 if (!spec)
743 return;
745 D(bug("zune_imspec_hide(0x%lx) [%s]\n", spec,
746 zune_imspec_to_string(spec)));
748 switch (spec->type)
750 case IST_CONFIG:
751 D(bug("*** zune_imspec_hide : IST_CONFIG\n"));
752 break;
753 default:
754 break;
759 void zune_imspec_drawbuffered(struct MUI_ImageSpec_intern *spec,
760 struct RastPort *rp, struct MUI_RenderInfo *mri, LONG left, LONG top,
761 LONG width, LONG height, LONG xoffset, LONG yoffset, LONG state,
762 LONG dx, LONG dy, WORD mode, LONG abs_l, LONG abs_t, LONG abs_r,
763 LONG abs_b)
765 LONG right = left + width - 1;
766 LONG bottom = top + height - 1;
767 struct MUI_ImageSpec_intern def;
769 if (!spec)
771 D(bug("*** zune_imspec_draw called on null imspec\n"));
772 return;
775 if ((spec->type == IST_BITMAP && !spec->u.bitmap.dt)
776 || (spec->type == IST_BRUSH && !spec->u.brush.dt[0]))
778 def.type = IST_COLOR;
779 zune_penspec_fill_muipen(&def.u.penspec, MPEN_BACKGROUND);
780 spec = &def;
783 switch (spec->type)
785 case IST_PATTERN:
787 LONG fg = mri->mri_Pens[patternPens[spec->u.pattern].fg];
788 LONG bg = mri->mri_Pens[patternPens[spec->u.pattern].bg];
789 SetDrMd(rp, JAM2);
790 SetAPen(rp, fg);
791 SetBPen(rp, bg);
792 SetAfPt(rp, patternPens[spec->u.pattern].pattern, 1);
793 RectFill(rp, left - dx, top - dy, right - dx, bottom - dy);
794 SetAfPt(rp, NULL, 0);
796 break;
798 case IST_VECTOR:
799 if (spec->u.vect.draw)
801 spec->u.vect.draw(mri, left - dx, top - dy, width, height,
802 state);
804 break;
806 case IST_COLOR:
807 zune_penspec_drawdirect(&spec->u.penspec, rp, mri, left - dx,
808 top - dy, right - dx, bottom - dy);
809 break;
811 case IST_BOOPSI:
812 break;
814 case IST_BRUSH:
815 if (state < 0 || state > 1)
816 state = 0;
817 if (spec->u.brush.dt[state])
819 const char *straddr;
820 long len;
821 straddr = *(spec->u.brush.filename);
822 len = strlen(straddr);
823 if (len > 4)
825 if (strcmp(&straddr[len - 4], ".mim") == 0)
827 dt_put_mim_on_rastport(spec->u.brush.dt[0],
828 mri->mri_RastPort, left - dx, top - dy, state);
829 break;
832 dt_put_on_rastport(spec->u.brush.dt[state], mri->mri_RastPort,
833 left - dx, top - dy);
834 /* dt_put_on_rastport_tiled(spec->u.brush.dt[state], mri->mri_RastPort, */
835 /* left, top, right, bottom, */
836 /* xoffset - left, yoffset - top); */
838 break;
840 case IST_BITMAP:
841 if (spec->u.bitmap.dt)
843 dt_put_on_rastport_tiled(spec->u.bitmap.dt, rp,
844 left - dx, top - dy, right - dx, bottom - dy,
845 xoffset - left, yoffset - top);
847 break;
849 case IST_CONFIG:
850 D(bug("*** zune_imspec_draw : IST_CONFIG\n"));
851 break;
853 case IST_SCALED_GRADIENT:
854 if (mode == 0)
855 zune_gradient_draw(spec, mri, left, top, right, bottom, 0, 0);
856 else
857 zune_gradient_drawfast(spec, rp, mri, 1, abs_l, abs_t, abs_r,
858 abs_b, left, top, right, bottom, xoffset, yoffset);
859 break;
861 case IST_TILED_GRADIENT:
862 if (mode == 0)
863 zune_gradient_draw(spec, mri, left, top, right, bottom, xoffset,
864 yoffset);
865 else
866 zune_gradient_drawfast(spec, rp, mri, 1, abs_l, abs_t, abs_r,
867 abs_b, left, top, right, bottom, xoffset, yoffset);
868 break;
872 void zune_imspec_draw(struct MUI_ImageSpec_intern *spec,
873 struct MUI_RenderInfo *mri, LONG left, LONG top, LONG width,
874 LONG height, LONG xoffset, LONG yoffset, LONG state)
876 zune_imspec_drawbuffered(spec, mri->mri_RastPort, mri, left, top, width,
877 height, xoffset, yoffset, state, 0, 0, 0, left, top, left + width,
878 top + height);
881 /**************************************************************************
882 Duplicates an image spec. In 'in' may be one of the MUII_#? identifiers
883 (but it will always return a string).
884 The returned string must be freed with zune_image_spec_free() because
885 in the future it might be that the MUII_#? stuff is not converted to
886 a string
887 **************************************************************************/
888 STRPTR zune_image_spec_duplicate(IPTR in)
890 char *spec;
891 char spec_buf[20];
893 if (in >= MUII_WindowBack && in < MUII_BACKGROUND)
895 sprintf(spec_buf, "6:%ld", in);
896 spec = spec_buf;
898 else
900 if (in >= MUII_BACKGROUND && in < MUII_LASTPAT)
902 sprintf(spec_buf, "0:%ld", in);
903 spec = spec_buf;
905 else
906 spec = (char *)in;
909 return StrDup(spec);
912 /**************************************************************************
913 Use this function to free the zune_image_spec_duplicate() result
914 **************************************************************************/
915 void zune_image_spec_free(CONST_STRPTR spec)
917 if (spec)
918 FreeVec((APTR) spec);