00001 #ifndef OglGui_StaticText_h
00002 #define OglGui_StaticText_h
00003
00004
00005 #ifndef OglGui_Window_h
00006 #include "OglGui/Window.h"
00007 #endif
00008
00009 namespace OglGui
00010 {
00011
00012 class StaticText : public Window
00013 {
00014 public:
00015
00016 StaticText(int x, int y, int w, int h, strconst text,
00017 bool centered=true, bool shadowed=false) :
00018 Window(x, y, w, h)
00019 {
00020 if (centered)
00021 Init(text, oglCenterAlign, oglCenterAlign, shadowed);
00022 else
00023 Init(text, oglLeftAlign, oglCenterAlign, shadowed);
00024 }
00025
00026 StaticText(Window* parent, int x, int y, int width, int height,
00027 strconst text, bool centered=true, bool shadowed=false) :
00028 Window(parent, x, y, width, height)
00029 {
00030 if (centered)
00031 Init(text, oglCenterAlign, oglCenterAlign, shadowed);
00032 else
00033 Init(text, oglLeftAlign, oglCenterAlign, shadowed);
00034 }
00035
00036 StaticText(Window* parent, int x, int y, int width, int height,
00037 strconst text, int hAlign, int vAlign=oglCenterAlign,
00038 bool shadowed=false) :
00039 Window(parent, x, y, width, height)
00040 {
00041 Init(text, hAlign, vAlign, shadowed);
00042 }
00043
00044 StaticText(Window* parent, int width, int height, strconst text,
00045 bool centered = true, bool shadowed=false) :
00046 Window(parent, width, height)
00047 {
00048 if (centered)
00049 Init(text, oglCenterAlign, oglCenterAlign, shadowed);
00050 else
00051 Init(text, oglLeftAlign, oglCenterAlign, shadowed);
00052 }
00053
00054 StaticText(Window* parent, int width, int height, strconst text,
00055 int hAlign, int vAlign=oglCenterAlign, bool shadowed=false) :
00056 Window(parent, width, height)
00057 {
00058 Init(text, hAlign, vAlign, shadowed);
00059 }
00060
00061 virtual void AlignString(int offsetX=0, int offsetY=0)
00062 {
00063 int x, y;
00064 ULONG fCol = GetState() ? GetForeground() : oglGREY;
00065
00066 oglSys.AlignTextXY(mOglWnd, (char *) mText.c_str(), mAlignH, mAlignV,
00067 mOglWnd->width, mOglWnd->height, &x, &y);
00068 y += 3 + offsetY;
00069 x += offsetX;
00070 glNormal3f(0,0,1);
00071 if (mTextShadowed)
00072 oglSys.ShadowPrintf(mOglWnd, x, y, mShadowColor, fCol,
00073 "%s", mText.c_str());
00074 else
00075 oglSys.PosColPrintf(mOglWnd, x, y, fCol, "%s", mText.c_str());
00076 }
00077
00078
00079 virtual void MouseFunc(INT msg, INT but, INT state, INT x, INT y)
00080 {
00081 Window::MouseFunc(msg, but, state, x, y);
00082 if (msg == oglMouseWheelUp || msg == oglMouseWheelDown)
00083 GetParent()->MouseFunc(msg, but, state, x, y);
00084 }
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 virtual void DisplayFunc()
00096 {
00097 Window::DisplayFunc();
00098
00099 OGC oldOGC;
00100 OGCSave(&oldOGC);
00101 AlignString(mAlignOffH, mAlignOffV);
00102 OGCRestore(&oldOGC);
00103 }
00104
00106
00107 virtual void SetText(std::string text)
00108 {
00109 mText = text;
00110 }
00111
00112 std::string GetText() const
00113 {
00114 return mText;
00115 }
00116
00117 void GetTextExtent(int& w, int& h) const
00118 {
00119 int cW, cH;
00120 oglSys.GetTextExtent(mOglWnd, mText.c_str(), &cW, &cH);
00121 w = cW;
00122 h = cH;
00123 }
00124
00125 void GetAlign(int& hAlign, int& vAlign) const
00126 {
00127 hAlign = mAlignH;
00128 vAlign = mAlignV;
00129 }
00130
00131 void SetAlign(int hAlign, int vAlign=oglCenterAlign)
00132 {
00133 mAlignH = hAlign;
00134 mAlignV = vAlign;
00135 }
00136
00137 void SetAlignOffsets(int hOff, int vOff)
00138 {
00139 mAlignOffH = hOff;
00140 mAlignOffV = vOff;
00141 }
00142
00143 void SetCentered(bool val)
00144 {
00145 mAlignH = val ? oglCenterAlign : oglLeftAlign;
00146 mAlignV = oglCenterAlign;
00147 }
00148
00149 void SetTextShadowed(bool mode=true)
00150 {
00151 mTextShadowed = mode;
00152 }
00153
00154 void SetShadowColor(ULONG shadCol)
00155 {
00156 mShadowColor = shadCol;
00157 }
00158
00159 ULONG GetShadowColor() const
00160 {
00161 return mShadowColor;
00162 }
00163
00164 protected:
00165
00166 std::string mText;
00167 int mAlignH, mAlignOffH;
00168 int mAlignV, mAlignOffV;
00169 bool mTextShadowed;
00170 ULONG mShadowColor;
00171
00172 private:
00173
00174 void Init(strconst txt, int hAlign, int vAlign, bool shadowed)
00175 {
00176 mText = txt;
00177 mAlignH = hAlign;
00178 mAlignV = vAlign;
00179 mAlignOffH = mAlignOffV = 0;
00180 mTextShadowed = shadowed;
00181 mShadowColor = oglLIGHTGREY;
00182 }
00183 };
00184
00185 }
00186 #endif