vdr-plugin-tvguide/headergrid.c

137 lines
5.1 KiB
C
Raw Normal View History

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