remove lambdas

This commit is contained in:
Eduardo Bart
2011-04-11 18:11:22 -03:00
parent 451719479b
commit 08b6563fd5
14 changed files with 72 additions and 40 deletions

View File

@@ -29,8 +29,6 @@
#include <queue>
typedef std::function<void (void)> Callback;
class Task {
public:
inline Task(const Callback& _callback) : ticks(0), callback(_callback) { }

View File

@@ -27,8 +27,6 @@
#include "textures.h"
#include "graphics.h"
void Font::calculateGlyphsWidthsAutomatically(const Size& glyphSize)
{
int numHorizontalGlyphs = m_texture->getSize().width() / glyphSize.width();

View File

@@ -64,8 +64,11 @@ typedef int8_t int8;
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/foreach.hpp>
#include <boost/bind.hpp>
#define foreach BOOST_FOREACH
typedef std::function<void()> Callback;
// yaml
#include <yaml-cpp/yaml.h>

View File

@@ -29,8 +29,6 @@
#include "uielement.h"
#include "graphics/borderedimage.h"
typedef std::function<void()> Callback;
class UIButton : public UIElement
{
public:
@@ -45,7 +43,7 @@ public:
UI::EButtonState getState() { return m_state; }
void onClick(const Callback& callback) { m_buttonClickCallback = callback; }
void setOnClick(const Callback& callback) { m_buttonClickCallback = callback; }
private:
std::string m_text;

View File

@@ -45,6 +45,8 @@ void UILabelSkin::load(const YAML::Node& node)
void UILabelSkin::draw(UIElement *element)
{
UIElementSkin::draw(element);
UILabel *label = static_cast<UILabel*>(element);
m_font->renderText(label->getText(), label->getRect(), ALIGN_TOP_LEFT, m_textColor);

View File

@@ -25,26 +25,12 @@
#include "uitextedit.h"
#include "graphics/fonts.h"
UITextEdit::UITextEdit(Font* font) :
UITextEdit::UITextEdit() :
UIElement(UI::TextEdit),
m_cursorPos(0),
m_startRenderPos(0),
m_font(font)
m_startRenderPos(0)
{
if(!font)
m_font = g_fonts.get("tibia-10px-antialised");
}
void UITextEdit::render()
{
UIElement::render();
Rect textRect = getRect();
textRect.setLeft(textRect.left() + 2);
textRect.setRight(textRect.right() - 2);
// render text
m_font->renderText(m_text, textRect, ALIGN_LEFT, Color(0xFFBFBFBF), Point(m_startRenderPos, 0), m_cursorPos);
}
void UITextEdit::onInputEvent(const InputEvent& event)

View File

@@ -33,12 +33,10 @@ class Font;
class UITextEdit : public UIElement
{
public:
UITextEdit(Font *font = NULL);
UITextEdit();
void onInputEvent(const InputEvent& event);
void render();
void clearText();
void setText(const std::string& text);
const std::string& getText() const { return m_text; }
@@ -57,7 +55,6 @@ private:
uint m_cursorPos;
int m_startRenderPos;
std::string m_text;
Font *m_font;
};
typedef std::shared_ptr<UITextEdit> UITextEditPtr;

View File

@@ -23,4 +23,35 @@
#include "uitexteditskin.h"
#include "uitextedit.h"
#include "graphics/fonts.h"
void UITextEditSkin::load(const YAML::Node& node)
{
UIElementSkin::load(node);
std::string tmp;
if(node.FindValue("font")) {
node["font"] >> tmp;
m_font = g_fonts.get(tmp);
} else
m_font = g_fonts.getDefaultFont();
if(node.FindValue("text color"))
node["text color"] >> m_textColor;
else
m_textColor = Color::white;
if(node.FindValue("text margin"))
node["text margin"] >> m_textMargin;
else
m_textMargin = 2;
}
void UITextEditSkin::draw(UIElement* element)
{
UIElementSkin::draw(element);
UITextEdit *textEdit = static_cast<UITextEdit*>(element);
m_font->renderText(textEdit->getText(), textEdit->getRect(), ALIGN_TOP_LEFT, m_textColor);
}

View File

@@ -29,12 +29,24 @@
#include "uiconstants.h"
#include "uielementskin.h"
class Font;
class UITextEditSkin : public UIElementSkin
{
public:
UITextEditSkin(const std::string& name) :
UIElementSkin(name, UI::TextEdit) { }
void load(const YAML::Node& node);
void draw(UIElement *element);
Font *getFont() const { return m_font; }
int getTextMargin() const { return m_textMargin; }
private:
Font *m_font;
int m_textMargin;
Color m_textColor;
};
#endif // UITEXTEDITSKIN_H