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

@ -1,3 +1,2 @@
Developers edubart - leader developer <edub4rt@gmail.com>
edubart - leader developer <edub4rt@gmail.com> baxnie - developer <henrique_santiago93@hotmail.com>
baxnie - developer <henrique_santiago93@hotmail.com>

View File

@ -25,7 +25,7 @@ MESSAGE(STATUS "BUILD TYPE: " ${CMAKE_BUILD_TYPE})
# setup compiler options # setup compiler options
IF(CMAKE_COMPILER_IS_GNUCXX) IF(CMAKE_COMPILER_IS_GNUCXX)
SET(CXX_WARNS "-Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-unused-result") SET(CXX_WARNS "-Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-unused-variable")
SET(CMAKE_CXX_FLAGS "-std=c++0x -pipe ${CXX_WARNS}") SET(CMAKE_CXX_FLAGS "-std=c++0x -pipe ${CXX_WARNS}")
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -ggdb3 -fno-inline") SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -ggdb3 -fno-inline")
SET(CMAKE_CXX_FLAGS_RELEASE "-O2") SET(CMAKE_CXX_FLAGS_RELEASE "-O2")
@ -84,7 +84,6 @@ SET(SOURCES
src/framework/net/rsa.cpp src/framework/net/rsa.cpp
# framework util # framework util
src/framework/util/color.cpp
src/framework/util/translator.cpp src/framework/util/translator.cpp
# framework core # framework core

View File

@ -23,17 +23,39 @@
#ifndef FRAMEWORK_CONST_H #ifndef FRAMEWORK_CONST_H
#define FRAMEWORK_CONST_H #define FRAMEWORK_CONST_H
//namespace fw { #include "util/color.h"
enum LogLevel { 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 LogLevel {
LogDebug = 0, LogDebug = 0,
LogInfo, LogInfo,
LogWarning, LogWarning,
LogError, LogError,
LogFatal LogFatal
}; };
enum AlignmentFlag { enum BlendFunc {
BlendNormal,
BlendColorzing
};
enum AspectRatioMode {
IgnoreAspectRatio,
KeepAspectRatio,
KeepAspectRatioByExpanding
};
enum AlignmentFlag {
AlignNone = 0, AlignNone = 0,
AlignLeft = 1, AlignLeft = 1,
AlignRight = 2, AlignRight = 2,
@ -50,9 +72,9 @@ enum AlignmentFlag {
AlignTopCenter = AlignTop | AlignHorizontalCenter, AlignTopCenter = AlignTop | AlignHorizontalCenter,
AlignBottomCenter = AlignBottom | AlignHorizontalCenter, AlignBottomCenter = AlignBottom | AlignHorizontalCenter,
AlignCenter = AlignVerticalCenter | AlignHorizontalCenter AlignCenter = AlignVerticalCenter | AlignHorizontalCenter
}; };
enum AnchorEdge { enum AnchorEdge {
AnchorNone = 0, AnchorNone = 0,
AnchorTop, AnchorTop,
AnchorBottom, AnchorBottom,
@ -60,36 +82,36 @@ enum AnchorEdge {
AnchorRight, AnchorRight,
AnchorVerticalCenter, AnchorVerticalCenter,
AnchorHorizontalCenter, AnchorHorizontalCenter,
}; };
enum FocusReason { enum FocusReason {
MouseFocusReason = 0, MouseFocusReason = 0,
TabFocusReason, TabFocusReason,
ActiveFocusReason, ActiveFocusReason,
OtherFocusReason OtherFocusReason
}; };
enum MouseButton { enum MouseButton {
MouseNoButton = 0, MouseNoButton = 0,
MouseLeftButton, MouseLeftButton,
MouseRightButton, MouseRightButton,
MouseMidButton MouseMidButton
}; };
enum MouseWheelDirection { enum MouseWheelDirection {
MouseNoWheel = 0, MouseNoWheel = 0,
MouseWheelUp, MouseWheelUp,
MouseWheelDown MouseWheelDown
}; };
enum KeyboardModifier { enum KeyboardModifier {
KeyboardNoModifier = 0, KeyboardNoModifier = 0,
KeyboardCtrlModifier = 1, KeyboardCtrlModifier = 1,
KeyboardAltModifier = 2, KeyboardAltModifier = 2,
KeyboardShiftModifier = 4 KeyboardShiftModifier = 4
}; };
enum WidgetState { enum WidgetState {
DefaultState = 0, DefaultState = 0,
ActiveState = 1, ActiveState = 1,
FocusState = 2, FocusState = 2,
@ -100,8 +122,7 @@ enum WidgetState {
//MiddleState, //MiddleState,
//LastState, //LastState,
//AlternateState //AlternateState
}; };
}
//}
#endif #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: " }; 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); m_onLog(level, message, now);
} }
if(level == LogFatal) { if(level == Fw::LogFatal) {
m_terminated = true; m_terminated = true;
exit(-1); 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; std::stringstream ss;
prettyFunction = prettyFunction.substr(0, prettyFunction.find_first_of('(')); prettyFunction = prettyFunction.substr(0, prettyFunction.find_first_of('('));

View File

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

View File

@ -61,10 +61,10 @@ bool Module::load()
for(const std::string& depName : m_dependencies) { for(const std::string& depName : m_dependencies) {
ModulePtr dep = g_modules.getModule(depName); ModulePtr dep = g_modules.getModule(depName);
if(!dep) 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()) 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) { 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()); PHYSFS_file* file = PHYSFS_openRead(fullPath.c_str());
if(!file) { if(!file) {
out.clear(std::ios::failbit); 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 { } else {
int fileSize = PHYSFS_fileLength(file); int fileSize = PHYSFS_fileLength(file);
if(fileSize > 0) { if(fileSize > 0) {

View File

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

View File

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

View File

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

View File

@ -25,11 +25,6 @@
#include "declarations.h" #include "declarations.h"
enum BlendFuncType {
BLEND_NORMAL,
BLEND_COLORIZING
};
class Graphics class Graphics
{ {
public: public:
@ -56,7 +51,7 @@ public:
void bindColor(const Color& color); void bindColor(const Color& color);
void bindTexture(const TexturePtr& texture); void bindTexture(const TexturePtr& texture);
void bindBlendFunc(BlendFuncType blendType); void bindBlendFunc(Fw::BlendFunc blendType);
// drawing API // drawing API
void drawTexturedRect(const Rect& screenCoords, 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 // append trace level to error message
if(traceLevel >= 0) 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 else
m_what = fw::mkstr("LUA ERROR: ", error); m_what = Fw::mkstr("LUA ERROR: ", error);
} }
LuaBadNumberOfArgumentsException::LuaBadNumberOfArgumentsException(int expected, int got) LuaBadNumberOfArgumentsException::LuaBadNumberOfArgumentsException(int expected, int got)
{ {
std::string error = "attempt to call a function with wrong number of arguments"; std::string error = "attempt to call a function with wrong number of arguments";
if(expected >= 0 && got >= 0) 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); generateLuaErrorMessage(error, 1);
} }
LuaBadValueCastException::LuaBadValueCastException(const std::string& luaTypeName, const std::string& cppTypeName) 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); generateLuaErrorMessage(error, 0);
} }

View File

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

View File

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

View File

@ -64,7 +64,7 @@ public:
/// Returns the class name used in Lua /// Returns the class name used in Lua
virtual std::string getLuaObjectName() const { virtual std::string getLuaObjectName() const {
// this could later be cached for more performance // 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(); } LuaObjectPtr asLuaObject() { return shared_from_this(); }

View File

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

View File

@ -52,7 +52,7 @@ void Connection::connect(const std::string& host, uint16 port, const SimpleCallb
m_connected = false; m_connected = false;
m_connectCallback = connectCallback; 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_resolver.async_resolve(query, std::bind(&Connection::onResolve, shared_from_this(), _1, _2));
m_readTimer.expires_from_now(boost::posix_time::seconds(READ_TIMEOUT)); 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) 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; return res;
} }
OTMLNodePtr OTMLNode::atIndex(int childIndex) OTMLNodePtr OTMLNode::atIndex(int childIndex)
{ {
if(childIndex >= size() || childIndex < 0) 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]; return m_children[childIndex];
} }

View File

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

View File

@ -181,7 +181,7 @@ void OTMLParser::parseNode(const std::string& data)
node->setUnique(dotsPos != std::string::npos); node->setUnique(dotsPos != std::string::npos);
node->setTag(tag); 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 // ~ is considered the null value
if(value == "~") if(value == "~")

View File

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

View File

@ -28,16 +28,16 @@
class UIAnchor class UIAnchor
{ {
public: 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) { } 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; } std::string getHookedWidgetId() const { return m_hookedWidgetId; }
AnchorEdge getHookedEdge() const { return m_hookedEdge; } Fw::AnchorEdge getHookedEdge() const { return m_hookedEdge; }
private: private:
AnchorEdge m_anchoredEdge; Fw::AnchorEdge m_anchoredEdge;
AnchorEdge m_hookedEdge; Fw::AnchorEdge m_hookedEdge;
std::string m_hookedWidgetId; std::string m_hookedWidgetId;
}; };
@ -61,8 +61,8 @@ class UIAnchorLayout : public UILayout
public: public:
UIAnchorLayout(UIWidgetPtr parentWidget) : UILayout(parentWidget) { } UIAnchorLayout(UIWidgetPtr parentWidget) : UILayout(parentWidget) { }
void addAnchor(const UIWidgetPtr& anchoredWidget, AnchorEdge anchoredEdge, void addAnchor(const UIWidgetPtr& anchoredWidget, Fw::AnchorEdge anchoredEdge,
const std::string& hookedWidgetId, AnchorEdge hookedEdge); const std::string& hookedWidgetId, Fw::AnchorEdge hookedEdge);
void removeAnchors(const UIWidgetPtr& anchoredWidget); void removeAnchors(const UIWidgetPtr& anchoredWidget);
void centerIn(const UIWidgetPtr& anchoredWidget, const std::string& hookedWidgetId); void centerIn(const UIWidgetPtr& anchoredWidget, const std::string& hookedWidgetId);
void fill(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(); UIWidget::render();
Rect textRect = m_rect; Rect textRect = m_rect;
textRect.translate(m_textTranslate); 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) 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(isPressed()) {
if(m_onClick && getRect().contains(mousePos)) if(m_onClick && getRect().contains(mousePos))

View File

@ -41,7 +41,7 @@ public:
protected: protected:
virtual void onStyleApply(const OTMLNodePtr& styleNode); 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; SimpleCallback m_onClick;
Point m_textTranslate; Point m_textTranslate;

View File

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

View File

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

View File

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

View File

@ -35,7 +35,7 @@ public:
void update(); void update();
void setText(const std::string& text); void setText(const std::string& text);
void setAlign(AlignmentFlag align); void setAlign(Fw::AlignmentFlag align);
void setCursorPos(int pos); void setCursorPos(int pos);
void setCursorEnabled(bool enable = true); void setCursorEnabled(bool enable = true);
@ -51,16 +51,16 @@ public:
protected: protected:
virtual void onStyleApply(const OTMLNodePtr& styleNode); virtual void onStyleApply(const OTMLNodePtr& styleNode);
virtual void onGeometryUpdate(const Rect& oldRect, const Rect& newRect); 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 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: private:
void blinkCursor(); void blinkCursor();
std::string m_text; std::string m_text;
Rect m_drawArea; Rect m_drawArea;
AlignmentFlag m_align; Fw::AlignmentFlag m_align;
int m_cursorPos; int m_cursorPos;
Point m_startInternalPos; Point m_startInternalPos;
int m_startRenderPos; int m_startRenderPos;

View File

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

View File

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

View File

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

View File

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

View File

@ -37,9 +37,9 @@ public:
protected: protected:
virtual void onStyleApply(const OTMLNodePtr& styleNode); virtual void onStyleApply(const OTMLNodePtr& styleNode);
virtual void onGeometryUpdate(const Rect& oldRect, const Rect& newRect); 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 onMousePress(const Point& mousePos, MouseButton button); virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button);
virtual bool onMouseRelease(const Point& mousePos, MouseButton button); virtual bool onMouseRelease(const Point& mousePos, Fw::MouseButton button);
virtual bool onMouseMove(const Point& mousePos, const Point& mouseMoved); virtual bool onMouseMove(const Point& mousePos, const Point& mouseMoved);
private: private:
@ -52,7 +52,7 @@ private:
ImagePtr m_bodyImage; ImagePtr m_bodyImage;
int m_headHeight; int m_headHeight;
int m_headMargin; int m_headMargin;
AlignmentFlag m_titleAlign; Fw::AlignmentFlag m_titleAlign;
}; };
#endif #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; }
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: private:
RGBA color; RGBA color;
}; };
@ -111,11 +102,11 @@ inline std::istream& operator>>(std::istream& in, Color& color)
in >> tmp; in >> tmp;
if(tmp.length() == 6 || tmp.length() == 8) { if(tmp.length() == 6 || tmp.length() == 8) {
color.setRed((uint8)fw::hex2dec(tmp.substr(0, 2))); color.setRed((uint8)Fw::hex2dec(tmp.substr(0, 2)));
color.setGreen((uint8)fw::hex2dec(tmp.substr(2, 2))); color.setGreen((uint8)Fw::hex2dec(tmp.substr(2, 2)));
color.setBlue((uint8)fw::hex2dec(tmp.substr(4, 2))); color.setBlue((uint8)Fw::hex2dec(tmp.substr(4, 2)));
if(tmp.length() == 8) if(tmp.length() == 8)
color.setAlpha((uint8)fw::hex2dec(tmp.substr(6, 2))); color.setAlpha((uint8)Fw::hex2dec(tmp.substr(6, 2)));
else else
color.setAlpha(255); color.setAlpha(255);
} else } else

