many changes and refactoring

This commit is contained in:
Eduardo Bart
2011-07-13 18:12:36 -03:00
parent 6c05ee0e82
commit 8ef1b28546
120 changed files with 1545 additions and 1273 deletions

View File

@@ -25,7 +25,7 @@
#ifndef UI_H
#define UI_H
#include <prerequisites.h>
#include <global.h>
#include <ui/uiconstants.h>
#include <ui/uiskins.h>

View File

@@ -22,7 +22,7 @@
*/
#include <prerequisites.h>
#include <global.h>
#include <ui/uianchorlayout.h>
UIElementPtr Anchor::getAnchorLineElement() const
@@ -61,19 +61,19 @@ bool UIAnchorLayout::addAnchor(const UIElementPtr& anchoredElement, UI::AnchorPo
UIElementPtr anchorLineElement = anchor.getAnchorLineElement();
if(!anchorLineElement) {
logError("ERROR: could not find the element to anchor on, wrong id?");
error("ERROR: could not find the element to anchor on, wrong id?");
return false;
}
// we can never anchor with itself
if(anchoredElement == anchorLineElement) {
logError("ERROR: anchoring with itself is not possible");
error("ERROR: anchoring with itself is not possible");
return false;
}
// we must never anchor to an anchor child
if(hasElementInAnchorTree(anchorLineElement, anchoredElement)) {
logError("ERROR: anchors is miss configurated, you must never make anchor chains in loops");
error("ERROR: anchors is miss configurated, you must never make anchor chains in loops");
return false;
}

View File

@@ -25,7 +25,7 @@
#ifndef UIANCHORLAYOUT_H
#define UIANCHORLAYOUT_H
#include <prerequisites.h>
#include <global.h>
#include <ui/uiconstants.h>
#include <ui/uilayout.h>
#include <ui/uielement.h>

View File

@@ -22,7 +22,7 @@
*/
#include <prerequisites.h>
#include <global.h>
#include <core/dispatcher.h>
#include <ui/uibutton.h>
#include "uicontainer.h"

View File

@@ -25,7 +25,7 @@
#ifndef UIBUTTON_H
#define UIBUTTON_H
#include <prerequisites.h>
#include <global.h>
#include <ui/uielement.h>
#include <graphics/borderedimage.h>

View File

@@ -22,25 +22,25 @@
*/
#include <prerequisites.h>
#include <global.h>
#include <graphics/fonts.h>
#include <ui/uibuttonskin.h>
#include <ui/uibutton.h>
void UIButtonSkin::load(FML::Node* node)
void UIButtonSkin::load(OTMLNode* node)
{
UIElementSkin::load(node);
m_buttonDownTextColor = getFontColor();
m_buttonHoverTextColor = getFontColor();
if(FML::Node* cnode = node->at("down state")) {
if(OTMLNode* cnode = node->at("down state")) {
m_buttonDownImage = loadImage(cnode);
m_buttonDownTranslate = cnode->readAt("text translate", Point());
m_buttonDownTextColor = cnode->readAt("font color", getFontColor());
}
if(FML::Node* cnode = node->at("hover state")) {
if(OTMLNode* cnode = node->at("hover state")) {
m_buttonHoverImage = loadImage(cnode);
m_buttonHoverTextColor = cnode->readAt("font color", getFontColor());
}

View File

@@ -25,7 +25,7 @@
#ifndef UIBUTTONSKIN_H
#define UIBUTTONSKIN_H
#include <prerequisites.h>
#include <global.h>
#include <ui/uiconstants.h>
#include <ui/uielementskin.h>
@@ -37,7 +37,7 @@ public:
UIButtonSkin(const std::string& name) :
UIElementSkin(name, UI::Button) { }
void load(FML::Node* node);
void load(OTMLNode* node);
void draw(UIElement *element);
private:

View File

@@ -22,7 +22,7 @@
*/
#include <prerequisites.h>
#include <global.h>
#include <ui/uicheckbox.h>
UICheckBox::UICheckBox(UI::ElementType type): UIElement(type)

View File

@@ -25,7 +25,7 @@
#ifndef UICHECKBOX_H
#define UICHECKBOX_H
#include <prerequisites.h>
#include <global.h>
#include <ui/uielement.h>
class UICheckBox : public UIElement

View File

@@ -22,6 +22,6 @@
*/
#include <prerequisites.h>
#include <global.h>
#include <ui/uicheckboxskin.h>

View File

@@ -25,7 +25,7 @@
#ifndef UICHECKBOXSKIN_H
#define UICHECKBOXSKIN_H
#include <prerequisites.h>
#include <global.h>
#include <ui/uielementskin.h>
class UICheckBoxSkin : public UIElementSkin

View File

@@ -22,7 +22,7 @@
*/
#include <prerequisites.h>
#include <global.h>
#include <core/resources.h>
#include <ui/uicontainer.h>
#include <ui/uianchorlayout.h>

View File

@@ -25,7 +25,7 @@
#ifndef UICONTAINER_H
#define UICONTAINER_H
#include <prerequisites.h>
#include <global.h>
#include <ui/uielement.h>
class UIContainer : public UIElement

View File

@@ -22,7 +22,7 @@
*/
#include <prerequisites.h>
#include <global.h>
#include <core/dispatcher.h>
#include <graphics/graphics.h>
#include <ui/uielement.h>
@@ -79,7 +79,7 @@ void UIElement::destroyCheck()
UIElementPtr me = asUIElement();
// check for leaks, the number of references must be always 2 here
if(me.use_count() != 2 && me != UIContainer::getRoot()) {
flogWarning("destroyed element with id '%s', but it still have %d references left", getId() % (me.use_count()-2));
warning("destroyed element with id '",getId(),"', but it still have ",(me.use_count()-2)," references left");
}
}

View File

@@ -25,7 +25,7 @@
#ifndef UIELEMENT_H
#define UIELEMENT_H
#include <prerequisites.h>
#include <global.h>
#include <core/input.h>
#include <script/scriptable.h>
#include <ui/uiconstants.h>

View File

@@ -22,7 +22,7 @@
*/
#include <prerequisites.h>
#include <global.h>
#include <ui/uiskins.h>
#include <ui/uielement.h>
#include <ui/uielementskin.h>
@@ -30,7 +30,7 @@
#include <graphics/textures.h>
#include <graphics/fonts.h>
void UIElementSkin::load(FML::Node* node)
void UIElementSkin::load(OTMLNode* node)
{
m_defaultSize = node->readAt("default size", Size());
m_defaultImage = loadImage(node);
@@ -50,12 +50,12 @@ void UIElementSkin::draw(UIElement *element)
m_defaultImage->draw(element->getRect());
}
ImagePtr UIElementSkin::loadImage(FML::Node* node)
ImagePtr UIElementSkin::loadImage(OTMLNode* node)
{
ImagePtr image;
TexturePtr texture;
if(FML::Node* cnode = node->at("bordered image")) {
if(OTMLNode* cnode = node->at("bordered image")) {
Rect left = cnode->readAt("left border", Rect());
Rect right = cnode->readAt("right border", Rect());
Rect top = cnode->readAt("top border", Rect());
@@ -86,8 +86,8 @@ ImagePtr UIElementSkin::loadImage(FML::Node* node)
}
if(!image)
logError(node->generateErrorMessage("failed to load bordered image"));
} else if(FML::Node* cnode = node->at("image")) {
error(node->generateErrorMessage("failed to load bordered image"));
} else if(OTMLNode* cnode = node->at("image")) {
texture = g_textures.get(cnode->value());
if(texture)
image = ImagePtr(new Image(texture));
@@ -95,7 +95,7 @@ ImagePtr UIElementSkin::loadImage(FML::Node* node)
m_defaultSize = texture->getSize();
if(!image)
logError(cnode->generateErrorMessage("failed to load image"));
error(cnode->generateErrorMessage("failed to load image"));
}
if(texture) {
@@ -107,10 +107,10 @@ ImagePtr UIElementSkin::loadImage(FML::Node* node)
return image;
}
FontPtr UIElementSkin::loadFont(FML::Node* node)
FontPtr UIElementSkin::loadFont(OTMLNode* node)
{
FontPtr font;
if(FML::Node* cnode = node->at("font"))
if(OTMLNode* cnode = node->at("font"))
font = g_fonts.get(cnode->value());
if(!font)
font = g_uiSkins.getDefaultFont();

View File

@@ -25,10 +25,11 @@
#ifndef UIELEMENTSKIN_H
#define UIELEMENTSKIN_H
#include <prerequisites.h>
#include <global.h>
#include <graphics/image.h>
#include <ui/uiconstants.h>
#include <graphics/font.h>
#include <otml/otmlnode.h>
class UIElement;
@@ -42,7 +43,7 @@ public:
virtual ~UIElementSkin() { }
/// Load the skin from a FML node
virtual void load(FML::Node* node);
virtual void load(OTMLNode* node);
/// Apply the skin to an element
virtual void apply(UIElement *element);
/// Draw the skinned element
@@ -56,8 +57,8 @@ public:
Color getFontColor() const { return m_fontColor; }
protected:
ImagePtr loadImage(FML::Node* node);
FontPtr loadFont(FML::Node* node);
ImagePtr loadImage(OTMLNode* node);
FontPtr loadFont(OTMLNode* node);
private:
std::string m_name;

View File

@@ -22,7 +22,7 @@
*/
#include <prerequisites.h>
#include <global.h>
#include <ui/uilabel.h>
void UILabel::setText(const std::string& text)

View File

@@ -25,7 +25,7 @@
#ifndef UILABEL_H
#define UILABEL_H
#include <prerequisites.h>
#include <global.h>
#include <ui/uielement.h>
#include <graphics/font.h>

View File

@@ -22,12 +22,12 @@
*/
#include <prerequisites.h>
#include <global.h>
#include <graphics/fonts.h>
#include <ui/uilabelskin.h>
#include <ui/uilabel.h>
void UILabelSkin::load(FML::Node* node)
void UILabelSkin::load(OTMLNode* node)
{
UIElementSkin::load(node);
}

View File

@@ -25,7 +25,7 @@
#ifndef UILABELSKIN_H
#define UILABELSKIN_H
#include <prerequisites.h>
#include <global.h>
#include <graphics/font.h>
#include <ui/uielementskin.h>
@@ -35,7 +35,7 @@ public:
UILabelSkin(const std::string& name) :
UIElementSkin(name, UI::Label) { }
void load(FML::Node* node);
void load(OTMLNode* node);
void apply(UIElement *element);
void draw(UIElement *element);
};

View File

@@ -25,7 +25,7 @@
#ifndef UILAYOUT_H
#define UILAYOUT_H
#include <prerequisites.h>
#include <global.h>
class UIElement;
typedef boost::shared_ptr<UIElement> UIElementPtr;

View File

@@ -22,13 +22,17 @@
*/
#include <prerequisites.h>
#include <global.h>
#include <core/resources.h>
#include <ui/ui.h>
#include <ui/uiloader.h>
#include <script/luascript.h>
#include <script/luafunctions.h>
#include "uianchorlayout.h"
#include <otml/otml.h>
#include <ui/uianchorlayout.h>
#include <util/translator.h>
#include <boost/algorithm/string.hpp>
UILoader g_uiLoader;
@@ -41,28 +45,26 @@ UIElementPtr UILoader::createElementFromId(const std::string& id)
if(split.size() != 2)
return element;
std::string elementType = split[0];
std::string elementType = split[0].substr(1);
std::string elementId = split[1];
if(elementType == "panel") {
if(elementType == "panel")
element = UIElementPtr(new UIContainer(UI::Panel));
} else if(elementType == "button") {
else if(elementType == "button")
element = UIElementPtr(new UIButton);
} else if(elementType == "label") {
else if(elementType == "label")
element = UIElementPtr(new UILabel);
} else if(elementType == "window") {
else if(elementType == "window")
element = UIElementPtr(new UIWindow);
} else if(elementType == "textEdit") {
else if(elementType == "textEdit")
element = UIElementPtr(new UITextEdit);
} else if(elementType == "lineDecoration") {
else if(elementType == "lineDecoration")
element = UIElementPtr(new UIElement(UI::LineDecoration));
} else if(elementType == "checkBox") {
else if(elementType == "checkBox")
element = UIElementPtr(new UICheckBox);
}
if(element) {
if(element)
element->setId(elementId);
}
return element;
}
@@ -71,13 +73,13 @@ UIElementPtr UILoader::loadFromFile(std::string filePath, const UIContainerPtr&
{
std::stringstream fin;
if(!g_resources.loadFile(filePath, fin)) {
flogError("ERROR: Could not load ui %s", filePath.c_str());
error("ERROR: Could not load ui ", filePath);
return UIElementPtr();
}
try {
FML::Parser parser(fin, filePath);
FML::Node* doc = parser.getDocument();
OTMLParser parser(fin, filePath);
OTMLNode* doc = parser.getDocument();
// get element id
std::string elementId = doc->front()->tag();
@@ -88,7 +90,7 @@ UIElementPtr UILoader::loadFromFile(std::string filePath, const UIContainerPtr&
// create element interpreting it's id
UIElementPtr element = createElementFromId(elementId);
if(!element) {
logError(doc->front()->generateErrorMessage("invalid root element type"));
error(doc->front()->generateErrorMessage("invalid root element type"));
return element;
}
parent->addChild(element);
@@ -103,22 +105,22 @@ UIElementPtr UILoader::loadFromFile(std::string filePath, const UIContainerPtr&
// report onLoad events
element->onLoad();
return element;
} catch(FML::Exception e) {
flogError("ERROR: Failed to load ui %s: %s", filePath.c_str() % e.what());
} catch(OTMLException e) {
error("ERROR: Failed to load ui ",filePath,": ", e.what());
}
return UIElementPtr();
}
void UILoader::populateContainer(const UIContainerPtr& parent, FML::Node* node)
void UILoader::populateContainer(const UIContainerPtr& parent, OTMLNode* node)
{
// populate ordered elements
foreach(FML::Node* cnode, *node) {
foreach(OTMLNode* cnode, *node) {
std::string id = cnode->tag();
if(id.find("#") != std::string::npos) {
if(id[0] == '%') {
UIElementPtr element = createElementFromId(id);
if(!element) {
logError(cnode->generateErrorMessage("invalid element type"));
error(cnode->generateErrorMessage("invalid element type"));
continue;
}
parent->addChild(element);
@@ -130,13 +132,13 @@ void UILoader::populateContainer(const UIContainerPtr& parent, FML::Node* node)
}
}
void UILoader::loadElements(const UIElementPtr& parent, FML::Node* node)
void UILoader::loadElements(const UIElementPtr& parent, OTMLNode* node)
{
loadElement(parent, node);
if(UIContainerPtr container = parent->asUIContainer()) {
foreach(const UIElementPtr& element, container->getChildren()) {
foreach(FML::Node* cnode, *node) {
foreach(OTMLNode* cnode, *node) {
// node found, load it
if(boost::ends_with(cnode->tag(), "#" + element->getId())) {
loadElements(element, cnode);
@@ -147,10 +149,10 @@ void UILoader::loadElements(const UIElementPtr& parent, FML::Node* node)
}
}
void UILoader::loadElement(const UIElementPtr& element, FML::Node* node)
void UILoader::loadElement(const UIElementPtr& element, OTMLNode* node)
{
// set element skin
if(FML::Node* cnode = node->at("skin")) {
if(OTMLNode* cnode = node->at("skin")) {
if(cnode->hasValue()) {
element->setSkin(g_uiSkins.getElementSkin(element->getElementType(), cnode->value()));
} else {
@@ -165,72 +167,61 @@ void UILoader::loadElement(const UIElementPtr& element, FML::Node* node)
if(node->hasNode("size"))
element->setSize(node->readAt<Size>("size"));
element->setMarginLeft(node->readAt("margin.left", 0));
element->setMarginRight(node->readAt("margin.right", 0));
element->setMarginTop(node->readAt("margin.top", 0));
element->setMarginBottom(node->readAt("margin.bottom", 0));
// load margins
element->setMarginLeft(node->readAtPath("margin/left", 0));
element->setMarginRight(node->readAtPath("margin/right", 0));
element->setMarginTop(node->readAtPath("margin/top", 0));
element->setMarginBottom(node->readAtPath("margin/bottom", 0));
if(node->hasNode("anchors.left"))
loadElementAnchor(element, UI::AnchorLeft, node->at("anchors.left"));
// load anchors
loadElementAnchor(element, UI::AnchorLeft, node->atPath("anchors/left"));
loadElementAnchor(element, UI::AnchorRight, node->atPath("anchors/right"));
loadElementAnchor(element, UI::AnchorTop, node->atPath("anchors/top"));
loadElementAnchor(element, UI::AnchorBottom, node->atPath("anchors/bottom"));
loadElementAnchor(element, UI::AnchorHorizontalCenter, node->atPath("anchors/horizontalCenter"));
loadElementAnchor(element, UI::AnchorVerticalCenter, node->atPath("anchors/verticalCenter"));
if(node->hasNode("anchors.right"))
loadElementAnchor(element, UI::AnchorRight, node->at("anchors.right"));
if(node->hasNode("anchors.top"))
loadElementAnchor(element, UI::AnchorTop, node->at("anchors.top"));
if(node->hasNode("anchors.bottom"))
loadElementAnchor(element, UI::AnchorBottom, node->at("anchors.bottom"));
if(node->hasNode("anchors.horizontalCenter"))
loadElementAnchor(element, UI::AnchorHorizontalCenter, node->at("anchors.horizontalCenter"));
if(node->hasNode("anchors.verticalCenter"))
loadElementAnchor(element, UI::AnchorVerticalCenter, node->at("anchors.verticalCenter"));
// load events
if(FML::Node* cnode = node->at("onLoad")) {
if(g_lua.loadBufferAsFunction(cnode->value(), getElementSourceDesc(element, cnode)))
g_lua.setScriptableField(element, "onLoad");
else
logError(cnode->generateErrorMessage("failed to parse inline lua script"));
}
if(FML::Node* cnode = node->at("onDestroy")) {
if(g_lua.loadBufferAsFunction(cnode->value(), getElementSourceDesc(element, cnode)))
g_lua.setScriptableField(element, "onDestroy");
else
logError(cnode->generateErrorMessage("failed to parse inline lua script"));
}
// load basic element events
loadElementScriptFunction(element, node->at("onLoad"));
loadElementScriptFunction(element, node->at("onDestroy"));
// load specific element type
if(element->getElementType() == UI::Button)
loadButton(boost::static_pointer_cast<UIButton>(element), node);
else if(element->getElementType() == UI::Window) {
UIWindowPtr window = boost::static_pointer_cast<UIWindow>(element);
window->setTitle(node->readAt("title", std::string()));
}
else if(element->getElementType() == UI::Label) {
UILabelPtr label = boost::static_pointer_cast<UILabel>(element);
label->setText(node->readAt("text", std::string()));
label->setAlign(parseAlignment(node->readAt("align", std::string("left"))));
}
switch(element->getElementType()) {
case UI::Button:
loadButton(boost::static_pointer_cast<UIButton>(element), node);
break;
case UI::Window:
loadWindow(boost::static_pointer_cast<UIWindow>(element), node);
break;
case UI::Label:
loadLabel(boost::static_pointer_cast<UILabel>(element), node);
break;
default:
break;
}
}
void UILoader::loadElementAnchor(const UIElementPtr& anchoredElement, UI::AnchorPoint anchoredEdge, FML::Node* node)
void UILoader::loadElementAnchor(const UIElementPtr& anchoredElement, UI::AnchorPoint anchoredEdge, OTMLNode* node)
{
UIAnchorLayoutPtr layout = boost::dynamic_pointer_cast<UIAnchorLayout>(anchoredElement->getLayout());
if(!layout) {
logError(node->generateErrorMessage("could not add anchor, because this element does not participate of an anchor layout"));
if(!node)
return;
std::string anchorDescription = node->value();
if(anchorDescription.empty()) {
error(node->generateErrorMessage("anchor is empty, did you forget to fill it?"));
return;
}
std::string anchorDescription = node->value();
UIAnchorLayoutPtr layout = boost::dynamic_pointer_cast<UIAnchorLayout>(anchoredElement->getLayout());
if(!layout) {
error(node->generateErrorMessage("could not add anchor, because this element does not participate of an anchor layout"));
return;
}
std::vector<std::string> split;
boost::split(split, anchorDescription, boost::is_any_of(std::string(".")));
if(split.size() != 2) {
logError(node->generateErrorMessage("invalid anchor"));
error(node->generateErrorMessage("invalid anchor"));
return;
}
@@ -238,33 +229,42 @@ void UILoader::loadElementAnchor(const UIElementPtr& anchoredElement, UI::Anchor
UI::AnchorPoint anchorLineEdge = UIAnchorLayout::parseAnchorPoint(split[1]);
if(anchorLineEdge == UI::AnchorNone) {
logError(node->generateErrorMessage("invalid anchor type"));
error(node->generateErrorMessage("invalid anchor type"));
return;
}
if(!layout->addAnchor(anchoredElement, anchoredEdge, AnchorLine(anchorLineElementId, anchorLineEdge)))
logError(node->generateErrorMessage("anchoring failed"));
error(node->generateErrorMessage("anchoring failed"));
}
void UILoader::loadButton(const UIButtonPtr& button, FML::Node* node)
void UILoader::loadElementScriptFunction(const UIElementPtr& element, OTMLNode* node)
{
if(!node)
return;
std::string functionDesc;
functionDesc += g_resources.resolvePath(node->what()) + ":" + element->getId();
functionDesc += "[" + node->tag() + "]";
if(g_lua.loadBufferAsFunction(node->value(), functionDesc))
g_lua.setScriptableField(element, node->tag());
else
error(node->generateErrorMessage("failed to parse inline lua script"));
}
void UILoader::loadButton(const UIButtonPtr& button, OTMLNode* node)
{
button->setText(node->valueAt("text"));
// set on click event
if(FML::Node* cnode = node->at("onClick")) {
if(g_lua.loadBufferAsFunction(cnode->value(), getElementSourceDesc(button, cnode)))
g_lua.setScriptableField(button, "onClick");
else
logError(cnode->generateErrorMessage("failed to parse inline lua script"));
}
loadElementScriptFunction(button, node->at("onClick"));
}
std::string UILoader::getElementSourceDesc(const UIElementPtr& element, const FML::Node *node)
void UILoader::loadWindow(const UIWindowPtr& window, OTMLNode* node)
{
std::string desc;
desc += g_resources.resolvePath(node->what()) + ":" + element->getId();
if(!node->tag().empty())
desc += "[" + node->tag() + "]";
return desc;
window->setTitle(node->readAt("title", std::string()));
}
void UILoader::loadLabel(const UILabelPtr& label, OTMLNode* node)
{
label->setText(node->readAt("text", std::string()));
label->setAlign(parseAlignment(node->readAt("align", std::string("left"))));
}

View File

@@ -25,10 +25,12 @@
#ifndef UILOADER_H
#define UILOADER_H
#include <prerequisites.h>
#include <global.h>
#include <ui/uiconstants.h>
#include <ui/uicontainer.h>
#include <ui/uibutton.h>
#include <ui/uiwindow.h>
#include <ui/uilabel.h>
class UILoader
{
@@ -40,22 +42,25 @@ private:
/// Detect element type and create it
UIElementPtr createElementFromId(const std::string& id);
/// Populate container children from a FML node
void populateContainer(const UIContainerPtr& parent, FML::Node* node);
/// Populate container children from a OTML node
void populateContainer(const UIContainerPtr& parent, OTMLNode* node);
/// Load element and its children from a FML node
void loadElements(const UIElementPtr& parent, FML::Node* node);
/// Load element and its children from a OTML node
void loadElements(const UIElementPtr& parent, OTMLNode* node);
/// Load element proprieties from a FML node
void loadElement(const UIElementPtr& element, FML::Node* node);
/// Load element proprieties from a OTML node
void loadElement(const UIElementPtr& element, OTMLNode* node);
/// Load anchor from a FML node
void loadElementAnchor(const UIElementPtr& anchoredElement, UI::AnchorPoint anchoredEdge, FML::Node* node);
/// Load anchor from a OTML node
void loadElementAnchor(const UIElementPtr& anchoredElement, UI::AnchorPoint anchoredEdge, OTMLNode* node);
/// Load element lua function
void loadElementScriptFunction(const UIElementPtr& element, OTMLNode* node);
// specific elements loading
void loadButton(const UIButtonPtr& button, FML::Node* node);
std::string getElementSourceDesc(const UIElementPtr& element, const FML::Node *node);
void loadButton(const UIButtonPtr& button, OTMLNode* node);
void loadWindow(const UIWindowPtr& window, OTMLNode* node);
void loadLabel(const UILabelPtr& label, OTMLNode* node);
};
extern UILoader g_uiLoader;

View File

@@ -22,7 +22,7 @@
*/
#include <prerequisites.h>
#include <global.h>
#include <core/resources.h>
#include <graphics/textures.h>
#include <ui/uiskins.h>
@@ -32,6 +32,7 @@
#include <ui/uitexteditskin.h>
#include <ui/uilabelskin.h>
#include <graphics/fonts.h>
#include <otml/otml.h>
UISkins g_uiSkins;
@@ -41,15 +42,15 @@ void UISkins::load(const std::string& skinName)
std::stringstream fin;
if(!g_resources.loadFile(skinName + ".yml", fin))
flogFatal("FATAL ERROR: Could not load skin \"%s", skinName.c_str());
fatal("FATAL ERROR: Could not load skin '",skinName,"'");
try {
FML::Parser parser(fin, skinName);
FML::Node* doc = parser.getDocument();
OTMLParser parser(fin, skinName);
OTMLNode* doc = parser.getDocument();
m_defaultFont = g_fonts.get(doc->valueAt("default font"));
if(!m_defaultFont)
logFatal("FATAL ERROR: Could not load skin default font");
fatal("FATAL ERROR: Could not load skin default font");
m_defaultFontColor = doc->readAt("default font color", Color::white);
@@ -57,9 +58,9 @@ void UISkins::load(const std::string& skinName)
if(!defaultTextureName.empty())
m_defaultTexture = g_textures.get(defaultTextureName);
foreach(FML::Node* node, *doc) {
foreach(OTMLNode* node, *doc) {
UIElementSkinPtr skin;
foreach(FML::Node* cnode, *node) {
foreach(OTMLNode* cnode, *node) {
if(node->tag() == "buttons")
skin = UIElementSkinPtr(new UIButtonSkin(cnode->tag()));
else if(node->tag() == "panels")
@@ -79,8 +80,8 @@ void UISkins::load(const std::string& skinName)
m_elementSkins.push_back(skin);
}
}
} catch(FML::Exception e) {
flogFatal("FATAL ERROR: Malformed skin file \"%s\":\n %s", skinName.c_str() % e.what());
} catch(OTMLException e) {
fatal("FATAL ERROR: Malformed skin file '",skinName,"':\n ",e.what());
}
g_resources.popCurrentPath();
@@ -99,6 +100,6 @@ UIElementSkinPtr UISkins::getElementSkin(UI::ElementType elementType, const std:
if(elementType == skin->getElementType() && name == skin->getName())
return skin;
}
flogWarning("Element skin '%s' not found", name.c_str());
warning("Element skin '",name,"' not found");
return UIElementSkinPtr();
}

View File

@@ -25,7 +25,7 @@
#ifndef UISKIN_H
#define UISKIN_H
#include <prerequisites.h>
#include <global.h>
#include <graphics/texture.h>
#include <ui/uielementskin.h>
#include <graphics/font.h>

View File

@@ -22,7 +22,7 @@
*/
#include <prerequisites.h>
#include <global.h>
#include <ui/uitextedit.h>
#include <ui/uitexteditskin.h>
#include <ui/uicontainer.h>

View File

@@ -25,7 +25,7 @@
#ifndef UITEXTEDIT_H
#define UITEXTEDIT_H
#include <prerequisites.h>
#include <global.h>
#include <graphics/textarea.h>
#include <ui/uielement.h>

View File

@@ -22,12 +22,12 @@
*/
#include <prerequisites.h>
#include <global.h>
#include <graphics/fonts.h>
#include <ui/uitexteditskin.h>
#include <ui/uitextedit.h>
void UITextEditSkin::load(FML::Node* node)
void UITextEditSkin::load(OTMLNode* node)
{
UIElementSkin::load(node);
m_textMargin = node->readAt("text margin", 2);

View File

@@ -25,7 +25,7 @@
#ifndef UITEXTEDITSKIN_H
#define UITEXTEDITSKIN_H
#include <prerequisites.h>
#include <global.h>
#include <ui/uielementskin.h>
class Font;
@@ -36,7 +36,7 @@ public:
UITextEditSkin(const std::string& name) :
UIElementSkin(name, UI::TextEdit) { }
void load(FML::Node* node);
void load(OTMLNode* node);
void apply(UIElement *element);
void draw(UIElement *element);

View File

@@ -22,7 +22,7 @@
*/
#include <prerequisites.h>
#include <global.h>
#include <ui/uiwindow.h>
#include <ui/uiwindowskin.h>

View File

@@ -25,7 +25,7 @@
#ifndef UIWINDOW_H
#define UIWINDOW_H
#include <prerequisites.h>
#include <global.h>
#include <ui/uicontainer.h>
class UIWindow : public UIContainer

View File

@@ -21,17 +21,18 @@
* THE SOFTWARE.
*/
#include <prerequisites.h>
#include <global.h>
#include <graphics/fonts.h>
#include <ui/uiwindowskin.h>
#include <ui/uiwindow.h>
#include <util/translator.h>
void UIWindowSkin::load(FML::Node* node)
void UIWindowSkin::load(OTMLNode* node)
{
UIElementSkin::load(node);
FML::Node* headNode = node->at("head");
FML::Node* bodyNode = node->at("body");
OTMLNode* headNode = node->at("head");
OTMLNode* bodyNode = node->at("body");
m_headImage = boost::dynamic_pointer_cast<BorderedImage>(loadImage(headNode));
m_headHeight = headNode->readAt("height", m_headImage->getDefaultSize().height());

View File

@@ -24,7 +24,7 @@
#ifndef UIWINDOWSKIN_H
#define UIWINDOWSKIN_H
#include <prerequisites.h>
#include <global.h>
#include <graphics/font.h>
#include <ui/uielementskin.h>
#include <graphics/borderedimage.h>
@@ -35,7 +35,7 @@ public:
UIWindowSkin(const std::string& name) :
UIElementSkin(name, UI::Window) { }
void load(FML::Node* node);
void load(OTMLNode* node);
void draw(UIElement *element);
int getHeadHeight() const { return m_headHeight; }