~ubuntu-branches/ubuntu/wily/xmoto/wily-proposed

« back to all changes in this revision

Viewing changes to src/VDrawText.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Samuel Mimram
  • Date: 2006-09-14 21:01:20 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060914210120-bvr7yu9rafb3fivp
Tags: 0.2.1-1
* New upstream release.
* Removed manpages and desktop files from the Debian package as they are now
  provided upstream.
* Make the package binNMUable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
  int DrawLib::getTextHeight(std::string Text) {
36
36
    int cx = 0,cy = 0,c;
37
37
    int h=0;
38
 
    for(int i=0;i<Text.size();i++) {
 
38
    for(unsigned int i=0;i<Text.size();i++) {
39
39
      c = Text[i];
40
40
      if(c==' ') {
41
41
        cx += 8;
58
58
  int DrawLib::getTextWidth(std::string Text) {
59
59
    int cx = 0,cy = 0,c;
60
60
    int w=0;
61
 
    for(int i=0;i<Text.size();i++) {
 
61
    for(unsigned int i=0;i<Text.size();i++) {
62
62
      c = Text[i];
63
63
      if(c==' ') {
64
64
        cx += 8;
90
90
                        drawText(Pos + Vector2f(-1,-1),Text,0,MAKE_COLOR(0,0,0,255),false);
91
91
                }
92
92
  
93
 
    int cx = Pos.x,cy = Pos.y,c;
94
 
    glBindTexture(GL_TEXTURE_2D,m_pDefaultFontTexture->nID);
 
93
    int cx = (int) Pos.x, cy = (int) Pos.y, c;
 
94
    if(m_pDefaultFontTex != NULL) {
 
95
      glBindTexture(GL_TEXTURE_2D,m_pDefaultFontTex->nID);
 
96
    }
 
97
 
95
98
    glEnable(GL_BLEND);
96
99
    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
97
100
    int nCharsPerLine = 256 / 8;
98
 
    for(int i=0;i<Text.size();i++) {
 
101
    for(unsigned int i=0;i<Text.size();i++) {
99
102
      c = Text[i];
100
103
      if(c==' ') {
101
104
        glBegin(GL_POLYGON);
111
114
        cx += 8;
112
115
      }
113
116
      else if(c=='\r') {
114
 
        cx = Pos.x;
 
117
        cx = (int) Pos.x;
115
118
      }
116
119
      else if(c=='\n') {
117
 
        cx = Pos.x;
 
120
        cx = (int) Pos.x;
118
121
        cy += 12;
119
122
      }
120
123
      else {
157
160
  /*===========================================================================
158
161
  Init of text rendering
159
162
  ===========================================================================*/  
160
 
  void DrawLib::_InitTextRendering(TextureManager *pTextureManager) {   
161
 
    CBuiltInFont Fnt;
162
 
      
163
 
    /* Create texture */
164
 
    int nImgWidth = 256, nImgHeight = 256;
165
 
    Color *pImgData = new Color[nImgWidth * nImgHeight];
166
 
    memset(pImgData,0,nImgWidth * nImgHeight * sizeof(Color));
167
 
  
168
 
    /* Fill texture with glyphs */
169
 
    int cx=0,cy=0,w=Fnt.getCharWidth(),h=Fnt.getCharHeight();
170
 
    for(int i=0;i<256;i++) {
171
 
      unsigned char *pc = Fnt.fetchChar(i);
172
 
      for(int y=0;y<h;y++) {
173
 
        for(int x=0;x<w;x++) {
174
 
          unsigned char *pcT = (unsigned char *)&pImgData[(cx+x) + (cy+y)*nImgWidth];
175
 
          pcT[0] = 255;
176
 
          pcT[1] = 255;
177
 
          pcT[2] = 255;
178
 
          pcT[3] = pc[x+y*w];        
179
 
          //pImgData[(cx+x) + (cy+y)*nImgWidth] = MAKE_COLOR(pc[x+y*w],255,255,255);
180
 
        }
181
 
      }
182
 
      
183
 
      cx += w;
184
 
      if(cx+w > nImgWidth) {
185
 
        cx = 0;
186
 
        cy += h;
187
 
        if(cy+h > nImgHeight) {
188
 
          delete [] pImgData;
189
 
          throw TextureError("default font does not fit in texture");
190
 
        }
191
 
      }        
192
 
    }
193
 
    
194
 
    /* Load it */
195
 
    m_pDefaultFontTexture = pTextureManager->createTexture("default-font",(unsigned char *)pImgData,
196
 
                                                           256,256,true);
197
 
      
198
 
    delete [] pImgData;
 
163
  void DrawLib::_InitTextRendering(Theme *p_theme) {   
 
164
    m_pDefaultFontTex = p_theme->getDefaultFont();
199
165
          
200
166
    /* Create font texture (default) */
201
167
    //m_pDefaultFontTexture = (DefaultFontTexture *)pTextureManager->loadTexture(new DefaultFontTexture,"default-font");
204
170
  /*===========================================================================
205
171
  Uninit of text rendering
206
172
  ===========================================================================*/  
207
 
  void DrawLib::_UninitTextRendering(TextureManager *pTextureManager) {    
 
173
  void DrawLib::_UninitTextRendering(Theme *p_theme) {    
208
174
  }
209
175
 
210
176
  /*===========================================================================
234
200
  //void DefaultFontTexture::unload(void) {
235
201
 // }
236
202
      
237
 
};
 
203
}
238
204