vdr-plugin-tvguide/headergrid.c

135 lines
5.3 KiB
C
Raw Normal View History

2013-12-07 15:51:50 +01:00
#include "imageloader.h"
#include "tools.h"
#include "headergrid.h"
cHeaderGrid::cHeaderGrid(void) : cGrid(NULL) {
pixmap = NULL;
pixmapLogo = NULL;
}
cHeaderGrid::~cHeaderGrid(void) {
osdManager.releasePixmap(pixmapLogo);
}
void cHeaderGrid::createBackground(int num) {
color = theme.Color(clrHeader);
colorBlending = theme.Color(clrHeaderBlending);
2013-12-21 11:25:03 +01:00
int x, y;
2013-05-24 16:23:23 +02:00
if (tvguideConfig.displayMode == eVertical) {
2013-12-21 11:25:03 +01:00
x = geoManager.timeLineWidth + num*geoManager.colWidth;
y = geoManager.statusHeaderHeight + geoManager.channelGroupsHeight;
2013-05-24 16:23:23 +02:00
} else if (tvguideConfig.displayMode == eHorizontal) {
2013-12-21 11:25:03 +01:00
x = geoManager.channelGroupsWidth;
y = geoManager.statusHeaderHeight + geoManager.timeLineHeight + num*geoManager.rowHeight;
2013-05-24 16:23:23 +02:00
}
2013-12-21 11:25:03 +01:00
pixmap = osdManager.requestPixmap(1, cRect(x, y, geoManager.channelLogoWidth, geoManager.channelLogoHeight));
pixmapLogo = osdManager.requestPixmap(2, cRect(x, y, geoManager.channelLogoWidth, geoManager.channelLogoHeight));
2013-05-26 11:38:05 +02:00
if ((!pixmap) || (!pixmapLogo)){
return;
}
pixmapLogo->Fill(clrTransparent);
2013-12-21 11:25:03 +01:00
if (tvguideConfig.style == eStyleGraphical) {
drawBackgroundGraphical(bgChannelHeader);
} else {
drawBackground();
drawBorder();
}
}
void cHeaderGrid::drawChannel(const cChannel *channel) {
2013-05-24 16:23:23 +02:00
if (tvguideConfig.displayMode == eVertical) {
drawChannelVertical(channel);
} else if (tvguideConfig.displayMode == eHorizontal) {
drawChannelHorizontal(channel);
}
}
2018-07-25 19:10:28 +02:00
// Draw Channel horizontal view
2013-05-24 16:23:23 +02:00
void cHeaderGrid::drawChannelHorizontal(const cChannel *channel) {
2013-12-21 11:25:03 +01:00
int logoWidth = geoManager.logoWidth;
2013-05-24 16:23:23 +02:00
int logoX = tvguideConfig.displayChannelName?2:(Width()-logoWidth)/2;
int textX = 5;
2013-12-21 11:25:03 +01:00
int textY = (Height() - fontManager.FontChannelHeaderHorizontal->Height())/2;
2013-05-24 16:23:23 +02:00
bool logoFound = false;
if (!tvguideConfig.hideChannelLogos) {
2013-12-21 11:25:03 +01:00
cImage *logo = imgCache.GetLogo(channel);
if (logo) {
2018-07-25 19:10:28 +02:00
const int logoheight = logo->Height();
pixmapLogo->DrawImage(cPoint(logoX, (Height() - logoheight) / 2), *logo);
2013-05-24 16:23:23 +02:00
logoFound = true;
}
2013-05-26 11:38:05 +02:00
}
2013-05-24 16:23:23 +02:00
bool drawText = false;
int textWidthMax = Width() - 10;
if (!logoFound) {
drawText = true;
} else if (tvguideConfig.displayChannelName) {
drawText = true;
textX += logoWidth;
textWidthMax -= logoWidth;
}
if (drawText) {
2013-12-21 11:25:03 +01:00
tColor colorTextBack = (tvguideConfig.style == eStyleFlat)?color:clrTransparent;
2013-05-24 16:23:23 +02:00
cString strChannel = cString::sprintf("%d %s", channel->Number(), channel->Name());
2013-12-21 11:25:03 +01:00
strChannel = CutText(*strChannel, textWidthMax, fontManager.FontChannelHeaderHorizontal).c_str();
pixmap->DrawText(cPoint(textX, textY), *strChannel, theme.Color(clrFontHeader), colorTextBack, fontManager.FontChannelHeaderHorizontal);
2013-05-24 16:23:23 +02:00
}
}
2018-07-25 19:10:28 +02:00
// Draw Channel vertical view
2013-05-24 16:23:23 +02:00
void cHeaderGrid::drawChannelVertical(const cChannel *channel) {
2013-12-21 11:25:03 +01:00
int logoWidth = geoManager.logoWidth;
int logoHeight = geoManager.logoHeight;
cTextWrapper tw;
2013-05-26 11:38:05 +02:00
cString headerText = cString::sprintf("%d - %s", channel->Number(), channel->Name());
2013-12-21 11:25:03 +01:00
tw.Set(*headerText, fontManager.FontChannelHeader, geoManager.colWidth - 8);
2013-05-26 11:38:05 +02:00
int lines = tw.Lines();
2013-12-21 11:25:03 +01:00
int lineHeight = fontManager.FontChannelHeader->Height();
int yStart = (geoManager.channelHeaderHeight - lines*lineHeight)/2 + 8;
2013-05-26 11:38:05 +02:00
bool logoFound = false;
2013-05-24 16:23:23 +02:00
if (!tvguideConfig.hideChannelLogos) {
2013-12-21 11:25:03 +01:00
cImage *logo = imgCache.GetLogo(channel);
if (logo) {
2018-07-25 19:10:28 +02:00
const int logoheight = logo->Height();
pixmapLogo->DrawImage(cPoint((Width() - logoWidth) / 2, (geoManager.channelHeaderHeight - lineHeight - logoheight) / 2), *logo);
2013-05-24 16:23:23 +02:00
logoFound = true;
2013-05-26 11:38:05 +02:00
}
}
2013-05-24 16:23:23 +02:00
bool drawText = false;
if (!logoFound) {
drawText = true;
} else if (tvguideConfig.displayChannelName) {
drawText = true;
2013-05-26 11:38:05 +02:00
yStart = logoHeight;
2013-05-24 16:23:23 +02:00
}
if (!drawText)
return;
2013-12-21 11:25:03 +01:00
tColor colorTextBack = (tvguideConfig.style == eStyleFlat)?color:clrTransparent;
2013-05-26 11:38:05 +02:00
for (int i=0; i<lines; i++) {
2013-12-21 11:25:03 +01:00
int textWidth = fontManager.FontChannelHeader->Width(tw.GetLine(i));
int xText = (geoManager.colWidth - textWidth) / 2;
2013-05-26 11:38:05 +02:00
if (xText < 0)
xText = 0;
2013-12-21 11:25:03 +01:00
pixmap->DrawText(cPoint(xText, yStart + i*lineHeight), tw.GetLine(i), theme.Color(clrFontHeader), colorTextBack, fontManager.FontChannelHeader);
2013-05-26 11:38:05 +02:00
}
}
void cHeaderGrid::setPosition(int num) {
2013-05-24 16:23:23 +02:00
int x, y, width, height;
if (tvguideConfig.displayMode == eVertical) {
2013-12-21 11:25:03 +01:00
x = geoManager.timeLineWidth + num*geoManager.colWidth;
y = geoManager.statusHeaderHeight + geoManager.channelGroupsHeight;
width = geoManager.colWidth;
height = geoManager.channelHeaderHeight;
2013-05-24 16:23:23 +02:00
} else if (tvguideConfig.displayMode == eHorizontal) {
2013-12-21 11:25:03 +01:00
x = geoManager.channelGroupsWidth;
y = geoManager.statusHeaderHeight + geoManager.timeLineHeight + num*geoManager.rowHeight;
width = geoManager.channelHeaderWidth;
height = geoManager.rowHeight;
2013-05-24 16:23:23 +02:00
}
pixmap->SetViewPort(cRect(x, y, width, height));
2013-05-26 11:38:05 +02:00
pixmapLogo->SetViewPort(cRect(x, y, width, height));
}