vdr-plugin-tvguide/styledpixmap.c

143 lines
5.1 KiB
C
Raw Normal View History

2013-12-07 15:51:50 +01:00
#include "imageloader.h"
2013-01-17 13:16:44 +01:00
#include "styledpixmap.h"
cStyledPixmap::cStyledPixmap(void) {
2013-05-26 11:38:05 +02:00
pixmap = NULL;
2013-01-17 13:16:44 +01:00
}
cStyledPixmap::cStyledPixmap(cPixmap *pixmap) {
2013-05-26 11:38:05 +02:00
this->pixmap = pixmap;
2013-01-17 13:16:44 +01:00
}
cStyledPixmap::~cStyledPixmap(void) {
2013-05-26 11:38:05 +02:00
if (pixmap)
osdManager.releasePixmap(pixmap);
2013-01-17 13:16:44 +01:00
}
void cStyledPixmap::setPixmap(cPixmap *pixmap) {
2013-05-26 11:38:05 +02:00
if (pixmap) {
this->pixmap = pixmap;
}
2013-01-17 13:16:44 +01:00
}
void cStyledPixmap::drawBackground() {
if (tvguideConfig.useBlending == 1){
2013-05-26 11:38:05 +02:00
drawBlendedBackground();
} else if (tvguideConfig.useBlending == 2){
drawSparsedBackground();
} else {
pixmap->Fill(color);
}
2013-01-17 13:16:44 +01:00
}
void cStyledPixmap::drawBlendedBackground() {
2013-05-26 11:38:05 +02:00
int width = pixmap->ViewPort().Width();
int height = pixmap->ViewPort().Height();
pixmap->Fill(color);
int numSteps = 64;
int alphaStep = 0x04;
if (height < 30)
return;
else if (height < 100) {
numSteps = 32;
alphaStep = 0x08;
}
int stepY = 0.5*height / numSteps;
if (stepY == 0) stepY = 1;
int alpha = 0x00;
tColor clr;
for (int i = 0; i<numSteps; i++) {
clr = AlphaBlend(color, colorBlending, alpha);
pixmap->DrawRectangle(cRect(0,i*stepY,width,stepY), clr);
alpha += alphaStep;
}
2013-01-17 13:16:44 +01:00
}
void cStyledPixmap::drawSparsedBackground() {
2013-05-26 11:38:05 +02:00
int width = pixmap->ViewPort().Width();
int height = pixmap->ViewPort().Height();
cImageLoader imgLoader;
if (imgLoader.DrawBackground(colorBlending, color, width, height))
pixmap->DrawImage(cPoint(0,0), imgLoader.GetImage());
}
2013-01-17 13:16:44 +01:00
void cStyledPixmap::drawBorder() {
2013-05-26 11:38:05 +02:00
int width = pixmap->ViewPort().Width();
int height = pixmap->ViewPort().Height();
drawDefaultBorder(width, height);
if (tvguideConfig.roundedCorners) {
int borderRadius = 12;
drawRoundedCorners(width, height, borderRadius);
}
2013-01-17 13:16:44 +01:00
}
void cStyledPixmap::drawDefaultBorder(int width, int height) {
2013-05-26 11:38:05 +02:00
pixmap->DrawRectangle(cRect(0,0,width,2), theme.Color(clrBackground)); //top
pixmap->DrawRectangle(cRect(0,0,2,height), theme.Color(clrBackground)); //left
pixmap->DrawRectangle(cRect(0,height-2,width,2), theme.Color(clrBackground)); //bottom
pixmap->DrawRectangle(cRect(width-2,0,2,height), theme.Color(clrBackground)); //right
pixmap->DrawRectangle(cRect(2,2,width-4,1), theme.Color(clrBorder)); //top
pixmap->DrawRectangle(cRect(2,2,1,height-4), theme.Color(clrBorder)); //left
pixmap->DrawRectangle(cRect(2,height-3,width-4,1), theme.Color(clrBorder)); //bottom
pixmap->DrawRectangle(cRect(width-3,2,1,height-4), theme.Color(clrBorder)); //right
2013-01-17 13:16:44 +01:00
}
void cStyledPixmap::drawBoldBorder() {
2013-05-26 11:38:05 +02:00
int width = pixmap->ViewPort().Width();
int height = pixmap->ViewPort().Height();
pixmap->DrawRectangle(cRect(0,0,width,2), theme.Color(clrBorder)); //top
pixmap->DrawRectangle(cRect(0,0,2,height), theme.Color(clrBorder)); //left
pixmap->DrawRectangle(cRect(0,height-2,width,2), theme.Color(clrBorder)); //bottom
pixmap->DrawRectangle(cRect(width-2,0,2,height), theme.Color(clrBorder)); //right
2013-01-17 13:16:44 +01:00
}
void cStyledPixmap::drawRoundedCorners(int width, int height, int radius) {
2013-05-26 11:38:05 +02:00
pixmap->DrawEllipse(cRect(2,2,radius,radius), theme.Color(clrBorder), -2);
pixmap->DrawEllipse(cRect(1,1,radius,radius), theme.Color(clrBackground), -2);
pixmap->DrawEllipse(cRect(width-radius - 2,2,radius,radius), theme.Color(clrBorder), -1);
pixmap->DrawEllipse(cRect(width-radius - 1,1,radius,radius), theme.Color(clrBackground), -1);
if( height > 2*radius) {
pixmap->DrawEllipse(cRect(2,height-radius - 2,radius,radius), theme.Color(clrBorder), -3);
pixmap->DrawEllipse(cRect(1,height-radius - 1,radius,radius), theme.Color(clrBackground), -3);
pixmap->DrawEllipse(cRect(width-radius - 2,height-radius - 2,radius,radius), theme.Color(clrBorder), -4);
pixmap->DrawEllipse(cRect(width-radius - 1,height-radius - 1,radius,radius), theme.Color(clrBackground), -4);
}
2013-01-17 13:16:44 +01:00
}
void cStyledPixmap::drawVerticalLine(int x, int yStart, int yStop, tColor col) {
2013-05-26 11:38:05 +02:00
for (int y = yStart; y <= yStop; y++) {
pixmap->DrawPixel(cPoint(x,y), col);
}
2013-01-17 13:16:44 +01:00
}
void cStyledPixmap::drawHorizontalLine(int y, int xStart, int xStop, tColor col) {
2013-05-26 11:38:05 +02:00
for (int x = xStart; x <= xStop; x++) {
pixmap->DrawPixel(cPoint(x,y), col);
}
2013-01-17 13:16:44 +01:00
}
void cStyledPixmap::DrawText(const cPoint &Point, const char *s, tColor ColorFg, tColor ColorBg, const cFont *Font) {
2013-05-26 11:38:05 +02:00
pixmap->DrawText(Point, s, ColorFg, ColorBg, Font);
2013-01-17 13:16:44 +01:00
}
void cStyledPixmap::DrawImage(const cPoint &Point, const cImage &Image) {
2013-05-26 11:38:05 +02:00
pixmap->DrawImage(Point, Image);
2013-01-17 13:16:44 +01:00
}
void cStyledPixmap::DrawRectangle(const cRect &Rect, tColor Color) {
2013-05-26 11:38:05 +02:00
pixmap->DrawRectangle(Rect,Color);
2013-01-17 13:16:44 +01:00
}
2013-07-09 00:17:42 +02:00
void cStyledPixmap::DrawEllipse(const cRect &Rect, tColor Color, int Quadrant) {
pixmap->DrawEllipse(Rect,Color,Quadrant);
}
void cStyledPixmap::SetViewPort(const cRect &Rect) {
pixmap->SetViewPort(Rect);
}