From bb6784e0e1a385cdd20b41d3254093e89a210332 Mon Sep 17 00:00:00 2001 From: pescuma Date: Wed, 31 Dec 2008 21:12:58 +0000 Subject: skins: Added SkinLib git-svn-id: http://pescuma.googlecode.com/svn/trunk/Miranda@120 c086bb3d-8645-0410-b8da-73a8550f86e7 --- Plugins/skins/SkinLib/FieldState.cpp | 175 +++++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 Plugins/skins/SkinLib/FieldState.cpp (limited to 'Plugins/skins/SkinLib/FieldState.cpp') diff --git a/Plugins/skins/SkinLib/FieldState.cpp b/Plugins/skins/SkinLib/FieldState.cpp new file mode 100644 index 0000000..7186b0c --- /dev/null +++ b/Plugins/skins/SkinLib/FieldState.cpp @@ -0,0 +1,175 @@ +#include "globals.h" +#include "FieldState.h" + +#define START 1<<0 +#define LEN 1<<1 +#define END 1<<2 +#define USING_MASK 0xFF +#define LAST_SHIFT 8 +#define SET(_FIELD_, _ITEM_) _FIELD_ = (((_FIELD_ | _ITEM_) & USING_MASK) | (_ITEM_ << LAST_SHIFT)) +#define LAST_SET(_FIELD_) (_FIELD_ >> LAST_SHIFT) + + +FieldState::FieldState(Field *aField) : field(aField), size(-1, -1), pos(0, 0), + usingX(0), usingY(0), visible(true) +{ +} + +FieldState::~FieldState() +{ +} + +Field * FieldState::getField() const +{ + return field; +} + +int FieldState::getX() const +{ + return pos.x; +} + +void FieldState::setX(int x) +{ + if (usingX & END) + { + int diff = x - getX(); + size.x = max(0, getWidth() - diff); + } + + pos.x = x; + + SET(usingX, START); +} + +int FieldState::getY() const +{ + return pos.y; +} + +void FieldState::setY(int y) +{ + if (usingY & END) + { + int diff = y - getY(); + size.y = max(0, getHeight() - diff); + } + + pos.y = y; + + SET(usingY, START); +} + +int FieldState::getWidth() const +{ + if (size.x >= 0) + return size.x; + + return getPreferedSize().x; +} + +void FieldState::setWidth(int width) +{ + width = max(0, width); + + if (LAST_SET(usingX) == END) + { + int diff = width - getWidth(); + pos.x = getX() - diff; + } + + size.x = width; + + usingX |= LEN; +} + +int FieldState::getHeight() const +{ + if (size.y >= 0) + return size.y; + + return getPreferedSize().y; +} + +void FieldState::setHeight(int height) +{ + height = max(0, height); + + if (LAST_SET(usingY) == END) + { + int diff = height - getHeight(); + pos.y = getY() - diff; + } + + size.y = height; + + usingY |= LEN; +} + +bool FieldState::isVisible() const +{ + return visible; +} + +void FieldState::setVisible(bool visible) +{ + this->visible = visible; +} + +int FieldState::getLeft() const +{ + return getX(); +} + +void FieldState::setLeft(int left) +{ + setX(left); +} + +int FieldState::getTop() const +{ + return getY(); +} + +void FieldState::setTop(int top) +{ + setY(top); +} + +int FieldState::getRight() const +{ + return getX() + getWidth(); +} + +void FieldState::setRight(int right) +{ + if (usingX & START) + { + size.x = max(0, right - getX()); + } + else + { + pos.x = right - getWidth(); + } + + SET(usingX, END); +} + +int FieldState::getBottom() const +{ + return getY() + getHeight(); +} + +void FieldState::setBottom(int botom) +{ + if (usingY & START) + { + size.y = max(0, botom - getY()); + } + else + { + pos.y = botom - getHeight(); + } + + SET(usingY, END); +} \ No newline at end of file -- cgit v1.2.3