2 Copyright © 1995-2005, The AROS Development Team. All rights reserved.
5 Desc: Support functions for the colorwheel class
9 #include <exec/memory.h>
10 #include <graphics/gfxmacros.h>
11 #include <intuition/classes.h>
12 #include <intuition/cghooks.h>
13 #include <intuition/gadgetclass.h>
14 #include <intuition/imageclass.h>
15 #include <intuition/screens.h>
16 #include <intuition/intuition.h>
17 #include <proto/exec.h>
18 #include <proto/graphics.h>
19 #include <proto/intuition.h>
20 #include <proto/colorwheel.h>
21 #include <proto/cybergraphics.h>
23 #include <cybergraphx/cybergraphics.h>
25 #include <cybergraphics/cybergraphics.h>
28 #include <gadgets/colorwheel.h>
30 #include "colorwheel_intern.h"
42 /***************************************************************************************************/
47 #include <aros/debug.h>
51 #define SQR(x) FixMul( (x), (x) )
53 #define SQR(x) ((x) * (x))
56 #define CW_PI 3.14159265358979
58 #define USE_WRITEPIXELARRAY 1
59 #define USE_SYMMETRIC_SPEEDUP 1
61 #define MAKE_RGB_BE(r,g,b) ( (((r) >> 8) & 0x00FF0000) | \
62 (((g) >> 16) & 0x0000FF00) | \
63 (((b) >> 24) & 0x000000FF) )
65 #define MAKE_RGB_LE(r,g,b) ( (((r) >> 16) & 0x0000FF00) | \
66 (((g) >> 8) & 0x00FF0000) | \
67 (((b) >> 0) & 0xFF000000) )
71 # define MAKE_RGB(r,g,b) MAKE_RGB_LE(r,g,b)
73 # define MAKE_RGB(r,g,b) MAKE_RGB_BE(r,g,b)
76 # define MAKE_RGB(r,g,b) MAKE_RGB_BE(r,g,b)
79 /****************************************************************************/
81 UBYTE Bayer16
[16][16] =
83 { 1,235, 59,219, 15,231, 55,215, 2,232, 56,216, 12,228, 52,212},
84 { 129, 65,187,123,143, 79,183,119,130, 66,184,120,140, 76,180,116},
85 { 33,193, 17,251, 47,207, 31,247, 34,194, 18,248, 44,204, 28,244},
86 { 161, 97,145, 81,175,111,159, 95,162, 98,146, 82,172,108,156, 92},
87 { 9,225, 49,209, 5,239, 63,223, 10,226, 50,210, 6,236, 60,220},
88 { 137, 73,177,113,133, 69,191,127,138, 74,178,114,134, 70,188,124},
89 { 41,201, 25,241, 37,197, 21,255, 42,202, 26,242, 38,198, 22,252 },
90 { 169,105,153, 89,165,101,149, 85,170,106,154, 90,166,102,150, 86},
91 { 3,233, 57,217, 13,229, 53,213, 0,234, 58,218, 14,230, 54,214},
92 { 131, 67,185,121,141, 77,181,117,128, 64,186,122,142, 78,182,118},
93 { 35,195, 19,249, 45,205, 29,245, 32,192, 16,250, 46,206, 30,246},
94 { 163, 99,147, 83,173,109,157, 93,160, 96,144, 80,174,110,158, 94},
95 { 11,227, 51,211, 7,237, 61,221, 8,224, 48,208, 4,238, 62,222},
96 { 139, 75,179,115,135, 71,189,125,136, 72,176,112,132, 68,190,126},
97 { 43,203, 27,243, 39,199, 23,253, 40,200, 24,240, 36,196, 20,255 },
98 { 171,107,155, 91,167,103,151, 87,168,104,152, 88,164,100,148, 84}
102 extern void ConvertHSBToRGB( REG(a0
, struct ColorWheelHSB
*hsb
), REG(a1
, struct ColorWheelRGB
*rgb
) );
107 void kprintf( STRPTR FormatStr
, ... )
110 STRPTR p
= PutChData
;
111 struct Library
*SysBase
= (*(struct Library
**)4L);
112 RawDoFmt(FormatStr
, ((STRPTR
)(&FormatStr
))+4, (void (*)())"\x16\xc0\x4e\x75", PutChData
);
117 #define SysBase CWB(ColorWheelBase)->sysbase
120 /***************************************************************************************************/
123 BOOL
CalcWheelColor(LONG x
, LONG y
, LONG cx
, LONG cy
, ULONG
*hue
, ULONG
*sat
)
125 Fixed32 r
, l
, h
, s
, sinus
;
129 ry
= ( y
- cy
) * cx
/ cy
;
131 r
= FixSqrti( (rx
*rx
) + (ry
*ry
) );
133 h
= (r
!= 0) ? FixAtan2( FixDiv( INT_TO_FIXED(rx
), r
), FixDiv( INT_TO_FIXED(ry
), r
) ) : 0;
135 l
= FixSqrti( FIXED_TO_INT( (FixSqr( cx
* FixSinCos( h
+ (FIXED_PI
/2), &sinus
) ) +
136 FixSqr( cx
* sinus
)) ) );
140 h
= FixMul( h
+ FIXED_PI
, 10430 ); // == FixDiv( h + FIXED_PI, FIXED_2PI );
143 else if (s
>= FIXED_ONE
)
148 *hue
= ( h
<< 16 ) | h
;
149 *sat
= ( s
<< 16 ) | s
;
151 return (r
<= INT_TO_FIXED(cx
));
154 BOOL
CalcWheelColor(LONG x
, LONG y
, double cx
, double cy
, ULONG
*hue
, ULONG
*sat
)
156 double d
, r
, rx
, ry
, l
, h
, s
;
159 /* Should also work with not perfect (cy == cy) circle */
161 rx
= (double) cx
- x
;
162 ry
= ((double) y
- cy
) * cx
/ cy
;
164 /* d = (SQR(cx) * SQR(rx) + SQR(cx) * SQR(ry) - SQR(cx) * SQR(cx)); */
166 r
= sqrt (SQR(rx
) + SQR(ry
));
167 if (r
> cx
) d
= 1.0; else d
= 0.0;
170 h
= atan2 (rx
/ r
, ry
/ r
);
174 l
= sqrt (SQR((cx
* cos (h
+ 0.5 * CW_PI
))) + SQR((cx
* sin (h
+ 0.5 * CW_PI
))));
179 /* Does not work well if cx != cy (elliptical shape) */
181 rx
= (double) cx
- x
;
182 ry
= (double) y
- cy
;
184 d
= (SQR(cy
) * SQR(rx
) + SQR(cx
) * SQR(ry
) - SQR(cx
) * SQR(cy
));
186 r
= sqrt (SQR(rx
) + SQR(ry
));
189 h
= atan2 (rx
/ r
, ry
/ r
);
193 l
= sqrt (SQR((cx
* cos (h
+ 0.5 * CW_PI
))) + SQR((cy
* sin (h
+ 0.5 * CW_PI
))));
197 h
= (h
+ CW_PI
) / (2.0 * CW_PI
);
204 *hue
= (ULONG
)rint (h
* 0xFFFFFFFF);
205 *sat
= (ULONG
)rint (s
* 0xFFFFFFFF);
207 return (d
> 0.0) ? FALSE
: TRUE
;
211 /***************************************************************************************************/
213 STATIC VOID
CalcKnobPos(struct ColorWheelData
*data
, WORD
*x
, WORD
*y
)
216 Fixed32 alpha
, sat
, sinus
;
218 alpha
= data
->hsb
.cw_Hue
>> 16;
219 alpha
= FixMul( FIXED_2PI
, alpha
) - (FIXED_PI
/2);
221 sat
= data
->hsb
.cw_Saturation
>> 16;
223 *x
= data
->wheelcx
+ (WORD
) FIXED_TO_INT( FixMul( ( (LONG
) data
->wheelrx
) * sat
, FixSinCos(alpha
,&sinus
) ) );
224 *y
= data
->wheelcy
+ (WORD
) FIXED_TO_INT( FixMul( ( (LONG
) data
->wheelry
) * sat
, sinus
) );
228 alpha
= (double)data
->hsb
.cw_Hue
/ (double) 0xFFFFFFFF;
229 alpha
*= CW_PI
* 2.0;
230 alpha
-= CW_PI
/ 2.0;
232 sat
= (double)data
->hsb
.cw_Saturation
/ (double) 0xFFFFFFFF;
234 *x
= data
->wheelcx
+ (WORD
) ((double)data
->wheelrx
* sat
* cos(alpha
));
235 *y
= data
->wheelcy
+ (WORD
) ((double)data
->wheelry
* sat
* sin(alpha
));
239 /***************************************************************************************************/
241 STATIC VOID
TrueWheel(struct ColorWheelData
*data
, struct RastPort
*rp
, struct IBox
*box
,
242 struct Library
*ColorWheelBase
245 struct ColorWheelHSB hsb
;
246 struct ColorWheelRGB rgb
;
248 WORD x
, y
, left
, top
, width
, height
;
258 height
= box
->Height
;
263 cx
= (double)width
/ 2.0;
264 cy
= (double)height
/ 2.0;
267 hsb
.cw_Brightness
= 0xFFFFFFFF;
269 #if USE_WRITEPIXELARRAY
270 if (!data
->rgblinebuffer
|| data
->rgblinebuffer_size
< width
)
272 if (data
->rgblinebuffer
) FreeVec(data
->rgblinebuffer
);
274 data
->rgblinebuffer
= AllocVec(width
* sizeof(LONG
), MEMF_ANY
);
275 data
->rgblinebuffer_size
= width
;
279 if (data
->rgblinebuffer
)
284 GetRGB32(data->scr->ViewPort.ColorMap, 0, 1, backrgb);
286 backcol = ((backrgb[0] >> 8) & 0xFF0000) |
287 ((backrgb[1] >> 16) & 0x00FF00) |
288 ((backrgb[2] >> 24) & 0x0000FF);
290 for(y
= 0; y
< height
; y
++)
292 UWORD startX
= 0, w
= width
;
293 ULONG
*p
= data
->rgblinebuffer
;
294 #if USE_SYMMETRIC_SPEEDUP
295 ULONG
*p2
= &p
[width
];
296 for(x
= 0; x
< width
/ 2; x
++)
299 for(x
= 0; x
< width
; x
++)
302 if (CalcWheelColor(x
, y
, cx
, cy
, &hsb
.cw_Hue
, &hsb
.cw_Saturation
))
304 ConvertHSBToRGB(&hsb
, &rgb
);
306 col
= MAKE_RGB(rgb
.cw_Red
, rgb
.cw_Green
, rgb
.cw_Blue
);
309 #if USE_SYMMETRIC_SPEEDUP
310 col
= MAKE_RGB(rgb
.cw_Red
, rgb
.cw_Blue
, rgb
.cw_Green
);
316 #if USE_SYMMETRIC_SPEEDUP
321 } /* for(x = 0; x < width; x++) */
323 if (w
) WritePixelArray(&data
->rgblinebuffer
[startX
],
326 0, //width * sizeof(LONG),
334 } /* for(y = 0; y < height; y++) */
336 } /* if (data->rgblinebuffer) */
339 for(y
= 0; y
< height
; y
++)
341 #if USE_SYMMETRIC_SPEEDUP
342 for(x
= 0; x
< width
/ 2; x
++)
344 for(x
= 0; x
< width
; x
++)
347 if (CalcWheelColor(x
, y
, cx
, cy
, &hsb
.cw_Hue
, &hsb
.cw_Saturation
))
349 ConvertHSBToRGB(&hsb
, &rgb
);
351 col
= MAKE_RGB_BE(rgb
.cw_Red
, rgb
.cw_Green
, rgb
.cw_Blue
);
353 WriteRGBPixel(rp
, left
+ x
, top
+ y
, col
);
355 #if USE_SYMMETRIC_SPEEDUP
356 col
= MAKE_RGB_BE(rgb
.cw_Red
, rgb
.cw_Blue
, rgb
.cw_Green
);
358 WriteRGBPixel(rp
, left
+ width
- 1 - x
, top
+ y
, col
);
362 } /* for(x = 0; x < width; x++) */
364 } /* for(y = 0; y < height; y++) */
366 } /* data->rgbinebuffer == NULL */
369 /****************************************************************************/
371 STATIC VOID
ClutWheel(struct ColorWheelData
*data
, struct RastPort
*rp
, struct IBox
*box
,
372 struct Library
*ColorWheelBase
375 struct ColorWheelHSB hsb
;
376 struct ColorWheelRGB rgb
;
377 struct RastPort
*tRP
= &data
->trp
;
380 WORD x
, y
, left
, top
, width
, height
;
391 height
= box
->Height
;
393 if( data
->gotpens
!= TRUE
)
395 STRPTR abbrv
= data
->abbrv
;
397 UWORD cx
= data
->wheelcx
,
399 rx
= data
->wheelrx
- 4,
400 ry
= data
->wheelry
- 4,
401 depth
= GetBitMapAttr( rp
->BitMap
, BMA_DEPTH
);
404 rasSize
= RASSIZE( width
*depth
, height
);
406 #ifndef USE_ALLOCRASTER
407 if( ( ras
= AllocVec( rasSize
, MEMF_CHIP
) ) )
409 if( ( ras
= AllocRaster( width
*depth
, height
) ) )
414 ULONG pattern
= 0xaaaa5555;
415 UWORD black
= FindColor( data
->scr
->ViewPort
.ColorMap
, 0,0,0, -1 ),
416 white
= FindColor( data
->scr
->ViewPort
.ColorMap
, ~0,~0,~0, -1 ),
418 WORD endx
, endy
, TxOffset
;
420 InitArea( &ai
, buf
, sizeof( buf
) / 5 );
423 InitTmpRas( &tr
, ras
, rasSize
);
425 SetAPen( rp
, black
);
427 AreaEllipse( rp
, cx
, cy
, rx
, ry
);
430 SetAPen( rp
, white
);
431 SetFont( rp
, data
->dri
->dri_Font
);
433 TxOffset
= rp
->TxHeight
-rp
->TxBaseline
;
435 endx
= 500*rx
/2000, // 30°
438 Move( rp
, cx
+ rx
/2, cy
);
439 Draw( rp
, cx
+ rx
, cy
);
441 Move( rp
, cx
- rx
/2, cy
);
442 Draw( rp
, cx
- rx
, cy
);
444 Move( rp
, cx
+ endx
, cy
+ endy
);
445 Draw( rp
, cx
+ 2*endx
, cy
+ 2*endy
);
447 Move( rp
, cx
+ endx
, cy
- endy
);
448 Draw( rp
, cx
+ 2*endx
, cy
- 2*endy
);
450 Move( rp
, cx
- endx
, cy
+ endy
);
451 Draw( rp
, cx
- 2*endx
, cy
+ 2*endy
);
453 Move( rp
, cx
- endx
, cy
- endy
);
454 Draw( rp
, cx
- 2*endx
, cy
- 2*endy
);
456 endx
= 866*rx
/1500; // 60°
459 Move( rp
, cx
+ endx
+ ( TextLength( rp
, abbrv
, 1L ) / 2 ), cy
- (endy
- TxOffset
) );
460 Text( rp
, abbrv
++, 1L ); // G
462 Move( rp
, cx
- ( TextLength( rp
, abbrv
, 1L ) / 2 ), cy
+ (ry
- ry
/4) + TxOffset
);
463 Text( rp
, abbrv
++, 1L ); // C
465 Move( rp
, cx
- endx
- ( TextLength( rp
, abbrv
, 1L ) ), cy
- (endy
- TxOffset
) );
466 Text( rp
, abbrv
++, 1L ); // B
468 Move( rp
, cx
- endx
- ( TextLength( rp
, abbrv
, 1L ) ), cy
+ (endy
- TxOffset
) );
469 Text( rp
, abbrv
++, 1L ); // M
471 Move( rp
, cx
- ( TextLength( rp
, abbrv
, 1L ) / 2 ), cy
- (ry
- ry
/4) + TxOffset
);
472 Text( rp
, abbrv
++, 1L ); // R
474 Move( rp
, cx
+ endx
+ ( TextLength( rp
, abbrv
, 1L ) / 2 ), cy
+ (endy
+ TxOffset
) );
475 Text( rp
, abbrv
++, 1L ); // Y
477 SetAfPt( rp
, (UWORD
*)&pattern
, 1L );
479 AreaEllipse( rp
, cx
, cy
, rx
/2, ry
/2 );
482 SetAfPt( rp
, NULL
, 0L );
484 AreaEllipse( rp
, cx
, cy
, rx
/5, ry
/5 );
488 #ifndef USE_ALLOCRASTER
491 FreeRaster( ras
, width
*depth
,height
);
505 cx
= (double)width
/ 2.0;
506 cy
= (double)height
/ 2.0;
509 hsb
.cw_Brightness
= 0xFFFFFFFF;
511 if( ( tBM
= AllocBitMap( width
,1, GetBitMapAttr( rp
->BitMap
, BMA_DEPTH
), 0L, NULL
) ) )
515 if( ( buf
= AllocVec( (((width
+15)>>4)<<4), MEMF_ANY
) ) )
517 LONG range
= data
->range
,
518 levels
= data
->levels
;
520 for(y
= 0; y
< height
; y
++)
522 UWORD startX
= 0, w
= width
;
524 #if USE_SYMMETRIC_SPEEDUP
525 UBYTE
*p2
= &p
[width
];
526 for(x
= 0; x
< width
/ 2; x
++)
528 for(x
= 0; x
< width
; x
++)
531 if (CalcWheelColor(x
, y
, cx
, cy
, &hsb
.cw_Hue
, &hsb
.cw_Saturation
))
533 LONG t
,v
, r
,g
,b
, base
;
535 ConvertHSBToRGB(&hsb
, &rgb
);
537 t
= Bayer16
[y
& 15][x
& 15];
539 t
= (t
* range
) / 255;
541 v
= ( rgb
.cw_Red
>> 24 );
542 base
= (v
/ range
) * range
;
543 r
= (v
- base
> t
) ? base
+ range
: base
;
545 v
= ( rgb
.cw_Green
>> 24 );
546 base
= (v
/ range
) * range
;
547 g
= (v
- base
> t
) ? base
+ range
: base
;
549 v
= ( rgb
.cw_Blue
>> 24 );
550 base
= (v
/ range
) * range
;
551 b
= (v
- base
> t
) ? base
+ range
: base
;
553 r
/= range
;if (r
>= levels
) r
= levels
- 1;
554 g
/= range
;if (g
>= levels
) g
= levels
- 1;
555 b
/= range
;if (b
>= levels
) b
= levels
- 1;
559 base
= r
+ (g
*levels
) + b
;
560 *p
++ = data
->pens
[ base
];
562 #if USE_SYMMETRIC_SPEEDUP
563 base
= r
+ (b
*levels
) + g
;
564 *--p2
= data
->pens
[ base
];
571 #if USE_SYMMETRIC_SPEEDUP
576 } /* for(x = 0; x < width; x++) */
579 WritePixelLine8( rp
, startX
+left
,top
+y
, w
, &buf
[startX
], tRP
);
581 } /* for(y = 0; y < height; y++) */
591 /***************************************************************************************************/
593 VOID
RenderWheel(struct ColorWheelData
*data
, struct RastPort
*rp
, struct IBox
*box
,
594 struct Library
*ColorWheelBase
598 struct RastPort temprp
;
601 cx
= data
->frame
? BORDERWHEELSPACINGX
* 4 : BORDERWHEELSPACINGX
* 2;
602 cy
= data
->frame
? BORDERWHEELSPACINGY
* 4 : BORDERWHEELSPACINGY
* 2;
604 data
->wheeldrawn
= FALSE
;
606 if ( (box
->Width
< cx
) || (box
->Height
< cy
) ) return;
608 if (!data
->bm
|| (box
->Width
!= data
->bmwidth
) || (box
->Height
!= data
->bmheight
))
616 #ifdef USE_ALLOCRASTER
617 FreeRaster( data
->mask
,
618 GetBitMapAttr( data
->bm
, BMA_WIDTH
),
619 GetBitMapAttr( data
->bm
, BMA_HEIGHT
) );
621 FreeVec( data
->mask
);
627 FreeBitMap(data
->bm
);
630 data
->bm
= AllocBitMap(box
->Width
,
632 GetBitMapAttr(rp
->BitMap
, BMA_DEPTH
),
638 data
->bmwidth
= box
->Width
;
639 data
->bmheight
= box
->Height
;
641 wbox
.Left
= data
->frame
? BORDERWHEELSPACINGX
: 2;
642 wbox
.Top
= data
->frame
? BORDERWHEELSPACINGY
: 2;
643 wbox
.Width
= (box
->Width
- (data
->frame
? BORDERWHEELSPACINGX
* 2 : 4)) & ~1;
644 wbox
.Height
= (box
->Height
- (data
->frame
? BORDERWHEELSPACINGY
* 2 : 4)) & ~1;
646 if( wbox
.Width
> 440 )
648 wbox
.Left
+= (wbox
.Width
-440)/2;
652 if( wbox
.Height
> 440 )
654 wbox
.Top
+= (wbox
.Height
-440)/2;
658 InitRastPort(&temprp
);
659 temprp
.BitMap
= data
->bm
;
661 SetDrMd(&temprp
, JAM1
);
662 SetRast( &temprp
, data
->dri
->dri_Pens
[ BACKGROUNDPEN
] );
665 ry
= wbox
.Height
/ 2;
677 struct TagItem fitags
[] =
679 {IA_Width
, box
->Width
},
680 {IA_Height
, box
->Height
},
684 SetAttrsA(data
->frame
, fitags
);
685 DrawImageState(&temprp
, (struct Image
*)data
->frame
, 0, 0, IDS_NORMAL
, data
->dri
);
689 struct BitMap maskBM
;
690 ULONG bmWidth
, bmHeight
, rasSize
;
693 bmWidth
= GetBitMapAttr( data
->bm
, BMA_WIDTH
);
694 bmHeight
= GetBitMapAttr( data
->bm
, BMA_HEIGHT
);
695 InitBitMap( &maskBM
, 1L, bmWidth
, bmHeight
);
697 rasSize
= RASSIZE( bmWidth
, bmHeight
);
699 #ifdef USE_ALLOCRASTER
700 if( ( ras
= AllocRaster( bmWidth
, bmHeight
) ) )
702 if( ( ras
= AllocVec( rasSize
, MEMF_CHIP
) ) )
705 #ifdef USE_ALLOCRASTER
706 if( ( data
->mask
= AllocRaster( bmWidth
, bmHeight
) ) )
708 if( ( data
->mask
= AllocVec( rasSize
, MEMF_CHIP
) ) )
713 struct RastPort
*maskRP
= &data
->trp
;
716 maskRP
->BitMap
= &maskBM
;
717 maskBM
.Planes
[0] = data
->mask
;
718 InitArea( &ai
, buf
, sizeof( buf
) / 5 );
719 maskRP
->AreaInfo
= &ai
;
720 maskRP
->TmpRas
= &tr
;
721 InitTmpRas( &tr
, ras
, rasSize
);
723 SetRast( maskRP
, 0L );
724 SetAPen( maskRP
, 1L );
725 AreaEllipse( maskRP
, cx
,cy
, rx
,ry
);
731 data
->savebm
= AllocBitMap(
732 KNOBWIDTH
, KNOBHEIGHT
,
733 GetBitMapAttr(rp
->BitMap
, BMA_DEPTH
),
734 BMF_MINPLANES
, rp
->BitMap
);
737 maskRP
->AreaInfo
= NULL
;
738 maskRP
->TmpRas
= NULL
;
741 #ifndef USE_ALLOCRASTER
744 FreeRaster( ras
, bmWidth
, bmHeight
);
750 if (CyberGfxBase
&& (GetBitMapAttr(data
->bm
, BMA_DEPTH
) >= 15))
752 TrueWheel(data
, &temprp
, &wbox
, ColorWheelBase
);
754 ClutWheel(data
, &temprp
, &wbox
, ColorWheelBase
);
757 SetAPen(&temprp
, data
->dri
->dri_Pens
[SHADOWPEN
]);
758 DrawEllipse(&temprp
, cx
, cy
, rx
, ry
);
759 DrawEllipse(&temprp
, cx
, cy
, rx
- 1, ry
);
760 DrawEllipse(&temprp
, cx
, cy
, rx
, ry
- 1);
761 DrawEllipse(&temprp
, cx
, cy
, rx
- 1, ry
- 1);
763 DeinitRastPort(&temprp
);
765 } /* if (data->bm) */
767 } /* if (!data->bm || (box->Width != data->bmwidth) || (box->Height != data->bmheight)) */
773 EraseRect( rp
, box
->Left
,box
->Top
, box
->Left
+box
->Width
-1, box
->Top
+box
->Height
-1 );
775 BltMaskBitMapRastPort(
777 rp
, box
->Left
, box
->Top
, box
->Width
, box
->Height
,
780 NewBltMaskBitMapRastPort(
782 rp
, box
->Left
, box
->Top
, box
->Width
, box
->Height
,
783 0xe0, data
->mask
, (struct Library
*)GfxBase
, LayersBase
);
786 else BltBitMapRastPort(data
->bm
, 0, 0, rp
, box
->Left
, box
->Top
, box
->Width
, box
->Height
, 0xC0);
788 data
->wheeldrawn
= TRUE
;
793 /***************************************************************************************************/
795 VOID
RenderKnob(struct ColorWheelData
*data
, struct RastPort
*rp
,
796 struct IBox
*gbox
, BOOL update
801 if (!data
->wheeldrawn
) return;
808 BltBitMapRastPort(data
->savebm
,
811 data
->knobsavex
+ gbox
->Left
,
812 data
->knobsavey
+ gbox
->Top
,
817 BltBitMapRastPort(data
->bm
,
818 data
->knobsavex
,data
->knobsavey
,
820 data
->knobsavex
+ gbox
->Left
,
821 data
->knobsavey
+ gbox
->Top
,
827 CalcKnobPos(data
, &x
, &y
);
829 if (x
< KNOBCX
) x
= KNOBCX
; else if (x
> gbox
->Width
- 1 - KNOBCX
) x
= gbox
->Width
- 1 - KNOBCX
;
830 if (y
< KNOBCY
) y
= KNOBCY
; else if (y
> gbox
->Height
- 1 - KNOBCY
) y
= gbox
->Height
- 1 - KNOBCY
;
834 data
->knobsavex
= x
- KNOBCX
;
835 data
->knobsavey
= y
- KNOBCY
;
844 data
->trp
.BitMap
= data
->savebm
;
845 ClipBlit(rp
, x
-KNOBCX
,y
-KNOBCY
, &data
->trp
, 0,0, KNOBWIDTH
,KNOBHEIGHT
, 0xc0 );
850 SetAPen(rp
, data
->dri
->dri_Pens
[SHADOWPEN
]);
852 RectFill(rp
, x
- 3, y
- 1, x
- 3, y
+ 1);
853 RectFill(rp
, x
- 2, y
- 2, x
- 2, y
+ 2);
854 RectFill(rp
, x
- 1, y
- 3, x
+ 1, y
+ 3);
855 RectFill(rp
, x
+ 2, y
- 2, x
+ 2, y
+ 2);
856 RectFill(rp
, x
+ 3, y
- 1, x
+ 3, y
+ 1);
858 SetAPen(rp
, data
->dri
->dri_Pens
[SHINEPEN
]);
860 RectFill(rp
, x
- 1, y
, x
+ 1, y
);
861 RectFill(rp
, x
, y
- 1, x
, y
+ 1);
864 /***************************************************************************************************/
866 VOID
GetGadgetIBox(Object
*o
, struct GadgetInfo
*gi
, struct IBox
*ibox
)
868 ibox
->Left
= EG(o
)->LeftEdge
;
869 ibox
->Top
= EG(o
)->TopEdge
;
870 ibox
->Width
= EG(o
)->Width
;
871 ibox
->Height
= EG(o
)->Height
;
875 if (EG(o
)->Flags
& GFLG_RELRIGHT
)
876 ibox
->Left
+= gi
->gi_Domain
.Width
- 1;
878 if (EG(o
)->Flags
& GFLG_RELBOTTOM
)
879 ibox
->Top
+= gi
->gi_Domain
.Height
- 1;
881 if (EG(o
)->Flags
& GFLG_RELWIDTH
)
882 ibox
->Width
+= gi
->gi_Domain
.Width
;
884 if (EG(o
)->Flags
& GFLG_RELHEIGHT
)
885 ibox
->Height
+= gi
->gi_Domain
.Height
;
890 /***************************************************************************************************/
892 void DrawDisabledPattern(struct ColorWheelData
*data
, struct RastPort
*rport
,
896 ULONG pattern
= 0x88882222;
898 EnterFunc(bug("DrawDisabledPattern(rp=%p, gadbox=%p, pen=%d)\n",
899 rport
, gadbox
, pen
));
901 SetDrMd( rport
, JAM1
);
902 SetAPen( rport
, data
->dri
->dri_Pens
[SHADOWPEN
] );
903 SetAfPt( rport
, (UWORD
*)&pattern
, 1);
909 UWORD rx
= data
->wheelrx
,
911 d
= GetBitMapAttr( data
->bm
, BMA_DEPTH
);
915 rasSize
= RASSIZE( rx
*2*d
, ry
*2 );
916 #ifdef USE_ALLOCRASTER
917 if( ( ras
= AllocRaster( rx
*2*d
, ry
*2 ) ) )
919 if( ( ras
= AllocVec( rasSize
, MEMF_CHIP
) ) )
926 InitArea( &ai
, buf
, sizeof( buf
) / 5 );
927 rport
->AreaInfo
= &ai
;
928 InitTmpRas( &tr
, ras
, rasSize
);
932 gadbox
->Left
+data
->wheelcx
,
933 gadbox
->Top
+data
->wheelcy
, rx
,ry
);
938 rport
->AreaInfo
= NULL
;
939 rport
->TmpRas
= NULL
;
941 SetAfPt ( rport
, NULL
, 0);
942 #ifdef USE_ALLOCRASTER
943 FreeRaster( ras
, rx
*2*d
, ry
*2 );
947 ReturnVoid("DrawDisabledPattern");
951 /* render disable pattern */
952 RectFill( rport
, gadbox
->Left
,
954 gadbox
->Left
+ gadbox
->Width
- 1,
955 gadbox
->Top
+ gadbox
->Height
- 1);
957 SetAfPt ( rport
, NULL
, 0);
959 ReturnVoid("DrawDisabledPattern");
962 /***************************************************************************************************/
964 BOOL
getPens( struct ColorWheelData
*data
)
966 struct ColorMap
*cm
= data
->scr
->ViewPort
.ColorMap
;
967 LONG r
,g
,b
, levels
= data
->levels
, range
= data
->range
, i
;
968 WORD
*p
, *donation
= data
->donation
;
970 for(p
= data
->pens
, i
= levels
-1, r
= 0 ; r
< levels
; r
++)
972 for(g
= 0 ; g
< levels
; g
++)
974 for(b
= 0 ; b
< levels
; b
++)
976 if( r
== i
|| g
== i
|| b
== i
)
978 if( donation
&& *donation
!= -1 )
982 ( 1 << 16 ) | ( *donation
),
983 (r
*range
)*0x01010101,
984 (g
*range
)*0x01010101,
985 (b
*range
)*0x01010101,
989 LoadRGB32( &data
->scr
->ViewPort
, tab
);
994 static struct TagItem tags
[] =
996 {OBP_Precision
, PRECISION_EXACT
},
997 {OBP_FailIfBad
, TRUE
},
1001 if( ( *p
++ = ObtainBestPenA( cm
,
1002 (r
*range
)*0x01010101,
1003 (g
*range
)*0x01010101,
1004 (b
*range
)*0x01010101, tags
) ) == -1L )
1006 WORD
*p2
= data
->pens
;
1010 if( ( donation
= data
->donation
) )
1014 if( *donation
== *p2
)
1020 while( *donation
++ != -1 );
1023 ReleasePen( cm
, *p2
++ );
1035 return data
->gotpens
= TRUE
;
1038 /***************************************************************************************************/
1040 void allocPens( struct ColorWheelData
*data
)
1042 LONG depth
= GetBitMapAttr( data
->scr
->RastPort
.BitMap
, BMA_DEPTH
);
1044 if( ! ( CyberGfxBase
&& depth
>= 15 ) )
1046 LONG donated
= 0L, levels
;
1048 if( data
->donation
)
1049 for( donated
= 0L; data
->donation
[donated
] != 0xffff; donated
++ );
1051 for( levels
= 6; levels
>= 2; levels
-- )
1056 i
= levels
*levels
*levels
-i
*i
*i
;
1058 if( ( i
> (donated
+data
->maxpens
) ) || ( i
> (1L<<depth
) ) )
1061 data
->range
= 255 / (levels
-1);
1062 data
->levels
= levels
;
1064 if( getPens( data
) ) break;
1070 /****************************************************************************/
1072 void freePens( struct ColorWheelData
*data
)
1076 struct ColorMap
*cm
= data
->scr
->ViewPort
.ColorMap
;
1077 LONG i
= data
->levels
;
1079 for( i
= (i
*i
*i
)-1; i
; i
-- )
1081 if( data
->pens
[i
] != -1 )
1085 if( ( donation
= data
->donation
) )
1089 if( data
->pens
[i
] == *donation
)
1095 while( *donation
++ != -1 );
1098 ReleasePen( cm
, data
->pens
[i
] );
1105 /****************************************************************************/