2011-08-28 15:17:58 +02:00
|
|
|
/*
|
2013-01-08 19:21:54 +01:00
|
|
|
* Copyright (c) 2010-2013 OTClient <https://github.com/edubart/otclient>
|
2011-08-28 15:17:58 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2011-08-14 04:09:11 +02:00
|
|
|
#ifndef UIWIDGET_H
|
|
|
|
#define UIWIDGET_H
|
|
|
|
|
2011-08-15 16:06:15 +02:00
|
|
|
#include "declarations.h"
|
2012-07-29 05:34:40 +02:00
|
|
|
#include "uilayout.h"
|
|
|
|
|
2012-07-14 03:10:24 +02:00
|
|
|
#include <framework/luaengine/luaobject.h>
|
2011-08-15 16:06:15 +02:00
|
|
|
#include <framework/graphics/declarations.h>
|
2012-01-03 02:32:34 +01:00
|
|
|
#include <framework/otml/otmlnode.h>
|
2012-06-17 01:19:43 +02:00
|
|
|
#include <framework/graphics/bitmapfont.h>
|
2012-01-10 23:13:40 +01:00
|
|
|
#include <framework/graphics/coordsbuffer.h>
|
2012-02-03 06:25:01 +01:00
|
|
|
#include <framework/core/timer.h>
|
2012-01-10 23:13:40 +01:00
|
|
|
|
|
|
|
template<typename T = int>
|
|
|
|
struct EdgeGroup {
|
|
|
|
EdgeGroup() { top = right = bottom = left = T(0); }
|
|
|
|
void set(T value) { top = right = bottom = left = value; }
|
|
|
|
T top;
|
|
|
|
T right;
|
|
|
|
T bottom;
|
|
|
|
T left;
|
|
|
|
};
|
2011-08-14 04:09:11 +02:00
|
|
|
|
2012-06-22 05:14:13 +02:00
|
|
|
// @bindclass
|
2011-08-14 04:09:11 +02:00
|
|
|
class UIWidget : public LuaObject
|
|
|
|
{
|
2012-01-10 23:13:40 +01:00
|
|
|
// widget core
|
2011-08-14 04:09:11 +02:00
|
|
|
public:
|
2011-08-22 14:44:26 +02:00
|
|
|
UIWidget();
|
2012-01-10 23:13:40 +01:00
|
|
|
virtual ~UIWidget();
|
2011-08-20 22:30:41 +02:00
|
|
|
|
2012-01-05 02:28:29 +01:00
|
|
|
protected:
|
2012-06-08 18:58:08 +02:00
|
|
|
virtual void draw(const Rect& visibleRect, Fw::DrawPane drawPane);
|
|
|
|
virtual void drawSelf(Fw::DrawPane drawPane);
|
|
|
|
virtual void drawChildren(const Rect& visibleRect, Fw::DrawPane drawPane);
|
2011-08-14 04:09:11 +02:00
|
|
|
|
2012-01-05 02:28:29 +01:00
|
|
|
friend class UIManager;
|
|
|
|
|
2012-01-10 23:13:40 +01:00
|
|
|
std::string m_id;
|
|
|
|
Rect m_rect;
|
2012-03-24 16:22:40 +01:00
|
|
|
Point m_virtualOffset;
|
2012-07-29 12:32:44 +02:00
|
|
|
stdext::boolean<true> m_enabled;
|
|
|
|
stdext::boolean<true> m_visible;
|
|
|
|
stdext::boolean<true> m_focusable;
|
|
|
|
stdext::boolean<false> m_fixedSize;
|
|
|
|
stdext::boolean<false> m_phantom;
|
2012-08-07 01:43:14 +02:00
|
|
|
stdext::boolean<false> m_draggable;
|
2012-07-29 12:32:44 +02:00
|
|
|
stdext::boolean<false> m_destroyed;
|
|
|
|
stdext::boolean<false> m_clipping;
|
2012-01-10 23:13:40 +01:00
|
|
|
UILayoutPtr m_layout;
|
2012-07-29 05:34:40 +02:00
|
|
|
UIWidgetPtr m_parent;
|
2012-01-10 23:13:40 +01:00
|
|
|
UIWidgetList m_children;
|
|
|
|
UIWidgetList m_lockedChildren;
|
|
|
|
UIWidgetPtr m_focusedChild;
|
|
|
|
OTMLNodePtr m_style;
|
2012-02-03 06:25:01 +01:00
|
|
|
Timer m_clickTimer;
|
2012-01-10 23:13:40 +01:00
|
|
|
Fw::FocusReason m_lastFocusReason;
|
2013-01-26 20:06:25 +01:00
|
|
|
Fw::AutoFocusPolicy m_autoFocusPolicy;
|
2012-01-04 11:26:58 +01:00
|
|
|
|
|
|
|
public:
|
2012-01-10 23:13:40 +01:00
|
|
|
void addChild(const UIWidgetPtr& child);
|
|
|
|
void insertChild(int index, const UIWidgetPtr& child);
|
2012-02-05 23:42:35 +01:00
|
|
|
void removeChild(UIWidgetPtr child);
|
2012-01-10 23:13:40 +01:00
|
|
|
void focusChild(const UIWidgetPtr& child, Fw::FocusReason reason);
|
2013-01-26 20:06:25 +01:00
|
|
|
void focusNextChild(Fw::FocusReason reason, bool rotate = false);
|
|
|
|
void focusPreviousChild(Fw::FocusReason reason, bool rotate = false);
|
2012-02-05 23:42:35 +01:00
|
|
|
void lowerChild(UIWidgetPtr child);
|
|
|
|
void raiseChild(UIWidgetPtr child);
|
2012-01-10 23:13:40 +01:00
|
|
|
void moveChildToIndex(const UIWidgetPtr& child, int index);
|
|
|
|
void lockChild(const UIWidgetPtr& child);
|
|
|
|
void unlockChild(const UIWidgetPtr& child);
|
2012-04-30 18:40:12 +02:00
|
|
|
void mergeStyle(const OTMLNodePtr& styleNode);
|
2012-01-10 23:13:40 +01:00
|
|
|
void applyStyle(const OTMLNodePtr& styleNode);
|
|
|
|
void addAnchor(Fw::AnchorEdge anchoredEdge, const std::string& hookedWidgetId, Fw::AnchorEdge hookedEdge);
|
2012-04-06 00:46:53 +02:00
|
|
|
void removeAnchor(Fw::AnchorEdge anchoredEdge);
|
2012-01-10 23:13:40 +01:00
|
|
|
void fill(const std::string& hookedWidgetId);
|
|
|
|
void centerIn(const std::string& hookedWidgetId);
|
|
|
|
void breakAnchors();
|
|
|
|
void updateParentLayout();
|
|
|
|
void updateLayout();
|
2011-08-29 16:14:21 +02:00
|
|
|
void lock();
|
|
|
|
void unlock();
|
2011-11-03 10:59:11 +01:00
|
|
|
void focus();
|
2012-03-30 00:46:44 +02:00
|
|
|
void recursiveFocus(Fw::FocusReason reason);
|
2012-02-05 23:42:35 +01:00
|
|
|
void lower();
|
|
|
|
void raise();
|
2012-01-02 23:09:49 +01:00
|
|
|
void grabMouse();
|
|
|
|
void ungrabMouse();
|
|
|
|
void grabKeyboard();
|
|
|
|
void ungrabKeyboard();
|
2012-01-10 23:13:40 +01:00
|
|
|
void bindRectToParent();
|
|
|
|
void destroy();
|
2012-02-06 02:44:47 +01:00
|
|
|
void destroyChildren();
|
2012-01-10 23:13:40 +01:00
|
|
|
|
|
|
|
void setId(const std::string& id);
|
|
|
|
void setParent(const UIWidgetPtr& parent);
|
|
|
|
void setLayout(const UILayoutPtr& layout);
|
2012-03-27 20:14:35 +02:00
|
|
|
bool setRect(const Rect& rect);
|
2012-01-10 23:13:40 +01:00
|
|
|
void setStyle(const std::string& styleName);
|
|
|
|
void setStyleFromNode(const OTMLNodePtr& styleNode);
|
|
|
|
void setEnabled(bool enabled);
|
|
|
|
void setVisible(bool visible);
|
|
|
|
void setOn(bool on);
|
|
|
|
void setChecked(bool checked);
|
|
|
|
void setFocusable(bool focusable);
|
|
|
|
void setPhantom(bool phantom);
|
2012-08-07 01:43:14 +02:00
|
|
|
void setDraggable(bool draggable);
|
2012-01-10 23:13:40 +01:00
|
|
|
void setFixedSize(bool fixed);
|
2012-03-25 16:10:15 +02:00
|
|
|
void setClipping(bool clipping) { m_clipping = clipping; }
|
2012-01-10 23:13:40 +01:00
|
|
|
void setLastFocusReason(Fw::FocusReason reason);
|
2013-01-26 20:06:25 +01:00
|
|
|
void setAutoFocusPolicy(Fw::AutoFocusPolicy policy);
|
2012-02-06 13:53:28 +01:00
|
|
|
void setAutoRepeatDelay(int delay) { m_autoRepeatDelay = delay; }
|
2012-03-24 16:22:40 +01:00
|
|
|
void setVirtualOffset(const Point& offset);
|
2011-08-14 04:09:11 +02:00
|
|
|
|
2012-03-28 16:10:21 +02:00
|
|
|
bool isAnchored();
|
2012-01-10 23:13:40 +01:00
|
|
|
bool isChildLocked(const UIWidgetPtr& child);
|
2011-08-14 04:09:11 +02:00
|
|
|
bool hasChild(const UIWidgetPtr& child);
|
2012-01-10 23:13:40 +01:00
|
|
|
int getChildIndex(const UIWidgetPtr& child);
|
2012-06-02 02:38:26 +02:00
|
|
|
Rect getPaddingRect();
|
2012-03-27 00:24:01 +02:00
|
|
|
Rect getMarginRect();
|
2012-01-09 19:45:28 +01:00
|
|
|
Rect getChildrenRect();
|
2012-01-10 23:13:40 +01:00
|
|
|
UIAnchorLayoutPtr getAnchoredLayout();
|
|
|
|
UIWidgetPtr getRootParent();
|
2011-08-14 04:09:11 +02:00
|
|
|
UIWidgetPtr getChildAfter(const UIWidgetPtr& relativeChild);
|
|
|
|
UIWidgetPtr getChildBefore(const UIWidgetPtr& relativeChild);
|
|
|
|
UIWidgetPtr getChildById(const std::string& childId);
|
|
|
|
UIWidgetPtr getChildByPos(const Point& childPos);
|
2011-08-23 03:08:36 +02:00
|
|
|
UIWidgetPtr getChildByIndex(int index);
|
2011-08-21 21:43:05 +02:00
|
|
|
UIWidgetPtr recursiveGetChildById(const std::string& id);
|
2012-03-28 16:10:21 +02:00
|
|
|
UIWidgetPtr recursiveGetChildByPos(const Point& childPos, bool wantsPhantom);
|
2012-07-26 08:10:28 +02:00
|
|
|
UIWidgetList recursiveGetChildren();
|
2012-02-07 01:41:53 +01:00
|
|
|
UIWidgetList recursiveGetChildrenByPos(const Point& childPos);
|
2012-06-11 16:10:03 +02:00
|
|
|
UIWidgetList recursiveGetChildrenByMarginPos(const Point& childPos);
|
2011-08-14 04:09:11 +02:00
|
|
|
UIWidgetPtr backwardsGetWidgetById(const std::string& id);
|
|
|
|
|
2012-01-10 23:13:40 +01:00
|
|
|
private:
|
2012-07-29 12:32:44 +02:00
|
|
|
stdext::boolean<false> m_updateEventScheduled;
|
|
|
|
stdext::boolean<false> m_loadingStyle;
|
2011-11-16 00:47:32 +01:00
|
|
|
|
2012-01-02 23:49:34 +01:00
|
|
|
|
2012-01-10 23:13:40 +01:00
|
|
|
// state managment
|
2012-01-02 23:49:34 +01:00
|
|
|
protected:
|
2011-11-16 18:03:11 +01:00
|
|
|
bool setState(Fw::WidgetState state, bool on);
|
2011-11-16 00:47:32 +01:00
|
|
|
bool hasState(Fw::WidgetState state);
|
|
|
|
|
2012-01-02 23:49:34 +01:00
|
|
|
private:
|
2012-04-09 22:52:39 +02:00
|
|
|
void internalDestroy();
|
2012-01-02 23:49:34 +01:00
|
|
|
void updateState(Fw::WidgetState state);
|
|
|
|
void updateStates();
|
|
|
|
void updateChildrenIndexStates();
|
|
|
|
void updateStyle();
|
2011-08-14 04:09:11 +02:00
|
|
|
|
2012-07-29 12:32:44 +02:00
|
|
|
stdext::boolean<false> m_updateStyleScheduled;
|
|
|
|
stdext::boolean<true> m_firstOnStyle;
|
2012-01-10 23:13:40 +01:00
|
|
|
OTMLNodePtr m_stateStyle;
|
|
|
|
int m_states;
|
|
|
|
|
|
|
|
|
|
|
|
// event processing
|
2011-08-14 04:09:11 +02:00
|
|
|
protected:
|
2012-01-04 11:26:58 +01:00
|
|
|
virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
|
2012-01-05 03:42:17 +01:00
|
|
|
virtual void onGeometryChange(const Rect& oldRect, const Rect& newRect);
|
2012-03-25 19:10:19 +02:00
|
|
|
virtual void onLayoutUpdate();
|
2011-08-28 18:02:26 +02:00
|
|
|
virtual void onFocusChange(bool focused, Fw::FocusReason reason);
|
2012-02-06 02:44:47 +01:00
|
|
|
virtual void onChildFocusChange(const UIWidgetPtr& focusedChild, const UIWidgetPtr& unfocusedChild, Fw::FocusReason reason);
|
2011-08-22 14:44:26 +02:00
|
|
|
virtual void onHoverChange(bool hovered);
|
2013-01-08 21:01:47 +01:00
|
|
|
virtual void onVisibilityChange(bool visible);
|
2012-02-09 19:38:50 +01:00
|
|
|
virtual bool onDragEnter(const Point& mousePos);
|
2012-03-23 23:48:18 +01:00
|
|
|
virtual bool onDragLeave(UIWidgetPtr droppedWidget, const Point& mousePos);
|
2012-02-07 01:41:53 +01:00
|
|
|
virtual bool onDragMove(const Point& mousePos, const Point& mouseMoved);
|
2012-02-07 03:06:48 +01:00
|
|
|
virtual bool onDrop(UIWidgetPtr draggedWidget, const Point& mousePos);
|
2012-01-15 22:19:52 +01:00
|
|
|
virtual bool onKeyText(const std::string& keyText);
|
|
|
|
virtual bool onKeyDown(uchar keyCode, int keyboardModifiers);
|
2012-02-06 13:53:28 +01:00
|
|
|
virtual bool onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeatTicks);
|
2012-01-17 07:24:58 +01:00
|
|
|
virtual bool onKeyUp(uchar keyCode, int keyboardModifiers);
|
2011-08-28 18:02:26 +02:00
|
|
|
virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button);
|
2012-01-24 19:39:16 +01:00
|
|
|
virtual bool onMouseRelease(const Point& mousePos, Fw::MouseButton button);
|
2011-08-22 14:44:26 +02:00
|
|
|
virtual bool onMouseMove(const Point& mousePos, const Point& mouseMoved);
|
2011-08-28 18:02:26 +02:00
|
|
|
virtual bool onMouseWheel(const Point& mousePos, Fw::MouseWheelDirection direction);
|
2012-02-06 02:44:47 +01:00
|
|
|
virtual bool onClick(const Point& mousePos);
|
2012-02-04 18:04:44 +01:00
|
|
|
virtual bool onDoubleClick(const Point& mousePos);
|
2011-08-14 04:09:11 +02:00
|
|
|
|
2012-03-25 19:10:19 +02:00
|
|
|
friend class UILayout;
|
|
|
|
|
2012-01-15 22:19:52 +01:00
|
|
|
bool propagateOnKeyText(const std::string& keyText);
|
|
|
|
bool propagateOnKeyDown(uchar keyCode, int keyboardModifiers);
|
2012-02-06 13:53:28 +01:00
|
|
|
bool propagateOnKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeatTicks);
|
2012-01-17 07:24:58 +01:00
|
|
|
bool propagateOnKeyUp(uchar keyCode, int keyboardModifiers);
|
2012-03-28 13:46:15 +02:00
|
|
|
bool propagateOnMouseEvent(const Point& mousePos, UIWidgetList& widgetList);
|
|
|
|
bool propagateOnMouseMove(const Point& mousePos, const Point& mouseMoved, UIWidgetList& widgetList);
|
2012-01-05 03:42:17 +01:00
|
|
|
|
2012-01-10 23:13:40 +01:00
|
|
|
|
|
|
|
// function shortcuts
|
|
|
|
public:
|
2012-01-30 01:00:12 +01:00
|
|
|
void resize(int width, int height) { setRect(Rect(getPosition(), Size(width, height))); }
|
2012-01-10 23:13:40 +01:00
|
|
|
void move(int x, int y) { setRect(Rect(x, y, getSize())); }
|
2013-01-19 17:44:07 +01:00
|
|
|
void rotate(float degrees) { setRotation(degrees); }
|
2012-01-10 23:13:40 +01:00
|
|
|
void hide() { setVisible(false); }
|
|
|
|
void show() { setVisible(true); }
|
|
|
|
void disable() { setEnabled(false); }
|
|
|
|
void enable() { setEnabled(true); }
|
|
|
|
|
|
|
|
bool isActive() { return hasState(Fw::ActiveState); }
|
|
|
|
bool isEnabled() { return !hasState(Fw::DisabledState); }
|
|
|
|
bool isDisabled() { return hasState(Fw::DisabledState); }
|
|
|
|
bool isFocused() { return hasState(Fw::FocusState); }
|
|
|
|
bool isHovered() { return hasState(Fw::HoverState); }
|
|
|
|
bool isPressed() { return hasState(Fw::PressedState); }
|
|
|
|
bool isFirst() { return hasState(Fw::FirstState); }
|
|
|
|
bool isMiddle() { return hasState(Fw::MiddleState); }
|
|
|
|
bool isLast() { return hasState(Fw::LastState); }
|
|
|
|
bool isAlternate() { return hasState(Fw::AlternateState); }
|
|
|
|
bool isChecked() { return hasState(Fw::CheckedState); }
|
|
|
|
bool isOn() { return hasState(Fw::OnState); }
|
2012-02-07 20:21:53 +01:00
|
|
|
bool isDragging() { return hasState(Fw::DraggingState); }
|
2013-01-08 21:01:47 +01:00
|
|
|
bool isVisible() { return !hasState(Fw::HiddenState); }
|
|
|
|
bool isHidden() { return hasState(Fw::HiddenState); }
|
2012-01-10 23:13:40 +01:00
|
|
|
bool isExplicitlyEnabled() { return m_enabled; }
|
|
|
|
bool isExplicitlyVisible() { return m_visible; }
|
|
|
|
bool isFocusable() { return m_focusable; }
|
|
|
|
bool isPhantom() { return m_phantom; }
|
2012-08-07 01:43:14 +02:00
|
|
|
bool isDraggable() { return m_draggable; }
|
2012-01-10 23:13:40 +01:00
|
|
|
bool isFixedSize() { return m_fixedSize; }
|
2012-03-25 16:10:15 +02:00
|
|
|
bool isClipping() { return m_clipping; }
|
2012-01-10 23:13:40 +01:00
|
|
|
bool isDestroyed() { return m_destroyed; }
|
|
|
|
|
|
|
|
bool hasChildren() { return m_children.size() > 0; }
|
2012-06-11 16:10:03 +02:00
|
|
|
bool containsMarginPoint(const Point& point) { return getMarginRect().contains(point); }
|
|
|
|
bool containsPaddingPoint(const Point& point) { return getPaddingRect().contains(point); }
|
2012-01-10 23:13:40 +01:00
|
|
|
bool containsPoint(const Point& point) { return m_rect.contains(point); }
|
|
|
|
|
|
|
|
std::string getId() { return m_id; }
|
2012-07-29 05:34:40 +02:00
|
|
|
UIWidgetPtr getParent() { return m_parent; }
|
2012-01-10 23:13:40 +01:00
|
|
|
UIWidgetPtr getFocusedChild() { return m_focusedChild; }
|
|
|
|
UIWidgetList getChildren() { return m_children; }
|
|
|
|
UIWidgetPtr getFirstChild() { return getChildByIndex(1); }
|
|
|
|
UIWidgetPtr getLastChild() { return getChildByIndex(-1); }
|
|
|
|
UILayoutPtr getLayout() { return m_layout; }
|
|
|
|
OTMLNodePtr getStyle() { return m_style; }
|
|
|
|
int getChildCount() { return m_children.size(); }
|
|
|
|
Fw::FocusReason getLastFocusReason() { return m_lastFocusReason; }
|
2013-01-26 20:06:25 +01:00
|
|
|
Fw::AutoFocusPolicy getAutoFocusPolicy() { return m_autoFocusPolicy; }
|
2012-02-06 13:53:28 +01:00
|
|
|
int getAutoRepeatDelay() { return m_autoRepeatDelay; }
|
2012-03-24 16:22:40 +01:00
|
|
|
Point getVirtualOffset() { return m_virtualOffset; }
|
2012-01-10 23:13:40 +01:00
|
|
|
std::string getStyleName() { return m_style->tag(); }
|
2012-03-26 20:33:00 +02:00
|
|
|
Point getLastClickPosition() { return m_lastClickPosition; }
|
2012-01-10 23:13:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
// base style
|
|
|
|
private:
|
|
|
|
void initBaseStyle();
|
|
|
|
void parseBaseStyle(const OTMLNodePtr& styleNode);
|
|
|
|
|
2011-08-14 16:09:26 +02:00
|
|
|
protected:
|
2012-01-10 23:13:40 +01:00
|
|
|
void drawBackground(const Rect& screenCoords);
|
|
|
|
void drawBorder(const Rect& screenCoords);
|
|
|
|
void drawIcon(const Rect& screenCoords);
|
|
|
|
|
2012-01-09 19:45:28 +01:00
|
|
|
Color m_color;
|
2012-01-10 23:13:40 +01:00
|
|
|
Color m_backgroundColor;
|
|
|
|
Rect m_backgroundRect;
|
|
|
|
TexturePtr m_icon;
|
|
|
|
Color m_iconColor;
|
|
|
|
Rect m_iconRect;
|
2012-07-12 21:16:23 +02:00
|
|
|
Rect m_iconClipRect;
|
2013-01-08 21:01:47 +01:00
|
|
|
Fw::AlignmentFlag m_iconAlign;
|
2012-01-10 23:13:40 +01:00
|
|
|
EdgeGroup<Color> m_borderColor;
|
|
|
|
EdgeGroup<int> m_borderWidth;
|
|
|
|
EdgeGroup<int> m_margin;
|
|
|
|
EdgeGroup<int> m_padding;
|
|
|
|
float m_opacity;
|
2013-01-19 17:44:07 +01:00
|
|
|
float m_rotation;
|
2012-02-06 13:53:28 +01:00
|
|
|
int m_autoRepeatDelay;
|
2012-03-26 20:33:00 +02:00
|
|
|
Point m_lastClickPosition;
|
2012-01-10 23:13:40 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
void setX(int x) { move(x, getY()); }
|
|
|
|
void setY(int y) { move(getX(), y); }
|
|
|
|
void setWidth(int width) { resize(width, getHeight()); }
|
|
|
|
void setHeight(int height) { resize(getWidth(), height); }
|
|
|
|
void setSize(const Size& size) { resize(size.width(), size.height()); }
|
2012-01-30 01:00:12 +01:00
|
|
|
void setPosition(const Point& pos) { move(pos.x, pos.y); }
|
2012-01-10 23:13:40 +01:00
|
|
|
void setColor(const Color& color) { m_color = color; }
|
|
|
|
void setBackgroundColor(const Color& color) { m_backgroundColor = color; }
|
|
|
|
void setBackgroundOffsetX(int x) { m_backgroundRect.setX(x); }
|
|
|
|
void setBackgroundOffsetY(int y) { m_backgroundRect.setX(y); }
|
|
|
|
void setBackgroundOffset(const Point& pos) { m_backgroundRect.move(pos); }
|
|
|
|
void setBackgroundWidth(int width) { m_backgroundRect.setWidth(width); }
|
|
|
|
void setBackgroundHeight(int height) { m_backgroundRect.setHeight(height); }
|
|
|
|
void setBackgroundSize(const Size& size) { m_backgroundRect.resize(size); }
|
|
|
|
void setBackgroundRect(const Rect& rect) { m_backgroundRect = rect; }
|
|
|
|
void setIcon(const std::string& iconFile);
|
|
|
|
void setIconColor(const Color& color) { m_iconColor = color; }
|
2013-01-08 21:01:47 +01:00
|
|
|
void setIconOffsetX(int x) { m_iconOffset.x = x; }
|
|
|
|
void setIconOffsetY(int y) { m_iconOffset.y = y; }
|
|
|
|
void setIconOffset(const Point& pos) { m_iconOffset = pos; }
|
2012-01-10 23:13:40 +01:00
|
|
|
void setIconWidth(int width) { m_iconRect.setWidth(width); }
|
|
|
|
void setIconHeight(int height) { m_iconRect.setHeight(height); }
|
|
|
|
void setIconSize(const Size& size) { m_iconRect.resize(size); }
|
|
|
|
void setIconRect(const Rect& rect) { m_iconRect = rect; }
|
2012-07-12 21:16:23 +02:00
|
|
|
void setIconClip(const Rect& rect) { m_iconClipRect = rect; }
|
2013-01-08 21:01:47 +01:00
|
|
|
void setIconAlign(Fw::AlignmentFlag align) { m_iconAlign = align; }
|
2012-01-10 23:13:40 +01:00
|
|
|
void setBorderWidth(int width) { m_borderWidth.set(width); updateLayout(); }
|
|
|
|
void setBorderWidthTop(int width) { m_borderWidth.top = width; }
|
|
|
|
void setBorderWidthRight(int width) { m_borderWidth.right = width; }
|
|
|
|
void setBorderWidthBottom(int width) { m_borderWidth.bottom = width; }
|
|
|
|
void setBorderWidthLeft(int width) { m_borderWidth.left = width; }
|
|
|
|
void setBorderColor(const Color& color) { m_borderColor.set(color); updateLayout(); }
|
|
|
|
void setBorderColorTop(const Color& color) { m_borderColor.top = color; }
|
|
|
|
void setBorderColorRight(const Color& color) { m_borderColor.right = color; }
|
|
|
|
void setBorderColorBottom(const Color& color) { m_borderColor.bottom = color; }
|
|
|
|
void setBorderColorLeft(const Color& color) { m_borderColor.left = color; }
|
|
|
|
void setMargin(int margin) { m_margin.set(margin); updateParentLayout(); }
|
|
|
|
void setMarginHorizontal(int margin) { m_margin.right = m_margin.left = margin; updateParentLayout(); }
|
|
|
|
void setMarginVertical(int margin) { m_margin.bottom = m_margin.top = margin; updateParentLayout(); }
|
|
|
|
void setMarginTop(int margin) { m_margin.top = margin; updateParentLayout(); }
|
|
|
|
void setMarginRight(int margin) { m_margin.right = margin; updateParentLayout(); }
|
|
|
|
void setMarginBottom(int margin) { m_margin.bottom = margin; updateParentLayout(); }
|
|
|
|
void setMarginLeft(int margin) { m_margin.left = margin; updateParentLayout(); }
|
|
|
|
void setPadding(int padding) { m_padding.top = m_padding.right = m_padding.bottom = m_padding.left = padding; updateLayout(); }
|
|
|
|
void setPaddingHorizontal(int padding) { m_padding.right = m_padding.left = padding; updateLayout(); }
|
|
|
|
void setPaddingVertical(int padding) { m_padding.bottom = m_padding.top = padding; updateLayout(); }
|
|
|
|
void setPaddingTop(int padding) { m_padding.top = padding; updateLayout(); }
|
|
|
|
void setPaddingRight(int padding) { m_padding.right = padding; updateLayout(); }
|
|
|
|
void setPaddingBottom(int padding) { m_padding.bottom = padding; updateLayout(); }
|
|
|
|
void setPaddingLeft(int padding) { m_padding.left = padding; updateLayout(); }
|
2012-02-07 05:55:20 +01:00
|
|
|
void setOpacity(float opacity) { m_opacity = std::min(std::max(opacity, 0.0f), 1.0f); }
|
2013-01-19 17:44:07 +01:00
|
|
|
void setRotation(float degrees) { m_rotation = degrees; }
|
2012-01-10 23:13:40 +01:00
|
|
|
|
|
|
|
int getX() { return m_rect.x(); }
|
|
|
|
int getY() { return m_rect.y(); }
|
2012-01-30 01:00:12 +01:00
|
|
|
Point getPosition() { return m_rect.topLeft(); }
|
2012-01-10 23:13:40 +01:00
|
|
|
int getWidth() { return m_rect.width(); }
|
|
|
|
int getHeight() { return m_rect.height(); }
|
|
|
|
Size getSize() { return m_rect.size(); }
|
|
|
|
Rect getRect() { return m_rect; }
|
|
|
|
Color getColor() { return m_color; }
|
|
|
|
Color getBackgroundColor() { return m_backgroundColor; }
|
|
|
|
int getBackgroundOffsetX() { return m_backgroundRect.x(); }
|
|
|
|
int getBackgroundOffsetY() { return m_backgroundRect.y(); }
|
|
|
|
Point getBackgroundOffset() { return m_backgroundRect.topLeft(); }
|
|
|
|
int getBackgroundWidth() { return m_backgroundRect.width(); }
|
|
|
|
int getBackgroundHeight() { return m_backgroundRect.height(); }
|
|
|
|
Size getBackgroundSize() { return m_backgroundRect.size(); }
|
|
|
|
Rect getBackgroundRect() { return m_backgroundRect; }
|
|
|
|
Color getIconColor() { return m_iconColor; }
|
|
|
|
int getIconOffsetX() { return m_iconRect.x(); }
|
|
|
|
int getIconOffsetY() { return m_iconRect.y(); }
|
|
|
|
Point getIconOffset() { return m_iconRect.topLeft(); }
|
|
|
|
int getIconWidth() { return m_iconRect.width(); }
|
|
|
|
int getIconHeight() { return m_iconRect.height(); }
|
|
|
|
Size getIconSize() { return m_iconRect.size(); }
|
|
|
|
Rect getIconRect() { return m_iconRect; }
|
2012-07-12 21:16:23 +02:00
|
|
|
Rect getIconClip() { return m_iconClipRect; }
|
2013-02-06 20:35:59 +01:00
|
|
|
Fw::AlignmentFlag getIconAlign() { return m_iconAlign; }
|
2012-01-10 23:13:40 +01:00
|
|
|
Color getBorderTopColor() { return m_borderColor.top; }
|
|
|
|
Color getBorderRightColor() { return m_borderColor.right; }
|
|
|
|
Color getBorderBottomColor() { return m_borderColor.bottom; }
|
|
|
|
Color getBorderLeftColor() { return m_borderColor.left; }
|
|
|
|
int getBorderTopWidth() { return m_borderWidth.top; }
|
|
|
|
int getBorderRightWidth() { return m_borderWidth.right; }
|
|
|
|
int getBorderBottomWidth() { return m_borderWidth.bottom; }
|
|
|
|
int getBorderLeftWidth() { return m_borderWidth.left; }
|
|
|
|
int getMarginTop() { return m_margin.top; }
|
|
|
|
int getMarginRight() { return m_margin.right; }
|
|
|
|
int getMarginBottom() { return m_margin.bottom; }
|
|
|
|
int getMarginLeft() { return m_margin.left; }
|
|
|
|
int getPaddingTop() { return m_padding.top; }
|
|
|
|
int getPaddingRight() { return m_padding.right; }
|
|
|
|
int getPaddingBottom() { return m_padding.bottom; }
|
|
|
|
int getPaddingLeft() { return m_padding.left; }
|
|
|
|
float getOpacity() { return m_opacity; }
|
2013-01-19 17:44:07 +01:00
|
|
|
float getRotation() { return m_rotation; }
|
2012-01-10 23:13:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
// image
|
|
|
|
private:
|
2012-03-20 20:10:04 +01:00
|
|
|
void initImage();
|
2012-01-10 23:13:40 +01:00
|
|
|
void parseImageStyle(const OTMLNodePtr& styleNode);
|
|
|
|
|
|
|
|
void updateImageCache() { m_imageMustRecache = true; }
|
|
|
|
void configureBorderImage() { m_imageBordered = true; updateImageCache(); }
|
|
|
|
|
|
|
|
CoordsBuffer m_imageCoordsBuffer;
|
|
|
|
Rect m_imageCachedScreenCoords;
|
2012-07-29 12:32:44 +02:00
|
|
|
stdext::boolean<true> m_imageMustRecache;
|
|
|
|
stdext::boolean<false> m_imageBordered;
|
2012-01-10 23:13:40 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void drawImage(const Rect& screenCoords);
|
|
|
|
|
|
|
|
TexturePtr m_imageTexture;
|
|
|
|
Rect m_imageClipRect;
|
|
|
|
Rect m_imageRect;
|
|
|
|
Color m_imageColor;
|
2013-01-08 21:01:47 +01:00
|
|
|
Point m_iconOffset;
|
2012-07-29 12:32:44 +02:00
|
|
|
stdext::boolean<false> m_imageFixedRatio;
|
|
|
|
stdext::boolean<false> m_imageRepeated;
|
|
|
|
stdext::boolean<false> m_imageSmooth;
|
2012-01-10 23:13:40 +01:00
|
|
|
EdgeGroup<int> m_imageBorder;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void setImageSource(const std::string& source);
|
|
|
|
void setImageClip(const Rect& clipRect) { m_imageClipRect = clipRect; updateImageCache(); }
|
|
|
|
void setImageOffsetX(int x) { m_imageRect.setX(x); updateImageCache(); }
|
2012-08-05 23:43:45 +02:00
|
|
|
void setImageOffsetY(int y) { m_imageRect.setY(y); updateImageCache(); }
|
2012-01-10 23:13:40 +01:00
|
|
|
void setImageOffset(const Point& pos) { m_imageRect.move(pos); updateImageCache(); }
|
|
|
|
void setImageWidth(int width) { m_imageRect.setWidth(width); updateImageCache(); }
|
|
|
|
void setImageHeight(int height) { m_imageRect.setHeight(height); updateImageCache(); }
|
|
|
|
void setImageSize(const Size& size) { m_imageRect.resize(size); updateImageCache(); }
|
|
|
|
void setImageRect(const Rect& rect) { m_imageRect = rect; updateImageCache(); }
|
|
|
|
void setImageColor(const Color& color) { m_imageColor = color; updateImageCache(); }
|
|
|
|
void setImageFixedRatio(bool fixedRatio) { m_imageFixedRatio = fixedRatio; updateImageCache(); }
|
|
|
|
void setImageRepeated(bool repeated) { m_imageRepeated = repeated; updateImageCache(); }
|
|
|
|
void setImageSmooth(bool smooth) { m_imageSmooth = smooth; }
|
|
|
|
void setImageBorderTop(int border) { m_imageBorder.top = border; configureBorderImage(); }
|
|
|
|
void setImageBorderRight(int border) { m_imageBorder.right = border; configureBorderImage(); }
|
|
|
|
void setImageBorderBottom(int border) { m_imageBorder.bottom = border; configureBorderImage(); }
|
|
|
|
void setImageBorderLeft(int border) { m_imageBorder.left = border; configureBorderImage(); }
|
|
|
|
void setImageBorder(int border) { m_imageBorder.set(border); configureBorderImage(); }
|
|
|
|
|
|
|
|
Rect getImageClip() { return m_imageClipRect; }
|
|
|
|
int getImageOffsetX() { return m_imageRect.x(); }
|
|
|
|
int getImageOffsetY() { return m_imageRect.y(); }
|
|
|
|
Point getImageOffset() { return m_imageRect.topLeft(); }
|
|
|
|
int getImageWidth() { return m_imageRect.width(); }
|
|
|
|
int getImageHeight() { return m_imageRect.height(); }
|
|
|
|
Size getImageSize() { return m_imageRect.size(); }
|
|
|
|
Rect getImageRect() { return m_imageRect; }
|
|
|
|
Color getImageColor() { return m_imageColor; }
|
|
|
|
bool isImageFixedRatio() { return m_imageFixedRatio; }
|
|
|
|
bool isImageSmooth() { return m_imageSmooth; }
|
|
|
|
int getImageBorderTop() { return m_imageBorder.top; }
|
|
|
|
int getImageBorderRight() { return m_imageBorder.right; }
|
|
|
|
int getImageBorderBottom() { return m_imageBorder.bottom; }
|
|
|
|
int getImageBorderLeft() { return m_imageBorder.left; }
|
2013-01-31 17:20:04 +01:00
|
|
|
int getImageTextureWidth() { return m_imageTexture ? m_imageTexture->getWidth() : 0; }
|
|
|
|
int getImageTextureHeight() { return m_imageTexture ? m_imageTexture->getHeight() : 0; }
|
2012-01-10 23:13:40 +01:00
|
|
|
|
|
|
|
// text related
|
|
|
|
private:
|
|
|
|
void initText();
|
|
|
|
void parseTextStyle(const OTMLNodePtr& styleNode);
|
|
|
|
|
2012-07-29 12:32:44 +02:00
|
|
|
stdext::boolean<true> m_textMustRecache;
|
2012-03-20 20:10:04 +01:00
|
|
|
CoordsBuffer m_textCoordsBuffer;
|
|
|
|
Rect m_textCachedScreenCoords;
|
2012-01-17 06:36:25 +01:00
|
|
|
|
2012-01-10 23:13:40 +01:00
|
|
|
protected:
|
2013-01-20 16:40:40 +01:00
|
|
|
virtual void updateText();
|
2012-01-10 23:13:40 +01:00
|
|
|
void drawText(const Rect& screenCoords);
|
|
|
|
|
2012-02-03 12:59:55 +01:00
|
|
|
virtual void onTextChange(const std::string& text, const std::string& oldText);
|
2012-01-10 23:13:40 +01:00
|
|
|
virtual void onFontChange(const std::string& font);
|
|
|
|
|
2012-01-04 11:26:58 +01:00
|
|
|
std::string m_text;
|
2012-03-26 00:14:00 +02:00
|
|
|
std::string m_drawText;
|
2012-01-04 11:26:58 +01:00
|
|
|
Fw::AlignmentFlag m_textAlign;
|
2012-01-10 23:13:40 +01:00
|
|
|
Point m_textOffset;
|
2012-07-29 12:32:44 +02:00
|
|
|
stdext::boolean<false> m_textWrap;
|
2013-02-09 22:57:37 +01:00
|
|
|
stdext::boolean<false> m_textVerticalAutoResize;
|
|
|
|
stdext::boolean<false> m_textHorizontalAutoResize;
|
2012-08-05 20:26:08 +02:00
|
|
|
stdext::boolean<false> m_textOnlyUpperCase;
|
2012-06-17 01:19:43 +02:00
|
|
|
BitmapFontPtr m_font;
|
2012-01-10 23:13:40 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
void resizeToText() { setSize(getTextSize()); }
|
|
|
|
void clearText() { setText(""); }
|
|
|
|
|
2012-08-05 20:26:08 +02:00
|
|
|
void setText(std::string text);
|
2012-03-26 00:14:00 +02:00
|
|
|
void setTextAlign(Fw::AlignmentFlag align) { m_textAlign = align; updateText(); }
|
|
|
|
void setTextOffset(const Point& offset) { m_textOffset = offset; updateText(); }
|
|
|
|
void setTextWrap(bool textWrap) { m_textWrap = textWrap; updateText(); }
|
2013-02-09 22:57:37 +01:00
|
|
|
void setTextAutoResize(bool textAutoResize) { m_textHorizontalAutoResize = textAutoResize; m_textVerticalAutoResize = textAutoResize; updateText(); }
|
|
|
|
void setTextHorizontalAutoResize(bool textAutoResize) { m_textHorizontalAutoResize = textAutoResize; updateText(); }
|
|
|
|
void setTextVerticalAutoResize(bool textAutoResize) { m_textVerticalAutoResize = textAutoResize; updateText(); }
|
2012-08-05 20:26:08 +02:00
|
|
|
void setTextOnlyUpperCase(bool textOnlyUpperCase) { m_textOnlyUpperCase = textOnlyUpperCase; setText(m_text); }
|
2012-01-10 23:13:40 +01:00
|
|
|
void setFont(const std::string& fontName);
|
|
|
|
|
|
|
|
std::string getText() { return m_text; }
|
2012-03-26 00:14:00 +02:00
|
|
|
std::string getDrawText() { return m_drawText; }
|
2012-01-10 23:13:40 +01:00
|
|
|
Fw::AlignmentFlag getTextAlign() { return m_textAlign; }
|
|
|
|
Point getTextOffset() { return m_textOffset; }
|
2012-03-26 00:14:00 +02:00
|
|
|
bool getTextWrap() { return m_textWrap; }
|
2012-01-10 23:13:40 +01:00
|
|
|
std::string getFont() { return m_font->getName(); }
|
2012-03-26 00:14:00 +02:00
|
|
|
Size getTextSize() { return m_font->calculateTextRectSize(m_drawText); }
|
2011-08-14 04:09:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|