4 #if defined(__APPLE__)
\r
11 #include "psychlops_g_cache.h"
\r
13 namespace Psychlops {
\r
14 namespace Utilities {
\r
17 //////// TextCacheAllocation ////////
\r
18 CacheOnImage::CacheOnImage() { }
\r
19 CacheOnImage::~CacheOnImage() { uncache(); }
\r
20 void CacheOnImage::dirty() { dirty_ = true; }
\r
21 void CacheOnImage::uncache()
\r
25 void CacheOnImage::draw(
\r
26 Letters &drawee, const double xx, const double yy,
\r
27 const double r, const double g, const double b, const double a,
\r
28 const int horiz_align, const int vertical_align, const double max_width, Drawable &outer)
\r
30 const int anchor = horiz_align, vertical_anchor = vertical_align;
\r
31 double mx = xx, my = yy;
\r
32 //double mx = drawee.getDatum().x, my = drawee.getDatum().y;
\r
36 case Letters::TEXT_ALIGN_CENTER:
\r
37 x = mx - img.getWidth() / 2;
\r
39 case Letters::TEXT_ALIGN_RIGHT:
\r
40 x = mx - img.getWidth();
\r
42 case Letters::NOT_SPECIFIED:
\r
43 case Letters::TEXT_ALIGN_LEFT:
\r
48 switch(vertical_anchor) {
\r
49 case Letters::TEXT_ALIGN_MIDDLE:
\r
51 img.centering(x, y);
\r
53 case Letters::TEXT_ALIGN_TOP:
\r
58 y = my - drawee.font.size;
\r
65 Rectangle targetarea(img.getLeft(), img.getTop(), img.getRight(), img.getBottom());
\r
66 const Color zero_alpha(1,1,1,0,false);
\r
67 glPushAttrib(GL_COLOR_BUFFER_BIT);
\r
68 //img.move_to(posX, posY-cache_baseY);
\r
70 // clear destination alpha
\r
71 glBlendFunc(GL_ZERO, GL_SRC_COLOR);
\r
72 targetarea.draw(zero_alpha, outer);
\r
74 // draw font in alpha channel
\r
75 glBlendFunc(GL_ONE, GL_ONE);
\r
78 // apply alpha factor
\r
80 Color alpha_mask(1,1,1,a,false);
\r
81 glBlendFunc(GL_ZERO, GL_SRC_COLOR);
\r
82 targetarea.draw(alpha_mask, outer);
\r
85 // drawing in specified color by destination alpha
\r
86 glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);
\r
87 targetarea.draw(col, outer);
\r
89 // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
\r
94 //////// TextCacheManager ////////
\r
95 bool TextCacheManager::isCached(Letters *letters)
\r
97 return (map.count(letters) != 0);// && !(image_cache[img].dirty_);
\r
99 void TextCacheManager::cache(Letters *letters, CacheOnImage *allocation)
\r
101 map[letters] = allocation;
\r
103 void TextCacheManager::uncache(Letters *letters)
\r
105 if( isCached(letters) ) {
\r
106 map[letters]->uncache();
\r
107 map.erase(letters);
\r
110 void TextCacheManager::uncacheAll()
\r
117 } /* <- namespace Psycholops */