window ui

This commit is contained in:
Eduardo Bart
2011-04-09 19:55:58 -03:00
parent a9a110f44b
commit f2bdc89d8d
18 changed files with 338 additions and 59 deletions

View File

@@ -29,11 +29,11 @@
#include "uiconstants.h"
#include "uielement.h"
#include "uielementskin.h"
#include "uicontainer.h"
#include "uipanel.h"
#include "uibutton.h"
#include "uilabel.h"
#include "uiskins.h"
#include "uiwindow.h"
#endif // UI_H

View File

@@ -30,7 +30,7 @@ void UIButton::render()
{
UIElement::render();
g_fonts.get("tibia-8px-antialised")->renderText(m_text, getRect(), ALIGN_CENTER);
g_fonts.get("tibia-8px-antialised")->renderText(m_text, getRect(), ALIGN_CENTER, Color(0xFFEEEEEE));
}
bool UIButton::onInputEvent(const InputEvent& event)

View File

@@ -27,7 +27,6 @@
void UIButtonSkin::draw(UIElement *element)
{
UIButton *button = static_cast<UIButton*>(element);
if(button->getState() == UI::ButtonDown && m_buttonDownImage) {

View File

@@ -47,15 +47,24 @@ ImagePtr UIElementSkin::loadImage(const YAML::Node& node)
if(node.FindValue("bordered image")) {
const YAML::Node& child = node["bordered image"];
Rect left, right, top, bottom, topLeft, topRight, bottomLeft, bottomRight, center;
child["left border"] >> left;
child["right border"] >> right;
child["top border"] >> top;
child["bottom border"] >> bottom;
child["top left corner"] >> topLeft;
child["top right corner"] >> topRight;
child["bottom left corner"] >> bottomLeft;
child["bottom right corner"] >> bottomRight;
child["center"] >> center;
if(child.FindValue("left border"))
child["left border"] >> left;
if(child.FindValue("right border"))
child["right border"] >> right;
if(child.FindValue("top border"))
child["top border"] >> top;
if(child.FindValue("bottom border"))
child["bottom border"] >> bottom;
if(child.FindValue("top left corner"))
child["top left corner"] >> topLeft;
if(child.FindValue("top right corner"))
child["top right corner"] >> topRight;
if(child.FindValue("bottom left corner"))
child["bottom left corner"] >> bottomLeft;
if(child.FindValue("bottom right corner"))
child["bottom right corner"] >> bottomRight;
if(child.FindValue("center"))
child["center"] >> center;
TexturePtr texture;
if(child.FindValue("image")) {

View File

@@ -27,6 +27,7 @@
#include "../textures.h"
#include "uielementskin.h"
#include "uibuttonskin.h"
#include "uiwindowskin.h"
UISkins g_uiSkins;
@@ -79,6 +80,18 @@ bool UISkins::load(const std::string& file)
m_elementSkins.push_back(skin);
}
}
{
const YAML::Node& node = doc["windows"];
for(auto it = node.begin(); it != node.end(); ++it) {
std::string name;
it.first() >> name;
UIWindowSkin *skin = new UIWindowSkin(name, UI::Window);
skin->load(it.second());
m_elementSkins.push_back(skin);
}
}
} catch (YAML::ParserException& e) {
logError("Malformed font file \"%s\"", file.c_str());
return false;

View File

@@ -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"

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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, UI::EElementType elementType) :
UIElementSkin(name, elementType) { }
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