comparison engine/core/video/fonts/subimagefont.cpp @ 425:ad7969d9460b

A client can now specify a global color key to be used with all images. The default color key is (255,0,255) in RGB format. Also the client can enable/disable the color key feature by using the setColorKeyEnabled function in the EngineSettings class. By default the color key feature is disabled. fixes[t:451]
author vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
date Sat, 20 Feb 2010 19:11:01 +0000
parents 756b895e1dab
children
comparison
equal deleted inserted replaced
424:e29fbf84cb41 425:ad7969d9460b
51 FL_LOG(_log, LMsg("guichan_image_font, loading ") << filename << " glyphs " << glyphs); 51 FL_LOG(_log, LMsg("guichan_image_font, loading ") << filename << " glyphs " << glyphs);
52 52
53 int image_id = m_pool.addResourceFromFile(filename); 53 int image_id = m_pool.addResourceFromFile(filename);
54 Image& img = dynamic_cast<Image&>(m_pool.get(image_id)); 54 Image& img = dynamic_cast<Image&>(m_pool.get(image_id));
55 SDL_Surface* surface = img.getSurface(); 55 SDL_Surface* surface = img.getSurface();
56 m_colorkey = RenderBackend::instance()->getColorKey();
56 57
57 if( !surface ) { 58 if( !surface ) {
58 throw CannotOpenFile(filename); 59 throw CannotOpenFile(filename);
59 } 60 }
60 61
75 76
76 SDL_Rect src; 77 SDL_Rect src;
77 78
78 src.h = surface->h; 79 src.h = surface->h;
79 src.y = 0; 80 src.y = 0;
81
82 uint32_t separator = pixels[0];
83 uint32_t colorkey = SDL_MapRGB(surface->format, m_colorkey.r, m_colorkey.g, m_colorkey.b);
80 84
81 uint32_t separator = pixels[0]; 85 // if colorkey feature is not enabled then manually find the color key in the font
82 while(x < surface->w && pixels[x] == separator) 86 if (!RenderBackend::instance()->isColorKeyEnabled()) {
83 ++x; 87 while(x < surface->w && pixels[x] == separator) {
84 uint32_t colorkey = pixels[x]; 88 ++x;
89 }
90
91 colorkey = pixels[x];
92 }
93
94 // Disable alpha blending, so that we use color keying
95 SDL_SetAlpha(surface,0,255);
96 SDL_SetColorKey(surface,SDL_SRCCOLORKEY,colorkey);
85 97
86 FL_DBG(_log, LMsg("image_font") 98 FL_DBG(_log, LMsg("image_font")
87 << " glyph separator is " 99 << " glyph separator is "
88 << pprint(reinterpret_cast<void*>(separator)) 100 << pprint(reinterpret_cast<void*>(separator))
89 << " transparent color is " 101 << " transparent color is "
90 << pprint(reinterpret_cast<void*>(colorkey))); 102 << pprint(reinterpret_cast<void*>(colorkey)));
91
92 // Disable alpha blending, so that we use colorkeying
93 SDL_SetAlpha(surface,0,255);
94 SDL_SetColorKey(surface,SDL_SRCCOLORKEY,colorkey);
95 103
96 // Finally extract all glyphs 104 // Finally extract all glyphs
97 std::string::const_iterator text_it = glyphs.begin(); 105 std::string::const_iterator text_it = glyphs.begin();
98 while(text_it != glyphs.end()) { 106 while(text_it != glyphs.end()) {
99 w=0; 107 w=0;