diff options
author | kamel5 <vdr.kamel5 (at) gmx (dot) net> | 2020-01-06 14:09:56 +0100 |
---|---|---|
committer | kamel5 <vdr.kamel5 (at) gmx (dot) net> | 2020-01-06 15:14:45 +0100 |
commit | c77f74321fcfc88a81513184797c03850f105840 (patch) | |
tree | 24edecf64ce3123777346fbaa05baee184044e2c /timeline.c | |
parent | efe06b8e9812c06c9e16ea4affd8f427b43ad70b (diff) | |
download | vdr-plugin-tvguide-c77f74321fcfc88a81513184797c03850f105840.tar.gz vdr-plugin-tvguide-c77f74321fcfc88a81513184797c03850f105840.tar.bz2 |
Refactor Timeline
Diffstat (limited to 'timeline.c')
-rw-r--r-- | timeline.c | 129 |
1 files changed, 62 insertions, 67 deletions
@@ -5,33 +5,28 @@ cTimeLine::cTimeLine(cTimeManager *timeManager) { this->timeManager = timeManager; lastClock = ""; timeBase = NULL; + int x11, x21, y11, y21, x12, x22, y12, y22; if (config.displayMode == eVertical) { - dateViewer = new cStyledPixmap(osdManager.requestPixmap(1, cRect(0, - geoManager.statusHeaderHeight + geoManager.clockHeight, - geoManager.dateVieverWidth, - geoManager.dateVieverHeight))); - timeline = osdManager.requestPixmap(2, cRect(0, - geoManager.statusHeaderHeight + geoManager.channelHeaderHeight + geoManager.channelGroupsHeight, - geoManager.timeLineWidth, - geoManager.osdHeight - geoManager.statusHeaderHeight - geoManager.channelHeaderHeight - geoManager.channelGroupsHeight - geoManager.footerHeight) - , cRect(0, - 0, - geoManager.timeLineWidth, - 1440 * geoManager.minutePixel)); + x11 = 0; + x21 = geoManager.dateVieverWidth; + y11 = geoManager.statusHeaderHeight + geoManager.clockHeight; + y21 = geoManager.dateVieverHeight; + x12 = 0; + x22 = geoManager.timeLineWidth; + y12 = geoManager.statusHeaderHeight + geoManager.channelHeaderHeight + geoManager.channelGroupsHeight; + y22 = geoManager.osdHeight - geoManager.statusHeaderHeight - geoManager.channelHeaderHeight - geoManager.channelGroupsHeight - geoManager.footerHeight; } else if (config.displayMode == eHorizontal) { - dateViewer = new cStyledPixmap(osdManager.requestPixmap(1, cRect(geoManager.clockWidth, - geoManager.statusHeaderHeight, - geoManager.dateVieverWidth, - geoManager.dateVieverHeight))); - timeline = osdManager.requestPixmap(2, cRect(geoManager.channelHeaderWidth + geoManager.channelGroupsWidth, - geoManager.statusHeaderHeight, - geoManager.osdWidth - geoManager.channelHeaderWidth - geoManager.channelGroupsWidth, - geoManager.timeLineHeight) - , cRect(0, - 0, - 1440 * geoManager.minutePixel, - geoManager.timeLineHeight)); + x11 = geoManager.clockWidth; + x21 = geoManager.dateVieverWidth; + y11 = geoManager.statusHeaderHeight; + y21 = geoManager.dateVieverHeight; + x12 = geoManager.channelHeaderWidth + geoManager.channelGroupsWidth; + x22 = geoManager.osdWidth - geoManager.channelHeaderWidth - geoManager.channelGroupsWidth; + y12 = geoManager.statusHeaderHeight; + y22 = geoManager.timeLineHeight; } + dateViewer = new cStyledPixmap(osdManager.requestPixmap(1, cRect(x11, y11, x21, y21))); + timeline = osdManager.requestPixmap(2, cRect(x12, y12, x22, y22)); clock = new cStyledPixmap(osdManager.requestPixmap(3, cRect(0, geoManager.statusHeaderHeight, geoManager.clockWidth, @@ -43,10 +38,11 @@ cTimeLine::~cTimeLine(void) { delete clock; osdManager.releasePixmap(timeBase); osdManager.releasePixmap(timeline); - delete dateViewer; + if (dateViewer) + delete dateViewer; } -void cTimeLine::drawDateViewer() { +void cTimeLine::DrawDateViewer(void) { cString weekDay = timeManager->GetWeekday(); cString date = timeManager->GetDate(); if (config.style != eStyleGraphical) { @@ -80,8 +76,8 @@ void cTimeLine::drawDateViewer() { } } -void cTimeLine::drawTimeline() { - timeline->SetTile(true); +void cTimeLine::DrawTimeline(void) { +// timeline->SetTile(true); timeline->Fill(clrTransparent); tColor colorFont, colorBackground; @@ -93,8 +89,8 @@ void cTimeLine::drawTimeline() { img1 = imgCache.GetOsdElement(oeTimeline1); img2 = imgCache.GetOsdElement(oeTimeline2); } else { - img1 = createBackgroundImage(imgWidth, imgHeight, theme.Color(clrTimeline1), theme.Color(clrTimeline1Blending)); - img2 = createBackgroundImage(imgWidth, imgHeight, theme.Color(clrTimeline2), theme.Color(clrTimeline2Blending)); + img1 = CreateBackgroundImage(imgWidth, imgHeight, theme.Color(clrTimeline1), theme.Color(clrTimeline1Blending)); + img2 = CreateBackgroundImage(imgWidth, imgHeight, theme.Color(clrTimeline2), theme.Color(clrTimeline2Blending)); } const cImage *img = NULL; if (!img1 || !img2) @@ -102,8 +98,19 @@ void cTimeLine::drawTimeline() { int textWidth, posX, posY; char timetext[10]; - for (int i=0; i<48; i++) { - if (i%2==0) { + int halfHours; + if (config.displayMode == eVertical) + halfHours = config.displayTime / 30 + 1; + else + halfHours = config.displayHorizontalTime / 30 + 1; + + time_t tStart = timeManager->GetStart(); + tm *t = localtime ( &tStart ); + + int x = 2 * t->tm_hour + ((t->tm_min == 0) ? 0 : 1); + for (int j = x; j < (x + halfHours); j++) { + int i = (j >= 48) ? (j - 48) : j; + if (i % 2 == 0) { img = img1; colorFont = theme.Color(clrTimeline2); colorBackground = (config.style == eStyleFlat)?theme.Color(clrTimeline1):clrTransparent; @@ -111,11 +118,11 @@ void cTimeLine::drawTimeline() { if (i == 0) sprintf(timetext, "12:00 PM"); else if (i/2 < 13) - sprintf(timetext, "%d:00 AM", i/2); + sprintf(timetext, "%d:00 AM", i / 2); else - sprintf(timetext, "%d:00 PM", i/2-12); + sprintf(timetext, "%d:00 PM", i / 2 - 12); } else { - sprintf(timetext, "%d:00", i/2); + sprintf(timetext, "%d:00", i / 2); } } else { img = img2; @@ -125,38 +132,38 @@ void cTimeLine::drawTimeline() { if (i == 1) sprintf(timetext, "12:30 PM"); else if (i/2 < 13) - sprintf(timetext, "%d:30 AM", i/2); + sprintf(timetext, "%d:30 AM", i / 2); else - sprintf(timetext, "%d:30 PM", i/2-12); + sprintf(timetext, "%d:30 PM", i / 2 - 12); } else { - sprintf(timetext, "%d:30", i/2); + sprintf(timetext, "%d:30", i / 2); } } if (config.displayMode == eVertical) { - posY = i*geoManager.minutePixel*30; + posY = (j - x) * geoManager.minutePixel * 30; timeline->DrawImage(cPoint(0, posY), *img); if (config.style != eStyleGraphical) { - decorateTile(0, posY, imgWidth+2, imgHeight); + DecorateTile(0, posY, imgWidth + 2, imgHeight); } textWidth = fontManager.FontTimeLineTime->Width(timetext); - timeline->DrawText(cPoint((geoManager.timeLineWidth-textWidth)/2, posY + 5), timetext, colorFont, colorBackground, fontManager.FontTimeLineTime); + timeline->DrawText(cPoint((geoManager.timeLineWidth-textWidth) / 2, posY + 5), timetext, colorFont, colorBackground, fontManager.FontTimeLineTime); } else if (config.displayMode == eHorizontal) { - posX = i*geoManager.minutePixel*30; + posX = (j - x) * geoManager.minutePixel * 30; timeline->DrawImage(cPoint(posX, 0), *img); if (config.style != eStyleGraphical) { - decorateTile(posX, 0, imgWidth, imgHeight+2); + DecorateTile(posX, 0, imgWidth, imgHeight + 2); } - timeline->DrawText(cPoint(posX + 15, (dateViewer->Height() - fontManager.FontTimeLineTimeHorizontal->Height())/2), timetext, colorFont, colorBackground, fontManager.FontTimeLineTimeHorizontal); + timeline->DrawText(cPoint(posX + 15, (dateViewer->Height() - fontManager.FontTimeLineTimeHorizontal->Height()) / 2), timetext, colorFont, colorBackground, fontManager.FontTimeLineTimeHorizontal); } } - setTimeline(); + DrawTimeIndicator(); if (config.style != eStyleGraphical) { delete img1; delete img2; } } -void cTimeLine::decorateTile(int posX, int posY, int tileWidth, int tileHeight) { +void cTimeLine::DecorateTile(int posX, int posY, int tileWidth, int tileHeight) { timeline->DrawRectangle(cRect(posX,posY,tileWidth,2), clrTransparent); //top timeline->DrawRectangle(cRect(posX,posY,2,tileHeight), clrTransparent); //left timeline->DrawRectangle(cRect(posX,posY + tileHeight-2,tileWidth,2), clrTransparent); //bottom @@ -169,11 +176,11 @@ void cTimeLine::decorateTile(int posX, int posY, int tileWidth, int tileHeight) if (config.roundedCorners) { int borderRadius = 12; - drawRoundedCorners(posX, posY, tileWidth, tileHeight, borderRadius); + DrawRoundedCorners(posX, posY, tileWidth, tileHeight, borderRadius); } } -void cTimeLine::drawRoundedCorners(int posX, int posY, int width, int height, int radius) { +void cTimeLine::DrawRoundedCorners(int posX, int posY, int width, int height, int radius) { timeline->DrawEllipse(cRect(posX+2,posY+2,radius,radius), theme.Color(clrBorder), -2); timeline->DrawEllipse(cRect(posX+1,posY+1,radius,radius), clrTransparent, -2); @@ -189,14 +196,16 @@ void cTimeLine::drawRoundedCorners(int posX, int posY, int width, int height, in } } -void cTimeLine::drawCurrentTimeBase(void) { +void cTimeLine::DrawTimeIndicator(void) { + if (!config.displayTimeBase) + return; if (!timeManager->NowVisible()) { if (timeBase) timeBase->Fill(clrTransparent); return; } + int deltaTime = (time(0) - timeManager->GetStart()) / 60 * geoManager.minutePixel; osdManager.releasePixmap(timeBase); - int deltaTime = (timeManager->GetNow() - timeManager->GetStart()) / 60 * geoManager.minutePixel; int x1, x2, y1, y2; if (config.displayMode == eVertical) { x1 = 0; @@ -214,7 +223,7 @@ void cTimeLine::drawCurrentTimeBase(void) { timeBase->DrawRectangle(cRect(0, 0, timeBase->ViewPort().Width(), timeBase->ViewPort().Height()), theme.Color(clrTimeBase)); } -cImage *cTimeLine::createBackgroundImage(int width, int height, tColor clrBgr, tColor clrBlend) { +cImage *cTimeLine::CreateBackgroundImage(int width, int height, tColor clrBgr, tColor clrBlend) { cImage *image = NULL; if (config.style == eStyleBlendingDefault) { image = new cImage(cSize(width, height)); @@ -243,22 +252,7 @@ cImage *cTimeLine::createBackgroundImage(int width, int height, tColor clrBgr, t return image; } -void cTimeLine::setTimeline() { - int offset = timeManager->GetTimelineOffset(); - int xNew, yNew; - if (config.displayMode == eVertical) { - xNew = 0; - yNew = -offset*geoManager.minutePixel; - } else if (config.displayMode == eHorizontal) { - xNew = -offset*geoManager.minutePixel; - yNew = 0; - } - timeline->SetDrawPortPoint(cPoint(xNew, yNew)); - if (config.displayTimeBase) - drawCurrentTimeBase(); -} - -bool cTimeLine::drawClock() { +bool cTimeLine::DrawClock(void) { cString currentTime = timeManager->GetCurrentTime(); if (strcmp(currentTime, lastClock)) { clock->Fill(clrTransparent); @@ -275,6 +269,7 @@ bool cTimeLine::drawClock() { } clock->DrawText(cPoint((geoManager.clockWidth - clockTextWidth) / 2, (geoManager.clockHeight - textHeight) / 2), *currentTime, theme.Color(clrFont), colorFontBack, font); lastClock = currentTime; + DrawTimeIndicator(); return true; } return false; |