Safer handling of Booleans.
[AROS.git] / workbench / libs / muimaster / imspec.c
blob05273412613ad1f2fe6909fa47c85f16b5fcbc6c
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 /* bug : never called in textengine, fix this */
569 void zune_imspec_cleanup(struct MUI_ImageSpec_intern *spec)
571 if (!spec)
572 return;
574 D(bug("zune_imspec_cleanup(0x%lx) [%s]\n",
575 spec, zune_imspec_to_string(spec)));
577 switch (spec->type)
579 case IST_PATTERN:
580 break;
582 case IST_VECTOR:
583 break;
585 case IST_COLOR:
586 zune_penspec_cleanup(&spec->u.penspec);
587 break;
589 case IST_BOOPSI:
590 break;
592 case IST_BRUSH:
594 int i;
596 for (i = 0; i < 2; i++)
598 if (spec->u.brush.filename[i])
600 dt_dispose_picture(spec->u.brush.dt[i]);
602 spec->u.brush.dt[i] = NULL;
604 break;
606 case IST_BITMAP:
607 if (spec->u.bitmap.dt)
609 dt_dispose_picture(spec->u.bitmap.dt);
610 spec->u.bitmap.dt = NULL;
612 break;
614 case IST_CONFIG:
615 D(bug("*** zune_imspec_cleanup : IST_CONFIG\n"));
616 break;
618 case IST_SCALED_GRADIENT:
619 case IST_TILED_GRADIENT:
620 zune_gradientspec_cleanup(spec);
621 break;
625 zune_imspec_free(spec);
629 BOOL zune_imspec_askminmax(struct MUI_ImageSpec_intern *spec,
630 struct MUI_MinMax *minmax)
632 if ((!spec) || (!minmax))
633 return FALSE;
635 switch (spec->type)
637 case IST_PATTERN:
638 case IST_SCALED_GRADIENT:
639 case IST_TILED_GRADIENT:
640 case IST_COLOR:
641 minmax->MinWidth = 3;
642 minmax->MinHeight = 3;
643 minmax->DefWidth = 8;
644 minmax->DefHeight = 8;
645 minmax->MaxWidth = MUI_MAXMAX;
646 minmax->MaxHeight = MUI_MAXMAX;
647 break;
649 case IST_VECTOR:
650 return zune_imspec_vector_get_minmax(spec, minmax);
651 break;
653 case IST_BOOPSI:
654 /* ??? */
655 break;
657 case IST_BRUSH:
658 if (spec->u.brush.dt[0])
660 const char *straddr;
661 long len;
662 straddr = *(spec->u.brush.filename);
663 len = strlen(straddr);
664 if (len > 4)
666 if (strcmp(&straddr[len - 4], ".mim") == 0)
668 minmax->MinWidth = dt_width(spec->u.brush.dt[0]) >> 1;
669 minmax->MinHeight = dt_height(spec->u.brush.dt[0]);
670 minmax->DefWidth = minmax->MinWidth;
671 minmax->DefHeight = minmax->MinHeight;
672 minmax->MaxWidth = minmax->MinWidth;
673 minmax->MaxHeight = minmax->MinHeight;
674 break;
677 minmax->MinWidth = dt_width(spec->u.brush.dt[0]);
678 minmax->MinHeight = dt_height(spec->u.brush.dt[0]);
679 minmax->DefWidth = minmax->MinWidth;
680 minmax->DefHeight = minmax->MinHeight;
681 minmax->MaxWidth = minmax->MinWidth;
682 minmax->MaxHeight = minmax->MinHeight;
684 else
686 minmax->MinWidth = 3;
687 minmax->MinHeight = 3;
688 minmax->DefWidth = 8;
689 minmax->DefHeight = 8;
690 minmax->MaxWidth = MUI_MAXMAX;
691 minmax->MaxHeight = MUI_MAXMAX;
692 return FALSE;
694 break;
696 case IST_BITMAP:
697 minmax->MinWidth = 3;
698 minmax->MinHeight = 3;
699 minmax->DefWidth = dt_width(spec->u.bitmap.dt);
700 minmax->DefHeight = dt_height(spec->u.bitmap.dt);
701 minmax->MaxWidth = MUI_MAXMAX;
702 minmax->MaxHeight = MUI_MAXMAX;
703 if (!spec->u.bitmap.dt)
704 return FALSE;
705 break;
707 case IST_CONFIG:
708 D(bug("*** zune_imspec_askminmax : IST_CONFIG\n"));
709 break;
711 return TRUE;
715 void zune_imspec_show(struct MUI_ImageSpec_intern *spec, Object *obj)
717 if ((!spec) || (!obj))
718 return;
720 D(bug("zune_imspec_show(0x%lx) [%s]\n", spec,
721 zune_imspec_to_string(spec)));
723 /* scaled gradient generation made here */
724 switch (spec->type)
726 case IST_CONFIG:
727 D(bug("*** zune_imspec_show : IST_CONFIG\n"));
728 break;
730 case IST_SCALED_GRADIENT:
731 case IST_TILED_GRADIENT:
732 spec->u.gradient.obj = obj;
733 break;
735 default:
736 break;
741 void zune_imspec_hide(struct MUI_ImageSpec_intern *spec)
743 if (!spec)
744 return;
746 D(bug("zune_imspec_hide(0x%lx) [%s]\n", spec,
747 zune_imspec_to_string(spec)));
749 switch (spec->type)
751 case IST_CONFIG:
752 D(bug("*** zune_imspec_hide : IST_CONFIG\n"));
753 break;
754 default:
755 break;
760 void zune_imspec_drawbuffered(struct MUI_ImageSpec_intern *spec,
761 struct RastPort *rp, struct MUI_RenderInfo *mri, LONG left, LONG top,
762 LONG width, LONG height, LONG xoffset, LONG yoffset, LONG state,
763 LONG dx, LONG dy, WORD mode, LONG abs_l, LONG abs_t, LONG abs_r,
764 LONG abs_b)
766 LONG right = left + width - 1;
767 LONG bottom = top + height - 1;
768 struct MUI_ImageSpec_intern def;
770 if (!spec)
772 D(bug("*** zune_imspec_draw called on null imspec\n"));
773 return;
776 if ((spec->type == IST_BITMAP && !spec->u.bitmap.dt)
777 || (spec->type == IST_BRUSH && !spec->u.brush.dt[0]))
779 def.type = IST_COLOR;
780 zune_penspec_fill_muipen(&def.u.penspec, MPEN_BACKGROUND);
781 spec = &def;
784 switch (spec->type)
786 case IST_PATTERN:
788 LONG fg = mri->mri_Pens[patternPens[spec->u.pattern].fg];
789 LONG bg = mri->mri_Pens[patternPens[spec->u.pattern].bg];
790 SetDrMd(rp, JAM2);
791 SetAPen(rp, fg);
792 SetBPen(rp, bg);
793 SetAfPt(rp, patternPens[spec->u.pattern].pattern, 1);
794 RectFill(rp, left - dx, top - dy, right - dx, bottom - dy);
795 SetAfPt(rp, NULL, 0);
797 break;
799 case IST_VECTOR:
800 if (spec->u.vect.draw)
802 spec->u.vect.draw(mri, left - dx, top - dy, width, height,
803 state);
805 break;
807 case IST_COLOR:
808 zune_penspec_drawdirect(&spec->u.penspec, rp, mri, left - dx,
809 top - dy, right - dx, bottom - dy);
810 break;
812 case IST_BOOPSI:
813 break;
815 case IST_BRUSH:
816 if (state < 0 || state > 1)
817 state = 0;
818 if (spec->u.brush.dt[state])
820 const char *straddr;
821 long len;
822 straddr = *(spec->u.brush.filename);
823 len = strlen(straddr);
824 if (len > 4)
826 if (strcmp(&straddr[len - 4], ".mim") == 0)
828 dt_put_mim_on_rastport(spec->u.brush.dt[0],
829 mri->mri_RastPort, left - dx, top - dy, state);
830 break;
833 dt_put_on_rastport(spec->u.brush.dt[state], mri->mri_RastPort,
834 left - dx, top - dy);
835 /* dt_put_on_rastport_tiled(spec->u.brush.dt[state], mri->mri_RastPort, */
836 /* left, top, right, bottom, */
837 /* xoffset - left, yoffset - top); */
839 break;
841 case IST_BITMAP:
842 if (spec->u.bitmap.dt)
844 dt_put_on_rastport_tiled(spec->u.bitmap.dt, rp,
845 left - dx, top - dy, right - dx, bottom - dy,
846 xoffset - left, yoffset - top);
848 break;
850 case IST_CONFIG:
851 D(bug("*** zune_imspec_draw : IST_CONFIG\n"));
852 break;
854 case IST_SCALED_GRADIENT:
855 if (mode == 0)
856 zune_gradient_draw(spec, mri, left, top, right, bottom, 0, 0);
857 else
858 zune_gradient_drawfast(spec, rp, mri, 1, abs_l, abs_t, abs_r,
859 abs_b, left, top, right, bottom, xoffset, yoffset);
860 break;
862 case IST_TILED_GRADIENT:
863 if (mode == 0)
864 zune_gradient_draw(spec, mri, left, top, right, bottom, xoffset,
865 yoffset);
866 else
867 zune_gradient_drawfast(spec, rp, mri, 1, abs_l, abs_t, abs_r,
868 abs_b, left, top, right, bottom, xoffset, yoffset);
869 break;
873 void zune_imspec_draw(struct MUI_ImageSpec_intern *spec,
874 struct MUI_RenderInfo *mri, LONG left, LONG top, LONG width,
875 LONG height, LONG xoffset, LONG yoffset, LONG state)
877 zune_imspec_drawbuffered(spec, mri->mri_RastPort, mri, left, top, width,
878 height, xoffset, yoffset, state, 0, 0, 0, left, top, left + width,
879 top + height);
882 /**************************************************************************
883 Duplicates an image spec. In 'in' may be one of the MUII_#? identifiers
884 (but it will always return a string).
885 The returned string must be freed with zune_image_spec_free() because
886 in the future it might be that the MUII_#? stuff is not converted to
887 a string
888 **************************************************************************/
889 STRPTR zune_image_spec_duplicate(IPTR in)
891 char *spec;
892 char spec_buf[20];
894 if (in >= MUII_WindowBack && in < MUII_BACKGROUND)
896 sprintf(spec_buf, "6:%ld", in);
897 spec = spec_buf;
899 else
901 if (in >= MUII_BACKGROUND && in < MUII_LASTPAT)
903 sprintf(spec_buf, "0:%ld", in);
904 spec = spec_buf;
906 else
907 spec = (char *)in;
910 return StrDup(spec);
913 /**************************************************************************
914 Use this function to free the zune_image_spec_duplicate() result
915 **************************************************************************/
916 void zune_image_spec_free(CONST_STRPTR spec)
918 if (spec)
919 FreeVec((APTR) spec);