diff options
author | louis <louis.braun@gmx.de> | 2015-03-12 17:22:16 +0100 |
---|---|---|
committer | louis <louis.braun@gmx.de> | 2015-03-12 17:22:16 +0100 |
commit | 3cc8e78e1bf00e16b49520ac416b74b5fd73c906 (patch) | |
tree | 4425c4eb4b9833d927aae2f65d0f3a99d3792f83 /timeline.c | |
download | vdr-plugin-tvguideng-3cc8e78e1bf00e16b49520ac416b74b5fd73c906.tar.gz vdr-plugin-tvguideng-3cc8e78e1bf00e16b49520ac416b74b5fd73c906.tar.bz2 |
Version 0.0.10.0.1
Diffstat (limited to 'timeline.c')
-rw-r--r-- | timeline.c | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/timeline.c b/timeline.c new file mode 100644 index 0000000..143a6a6 --- /dev/null +++ b/timeline.c @@ -0,0 +1,153 @@ +#include "timeline.h" + +// --- cTimelineElement ------------------------------------------------------------- + +cTimelineElement::cTimelineElement(time_t elementTime) { + 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(cViewGrid *timelineGrid, cViewElement *timelineDate, 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) { + time_t startTime = timeManager->GetStart(); + time_t endTime = timeManager->GetEnd(); + 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("fullhour", e->IsFullHour()); + timelineGrid->AddStringToken("timestring", e->ToString()); + 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(); + string date = *(timeManager->GetDate()); + timelineDate->AddStringToken("weekday", weekday); + timelineDate->AddStringToken("date", date); + 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("percenttotal", percentTotal); + timeIndicator->Display(); + } else if (timeIndicatorShown) { + timeIndicatorShown = false; + timeIndicator->Clear(); + } +} |