vdr-plugin-tvguide/epggrid.c

190 lines
7.7 KiB
C
Raw Permalink Normal View History

2013-12-07 15:51:50 +01:00
#include "services/remotetimers.h"
2013-01-17 13:16:44 +01:00
#include "channelcolumn.h"
2013-12-07 15:51:50 +01:00
#include "tools.h"
2013-01-17 13:16:44 +01:00
#include "epggrid.h"
cEpgGrid::cEpgGrid(cChannelColumn *c, const cEvent *event) : cGrid(c) {
2013-05-26 11:38:05 +02:00
this->event = event;
extText = new cTextWrapper();
hasTimer = false;
2013-07-20 13:46:26 +02:00
SetTimer();
2013-07-09 00:17:42 +02:00
hasSwitchTimer = false;
2013-07-20 13:46:26 +02:00
SetSwitchTimer();
dummy = false;
2013-01-17 13:16:44 +01:00
}
cEpgGrid::~cEpgGrid(void) {
2013-05-26 11:38:05 +02:00
delete extText;
2013-01-17 13:16:44 +01:00
}
void cEpgGrid::SetViewportHeight() {
2013-05-26 11:38:05 +02:00
int viewportHeightOld = viewportHeight;
if ( column->Start() > StartTime() ) {
viewportHeight = (min((int)EndTime(), column->Stop()) - column->Start()) /60;
} else if ( column->Stop() < EndTime() ) {
viewportHeight = (column->Stop() - StartTime()) /60;
if (viewportHeight < 0) viewportHeight = 0;
2013-05-26 11:38:05 +02:00
} else {
viewportHeight = Duration() / 60;
}
2013-12-21 11:25:03 +01:00
viewportHeight *= geoManager.minutePixel;
2013-05-26 11:38:05 +02:00
if (viewportHeight != viewportHeightOld)
dirty = true;
2013-01-17 13:16:44 +01:00
}
void cEpgGrid::PositionPixmap() {
2013-05-24 16:23:23 +02:00
if (tvguideConfig.displayMode == eVertical) {
int x0 = column->getX();
2013-12-21 11:25:03 +01:00
int y0 = geoManager.statusHeaderHeight + geoManager.channelHeaderHeight + geoManager.channelGroupsHeight;
2013-05-24 16:23:23 +02:00
if ( column->Start() < StartTime() ) {
2013-12-21 11:25:03 +01:00
y0 += (StartTime() - column->Start())/60*geoManager.minutePixel;
2013-05-24 16:23:23 +02:00
}
if (!pixmap) {
2018-04-01 12:09:13 +02:00
pixmap = osdManager.requestPixmap(-1, cRect(x0, y0, geoManager.colWidth, viewportHeight),
2013-12-21 11:25:03 +01:00
cRect(0, 0, geoManager.colWidth, Duration()/60*geoManager.minutePixel));
2013-05-24 16:23:23 +02:00
} else {
2013-12-21 11:25:03 +01:00
pixmap->SetViewPort(cRect(x0, y0, geoManager.colWidth, viewportHeight));
2013-05-24 16:23:23 +02:00
}
} else if (tvguideConfig.displayMode == eHorizontal) {
2013-12-21 11:25:03 +01:00
int x0 = geoManager.channelHeaderWidth + geoManager.channelGroupsWidth;
2013-05-24 16:23:23 +02:00
int y0 = column->getY();
if ( column->Start() < StartTime() ) {
2013-12-21 11:25:03 +01:00
x0 += (StartTime() - column->Start())/60*geoManager.minutePixel;
2013-05-24 16:23:23 +02:00
}
if (!pixmap) {
2018-04-01 12:09:13 +02:00
pixmap = osdManager.requestPixmap(-1, cRect(x0, y0, viewportHeight, geoManager.rowHeight),
2013-12-21 11:25:03 +01:00
cRect(0, 0, Duration()/60*geoManager.minutePixel, geoManager.rowHeight));
2013-05-24 16:23:23 +02:00
} else {
2013-12-21 11:25:03 +01:00
pixmap->SetViewPort(cRect(x0, y0, viewportHeight, geoManager.rowHeight ));
2013-05-24 16:23:23 +02:00
}
}
2013-01-17 13:16:44 +01:00
}
2013-07-20 13:46:26 +02:00
void cEpgGrid::SetTimer() {
if (tvguideConfig.useRemoteTimers && pRemoteTimers) {
RemoteTimers_Event_v1_0 rt;
rt.event = event;
if (pRemoteTimers->Service("RemoteTimers::GetTimerByEvent-v1.0", &rt))
hasTimer = true;
2013-07-20 15:53:33 +02:00
else
hasTimer = false;
2019-01-27 11:50:59 +01:00
#if VDRVERSNUM >= 30400
2018-03-08 14:16:33 +01:00
} else if (event->HasTimer()) {
hasTimer = true;
#else
2013-07-20 13:46:26 +02:00
} else if (column->HasTimer()) {
hasTimer = event->HasTimer();
2018-03-08 14:16:33 +01:00
#endif
2013-07-20 13:46:26 +02:00
} else {
hasTimer = false;
}
}
void cEpgGrid::SetSwitchTimer() {
if (column->HasSwitchTimer()) {
hasSwitchTimer = SwitchTimers.EventInSwitchList(event);
} else {
hasSwitchTimer = false;
}
}
2013-01-17 13:16:44 +01:00
void cEpgGrid::setText() {
2013-05-24 16:23:23 +02:00
if (tvguideConfig.displayMode == eVertical) {
cString strText;
strText = cString::sprintf("%s - %s:\n%s", *(event->GetTimeString()), *(event->GetEndTimeString()), event->Title());
2013-12-21 11:25:03 +01:00
text->Set(*(strText), fontManager.FontGrid, geoManager.colWidth-2*borderWidth);
extText->Set(event->ShortText(), fontManager.FontGridSmall, geoManager.colWidth-2*borderWidth);
2013-05-24 16:23:23 +02:00
} else if (tvguideConfig.displayMode == eHorizontal) {
timeString = cString::sprintf("%s - %s", *(event->GetTimeString()), *(event->GetEndTimeString()));
}
2013-01-17 13:16:44 +01:00
}
void cEpgGrid::drawText() {
2013-05-28 17:06:53 +02:00
tColor colorText = (active)?theme.Color(clrFontActive):theme.Color(clrFont);
tColor colorTextBack;
if (tvguideConfig.style == eStyleFlat)
colorTextBack = color;
else if (tvguideConfig.style == eStyleGraphical)
colorTextBack = (active)?theme.Color(clrGridActiveFontBack):theme.Color(clrGridFontBack);
else
colorTextBack = clrTransparent;
2013-05-24 16:23:23 +02:00
if (tvguideConfig.displayMode == eVertical) {
2013-12-21 11:25:03 +01:00
if (Height()/geoManager.minutePixel < 6)
2013-05-24 16:23:23 +02:00
return;
2013-12-21 11:25:03 +01:00
int textHeight = fontManager.FontGrid->Height();
2013-05-24 16:23:23 +02:00
int textLines = text->Lines();
for (int i=0; i<textLines; i++) {
2013-12-21 11:25:03 +01:00
pixmap->DrawText(cPoint(borderWidth, borderWidth + i*textHeight), text->GetLine(i), colorText, colorTextBack, fontManager.FontGrid);
2013-05-24 16:23:23 +02:00
}
int extTextLines = extText->Lines();
int offset = (textLines+1)*textHeight - 0.5*textHeight;
2013-12-21 11:25:03 +01:00
textHeight = fontManager.FontGridSmall->Height();
2013-05-24 16:23:23 +02:00
if ((Height()-textHeight-10) > offset) {
for (int i=0; i<extTextLines; i++) {
2013-12-21 11:25:03 +01:00
pixmap->DrawText(cPoint(borderWidth, borderWidth + offset + i*textHeight), extText->GetLine(i), colorText, colorTextBack, fontManager.FontGridSmall);
2013-05-24 16:23:23 +02:00
}
}
} else if (tvguideConfig.displayMode == eHorizontal) {
2013-12-21 11:25:03 +01:00
if (Width()/geoManager.minutePixel < 10) {
int titleY = (geoManager.rowHeight - fontManager.FontGridHorizontal->Height())/2;
pixmap->DrawText(cPoint(borderWidth - 2, titleY), "...", colorText, colorTextBack, fontManager.FontGridHorizontal);
2013-05-24 16:23:23 +02:00
return;
}
2013-12-21 11:25:03 +01:00
cString strTitle = CutText(event->Title(), viewportHeight, fontManager.FontGridHorizontal).c_str();
int titleY = 0;
if (tvguideConfig.showTimeInGrid) {
2013-12-21 11:25:03 +01:00
pixmap->DrawText(cPoint(borderWidth, borderWidth), *timeString, colorText, colorTextBack, fontManager.FontGridHorizontalSmall);
titleY = fontManager.FontGridHorizontalSmall->Height() + (geoManager.rowHeight - fontManager.FontGridHorizontalSmall->Height() - fontManager.FontGridHorizontal->Height())/2;
} else {
2013-12-21 11:25:03 +01:00
titleY = (geoManager.rowHeight - fontManager.FontGridHorizontal->Height())/2;
}
2013-12-21 11:25:03 +01:00
pixmap->DrawText(cPoint(borderWidth, titleY), *strTitle, colorText, colorTextBack, fontManager.FontGridHorizontal);
2013-05-24 16:23:23 +02:00
}
2018-04-01 12:09:13 +02:00
if (hasSwitchTimer)
2013-07-09 00:17:42 +02:00
drawIcon("Switch", theme.Color(clrButtonYellow));
2018-03-08 14:16:33 +01:00
if (hasTimer) {
const cTimer *timer = NULL;
{
2018-03-08 14:16:33 +01:00
LOCK_TIMERS_READ;
timer = Timers->GetMatch(event);
}
if (timer)
2018-03-31 14:29:41 +02:00
#ifdef USE_SWITCHONLY
if (timer->HasFlags(tfSwitchOnly))
drawIcon("Switch", theme.Color(clrButtonYellow));
else if (timer->HasFlags(tfActive))
2018-04-01 12:09:13 +02:00
#else /* SWITCHONLY */
if (timer->HasFlags(tfActive))
#endif /* SWITCHONLY */
2018-03-08 14:16:33 +01:00
drawIcon("REC", theme.Color(clrButtonRed));
else
drawIcon("REC", theme.Color(clrButtonGreen));
}
2013-01-17 13:16:44 +01:00
}
2013-07-09 00:17:42 +02:00
void cEpgGrid::drawIcon(cString iconText, tColor color) {
2018-04-01 12:09:13 +02:00
2013-07-09 00:17:42 +02:00
const cFont *font = (tvguideConfig.displayMode == eVertical)
2013-12-21 11:25:03 +01:00
?fontManager.FontGrid
:fontManager.FontGridHorizontalSmall;
2013-07-09 00:17:42 +02:00
int textWidth = font->Width(*iconText)+2*borderWidth;
int textHeight = font->Height()+10;
pixmap->DrawRectangle( cRect(Width() - textWidth - borderWidth, Height() - textHeight - borderWidth, textWidth, textHeight), color);
2018-04-01 12:09:13 +02:00
pixmap->DrawText(cPoint(Width() - textWidth, Height() - textHeight - borderWidth/2), *iconText, theme.Color(clrFont), color, font);
2013-01-17 13:16:44 +01:00
}
cString cEpgGrid::getTimeString(void) {
return cString::sprintf("%s - %s", *(event->GetTimeString()), *(event->GetEndTimeString()));
2013-01-17 13:16:44 +01:00
}
void cEpgGrid::debug() {
2018-04-01 12:09:13 +02:00
esyslog("tvguide epggrid: %s: %s, %s, viewportHeight: %d px, Duration: %d min, active: %d",
column->Name(),
2018-04-01 12:09:13 +02:00
*(event->GetTimeString()),
event->Title(),
viewportHeight,
event->Duration()/60,
active);
2013-07-20 15:53:33 +02:00
}