2 * Copyright 2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 #ifndef ACTIVITY_VIEW_H
6 #define ACTIVITY_VIEW_H
13 #include <ObjectList.h>
16 #include "CircularBuffer.h"
17 #include "DataSource.h"
23 class SystemInfoHandler
;
29 DataHistory(bigtime_t memorize
, bigtime_t interval
);
32 void AddValue(bigtime_t time
, int64 value
);
34 int64
ValueAt(bigtime_t time
);
35 int64
MaximumValue() const;
36 int64
MinimumValue() const;
37 bigtime_t
Start() const;
38 bigtime_t
End() const;
40 void SetRefreshInterval(bigtime_t interval
);
41 void SetScale(Scale
* scale
);
44 CircularBuffer
<data_item
> fBuffer
;
47 bigtime_t fRefreshInterval
;
53 class ActivityView
: public BView
{
55 ActivityView(BRect frame
, const char* name
,
56 const BMessage
* settings
, uint32 resizingMode
);
57 ActivityView(const char* name
,
58 const BMessage
* settings
);
59 ActivityView(BMessage
* archive
);
60 virtual ~ActivityView();
62 virtual status_t
Archive(BMessage
* into
, bool deep
= true) const;
63 static BArchivable
* Instantiate(BMessage
* archive
);
65 status_t
SaveState(BMessage
& state
) const;
68 BLayoutItem
* CreateHistoryLayoutItem();
69 BLayoutItem
* CreateLegendLayoutItem();
72 DataSource
* FindDataSource(const DataSource
* source
);
73 status_t
AddDataSource(const DataSource
* source
,
74 const BMessage
* state
= NULL
);
75 status_t
RemoveDataSource(const DataSource
* source
);
76 void RemoveAllDataSources();
78 bigtime_t
RefreshInterval() const
79 { return atomic_get64((int64
*)&fRefreshInterval
); }
82 virtual void AttachedToWindow();
83 virtual void DetachedFromWindow();
86 virtual BSize
MinSize();
89 virtual void FrameResized(float width
, float height
);
90 virtual void MouseDown(BPoint where
);
91 virtual void MouseUp(BPoint where
);
92 virtual void MouseMoved(BPoint where
, uint32 transit
,
93 const BMessage
* dragMessage
);
95 virtual void MessageReceived(BMessage
* message
);
97 virtual void Draw(BRect updateRect
);
100 void _Init(const BMessage
* settings
);
101 ::Scale
* _ScaleFor(scale_type type
);
103 static status_t
_RefreshThread(void* self
);
104 void _UpdateOffscreenBitmap();
105 BView
* _OffscreenView();
107 BRect
_HistoryFrame() const;
108 float _LegendHeight() const;
109 BRect
_LegendFrame() const;
110 BRect
_LegendFrameAt(BRect frame
, int32 index
) const;
111 BRect
_LegendColorFrameAt(BRect frame
, int32 index
) const;
112 float _PositionForValue(DataSource
* source
,
113 DataHistory
* values
, int64 value
);
114 void _DrawHistory(bool drawBackground
);
115 void _UpdateResolution(int32 resolution
,
116 bool broadcast
= true);
119 class HistoryLayoutItem
;
120 class LegendLayoutItem
;
122 friend class HistoryLayoutItem
;
123 friend class LegendLayoutItem
;
125 rgb_color fHistoryBackgroundColor
;
126 rgb_color fLegendBackgroundColor
;
129 BLayoutItem
* fHistoryLayoutItem
;
130 BLayoutItem
* fLegendLayoutItem
;
133 mutable BLocker fSourcesLock
;
134 BObjectList
<DataSource
> fSources
;
135 BObjectList
<DataHistory
> fValues
;
136 BObjectList
<ViewHistory
> fViewValues
;
137 thread_id fRefreshThread
;
139 bigtime_t fRefreshInterval
;
140 bigtime_t fLastRefresh
;
141 int32 fDrawResolution
;
145 int32 fOriginalResolution
;
146 SystemInfoHandler
* fSystemInfoHandler
;
147 std::map
<scale_type
, ::Scale
*> fScales
;
150 #endif // ACTIVITY_VIEW_H