reorganize all constants and place them into namespaces

This commit is contained in:
Eduardo Bart
2011-08-28 13:02:26 -03:00
parent dab483caab
commit e87297c1b5
62 changed files with 527 additions and 800 deletions

View File

@@ -23,85 +23,106 @@
#ifndef FRAMEWORK_CONST_H
#define FRAMEWORK_CONST_H
//namespace fw {
#include "util/color.h"
enum LogLevel {
LogDebug = 0,
LogInfo,
LogWarning,
LogError,
LogFatal
};
namespace Fw
{
const Color white (0xFF, 0xFF, 0xFF, 0xFF);
const Color black (0x00, 0x00, 0x00, 0xFF);
const Color alpha (0x00, 0x00, 0x00, 0x00);
const Color red (0xFF, 0x00, 0x00, 0xFF);
const Color green (0x00, 0xFF, 0x00, 0xFF);
const Color blue (0x00, 0x00, 0xFF, 0xFF);
const Color pink (0xFF, 0x00, 0xFF, 0xFF);
const Color yellow(0xFF, 0xFF, 0x00, 0xFF);
enum AlignmentFlag {
AlignNone = 0,
AlignLeft = 1,
AlignRight = 2,
AlignTop = 4,
AlignBottom = 8,
AlignHorizontalCenter = 16,
AlignVerticalCenter = 32,
AlignTopLeft = AlignTop | AlignLeft,
AlignTopRight = AlignTop | AlignRight,
AlignBottomLeft = AlignBottom | AlignLeft,
AlignBottomRight = AlignBottom | AlignRight,
AlignLeftCenter = AlignLeft | AlignVerticalCenter,
AlignRightCenter = AlignRight | AlignVerticalCenter,
AlignTopCenter = AlignTop | AlignHorizontalCenter,
AlignBottomCenter = AlignBottom | AlignHorizontalCenter,
AlignCenter = AlignVerticalCenter | AlignHorizontalCenter
};
enum LogLevel {
LogDebug = 0,
LogInfo,
LogWarning,
LogError,
LogFatal
};
enum AnchorEdge {
AnchorNone = 0,
AnchorTop,
AnchorBottom,
AnchorLeft,
AnchorRight,
AnchorVerticalCenter,
AnchorHorizontalCenter,
};
enum BlendFunc {
BlendNormal,
BlendColorzing
};
enum FocusReason {
MouseFocusReason = 0,
TabFocusReason,
ActiveFocusReason,
OtherFocusReason
};
enum AspectRatioMode {
IgnoreAspectRatio,
KeepAspectRatio,
KeepAspectRatioByExpanding
};
enum MouseButton {
MouseNoButton = 0,
MouseLeftButton,
MouseRightButton,
MouseMidButton
};
enum AlignmentFlag {
AlignNone = 0,
AlignLeft = 1,
AlignRight = 2,
AlignTop = 4,
AlignBottom = 8,
AlignHorizontalCenter = 16,
AlignVerticalCenter = 32,
AlignTopLeft = AlignTop | AlignLeft,
AlignTopRight = AlignTop | AlignRight,
AlignBottomLeft = AlignBottom | AlignLeft,
AlignBottomRight = AlignBottom | AlignRight,
AlignLeftCenter = AlignLeft | AlignVerticalCenter,
AlignRightCenter = AlignRight | AlignVerticalCenter,
AlignTopCenter = AlignTop | AlignHorizontalCenter,
AlignBottomCenter = AlignBottom | AlignHorizontalCenter,
AlignCenter = AlignVerticalCenter | AlignHorizontalCenter
};
enum MouseWheelDirection {
MouseNoWheel = 0,
MouseWheelUp,
MouseWheelDown
};
enum AnchorEdge {
AnchorNone = 0,
AnchorTop,
AnchorBottom,
AnchorLeft,
AnchorRight,
AnchorVerticalCenter,
AnchorHorizontalCenter,
};
enum KeyboardModifier {
KeyboardNoModifier = 0,
KeyboardCtrlModifier = 1,
KeyboardAltModifier = 2,
KeyboardShiftModifier = 4
};
enum FocusReason {
MouseFocusReason = 0,
TabFocusReason,
ActiveFocusReason,
OtherFocusReason
};
enum WidgetState {
DefaultState = 0,
ActiveState = 1,
FocusState = 2,
HoverState = 4,
PressedState = 8,
DisabledState = 16
//FirstState,
//MiddleState,
//LastState,
//AlternateState
};
enum MouseButton {
MouseNoButton = 0,
MouseLeftButton,
MouseRightButton,
MouseMidButton
};
//}
enum MouseWheelDirection {
MouseNoWheel = 0,
MouseWheelUp,
MouseWheelDown
};
enum KeyboardModifier {
KeyboardNoModifier = 0,
KeyboardCtrlModifier = 1,
KeyboardAltModifier = 2,
KeyboardShiftModifier = 4
};
enum WidgetState {
DefaultState = 0,
ActiveState = 1,
FocusState = 2,
HoverState = 4,
PressedState = 8,
DisabledState = 16
//FirstState,
//MiddleState,
//LastState,
//AlternateState
};
}
#endif

View File

