2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
6 #define MUIMASTER_YES_INLINE_STDARG
8 #include <exec/types.h>
9 #include <utility/date.h>
11 #include <aros/debug.h>
12 #include <aros/asmcall.h>
14 #include <proto/alib.h>
15 #include <proto/muimaster.h>
16 #include <proto/graphics.h>
17 #include <proto/intuition.h>
18 #include <proto/utility.h>
19 #include <proto/timer.h>
26 #include "clock_private.h"
32 /*** Methods ****************************************************************/
33 IPTR
Clock__OM_NEW(Class
*cl
, Object
*obj
, struct opSet
*msg
)
35 struct Clock_DATA
*data
;
38 obj
= (Object
*) DoSuperNewTags
47 TAG_MORE
, (IPTR
) msg
->ops_AttrList
52 data
= INST_DATA(cl
, obj
);
53 data
->frozen
= GetTagData(MUIA_Clock_Frozen
, FALSE
, msg
->ops_AttrList
) ? TRUE
: FALSE
;
54 data
->edithand
= (WORD
)GetTagData(MUIA_Clock_EditHand
, (IPTR
)-1, msg
->ops_AttrList
);
57 if ((ti
= FindTagItem(MUIA_Clock_Time
, msg
->ops_AttrList
)))
59 struct ClockData
*cd
= (struct ClockData
*)ti
->ti_Data
;
61 data
->clockdata
= *cd
;
68 Amiga2Date(tv
.tv_secs
, &data
->clockdata
);
71 data
->ihn
.ihn_Flags
= MUIIHNF_TIMER
;
72 data
->ihn
.ihn_Method
= MUIM_Clock_Timer
;
73 data
->ihn
.ihn_Object
= obj
;
74 data
->ihn
.ihn_Millis
= 1000;
80 IPTR
Clock__OM_DISPOSE(Class
*cl
, Object
*obj
, Msg msg
)
82 return DoSuperMethodA(cl
, obj
, msg
);
86 IPTR
Clock__OM_SET(Class
*cl
, Object
*obj
, struct opSet
*msg
)
88 struct Clock_DATA
*data
= INST_DATA(cl
, obj
);
89 struct TagItem
*tags
= msg
->ops_AttrList
;
93 while ((tag
= NextTagItem(&tags
)) != NULL
)
98 data
->clockdata
= *(struct ClockData
*)tag
->ti_Data
;
102 case MUIA_Clock_Hour
:
103 data
->clockdata
.hour
= tag
->ti_Data
;
108 data
->clockdata
.min
= tag
->ti_Data
;
113 data
->clockdata
.sec
= tag
->ti_Data
;
117 case MUIA_Clock_Frozen
:
118 data
->frozen
= tag
->ti_Data
? TRUE
: FALSE
;
121 case MUIA_Clock_EditHand
:
122 data
->edithand
= tag
->ti_Data
;
126 } /* switch(tag->ti_Tag) */
128 } /* while ((tag = NextTagItem(&tags)) != NULL) */
132 MUI_Redraw(obj
, MADF_DRAWUPDATE
);
135 return DoSuperMethodA(cl
, obj
, (Msg
)msg
);
139 IPTR
Clock__OM_GET(Class
*cl
, Object
*obj
, struct opGet
*msg
)
141 struct Clock_DATA
*data
= INST_DATA(cl
, obj
);
144 switch(msg
->opg_AttrID
)
146 case MUIA_Clock_Time
:
147 *(struct ClockData
**)msg
->opg_Storage
= &data
->clockdata
;
150 case MUIA_Clock_Hour
:
151 *msg
->opg_Storage
= data
->clockdata
.hour
;
155 *msg
->opg_Storage
= data
->clockdata
.min
;
159 *msg
->opg_Storage
= data
->clockdata
.sec
;
162 case MUIA_Clock_Frozen
:
163 *msg
->opg_Storage
= data
->frozen
;
166 case MUIA_Clock_EditHand
:
167 *msg
->opg_Storage
= data
->edithand
;
171 retval
= DoSuperMethodA(cl
, obj
, (Msg
)msg
);
179 IPTR
Clock__MUIM_Setup(Class
*cl
, Object
*obj
, struct MUIP_Setup
*msg
)
181 struct Clock_DATA
*data
= INST_DATA(cl
, obj
);
183 if (!DoSuperMethodA(cl
, obj
, (Msg
)msg
)) return FALSE
;
185 DoMethod(_app(obj
), MUIM_Application_AddInputHandler
, (IPTR
) &data
->ihn
);
187 data
->editpen
= ObtainBestPen(_screen(obj
)->ViewPort
.ColorMap
,
191 OBP_Precision
, PRECISION_GUI
,
192 OBP_FailIfBad
, FALSE
,
198 IPTR
Clock__MUIM_Cleanup(Class
*cl
, Object
*obj
, struct MUIP_Cleanup
*msg
)
200 struct Clock_DATA
*data
= INST_DATA(cl
, obj
);
202 if (data
->editpen
!= -1)
204 ReleasePen(_screen(obj
)->ViewPort
.ColorMap
, data
->editpen
);
210 FreeBitMap(data
->clockbm
);
211 FreeRaster(data
->clockraster
, data
->clockbmw
, data
->clockbmh
);
212 data
->clockbm
= NULL
;
213 data
->clockraster
= NULL
;
215 DoMethod(_app(obj
), MUIM_Application_RemInputHandler
, (IPTR
) &data
->ihn
);
217 return DoSuperMethodA(cl
, obj
, (Msg
)msg
);
221 IPTR
Clock__MUIM_AskMinMax(Class
*cl
, Object
*obj
, struct MUIP_AskMinMax
*msg
)
223 DoSuperMethodA(cl
, obj
, (Msg
)msg
);
225 msg
->MinMaxInfo
->MinWidth
+= 31;
226 msg
->MinMaxInfo
->MinHeight
+= 31;
227 msg
->MinMaxInfo
->DefWidth
+= 31;
228 msg
->MinMaxInfo
->DefHeight
+= 31;
229 msg
->MinMaxInfo
->MaxWidth
= MUI_MAXMAX
;
230 msg
->MinMaxInfo
->MaxHeight
= MUI_MAXMAX
;
236 #define MY_PI 3.14159265358979323846
240 struct RastPort
*rp
, WORD cx
, WORD cy
, DOUBLE angle
,
241 WORD radius1
, WORD radius2
246 x
= cx
+ (WORD
)(cos(angle
+ MY_PI
) * radius1
);
247 y
= cy
- (WORD
)(sin(angle
+ MY_PI
) * radius1
);
251 x
= cx
+ (WORD
)(cos(angle
+ MY_PI
/ 2.0) * radius1
);
252 y
= cy
- (WORD
)(sin(angle
+ MY_PI
/ 2.0) * radius1
);
256 x
= cx
+ (WORD
)(cos(angle
) * radius2
);
257 y
= cy
- (WORD
)(sin(angle
) * radius2
);
261 x
= cx
+ (WORD
)(cos(angle
- MY_PI
/ 2.0) * radius1
);
262 y
= cy
- (WORD
)(sin(angle
- MY_PI
/ 2.0) * radius1
);
266 x
= cx
+ (WORD
)(cos(angle
+ MY_PI
) * radius1
);
267 y
= cy
- (WORD
)(sin(angle
+ MY_PI
) * radius1
);
275 static void DrawThinHand(struct RastPort
*rp
, WORD cx
, WORD cy
, DOUBLE angle
, WORD radius
)
281 x
= cx
+ (WORD
)(cos(angle
) * radius
);
282 y
= cy
- (WORD
)(sin(angle
) * radius
);
287 IPTR
Clock__MUIM_Draw(Class
*cl
, Object
*obj
, struct MUIP_Draw
*msg
)
289 struct Clock_DATA
*data
= INST_DATA(cl
, obj
);
290 struct RastPort
*obj_rp
;
291 struct Region
*region
;
292 struct Rectangle rect
;
294 WORD r
, x
, y
, x2
, y2
, i
, cx
, cy
, c
;
295 WORD new_clockbmw
, new_clockbmh
;
296 WORD clock_posx
, clock_posy
;
299 r
= (_mwidth(obj
) - SHADOW_OFFX
) / 2;
300 y
= (_mheight(obj
) - SHADOW_OFFY
) / 2;
304 new_clockbmw
= r
* 2 + 1 + SHADOW_OFFX
;
305 new_clockbmh
= r
* 2 + 1 + SHADOW_OFFY
;
307 clock_posx
= _mleft(obj
) + (_mwidth(obj
) - new_clockbmw
) / 2;
308 clock_posy
= _mtop(obj
) + (_mheight(obj
) - new_clockbmh
) / 2;
310 region
= NewRegion();
313 rect
.MinX
= _left(obj
);
314 rect
.MinY
= _top(obj
);
315 rect
.MaxX
= _right(obj
);
316 rect
.MaxY
= _bottom(obj
);
318 OrRectRegion(region
, &rect
);
320 rect
.MinX
= clock_posx
;
321 rect
.MinY
= clock_posy
;
322 rect
.MaxX
= clock_posx
+ new_clockbmw
- 1;
323 rect
.MaxY
= clock_posy
+ new_clockbmh
- 1;
325 ClearRectRegion(region
, &rect
);
327 clip
= MUI_AddClipRegion(muiRenderInfo(obj
), region
);
330 DoSuperMethodA(cl
, obj
, (Msg
)msg
);
334 MUI_RemoveClipRegion(muiRenderInfo(obj
), clip
);
337 if (!(msg
->flags
& (MADF_DRAWOBJECT
| MADF_DRAWUPDATE
))) return 0;
339 if (!data
->clockbm
|| (data
->clockbmr
!= r
))
343 FreeBitMap(data
->clockbm
);
344 FreeRaster(data
->clockraster
, data
->clockbmw
, data
->clockbmh
);
345 data
->clockraster
= NULL
;
348 data
->clockbmw
= new_clockbmw
;
349 data
->clockbmh
= new_clockbmh
;
351 data
->clockbm
= AllocBitMap(data
->clockbmw
,
353 GetBitMapAttr(_rp(obj
)->BitMap
, BMA_DEPTH
),
357 if (!data
->clockbm
) return 0;
359 data
->clockraster
= AllocRaster(data
->clockbmw
, data
->clockbmh
);
360 if (!data
->clockraster
)
362 FreeBitMap(data
->clockbm
);
367 InitRastPort(&data
->clockrp
);
368 data
->clockrp
.BitMap
= data
->clockbm
;
370 InitArea(&data
->clockai
, data
->areabuf
, sizeof(data
->areabuf
) / 5);
371 data
->clockrp
.AreaInfo
= &data
->clockai
;
373 InitTmpRas(&data
->clocktr
, data
->clockraster
, RASSIZE(data
->clockbmw
, data
->clockbmh
));
374 data
->clockrp
.TmpRas
= &data
->clocktr
;
380 _rp(obj
) = &data
->clockrp
;
382 DoMethod(obj
, MUIM_DrawBackground
, 0, 0, data
->clockbmw
, data
->clockbmh
, clock_posx
, clock_posy
, 0);
384 cx
= r
+ SHADOW_OFFX
;
385 cy
= r
+ SHADOW_OFFY
;
387 SetDrMd(_rp(obj
), JAM1
);
388 SetAPen(_rp(obj
), _pens(obj
)[MPEN_HALFSHADOW
]);
390 for(c
= 0; c
< 2; c
++)
392 for(angle
= 0.0, i
= 0; angle
< 2.0 * MY_PI
; angle
+= 2 * MY_PI
/ 60.0, i
++)
394 x
= cx
+ (WORD
)(cos(angle
) * r
);
395 y
= cy
- (WORD
)(sin(angle
) * r
);
399 x2
= cx
+ (WORD
)(cos(angle
) * (r
* 90 / 100));
400 y2
= cy
- (WORD
)(sin(angle
) * (r
* 90 / 100));
401 Move(_rp(obj
), x
, y
); Draw(_rp(obj
), x2
, y2
);
405 WritePixel(_rp(obj
), x
, y
);
411 SetAPen(_rp(obj
), _dri(obj
)->dri_Pens
[SHADOWPEN
]);
414 cx
+= SHADOW_OFFX
* 2;
415 cy
+= SHADOW_OFFY
* 2;
417 SetAPen(_rp(obj
), _pens(obj
)[MPEN_HALFSHADOW
]);
419 for(c
= 0; c
< 2; c
++)
423 h
= data
->clockdata
.hour
+ (data
->clockdata
.min
/ 60.0);
424 if (h
> 12.0) h
-= 12.0;
426 angle
= MY_PI
/ 2.0 + MY_PI
* 2.0 * (12.0 - h
) / 12.0;
430 if ((data
->edithand
== MUIV_Clock_EditHand_Hour
) && data
->frozen
)
432 SetAPen(_rp(obj
), (data
->editpen
== -1) ? _dri(obj
)->dri_Pens
[SHINEPEN
] : data
->editpen
);
436 SetAPen(_rp(obj
), _dri(obj
)->dri_Pens
[SHADOWPEN
]);
447 angle
= MY_PI
/ 2.0 + MY_PI
* 2.0 * ((double)60 - data
->clockdata
.min
) / 60.0;
451 if ((data
->edithand
== MUIV_Clock_EditHand_Minute
) && data
->frozen
)
453 SetAPen(_rp(obj
), (data
->editpen
== -1) ? _dri(obj
)->dri_Pens
[SHINEPEN
] : data
->editpen
);
457 SetAPen(_rp(obj
), _dri(obj
)->dri_Pens
[SHADOWPEN
]);
468 angle
= MY_PI
/ 2.0 + MY_PI
* 2.0 * ((double)60 - data
->clockdata
.sec
) / 60.0;
472 if ((data
->edithand
== MUIV_Clock_EditHand_Second
) && data
->frozen
)
474 SetAPen(_rp(obj
), (data
->editpen
== -1) ? _dri(obj
)->dri_Pens
[SHINEPEN
] : data
->editpen
);
478 SetAPen(_rp(obj
), _dri(obj
)->dri_Pens
[SHADOWPEN
]);
482 DrawThinHand(_rp(obj
), cx
, cy
, angle
, r
* 85 / 100);
491 BltBitMapRastPort(data
->clockbm
,
498 data
->clockbmh
, 192);
504 IPTR
Clock__MUIM_Clock_Timer(Class
*cl
, Object
*obj
, Msg msg
)
506 struct Clock_DATA
*data
;
510 data
= INST_DATA(cl
, obj
);
515 Amiga2Date(tv
.tv_secs
, &cd
);
517 set(obj
, MUIA_Clock_Time
, &cd
);
518 set(obj
, MUIA_Clock_Ticked
, TRUE
);