$treeview $search $mathjax
Stratagus
2.2.7
$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 explicit ImageWidget(gcn::Image *img) : gcn::Icon(img) {} 00080 }; 00081 00082 class ButtonWidget : public gcn::Button 00083 { 00084 public: 00085 explicit ButtonWidget(const std::string &caption) : Button(caption) { 00086 this->setHotKey(GetHotKey(caption)); 00087 } 00088 }; 00089 00090 class ImageButton : public gcn::Button 00091 { 00092 public: 00093 ImageButton(); 00094 explicit ImageButton(const std::string &caption); 00095 00096 virtual void draw(gcn::Graphics *graphics); 00097 virtual void adjustSize(); 00098 00099 void setNormalImage(gcn::Image *image) { normalImage = image; adjustSize(); } 00100 void setPressedImage(gcn::Image *image) { pressedImage = image; } 00101 void setDisabledImage(gcn::Image *image) { disabledImage = image; } 00102 00103 gcn::Image *normalImage; 00104 gcn::Image *pressedImage; 00105 gcn::Image *disabledImage; 00106 }; 00107 00108 class ImageRadioButton : public gcn::RadioButton 00109 { 00110 public: 00111 ImageRadioButton(); 00112 ImageRadioButton(const std::string &caption, const std::string &group, 00113 bool marked); 00114 00115 virtual void drawBox(gcn::Graphics *graphics); 00116 virtual void draw(gcn::Graphics *graphics); 00117 00118 virtual void mousePress(int x, int y, int button); 00119 virtual void mouseRelease(int x, int y, int button); 00120 virtual void mouseClick(int x, int y, int button, int count); 00121 virtual void adjustSize(); 00122 00123 void setUncheckedNormalImage(gcn::Image *image) { uncheckedNormalImage = image; } 00124 void setUncheckedPressedImage(gcn::Image *image) { uncheckedPressedImage = image; } 00125 void setCheckedNormalImage(gcn::Image *image) { checkedNormalImage = image; } 00126 void setCheckedPressedImage(gcn::Image *image) { checkedPressedImage = image; } 00127 00128 gcn::Image *uncheckedNormalImage; 00129 gcn::Image *uncheckedPressedImage; 00130 gcn::Image *checkedNormalImage; 00131 gcn::Image *checkedPressedImage; 00132 bool mMouseDown; 00133 }; 00134 00135 class ImageCheckBox : public gcn::CheckBox 00136 { 00137 public: 00138 ImageCheckBox(); 00139 ImageCheckBox(const std::string &caption, bool marked = false); 00140 00141 virtual void draw(gcn::Graphics *graphics); 00142 virtual void drawBox(gcn::Graphics *graphics); 00143 00144 virtual void mousePress(int x, int y, int button); 00145 virtual void mouseRelease(int x, int y, int button); 00146 virtual void mouseClick(int x, int y, int button, int count); 00147 virtual void adjustSize(); 00148 00149 void setUncheckedNormalImage(gcn::Image *image) { uncheckedNormalImage = image; } 00150 void setUncheckedPressedImage(gcn::Image *image) { uncheckedPressedImage = image; } 00151 void setCheckedNormalImage(gcn::Image *image) { checkedNormalImage = image; } 00152 void setCheckedPressedImage(gcn::Image *image) { checkedPressedImage = image; } 00153 00154 gcn::Image *uncheckedNormalImage; 00155 gcn::Image *uncheckedPressedImage; 00156 gcn::Image *checkedNormalImage; 00157 gcn::Image *checkedPressedImage; 00158 bool mMouseDown; 00159 }; 00160 00161 class ImageSlider : public gcn::Slider 00162 { 00163 public: 00164 explicit ImageSlider(double scaleEnd = 1.0); 00165 ImageSlider(double scaleStart, double scaleEnd); 00166 00167 virtual void drawMarker(gcn::Graphics *graphics); 00168 virtual void draw(gcn::Graphics *graphics); 00169 00170 void setMarkerImage(gcn::Image *image); 00171 void setBackgroundImage(gcn::Image *image); 00172 00173 gcn::Image *markerImage; 00174 gcn::Image *backgroundImage; 00175 }; 00176 00177 class MultiLineLabel : public gcn::Widget 00178 { 00179 public: 00180 MultiLineLabel(); 00181 explicit MultiLineLabel(const std::string &caption); 00182 00183 virtual void setCaption(const std::string &caption); 00184 virtual const std::string &getCaption() const; 00185 virtual void setAlignment(unsigned int alignment); 00186 virtual unsigned int getAlignment(); 00187 virtual void setVerticalAlignment(unsigned int alignment); 00188 virtual unsigned int getVerticalAlignment(); 00189 virtual void setLineWidth(int width); 00190 virtual int getLineWidth(); 00191 virtual void adjustSize(); 00192 virtual void draw(gcn::Graphics *graphics); 00193 virtual void drawBorder(gcn::Graphics *graphics); 00194 00195 enum { 00196 LEFT = 0, 00197 CENTER, 00198 RIGHT, 00199 TOP, 00200 BOTTOM 00201 }; 00202 00203 private: 00204 void wordWrap(); 00205 00206 std::string mCaption; 00207 std::vector<std::string> mTextRows; 00208 unsigned int mAlignment; 00209 unsigned int mVerticalAlignment; 00210 int mLineWidth; 00211 }; 00212 00213 class ScrollingWidget : public gcn::ScrollArea 00214 { 00215 public: 00216 ScrollingWidget(int width, int height); 00217 void add(gcn::Widget *widget, int x, int y); 00218 void restart(); 00219 void setSpeed(float speed) { this->speedY = speed; } 00220 float getSpeed() const { return this->speedY; } 00221 private: 00222 virtual void logic(); 00223 private: 00224 gcn::Container container; 00225 float speedY; 00226 float containerY; 00227 bool finished; 00228 }; 00229 00230 class Windows : public gcn::Window 00231 { 00232 public: 00233 Windows(const std::string &text, int width, int height); 00234 void add(gcn::Widget *widget, int x, int y); 00235 private: 00236 virtual void mouseMotion(int x, int y); 00237 virtual void setBackgroundColor(const gcn::Color &color); 00238 virtual void setBaseColor(const gcn::Color &color); 00239 private: 00240 gcn::ScrollArea scroll; 00241 gcn::Container container; 00242 bool blockwholewindow; 00243 00244 }; 00245 00246 class LuaListModel : public gcn::ListModel 00247 { 00248 std::vector<std::string> list; 00249 public: 00250 LuaListModel() {} 00251 00252 void setList(lua_State *lua, lua_Object *lo); 00253 virtual int getNumberOfElements() {return list.size();} 00254 virtual std::string getElementAt(int i) {return list[i];} 00255 }; 00256 00257 class ListBoxWidget : public gcn::ScrollArea 00258 { 00259 public: 00260 ListBoxWidget(unsigned int width, unsigned int height); 00261 void setList(lua_State *lua, lua_Object *lo); 00262 void setSelected(int i); 00263 int getSelected() const; 00264 virtual void setBackgroundColor(const gcn::Color &color); 00265 virtual void setFont(gcn::Font *font); 00266 virtual void addActionListener(gcn::ActionListener *actionListener); 00267 private: 00268 void adjustSize(); 00269 private: 00270 LuaListModel lualistmodel; 00271 gcn::ListBox listbox; 00272 }; 00273 00274 class DropDownWidget : public gcn::DropDown 00275 { 00276 LuaListModel listmodel; 00277 public: 00278 DropDownWidget() {} 00279 void setList(lua_State *lua, lua_Object *lo); 00280 virtual void setSize(int width, int height); 00281 }; 00282 00283 class StatBoxWidget : public gcn::Widget 00284 { 00285 public: 00286 StatBoxWidget(int width, int height); 00287 00288 virtual void draw(gcn::Graphics *graphics); 00289 void setCaption(const std::string &s); 00290 const std::string &getCaption() const; 00291 void setPercent(const int percent); 00292 int getPercent() const; 00293 00294 private: 00295 int width; 00296 int height; 00297 std::string caption; 00298 unsigned int percent; 00299 }; 00300 00301 class MenuScreen : public gcn::Container 00302 { 00303 public: 00304 MenuScreen(); 00305 00306 int run(bool loop = true); 00307 void stop(int result = 0, bool stopAll = false); 00308 void stopAll(int result = 0) { stop(result, true); } 00309 void addLogicCallback(LuaActionListener *listener); 00310 virtual void draw(gcn::Graphics *graphics); 00311 virtual void logic(); 00312 void setDrawMenusUnder(bool drawUnder) { this->drawUnder = drawUnder; } 00313 bool getDrawMenusUnder() const { return this->drawUnder; } 00314 00315 private: 00316 bool runLoop; 00317 int loopResult; 00318 gcn::Widget *oldtop; 00319 LuaActionListener *logiclistener; 00320 bool drawUnder; 00321 }; 00322 00323 #endif