2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
9 /****************************************************************************************/
11 #define USE_BOOPSI_STUBS
13 #include <exec/execbase.h>
14 #include <exec/memory.h>
15 #include <intuition/intuition.h>
16 #include <intuition/classes.h>
17 #include <intuition/classusr.h>
18 #include <intuition/imageclass.h>
19 #include <intuition/gadgetclass.h>
20 #include <intuition/cghooks.h>
21 #include <graphics/gfx.h>
22 #include <cybergraphx/cybergraphics.h>
23 #include <proto/exec.h>
24 #include <proto/intuition.h>
25 #include <proto/graphics.h>
26 #include <proto/cybergraphics.h>
27 #include <proto/utility.h>
28 #include <aros/asmcall.h>
29 #include <clib/boopsistubs.h>
32 #include "coolimages.h"
34 /****************************************************************************************/
38 struct CoolImage
*image
;
45 /****************************************************************************************/
47 extern struct IntuitionBase
*IntuitionBase
;
48 extern struct GfxBase
*GfxBase
;
49 extern struct UtilityBase
*UtilityBase
;
51 struct IClass
*cool_buttonclass
;
53 /****************************************************************************************/
55 #define CyberGfxBase cool_cybergfxbase
56 #define G(x) ((struct Gadget *)(x))
58 #define BORDERIMAGESPACINGX 4
60 /****************************************************************************************/
62 static struct Library
*cool_cybergfxbase
;
64 /****************************************************************************************/
66 static void getgadgetcoords(struct Gadget
*gad
, struct GadgetInfo
*gi
,
67 WORD
*x
, WORD
*y
, WORD
*w
, WORD
*h
)
69 *x
= gad
->LeftEdge
+ ((gad
->Flags
& GFLG_RELRIGHT
) ? gi
->gi_Domain
.Width
- 1 : 0);
70 *y
= gad
->TopEdge
+ ((gad
->Flags
& GFLG_RELBOTTOM
) ? gi
->gi_Domain
.Height
- 1 : 0);
71 *w
= gad
->Width
+ ((gad
->Flags
& GFLG_RELWIDTH
) ? gi
->gi_Domain
.Width
: 0);
72 *h
= gad
->Height
+ ((gad
->Flags
& GFLG_RELHEIGHT
) ? gi
->gi_Domain
.Height
: 0);
75 /****************************************************************************************/
77 static IPTR
coolbutton_new(Class
* cl
, Object
* o
, struct opSet
* msg
)
80 struct CoolButtonData
*data
;
81 struct TagItem fitags
[] =
83 { IA_FrameType
, FRAME_BUTTON
},
84 { IA_EdgesOnly
, FALSE
},
88 o
= (Object
*)DoSuperMethodA(cl
, o
, (Msg
)msg
);
92 data
= INST_DATA(cl
, o
);
94 data
->image
= (struct CoolImage
*)GetTagData(COOLBT_CoolImage
, 0, msg
->ops_AttrList
);
95 data
->frame
= NewObjectA(NULL
, FRAMEICLASS
, fitags
);
99 CoerceMethod(cl
, o
, OM_DISPOSE
);
102 if (CyberGfxBase
&& data
->image
)
104 if ((data
->pal
= AllocVec(data
->image
->numcolors
* sizeof(ULONG
), MEMF_PUBLIC
)))
106 ULONG
*p
= data
->pal
;
109 for(i
= 0; i
< data
->image
->numcolors
; i
++)
111 *p
++ = (data
->image
->pal
[i
* 3] << 16) |
112 (data
->image
->pal
[i
* 3 + 1] << 8) |
113 (data
->image
->pal
[i
* 3 + 2]);
129 /****************************************************************************************/
131 static IPTR
coolbutton_dispose(Class
* cl
, Object
* o
, Msg msg
)
134 struct CoolButtonData
*data
;
136 data
= INST_DATA(cl
, o
);
138 if (data
->frame
) DisposeObject(data
->frame
);
139 if (data
->pal
) FreeVec(data
->pal
);
141 return DoSuperMethodA(cl
, o
, msg
);
144 /****************************************************************************************/
146 static IPTR
coolbutton_hittest(Class
*cl
, Object
*o
, struct gpHitTest
*msg
)
148 WORD gadx
, gady
, gadw
, gadh
;
150 getgadgetcoords(G(o
), msg
->gpht_GInfo
, &gadx
, &gady
, &gadw
, &gadh
);
152 return ((msg
->gpht_Mouse
.X
>= 0) &&
153 (msg
->gpht_Mouse
.Y
>= 0) &&
154 (msg
->gpht_Mouse
.X
< gadw
) &&
155 (msg
->gpht_Mouse
.Y
< gadh
)) ? GMR_GADGETHIT
: 0;
158 /****************************************************************************************/
160 static IPTR
coolbutton_render(Class
*cl
, Object
*o
, struct gpRender
*msg
)
162 struct CoolButtonData
*data
;
163 STRPTR text
= (STRPTR
)G(o
)->GadgetText
;
164 struct TagItem im_tags
[] =
172 getgadgetcoords(G(o
), msg
->gpr_GInfo
, &x
, &y
, &w
, &h
);
174 data
= INST_DATA(cl
, o
);
176 im_tags
[0].ti_Data
= w
;
177 im_tags
[1].ti_Data
= h
;
179 SetAttrsA(data
->frame
, im_tags
);
181 DrawImageState(msg
->gpr_RPort
,
182 (struct Image
*)data
->frame
,
185 (G(o
)->Flags
& GFLG_SELECTED
) ? IDS_SELECTED
: IDS_NORMAL
,
186 msg
->gpr_GInfo
->gi_DrInfo
);
188 if (GetBitMapAttr(msg
->gpr_RPort
->BitMap
, BMA_DEPTH
) < 15)
195 WORD len
= strlen(text
);
198 SetFont(msg
->gpr_RPort
, msg
->gpr_GInfo
->gi_DrInfo
->dri_Font
);
202 tx
+= BORDERIMAGESPACINGX
+ data
->image
->width
+ BORDERIMAGESPACINGX
;
203 w
-= (BORDERIMAGESPACINGX
+ data
->image
->width
+ BORDERIMAGESPACINGX
+ BORDERIMAGESPACINGX
);
206 tx
+= (w
- TextLength(msg
->gpr_RPort
, text
, len
)) / 2;
207 ty
+= (h
- msg
->gpr_RPort
->TxHeight
) / 2 + msg
->gpr_RPort
->TxBaseline
;
209 SetABPenDrMd(msg
->gpr_RPort
,
210 msg
->gpr_GInfo
->gi_DrInfo
->dri_Pens
[(G(o
)->Flags
& GFLG_SELECTED
) ? FILLTEXTPEN
: TEXTPEN
],
213 Move(msg
->gpr_RPort
, tx
, ty
);
214 Text(msg
->gpr_RPort
, text
, len
);
219 SetABPenDrMd(msg
->gpr_RPort
,
220 msg
->gpr_GInfo
->gi_DrInfo
->dri_Pens
[(G(o
)->Flags
& GFLG_SELECTED
) ? FILLPEN
: BACKGROUNDPEN
],
224 RectFill(msg
->gpr_RPort
, x
, y
, x
+ w
- 1, y
+ h
- 1);
229 if ((data
->selcol
== 0) && (data
->bgcol
== 0))
233 GetRGB32(msg
->gpr_GInfo
->gi_Screen
->ViewPort
.ColorMap
,
234 msg
->gpr_GInfo
->gi_DrInfo
->dri_Pens
[FILLPEN
],
238 data
->selcol
= ((col
[0] & 0xFF000000) >> 8) +
239 ((col
[1] & 0xFF000000) >> 16) +
240 ((col
[2] & 0xFF000000) >> 24);
243 GetRGB32(msg
->gpr_GInfo
->gi_Screen
->ViewPort
.ColorMap
,
244 msg
->gpr_GInfo
->gi_DrInfo
->dri_Pens
[BACKGROUNDPEN
],
248 data
->bgcol
= ((col
[0] & 0xFF000000) >> 8) +
249 ((col
[1] & 0xFF000000) >> 16) +
250 ((col
[2] & 0xFF000000) >> 24);
255 data
->pal
[0] = (G(o
)->Flags
& GFLG_SELECTED
) ? data
->selcol
: data
->bgcol
;
257 WriteLUTPixelArray((APTR
)data
->image
->data
,
263 x
+ BORDERIMAGESPACINGX
,
264 y
+ (h
- data
->image
->height
) / 2,
274 /****************************************************************************************/
275 /****************************************************************************************/
276 /****************************************************************************************/
278 AROS_UFH3S(IPTR
, cool_buttonclass_dispatcher
,
279 AROS_UFHA(Class
*, cl
, A0
),
280 AROS_UFHA(Object
*, obj
, A2
),
281 AROS_UFHA(Msg
, msg
, A1
))
287 switch (msg
->MethodID
)
290 retval
= coolbutton_new(cl
, obj
, (struct opSet
*)msg
);
294 retval
= coolbutton_dispose(cl
, obj
, msg
);
298 retval
= coolbutton_hittest(cl
, obj
, (struct gpHitTest
*)msg
);
302 retval
= coolbutton_render(cl
, obj
, (struct gpRender
*)msg
);
306 retval
= DoSuperMethodA(cl
, obj
, msg
);
309 } /* switch (msg->MethodID) */
316 /****************************************************************************************/
320 /****************************************************************************************/
322 BOOL
InitCoolButtonClass(struct Library
*CyberGfxBase
)
327 cool_cybergfxbase
= CyberGfxBase
;
329 if (IntuitionBase
&& GfxBase
&& UtilityBase
&& SysBase
)
331 if (!cool_buttonclass
)
333 cool_buttonclass
= MakeClass(NULL
, BUTTONGCLASS
, NULL
, sizeof(struct CoolButtonData
), 0UL);
336 if (cool_buttonclass
)
338 cool_buttonclass
->cl_Dispatcher
.h_Entry
= (HOOKFUNC
)cool_buttonclass_dispatcher
;
346 /****************************************************************************************/
348 void CleanupCoolButtonClass(void)
350 if (cool_buttonclass
)
352 FreeClass(cool_buttonclass
);
353 cool_buttonclass
= NULL
;
357 /****************************************************************************************/