2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
6 #include <proto/alib.h>
7 #include <proto/exec.h>
9 #include <proto/utility.h>
10 #include <proto/intuition.h>
11 #include <proto/graphics.h>
13 #include <exec/memory.h>
14 #include <intuition/screens.h>
15 #include <intuition/cghooks.h>
16 #include <intuition/imageclass.h>
17 #include <intuition/gadgetclass.h>
18 #include <graphics/gfx.h>
23 #include "asl_intern.h"
29 #include <aros/debug.h>
31 #define CLASS_ASLBASE ((struct AslBase_intern *)cl->cl_UserData)
32 #define HOOK_ASLBASE ((struct AslBase_intern *)hook->h_Data)
34 #define AslBase CLASS_ASLBASE
36 /********************** ASL CYCLE CLASS **************************************************/
38 #define CYCLEIMAGEWIDTH 19
45 /***********************************************************************************/
47 IPTR
AslColorPicker__OM_SET(Class
* cl
, struct Gadget
* g
, struct opSet
*msg
);
49 /***********************************************************************************/
51 static void RenderObject_Update(Class
*cl
, struct Gadget
*g
, struct GadgetInfo
*gi
)
55 if ((rp
= ObtainGIRPort(gi
)))
57 DoMethod((Object
*)g
, GM_RENDER
,
67 /***********************************************************************************/
69 static void DrawArrow(Class
*cl
, struct RastPort
*rp
, WORD x1
, WORD y1
, WORD type
)
78 RectFill(rp
, x1
, y1
, x1
+ 6, y1
); y1
+= dy
;
79 RectFill(rp
, x1
+ 1, y1
, x1
+ 5, y1
); y1
+= dy
;
80 RectFill(rp
, x1
+ 2, y1
, x1
+ 4, y1
); y1
+= dy
;
82 WritePixel(rp
, x1
+ 3, y1
);
85 /***********************************************************************************/
87 static void DrawCell(Class
*cl
, struct AslColorPickerData
*data
, WORD index
)
89 WORD x1
, y1
, x2
, y2
, col
, row
;
91 row
= index
% data
->columns
;
92 col
= index
/ data
->columns
;
94 x1
= data
->menux1
+ row
* (data
->cellwidth
+ data
->cellspacex
);
95 y1
= data
->menuy1
+ col
* (data
->cellheight
+ data
->cellspacey
);
97 x2
= x1
+ data
->cellwidth
- 1;
98 y2
= y1
+ data
->cellheight
- 1;
100 SetDrMd(data
->rp
, JAM1
);
101 SetAPen(data
->rp
, data
->colortable
? data
->colortable
[index
] : index
);
102 RectFill(data
->rp
, x1
, y1
, x2
, y2
);
105 /***********************************************************************************/
107 static void DrawCellMark(Class
*cl
, struct AslColorPickerData
*data
, struct DrawInfo
*dri
, WORD index
, BOOL selected
)
109 WORD x1
, y1
, x2
, y2
, col
, row
;
111 row
= index
% data
->columns
;
112 col
= index
/ data
->columns
;
114 x1
= data
->menux1
+ row
* (data
->cellwidth
+ data
->cellspacex
) - 2;
115 y1
= data
->menuy1
+ col
* (data
->cellheight
+ data
->cellspacey
) - 2;
117 x2
= x1
+ data
->cellwidth
- 1 + 4;
118 y2
= y1
+ data
->cellheight
- 1 + 4;
120 SetDrMd(data
->rp
, JAM1
);
121 SetAPen(data
->rp
, dri
->dri_Pens
[selected
? SHADOWPEN
: SHINEPEN
]);
123 Move(data
->rp
, x1
, y1
);
124 Draw(data
->rp
, x2
, y1
);
125 Draw(data
->rp
, x2
, y2
);
126 Draw(data
->rp
, x1
, y2
);
127 Draw(data
->rp
, x1
, y1
);
130 /***********************************************************************************/
132 static void DrawAllCells(Class
*cl
, struct AslColorPickerData
*data
)
136 for(i
= 0; i
< data
->numcolors
; i
++)
138 DrawCell(cl
, data
, i
);
142 /***********************************************************************************/
144 IPTR
AslColorPicker__OM_NEW(Class
* cl
, Object
* o
, struct opSet
*msg
)
146 struct AslColorPickerData
*data
;
147 struct TagItem fitags
[] =
149 {IA_FrameType
, FRAME_BUTTON
},
150 {IA_EdgesOnly
, FALSE
},
154 struct Gadget
*g
= (struct Gadget
*)DoSuperMethodA(cl
, o
, (Msg
)msg
);
157 data
= INST_DATA(cl
, g
);
159 /* We want to get a GM_LAYOUT message, no matter if gadget is GFLG_RELRIGHT/RELBOTTOM/
160 RELWIDTH/RELHEIGHT or not */
161 g
->Flags
|= GFLG_RELSPECIAL
;
163 data
->frame
= NewObjectA(NULL
, FRAMEICLASS
, fitags
);
166 AslColorPicker__OM_SET(cl
, g
, msg
);
170 CoerceMethod(cl
, (Object
*)g
, OM_DISPOSE
);
179 /***********************************************************************************/
181 IPTR
AslColorPicker__OM_DISPOSE(Class
* cl
, Object
* o
, Msg msg
)
183 struct AslColorPickerData
*data
= INST_DATA(cl
, o
);
185 if (data
->frame
) DisposeObject(data
->frame
);
187 return DoSuperMethodA(cl
, o
, msg
);
190 /***********************************************************************************/
192 IPTR
AslColorPicker__OM_SET(Class
* cl
, struct Gadget
* g
, struct opSet
*msg
)
194 struct AslColorPickerData
*data
= INST_DATA(cl
, g
);
195 struct TagItem
*tag
, *tstate
= msg
->ops_AttrList
;
198 retval
= DoSuperMethod(cl
, (Object
*)g
, OM_SET
, (IPTR
) msg
->ops_AttrList
, (IPTR
) msg
->ops_GInfo
);
200 while((tag
= NextTagItem(&tstate
)))
202 tidata
= tag
->ti_Data
;
207 data
->color
= tidata
;
211 case ASLCP_ColorTable
:
212 data
->colortable
= (UBYTE
*)tidata
;
216 case ASLCP_NumColors
:
217 data
->numcolors
= tidata
;
221 } /* switch(tag->ti_Tag) */
223 } /* while((tag = NextTagItem(&tstate))) */
227 RenderObject_Update(cl
, g
, msg
->ops_GInfo
);
234 /***********************************************************************************/
236 IPTR
AslColorPicker__OM_GET(Class
* cl
, Object
* o
, struct opGet
*msg
)
238 struct AslColorPickerData
*data
= INST_DATA(cl
, o
);
241 switch(msg
->opg_AttrID
)
244 *msg
->opg_Storage
= data
->color
;
248 retval
= DoSuperMethodA(cl
, o
, (Msg
)msg
);
255 /***********************************************************************************/
257 IPTR
AslColorPicker__GM_RENDER(Class
* cl
, struct Gadget
* g
, struct gpRender
*msg
)
259 struct AslColorPickerData
*data
= INST_DATA(cl
, g
);
260 struct RastPort
*rp
= msg
->gpr_RPort
;
261 struct DrawInfo
*dri
= msg
->gpr_GInfo
->gi_DrInfo
;
262 WORD gadx
, gady
, gadw
, gadh
, x
, y
, y2
, a1
, a2
;
266 struct TagItem im_tags
[] =
273 getgadgetcoords(g
, msg
->gpr_GInfo
, &gadx
, &gady
, &gadw
, &gadh
);
275 if (msg
->gpr_Redraw
== GREDRAW_REDRAW
)
277 im_tags
[0].ti_Data
= gadw
;
278 im_tags
[1].ti_Data
= gadh
;
280 SetAttrsA(data
->frame
, im_tags
);
282 DrawImageState(msg
->gpr_RPort
,
283 (struct Image
*)data
->frame
,
286 (g
->Flags
& GFLG_SELECTED
) ? IDS_SELECTED
: IDS_NORMAL
,
287 msg
->gpr_GInfo
->gi_DrInfo
);
289 x
= gadx
+ gadw
- CYCLEIMAGEWIDTH
;
291 y2
= gady
+ gadh
- 1 - 2;
295 SetAPen(rp
, dri
->dri_Pens
[SHINEPEN
]);
296 RectFill(rp
, x
+ 1, y
, x
+ 1, y2
);
297 SetAPen(rp
, dri
->dri_Pens
[SHADOWPEN
]);
298 RectFill(rp
, x
, y
, x
, y2
);
300 y
= gady
+ (gadh
- 4) / 2;
303 DrawArrow(cl
, rp
, x
, y
, ARROW_DOWN
);
309 a2
= gadx
+ gadw
- CYCLEIMAGEWIDTH
- 3;
311 SetAPen(rp
, data
->color
);
312 RectFill(rp
, a1
, gady
+ 3, a2
, gady
+ gadh
- 1 - 3);
319 /***********************************************************************************/
321 IPTR
AslColorPicker__GM_GOACTIVE(Class
* cl
, struct Gadget
* g
, struct gpInput
*msg
)
323 struct AslColorPickerData
*data
= INST_DATA(cl
, g
);
324 struct DrawInfo
*dri
= msg
->gpi_GInfo
->gi_DrInfo
;
325 WORD x
, y
, x2
, y2
, gadx
, gady
, gadw
, gadh
;
326 IPTR rc
= GMR_MEACTIVE
;
328 if (!msg
->gpi_IEvent
|| !data
->numcolors
) return GMR_NOREUSE
;
330 data
->sentgadgetup
= FALSE
;
332 getgadgetcoords(g
, msg
->gpi_GInfo
, &gadx
, &gady
, &gadw
, &gadh
);
334 data
->borderleft
= 4;
336 data
->borderright
= 4;
337 data
->borderbottom
= 4;
339 if (!data
->colortable
&& data
->numcolors
> (1L << dri
->dri_Depth
))
341 data
->numcolors
= 1L << dri
->dri_Depth
;
347 * Do a sqrt 'by hand'
349 while ((n
*n
) <= data
->numcolors
) {
352 if ((n
* n
) > data
->numcolors
) {
358 data
->rows
= (WORD
)sqrt((double)data
->numcolors
);
360 data
->columns
= (data
->numcolors
+ data
->rows
- 1) / data
->rows
;
362 data
->cellspacex
= 3;
363 data
->cellspacey
= 3;
365 data
->cellwidth
= dri
->dri_Font
->tf_YSize
;
366 data
->cellheight
= data
->cellwidth
;
368 data
->menuwidth
= data
->columns
* data
->cellwidth
+
369 (data
->columns
- 1) * data
->cellspacex
+
370 data
->borderleft
+ data
->borderright
;
372 data
->menuheight
= data
->rows
* data
->cellheight
+
373 (data
->rows
- 1) * data
->cellspacey
+
374 data
->bordertop
+ data
->borderbottom
;
376 data
->menux1
= data
->borderleft
;
377 data
->menuy1
= data
->bordertop
;
378 data
->menux2
= data
->menuwidth
- data
->borderright
- 1;
379 data
->menuy2
= data
->menuheight
- data
->borderbottom
- 1;
382 x
= msg
->gpi_GInfo
->gi_Window
->MouseX
;
384 x
= msg
->gpi_GInfo
->gi_Window
->LeftEdge
+ gadx
;
385 y
= msg
->gpi_GInfo
->gi_Window
->TopEdge
+ gady
+ gadh
;
388 if ((x
+ data
->menuwidth
) > msg
->gpi_GInfo
->gi_Screen
->Width
)
390 x
= msg
->gpi_GInfo
->gi_Screen
->Width
- data
->menuwidth
;
394 if ((y
+ data
->menuheight
) > msg
->gpi_GInfo
->gi_Screen
->Height
)
396 y
= msg
->gpi_GInfo
->gi_Screen
->Height
- data
->menuheight
;
399 x2
= x
+ data
->menuwidth
- 1;
400 y2
= y
+ data
->menuheight
- 1;
402 if ((data
->popupwindow
= OpenWindowTags(0,WA_CustomScreen
, (IPTR
) msg
->gpi_GInfo
->gi_Screen
,
405 WA_Width
, data
->menuwidth
,
406 WA_Height
, data
->menuheight
,
407 WA_Flags
, WFLG_BORDERLESS
,
408 WA_BackFill
, (IPTR
) LAYERS_NOBACKFILL
,
411 data
->rp
= data
->popupwindow
->RPort
;
413 data
->layerx1
= x
; data
->layery1
= y
;
414 data
->layerx2
= x2
; data
->layery2
= y2
;
417 SetDrMd(data
->rp
, JAM1
);
421 x2
= x
+ data
->menuwidth
- 1;
422 y2
= y
+ data
->menuheight
- 1;
424 SetAPen(data
->rp
, dri
->dri_Pens
[SHADOWPEN
]);
425 RectFill(data
->rp
, x
, y
, x2
, y
);
426 RectFill(data
->rp
, x2
, y
+ 1, x2
, y2
);
427 RectFill(data
->rp
, x
, y2
, x2
- 1, y2
);
428 RectFill(data
->rp
, x
, y
+ 1, x
, y2
- 1);
430 SetAPen (data
->rp
, dri
->dri_Pens
[SHINEPEN
]);
431 RectFill(data
->rp
, x
+ 1, y
+ 1, x2
- 1, y2
- 1);
433 DrawAllCells(cl
, data
);
443 /***********************************************************************************/
445 IPTR
AslColorPicker__GM_HANDLEINPUT(Class
* cl
, struct Gadget
* g
, struct gpInput
*msg
)
447 struct AslColorPickerData
*data
= INST_DATA(cl
, g
);
448 WORD gadx
, gady
, gadw
, gadh
, x
, y
, sel
;
449 IPTR rc
= GMR_MEACTIVE
;
451 getgadgetcoords(g
, msg
->gpi_GInfo
, &gadx
, &gady
, &gadw
, &gadh
);
453 switch(msg
->gpi_IEvent
->ie_Class
)
455 case IECLASS_RAWMOUSE
:
456 if (msg
->gpi_IEvent
->ie_Code
== SELECTUP
)
459 if (data
->selected
!= -1)
461 data
->color
= data
->colortable
? data
->colortable
[data
->selected
] : data
->selected
;
462 data
->sentgadgetup
= TRUE
;
465 *msg
->gpi_Termination
= data
->color
;
469 else if (msg
->gpi_IEvent
->ie_Code
== IECODE_NOBUTTON
)
471 /* fall through to IECLASS_TIMER */
480 x
= msg
->gpi_GInfo
->gi_Screen
->MouseX
- data
->layerx1
;
481 y
= msg
->gpi_GInfo
->gi_Screen
->MouseY
- data
->layery1
;
483 if ((x
< data
->menux1
) || (x
> data
->menux2
) ||
484 (y
< data
->menuy1
) || (y
> data
->menuy2
))
486 if (data
->selected
!= -1)
488 DrawCellMark(cl
, data
, msg
->gpi_GInfo
->gi_DrInfo
, data
->selected
, FALSE
);
497 sel
= data
->columns
* (y
/ (data
->cellheight
+ data
->cellspacey
)) +
498 x
/ (data
->cellwidth
+ data
->cellspacex
);
500 if (sel
< 0) sel
= 0; /* paranoia */
502 if (sel
!= data
->selected
)
504 if (data
->selected
!= -1)
506 DrawCellMark(cl
, data
, msg
->gpi_GInfo
->gi_DrInfo
, data
->selected
, FALSE
);
510 if (sel
< data
->numcolors
)
512 data
->selected
= sel
;
513 DrawCellMark(cl
, data
, msg
->gpi_GInfo
->gi_DrInfo
, data
->selected
, TRUE
);
520 } /* switch(msg->gpi_IEvent->ie_Class) */
526 /***********************************************************************************/
528 IPTR
AslColorPicker__GM_GOINACTIVE(Class
* cl
, struct Gadget
* g
, struct gpGoInactive
*msg
)
530 struct AslColorPickerData
*data
= INST_DATA(cl
, g
);
532 if (data
->popupwindow
)
534 CloseWindow(data
->popupwindow
);
535 data
->popupwindow
= 0;
538 if (data
->sentgadgetup
)
540 RenderObject_Update(cl
, g
, msg
->gpgi_GInfo
);
546 /***********************************************************************************/