1 /* 2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Mike Berg <mike@berg-net.us> 7 * Julun <host.haiku@gmx.de> 8 * Hamish Morrison <hamish@lavabit.com> 9 */ 10 #ifndef _ANALOG_CLOCK_H 11 #define _ANALOG_CLOCK_H 12 13 14 #include <View.h> 15 16 17 class TAnalogClock : public BView { 18 public: 19 TAnalogClock(const char* name, 20 bool drawSecondHand = true, 21 bool interactive = true); 22 virtual ~TAnalogClock(); 23 24 virtual void Draw(BRect updateRect); 25 virtual void MessageReceived(BMessage* message); 26 virtual void MouseDown(BPoint point); 27 virtual void MouseUp(BPoint point); 28 virtual void MouseMoved(BPoint point, uint32 transit, 29 const BMessage* message); 30 virtual void DoLayout(); 31 32 virtual BSize MaxSize(); 33 virtual BSize MinSize(); 34 virtual BSize PreferredSize(); 35 36 void SetTime(int32 hour, int32 minute, int32 second); 37 bool IsChangingTime(); 38 void ChangeTimeFinished(); 39 40 void GetTime(int32* hour, int32* minute, int32* second); 41 void DrawClock(); 42 43 bool InHourHand(BPoint point); 44 bool InMinuteHand(BPoint point); 45 46 void SetHourHand(BPoint point); 47 void SetMinuteHand(BPoint point); 48 49 void SetHourDragging(bool dragging); 50 void SetMinuteDragging(bool dragging); 51 private: 52 float _GetPhi(BPoint point); 53 bool _InHand(BPoint point, int32 ticks, float radius); 54 void _DrawHands(float x, float y, float radius, 55 rgb_color hourHourColor, 56 rgb_color hourMinuteColor, 57 rgb_color secondsColor, rgb_color knobColor); 58 59 int32 fHours; 60 int32 fMinutes; 61 int32 fSeconds; 62 bool fDirty; 63 64 float fCenterX; 65 float fCenterY; 66 float fRadius; 67 68 bool fHourDragging; 69 bool fMinuteDragging; 70 bool fDrawSecondHand; 71 bool fInteractive; 72 73 bool fTimeChangeIsOngoing; 74 }; 75 76 77 #endif // _ANALOG_CLOCK_H 78