2 Copyright © 2002-2018, 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 "scale_private.h"
28 /* #define MYDEBUG 1 */
31 extern struct Library
*MUIMasterBase
;
34 IPTR
Scale__OM_NEW(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
36 struct Scale_DATA
*data
;
37 struct TagItem
*tag
, *tags
;
39 obj
= (Object
*) DoSuperMethodA(cl
, obj
, (Msg
) msg
);
43 data
= INST_DATA(cl
, obj
);
47 /* parse initial taglist */
49 for (tags
= msg
->ops_AttrList
; (tag
= NextTagItem(&tags
));)
53 case MUIA_Scale_Horiz
:
54 data
->horiz
= tag
->ti_Data
;
59 D(bug("muimaster.library/scale.c: Scale Object created at 0x%lx\n",
65 IPTR
Scale__OM_SET(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
67 struct Scale_DATA
*data
;
68 struct TagItem
*tag
, *tags
;
71 data
= INST_DATA(cl
, obj
);
73 for (tags
= msg
->ops_AttrList
; (tag
= NextTagItem(&tags
));)
77 case MUIA_Scale_Horiz
:
78 if (data
->horiz
!= tag
->ti_Data
)
80 data
->horiz
= tag
->ti_Data
;
87 MUI_Redraw(obj
, MADF_DRAWOBJECT
);
89 return DoSuperMethodA(cl
, obj
, (Msg
) msg
);
92 IPTR
Scale__OM_GET(struct IClass
*cl
, Object
*obj
, struct opGet
*msg
)
94 struct Scale_DATA
*data
= INST_DATA(cl
, obj
);
95 IPTR
*store
= msg
->opg_Storage
;
96 IPTR tag
= msg
->opg_AttrID
;
100 case MUIA_Scale_Horiz
:
101 *store
= (IPTR
) data
->horiz
;
105 return DoSuperMethodA(cl
, obj
, (Msg
) msg
);
108 IPTR
Scale__MUIM_Setup(struct IClass
*cl
, Object
*obj
,
109 struct MUIP_Setup
*msg
)
111 struct Scale_DATA
*data
= INST_DATA(cl
, obj
);
113 if (!(DoSuperMethodA(cl
, obj
, (Msg
) msg
)))
117 char *minlabel
= "0% 100%";
121 SetFont(&rp
, _font(obj
));
123 data
->label_minwidth
= TextLength(&rp
, minlabel
, strlen(minlabel
));
124 data
->label_height
= _font(obj
)->tf_YSize
;
130 IPTR
Scale__MUIM_AskMinMax(struct IClass
*cl
, Object
*obj
,
131 struct MUIP_AskMinMax
*msg
)
133 struct Scale_DATA
*data
= INST_DATA(cl
, obj
);
134 DoSuperMethodA(cl
, obj
, (Msg
) msg
);
138 msg
->MinMaxInfo
->MinWidth
+= data
->label_minwidth
;
139 msg
->MinMaxInfo
->MinHeight
+= data
->label_height
+ 4;
140 msg
->MinMaxInfo
->DefWidth
+= data
->label_minwidth
;
141 msg
->MinMaxInfo
->DefHeight
+= data
->label_height
+ 4;
142 msg
->MinMaxInfo
->MaxWidth
= MUI_MAXMAX
;
143 msg
->MinMaxInfo
->MaxHeight
+= data
->label_height
+ 4;
151 IPTR
Scale__MUIM_Draw(struct IClass
*cl
, Object
*obj
,
152 struct MUIP_Draw
*msg
)
154 struct Scale_DATA
*data
= INST_DATA(cl
, obj
);
156 DoSuperMethodA(cl
, obj
, (Msg
) msg
);
157 D(bug("muimaster.library/scale.c: Draw Scale Object "
158 "at 0x%lx %ldx%ldx%ldx%ld\n",
159 obj
, _left(obj
), _top(obj
), _right(obj
), _bottom(obj
)));
169 /* main horizontal bar */
170 SetAPen(_rp(obj
), _pens(obj
)[MPEN_TEXT
]);
171 Move(_rp(obj
), _mleft(obj
), _mtop(obj
) + 3);
172 Draw(_rp(obj
), _mright(obj
), _mtop(obj
) + 3);
174 /* testing possible layouts: 1 = 0...100 ; 2 = 0...50..100 ; etc ... */
175 for (i
= 2; i
< _mwidth(obj
); i
*= 2)
181 for (j
= 0; j
<= i
; j
++)
183 //int pct = j * 100 / i;
185 snprintf(buf
, 255, "%d%%", (int)j
);
186 total_width
+= TextLength(_rp(obj
), buf
, strlen(buf
));
187 if (total_width
> (3 * _mwidth(obj
) / 8))
197 for (k
= 0, drawpct
= TRUE
; k
<= i
; k
++)
202 ZText
*ztext
= zune_text_new(NULL
, "0%", ZTEXT_ARG_NONE
, 0);
205 zune_text_get_bounds(ztext
, obj
);
206 zune_text_draw(ztext
, obj
, _mleft(obj
), _mright(obj
),
208 zune_text_destroy(ztext
);
210 Move(_rp(obj
), _mleft(obj
), _mtop(obj
));
211 Draw(_rp(obj
), _mleft(obj
), _mtop(obj
) + 3);
214 else if (k
== i
) /* draw 100% */
217 zune_text_new("\33r", "100%", ZTEXT_ARG_NONE
, 0);
220 zune_text_get_bounds(ztext
, obj
);
221 zune_text_draw(ztext
, obj
, _mleft(obj
), _mright(obj
),
223 zune_text_destroy(ztext
);
225 Move(_rp(obj
), _mright(obj
), _mtop(obj
));
226 Draw(_rp(obj
), _mright(obj
), _mtop(obj
) + 3);
229 else if (drawpct
) /* draw intermediate values and lines */
232 int val
= k
* 100 / i
;
234 snprintf(buf
, 255, "%d%%", (int)val
);
235 ztext
= zune_text_new(NULL
, buf
, ZTEXT_ARG_NONE
, 0);
239 zune_text_get_bounds(ztext
, obj
);
240 width
= TextLength(_rp(obj
), buf
, strlen(buf
));
241 zune_text_draw(ztext
, obj
,
242 _mleft(obj
) + _mwidth(obj
) * k
/ i
- width
/ 2,
243 _mright(obj
), _mtop(obj
) + 4);
244 zune_text_destroy(ztext
);
246 Move(_rp(obj
), _mleft(obj
) + _mwidth(obj
) * k
/ i
,
248 Draw(_rp(obj
), _mleft(obj
) + _mwidth(obj
) * k
/ i
,
252 else /* draw intermediate lines */
254 Move(_rp(obj
), _mleft(obj
) + _mwidth(obj
) * k
/ i
,
256 Draw(_rp(obj
), _mleft(obj
) + _mwidth(obj
) * k
/ i
,
268 #if ZUNE_BUILTIN_SCALE
269 BOOPSI_DISPATCHER(IPTR
, Scale_Dispatcher
, cl
, obj
, msg
)
271 switch (msg
->MethodID
)
274 return Scale__OM_NEW(cl
, obj
, (struct opSet
*)msg
);
276 return Scale__OM_SET(cl
, obj
, (struct opSet
*)msg
);
278 return Scale__OM_GET(cl
, obj
, (struct opGet
*)msg
);
280 return Scale__MUIM_Setup(cl
, obj
, (struct MUIP_Setup
*)msg
);
282 return Scale__MUIM_AskMinMax(cl
, obj
, (struct MUIP_AskMinMax
*)msg
);
284 return Scale__MUIM_Draw(cl
, obj
, (struct MUIP_Draw
*)msg
);
286 return DoSuperMethodA(cl
, obj
, msg
);
289 BOOPSI_DISPATCHER_END
291 const struct __MUIBuiltinClass _MUI_Scale_desc
=
295 sizeof(struct Scale_DATA
),
296 (void *) Scale_Dispatcher
298 #endif /* ZUNE_BUILTIN_SCALE */