1 /* _______ __ __ __ ______ __ __ _______ __ __ 2 * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ 3 * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / 4 * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / 5 * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / 6 * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / 7 * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ 8 * 9 * Copyright (c) 2004, 2005 darkbits Js_./ 10 * Per Larsson a.k.a finalman _RqZ{a<^_aa 11 * Olof Naess�n a.k.a jansem/yakslem _asww7!uY`> )\a// 12 * _Qhm`] _f "'c 1!5m 13 * Visit: http://guichan.darkbits.org )Qk<P ` _: :+' .' "{[ 14 * .)j(] .d_/ '-( P . S 15 * License: (BSD) <Td/Z <fP"5(\"??"\a. .L 16 * Redistribution and use in source and _dV>ws?a-?' ._/L #' 17 * binary forms, with or without )4d[#7r, . ' )d`)[ 18 * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' 19 * that the following conditions are met: j<<WP+k/);. _W=j f 20 * 1. Redistributions of source code must .$%w\/]Q . ."' . mj$ 21 * retain the above copyright notice, ]E.pYY(Q]>. a J@\ 22 * this list of conditions and the j(]1u<sE"L,. . ./^ ]{a 23 * following disclaimer. 4'_uomm\. )L);-4 (3= 24 * 2. Redistributions in binary form must )_]X{Z('a_"a7'<a"a, ]"[ 25 * reproduce the above copyright notice, #}<]m7`Za??4,P-"'7. ).m 26 * this list of conditions and the ]d2e)Q(<Q( ?94 b- LQ/ 27 * following disclaimer in the <B!</]C)d_, '(<' .f. =C+m 28 * documentation and/or other materials .Z!=J ]e []('-4f _ ) -.)m]' 29 * provided with the distribution. .w[5]' _[ /.)_-"+? _/ <W" 30 * 3. Neither the name of Guichan nor the :$we` _! + _/ . j? 31 * names of its contributors may be used =3)= _f (_yQmWW$#( " 32 * to endorse or promote products derived - W, sQQQQmZQ#Wwa].. 33 * from this software without specific (js, \[QQW$QWW#?!V"". 34 * prior written permission. ]y:.<\.. . 35 * -]n w/ ' [. 36 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT )/ )/ ! 37 * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY < (; sac , ' 38 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, ]^ .- % 39 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF c < r 40 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR aga< <La 41 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 5% )P'-3L 42 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR _bQf` y`..)a 43 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, ,J?4P'.P"_(\?d'., 44 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES _Pa,)!f/<[]/ ?" 45 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT _2-..:. .r+_,.. . 46 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ?a.<%"' " -'.a_ _, 47 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ^ 48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 49 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 50 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 51 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 52 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 53 */ 54 55 #ifndef GCN_WINDOW_HPP 56 #define GCN_WINDOW_HPP 57 58 #include <string> 59 60 #include "guichan/platform.h" 61 #include "guichan/basiccontainer.h" 62 63 namespace gcn 64 { 65 /** 66 * A movable window which can conatin another Widget. 67 */ 68 class GCN_CORE_DECLSPEC Window : public BasicContainer, 69 public MouseListener 70 { 71 public: 72 /** 73 * Constructor. 74 */ 75 Window(); 76 77 /** 78 * Constructor. 79 * 80 * @param caption the Window caption. 81 */ 82 Window(const std::string& caption); 83 84 /** 85 * Constructor. 86 * 87 * @param content the content Widget. 88 * @param caption the Window caption. 89 */ 90 Window(Widget* content, const std::string& caption = ""); 91 92 /** 93 * Destructor. 94 */ 95 virtual ~Window(); 96 97 /** 98 * Sets the Window caption. 99 * 100 * @param caption the Window caption. 101 */ 102 virtual void setCaption(const std::string& caption); 103 104 /** 105 * Gets the Window caption. 106 * 107 * @return the Window caption. 108 */ 109 virtual const std::string& getCaption() const; 110 111 /** 112 * Sets the alignment for the caption. 113 * 114 * @param alignment Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT. 115 */ 116 virtual void setAlignment(unsigned int alignment); 117 118 /** 119 * Gets the alignment for the caption. 120 * 121 * @return alignment of caption. 122 */ 123 virtual unsigned int getAlignment() const; 124 125 /** 126 * Sets the content Widget. 127 * 128 * @param widget the contant Widget. 129 */ 130 virtual void setContent(Widget* widget); 131 132 /** 133 * Gets the content Widget. 134 * 135 * @return the contant Widget. 136 */ 137 virtual Widget* getContent() const; 138 139 /** 140 * Sets the padding of the window which is the distance between the 141 * window border and the content. 142 * 143 * @param padding the padding value. 144 */ 145 virtual void setPadding(unsigned int padding); 146 147 /** 148 * Gets the padding. 149 * 150 * @return the padding value. 151 */ 152 virtual unsigned int getPadding() const; 153 154 /** 155 * Sets the title bar height. 156 * 157 * @param height the title height value. 158 */ 159 virtual void setTitleBarHeight(unsigned int height); 160 161 /** 162 * Gets the title bar height. 163 * 164 * @return the title bar height. 165 */ 166 virtual unsigned int getTitleBarHeight(); 167 168 /** 169 * Sets the Window to be moveble. 170 * 171 * @param movable true or false. 172 */ 173 virtual void setMovable(bool movable); 174 175 /** 176 * Check if the window is movable. 177 * 178 * @return true or false. 179 */ 180 virtual bool isMovable() const; 181 182 /** 183 * Resizes the window to fit the content. 184 */ 185 virtual void resizeToContent(); 186 187 /** 188 * Sets the Window to be opaque. If it's not opaque, the content area 189 * will not be filled with a color. 190 * 191 * @param opaque true or false. 192 */ 193 virtual void setOpaque(bool opaque); 194 195 /** 196 * Checks if the Window is opaque. 197 * 198 * @return true or false. 199 */ 200 virtual bool isOpaque(); 201 202 /** 203 * Draws the content of the Window. This functions uses the 204 * getContentDimension to determin where to draw the content. 205 * 206 * @param graphics a Graphics object to draw with. 207 */ 208 virtual void drawContent(Graphics* graphics); 209 210 211 // Inherited from BasicContainer 212 213 virtual void moveToTop(Widget* widget); 214 215 virtual void moveToBottom(Widget* widget); 216 217 virtual void getDrawSize(int& width, int& height, Widget* widget); 218 219 virtual void _announceDeath(Widget *widget); 220 221 222 // Inherited from Widget 223 224 virtual void draw(Graphics* graphics); 225 226 virtual void drawBorder(Graphics* graphics); 227 228 virtual void logic(); 229 230 virtual void _mouseInputMessage(const MouseInput &mouseInput); 231 232 virtual void _mouseOutMessage(); 233 234 virtual void _setFocusHandler(FocusHandler* focusHandler); 235 236 237 // Inherited from MouseListener 238 239 virtual void mousePress(int x, int y, int button); 240 241 virtual void mouseRelease(int x, int y, int button); 242 243 virtual void mouseMotion(int x, int y); 244 245 virtual void setDirty(bool dirty); 246 virtual bool getDirty() const; 247 248 protected: 249 /** 250 * Moves the content to the top left corner of the window, 251 * uses getContentDimension to get the offset 252 */ 253 virtual void repositionContent(); 254 255 /** 256 * Gets the area in the window that the content occupies. 257 */ 258 virtual Rectangle getContentDimension(); 259 260 std::string mCaption; 261 unsigned int mAlignment; 262 Widget* mContent; 263 unsigned int mPadding; 264 unsigned int mTitleBarHeight; 265 bool mMouseDrag; 266 int mMouseXOffset; 267 int mMouseYOffset; 268 bool mMovable; 269 bool mOpaque; 270 }; 271 } 272 273 #endif // end GCN_WINDOW_HPP 274