~unity-team/nux/nux.remove-deprecated

« back to all changes in this revision

Viewing changes to NuxGraphics/FontTexture.cpp

  • Committer: Tarmac
  • Author(s): Jay Taoko, Michi Henning
  • Date: 2012-10-11 18:57:49 UTC
  • mfrom: (686.3.4 nux.nstring-removal)
  • Revision ID: tarmac-20121011185749-v8y4evu36vue3rfx
* Removal of nux::NString in favor of std::string.
* The branch has a lot of changes due to the enablement of -Werror. All the warnings have been fixed.
* -Werror is disabled when building with --enable-debug.

[Test] The changes are covered by existing tests.. Fixes: https://bugs.launchpad.net/bugs/1065293. Approved by Jay Taoko.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
  FontTexture::FontTexture(const char *FontFile, NUX_FILE_LINE_DECL)
37
37
    :   Object(true, NUX_FILE_LINE_PARAM)
38
38
  {
39
 
    NString FontPath = GNuxGraphicsResources.FindResourceLocation(FontFile);
 
39
    std::string FontPath = GNuxGraphicsResources.FindResourceLocation(FontFile);
40
40
 
41
41
    std::filebuf fb;
42
 
    fb.open(FontPath.GetTCharPtr(), std::ios::in);
 
42
    fb.open(FontPath.c_str(), std::ios::in);
43
43
    std::istream is(&fb);
44
44
 
45
45
    BMFontParseFNT(is);
72
72
    return m_Charset.Chars[ascii].XAdvance;
73
73
  }
74
74
 
75
 
  int FontTexture::GetStringWidth(const NString &str) const
 
75
  int FontTexture::GetStringWidth(const std::string &str) const
76
76
  {
77
77
//     unsigned int total = 0;
78
78
//     for (unsigned int i = 0; i != (unsigned int)str.size(); ++i)
80
80
//         total += GetCharWidth(str[i]);
81
81
//     }
82
82
//     return total;
83
 
    return GetCharStringWidth(str.GetTCharPtr());
 
83
    return GetCharStringWidth(str.c_str());
84
84
  }
85
85
 
86
86
  int FontTexture::GetCharStringWidth(const char *str) const
87
87
  {
88
 
    if ((str == 0) || (NString(str) == NString("")))
 
88
    if (str == 0 || *str == '\0')
89
89
      return 0;
90
90
 
91
91
    unsigned int total = 0;
101
101
    return total;
102
102
  }
103
103
 
104
 
  int FontTexture::GetStringWidth(const NString &str, int num_char_to_compute) const
 
104
  int FontTexture::GetStringWidth(const std::string &str, int num_char_to_compute) const
105
105
  {
106
 
    return GetCharStringWidth(str.GetTCharPtr(), num_char_to_compute);
 
106
    return GetCharStringWidth(str.c_str(), num_char_to_compute);
107
107
  }
108
108
 
109
109
  int FontTexture::GetCharStringWidth(const char *str, int num_char_to_compute) const
110
110
  {
111
 
    if ((str == 0) || (NString(str) == NString("")))
 
111
    if (str == 0 || *str == '\0')
112
112
      return 0;
113
113
 
114
114
    int num_chars = num_char_to_compute;
215
215
//                 FontPath.AddSearchPath(".");
216
216
//                 FontPath.AddSearchPath("../Fonts");
217
217
 
218
 
#ifdef UNICODE
219
 
          NString font_texture_file = GNuxGraphicsResources.FindResourceLocation(texture);
220
 
#else
221
 
          NString font_texture_file = GNuxGraphicsResources.FindResourceLocation(texture);
222
 
#endif
 
218
          std::string font_texture_file = GNuxGraphicsResources.FindResourceLocation(texture);
223
219
 
224
220
#ifdef NUX_OPENGLES_20
225
221
          Texture2D *Texture = new Texture2D(NUX_TRACKER_LOCATION);
227
223
          TextureRectangle *Texture = new TextureRectangle(NUX_TRACKER_LOCATION);
228
224
#endif
229
225
 
230
 
          NBitmapData* bitmap_data = LoadImageFile(font_texture_file.GetTCharPtr());
 
226
          NBitmapData* bitmap_data = LoadImageFile(font_texture_file.c_str());
231
227
 
232
228
          if (bitmap_data)
233
229
            Texture->Update(bitmap_data, false);
258
254
//          If the function succeeds, it returns S_OK.
259
255
//          If the function fails, it returns an HRESULT.
260
256
//          The return value can be tested with the SUCCEEDED and FAILED macros.
261
 
  bool FontTexture::CursorPosToX(const NString &Str,
 
257
  bool FontTexture::CursorPosToX(const std::string &Str,
262
258
                                  int icp,
263
259
                                  bool fTrailing,
264
260
                                  int *pX)
265
261
  {
266
 
    if (icp > (int) Str.Size())
 
262
    if (icp > (int) Str.size())
267
263
      return false;
268
264
 
269
265
    if (fTrailing)
293
289
//          If the function is successful, it returns S_OK.
294
290
//          If the function fails, it returns an HRESULT.
295
291
//          The return value can be tested with the SUCCEEDED and FAILED macros.
296
 
  bool FontTexture::XToCursorPosition(const NString &Str,
 
292
  bool FontTexture::XToCursorPosition(const std::string &Str,
297
293
                                       int iX,
298
294
                                       unsigned int FirstVisibleCharIndex,
299
295
                                       int *piCh,
300
296
                                       int *piTrailing)
301
297
  {
302
298
    unsigned int num_chars;
303
 
    num_chars = (unsigned int) Str.Size();
 
299
    num_chars = (unsigned int) Str.size();
304
300
    nuxAssert(FirstVisibleCharIndex < num_chars);
305
301
 
306
302
    *piCh = 0;