~performous-team/performous/trunk

« back to all changes in this revision

Viewing changes to game/opengl_text.cc

  • Committer: GitHub
  • Author(s): niek nooijens
  • Date: 2017-10-05 06:39:20 UTC
  • mfrom: (2735.1.15)
  • Revision ID: git-v1:c114cf10130e9c8dd5c54bce298ba1db48089d0e
Merge pull request #260 from performous/feature/text-rendering-changes

Toy around with resolution. <merged because of multiple approvements>

Show diffs side-by-side

added added

removed removed

Lines of Context:
219
219
        parseTheme(themeFile, m_text_highlight, a, b, c, d, e);
220
220
}
221
221
 
222
 
void SvgTxtTheme::draw(std::vector<std::string> const& _text) {
223
 
        std::vector<TZoomText> tmp;
224
 
 
225
 
        for (auto const& str: _text) {
226
 
                TZoomText t;
227
 
                t.string = str;
228
 
                t.factor = 1.0;
229
 
                tmp.push_back(t);
230
 
        }
231
 
 
232
 
        draw(tmp);
233
 
}
 
222
// void SvgTxtTheme::draw(std::vector<std::string> const& _text) {
 
223
//      std::vector<TZoomText> tmp;
 
224
//      
 
225
//      for (auto const& str: _text) {          
 
226
//              TZoomText t;
 
227
//              t.string = str;
 
228
//              t.factor = 1.0;
 
229
//              
 
230
//              tmp.push_back(t);
 
231
//      }
 
232
//      std::clog << "text/debug: This function did get called." << std::endl;
 
233
//      draw(tmp);
 
234
// }
234
235
 
235
236
void SvgTxtTheme::draw(std::string _text) {
236
237
        std::vector<TZoomText> tmp;
241
242
        draw(tmp);
242
243
}
243
244
 
244
 
void SvgTxtTheme::draw(std::vector<TZoomText> const& _text) {
 
245
void SvgTxtTheme::draw(std::vector<TZoomText>& _text) {
245
246
        std::string tmp;
246
 
        for (auto& zt: _text) tmp += zt.string;
 
247
 
 
248
        for (auto& zt: _text) { 
 
249
                bool wordBoundaryCheck = false;
 
250
        // Check whether current syllable begins or previous syllable ends with a space.
 
251
                if (_text.size() > 1) {
 
252
                        wordBoundaryCheck = (zt.string.front() == ' ');
 
253
                        if (wordBoundaryCheck == false && tmp.size() > 0) {
 
254
                                wordBoundaryCheck = (tmp.back() == ' ');
 
255
                        }
 
256
                zt.updateWordStart(wordBoundaryCheck);  
 
257
                }
 
258
                tmp += zt.string;
 
259
        }
247
260
 
248
261
        if (m_opengl_text.size() != _text.size() || m_cache_text != tmp) {
249
262
                m_cache_text = tmp;
250
263
                m_opengl_text.clear();
251
264
                for (auto& zt: _text) {
 
265
                        if (zt.wordStart == true) { zt.addSpace(); } // If it's a different word, add an extra space to account for lyrics zooming in.
252
266
                        m_text.text = zt.string;
253
267
                        m_opengl_text.push_back(new OpenGLText(m_text, m_factor));
254
268
                }
262
276
        }
263
277
 
264
278
        double texture_ar = text_x / text_y;
265
 
        m_texture_width = std::min(0.96, text_x/800.);
266
 
        m_texture_height = m_texture_width / texture_ar;
267
 
 
 
279
        m_texture_width = std::min(0.96, text_x / targetWidth); // targetWidth is defined in video_driver.cc, it's the base rendering width, used to project the svg onto a gltexture. currently we're targeting 1366x768 as base resolution.
 
280
        
268
281
        double position_x = dimensions.x1();
269
282
        if (m_align == CENTER) position_x -= 0.5 * m_texture_width;
270
283
        if (m_align == RIGHT) position_x -= m_texture_width;
271
284
 
272
 
        if ((position_x + m_texture_width) > 0.48) {
 
285
        if ((position_x + m_texture_width) > 0.48) { 
273
286
                m_texture_width = (0.48 - position_x);
274
287
        }
 
288
        m_texture_height = m_texture_width / texture_ar; // Keep aspect ratio.
275
289
        for (unsigned int i = 0; i < _text.size(); i++ ) {
276
290
                double syllable_x = m_opengl_text[i].x();
277
291
                double syllable_width = syllable_x *  m_texture_width / text_x;
286
300
                        ColorTrans c(Color(m_text_highlight.fill_col.r, m_text_highlight.fill_col.g, m_text_highlight.fill_col.b));
287
301
                        dim.fixedWidth(dim.w() * factor);
288
302
                        m_opengl_text[i].draw(dim, tex);
289
 
                } else m_opengl_text[i].draw(dim, tex);
290
 
                        position_x += syllable_width;
291
 
                }
 
303
                } 
 
304
                else { m_opengl_text[i].draw(dim, tex); }
 
305
                position_x += syllable_width;
 
306
        }
292
307
}
293
308