JNR
laFont.h
1 /*
2 
3 Jump'n'Run Engine
4 http://www.atanaslaskov.com/jnr/
5 
6 BSD LICENSE
7 Copyright (c) 2007-2013, Atanas Laskov
8 All rights reserved.
9 
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12 1. Redistributions of source code must retain the above copyright notice,
13 this list of conditions and the following disclaimer.
14 2. Redistributions in binary form must reproduce the above copyright notice,
15 this list of conditions and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL ATANAS LASKOV BE LIABLE FOR ANY
21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 */
29 #ifndef M_FONT_H
30 #define M_FONT_H
31 
33 
34 
40 
41 class laFont: public laLoadableObj
42 {
43 protected:
44  laTexture _tex;
45 
46  double _dSz;
47  double _dWidthFactor;
48 
49  char _charStart;
50  double _dTexCharW;
51  double _dTexCharH;
52  unsigned _nCharsPerLine;
53 
54  unsigned _nAlignH;
55  unsigned _nAlignV;
56 
57  /*inline void _draw_char(laRenderer* r, const laPoint3 &pos, char ch) {
58  PROFILE_REN(laFont__draw_char);
59 
60  unsigned index = ch - _charStart;
61  double tx = (index%_nCharsPerLine)*_dTexCharW;
62  double ty = (index/_nCharsPerLine+1)*_dTexCharH;
63 
64  r->drawRect(pos, laPoint3(_dSz*_dWidthFactor, _dSz), laPoint2(tx, 1-ty*0.99), laPoint2(_dTexCharW, _dTexCharH));
65  }*/
66 
67  void _draw_string(laRenderer* r, laPoint3 pos, char* strStr);
68 
69  //Discard
70  friend class laRenderer;
71  void discard();
72  //void create(char* strTex,)
73 
74  static char _str[256];
75 
76 public:
77  laFont(void);
78  ~laFont(void);
79 
80  //Control methods
81  void ctlSize(double sz);
82  void ctlAlignH(unsigned align){ _nAlignH=align; };
83  void ctlAlignV(unsigned align){ _nAlignV=align; };
84 
85  //Draw text
86  void draw(const laPoint3 &pos, char* strFormat, ...);
87 
88  //Calculate string lenght
89  inline double lenght(char* str) { return strlen(str)*_dSz*_dWidthFactor; }
90 
91  //This method is part of the laLoadableObj interface
92  virtual void load(class laFileParser *fp);
93 
94  // String obfuscation
95  //
96  static char* obfuscated(char* str); //< obfuscate and deobfuscate string
97  static char* obfuscated_escape(char* str_in, char* str_out); //< quote obfuscated as string literal
98  static char* getSourceStr(unsigned i); //< get built-in obfuscated string
99 };
101 #endif
Font and Text Drawing.
Definition: laFont.h:41
Interface for loadable objects.
Definition: laLoadableObj.h:43
2D Texture
Definition: laTexture.h:45
Virtual interface for the Engine graphics renderer.
Definition: laRenderer.h:98
File Parser.
Definition: laFileParser.h:41