| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- //
- // Urho3D Engine
- // Copyright (c) 2008-2011 Lasse Öörni
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to deal
- // in the Software without restriction, including without limitation the rights
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- // copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- // THE SOFTWARE.
- //
- #ifndef UI_WINDOW_H
- #define UI_WINDOW_H
- #include "BorderImage.h"
- //! Window movement and resizing modes
- enum WindowDragMode
- {
- DRAG_NONE,
- DRAG_MOVE,
- DRAG_RESIZE_TOPLEFT,
- DRAG_RESIZE_TOP,
- DRAG_RESIZE_TOPRIGHT,
- DRAG_RESIZE_RIGHT,
- DRAG_RESIZE_BOTTOMRIGHT,
- DRAG_RESIZE_BOTTOM,
- DRAG_RESIZE_BOTTOMLEFT,
- DRAG_RESIZE_LEFT
- };
- //! A window that can optionally by moved or resized
- class Window : public BorderImage
- {
- DEFINE_TYPE(Window);
-
- public:
- //! Construct with name
- Window(const std::string& name = std::string());
- //! Destruct
- virtual ~Window();
-
- //! Set UI element style from XML data
- virtual void setStyle(const XMLElement& element, ResourceCache* cache);
- //! React to mouse hover
- virtual void onHover(const IntVector2& position, const IntVector2& screenPosition, int buttons, int qualifiers, Cursor* cursor);
- //! React to mouse drag start
- virtual void onDragStart(const IntVector2& position, const IntVector2& screenPosition, int buttons, int qualifiers, Cursor* cursor);
- //! React to mouse drag motion
- virtual void onDragMove(const IntVector2& position, const IntVector2& screenPosition, int buttons, int qualifiers, Cursor* cursor);
- //! React to mouse drag end
- virtual void onDragEnd(const IntVector2& position, const IntVector2& screenPosition, Cursor* cursor);
-
- //! Set whether can be moved
- void setMovable(bool enable);
- //! Set whether can be resized
- void setResizable(bool enable);
- //! Set resize area width at edges
- void setResizeBorder(const IntRect& rect);
- //! Set resize area width at edges
- void setResizeBorder(int left, int top, int right, int bottom);
-
- //! Return whether is movable
- bool isMovable() const { return mMovable; }
- //! Return whether is resizable
- bool isResizable() const { return mResizable; }
- //! Return resize area width at edges
- const IntRect& getResizeBorder() const { return mResizeBorder; }
-
- protected:
- //! Identify drag mode (move/resize)
- WindowDragMode identifyDragMode(const IntVector2& position) const;
- //! Set cursor shape based on drag mode
- void setCursorShape(WindowDragMode mode, Cursor* cursor) const;
- //! Validate window position
- void validatePosition();
- //! Check whether alignment supports moving and resizing
- bool checkAlignment() const;
-
- //! Movable flag
- bool mMovable;
- //! Resizable flag
- bool mResizable;
- //! Resize area width at edges
- IntRect mResizeBorder;
- //! Current drag mode
- WindowDragMode mDragMode;
- //! Mouse position at drag start
- IntVector2 mDragStartPosition;
- //! Original position at drag start
- IntVector2 mOriginalPosition;
- //! Original size at drag start
- IntVector2 mOriginalSize;
- };
- #endif // UI_WINDOW_H
|