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
34 double w_ratio = 1.0;
\r
35 if(drawee._zoom_cache) { w_ratio = drawee.font.size/font_size; img._zoom_(100.0*w_ratio); }
\r
39 case Letters::TEXT_ALIGN_CENTER:
\r
40 x = mx - img.getWidth() * w_ratio / 2;
\r
42 case Letters::TEXT_ALIGN_RIGHT:
\r
43 x = mx - img.getWidth() * w_ratio;
\r
45 case Letters::NOT_SPECIFIED:
\r
46 case Letters::TEXT_ALIGN_LEFT:
\r
51 switch(vertical_anchor) {
\r
52 case Letters::TEXT_ALIGN_MIDDLE:
\r
54 img.centering(x, y);
\r
56 case Letters::TEXT_ALIGN_TOP:
\r
61 y = my - drawee.font.size;
\r
69 Rectangle targetarea;
\r
70 if(drawee._zoom_cache) {
\r
71 targetarea.set(img.getLeft(), img.getTop(), img.getRight(), img.getBottom());
\r
73 targetarea.set(img.getLeft(), img.getTop(), img.getRight(), img.getBottom());
\r
75 const Color zero_alpha(1,1,1,0,false);
\r
76 glPushAttrib(GL_COLOR_BUFFER_BIT);
\r
77 //img.move_to(posX, posY-cache_baseY);
\r
79 // clear destination alpha
\r
80 glBlendFunc(GL_ZERO, GL_SRC_COLOR);
\r
81 targetarea.draw(zero_alpha, outer);
\r
83 // draw font in alpha channel
\r
84 glBlendFunc(GL_ONE, GL_ONE);
\r
87 // apply alpha factor
\r
89 Color alpha_mask(1,1,1,a,false);
\r
90 glBlendFunc(GL_ZERO, GL_SRC_COLOR);
\r
91 targetarea.draw(alpha_mask, outer);
\r
94 // drawing in specified color by destination alpha
\r
95 glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);
\r
96 targetarea.draw(col, outer);
\r
98 // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
\r
103 //////// TextCacheManager ////////
\r
104 bool TextCacheManager::isCached(Letters *letters)
\r
106 return (map.count(letters) != 0);// && !(image_cache[img].dirty_);
\r
108 void TextCacheManager::cache(Letters *letters, CacheOnImage *allocation)
\r
110 map[letters] = allocation;
\r
112 void TextCacheManager::uncache(Letters *letters)
\r
114 if( isCached(letters) ) {
\r
115 map[letters]->uncache();
\r
116 map.erase(letters);
\r
119 void TextCacheManager::uncacheAll()
\r
126 } /* <- namespace Psycholops */