@@ -30,7 +30,7 @@ Logger::Logger() : m_terminated(false)
}
void Logger::log(LogLevel level, std::string message)
void Logger::log(Fw::LogLevel level, std::string message)
{
const static std::string logPrefixes[] = { "", "", "WARNING: ", "ERROR: ", "FATAL ERROR: " };
@@ -45,13 +45,13 @@ void Logger::log(LogLevel level, std::string message)
m_onLog(level, message, now);
}
if(level == LogFatal) {
if(level == Fw::LogFatal) {
m_terminated = true;
exit(-1);
}
}
void Logger::logFunc(LogLevel level, const std::string& message, std::string prettyFunction)
void Logger::logFunc(Fw::LogLevel level, const std::string& message, std::string prettyFunction)
{
std::stringstream ss;
prettyFunction = prettyFunction.substr(0, prettyFunction.find_first_of('('));

View File

@@ -29,21 +29,21 @@
#include <functional>
struct LogMessage {
LogMessage(LogLevel level, const std::string& message, std::size_t when) : level(level), message(message), when(when) { }
LogLevel level;
LogMessage(Fw::LogLevel level, const std::string& message, std::size_t when) : level(level), message(message), when(when) { }
Fw::LogLevel level;
std::string message;
std::size_t when;
};
class Logger
{
typedef std::function<void(LogLevel, std::string, std::size_t)> OnLogCallback;
typedef std::function<void(Fw::LogLevel, std::string, std::size_t)> OnLogCallback;
public:
Logger();
void log(LogLevel level, std::string message);
void logFunc(LogLevel level, const std::string& message, std::string prettyFunction);
void log(Fw::LogLevel level, std::string message);
void logFunc(Fw::LogLevel level, const std::string& message, std::string prettyFunction);
void fireOldMessages();
void setOnLog(const OnLogCallback& onLog) { m_onLog = onLog; }
@@ -57,16 +57,16 @@ private:
extern Logger g_logger;
// specialized logging
#define logDebug(...) g_logger.log(LogDebug, fw::mkstr(__VA_ARGS__))
#define logInfo(...) g_logger.log(LogInfo, fw::mkstr(__VA_ARGS__))
#define logWarning(...) g_logger.log(LogWarning, fw::mkstr(__VA_ARGS__))
#define logError(...) g_logger.log(LogError, fw::mkstr(__VA_ARGS__))
#define logFatal(...) g_logger.log(LogFatal, fw::mkstr(__VA_ARGS__))
#define logDebug(...) g_logger.log(Fw::LogDebug, Fw::mkstr(__VA_ARGS__))
#define logInfo(...) g_logger.log(Fw::LogInfo, Fw::mkstr(__VA_ARGS__))
#define logWarning(...) g_logger.log(Fw::LogWarning, Fw::mkstr(__VA_ARGS__))
#define logError(...) g_logger.log(Fw::LogError, Fw::mkstr(__VA_ARGS__))
#define logFatal(...) g_logger.log(Fw::LogFatal, Fw::mkstr(__VA_ARGS__))
#define logTrace() g_logger.logFunc(LogDebug, "", __PRETTY_FUNCTION__)
#define logTraceDebug(...) g_logger.logFunc(LogDebug, fw::mkstr(__VA_ARGS__), __PRETTY_FUNCTION__)
#define logTraceInfo(...) g_logger.logFunc(LogInfo, fw::mkstr(__VA_ARGS__), __PRETTY_FUNCTION__)
#define logTraceWarning(...) g_logger.logFunc(LogWarning, fw::mkstr(__VA_ARGS__), __PRETTY_FUNCTION__)
#define logTraceError(...) g_logger.logFunc(LogError, fw::mkstr(__VA_ARGS__), __PRETTY_FUNCTION__)
#define logTrace() g_logger.logFunc(Fw::LogDebug, "", __PRETTY_FUNCTION__)
#define logTraceDebug(...) g_logger.logFunc(Fw::LogDebug, Fw::mkstr(__VA_ARGS__), __PRETTY_FUNCTION__)
#define logTraceInfo(...) g_logger.logFunc(Fw::LogInfo, Fw::mkstr(__VA_ARGS__), __PRETTY_FUNCTION__)
#define logTraceWarning(...) g_logger.logFunc(Fw::LogWarning, Fw::mkstr(__VA_ARGS__), __PRETTY_FUNCTION__)
#define logTraceError(...) g_logger.logFunc(Fw::LogError, Fw::mkstr(__VA_ARGS__), __PRETTY_FUNCTION__)
#endif

View File

@@ -61,10 +61,10 @@ bool Module::load()
for(const std::string& depName : m_dependencies) {
ModulePtr dep = g_modules.getModule(depName);
if(!dep)
throw std::runtime_error(fw::mkstr("could not find module dependency '", depName ,"'"));
throw std::runtime_error(Fw::mkstr("could not find module dependency '", depName ,"'"));
if(!dep->isLoaded() && !dep->load())
throw std::runtime_error(fw::mkstr("dependency '", depName, "' has failed to load"));
throw std::runtime_error(Fw::mkstr("dependency '", depName, "' has failed to load"));
}
if(m_loadCallback) {

View File

@@ -107,7 +107,7 @@ void ResourceManager::loadFile(const std::string& fileName, std::iostream& out)
PHYSFS_file* file = PHYSFS_openRead(fullPath.c_str());
if(!file) {
out.clear(std::ios::failbit);
throw std::runtime_error(fw::mkstr("failed to load file '", fullPath.c_str(), "': ", PHYSFS_getLastError()));
throw std::runtime_error(Fw::mkstr("failed to load file '", fullPath.c_str(), "': ", PHYSFS_getLastError()));
} else {
int fileSize = PHYSFS_fileLength(file);
if(fileSize > 0) {

View File

@@ -49,7 +49,7 @@ void Font::load(const OTMLNodePtr& fontNode)
// read custom widths
if(OTMLNodePtr node = fontNode->get("glyph widths")) {
for(const OTMLNodePtr& child : node->children())
m_glyphsSize[fw::safe_cast<int>(child->tag())].setWidth(child->value<int>());
m_glyphsSize[Fw::safeCast<int>(child->tag())].setWidth(child->value<int>());
}
// calculate glyphs texture coords
@@ -68,13 +68,13 @@ void Font::renderText(const std::string& text,
{
Size boxSize = g_graphics.getScreenSize() - startPos.toSize();
Rect screenCoords(startPos, boxSize);
renderText(text, screenCoords, AlignTopLeft, color);
renderText(text, screenCoords, Fw::AlignTopLeft, color);
}
void Font::renderText(const std::string& text,
const Rect& screenCoords,
AlignmentFlag align,
Fw::AlignmentFlag align,
const Color& color)
{
// prevent glitches from invalid rects
@@ -103,17 +103,17 @@ void Font::renderText(const std::string& text,
Rect glyphTextureCoords = m_glyphsTextureCoords[glyph];
// first translate to align position
if(align & AlignBottom) {
if(align & Fw::AlignBottom) {
glyphScreenCoords.translate(0, screenCoords.height() - textBoxSize.height());
} else if(align & AlignVerticalCenter) {
} else if(align & Fw::AlignVerticalCenter) {
glyphScreenCoords.translate(0, (screenCoords.height() - textBoxSize.height()) / 2);
} else { // AlignTop
// nothing to do
}
if(align & AlignRight) {
if(align & Fw::AlignRight) {
glyphScreenCoords.translate(screenCoords.width() - textBoxSize.width(), 0);
} else if(align & AlignHorizontalCenter) {
} else if(align & Fw::AlignHorizontalCenter) {
glyphScreenCoords.translate((screenCoords.width() - textBoxSize.width()) / 2, 0);
} else { // AlignLeft
// nothing to do
@@ -158,7 +158,7 @@ void Font::renderText(const std::string& text,
}
const std::vector<Point>& Font::calculateGlyphsPositions(const std::string& text,
AlignmentFlag align,
Fw::AlignmentFlag align,
Size *textBoxSize) const
{
// for performance reasons we use statics vectors that are allocated on demand
@@ -183,7 +183,7 @@ const std::vector<Point>& Font::calculateGlyphsPositions(const std::string& text
glyphsPositions.resize(textLength);
// calculate lines width
if((align & AlignRight || align & AlignHorizontalCenter) || textBoxSize) {
if((align & Fw::AlignRight || align & Fw::AlignHorizontalCenter) || textBoxSize) {
lineWidths[0] = 0;
for(i = 0; i< textLength; ++i) {
glyph = (uchar)text[i];
@@ -213,9 +213,9 @@ const std::vector<Point>& Font::calculateGlyphsPositions(const std::string& text
}
// calculate start x pos
if(align & AlignRight) {
if(align & Fw::AlignRight) {
virtualPos.x = (maxLineWidth - lineWidths[lines]);
} else if(align & AlignHorizontalCenter) {
} else if(align & Fw::AlignHorizontalCenter) {
virtualPos.x = (maxLineWidth - lineWidths[lines]) / 2;
} else { // AlignLeft
virtualPos.x = 0;
@@ -242,7 +242,7 @@ const std::vector<Point>& Font::calculateGlyphsPositions(const std::string& text
Size Font::calculateTextRectSize(const std::string& text)
{
Size size;
calculateGlyphsPositions(text, AlignTopLeft, &size);
calculateGlyphsPositions(text, Fw::AlignTopLeft, &size);
return size;
}

View File

@@ -38,17 +38,17 @@ public:
/// Simple text render starting at startPos
void renderText(const std::string& text,
const Point& startPos,
const Color& color = Color::white);
const Color& color = Fw::white);
/// Advanced text render delimited by a screen region and alignment
void renderText(const std::string& text,
const Rect& screenCoords,
AlignmentFlag align = AlignTopLeft,
const Color& color = Color::white);
Fw::AlignmentFlag align = Fw::AlignTopLeft,
const Color& color = Fw::white);
/// Calculate glyphs positions to use on render, also calculates textBoxSize if wanted
const std::vector<Point>& calculateGlyphsPositions(const std::string& text,
AlignmentFlag align = AlignTopLeft,
Fw::AlignmentFlag align = Fw::AlignTopLeft,
Size* textBoxSize = NULL) const;
/// Simulate render and calculate text size

View File

@@ -50,8 +50,8 @@ void Graphics::init()
m_opacity = 255;
m_emptyTexture = TexturePtr(new Texture);
bindColor(Color::white);
bindBlendFunc(BLEND_NORMAL);
bindColor(Fw::white);
bindBlendFunc(Fw::BlendNormal);
}
void Graphics::terminate()
@@ -299,13 +299,13 @@ void Graphics::bindTexture(const TexturePtr& texture)
glBindTexture(GL_TEXTURE_2D, texture->getId());
}
void Graphics::bindBlendFunc(BlendFuncType blendType)
void Graphics::bindBlendFunc(Fw::BlendFunc blendType)
{
switch(blendType) {
case BLEND_NORMAL:
case Fw::BlendNormal:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
break;
case BLEND_COLORIZING:
case Fw::BlendColorzing:
glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA);
break;
}

View File

@@ -25,11 +25,6 @@
#include "declarations.h"
enum BlendFuncType {
BLEND_NORMAL,
BLEND_COLORIZING
};
class Graphics
{
public:
@@ -56,7 +51,7 @@ public:
void bindColor(const Color& color);
void bindTexture(const TexturePtr& texture);
void bindBlendFunc(BlendFuncType blendType);
void bindBlendFunc(Fw::BlendFunc blendType);
// drawing API
void drawTexturedRect(const Rect& screenCoords,

View File

@@ -33,21 +33,21 @@ void LuaException::generateLuaErrorMessage(const std::string& error, int traceLe
{
// append trace level to error message
if(traceLevel >= 0)
m_what = fw::mkstr("LUA ERROR: ", g_lua.traceback(error, traceLevel));
m_what = Fw::mkstr("LUA ERROR: ", g_lua.traceback(error, traceLevel));
else
m_what = fw::mkstr("LUA ERROR: ", error);
m_what = Fw::mkstr("LUA ERROR: ", error);
}
LuaBadNumberOfArgumentsException::LuaBadNumberOfArgumentsException(int expected, int got)
{
std::string error = "attempt to call a function with wrong number of arguments";
if(expected >= 0 && got >= 0)
error = fw::mkstr(error, " (expected ", expected, ", but got ", got, ")");
error = Fw::mkstr(error, " (expected ", expected, ", but got ", got, ")");
generateLuaErrorMessage(error, 1);
}
LuaBadValueCastException::LuaBadValueCastException(const std::string& luaTypeName, const std::string& cppTypeName)
{
std::string error = fw::mkstr("attempt to cast a '", luaTypeName, "' lua value to '", cppTypeName, "'");
std::string error = Fw::mkstr("attempt to cast a '", luaTypeName, "' lua value to '", cppTypeName, "'");
generateLuaErrorMessage(error, 0);
}

View File

@@ -42,7 +42,7 @@ void LuaInterface::init()
createLuaState();
// check if demangle_type is working as expected
assert(fw::demangle_type<LuaObject>() == "LuaObject");
assert(Fw::demangleType<LuaObject>() == "LuaObject");
// register LuaObject, the base of all other objects
registerClass<LuaObject>();
@@ -147,12 +147,12 @@ void LuaInterface::registerClassMemberField(const std::string& className,
if(getFunction) {
pushCppFunction(getFunction);
setField(fw::mkstr("get_", field));
setField(Fw::mkstr("get_", field));
}
if(setFunction) {
pushCppFunction(setFunction);
setField(fw::mkstr("set_", field));
setField(Fw::mkstr("set_", field));
}
pop();
@@ -295,7 +295,7 @@ void LuaInterface::loadFunction(const std::string& buffer, const std::string& so
// gets the function contained in that buffer
if(boost::starts_with(buffer, "function")) {
// evaluate the function
std::string buf = fw::mkstr("__func = ", buffer);
std::string buf = Fw::mkstr("__func = ", buffer);
loadBuffer(buf, source);
safeCall();
@@ -317,7 +317,7 @@ void LuaInterface::evaluateExpression(const std::string& expression, const std::
{
// evaluates the expression
if(!expression.empty()) {
std::string buffer = fw::mkstr("__exp = (", expression, ")");
std::string buffer = Fw::mkstr("__exp = (", expression, ")");
loadBuffer(buffer, source);
safeCall();
@@ -917,7 +917,7 @@ void LuaInterface::pushObject(const LuaObjectPtr& obj)
new(newUserdata(sizeof(LuaObjectPtr))) LuaObjectPtr(obj);
// set the userdata metatable
getGlobal(fw::mkstr(obj->getLuaObjectName(), "_mt"));
getGlobal(Fw::mkstr(obj->getLuaObjectName(), "_mt"));
assert(!isNil());
setMetatable();
}

View File

@@ -63,24 +63,24 @@ public:
// register shortcuts using templates
template<class C, class B = LuaObject>
void registerClass() {
registerClass(fw::demangle_type<C>(), fw::demangle_type<B>());
registerClass(Fw::demangleType<C>(), Fw::demangleType<B>());
}
template<class C>
void registerClassStaticFunction(const std::string& functionName, const LuaCppFunction& function) {
registerClassStaticFunction(fw::demangle_type<C>(), functionName, function);
registerClassStaticFunction(Fw::demangleType<C>(), functionName, function);
}
template<class C>
void registerClassMemberFunction(const std::string& functionName, const LuaCppFunction& function) {
registerClassMemberFunction(fw::demangle_type<C>(), functionName, function);
registerClassMemberFunction(Fw::demangleType<C>(), functionName, function);
}
template<class C>
void registerClassMemberField(const std::string& field,
const LuaCppFunction& getFunction,
const LuaCppFunction& setFunction) {
registerClassMemberField(fw::demangle_type<C>(), field, getFunction, setFunction);
registerClassMemberField(Fw::demangleType<C>(), field, getFunction, setFunction);
}
// methods for binding functions
@@ -343,7 +343,7 @@ template<class T>
T LuaInterface::castValue(int index) {
T o;
if(!luavalue_cast(index, o))
throw LuaBadValueCastException(typeName(index), fw::demangle_type<T>());
throw LuaBadValueCastException(typeName(index), Fw::demangleType<T>());
return o;
}

View File

@@ -64,7 +64,7 @@ public:
/// Returns the class name used in Lua
virtual std::string getLuaObjectName() const {
// this could later be cached for more performance
return fw::demangle_name(typeid(*this).name());
return Fw::demangleName(typeid(*this).name());
}
LuaObjectPtr asLuaObject() { return shared_from_this(); }

View File

@@ -130,9 +130,9 @@ bool luavalue_cast(int index, Color& color)
color.setAlpha(g_lua.popInteger());
return true;
} else if(g_lua.isString()) {
return fw::cast(g_lua.toString(index), color);
return Fw::cast(g_lua.toString(index), color);
} else if(g_lua.isNil()) {
color = Color::white;
color = Fw::white;
return true;
}
return false;
@@ -164,7 +164,7 @@ bool luavalue_cast(int index, Rect& rect)
g_lua.getField("height", index);
rect.setHeight(g_lua.popInteger());
} else if(g_lua.isString()) {
return fw::cast(g_lua.toString(index), rect);
return Fw::cast(g_lua.toString(index), rect);
} else if(g_lua.isNil()) {
rect = Rect();
return true;
@@ -191,7 +191,7 @@ bool luavalue_cast(int index, Point& point)
point.y = g_lua.popInteger();
return true;
} else if(g_lua.isString()) {
return fw::cast(g_lua.toString(index), point);
return Fw::cast(g_lua.toString(index), point);
} else if(g_lua.isNil()) {
point = Point();
return true;

View File

@@ -52,7 +52,7 @@ void Connection::connect(const std::string& host, uint16 port, const SimpleCallb
m_connected = false;
m_connectCallback = connectCallback;
asio::ip::tcp::resolver::query query(host, fw::unsafe_cast<std::string>(port));
asio::ip::tcp::resolver::query query(host, Fw::unsafeCast<std::string>(port));
m_resolver.async_resolve(query, std::bind(&Connection::onResolve, shared_from_this(), _1, _2));
m_readTimer.expires_from_now(boost::posix_time::seconds(READ_TIMEOUT));

View File

@@ -77,14 +77,14 @@ OTMLNodePtr OTMLNode::at(const std::string& childTag)
}
}
if(!res)
throw OTMLException(shared_from_this(), fw::mkstr("child node with tag '", childTag, "' not found"));
throw OTMLException(shared_from_this(), Fw::mkstr("child node with tag '", childTag, "' not found"));
return res;
}
OTMLNodePtr OTMLNode::atIndex(int childIndex)
{
if(childIndex >= size() || childIndex < 0)
throw OTMLException(shared_from_this(), fw::mkstr("child node with index '", childIndex, "' not found"));
throw OTMLException(shared_from_this(), Fw::mkstr("child node with index '", childIndex, "' not found"));
return m_children[childIndex];
}

View File

@@ -30,7 +30,7 @@ class OTMLNode : public std::enable_shared_from_this<OTMLNode>
public:
virtual ~OTMLNode() { }
static OTMLNodePtr create(std::string tag = fw::empty_string, bool unique = false);
static OTMLNodePtr create(std::string tag = Fw::empty_string, bool unique = false);
static OTMLNodePtr create(std::string tag, std::string value);
std::string tag() const { return m_tag; }
@@ -106,8 +106,8 @@ protected:
template<typename T>
T OTMLNode::value() {
T ret;
if(!fw::cast(m_value, ret))
throw OTMLException(shared_from_this(), fw::mkstr("failed to cast node value to type '", fw::demangle_type<T>(), "'"));
if(!Fw::cast(m_value, ret))
throw OTMLException(shared_from_this(), Fw::mkstr("failed to cast node value to type '", Fw::demangleType<T>(), "'"));
return ret;
}
@@ -140,7 +140,7 @@ T OTMLNode::valueAtIndex(int childIndex, const T& def) {
template<typename T>
void OTMLNode::write(const T& v) {
m_value = fw::safe_cast<std::string>(v);
m_value = Fw::safeCast<std::string>(v);
}
template<typename T>

View File

@@ -181,7 +181,7 @@ void OTMLParser::parseNode(const std::string& data)
node->setUnique(dotsPos != std::string::npos);
node->setTag(tag);
node->setSource(doc->source() + ":" + fw::unsafe_cast<std::string>(nodeLine));
node->setSource(doc->source() + ":" + Fw::unsafeCast<std::string>(nodeLine));
// ~ is considered the null value
if(value == "~")

View File

@@ -35,8 +35,8 @@ void UIAnchorGroup::addAnchor(const UIAnchor& anchor)
m_anchors.push_back(anchor);
}
void UIAnchorLayout::addAnchor(const UIWidgetPtr& anchoredWidget, AnchorEdge anchoredEdge,
const std::string& hookedWidgetId, AnchorEdge hookedEdge)
void UIAnchorLayout::addAnchor(const UIWidgetPtr& anchoredWidget, Fw::AnchorEdge anchoredEdge,
const std::string& hookedWidgetId, Fw::AnchorEdge hookedEdge)
{
if(!anchoredWidget)
return;
@@ -59,16 +59,16 @@ void UIAnchorLayout::removeAnchors(const UIWidgetPtr& anchoredWidget)
void UIAnchorLayout::centerIn(const UIWidgetPtr& anchoredWidget, const std::string& hookedWidgetId)
{
addAnchor(anchoredWidget, AnchorHorizontalCenter, hookedWidgetId, AnchorHorizontalCenter);
addAnchor(anchoredWidget, AnchorVerticalCenter, hookedWidgetId, AnchorVerticalCenter);
addAnchor(anchoredWidget, Fw::AnchorHorizontalCenter, hookedWidgetId, Fw::AnchorHorizontalCenter);
addAnchor(anchoredWidget, Fw::AnchorVerticalCenter, hookedWidgetId, Fw::AnchorVerticalCenter);
}
void UIAnchorLayout::fill(const UIWidgetPtr& anchoredWidget, const std::string& hookedWidgetId)
{
addAnchor(anchoredWidget, AnchorLeft, hookedWidgetId, AnchorLeft);
addAnchor(anchoredWidget, AnchorRight, hookedWidgetId, AnchorRight);
addAnchor(anchoredWidget, AnchorTop, hookedWidgetId, AnchorTop);
addAnchor(anchoredWidget, AnchorBottom, hookedWidgetId, AnchorBottom);
addAnchor(anchoredWidget, Fw::AnchorLeft, hookedWidgetId, Fw::AnchorLeft);
addAnchor(anchoredWidget, Fw::AnchorRight, hookedWidgetId, Fw::AnchorRight);
addAnchor(anchoredWidget, Fw::AnchorTop, hookedWidgetId, Fw::AnchorTop);
addAnchor(anchoredWidget, Fw::AnchorBottom, hookedWidgetId, Fw::AnchorBottom);
}
void UIAnchorLayout::update()
@@ -108,7 +108,7 @@ void UIAnchorLayout::updateWidget(const UIWidgetPtr& widget, UIAnchorGroup& anch
// calculates new rect based on anchors
for(const UIAnchor& anchor : anchorGroup.getAnchors()) {
// skip invalid anchors
if(anchor.getHookedEdge() == AnchorNone)
if(anchor.getHookedEdge() == Fw::AnchorNone)
continue;
// determine hooked widget
@@ -141,22 +141,22 @@ void UIAnchorLayout::updateWidget(const UIWidgetPtr& widget, UIAnchorGroup& anch
// determine hooked widget edge point
int point = 0;
switch(anchor.getHookedEdge()) {
case AnchorLeft:
case Fw::AnchorLeft:
point = hookedWidget->getRect().left();
break;
case AnchorRight:
case Fw::AnchorRight:
point = hookedWidget->getRect().right();
break;
case AnchorTop:
case Fw::AnchorTop:
point = hookedWidget->getRect().top();
break;
case AnchorBottom:
case Fw::AnchorBottom:
point = hookedWidget->getRect().bottom();
break;
case AnchorHorizontalCenter:
case Fw::AnchorHorizontalCenter:
point = hookedWidget->getRect().horizontalCenter();
break;
case AnchorVerticalCenter:
case Fw::AnchorVerticalCenter:
point = hookedWidget->getRect().verticalCenter();
break;
default:
@@ -166,36 +166,36 @@ void UIAnchorLayout::updateWidget(const UIWidgetPtr& widget, UIAnchorGroup& anch
}
switch(anchor.getAnchoredEdge()) {
case AnchorHorizontalCenter:
case Fw::AnchorHorizontalCenter:
newRect.moveHorizontalCenter(point + widget->getMarginLeft() - widget->getMarginRight());
horizontalMoved = true;
break;
case AnchorLeft:
case Fw::AnchorLeft:
if(!horizontalMoved) {
newRect.moveLeft(point + widget->getMarginLeft());
horizontalMoved = true;
} else
newRect.setLeft(point + widget->getMarginLeft());
break;
case AnchorRight:
case Fw::AnchorRight:
if(!horizontalMoved) {
newRect.moveRight(point - widget->getMarginRight());
horizontalMoved = true;
} else
newRect.setRight(point - widget->getMarginRight());
break;
case AnchorVerticalCenter:
case Fw::AnchorVerticalCenter:
newRect.moveVerticalCenter(point + widget->getMarginTop() - widget->getMarginBottom());
verticalMoved = true;
break;
case AnchorTop:
case Fw::AnchorTop:
if(!verticalMoved) {
newRect.moveTop(point + widget->getMarginTop());
verticalMoved = true;
} else
newRect.setTop(point + widget->getMarginTop());
break;
case AnchorBottom:
case Fw::AnchorBottom:
if(!verticalMoved) {
newRect.moveBottom(point - widget->getMarginBottom());
verticalMoved = true;

View File

@@ -28,16 +28,16 @@
class UIAnchor
{
public:
UIAnchor(AnchorEdge anchoredEdge, const std::string& hookedWidgetId, AnchorEdge hookedEdge) :
UIAnchor(Fw::AnchorEdge anchoredEdge, const std::string& hookedWidgetId, Fw::AnchorEdge hookedEdge) :
m_anchoredEdge(anchoredEdge), m_hookedEdge(hookedEdge), m_hookedWidgetId(hookedWidgetId) { }
AnchorEdge getAnchoredEdge() const { return m_anchoredEdge; }
Fw::AnchorEdge getAnchoredEdge() const { return m_anchoredEdge; }
std::string getHookedWidgetId() const { return m_hookedWidgetId; }
AnchorEdge getHookedEdge() const { return m_hookedEdge; }
Fw::AnchorEdge getHookedEdge() const { return m_hookedEdge; }
private:
AnchorEdge m_anchoredEdge;
AnchorEdge m_hookedEdge;
Fw::AnchorEdge m_anchoredEdge;
Fw::AnchorEdge m_hookedEdge;
std::string m_hookedWidgetId;
};
@@ -61,8 +61,8 @@ class UIAnchorLayout : public UILayout
public:
UIAnchorLayout(UIWidgetPtr parentWidget) : UILayout(parentWidget) { }
void addAnchor(const UIWidgetPtr& anchoredWidget, AnchorEdge anchoredEdge,
const std::string& hookedWidgetId, AnchorEdge hookedEdge);
void addAnchor(const UIWidgetPtr& anchoredWidget, Fw::AnchorEdge anchoredEdge,
const std::string& hookedWidgetId, Fw::AnchorEdge hookedEdge);
void removeAnchors(const UIWidgetPtr& anchoredWidget);
void centerIn(const UIWidgetPtr& anchoredWidget, const std::string& hookedWidgetId);
void fill(const UIWidgetPtr& anchoredWidget, const std::string& hookedWidgetId);

View File

@@ -41,7 +41,7 @@ void UIButton::render()
UIWidget::render();
Rect textRect = m_rect;
textRect.translate(m_textTranslate);
m_font->renderText(m_text, textRect, AlignCenter, m_foregroundColor);
m_font->renderText(m_text, textRect, Fw::AlignCenter, m_foregroundColor);
}
void UIButton::onStyleApply(const OTMLNodePtr& styleNode)
@@ -60,7 +60,7 @@ void UIButton::onStyleApply(const OTMLNodePtr& styleNode)
}
}
bool UIButton::onMouseRelease(const Point& mousePos, MouseButton button)
bool UIButton::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
{
if(isPressed()) {
if(m_onClick && getRect().contains(mousePos))

View File

@@ -41,7 +41,7 @@ public:
protected:
virtual void onStyleApply(const OTMLNodePtr& styleNode);
virtual bool onMouseRelease(const Point& mousePos, MouseButton button);
virtual bool onMouseRelease(const Point& mousePos, Fw::MouseButton button);
SimpleCallback m_onClick;
Point m_textTranslate;

View File

@@ -28,7 +28,7 @@ void UILabel::setup()
{
UIWidget::setup();
setFocusable(false);
setAlign(AlignLeft);
setAlign(Fw::AlignLeft);
}
void UILabel::render()
@@ -66,7 +66,7 @@ void UILabel::onStyleApply(const OTMLNodePtr& styleNode)
if(node->tag() == "text")
setText(node->value());
else if(node->tag() == "align")
setAlign(fw::translateAlignment(node->value()));
setAlign(Fw::translateAlignment(node->value()));
else if(node->tag() == "offset") {
setOffset(node->value<Point>());
}

View File

@@ -34,11 +34,11 @@ public:
void resizeToText();
void setText(const std::string& text);
void setAlign(AlignmentFlag align) { m_align = align; }
void setAlign(Fw::AlignmentFlag align) { m_align = align; }
void setOffset(const Point& offset) { m_offset = offset; }
std::string getText() const { return m_text; }
AlignmentFlag getAlign() const { return m_align; }
Fw::AlignmentFlag getAlign() const { return m_align; }
Point getOffset() const { return m_offset; }
protected:
@@ -47,7 +47,7 @@ protected:
private:
std::string m_text;
Point m_offset;
AlignmentFlag m_align;
Fw::AlignmentFlag m_align;
};
#endif

View File

@@ -28,7 +28,7 @@
UILineEdit::UILineEdit()
{
m_align = AlignLeftCenter;
m_align = Fw::AlignLeftCenter;
m_cursorPos = 0;
m_startRenderPos = 0;
m_textHorizontalMargin = 3;
@@ -139,16 +139,16 @@ void UILineEdit::update()
textScreenCoords.addRight(-m_textHorizontalMargin);
m_drawArea = textScreenCoords;
if(m_align & AlignBottom) {
if(m_align & Fw::AlignBottom) {
m_drawArea.translate(0, textScreenCoords.height() - textBoxSize.height());
} else if(m_align & AlignVerticalCenter) {
} else if(m_align & Fw::AlignVerticalCenter) {
m_drawArea.translate(0, (textScreenCoords.height() - textBoxSize.height()) / 2);
} else { // AlignTop
}
if(m_align & AlignRight) {
if(m_align & Fw::AlignRight) {
m_drawArea.translate(textScreenCoords.width() - textBoxSize.width(), 0);
} else if(m_align & AlignHorizontalCenter) {
} else if(m_align & Fw::AlignHorizontalCenter) {
m_drawArea.translate((textScreenCoords.width() - textBoxSize.width()) / 2, 0);
} else { // AlignLeft
@@ -167,17 +167,17 @@ void UILineEdit::update()
Rect glyphTextureCoords = glyphsTextureCoords[glyph];
// first translate to align position
if(m_align & AlignBottom) {
if(m_align & Fw::AlignBottom) {
glyphScreenCoords.translate(0, textScreenCoords.height() - textBoxSize.height());
} else if(m_align & AlignVerticalCenter) {
} else if(m_align & Fw::AlignVerticalCenter) {
glyphScreenCoords.translate(0, (textScreenCoords.height() - textBoxSize.height()) / 2);
} else { // AlignTop
// nothing to do
}
if(m_align & AlignRight) {
if(m_align & Fw::AlignRight) {
glyphScreenCoords.translate(textScreenCoords.width() - textBoxSize.width(), 0);
} else if(m_align & AlignHorizontalCenter) {
} else if(m_align & Fw::AlignHorizontalCenter) {
glyphScreenCoords.translate((textScreenCoords.width() - textBoxSize.width()) / 2, 0);
} else { // AlignLeft
// nothing to do
@@ -243,7 +243,7 @@ void UILineEdit::setText(const std::string& text)
}
}
void UILineEdit::setAlign(AlignmentFlag align)
void UILineEdit::setAlign(Fw::AlignmentFlag align)
{
if(m_align != align) {
m_align = align;
@@ -360,10 +360,10 @@ void UILineEdit::onGeometryUpdate(const Rect& oldRect, const Rect& newRect)
update();
}
void UILineEdit::onFocusChange(bool focused, FocusReason reason)
void UILineEdit::onFocusChange(bool focused, Fw::FocusReason reason)
{
if(focused) {
if(reason == TabFocusReason)
if(reason == Fw::TabFocusReason)
setCursorPos(m_text.length());
else
blinkCursor();
@@ -386,7 +386,7 @@ bool UILineEdit::onKeyPress(uchar keyCode, char keyChar, int keyboardModifiers)
setCursorPos(m_text.length());
else if(keyCode == KC_TAB) {
if(UIWidgetPtr parent = getParent())
parent->focusNextChild(TabFocusReason);
parent->focusNextChild(Fw::TabFocusReason);
} else if(keyCode == KC_RETURN) {
if(m_onAction)
m_onAction();
@@ -398,9 +398,9 @@ bool UILineEdit::onKeyPress(uchar keyCode, char keyChar, int keyboardModifiers)
return true;
}
bool UILineEdit::onMousePress(const Point& mousePos, MouseButton button)
bool UILineEdit::onMousePress(const Point& mousePos, Fw::MouseButton button)
{
if(button == MouseLeftButton) {
if(button == Fw::MouseLeftButton) {
int pos = getTextPos(mousePos);
if(pos >= 0)
setCursorPos(pos);

View File

@@ -35,7 +35,7 @@ public:
void update();
void setText(const std::string& text);
void setAlign(AlignmentFlag align);
void setAlign(Fw::AlignmentFlag align);
void setCursorPos(int pos);
void setCursorEnabled(bool enable = true);
@@ -51,16 +51,16 @@ public:
protected:
virtual void onStyleApply(const OTMLNodePtr& styleNode);
virtual void onGeometryUpdate(const Rect& oldRect, const Rect& newRect);
virtual void onFocusChange(bool focused, FocusReason reason);
virtual void onFocusChange(bool focused, Fw::FocusReason reason);
virtual bool onKeyPress(uchar keyCode, char keyChar, int keyboardModifiers);
virtual bool onMousePress(const Point& mousePos, MouseButton button);
virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button);
private:
void blinkCursor();
std::string m_text;
Rect m_drawArea;
AlignmentFlag m_align;
Fw::AlignmentFlag m_align;
int m_cursorPos;
Point m_startInternalPos;
int m_startRenderPos;

View File

@@ -60,13 +60,13 @@ void UIManager::inputEvent(const PlatformEvent& event)
// translate input event to ui events
if(m_rootWidget) {
if(event.type & EventKeyboardAction) {
int keyboardModifiers = KeyboardNoModifier;
int keyboardModifiers = Fw::KeyboardNoModifier;
if(event.ctrl)
keyboardModifiers |= KeyboardCtrlModifier;
keyboardModifiers |= Fw::KeyboardCtrlModifier;
if(event.shift)
keyboardModifiers |= KeyboardShiftModifier;
keyboardModifiers |= Fw::KeyboardShiftModifier;
if(event.alt)
keyboardModifiers |= KeyboardAltModifier;
keyboardModifiers |= Fw::KeyboardAltModifier;
if(event.type == EventKeyDown)
m_rootWidget->onKeyPress(event.keycode, event.keychar, keyboardModifiers);
@@ -74,25 +74,25 @@ void UIManager::inputEvent(const PlatformEvent& event)
m_rootWidget->onKeyRelease(event.keycode, event.keychar, keyboardModifiers);
} else if(event.type & EventMouseAction) {
if(event.type == EventMouseMove) {
m_rootWidget->updateState(HoverState);
m_rootWidget->updateState(Fw::HoverState);
m_rootWidget->onMouseMove(event.mousePos, event.mouseMoved);
}
else if(event.type & EventMouseWheel) {
MouseWheelDirection dir = MouseNoWheel;
Fw::MouseWheelDirection dir = Fw::MouseNoWheel;
if(event.type & EventDown)
dir = MouseWheelDown;
dir = Fw::MouseWheelDown;
else if(event.type & EventUp)
dir = MouseWheelUp;
dir = Fw::MouseWheelUp;
m_rootWidget->onMouseWheel(event.mousePos, dir);
} else {
MouseButton button = MouseNoButton;
Fw::MouseButton button = Fw::MouseNoButton;
if(event.type & EventMouseLeftButton)
button = MouseLeftButton;
button = Fw::MouseLeftButton;
else if(event.type & EventMouseMidButton)
button = MouseMidButton;
button = Fw::MouseMidButton;
else if(event.type & EventMouseRightButton)
button = MouseRightButton;
button = Fw::MouseRightButton;
if(event.type & EventDown)
m_rootWidget->onMousePress(event.mousePos, button);
@@ -151,7 +151,7 @@ OTMLNodePtr UIManager::getStyle(const std::string& styleName)
auto it = m_styles.find(styleName);
if(it == m_styles.end())
throw std::runtime_error(fw::mkstr("style '", styleName, "' is not a defined style"));
throw std::runtime_error(Fw::mkstr("style '", styleName, "' is not a defined style"));
return m_styles[styleName];
}

View File

@@ -36,11 +36,11 @@
UIWidget::UIWidget()
{
m_updateEventScheduled = false;
m_states = DefaultState;
m_states = Fw::DefaultState;
// generate an unique id, this is need because anchored layouts find widgets by id
static unsigned long id = 1;
m_id = fw::mkstr("widget", id++);
m_id = Fw::mkstr("widget", id++);
}
UIWidget::~UIWidget()
@@ -62,8 +62,8 @@ void UIWidget::setup()
setPressed(false);
setSizeFixed(false);
setFont(g_fonts.getDefaultFont());
setBackgroundColor(Color::white);
setForegroundColor(Color::white);
setBackgroundColor(Fw::white);
setForegroundColor(Fw::white);
setOpacity(255);
setMarginTop(0);
setMarginRight(0);
@@ -272,7 +272,7 @@ UIWidgetPtr UIWidget::backwardsGetWidgetById(const std::string& id)
return widget;
}
void UIWidget::focusChild(const UIWidgetPtr& child, FocusReason reason)
void UIWidget::focusChild(const UIWidgetPtr& child, Fw::FocusReason reason)
{
if(child && !hasChild(child)) {
logError("attempt to focus an unknown child in a UIWidget");
@@ -285,14 +285,14 @@ void UIWidget::focusChild(const UIWidgetPtr& child, FocusReason reason)
if(child) {
child->setLastFocusReason(reason);
child->updateState(FocusState);
child->updateState(ActiveState);
child->updateState(Fw::FocusState);
child->updateState(Fw::ActiveState);
}
if(oldFocused) {
oldFocused->setLastFocusReason(reason);
oldFocused->updateState(FocusState);
oldFocused->updateState(ActiveState);
oldFocused->updateState(Fw::FocusState);
oldFocused->updateState(Fw::ActiveState);
}
}
}
@@ -314,7 +314,7 @@ void UIWidget::addChild(const UIWidgetPtr& child)
// always focus new child
if(child->isFocusable() && child->isExplicitlyVisible() && child->isExplicitlyEnabled())
focusChild(child, ActiveFocusReason);
focusChild(child, Fw::ActiveFocusReason);
// create default layout
if(!m_layout)
@@ -366,7 +366,7 @@ void UIWidget::removeChild(const UIWidgetPtr& child)
if(it != m_children.end()) {
// defocus if needed
if(m_focusedChild == child)
focusChild(nullptr, ActiveFocusReason);
focusChild(nullptr, Fw::ActiveFocusReason);
// unlock child if it was locked
unlockChild(child);
@@ -385,7 +385,7 @@ void UIWidget::removeChild(const UIWidgetPtr& child)
logError("attempt to remove an unknown child from a UIWidget");
}
void UIWidget::focusNextChild(FocusReason reason)
void UIWidget::focusNextChild(Fw::FocusReason reason)
{
UIWidgetPtr toFocus;
UIWidgetList rotatedChildren(m_children);
@@ -444,7 +444,7 @@ void UIWidget::lockChild(const UIWidgetPtr& child)
// lock child focus
if(child->isFocusable())
focusChild(child, ActiveFocusReason);
focusChild(child, Fw::ActiveFocusReason);
moveChildToTop(child);
}
@@ -495,13 +495,13 @@ void UIWidget::updateLayout()
m_layout->update();
}
void UIWidget::updateState(WidgetState state)
void UIWidget::updateState(Fw::WidgetState state)
{
bool newStatus = true;
bool oldStatus = hasState(state);
bool updateChildren = false;
if(state == ActiveState) {
if(state == Fw::ActiveState) {
UIWidgetPtr widget = asUIWidget();
UIWidgetPtr parent;
do {
@@ -515,10 +515,10 @@ void UIWidget::updateState(WidgetState state)
updateChildren = true;
}
else if(state == FocusState) {
else if(state == Fw::FocusState) {
newStatus = (getParent() && getParent()->getFocusedChild() == asUIWidget());
}
else if(state == HoverState) {
else if(state == Fw::HoverState) {
updateChildren = true;
Point mousePos = g_platform.getMouseCursorPos();
UIWidgetPtr widget = asUIWidget();
@@ -532,10 +532,10 @@ void UIWidget::updateState(WidgetState state)
}
} while(widget = parent);
}
else if(state == PressedState) {
else if(state == Fw::PressedState) {
newStatus = m_pressed;
}
else if(state == DisabledState) {
else if(state == Fw::DisabledState) {
bool enabled = true;
updateChildren = true;
UIWidgetPtr widget = asUIWidget();
@@ -564,19 +564,19 @@ void UIWidget::updateState(WidgetState state)
updateStyle();
if(state == FocusState)
if(state == Fw::FocusState)
onFocusChange(newStatus, m_lastFocusReason);
else if(state == HoverState)
else if(state == Fw::HoverState)
onHoverChange(newStatus);
}
}
void UIWidget::updateStates()
{
updateState(ActiveState);
updateState(FocusState);
updateState(DisabledState);
updateState(HoverState);
updateState(Fw::ActiveState);
updateState(Fw::FocusState);
updateState(Fw::DisabledState);
updateState(Fw::HoverState);
}
void UIWidget::updateStyle()
@@ -596,23 +596,23 @@ void UIWidget::updateStyle()
// merge states styles, NOTE: order does matter
OTMLNodePtr style = m_style->get("state.active");
if(style && hasState(ActiveState))
if(style && hasState(Fw::ActiveState))
newStateStyle->merge(style);
style = m_style->get("state.focus");
if(style && hasState(FocusState))
if(style && hasState(Fw::FocusState))
newStateStyle->merge(style);
style = m_style->get("state.hover");
if(style && hasState(HoverState))
if(style && hasState(Fw::HoverState))
newStateStyle->merge(style);
style = m_style->get("state.pressed");
if(style && hasState(PressedState))
if(style && hasState(Fw::PressedState))
newStateStyle->merge(style);
style = m_style->get("state.disabled");
if(style && hasState(DisabledState))
if(style && hasState(Fw::DisabledState))
newStateStyle->merge(style);
applyStyle(newStateStyle);
@@ -725,7 +725,7 @@ void UIWidget::onStyleApply(const OTMLNodePtr& styleNode)
} else if(what == "centerIn") {
anchorLayout->centerIn(asUIWidget(), node->value());
} else {
AnchorEdge anchoredEdge = fw::translateAnchorEdge(what);
Fw::AnchorEdge anchoredEdge = Fw::translateAnchorEdge(what);
std::string anchorDescription = node->value();
std::vector<std::string> split;
@@ -734,12 +734,12 @@ void UIWidget::onStyleApply(const OTMLNodePtr& styleNode)
throw OTMLException(node, "invalid anchor description");
std::string hookedWidgetId = split[0];
AnchorEdge hookedEdge = fw::translateAnchorEdge(split[1]);
Fw::AnchorEdge hookedEdge = Fw::translateAnchorEdge(split[1]);
if(anchoredEdge == AnchorNone)
if(anchoredEdge == Fw::AnchorNone)
throw OTMLException(node, "invalid anchor edge");
if(hookedEdge == AnchorNone)
if(hookedEdge == Fw::AnchorNone)
throw OTMLException(node, "invalid anchor target edge");
anchorLayout->addAnchor(asUIWidget(), anchoredEdge, hookedWidgetId, hookedEdge);
@@ -753,7 +753,7 @@ void UIWidget::onGeometryUpdate(const Rect& oldRect, const Rect& newRect)
}
void UIWidget::onFocusChange(bool focused, FocusReason reason)
void UIWidget::onFocusChange(bool focused, Fw::FocusReason reason)
{
}
@@ -807,7 +807,7 @@ bool UIWidget::onKeyRelease(uchar keyCode, char keyChar, int keyboardModifiers)
return false;
}
bool UIWidget::onMousePress(const Point& mousePos, MouseButton button)
bool UIWidget::onMousePress(const Point& mousePos, Fw::MouseButton button)
{
// do a backup of children list, because it may change while looping it
UIWidgetList children;
@@ -824,7 +824,7 @@ bool UIWidget::onMousePress(const Point& mousePos, MouseButton button)
for(const UIWidgetPtr& child : children) {
// when a focusable item is focused it must gain focus
if(child->isFocusable())
focusChild(child, MouseFocusReason);
focusChild(child, Fw::MouseFocusReason);
bool mustEnd = child->onMousePress(mousePos, button);
@@ -838,7 +838,7 @@ bool UIWidget::onMousePress(const Point& mousePos, MouseButton button)
return false;
}
bool UIWidget::onMouseRelease(const Point& mousePos, MouseButton button)
bool UIWidget::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
{
// do a backup of children list, because it may change while looping it
UIWidgetList children;
@@ -885,7 +885,7 @@ bool UIWidget::onMouseMove(const Point& mousePos, const Point& mouseMoved)
return false;
}
bool UIWidget::onMouseWheel(const Point& mousePos, MouseWheelDirection direction)
bool UIWidget::onMouseWheel(const Point& mousePos, Fw::MouseWheelDirection direction)
{
// do a backup of children list, because it may change while looping it
UIWidgetList children;

View File

@@ -41,9 +41,9 @@ public:
virtual void setup();
virtual void render();
void setEnabled(bool enabled) { m_enabled = enabled; updateState(DisabledState); }
void setEnabled(bool enabled) { m_enabled = enabled; updateState(Fw::DisabledState); }
void setVisible(bool visible) { m_visible = visible; }
void setPressed(bool pressed) { m_pressed = pressed; updateState(PressedState); }
void setPressed(bool pressed) { m_pressed = pressed; updateState(Fw::PressedState); }
void setId(const std::string& id) { m_id = id; }
void setFocusable(bool focusable) { m_focusable = focusable; }
void setStyle(const std::string& styleName);
@@ -65,7 +65,7 @@ public:
void setMarginTop(int margin) { m_marginTop = margin; updateParentLayout(); }
void setMarginBottom(int margin) { m_marginBottom = margin; updateParentLayout(); }
void setSizeFixed(bool fixed) { m_fixedSize = fixed; updateParentLayout(); }
void setLastFocusReason(FocusReason reason) { m_lastFocusReason = reason; }
void setLastFocusReason(Fw::FocusReason reason) { m_lastFocusReason = reason; }
void resize(const Size& size) { setRect(Rect(getPosition(), size)); }
void moveTo(const Point& pos) { setRect(Rect(pos, getSize())); }
@@ -74,12 +74,12 @@ public:
void disable() { setEnabled(false); }
void enable() { setEnabled(true); }
bool isActive() const { return hasState(ActiveState); }
bool isEnabled() const { return !hasState(DisabledState); }
bool isDisabled() const { return hasState(DisabledState); }
bool isFocused() const { return hasState(FocusState); }
bool isHovered() const { return hasState(HoverState); }
bool isPressed() const { return hasState(PressedState); }
bool isActive() const { return hasState(Fw::ActiveState); }
bool isEnabled() const { return !hasState(Fw::DisabledState); }
bool isDisabled() const { return hasState(Fw::DisabledState); }
bool isFocused() const { return hasState(Fw::FocusState); }
bool isHovered() const { return hasState(Fw::HoverState); }
bool isPressed() const { return hasState(Fw::PressedState); }
bool isVisible();
bool isExplicitlyEnabled() const { return m_enabled; }
bool isExplicitlyVisible() const { return m_visible; }
@@ -87,7 +87,7 @@ public:
bool isSizeFixed() const { return m_fixedSize; }
bool hasChildren() const { return m_children.size() > 0; }
bool hasChild(const UIWidgetPtr& child);
bool hasState(WidgetState state) const { return m_states & state; }
bool hasState(Fw::WidgetState state) const { return m_states & state; }
std::string getId() const { return m_id; }
int getChildCount() const { return m_children.size(); }
@@ -110,7 +110,7 @@ public:
int getMarginRight() const { return m_marginRight; }
int getMarginTop() const { return m_marginTop; }
int getMarginBottom() const { return m_marginBottom; }
FocusReason getLastFocusReason() const { return m_lastFocusReason; }
Fw::FocusReason getLastFocusReason() const { return m_lastFocusReason; }
UIWidgetList getChildren() const { return m_children; }
UIWidgetPtr getFocusedChild() const { return m_focusedChild; }
@@ -126,15 +126,15 @@ public:
void addChild(const UIWidgetPtr& child);
void insertChild(int index, const UIWidgetPtr& child);
void removeChild(const UIWidgetPtr& child);
void focusChild(const UIWidgetPtr& child, FocusReason reason);
void focusNextChild(FocusReason reason);
void focusChild(const UIWidgetPtr& child, Fw::FocusReason reason);
void focusNextChild(Fw::FocusReason reason);
void moveChildToTop(const UIWidgetPtr& child);
void lockChild(const UIWidgetPtr& child);
void unlockChild(const UIWidgetPtr& child);
void updateParentLayout();
void updateLayout();
virtual void updateState(WidgetState state);
virtual void updateState(Fw::WidgetState state);
void updateStates();
virtual void updateStyle();
void applyStyle(const OTMLNodePtr& styleNode);
@@ -153,7 +153,7 @@ protected:
/// Triggered when widget is moved or resized
virtual void onGeometryUpdate(const Rect& oldRect, const Rect& newRect);
/// Triggered when widget gets or loses focus
virtual void onFocusChange(bool focused, FocusReason reason);
virtual void onFocusChange(bool focused, Fw::FocusReason reason);
/// Triggered when the mouse enters or leaves widget area
virtual void onHoverChange(bool hovered);
/// Triggered when user presses key while widget has focus
@@ -161,19 +161,19 @@ protected:
/// Triggered when user releases key while widget has focus
virtual bool onKeyRelease(uchar keyCode, char keyChar, int keyboardModifiers);
/// Triggered when a mouse button is pressed down while mouse pointer is inside widget area
virtual bool onMousePress(const Point& mousePos, MouseButton button);
virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button);
/// Triggered when a mouse button is released
virtual bool onMouseRelease(const Point& mousePos, MouseButton button);
virtual bool onMouseRelease(const Point& mousePos, Fw::MouseButton button);
/// Triggered when mouse moves (even when the mouse is outside widget area)
virtual bool onMouseMove(const Point& mousePos, const Point& mouseMoved);
/// Triggered when mouse middle button wheels inside widget area
virtual bool onMouseWheel(const Point& mousePos, MouseWheelDirection direction);
virtual bool onMouseWheel(const Point& mousePos, Fw::MouseWheelDirection direction);
friend class UIManager;
protected:
std::string m_id;
FocusReason m_lastFocusReason;
Fw::FocusReason m_lastFocusReason;
bool m_enabled;
bool m_visible;
bool m_focusable;

View File

@@ -32,7 +32,7 @@ void UIWindow::setup()
m_moving = false;
m_headHeight = 0;
m_headMargin = 0;
m_titleAlign = AlignCenter;
m_titleAlign = Fw::AlignCenter;
}
void UIWindow::render()
@@ -47,9 +47,9 @@ void UIWindow::render()
// draw window head text
Rect headTextRect = headRect;
if(m_titleAlign & AlignLeft)
if(m_titleAlign & Fw::AlignLeft)
headTextRect.addLeft(-m_headMargin);
else if(m_titleAlign & AlignRight)
else if(m_titleAlign & Fw::AlignRight)
headTextRect.addRight(-m_headMargin);
m_font->renderText(m_title, headTextRect, m_titleAlign, m_foregroundColor);
}
@@ -76,7 +76,7 @@ void UIWindow::onStyleApply(const OTMLNodePtr& styleNode)
m_headImage = BorderImage::loadFromOTML(cnode);
m_headHeight = node->valueAt("height", m_headImage->getDefaultSize().height());
m_headMargin = node->valueAt("margin", 0);
m_titleAlign = fw::translateAlignment(node->valueAt("text align", std::string("center")));
m_titleAlign = Fw::translateAlignment(node->valueAt("text align", std::string("center")));
}
else if(node->tag() == "body") {
if(OTMLNodePtr cnode = node->get("border-image"))
@@ -109,7 +109,7 @@ void UIWindow::onGeometryUpdate(const Rect& oldRect, const Rect& newRect)
setRect(boundRect);
}
void UIWindow::onFocusChange(bool focused, FocusReason reason)
void UIWindow::onFocusChange(bool focused, Fw::FocusReason reason)
{
// when a window is focused it goes to the top
if(focused) {
@@ -118,7 +118,7 @@ void UIWindow::onFocusChange(bool focused, FocusReason reason)
}
}
bool UIWindow::onMousePress(const Point& mousePos, MouseButton button)
bool UIWindow::onMousePress(const Point& mousePos, Fw::MouseButton button)
{
if(!getChildByPos(mousePos)) {
m_moving = true;
@@ -128,7 +128,7 @@ bool UIWindow::onMousePress(const Point& mousePos, MouseButton button)
return UIWidget::onMousePress(mousePos, button);
}
bool UIWindow::onMouseRelease(const Point& mousePos, MouseButton button)
bool UIWindow::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
{
if(m_moving) {
m_moving = false;

View File

@@ -37,9 +37,9 @@ public:
protected:
virtual void onStyleApply(const OTMLNodePtr& styleNode);
virtual void onGeometryUpdate(const Rect& oldRect, const Rect& newRect);
virtual void onFocusChange(bool focused, FocusReason reason);
virtual bool onMousePress(const Point& mousePos, MouseButton button);
virtual bool onMouseRelease(const Point& mousePos, MouseButton button);
virtual void onFocusChange(bool focused, Fw::FocusReason reason);
virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button);
virtual bool onMouseRelease(const Point& mousePos, Fw::MouseButton button);
virtual bool onMouseMove(const Point& mousePos, const Point& mouseMoved);
private:
@@ -52,7 +52,7 @@ private:
ImagePtr m_bodyImage;
int m_headHeight;
int m_headMargin;
AlignmentFlag m_titleAlign;
Fw::AlignmentFlag m_titleAlign;
};
#endif

View File

@@ -1,32 +0,0 @@
/*
* Copyright (c) 2010-2011 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 "color.h"
Color Color::white (0xFF, 0xFF, 0xFF, 0xFF);
Color Color::black (0x00, 0x00, 0x00, 0xFF);
Color Color::alpha (0x00, 0x00, 0x00, 0x00);
Color Color::red (0xFF, 0x00, 0x00, 0xFF);
Color Color::green (0x00, 0xFF, 0x00, 0xFF);
Color Color::blue (0x00, 0x00, 0xFF, 0xFF);
Color Color::pink (0xFF, 0x00, 0xFF, 0xFF);
Color Color::yellow(0xFF, 0xFF, 0x00, 0xFF);

View File

@@ -77,15 +77,6 @@ public:
bool operator==(const Color& other) const { return other.color.rgba == color.rgba; }
bool operator!=(const Color& other) const { return other.color.rgba != color.rgba; }
static Color white;
static Color black;
static Color alpha;
static Color red;
static Color green;
static Color blue;
static Color pink;
static Color yellow;
private:
RGBA color;
};
@@ -111,11 +102,11 @@ inline std::istream& operator>>(std::istream& in, Color& color)
in >> tmp;
if(tmp.length() == 6 || tmp.length() == 8) {
color.setRed((uint8)fw::hex2dec(tmp.substr(0, 2)));
color.setGreen((uint8)fw::hex2dec(tmp.substr(2, 2)));
color.setBlue((uint8)fw::hex2dec(tmp.substr(4, 2)));
color.setRed((uint8)Fw::hex2dec(tmp.substr(0, 2)));
color.setGreen((uint8)Fw::hex2dec(tmp.substr(2, 2)));
color.setBlue((uint8)Fw::hex2dec(tmp.substr(4, 2)));
if(tmp.length() == 8)
color.setAlpha((uint8)fw::hex2dec(tmp.substr(6, 2)));
color.setAlpha((uint8)Fw::hex2dec(tmp.substr(6, 2)));
else
color.setAlpha(255);
} else

View File

@@ -24,12 +24,7 @@
#define SIZE_H
#include "point.h"
enum ESizeScaleMode {
IGNORE_ASPECT_RATIO,
KEEP_ASPECT_RATIO,
KEEP_ASPECT_RATIO_BY_EXPANDING
};
#include "../const.h"
template<class T>
class TSize
@@ -74,17 +69,17 @@ public:
TSize<T> expandedTo(const TSize<T>& other) const { return TSize<T>(std::max(wd,other.wd), std::max(ht,other.ht)); }
TSize<T> boundedTo(const TSize<T>& other) const { return TSize<T>(std::min(wd,other.wd), std::min(ht,other.ht)); }
void scale(const TSize<T>& s, ESizeScaleMode mode) {
if(mode == IGNORE_ASPECT_RATIO || wd == 0 || ht == 0) {
void scale(const TSize<T>& s, Fw::AspectRatioMode mode) {
if(mode == Fw::IgnoreAspectRatio || wd == 0 || ht == 0) {
wd = s.wd;
ht = s.ht;
} else {
bool useHeight;
T rw = (s.ht * wd) / ht;
if(mode == KEEP_ASPECT_RATIO)
if(mode == Fw::KeepAspectRatio)
useHeight = (rw <= s.wd);
else // mode == KEEP_ASPECT_RATIO_BY_EXPANDING
else // mode == Fw::KeepAspectRatioByExpanding
useHeight = (rw >= s.wd);
if(useHeight) {
@@ -96,7 +91,7 @@ public:
}
}
}
void scale(int w, int h, ESizeScaleMode mode) { scale(TSize<T>(w, h)); }
void scale(int w, int h, Fw::AspectRatioMode mode) { scale(TSize<T>(w, h)); }
float ratio() const { return (float)wd/ht; }
T area() const { return wd*ht; }

View File

@@ -31,22 +31,22 @@
#include <cxxabi.h>
#include "types.h"
namespace fw {
namespace Fw {
// read utilities for istream
inline uint8 getu8(std::istream& in) {
inline uint8 getU8(std::istream& in) {
uint8 tmp;
in.read((char*)&tmp, 1);
return tmp;
}
inline uint16 getu16(std::istream& in) {
inline uint16 getU16(std::istream& in) {
uint16 tmp;
in.read((char*)&tmp, 2);
return tmp;
}
inline uint32 getu32(std::istream& in) {
inline uint32 getU32(std::istream& in) {
uint32 tmp;
in.read((char*)&tmp, 4);
return tmp;
@@ -54,21 +54,21 @@ inline uint32 getu32(std::istream& in) {
/// Fill an ostream by concatenating args
/// Usage:
/// fw::fill_ostream(stream, a1, a2, ..., aN);
inline void fill_ostream(std::ostringstream&) { }
/// Fw::fill_ostream(stream, a1, a2, ..., aN);
inline void fillOstream(std::ostringstream&) { }
template<class T, class... Args>
void fill_ostream(std::ostringstream& stream, const T& first, const Args&... rest) {
void fillOstream(std::ostringstream& stream, const T& first, const Args&... rest) {
stream << first;
fill_ostream(stream, rest...);
fillOstream(stream, rest...);
}
/// Makes a std::string by concatenating args
/// Usage:
/// std::string str = fw::mkstr(a1, a2, ..., aN);
/// std::string str = Fw::mkstr(a1, a2, ..., aN);
template<class... T>
std::string mkstr(const T&... args) {
std::ostringstream buf;
fill_ostream(buf, args...);
fillOstream(buf, args...);
return buf.str();
}
@@ -84,7 +84,7 @@ struct dump_util {
/// Utility for dumping variables
/// Usage:
/// fw::dump << v1, v2, ..., vN;
/// Fw::dump << v1, v2, ..., vN;
struct dumper {
dumper() { }
template<class T>
@@ -97,15 +97,15 @@ struct dumper {
/// Utility for printing messages into stdout
/// Usage:
/// fw::print(v1, v2, ..., vN);
/// Fw::print(v1, v2, ..., vN);
template<class... T>
void print(const T&... args) {
std::ostringstream buf;
fill_ostream(buf, args...);
fillOstream(buf, args...);
std::cout << buf.str();
}
/// Same as fw::print but adds a new line at the end
/// Same as Fw::print but adds a new line at the end
template<class... T>
void println(const T&... args) {
print(args...);
@@ -113,7 +113,7 @@ void println(const T&... args) {
}
/// Demangle names for GNU g++ compiler
inline std::string demangle_name(const char* name) {
inline std::string demangleName(const char* name) {
size_t len;
int status;
std::string ret;
@@ -126,10 +126,10 @@ inline std::string demangle_name(const char* name) {
}
/// Returns the name of a type
/// e.g. fw::demangle_type<Foo*>() returns a string containing 'Foo*'
/// e.g. Fw::demangle_type<Foo*>() returns a string containing 'Foo*'
template<typename T>
std::string demangle_type() {
return demangle_name(typeid(T).name());
std::string demangleType() {
return demangleName(typeid(T).name());
}
/// Cast a type to another type
@@ -185,27 +185,27 @@ inline bool cast(const bool& in, std::string& out) {
}
// used by safe_cast
class bad_cast : public std::bad_cast {
class BadCast : public std::bad_cast {
public:
virtual ~bad_cast() throw() { }
virtual ~BadCast() throw() { }
template<class T, class R>
void setWhat() {
m_what = mkstr("failed to cast value of type '", demangle_type<T>(),
"' to type '", demangle_type<R>(), "'");
m_what = mkstr("failed to cast value of type '", demangleType<T>(),
"' to type '", demangleType<R>(), "'");
}
virtual const char* what() { return m_what.c_str(); }
private:
std::string m_what;
};
/// Cast a type to another type, any error throws a fw::bad_cast_exception
/// Cast a type to another type, any error throws a Fw::bad_cast_exception
/// Usage:
/// R r = fw::safe_cast<R>(t);
/// R r = Fw::safe_cast<R>(t);
template<typename R, typename T>
R safe_cast(const T& t) {
R safeCast(const T& t) {
R r;
if(!cast(t, r)) {
bad_cast e;
BadCast e;
e.setWhat<T,R>();
throw e;
}
@@ -214,12 +214,12 @@ R safe_cast(const T& t) {
/// Cast a type to another type, cast errors are ignored
/// Usage:
/// R r = fw::unsafe_cast<R>(t);
/// R r = Fw::unsafe_cast<R>(t);
template<typename R, typename T>
R unsafe_cast(const T& t, R def = R()) {
R unsafeCast(const T& t, R def = R()) {
try {
return safe_cast<R,T>(t);
} catch(bad_cast& e) {
return safeCast<R,T>(t);
} catch(BadCast& e) {
println("CAST ERROR: ", e.what());
return def;
}
@@ -227,12 +227,12 @@ R unsafe_cast(const T& t, R def = R()) {
template<typename T>
std::string tostring(const T& t) {
return unsafe_cast<std::string, T>(t);
return unsafeCast<std::string, T>(t);
}
template<typename T>
T fromstring(const std::string& str, T def = T()) {
return unsafe_cast<T, std::string>(str, def);
return unsafeCast<T, std::string>(str, def);
}
inline std::string dec2hex(unsigned int num) {
@@ -261,7 +261,7 @@ const static std::string empty_string;
}
// shortcut for fw::dump
const static fw::dumper dump;
// shortcut for Fw::dump
const static Fw::dumper dump;
#endif

View File

@@ -23,46 +23,46 @@
#include "translator.h"
#include <boost/algorithm/string.hpp>
AlignmentFlag fw::translateAlignment(std::string aligment)
Fw::AlignmentFlag Fw::translateAlignment(std::string aligment)
{
boost::to_lower(aligment);
boost::erase_all(aligment, " ");
if(aligment == "topleft")
return AlignTopLeft;
return Fw::AlignTopLeft;
else if(aligment == "topright")
return AlignTopRight;
return Fw::AlignTopRight;
else if(aligment == "bottomleft")
return AlignBottomLeft;
return Fw::AlignBottomLeft;
else if(aligment == "bottomright")
return AlignBottomRight;
return Fw::AlignBottomRight;
else if(aligment == "left")
return AlignLeftCenter;
return Fw::AlignLeftCenter;
else if(aligment == "right")
return AlignRightCenter;
return Fw::AlignRightCenter;
else if(aligment == "top")
return AlignTopCenter;
return Fw::AlignTopCenter;
else if(aligment == "bottom")
return AlignBottomCenter;
return Fw::AlignBottomCenter;
else if(aligment == "center")
return AlignCenter;
return AlignNone;
return Fw::AlignCenter;
return Fw::AlignNone;
}
AnchorEdge fw::translateAnchorEdge(std::string anchorEdge)
Fw::AnchorEdge Fw::translateAnchorEdge(std::string anchorEdge)
{
boost::to_lower(anchorEdge);
boost::erase_all(anchorEdge, " ");
if(anchorEdge == "left")
return AnchorLeft;
return Fw::AnchorLeft;
else if(anchorEdge == "right")
return AnchorRight;
return Fw::AnchorRight;
else if(anchorEdge == "top")
return AnchorTop;
return Fw::AnchorTop;
else if(anchorEdge == "bottom")
return AnchorBottom;
return Fw::AnchorBottom;
else if(anchorEdge == "horizontalcenter")
return AnchorHorizontalCenter;
return Fw::AnchorHorizontalCenter;
else if(anchorEdge == "verticalcenter")
return AnchorVerticalCenter;
return AnchorNone;
return Fw::AnchorVerticalCenter;
return Fw::AnchorNone;
}

View File

@@ -26,7 +26,7 @@
#include "../const.h"
#include <string>
namespace fw {
namespace Fw {
AlignmentFlag translateAlignment(std::string aligment);
AnchorEdge translateAnchorEdge(std::string anchorEdge);