View File

@ -24,12 +24,7 @@
#define SIZE_H #define SIZE_H
#include "point.h" #include "point.h"
#include "../const.h"
enum ESizeScaleMode {
IGNORE_ASPECT_RATIO,
KEEP_ASPECT_RATIO,
KEEP_ASPECT_RATIO_BY_EXPANDING
};
template<class T> template<class T>
class TSize 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> 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)); } 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) { void scale(const TSize<T>& s, Fw::AspectRatioMode mode) {
if(mode == IGNORE_ASPECT_RATIO || wd == 0 || ht == 0) { if(mode == Fw::IgnoreAspectRatio || wd == 0 || ht == 0) {
wd = s.wd; wd = s.wd;
ht = s.ht; ht = s.ht;
} else { } else {
bool useHeight; bool useHeight;
T rw = (s.ht * wd) / ht; T rw = (s.ht * wd) / ht;
if(mode == KEEP_ASPECT_RATIO) if(mode == Fw::KeepAspectRatio)
useHeight = (rw <= s.wd); useHeight = (rw <= s.wd);
else // mode == KEEP_ASPECT_RATIO_BY_EXPANDING else // mode == Fw::KeepAspectRatioByExpanding
useHeight = (rw >= s.wd); useHeight = (rw >= s.wd);
if(useHeight) { 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; } float ratio() const { return (float)wd/ht; }
T area() const { return wd*ht; } T area() const { return wd*ht; }

View File

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

View File

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

View File

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

View File

@ -1,210 +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.
*/
#ifndef OTCLIENT_CORE_CONST_H
#define OTCLIENT_CORE_CONST_H
#include <framework/util/color.h>
enum ThingAttributesGroup {
THING_GROUP_NONE = 0,
THING_GROUP_GROUND,
THING_GROUP_CONTAINER,
THING_GROUP_WEAPON,
THING_GROUP_AMMUNITION,
THING_GROUP_ARMOR,
THING_GROUP_RUNE,
THING_GROUP_TELEPORT,
THING_GROUP_MAGICFIELD,
THING_GROUP_WRITEABLE,
THING_GROUP_KEY,
THING_GROUP_SPLASH,
THING_GROUP_FLUID,
THING_GROUP_DOOR,
THING_GROUP_LAST
};
enum ThingType {
THING_ITEM,
THING_CREATURE,
THING_EFFECT,
THING_SHOT
};
enum Direction {
DIRECTION_NORTH,
DIRECTION_EAST,
DIRECTION_SOUTH,
DIRECTION_WEST
};
enum SpriteMask {
SpriteMaskRed = 0,
SpriteMaskGreen,
SpriteMaskBlue,
SpriteMaskYellow,
SpriteMaskNone = 255
};
static const Color OutfitColors[] = {
Color(255,255,255),
Color(255,212,191),
Color(255,233,191),
Color(255,255,191),
Color(233,255,191),
Color(212,255,191),
Color(191,255,191),
Color(191,255,212),
Color(191,255,233),
Color(191,255,255),
Color(191,233,255),
Color(191,212,255),
Color(191,191,255),
Color(212,191,255),
Color(233,191,255),
Color(255,191,255),
Color(255,191,233),
Color(255,191,212),
Color(255,191,191),
Color(128,128,128),
Color(191,159,143),
Color(191,175,143),
Color(191,191,143),
Color(175,191,143),
Color(159,191,143),
Color(143,191,143),
Color(143,191,159),
Color(143,191,175),
Color(143,191,191),
Color(143,175,191),
Color(143,159,191),
Color(143,143,191),
Color(159,143,191),
Color(175,143,191),
Color(191,143,191),
Color(191,143,175),
Color(191,143,159),
Color(191,143,143),
Color(182,182,182),
Color(191,127,95),
Color(191,159,95),
Color(191,191,95),
Color(159,191,95),
Color(127,191,95),
Color(95,191,95),
Color(95,191,127),
Color(95,191,159),
Color(95,191,191),
Color(95,159,191),
Color(95,127,191),
Color(95,95,191),
Color(127,95,191),
Color(159,95,191),
Color(191,95,191),
Color(191,95,159),
Color(191,95,127),
Color(191,95,95),
Color(145,145,145),
Color(191,106,63),
Color(191,148,63),
Color(191,191,63),
Color(148,191,63),
Color(107,191,63),
Color(63,191,63),
Color(63,191,106),
Color(63,191,148),
Color(63,191,191),
Color(63,148,191),
Color(63,106,191),
Color(63,63,191),
Color(106,63,191),
Color(148,63,191),
Color(191,63,191),
Color(191,63,148),
Color(191,63,106),
Color(191,63,63),
Color(109,109,109),
Color(255,85,0),
Color(255,170,0),
Color(255,255,0),
Color(170,255,0),
Color(84,255,0),
Color(0,255,0),
Color(0,255,84),
Color(0,255,170),
Color(0,255,255),
Color(0,169,255),
Color(0,85,255),
Color(0,0,255),
Color(85,0,255),
Color(169,0,255),
Color(254,0,255),
Color(255,0,170),
Color(255,0,85),
Color(255,0,0),
Color(72,72,72),
Color(191,63,0),
Color(191,127,0),
Color(191,191,0),
Color(127,191,0),
Color(63,191,0),
Color(0,191,0),
Color(0,191,63),
Color(0,191,127),
Color(0,191,191),
Color(0,127,191),
Color(0,63,191),
Color(0,0,191),
Color(63,0,191),
Color(127,0,191),
Color(191,0,191),
Color(191,0,127),
Color(191,0,63),
Color(191,0,0),
Color(36,36,36),
Color(127,42,0),
Color(127,85,0),
Color(127,127,0),
Color(85,127,0),
Color(42,127,0),
Color(0,127,0),
Color(0,127,42),
Color(0,127,85),
Color(0,127,127),
Color(0,84,127),
Color(0,42,127),
Color(0,0,127),
Color(42,0,127),
Color(84,0,127),
Color(127,0,127),
Color(191,0,85),
Color(127,0,42),
Color(127,0,0)
};
#endif

View File

@ -28,10 +28,10 @@
#include <framework/graphics/graphics.h> #include <framework/graphics/graphics.h>
#include <framework/graphics/fontmanager.h> #include <framework/graphics/fontmanager.h>
Creature::Creature() : Thing(THING_CREATURE) Creature::Creature() : Thing(Otc::Creature)
{ {
m_healthPercent = 0; m_healthPercent = 0;
m_direction = DIRECTION_SOUTH; m_direction = Otc::South;
m_animation = 0; m_animation = 0;
m_walking = false; m_walking = false;
@ -72,13 +72,13 @@ void Creature::draw(int x, int y)
if(m_walking && attributes.animcount > 1) { if(m_walking && attributes.animcount > 1) {
double offset = (32.0 / m_walkTime) * (g_platform.getTicks() - m_lastTicks); double offset = (32.0 / m_walkTime) * (g_platform.getTicks() - m_lastTicks);
if(m_direction == DIRECTION_NORTH) if(m_direction == Otc::North)
m_walkOffsetY = std::max(m_walkOffsetY - offset, 0.0); m_walkOffsetY = std::max(m_walkOffsetY - offset, 0.0);
else if(m_direction == DIRECTION_EAST) else if(m_direction == Otc::East)
m_walkOffsetX = std::min(m_walkOffsetX + offset, 0.0); m_walkOffsetX = std::min(m_walkOffsetX + offset, 0.0);
else if(m_direction == DIRECTION_SOUTH) else if(m_direction == Otc::South)
m_walkOffsetY = std::min(m_walkOffsetY + offset, 0.0); m_walkOffsetY = std::min(m_walkOffsetY + offset, 0.0);
else if(m_direction == DIRECTION_WEST) else if(m_direction == Otc::West)
m_walkOffsetX = std::max(m_walkOffsetX - offset, 0.0); m_walkOffsetX = std::max(m_walkOffsetX - offset, 0.0);
/*if(g_platform.getTicks() - m_lastTicks > m_speed / 4) { /*if(g_platform.getTicks() - m_lastTicks > m_speed / 4) {
@ -117,26 +117,26 @@ void Creature::draw(int x, int y)
// draw mask if exists // draw mask if exists
if(attributes.blendframes > 1) { if(attributes.blendframes > 1) {
g_graphics.bindBlendFunc(BLEND_COLORIZING); g_graphics.bindBlendFunc(Fw::BlendColorzing);
for(int mask = 0; mask < 4; ++mask) { for(int mask = 0; mask < 4; ++mask) {
int outfitColorId = 0; int outfitColorId = 0;
if(mask == SpriteMaskYellow) if(mask == Otc::SpriteYellowMask)
outfitColorId = m_outfit.head; outfitColorId = m_outfit.head;
else if(mask == SpriteMaskRed) else if(mask == Otc::SpriteRedMask)
outfitColorId = m_outfit.body; outfitColorId = m_outfit.body;
else if(mask == SpriteMaskGreen) else if(mask == Otc::SpriteGreenMask)
outfitColorId = m_outfit.legs; outfitColorId = m_outfit.legs;
else if(mask == SpriteMaskBlue) else if(mask == Otc::SpriteBlueMask)
outfitColorId = m_outfit.feet; outfitColorId = m_outfit.feet;
g_graphics.bindColor(OutfitColors[outfitColorId]); g_graphics.bindColor(Otc::OutfitColors[outfitColorId]);
internalDraw(x, y, 1, m_direction, ydiv, 0, m_animation, (SpriteMask)mask); internalDraw(x, y, 1, m_direction, ydiv, 0, m_animation, (Otc::SpriteMask)mask);
} }
g_graphics.bindBlendFunc(BLEND_NORMAL); g_graphics.bindBlendFunc(Fw::BlendNormal);
g_graphics.bindColor(Color::white); g_graphics.bindColor(Fw::white);
} }
} }
} }
@ -147,7 +147,7 @@ void Creature::drawInformation(int x, int y, bool useGray)
if(!useGray) { if(!useGray) {
// health bar according to yatc // health bar according to yatc
fillColor = Color::black; fillColor = Fw::black;
if(m_healthPercent > 92) { if(m_healthPercent > 92) {
fillColor.setGreen(188); fillColor.setGreen(188);
} }
@ -177,18 +177,18 @@ void Creature::drawInformation(int x, int y, bool useGray)
Rect healthRect = backgroundRect.expanded(-1); Rect healthRect = backgroundRect.expanded(-1);
healthRect.setWidth((m_healthPercent/100.0)*25); healthRect.setWidth((m_healthPercent/100.0)*25);
g_graphics.bindColor(Color::black); g_graphics.bindColor(Fw::black);
g_graphics.drawFilledRect(backgroundRect); g_graphics.drawFilledRect(backgroundRect);
g_graphics.bindColor(fillColor); g_graphics.bindColor(fillColor);
g_graphics.drawFilledRect(healthRect); g_graphics.drawFilledRect(healthRect);
// restore white color // restore white color
g_graphics.bindColor(Color::white); g_graphics.bindColor(Fw::white);
// name // name
FontPtr font = g_fonts.getFont("tibia-12px-rounded"); FontPtr font = g_fonts.getFont("tibia-12px-rounded");
font->renderText(m_name, Rect(x-100, y-15, 200, 15), AlignTopCenter, fillColor); font->renderText(m_name, Rect(x-100, y-15, 200, 15), Fw::AlignTopCenter, fillColor);
} }
void Creature::walk(const Position& position) void Creature::walk(const Position& position)
@ -206,19 +206,19 @@ void Creature::walk(const Position& position)
// set new direction // set new direction
if(m_walkingFromPosition + Position(0, -1, 0) == m_position) { if(m_walkingFromPosition + Position(0, -1, 0) == m_position) {
m_direction = DIRECTION_NORTH; m_direction = Otc::North;
m_walkOffsetY = 32; m_walkOffsetY = 32;
} }
else if(m_walkingFromPosition + Position(1, 0, 0) == m_position) { else if(m_walkingFromPosition + Position(1, 0, 0) == m_position) {
m_direction = DIRECTION_EAST; m_direction = Otc::East;
m_walkOffsetX = -32; m_walkOffsetX = -32;
} }
else if(m_walkingFromPosition + Position(0, 1, 0) == m_position) { else if(m_walkingFromPosition + Position(0, 1, 0) == m_position) {
m_direction = DIRECTION_SOUTH; m_direction = Otc::South;
m_walkOffsetY = -32; m_walkOffsetY = -32;
} }
else if(m_walkingFromPosition + Position(-1, 0, 0) == m_position) { else if(m_walkingFromPosition + Position(-1, 0, 0) == m_position) {
m_direction = DIRECTION_WEST; m_direction = Otc::West;
m_walkOffsetX = 32; m_walkOffsetX = 32;
} }
else { // Teleport else { // Teleport

View File

@ -45,7 +45,7 @@ public:
void setName(const std::string& name) { m_name = name; } void setName(const std::string& name) { m_name = name; }
void setHealthPercent(uint8 healthPercent) { m_healthPercent = healthPercent; } void setHealthPercent(uint8 healthPercent) { m_healthPercent = healthPercent; }
void setDirection(Direction direction) { m_direction = direction; } void setDirection(Otc::Direction direction) { m_direction = direction; }
void setOutfit(const Outfit& outfit) { m_outfit = outfit; } void setOutfit(const Outfit& outfit) { m_outfit = outfit; }
void setLight(const Light& light) { m_light = light; } void setLight(const Light& light) { m_light = light; }
void setSpeed(uint16 speed) { m_speed = speed; } void setSpeed(uint16 speed) { m_speed = speed; }
@ -56,7 +56,7 @@ public:
std::string getName() { return m_name; } std::string getName() { return m_name; }
uint8 getHealthPercent() { return m_healthPercent; } uint8 getHealthPercent() { return m_healthPercent; }
Direction getDirection() { return m_direction; } Otc::Direction getDirection() { return m_direction; }
Outfit getOutfit() { return m_outfit; } Outfit getOutfit() { return m_outfit; }
Light getLight() { return m_light; } Light getLight() { return m_light; }
uint16 getSpeed() { return m_speed; } uint16 getSpeed() { return m_speed; }
@ -76,7 +76,7 @@ public:
private: private:
std::string m_name; std::string m_name;
uint8 m_healthPercent; uint8 m_healthPercent;
Direction m_direction; Otc::Direction m_direction;
Outfit m_outfit; Outfit m_outfit;
Light m_light; Light m_light;
uint16 m_speed; uint16 m_speed;

View File

@ -32,11 +32,11 @@ bool DatManager::load(const std::string& file)
std::stringstream fin; std::stringstream fin;
g_resources.loadFile(file, fin); g_resources.loadFile(file, fin);
m_signature = fw::getu32(fin); m_signature = Fw::getU32(fin);
int numItems = fw::getu16(fin); int numItems = Fw::getU16(fin);
int numCreatures = fw::getu16(fin); int numCreatures = Fw::getU16(fin);
int numEffects = fw::getu16(fin); int numEffects = Fw::getU16(fin);
int numShots = fw::getu16(fin); int numShots = Fw::getU16(fin);
m_itemsAttributes.resize(numItems); m_itemsAttributes.resize(numItems);
for(int id = 100; id < numItems; ++id) for(int id = 100; id < numItems; ++id)
@ -83,16 +83,16 @@ void DatManager::parseThingAttributes(std::stringstream& fin, ThingAttributes& t
parseThingAttributesOpt(fin, thingAttributes, opt); parseThingAttributesOpt(fin, thingAttributes, opt);
} }
thingAttributes.width = fw::getu8(fin); thingAttributes.width = Fw::getU8(fin);
thingAttributes.height = fw::getu8(fin); thingAttributes.height = Fw::getU8(fin);
if(thingAttributes.width > 1 || thingAttributes.height > 1) if(thingAttributes.width > 1 || thingAttributes.height > 1)
fw::getu8(fin); // ?? Fw::getU8(fin); // ??
thingAttributes.blendframes = fw::getu8(fin); thingAttributes.blendframes = Fw::getU8(fin);
thingAttributes.xdiv = fw::getu8(fin); thingAttributes.xdiv = Fw::getU8(fin);
thingAttributes.ydiv = fw::getu8(fin); thingAttributes.ydiv = Fw::getU8(fin);
thingAttributes.zdiv = fw::getu8(fin); thingAttributes.zdiv = Fw::getU8(fin);
thingAttributes.animcount = fw::getu8(fin); thingAttributes.animcount = Fw::getU8(fin);
int totalSprites = thingAttributes.width int totalSprites = thingAttributes.width
* thingAttributes.height * thingAttributes.height
@ -104,15 +104,15 @@ void DatManager::parseThingAttributes(std::stringstream& fin, ThingAttributes& t
thingAttributes.sprites.resize(totalSprites); thingAttributes.sprites.resize(totalSprites);
for(uint16 i = 0; i < totalSprites; i++) for(uint16 i = 0; i < totalSprites; i++)
thingAttributes.sprites[i] = fw::getu16(fin); thingAttributes.sprites[i] = Fw::getU16(fin);
} }
void DatManager::parseThingAttributesOpt(std::stringstream& fin, ThingAttributes& thingAttributes, uint8 opt) void DatManager::parseThingAttributesOpt(std::stringstream& fin, ThingAttributes& thingAttributes, uint8 opt)
{ {
switch(opt) { switch(opt) {
case 0x00: // Ground tile case 0x00: // Ground tile
thingAttributes.speed = fw::getu16(fin); thingAttributes.speed = Fw::getU16(fin);
thingAttributes.group = THING_GROUP_GROUND; thingAttributes.group = Otc::ThingGroundGroup;
break; break;
case 0x01: // All OnTop case 0x01: // All OnTop
thingAttributes.alwaysOnTop = true; thingAttributes.alwaysOnTop = true;
@ -127,7 +127,7 @@ void DatManager::parseThingAttributesOpt(std::stringstream& fin, ThingAttributes
thingAttributes.alwaysOnTopOrder = 3; thingAttributes.alwaysOnTopOrder = 3;
break; break;
case 0x04: // Container case 0x04: // Container
thingAttributes.group = THING_GROUP_CONTAINER; thingAttributes.group = Otc::ThingContainerGroup;
break; break;
case 0x05: // Stackable case 0x05: // Stackable
thingAttributes.stackable = true; thingAttributes.stackable = true;
@ -138,21 +138,21 @@ void DatManager::parseThingAttributesOpt(std::stringstream& fin, ThingAttributes
thingAttributes.useable = true; thingAttributes.useable = true;
break; break;
case 0x08: // Writtable case 0x08: // Writtable
thingAttributes.group = THING_GROUP_WRITEABLE; thingAttributes.group = Otc::ThingWriteableGroup;
thingAttributes.readable = true; thingAttributes.readable = true;
thingAttributes.subParam08 = fw::getu16(fin); thingAttributes.subParam08 = Fw::getU16(fin);
break; break;
case 0x09: // Writtable once case 0x09: // Writtable once
// Writtable objects that can't be edited by players // Writtable objects that can't be edited by players
thingAttributes.readable = true; thingAttributes.readable = true;
thingAttributes.subParam08 = fw::getu16(fin); thingAttributes.subParam08 = Fw::getU16(fin);
break; break;
case 0x0A: // Fluid containers case 0x0A: // Fluid containers
thingAttributes.group = THING_GROUP_FLUID; thingAttributes.group = Otc::ThingFluidGroup;
fw::getu8(fin); Fw::getU8(fin);
break; break;
case 0x0B: // Splashes case 0x0B: // Splashes
thingAttributes.group = THING_GROUP_SPLASH; thingAttributes.group = Otc::ThingSplashGroup;
break; break;
case 0x0C: // Blocks solid objects (creatures, walls etc) case 0x0C: // Blocks solid objects (creatures, walls etc)
thingAttributes.blockSolid = true; thingAttributes.blockSolid = true;
@ -182,8 +182,8 @@ void DatManager::parseThingAttributesOpt(std::stringstream& fin, ThingAttributes
thingAttributes.rotable = true; thingAttributes.rotable = true;
break; break;
case 0x15: // Light info case 0x15: // Light info
thingAttributes.lightLevel = fw::getu16(fin); thingAttributes.lightLevel = Fw::getU16(fin);
thingAttributes.lightColor = fw::getu16(fin); thingAttributes.lightColor = Fw::getU16(fin);
break; break;
case 0x16: case 0x16:
break; break;
@ -191,13 +191,13 @@ void DatManager::parseThingAttributesOpt(std::stringstream& fin, ThingAttributes
break; break;
case 0x18: // Thing must be drawed with offset case 0x18: // Thing must be drawed with offset
thingAttributes.hasHeight = true; thingAttributes.hasHeight = true;
thingAttributes.drawOffset = fw::getu8(fin); thingAttributes.drawOffset = Fw::getU8(fin);
fw::getu8(fin); Fw::getU8(fin);
fw::getu16(fin); Fw::getU16(fin);
break; break;
case 0x19: // pixels characters height case 0x19: // pixels characters height
thingAttributes.drawNextOffset = fw::getu8(fin); thingAttributes.drawNextOffset = Fw::getU8(fin);
fw::getu8(fin); Fw::getU8(fin);
break; break;
case 0x1A: case 0x1A:
//thingAttributes.hasHeight = true; //thingAttributes.hasHeight = true;
@ -205,11 +205,11 @@ void DatManager::parseThingAttributesOpt(std::stringstream& fin, ThingAttributes
case 0x1B: case 0x1B:
break; break;
case 0x1C: // Minimap color case 0x1C: // Minimap color
thingAttributes.miniMapColor = fw::getu16(fin); thingAttributes.miniMapColor = Fw::getU16(fin);
thingAttributes.hasMiniMapColor = true; thingAttributes.hasMiniMapColor = true;
break; break;
case 0x1D: // Unknown case 0x1D: // Unknown
if(fw::getu16(fin) == 1112) if(Fw::getU16(fin) == 1112)
thingAttributes.readable = true; thingAttributes.readable = true;
break; break;
case 0x1E: case 0x1E:
@ -220,6 +220,6 @@ void DatManager::parseThingAttributesOpt(std::stringstream& fin, ThingAttributes
case 0x20: case 0x20:
break; break;
default: default:
throw std::runtime_error(fw::mkstr("unknown .dat byte code: 0x", std::hex, (int)opt)); throw std::runtime_error(Fw::mkstr("unknown .dat byte code: 0x", std::hex, (int)opt));
} }
} }

View File

@ -24,7 +24,6 @@
#define OTCLIENT_CORE_DECLARATIONS_H #define OTCLIENT_CORE_DECLARATIONS_H
#include <otclient/global.h> #include <otclient/global.h>
#include "const.h"
class Tile; class Tile;
class Thing; class Thing;

View File

@ -26,7 +26,7 @@
#include <framework/platform/platform.h> #include <framework/platform/platform.h>
#include <framework/core/eventdispatcher.h> #include <framework/core/eventdispatcher.h>
Effect::Effect() : Thing(THING_EFFECT) Effect::Effect() : Thing(Otc::Effect)
{ {
m_lastTicks = g_platform.getTicks(); m_lastTicks = g_platform.getTicks();
m_animation = 0; m_animation = 0;

View File

@ -65,7 +65,7 @@ void Game::onLogout()
m_online = false; m_online = false;
} }
void Game::walk(Direction direction) void Game::walk(Otc::Direction direction)
{ {
if(!m_online) if(!m_online)
return; return;
@ -75,37 +75,37 @@ void Game::walk(Direction direction)
m_localPlayer->setDirection(direction); m_localPlayer->setDirection(direction);
switch(direction) { switch(direction) {
case DIRECTION_NORTH: case Otc::North:
m_protocolGame->sendWalkNorth(); m_protocolGame->sendWalkNorth();
break; break;
case DIRECTION_EAST: case Otc::East:
m_protocolGame->sendWalkEast(); m_protocolGame->sendWalkEast();
break; break;
case DIRECTION_SOUTH: case Otc::South:
m_protocolGame->sendWalkSouth(); m_protocolGame->sendWalkSouth();
break; break;
case DIRECTION_WEST: case Otc::West:
m_protocolGame->sendWalkWest(); m_protocolGame->sendWalkWest();
break; break;
} }
} }
void Game::turn(Direction direction) void Game::turn(Otc::Direction direction)
{ {
if(!m_online) if(!m_online)
return; return;
switch(direction) { switch(direction) {
case DIRECTION_NORTH: case Otc::North:
m_protocolGame->sendTurnNorth(); m_protocolGame->sendTurnNorth();
break; break;
case DIRECTION_EAST: case Otc::East:
m_protocolGame->sendTurnEast(); m_protocolGame->sendTurnEast();
break; break;
case DIRECTION_SOUTH: case Otc::South:
m_protocolGame->sendTurnSouth(); m_protocolGame->sendTurnSouth();
break; break;
case DIRECTION_WEST: case Otc::West:
m_protocolGame->sendTurnWest(); m_protocolGame->sendTurnWest();
break; break;
} }

View File

@ -41,8 +41,8 @@ public:
void onLogin(); void onLogin();
void onLogout(); void onLogout();
void walk(Direction direction); void walk(Otc::Direction direction);
void turn(Direction direction); void turn(Otc::Direction direction);
bool isOnline() { return m_online; } bool isOnline() { return m_online; }

View File

@ -26,7 +26,7 @@
#include "thing.h" #include "thing.h"
#include <framework/platform/platform.h> #include <framework/platform/platform.h>
Item::Item() : Thing(THING_ITEM) Item::Item() : Thing(Otc::Item)
{ {
m_count = 0; m_count = 0;
m_lastTicks = g_platform.getTicks(); m_lastTicks = g_platform.getTicks();
@ -50,7 +50,7 @@ void Item::draw(int x, int y)
} }
} }
if(attributes.group == THING_GROUP_SPLASH || attributes.group == THING_GROUP_FLUID) { if(attributes.group == Otc::ThingSplashGroup || attributes.group == Otc::ThingFluidGroup) {
//xdiv = m_count % attributes.xdiv; //xdiv = m_count % attributes.xdiv;
//ydiv = m_count / attributes.ydiv; //ydiv = m_count / attributes.ydiv;

View File

@ -33,7 +33,7 @@ void Map::draw(const Rect& rect)
if(!m_framebuffer) if(!m_framebuffer)
m_framebuffer = FrameBufferPtr(new FrameBuffer(15*32, 11*32)); m_framebuffer = FrameBufferPtr(new FrameBuffer(15*32, 11*32));
g_graphics.bindColor(Color::white); g_graphics.bindColor(Fw::white);
m_framebuffer->bind(); m_framebuffer->bind();
LocalPlayerPtr player = g_game.getLocalPlayer(); LocalPlayerPtr player = g_game.getLocalPlayer();
@ -91,12 +91,12 @@ void Map::draw(const Rect& rect)
} }
// debug draws // debug draws
g_graphics.bindColor(Color::red); g_graphics.bindColor(Fw::red);
g_graphics.drawBoundingRect(Rect(7*32, 5*32, 32, 32)); g_graphics.drawBoundingRect(Rect(7*32, 5*32, 32, 32));
m_framebuffer->unbind(); m_framebuffer->unbind();
g_graphics.bindColor(Color::white); g_graphics.bindColor(Fw::white);
m_framebuffer->draw(rect); m_framebuffer->draw(rect);
// calculate stretch factor // calculate stretch factor

View File

@ -36,8 +36,8 @@ bool SpriteManager::load(const std::string& file)
{ {
try { try {
g_resources.loadFile(file, m_fin); g_resources.loadFile(file, m_fin);
m_signature = fw::getu32(m_fin); m_signature = Fw::getU32(m_fin);
m_spritesCount = fw::getu16(m_fin); m_spritesCount = Fw::getU16(m_fin);
m_sprites.resize(m_spritesCount); m_sprites.resize(m_spritesCount);
return true; return true;
} catch(std::exception& e) { } catch(std::exception& e) {
@ -57,7 +57,7 @@ TexturePtr SpriteManager::loadSpriteTexture(int id)
{ {
m_fin.seekg(((id-1) * 4) + 6, std::ios_base::beg); m_fin.seekg(((id-1) * 4) + 6, std::ios_base::beg);
uint32 spriteAddress = fw::getu32(m_fin); uint32 spriteAddress = Fw::getU32(m_fin);
// no sprite? return an empty texture // no sprite? return an empty texture
if(spriteAddress == 0) if(spriteAddress == 0)
@ -67,11 +67,11 @@ TexturePtr SpriteManager::loadSpriteTexture(int id)
assert(m_fin.good()); assert(m_fin.good());
// skip color key // skip color key
fw::getu8(m_fin); Fw::getU8(m_fin);
fw::getu8(m_fin); Fw::getU8(m_fin);
fw::getu8(m_fin); Fw::getU8(m_fin);
uint16 pixelDataSize = fw::getu16(m_fin); uint16 pixelDataSize = Fw::getU16(m_fin);
uchar pixels[4096]; uchar pixels[4096];
int writePos = 0; int writePos = 0;
@ -92,9 +92,9 @@ TexturePtr SpriteManager::loadSpriteTexture(int id)
} }
for(int i = 0; i < coloredPixels; i++) { for(int i = 0; i < coloredPixels; i++) {
pixels[writePos + 0] = fw::getu8(m_fin); pixels[writePos + 0] = Fw::getU8(m_fin);
pixels[writePos + 1] = fw::getu8(m_fin); pixels[writePos + 1] = Fw::getU8(m_fin);
pixels[writePos + 2] = fw::getu8(m_fin); pixels[writePos + 2] = Fw::getU8(m_fin);
pixels[writePos + 3] = 0xFF; pixels[writePos + 3] = 0xFF;
writePos += 4; writePos += 4;
@ -115,14 +115,14 @@ TexturePtr SpriteManager::loadSpriteTexture(int id)
return TexturePtr(new Texture(32, 32, 4, pixels)); return TexturePtr(new Texture(32, 32, 4, pixels));
} }
TexturePtr SpriteManager::loadSpriteMask(TexturePtr spriteTex, SpriteMask mask) TexturePtr SpriteManager::loadSpriteMask(TexturePtr spriteTex, Otc::SpriteMask mask)
{ {
auto pixels = spriteTex->getPixels(); auto pixels = spriteTex->getPixels();
static RGBA maskColors[4] = { Color::red.rgba(), Color::green.rgba(), Color::blue.rgba(), Color::yellow.rgba() }; static RGBA maskColors[4] = { Fw::red.rgba(), Fw::green.rgba(), Fw::blue.rgba(), Fw::yellow.rgba() };
RGBA maskColor = maskColors[mask]; RGBA maskColor = maskColors[mask];
RGBA whiteColor = Color::white.rgba(); RGBA whiteColor = Fw::white.rgba();
RGBA alphaColor = Color::alpha.rgba(); RGBA alphaColor = Fw::alpha.rgba();
// convert pixels // convert pixels
// masked color -> white color // masked color -> white color
@ -138,7 +138,7 @@ TexturePtr SpriteManager::loadSpriteMask(TexturePtr spriteTex, SpriteMask mask)
return TexturePtr(new Texture(32, 32, 4, &pixels[0])); return TexturePtr(new Texture(32, 32, 4, &pixels[0]));
} }
TexturePtr SpriteManager::getSpriteTexture(int id, SpriteMask mask) TexturePtr SpriteManager::getSpriteTexture(int id, Otc::SpriteMask mask)
{ {
if(id == 0) if(id == 0)
return g_graphics.getEmptyTexture(); return g_graphics.getEmptyTexture();
@ -153,7 +153,7 @@ TexturePtr SpriteManager::getSpriteTexture(int id, SpriteMask mask)
//TODO: release unused sprites textures after X seconds //TODO: release unused sprites textures after X seconds
// to avoid massive texture allocations // to avoid massive texture allocations
if(mask != SpriteMaskNone) { if(mask != Otc::SpriteNoMask) {
if(!sprite.masks[mask]) if(!sprite.masks[mask])
sprite.masks[mask] = loadSpriteMask(sprite.texture, mask); sprite.masks[mask] = loadSpriteMask(sprite.texture, mask);
return sprite.masks[mask]; return sprite.masks[mask];

View File

@ -42,11 +42,11 @@ public:
uint32 getSignature() { return m_signature; } uint32 getSignature() { return m_signature; }
int getSpritesCount() { return m_spritesCount; } int getSpritesCount() { return m_spritesCount; }
TexturePtr getSpriteTexture(int id, SpriteMask mask = SpriteMaskNone); TexturePtr getSpriteTexture(int id, Otc::SpriteMask mask = Otc::SpriteNoMask);
private: private:
TexturePtr loadSpriteTexture(int id); TexturePtr loadSpriteTexture(int id);
TexturePtr loadSpriteMask(TexturePtr spriteTex, SpriteMask mask); TexturePtr loadSpriteMask(TexturePtr spriteTex, Otc::SpriteMask mask);
uint32 m_signature; uint32 m_signature;
uint16 m_spritesCount; uint16 m_spritesCount;

View File

@ -24,11 +24,11 @@
#include "spritemanager.h" #include "spritemanager.h"
#include <framework/graphics/graphics.h> #include <framework/graphics/graphics.h>
Thing::Thing(ThingType type) : m_id(0), m_type(type) Thing::Thing(Otc::ThingType type) : m_id(0), m_type(type)
{ {
} }
void Thing::internalDraw(int x, int y, int blendframes, int xdiv, int ydiv, int zdiv, int anim, SpriteMask mask) void Thing::internalDraw(int x, int y, int blendframes, int xdiv, int ydiv, int zdiv, int anim, Otc::SpriteMask mask)
{ {
const ThingAttributes& attributes = getAttributes(); const ThingAttributes& attributes = getAttributes();

View File

@ -36,7 +36,7 @@ struct Light
class Thing : public LuaObject class Thing : public LuaObject
{ {
public: public:
Thing(ThingType type); Thing(Otc::ThingType type);
virtual ~Thing() { } virtual ~Thing() { }
virtual void draw(int x, int y) = 0; virtual void draw(int x, int y) = 0;
@ -45,7 +45,7 @@ public:
void setPosition(const Position& position) { m_position = position; } void setPosition(const Position& position) { m_position = position; }
uint32 getId() const { return m_id; } uint32 getId() const { return m_id; }
ThingType getType() const { return m_type; } Otc::ThingType getType() const { return m_type; }
Position getPosition() const { return m_position; } Position getPosition() const { return m_position; }
virtual const ThingAttributes& getAttributes() = 0; virtual const ThingAttributes& getAttributes() = 0;
@ -57,10 +57,10 @@ public:
virtual LocalPlayerPtr asLocalPlayer() { return nullptr; } virtual LocalPlayerPtr asLocalPlayer() { return nullptr; }
protected: protected:
void internalDraw(int x, int y, int blendframes, int xdiv, int ydiv, int zdiv, int anim, SpriteMask mask = SpriteMaskNone); void internalDraw(int x, int y, int blendframes, int xdiv, int ydiv, int zdiv, int anim, Otc::SpriteMask mask = Otc::SpriteNoMask);
uint32 m_id; uint32 m_id;
ThingType m_type; Otc::ThingType m_type;
Position m_position; Position m_position;
}; };

View File

@ -28,7 +28,7 @@
struct ThingAttributes struct ThingAttributes
{ {
ThingAttributes() { ThingAttributes() {
group = THING_GROUP_NONE; group = Otc::ThingNoGroup;
blockSolid = false; blockSolid = false;
hasHeight = false; hasHeight = false;
blockPathFind = false; blockPathFind = false;
@ -69,7 +69,7 @@ struct ThingAttributes
uint16 speed, subParam07, subParam08, lightLevel, lightColor, miniMapColor; uint16 speed, subParam07, subParam08, lightLevel, lightColor, miniMapColor;
std::vector<int> sprites; std::vector<int> sprites;
ThingAttributesGroup group; Otc::ThingAttributesGroup group;
}; };
#endif #endif

View File

@ -99,14 +99,14 @@ void Tile::addThing(ThingPtr thing, int stackpos)
const ThingAttributes& thingAttributes = thing->getAttributes(); const ThingAttributes& thingAttributes = thing->getAttributes();
if(thing->getPosition() == g_game.getLocalPlayer()->getPosition() + Position(-1, 0, 0) && thingAttributes.group == THING_GROUP_GROUND) { if(thing->getPosition() == g_game.getLocalPlayer()->getPosition() + Position(-1, 0, 0) && thingAttributes.group == Otc::ThingGroundGroup) {
logDebug((int)thing->getId()); logDebug((int)thing->getId());
} }
if(thing->asItem()) { if(thing->asItem()) {
if(thingAttributes.group == THING_GROUP_GROUND) if(thingAttributes.group == Otc::ThingGroundGroup)
m_ground = thing; m_ground = thing;
else { else {
if(thingAttributes.alwaysOnTop) if(thingAttributes.alwaysOnTop)

View File

@ -26,6 +26,7 @@
#include <framework/global.h> #include <framework/global.h>
// widely used headers // widely used headers
#include <otclient/util/position.h> #include "const.h"
#include "util/position.h"
#endif #endif

View File

@ -32,37 +32,4 @@ class ProtocolGame;
typedef std::shared_ptr<ProtocolGame> ProtocolGamePtr; typedef std::shared_ptr<ProtocolGame> ProtocolGamePtr;
typedef std::shared_ptr<ProtocolLogin> ProtocolLoginPtr; typedef std::shared_ptr<ProtocolLogin> ProtocolLoginPtr;
#define CIPSOFT_PUBLIC_RSA "1321277432058722840622950990822933849527763264961655079678763618" \
"4334395343554449668205332383339435179772895415509701210392836078" \
"6959821132214473291575712138800495033169914814069637740318278150" \
"2907336840325241747827401343576296990629870233111328210165697754" \
"88792221429527047321331896351555606801473202394175817"
#define OTSERV_PUBLIC_RSA "1091201329673994292788609605089955415282375029027981291234687579" \
"3726629149257644633073969600111060390723088861007265581882535850" \
"3429057592827629436413108566029093628212635953836686562675849720" \
"6207862794310902180176810615217550567108238764764442605581471797" \
"07119674283982419152118103759076030616683978566631413"
// TODO: place it somewhere else
enum SpeakClasses {
SPEAK_SAY = 0x01, //normal talk
SPEAK_WHISPER = 0x02, //whispering - #w text
SPEAK_YELL = 0x03, //yelling - #y text
SPEAK_PRIVATE_PN = 0x04, //Player-to-NPC speaking(NPCs channel)
SPEAK_PRIVATE_NP = 0x05, //NPC-to-Player speaking
SPEAK_PRIVATE = 0x06, //Players speaking privately to players
SPEAK_CHANNEL_Y = 0x07, //Yellow message in chat
SPEAK_CHANNEL_W = 0x08, //White message in chat
SPEAK_BROADCAST = 0x09, //Broadcast a message - #b
SPEAK_CHANNEL_R1 = 0x0A, //Talk red on chat - #c
SPEAK_PRIVATE_RED = 0x0B, //Red private - @name@ text
SPEAK_CHANNEL_O = 0x0C, //Talk orange on text
SPEAK_MONSTER_SAY = 0x0D, //Talk orange
SPEAK_MONSTER_YELL = 0x0E //Yell orange
};
#endif #endif

View File

@ -598,7 +598,7 @@ void ProtocolGame::parseCreatureShields(InputMessage& msg)
void ProtocolGame::parseCreatureTurn(InputMessage& msg) void ProtocolGame::parseCreatureTurn(InputMessage& msg)
{ {
uint32 id = msg.getU32(); uint32 id = msg.getU32();
Direction direction = (Direction)msg.getU8(); Otc::Direction direction = (Otc::Direction)msg.getU8();
CreaturePtr creature = g_map.getCreatureById(id); CreaturePtr creature = g_map.getCreatureById(id);
if(creature) if(creature)
@ -680,27 +680,27 @@ void ProtocolGame::parseCreatureSpeak(InputMessage& msg)
uint8 type = msg.getU8(); uint8 type = msg.getU8();
switch(type) { switch(type) {
case SPEAK_SAY: case Otc::SpeakSay:
case SPEAK_WHISPER: case Otc::SpeakWhisper:
case SPEAK_YELL: case Otc::SpeakYell:
case SPEAK_MONSTER_SAY: case Otc::SpeakMonsterSay:
case SPEAK_MONSTER_YELL: case Otc::SpeakMonsterYell:
case SPEAK_PRIVATE_NP: case Otc::SpeakPrivateNpcToPlayer:
parsePosition(msg); // creaturePos parsePosition(msg); // creaturePos
break; break;
case SPEAK_CHANNEL_R1: case Otc::SpeakChannelRed:
case SPEAK_CHANNEL_O: case Otc::SpeakChannelOrange:
case SPEAK_CHANNEL_Y: case Otc::SpeakChannelYellow:
case SPEAK_CHANNEL_W: case Otc::SpeakChannelWhite:
msg.getU16(); // channelId msg.getU16(); // channelId
break; break;
case SPEAK_PRIVATE: case Otc::SpeakPrivate:
case SPEAK_PRIVATE_PN: case Otc::SpeakPrivatePlayerToNpc:
case SPEAK_BROADCAST: case Otc::SpeakBroadcast:
case SPEAK_PRIVATE_RED: case Otc::SpeakPrivateRed:
break; break;
default: default:
logDebug("[ProtocolGame::parseCreatureSpeak]: Unknown speak type.", (int)type); logTraceDebug("Unknown speak type.", (int)type);
break; break;
} }
@ -767,7 +767,7 @@ void ProtocolGame::parseTextMessage(InputMessage& msg)
void ProtocolGame::parseCancelWalk(InputMessage& msg) void ProtocolGame::parseCancelWalk(InputMessage& msg)
{ {
Direction direction = (Direction)msg.getU8(); Otc::Direction direction = (Otc::Direction)msg.getU8();
g_game.getLocalPlayer()->setDirection(direction); g_game.getLocalPlayer()->setDirection(direction);
} }
@ -921,7 +921,7 @@ void ProtocolGame::setTileDescription(InputMessage& msg, Position position)
return; return;
else { else {
if(stackpos >= 10) { if(stackpos >= 10) {
logDebug("[ProtocolGame::setTileDescription] Too many things!."); logTraceDebug("Too many things!.");
return; return;
} }
@ -984,7 +984,7 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg)
} }
uint8 healthPercent = msg.getU8(); uint8 healthPercent = msg.getU8();
Direction direction = (Direction)msg.getU8(); Otc::Direction direction = (Otc::Direction)msg.getU8();
Outfit outfit = internalGetOutfit(msg); Outfit outfit = internalGetOutfit(msg);
Light light; Light light;
@ -1032,7 +1032,7 @@ ItemPtr ProtocolGame::internalGetItem(InputMessage& msg, uint16 id)
item->setId(id); item->setId(id);
const ThingAttributes& itemAttributes = g_dat.getItemAttributes(id); const ThingAttributes& itemAttributes = g_dat.getItemAttributes(id);
if(itemAttributes.stackable || itemAttributes.group == THING_GROUP_FLUID || itemAttributes.group == THING_GROUP_SPLASH) if(itemAttributes.stackable || itemAttributes.group == Otc::ThingFluidGroup || itemAttributes.group == Otc::ThingSplashGroup)
item->setCount(msg.getU8()); item->setCount(msg.getU8());
return item; return item;

View File

@ -52,7 +52,7 @@ void ProtocolGame::sendLoginPacket(uint32 timestamp, uint8 unknown)
oMsg.addPaddingBytes(128 - (29 + m_accountName.length() + m_characterName.length() + m_accountPassword.length())); oMsg.addPaddingBytes(128 - (29 + m_accountName.length() + m_characterName.length() + m_accountPassword.length()));
// encrypt with RSA // encrypt with RSA
if(!Rsa::encrypt((char*)oMsg.getBuffer() + 6 + oMsg.getMessageSize() - 128, 128, OTSERV_PUBLIC_RSA)) if(!Rsa::encrypt((char*)oMsg.getBuffer() + 6 + oMsg.getMessageSize() - 128, 128, Otc::OtservPublicRSA))
return; return;
send(oMsg); send(oMsg);

View File

@ -106,7 +106,7 @@ void ProtocolLogin::sendLoginPacket()
// complete the 128 bytes for rsa encryption with zeros // complete the 128 bytes for rsa encryption with zeros
oMsg.addPaddingBytes(128 - (21 + m_accountName.length() + m_accountPassword.length())); oMsg.addPaddingBytes(128 - (21 + m_accountName.length() + m_accountPassword.length()));
if(!Rsa::encrypt((char*)oMsg.getBuffer() + 6 + oMsg.getMessageSize() - 128, 128, OTSERV_PUBLIC_RSA)) if(!Rsa::encrypt((char*)oMsg.getBuffer() + 6 + oMsg.getMessageSize() - 128, 128, Otc::OtservPublicRSA))
return; return;
send(oMsg); send(oMsg);
@ -140,7 +140,7 @@ void ProtocolLogin::parseCharacterList(InputMessage& inputMessage)
std::string world = inputMessage.getString(); std::string world = inputMessage.getString();
uint32 ip = inputMessage.getU32(); uint32 ip = inputMessage.getU32();
uint16 port = inputMessage.getU16(); uint16 port = inputMessage.getU16();
charList.push_back(CharacterInfo(name, world, fw::ip2str(ip), port)); charList.push_back(CharacterInfo(name, world, Fw::ip2str(ip), port));
} }
int premDays = inputMessage.getU16(); int premDays = inputMessage.getU16();

View File

@ -38,8 +38,6 @@
#include <otclient/core/game.h> #include <otclient/core/game.h>
#include <otclient/core/map.h> #include <otclient/core/map.h>
#define POLL_CYCLE_DELAY 10
OTClient g_client; OTClient g_client;
void OTClient::init(std::vector<std::string> args) void OTClient::init(std::vector<std::string> args)
@ -68,11 +66,11 @@ void OTClient::init(std::vector<std::string> args)
// create the client window // create the client window
int minWidth = 550; int minWidth = 550;
int minHeight = 450; int minHeight = 450;
int windowX = fw::fromstring(g_configs.get("window x"), 0); int windowX = Fw::fromstring(g_configs.get("window x"), 0);
int windowY = fw::fromstring(g_configs.get("window y"), 0); int windowY = Fw::fromstring(g_configs.get("window y"), 0);
int windowWidth = fw::fromstring(g_configs.get("window width"), minWidth); int windowWidth = Fw::fromstring(g_configs.get("window width"), minWidth);
int windowHeight = fw::fromstring(g_configs.get("window height"), minHeight); int windowHeight = Fw::fromstring(g_configs.get("window height"), minHeight);
bool maximized = fw::fromstring(g_configs.get("window maximized"), false); bool maximized = Fw::fromstring(g_configs.get("window maximized"), false);
g_platform.createWindow(windowX, windowY, windowWidth, windowHeight, minWidth, minHeight, maximized); g_platform.createWindow(windowX, windowY, windowWidth, windowHeight, minWidth, minHeight, maximized);
g_platform.setWindowTitle("OTClient"); g_platform.setWindowTitle("OTClient");
@ -128,7 +126,7 @@ void OTClient::run()
// calculate fps // calculate fps
frameCount++; frameCount++;
if(frameTicks - lastFpsTicks >= 1000) { if(frameTicks - lastFpsTicks >= 1000) {
fpsText = fw::mkstr("FPS: ", frameCount); fpsText = Fw::mkstr("FPS: ", frameCount);
fpsTextSize = defaultFont->calculateTextRectSize(fpsText); fpsTextSize = defaultFont->calculateTextRectSize(fpsText);
frameCount = 0; frameCount = 0;
lastFpsTicks = frameTicks; lastFpsTicks = frameTicks;
@ -244,12 +242,12 @@ void OTClient::loadConfigurations()
int defHeight = 450; int defHeight = 450;
// sets default window configuration // sets default window configuration
g_configs.set("window x", fw::tostring((g_platform.getDisplayWidth() - defWidth)/2)); g_configs.set("window x", Fw::tostring((g_platform.getDisplayWidth() - defWidth)/2));
g_configs.set("window y", fw::tostring((g_platform.getDisplayHeight() - defHeight)/2)); g_configs.set("window y", Fw::tostring((g_platform.getDisplayHeight() - defHeight)/2));
g_configs.set("window width", fw::tostring(defWidth)); g_configs.set("window width", Fw::tostring(defWidth));
g_configs.set("window height", fw::tostring(defHeight)); g_configs.set("window height", Fw::tostring(defHeight));
g_configs.set("window maximized", fw::tostring(false)); g_configs.set("window maximized", Fw::tostring(false));
g_configs.set("vsync", fw::tostring(true)); g_configs.set("vsync", Fw::tostring(true));
// loads user configuration // loads user configuration
if(!g_configs.load("config.otml")) if(!g_configs.load("config.otml"))
@ -259,17 +257,17 @@ void OTClient::loadConfigurations()
void OTClient::setupConfigurations() void OTClient::setupConfigurations()
{ {
// activate vertical synchronization? // activate vertical synchronization?
bool vsync = fw::fromstring(g_configs.get("vsync"), true); bool vsync = Fw::fromstring(g_configs.get("vsync"), true);
g_platform.setVerticalSync(vsync); g_platform.setVerticalSync(vsync);
} }
void OTClient::saveConfigurations() void OTClient::saveConfigurations()
{ {
g_configs.set("window x", fw::tostring(g_platform.getWindowX())); g_configs.set("window x", Fw::tostring(g_platform.getWindowX()));
g_configs.set("window y", fw::tostring(g_platform.getWindowY())); g_configs.set("window y", Fw::tostring(g_platform.getWindowY()));
g_configs.set("window width", fw::tostring(g_platform.getWindowWidth())); g_configs.set("window width", Fw::tostring(g_platform.getWindowWidth()));
g_configs.set("window height", fw::tostring(g_platform.getWindowHeight())); g_configs.set("window height", Fw::tostring(g_platform.getWindowHeight()));
g_configs.set("window maximized", fw::tostring(g_platform.isWindowMaximized())); g_configs.set("window maximized", Fw::tostring(g_platform.isWindowMaximized()));
// saves user configuration // saves user configuration
if(!g_configs.save()) if(!g_configs.save())
@ -297,23 +295,23 @@ void OTClient::onPlatformEvent(const PlatformEvent& event)
if(event.type == EventKeyDown) { if(event.type == EventKeyDown) {
if(!event.ctrl && !event.alt && !event.shift) { if(!event.ctrl && !event.alt && !event.shift) {
if(event.keycode == KC_UP) if(event.keycode == KC_UP)
g_game.walk(DIRECTION_NORTH); g_game.walk(Otc::North);
else if(event.keycode == KC_RIGHT) else if(event.keycode == KC_RIGHT)
g_game.walk(DIRECTION_EAST); g_game.walk(Otc::East);
else if(event.keycode == KC_DOWN) else if(event.keycode == KC_DOWN)
g_game.walk(DIRECTION_SOUTH); g_game.walk(Otc::South);
else if(event.keycode == KC_LEFT) else if(event.keycode == KC_LEFT)
g_game.walk(DIRECTION_WEST); g_game.walk(Otc::West);
} }
else if(event.ctrl && !event.alt && !event.shift) { else if(event.ctrl && !event.alt && !event.shift) {
if(event.keycode == KC_UP) if(event.keycode == KC_UP)
g_game.turn(DIRECTION_NORTH); g_game.turn(Otc::North);
else if(event.keycode == KC_RIGHT) else if(event.keycode == KC_RIGHT)
g_game.turn(DIRECTION_EAST); g_game.turn(Otc::East);
else if(event.keycode == KC_DOWN) else if(event.keycode == KC_DOWN)
g_game.turn(DIRECTION_SOUTH); g_game.turn(Otc::South);
else if(event.keycode == KC_LEFT) else if(event.keycode == KC_LEFT)
g_game.turn(DIRECTION_WEST); g_game.turn(Otc::West);
else if(event.keycode == KC_APOSTROPHE) { else if(event.keycode == KC_APOSTROPHE) {
// TODO: move these events to lua // TODO: move these events to lua
UIWidgetPtr console = g_ui.getRootWidget()->getChildById("consolePanel"); UIWidgetPtr console = g_ui.getRootWidget()->getChildById("consolePanel");

View File

@ -28,6 +28,10 @@
class OTClient : public PlatformListener class OTClient : public PlatformListener
{ {
enum {
POLL_CYCLE_DELAY = 10
};
public: public:
/// Where everything begins... /// Where everything begins...
void init(std::vector<std::string> args); void init(std::vector<std::string> args);