Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / c / Decoration / decoration.c
blobdd7c8ff56c485bd7e0ea979f66b56e0b6a8b6e4a
1 /*
2 Copyright 1995-2007, The AROS Development Team.
3 $Id$
4 */
6 /******************************************************************************
8 NAME
10 Decoration
12 SYNOPSIS
14 (N/A)
16 LOCATION
18 Sys:C
20 FUNCTION
22 Allows user definable skins for the intuition windows, menus and gadgets.
24 NOTES
26 Must be launched before Wanderer - usually in the S:startup-sequence
28 BUGS
30 SEE ALSO
32 IPREFS
34 INTERNALS
36 ******************************************************************************/
38 #include <clib/alib_protos.h>
40 #include <proto/exec.h>
41 #include <proto/dos.h>
42 #include <proto/graphics.h>
43 #include <proto/layers.h>
44 #include <proto/intuition.h>
45 #include <proto/utility.h>
46 #include <proto/cybergraphics.h>
47 #include <proto/datatypes.h>
49 #include <dos/dos.h>
50 #include <intuition/classusr.h>
51 #include <intuition/classes.h>
52 #include <intuition/windecorclass.h>
53 #include <intuition/scrdecorclass.h>
54 #include <intuition/menudecorclass.h>
55 #include <intuition/extensions.h>
56 #include <intuition/intuitionbase.h>
57 #include <graphics/rpattr.h>
58 #include <graphics/gfxmacros.h>
59 #include <libraries/mui.h>
60 #include <libraries/cybergraphics.h>
61 #include <datatypes/pictureclass.h>
62 #include <utility/tagitem.h>
64 #include <string.h>
66 #include <aros/debug.h>
67 #include <aros/detach.h>
69 #include "stdlib.h"
70 #include "stdio.h"
71 #include "string.h"
72 #include "math.h"
74 /**************************************************************************************************/
76 #define PUTIMAGE_WIN(id) data->img_##id=data->sd->img_##id
77 #define PUTIMAGE_MEN(id) data->img_##id=data->sd->img_##id
79 #define SETIMAGE_SCR(id) SetImage(data->img_##id, &sd->img_##id, truecolor, screen)
80 #define SETIMAGE_WIN(id) wd->img_##id=&sd->img_##id
81 #define SETIMAGE_MEN(id) md->img_##id=&sd->img_##id
83 #define DELIMAGE_SCR(id) RemoveLUTImage(&sd->img_##id)
85 #if AROS_BIG_ENDIAN
86 #define GET_A(rgb) ((rgb >> 24) & 0xff)
87 #define GET_R(rgb) ((rgb >> 16) & 0xff)
88 #define GET_G(rgb) ((rgb >> 8) & 0xff)
89 #define GET_B(rgb) (rgb & 0xff)
90 #define SET_ARGB(a, r, g, b) a << 24 | r << 16 | g << 8 | b
91 #else
92 #define GET_A(rgb) (rgb & 0xff)
93 #define GET_R(rgb) ((rgb >> 8) & 0xff)
94 #define GET_G(rgb) ((rgb >> 16) & 0xff)
95 #define GET_B(rgb) ((rgb >> 24) & 0xff)
96 #define SET_ARGB(a, r, g, b) b << 24 | g << 16 | r << 8 | a
97 #endif
99 #define MDA_Configuration 0x10002
100 #define SDA_Configuration 0x20002
101 #define WDA_Configuration 0x30002
103 #define MDA_ScreenData 0x10003
104 #define SDA_ScreenData 0x20003
105 #define WDA_ScreenData 0x30003
107 struct IClass *cl, *scrcl, *menucl;
109 struct NewImage
111 UWORD w;
112 UWORD h;
113 BOOL istiled;
114 ULONG *data;
115 UWORD tile_left, tile_top, tile_bottom, tile_right;
116 UWORD inner_left, inner_top, inner_bottom, inner_right;
117 APTR mask;
118 Object *o;
119 struct BitMap *bitmap;
120 BOOL ok;
121 STRPTR filename;
125 struct NewLUT8Image
127 UWORD w;
128 UWORD h;
129 UBYTE *data;
132 /**************************************************************************************************/
133 struct scrdecor_data
136 struct NewImage *img_sdepth;
137 struct NewImage *img_sbarlogo;
138 struct NewImage *img_stitlebar;
140 struct NewImage *img_size;
141 struct NewImage *img_close;
142 struct NewImage *img_depth;
143 struct NewImage *img_zoom;
144 struct NewImage *img_up;
145 struct NewImage *img_down;
146 struct NewImage *img_left;
147 struct NewImage *img_right;
148 struct NewImage *img_mui;
149 struct NewImage *img_popup;
150 struct NewImage *img_snapshot;
151 struct NewImage *img_iconify;
152 struct NewImage *img_lock;
153 struct NewImage *img_winbar_normal;
154 struct NewImage *img_border_normal;
155 struct NewImage *img_border_deactivated;
156 struct NewImage *img_verticalcontainer;
157 struct NewImage *img_verticalknob;
158 struct NewImage *img_horizontalcontainer;
159 struct NewImage *img_horizontalknob;
161 struct NewImage *img_menu;
162 struct NewImage *img_amigakey;
163 struct NewImage *img_menucheck;
164 struct NewImage *img_submenu;
166 UWORD sbarheight;
167 UWORD slogo_off;
168 UWORD stitle_off;
169 UWORD winbarheight;
171 BOOL outline;
172 BOOL shadow;
174 int leftborder, bottomborder, rightborder;
175 int lut_col_a, lut_col_d;
176 int text_col, shadow_col;
182 struct windecor_data
184 struct scrdecor_data *sd;
185 struct DrawInfo *dri;
186 struct Screen *scr;
187 struct NewImage *img_size;
188 struct NewImage *img_close;
189 struct NewImage *img_depth;
190 struct NewImage *img_zoom;
191 struct NewImage *img_up;
192 struct NewImage *img_down;
193 struct NewImage *img_left;
194 struct NewImage *img_right;
195 struct NewImage *img_mui;
196 struct NewImage *img_popup;
197 struct NewImage *img_snapshot;
198 struct NewImage *img_iconify;
199 struct NewImage *img_lock;
200 struct NewImage *img_winbar_normal;
201 struct NewImage *img_border_normal;
202 struct NewImage *img_border_deactivated;
203 struct NewImage *img_verticalcontainer;
204 struct NewImage *img_verticalknob;
205 struct NewImage *img_horizontalcontainer;
206 struct NewImage *img_horizontalknob;
208 BOOL outline;
209 BOOL shadow;
210 BOOL barmasking;
211 BOOL closeright;
212 BOOL threestate;
213 BOOL barvert;
214 BOOL usegradients;
215 BOOL rounded;
216 BOOL filltitlebar;
218 UWORD winbarheight;
219 UWORD txt_align;
221 int BarJoinTB_o;
222 int BarJoinTB_s;
223 int BarPreGadget_o;
224 int BarPreGadget_s;
225 int BarPre_o;
226 int BarPre_s;
227 int BarLGadgetFill_o;
228 int BarLGadgetFill_s;
229 int BarJoinGB_o;
230 int BarJoinGB_s;
231 int BarLFill_o;
232 int BarLFill_s;
233 int BarJoinBT_o;
234 int BarJoinBT_s;
235 int BarTitleFill_o;
236 int BarTitleFill_s;
237 int BarRFill_o;
238 int BarRFill_s;
239 int BarJoinBG_o;
240 int BarJoinBG_s;
241 int BarRGadgetFill_o;
242 int BarRGadgetFill_s;
243 int BarPostGadget_o;
244 int BarPostGadget_s;
245 int BarPost_o;
246 int BarPost_s;
248 int ContainerTop_o, ContainerTop_s;
249 int ContainerVertTile_o, ContainerVertTile_s;
250 int ContainerBottom_o, ContainerBottom_s;
251 int KnobTop_o, KnobTop_s;
252 int KnobTileTop_o, KnobTileTop_s;
253 int KnobVertGripper_o, KnobVertGripper_s;
254 int KnobTileBottom_o, KnobTileBottom_s;
255 int KnobBottom_o, KnobBottom_s;
256 int ContainerLeft_o, ContainerLeft_s;
257 int ContainerHorTile_o, ContainerHorTile_s;
258 int ContainerRight_o, ContainerRight_s;
259 int KnobLeft_o, KnobLeft_s;
260 int KnobTileLeft_o, KnobTileLeft_s;
261 int KnobHorGripper_o, KnobHorGripper_s;
262 int KnobTileRight_o, KnobTileRight_s;
263 int KnobRight_o, KnobRight_s;
264 int sizeaddx, sizeaddy;
265 int updownaddx, updownaddy;
266 int leftrightaddx, leftrightaddy;
267 int rightbordergads, bottombordergads;
268 int rightbordernogads, bottombordernogads;
269 int horscrollerheight;
270 int scrollerinnerspacing;
271 int a_arc, d_arc;
272 int a_col_s, a_col_e;
273 int d_col_s, d_col_e;
274 int b_col_a, b_col_d;
275 int light, middle, dark;
276 int text_col, shadow_col;
280 struct menudecor_data
282 struct scrdecor_data *sd;
284 struct DrawInfo *dri;
285 struct Screen *scr;
286 struct NewImage *img_menu;
287 struct NewImage *img_amigakey;
288 struct NewImage *img_menucheck;
289 struct NewImage *img_submenu;
292 struct WindowData
294 struct NewImage *ni;
296 struct NewImage *img_size;
297 struct NewImage *img_close;
298 struct NewImage *img_depth;
299 struct NewImage *img_zoom;
300 struct NewImage *img_up;
301 struct NewImage *img_down;
302 struct NewImage *img_left;
303 struct NewImage *img_right;
304 struct NewImage *img_mui;
305 struct NewImage *img_popup;
306 struct NewImage *img_snapshot;
307 struct NewImage *img_iconify;
308 struct NewImage *img_lock;
309 struct NewImage *img_winbar_normal;
310 struct NewImage *img_border_normal;
311 struct NewImage *img_border_deactivated;
312 struct NewImage *img_verticalcontainer;
313 struct NewImage *img_verticalknob;
314 struct NewImage *img_horizontalcontainer;
315 struct NewImage *img_horizontalknob;
317 struct RastPort *rp;
318 UWORD w, h;
319 LONG ActivePen;
320 LONG DeactivePen;
322 WORD closewidth, depthwidth, zoomwidth;
323 BOOL truecolor;
327 struct MenuData
329 struct NewImage *ni;
330 struct BitMap *map;
332 struct NewImage *img_menu;
333 struct NewImage *img_amigakey;
334 struct NewImage *img_menucheck;
335 struct NewImage *img_submenu;
336 LONG ActivePen;
337 LONG DeactivePen;
338 BOOL truecolor;
343 struct ScreenData
345 struct NewImage img_sdepth;
346 struct NewImage img_sbarlogo;
347 struct NewImage img_stitlebar;
349 struct NewImage img_size;
350 struct NewImage img_close;
351 struct NewImage img_depth;
352 struct NewImage img_zoom;
353 struct NewImage img_up;
354 struct NewImage img_down;
355 struct NewImage img_left;
356 struct NewImage img_right;
357 struct NewImage img_mui;
358 struct NewImage img_popup;
359 struct NewImage img_snapshot;
360 struct NewImage img_iconify;
361 struct NewImage img_lock;
362 struct NewImage img_winbar_normal;
363 struct NewImage img_border_normal;
364 struct NewImage img_border_deactivated;
365 struct NewImage img_verticalcontainer;
366 struct NewImage img_verticalknob;
367 struct NewImage img_horizontalcontainer;
368 struct NewImage img_horizontalknob;
370 struct NewImage img_menu;
371 struct NewImage img_amigakey;
372 struct NewImage img_menucheck;
373 struct NewImage img_submenu;
374 LONG ActivePen;
375 LONG DeactivePen;
376 BOOL truecolor;
380 struct myrgb
382 int red,green,blue;
385 BOOL InitWindowSkinning(STRPTR path, struct windecor_data *data);
386 BOOL InitMenuSkinning(STRPTR path, struct menudecor_data *data);
387 BOOL InitScreenSkinning(STRPTR path, struct scrdecor_data *data);
388 void DisposeWindowSkinning(struct windecor_data *data);
389 void DisposeMenuSkinning(struct menudecor_data *data);
390 void DisposeScreenSkinning(struct scrdecor_data *data);
392 void DrawTileToRP(struct RastPort *rp, struct NewImage *ni, ULONG col, UWORD offx, UWORD offy, UWORD x, UWORD y, WORD w, WORD h);
393 void DrawPartialTitleBar(struct WindowData *wd, struct windecor_data * data, struct Window *win, struct RastPort *dst_rp, struct DrawInfo *dri, UWORD align, UWORD start, UWORD width, UWORD *pens);
395 static Object *LoadPicture(CONST_STRPTR filename, struct Screen *scr)
397 Object *o;
400 o = NewDTObject((APTR)filename,
401 DTA_GroupID , GID_PICTURE,
402 OBP_Precision , PRECISION_EXACT,
403 PDTA_Screen , (IPTR)scr,
404 PDTA_FreeSourceBitMap, TRUE,
405 PDTA_DestMode , PMODE_V43,
406 PDTA_UseFriendBitMap , TRUE,
407 TAG_DONE);
410 if (o)
412 struct BitMapHeader *bmhd;
414 GetDTAttrs(o,PDTA_BitMapHeader, (IPTR)&bmhd, TAG_DONE);
416 struct FrameInfo fri = {0};
418 D(bug("DTM_FRAMEBOX\n", o));
419 DoMethod(o,DTM_FRAMEBOX,NULL,(IPTR)&fri,(IPTR)&fri,sizeof(struct FrameInfo),0);
421 if (fri.fri_Dimensions.Depth>0)
423 D(bug("DTM_PROCLAYOUT\n", o));
424 if (DoMethod(o,DTM_PROCLAYOUT,NULL,1))
426 return o;
429 DisposeDTObject(o);
431 return NULL;
435 void SetImage(struct NewImage *in, struct NewImage *out, BOOL truecolor, struct Screen* scr)
437 out->ok = FALSE;
438 if (in != NULL)
440 out->w = in->w;
441 out->h = in->h;
442 out->istiled = in->istiled;
443 out->data = in->data;
444 out->tile_left = in->tile_left;
445 out->tile_right = in->tile_right;
446 out->tile_top = in->tile_top;
447 out->tile_bottom = in->tile_bottom;
448 out->inner_left = in->inner_left;
449 out->inner_right = in->inner_right;
450 out->inner_top = in->inner_top;
451 out->inner_bottom = in->inner_bottom;
452 out->bitmap = NULL;
453 out->mask = NULL;
454 out->o = NULL;
455 out->ok = (in->data != NULL) ? TRUE : FALSE;
456 if (!truecolor)
458 out->ok = FALSE;
459 STRPTR file = AllocVec(strlen(in->filename) + 5, MEMF_ANY | MEMF_CLEAR);
460 if (file != NULL)
462 strcpy(file, in->filename);
463 strcat(file, "_LUT");
464 out->o = LoadPicture(file, scr);
465 FreeVec(file);
467 out->filename = in->filename;
468 if (out->o == NULL) out->o = LoadPicture(in->filename, scr);
469 if (out->o)
471 GetDTAttrs(out->o, PDTA_DestBitMap, (IPTR)&out->bitmap, TAG_DONE);
472 if (out->bitmap == NULL) GetDTAttrs(out->o, PDTA_BitMap, (IPTR)&out->bitmap, TAG_DONE);
474 if (out->bitmap) GetDTAttrs(out->o, PDTA_MaskPlane, (IPTR)&out->mask, TAG_DONE);
475 if (out->bitmap == NULL)
477 DisposeDTObject(out->o);
478 out->o = NULL;
479 } else out->ok = TRUE;
485 void RemoveLUTImage(struct NewImage *ni)
487 if (ni)
489 if (ni->ok)
491 if (ni->o) DisposeDTObject(ni->o);
492 ni->o = NULL;
493 ni->bitmap = NULL;
494 ni->mask = NULL;
499 void DrawAlphaStateImageToRP(struct windecor_data *data, struct RastPort *rp, struct NewImage *ni, ULONG state, UWORD xp, UWORD yp, BOOL multiple)
502 UWORD ix, iy, dx;
503 UBYTE *d;
505 int images = (data == NULL) ? 2 : data->threestate ? 3 : 4;
507 if (ni->ok)
509 dx = 0;
510 d = (UBYTE *) ni->data;
511 ix=ni->w;
512 iy=ni->h;
513 if (multiple)
515 switch(state)
517 case IDS_NORMAL:
518 break;
519 case IDS_SELECTED:
520 dx += ix / images;
521 d += ix / images * 4;
522 break;
523 case IDS_INACTIVENORMAL:
524 dx += ix / images * 2;
525 d += ix / images * 8;
526 break;
529 else
530 images = 1;
532 if (ni->bitmap == NULL)
534 WritePixelArrayAlpha(d, 0 , 0, ix*4, rp, xp, yp, ix / images, iy, 0xffffffff);
536 else
538 if (ni->mask)
540 BltMaskBitMapRastPort(ni->bitmap, dx, 0, rp, xp, yp, ix / images, iy, 0xe0, (PLANEPTR) ni->mask);
542 else BltBitMapRastPort(ni->bitmap, dx, 0, rp, xp, yp, ix / images, iy, 0xc0);
547 void DrawPartImageToRP(struct RastPort *rp, struct NewImage *ni, UWORD x, UWORD y, UWORD sx, UWORD sy, UWORD sw, UWORD sh)
549 if (ni->ok)
551 if (ni->bitmap == NULL)
553 WritePixelArray(ni->data, sx, sy, ni->w*4, rp, x, y, sw, sh, RECTFMT_ARGB);
555 else
557 BltBitMapRastPort(ni->bitmap, sx, sy, rp, x, y, sw, sh, 0xc0);
562 void DisposeImageContainer(struct NewImage *ni)
564 if (ni)
566 if (ni->data)
568 FreeVec(ni->data);
570 if (ni->o) DisposeDTObject(ni->o);
571 if (ni->filename) FreeVec(ni->filename);
572 FreeVec(ni);
576 void DisposeLUT8ImageContainer(struct NewLUT8Image *ni)
578 if (ni)
580 if (ni->data)
582 FreeVec(ni->data);
584 FreeVec(ni);
588 struct NewLUT8Image *NewLUT8ImageContainer(UWORD w, UWORD h)
590 struct NewLUT8Image *ni;
592 ni = AllocVec(sizeof(struct NewLUT8Image), MEMF_ANY | MEMF_CLEAR);
593 if (ni)
595 ni->w = w;
596 ni->h = h;
597 ni->data = AllocVec(w * h, MEMF_ANY | MEMF_CLEAR);
598 if (ni->data == NULL)
600 FreeVec(ni);
601 ni = NULL;
604 return ni;
607 struct NewImage *NewImageContainer(UWORD w, UWORD h)
609 struct NewImage *ni;
611 ni = AllocVec(sizeof(struct NewImage), MEMF_ANY | MEMF_CLEAR);
612 if (ni)
614 ni->w = w;
615 ni->h = h;
616 ni->data = AllocVec(w * h * sizeof (ULONG), MEMF_ANY | MEMF_CLEAR);
617 if (ni->data == NULL)
619 FreeVec(ni);
620 ni = NULL;
623 return ni;
626 struct NewImage *GetImageFromFile(STRPTR path, STRPTR name, BOOL fixmode)
628 struct BitMapHeader *bmhd;
629 struct NewImage *ni = NULL;
630 struct BitMap *map = NULL;
631 struct RastPort *rp = NULL;
632 Object *pic;
633 struct pdtBlitPixelArray pa;
634 char Buffer[256];
635 UWORD w, h, tc, x, y;
636 UBYTE mask;
637 ULONG a;
638 ULONG *dst;
640 if (fixmode)
642 strcpy(Buffer, name);
643 strcat(Buffer, "Default");
645 else
646 strcpy(Buffer, name);
648 pic = NewDTObject(Buffer, DTA_SourceType, DTST_FILE,
649 DTA_GroupID, GID_PICTURE,
650 PDTA_Remap, FALSE,
651 PDTA_DestMode, PMODE_V43,
652 TAG_DONE);
653 if (pic)
656 get(pic, PDTA_BitMapHeader, &bmhd);
657 if(bmhd)
660 w = bmhd->bmh_Width;
661 h = bmhd->bmh_Height;
662 mask = bmhd->bmh_Masking;
663 ni = NewImageContainer(w, h);
664 if (ni)
666 int len = strlen(path) + strlen(Buffer) +2;
667 ni->filename = AllocVec(len, MEMF_CLEAR | MEMF_ANY);
668 if (ni->filename != NULL)
670 strncpy(ni->filename, path, len);
671 AddPart(ni->filename, Buffer, len);
673 pa.MethodID = PDTM_READPIXELARRAY;
674 pa.pbpa_PixelData = (APTR) ni->data;
675 pa.pbpa_PixelFormat = PBPAFMT_ARGB;
676 pa.pbpa_PixelArrayMod = w*4;
677 pa.pbpa_Left = 0;
678 pa.pbpa_Top = 0;
679 pa.pbpa_Width = w;
680 pa.pbpa_Height = h;
681 DoMethodA(pic, (Msg) &pa);
682 ni->ok = TRUE;
683 if (bmhd->bmh_Depth <= 8)
685 get(pic, PDTA_BitMap, &map);
686 if (map && (mask == mskHasTransparentColor))
688 rp = CreateRastPort();
689 if (rp) rp->BitMap = map;
690 tc = bmhd->bmh_Transparent;
694 if (rp)
696 dst = ni->data;
697 for (y = 0; y < h; y++)
699 for (x = 0; x < w; x++)
701 #if !AROS_BIG_ENDIAN
702 if (ReadPixel(rp, x, y) == 0) dst[x+y*w] &= 0xffffff00; else dst[x+y*w] |= 0x000000ff;
703 #else
704 if (ReadPixel(rp, x, y) == 0) dst[x+y*w] &= 0x00ffffff; else dst[x+y*w] |= 0xff000000;
705 #endif
708 FreeRastPort(rp);
710 else
713 if (mask != mskHasAlpha)
715 #if !AROS_BIG_ENDIAN
716 for (a= 0; a < (w*h); a++) ni->data[a] |= 0x000000ff;
717 #else
718 for (a= 0; a < (w*h); a++) ni->data[a] |= 0xff000000;
719 #endif
723 else
725 DisposeImageContainer(ni);
726 ni = NULL;
731 DisposeDTObject(pic);
734 return ni;
737 struct NewImage *GetImageFromRP(struct RastPort *rp, UWORD x, UWORD y, UWORD w, UWORD h)
739 struct NewImage *ni;
741 ni = NewImageContainer(w, h);
742 if (ni)
744 ReadPixelArray(ni->data, 0, 0, w*4, rp, x, y, w, h, RECTFMT_ARGB);
746 return ni;
749 void PutImageToRP(struct RastPort *rp, struct NewImage *ni, UWORD x, UWORD y) {
751 if (ni)
753 if (ni->data) WritePixelArray(ni->data, 0, 0, ni->w*4, rp, x, y, ni->w, ni->h, RECTFMT_ARGB);
754 DisposeImageContainer(ni);
758 /* the following code is taken from zune sources and modified */
760 void FillPixelArrayGradientDelta(LONG pen, BOOL tc, struct RastPort *rp, int xt, int yt, int xb, int yb, int xp, int yp, int w, int h, ULONG start_rgb, ULONG end_rgb, int angle, int dx, int dy)
763 /* The basic idea of this algorithm is to calc the intersection between the
764 * diagonal of the rectangle (xs,ys) with dimension (xw,yw) a with the line starting
765 * at (x,y) (every pixel inside the rectangle) and angle angle with direction vector (vx,vy).
767 * Having the intersection point we then know the color of the pixel.
769 * TODO: Turn the algorithm into a incremental one
770 * Remove the use of floating point variables
772 double rad = angle*M_PI/180;
773 double cosarc = cos(rad);
774 double sinarc = sin(rad);
776 struct myrgb startRGB,endRGB;
778 int diffR, diffG, diffB;
780 int r,t; /* some helper variables to short the code */
781 int l,y,c,x;
782 int y1; /* The intersection point */
783 int incr_y1; /* increment of y1 */
784 int xs,ys,xw,yw;
785 int xadd,ystart,yadd;
786 // double vx = -cosarc;
787 // double vy = sinarc;
788 int vx = (int)(-cosarc*0xff);
789 int vy = (int)(sinarc*0xff);
791 int width = xb - xt + 1;
792 int height = yb - yt + 1;
794 if ((w <= 0) || (h <= 0)) return;
795 if (!tc)
797 if (pen != -1) SetAPen(rp, pen); else SetAPen(rp, 2);
798 RectFill(rp, xp, yp, xp + w - 1, yp + h - 1);
799 return;
802 UBYTE *buf = AllocVec(w*h*3, 0);
803 if (buf == NULL) return;
804 startRGB.red = (start_rgb >> 16) & 0xff;
805 startRGB.green = (start_rgb >> 8) & 0xff;
806 startRGB.blue = start_rgb & 0xff;
808 endRGB.red = (end_rgb >> 16) & 0xff;
809 endRGB.green = (end_rgb >> 8) & 0xff;
810 endRGB.blue = end_rgb & 0xff;
812 diffR = endRGB.red - startRGB.red;
813 diffG = endRGB.green - startRGB.green;
814 diffB = endRGB.blue - startRGB.blue;
816 /* Normalize the angle */
817 if (angle < 0) angle = 360 - ((-angle)%360);
818 if (angle >= 0) angle = angle % 360;
820 if (angle <= 90 || (angle > 180 && angle <= 270))
822 /* The to be intersected diagonal goes from the top left edge to the bottom right edge */
823 xs = 0;
824 ys = 0;
825 xw = width;
826 yw = height;
827 } else
829 /* The to be intersected diagonal goes from the bottom left edge to the top right edge */
830 xs = 0;
831 ys = height;
832 xw = width;
833 yw = -height;
836 if (angle > 90 && angle <= 270)
838 /* for these angle we have y1 = height - y1. Instead of
840 * y1 = height - (-vy*(yw* xs -xw* ys) + yw*(vy* x -vx* y)) /(-yw*vx + xw*vy);
842 * we can write
844 * y1 = (-vy*(yw*(-xs)-xw*(-ys+height)) + yw*(vy*(-x)-vx*(-y+height)))/(-yw*vx + xw*vy);
846 * so height - y1 can be expressed with the normal formular adapting some parameters.
848 * Note that if one would exchanging startRGB/endRGB the values would only work
849 * for linear color gradients
851 xadd = -1;
852 yadd = -1;
853 ystart = height;
855 xs = -xs;
856 ys = -ys + height;
858 else
860 xadd = 1;
861 yadd = 1;
862 ystart = 0;
865 r = -vy*(yw*xs-xw*ys);
866 t = -yw*vx + xw*vy;
868 /* The formular as shown above is
870 * y1 = ((-vy*(yw*xs-xw*ys) + yw*(vy*x-vx*y)) /(-yw*vx + xw*vy));
872 * We see that only yw*(vy*x-vx*y) changes during the loop.
874 * We write
876 * Current Pixel: y1(x,y) = (r + yw*(vy*x-vx*y))/t = r/t + yw*(vy*x-vx*y)/t
877 * Next Pixel: y1(x+xadd,y) = (r + vw*(vy*(x+xadd)-vx*y))/t
879 * t*(y1(x+xadd,y) - y1(x,y)) = yw*(vy*(x+xadd)-vx*y) - yw*(vy*x-vx*y) = yw*vy*xadd;
883 incr_y1 = yw*vy*xadd;
884 UBYTE *bufptr = buf;
885 for (l = 0, y = ystart + ((yp - yt)* yadd); l < h; l++, y+=yadd)
888 /* Calculate initial y1 accu, can be brought out of the loop as well (x=0). It's probably a
889 * a good idea to add here also a value of (t-1)/2 to ensure the correct rounding
890 * This (and for r) is also a place were actually a overflow can happen |yw|=16 |y|=16. So for
891 * vx nothing is left, currently 9 bits are used for vx or vy */
892 int y1_mul_t_accu = r - yw*vx*y;
896 for (c = 0, x = ((xp - xt) * xadd); c < w; c++, x+=xadd)
898 int red,green,blue;
900 /* Calculate the intersection of two lines, this is not the fastet way to do but
901 * it is intuitive. Note: very slow! Will be optimzed later (remove FFP usage
902 * and making it incremental)...update: it's now incremental and no FFP is used
903 * but it probably can be optimized more by removing some more of the divisions and
904 * further specialize the stuff here (use of three accus). */
905 /* y1 = (int)((-vy*(yw*xs-xw*ys) + yw*(vy*x-vx*y)) /(-yw*vx + xw*vy));*/
906 y1 = y1_mul_t_accu / t;
908 red = startRGB.red + (int)(diffR*y1/height);
909 green = startRGB.green + (int)(diffG*y1/height);
910 blue = startRGB.blue + (int)(diffB*y1/height);
911 /* By using full 32 bits this can be made faster as well */
912 *bufptr++ = red;
913 *bufptr++ = green;
914 *bufptr++ = blue;
916 y1_mul_t_accu += incr_y1;
918 /* By bringing building the gradient array in the same format as the RastPort BitMap a call
919 * to WritePixelArray() can be made also faster */
921 WritePixelArray(buf,0,0,w*3, rp,dx,dy,w,h,RECTFMT_RGB);
922 FreeVec(buf);
925 void FillPixelArrayGradient(LONG pen, BOOL tc, struct RastPort *rp, int xt, int yt, int xb, int yb, int xp, int yp, int w, int h, ULONG start_rgb, ULONG end_rgb, int angle)
927 FillPixelArrayGradientDelta(pen, tc, rp, xt, yt, xb, yb, xp, yp, w, h, start_rgb, end_rgb, angle, xp, yp);
931 void DrawPartToImage(struct NewImage *src, struct NewImage *dest, UWORD sx, UWORD sy, UWORD sw, UWORD sh, UWORD dx, UWORD dy)
933 UWORD x, y;
935 for (y = 0; y < sh; y++)
937 for (x = 0; x < sw; x++)
939 dest->data[dx + x + (dy + y) * dest->w] = src->data[sx + x + (sy + y) * src->w];
944 void DrawTileToImage(struct NewImage *src, struct NewImage *dest, UWORD _sx, UWORD _sy, UWORD _sw, UWORD _sh, UWORD _dx, UWORD _dy, UWORD _dw, UWORD _dh)
947 ULONG dy, dx;
948 LONG dh, height, dw, width;
950 if (src == NULL) return;
951 if (dest == NULL) return;
953 dh = _sh;
954 dy = _dy;
955 height = _dh;
957 while (height > 0)
959 if ((height-dh)<0) dh = height;
960 height -= dh;
961 dw = _sw;
962 width = _dw;
963 dx = _dx;
964 while (width > 0)
966 if ((width-dw)<0) dw = width;
967 width -= dw;
968 DrawPartToImage(src, dest, _sx, _sy, dw, dh, dx, dy);
969 dx += dw;
971 dy += dh;
975 void DrawMapTileToRP(struct NewImage *src, struct RastPort *rp, UWORD _sx, UWORD _sy, UWORD _sw, UWORD _sh, UWORD _dx, UWORD _dy, UWORD _dw, UWORD _dh)
978 ULONG dy, dx;
979 LONG dh, height, dw, width;
981 if (src == NULL) return;
982 if (rp == NULL) return;
984 dh = _sh;
985 dy = _dy;
986 height = _dh;
988 if (!src->ok) return;
990 while (height > 0)
992 if ((height-dh)<0) dh = height;
993 height -= dh;
994 dw = _sw;
995 width = _dw;
996 dx = _dx;
997 while (width > 0)
999 if ((width-dw)<0) dw = width;
1000 width -= dw;
1002 if (src->mask)
1004 BltMaskBitMapRastPort(src->bitmap, _sx, _sy, rp, dx, dy, dw, dh, 0xe0, (PLANEPTR) src->mask);
1006 else BltBitMapRastPort(src->bitmap, _sx, _sy, rp, dx, dy, dw, dh, 0xc0);
1008 dx += dw;
1010 dy += dh;
1013 /**************************************************************************************************/
1015 char *SkipChars(char *v)
1017 char *c;
1018 c = strstr(v, "=");
1019 return ++c;
1022 int GetInt(char *v)
1024 char *c;
1025 c = SkipChars(v);
1026 return (int) atol(c);
1029 void GetIntegers(char *v, int *v1, int *v2)
1031 char *c;
1032 char va1[32], va2[32];
1033 int cnt;
1034 c = SkipChars(v);
1035 if (c)
1037 cnt = sscanf(c, "%s %s", va1, va2);
1038 if (cnt == 1)
1040 *v1 = -1;
1041 *v2 = atol(va1);
1043 else if (cnt == 2)
1045 *v1 = atol(va1);
1046 *v2 = atol(va2);
1051 void GetTripleIntegers(char *v, int *v1, int *v2, int *v3)
1053 char *ch;
1054 int a, b, c;
1055 int cnt;
1056 ch = SkipChars(v);
1057 if (ch)
1059 cnt = sscanf(ch, "%x %x %d", &a, &b, &c);
1060 if (cnt == 3)
1062 *v1 = a;
1063 *v2 = b;
1064 *v3 = c;
1069 void GetColors(char *v, int *v1, int *v2)
1071 char *ch;
1072 int a, b;
1073 int cnt;
1074 ch = SkipChars(v);
1075 if (ch)
1077 cnt = sscanf(ch, "%x %x", &a, &b);
1078 if (cnt == 2)
1080 *v1 = a;
1081 *v2 = b;
1087 BOOL GetBool(char *v, char *id)
1089 if (strstr(v, id)) return TRUE; else return FALSE;
1092 static IPTR windecor_new(Class *cl, Object *obj, struct opSet *msg)
1094 struct windecor_data *data;
1096 obj = (Object *)DoSuperMethodA(cl, obj, (Msg)msg);
1097 if (obj)
1099 data = INST_DATA(cl, obj);
1101 STRPTR path = (STRPTR) GetTagData(WDA_Configuration, (IPTR) "Theme:", msg->ops_AttrList);
1102 data->sd = (struct scrdecor_data *) GetTagData(WDA_ScreenData, 0, msg->ops_AttrList);
1104 if (!InitWindowSkinning(path, data))
1106 CoerceMethod(cl,obj,OM_DISPOSE);
1107 obj = NULL;
1111 return (IPTR)obj;
1114 static IPTR windecor_dispose(Class *cl, Object *obj, struct opSet *msg)
1116 struct windecor_data *data = INST_DATA(cl, obj);
1118 DisposeWindowSkinning(data);
1120 return 1;
1122 /**************************************************************************************************/
1124 static IPTR windecor_get(Class *cl, Object *obj, struct opGet *msg)
1126 switch(msg->opg_AttrID)
1128 case WDA_TrueColorOnly:
1129 *msg->opg_Storage = TRUE;
1130 break;
1131 default:
1132 return DoSuperMethodA(cl, obj, (Msg)msg);
1134 return 1;
1137 /**************************************************************************************************/
1139 /**************************************************************************************************/
1141 IPTR windecor_draw_sysimage(Class *cl, Object *obj, struct wdpDrawSysImage *msg)
1143 struct windecor_data *data = INST_DATA(cl, obj);
1144 struct RastPort *rp = msg->wdp_RPort;
1145 struct NewImage *ni = NULL;
1146 struct WindowData *wd = (struct WindowData *) msg->wdp_UserBuffer;
1147 LONG state = msg->wdp_State;
1148 LONG left = msg->wdp_X;
1149 LONG top = msg->wdp_Y;
1150 LONG width = msg->wdp_Width;
1151 LONG height = msg->wdp_Height;
1152 WORD addx = 0;
1153 WORD addy = 0;
1154 BOOL isset = FALSE;
1155 BOOL titlegadget = FALSE;
1157 switch(msg->wdp_Which)
1159 case SIZEIMAGE:
1160 if (wd->img_size->ok)
1162 ni = wd->img_size;
1163 isset = TRUE;
1164 if (data->threestate) addx = (data->rightbordergads - (data->img_size->w / 3)) /2; else addx = (data->rightbordergads - (data->img_size->w >> 2)) /2;
1165 addy = (data->bottombordergads - data->img_size->h) / 2;
1167 break;
1169 case CLOSEIMAGE:
1170 if (wd->img_close->ok)
1172 ni = wd->img_close;
1173 isset = TRUE;
1174 titlegadget = TRUE;
1176 break;
1178 case MUIIMAGE:
1179 if (wd->img_mui->ok)
1181 ni = wd->img_mui;
1182 isset = TRUE;
1183 titlegadget = TRUE;
1185 break;
1187 case POPUPIMAGE:
1188 if (wd->img_popup->ok)
1190 ni = wd->img_popup;
1191 isset = TRUE;
1192 titlegadget = TRUE;
1194 break;
1196 case SNAPSHOTIMAGE:
1197 if (wd->img_snapshot->ok)
1199 ni = wd->img_snapshot;
1200 isset = TRUE;
1201 titlegadget = TRUE;
1203 break;
1205 case LOCKIMAGE:
1206 if (wd->img_lock->ok)
1208 ni = wd->img_lock;
1209 isset = TRUE;
1210 titlegadget = TRUE;
1212 break;
1214 case ICONIFYIMAGE:
1215 if (wd->img_iconify->ok)
1217 ni = wd->img_iconify;
1218 isset = TRUE;
1219 titlegadget = TRUE;
1221 break;
1223 case DEPTHIMAGE:
1224 if (wd->img_depth->ok)
1226 ni = wd->img_depth;
1227 isset = TRUE;
1228 titlegadget = TRUE;
1230 break;
1232 case ZOOMIMAGE:
1233 if (wd->img_zoom->ok)
1235 ni = wd->img_zoom;
1236 isset = TRUE;
1237 titlegadget = TRUE;
1239 break;
1241 case UPIMAGE:
1242 ni = wd->img_up;
1243 if (data->threestate) addx = (data->rightbordergads - (data->img_up->w / 3)) /2; else addx = (data->rightbordergads - (data->img_up->w >> 2)) /2;
1244 addy = data->updownaddy / 2;
1245 isset = TRUE;
1246 break;
1248 case DOWNIMAGE:
1249 ni = wd->img_down;
1250 if (data->threestate) addx = (data->rightbordergads - (data->img_down->w / 3)) /2; else addx = (data->rightbordergads - (data->img_down->w >> 2)) /2;
1251 addy = data->updownaddy / 2;
1252 isset = TRUE;
1253 break;
1255 case LEFTIMAGE:
1256 ni = wd->img_left;
1257 addx = data->leftrightaddx / 2;
1258 addy = (data->bottombordergads - data->img_left->h) / 2;
1259 isset = TRUE;
1260 break;
1262 case RIGHTIMAGE:
1263 ni = wd->img_right;
1264 addx = data->leftrightaddx / 2;
1265 addy = (data->bottombordergads - data->img_right->h) /2;
1266 isset = TRUE;
1267 break;
1269 default:
1270 return DoSuperMethodA(cl, obj, (Msg)msg);
1273 if (!isset) return DoSuperMethodA(cl, obj, (Msg)msg);
1275 if (wd && titlegadget) if (wd->rp) if (wd->rp->BitMap) BltBitMapRastPort(wd->rp->BitMap, left+addy, top+addy, rp, left+addy, top+addy, width, height, 0xc0);
1277 if (ni) DrawAlphaStateImageToRP(data, rp, ni, state, left+addx, top+addy, TRUE);
1279 return TRUE;
1282 /**************************************************************************************************/
1284 void getrightgadgetsdimensions(struct windecor_data *data, struct Window *win, int *xs, int *xe)
1286 struct Gadget *g;
1288 int x0 = 1000000;
1289 int x1 = 0;
1290 UWORD type;
1292 for (g = win->FirstGadget; g; g = g->NextGadget)
1294 if ((g->Flags & GFLG_RELRIGHT) == GFLG_RELRIGHT)
1296 type = g->GadgetType & GTYP_SYSTYPEMASK;
1297 if (data->closeright)
1299 if (((type & (GTYP_CLOSE | GTYP_WDEPTH | GTYP_WZOOM)) != 0) || (g->Activation & GACT_TOPBORDER))
1301 if (g->Width > 0)
1303 if ((win->Width + g->LeftEdge) < x0) x0 = win->Width + g->LeftEdge;
1304 if ((win->Width + g->LeftEdge + g->Width) > x1) x1 = win->Width + g->LeftEdge + g->Width;
1308 else
1310 if (((type & (GTYP_WDEPTH | GTYP_WZOOM)) != 0) || (g->Activation & GACT_TOPBORDER))
1312 if (g->Width > 0)
1314 if ((win->Width + g->LeftEdge) < x0) x0 = win->Width + g->LeftEdge;
1315 if ((win->Width + g->LeftEdge + g->Width) > x1) x1 = win->Width + g->LeftEdge + g->Width;
1321 if (x0 == 1000000) x0 = 0;
1322 *xs = x0;
1323 *xe = x1;
1326 void getleftgadgetsdimensions(struct windecor_data *data, struct Window *win, int *xs, int *xe)
1328 struct Gadget *g;
1330 int w = 0;
1331 int x0 = 1000000;
1332 int x1 = 0;
1333 for (g = win->FirstGadget; g; g = g->NextGadget)
1335 w++;
1336 if (((g->Flags & GFLG_RELRIGHT) == 0) && (g->Activation & GACT_TOPBORDER))
1338 if ((g->GadgetType & GTYP_WDRAGGING) == 0)
1340 if (g->Width > 0)
1342 if (g->LeftEdge < x0) x0 = g->LeftEdge;
1343 if ((g->LeftEdge + g->Width) > x1) x1 = g->LeftEdge + g->Width;
1348 if (x0 == 1000000) x0 = 0;
1349 *xs = x0;
1350 *xe = x1;
1353 /**************************************************************************************************/
1355 void ShadeLine(LONG pen, BOOL tc, struct windecor_data *d, struct RastPort *rp, struct NewImage *ni, ULONG basecolor, UWORD fact, UWORD _offy, UWORD x0, UWORD y0, UWORD x1, UWORD y1)
1357 int px, py, x, y;
1358 ULONG c;
1359 int c0, c1, c2, c3;
1360 UWORD offy = 0;
1362 if ((x1 < x0) || (y1 < y0)) return;
1363 if (!tc)
1365 SetAPen(rp, pen);
1366 Move(rp, x0, y0);
1367 Draw(rp, x1, y1);
1368 return;
1370 if (d->usegradients)
1372 c = basecolor;
1373 c3 = (c >> 24) & 0xff;
1374 c2 = (c >> 16) & 0xff;
1375 c1 = (c >> 8) & 0xff;
1376 c0 = c & 0xff;
1377 c0 *= fact;
1378 c1 *= fact;
1379 c2 *= fact;
1380 c3 *= fact;
1381 c0 = c0 >> 8;
1382 c1 = c1 >> 8;
1383 c2 = c2 >> 8;
1384 c3 = c3 >> 8;
1385 if (c0 > 255) c0 = 255;
1386 if (c1 > 255) c1 = 255;
1387 if (c2 > 255) c2 = 255;
1388 if (c3 > 255) c3 = 255;
1389 c = (c3 << 24) | (c2 << 16) | (c1 << 8) | c0;
1390 SetRPAttrs(rp, RPTAG_FgColor, c, TAG_DONE);
1391 Move(rp, x0, y0);
1392 Draw(rp, x1, y1);
1394 else if (ni->ok)
1396 if (x0 == x1)
1398 x = x0 % ni->w;
1399 for (py = y0; py < y1; py++)
1401 y = (py - offy) % ni->h;
1402 c = ni->data[x + y * ni->w];
1403 c0 = (c >> 24) & 0xff;
1404 c1 = (c >> 16) & 0xff;
1405 c2 = (c >> 8) & 0xff;
1406 c3 = c & 0xff;
1407 c0 *= fact;
1408 c1 *= fact;
1409 c2 *= fact;
1410 c3 *= fact;
1411 c0 = c0 >> 8;
1412 c1 = c1 >> 8;
1413 c2 = c2 >> 8;
1414 c3 = c3 >> 8;
1415 if (c0 > 255) c0 = 255;
1416 if (c1 > 255) c1 = 255;
1417 if (c2 > 255) c2 = 255;
1418 if (c3 > 255) c3 = 255;
1419 c = (c3 << 24) | (c2 << 16) | (c1 << 8) | c0;
1420 WriteRGBPixel(rp, x0, py, c);
1422 } else {
1423 y = (y0 - offy) % ni->h;
1424 for (px = x0; px < x1; px++) {
1425 x = px % ni->h;
1426 c = ni->data[x + y * ni->w];
1427 c0 = (c >> 24) & 0xff;
1428 c1 = (c >> 16) & 0xff;
1429 c2 = (c >> 8) & 0xff;
1430 c3 = c & 0xff;
1431 c0 *= fact;
1432 c1 *= fact;
1433 c2 *= fact;
1434 c3 *= fact;
1435 c0 = c0 >> 8;
1436 c1 = c1 >> 8;
1437 c2 = c2 >> 8;
1438 c3 = c3 >> 8;
1439 if (c0 > 255) c0 = 255;
1440 if (c1 > 255) c1 = 255;
1441 if (c2 > 255) c2 = 255;
1442 if (c3 > 255) c3 = 255;
1443 c = (c3 << 24) | (c2 << 16) | (c1 << 8) | c0;
1444 WriteRGBPixel(rp, px, y0, c);
1448 else
1450 Move(rp, x0, y0);
1451 Draw(rp, x1, y1);
1455 int WriteTiledImage(struct Window *win, struct RastPort *rp, struct NewImage *ni, int sx, int sy, int sw, int sh, int xp, int yp, int dw, int dh)
1457 int w = dw;
1458 int x = xp;
1459 int ddw;
1461 if (!ni->ok) return xp;
1463 if ((sw == 0) || (dw == 0)) return xp;
1464 if (win)
1466 if (x > win->Width) return xp;
1467 if ((x + w) > win->Width) w = win->Width - x;
1470 while (w > 0)
1472 ddw = sw;
1473 if (w < ddw) ddw = w;
1474 if (ni->bitmap == NULL)
1476 WritePixelArrayAlpha(ni->data, sx , sy, ni->w*4, rp, x, yp, ddw, dh, 0xffffffff);
1478 else
1480 if (ni->mask)
1482 BltMaskBitMapRastPort(ni->bitmap, sx, sy, rp, x, yp, ddw, dh, 0xe0, (PLANEPTR) ni->mask);
1484 else BltBitMapRastPort(ni->bitmap, sx, sy, rp, x, yp, ddw, dh, 0xc0);
1486 w -= ddw;
1487 x += ddw;
1489 return x;
1492 int WriteTiledImageNoAlpha(struct Window *win, struct RastPort *rp, struct NewImage *ni, int sx, int sy, int sw, int sh, int xp, int yp, int dw, int dh)
1494 int w = dw;
1495 int x = xp;
1496 int ddw;
1498 if (!ni->ok) return x;
1500 if ((sw == 0) || (dw == 0)) return xp;
1502 if (win)
1504 if (x > win->Width) return xp;
1505 if ((x + w) > win->Width) w = win->Width - x;
1508 while (w > 0)
1510 ddw = sw;
1511 if (w < ddw) ddw = w;
1512 if (ni->bitmap == NULL)
1514 WritePixelArray(ni->data, sx , sy, ni->w*4, rp, x, yp, ddw, dh, RECTFMT_ARGB);
1516 else
1518 BltBitMapRastPort(ni->bitmap, sx, sy, rp, x, yp, ddw, dh, 0xc0);
1520 w -= ddw;
1521 x += ddw;
1523 return x;
1527 void WriteAlphaPixelArray(struct NewImage *src, struct NewLUT8Image *dst, int sx, int sy, int dx, int dy, int w, int h)
1529 ULONG *s = src->data;
1530 ULONG argb;
1531 UBYTE *d = dst->data;
1532 int x, y;
1534 for (y = 0; y < h; y++)
1536 for (x = 0; x < w; x++)
1538 argb = s[sx + x + (sy + y) * src->w];
1539 d[dx + x + (dy + y) * dst->w] = GET_A(argb);
1544 int WriteTiledImageTitle(BOOL fill, struct Window *win, struct RastPort *rp, struct NewImage *ni, int sx, int sy, int sw, int sh, int xp, int yp, int dw, int dh)
1546 int w = dw;
1547 int x = xp;
1548 int ddw;
1550 if (!ni->ok) return x;
1552 if (!fill) return WriteTiledImageNoAlpha(win, rp, ni, sx, sy, sw, sh, xp, yp, dw, dh);
1554 if ((sw == 0) || (dw == 0)) return xp;
1556 if (win)
1558 if (x > win->Width) return xp;
1559 if ((x + w) > win->Width) w = win->Width - x;
1562 while (w > 0)
1564 ddw = sw;
1565 if (w < ddw) ddw = w;
1566 if (ni->bitmap == NULL)
1568 if (fill) WritePixelArrayAlpha(ni->data, sx, sy, ni->w*4, rp, x, yp, ddw, dh, 0xffffffff); //RECTFMT_ARGB);
1569 else WritePixelArray(ni->data, sx, sy, ni->w*4, rp, x, yp, ddw, dh, RECTFMT_ARGB);
1572 else
1574 if (fill)
1576 if (ni->mask)
1578 BltMaskBitMapRastPort(ni->bitmap, sx, sy, rp, x, yp, ddw, dh, 0xe0, (PLANEPTR) ni->mask);
1580 else BltBitMapRastPort(ni->bitmap, sx, sy, rp, x, yp, ddw, dh, 0xc0);
1582 else
1584 BltBitMapRastPort(ni->bitmap, sx, sy, rp, x, yp, ddw, dh, 0xc0);
1587 w -= ddw;
1588 x += ddw;
1590 return x;
1593 int WriteTiledImageShape(BOOL fill, struct Window *win, struct NewLUT8Image *lut8, struct NewImage *ni, int sx, int sy, int sw, int sh, int xp, int yp, int dw, int dh)
1595 int w = dw;
1596 int x = xp;
1597 int ddw;
1599 if (!ni->ok) return xp;
1601 if ((sw == 0) || (dw == 0)) return xp;
1603 if (win)
1605 if (x > win->Width) return xp;
1606 if ((x + w) > win->Width) w = win->Width - x;
1609 while (w > 0)
1611 ddw = sw;
1612 if (w < ddw) ddw = w;
1613 WriteAlphaPixelArray(ni, lut8, sx, sy, x, yp, ddw, dh);
1614 w -= ddw;
1615 x += ddw;
1617 return x;
1620 int WriteTiledImageHorizontal(struct RastPort *rp, struct NewImage *ni, int sx, int sy, int sw, int sh, int xp, int yp, int dw, int dh)
1622 return WriteTiledImage(NULL, rp, ni, sx, sy, sw, sh, xp, yp, dw, dh);
1625 int WriteTiledImageVertical(struct RastPort *rp, struct NewImage *ni, int sx, int sy, int sw, int sh, int xp, int yp, int dw, int dh)
1627 int h = dh;
1628 int y = yp;
1629 int ddh;
1631 if (!ni->ok) return y;
1633 if ((sh == 0) || (dh == 0)) return yp;
1635 while (h > 0)
1637 ddh = sh;
1638 if (h < ddh) ddh = h;
1639 if (ni->bitmap == NULL)
1641 WritePixelArrayAlpha(ni->data, sx , sy, ni->w*4, rp, xp, y, dw, ddh, 0xffffffff);
1643 else
1645 if (ni->mask)
1647 BltMaskBitMapRastPort(ni->bitmap, sx, sy, rp, xp, y, dw, ddh, 0xe0, (PLANEPTR) ni->mask);
1649 else BltBitMapRastPort(ni->bitmap, sx, sy, rp, xp, y, dw, ddh, 0xc0);
1651 h -= ddh;
1652 y += ddh;
1654 return y;
1657 IPTR windecor_draw_winborder(Class *cl, Object *obj, struct wdpDrawWinBorder *msg)
1659 struct windecor_data *data = INST_DATA(cl, obj);
1660 struct RastPort *rp = msg->wdp_RPort;
1661 struct Window *window = msg->wdp_Window;
1662 struct WindowData *wd = (struct WindowData *) msg->wdp_UserBuffer;
1663 struct NewImage *ni = NULL;
1664 UWORD *pens = msg->wdp_Dri->dri_Pens;
1665 ULONG bc, color, s_col, e_col, arc;
1666 UWORD bl, bt, br, bb, ww, wh;
1667 LONG pen = -1;
1668 int dy;
1670 if (wd->img_border_normal->ok) ni = wd->img_border_normal;
1672 if (ni == NULL) data->usegradients = TRUE;
1674 BOOL tc = wd->truecolor;
1676 LONG dpen = pens[SHADOWPEN];
1677 LONG lpen = pens[SHINEPEN];
1678 LONG mpen = pens[SHINEPEN];
1680 bl = window->BorderLeft;
1681 bt = window->BorderTop;
1682 bb = window->BorderBottom;
1683 br = window->BorderRight;
1684 ww = window->Width;
1685 wh = window->Height;
1687 color = 0x00cccccc;
1689 if (window->Flags & (WFLG_WINDOWACTIVE | WFLG_TOOLBOX))
1691 pen = wd->ActivePen;
1692 s_col = data->a_col_s;
1693 e_col = data->a_col_e;
1694 arc = data->a_arc;
1695 dy = 0;
1696 bc = data->b_col_a;
1697 } else {
1698 pen = wd->DeactivePen;
1699 s_col = data->d_col_s;
1700 e_col = data->d_col_e;
1701 arc = data->d_arc;
1702 dy = data->winbarheight;
1703 bc = data->b_col_d;
1704 if (!data->usegradients)
1706 if (wd->img_border_deactivated->ok) ni = wd->img_border_deactivated;
1710 // if (data->filltitlebar)
1711 // {
1712 // if (data->usegradients) FillPixelArrayGradient(pen, wd->truecolor, rp, 0, 0, window->Width, window->Height, 0, 0, window->Width, window->BorderTop, s_col, e_col, arc);
1713 // else DrawTileToRP(rp, ni, color, 0, 0, 0, 0, window->Width, window->BorderTop);
1714 // }
1716 if (window->BorderTop == data->winbarheight) DrawPartialTitleBar(wd, data, window, rp, msg->wdp_Dri, data->txt_align, 0, window->Width, pens);
1717 if (!(msg->wdp_Flags & WDF_DWB_TOP_ONLY))
1719 if (window->BorderLeft > 2)
1721 if (data->usegradients) FillPixelArrayGradient(pen, wd->truecolor, rp, 0, 0, window->Width-1, window->Height-1, 0, window->BorderTop, window->BorderLeft, window->Height - window->BorderTop, s_col, e_col, arc);
1722 else DrawTileToRP(rp, ni, color, 0, 0, 0, window->BorderTop, window->BorderLeft - 1, window->Height - window->BorderTop);
1724 if (window->BorderRight > 2)
1726 if (data->usegradients) FillPixelArrayGradient(pen, wd->truecolor, rp, 0, 0, window->Width-1, window->Height-1, window->Width - window->BorderRight , window->BorderTop, window->BorderRight, window->Height - window->BorderTop, s_col, e_col, arc);
1727 else DrawTileToRP(rp, ni, color, 0, 0, window->Width - window->BorderRight , window->BorderTop, window->BorderRight, window->Height - window->BorderTop);
1729 if (window->BorderBottom > 2)
1731 if (data->usegradients) FillPixelArrayGradient(pen, wd->truecolor, rp, 0, 0, window->Width-1, window->Height-1, 0, window->Height - window->BorderBottom , window->Width, window->BorderBottom, s_col, e_col, arc);
1732 else DrawTileToRP(rp, ni, color, 0, 0, 0, window->Height - window->BorderBottom , window->Width, window->BorderBottom);
1735 int bbt = bt;
1737 if (bt != data->winbarheight) {
1738 int bq = 0;
1739 if (bt > 1) bq = bt - 1;
1740 if (window->BorderTop > 2)
1742 if (data->usegradients) FillPixelArrayGradient(pen, wd->truecolor, rp, 0, 0, window->Width-1, window->Height-1, 0, 0 , window->Width - 1, window->BorderTop - 1, s_col, e_col, arc);
1743 else DrawTileToRP(rp, ni, color, 0, 0, 0, 0 , window->Width, window->BorderTop);
1745 if (bt > 0) ShadeLine(dpen, tc, data, rp, ni, bc, data->dark, 0, 0, 0, ww - 1, 0);
1746 if (bq > 0) ShadeLine(dpen, tc, data, rp, ni, bc, data->dark, bq, 0, bq, ww - 1, bq);
1747 if (bt > 1) ShadeLine(lpen, tc, data, rp, ni, bc, data->light, 1, 1, 1, ww - 2, 1);
1748 bbt = 0;
1751 if (bl > 0) ShadeLine(dpen, tc, data, rp, ni, bc, data->dark, bbt, 0, bbt, 0, wh - 1);
1752 if (bb > 0) ShadeLine(dpen, tc, data, rp, ni, bc, data->dark, wh - 1, 0, wh - 1, ww - 1, wh - 1);
1753 if (br > 0) ShadeLine(dpen, tc, data, rp, ni, bc, data->dark, bbt , ww - 1, bbt , ww - 1, wh - 1);
1754 if (bl > 1) ShadeLine(dpen, tc, data, rp, ni, bc, data->dark, bbt, bl - 1, bbt, bl - 1, wh - bb);
1755 if (bb > 1) ShadeLine(dpen, tc, data, rp, ni, bc, data->dark, wh - bb, bl - 1, wh - bb, ww - br, wh - bb);
1756 if (br > 1) ShadeLine(dpen, tc, data, rp, ni, bc, data->dark, bbt , ww - br, bbt , ww - br, wh - bb);
1757 if (bl > 2) ShadeLine(lpen, tc, data, rp, ni, bc, data->light, bbt, 1, bbt, 1, wh - 2);
1758 if (bl > 3) {
1759 if (bb > 1) ShadeLine(mpen, tc, data, rp, ni, bc, data->middle, bbt, bl - 2, bbt, bl - 2, wh - bb + 1);
1760 else ShadeLine(mpen, tc, data, rp, ni, bc, data->middle, bbt, bl - 2, bbt, bl - 2, wh - bb);
1762 if (br > 2) ShadeLine(mpen, tc, data, rp, ni, bc, data->middle, bbt, ww - 2, bbt, ww - 2, wh - 2);
1763 if (bb > 2) ShadeLine(mpen, tc, data, rp, ni, bc, data->middle, wh - 2, 1, wh - 2, ww - 2, wh - 2);
1764 if (bb > 3) {
1765 if ((bl > 0) && (br > 0)) ShadeLine(lpen, tc, data, rp, ni, bc, data->light, wh - bb + 1, bl, wh - bb + 1, ww - br, wh - bb + 1);
1767 if (br > 3) {
1768 if (bb > 1) ShadeLine(lpen, tc, data, rp, ni, bc, data->light, bbt, ww - br + 1, bbt, ww - br + 1, wh - bb + 1);
1771 return TRUE;
1774 void DrawTileToRP(struct RastPort *rp, struct NewImage *ni, ULONG color, UWORD offx, UWORD offy, UWORD x, UWORD y, WORD w, WORD h)
1777 ULONG ow, oh, sy, sx, dy, dx;
1778 LONG dh, height, dw, width;
1780 if ((w <= 0) || (h <= 0)) return;
1782 if (ni == NULL)
1784 FillPixelArray(rp, x, y, w, h, color);
1785 return;
1788 ow = ni->w;
1789 oh = ni->h;
1791 sy = (y - offy )% oh;
1792 dh = oh - sy;
1793 height = h;
1794 dy = y;
1795 while (height > 0)
1797 if ((height-dh)<0) dh = height;
1798 height -= dh;
1800 sx = (x - offx) % ow;
1801 dw = ow - sx;
1802 width = w;
1803 dx = x;
1804 while (width > 0)
1806 if ((width-dw)<0) dw = width;
1807 width -= dw;
1808 if (ni->bitmap == NULL)
1810 WritePixelArray(ni->data, sx, sy, ni->w*4, rp, dx, dy, dw, dh, RECTFMT_ARGB);
1812 else
1814 BltBitMapRastPort(ni->bitmap, sx, sy, rp, dx, dy, dw, dh, 0xc0);
1816 dx += dw;
1817 sx = 0;
1818 dw = ow;
1820 dy += dh;
1821 sy = 0;
1822 dh = oh;
1826 void DrawTileToRPRoot(struct RastPort *rp, struct NewImage *ni, ULONG color, UWORD offx, UWORD offy, UWORD x, UWORD y, WORD w, WORD h)
1829 ULONG ow, oh, sy, sx, dy, dx, _dy, _dx;
1830 LONG dh, height, dw, width;
1832 if (!ni->ok) return;
1834 if ((w <= 0) || (h <= 0)) return;
1836 if (!ni->ok)
1838 FillPixelArray(rp, x, y, w, h, color);
1839 return;
1842 ow = ni->w;
1843 oh = ni->h;
1845 _dy = 0;
1847 sy = (y - offy )% oh;
1848 dh = oh - sy;
1849 height = h;
1850 dy = y;
1851 while (height > 0)
1853 if ((height-dh)<0) dh = height;
1854 height -= dh;
1856 sx = (x - offx) % ow;
1857 dw = ow - sx;
1858 width = w;
1859 dx = x;
1860 _dx = 0;
1861 while (width > 0)
1863 if ((width-dw)<0) dw = width;
1864 width -= dw;
1865 if (ni->bitmap == NULL)
1867 WritePixelArray(ni->data, sx, sy, ni->w*4, rp, _dx, _dy, dw, dh, RECTFMT_ARGB);
1869 else
1871 BltBitMapRastPort(ni->bitmap, sx, sy, rp, _dx, _dy, dw, dh, 0xc0);
1873 dx += dw;
1874 _dx += dw;
1875 sx = 0;
1876 dw = ow;
1878 dy += dh;
1879 _dy += dh;
1880 sy = 0;
1881 dh = oh;
1885 void SetImageTint(struct NewImage *dst, UWORD ratio, ULONG argb)
1888 ULONG *d;
1889 ULONG rgb;
1890 UWORD r, g, b, w, h;
1891 UBYTE rs, gs, bs, rd, gd, bd;
1892 int x, y;
1894 if (dst == NULL) return;
1896 d = dst->data;
1898 w = dst->w;
1899 h = dst->h;
1901 rs = (argb >> 16) & 0xff;
1902 gs = (argb >> 8) & 0xff;
1903 bs = argb & 0xff;
1905 for (y = 0; y < h; y++)
1907 for (x = 0; x < w; x++)
1909 rgb = d[x + y * w];
1910 rd = GET_R(rgb);
1911 gd = GET_G(rgb);
1912 bd = GET_B(rgb);
1913 r = ((rs * ratio) >> 8) + ((rd * (255 - ratio)) >> 8);
1914 g = ((gs * ratio) >> 8) + ((gd * (255 - ratio)) >> 8);
1915 b = ((bs * ratio) >> 8) + ((bd * (255 - ratio)) >> 8);
1917 r = r & 0xff;
1918 g = g & 0xff;
1919 b = b & 0xff;
1921 d[x + y * w] = SET_ARGB(255, r, g, b);
1926 void MixImage(struct NewImage *dst, struct NewImage *src, UWORD ratio, UWORD w, UWORD h, UWORD dx, UWORD dy)
1928 ULONG *s, *d;
1929 ULONG rgba, rgb;
1930 UWORD r, g, b;
1931 UBYTE as, rs, gs, bs, rd, gd, bd;
1932 BOOL tiled = FALSE;
1933 int x, y;
1935 if (src == NULL) return;
1936 if (dst == NULL) return;
1938 s = src->data;
1939 d = dst->data;
1941 if (src) if (src->istiled) tiled = TRUE;
1943 for (y = 0; y < h; y++)
1945 for (x = 0; x < w; x++)
1947 rgba = s[x+y*src->w];
1948 as = GET_A(rgba);
1949 rs = GET_R(rgba);
1950 gs = GET_G(rgba);
1951 bs = GET_B(rgba);
1952 rgb = d[x+dx + (y+dy) * dst->w];
1954 rd = GET_R(rgb);
1955 gd = GET_G(rgb);
1956 bd = GET_B(rgb);
1958 r = ((rs * ratio) >> 8) + ((rd * (255 - ratio)) >> 8);
1959 g = ((gs * ratio) >> 8) + ((gd * (255 - ratio)) >> 8);
1960 b = ((bs * ratio) >> 8) + ((bd * (255 - ratio)) >> 8);
1962 if (tiled) {
1963 r = ((r * as) >> 8) + ((rd * (255 - as)) >> 8);
1964 g = ((g * as) >> 8) + ((gd * (255 - as)) >> 8);
1965 b = ((b * as) >> 8) + ((bd * (255 - as)) >> 8);
1968 r = r & 0xff;
1969 g = g & 0xff;
1970 b = b & 0xff;
1972 d[x+dx + (y+dy) * dst->w] = SET_ARGB(as, r, g, b);
1977 void BlurSourceAndMixTexture(struct NewImage *pic, struct NewImage *texture, UWORD ratio)
1979 int x, y, ytw, t1, t2, b1, b2, l1, l2, r1, r2;
1980 UWORD red, green, blue, alpha= 0, rs, gs, bs, as;
1981 ULONG rgb, argb;
1982 int width, w, height, ah, aw, xpos, ypos;
1983 BOOL tiled = FALSE;
1984 ULONG *raw, tw, th;
1986 if (pic == NULL) return;
1987 if (pic->data == NULL) return;
1989 tw = pic->w;
1990 if (texture) if (texture->istiled) tiled = TRUE;
1991 th = pic->h;
1992 raw = pic->data;
1993 height = th;
1994 width = tw;
1996 if (raw)
1998 for (y = 0; y < th; y++)
2000 t1 = tw;
2001 t2 = tw+tw;
2002 b1 = tw;
2003 b2 = tw+tw;
2004 if (y == 0) t1 = t2 = 0;
2005 else if (y == 1) t2 = t1;
2007 if (y == (th-1)) b1 = b2 = 0;
2008 else if (y == (th-2)) b2 = b1;
2010 ytw = y*tw;
2012 for (x = 0; x < tw; x++)
2014 r1 = 1;
2015 r2 = 2;
2016 l1 = 1;
2017 l2 = 2;
2019 if (x == 0) l1 = r1 = 0;
2020 else if (x == 1) l2 = l1;
2022 if (x == (tw-1)) r1 = r2 = 0;
2023 else if (x == (tw-2)) r2 = r1;
2025 rgb = raw[x+ytw];
2026 red = GET_R(rgb);
2027 green = GET_G(rgb);
2028 blue = GET_B(rgb);
2030 rgb = raw[x+ytw-t2];
2031 red += GET_R(rgb);
2032 green += GET_G(rgb);
2033 blue += GET_B(rgb);
2035 rgb = raw[x+ytw-l1-t1];
2036 red += GET_R(rgb);
2037 green += GET_G(rgb);
2038 blue += GET_B(rgb);
2040 rgb = raw[x+ytw-t1];
2041 red += GET_R(rgb);
2042 green += GET_G(rgb);
2043 blue += GET_B(rgb);
2045 rgb = raw[x+ytw-t1];
2046 red += GET_R(rgb);
2047 green += GET_G(rgb);
2048 blue += GET_B(rgb);
2050 rgb = raw[x+ytw-t1+r1];
2051 red += GET_R(rgb);
2052 green += GET_G(rgb);
2053 blue += GET_B(rgb);
2055 rgb = raw[x+ytw-l2];
2056 red += GET_R(rgb);
2057 green += GET_G(rgb);
2058 blue += GET_B(rgb);
2060 rgb = raw[x+ytw-l1];
2061 red += GET_R(rgb);
2062 green += GET_G(rgb);
2063 blue += GET_B(rgb);
2065 rgb = raw[x+ytw+r1];
2066 red += GET_R(rgb);
2067 green += GET_G(rgb);
2068 blue += GET_B(rgb);
2070 rgb = raw[x+ytw+r2];
2071 red += GET_R(rgb);
2072 green += GET_G(rgb);
2073 blue += GET_B(rgb);
2075 rgb = raw[x+ytw+b1-l1];
2076 red += GET_R(rgb);
2077 green += GET_G(rgb);
2078 blue += GET_B(rgb);
2080 rgb = raw[x+ytw+b1];
2081 red += GET_R(rgb);
2082 green += GET_G(rgb);
2083 blue += GET_B(rgb);
2085 rgb = raw[x+ytw+b1+r1];
2086 red += GET_R(rgb);
2087 green += GET_G(rgb);
2088 blue += GET_B(rgb);
2090 rgb = raw[x+ytw+b2];
2091 red += GET_R(rgb);
2092 green += GET_G(rgb);
2093 blue += GET_B(rgb);
2095 red = red/14;
2096 green = green/14;
2097 blue = blue/14;
2098 alpha = 255;
2100 if (tiled)
2102 argb = raw[x+ytw];
2103 as = 255 - GET_A(texture->data[x + y * texture->w]);
2104 rs = GET_R(argb);
2105 gs = GET_G(argb);
2106 bs = GET_B(argb);
2108 red = ((rs * as) >> 8) + ((red * (255 - as)) >> 8);
2109 green = ((gs * as) >> 8) + ((green * (255 - as)) >> 8);
2110 blue = ((bs * as) >> 8) + ((blue * (255 - as)) >> 8);
2112 raw[x+ytw] = SET_ARGB(as, red, green, blue);
2115 else
2117 raw[x+ytw] = SET_ARGB(alpha, red, green, blue);
2122 if (ratio < 100)
2124 if (texture)
2126 ypos = 0;
2127 while (height>0)
2129 ah = texture->h;
2130 if (ah > height) ah = height;
2131 xpos = 0;
2132 w = width;
2133 while (w>0)
2135 aw = texture->w;
2136 if (aw > w) aw = w;
2137 MixImage(pic, texture, 255 - (2.55 * ratio), aw, ah, xpos, ypos);
2138 w -= aw;
2139 xpos += aw;
2141 height -= ah;
2142 ypos += ah;
2148 void TileImageToImage(struct NewImage *src, struct NewImage *dest)
2150 ULONG *s, *d;
2151 UWORD y, h;
2153 if (dest == NULL) return;
2154 if (src == NULL) return;
2155 y = 0;
2157 h = src->h;
2159 s = src->data;
2160 d = dest->data;
2161 if (src->istiled == FALSE) return;
2162 dest->istiled = TRUE;
2164 if ((src->tile_top + src->tile_bottom) > dest->h) return;
2165 if ((src->tile_left + src->tile_right) > dest->w) return;
2167 DrawTileToImage(src, dest, 0, y, src->tile_left, src->tile_top, 0 , 0, src->tile_left, src->tile_top);
2168 DrawTileToImage(src, dest, 0, y + h - src->tile_bottom, src->tile_left, src->tile_bottom, 0 , dest->h - src->tile_bottom, src->tile_left, src->tile_bottom);
2169 DrawTileToImage(src, dest, src->w - src->tile_right, y, src->tile_right, src->tile_top, dest->w - src->tile_right, 0, src->tile_right, src->tile_top);
2170 DrawTileToImage(src, dest, src->w - src->tile_right, y + h - src->tile_bottom, src->tile_right, src->tile_bottom, dest->w - src->tile_right , dest->h - src->tile_bottom, src->tile_right, src->tile_bottom);
2172 DrawTileToImage(src, dest, src->tile_left, y, src->w - src->tile_left - src->tile_right, src->tile_top, src->tile_left, 0, dest->w - src->tile_left - src->tile_right, src->tile_top);
2173 DrawTileToImage(src, dest, src->tile_left, y + h - src->tile_bottom, src->w - src->tile_left - src->tile_right, src->tile_bottom, src->tile_left, dest->h - src->tile_bottom, dest->w - src->tile_left - src->tile_right, src->tile_bottom);
2174 DrawTileToImage(src, dest, 0, y + src->tile_top, src->tile_left, h - src->tile_bottom - src->tile_top, 0 , src->tile_top + 0, src->tile_left, dest->h - src->tile_top - src->tile_bottom - 0);
2175 DrawTileToImage(src, dest, src->w - src->tile_right, y + src->tile_top, src->tile_right, h - src->tile_bottom - src->tile_top, dest->w - src->tile_right, src->tile_top + 0, src->tile_right, dest->h - src->tile_top - src->tile_bottom - 0);
2176 DrawTileToImage(src, dest, src->tile_left, y + src->tile_top, src->w - src->tile_left - src->tile_right, h - src->tile_bottom - src->tile_top, src->tile_left, src->tile_top + 0, dest->w - src->tile_left - src->tile_right, dest->h - src->tile_top - src->tile_bottom - 0);
2179 void TileMapToBitmap(struct NewImage *src, struct BitMap *map, UWORD dw, UWORD dh)
2181 UWORD y, h;
2183 if (map == NULL) return;
2184 if (src == NULL) return;
2185 y = 0;
2187 h = src->h;
2189 if (src->istiled == FALSE) return;
2191 if ((src->tile_top + src->tile_bottom) > dh) return;
2192 if ((src->tile_left + src->tile_right) > dw) return;
2194 struct RastPort *dest = CreateRastPort();
2196 if (dest != NULL)
2198 dest->BitMap = map;
2200 DrawMapTileToRP(src, dest, 0, y, src->tile_left, src->tile_top, 0 , 0, src->tile_left, src->tile_top);
2201 DrawMapTileToRP(src, dest, 0, y + h - src->tile_bottom, src->tile_left, src->tile_bottom, 0 , dh - src->tile_bottom, src->tile_left, src->tile_bottom);
2202 DrawMapTileToRP(src, dest, src->w - src->tile_right, y, src->tile_right, src->tile_top, dw - src->tile_right, 0, src->tile_right, src->tile_top);
2203 DrawMapTileToRP(src, dest, src->w - src->tile_right, y + h - src->tile_bottom, src->tile_right, src->tile_bottom, dw - src->tile_right , dh - src->tile_bottom, src->tile_right, src->tile_bottom);
2205 DrawMapTileToRP(src, dest, src->tile_left, y, src->w - src->tile_left - src->tile_right, src->tile_top, src->tile_left, 0, dw - src->tile_left - src->tile_right, src->tile_top);
2206 DrawMapTileToRP(src, dest, src->tile_left, y + h - src->tile_bottom, src->w - src->tile_left - src->tile_right, src->tile_bottom, src->tile_left, dh - src->tile_bottom, dw - src->tile_left - src->tile_right, src->tile_bottom);
2207 DrawMapTileToRP(src, dest, 0, y + src->tile_top, src->tile_left, h - src->tile_bottom - src->tile_top, 0 , src->tile_top + 0, src->tile_left, dh - src->tile_top - src->tile_bottom - 0);
2208 DrawMapTileToRP(src, dest, src->w - src->tile_right, y + src->tile_top, src->tile_right, h - src->tile_bottom - src->tile_top, dw - src->tile_right, src->tile_top + 0, src->tile_right, dh - src->tile_top - src->tile_bottom - 0);
2209 DrawMapTileToRP(src, dest, src->tile_left, y + src->tile_top, src->w - src->tile_left - src->tile_right, h - src->tile_bottom - src->tile_top, src->tile_left, src->tile_top + 0, dw - src->tile_left - src->tile_right, dh - src->tile_top - src->tile_bottom - 0);
2210 FreeRastPort(dest);
2214 void RenderBackgroundTiled(struct NewImage *pic, struct NewImage *texture, UWORD ratio)
2216 struct NewImage *ni;
2218 if (texture)
2220 ni = NewImageContainer(pic->w, pic->h);
2221 if (ni)
2223 if (texture->istiled)
2225 TileImageToImage(texture, ni);
2226 BlurSourceAndMixTexture(pic, ni, ratio);
2228 else BlurSourceAndMixTexture(pic, texture, ratio);
2230 DisposeImageContainer(ni);
2232 else BlurSourceAndMixTexture(pic, texture, ratio);
2234 else BlurSourceAndMixTexture(pic, NULL, ratio);
2237 void RenderBackground(struct NewImage *pic, struct NewImage *texture, UWORD ratio)
2239 if (texture)
2241 if (texture->istiled) RenderBackgroundTiled(pic, texture, ratio); else BlurSourceAndMixTexture(pic, texture, ratio);
2243 else BlurSourceAndMixTexture(pic, NULL, ratio);
2246 /**************************************************************************************************/
2248 void DrawPartialTitleBar(struct WindowData *wd, struct windecor_data *data, struct Window *window, struct RastPort *dst_rp, struct DrawInfo *dri, UWORD align, UWORD start, UWORD width, UWORD *pens)
2250 int xl0, xl1, xr0, xr1, defwidth;
2251 ULONG textlen = 0, titlelen = 0, textpixellen = 0;
2252 struct TextExtent te;
2253 struct RastPort *rp;
2254 struct NewImage *ni = NULL;
2256 BOOL hasdepth;
2257 BOOL haszoom;
2258 BOOL hasclose;
2259 BOOL hasdrag;
2260 BOOL hastitle;
2261 BOOL hastitlebar;
2262 UWORD textstart = 0, barh, x;
2263 ULONG bc, color, s_col, e_col, arc;
2264 int dy;
2266 LONG pen = -1;
2268 if ((wd->rp == NULL) || (window->Width != wd->w) || (window->BorderTop != wd->h))
2270 if (wd->rp)
2272 FreeBitMap(wd->rp->BitMap);
2273 FreeRastPort(wd->rp);
2278 wd->h = window->BorderTop;
2279 wd->w = window->Width;
2280 wd->rp = NULL;
2283 rp = CreateRastPort();
2284 if (rp)
2286 SetFont(rp, dri->dri_Font);
2287 rp->BitMap = AllocBitMap(window->Width, window->BorderTop, 1, 0, window->WScreen->RastPort.BitMap);
2288 if (rp->BitMap == NULL)
2290 FreeRastPort(rp);
2291 return;
2293 } else return;
2295 wd->rp = rp;
2297 } else rp = wd->rp;
2299 hastitle = window->Title != NULL ? TRUE : FALSE;
2300 hasclose = (window->Flags & WFLG_CLOSEGADGET) ? TRUE : FALSE;
2301 hasdepth = (window->Flags & WFLG_DEPTHGADGET) ? TRUE : FALSE;
2302 hasdrag = (window->Flags & WFLG_DRAGBAR) ? TRUE : FALSE;
2303 haszoom = ((window->Flags & WFLG_HASZOOM) || ((window->Flags & WFLG_SIZEGADGET) && hasdepth)) ? TRUE : FALSE;
2304 hastitlebar = (window->BorderTop == data->winbarheight) ? TRUE : FALSE;
2306 if (wd->img_border_normal->ok) ni = wd->img_border_normal;
2308 if (ni == NULL) data->usegradients = TRUE;
2310 color = 0x00cccccc;
2312 if (window->Flags & (WFLG_WINDOWACTIVE | WFLG_TOOLBOX))
2314 s_col = data->a_col_s;
2315 e_col = data->a_col_e;
2316 arc = data->a_arc;
2317 dy = 0;
2318 bc = data->b_col_a;
2319 pen = wd->ActivePen;
2320 } else {
2321 s_col = data->d_col_s;
2322 e_col = data->d_col_e;
2323 arc = data->d_arc;
2324 dy = data->winbarheight;
2325 bc = data->b_col_d;
2326 if (!data->usegradients)
2328 if (wd->img_border_deactivated->ok) ni = wd->img_border_deactivated;
2330 pen = wd->DeactivePen;
2334 if (data->filltitlebar)
2336 if (data->usegradients) FillPixelArrayGradient(pen, wd->truecolor, rp, 0, 0, window->Width - 1, window->Height - 1, 0, 0, window->Width, window->BorderTop, s_col, e_col, arc);
2337 else DrawTileToRP(rp, ni, color, 0, 0, 0, 0, window->Width, window->BorderTop);
2340 if (window->Flags & (WFLG_WINDOWACTIVE | WFLG_TOOLBOX))
2342 dy = 0;
2344 else
2346 dy = data->winbarheight;
2348 getleftgadgetsdimensions(data, window, &xl0, &xl1);
2349 getrightgadgetsdimensions(data, window, &xr0, &xr1);
2350 defwidth = (xl0 != xl1) ? data->BarPreGadget_s : data->BarPre_s;
2351 if(xr1 == 0)
2353 xr1 = window->Width - data->BarPre_s;
2354 xr0 = window->Width - data->BarPre_s;
2357 defwidth += (xl1 - xl0);
2359 defwidth += data->BarJoinGB_s;
2360 defwidth += data->BarJoinBT_s;
2361 defwidth += data->BarJoinTB_s;
2362 defwidth += data->BarJoinBG_s;
2363 defwidth += (xr1 - xr0);
2364 defwidth += (xr0 != xr1) ? data->BarPostGadget_s : data->BarPost_s;
2366 if (defwidth >= window->Width) hastitle = FALSE;
2368 if (hastitle)
2370 titlelen = strlen(window->Title);
2371 textlen = TextFit(rp, window->Title, titlelen, &te, NULL, 1, window->Width-defwidth, window->BorderTop - 2);
2372 if (textlen)
2374 textpixellen = te.te_Extent.MaxX - te.te_Extent.MinX + 1;
2378 if (wd->img_winbar_normal->ok && hastitlebar)
2380 barh = data->img_winbar_normal->h;
2381 if (data->barvert)
2383 if (barh > data->winbarheight) barh = data->winbarheight;
2385 x = 0;
2386 if (xl0 != xl1)
2388 x = WriteTiledImageTitle(data->filltitlebar, window, rp, wd->img_winbar_normal, data->BarPreGadget_o, dy, data->BarPreGadget_s, barh, x, 0, data->BarPreGadget_s, barh);
2389 if ((xl1-xl0) > 0) x = WriteTiledImageTitle(data->filltitlebar, window, rp, wd->img_winbar_normal, data->BarLGadgetFill_o, dy, data->BarLGadgetFill_s, barh, x, 0, xl1-xl0, barh);
2391 else
2393 x = WriteTiledImageTitle(data->filltitlebar, window, rp, wd->img_winbar_normal, data->BarPre_o, dy, data->BarPre_s, barh, x, 0, data->BarPreGadget_s, barh);
2395 x = WriteTiledImageTitle(data->filltitlebar, window, rp, wd->img_winbar_normal, data->BarJoinGB_o, dy, data->BarJoinGB_s, barh, x, 0, data->BarJoinGB_s, barh);
2396 if (hastitle && (textlen > 0))
2398 switch(align)
2400 case WD_DWTA_CENTER:
2401 //BarLFill
2402 x = WriteTiledImageTitle(data->filltitlebar, window, rp, wd->img_winbar_normal, data->BarLFill_o, dy, data->BarLFill_s, barh, x, 0, 60, barh);
2403 break;
2404 case WD_DWTA_RIGHT:
2405 //BarLFill
2406 break;
2407 default:
2408 case WD_DWTA_LEFT:
2409 break;
2411 x = WriteTiledImageTitle(data->filltitlebar, window, rp, wd->img_winbar_normal, data->BarJoinBT_o, dy, data->BarJoinBT_s, barh, x, 0, data->BarJoinBT_s, barh);
2412 textstart = x;
2413 if (textpixellen > 0) x = WriteTiledImageTitle(data->filltitlebar, window, rp, wd->img_winbar_normal, data->BarTitleFill_o, dy, data->BarTitleFill_s, barh, x, 0, textpixellen, barh);
2414 x = WriteTiledImageTitle(data->filltitlebar, window, rp, wd->img_winbar_normal, data->BarJoinTB_o, dy, data->BarJoinTB_s, barh, x, 0, data->BarJoinTB_s, barh);
2416 x = WriteTiledImageTitle(data->filltitlebar, window, rp, wd->img_winbar_normal, data->BarRFill_o, dy, data->BarRFill_s, barh, x, 0, xr0 - x - data->BarJoinBG_s, barh);
2417 x = WriteTiledImageTitle(data->filltitlebar, window, rp, wd->img_winbar_normal, data->BarJoinBG_o, dy, data->BarJoinBG_s, barh, x, 0, data->BarJoinBG_s, barh);
2418 if ((xr1-xr0) > 0) x = WriteTiledImageTitle(data->filltitlebar, window, rp, wd->img_winbar_normal, data->BarRGadgetFill_o, dy, data->BarRGadgetFill_s, barh, x, 0, xr1-xr0, barh);
2419 if (xr0 != xr1)
2421 x = WriteTiledImageTitle(data->filltitlebar, window, rp, wd->img_winbar_normal, data->BarPostGadget_o, dy, data->BarPostGadget_s, barh, x, 0, data->BarPostGadget_s, barh);
2423 else
2425 x = WriteTiledImageTitle(data->filltitlebar, window, rp, wd->img_winbar_normal, data->BarPost_o, dy, data->BarPost_s, barh, x, 0, data->BarPost_s, barh);
2429 if ((textlen > 0) && hastitle)
2431 SetAPen(rp, pens[(window->Flags & (WFLG_WINDOWACTIVE | WFLG_TOOLBOX)) ? FILLTEXTPEN : TEXTPEN]);
2432 SetDrMd(rp, JAM1);
2433 UWORD tx = textstart;
2434 UWORD ty = ((data->winbarheight - dri->dri_Font->tf_YSize) >> 1) + dri->dri_Font->tf_Baseline;
2436 if (!wd->truecolor || ((data->outline == FALSE) && (data->shadow == FALSE)))
2438 Move(rp, tx, ty);
2439 Text(rp, window->Title, textlen);
2441 else if (data->outline)
2444 SetSoftStyle(rp, FSF_BOLD, AskSoftStyle(rp));
2445 SetRPAttrs(rp, RPTAG_PenMode, FALSE, RPTAG_FgColor, data->shadow_col, TAG_DONE);
2447 Move(rp, tx + 1, ty ); Text(rp, window->Title, textlen);
2448 Move(rp, tx + 2, ty ); Text(rp, window->Title, textlen);
2449 Move(rp, tx , ty ); Text(rp, window->Title, textlen);
2450 Move(rp, tx, ty + 1); Text(rp, window->Title, textlen);
2451 Move(rp, tx, ty + 2); Text(rp, window->Title, textlen);
2452 Move(rp, tx + 1, ty + 2); Text(rp, window->Title, textlen);
2453 Move(rp, tx + 2, ty + 1); Text(rp, window->Title, textlen);
2454 Move(rp, tx + 2, ty + 2); Text(rp, window->Title, textlen);
2456 SetRPAttrs(rp, RPTAG_PenMode, FALSE, RPTAG_FgColor, data->text_col, TAG_DONE);
2457 Move(rp, tx + 1, ty + 1);
2458 Text(rp, window->Title, textlen);
2459 SetSoftStyle(rp, FS_NORMAL, AskSoftStyle(rp));
2461 else
2463 SetRPAttrs(rp, RPTAG_PenMode, FALSE, RPTAG_FgColor, data->shadow_col, TAG_DONE);
2464 Move(rp, tx + 1, ty + 1 );
2465 Text(rp, window->Title, textlen);
2467 SetRPAttrs(rp, RPTAG_PenMode, FALSE, RPTAG_FgColor, data->text_col, TAG_DONE);
2468 Move(rp, tx, ty);
2469 Text(rp, window->Title, textlen);
2473 struct Gadget *g;
2475 for (g = window->FirstGadget; g; g = g->NextGadget)
2477 if (g->Activation & GACT_TOPBORDER && (g->GadgetType & GTYP_SYSTYPEMASK) != GTYP_WDRAGGING)
2479 int x, y;
2480 y = g->TopEdge;
2481 if (!(g->Flags & GFLG_RELRIGHT))
2483 x = g->LeftEdge;
2485 else
2487 x = g->LeftEdge + window->Width - 1;
2489 struct NewImage *ni = NULL;
2490 UWORD state = IDS_NORMAL;
2492 if ((window->Flags & (WFLG_WINDOWACTIVE | WFLG_TOOLBOX)) == 0)
2494 state = IDS_INACTIVENORMAL;
2496 else if (g->Flags & GFLG_SELECTED) state = IDS_SELECTED;
2498 if (g->GadgetType & GTYP_SYSTYPEMASK) {
2499 switch(g->GadgetType & GTYP_SYSTYPEMASK)
2501 case GTYP_CLOSE:
2502 ni = wd->img_close;
2503 break;
2504 case GTYP_WDEPTH:
2505 ni = wd->img_depth;
2506 break;
2507 case GTYP_WZOOM:
2508 ni = wd->img_zoom;
2509 break;
2512 else
2514 switch(g->GadgetID)
2516 case ETI_MUI:
2517 ni = wd->img_mui;
2518 break;
2520 case ETI_PopUp:
2521 ni = wd->img_popup;
2522 break;
2524 case ETI_Snapshot:
2525 ni = wd->img_snapshot;
2526 break;
2528 case ETI_Iconify:
2529 ni = wd->img_iconify;
2530 break;
2532 case ETI_Lock:
2533 ni = wd->img_lock;
2534 break;
2538 if (ni) DrawAlphaStateImageToRP(data, rp, ni, state, x, y, TRUE);
2541 BltBitMapRastPort(rp->BitMap, start, 0, dst_rp, start, 0, width, window->BorderTop, 0xc0);
2544 /**************************************************************************************************/
2547 IPTR windecor_layout_bordergadgets(Class *cl, Object *obj, struct wdpLayoutBorderGadgets *msg)
2549 struct windecor_data *data = INST_DATA(cl, obj);
2550 struct Window *window = msg->wdp_Window;
2551 struct Gadget *gadget = msg->wdp_Gadgets;
2552 struct Gadget *draggadget = NULL;
2553 struct WindowData *wd = (struct WindowData *) msg->wdp_UserBuffer;
2554 ULONG eb = msg->wdp_ExtraButtons;
2556 BOOL hasdepth;
2557 BOOL haszoom;
2558 BOOL hasclose;
2559 BOOL hasdrag;
2560 BOOL hastitle;
2561 BOOL hassize;
2562 BOOL borderless;
2563 LONG width;
2564 LONG rightborder = 0;
2565 LONG bottomborder = 0;
2567 DoSuperMethodA(cl, obj, (Msg)msg);
2569 hastitle = window->Title != NULL ? TRUE : FALSE;
2570 hasclose = (window->Flags & WFLG_CLOSEGADGET) ? TRUE : FALSE;
2571 hassize = (window->Flags & WFLG_SIZEGADGET) ? TRUE : FALSE;
2572 hasdepth = (window->Flags & WFLG_DEPTHGADGET) ? TRUE : FALSE;
2573 hasdrag = (window->Flags & WFLG_DRAGBAR) ? TRUE : FALSE;
2574 borderless = (window->Flags & WFLG_BORDERLESS) ? TRUE : FALSE;
2575 haszoom = ((window->Flags & WFLG_HASZOOM) || ((window->Flags & WFLG_SIZEGADGET) && hasdepth)) ? TRUE : FALSE;
2578 if ((msg->wdp_Flags & WDF_LBG_SYSTEMGADGET) != 0)
2580 if (gadget->GadgetType == GTYP_CUSTOMGADGET)
2582 switch(gadget->GadgetID)
2584 case ETI_MUI:
2585 if (wd->img_mui->ok)
2587 if (data->threestate) width = (wd->img_mui->w / 3); else width = (wd->img_mui->w >> 2);
2589 gadget->Width = width;
2590 gadget->Height = wd->img_mui->h;
2591 gadget->TopEdge = (data->winbarheight - gadget->Height) / 2;
2593 if (haszoom)
2595 if (data->threestate) width += (wd->img_zoom->w / 3); else width += (wd->img_zoom->w >> 2);
2597 if (hasclose && data->closeright)
2599 if (data->threestate) width += (wd->img_close->w / 3); else width += (wd->img_close->w >> 2);
2601 if (hasdepth)
2603 if (data->threestate) width += (wd->img_depth->w / 3); else width += (wd->img_depth->w >> 2);
2604 gadget->LeftEdge = -data->BarPostGadget_s - width;
2606 else
2608 gadget->LeftEdge = -data->BarPostGadget_s - width;
2610 gadget->Flags &= ~GFLG_RELWIDTH;
2611 gadget->Flags |= GFLG_RELRIGHT;
2614 break;
2616 case ETI_PopUp:
2617 if (wd->img_popup->ok)
2619 if (data->threestate) width = (wd->img_popup->w / 3); else width = (wd->img_popup->w >> 2);
2621 gadget->Width = width;
2622 gadget->Height = wd->img_popup->h;
2623 gadget->TopEdge = (data->winbarheight - gadget->Height) / 2;
2625 if ((eb & ETG_MUI) != 0)
2627 if (wd->img_mui->ok)
2629 if (data->threestate) width += (wd->img_mui->w / 3); else width += (wd->img_mui->w >> 2);
2633 if (haszoom)
2635 if (data->threestate) width += (wd->img_zoom->w / 3); else width += (wd->img_zoom->w >> 2);
2638 if (hasclose && data->closeright)
2640 if (data->threestate) width += (wd->img_close->w / 3); else width += (wd->img_close->w >> 2);
2642 if (hasdepth)
2644 if (data->threestate) width += (wd->img_depth->w / 3); else width += (wd->img_depth->w >> 2);
2645 gadget->LeftEdge = -data->BarPostGadget_s - width;
2647 else
2649 gadget->LeftEdge = -data->BarPostGadget_s - width;
2651 gadget->Flags &= ~GFLG_RELWIDTH;
2652 gadget->Flags |= GFLG_RELRIGHT;
2655 break;
2657 case ETI_Snapshot:
2658 if (wd->img_snapshot->ok)
2660 if (data->threestate) width = (wd->img_snapshot->w / 3); else width = (wd->img_snapshot->w >> 2);
2662 gadget->Width = width;
2663 gadget->Height = wd->img_snapshot->h;
2664 gadget->TopEdge = (data->winbarheight - gadget->Height) / 2;
2666 if ((eb & ETG_MUI) != 0)
2669 if (wd->img_mui->ok)
2671 if (data->threestate) width += (wd->img_mui->w / 3); else width += (wd->img_mui->w >> 2);
2675 if ((eb & ETG_POPUP) != 0)
2677 if (wd->img_popup->ok)
2679 if (data->threestate) width += (wd->img_popup->w / 3); else width += (wd->img_popup->w >> 2);
2683 if (haszoom)
2685 if (data->threestate) width += (wd->img_zoom->w / 3); else width += (wd->img_zoom->w >> 2);
2688 if (hasclose && data->closeright)
2690 if (data->threestate) width += (wd->img_close->w / 3); else width += (wd->img_close->w >> 2);
2693 if (hasdepth)
2695 if (data->threestate) width += (wd->img_depth->w / 3); else width += (wd->img_depth->w >> 2);
2696 gadget->LeftEdge = -data->BarPostGadget_s - width;
2698 else
2700 gadget->LeftEdge = -data->BarPostGadget_s - width;
2703 gadget->Flags &= ~GFLG_RELWIDTH;
2704 gadget->Flags |= GFLG_RELRIGHT;
2707 break;
2709 case ETI_Iconify:
2710 if (wd->img_iconify->ok)
2712 if (data->threestate) width = (wd->img_iconify->w / 3); else width = (wd->img_iconify->w >> 2);
2714 gadget->Width = width;
2715 gadget->Height = wd->img_iconify->h;
2716 gadget->TopEdge = (data->winbarheight - gadget->Height) / 2;
2718 if ((eb & ETG_MUI) != 0)
2720 if (wd->img_mui->ok)
2722 if (data->threestate) width += (wd->img_mui->w / 3); else width += (wd->img_mui->w >> 2);
2726 if ((eb & ETG_POPUP) != 0)
2728 if (wd->img_popup->ok)
2730 if (data->threestate) width += (wd->img_popup->w / 3); else width += (wd->img_popup->w >> 2);
2734 if ((eb & ETG_SNAPSHOT) != 0)
2736 if (wd->img_snapshot->ok)
2738 if (data->threestate) width += (wd->img_snapshot->w / 3); else width += (wd->img_snapshot->w >> 2);
2742 if (haszoom)
2744 if (data->threestate) width += (wd->img_zoom->w / 3); else width += (wd->img_zoom->w >> 2);
2747 if (hasclose && data->closeright)
2749 if (data->threestate) width += (wd->img_close->w / 3); else width += (wd->img_close->w >> 2);
2751 if (hasdepth)
2753 if (data->threestate) width += (wd->img_depth->w / 3); else width += (wd->img_depth->w >> 2);
2754 gadget->LeftEdge = -data->BarPostGadget_s - width;
2756 else
2758 gadget->LeftEdge = -data->BarPostGadget_s - width;
2760 gadget->Flags &= ~GFLG_RELWIDTH;
2761 gadget->Flags |= GFLG_RELRIGHT;
2764 break;
2766 case ETI_Lock:
2767 if (wd->img_lock->ok)
2769 if (data->threestate) width = (wd->img_lock->w / 3); else width = (wd->img_lock->w >> 2);
2771 gadget->Width = width;
2772 gadget->Height = wd->img_lock->h;
2773 gadget->TopEdge = (data->winbarheight - gadget->Height) / 2;
2775 if ((eb & ETG_MUI) != 0)
2777 if (wd->img_mui->ok)
2779 if (data->threestate) width += (wd->img_mui->w / 3); else width += (wd->img_mui->w >> 2);
2783 if ((eb & ETG_POPUP) != 0)
2785 if (wd->img_popup->ok)
2787 if (data->threestate) width += (wd->img_popup->w / 3); else width += (wd->img_popup->w >> 2);
2791 if ((eb & ETG_SNAPSHOT) != 0)
2793 if (wd->img_snapshot->ok)
2795 if (data->threestate) width += (wd->img_snapshot->w / 3); else width += (wd->img_snapshot->w >> 2);
2799 if ((eb & ETG_ICONIFY) != 0)
2801 if (wd->img_iconify->ok)
2803 if (data->threestate) width += (wd->img_iconify->w / 3); else width += (wd->img_iconify->w >> 2);
2807 if (haszoom)
2809 if (data->threestate) width += (wd->img_zoom->w / 3); else width += (wd->img_zoom->w >> 2);
2812 if (hasclose && data->closeright)
2814 if (data->threestate) width += (wd->img_close->w / 3); else width += (wd->img_close->w >> 2);
2816 if (hasdepth)
2818 if (data->threestate) width += (wd->img_depth->w / 3); else width += (wd->img_depth->w >> 2);
2819 gadget->LeftEdge = -data->BarPostGadget_s - width;
2821 else
2823 gadget->LeftEdge = -data->BarPostGadget_s - width;
2825 gadget->Flags &= ~GFLG_RELWIDTH;
2826 gadget->Flags |= GFLG_RELRIGHT;
2829 break;
2833 else
2835 switch(gadget->GadgetType & GTYP_SYSTYPEMASK)
2837 case GTYP_CLOSE:
2838 if (data->threestate) width = (data->img_close->w / 3); else width = (data->img_close->w >> 2);
2839 gadget->Width = width;
2840 wd->closewidth = width;
2841 gadget->Height = data->img_close->h;
2842 if (data->closeright)
2844 gadget->Flags &= ~GFLG_RELWIDTH;
2845 gadget->Flags |= GFLG_RELRIGHT;
2846 gadget->LeftEdge = -data->BarPostGadget_s - width;
2848 else
2850 gadget->LeftEdge = data->BarPreGadget_s;
2852 gadget->TopEdge = (data->winbarheight - gadget->Height) / 2;
2853 break;
2855 case GTYP_WDEPTH:
2856 if (data->threestate) width = (data->img_depth->w / 3); else width = (data->img_depth->w >> 2);
2857 gadget->Width = width;
2858 wd->depthwidth = width;
2859 gadget->Height = data->img_depth->h;
2860 if (hasclose && data->closeright)
2862 if (data->threestate) width += (data->img_close->w / 3); else width += (data->img_close->w >> 2);
2864 gadget->LeftEdge = -data->BarPostGadget_s - width;
2865 gadget->TopEdge = (data->winbarheight - gadget->Height) / 2;
2866 gadget->Flags &= ~GFLG_RELWIDTH;
2867 gadget->Flags |= GFLG_RELRIGHT;
2868 break;
2870 case GTYP_WZOOM:
2871 if (data->threestate) width = (data->img_zoom->w / 3); else width = (data->img_zoom->w >> 2);
2872 gadget->Width = width;
2873 wd->zoomwidth = width;
2874 gadget->Height = data->img_zoom->h;
2875 gadget->TopEdge = (data->winbarheight - gadget->Height) / 2;
2876 if (hasclose && data->closeright)
2878 if (data->threestate) width += (data->img_close->w / 3); else width += (data->img_close->w >> 2);
2880 if (hasdepth)
2882 if (data->threestate) width += (data->img_depth->w / 3); else width += (data->img_depth->w >> 2);
2883 gadget->LeftEdge = -data->BarPostGadget_s - width;
2885 else
2887 gadget->LeftEdge = -data->BarPostGadget_s - width;
2889 gadget->Flags &= ~GFLG_RELWIDTH;
2890 gadget->Flags |= GFLG_RELRIGHT;
2892 break;
2894 case GTYP_SIZING:
2895 rightborder = data->rightbordergads;
2896 if ((gadget->Flags & WFLG_SIZEBBOTTOM) != 0) bottomborder = data->bottombordergads;
2897 break;
2899 case GTYP_WDRAGGING:
2900 break;
2904 return TRUE;
2907 int sysrgad = -data->BarPostGadget_s - 1;
2909 if (data->closeright && hasclose) sysrgad -= wd->closewidth;
2910 if (hasdepth) sysrgad -= wd->depthwidth;
2911 if (haszoom) sysrgad -= wd->zoomwidth;
2912 while(gadget)
2914 if ((gadget->GadgetType & GTYP_SYSTYPEMASK) == 0)
2916 switch(gadget->GadgetType & GTYP_SYSTYPEMASK)
2918 case GTYP_WDRAGGING:
2919 break;
2921 default:
2922 if ((gadget->Flags & GFLG_EXTENDED) != 0)
2924 if ((((struct ExtGadget *) gadget)->MoreFlags & GMORE_BOOPSIGADGET) != 0)
2926 ULONG rtsm;
2927 get((Object *) gadget, GA_RightBorder, &rtsm);
2928 if (rtsm)
2930 if (get((Object *) gadget, PGA_Top, &rtsm))
2932 SetAttrs((Object *) gadget, GA_RelRight, - data->rightbordergads + ((data->rightbordergads - (data->img_verticalcontainer->w >> 1) + 1) >> 1) + 1, GA_Width, data->img_verticalcontainer->w >> 1, TAG_DONE);
2934 else
2936 get((Object *) gadget, GA_Width, &rtsm);
2937 SetAttrs((Object *) gadget, GA_RelRight, - data->rightbordergads + ((data->rightbordergads - rtsm + 1) >> 1) + 1, TAG_DONE);
2940 else
2942 get((Object *) gadget, GA_BottomBorder, &rtsm);
2943 if (rtsm)
2945 if (get((Object *) gadget, PGA_Top, &rtsm))
2947 SetAttrs((Object *) gadget, GA_RelBottom, - data->bottombordergads + ((data->bottombordergads - (data->img_horizontalcontainer->h >> 1) + 1) >> 1) +1, GA_Height, (data->img_horizontalcontainer->h >> 1), TAG_DONE);
2949 else
2951 get((Object *) gadget, GA_Height, &rtsm);
2952 SetAttrs((Object *) gadget, GA_RelBottom, - data->bottombordergads + ((data->bottombordergads - rtsm + 1) >> 1) + 1, TAG_DONE);
2958 break;
2961 if (msg->wdp_Flags & WDF_LBG_MULTIPLE)
2963 gadget = gadget->NextGadget;
2965 else
2967 gadget = NULL;
2970 gadget = msg->wdp_Gadgets;
2972 while(gadget)
2974 if ((gadget->GadgetType & GTYP_SYSTYPEMASK) == 0)
2976 if ((gadget->Activation & GACT_TOPBORDER) != 0)
2978 if ((gadget->Flags & GFLG_RELRIGHT) != 0)
2980 gadget->TopEdge = (data->winbarheight - gadget->Height) / 2;
2981 sysrgad -= gadget->Width;
2982 gadget->LeftEdge = sysrgad;
2986 gadget = gadget->NextGadget;
2989 gadget = msg->wdp_Gadgets;
2991 if ((msg->wdp_Flags & WDF_LBG_SYSTEMGADGET) != 0) while(gadget)
2993 switch(gadget->GadgetType & GTYP_SYSTYPEMASK)
2995 case GTYP_WDRAGGING:
2996 gadget->Width = sysrgad;
2997 if (hasclose && !data->closeright)
2999 gadget->Width -= data->BarPreGadget_s;
3000 if (data->threestate) gadget->Width -= (data->img_close->w / 3); else gadget->Width -= (data->img_close->w >> 2);
3002 break;
3004 gadget = gadget->NextGadget;
3007 if (draggadget)
3011 return TRUE;
3014 /**************************************************************************************************/
3016 IPTR windecor_draw_borderpropback(Class *cl, Object *obj, struct wdpDrawBorderPropBack *msg)
3018 /* Simply return, we need to render the back in the knob method */
3019 /* because we want to use irregular (alpha images) for the sliders */
3020 return TRUE;
3023 /**************************************************************************************************/
3025 IPTR windecor_draw_borderpropknob(Class *cl, Object *obj, struct wdpDrawBorderPropKnob *msg)
3027 struct windecor_data *data = INST_DATA(cl, obj);
3028 struct Window *window = msg->wdp_Window;
3029 struct RastPort *winrp = msg->wdp_RPort;
3030 struct WindowData *wd = (struct WindowData *) msg->wdp_UserBuffer;
3032 struct RastPort *rp;
3033 struct Gadget *gadget = msg->wdp_Gadget;
3034 struct Rectangle *r;
3035 struct PropInfo *pi = ((struct PropInfo *)gadget->SpecialInfo);
3036 struct NewImage *ni = NULL;
3037 BOOL hit = (msg->wdp_Flags & WDF_DBPK_HIT) ? TRUE : FALSE;
3038 ULONG y, x, bx0, bx1, by0, by1;
3039 int size, is, pos;
3040 ULONG bc, color, s_col, e_col, arc;
3041 LONG pen = -1;
3043 if (!(pi->Flags & PROPNEWLOOK) || (gadget->Activation && (GACT_RIGHTBORDER | GACT_BOTTOMBORDER) == 0))
3045 return DoSuperMethodA(cl, obj, (Msg)msg);
3048 r = msg->wdp_PropRect;
3050 bx0 = r->MinX;
3051 by0 = r->MinY;
3052 bx1 = r->MaxX;
3053 by1 = r->MaxY;
3055 rp = CreateRastPort();
3056 if (rp)
3058 struct Rectangle cliprect = {0, 0, bx1 - bx0, by1 - by0};
3059 struct TagItem rptags[] =
3061 {RPTAG_ClipRectangle, (IPTR)&cliprect},
3062 {TAG_DONE }
3065 rp->BitMap = AllocBitMap(bx1 - bx0 + 1, by1 - by0 + 1, 1, 0, window->WScreen->RastPort.BitMap);
3066 if (rp->BitMap == NULL)
3068 FreeRastPort(rp);
3069 return FALSE;
3072 SetRPAttrsA(rp, rptags);
3074 else return FALSE;
3076 color = 0x00cccccc;
3078 if (wd->img_border_normal->ok) ni = wd->img_border_normal;
3080 if (ni == NULL) data->usegradients = TRUE;
3082 if (window->Flags & (WFLG_WINDOWACTIVE | WFLG_TOOLBOX))
3084 s_col = data->a_col_s;
3085 e_col = data->a_col_e;
3086 arc = data->a_arc;
3087 bc = data->b_col_a;
3088 pen = wd->ActivePen;
3090 else
3092 s_col = data->d_col_s;
3093 e_col = data->d_col_e;
3094 arc = data->d_arc;
3095 bc = data->b_col_d;
3096 if (!data->usegradients)
3098 if (wd->img_border_deactivated->ok) ni = wd->img_border_deactivated;
3100 pen = wd->DeactivePen;
3103 if (data->usegradients)
3106 FillPixelArrayGradientDelta(pen, wd->truecolor, rp, 0, 0, window->Width-1, window->Height-1, 0, 0, bx1 - bx0 + 1, by1 - by0 + 1, s_col, e_col, arc, 0, 0);
3109 else
3113 if (ni->ok != 0)
3115 ULONG color = 0x00cccccc;
3117 DrawTileToRPRoot(rp, ni, color, 0, 0, bx0, by0, bx1 - bx0 + 1, by1 - by0 + 1);
3122 r = msg->wdp_PropRect;
3124 bx0 = 0;
3125 by0 = 0;
3126 bx1 = r->MaxX - r->MinX;
3127 by1 = r->MaxY - r->MinY;
3129 if ((pi->Flags & FREEVERT) != 0)
3132 is = data->img_verticalcontainer->w >> 1;
3133 if (window->Flags & (WFLG_WINDOWACTIVE | WFLG_TOOLBOX)) pos = 0; else pos = is;
3134 y = by0;
3135 size = by1 - by0 - data->ContainerTop_s - data->ContainerBottom_s + 1;
3136 y = WriteTiledImageVertical(rp, wd->img_verticalcontainer, pos, data->ContainerTop_o, is, data->ContainerTop_s, bx0, y, is, data->ContainerTop_s);
3137 if (size > 0) y = WriteTiledImageVertical(rp, wd->img_verticalcontainer, pos, data->ContainerVertTile_o, is, data->ContainerVertTile_s, bx0, y, is, size);
3139 y = WriteTiledImageVertical(rp, wd->img_verticalcontainer, pos, data->ContainerBottom_o, is, data->ContainerBottom_s, bx0, y, is, data->ContainerBottom_s);
3142 else if ((pi->Flags & FREEHORIZ) != 0)
3145 is = data->img_horizontalcontainer->h >> 1;
3146 if (window->Flags & (WFLG_WINDOWACTIVE | WFLG_TOOLBOX)) pos = 0; else pos = is;
3147 x = bx0;
3148 size = bx1 - bx0 - data->ContainerLeft_s - data->ContainerRight_s + 1;
3149 x = WriteTiledImageHorizontal(rp, wd->img_horizontalcontainer, data->ContainerLeft_o, pos, data->ContainerLeft_s, is, x, by0, data->ContainerLeft_s, is);
3150 if (size > 0) x = WriteTiledImageHorizontal(rp, wd->img_horizontalcontainer, data->ContainerHorTile_o, pos, data->ContainerHorTile_s, is, x, by0, size, is);
3151 x = WriteTiledImageHorizontal(rp, wd->img_horizontalcontainer, data->ContainerRight_o, pos, data->ContainerRight_s, is, x, by0, data->ContainerRight_s, is);
3154 bx0 = msg->wdp_PropRect->MinX;
3155 by0 = msg->wdp_PropRect->MinY;
3156 bx1 = msg->wdp_PropRect->MaxX;
3157 by1 = msg->wdp_PropRect->MaxY;
3159 r = msg->wdp_RenderRect;
3160 if ((pi->Flags & FREEVERT) != 0)
3162 is = data->img_verticalknob->w / 3;
3163 if (hit) pos = is; else if (window->Flags & (WFLG_WINDOWACTIVE | WFLG_TOOLBOX)) pos = 0; else pos = is * 2;
3164 y = r->MinY - by0;
3165 size = r->MaxY - r->MinY - data->KnobTop_s - data->KnobBottom_s + 1;
3167 y = WriteTiledImageVertical(rp, wd->img_verticalknob, pos, data->KnobTop_o, is, data->KnobTop_s, r->MinX - bx0, y, is, data->KnobTop_s);
3168 if (size > 0)
3170 if (size > data->KnobVertGripper_s)
3172 size = size - data->KnobVertGripper_s;
3173 int size_bak = size;
3174 size = size / 2;
3175 if (size > 0) y = WriteTiledImageVertical(rp, wd->img_verticalknob, pos, data->KnobTileTop_o, is, data->KnobTileTop_s, r->MinX - bx0, y, is, size);
3176 y = WriteTiledImageVertical(rp, wd->img_verticalknob, pos, data->KnobVertGripper_o, is, data->KnobVertGripper_s, r->MinX - bx0, y, is, data->KnobVertGripper_s);
3177 size = size_bak - size;
3178 if (size > 0) y = WriteTiledImageVertical(rp, wd->img_verticalknob, pos, data->KnobTileBottom_o, is, data->KnobTileBottom_s, r->MinX - bx0, y, is, size);
3180 else
3182 y = WriteTiledImageVertical(rp, wd->img_verticalknob, pos, data->KnobTileTop_o, is, data->KnobTileTop_s, r->MinX - bx0, y, is, size);
3185 y = WriteTiledImageVertical(rp, wd->img_verticalknob, pos, data->KnobBottom_o, is, data->KnobBottom_s, r->MinX - bx0, y, is, data->KnobBottom_s);
3187 else if ((pi->Flags & FREEHORIZ) != 0)
3190 is = data->img_horizontalknob->h / 3;
3191 if (hit) pos = is; else if (window->Flags & (WFLG_WINDOWACTIVE | WFLG_TOOLBOX)) pos = 0; else pos = is * 2;
3192 x = r->MinX - bx0;
3193 size = r->MaxX - r->MinX - data->KnobLeft_s - data->KnobRight_s + 1;
3194 x = WriteTiledImageHorizontal(rp, wd->img_horizontalknob, data->KnobLeft_o, pos, data->KnobLeft_s, is, x, r->MinY - by0, data->KnobLeft_s, is);
3196 if (size > 0)
3198 if (size > data->KnobHorGripper_s)
3200 size = size - data->KnobHorGripper_s;
3201 int size_bak = size;
3202 size = size / 2;
3203 if (size > 0) x = WriteTiledImageHorizontal(rp, wd->img_horizontalknob, data->KnobTileLeft_o, pos, data->KnobTileLeft_s, is, x, r->MinY - by0, size, is);
3204 x = WriteTiledImageHorizontal(rp, wd->img_horizontalknob, data->KnobHorGripper_o, pos, data->KnobHorGripper_s, is, x, r->MinY - by0, data->KnobHorGripper_s, is);
3205 size = size_bak - size;
3206 if (size > 0) x = WriteTiledImageHorizontal(rp, wd->img_horizontalknob, data->KnobTileRight_o, pos, data->KnobTileRight_s, is, x, r->MinY - by0, size, is);
3208 else
3210 x = WriteTiledImageHorizontal(rp, wd->img_horizontalknob, data->KnobTileRight_o, pos, data->KnobTileRight_s, is, x, r->MinY - by0, size, is);
3213 x = WriteTiledImageHorizontal(rp, wd->img_horizontalknob, data->KnobRight_o, pos, data->KnobRight_s, is, x, r->MinY - by0, data->KnobRight_s, is);
3216 BltBitMapRastPort(rp->BitMap, 0, 0, winrp, msg->wdp_PropRect->MinX, msg->wdp_PropRect->MinY, bx1 - bx0 + 1, by1 - by0 + 1, 0xc0);
3218 FreeBitMap(rp->BitMap);
3219 FreeRastPort(rp);
3221 return TRUE;
3224 IPTR windecor_getdefsizes(Class *cl, Object *obj, struct wdpGetDefSizeSysImage *msg)
3226 struct windecor_data *data = INST_DATA(cl, obj);
3227 struct NewImage *n = NULL;
3228 WORD w = 0, h = 0;
3229 BOOL isset = FALSE;
3230 switch(msg->wdp_Which)
3232 case SIZEIMAGE:
3233 n = NULL;
3234 w = data->rightbordergads;
3235 h = data->bottombordergads;
3236 isset = TRUE;
3237 break;
3239 case CLOSEIMAGE:
3240 n = data->img_close;
3241 isset = TRUE;
3242 break;
3244 case MUIIMAGE:
3245 n = data->img_mui;
3246 isset = TRUE;
3247 break;
3249 case POPUPIMAGE:
3250 n = data->img_popup;
3251 isset = TRUE;
3252 break;
3254 case SNAPSHOTIMAGE:
3255 n = data->img_snapshot;
3256 isset = TRUE;
3257 break;
3259 case ICONIFYIMAGE:
3260 n = data->img_iconify;
3261 isset = TRUE;
3262 break;
3264 case LOCKIMAGE:
3265 n = data->img_lock;
3266 isset = TRUE;
3267 break;
3269 case UPIMAGE:
3270 n = NULL;
3271 w = data->rightbordergads;
3272 h = data->img_up->h + data->updownaddy;
3273 isset = TRUE;
3274 break;
3276 case DOWNIMAGE:
3277 n = NULL;
3278 w = data->rightbordergads;
3279 h = data->img_down->h + data->updownaddy;
3280 isset = TRUE;
3281 break;
3283 case LEFTIMAGE:
3284 n = NULL;
3285 if (data->threestate) w = (data->img_left->w / 3); else w = (data->img_left->w >> 2);
3286 w += data->leftrightaddx;
3287 h = data->bottombordergads;
3288 isset = TRUE;
3289 break;
3291 case RIGHTIMAGE:
3292 n = NULL;
3293 if (data->threestate) w = (data->img_right->w / 3); else w = (data->img_right->w >> 2);
3294 w += data->leftrightaddx;
3295 h = data->bottombordergads;
3296 isset = TRUE;
3297 break;
3299 case DEPTHIMAGE:
3300 n = data->img_depth;
3301 isset = TRUE;
3302 break;
3304 case ZOOMIMAGE:
3305 n = data->img_zoom;
3306 isset = TRUE;
3307 break;
3309 default:
3310 return FALSE;
3313 if (!isset) return DoSuperMethodA(cl, obj, (Msg) msg);
3315 if (n == NULL)
3317 *msg->wdp_Width = w;
3318 *msg->wdp_Height = h;
3320 else
3322 if (n->ok) {
3323 if (data->threestate)
3325 *msg->wdp_Width = (n->w / 3);
3326 *msg->wdp_Height = n->h;
3328 else
3330 *msg->wdp_Width = (n->w >> 2);
3331 *msg->wdp_Height = n->h;
3333 } else return DoSuperMethodA(cl, obj, (Msg) msg);
3336 return TRUE;
3339 struct Region *RegionFromLUT8Image(int w, int h, struct NewLUT8Image *s)
3341 struct Region *shape;
3342 int x, y;
3343 BOOL transp, transpstate;
3344 BOOL failed = FALSE;
3346 if (s == NULL) return NULL;
3348 UBYTE *src = s->data;
3350 shape = NewRegion();
3352 if (shape) {
3353 struct Rectangle rect = {0, s->h, w-1, h-1};
3354 if (!OrRectRegion(shape, &rect)) failed = TRUE;
3355 for(y = 0; y < s->h; y++)
3357 struct Rectangle rect = {0, y, 0, y};
3358 transpstate = TRUE;
3359 for(x = 0; x < s->w; x++)
3361 transp = src[y * s->w + x] == 0;
3362 if (transpstate)
3364 if (!transp)
3366 rect.MaxX = rect.MinX = x;
3367 transpstate = FALSE;
3369 } else {
3370 if (transp)
3372 OrRectRegion(shape, &rect);
3373 transpstate = TRUE;
3375 else
3377 rect.MaxX++;
3381 if (!transpstate) if (!OrRectRegion(shape, &rect)) failed = TRUE;
3383 if (failed)
3385 DisposeRegion(shape);
3386 shape = NULL;
3389 return shape;
3393 void DrawShapePartialTitleBar(struct WindowData *wd, struct NewLUT8Image *shape, struct windecor_data *data, struct Window *window, UWORD align, UWORD start, UWORD width)
3395 int xl0, xl1, xr0, xr1, defwidth;
3396 ULONG textlen = 0, titlelen = 0, textpixellen = 0;
3397 struct TextExtent te;
3399 BOOL hastitle;
3400 BOOL hastitlebar;
3401 UWORD textstart = 0, barh, x;
3402 int dy;
3404 struct RastPort *rp = &window->WScreen->RastPort;
3405 hastitle = window->Title != NULL ? TRUE : FALSE;
3406 hastitlebar = (window->BorderTop == data->winbarheight) ? TRUE : FALSE;
3408 if (window->Flags & (WFLG_WINDOWACTIVE | WFLG_TOOLBOX))
3410 dy = 0;
3412 else
3414 dy = data->winbarheight;
3416 getleftgadgetsdimensions(data, window, &xl0, &xl1);
3417 getrightgadgetsdimensions(data, window, &xr0, &xr1);
3419 defwidth = (xl0 != xl1) ? data->BarPreGadget_s : data->BarPre_s;
3420 if(xr1 == 0)
3422 xr1 = window->Width - data->BarPre_s;
3423 xr0 = window->Width - data->BarPre_s;
3426 defwidth += (xl1 - xl0);
3428 defwidth += data->BarJoinGB_s;
3429 defwidth += data->BarJoinBT_s;
3430 defwidth += data->BarJoinTB_s;
3431 defwidth += data->BarJoinBG_s;
3432 defwidth += (xr1 - xr0);
3433 defwidth += (xr0 != xr1) ? data->BarPostGadget_s : data->BarPost_s;
3435 if (defwidth >= window->Width) hastitle = FALSE;
3437 if (hastitle)
3439 titlelen = strlen(window->Title);
3440 textlen = TextFit(rp, window->Title, titlelen, &te, NULL, 1, window->Width-defwidth, window->BorderTop - 2);
3441 if (textlen)
3443 textpixellen = te.te_Extent.MaxX - te.te_Extent.MinX + 1;
3448 if (data->img_winbar_normal->ok && hastitlebar)
3450 barh = data->img_winbar_normal->h;
3451 if (data->barvert)
3453 if (barh > data->winbarheight) barh = data->winbarheight;
3455 x = 0;
3456 if (xl0 != xl1)
3458 x = WriteTiledImageShape(data->filltitlebar, window, shape, data->img_winbar_normal, data->BarPreGadget_o, dy, data->BarPreGadget_s, barh, x, 0, data->BarPreGadget_s, barh);
3459 if ((xl1-xl0) > 0) x = WriteTiledImageShape(data->filltitlebar, window, shape, data->img_winbar_normal, data->BarLGadgetFill_o, dy, data->BarLGadgetFill_s, barh, x, 0, xl1-xl0, barh);
3461 else
3463 x = WriteTiledImageShape(data->filltitlebar, window, shape, data->img_winbar_normal, data->BarPre_o, dy, data->BarPre_s, barh, x, 0, data->BarPreGadget_s, barh);
3465 x = WriteTiledImageShape(data->filltitlebar, window, shape, data->img_winbar_normal, data->BarJoinGB_o, dy, data->BarJoinGB_s, barh, x, 0, data->BarJoinGB_s, barh);
3466 if (hastitle && (textlen > 0))
3468 switch(align)
3470 case WD_DWTA_CENTER:
3471 //BarLFill
3472 x = WriteTiledImageShape(data->filltitlebar, window, shape, data->img_winbar_normal, data->BarLFill_o, dy, data->BarLFill_s, barh, x, 0, 60, barh);
3473 break;
3474 case WD_DWTA_RIGHT:
3475 //BarLFill
3476 break;
3477 default:
3478 case WD_DWTA_LEFT:
3479 break;
3481 x = WriteTiledImageShape(data->filltitlebar, window, shape, data->img_winbar_normal, data->BarJoinBT_o, dy, data->BarJoinBT_s, barh, x, 0, data->BarJoinBT_s, barh);
3482 textstart = x;
3483 if (textpixellen > 0) x = WriteTiledImageShape(data->filltitlebar, window, shape, data->img_winbar_normal, data->BarTitleFill_o, dy, data->BarTitleFill_s, barh, x, 0, textpixellen, barh);
3484 x = WriteTiledImageShape(data->filltitlebar, window, shape, data->img_winbar_normal, data->BarJoinTB_o, dy, data->BarJoinTB_s, barh, x, 0, data->BarJoinTB_s, barh);
3486 x = WriteTiledImageShape(data->filltitlebar, window, shape, data->img_winbar_normal, data->BarRFill_o, dy, data->BarRFill_s, barh, x, 0, xr0 - x - data->BarJoinBG_s, barh);
3487 x = WriteTiledImageShape(data->filltitlebar, window, shape, data->img_winbar_normal, data->BarJoinBG_o, dy, data->BarJoinBG_s, barh, x, 0, data->BarJoinBG_s, barh);
3488 if ((xr1-xr0) > 0) x = WriteTiledImageShape(data->filltitlebar, window, shape, data->img_winbar_normal, data->BarRGadgetFill_o, dy, data->BarRGadgetFill_s, barh, x, 0, xr1-xr0, barh);
3489 if (xr0 != xr1)
3491 x = WriteTiledImageShape(data->filltitlebar, window, shape, data->img_winbar_normal, data->BarPostGadget_o, dy, data->BarPostGadget_s, barh, x, 0, data->BarPostGadget_s, barh);
3493 else
3495 x = WriteTiledImageShape(data->filltitlebar, window, shape, data->img_winbar_normal, data->BarPost_o, dy, data->BarPost_s, barh, x, 0, data->BarPost_s, barh);
3503 /**************************************************************************************************/
3504 IPTR windecor_windowshape(Class *cl, Object *obj, struct wdpWindowShape *msg)
3506 struct windecor_data *data = INST_DATA(cl, obj);
3507 struct WindowData *wd = (struct WindowData *) msg->wdp_UserBuffer;
3508 struct Window *window = msg->wdp_Window;
3510 if (data->barmasking)
3512 struct NewLUT8ImageContainer *shape;
3513 IPTR back = 0;
3514 shape = (struct NewLUT8ImageContainer *)NewLUT8ImageContainer(window->Width, window->BorderTop);
3515 if (shape)
3517 if (window->BorderTop == data->winbarheight) DrawShapePartialTitleBar(wd, (struct NewLUT8Image *)shape, data, window, data->txt_align, 0, window->Width);
3518 back =(IPTR) RegionFromLUT8Image(msg->wdp_Width, msg->wdp_Height, (struct NewLUT8Image *)shape);
3520 DisposeLUT8ImageContainer((struct NewLUT8Image *)shape);
3521 return back;
3527 if (!data->rounded) return (IPTR) NULL;
3529 struct Region *newshape;
3531 int x2 = msg->wdp_Width-1;
3532 int y2 = msg->wdp_Height-1;
3534 if ((newshape = NewRegion()))
3536 struct Rectangle rect;
3537 BOOL success = TRUE;
3539 rect.MinX = 9;
3540 rect.MinY = 0;
3541 rect.MaxX = x2 - 9;
3542 rect.MaxY = y2;
3543 success &= OrRectRegion(newshape, &rect);
3545 rect.MinX = 6;
3546 rect.MinY = 1;
3547 rect.MaxX = x2 - 6;
3548 rect.MaxY = y2;
3549 success &= OrRectRegion(newshape, &rect);
3551 rect.MinX = 4;
3552 rect.MinY = 2;
3553 rect.MaxX = x2 - 4;
3554 rect.MaxY = y2;
3555 success &= OrRectRegion(newshape, &rect);
3557 rect.MinX = 3;
3558 rect.MinY = 3;
3559 rect.MaxX = x2 - 3;
3560 rect.MaxY = y2;
3561 success &= OrRectRegion(newshape, &rect);
3563 rect.MinX = 2;
3564 rect.MinY = 4;
3565 rect.MaxX = x2 - 2;
3566 rect.MaxY = y2;
3567 success &= OrRectRegion(newshape, &rect);
3569 rect.MinX = 1;
3570 rect.MinY = 6;
3571 rect.MaxX = x2 - 1;
3572 rect.MaxY = y2;
3573 success &= OrRectRegion(newshape, &rect);
3575 rect.MinX = 0;
3576 rect.MinY = 9;
3577 rect.MaxX = x2;
3578 rect.MaxY = y2;
3579 success &= OrRectRegion(newshape, &rect);
3581 return (IPTR) newshape;
3584 /**************************************************************************************************/
3586 IPTR windecor_initwindow(Class *cl, Object *obj, struct wdpInitWindow *msg)
3588 struct WindowData *wd = (struct WindowData *)msg->wdp_UserBuffer;
3589 struct ScreenData *sd = (struct ScreenData *)msg->wdp_ScreenUserBuffer;
3591 wd->truecolor = msg->wdp_TrueColor;
3593 wd->ActivePen = sd->ActivePen;
3594 wd->DeactivePen = sd->DeactivePen;
3596 SETIMAGE_WIN(size);
3597 SETIMAGE_WIN(close);
3598 SETIMAGE_WIN(depth);
3599 SETIMAGE_WIN(zoom);
3600 SETIMAGE_WIN(up);
3601 SETIMAGE_WIN(down);
3602 SETIMAGE_WIN(left);
3603 SETIMAGE_WIN(right);
3604 SETIMAGE_WIN(mui);
3605 SETIMAGE_WIN(popup);
3606 SETIMAGE_WIN(snapshot);
3607 SETIMAGE_WIN(iconify);
3608 SETIMAGE_WIN(lock);
3609 SETIMAGE_WIN(winbar_normal);
3610 SETIMAGE_WIN(border_normal);
3611 SETIMAGE_WIN(border_deactivated);
3612 SETIMAGE_WIN(verticalcontainer);
3613 SETIMAGE_WIN(verticalknob);
3614 SETIMAGE_WIN(horizontalcontainer);
3615 SETIMAGE_WIN(horizontalknob);
3617 return TRUE;
3620 /**************************************************************************************************/
3622 IPTR windecor_exitwindow(Class *cl, Object *obj, struct wdpExitWindow *msg)
3624 struct WindowData *wd = (struct WindowData *) msg->wdp_UserBuffer;
3626 if (wd->rp)
3628 if (wd->rp->BitMap) FreeBitMap(wd->rp->BitMap);
3629 FreeRastPort(wd->rp);
3632 return TRUE;
3635 IPTR windecor_dispatcher(struct IClass *cl, Object *obj, Msg msg)
3637 IPTR retval;
3639 switch(msg->MethodID)
3641 case OM_NEW:
3642 retval = windecor_new(cl, obj, (struct opSet *)msg);
3643 break;
3645 case OM_DISPOSE:
3646 retval = windecor_dispose(cl, obj, (struct opSet *)msg);
3647 break;
3649 case OM_GET:
3650 retval = windecor_get(cl, obj, (struct opGet *)msg);
3651 break;
3653 case WDM_DRAW_SYSIMAGE:
3654 retval = windecor_draw_sysimage(cl, obj, (struct wdpDrawSysImage *)msg);
3655 break;
3657 case WDM_DRAW_WINBORDER:
3658 retval = windecor_draw_winborder(cl, obj, (struct wdpDrawWinBorder *)msg);
3659 break;
3661 case WDM_LAYOUT_BORDERGADGETS:
3662 retval = windecor_layout_bordergadgets(cl, obj, (struct wdpLayoutBorderGadgets *)msg);
3663 break;
3665 case WDM_DRAW_BORDERPROPBACK:
3666 retval = windecor_draw_borderpropback(cl, obj, (struct wdpDrawBorderPropBack *)msg);
3667 break;
3669 case WDM_DRAW_BORDERPROPKNOB:
3670 retval = windecor_draw_borderpropknob(cl, obj, (struct wdpDrawBorderPropKnob *)msg);
3671 break;
3673 case WDM_GETDEFSIZE_SYSIMAGE:
3674 retval = windecor_getdefsizes(cl, obj, (struct wdpGetDefSizeSysImage *) msg);
3675 break;
3677 case WDM_WINDOWSHAPE:
3678 retval = windecor_windowshape(cl, obj, (struct wdpWindowShape *) msg);
3679 break;
3681 case WDM_INITWINDOW:
3682 retval = windecor_initwindow(cl, obj, (struct wdpInitWindow *) msg);
3683 break;
3685 case WDM_EXITWINDOW:
3686 retval = windecor_exitwindow(cl, obj, (struct wdpExitWindow *) msg);
3687 break;
3689 default:
3690 retval = DoSuperMethodA(cl, obj, msg);
3691 break;
3694 return retval;
3697 static IPTR scrdecor_new(Class *cl, Object *obj, struct opSet *msg)
3699 struct scrdecor_data *data;
3700 UWORD barh;
3702 obj = (Object *)DoSuperMethodA(cl, obj, (Msg)msg);
3704 if (obj)
3706 data = INST_DATA(cl, obj);
3707 STRPTR path = (STRPTR) GetTagData(SDA_Configuration, (IPTR) "Theme:", msg->ops_AttrList);
3709 if (!InitScreenSkinning(path, data))
3711 CoerceMethod(cl,obj,OM_DISPOSE);
3712 obj = NULL;
3714 else
3716 barh = data->sbarheight;
3718 if (data->img_sbarlogo) if (data->img_sbarlogo->h > barh) barh = data->img_sbarlogo->h;
3719 if (data->img_stitlebar) if (data->img_stitlebar->h > barh) barh = data->img_stitlebar->h;
3722 return (IPTR)obj;
3725 static IPTR scrdecor_dispose(Class *cl, Object *obj, struct opSet *msg)
3727 struct scrdecor_data *data = INST_DATA(cl, obj);
3729 DisposeScreenSkinning(data);
3731 return 1;
3734 /**************************************************************************************************/
3736 static IPTR scrdecor_get(Class *cl, Object *obj, struct opGet *msg)
3739 switch(msg->opg_AttrID)
3741 case SDA_TrueColorOnly:
3742 *msg->opg_Storage = TRUE;
3743 break;
3745 case SDA_ScreenData:
3746 *msg->opg_Storage = (IPTR)INST_DATA(cl, obj);
3747 break;
3749 default:
3750 return DoSuperMethodA(cl, obj, (Msg)msg);
3752 return 1;
3755 /**************************************************************************************************/
3757 static void scr_findtitlearea(struct Screen *scr, LONG *left, LONG *right)
3759 struct Gadget *g;
3761 *left = 0;
3762 *right = scr->Width - 1;
3764 for (g = scr->FirstGadget; g; g = g->NextGadget)
3766 if (!(g->Flags & GFLG_RELRIGHT))
3768 if (g->LeftEdge + g->Width > *left) *left = g->LeftEdge + g->Width;
3770 else
3772 if (g->LeftEdge + scr->Width - 1 - 1 < *right) *right = g->LeftEdge + scr->Width - 1 - 1;
3777 IPTR scrdecor_draw_screenbar(Class *cl, Object *obj, struct sdpDrawScreenBar *msg)
3779 struct scrdecor_data *data = INST_DATA(cl, obj);
3780 struct ScreenData *sd = (struct ScreenData *) msg->sdp_UserBuffer;
3781 struct TextExtent te;
3782 struct RastPort *rp = msg->sdp_RPort;
3783 struct Screen *scr = msg->sdp_Screen;
3784 LONG left, right, titlelen = 0;
3785 BOOL hastitle = TRUE;
3787 if (sd->img_stitlebar.ok) WriteTiledImage(NULL, rp, &sd->img_stitlebar, 0, 0, data->img_stitlebar->w, data->img_stitlebar->h, 0, 0, scr->Width, data->img_stitlebar->h);
3788 if (sd->img_sbarlogo.ok) WriteTiledImage(NULL, rp, &sd->img_sbarlogo, 0, 0, data->img_sbarlogo->w, data->img_sbarlogo->h, data->slogo_off, (scr->BarHeight + 1 - data->img_sbarlogo->h) / 2, data->img_sbarlogo->w, data->img_sbarlogo->h);
3789 if (scr->Title == NULL) hastitle = FALSE;
3791 if (hastitle)
3793 scr_findtitlearea(scr, &left, &right);
3794 titlelen = strlen(scr->Title);
3795 titlelen = TextFit(rp, scr->Title, titlelen, &te, NULL, 1, right - data->stitle_off, data->sbarheight);
3796 if (titlelen == 0) hastitle = 0;
3799 if (hastitle)
3801 UWORD tx = data->stitle_off;
3802 UWORD ty = (scr->BarHeight + 1 - msg->sdp_Dri->dri_Font->tf_YSize) / 2 + rp->TxBaseline;
3804 SetFont(rp, msg->sdp_Dri->dri_Font);
3805 SetDrMd(rp, JAM1);
3806 // Move(rp, data->stitle_off, (scr->BarHeight + 1 - msg->sdp_Dri->dri_Font->tf_YSize) / 2 + rp->TxBaseline);
3807 // Text(rp, scr->Title, titlelen);
3809 if (!sd->truecolor || ((data->outline == FALSE) && (data->shadow == FALSE)))
3811 Move(rp, tx, ty);
3812 Text(rp, scr->Title, titlelen);
3814 else if (data->outline)
3817 SetSoftStyle(rp, FSF_BOLD, AskSoftStyle(rp));
3818 SetRPAttrs(rp, RPTAG_PenMode, FALSE, RPTAG_FgColor, data->shadow_col, TAG_DONE);
3820 Move(rp, tx + 1, ty ); Text(rp, scr->Title, titlelen);
3821 Move(rp, tx + 2, ty ); Text(rp, scr->Title, titlelen);
3822 Move(rp, tx , ty ); Text(rp, scr->Title, titlelen);
3823 Move(rp, tx, ty + 1); Text(rp, scr->Title, titlelen);
3824 Move(rp, tx, ty + 2); Text(rp, scr->Title, titlelen);
3825 Move(rp, tx + 1, ty + 2); Text(rp, scr->Title, titlelen);
3826 Move(rp, tx + 2, ty + 1); Text(rp, scr->Title, titlelen);
3827 Move(rp, tx + 2, ty + 2); Text(rp, scr->Title, titlelen);
3829 SetRPAttrs(rp, RPTAG_PenMode, FALSE, RPTAG_FgColor, data->text_col, TAG_DONE);
3830 Move(rp, tx + 1, ty + 1);
3831 Text(rp, scr->Title, titlelen);
3832 SetSoftStyle(rp, FS_NORMAL, AskSoftStyle(rp));
3834 else
3836 SetRPAttrs(rp, RPTAG_PenMode, FALSE, RPTAG_FgColor, data->shadow_col, TAG_DONE);
3837 Move(rp, tx + 1, ty + 1 );
3838 Text(rp, scr->Title, titlelen);
3840 SetRPAttrs(rp, RPTAG_PenMode, FALSE, RPTAG_FgColor, data->text_col, TAG_DONE);
3841 Move(rp, tx, ty);
3842 Text(rp, scr->Title, titlelen);
3846 return TRUE;
3849 IPTR scrdecor_getdefsize_sysimage(Class *cl, Object *obj, struct sdpGetDefSizeSysImage *msg)
3851 struct scrdecor_data *data = INST_DATA(cl, obj);
3853 if (msg->sdp_Which == SDEPTHIMAGE)
3855 if (data->img_sdepth)
3857 *msg->sdp_Height = data->img_sdepth->h;
3858 *msg->sdp_Width = data->img_sdepth->w >> 1;
3860 else return DoSuperMethodA(cl, obj, (Msg) msg);
3862 else return DoSuperMethodA(cl, obj, (Msg) msg);
3864 return TRUE;
3867 IPTR scrdecor_draw_sysimage(Class *cl, Object *obj, struct sdpDrawSysImage *msg)
3869 struct scrdecor_data *data = INST_DATA(cl, obj);
3870 struct ScreenData *sd = (struct ScreenData *) msg->sdp_UserBuffer;
3872 struct RastPort *rp = msg->sdp_RPort;
3873 LONG left = msg->sdp_X;
3874 LONG top = msg->sdp_Y;
3875 LONG state = msg->sdp_State;
3877 if (msg->sdp_Which == SDEPTHIMAGE)
3879 if (data->img_sdepth)
3881 DrawAlphaStateImageToRP(NULL, rp, &sd->img_sdepth, state, left, top, TRUE);
3883 else return DoSuperMethodA(cl, obj, (Msg) msg);
3885 else return DoSuperMethodA(cl, obj, (Msg) msg);
3887 return TRUE;
3890 IPTR scrdecor_layoutscrgadgets(Class *cl, Object *obj, struct sdpLayoutScreenGadgets *msg)
3892 struct Gadget *gadget = msg->sdp_Gadgets;
3894 struct scrdecor_data *data = INST_DATA(cl, obj);
3896 while(gadget)
3898 switch(gadget->GadgetType & GTYP_SYSTYPEMASK)
3900 case GTYP_SDEPTH:
3901 gadget->LeftEdge = -gadget->Width;
3902 gadget->TopEdge = (data->sbarheight - data->img_sdepth->h) >> 1;
3903 gadget->Flags &= ~GFLG_RELWIDTH;
3904 gadget->Flags |= GFLG_RELRIGHT;
3905 break;
3908 if (msg->sdp_Flags & SDF_LSG_MULTIPLE)
3910 gadget = gadget->NextGadget;
3912 else
3914 gadget = NULL;
3918 return TRUE;
3922 IPTR scrdecor_initscreen(Class *cl, Object *obj, struct sdpInitScreen *msg)
3924 struct scrdecor_data *data = INST_DATA(cl, obj);
3925 struct ScreenData *sd = (struct ScreenData *)msg->sdp_UserBuffer;
3926 struct Screen *screen = msg->sdp_Screen;
3928 sd->truecolor = msg->sdp_TrueColor;
3930 BOOL truecolor = sd->truecolor;
3932 msg->sdp_WBorTop = data->winbarheight - 1 - msg->sdp_FontHeight;
3933 msg->sdp_BarHBorder = 1;
3934 msg->sdp_BarHeight = data->sbarheight - 1; //compatiblity issue
3935 msg->sdp_WBorLeft = data->leftborder;
3936 msg->sdp_WBorRight = data->rightborder;
3937 msg->sdp_WBorBottom = data->bottomborder;
3939 sd->ActivePen = -1;
3940 sd->DeactivePen = -1;
3941 if (!truecolor) {
3942 sd->ActivePen = ObtainPen(screen->ViewPort.ColorMap, -1, (data->lut_col_a << 8) & 0xff000000, (data->lut_col_a << 16) & 0xff000000, (data->lut_col_a << 24) & 0xff000000, PEN_EXCLUSIVE);
3943 sd->DeactivePen = ObtainPen(screen->ViewPort.ColorMap, -1, (data->lut_col_d << 8) & 0xff000000, (data->lut_col_d << 16) & 0xff000000, (data->lut_col_d << 24) & 0xff000000, PEN_EXCLUSIVE);
3946 SETIMAGE_SCR(sdepth);
3947 SETIMAGE_SCR(sbarlogo);
3948 SETIMAGE_SCR(stitlebar);
3950 SETIMAGE_SCR(size);
3951 SETIMAGE_SCR(close);
3952 SETIMAGE_SCR(depth);
3953 SETIMAGE_SCR(zoom);
3954 SETIMAGE_SCR(up);
3955 SETIMAGE_SCR(down);
3956 SETIMAGE_SCR(left);
3957 SETIMAGE_SCR(right);
3958 SETIMAGE_SCR(mui);
3959 SETIMAGE_SCR(popup);
3960 SETIMAGE_SCR(snapshot);
3961 SETIMAGE_SCR(iconify);
3962 SETIMAGE_SCR(lock);
3963 SETIMAGE_SCR(winbar_normal);
3964 SETIMAGE_SCR(border_normal);
3965 SETIMAGE_SCR(border_deactivated);
3966 SETIMAGE_SCR(verticalcontainer);
3967 SETIMAGE_SCR(verticalknob);
3968 SETIMAGE_SCR(horizontalcontainer);
3969 SETIMAGE_SCR(horizontalknob);
3971 SETIMAGE_SCR(menu);
3972 SETIMAGE_SCR(amigakey);
3973 SETIMAGE_SCR(menucheck);
3974 SETIMAGE_SCR(submenu);
3976 return TRUE;
3979 IPTR scrdecor_exitscreen(Class *cl, Object *obj, struct sdpExitScreen *msg)
3981 struct ScreenData *sd = (struct ScreenData *)msg->sdp_UserBuffer;
3983 DELIMAGE_SCR(sdepth);
3984 DELIMAGE_SCR(sbarlogo);
3985 DELIMAGE_SCR(stitlebar);
3987 DELIMAGE_SCR(size);
3988 DELIMAGE_SCR(close);
3989 DELIMAGE_SCR(depth);
3990 DELIMAGE_SCR(zoom);
3991 DELIMAGE_SCR(up);
3992 DELIMAGE_SCR(down);
3993 DELIMAGE_SCR(left);
3994 DELIMAGE_SCR(right);
3995 DELIMAGE_SCR(mui);
3996 DELIMAGE_SCR(popup);
3997 DELIMAGE_SCR(snapshot);
3998 DELIMAGE_SCR(iconify);
3999 DELIMAGE_SCR(lock);
4000 DELIMAGE_SCR(winbar_normal);
4001 DELIMAGE_SCR(border_normal);
4002 DELIMAGE_SCR(border_deactivated);
4003 DELIMAGE_SCR(verticalcontainer);
4004 DELIMAGE_SCR(verticalknob);
4005 DELIMAGE_SCR(horizontalcontainer);
4006 DELIMAGE_SCR(horizontalknob);
4008 DELIMAGE_SCR(menu);
4009 DELIMAGE_SCR(amigakey);
4010 DELIMAGE_SCR(menucheck);
4011 DELIMAGE_SCR(submenu);
4013 return TRUE;
4016 /**************************************************************************************************/
4018 IPTR scrdecor_dispatcher(struct IClass *cl, Object *obj, Msg msg)
4020 IPTR retval;
4022 switch(msg->MethodID)
4024 case OM_NEW:
4025 retval = scrdecor_new(cl, obj, (struct opSet *)msg);
4026 break;
4028 case OM_DISPOSE:
4029 retval = scrdecor_dispose(cl, obj, (struct opSet *)msg);
4030 break;
4032 case OM_GET:
4033 retval = scrdecor_get(cl, obj, (struct opGet *)msg);
4034 break;
4036 case SDM_GETDEFSIZE_SYSIMAGE:
4037 retval = scrdecor_getdefsize_sysimage(cl, obj, (struct sdpGetDefSizeSysImage *)msg);
4038 break;
4040 case SDM_DRAW_SCREENBAR:
4041 retval = scrdecor_draw_screenbar(cl, obj, (struct sdpDrawScreenBar *)msg);
4042 break;
4044 case SDM_DRAW_SYSIMAGE:
4045 retval = scrdecor_draw_sysimage(cl, obj, (struct sdpDrawSysImage *)msg);
4046 break;
4048 case SDM_LAYOUT_SCREENGADGETS:
4049 retval = scrdecor_layoutscrgadgets(cl, obj, (struct sdpLayoutScreenGadgets *)msg);
4050 break;
4052 case SDM_INITSCREEN:
4053 retval = scrdecor_initscreen(cl, obj, (struct sdpInitScreen *)msg);
4054 break;
4056 case SDM_EXITSCREEN:
4057 retval = scrdecor_exitscreen(cl, obj, (struct sdpExitScreen *)msg);
4058 break;
4060 default:
4061 retval = DoSuperMethodA(cl, obj, msg);
4062 break;
4065 return retval;
4068 IPTR menudecor_getdefsizes(Class *cl, Object *obj, struct mdpGetDefSizeSysImage *msg)
4070 struct menudecor_data *data = INST_DATA(cl, obj);
4072 struct NewImage *n = NULL;
4073 BOOL isset = FALSE;
4075 switch(msg->mdp_Which)
4077 case AMIGAKEY:
4078 n = data->img_amigakey;
4079 isset = TRUE;
4080 break;
4082 case MENUCHECK:
4083 n = data->img_menucheck;
4084 isset = TRUE;
4085 break;
4087 case SUBMENUIMAGE:
4088 n = data->img_submenu;
4089 isset = TRUE;
4090 break;
4092 default:
4093 return FALSE;
4096 if (!isset || (n==NULL)) return DoSuperMethodA(cl, obj, (Msg) msg);
4098 *msg->mdp_Width = n->w;
4099 *msg->mdp_Height = n->h;
4100 return TRUE;
4103 IPTR menudecor_draw_sysimage(Class *cl, Object *obj, struct mdpDrawSysImage *msg)
4105 struct ScreenData *md = (struct ScreenData *) msg->mdp_UserBuffer;
4106 struct RastPort *rp = msg->mdp_RPort;
4107 struct NewImage *ni = NULL;
4108 LONG state = msg->mdp_State;
4109 LONG left = msg->mdp_X;
4110 LONG top = msg->mdp_Y;
4111 WORD addx = 0;
4112 WORD addy = 0;
4113 BOOL isset = FALSE;
4115 switch(msg->mdp_Which)
4117 case AMIGAKEY:
4118 if (md->img_amigakey.ok)
4120 ni = &md->img_amigakey;
4121 isset = TRUE;
4123 break;
4125 case MENUCHECK:
4126 if (md->img_amigakey.ok)
4128 ni = &md->img_menucheck;
4129 isset = TRUE;
4131 break;
4133 case SUBMENUIMAGE:
4134 if (md->img_submenu.ok)
4136 ni = &md->img_submenu;
4137 isset = TRUE;
4139 break;
4141 default:
4142 return DoSuperMethodA(cl, obj, (Msg)msg);
4145 if (!isset || (ni == NULL)) return DoSuperMethodA(cl, obj, (Msg)msg);
4147 DrawAlphaStateImageToRP(NULL, rp, ni, state, left+addx, top+addy, FALSE);
4149 return TRUE;
4152 /**************************************************************************************************/
4154 IPTR menudecor_renderbackground(Class *cl, Object *obj, struct mdpDrawBackground *msg)
4156 struct RastPort *rp = msg->mdp_RPort;
4157 struct NewImage *ni;
4158 struct MenuData *md = (struct MenuData *) msg->mdp_UserBuffer;
4159 UWORD flags = msg->mdp_Flags;
4161 if (!msg->mdp_TrueColor)
4164 if ((flags & HIGHITEM) && md->map)
4167 else
4169 if (md->map)
4171 BltBitMapRastPort(md->map, msg->mdp_ItemLeft, msg->mdp_ItemTop, rp, msg->mdp_ItemLeft, msg->mdp_ItemTop, msg->mdp_ItemWidth, msg->mdp_ItemHeight, 0xc0);
4172 return TRUE;
4175 return FALSE;
4179 if ((flags & HIGHITEM) && md->ni)
4181 ni = NewImageContainer(msg->mdp_ItemWidth, msg->mdp_ItemHeight);
4182 if (ni)
4184 DrawPartToImage(md->ni, ni, msg->mdp_ItemLeft, msg->mdp_ItemTop, msg->mdp_ItemWidth, msg->mdp_ItemHeight, 0, 0);
4185 SetImageTint(ni, 60, 0x00888800);
4186 PutImageToRP(rp, ni, msg->mdp_ItemLeft, msg->mdp_ItemTop);
4189 else
4191 if (md->ni) DrawPartImageToRP(rp, md->ni, msg->mdp_ItemLeft, msg->mdp_ItemTop, msg->mdp_ItemLeft, msg->mdp_ItemTop, msg->mdp_ItemWidth, msg->mdp_ItemHeight);
4194 return TRUE;
4197 IPTR menudecor_initmenu(Class *cl, Object *obj, struct mdpInitMenu *msg)
4199 struct RastPort *rp = msg->mdp_RPort;
4200 struct MenuData *md = (struct MenuData *) msg->mdp_UserBuffer;
4201 struct ScreenData *sd = (struct ScreenData *) msg->mdp_ScreenUserBuffer;
4203 SETIMAGE_MEN(menu);
4204 SETIMAGE_MEN(amigakey);
4205 SETIMAGE_MEN(menucheck);
4206 SETIMAGE_MEN(submenu);
4208 md->truecolor = msg->mdp_TrueColor;
4210 // if (!msg->mdp_TrueColor) return DoSuperMethodA(cl, obj, (Msg) msg);
4212 if (md->truecolor)
4214 md->ni = GetImageFromRP(rp, msg->mdp_Left, msg->mdp_Top, msg->mdp_Width, msg->mdp_Height);
4215 if (md->ni) {
4216 md->ni->ok = TRUE;
4217 RenderBackground(md->ni, md->img_menu, 20);
4220 else
4222 md->map = AllocBitMap(msg->mdp_Width, msg->mdp_Height, 1, BMF_CLEAR, rp->BitMap);
4223 if (md->map) {
4224 BltBitMap(rp->BitMap, msg->mdp_Left, msg->mdp_Top, md->map, 0, 0, msg->mdp_Width, msg->mdp_Height, 0xc0, 0xff, NULL);
4226 TileMapToBitmap(md->img_menu, md->map, msg->mdp_Width, msg->mdp_Height);
4230 return TRUE;
4233 IPTR menudecor_exitmenu(Class *cl, Object *obj, struct mdpExitMenu *msg)
4235 struct MenuData *md = (struct MenuData *) msg->mdp_UserBuffer;
4237 if (md->ni) DisposeImageContainer(md->ni);
4238 if (md->map) FreeBitMap(md->map);
4240 return TRUE;
4243 IPTR menudecor_getmenuspaces(Class *cl, Object *obj, struct mdpGetMenuSpaces *msg)
4245 struct menudecor_data *data = INST_DATA(cl, obj);
4247 if (data->img_menu)
4249 msg->mdp_InnerLeft = data->img_menu->inner_left;
4250 msg->mdp_InnerTop = data->img_menu->inner_top;
4251 msg->mdp_InnerRight = data->img_menu->inner_right;
4252 msg->mdp_InnerBottom = data->img_menu->inner_bottom;
4253 msg->mdp_ItemInnerLeft = 1;
4254 msg->mdp_ItemInnerTop = 2;
4255 msg->mdp_ItemInnerRight = 2;
4256 msg->mdp_ItemInnerBottom = 1;
4257 if ((data->img_menu->tile_left + data->img_menu->tile_right) > (data->img_menu->inner_left + data->img_menu->inner_right)) msg->mdp_MinWidth = data->img_menu->tile_left + data->img_menu->tile_right; else msg->mdp_MinWidth = data->img_menu->inner_left + data->img_menu->inner_right;
4258 if ((data->img_menu->tile_top + data->img_menu->tile_bottom) > (data->img_menu->inner_top + data->img_menu->inner_bottom)) msg->mdp_MinHeight = data->img_menu->tile_top + data->img_menu->tile_bottom; else msg->mdp_MinHeight = data->img_menu->inner_top + data->img_menu->inner_bottom;
4260 return TRUE;
4263 void DisposeMenuSkinning(struct menudecor_data *data)
4267 BOOL InitMenuSkinning(STRPTR path, struct menudecor_data *data) {
4269 char buffer[256];
4270 char *line, *v;
4271 BPTR file;
4272 BOOL tiled = FALSE;
4273 int tile_left = 0;
4274 int tile_top = 0;
4275 int tile_right = 0;
4276 int tile_bottom = 0;
4277 int inner_left = 0;
4278 int inner_top = 0;
4279 int inner_right = 0;
4280 int inner_bottom = 0;
4281 BPTR lock;
4282 BPTR olddir = 0;
4284 lock = Lock(path, ACCESS_READ);
4285 if (lock)
4287 olddir = CurrentDir(lock);
4289 else return FALSE;
4291 file = Open("Menu/Config", MODE_OLDFILE);
4292 if (file)
4296 line = FGets(file, buffer, 256);
4297 if (line)
4299 if ((v = strstr(line, "TileLeft ")) == line)
4301 tile_left = GetInt(v);
4302 tiled = TRUE;
4304 else if ((v = strstr(line, "TileTop ")) == line)
4306 tile_top = GetInt(v);
4307 tiled = TRUE;
4309 else if ((v = strstr(line, "TileRight ")) == line)
4311 tile_right = GetInt(v);
4312 tiled = TRUE;
4314 else if ((v = strstr(line, "TileBottom ")) == line)
4316 tile_bottom = GetInt(v);
4317 tiled = TRUE;
4319 else if ((v = strstr(line, "InnerLeft ")) == line)
4321 inner_left = GetInt(v);
4323 else if ((v = strstr(line, "InnerTop ")) == line)
4325 inner_top = GetInt(v);
4327 else if ((v = strstr(line, "InnerRight ")) == line)
4329 inner_right = GetInt(v);
4331 else if ((v = strstr(line, "InnerBottom ")) == line)
4333 inner_bottom = GetInt(v);
4337 while(line);
4338 Close(file);
4341 PUTIMAGE_MEN(menu);
4342 PUTIMAGE_MEN(amigakey);
4343 PUTIMAGE_MEN(menucheck);
4344 PUTIMAGE_MEN(submenu);
4346 if (data->img_menu)
4348 data->img_menu->tile_left = tile_left;
4349 data->img_menu->tile_right = tile_right;
4350 data->img_menu->tile_top = tile_top;
4351 data->img_menu->tile_bottom = tile_bottom;
4352 data->img_menu->inner_left = inner_left;
4353 data->img_menu->inner_right = inner_right;
4354 data->img_menu->inner_top = inner_top;
4355 data->img_menu->inner_bottom = inner_bottom;
4356 data->img_menu->istiled = tiled;
4358 if (olddir) CurrentDir(olddir);
4359 UnLock(lock);
4360 if (data->img_menu) return TRUE;
4361 DisposeMenuSkinning(data);
4362 return FALSE;
4365 IPTR menudecor__OM_NEW(Class *cl, Object *obj, struct opSet *msg)
4367 struct menudecor_data *data;
4369 obj = (Object *)DoSuperMethodA(cl, obj, (Msg)msg);
4370 if (obj)
4372 data = INST_DATA(cl, obj);
4374 STRPTR path = (STRPTR) GetTagData(MDA_Configuration, (IPTR) "Theme:", msg->ops_AttrList);
4375 data->sd = (struct scrdecor_data *) GetTagData(MDA_ScreenData, 0, msg->ops_AttrList);
4377 if (!InitMenuSkinning(path, data))
4379 CoerceMethod(cl,obj,OM_DISPOSE);
4380 obj = NULL;
4383 return (IPTR)obj;
4387 IPTR menudecor__OM_DISPOSE(Class *cl, Object *obj, struct opSet *msg)
4389 struct menudecor_data *data = INST_DATA(cl, obj);
4391 DisposeMenuSkinning(data);
4393 return DoSuperMethodA(cl, obj, (Msg)msg);
4396 IPTR menudecor_dispatcher(struct IClass *cl, Object *obj, Msg msg)
4398 IPTR retval;
4400 switch(msg->MethodID)
4402 case OM_NEW:
4403 retval = menudecor__OM_NEW(cl, obj, (struct opSet *) msg);
4404 break;
4406 case OM_DISPOSE:
4407 retval = menudecor__OM_DISPOSE(cl, obj, (struct opSet *) msg);
4408 break;
4410 case MDM_DRAW_SYSIMAGE:
4411 retval = menudecor_draw_sysimage(cl, obj, (struct mdpDrawSysImage *)msg);
4412 break;
4414 case MDM_GETDEFSIZE_SYSIMAGE:
4415 retval = menudecor_getdefsizes(cl, obj, (struct mdpGetDefSizeSysImage *) msg);
4416 break;
4418 case MDM_DRAWBACKGROUND:
4419 retval = menudecor_renderbackground(cl, obj, (struct mdpDrawBackground *)msg);
4420 break;
4422 case MDM_INITMENU:
4423 retval = menudecor_initmenu(cl, obj, (struct mdpInitMenu *)msg);
4424 break;
4426 case MDM_EXITMENU:
4427 retval = menudecor_exitmenu(cl, obj, (struct mdpExitMenu *)msg);
4428 break;
4430 case MDM_GETMENUSPACES:
4431 retval = menudecor_getmenuspaces(cl, obj, (struct mdpGetMenuSpaces *)msg);
4432 break;
4434 default:
4435 retval = DoSuperMethodA(cl, obj, msg);
4436 break;
4439 return retval;
4442 /**************************************************************************************************/
4444 void DisposeWindowSkinning(struct windecor_data *data)
4449 BOOL InitWindowSkinning(STRPTR path, struct windecor_data *data) {
4450 char buffer[256];
4451 char *line, *v;
4452 BPTR file;
4453 BPTR lock;
4454 BPTR olddir = 0;
4456 lock = Lock(path, ACCESS_READ);
4457 if (lock)
4459 olddir = CurrentDir(lock);
4461 else return FALSE;
4463 data->rounded = FALSE;
4464 data->threestate = FALSE;
4465 data->barmasking = FALSE;
4466 data->winbarheight = 0; //screen, window
4468 data->sizeaddx = 2;
4469 data->sizeaddy = 2;
4470 data->BarJoinTB_o = 0;
4471 data->BarJoinTB_s = 0;
4472 data->BarPreGadget_o = 0;
4473 data->BarPreGadget_s = 0;
4474 data->BarPre_o = 0;
4475 data->BarPre_s = 0;
4476 data->BarLGadgetFill_o = 0;
4477 data->BarLGadgetFill_s = 0;
4478 data->BarJoinGB_o = 0;
4479 data->BarJoinGB_s = 0;
4480 data->BarLFill_o = 0;
4481 data->BarLFill_s = 0;
4482 data->BarJoinBT_o = 0;
4483 data->BarJoinBT_s = 0;
4484 data->BarTitleFill_o = 0;
4485 data->BarTitleFill_s = 0;
4486 data->BarRFill_o = 0;
4487 data->BarRFill_s = 0;
4488 data->BarJoinBG_o = 0;
4489 data->BarJoinBG_s = 0;
4490 data->BarRGadgetFill_o = 0;
4491 data->BarRGadgetFill_s = 0;
4492 data->BarPostGadget_o = 0;
4493 data->BarPostGadget_s = 0;
4494 data->BarPost_o = 0;
4495 data->BarPost_s = 0;
4496 data->txt_align = WD_DWTA_LEFT;
4497 data->usegradients = FALSE;
4498 data->closeright = FALSE;
4499 data->barvert = FALSE;
4500 data->filltitlebar = FALSE;
4501 data->outline = FALSE;
4502 data->shadow = FALSE;
4504 data->a_col_s = 0xaaaaaaaa;
4505 data->a_col_e = 0xeeeeeeff;
4506 data->d_col_s = 0x66666666;
4507 data->d_col_e = 0xaaaaaabb;
4509 data->text_col = 0x00cccccc;
4510 data->shadow_col = 0x00444444;
4512 data->a_arc = 0;
4513 data->d_arc = 0;
4514 data->light = 320;
4515 data->middle = 240;
4516 data->dark = 128;
4518 file = Open("System/Config", MODE_OLDFILE);
4519 if (file)
4523 line = FGets(file, buffer, 256);
4524 if (line)
4526 if ((v = strstr(line, "NoInactiveSelected ")) == line) {
4527 data->threestate = GetBool(v, "Yes");
4528 } else if ((v = strstr(line, "BarRounded ")) == line) {
4529 data->rounded = GetBool(v, "Yes");
4530 } else if ((v = strstr(line, "WindowTitleMode ")) == line) {
4531 data->outline = GetBool(v, "Outline");
4532 data->shadow = GetBool(v, "Shadow");
4533 } else if ((v = strstr(line, "FillTitleBar ")) == line) {
4534 data->filltitlebar = GetBool(v, "Yes");
4535 } else if ((v = strstr(line, "BarMasking ")) == line) {
4536 data->barmasking = GetBool(v, "Yes");
4537 } else if ((v = strstr(line, "CloseRight ")) == line) {
4538 data->closeright = GetBool(v, "Yes");
4539 } else if ((v = strstr(line, "UseGradients ")) == line) {
4540 data->usegradients = GetBool(v, "Yes");
4541 } else if ((v = strstr(line, "BarLayout ")) == line) {
4542 data->barvert = GetBool(v, "Vertical");
4543 } else if ((v = strstr(line, "RightBorderGads ")) == line) {
4544 data->rightbordergads = GetInt(v);
4545 } else if ((v = strstr(line, "HorScrollerHeight ")) == line) {
4546 data->horscrollerheight = GetInt(v);
4547 } else if ((v = strstr(line, "ScrollerInnerSpacing ")) == line) {
4548 data->scrollerinnerspacing = GetInt(v);
4549 } else if ((v = strstr(line, "BottomBorderGads ")) == line) {
4550 data->bottombordergads = GetInt(v);
4551 } else if ((v = strstr(line, "RightBorderNoGads ")) == line) {
4552 data->rightbordernogads = GetInt(v);
4553 } else if ((v = strstr(line, "BottomBorderNoGads ")) == line) {
4554 data->bottombordernogads = GetInt(v);
4555 } else if ((v = strstr(line, "BarHeight ")) == line) {
4556 data->winbarheight = GetInt(v); //screen, window
4557 } else if ((v = strstr(line, "BarJoinTB ")) == line) {
4558 GetIntegers(v, &data->BarJoinTB_o, &data->BarJoinTB_s);
4559 } else if ((v = strstr(line, "BarPreGadget ")) == line) {
4560 GetIntegers(v, &data->BarPreGadget_o, &data->BarPreGadget_s);
4561 } else if ((v = strstr(line, "BarPre ")) == line) {
4562 GetIntegers(v, &data->BarPre_o, &data->BarPre_s);
4563 } else if ((v = strstr(line, "BarLGadgetFill ")) == line) {
4564 GetIntegers(v, &data->BarLGadgetFill_o, &data->BarLGadgetFill_s);
4565 } else if ((v = strstr(line, "BarJoinGB ")) == line) {
4566 GetIntegers(v, &data->BarJoinGB_o, &data->BarJoinGB_s);
4567 } else if ((v = strstr(line, "BarLFill ")) == line) {
4568 GetIntegers(v, &data->BarLFill_o, &data->BarLFill_s);
4569 } else if ((v = strstr(line, "BarJoinBT ")) == line) {
4570 GetIntegers(v, &data->BarJoinBT_o, &data->BarJoinBT_s);
4571 } else if ((v = strstr(line, "BarTitleFill ")) == line) {
4572 GetIntegers(v, &data->BarTitleFill_o, &data->BarTitleFill_s);
4573 } else if ((v = strstr(line, "BarRFill ")) == line) {
4574 GetIntegers(v, &data->BarRFill_o, &data->BarRFill_s);
4575 } else if ((v = strstr(line, "BarJoinBG ")) == line) {
4576 GetIntegers(v, &data->BarJoinBG_o, &data->BarJoinBG_s);
4577 } else if ((v = strstr(line, "BarRGadgetFill ")) == line) {
4578 GetIntegers(v, &data->BarRGadgetFill_o, &data->BarRGadgetFill_s);
4579 } else if ((v = strstr(line, "BarPostGadget ")) == line) {
4580 GetIntegers(v, &data->BarPostGadget_o, &data->BarPostGadget_s);
4581 } else if ((v = strstr(line, "BarPost ")) == line) {
4582 GetIntegers(v, &data->BarPost_o, &data->BarPost_s);
4583 } else if ((v = strstr(line, "ContainerTop ")) == line) {
4584 GetIntegers(v, &data->ContainerTop_o, &data->ContainerTop_s);
4585 } else if ((v = strstr(line, "ContainerVertTile ")) == line) {
4586 GetIntegers(v, &data->ContainerVertTile_o, &data->ContainerVertTile_s);
4587 } else if ((v = strstr(line, "KnobTop ")) == line) {
4588 GetIntegers(v, &data->KnobTop_o, &data->KnobTop_s);
4589 } else if ((v = strstr(line, "KnobTileTop ")) == line) {
4590 GetIntegers(v, &data->KnobTileTop_o, &data->KnobTileTop_s);
4591 } else if ((v = strstr(line, "KnobVertGripper ")) == line) {
4592 GetIntegers(v, &data->KnobVertGripper_o, &data->KnobVertGripper_s);
4593 } else if ((v = strstr(line, "KnobTileBottom ")) == line) {
4594 GetIntegers(v, &data->KnobTileBottom_o, &data->KnobTileBottom_s);
4595 } else if ((v = strstr(line, "KnobBottom ")) == line) {
4596 GetIntegers(v, &data->KnobBottom_o, &data->KnobBottom_s);
4597 } else if ((v = strstr(line, "ContainerBottom ")) == line) {
4598 GetIntegers(v, &data->ContainerBottom_o, &data->ContainerBottom_s);
4599 } else if ((v = strstr(line, "ContainerLeft ")) == line) {
4600 GetIntegers(v, &data->ContainerLeft_o, &data->ContainerLeft_s);
4601 } else if ((v = strstr(line, "ContainerHorTile ")) == line) {
4602 GetIntegers(v, &data->ContainerHorTile_o, &data->ContainerHorTile_s);
4603 } else if ((v = strstr(line, "KnobLeft ")) == line) {
4604 GetIntegers(v, &data->KnobLeft_o, &data->KnobLeft_s);
4605 } else if ((v = strstr(line, "KnobTileLeft ")) == line) {
4606 GetIntegers(v, &data->KnobTileLeft_o, &data->KnobTileLeft_s);
4607 } else if ((v = strstr(line, "KnobHorGripper ")) == line) {
4608 GetIntegers(v, &data->KnobHorGripper_o, &data->KnobHorGripper_s);
4609 } else if ((v = strstr(line, "KnobTileRight ")) == line) {
4610 GetIntegers(v, &data->KnobTileRight_o, &data->KnobTileRight_s);
4611 } else if ((v = strstr(line, "KnobRight ")) == line) {
4612 GetIntegers(v, &data->KnobRight_o, &data->KnobRight_s);
4613 } else if ((v = strstr(line, "ContainerRight ")) == line) {
4614 GetIntegers(v, &data->ContainerRight_o, &data->ContainerRight_s);
4615 } else if ((v = strstr(line, "AddSize ")) == line) {
4616 GetIntegers(v, &data->sizeaddx, &data->sizeaddy);
4617 } else if ((v = strstr(line, "AddUpDown ")) == line) {
4618 GetIntegers(v, &data->updownaddx, &data->updownaddy);
4619 } else if ((v = strstr(line, "AddLeftRight ")) == line) {
4620 GetIntegers(v, &data->leftrightaddx, &data->leftrightaddy);
4621 } else if ((v = strstr(line, "ActivatedGradient ")) == line) {
4622 GetTripleIntegers(v, &data->a_col_s, &data->a_col_e, &data->a_arc);
4623 } else if ((v = strstr(line, "DeactivatedGradient ")) == line) {
4624 GetTripleIntegers(v, &data->d_col_s, &data->d_col_e, &data->d_arc);
4625 } else if ((v = strstr(line, "ShadeValues ")) == line) {
4626 GetTripleIntegers(v, &data->light, &data->middle, &data->dark);
4627 } else if ((v = strstr(line, "BaseColors ")) == line) {
4628 GetColors(v, &data->b_col_a, &data->b_col_d);
4629 } else if ((v = strstr(line, "WindowTitleColors ")) == line) {
4630 GetColors(v, &data->text_col, &data->shadow_col);
4634 while(line);
4635 Close(file);
4638 PUTIMAGE_WIN(size);
4639 PUTIMAGE_WIN(close);
4640 PUTIMAGE_WIN(depth);
4641 PUTIMAGE_WIN(zoom);
4642 PUTIMAGE_WIN(up);
4643 PUTIMAGE_WIN(down);
4644 PUTIMAGE_WIN(left);
4645 PUTIMAGE_WIN(right);
4646 PUTIMAGE_WIN(mui);
4647 PUTIMAGE_WIN(popup);
4648 PUTIMAGE_WIN(snapshot);
4649 PUTIMAGE_WIN(iconify);
4650 PUTIMAGE_WIN(lock);
4651 PUTIMAGE_WIN(winbar_normal);
4652 PUTIMAGE_WIN(border_normal);
4653 PUTIMAGE_WIN(border_deactivated);
4654 PUTIMAGE_WIN(verticalcontainer);
4655 PUTIMAGE_WIN(verticalknob);
4656 PUTIMAGE_WIN(horizontalcontainer);
4657 PUTIMAGE_WIN(horizontalknob);
4659 if (olddir) CurrentDir(olddir);
4660 UnLock(lock);
4662 if (data->img_horizontalcontainer && data->img_horizontalknob && data->img_verticalcontainer && data->img_verticalknob && data->img_size && data->img_close && data->img_depth && data->img_zoom && data->img_up && data->img_down && data->img_left && data->img_right && data->img_winbar_normal) return TRUE;
4663 DisposeWindowSkinning(data);
4664 return FALSE;
4668 void DisposeScreenSkinning(struct scrdecor_data *data)
4670 DisposeImageContainer(data->img_sdepth);
4671 DisposeImageContainer(data->img_sbarlogo);
4672 DisposeImageContainer(data->img_stitlebar);
4674 DisposeImageContainer(data->img_size);
4675 DisposeImageContainer(data->img_close);
4676 DisposeImageContainer(data->img_depth);
4677 DisposeImageContainer(data->img_zoom);
4678 DisposeImageContainer(data->img_mui);
4679 DisposeImageContainer(data->img_popup);
4680 DisposeImageContainer(data->img_snapshot);
4681 DisposeImageContainer(data->img_iconify);
4682 DisposeImageContainer(data->img_lock);
4683 DisposeImageContainer(data->img_up);
4684 DisposeImageContainer(data->img_down);
4685 DisposeImageContainer(data->img_left);
4686 DisposeImageContainer(data->img_right);
4687 DisposeImageContainer(data->img_winbar_normal);
4688 DisposeImageContainer(data->img_border_normal);
4689 DisposeImageContainer(data->img_border_deactivated);
4690 DisposeImageContainer(data->img_verticalcontainer);
4691 DisposeImageContainer(data->img_verticalknob);
4692 DisposeImageContainer(data->img_horizontalcontainer);
4693 DisposeImageContainer(data->img_horizontalknob);
4695 DisposeImageContainer(data->img_menu);
4696 DisposeImageContainer(data->img_menucheck);
4697 DisposeImageContainer(data->img_amigakey);
4698 DisposeImageContainer(data->img_submenu);
4700 data->img_size = NULL;
4701 data->img_close = NULL;
4702 data->img_depth = NULL;
4703 data->img_zoom = NULL;
4704 data->img_mui = NULL;
4705 data->img_popup = NULL;
4706 data->img_snapshot = NULL;
4707 data->img_iconify = NULL;
4708 data->img_lock = NULL;
4709 data->img_up = NULL;
4710 data->img_down = NULL;
4711 data->img_left = NULL;
4712 data->img_right = NULL;
4713 data->img_winbar_normal = NULL;
4714 data->img_border_normal = NULL;
4715 data->img_border_deactivated = NULL;
4716 data->img_verticalcontainer = NULL;
4717 data->img_verticalknob = NULL;
4718 data->img_horizontalcontainer = NULL;
4719 data->img_horizontalknob = NULL;
4721 data->img_sdepth = NULL;
4722 data->img_sbarlogo = NULL;
4723 data->img_stitlebar = NULL;
4726 BOOL InitScreenSkinning(STRPTR path, struct scrdecor_data *data) {
4728 char buffer[256];
4729 char *line, *v;
4730 BPTR file;
4731 BPTR lock;
4732 BPTR olddir = 0;
4733 lock = Lock(path, ACCESS_READ);
4734 if (lock)
4736 olddir = CurrentDir(lock);
4738 else return FALSE;
4740 data->leftborder = 4;
4741 data->rightborder = 4;
4742 data->bottomborder = 4;
4744 data->lut_col_a = 0x00cccccc;
4745 data->lut_col_d = 0x00888888;
4747 data->outline = FALSE;
4748 data->shadow = FALSE;
4750 data->text_col = 0x00cccccc;
4751 data->shadow_col = 0x00444444;
4753 file = Open("System/Config", MODE_OLDFILE);
4754 if (file)
4758 line = FGets(file, buffer, 256);
4759 if (line)
4761 if ((v = strstr(line, "LeftBorder ")) == line) {
4762 data->leftborder = GetInt(v);
4763 } else if ((v = strstr(line, "RightBorder ")) == line) {
4764 data->rightborder = GetInt(v);
4765 } else if ((v = strstr(line, "BottomBorder ")) == line) {
4766 data->bottomborder = GetInt(v);
4767 } else if ((v = strstr(line, "LogoOffset ")) == line) {
4768 data->slogo_off = GetInt(v);
4769 } else if ((v = strstr(line, "TitleOffset ")) == line) {
4770 data->stitle_off = GetInt(v);
4771 } else if ((v = strstr(line, "SBarHeight ")) == line) {
4772 data->sbarheight = GetInt(v);
4773 } else if ((v = strstr(line, "BarHeight ")) == line) {
4774 data->winbarheight = GetInt(v); //screen, window
4775 } else if ((v = strstr(line, "LUTBaseColors ")) == line) {
4776 GetColors(v, &data->lut_col_a, &data->lut_col_d);
4777 } else if ((v = strstr(line, "ScreenTitleColors ")) == line) {
4778 GetColors(v, &data->text_col, &data->shadow_col);
4779 } else if ((v = strstr(line, "ScreenTitleMode ")) == line) {
4780 data->outline = GetBool(v, "Outline");
4781 data->shadow = GetBool(v, "Shadow");
4785 while(line);
4786 Close(file);
4789 data->img_sdepth = GetImageFromFile(path, "System/SDepth/", TRUE);
4790 data->img_stitlebar = GetImageFromFile(path, "System/STitlebar/", TRUE);
4791 data->img_sbarlogo = GetImageFromFile(path, "System/SBarLogo/Default", FALSE);
4793 data->img_size = GetImageFromFile(path, "System/Size/", TRUE);
4794 data->img_close = GetImageFromFile(path, "System/Close/", TRUE);
4795 data->img_depth = GetImageFromFile(path, "System/Depth/", TRUE);
4796 data->img_zoom = GetImageFromFile(path, "System/Zoom/", TRUE);
4797 data->img_mui = GetImageFromFile(path, "System/MUI/", TRUE);
4798 data->img_popup = GetImageFromFile(path, "System/PopUp/", TRUE);
4799 data->img_snapshot = GetImageFromFile(path, "System/Snapshot/", TRUE);
4800 data->img_iconify = GetImageFromFile(path, "System/Iconify/", TRUE);
4801 data->img_lock = GetImageFromFile(path, "System/Lock/", TRUE);
4802 data->img_up = GetImageFromFile(path, "System/ArrowUp/", TRUE);
4803 data->img_down = GetImageFromFile(path, "System/ArrowDown/", TRUE);
4804 data->img_left = GetImageFromFile(path, "System/ArrowLeft/", TRUE);
4805 data->img_right = GetImageFromFile(path, "System/ArrowRight/", TRUE);
4806 data->img_winbar_normal = GetImageFromFile(path, "System/Titlebar/", TRUE);
4807 data->img_border_normal = GetImageFromFile(path, "System/Borders/Default", FALSE);
4808 data->img_border_deactivated = GetImageFromFile(path, "System/Borders/Default_Deactivated", FALSE);
4809 data->img_verticalcontainer = GetImageFromFile(path, "System/Container/Vertical", FALSE);
4810 data->img_verticalknob = GetImageFromFile(path, "System/Knob/Vertical", FALSE);
4811 data->img_horizontalcontainer = GetImageFromFile(path, "System/Container/Horizontal", FALSE);
4812 data->img_horizontalknob = GetImageFromFile(path, "System/Knob/Horizontal", FALSE);
4814 data->img_menu = GetImageFromFile(path, "Menu/Background/Default", FALSE);
4815 data->img_amigakey = GetImageFromFile(path, "Menu/AmigaKey/", TRUE);
4816 data->img_menucheck = GetImageFromFile(path, "Menu/Checkmark/", TRUE);
4817 data->img_submenu = GetImageFromFile(path, "Menu/SubMenu/", TRUE);
4819 if (data->img_stitlebar)
4821 data->img_stitlebar->tile_left = 8;
4822 data->img_stitlebar->tile_right = 8;
4823 data->img_stitlebar->tile_top = 9;
4824 data->img_stitlebar->tile_bottom = 8;
4827 if (olddir) CurrentDir(olddir);
4828 UnLock(lock);
4830 if (data->img_sdepth) return TRUE;
4831 DisposeScreenSkinning(data);
4832 return FALSE;
4835 STRPTR __detached_name = "Decoration";
4837 #define MAGIC_PRIVATE_SKIN 0x0001
4839 struct SkinMessage {
4840 struct MagicMessage msg;
4841 UWORD class;
4842 STRPTR path;
4843 STRPTR id;
4846 void DeleteDecorator(struct NewDecorator *nd)
4848 if (nd == NULL) return;
4849 if (nd->nd_Menu != NULL) DisposeObject(nd->nd_Menu);
4850 if (nd->nd_Window != NULL) DisposeObject(nd->nd_Window);
4851 if (nd->nd_Screen != NULL) DisposeObject(nd->nd_Screen);
4852 FreeVec(nd);
4855 struct NewDecorator *GetDecorator(STRPTR path)
4857 struct NewDecorator *nd = NULL;
4859 STRPTR newpath;
4861 if (path != NULL) newpath = path; else newpath = "Theme:";
4863 struct TagItem ScreenTags[] = { {SDA_UserBuffer, sizeof(struct ScreenData)}, {SDA_Configuration, (ULONG) newpath}, {TAG_DONE} };
4866 nd = AllocVec(sizeof(struct NewDecorator), MEMF_CLEAR | MEMF_ANY);
4867 if (nd)
4869 nd->nd_Screen = NewObjectA(scrcl, NULL, ScreenTags);
4871 if (nd->nd_Screen)
4873 APTR screendata;
4875 get(nd->nd_Screen, SDA_ScreenData, &screendata);
4877 struct TagItem WindowTags[] = { {WDA_UserBuffer, sizeof(struct WindowData)}, {WDA_Configuration, (ULONG) newpath}, {WDA_ScreenData, (IPTR)screendata}, {TAG_DONE} };
4878 struct TagItem MenuTags[] = { {MDA_UserBuffer, sizeof(struct MenuData)}, {MDA_Configuration, (ULONG) newpath}, {MDA_ScreenData, (IPTR)screendata}, {TAG_DONE} };
4881 nd->nd_Window = NewObjectA(cl, NULL, WindowTags);
4882 nd->nd_Menu = NewObjectA(menucl, NULL, MenuTags);
4883 if ((nd->nd_Menu == NULL ) || (nd->nd_Window == NULL) || (nd->nd_Screen == NULL))
4885 DeleteDecorator(nd);
4886 nd = NULL;
4889 else
4891 DeleteDecorator(nd);
4892 nd = NULL;
4895 return nd;
4898 #define ARGUMENT_TEMPLATE "PATH,SCREENID=ID/K"
4900 char usage[] =
4901 "Decoration:\n"
4902 "Arguments:\n";
4904 int main(void)
4907 IPTR rd_Args[] = {0, 0, };
4909 struct RDArgs *args, *newargs;
4911 /* the 1M $$ Question why "Decoration ?" does not work in the shell? */
4913 newargs = (struct RDArgs*) AllocDosObject(DOS_RDARGS, NULL);
4915 if (newargs == NULL) return 0;
4917 newargs->RDA_ExtHelp = usage;
4918 newargs->RDA_Flags = 0;
4920 args = ReadArgs(ARGUMENT_TEMPLATE, rd_Args, newargs);
4922 if (args == NULL) {
4923 FreeDosObject (DOS_RDARGS, (APTR) newargs);
4924 return 0;
4927 Forbid();
4928 if (FindPort("DECORATIONS")) {
4929 struct MsgPort *port = CreateMsgPort();
4930 if (port) {
4931 struct SkinMessage msg;
4932 msg.msg.mn_ReplyPort = port;
4933 msg.msg.mn_Magic = MAGIC_PRIVATE_SKIN;
4934 msg.class = 0;
4935 msg.path = (STRPTR) rd_Args[0];
4936 msg.id = (STRPTR) rd_Args[1];
4937 PutMsg(FindPort("DECORATIONS"), (struct Message *) &msg);
4938 WaitPort(port);
4939 GetMsg(port);
4940 Permit();
4941 DeleteMsgPort(port);
4942 FreeArgs(args);
4943 return 0;
4946 Permit();
4948 cl = MakeClass(NULL, WINDECORCLASS, NULL, sizeof(struct windecor_data), 0);
4949 if (cl)
4951 cl->cl_Dispatcher.h_Entry = HookEntry;
4952 cl->cl_Dispatcher.h_SubEntry = (HOOKFUNC)windecor_dispatcher;
4954 scrcl = MakeClass(NULL, SCRDECORCLASS, NULL, sizeof(struct scrdecor_data), 0);
4955 if (scrcl)
4957 scrcl->cl_Dispatcher.h_Entry = HookEntry;
4958 scrcl->cl_Dispatcher.h_SubEntry = (HOOKFUNC)scrdecor_dispatcher;
4960 menucl = MakeClass(NULL, MENUDECORCLASS, NULL, sizeof(struct menudecor_data), 0);
4961 if (menucl)
4963 menucl->cl_Dispatcher.h_Entry = HookEntry;
4964 menucl->cl_Dispatcher.h_SubEntry = (HOOKFUNC)menudecor_dispatcher;
4966 struct MsgPort *port = CreateMsgPort();
4967 ULONG skinSignal;
4968 if (port)
4970 skinSignal = 1 << port->mp_SigBit;
4971 port->mp_Node.ln_Name="DECORATIONS";
4972 AddPort(port);
4974 struct NewDecorator *decor = GetDecorator((STRPTR) rd_Args[0]);
4976 if (decor != NULL)
4978 decor->nd_Pattern = (STRPTR) rd_Args[1];
4979 decor->nd_Port = port;
4980 ChangeDecoration(DECORATION_SET, decor);
4983 Detach();
4985 BOOL running = TRUE;
4987 while (running)
4989 ULONG sigs = Wait(SIGBREAKF_CTRL_C | skinSignal);
4990 if ((sigs & SIGBREAKF_CTRL_C) != 0)
4992 // running = FALSE; /* at the moment no exit */
4994 else if ((sigs & skinSignal) != 0)
4996 struct DecoratorMessage *dmsg;
4997 struct SkinMessage * msg = (struct SkinMessage *) GetMsg(port);
4998 while (msg)
5000 switch(msg->msg.mn_Magic)
5002 case MAGIC_PRIVATE_SKIN:
5003 decor = GetDecorator(msg->path);
5004 if (decor != NULL)
5006 decor->nd_Pattern = msg->id;
5007 decor->nd_Port = port;
5008 ChangeDecoration(DECORATION_SET, decor);
5010 break;
5011 case MAGIC_DECORATOR:
5012 dmsg = (struct DecoratorMessage *) msg;
5013 DeleteDecorator((struct NewDecorator *) dmsg->dm_Object);
5014 break;
5016 ReplyMsg((struct Message *) msg);
5017 msg = (struct SkinMessage *) GetMsg(port);
5022 FreeClass(menucl);
5024 FreeClass(scrcl);
5026 FreeClass(cl);
5028 FreeDosObject (DOS_RDARGS, (APTR) newargs);
5029 FreeArgs(args);
5030 return 0;