TextBase.hpp
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <etk/Color.hpp>
9 
10 #include <ewol/debug.hpp>
14 #include <exml/exml.hpp>
15 #include <string>
16 
17 namespace ewol {
18  namespace compositing {
24  public:
28  TextDecoration() {
29  m_colorBg = etk::color::blue;
30  m_colorBg = etk::color::green;
31  m_mode = ewol::font::Regular;
32  }
33  };
34 
35  enum aligneMode {
36  alignDisable,
37  alignRight,
38  alignLeft,
39  alignCenter,
40  alignJustify
41  };
42 
43  class TextBase : public ewol::Compositing {
44  protected:
46  public:
47  virtual ewol::compositing::Drawing& getDrawing() {
48  return m_vectorialDraw;
49  };
50  protected:
51  int32_t m_nbCharDisplayed;
59  protected:
62  protected:
67  protected:
69  bool m_kerning;
70  char32_t m_previousCharcode;
71  protected:
73  float m_stopTextPos;
74  enum aligneMode m_alignement;
75  protected:
77  int32_t m_GLPosition;
78  int32_t m_GLMatrix;
79  int32_t m_GLColor;
80  int32_t m_GLtexture;
81  int32_t m_GLtexID;
82  int32_t m_GLtextWidth;
83  int32_t m_GLtextHeight;
84  protected:
86  int32_t m_cursorPos;
87  protected: // Text
88  std::vector<vec3 > m_coord;
89  std::vector<vec2 > m_coordTex;
90  std::vector<etk::Color<float> > m_coordColor;
91  public:
95  virtual void loadProgram(const std::string& _shaderName);
96  public:
100  TextBase(const std::string& _shaderName = "{ewol}DATA:text.prog", bool _loadProgram = true);
104  virtual ~TextBase();
105  public: // Derived function
106  void translate(const vec3& _vect);
107  void rotate(const vec3& _vect, float _angle);
108  void scale(const vec3& _vect);
109  public:
113  void draw(bool _disableDepthTest=true) {
114  drawD(_disableDepthTest);
115  }
117  void draw(const mat4& _transformationMatrix, bool _enableDepthTest=false) {
118  drawMT(_transformationMatrix, _enableDepthTest);
119  }
123  virtual void drawD(bool _disableDepthTest) = 0;
125  virtual void drawMT(const mat4& _transformationMatrix, bool _enableDepthTest) = 0;
129  virtual void clear();
133  virtual void reset();
138  const vec3& getPos() {
139  return m_position;
140  };
145  void setPos(const vec3& _pos);
147  inline void setPos(const vec2& _pos) {
148  setPos(vec3(_pos.x(),_pos.y(),0));
149  };
154  void setRelPos(const vec3& _pos);
156  inline void setRelPos(const vec2& _pos) {
157  setRelPos(vec3(_pos.x(),_pos.y(),0));
158  };
163  void setDefaultColorBg(const etk::Color<>& _color) {
164  m_defaultColorBg = _color;
165  }
170  void setDefaultColorFg(const etk::Color<>& _color) {
171  m_defaultColorFg = _color;
172  }
177  void setColor(const etk::Color<>& _color) {
178  m_color = _color;
179  };
184  void setColorBg(const etk::Color<>& _color);
190  void setClippingWidth(const vec3& _pos, const vec3& _width) {
191  setClipping(_pos, _pos+_width);
192  }
194  void setClippingWidth(const vec2& _pos, const vec2& _width) {
195  setClipping(_pos, _pos+_width);
196  };
202  void setClipping(const vec3& _pos, const vec3& _posEnd);
204  void setClipping(const vec2& _pos, const vec2& _posEnd) {
205  setClipping(vec3(_pos.x(),_pos.y(),-1), vec3(_posEnd.x(),_posEnd.y(),1) );
206  };
211  // TODO : Rename setClippingActivity
212  void setClippingMode(bool _newMode);
217  virtual void setFontSize(int32_t _fontSize) = 0;
222  virtual void setFontName(const std::string& _fontName) = 0;
228  virtual void setFont(std::string _fontName, int32_t _fontSize) = 0;
233  virtual void setFontMode(enum ewol::font::mode _mode) = 0;
238  enum ewol::font::mode getFontMode() {
239  return m_mode;
240  };
241  virtual float getHeight() = 0;
242  virtual float getSize() = 0;
243  virtual ewol::GlyphProperty * getGlyphPointer(char32_t _charcode) = 0;
248  void setFontBold(bool _status);
253  void setFontItalic(bool _status);
258  void setKerningMode(bool _newMode);
263  void print(const std::string& _text);
265  void print(const std::u32string& _text);
295  void printDecorated(const std::string& _text);
297  void printDecorated(const std::u32string& _text);
331  void printHTML(const std::string& _text);
333  void printHTML(const std::u32string& _text);
339  void print(const std::string& _text, const std::vector<TextDecoration>& _decoration);
341  void print(const std::u32string& _text, const std::vector<TextDecoration>& _decoration);
346  virtual void printChar(const char32_t& _charcode) = 0;
350  void forceLineReturn();
351  protected:
356  void parseHtmlNode(const exml::Element& _element);
357  public:
365  void setTextAlignement(float _startTextpos, float _stopTextPos, enum ewol::compositing::aligneMode _alignement=ewol::compositing::alignDisable);
369  void disableAlignement();
374  enum ewol::compositing::aligneMode getAlignement();
380  vec3 calculateSizeHTML(const std::string& _text);
382  vec3 calculateSizeHTML(const std::u32string& _text);
388  vec3 calculateSizeDecorated(const std::string& _text);
390  vec3 calculateSizeDecorated(const std::u32string& _text);
396  vec3 calculateSize(const std::string& _text);
398  vec3 calculateSize(const std::u32string& _text);
404  inline vec3 calculateSize(const char32_t& _charcode) {
405  return calculateSizeChar(_charcode);
406  };
407  protected:
409  virtual vec3 calculateSizeChar(const char32_t& _charcode) = 0;
410  public:
416  void printCursor(bool _isInsertMode, float _cursorSize = 20.0f);
417  protected:
429  bool extrapolateLastId(const std::string& _text, const int32_t _start, int32_t& _stop, int32_t& _space, int32_t& _freeSpace);
431  bool extrapolateLastId(const std::u32string& _text, const int32_t _start, int32_t& _stop, int32_t& _space, int32_t& _freeSpace);
432  protected:
433  // this section is reserved for HTML parsing and display:
434  std::u32string m_htmlCurrrentLine;
435  std::vector<TextDecoration> m_htmlDecoration;
437 
441  void htmlAddData(const std::u32string& _data);
445  void htmlFlush();
446  public:
450  void disableCursor();
455  void setCursorPos(int32_t _cursorPos);
461  void setCursorSelection(int32_t _cursorPos, int32_t _selectionStartPos);
466  void setSelectionColor(const etk::Color<>& _color);
471  void setCursorColor(const etk::Color<>& _color);
472  };
473  }
474 }
475 
476 
const T & x() const
etk::Color m_defaultColorFg
The text foreground color.
Definition: TextBase.hpp:60
void draw(const mat4 &_transformationMatrix, bool _enableDepthTest=false)
Definition: TextBase.hpp:117
etk::Color m_defaultColorBg
The text background color.
Definition: TextBase.hpp:61
Definition: TextBase.hpp:43
etk::Color m_colorSelection
The text Selection color.
Definition: TextBase.hpp:66
vec3 m_sizeDisplayStop
The end windows of the display.
Definition: TextBase.hpp:53
std::vector< etk::Color< float > > m_coordColor
internal color of the different point
Definition: TextBase.hpp:90
void setDefaultColorFg(const etk::Color<> &_color)
set the default Foreground color of the font (when reset, set this value ...)
Definition: TextBase.hpp:170
int32_t m_GLColor
openGL id on the element (color buffer)
Definition: TextBase.hpp:79
vec3 calculateSize(const char32_t &_charcode)
calculate a theoric charcode size
Definition: TextBase.hpp:404
int32_t m_cursorPos
Cursor position (default no cursor == > -100)
Definition: TextBase.hpp:86
void draw(bool _disableDepthTest=true)
draw All the refistered text in the current element on openGL
Definition: TextBase.hpp:113
This class represent the specific display for every char in the string ... .
Definition: TextBase.hpp:23
Definition: Drawing.hpp:17
vec3 m_position
The current position to draw.
Definition: TextBase.hpp:55
int32_t m_selectionStartPos
start position of the Selection (if == m_cursorPos ==> no selection)
Definition: TextBase.hpp:85
vec3 m_sizeDisplayStart
The start windows of the display.
Definition: TextBase.hpp:52
mode
Definition: TexturedFont.hpp:16
void setColor(const etk::Color<> &_color)
set the Color of the current foreground font
Definition: TextBase.hpp:177
etk::Color m_colorBg
display background color
Definition: TextBase.hpp:25
char32_t m_previousCharcode
we remember the previous charcode to perform the kerning. Kerning
Definition: TextBase.hpp:70
float m_startTextpos
start position of the Alignement (when the text return at this position)
Definition: TextBase.hpp:72
const Color blue
int32_t m_GLtexture
openGL id on the element (Texture position)
Definition: TextBase.hpp:80
std::u32string m_htmlCurrrentLine
current line for HTML display
Definition: TextBase.hpp:434
int32_t m_nbCharDisplayed
prevent some error in calculation size.
Definition: TextBase.hpp:49
Definition: Area.hpp:16
bool m_needDisplay
This just need the display and not the size rendering.
Definition: TextBase.hpp:54
vec3 m_clippingPosStop
Clipping stop position.
Definition: TextBase.hpp:57
void setClippingWidth(const vec3 &_pos, const vec3 &_width)
Request a clipping area for the text (next draw only)
Definition: TextBase.hpp:190
void setRelPos(const vec2 &_pos)
Definition: TextBase.hpp:156
void setDefaultColorBg(const etk::Color<> &_color)
set the default background color of the font (when reset, set this value ...)
Definition: TextBase.hpp:163
void setPos(const vec2 &_pos)
Definition: TextBase.hpp:147
std::vector< vec2 > m_coordTex
internal texture coordinate for every point
Definition: TextBase.hpp:89
Definition: GlyphProperty.hpp:48
etk::Color m_colorBg
The text background color.
Definition: TextBase.hpp:64
void clear()
const T & y() const
std::vector< vec3 > m_coord
internal coord of the object
Definition: TextBase.hpp:88
enum ewol::font::mode m_mode
display mode Regular/Bold/Italic/BoldItalic
Definition: TextBase.hpp:27
bool m_clippingEnable
true if the clipping must be activated
Definition: TextBase.hpp:58
vec3 m_clippingPosStart
Clipping start position.
Definition: TextBase.hpp:56
Definition: Compositing.hpp:13
int32_t m_GLtextWidth
openGL Id on the texture width
Definition: TextBase.hpp:82
TextDecoration m_htmlDecoTmp
current decoration
Definition: TextBase.hpp:436
ememory::SharedPtr< gale::resource::Program > m_GLprogram
pointer on the opengl display program
Definition: TextBase.hpp:76
int32_t m_GLtextHeight
openGL Id on the texture height
Definition: TextBase.hpp:83
void setClipping(const vec2 &_pos, const vec2 &_posEnd)
Definition: TextBase.hpp:204
etk::Color m_color
The text foreground color.
Definition: TextBase.hpp:63
int32_t m_GLMatrix
openGL id on the element (transformation matrix)
Definition: TextBase.hpp:78
ewol::compositing::Drawing m_vectorialDraw
This is used to draw background selection and other things ...
Definition: TextBase.hpp:45
std::vector< TextDecoration > m_htmlDecoration
current decoration for the HTML display
Definition: TextBase.hpp:435
const Color green
int32_t m_GLtexID
openGL id on the element (texture ID)
Definition: TextBase.hpp:81
etk::Color m_colorFg
display foreground color
Definition: TextBase.hpp:26
bool m_kerning
Kerning enable or disable on the next elements displayed.
Definition: TextBase.hpp:69
etk::Color m_colorCursor
The text cursor color.
Definition: TextBase.hpp:65
float m_stopTextPos
end of the alignement (when a string is too hight it cut at the word previously this virtual line and...
Definition: TextBase.hpp:73
int32_t m_GLPosition
openGL id on the element (vertex buffer)
Definition: TextBase.hpp:77
void setClippingWidth(const vec2 &_pos, const vec2 &_width)
Definition: TextBase.hpp:194
const vec3 & getPos()
get the current display position (sometime needed in the gui control)
Definition: TextBase.hpp:138