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