commit
0b0a62b351
@ -0,0 +1,123 @@
|
|||||||
|
/* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "anchorlayout.h"
|
||||||
|
|
||||||
|
int AnchorLine::getPos() const
|
||||||
|
{
|
||||||
|
AnchorLayoutPtr element = m_relativeElement.lock();
|
||||||
|
if(element) {
|
||||||
|
switch(m_anchorType) {
|
||||||
|
case ANCHOR_LEFT:
|
||||||
|
return element->getRect().left();
|
||||||
|
case ANCHOR_RIGHT:
|
||||||
|
return element->getRect().right();
|
||||||
|
case ANCHOR_TOP:
|
||||||
|
return element->getRect().top();
|
||||||
|
case ANCHOR_BOTTOM:
|
||||||
|
return element->getRect().bottom();
|
||||||
|
case ANCHOR_HORIZONTAL_CENTER:
|
||||||
|
return element->getRect().horizontalCenter();
|
||||||
|
case ANCHOR_VERTICAL_CENTER:
|
||||||
|
return element->getRect().verticalCenter();
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logError("anchor line of an element have expired");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AnchorLayout::setSize(const Size& size)
|
||||||
|
{
|
||||||
|
m_rect.setSize(size);
|
||||||
|
recalculateAnchors();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AnchorLayout::setRect(const Rect& rect)
|
||||||
|
{
|
||||||
|
m_rect = rect;
|
||||||
|
recalculateAnchors();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AnchorLayout::addAnchor(EAnchorType type, const AnchorLine& anchorLine)
|
||||||
|
{
|
||||||
|
if(!anchorLine.isValid()) {
|
||||||
|
logError("anchoring for an element has failed, got an invalid anchor line");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_anchors[type] = anchorLine;
|
||||||
|
anchorLine.getRelativeElement()->addAnchoredElement(asAnchorLayout());
|
||||||
|
recalculateAnchors();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AnchorLayout::addAnchoredElement(AnchorLayoutPtr anchoredElement)
|
||||||
|
{
|
||||||
|
bool found = false;
|
||||||
|
for(auto it = m_anchoredElements.begin(); it != m_anchoredElements.end(); ++it) {
|
||||||
|
if((*it).lock() == anchoredElement) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!found)
|
||||||
|
m_anchoredElements.push_back(anchoredElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AnchorLayout::recalculateAnchors()
|
||||||
|
{
|
||||||
|
// horizontal
|
||||||
|
if(m_anchors[ANCHOR_HORIZONTAL_CENTER].isValid()) {
|
||||||
|
m_rect.moveHorizontalCenter(m_anchors[ANCHOR_HORIZONTAL_CENTER].getPos() + m_marginLeft - m_marginRight);
|
||||||
|
} else {
|
||||||
|
if(m_anchors[ANCHOR_LEFT].isValid() && m_anchors[ANCHOR_RIGHT].isValid()) {
|
||||||
|
m_rect.setLeft(m_anchors[ANCHOR_LEFT].getPos() + m_marginLeft);
|
||||||
|
m_rect.setRight(m_anchors[ANCHOR_RIGHT].getPos() - m_marginRight);
|
||||||
|
} else if(m_anchors[ANCHOR_LEFT].isValid()) {
|
||||||
|
m_rect.moveLeft(m_anchors[ANCHOR_LEFT].getPos() + m_marginLeft);
|
||||||
|
} else if(m_anchors[ANCHOR_RIGHT].isValid()) {
|
||||||
|
m_rect.moveRight(m_anchors[ANCHOR_RIGHT].getPos() - m_marginRight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// vertical
|
||||||
|
if(m_anchors[ANCHOR_VERTICAL_CENTER].isValid()) {
|
||||||
|
m_rect.moveVerticalCenter(m_anchors[ANCHOR_VERTICAL_CENTER].getPos() + m_marginTop - m_marginBottom);
|
||||||
|
} else {
|
||||||
|
if(m_anchors[ANCHOR_TOP].isValid() && m_anchors[ANCHOR_BOTTOM].isValid()) {
|
||||||
|
m_rect.setLeft(m_anchors[ANCHOR_TOP].getPos() + m_marginTop);
|
||||||
|
m_rect.setRight(m_anchors[ANCHOR_BOTTOM].getPos() - m_marginBottom);
|
||||||
|
} else if(m_anchors[ANCHOR_TOP].isValid()) {
|
||||||
|
m_rect.moveTop(m_anchors[ANCHOR_TOP].getPos() + m_marginTop);
|
||||||
|
} else if(m_anchors[ANCHOR_BOTTOM].isValid()) {
|
||||||
|
m_rect.moveBottom(m_anchors[ANCHOR_BOTTOM].getPos() - m_marginBottom);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(auto it = m_anchoredElements.begin(); it != m_anchoredElements.end(); ++it) {
|
||||||
|
AnchorLayoutPtr element = (*it).lock();
|
||||||
|
if(element)
|
||||||
|
element->recalculateAnchors();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,116 @@
|
|||||||
|
/* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||||
|
*
|
||||||
|
* 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 ANCHORLAYOUT_H
|
||||||
|
#define ANCHORLAYOUT_H
|
||||||
|
|
||||||
|
#include "../prerequisites.h"
|
||||||
|
#include "../rect.h"
|
||||||
|
#include "uiconstants.h"
|
||||||
|
|
||||||
|
enum EAnchorType {
|
||||||
|
ANCHOR_LEFT = 0,
|
||||||
|
ANCHOR_RIGHT,
|
||||||
|
ANCHOR_TOP,
|
||||||
|
ANCHOR_BOTTOM,
|
||||||
|
ANCHOR_HORIZONTAL_CENTER,
|
||||||
|
ANCHOR_VERTICAL_CENTER,
|
||||||
|
ANCHOR_NONE
|
||||||
|
};
|
||||||
|
|
||||||
|
class AnchorLayout;
|
||||||
|
typedef std::shared_ptr<AnchorLayout> AnchorLayoutPtr;
|
||||||
|
typedef std::weak_ptr<AnchorLayout> AnchorLayoutWeakPtr;
|
||||||
|
|
||||||
|
class AnchorLine
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AnchorLine() : m_anchorType(ANCHOR_NONE) { }
|
||||||
|
AnchorLine(const AnchorLine& other) :
|
||||||
|
m_relativeElement(other.m_relativeElement), m_anchorType(other.m_anchorType) { }
|
||||||
|
AnchorLine(AnchorLayoutPtr relativeElement, EAnchorType anchorType) :
|
||||||
|
m_relativeElement(relativeElement), m_anchorType(anchorType) { }
|
||||||
|
bool isValid() const { return (m_anchorType != ANCHOR_NONE && !m_relativeElement.expired()); }
|
||||||
|
|
||||||
|
int getPos() const;
|
||||||
|
EAnchorType getAnchorType() const { return m_anchorType; }
|
||||||
|
AnchorLayoutPtr getRelativeElement() const { return m_relativeElement.lock(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
AnchorLayoutWeakPtr m_relativeElement;
|
||||||
|
EAnchorType m_anchorType;
|
||||||
|
};
|
||||||
|
|
||||||
|
class AnchorLayout : public std::enable_shared_from_this<AnchorLayout>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AnchorLayout() :
|
||||||
|
m_marginLeft(0),
|
||||||
|
m_marginRight(0),
|
||||||
|
m_marginTop(0),
|
||||||
|
m_marginBottom(0) { }
|
||||||
|
virtual ~AnchorLayout() { }
|
||||||
|
|
||||||
|
void setSize(const Size& size);
|
||||||
|
Size getSize() { return m_rect.size(); }
|
||||||
|
|
||||||
|
void setRect(const Rect& rect);
|
||||||
|
const Rect& getRect() const{ return m_rect; }
|
||||||
|
|
||||||
|
void addAnchor(EAnchorType type, const AnchorLine& anchorLine);
|
||||||
|
void anchorLeft(const AnchorLine& anchorLine) { addAnchor(ANCHOR_LEFT, anchorLine); }
|
||||||
|
void anchorRight(const AnchorLine& anchorLine) { addAnchor(ANCHOR_RIGHT, anchorLine); }
|
||||||
|
void anchorTop(const AnchorLine& anchorLine) { addAnchor(ANCHOR_TOP, anchorLine); }
|
||||||
|
void anchorBottom(const AnchorLine& anchorLine) { addAnchor(ANCHOR_BOTTOM, anchorLine); }
|
||||||
|
void anchorHorizontalCenter(const AnchorLine& anchorLine) { addAnchor(ANCHOR_HORIZONTAL_CENTER, anchorLine); }
|
||||||
|
void anchorVerticalCenter(const AnchorLine& anchorLine) { addAnchor(ANCHOR_VERTICAL_CENTER, anchorLine); }
|
||||||
|
|
||||||
|
AnchorLine left() { return AnchorLine(asAnchorLayout(), ANCHOR_LEFT); }
|
||||||
|
AnchorLine right() { return AnchorLine(asAnchorLayout(), ANCHOR_RIGHT); }
|
||||||
|
AnchorLine top() { return AnchorLine(asAnchorLayout(), ANCHOR_TOP); }
|
||||||
|
AnchorLine bottom() { return AnchorLine(asAnchorLayout(), ANCHOR_BOTTOM); }
|
||||||
|
AnchorLine horizontalCenter() { return AnchorLine(asAnchorLayout(), ANCHOR_HORIZONTAL_CENTER); }
|
||||||
|
AnchorLine verticalCenter() { return AnchorLine(asAnchorLayout(), ANCHOR_VERTICAL_CENTER); }
|
||||||
|
|
||||||
|
void setMargin(int top, int left, int bottom, int right) { m_marginLeft = left; m_marginRight = right; m_marginTop = top; m_marginBottom = bottom; recalculateAnchors(); }
|
||||||
|
void setMargin(int horizontal, int vertical) { m_marginLeft = m_marginRight = horizontal; m_marginTop = m_marginBottom = vertical; recalculateAnchors(); }
|
||||||
|
void setMargin(int margin) { m_marginLeft = m_marginRight = m_marginTop = m_marginBottom = margin; recalculateAnchors(); }
|
||||||
|
|
||||||
|
AnchorLayoutPtr asAnchorLayout() { return shared_from_this(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
void recalculateAnchors();
|
||||||
|
void addAnchoredElement(AnchorLayoutPtr anchoredElement);
|
||||||
|
|
||||||
|
AnchorLine m_anchors[6];
|
||||||
|
|
||||||
|
Rect m_rect;
|
||||||
|
int m_marginLeft;
|
||||||
|
int m_marginRight;
|
||||||
|
int m_marginTop;
|
||||||
|
int m_marginBottom;
|
||||||
|
std::list<AnchorLayoutWeakPtr> m_anchoredElements;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ANCHORLAYOUT_H
|
@ -0,0 +1,50 @@
|
|||||||
|
/* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "uibuttonskin.h"
|
||||||
|
#include "uibutton.h"
|
||||||
|
|
||||||
|
void UIButtonSkin::draw(UIElement *element)
|
||||||
|
{
|
||||||
|
UIButton *button = static_cast<UIButton*>(element);
|
||||||
|
|
||||||
|
if(button->getState() == UI::ButtonDown && m_buttonDownImage) {
|
||||||
|
m_buttonDownImage->draw(element->getRect());
|
||||||
|
} else if(button->getState() == UI::ButtonMouseOver && m_buttonHoverImage) {
|
||||||
|
m_buttonHoverImage->draw(element->getRect());
|
||||||
|
} else {
|
||||||
|
UIElementSkin::draw(element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIButtonSkin::load(const YAML::Node& node)
|
||||||
|
{
|
||||||
|
UIElementSkin::load(node);
|
||||||
|
|
||||||
|
if(node.FindValue("down state"))
|
||||||
|
m_buttonDownImage = loadImage(node["down state"]);
|
||||||
|
|
||||||
|
if(node.FindValue("mouse over state"))
|
||||||
|
m_buttonHoverImage = loadImage(node["mouse over state"]);
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
/* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||||
|
*
|
||||||
|
* 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 UIBUTTONSKIN_H
|
||||||
|
#define UIBUTTONSKIN_H
|
||||||
|
|
||||||
|
#include "../prerequisites.h"
|
||||||
|
#include "uiconstants.h"
|
||||||
|
#include "uielementskin.h"
|
||||||
|
|
||||||
|
class UIButtonSkin : public UIElementSkin
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
UIButtonSkin(const std::string& name) :
|
||||||
|
UIElementSkin(name, UI::Button) { }
|
||||||
|
|
||||||
|
void load(const YAML::Node& node);
|
||||||
|
void draw(UIElement *element);
|
||||||
|
|
||||||
|
private:
|
||||||
|
ImagePtr m_buttonDownImage;
|
||||||
|
ImagePtr m_buttonHoverImage;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // UIBUTTONSKIN_H
|
@ -0,0 +1,45 @@
|
|||||||
|
/* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "uitextedit.h"
|
||||||
|
#include "../fonts.h"
|
||||||
|
|
||||||
|
UITextEdit::UITextEdit(Font* font) :
|
||||||
|
UIElement(UI::TextEdit),
|
||||||
|
m_font(font)
|
||||||
|
{
|
||||||
|
if(!font)
|
||||||
|
m_font = g_fonts.get("tibia-10px-antialised");
|
||||||
|
}
|
||||||
|
|
||||||
|
void UITextEdit::render()
|
||||||
|
{
|
||||||
|
UIElement::render();
|
||||||
|
m_font->renderText(m_text, getRect(), ALIGN_LEFT, Color(0xFFBFBFBF));
|
||||||
|
}
|
||||||
|
|
||||||
|
void UITextEdit::setText(const std::string& text)
|
||||||
|
{
|
||||||
|
m_text = text;
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
/* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||||
|
*
|
||||||
|
* 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 UITEXTEDIT_H
|
||||||
|
#define UITEXTEDIT_H
|
||||||
|
|
||||||
|
#include "../prerequisites.h"
|
||||||
|
#include "uielement.h"
|
||||||
|
|
||||||
|
class Font;
|
||||||
|
|
||||||
|
class UITextEdit : public UIElement
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
UITextEdit(Font *font = NULL);
|
||||||
|
|
||||||
|
void render();
|
||||||
|
|
||||||
|
void setText(const std::string& text);
|
||||||
|
const std::string& getText() const { return m_text; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string m_text;
|
||||||
|
Font *m_font;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::shared_ptr<UITextEdit> UITextEditPtr;
|
||||||
|
|
||||||
|
#endif // UITEXTEDIT_H
|
@ -0,0 +1,26 @@
|
|||||||
|
/* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "uitexteditskin.h"
|
||||||
|
|
@ -0,0 +1,40 @@
|
|||||||
|
/* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||||
|
*
|
||||||
|
* 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 UITEXTEDITSKIN_H
|
||||||
|
#define UITEXTEDITSKIN_H
|
||||||
|
|
||||||
|
#include "../prerequisites.h"
|
||||||
|
#include "uiconstants.h"
|
||||||
|
#include "uielementskin.h"
|
||||||
|
|
||||||
|
class UITextEditSkin : public UIElementSkin
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
UITextEditSkin(const std::string& name) :
|
||||||
|
UIElementSkin(name, UI::TextEdit) { }
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // UITEXTEDITSKIN_H
|
@ -0,0 +1,26 @@
|
|||||||
|
/* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "uiwindow.h"
|
||||||
|
|
@ -0,0 +1,46 @@
|
|||||||
|
/* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||||
|
*
|
||||||
|
* 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 UIWINDOW_H
|
||||||
|
#define UIWINDOW_H
|
||||||
|
|
||||||
|
#include "../prerequisites.h"
|
||||||
|
#include "uicontainer.h"
|
||||||
|
|
||||||
|
class UIWindow : public UIContainer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
UIWindow(const std::string& title) :
|
||||||
|
UIContainer(UI::Window),
|
||||||
|
m_title(title) { }
|
||||||
|
|
||||||
|
const std::string& getTitle() const { return m_title; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string m_title;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::shared_ptr<UIWindow> UIWindowPtr;
|
||||||
|
|
||||||
|
#endif // UIWINDOW_H
|
@ -0,0 +1,60 @@
|
|||||||
|
/* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "uiwindowskin.h"
|
||||||
|
#include "uiwindow.h"
|
||||||
|
#include "../fonts.h"
|
||||||
|
|
||||||
|
void UIWindowSkin::draw(UIElement* element)
|
||||||
|
{
|
||||||
|
UIElementSkin::draw(element);
|
||||||
|
|
||||||
|
UIWindow *window = static_cast<UIWindow*>(element);
|
||||||
|
|
||||||
|
Rect headRect = window->getRect();
|
||||||
|
Rect bodyRect = window->getRect();
|
||||||
|
|
||||||
|
headRect.setHeight(m_headHeight);
|
||||||
|
bodyRect.setTop(headRect.bottom() + 1);
|
||||||
|
|
||||||
|
m_headImage->draw(headRect);
|
||||||
|
m_titleFont->renderText(window->getTitle(),
|
||||||
|
headRect,
|
||||||
|
ALIGN_CENTER,
|
||||||
|
Color(0xFF8F8F8F));
|
||||||
|
|
||||||
|
m_bodyImage->draw(bodyRect);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIWindowSkin::load(const YAML::Node& node)
|
||||||
|
{
|
||||||
|
UIElementSkin::load(node);
|
||||||
|
|
||||||
|
node["head"]["height"] >> m_headHeight;
|
||||||
|
m_headImage = loadImage(node["head"]);
|
||||||
|
m_bodyImage = loadImage(node["body"]);
|
||||||
|
|
||||||
|
std::string fontName;
|
||||||
|
node["head"]["font"] >> fontName;
|
||||||
|
m_titleFont = g_fonts.get(fontName);
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
/* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||||
|
*
|
||||||
|
* 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 UIWINDOWSKIN_H
|
||||||
|
#define UIWINDOWSKIN_H
|
||||||
|
|
||||||
|
#include "../prerequisites.h"
|
||||||
|
#include "uiconstants.h"
|
||||||
|
#include "uielementskin.h"
|
||||||
|
#include "../font.h"
|
||||||
|
|
||||||
|
class UIWindowSkin : public UIElementSkin
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
UIWindowSkin(const std::string& name) :
|
||||||
|
UIElementSkin(name, UI::Window) { }
|
||||||
|
|
||||||
|
void load(const YAML::Node& node);
|
||||||
|
void draw(UIElement *element);
|
||||||
|
|
||||||
|
private:
|
||||||
|
ImagePtr m_headImage;
|
||||||
|
ImagePtr m_bodyImage;
|
||||||
|
Font *m_titleFont;
|
||||||
|
int m_headHeight;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // UIWINDOWSKIN_H
|
Loading…
Reference in new issue