1 /***************************************************************************
3 TheBar.mcc - Next Generation Toolbar MUI Custom Class
4 Copyright (C) 2003-2005 Alfonso Ranieri
5 Copyright (C) 2005-2007 by TheBar.mcc Open Source Team
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 TheBar class Support Site: http://www.sf.net/projects/thebar
21 ***************************************************************************/
27 #include <mui/muiundoc.h>
31 #include "SDI_stdarg.h"
32 #include "SDI_compiler.h"
34 /***********************************************************************/
38 // Calls parent NEW method within a subclass
39 Object
* VARARGS68K
DoSuperNew(struct IClass
*cl
, Object
*obj
, ...)
45 rc
= (Object
*)DoSuperMethod(cl
, obj
, OM_NEW
, VA_ARG(args
, ULONG
), NULL
);
52 /***********************************************************************/
56 #define HEX(c) ((c>'9')?c-'A'+10:c-'0')
58 ULONG
stch_l(char *chr_ptr
, ULONG
*u_ptr
)
61 while (isxdigit(*chr_ptr
))
63 *u_ptr
=*u_ptr
*16+HEX(*chr_ptr
);
72 /***********************************************************************/
75 obutton(const void *text
, const void *help
)
79 if((obj
= MUI_MakeObject(MUIO_Button
,(ULONG
)tr(text
))))
80 SetAttrs(obj
,MUIA_CycleChain
,TRUE
,MUIA_ShortHelp
,(ULONG
)tr(help
),TAG_DONE
);
85 /***********************************************************************/
88 ocycle(const char **array
, const void *key
, const void *help
)
92 if((obj
= MUI_MakeObject(MUIO_Cycle
,(ULONG
)tr(key
),(ULONG
)array
)))
93 SetAttrs(obj
,MUIA_CycleChain
,TRUE
,MUIA_ShortHelp
,(ULONG
)tr(help
),TAG_DONE
);
98 /***********************************************************************/
101 ocheck(const void *key
, const void *help
)
105 if((obj
= MUI_MakeObject(MUIO_Checkmark
,(ULONG
)tr(key
))))
106 SetAttrs(obj
,MUIA_CycleChain
,TRUE
,MUIA_ShortHelp
,(ULONG
)tr(help
),TAG_DONE
);
111 /***********************************************************************/
114 oslider(const void *key
, const void *help
, LONG min
, LONG max
)
118 if((obj
= MUI_MakeObject(MUIO_Slider
,(ULONG
)tr(key
),min
,max
)))
119 SetAttrs(obj
,MUIA_CycleChain
,TRUE
,MUIA_ShortHelp
,(ULONG
)tr(help
),TAG_DONE
);
124 /***********************************************************************/
127 opop(ULONG type
, const void *key
)
131 if (!(lib_flags
& BASEFLG_MUI4
) && (type
==MUII_PopFont
))
134 if((obj
= MUI_MakeObject(MUIO_PopButton
,type
)))
136 set(obj
,MUIA_CycleChain
,TRUE
);
142 if((k
= GetKeyChar(tr(key
))))
143 set(obj
,MUIA_ControlChar
,ToLower(k
));
150 /***********************************************************************/
153 opoppen(const void *key
, const void *title
, const void *help
)
155 #if defined(__MORPHOS__) || defined(__amigaos4__)
157 MUIA_Window_Title
, (ULONG
)tr(title
),
158 MUIA_ControlChar
, (ULONG
)GetKeyChar(tr(key
)),
159 MUIA_Draggable
, TRUE
,
160 MUIA_CycleChain
, TRUE
,
161 MUIA_ShortHelp
, (ULONG
)tr(help
),
164 if (lib_flags
& BASEFLG_MUI20
)
167 MUIA_Window_Title
, (ULONG
)tr(title
),
168 MUIA_ControlChar
, (ULONG
)GetKeyChar(tr(key
)),
169 MUIA_Draggable
, TRUE
,
170 MUIA_CycleChain
, TRUE
,
171 MUIA_ShortHelp
, (ULONG
)tr(help
),
177 MUIA_Window_Title
, (ULONG
)tr(title
),
178 MUIA_ControlChar
, (ULONG
)GetKeyChar(tr(key
)),
179 MUIA_Draggable
, TRUE
,
180 MUIA_CycleChain
, TRUE
,
181 MUIA_ShortHelp
, (ULONG
)tr(help
),
187 /***********************************************************************/
190 opopfri(const void *key
, const void *title
, const void *help
)
192 return MUI_NewObject("Popfrimage.mui",
193 MUIA_Window_Title
, (ULONG
)tr(title
),
194 MUIA_ControlChar
, (ULONG
)GetKeyChar(tr(key
)),
195 MUIA_CycleChain
, TRUE
,
196 MUIA_ShortHelp
, (ULONG
)tr(help
),
204 /***********************************************************************/
207 opopback(UNUSED ULONG gradient
, const void *key
, const void *title
, const void *help
)
209 #if defined(__MORPHOS__) || defined(__amigaos4__)
210 return MUI_NewObject(MUIC_Popimage
,
211 MUIA_Imageadjust_Type
, MUIV_Imageadjust_Type_Background
,
212 MUIA_Window_Title
, (ULONG
)tr(title
),
213 MUIA_ControlChar
, (ULONG
)GetKeyChar(tr(key
)),
214 MUIA_Draggable
, TRUE
,
215 MUIA_CycleChain
, TRUE
,
216 MUIA_ShortHelp
, (ULONG
)tr(help
),
219 if (lib_flags
& BASEFLG_MUI20
)
221 return MUI_NewObject(MUIC_Popimage
,
222 MUIA_Imageadjust_Type
, MUIV_Imageadjust_Type_Background
,
223 MUIA_Window_Title
, (ULONG
)tr(title
),
224 MUIA_ControlChar
, (ULONG
)GetKeyChar(tr(key
)),
225 MUIA_Draggable
, TRUE
,
226 MUIA_CycleChain
, TRUE
,
227 MUIA_ShortHelp
, (ULONG
)tr(help
),
232 return popbackObject
,
233 MUIA_Window_Title
, (ULONG
)tr(title
),
234 MUIA_ControlChar
, (ULONG
)GetKeyChar(tr(key
)),
235 MUIA_Draggable
, TRUE
,
236 MUIA_CycleChain
, TRUE
,
237 MUIA_ShortHelp
, (ULONG
)tr(help
),
238 MUIA_Popbackground_Gradient
, gradient
,
244 /***********************************************************************/
246 #ifndef PopframeObject
247 #define PopframeObject MUI_NewObject(MUIC_Popframe
251 opopframe(const void *key
, const void *title
, const void *help
)
253 return PopframeObject
,
254 MUIA_Window_Title
, (ULONG
)tr(title
),
255 MUIA_Draggable
, TRUE
,
257 MUIA_ShortHelp
, (ULONG
)tr(help
),
258 MUIA_ControlChar
, (ULONG
)GetKeyChar(tr(key
)),
262 /***********************************************************************/
266 drawGradient(Object
*obj
,struct MUIS_TheBar_Gradient
*grad
)
269 ULONG rs
, gs
, bs
, horiz
, from
, to
;
270 int i
, x
, d
, step
, rdif
, gdif
, bdif
, r1
, g1
, b1
, r2
, g2
, b2
, r
, g
, b
, rd
, gd
, bd
, ridx
, gidx
, bidx
;
271 UWORD l
= _mleft(obj
), t
= _mtop(obj
), w
= _mwidth(obj
), h
= _mheight(obj
);
273 rd
= rdif
= ridx
= gd
= gidx
= bd
= bidx
= 0;
279 horiz
= grad
->flags
& MUIV_TheBar_Gradient_Horiz
;
282 r1
= (from
& 0x00FF0000)>>16;
283 g1
= (from
& 0x0000FF00)>>8;
284 b1
= (from
& 0x000000FF);
286 r2
= (to
& 0x00FF0000)>>16;
287 g2
= (to
& 0x0000FF00)>>8;
288 b2
= (to
& 0x000000FF);
323 /* Find out max diff */
324 step
= (rdif
>=gdif
) ? rdif
: gdif
;
325 if (bdif
>step
) step
= bdif
;
327 /* Find out best step to minimize rest */
330 if (step
>w
) step
= w
;
332 if (step
==0) step
= 1;
339 if (step
>w
) step
= w
;
345 if (step
>h
) step
= h
;
347 if (step
==0) step
= 1;
354 if (step
>h
) step
= h
;
361 /* Compute color components deltas */
372 ridx
= (rdif
>step
) ? step
/((rdif
-step
)/rd
) : 0;
373 gidx
= (gdif
>step
) ? step
/((gdif
-step
)/gd
) : 0;
374 bidx
= (bdif
>step
) ? step
/((bdif
-step
)/bd
) : 0;
378 d
= (horiz
) ? w
/step
: h
/step
;
384 for (i
= 0; i
<step
; i
++)
386 ULONG col
= (r
<<16) | (g
<<8) | b
;
388 /* Fill; if last step fill all rest */
392 FillPixelArray(rp
,x
,t
,w
-x
+l
,h
,col
);
395 else FillPixelArray(rp
,x
,t
,d
,h
,col
);
399 FillPixelArray(rp
,l
,x
,w
,h
-x
+t
,col
);
402 else FillPixelArray(rp
,l
,x
,w
,d
,col
);
406 /* Add delta to each color component */
411 /* Time to add more one more delta? */
412 if (i
&& ridx
&& !(i
%ridx
)) r
+= rd
;
419 if (i
&& ridx
&& !(i
%ridx
)) r
-= rd
;
427 if (i
&& gidx
&& !(i
%gidx
)) g
+= gd
;
434 if (i
&& gidx
&& !(i
%gidx
)) g
-= gd
;
442 if (i
&& bidx
&& !(i
%bidx
)) b
+= bd
;
449 if (i
&& bidx
&& !(i
%bidx
)) b
-= bd
;
456 /***********************************************************************/