| 1 |
/*************************************************************************** |
| 2 |
* Copyright (C) 2005-2013 by the FIFE team * |
| 3 |
* http://www.fifengine.net * |
| 4 |
* This file is part of FIFE. * |
| 5 |
* * |
| 6 |
* FIFE is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Lesser General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2.1 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
| 14 |
* Lesser General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Lesser General Public * |
| 17 |
* License along with this library; if not, write to the * |
| 18 |
* Free Software Foundation, Inc., * |
| 19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * |
| 20 |
***************************************************************************/ |
| 21 |
|
| 22 |
#ifndef FIFE_GUI_WIDGETS_RESIZABLEWINDOW_H |
| 23 |
#define FIFE_GUI_WIDGETS_RESIZABLEWINDOW_H |
| 24 |
|
| 25 |
// Standard C++ library includes |
| 26 |
|
| 27 |
// 3rd party library includes |
| 28 |
#include <fifechan.hpp> |
| 29 |
|
| 30 |
// FIFE includes |
| 31 |
// These includes are split up in two parts, separated by one empty line |
| 32 |
// First block: files included from the FIFE root src directory |
| 33 |
// Second block: files included from the same folder |
| 34 |
#include "video/cursor.h" |
| 35 |
|
| 36 |
|
| 37 |
namespace fcn { |
| 38 |
class ResizableWindow : public Window, public KeyListener, public FocusListener { |
| 39 |
public: |
| 40 |
enum CursorDirections { |
| 41 |
// left |
| 42 |
CURSOR_DIRECTION_L = 0, |
| 43 |
// right |
| 44 |
CURSOR_DIRECTION_R = 1, |
| 45 |
// top |
| 46 |
CURSOR_DIRECTION_T = 2, |
| 47 |
// bottom |
| 48 |
CURSOR_DIRECTION_B = 5, |
| 49 |
// left and top |
| 50 |
CURSOR_DIRECTION_LT = 3, |
| 51 |
// right and top |
| 52 |
CURSOR_DIRECTION_RT = 4, |
| 53 |
// left and bottom |
| 54 |
CURSOR_DIRECTION_LB = 6, |
| 55 |
// right and bottom |
| 56 |
CURSOR_DIRECTION_RB = 7 |
| 57 |
}; |
| 58 |
|
| 59 |
ResizableWindow(); |
| 60 |
ResizableWindow(bool resizable); |
| 61 |
ResizableWindow(const std::string& caption, bool resizable=true); |
| 62 |
virtual ~ResizableWindow(); |
| 63 |
|
| 64 |
/** Sets the size of the area that is active for resize events. |
| 65 |
* @param border The distance from the edge that is active for resize events. |
| 66 |
*/ |
| 67 |
void setResizableBorderDistance(int32_t border); |
| 68 |
|
| 69 |
/** Gets the size of the area that is active for resize events. |
| 70 |
* @return The distance from the edge that is active for resize events. |
| 71 |
*/ |
| 72 |
int32_t getResizableBorderDistance() const; |
| 73 |
|
| 74 |
/** Sets if the widget is resizable. |
| 75 |
* @param resizable True if the widget should be resizeable, otherwise false. |
| 76 |
*/ |
| 77 |
void setResizable(bool resizable); |
| 78 |
|
| 79 |
/** Gets if the widget is resizable. |
| 80 |
* @return True if the widget should be resizeable, otherwise false. |
| 81 |
*/ |
| 82 |
bool isResizable() const; |
| 83 |
|
| 84 |
/** Sets if the widget is resizable at top. |
| 85 |
* @param resizable True if the widget should be resizeable at top, otherwise false. |
| 86 |
*/ |
| 87 |
void setTopResizable(bool resizable); |
| 88 |
|
| 89 |
/** Gets if the widget is resizable at top. |
| 90 |
* @return True if the widget should be resizeable at top, otherwise false. |
| 91 |
*/ |
| 92 |
bool isTopResizable() const; |
| 93 |
|
| 94 |
/** Sets if the widget is resizable at right. |
| 95 |
* @param resizable True if the widget should be resizeable at right, otherwise false. |
| 96 |
*/ |
| 97 |
void setRightResizable(bool resizable); |
| 98 |
|
| 99 |
/** Gets if the widget is resizable at right. |
| 100 |
* @return True if the widget should be resizeable at right, otherwise false. |
| 101 |
*/ |
| 102 |
bool isRightResizable() const; |
| 103 |
|
| 104 |
/** Sets if the widget is resizable at bottom. |
| 105 |
* @param resizable True if the widget should be resizeable at bottom, otherwise false. |
| 106 |
*/ |
| 107 |
void setBottomResizable(bool resizable); |
| 108 |
|
| 109 |
/** Gets if the widget is resizable at bottom. |
| 110 |
* @return True if the widget should be resizeable at bottom, otherwise false. |
| 111 |
*/ |
| 112 |
bool isBottomResizable() const; |
| 113 |
|
| 114 |
/** Sets if the widget is resizable at left. |
| 115 |
* @param resizable True if the widget should be resizeable at left, otherwise false. |
| 116 |
*/ |
| 117 |
void setLeftResizable(bool resizable); |
| 118 |
|
| 119 |
/** Gets if the widget is resizable at left. |
| 120 |
* @return True if the widget should be resizeable at left, otherwise false. |
| 121 |
*/ |
| 122 |
bool isLeftResizable() const; |
| 123 |
|
| 124 |
/** Sets if the widget should be pushed if the size reaches the minimum. |
| 125 |
* @param shove True if the widget should be pushed, otherwise false. |
| 126 |
*/ |
| 127 |
void setShove(bool shove); |
| 128 |
|
| 129 |
/** Gets if the widget should be pushed if the size reaches the minimum. |
| 130 |
* @return True if the widget should be pushed, otherwise false. |
| 131 |
*/ |
| 132 |
bool getShove() const; |
| 133 |
|
| 134 |
/** Sets the mouse cursor for the specified direction. |
| 135 |
* @param cursor_id For native cursors, this is the resource id to native cursor, or one of the values in NativeCursor |
| 136 |
*/ |
| 137 |
void set(CursorDirections direction, uint32_t cursor_id=0); |
| 138 |
|
| 139 |
/** Sets the mouse cursor type to image for the specified direction. |
| 140 |
* @param image ImagePtr to a image used for the cursor |
| 141 |
*/ |
| 142 |
void set(CursorDirections direction, FIFE::ImagePtr image); |
| 143 |
|
| 144 |
/** Sets the mouse cursor type to animation for the specified direction. |
| 145 |
* @param anim AnimationPtr to a loaded animation used for the cursor |
| 146 |
*/ |
| 147 |
void set(CursorDirections direction, FIFE::AnimationPtr anim); |
| 148 |
|
| 149 |
/** Gets the mouse cursor type for the specified direction. |
| 150 |
*/ |
| 151 |
FIFE::MouseCursorType getType(CursorDirections direction) const; |
| 152 |
|
| 153 |
/** Gets the mouse cursor handle for the specified direction. |
| 154 |
*/ |
| 155 |
uint32_t getId(CursorDirections direction) const; |
| 156 |
|
| 157 |
/** Gets the mouse image for the specified direction. |
| 158 |
*/ |
| 159 |
FIFE::ImagePtr getImage(CursorDirections direction); |
| 160 |
|
| 161 |
/** Gets the mouse animation for the specified direction. |
| 162 |
*/ |
| 163 |
FIFE::AnimationPtr getAnimation(CursorDirections direction); |
| 164 |
|
| 165 |
// Inherited from Window |
| 166 |
|
| 167 |
virtual void resizeToContent(bool recursiv=true); |
| 168 |
|
| 169 |
// Inherited from FocusListener |
| 170 |
|
| 171 |
virtual void focusLost(const Event& event); |
| 172 |
|
| 173 |
|
| 174 |
// Inherited from Window / MouseListener |
| 175 |
|
| 176 |
virtual void mouseEntered(MouseEvent& mouseEvent); |
| 177 |
|
| 178 |
virtual void mouseExited(MouseEvent& mouseEvent); |
| 179 |
|
| 180 |
virtual void mousePressed(MouseEvent& mouseEvent); |
| 181 |
|
| 182 |
virtual void mouseReleased(MouseEvent& mouseEvent); |
| 183 |
|
| 184 |
virtual void mouseMoved(MouseEvent& mouseEvent); |
| 185 |
|
| 186 |
virtual void mouseDragged(MouseEvent& mouseEvent); |
| 187 |
|
| 188 |
protected: |
| 189 |
// initialized the 8 cursors, see CursorDirections |
| 190 |
void initCursors(); |
| 191 |
// restore cursor |
| 192 |
void restoreCursor(); |
| 193 |
// save cursor so we can restore it later |
| 194 |
void saveCursor(); |
| 195 |
|
| 196 |
// access to fifes cursor class |
| 197 |
FIFE::Cursor* m_cursor; |
| 198 |
// distance from the widgets edge that is active for resizing events |
| 199 |
int32_t m_borderDistance; |
| 200 |
// is resizable |
| 201 |
bool m_resizable; |
| 202 |
// allow resize on top |
| 203 |
bool m_resizableTop; |
| 204 |
// allow resize on right |
| 205 |
bool m_resizableRight; |
| 206 |
// allow resize on bottom |
| 207 |
bool m_resizableBottom; |
| 208 |
// allow resize on left |
| 209 |
bool m_resizableLeft; |
| 210 |
// is currently resizing |
| 211 |
bool m_resizing; |
| 212 |
|
| 213 |
// indicate the changed size per direction |
| 214 |
bool m_resizeTop; |
| 215 |
bool m_resizeRight; |
| 216 |
bool m_resizeBottom; |
| 217 |
bool m_resizeLeft; |
| 218 |
// is shove allowed |
| 219 |
bool m_shove; |
| 220 |
|
| 221 |
struct CursorState { |
| 222 |
FIFE::MouseCursorType cursorType; |
| 223 |
uint32_t cursorId; |
| 224 |
FIFE::ImagePtr cursorImage; |
| 225 |
FIFE::AnimationPtr cursorAnimation; |
| 226 |
}; |
| 227 |
// old saved cursor |
| 228 |
CursorState m_saved; |
| 229 |
// contains the 8 CursorStates, one per direction |
| 230 |
std::vector<CursorState> m_cursors; |
| 231 |
}; |
| 232 |
} |
| 233 |
|
| 234 |
#endif |