$treeview $search $mathjax
Stratagus
2.2.6
$projectbrief
|
$projectbrief
|
$searchbox |
_________ __ __ / _____// |_____________ _/ |______ ____ __ __ ______ \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/ / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ \ /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ > \/ \/ \//_____/ \/ ______________________ ______________________ T H E W A R B E G I N S Stratagus - A free fantasy real time strategy game engine
00001 // _________ __ __ 00002 // / _____// |_____________ _/ |______ ____ __ __ ______ 00003 // \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/ 00004 // / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ | 00005 // /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ > 00006 // \/ \/ \//_____/ \/ 00007 // ______________________ ______________________ 00008 // T H E W A R B E G I N S 00009 // Stratagus - A free fantasy real time strategy game engine 00010 // 00012 // 00013 // (c) Copyright 2005-2006 by Fran�ois Beerten and Jimmy Salmon 00014 // 00015 // This program is free software; you can redistribute it and/or modify 00016 // it under the terms of the GNU General Public License as published by 00017 // the Free Software Foundation; only version 2 of the License. 00018 // 00019 // This program is distributed in the hope that it will be useful, 00020 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 // GNU General Public License for more details. 00023 // 00024 // You should have received a copy of the GNU General Public License 00025 // along with this program; if not, write to the Free Software 00026 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00027 // 02111-1307, USA. 00028 // 00029 00030 #ifndef __WIDGETS_H__ 00031 #define __WIDGETS_H__ 00032 00033 #include <guichan.h> 00034 #include <guichan/gsdl.h> 00035 #include "font.h" 00036 00037 #include "luacallback.h" 00038 00039 00040 extern bool GuichanActive; 00041 00042 void initGuichan(); 00043 void freeGuichan(); 00044 void handleInput(const SDL_Event *event); 00045 00046 class LuaActionListener : public gcn::ActionListener 00047 { 00048 LuaCallback callback; 00049 public: 00050 LuaActionListener(lua_State *lua, lua_Object function); 00051 virtual void action(const std::string &eventId); 00052 virtual ~LuaActionListener(); 00053 }; 00054 00055 class MyOpenGLGraphics : public gcn::Graphics 00056 { 00057 public: 00058 virtual void _beginDraw(); 00059 virtual void _endDraw(); 00060 00061 virtual void drawImage(const gcn::Image *image, int srcX, int srcY, 00062 int dstX, int dstY, int width, int height); 00063 00064 virtual void drawPoint(int x, int y); 00065 virtual void drawLine(int x1, int y1, int x2, int y2); 00066 virtual void drawRectangle(const gcn::Rectangle &rectangle); 00067 virtual void fillRectangle(const gcn::Rectangle &rectangle); 00068 00069 virtual void setColor(const gcn::Color &color) { mColor = color; } 00070 virtual const gcn::Color &getColor() { return mColor; } 00071 00072 private: 00073 gcn::Color mColor; 00074 }; 00075 00076 class ImageWidget : public gcn::Icon 00077 { 00078 public: 00079 ImageWidget(gcn::Image *img) : gcn::Icon(img) {} 00080 }; 00081 00082 class ButtonWidget : public gcn::Button 00083 { 00084 public: 00085 ButtonWidget(const std::string &caption) : Button(caption) 00086 { 00087 this->setHotKey(GetHotKey(caption)); 00088 } 00089 }; 00090 00091 class ImageButton : public gcn::Button 00092 { 00093 public: 00094 ImageButton(); 00095 ImageButton(const std::string &caption); 00096 00097 virtual void draw(gcn::Graphics *graphics); 00098 virtual void adjustSize(); 00099 00100 void setNormalImage(gcn::Image *image) { normalImage = image; adjustSize(); } 00101 void setPressedImage(gcn::Image *image) { pressedImage = image; } 00102 void setDisabledImage(gcn::Image *image) { disabledImage = image; } 00103 00104 gcn::Image *normalImage; 00105 gcn::Image *pressedImage; 00106 gcn::Image *disabledImage; 00107 }; 00108 00109 class ImageRadioButton : public gcn::RadioButton 00110 { 00111 public: 00112 ImageRadioButton(); 00113 ImageRadioButton(const std::string &caption, const std::string &group, 00114 bool marked); 00115 00116 virtual void drawBox(gcn::Graphics *graphics); 00117 virtual void draw(gcn::Graphics *graphics); 00118 00119 virtual void mousePress(int x, int y, int button); 00120 virtual void mouseRelease(int x, int y, int button); 00121 virtual void mouseClick(int x, int y, int button, int count); 00122 virtual void adjustSize(); 00123 00124 void setUncheckedNormalImage(gcn::Image *image) { uncheckedNormalImage = image; } 00125 void setUncheckedPressedImage(gcn::Image *image) { uncheckedPressedImage = image; } 00126 void setCheckedNormalImage(gcn::Image *image) { checkedNormalImage = image; } 00127 void setCheckedPressedImage(gcn::Image *image) { checkedPressedImage = image; } 00128 00129 gcn::Image *uncheckedNormalImage; 00130 gcn::Image *uncheckedPressedImage; 00131 gcn::Image *checkedNormalImage; 00132 gcn::Image *checkedPressedImage; 00133 bool mMouseDown; 00134 }; 00135 00136 class ImageCheckBox : public gcn::CheckBox 00137 { 00138 public: 00139 ImageCheckBox(); 00140 ImageCheckBox(const std::string &caption, bool marked = false); 00141 00142 virtual void draw(gcn::Graphics *graphics); 00143 virtual void drawBox(gcn::Graphics *graphics); 00144 00145 virtual void mousePress(int x, int y, int button); 00146 virtual void mouseRelease(int x, int y, int button); 00147 virtual void mouseClick(int x, int y, int button, int count); 00148 virtual void adjustSize(); 00149 00150 void setUncheckedNormalImage(gcn::Image *image) { uncheckedNormalImage = image; } 00151 void setUncheckedPressedImage(gcn::Image *image) { uncheckedPressedImage = image; } 00152 void setCheckedNormalImage(gcn::Image *image) { checkedNormalImage = image; } 00153 void setCheckedPressedImage(gcn::Image *image) { checkedPressedImage = image; } 00154 00155 gcn::Image *uncheckedNormalImage; 00156 gcn::Image *uncheckedPressedImage; 00157 gcn::Image *checkedNormalImage; 00158 gcn::Image *checkedPressedImage; 00159 bool mMouseDown; 00160 }; 00161 00162 class ImageSlider : public gcn::Slider 00163 { 00164 public: 00165 ImageSlider(double scaleEnd = 1.0); 00166 ImageSlider(double scaleStart, double scaleEnd); 00167 00168 virtual void drawMarker(gcn::Graphics* graphics); 00169 virtual void draw(gcn::Graphics* graphics); 00170 00171 void setMarkerImage(gcn::Image *image); 00172 void setBackgroundImage(gcn::Image *image); 00173 00174 gcn::Image *markerImage; 00175 gcn::Image *backgroundImage; 00176 }; 00177 00178 class MultiLineLabel : public gcn::Widget 00179 { 00180 public: 00181 MultiLineLabel(); 00182 MultiLineLabel(const std::string &caption); 00183 00184 virtual void setCaption(const std::string &caption); 00185 virtual const std::string &getCaption() const; 00186 virtual void setAlignment(unsigned int alignment); 00187 virtual unsigned int getAlignment(); 00188 virtual void setVerticalAlignment(unsigned int alignment); 00189 virtual unsigned int getVerticalAlignment(); 00190 virtual void setLineWidth(int width); 00191 virtual int getLineWidth(); 00192 virtual void adjustSize(); 00193 virtual void draw(gcn::Graphics *graphics); 00194 virtual void drawBorder(gcn::Graphics *graphics); 00195 00196 enum { 00197 LEFT = 0, 00198 CENTER, 00199 RIGHT, 00200 TOP, 00201 BOTTOM 00202 }; 00203 00204 private: 00205 void wordWrap(); 00206 00207 std::string mCaption; 00208 std::vector<std::string> mTextRows; 00209 unsigned int mAlignment; 00210 unsigned int mVerticalAlignment; 00211 int mLineWidth; 00212 }; 00213 00214 class ScrollingWidget : public gcn::ScrollArea 00215 { 00216 public: 00217 ScrollingWidget(int width, int height); 00218 void add(gcn::Widget *widget, int x, int y); 00219 void restart(); 00220 void setSpeed(float speed) { this->speedY = speed; } 00221 float getSpeed() { return this->speedY; } 00222 private: 00223 virtual void logic(); 00224 private: 00225 gcn::Container container; 00226 float speedY; 00227 float containerY; 00228 bool finished; 00229 }; 00230 00231 class Windows : public gcn::Window 00232 { 00233 public: 00234 Windows(const std::string &text, int width, int height); 00235 void add(gcn::Widget *widget, int x, int y); 00236 private: 00237 virtual void mouseMotion(int x, int y); 00238 virtual void setBackgroundColor(const gcn::Color &color); 00239 virtual void setBaseColor(const gcn::Color &color); 00240 private: 00241 gcn::ScrollArea scroll; 00242 gcn::Container container; 00243 bool blockwholewindow; 00244 00245 }; 00246 00247 class LuaListModel : public gcn::ListModel 00248 { 00249 std::vector<std::string> list; 00250 public: 00251 LuaListModel() {} 00252 00253 void setList(lua_State *lua, lua_Object *lo); 00254 virtual int getNumberOfElements() {return list.size();} 00255 virtual std::string getElementAt(int i) {return list[i];} 00256 }; 00257 00258 class ListBoxWidget : public gcn::ScrollArea 00259 { 00260 public: 00261 ListBoxWidget(unsigned int width, unsigned int height); 00262 void setList(lua_State *lua, lua_Object *lo); 00263 void setSelected(int i); 00264 int getSelected() const; 00265 virtual void setBackgroundColor(const gcn::Color &color); 00266 virtual void setFont(gcn::Font *font); 00267 virtual void addActionListener(gcn::ActionListener *actionListener); 00268 private: 00269 void adjustSize(); 00270 private: 00271 LuaListModel lualistmodel; 00272 gcn::ListBox listbox; 00273 }; 00274 00275 class DropDownWidget : public gcn::DropDown 00276 { 00277 LuaListModel listmodel; 00278 public: 00279 DropDownWidget() {} 00280 void setList(lua_State *lua, lua_Object *lo); 00281 virtual void setSize(int width, int height); 00282 }; 00283 00284 class StatBoxWidget : public gcn::Widget 00285 { 00286 public: 00287 StatBoxWidget(int width, int height); 00288 00289 virtual void draw(gcn::Graphics *graphics); 00290 void setCaption(const std::string &s); 00291 const std::string &getCaption() const; 00292 void setPercent(const int percent); 00293 int getPercent() const; 00294 00295 private: 00296 int width; 00297 int height; 00298 std::string caption; 00299 unsigned int percent; 00300 }; 00301 00302 class MenuScreen : public gcn::Container 00303 { 00304 public: 00305 MenuScreen(); 00306 00307 int run(bool loop = true); 00308 void stop(int result = 0, bool stopAll = false); 00309 void stopAll(int result = 0) { stop(result, true); } 00310 void addLogicCallback(LuaActionListener *listener); 00311 virtual void draw(gcn::Graphics *graphics); 00312 virtual void logic(); 00313 void setDrawMenusUnder(bool drawUnder) { this->drawUnder = drawUnder; } 00314 bool getDrawMenusUnder() { return this->drawUnder; } 00315 00316 private: 00317 bool runLoop; 00318 int loopResult; 00319 gcn::Widget *oldtop; 00320 LuaActionListener *logiclistener; 00321 bool drawUnder; 00322 }; 00323 00324 #endif 00325