2 Copyright © 2002-2011, The AROS Development Team. All rights reserved.
6 #define MUIMASTER_YES_INLINE_STDARG
10 #include <graphics/gfx.h>
11 #include <graphics/view.h>
12 #include <clib/alib_protos.h>
13 #include <proto/exec.h>
14 #include <proto/graphics.h>
15 #include <proto/utility.h>
16 #include <proto/intuition.h>
17 #include <proto/muimaster.h>
22 #include "muimaster_intern.h"
23 #include "textengine.h"
25 #include "support_classes.h"
26 #include "gauge_private.h"
28 /* #define MYDEBUG 1 */
31 extern struct Library
*MUIMasterBase
;
34 IPTR
Gauge__OM_NEW(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
36 struct Gauge_DATA
*data
;
40 obj
= (Object
*) DoSuperMethodA(cl
, obj
, (Msg
) msg
);
44 data
= INST_DATA(cl
, obj
);
50 data
->dupinfo
= FALSE
;
53 /* parse initial taglist */
54 for (tags
= msg
->ops_AttrList
; (tag
= NextTagItem(&tags
));)
58 case MUIA_Gauge_Current
:
59 data
->current
= tag
->ti_Data
;
61 case MUIA_Gauge_Divide
:
62 data
->divide
= tag
->ti_Data
;
64 case MUIA_Gauge_Horiz
:
65 data
->horiz
= tag
->ti_Data
;
67 case MUIA_Gauge_InfoText
:
68 data
->info
= (STRPTR
) tag
->ti_Data
;
71 data
->max
= tag
->ti_Data
;
73 case MUIA_Gauge_DupInfoText
:
74 data
->dupinfo
= tag
->ti_Data
;
78 if (data
->divide
!= 0)
79 data
->current
/= data
->divide
;
80 if (data
->current
> data
->max
)
81 data
->current
= data
->max
;
83 data
->info
= StrDup(data
->info
);
87 snprintf(data
->buf
, GAUGE_BUFSIZE
, data
->info
, data
->current
);
92 /* D(bug("Gauge_New(0x%lx, %d)\n",obj,muiAreaData(obj)->mad_Frame)); */
97 IPTR
Gauge__OM_DISPOSE(struct IClass
*cl
, Object
*obj
, Msg msg
)
99 struct Gauge_DATA
*data
= INST_DATA(cl
, obj
);
100 if (data
->dupinfo
&& data
->info
)
102 return DoSuperMethodA(cl
, obj
, msg
);
105 IPTR
Gauge__OM_SET(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
107 struct Gauge_DATA
*data
;
109 struct TagItem
*tags
;
110 int info_changed
= 0;
113 data
= INST_DATA(cl
, obj
);
115 for (tags
= msg
->ops_AttrList
; (tag
= NextTagItem(&tags
));)
119 case MUIA_Gauge_Current
:
120 if (data
->current
!= tag
->ti_Data
)
122 data
->current
= tag
->ti_Data
;
128 tag
->ti_Tag
= TAG_IGNORE
;
132 case MUIA_Gauge_Divide
:
133 if (data
->divide
!= tag
->ti_Data
)
135 data
->divide
= tag
->ti_Data
;
141 tag
->ti_Tag
= TAG_IGNORE
;
145 case MUIA_Gauge_InfoText
:
146 if (!data
->info
|| strcmp(data
->info
, (STRPTR
) tag
->ti_Data
))
152 data
->info
= StrDup((STRPTR
) tag
->ti_Data
);
156 data
->info
= (STRPTR
) tag
->ti_Data
;
158 need_redraw
= info_changed
= 1;
162 tag
->ti_Tag
= TAG_IGNORE
;
167 if (data
->max
!= tag
->ti_Data
)
169 data
->max
= tag
->ti_Data
;
174 tag
->ti_Tag
= TAG_IGNORE
;
180 if (data
->divide
!= 0)
181 data
->current
/= data
->divide
;
182 if (data
->current
> data
->max
)
183 data
->current
= data
->max
;
189 snprintf(data
->buf
, GAUGE_BUFSIZE
, data
->info
, data
->current
);
197 MUI_Redraw(obj
, MADF_DRAWOBJECT
);
199 return DoSuperMethodA(cl
, obj
, (Msg
) msg
);
202 IPTR
Gauge__OM_GET(struct IClass
*cl
, Object
*obj
, struct opGet
*msg
)
204 struct Gauge_DATA
*data
= INST_DATA(cl
, obj
);
205 IPTR
*store
= msg
->opg_Storage
;
206 ULONG tag
= msg
->opg_AttrID
;
210 case MUIA_Gauge_Current
:
211 *store
= data
->current
;
214 case MUIA_Gauge_Divide
:
215 *store
= data
->divide
;
218 case MUIA_Gauge_InfoText
:
219 *store
= (IPTR
) data
->info
;
226 case MUIA_Gauge_DupInfoText
:
227 *store
= (IPTR
) data
->dupinfo
;
231 return DoSuperMethodA(cl
, obj
, (Msg
) msg
);
237 IPTR
Gauge__MUIM_Setup(struct IClass
*cl
, Object
*obj
,
238 struct MUIP_Setup
*msg
)
240 struct Gauge_DATA
*data
= INST_DATA(cl
, obj
);
242 if (!(DoSuperMethodA(cl
, obj
, (Msg
) msg
)))
250 SetFont(&rp
, _font(obj
));
252 data
->info_width
= TextLength(&rp
, data
->buf
, strlen(data
->buf
));
253 data
->info_height
= _font(obj
)->tf_YSize
;
259 data
->info_width
= 0;
260 data
->info_height
= 0;
264 data
->info_width
= 0;
265 data
->info_height
= 0;
272 IPTR
Gauge__MUIM_AskMinMax(struct IClass
*cl
, Object
*obj
,
273 struct MUIP_AskMinMax
*msg
)
275 struct Gauge_DATA
*data
= INST_DATA(cl
, obj
);
276 DoSuperMethodA(cl
, obj
, (Msg
) msg
);
280 msg
->MinMaxInfo
->MinWidth
+= data
->info_width
;
281 msg
->MinMaxInfo
->MinHeight
+= data
->info_height
+ 2;
282 msg
->MinMaxInfo
->DefWidth
+= data
->info_width
+ 10;
283 msg
->MinMaxInfo
->DefHeight
+= data
->info_height
+ 2;
284 msg
->MinMaxInfo
->MaxWidth
= MUI_MAXMAX
;
286 msg
->MinMaxInfo
->MaxHeight
+= data
->info_height
+ 2;
288 msg
->MinMaxInfo
->MaxHeight
= MUI_MAXMAX
;
293 msg
->MinMaxInfo
->MinWidth
+= data
->info_width
+ 2;
294 msg
->MinMaxInfo
->MinHeight
+= data
->info_height
;
295 msg
->MinMaxInfo
->DefWidth
+= data
->info_width
+ 2;
296 msg
->MinMaxInfo
->DefHeight
+= data
->info_height
+ 10;
298 msg
->MinMaxInfo
->MaxWidth
+= data
->info_width
+ 2;
300 msg
->MinMaxInfo
->MaxWidth
= MUI_MAXMAX
;
302 msg
->MinMaxInfo
->MaxHeight
= MUI_MAXMAX
;
307 IPTR
Gauge__MUIM_Draw(struct IClass
*cl
, Object
*obj
,
308 struct MUIP_Draw
*msg
)
310 struct Gauge_DATA
*data
= INST_DATA(cl
, obj
);
313 DoSuperMethodA(cl
, obj
, (Msg
) msg
);
315 /* D(bug("Gauge_Draw(0x%lx) %ldx%ldx%ldx%ld :: %ldx%ldx%ldx%ld\n",obj,_left(obj),_top(obj),_right(obj),_bottom(obj), _mleft(obj),_mtop(obj), _mright(obj), _mbottom(obj))); */
322 /* NOTE: should be 64 bit */
323 w
= _mwidth(obj
) * data
->current
/ data
->max
;
329 SetABPenDrMd(_rp(obj
), _pens(obj
)[MPEN_FILL
], 0, JAM1
);
330 RectFill(_rp(obj
), _mleft(obj
), _mtop(obj
), _mleft(obj
) + w
- 1,
336 zune_text_new("\33c\0338", data
->buf
, ZTEXT_ARG_NONE
, 0);
339 zune_text_get_bounds(ztext
, obj
);
340 SetAPen(_rp(obj
), _pens(obj
)[MPEN_SHINE
]);
341 zune_text_draw(ztext
, obj
, _mleft(obj
), _mright(obj
),
342 _mtop(obj
) + (_mheight(obj
) - ztext
->height
) / 2);
343 zune_text_destroy(ztext
);
351 /* NOTE: should be 64 bit */
352 h
= _mheight(obj
) * data
->current
/ data
->max
;
354 SetABPenDrMd(_rp(obj
), _pens(obj
)[MPEN_FILL
], 0, JAM1
);
355 RectFill(_rp(obj
), _mleft(obj
), _mbottom(obj
) - h
+ 1, _mright(obj
),
361 zune_text_new("\33c\0338", data
->buf
, ZTEXT_ARG_NONE
, 0);
364 zune_text_get_bounds(ztext
, obj
);
365 SetAPen(_rp(obj
), _pens(obj
)[MPEN_SHINE
]);
366 zune_text_draw(ztext
, obj
, _mleft(obj
), _mright(obj
),
367 _mtop(obj
) + (_mheight(obj
) - ztext
->height
) / 2);
368 zune_text_destroy(ztext
);
376 #if ZUNE_BUILTIN_GAUGE
377 BOOPSI_DISPATCHER(IPTR
, Gauge_Dispatcher
, cl
, obj
, msg
)
379 switch (msg
->MethodID
)
382 return Gauge__OM_NEW(cl
, obj
, (struct opSet
*)msg
);
384 return Gauge__OM_DISPOSE(cl
, obj
, (Msg
) msg
);
386 return Gauge__OM_SET(cl
, obj
, (struct opSet
*)msg
);
388 return Gauge__OM_GET(cl
, obj
, (struct opGet
*)msg
);
390 return Gauge__MUIM_Setup(cl
, obj
, (struct MUIP_Setup
*)msg
);
392 return Gauge__MUIM_AskMinMax(cl
, obj
, (struct MUIP_AskMinMax
*)msg
);
394 return Gauge__MUIM_Draw(cl
, obj
, (struct MUIP_Draw
*)msg
);
396 return DoSuperMethodA(cl
, obj
, msg
);
399 BOOPSI_DISPATCHER_END
401 const struct __MUIBuiltinClass _MUI_Gauge_desc
=
405 sizeof(struct Gauge_DATA
),
406 (void *) Gauge_Dispatcher
408 #endif /* ZUNE_BUILTIN_GAUGE */