vdr-plugin-tvguide/osdmanager.c

86 lines
2.8 KiB
C
Raw Normal View History

#include <string>
#include <sstream>
2013-01-17 13:16:44 +01:00
#ifndef __TVGUIDE_OSDMANAGER_H
#define __TVGUIDE_OSDMANAGER_H
class cOsdManager {
2013-05-26 11:38:05 +02:00
private:
cOsd *osd;
public:
cOsdManager(void);
bool setOsd();
void setBackground();
void flush() {osd->Flush();};
cPixmap *requestPixmap(int Layer, const cRect &ViewPort, const cRect &DrawPort = cRect::Null);
void releasePixmap(cPixmap *pixmap);
void deleteOsd() {delete osd;};
int Width() { return osd->Width(); };
int Height() { return osd->Height(); };
2013-05-26 11:58:11 +02:00
int Top() { return osd->Top(); };
int Left() { return osd->Left(); };
2013-01-17 13:16:44 +01:00
};
#endif //__TVGUIDE_OSDMANAGER_H
cOsdManager::cOsdManager(void) {
}
bool cOsdManager::setOsd() {
2013-05-26 11:38:05 +02:00
osd = cOsdProvider::NewOsd(cOsd::OsdLeft(), cOsd::OsdTop());
if (osd) {
tArea Area = { 0, 0, cOsd::OsdWidth(), cOsd::OsdHeight(), 32 };
if (osd->SetAreas(&Area, 1) == oeOk) {
return true;
}
}
return false;
2013-01-17 13:16:44 +01:00
}
void cOsdManager::setBackground() {
if (tvguideConfig.displayStatusHeader && tvguideConfig.scaleVideo) {
2013-05-24 16:23:23 +02:00
int widthStatus = cOsd::OsdWidth() - tvguideConfig.statusHeaderHeight * 16 / 9;
osd->DrawRectangle(0, 0, widthStatus, tvguideConfig.statusHeaderHeight, theme.Color(clrBackgroundOSD));
2013-05-26 16:54:22 +02:00
osd->DrawRectangle(0, tvguideConfig.statusHeaderHeight, Width(), Height(), theme.Color(clrBackgroundOSD));
}
else
2013-05-26 16:54:22 +02:00
osd->DrawRectangle(0, 0, Width(), Height(), theme.Color(clrBackgroundOSD));
2013-01-17 13:16:44 +01:00
}
cPixmap *cOsdManager::requestPixmap(int Layer, const cRect &ViewPort, const cRect &DrawPort) {
2013-05-26 11:38:05 +02:00
return osd->CreatePixmap(Layer, ViewPort, DrawPort);
}
2013-01-17 13:16:44 +01:00
void cOsdManager::releasePixmap(cPixmap *pixmap) {
if (!pixmap)
return;
2013-05-26 11:38:05 +02:00
osd->DestroyPixmap(pixmap);
}
static std::string CutText(std::string text, int width, const cFont *font) {
if (width <= font->Size())
return text.c_str();
if (font->Width(text.c_str()) < width)
return text.c_str();
cTextWrapper twText;
twText.Set(text.c_str(), font, width);
std::string cuttedTextNative = twText.GetLine(0);
std::stringstream sstrText;
sstrText << cuttedTextNative << "...";
std::string cuttedText = sstrText.str();
int actWidth = font->Width(cuttedText.c_str());
if (actWidth > width) {
int overlap = actWidth - width;
int charWidth = font->Width(".");
if (charWidth == 0)
charWidth = 1;
int cutChars = overlap / charWidth;
if (cutChars > 0) {
cuttedTextNative = cuttedTextNative.substr(0, cuttedTextNative.length() - cutChars);
std::stringstream sstrText2;
sstrText2 << cuttedTextNative << "...";
cuttedText = sstrText2.str();
}
}
return cuttedText;
2013-01-17 13:16:44 +01:00
}