BEAWARE all game functionality is disabled with this commit for a while

* rework client modules
* hide main window when loading
* remake top menu functions
* rework modules autoload
* improve path resolving for otml and lua
* move core_widgets to core_lib
* fix tooltip issues
* split some styles
* add bit32 lua library
* fix assert issues
* fix compilation on linux 32 systems
* rework gcc compile options
* renable and fix some warnings
* remove unused constants
* speedup sprite cache
* move UIGame to lua (not funcional yet)
* fix a lot of issues in x11 window
* fix crash handler
* add some warnings do uiwidget
and much more...
This commit is contained in:
Eduardo Bart
2012-02-20 00:27:08 -02:00
parent 96358b317d
commit e03bf33f58
201 changed files with 1443 additions and 707 deletions

View File

@@ -13,7 +13,7 @@ OPTION(USE_OPENGL_ES2 "Use OpenGL ES 2.0 (for mobiles devices)" OFF)
# set debug as default build type
IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE Debug)
SET(CMAKE_BUILD_TYPE RelWithDebInfo)
ENDIF(NOT CMAKE_BUILD_TYPE)
# find needed libraries
@@ -36,18 +36,27 @@ FIND_PACKAGE(ZLIB REQUIRED)
# setup compiler options
IF(CMAKE_COMPILER_IS_GNUCXX)
SET(CXX_WARNS "-Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-unused-variable -Wno-switch -Wno-missing-field-initializers")
SET(CMAKE_CXX_FLAGS "-std=gnu++0x -pipe ${CXX_WARNS}")
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -ggdb3 -fno-inline")
SET(CMAKE_CXX_FLAGS_RELEASE "-O2")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O1 -g -ggdb -fno-inline")
SET(CMAKE_CXX_LINK_FLAGS "-static-libgcc -static-libstdc++ -Wl,--as-needed")
SET(CXX_WARNS "-Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-but-set-variable")
SET(CMAKE_CXX_FLAGS "-std=gnu++0x -pipe ${CXX_WARNS}")
SET(CMAKE_C_FLAGS "-pipe ${CXX_WARNS}")
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -ggdb")
SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -ggdb")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O1 -g -ggdb")
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O1 -g -ggdb")
SET(CMAKE_CXX_FLAGS_RELEASE "-O2")
SET(CMAKE_C_FLAGS_RELEASE "-O2")
SET(CMAKE_CXX_LINK_FLAGS "-static-libgcc -static-libstdc++ -Wl,--as-needed")
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
ADD_DEFINITIONS(-DDEBUG)
ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug")
IF(CMAKE_BUILD_TYPE STREQUAL "Release")
# NDEBUG disable asserts
ADD_DEFINITIONS(-DNDEBUG)
ENDIF(CMAKE_BUILD_TYPE STREQUAL "Release")
MESSAGE(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
IF(USE_OPENGL_ES2)
MESSAGE(STATUS "Renderer: OpenGL ES 2.0")
@@ -194,4 +203,5 @@ SET(framework_SOURCES ${framework_SOURCES}
# framework third party
${CMAKE_CURRENT_LIST_DIR}/thirdparty/apngloader.cpp
${CMAKE_CURRENT_LIST_DIR}/thirdparty/lbitlib-5.2.0-backport4.c
)

View File

@@ -99,6 +99,7 @@ void Application::init(const std::vector<std::string>& args, int appFlags)
g_ui.init();
g_window.init();
g_window.hide();
g_window.setOnResize(std::bind(&Application::resize, this, _1));
g_window.setOnInputEvent(std::bind(&Application::inputEvent, this, _1));
g_window.setOnClose(std::bind(&Application::close, this));
@@ -110,7 +111,7 @@ void Application::init(const std::vector<std::string>& args, int appFlags)
resize(g_window.getSize());
// display window when the application starts running
g_dispatcher.addEvent([]{ g_window.show(); });
//g_dispatcher.addEvent([]{ g_window.show(); });
}
if(m_appFlags & Fw::AppEnableModules)
@@ -169,6 +170,8 @@ void Application::run()
// run the first poll
poll();
g_lua.callGlobalField("g_app", "onRun");
while(!m_stopping) {
g_clock.updateTicks();

View File

@@ -30,7 +30,7 @@
namespace Fw
{
static const double pi = 3.14159265;
constexpr double pi = 3.14159265;
// NOTE: AABBGGRR order
enum GlobalColor : uint32 {

View File

@@ -56,6 +56,14 @@ bool Module::load()
logInfo("Loaded module '", m_name, "'");
g_modules.updateModuleLoadOrder(asModule());
for(const std::string& modName : m_loadLaterModules) {
ModulePtr dep = g_modules.getModule(modName);
if(!dep)
logError("Unable to find module '", modName, "' required by '", m_name, "'");
else if(!dep->isLoaded())
dep->load();
}
return true;
}
@@ -100,8 +108,8 @@ void Module::discover(const OTMLNodePtr& moduleNode)
m_website = moduleNode->valueAt("website", none);
m_version = moduleNode->valueAt("version", none);
m_autoLoad = moduleNode->valueAt<bool>("autoload", false);
m_unloadable = moduleNode->valueAt<bool>("unloadable", true);
m_autoLoadAntecedence = moduleNode->valueAt<int>("autoload-antecedence", 9999);
m_reloadable = moduleNode->valueAt<bool>("reloadable", false);
m_autoLoadPriority = moduleNode->valueAt<int>("autoload-priority", 9999);
if(OTMLNodePtr node = moduleNode->get("dependencies")) {
for(const OTMLNodePtr& tmp : node->children())
@@ -109,16 +117,21 @@ void Module::discover(const OTMLNodePtr& moduleNode)
}
// set onLoad callback
if(OTMLNodePtr node = moduleNode->get("onLoad")) {
if(OTMLNodePtr node = moduleNode->get("@onLoad")) {
g_lua.loadFunction(node->value(), "@" + node->source() + "[" + node->tag() + "]");
g_lua.useValue();
m_loadCallback = g_lua.polymorphicPop<SimpleCallback>();
}
// set onUnload callback
if(OTMLNodePtr node = moduleNode->get("onUnload")) {
if(OTMLNodePtr node = moduleNode->get("@onUnload")) {
g_lua.loadFunction(node->value(), "@" + node->source() + "[" + node->tag() + "]");
g_lua.useValue();
m_unloadCallback = g_lua.polymorphicPop<SimpleCallback>();
}
if(OTMLNodePtr node = moduleNode->get("load-later")) {
for(const OTMLNodePtr& tmp : node->children())
m_loadLaterModules.push_back(tmp->value());
}
}

View File

@@ -37,8 +37,10 @@ public:
void unload();
bool reload();
bool canUnload() { return m_loaded && m_unloadable && !isDependent(); }
bool canUnload() { return m_loaded && m_reloadable && !isDependent(); }
bool canReload() { return m_reloadable && !isDependent(); }
bool isLoaded() { return m_loaded; }
bool isReloadable() { return m_reloadable; }
bool isDependent();
bool hasDependency(const std::string& name);
@@ -48,7 +50,7 @@ public:
std::string getWebsite() { return m_website; }
std::string getVersion() { return m_version; }
bool isAutoLoad() { return m_autoLoad; }
int getAutoLoadAntecedence() { return m_autoLoadAntecedence; }
int getAutoLoadPriority() { return m_autoLoadPriority; }
ModulePtr asModule() { return std::static_pointer_cast<Module>(shared_from_this()); }
@@ -59,8 +61,8 @@ protected:
private:
Boolean<false> m_loaded;
Boolean<false> m_autoLoad;
Boolean<true> m_unloadable;
int m_autoLoadAntecedence;
Boolean<false> m_reloadable;
int m_autoLoadPriority;
std::string m_name;
std::string m_description;
std::string m_author;
@@ -69,6 +71,7 @@ private:
SimpleCallback m_loadCallback;
SimpleCallback m_unloadCallback;
std::list<std::string> m_dependencies;
std::list<std::string> m_loadLaterModules;
};
#endif

View File

@@ -40,17 +40,17 @@ void ModuleManager::discoverModules()
if(boost::ends_with(moduleFile, ".otmod")) {
ModulePtr module = discoverModule("/" + moduleDir + "/" + moduleFile);
if(module && module->isAutoLoad())
m_autoLoadModules.insert(make_pair(module->getAutoLoadAntecedence(), module));
m_autoLoadModules.insert(make_pair(module->getAutoLoadPriority(), module));
}
}
}
}
void ModuleManager::autoLoadModules(int maxAntecedence)
void ModuleManager::autoLoadModules(int maxPriority)
{
for(auto& pair : m_autoLoadModules) {
int priority = pair.first;
if(priority > maxAntecedence)
if(priority > maxPriority)
break;
ModulePtr module = pair.second;
if(!module->isLoaded() && !module->load())

View File

@@ -30,7 +30,7 @@ class ModuleManager
public:
void discoverModulesPath();
void discoverModules();
void autoLoadModules(int maxAntecedence);
void autoLoadModules(int maxPriority);
ModulePtr discoverModule(const std::string& moduleFile);
void ensureModuleLoaded(const std::string& moduleName);
void unloadModules();

View File

@@ -160,7 +160,6 @@ std::list<std::string> ResourceManager::listDirectoryFiles(const std::string& di
std::string ResourceManager::checkPath(const std::string& path)
{
/*
std::string fullPath;
if(boost::starts_with(path, "/"))
fullPath = path;
@@ -170,10 +169,9 @@ std::string ResourceManager::checkPath(const std::string& path)
fullPath += scriptPath + "/";
fullPath += path;
}
*/
if(!(boost::starts_with(path, "/")))
if(!(boost::starts_with(fullPath, "/")))
logTraceWarning("the following file path is not fully resolved: ", path);
return path;
return fullPath;
}
std::string ResourceManager::getBaseDir()

View File

@@ -23,6 +23,14 @@
#ifndef FRAMEWORK_GLOBAL_H
#define FRAMEWORK_GLOBAL_H
#if !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
#error "sorry, you need gcc 4.6 or greater to compile"
#endif
#if !defined(__GXX_EXPERIMENTAL_CXX0X__)
#error "sorry, you must enable C++0x to compile"
#endif
// common C/C++ headers
#include "pch.h"

View File

@@ -42,7 +42,7 @@ public:
int getMaxTextureSize();
const Size& getViewportSize() { return m_viewportSize; }
TexturePtr getEmptyTexture() { return m_emptyTexture; }
TexturePtr& getEmptyTexture() { return m_emptyTexture; }
private:
Size m_viewportSize;

View File

@@ -39,12 +39,12 @@ void Painter::init()
m_drawTexturedProgram = PainterShaderProgramPtr(new PainterShaderProgram);
m_drawTexturedProgram->addShaderFromSourceCode(Shader::Vertex, glslMainWithTexCoordsVertexShader + glslPositionOnlyVertexShader);
m_drawTexturedProgram->addShaderFromSourceCode(Shader::Fragment, glslMainFragmentShader + glslTextureSrcFragmentShader);
assert(m_drawTexturedProgram->link());
m_drawTexturedProgram->link();
m_drawSolidColorProgram = PainterShaderProgramPtr(new PainterShaderProgram);
m_drawSolidColorProgram->addShaderFromSourceCode(Shader::Vertex, glslMainVertexShader + glslPositionOnlyVertexShader);
m_drawSolidColorProgram->addShaderFromSourceCode(Shader::Fragment, glslMainFragmentShader + glslSolidColorFragmentShader);
assert(m_drawSolidColorProgram->link());
m_drawSolidColorProgram->link();
}
void Painter::terminate()

View File

@@ -92,7 +92,7 @@ void PainterShaderProgram::setTexture(const TexturePtr& texture)
void PainterShaderProgram::draw(const CoordsBuffer& coordsBuffer, DrawMode drawMode)
{
assert(bind());
bind();
setUniformValue(TIME_UNIFORM, (float)m_startTimer.timeElapsed());

View File

@@ -20,14 +20,14 @@
* THE SOFTWARE.
*/
static int VERTEX_COORDS_ATTR = 0;
static int TEXTURE_COORDS_ATTR = 1;
const static int VERTEX_COORDS_ATTR = 0;
const static int TEXTURE_COORDS_ATTR = 1;
static int PROJECTION_MATRIX_UNIFORM = 0;
static int TEXTURE_TRANSFORM_MATRIX_UNIFORM = 1;
static int COLOR_UNIFORM = 2;
static int OPACITY_UNIFORM = 3;
static int TEXTURE_UNIFORM = 4;
const static int PROJECTION_MATRIX_UNIFORM = 0;
const static int TEXTURE_TRANSFORM_MATRIX_UNIFORM = 1;
const static int COLOR_UNIFORM = 2;
const static int OPACITY_UNIFORM = 3;
const static int TEXTURE_UNIFORM = 4;
static const std::string glslMainVertexShader = "\n\
highp vec4 calculatePosition();\n\

View File

@@ -73,8 +73,6 @@ void Particle::update(double elapsedTime)
void Particle::updatePosition(double elapsedTime)
{
bool mustRedraw = false;
if(m_ignorePhysicsAfter < 0 || m_elapsedTime < m_ignorePhysicsAfter ) {
// update position
PointF delta = m_velocity * elapsedTime;
@@ -83,7 +81,6 @@ void Particle::updatePosition(double elapsedTime)
PointF position = m_position + delta;
if(m_position != position) {
mustRedraw = true;
m_position += delta;
}
@@ -96,11 +93,8 @@ void Particle::updatePosition(double elapsedTime)
void Particle::updateSize()
{
bool mustRedraw = false;
Size size = m_startSize + (m_finalSize - m_startSize) / m_duration * m_elapsedTime;
if(m_size != size) {
mustRedraw = true;
m_size = size;
}
@@ -109,15 +103,12 @@ void Particle::updateSize()
void Particle::updateColor()
{
bool mustRedraw = false;
if(m_elapsedTime < m_colorsStops[1]) {
Color color = Color(m_colors[0].r() + (m_colors[1].r() - m_colors[0].r()) / (m_colorsStops[1] - m_colorsStops[0]) * (m_elapsedTime - m_colorsStops[0]),
m_colors[0].g() + (m_colors[1].g() - m_colors[0].g()) / (m_colorsStops[1] - m_colorsStops[0]) * (m_elapsedTime - m_colorsStops[0]),
m_colors[0].b() + (m_colors[1].b() - m_colors[0].b()) / (m_colorsStops[1] - m_colorsStops[0]) * (m_elapsedTime - m_colorsStops[0]),
m_colors[0].a() + (m_colors[1].a() - m_colors[0].a()) / (m_colorsStops[1] - m_colorsStops[0]) * (m_elapsedTime - m_colorsStops[0]));
if(m_color != color) {
mustRedraw = true;
m_color = color;
}
}
@@ -128,7 +119,6 @@ void Particle::updateColor()
}
else {
if(m_color != m_colors[0]) {
mustRedraw = true;
m_color = m_colors[0];
}
}

View File

@@ -30,7 +30,6 @@ bool ParticleManager::load(const std::string& filename)
{
try {
OTMLDocumentPtr doc = OTMLDocument::parse(filename);
const OTMLNodePtr& node = doc->at("ParticleSystem");
for(const OTMLNodePtr& node : doc->children()) {
if(node->tag() == "ParticleSystem") {
ParticleSystemPtr particleSystem = ParticleSystemPtr(new ParticleSystem);

View File

@@ -386,15 +386,17 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<Module>("load", &Module::load);
g_lua.bindClassMemberFunction<Module>("unload", &Module::unload);
g_lua.bindClassMemberFunction<Module>("reload", &Module::reload);
g_lua.bindClassMemberFunction<Module>("canReload", &Module::canReload);
g_lua.bindClassMemberFunction<Module>("canUnload", &Module::canUnload);
g_lua.bindClassMemberFunction<Module>("isLoaded", &Module::isLoaded);
g_lua.bindClassMemberFunction<Module>("isReloadble", &Module::isReloadable);
g_lua.bindClassMemberFunction<Module>("getDescription", &Module::getDescription);
g_lua.bindClassMemberFunction<Module>("getName", &Module::getName);
g_lua.bindClassMemberFunction<Module>("getAuthor", &Module::getAuthor);
g_lua.bindClassMemberFunction<Module>("getWebsite", &Module::getWebsite);
g_lua.bindClassMemberFunction<Module>("getVersion", &Module::getVersion);
g_lua.bindClassMemberFunction<Module>("isAutoLoad", &Module::isAutoLoad);
g_lua.bindClassMemberFunction<Module>("getAutoLoadAntecedence", &Module::getAutoLoadAntecedence);
g_lua.bindClassMemberFunction<Module>("getAutoLoadPriority", &Module::getAutoLoadPriority);
// network manipulation via lua is disabled for a while
/*
@@ -468,14 +470,10 @@ void Application::registerLuaFunctions()
g_lua.bindClassStaticFunction("g_window", "hasFocus", std::bind(&PlatformWindow::hasFocus, &g_window));
// Logger
g_lua.registerClass<Logger>();
g_lua.bindClassStaticFunction<Logger>("log", std::bind(&Logger::log, &g_logger, _1, _2));
g_lua.bindClassStaticFunction<Logger>("fireOldMessages", std::bind(&Logger::fireOldMessages, &g_logger));
g_lua.bindClassStaticFunction<Logger>("setOnLog", std::bind(&Logger::setOnLog, &g_logger, _1));
// Lua
g_lua.registerStaticClass("g_lua");
g_lua.bindClassStaticFunction("g_lua", "runScript", std::bind(&LuaInterface::runScript, &g_lua, _1));
g_lua.registerStaticClass("g_logger");
g_lua.bindClassStaticFunction("g_logger", "log", std::bind(&Logger::log, &g_logger, _1, _2));
g_lua.bindClassStaticFunction("g_logger", "fireOldMessages", std::bind(&Logger::fireOldMessages, &g_logger));
g_lua.bindClassStaticFunction("g_logger", "setOnLog", std::bind(&Logger::setOnLog, &g_logger, _1));
// UI
g_lua.registerStaticClass("g_ui");

View File

@@ -26,6 +26,8 @@
#include <framework/core/resourcemanager.h>
#include <lua.hpp>
#include <framework/thirdparty/lbitlib-5.2.0-backport4.h>
LuaInterface g_lua;
LuaInterface::LuaInterface()
@@ -590,6 +592,9 @@ void LuaInterface::createLuaState()
// load lua standard libraries
luaL_openlibs(L);
// load bit32 lib for bitwise operations
luaopen_bit32(L);
// creates weak table
newTable();
@@ -812,7 +817,9 @@ void LuaInterface::getEnv(int index)
void LuaInterface::setEnv(int index)
{
assert(hasIndex(index));
assert(lua_setfenv(L, index) == 1);
int ret;
ret = lua_setfenv(L, index);
assert(ret == 1);
}
void LuaInterface::getTable(int index)

View File

@@ -191,7 +191,8 @@ bool luavalue_cast(int index, std::function<void(Args...)>& func) {
try {
if(g_lua.isFunction()) {
g_lua.polymorphicPush(args...);
assert(g_lua.safeCall(sizeof...(Args)) == 0);
int rets = g_lua.safeCall(sizeof...(Args));
g_lua.pop(rets);
} else {
throw LuaException("attempt to call an expired lua function from C++,"
"did you forget to hold a reference for that function?", 0);

View File

@@ -80,8 +80,8 @@ public:
bool isKeyPressed(Fw::Key keyCode) { return m_keysState[keyCode]; }
bool isVisible() { return m_visible; }
bool isMaximized() { return m_maximized; }
bool isFullscreen() { return m_fullscreen; }
virtual bool isMaximized() = 0;
bool hasFocus() { return m_focused; }
void setOnClose(const SimpleCallback& onClose) { m_onClose = onClose; }
@@ -112,6 +112,7 @@ protected:
Boolean<false> m_visible;
Boolean<false> m_focused;
Boolean<false> m_fullscreen;
Boolean<false> m_maximized;
SimpleCallback m_onClose;
OnResizeCallback m_onResize;

View File

@@ -20,14 +20,22 @@
* THE SOFTWARE.
*/
#define __USE_GNU
#include "crashhandler.h"
#include <framework/global.h>
#include <execinfo.h>
#include <framework/application.h>
#include <execinfo.h>
#include <ucontext.h>
#define MAX_BACKTRACE_DEPTH 128
#define DEMANGLE_BACKTRACE_SYMBOLS
#ifndef REG_RIP
#error fuck
#endif
void crashHandler(int signum, siginfo_t* info, void* secret)
{
logError("Application crashed");
@@ -41,20 +49,8 @@ void crashHandler(int signum, siginfo_t* info, void* secret)
std::stringstream ss;
ss.flags(std::ios::hex | std::ios::showbase);
#ifdef REG_EIP
ss <<
ss << " at eip = " << context.uc_mcontext.gregs[REG_EIP] << std::endl;
ss << " eax = " << context.uc_mcontext.gregs[REG_EAX] << std::endl;
ss << " ebx = " << context.uc_mcontext.gregs[REG_EBX] << std::endl;
ss << " ecx = " << context.uc_mcontext.gregs[REG_ECX] << std::endl;
ss << " edx = " << context.uc_mcontext.gregs[REG_EDX] << std::endl;
ss << " esi = " << context.uc_mcontext.gregs[REG_ESI] << std::endl;
ss << " edi = " << context.uc_mcontext.gregs[REG_EDI] << std::endl;
ss << " ebp = " << context.uc_mcontext.gregs[REG_EBP] << std::endl;
ss << " esp = " << context.uc_mcontext.gregs[REG_ESP] << std::endl;
ss << " efl = " << context.uc_mcontext.gregs[REG_EFL] << std::endl;
ss << std::endl;
#elifdef REG_RIP
#if __WORDSIZE == 64
ss << " at rip = " << context.uc_mcontext.gregs[REG_RIP] << std::endl;
ss << " rax = " << context.uc_mcontext.gregs[REG_RAX] << std::endl;
ss << " rbx = " << context.uc_mcontext.gregs[REG_RBX] << std::endl;
@@ -66,7 +62,20 @@ void crashHandler(int signum, siginfo_t* info, void* secret)
ss << " rsp = " << context.uc_mcontext.gregs[REG_RSP] << std::endl;
ss << " efl = " << context.uc_mcontext.gregs[REG_EFL] << std::endl;
ss << std::endl;
#else
ss << " at eip = " << context.uc_mcontext.gregs[REG_EIP] << std::endl;
ss << " eax = " << context.uc_mcontext.gregs[REG_EAX] << std::endl;
ss << " ebx = " << context.uc_mcontext.gregs[REG_EBX] << std::endl;
ss << " ecx = " << context.uc_mcontext.gregs[REG_ECX] << std::endl;
ss << " edx = " << context.uc_mcontext.gregs[REG_EDX] << std::endl;
ss << " esi = " << context.uc_mcontext.gregs[REG_ESI] << std::endl;
ss << " edi = " << context.uc_mcontext.gregs[REG_EDI] << std::endl;
ss << " ebp = " << context.uc_mcontext.gregs[REG_EBP] << std::endl;
ss << " esp = " << context.uc_mcontext.gregs[REG_ESP] << std::endl;
ss << " efl = " << context.uc_mcontext.gregs[REG_EFL] << std::endl;
ss << std::endl;
#endif
ss.flags(std::ios::dec);
ss << " backtrace:" << std::endl;

View File

@@ -36,7 +36,6 @@ WIN32Window::WIN32Window()
m_deviceContext = 0;
m_glContext = 0;
m_cursor = 0;
m_maximized = false;
m_minimumSize = Size(600,480);
m_keyMap[VK_ESCAPE] = Fw::KeyEscape;
@@ -675,7 +674,9 @@ void WIN32Window::setFullscreen(bool fullscreen)
return;
DWORD dwStyle = GetWindowLong(m_window, GWL_STYLE);
static WINDOWPLACEMENT wpPrev = { sizeof(wpPrev) };
static WINDOWPLACEMENT wpPrev;
wpPrev.length = sizeof(wpPrev);
if(fullscreen) {
GetWindowPlacement(m_window, &wpPrev);
SetWindowLong(m_window, GWL_STYLE, dwStyle & ~WS_OVERLAPPEDWINDOW);

View File

@@ -75,8 +75,6 @@ public:
std::string getClipboardText();
std::string getPlatformType();
bool isMaximized() { return m_maximized; }
private:
HWND m_window;
HINSTANCE m_instance;
@@ -84,7 +82,6 @@ private:
HGLRC m_glContext;
HCURSOR m_cursor;
HCURSOR m_defaultCursor;
bool m_maximized;
Size m_minimumSize;
};

View File

@@ -261,7 +261,8 @@ void X11Window::internalCreateWindow()
Visual *vis;
int depth;
unsigned int attrsMask = CWEventMask;
XSetWindowAttributes attrs = {0};
XSetWindowAttributes attrs;
memset(&attrs, 0, sizeof(attrs));
attrs.event_mask = KeyPressMask | KeyReleaseMask |
ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
@@ -290,6 +291,8 @@ void X11Window::internalCreateWindow()
InputOutput,
vis,
attrsMask, &attrs);
m_visible = true;
if(!m_window)
logFatal("Unable to create X11 window!");
@@ -474,12 +477,9 @@ bool X11Window::isExtensionSupported(const char *ext)
void X11Window::move(const Point& pos)
{
bool wasVisible = isVisible();
if(!wasVisible)
show();
XMoveWindow(m_display, m_window, pos.x, pos.y);
if(!wasVisible)
hide();
m_position = pos;
if(m_visible)
XMoveWindow(m_display, m_window, m_position.x, m_position.y);
}
void X11Window::resize(const Size& size)
@@ -489,33 +489,45 @@ void X11Window::resize(const Size& size)
void X11Window::show()
{
m_visible = true;
XMapWindow(m_display, m_window);
XMoveWindow(m_display, m_window, m_position.x, m_position.y);
XFlush(m_display);
if(m_maximized)
maximize();
if(m_fullscreen)
setFullscreen(true);
}
void X11Window::hide()
{
m_visible = false;
XUnmapWindow(m_display, m_window);
XFlush(m_display);
}
void X11Window::maximize()
{
Atom wmState = XInternAtom(m_display, "_NET_WM_STATE", False);
Atom wmStateMaximizedVert = XInternAtom(m_display, "_NET_WM_STATE_MAXIMIZED_VERT", False);
Atom wmStateMaximizedHorz = XInternAtom(m_display, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
if(m_visible) {
Atom wmState = XInternAtom(m_display, "_NET_WM_STATE", False);
Atom wmStateMaximizedVert = XInternAtom(m_display, "_NET_WM_STATE_MAXIMIZED_VERT", False);
Atom wmStateMaximizedHorz = XInternAtom(m_display, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
XEvent e = {0};
e.xany.type = ClientMessage;
e.xclient.send_event = True;
e.xclient.message_type = wmState;
e.xclient.format = 32;
e.xclient.window = m_window;
e.xclient.data.l[0] = 1;
e.xclient.data.l[1] = wmStateMaximizedVert;
e.xclient.data.l[2] = wmStateMaximizedHorz;
e.xclient.data.l[3] = 0;
XEvent e = {0};
e.xany.type = ClientMessage;
e.xclient.send_event = True;
e.xclient.message_type = wmState;
e.xclient.format = 32;
e.xclient.window = m_window;
e.xclient.data.l[0] = 1;
e.xclient.data.l[1] = wmStateMaximizedVert;
e.xclient.data.l[2] = wmStateMaximizedHorz;
e.xclient.data.l[3] = 0;
XSendEvent(m_display, m_rootWindow, 0, SubstructureNotifyMask | SubstructureRedirectMask, &e);
XFlush(m_display);
XSendEvent(m_display, m_rootWindow, 0, SubstructureNotifyMask | SubstructureRedirectMask, &e);
XFlush(m_display);
}
m_maximized = true;
}
void X11Window::poll()
@@ -543,7 +555,7 @@ void X11Window::poll()
// lookup keysym and translate it
KeySym keysym;
char buf[32];
int len = XLookupString(&xkey, buf, sizeof(buf), &keysym, 0);
XLookupString(&xkey, buf, sizeof(buf), &keysym, 0);
Fw::Key keyCode = Fw::KeyUnknown;
if(m_keyMap.find(keysym) != m_keyMap.end())
@@ -580,8 +592,41 @@ void X11Window::poll()
needsResizeUpdate = true;
}
// checks if the window is maximized
if(m_visible) {
m_maximized = false;
Atom wmState = XInternAtom(m_display, "_NET_WM_STATE", False);
Atom wmStateMaximizedVert = XInternAtom(m_display, "_NET_WM_STATE_MAXIMIZED_VERT", False);
Atom wmStateMaximizedHorz = XInternAtom(m_display, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
Atom actualType;
ulong i, numItems, bytesAfter;
uchar *propertyValue = NULL;
int actualFormat;
if(XGetWindowProperty(m_display, m_window, wmState,
0, 1024, False, XA_ATOM, &actualType,
&actualFormat, &numItems, &bytesAfter,
&propertyValue) == Success) {
Atom *atoms = (Atom*)propertyValue;
int maximizedMask = 0;
for(i=0; i<numItems; ++i) {
if(atoms[i] == wmStateMaximizedVert)
maximizedMask |= 1;
else if(atoms[i] == wmStateMaximizedHorz)
maximizedMask |= 2;
}
if(maximizedMask == 3)
m_maximized = true;
XFree(propertyValue);
}
}
// updates window pos
m_position = newPos;
if(m_visible)
m_position = newPos;
updateUnmaximizedCoords();
break;
}
@@ -754,7 +799,8 @@ void X11Window::hideMouse()
char bm[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
Pixmap pix = XCreateBitmapFromData(m_display, m_window, bm, 8, 8);
XColor black = {0};
XColor black;
memset(&black, 0, sizeof(black));
black.flags = DoRed | DoGreen | DoBlue;
m_cursor = XCreatePixmapCursor(m_display, pix, pix, &black, &black, 0, 0);
XFreePixmap(m_display, pix);
@@ -843,7 +889,8 @@ void X11Window::setTitle(const std::string& title)
void X11Window::setMinimumSize(const Size& minimumSize)
{
XSizeHints sizeHints = {0};
XSizeHints sizeHints;
memset(&sizeHints, 0, sizeof(sizeHints));
sizeHints.flags = PMinSize;
sizeHints.min_width = minimumSize.width();
sizeHints.min_height= minimumSize.height();
@@ -852,7 +899,7 @@ void X11Window::setMinimumSize(const Size& minimumSize)
void X11Window::setFullscreen(bool fullscreen)
{
if(m_fullscreen != fullscreen) {
if(m_visible) {
Atom wmState = XInternAtom(m_display, "_NET_WM_STATE", False);
Atom wmStateFullscreen = XInternAtom(m_display, "_NET_WM_STATE_FULLSCREEN", False);
@@ -869,9 +916,8 @@ void X11Window::setFullscreen(bool fullscreen)
XSendEvent(m_display, m_rootWindow, False, SubstructureRedirectMask | SubstructureNotifyMask, &xev);
XFlush(m_display);
m_fullscreen = fullscreen;
}
m_fullscreen = fullscreen;
}
void X11Window::setVerticalSync(bool enable)
@@ -1001,40 +1047,3 @@ std::string X11Window::getPlatformType()
return "X11-EGL";
#endif
}
bool X11Window::isMaximized()
{
if(!m_display || !m_window)
return false;
Atom wmState = XInternAtom(m_display, "_NET_WM_STATE", False);
Atom wmStateMaximizedVert = XInternAtom(m_display, "_NET_WM_STATE_MAXIMIZED_VERT", False);
Atom wmStateMaximizedHorz = XInternAtom(m_display, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
Atom actualType;
ulong i, numItems, bytesAfter;
uchar *propertyValue = NULL;
int actualFormat;
bool maximized = false;
if(XGetWindowProperty(m_display, m_window, wmState,
0, 1024, False, XA_ATOM, &actualType,
&actualFormat, &numItems, &bytesAfter,
&propertyValue) == Success) {
Atom *atoms = (Atom*)propertyValue;
int maximizedMask = 0;
for(i=0; i<numItems; ++i) {
if(atoms[i] == wmStateMaximizedVert)
maximizedMask |= 1;
else if(atoms[i] == wmStateMaximizedHorz)
maximizedMask |= 2;
}
if(maximizedMask == 3)
maximized = true;
XFree(propertyValue);
}
return maximized;
}

View File

@@ -0,0 +1,372 @@
/*
* This is the bit32 library from lua 5.2.0, backported to
* lua 5.1.4.
*
* version 5.2.0-backport4
*
* This backport was assembled by Sean Bolton (sean at smbolton
* dot com) almost entirely from the above mentioned Lua distributions,
* which are:
*
* Copyright (C) 1994-2011 Lua.org, PUC-Rio. All rights reserved.
*
* 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.
*/
#define LUA_LIB
#include <lua.h>
#include <lauxlib.h>
/* ----- adapted from lua-5.2.0 luaconf.h: ----- */
/*
@@ LUA_UNSIGNED is the integral type used by lua_pushunsigned/lua_tounsigned.
** It must have at least 32 bits.
*/
#define LUA_UNSIGNED unsigned LUAI_INT32
#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) /* { */
/* On a Microsoft compiler on a Pentium, use assembler to avoid clashes
with a DirectX idiosyncrasy */
#if defined(LUA_WIN) && defined(_MSC_VER) && defined(_M_IX86) /* { */
#define MS_ASMTRICK
#else /* }{ */
/* the next definition uses a trick that should work on any machine
using IEEE754 with a 32-bit integer type */
#define LUA_IEEE754TRICK
/*
@@ LUA_IEEEENDIAN is the endianness of doubles in your machine
** (0 for little endian, 1 for big endian); if not defined, Lua will
** check it dynamically.
*/
/* check for known architectures */
#if defined(__i386__) || defined(__i386) || defined(__X86__) || \
defined (__x86_64)
#define LUA_IEEEENDIAN 0
#elif defined(__POWERPC__) || defined(__ppc__)
#define LUA_IEEEENDIAN 1
#endif
#endif /* } */
#endif /* } */
/* ----- from lua-5.2.0 lua.h: ----- */
/* unsigned integer type */
typedef LUA_UNSIGNED lua_Unsigned;
/* ----- adapted from lua-5.2.0 llimits.h: ----- */
/* lua_number2unsigned is a macro to convert a lua_Number to a lua_Unsigned.
** lua_unsigned2number is a macro to convert a lua_Unsigned to a lua_Number.
*/
#if defined(MS_ASMTRICK) /* { */
/* trick with Microsoft assembler for X86 */
#define lua_number2unsigned(i,n) \
{__int64 l; __asm {__asm fld n __asm fistp l} i = (unsigned int)l;}
#elif defined(LUA_IEEE754TRICK) /* }{ */
/* the next trick should work on any machine using IEEE754 with
a 32-bit integer type */
union luai_Cast2 { double l_d; LUAI_INT32 l_p[2]; };
#if !defined(LUA_IEEEENDIAN) /* { */
#define LUAI_EXTRAIEEE \
static const union luai_Cast2 ieeeendian = {-(33.0 + 6755399441055744.0)};
#define LUA_IEEEENDIAN (ieeeendian.l_p[1] == 33)
#else
#define LUAI_EXTRAIEEE /* empty */
#endif /* } */
#define lua_number2int32(i,n,t) \
{ LUAI_EXTRAIEEE \
volatile union luai_Cast2 u; u.l_d = (n) + 6755399441055744.0; \
(i) = (t)u.l_p[LUA_IEEEENDIAN]; }
#define lua_number2unsigned(i,n) lua_number2int32(i, n, lua_Unsigned)
#endif /* } */
#if !defined(lua_number2unsigned) /* { */
/* the following definition assures proper modulo behavior */
#if defined(LUA_NUMBER_DOUBLE)
#include <math.h>
#define SUPUNSIGNED ((lua_Number)(~(lua_Unsigned)0) + 1)
#define lua_number2unsigned(i,n) \
((i)=(lua_Unsigned)((n) - floor((n)/SUPUNSIGNED)*SUPUNSIGNED))
#else
#define lua_number2unsigned(i,n) ((i)=(lua_Unsigned)(n))
#endif
#endif /* } */
/* on several machines, coercion from unsigned to double is slow,
so it may be worth to avoid */
#define lua_unsigned2number(u) \
(((u) <= (lua_Unsigned)INT_MAX) ? (lua_Number)(int)(u) : (lua_Number)(u))
/* ----- adapted from lua-5.2.0 lapi.c: ----- */
static void lua_pushunsigned (lua_State *L, lua_Unsigned u) {
lua_Number n;
n = lua_unsigned2number(u);
lua_pushnumber(L, n);
}
/* ----- adapted from lua-5.2.0-work3 lbitlib.c getuintarg(): ----- */
static lua_Unsigned luaL_checkunsigned (lua_State *L, int arg) {
lua_Unsigned r;
lua_Number x = lua_tonumber(L, arg);
if (x == 0) luaL_checktype(L, arg, LUA_TNUMBER);
lua_number2unsigned(r, x);
return r;
}
/* ----- Lua 5.2 luaL_newlib() compatibility: ----- */
#define LUAMOD_API LUALIB_API
#define LUA_BITLIBNAME "bit32"
#define luaL_newlib(x, y) luaL_register(x, LUA_BITLIBNAME, y)
/* ----- avoid a 'symbol redefined' warning below ----- */
#undef LUA_LIB
/* ----- here follows the unmodified lbitlib.c from Lua 5.2.0 ----- */
/*
** $Id: lbitlib.c,v 1.16 2011/06/20 16:35:23 roberto Exp $
** Standard library for bitwise operations
** See Copyright Notice in lua.h
*/
#define lbitlib_c
#define LUA_LIB
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
/* number of bits to consider in a number */
#if !defined(LUA_NBITS)
#define LUA_NBITS 32
#endif
#define ALLONES (~(((~(lua_Unsigned)0) << (LUA_NBITS - 1)) << 1))
/* macro to trim extra bits */
#define trim(x) ((x) & ALLONES)
/* builds a number with 'n' ones (1 <= n <= LUA_NBITS) */
#define mask(n) (~((ALLONES << 1) << ((n) - 1)))
typedef lua_Unsigned b_uint;
static b_uint andaux (lua_State *L) {
int i, n = lua_gettop(L);
b_uint r = ~(b_uint)0;
for (i = 1; i <= n; i++)
r &= luaL_checkunsigned(L, i);
return trim(r);
}
static int b_and (lua_State *L) {
b_uint r = andaux(L);
lua_pushunsigned(L, r);
return 1;
}
static int b_test (lua_State *L) {
b_uint r = andaux(L);
lua_pushboolean(L, r != 0);
return 1;
}
static int b_or (lua_State *L) {
int i, n = lua_gettop(L);
b_uint r = 0;
for (i = 1; i <= n; i++)
r |= luaL_checkunsigned(L, i);
lua_pushunsigned(L, trim(r));
return 1;
}
static int b_xor (lua_State *L) {
int i, n = lua_gettop(L);
b_uint r = 0;
for (i = 1; i <= n; i++)
r ^= luaL_checkunsigned(L, i);
lua_pushunsigned(L, trim(r));
return 1;
}
static int b_not (lua_State *L) {
b_uint r = ~luaL_checkunsigned(L, 1);
lua_pushunsigned(L, trim(r));
return 1;
}
static int b_shift (lua_State *L, b_uint r, int i) {
if (i < 0) { /* shift right? */
i = -i;
r = trim(r);
if (i >= LUA_NBITS) r = 0;
else r >>= i;
}
else { /* shift left */
if (i >= LUA_NBITS) r = 0;
else r <<= i;
r = trim(r);
}
lua_pushunsigned(L, r);
return 1;
}
static int b_lshift (lua_State *L) {
return b_shift(L, luaL_checkunsigned(L, 1), luaL_checkint(L, 2));
}
static int b_rshift (lua_State *L) {
return b_shift(L, luaL_checkunsigned(L, 1), -luaL_checkint(L, 2));
}
static int b_arshift (lua_State *L) {
b_uint r = luaL_checkunsigned(L, 1);
int i = luaL_checkint(L, 2);
if (i < 0 || !(r & ((b_uint)1 << (LUA_NBITS - 1))))
return b_shift(L, r, -i);
else { /* arithmetic shift for 'negative' number */
if (i >= LUA_NBITS) r = ALLONES;
else
r = trim((r >> i) | ~(~(b_uint)0 >> i)); /* add signal bit */
lua_pushunsigned(L, r);
return 1;
}
}
static int b_rot (lua_State *L, int i) {
b_uint r = luaL_checkunsigned(L, 1);
i &= (LUA_NBITS - 1); /* i = i % NBITS */
r = trim(r);
r = (r << i) | (r >> (LUA_NBITS - i));
lua_pushunsigned(L, trim(r));
return 1;
}
static int b_lrot (lua_State *L) {
return b_rot(L, luaL_checkint(L, 2));
}
static int b_rrot (lua_State *L) {
return b_rot(L, -luaL_checkint(L, 2));
}
/*
** get field and width arguments for field-manipulation functions,
** checking whether they are valid
*/
static int fieldargs (lua_State *L, int farg, int *width) {
int f = luaL_checkint(L, farg);
int w = luaL_optint(L, farg + 1, 1);
luaL_argcheck(L, 0 <= f, farg, "field cannot be negative");
luaL_argcheck(L, 0 < w, farg + 1, "width must be positive");
if (f + w > LUA_NBITS)
luaL_error(L, "trying to access non-existent bits");
*width = w;
return f;
}
static int b_extract (lua_State *L) {
int w;
b_uint r = luaL_checkunsigned(L, 1);
int f = fieldargs(L, 2, &w);
r = (r >> f) & mask(w);
lua_pushunsigned(L, r);
return 1;
}
static int b_replace (lua_State *L) {
int w;
b_uint r = luaL_checkunsigned(L, 1);
b_uint v = luaL_checkunsigned(L, 2);
int f = fieldargs(L, 3, &w);
int m = mask(w);
v &= m; /* erase bits outside given width */
r = (r & ~(m << f)) | (v << f);
lua_pushunsigned(L, r);
return 1;
}
static const luaL_Reg bitlib[] = {
{"arshift", b_arshift},
{"band", b_and},
{"bnot", b_not},
{"bor", b_or},
{"bxor", b_xor},
{"btest", b_test},
{"extract", b_extract},
{"lrotate", b_lrot},
{"lshift", b_lshift},
{"replace", b_replace},
{"rrotate", b_rrot},
{"rshift", b_rshift},
{NULL, NULL}
};
int luaopen_bit32 (lua_State *L) {
luaL_newlib(L, bitlib);
return 1;
}

View File

@@ -0,0 +1,32 @@
/*
* Copyright (c) 2010-2012 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 LBITLIB_520_BACKPORT4_H
#define LBITLIB_520_BACKPORT4_H
struct lua_State;
extern "C" {
int luaopen_bit32 (lua_State *L);
};
#endif

View File

@@ -113,6 +113,8 @@ void UIManager::inputEvent(const InputEvent& event)
case Fw::MouseWheelInputEvent:
m_mouseReceiver->propagateOnMouseWheel(event.mousePos, event.wheelDirection);
break;
default:
break;
};
m_isOnInputEvent = false;
}

View File

@@ -109,6 +109,11 @@ void UIWidget::addChild(const UIWidgetPtr& child)
return;
}
if(child->isDestroyed()) {
logWarning("attemp to add a destroyed child into a UIWidget");
return;
}
if(hasChild(child)) {
logWarning("attempt to add a child again into a UIWidget");
return;
@@ -145,7 +150,10 @@ void UIWidget::insertChild(int index, const UIWidgetPtr& child)
index = index <= 0 ? (m_children.size() + index) : index-1;
assert(index >= 0 && (uint)index <= m_children.size());
if(!(index >= 0 && (uint)index <= m_children.size())) {
logTraceError("attemp to insert a child in an invalid index");
return;
}
// retrieve child by index
auto it = m_children.begin() + index;
@@ -300,7 +308,11 @@ void UIWidget::lowerChild(UIWidgetPtr child)
// remove and push child again
auto it = std::find(m_children.begin(), m_children.end(), child);
assert(it != m_children.end());
if(it == m_children.end()) {
logTraceError("cannot find child");
return;
}
m_children.erase(it);
m_children.push_front(child);
updateChildrenIndexStates();
@@ -316,7 +328,10 @@ void UIWidget::raiseChild(UIWidgetPtr child)
// remove and push child again
auto it = std::find(m_children.begin(), m_children.end(), child);
assert(it != m_children.end());
if(it == m_children.end()) {
logTraceError("cannot find child");
return;
}
m_children.erase(it);
m_children.push_back(child);
updateChildrenIndexStates();
@@ -332,7 +347,10 @@ void UIWidget::moveChildToIndex(const UIWidgetPtr& child, int index)
// remove and push child again
auto it = std::find(m_children.begin(), m_children.end(), child);
assert(it != m_children.end());
if(it == m_children.end()) {
logTraceError("cannot find child");
return;
}
m_children.erase(it);
m_children.insert(m_children.begin() + index - 1, child);
updateChildrenIndexStates();
@@ -346,7 +364,10 @@ void UIWidget::lockChild(const UIWidgetPtr& child)
if(!child)
return;
assert(hasChild(child));
if(!hasChild(child)) {
logTraceError("cannot find child");
return;
}
// prevent double locks
if(isChildLocked(child))
@@ -365,8 +386,6 @@ void UIWidget::lockChild(const UIWidgetPtr& child)
// lock child focus
if(child->isFocusable())
focusChild(child, Fw::ActiveFocusReason);
raiseChild(child);
}
void UIWidget::unlockChild(const UIWidgetPtr& child)
@@ -377,7 +396,10 @@ void UIWidget::unlockChild(const UIWidgetPtr& child)
if(!child)
return;
assert(hasChild(child));
if(!hasChild(child)) {
logTraceError("cannot find child");
return;
}
auto it = std::find(m_lockedChildren.begin(), m_lockedChildren.end(), child);
if(it == m_lockedChildren.end())
@@ -408,8 +430,6 @@ void UIWidget::unlockChild(const UIWidgetPtr& child)
if(lockedChild) {
if(lockedChild->isFocusable())
focusChild(lockedChild, Fw::ActiveFocusReason);
raiseChild(lockedChild);
}
}

View File

@@ -28,10 +28,8 @@
void UIWidget::parseImageStyle(const OTMLNodePtr& styleNode)
{
for(const OTMLNodePtr& node : styleNode->children()) {
if(node->tag() == "image")
setImageSource(node->value());
else if(node->tag() == "image-source")
setImageSource(node->value());
if(node->tag() == "image-source")
setImageSource(Fw::resolvePath(node->value(), styleNode->source()));
else if(node->tag() == "image-offset-x")
setImageOffsetX(node->value<int>());
else if(node->tag() == "image-offset-y")

View File

@@ -45,7 +45,6 @@ SET(otclient_SOURCES ${otclient_SOURCES}
${CMAKE_CURRENT_LIST_DIR}/ui/uiitem.cpp
${CMAKE_CURRENT_LIST_DIR}/ui/uicreature.cpp
${CMAKE_CURRENT_LIST_DIR}/ui/uimap.cpp
${CMAKE_CURRENT_LIST_DIR}/ui/uigame.cpp
# otclient net
${CMAKE_CURRENT_LIST_DIR}/net/protocollogin.cpp

View File

@@ -27,9 +27,9 @@
namespace Otc
{
static const char* AppName = "OTClient";
static const char* AppCompactName = "otclient";
static const char* AppVersion = "0.4.0";
constexpr const char* AppName = "OTClient";
constexpr const char* AppCompactName = "otclient";
constexpr const char* AppVersion = "0.4.0";
enum {
TILE_PIXELS = 32,

View File

@@ -90,7 +90,7 @@ void Creature::internalDrawOutfit(const Point& dest, float scaleFactor, bool ani
outfitProgram = PainterShaderProgramPtr(new PainterShaderProgram);
outfitProgram->addShaderFromSourceCode(Shader::Vertex, glslMainWithTexCoordsVertexShader + glslPositionOnlyVertexShader);
outfitProgram->addShaderFromSourceFile(Shader::Fragment, "/game_shaders/outfit.frag");
assert(outfitProgram->link());
outfitProgram->link();
outfitProgram->bindUniformLocation(HEAD_COLOR_UNIFORM, "headColor");
outfitProgram->bindUniformLocation(BODY_COLOR_UNIFORM, "bodyColor");
outfitProgram->bindUniformLocation(LEGS_COLOR_UNIFORM, "legsColor");

View File

@@ -407,6 +407,8 @@ void Game::forceWalk(Otc::Direction direction)
case Otc::NorthWest:
m_protocolGame->sendWalkNorthWest();
break;
default:
break;
}
}
@@ -428,6 +430,8 @@ void Game::turn(Otc::Direction direction)
case Otc::West:
m_protocolGame->sendTurnWest();
break;
default:
break;
}
}

View File

@@ -166,7 +166,7 @@ void Item::draw(const Point& dest, float scaleFactor, bool animate)
itemProgram = PainterShaderProgramPtr(new PainterShaderProgram);
itemProgram->addShaderFromSourceCode(Shader::Vertex, glslMainWithTexCoordsVertexShader + glslPositionOnlyVertexShader);
itemProgram->addShaderFromSourceFile(Shader::Fragment, "/game_shaders/item.frag");
assert(itemProgram->link());
itemProgram->link();
//itemProgram->bindUniformLocation(ITEM_ID_UNIFORM, "itemId");
}
g_painter.setCustomProgram(itemProgram);

View File

@@ -84,8 +84,6 @@ bool LocalPlayer::canWalk(Otc::Direction direction)
void LocalPlayer::walk(const Position& oldPos, const Position& newPos)
{
Otc::Direction direction = oldPos.getDirectionFromPosition(newPos);
// a prewalk was going on
if(m_preWalking) {
// switch to normal walking

View File

@@ -47,7 +47,7 @@ MapView::MapView()
m_shaderProgram = PainterShaderProgramPtr(new PainterShaderProgram);
m_shaderProgram->addShaderFromSourceCode(Shader::Vertex, glslMainWithTexCoordsVertexShader + glslPositionOnlyVertexShader);
m_shaderProgram->addShaderFromSourceFile(Shader::Fragment, "/game_shaders/map.frag");
assert(m_shaderProgram->link());
m_shaderProgram->link();
}
void MapView::draw(const Rect& rect)
@@ -117,7 +117,7 @@ void MapView::draw(const Rect& rect)
float horizontalStretchFactor = rect.width() / (float)(m_visibleDimension.width() * m_tileSize);
float verticalStretchFactor = rect.height() / (float)(m_visibleDimension.height() * m_tileSize);
Size tileStretchedSize = Size(m_tileSize * horizontalStretchFactor, m_tileSize * verticalStretchFactor);
//Size tileStretchedSize = Size(m_tileSize * horizontalStretchFactor, m_tileSize * verticalStretchFactor);
// avoid drawing texts on map in far zoom outs
if(m_viewRange == NEAR_VIEW) {

View File

@@ -57,7 +57,7 @@ void SpriteManager::unload()
void SpriteManager::preloadSprites()
{
// preload every 100 sprites, periodically
// preload every 50 sprites, periodically
const int burst = 50;
const int interval = 10;
auto preload = [this](int start) {
@@ -138,7 +138,7 @@ TexturePtr SpriteManager::loadSpriteTexture(int id)
return spriteTex;
}
TexturePtr SpriteManager::getSpriteTexture(int id)
TexturePtr& SpriteManager::getSpriteTexture(int id)
{
if(id == 0)
return g_graphics.getEmptyTexture();

View File

@@ -38,7 +38,7 @@ public:
uint32 getSignature() { return m_signature; }
int getSpritesCount() { return m_spritesCount; }
TexturePtr getSpriteTexture(int id);
TexturePtr& getSpriteTexture(int id);
bool isLoaded() { return m_loaded; }
private:

View File

@@ -41,7 +41,6 @@
#include <otclient/ui/uiitem.h>
#include <otclient/ui/uicreature.h>
#include <otclient/ui/uimap.h>
#include <otclient/ui/uigame.h>
#include <otclient/core/outfit.h>
@@ -309,8 +308,4 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIMap>("getTile", &UIMap::getTile);
g_lua.bindClassMemberFunction<UIMap>("zoomIn", &UIMap::zoomIn);
g_lua.bindClassMemberFunction<UIMap>("zoomOut", &UIMap::zoomOut);
g_lua.registerClass<UIGame, UIWidget>();
g_lua.bindClassStaticFunction<UIGame>("create", []{ return UIGamePtr(new UIGame); } );
}

View File

@@ -31,26 +31,26 @@
namespace Proto {
#ifdef CIPSOFT_RSA
static const char* RSA = "1321277432058722840622950990822933849527763264961655079678763618"
"4334395343554449668205332383339435179772895415509701210392836078"
"6959821132214473291575712138800495033169914814069637740318278150"
"2907336840325241747827401343576296990629870233111328210165697754"
"88792221429527047321331896351555606801473202394175817";
constexpr const char* RSA = "1321277432058722840622950990822933849527763264961655079678763618"
"4334395343554449668205332383339435179772895415509701210392836078"
"6959821132214473291575712138800495033169914814069637740318278150"
"2907336840325241747827401343576296990629870233111328210165697754"
"88792221429527047321331896351555606801473202394175817";
#else
static const char* RSA = "1091201329673994292788609605089955415282375029027981291234687579"
"3726629149257644633073969600111060390723088861007265581882535850"
"3429057592827629436413108566029093628212635953836686562675849720"
"6207862794310902180176810615217550567108238764764442605581471797"
"07119674283982419152118103759076030616683978566631413";
constexpr const char* RSA = "1091201329673994292788609605089955415282375029027981291234687579"
"3726629149257644633073969600111060390723088861007265581882535850"
"3429057592827629436413108566029093628212635953836686562675849720"
"6207862794310902180176810615217550567108238764764442605581471797"
"07119674283982419152118103759076030616683978566631413";
#endif
static const int ClientVersion = PROTOCOL;
static const int PicSignature = 0x4E119CBF;
constexpr int ClientVersion = PROTOCOL;
constexpr int PicSignature = 0x4E119CBF;
#if PROTOCOL==860
const int NumViolationReasons = 20;
constexpr int NumViolationReasons = 20;
#elif PROTOCOL==861 || PROTOCOL==862
const int NumViolationReasons = 19;
constexpr int NumViolationReasons = 19;
#endif
enum OsTypes {

View File

@@ -43,8 +43,7 @@ void OTClient::init(const std::vector<std::string>& args)
g_modules.ensureModuleLoaded("core_lib");
// client modules 100-499
g_modules.autoLoadModules(499);
g_modules.ensureModuleLoaded("client_main");
g_modules.ensureModuleLoaded("client_tibiafiles");
g_modules.ensureModuleLoaded("client");
// game modules 500-999
g_modules.autoLoadModules(999);
g_modules.ensureModuleLoaded("game");

View File

@@ -64,6 +64,8 @@ public:
pos.x--;
pos.y--;
break;
default:
break;
}
return pos;
}
@@ -99,6 +101,8 @@ public:
pos.x++;
pos.y++;
break;
default:
break;
}
return pos;
}