skins2: fix RadialSlider
[vlc/asuraparaju-public.git] / modules / gui / skins2 / src / bitmap_font.cpp
blob3a9bd295f28390fab73ce93bba64b1a9dbcf9f61
1 /*****************************************************************************
2 * bitmap_font.cpp
3 *****************************************************************************
4 * Copyright (C) 2004 the VideoLAN team
5 * $Id$
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #include "bitmap_font.hpp"
25 #include "generic_bitmap.hpp"
26 #include "../utils/ustring.hpp"
29 BitmapFont::BitmapFont( intf_thread_t *pIntf, const GenericBitmap &rBitmap,
30 const string &rType ):
31 GenericFont( pIntf ), m_rBitmap( rBitmap )
33 int i;
35 // Build the character table
36 if( rType == "digits" )
38 m_width = 9;
39 m_height = 13;
40 m_advance = 12;
41 m_skip = 6;
42 for( i = 0; i <= 9; i++ )
44 m_table['0'+i].m_xPos = i * m_width;
46 m_table[(size_t)' '].m_xPos = 10 * m_width;
47 m_table[(size_t)'-'].m_xPos = 11 * m_width;
49 else if( rType == "text" )
51 m_width = 5;
52 m_height = 6;
53 m_advance = 5;
54 m_skip = 5;
55 for( i = 0; i < 26; i++ )
57 m_table['A'+i].m_xPos = m_table['a'+i].m_xPos = i * m_width;
59 m_table[(size_t)'"'].m_xPos = 26 * m_width;
60 m_table[(size_t)'@'].m_xPos = 27 * m_width;
61 m_table[(size_t)' '].m_xPos = 29 * m_width;
62 for( i = 0; i <= 9; i++ )
64 m_table['0'+i].m_xPos = i * m_width;
65 m_table['0'+i].m_yPos = m_height;
67 static const char specialChars[] = {'.', ':', '(', ')', '-', '\'',
68 '!', '_', '+', '\\', '/', '[', ']', '^', '&', '%', ',', '=', '$',
69 '#'};
70 for( i = 0; i < 19; i++ )
72 m_table[(size_t)specialChars[i]].m_xPos = (11 + i) * m_width;
73 m_table[(size_t)specialChars[i]].m_yPos = m_height;
75 m_table[(size_t)'?'].m_xPos = 4 * m_width;
76 m_table[(size_t)'*'].m_xPos = 5 * m_width;
77 m_table[(size_t)'?'].m_yPos = m_table[(size_t)'*'].m_yPos = 2 * m_height;
82 GenericBitmap *BitmapFont::drawString( const UString &rString,
83 uint32_t color, int maxWidth ) const
85 uint32_t *pString = (uint32_t*)rString.u_str();
86 // Compute the text width
87 int width = 0;
88 for( uint32_t *ptr = pString; *ptr; ptr++ )
90 uint32_t c = *ptr;
91 if( c < 256 && m_table[c].m_xPos != -1 )
93 width += m_advance;
95 else
97 width += m_skip;
100 // Create a bitmap
101 BitmapImpl *pBmp = new BitmapImpl( getIntf(), width, m_height );
102 int xDest = 0;
103 while( *pString )
105 uint32_t c = *(pString++);
106 if( c < 256 && m_table[c].m_xPos != -1 )
108 bool res = pBmp->drawBitmap( m_rBitmap, m_table[c].m_xPos,
109 m_table[c].m_yPos, xDest, 0,
110 m_width, m_height );
111 if ( !res )
112 msg_Warn( getIntf(), "BitmapFont::drawString: ignoring char" );
113 xDest += m_advance;
115 else
117 xDest += m_skip;
120 return pBmp;