mirror of
https://projects.vdr-developer.org/git/vdr-plugin-skindesigner.git
synced 2023-10-19 15:58:31 +00:00
version 0.3.0
This commit is contained in:
92
libcore/cairoimage.c
Normal file
92
libcore/cairoimage.c
Normal file
@@ -0,0 +1,92 @@
|
||||
#include "cairoimage.h"
|
||||
|
||||
cCairoImage::cCairoImage(void) {
|
||||
surface = NULL;
|
||||
cr = NULL;
|
||||
}
|
||||
|
||||
cCairoImage::~cCairoImage() {
|
||||
if (cr)
|
||||
cairo_destroy (cr);
|
||||
if (surface)
|
||||
cairo_surface_destroy (surface);
|
||||
}
|
||||
|
||||
void cCairoImage::InitCairoImage(int width, int height) {
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
|
||||
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
|
||||
cr = cairo_create(surface);
|
||||
cairo_set_antialias(cr, CAIRO_ANTIALIAS_BEST);
|
||||
}
|
||||
|
||||
void cCairoImage::DrawTextVertical(string text, tColor color, string font, int size) {
|
||||
|
||||
int imgHeight = GetTextWidth(text, font, size);
|
||||
InitCairoImage(size * 1.2, imgHeight);
|
||||
|
||||
SetColor(color);
|
||||
cairo_move_to (cr, size, imgHeight);
|
||||
cairo_font_weight_t fontWeight = CAIRO_FONT_WEIGHT_NORMAL;
|
||||
cairo_font_slant_t fontSlant = CAIRO_FONT_SLANT_NORMAL;
|
||||
cairo_select_font_face (cr, font.c_str(), fontSlant, fontWeight);
|
||||
cairo_set_font_size (cr, size);
|
||||
cairo_rotate(cr, 3*M_PI/2);
|
||||
cairo_show_text (cr, text.c_str());
|
||||
}
|
||||
|
||||
cImage *cCairoImage::GetImage(void) {
|
||||
if (!cr || !surface)
|
||||
return NULL;
|
||||
|
||||
unsigned char *data = cairo_image_surface_get_data(surface);
|
||||
cImage *image = new cImage(cSize(width, height), (tColor*)data);
|
||||
return image;
|
||||
}
|
||||
|
||||
/**********************************************************************************
|
||||
* Private Functions
|
||||
**********************************************************************************/
|
||||
|
||||
int cCairoImage::GetTextWidth(string text, string font, int size) {
|
||||
cairo_surface_t *tmpSurface;
|
||||
cairo_t *tmpCr;
|
||||
|
||||
double width = 300;
|
||||
double height = (double)size *1.3;
|
||||
|
||||
cairo_font_weight_t fontWeight = CAIRO_FONT_WEIGHT_NORMAL;
|
||||
cairo_font_slant_t fontSlant = CAIRO_FONT_SLANT_NORMAL;
|
||||
|
||||
tmpSurface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
|
||||
tmpCr = cairo_create (tmpSurface);
|
||||
|
||||
cairo_select_font_face (tmpCr, font.c_str(), fontSlant, fontWeight);
|
||||
cairo_set_font_size (tmpCr, size);
|
||||
|
||||
cairo_text_extents_t te;
|
||||
cairo_text_extents (tmpCr, text.c_str(), &te);
|
||||
int textWidth = te.width;
|
||||
|
||||
cairo_destroy (tmpCr);
|
||||
cairo_surface_destroy (tmpSurface);
|
||||
|
||||
return (double)textWidth * 1.1;
|
||||
}
|
||||
|
||||
void cCairoImage::SetColor(tColor color) {
|
||||
if (!cr || !surface)
|
||||
return;
|
||||
tIndex tAlpha = (color & 0xFF000000) >> 24;
|
||||
tIndex tRed = (color & 0x00FF0000) >> 16;
|
||||
tIndex tGreen = (color & 0x0000FF00) >> 8;
|
||||
tIndex tBlue = (color & 0x000000FF);
|
||||
|
||||
double a = (int)tAlpha / (double)255;
|
||||
double r = (int)tRed / (double)255;
|
||||
double g = (int)tGreen / (double)255;
|
||||
double b = (int)tBlue / (double)255;
|
||||
|
||||
cairo_set_source_rgba(cr, r, g, b, a);
|
||||
}
|
26
libcore/cairoimage.h
Normal file
26
libcore/cairoimage.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef __CAIROIMAGE_H
|
||||
#define __CAIROIMAGE_H
|
||||
|
||||
#include <cairo.h>
|
||||
#include <vdr/osd.h>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class cCairoImage {
|
||||
private:
|
||||
int width;
|
||||
int height;
|
||||
cairo_surface_t *surface;
|
||||
cairo_t *cr;
|
||||
void SetColor(tColor color);
|
||||
int GetTextWidth(string text, string font, int size);
|
||||
public:
|
||||
cCairoImage(void);
|
||||
virtual ~cCairoImage();
|
||||
void InitCairoImage(int width, int height);
|
||||
void DrawTextVertical(string text, tColor color, string font, int size);
|
||||
cImage *GetImage(void);
|
||||
};
|
||||
#endif //__CAIROIMAGE_H
|
@@ -4,6 +4,7 @@
|
||||
#include <fstream>
|
||||
#include <sys/stat.h>
|
||||
#include "imagecache.h"
|
||||
#include "cairoimage.h"
|
||||
#include "../config.h"
|
||||
#include "helpers.h"
|
||||
|
||||
@@ -331,6 +332,28 @@ cImage *cImageCache::GetSkinpart(string name, int width, int height) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cImage *cImageCache::GetVerticalText(string text, tColor color, string font, int size) {
|
||||
cMutexLock MutexLock(&mutex);
|
||||
stringstream buf;
|
||||
buf << text << "_" << size;
|
||||
string imgName = buf.str();
|
||||
map<string, cImage*>::iterator hit = cairoImageCache.find(imgName);
|
||||
if (hit != cairoImageCache.end()) {
|
||||
return (cImage*)hit->second;
|
||||
} else {
|
||||
cCairoImage c;
|
||||
c.DrawTextVertical(text, color, font, size);
|
||||
cImage *image = c.GetImage();
|
||||
cairoImageCache.insert(pair<string, cImage*>(imgName, image));
|
||||
hit = cairoImageCache.find(imgName);
|
||||
if (hit != cairoImageCache.end()) {
|
||||
return (cImage*)hit->second;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
bool cImageCache::LoadIcon(eImageType type, string name) {
|
||||
cString subdir("");
|
||||
if (type == itMenuIcon)
|
||||
@@ -409,11 +432,17 @@ void cImageCache::Clear(void) {
|
||||
}
|
||||
channelLogoCache.clear();
|
||||
|
||||
for(map<std::string, cImage*>::const_iterator it = skinPartsCache.begin(); it != skinPartsCache.end(); it++) {
|
||||
for(map<string, cImage*>::const_iterator it = skinPartsCache.begin(); it != skinPartsCache.end(); it++) {
|
||||
cImage *img = (cImage*)it->second;
|
||||
delete img;
|
||||
}
|
||||
skinPartsCache.clear();
|
||||
|
||||
for(map<string, cImage*>::const_iterator it = cairoImageCache.begin(); it != cairoImageCache.end(); it++) {
|
||||
cImage *img = (cImage*)it->second;
|
||||
delete img;
|
||||
}
|
||||
cairoImageCache.clear();
|
||||
}
|
||||
|
||||
void cImageCache::Debug(bool full) {
|
||||
|
@@ -30,6 +30,8 @@ public:
|
||||
//skinparts
|
||||
void CacheSkinpart(string path, int width, int height);
|
||||
cImage *GetSkinpart(string name, int width, int height);
|
||||
//cairo special images
|
||||
cImage *GetVerticalText(string text, tColor color, string font, int size);
|
||||
//helpers
|
||||
void Clear(void);
|
||||
void Debug(bool full);
|
||||
@@ -48,6 +50,7 @@ private:
|
||||
map<string, cImage*> iconCache;
|
||||
map<string, cImage*> channelLogoCache;
|
||||
map<string, cImage*> skinPartsCache;
|
||||
map<string, cImage*> cairoImageCache;
|
||||
bool LoadIcon(eImageType type, string name);
|
||||
bool LoadLogo(const cChannel *channel);
|
||||
bool LoadSeparatorLogo(string name);
|
||||
|
@@ -16,6 +16,7 @@ cPixmapContainer::cPixmapContainer(int numPixmaps) {
|
||||
pixmaps[i] = NULL;
|
||||
pixmapsTransparency[i] = 0;
|
||||
}
|
||||
pixmapsLayer = NULL;
|
||||
mutex.Unlock();
|
||||
checkRunning = false;
|
||||
fadeTime = 0;
|
||||
@@ -33,6 +34,9 @@ cPixmapContainer::~cPixmapContainer(void) {
|
||||
}
|
||||
delete[] pixmaps;
|
||||
delete[] pixmapsTransparency;
|
||||
if (pixmapsLayer)
|
||||
delete[] pixmapsLayer;
|
||||
|
||||
if (deleteOsdOnExit && osd) {
|
||||
mutex.Lock();
|
||||
delete osd;
|
||||
@@ -65,12 +69,6 @@ void cPixmapContainer::OpenFlush(void) {
|
||||
flushState = fsOpen;
|
||||
}
|
||||
|
||||
bool cPixmapContainer::PixmapExists(int num) {
|
||||
cMutexLock MutexLock(&mutex);
|
||||
if (pixmaps[num])
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void cPixmapContainer::DoFlush(void) {
|
||||
cMutexLock MutexLock(&mutex);
|
||||
@@ -81,6 +79,41 @@ void cPixmapContainer::DoFlush(void) {
|
||||
}
|
||||
}
|
||||
|
||||
void cPixmapContainer::HidePixmaps(void) {
|
||||
cMutexLock MutexLock(&mutex);
|
||||
pixmapsLayer = new int[numPixmaps];
|
||||
for(int i=0; i < numPixmaps; i++) {
|
||||
if (!pixmaps[i]) {
|
||||
pixmapsLayer[i] = 0;
|
||||
continue;
|
||||
}
|
||||
pixmapsLayer[i] = pixmaps[i]->Layer();
|
||||
pixmaps[i]->SetLayer(-1);
|
||||
}
|
||||
}
|
||||
|
||||
void cPixmapContainer::ShowPixmaps(void) {
|
||||
cMutexLock MutexLock(&mutex);
|
||||
if (!pixmapsLayer)
|
||||
return;
|
||||
for(int i=0; i < numPixmaps; i++) {
|
||||
if (!pixmaps[i])
|
||||
continue;
|
||||
pixmaps[i]->SetLayer(pixmapsLayer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************************************
|
||||
* Protected Functions
|
||||
******************************************************************************************************/
|
||||
|
||||
bool cPixmapContainer::PixmapExists(int num) {
|
||||
cMutexLock MutexLock(&mutex);
|
||||
if (pixmaps[num])
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void cPixmapContainer::CreatePixmap(int num, int Layer, const cRect &ViewPort, const cRect &DrawPort) {
|
||||
cMutexLock MutexLock(&mutex);
|
||||
if (!osd || (checkRunning && !Running()))
|
||||
|
@@ -20,13 +20,14 @@ private:
|
||||
int numPixmaps;
|
||||
cPixmap **pixmaps;
|
||||
int *pixmapsTransparency;
|
||||
int *pixmapsLayer;
|
||||
bool checkRunning;
|
||||
int fadeTime;
|
||||
bool deleteOsdOnExit;
|
||||
protected:
|
||||
void SetInitFinished(void) { pixContainerInit = false; };
|
||||
bool CreateOsd(int Left, int Top, int Width, int Height);
|
||||
void DeleteOsdOnExit(void) { deleteOsdOnExit = true; };
|
||||
void DeleteOsdOnExit(bool doDelete = true) { deleteOsdOnExit = doDelete; };
|
||||
//Wrappers for access to pixmaps
|
||||
bool PixmapExists(int num);
|
||||
int NumPixmaps(void) { return numPixmaps; };
|
||||
@@ -69,6 +70,8 @@ public:
|
||||
void LockFlush(void);
|
||||
void OpenFlush(void);
|
||||
void DoFlush(void);
|
||||
void HidePixmaps(void);
|
||||
void ShowPixmaps(void);
|
||||
virtual void Action(void) {};
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user