1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
#include "timeline.h"
long cTimelineElement::idCounter;
// --- cTimelineElement -------------------------------------------------------------
cTimelineElement::cTimelineElement(time_t elementTime) {
id = idCounter;
idCounter++;
init = true;
this->elementTime = elementTime;
}
cTimelineElement::~cTimelineElement() {
}
bool cTimelineElement::IsNew(void) {
if (init) {
init = false;
return true;
}
return init;
}
bool cTimelineElement::IsFullHour(void) {
if (elementTime%3600 == 0)
return true;
return false;
}
// --- cTimeline -------------------------------------------------------------
cTimeline::cTimeline(skindesignerapi::cViewGrid *timelineGrid, skindesignerapi::cViewElement *timelineDate, skindesignerapi::cViewElement *timeIndicator, cTimeManager *timeManager) {
this->timelineGrid = timelineGrid;
this->timelineDate = timelineDate;
this->timeIndicator = timeIndicator;
this->timeManager = timeManager;
steps = config.displayHours * 2;
stepDuration = 30 * 60;
weekday = "";
timeIndicatorShown = true;
}
cTimeline::~cTimeline(void) {
Clear();
delete timelineDate;
delete timeIndicator;
delete timelineGrid;
}
void cTimeline::Init(void) {
time_t startTime = timeManager->GetStart();
time_t elementTime = startTime;
for (int i=0; i < steps; i++) {
cTimelineElement *e = new cTimelineElement(elementTime);
grids.Add(e);
elementTime += stepDuration;
}
}
void cTimeline::Clear(void) {
timelineGrid->Clear();
grids.Clear();
}
void cTimeline::ScrollForward(int stepMinutes) {
int numSteps = stepMinutes / 30;
for (int i=0; i<numSteps; i++) {
cTimelineElement *e = grids.First();
timelineGrid->Delete(e->Id());
grids.Del(e);
}
time_t newStartTime = timeManager->GetEnd() - stepMinutes * 60;
for (int i=0; i<numSteps; i++) {
cTimelineElement *e = new cTimelineElement(newStartTime);
grids.Add(e);
newStartTime += stepDuration;
}
}
void cTimeline::ScrollBack(int stepMinutes) {
int numSteps = stepMinutes / 30;
for (int i=0; i<numSteps; i++) {
cTimelineElement *e = grids.Last();
timelineGrid->Delete(e->Id());
grids.Del(e);
}
time_t newStartTime = timeManager->GetStart() + (numSteps-1) * 30 * 60;
for (int i=0; i<numSteps; i++) {
cTimelineElement *e = new cTimelineElement(newStartTime);
grids.Ins(e);
newStartTime -= stepDuration;
}
}
void cTimeline::Draw(void) {
DrawDate();
DrawTimeIndicator();
double x, y, width, height;
if (config.displayMode == eHorizontal) {
x = 0.0;
y = 0.0;
width = (double)1 / (double)steps;
height = 1.0;
} else {
x = 0.0;
y = 0.0;
width = 1.0;
height = (double)1 / (double)steps;
}
for (cTimelineElement *e = grids.First(); e; e = grids.Next(e)) {
if (e->IsNew()) {
timelineGrid->ClearTokens();
timelineGrid->AddIntToken((int)eTimelineGridIT::fullhour, e->IsFullHour());
timelineGrid->AddStringToken((int)eTimelineGridST::timestring, e->ToString().c_str());
timelineGrid->SetGrid(e->Id(), x, y, width, height);
} else {
timelineGrid->MoveGrid(e->Id(), x, y, width, height);
}
if (config.displayMode == eHorizontal)
x += width;
else
y += height;
}
timelineGrid->Display();
}
void cTimeline::DrawDate(void) {
string weekdayNew = *(timeManager->GetWeekday());
if (!weekdayNew.compare(weekday))
return;
weekday = weekdayNew;
timelineDate->Clear();
timelineDate->ClearTokens();
timelineDate->AddStringToken((int)eDateTimeST::weekday, weekday.c_str());
timelineDate->AddStringToken((int)eDateTimeST::date, *(timeManager->GetDate()));
timelineDate->Display();
}
void cTimeline::DrawTimeIndicator(void) {
if (timeManager->NowVisible()) {
timeIndicatorShown = true;
int distance = (timeManager->GetNow() - timeManager->GetStart()) / 60;
int percentTotal = distance*1000/(config.displayHours*60);
timeIndicator->Clear();
timeIndicator->ClearTokens();
timeIndicator->AddIntToken((int)eTimeIndicatorIT::percenttotal, percentTotal);
timeIndicator->Display();
} else if (timeIndicatorShown) {
timeIndicatorShown = false;
timeIndicator->Clear();
}
}
|