Epee Engine  0.40
The Epee Engine is an open source cross platform graphics engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
EETextBox.h
Go to the documentation of this file.
1 /*
2 * EETextBox.h
3 *
4 *
5 * Epee Engine
6 * Created by Alan Uthoff on 3/12/06.
7 Copyright (C) 2011
8 
9 This Code is free software; you can redistribute it and/or
10 modify it under the terms of the zlib/libpng License as published
11 by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13 This software is provided 'as-is', without any express or implied warranty.
14 
15 In no event will the authors be held liable for any damages arising from the use of this software.
16 
17 Permission is granted to anyone to use this software for any purpose,
18 including commercial applications, and to alter it and redistribute
19 it freely, subject to the following restrictions:
20 
21 1. The origin of this software must not be misrepresented;
22 you must not claim that you wrote the original software.
23 If you use this software in a product, an acknowledgment
24 in the product documentation would be appreciated but is not required.
25 
26 2. Altered source versions must be plainly marked as such,
27 and must not be misrepresented as being the original software.
28 
29 3. This notice may not be removed or altered from any source distribution.
30 
31 
32 */
33 
34 #ifndef EETEXTBOX_H
35 #define EETEXTBOX_H
36 
38 #include <iostream>
39 #include <sstream>
40 #include "EEWidget.h"
41 #include "EpeeUtility.h"
42 #include "EELog.h"
43 //***********************Begin of textBox Class****************************
44 class textBox :public EEWidget
45 {
46 private:
47  std::string m_sTrue_Type_Font_Location;
48  std::string m_sTextBoxMessage;
49  std::string m_sFont;
50  int m_iFontPoint;
51  SDL_Color m_cColorOfText;
52  SDL_Color m_cBackGroundColor;
53  SDL_Color m_cColorOfSelectedText;
54  SDL_Color m_cSelectedBackGroundColor;
55  bool m_bblit;
56  TTF_Font *m_pLoadedFont;
57  bool m_bEditable;
58  bool m_bNumbersOnly;
59  int m_iJustify;
60  int m_iOffsetXJustiy;
61  bool m_bDoNotClipTextHeight;
62  bool m_bDoNotClipTextWidth;
63  int m_bQuality;
64  bool m_bChangeTextBoxColorOnClick;
65  SDL_Rect m_cModBox;
66 
67 public:
68 
69 protected:
70  textBox(int _Obj_Type,const std::string & _NameTextBox,int _x,int _y,int _z,const std::string & _TextBoxMessage=" ",unsigned int _height=-1,unsigned int _width=-1,const std::string & _Font=True_Type_Font_Defalut,int _FontPoint=18,unsigned int _red=255,unsigned int _blue=255 ,unsigned int _green=255,const std::string & _FontPath = True_Type_Font_Location);//:EEWidget(_NameTextBox,_Obj_Type);
71  virtual void SetModifySurFace(SDL_Surface * _ModifySurface);
72  virtual void Render();
73 public:
74  textBox(const std::string & _NameTextBox, int _x, int _y,int _z,const std::string & _TextBoxMessage=" ",unsigned int _height=-1,unsigned int _width=-1,const std::string & _Font=True_Type_Font_Defalut,int _FontPoint=18,unsigned int _red=255,unsigned int _blue=255 ,unsigned int _green=255,const std::string & _FontPath = True_Type_Font_Location);//:EEWidget(_NameTextBox,Type_TextBox);
75  textBox();
76  ~textBox();
77 
78  friend class EpeeEngine;
79 
80  SDL_Surface * LoadSurface();
81  bool GetClipTextHeight();
82  bool GetClipTextWidth();
83  void SetQuality(int _Quality);
84  int GetQuality();
85  void SetText(const std::string & _text,bool _setevent=false);
86  virtual void SetHeightWidth(unsigned int _Height,unsigned int _Width);
89  int GetJustifyOffset();
91  void SetTextJustification(int _justify);
92  std::string GetText ();
93  bool GetTextToInt(int & _value);
94  bool GetTextToFloat(float & _value);
95  bool SetTextFromInt(int _value,bool _setevent=false);
96  bool SetTextFromFloat(float _value,bool _setevent=false);
97  std::string GetFont();
98  void SetFont(const std::string & _FontArg);
99  int GetFontPoint();
100  void SetFontPoint(int _FontPointArg);
101  SDL_Color GetBackGroundColor();
102  bool SetBackGroundColor(unsigned int _red,unsigned int _blue ,unsigned int _green);
103  SDL_Color GetTextColor();
104  bool SetTextColor(unsigned int _red,unsigned int _blue ,unsigned int _green);
105  std::string GetFontPath();
106  void SetFontPath(const std::string & _Location);
107  void SetEditable(bool _flag);
108  bool GetEditable();
109  void SetNumbersOnly(bool _flag);
110  bool GetNumbersOnly();
111  bool IsColorChangedOnClick();
112  void SetColorChangedOnClick(bool _ChangeOnClick);
113  void SetSelectBackGroundColor(unsigned int _red,unsigned int _blue ,unsigned int _green);
114  void SetSelectTextColor(unsigned int _red,unsigned int _blue ,unsigned int _green);
115  virtual EEWidget * WasClicked(int _mouselocationX, int _mouselocationY);
116  // template <class datatype>
117  // datatype GetTextToNumericData(datatype _type);
118 
119  // template <class datatype>
120  // bool SetTextFromNumericData(datatype _value,bool _setevent);
121  template <class datatype>
122  bool GetTextToNumericData(datatype &_type)
123  {
124  if (!EpeeUtility::StringToNumericData(m_sTextBoxMessage,_type))
125  {
126  EE_WARNING<<"Could not convert \""+m_sTextBoxMessage+"\" to the specified data type"<<std::endl;
127  return false;
128  }
129  return true;
130  }
131 
132  template <class datatype>
133  bool SetTextFromNumericData(datatype _value,bool _setevent)
134  {
135  datatype tempint=_value;
136  std::string tempstr= " ";
137  if (!EpeeUtility::StringFromNumericData(tempstr, tempint))
138  {
139 
140  EE_DEBUG<<"Could not convert numeric data "<<_value<<" to string";
141  return false;
142 
143  }
144  this->SetText(tempstr,_setevent);
145  return true;
146  }
147 
148 
149  bool WillTextFitIntoBox(std::string _text);
150 protected:
151  TTF_Font * GetFontPointer();
152 
153  void LoadFont();
154 protected:
155  void SetJustifyOffset();
156 };
157 //***********************End of textBox Class****************************
158 
159 #endif // EETEXTBOX_H
void SetTextJustification(int _justify)
Definition: EETextBox.cpp:490
bool GetEditable()
Definition: EETextBox.cpp:606
std::string GetFont()
Definition: EETextBox.cpp:525
bool SetTextFromFloat(float _value, bool _setevent=false)
Definition: EETextBox.cpp:519
bool GetClipTextHeight()
Definition: EETextBox.cpp:343
void SetNumbersOnly(bool _flag)
Definition: EETextBox.cpp:611
void SetFont(const std::string &_FontArg)
Definition: EETextBox.cpp:530
SDL_Color GetTextColor()
Definition: EETextBox.cpp:553
bool GetClipTextWidth()
Definition: EETextBox.cpp:348
virtual void SetModifySurFace(SDL_Surface *_ModifySurface)
Definition: EETextBox.cpp:232
void SetText(const std::string &_text, bool _setevent=false)
Definition: EETextBox.cpp:368
virtual void SetHeightWidth(unsigned int _Height, unsigned int _Width)
Definition: EETextBox.cpp:407
int GetJustifyOffset()
Definition: EETextBox.cpp:480
int GetTextJustification()
Definition: EETextBox.cpp:485
std::string GetText()
Definition: EETextBox.cpp:499
Definition: EpeeEngine.h:101
void SetHightBasedOfRenderedText()
Definition: EETextBox.cpp:451
#define EE_DEBUG
Definition: EELog.h:28
SDL_Surface * LoadSurface()
Definition: EETextBox.cpp:630
textBox()
Definition: EETextBox.cpp:248
virtual void Render()
Definition: EETextBox.cpp:125
bool StringToNumericData(const std::string &_stringtoconvert, datatype &_temp)
Definition: EpeeUtility.h:40
void SetFontPoint(int _FontPointArg)
Definition: EETextBox.cpp:545
SDL_Color GetBackGroundColor()
Definition: EETextBox.cpp:570
void SetSelectBackGroundColor(unsigned int _red, unsigned int _blue, unsigned int _green)
Definition: EETextBox.cpp:317
bool GetTextToInt(int &_value)
Definition: EETextBox.cpp:504
bool StringFromNumericData(std::string &_dataString, datatype _value)
Definition: EpeeUtility.h:57
#define EE_WARNING
Definition: EELog.h:26
bool GetTextToFloat(float &_value)
Definition: EETextBox.cpp:509
void SetQuality(int _Quality)
Definition: EETextBox.cpp:353
int GetFontPoint()
Definition: EETextBox.cpp:540
void SetFontPath(const std::string &_Location)
Definition: EETextBox.cpp:592
void SetEditable(bool _flag)
Definition: EETextBox.cpp:598
void LoadFont()
Definition: EETextBox.cpp:689
bool SetTextColor(unsigned int _red, unsigned int _blue, unsigned int _green)
Definition: EETextBox.cpp:558
bool GetNumbersOnly()
Definition: EETextBox.cpp:617
void SetColorChangedOnClick(bool _ChangeOnClick)
Definition: EETextBox.cpp:338
bool SetTextFromNumericData(datatype _value, bool _setevent)
Definition: EETextBox.h:133
bool SetTextFromInt(int _value, bool _setevent=false)
Definition: EETextBox.cpp:514
Definition: EETextBox.h:44
Definition: EEWidget.h:43
~textBox()
Definition: EETextBox.cpp:252
int GetQuality()
Definition: EETextBox.cpp:362
std::string GetFontPath()
Definition: EETextBox.cpp:587
bool SetBackGroundColor(unsigned int _red, unsigned int _blue, unsigned int _green)
Definition: EETextBox.cpp:574
virtual EEWidget * WasClicked(int _mouselocationX, int _mouselocationY)
Definition: EETextBox.cpp:280
bool WillTextFitIntoBox(std::string _text)
Definition: EETextBox.cpp:260
bool IsColorChangedOnClick()
Definition: EETextBox.cpp:333
TTF_Font * GetFontPointer()
Definition: EETextBox.cpp:623
void SetWidthBasedOfRenderedText()
Definition: EETextBox.cpp:466
void SetJustifyOffset()
Definition: EETextBox.cpp:712
bool GetTextToNumericData(datatype &_type)
Definition: EETextBox.h:122
void SetSelectTextColor(unsigned int _red, unsigned int _blue, unsigned int _green)
Definition: EETextBox.cpp:324