diff options
author | louis <louis.braun@gmx.de> | 2015-03-12 17:28:35 +0100 |
---|---|---|
committer | louis <louis.braun@gmx.de> | 2015-03-12 17:28:35 +0100 |
commit | 44680b6ce80221e91cb14dca9ca7fad7015f1297 (patch) | |
tree | 8af805db50568ba41ebb461309d5724320295441 /libcore | |
parent | 45cb6c1663d66ebc22bed8dbc8cdbacdc82ad4a8 (diff) | |
download | vdr-plugin-skindesigner-0.3.0.tar.gz vdr-plugin-skindesigner-0.3.0.tar.bz2 |
version 0.3.00.3.0
Diffstat (limited to 'libcore')
-rw-r--r-- | libcore/cairoimage.c | 92 | ||||
-rw-r--r-- | libcore/cairoimage.h | 26 | ||||
-rw-r--r-- | libcore/imagecache.c | 31 | ||||
-rw-r--r-- | libcore/imagecache.h | 3 | ||||
-rw-r--r-- | libcore/pixmapcontainer.c | 45 | ||||
-rw-r--r-- | libcore/pixmapcontainer.h | 5 |
6 files changed, 194 insertions, 8 deletions
diff --git a/libcore/cairoimage.c b/libcore/cairoimage.c new file mode 100644 index 0000000..a8b56c3 --- /dev/null +++ b/libcore/cairoimage.c @@ -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); +}
\ No newline at end of file diff --git a/libcore/cairoimage.h b/libcore/cairoimage.h new file mode 100644 index 0000000..02e9c89 --- /dev/null +++ b/libcore/cairoimage.h @@ -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
\ No newline at end of file diff --git a/libcore/imagecache.c b/libcore/imagecache.c index 2a9a948..e6188d2 100644 --- a/libcore/imagecache.c +++ b/libcore/imagecache.c @@ -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) { diff --git a/libcore/imagecache.h b/libcore/imagecache.h index 086d8e4..f2c04f3 100644 --- a/libcore/imagecache.h +++ b/libcore/imagecache.h @@ -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); diff --git a/libcore/pixmapcontainer.c b/libcore/pixmapcontainer.c index b3ea83e..3e5e60a 100644 --- a/libcore/pixmapcontainer.c +++ b/libcore/pixmapcontainer.c @@ -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())) diff --git a/libcore/pixmapcontainer.h b/libcore/pixmapcontainer.h index 8fe1dfe..3b367c8 100644 --- a/libcore/pixmapcontainer.h +++ b/libcore/pixmapcontainer.h @@ -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) {}; }; |