mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-22 06:05:38 +00:00
Replace Eigen with "inhouse" vector and matrix math
This commit is contained in:
parent
997ee7b940
commit
73a2f6b716
|
@ -1,80 +0,0 @@
|
||||||
# - Try to find Eigen3 lib
|
|
||||||
#
|
|
||||||
# This module supports requiring a minimum version, e.g. you can do
|
|
||||||
# find_package(Eigen3 3.1.2)
|
|
||||||
# to require version 3.1.2 or newer of Eigen3.
|
|
||||||
#
|
|
||||||
# Once done this will define
|
|
||||||
#
|
|
||||||
# EIGEN3_FOUND - system has eigen lib with correct version
|
|
||||||
# EIGEN3_INCLUDE_DIR - the eigen include directory
|
|
||||||
# EIGEN3_VERSION - eigen version
|
|
||||||
|
|
||||||
# Copyright (c) 2006, 2007 Montel Laurent, <montel@kde.org>
|
|
||||||
# Copyright (c) 2008, 2009 Gael Guennebaud, <g.gael@free.fr>
|
|
||||||
# Copyright (c) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
|
|
||||||
# Redistribution and use is allowed according to the terms of the 2-clause BSD license.
|
|
||||||
|
|
||||||
if(NOT Eigen3_FIND_VERSION)
|
|
||||||
if(NOT Eigen3_FIND_VERSION_MAJOR)
|
|
||||||
set(Eigen3_FIND_VERSION_MAJOR 2)
|
|
||||||
endif(NOT Eigen3_FIND_VERSION_MAJOR)
|
|
||||||
if(NOT Eigen3_FIND_VERSION_MINOR)
|
|
||||||
set(Eigen3_FIND_VERSION_MINOR 91)
|
|
||||||
endif(NOT Eigen3_FIND_VERSION_MINOR)
|
|
||||||
if(NOT Eigen3_FIND_VERSION_PATCH)
|
|
||||||
set(Eigen3_FIND_VERSION_PATCH 0)
|
|
||||||
endif(NOT Eigen3_FIND_VERSION_PATCH)
|
|
||||||
|
|
||||||
set(Eigen3_FIND_VERSION "${Eigen3_FIND_VERSION_MAJOR}.${Eigen3_FIND_VERSION_MINOR}.${Eigen3_FIND_VERSION_PATCH}")
|
|
||||||
endif(NOT Eigen3_FIND_VERSION)
|
|
||||||
|
|
||||||
macro(_eigen3_check_version)
|
|
||||||
file(READ "${EIGEN3_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h" _eigen3_version_header)
|
|
||||||
|
|
||||||
string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen3_world_version_match "${_eigen3_version_header}")
|
|
||||||
set(EIGEN3_WORLD_VERSION "${CMAKE_MATCH_1}")
|
|
||||||
string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen3_major_version_match "${_eigen3_version_header}")
|
|
||||||
set(EIGEN3_MAJOR_VERSION "${CMAKE_MATCH_1}")
|
|
||||||
string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen3_minor_version_match "${_eigen3_version_header}")
|
|
||||||
set(EIGEN3_MINOR_VERSION "${CMAKE_MATCH_1}")
|
|
||||||
|
|
||||||
set(EIGEN3_VERSION ${EIGEN3_WORLD_VERSION}.${EIGEN3_MAJOR_VERSION}.${EIGEN3_MINOR_VERSION})
|
|
||||||
if(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
|
|
||||||
set(EIGEN3_VERSION_OK FALSE)
|
|
||||||
else(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
|
|
||||||
set(EIGEN3_VERSION_OK TRUE)
|
|
||||||
endif(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
|
|
||||||
|
|
||||||
if(NOT EIGEN3_VERSION_OK)
|
|
||||||
|
|
||||||
message(STATUS "Eigen3 version ${EIGEN3_VERSION} found in ${EIGEN3_INCLUDE_DIR}, "
|
|
||||||
"but at least version ${Eigen3_FIND_VERSION} is required")
|
|
||||||
endif(NOT EIGEN3_VERSION_OK)
|
|
||||||
endmacro(_eigen3_check_version)
|
|
||||||
|
|
||||||
if (EIGEN3_INCLUDE_DIR)
|
|
||||||
|
|
||||||
# in cache already
|
|
||||||
_eigen3_check_version()
|
|
||||||
set(EIGEN3_FOUND ${EIGEN3_VERSION_OK})
|
|
||||||
|
|
||||||
else (EIGEN3_INCLUDE_DIR)
|
|
||||||
|
|
||||||
find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library
|
|
||||||
PATHS
|
|
||||||
${CMAKE_INSTALL_PREFIX}/include
|
|
||||||
${KDE4_INCLUDE_DIR}
|
|
||||||
PATH_SUFFIXES eigen3 eigen Eigen
|
|
||||||
)
|
|
||||||
|
|
||||||
if(EIGEN3_INCLUDE_DIR)
|
|
||||||
_eigen3_check_version()
|
|
||||||
endif(EIGEN3_INCLUDE_DIR)
|
|
||||||
|
|
||||||
include(FindPackageHandleStandardArgs)
|
|
||||||
find_package_handle_standard_args(Eigen3 DEFAULT_MSG EIGEN3_INCLUDE_DIR EIGEN3_VERSION_OK)
|
|
||||||
|
|
||||||
mark_as_advanced(EIGEN3_INCLUDE_DIR)
|
|
||||||
|
|
||||||
endif(EIGEN3_INCLUDE_DIR)
|
|
|
@ -54,7 +54,6 @@ find_package(Boost REQUIRED COMPONENTS system date_time locale)
|
||||||
else()
|
else()
|
||||||
find_package(Boost REQUIRED COMPONENTS system filesystem date_time locale)
|
find_package(Boost REQUIRED COMPONENTS system filesystem date_time locale)
|
||||||
endif()
|
endif()
|
||||||
find_package(Eigen3 REQUIRED)
|
|
||||||
find_package(CURL REQUIRED)
|
find_package(CURL REQUIRED)
|
||||||
find_package(VLC REQUIRED)
|
find_package(VLC REQUIRED)
|
||||||
|
|
||||||
|
@ -102,8 +101,6 @@ else()
|
||||||
add_definitions(-DUSE_OPENGL_ES)
|
add_definitions(-DUSE_OPENGL_ES)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_definitions(-DEIGEN_DONT_ALIGN)
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
#add include directories
|
#add include directories
|
||||||
set(COMMON_INCLUDE_DIRS
|
set(COMMON_INCLUDE_DIRS
|
||||||
|
@ -111,7 +108,6 @@ set(COMMON_INCLUDE_DIRS
|
||||||
${FreeImage_INCLUDE_DIRS}
|
${FreeImage_INCLUDE_DIRS}
|
||||||
${SDL2_INCLUDE_DIR}
|
${SDL2_INCLUDE_DIR}
|
||||||
${Boost_INCLUDE_DIRS}
|
${Boost_INCLUDE_DIRS}
|
||||||
${EIGEN3_INCLUDE_DIR}
|
|
||||||
${CURL_INCLUDE_DIR}
|
${CURL_INCLUDE_DIR}
|
||||||
${VLC_INCLUDE_DIR}
|
${VLC_INCLUDE_DIR}
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/external
|
${CMAKE_CURRENT_SOURCE_DIR}/external
|
||||||
|
|
|
@ -154,7 +154,7 @@ SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Alec Lofquist <allofquist@yahoo.com>")
|
||||||
SET(CPACK_DEBIAN_PACKAGE_SECTION "misc")
|
SET(CPACK_DEBIAN_PACKAGE_SECTION "misc")
|
||||||
SET(CPACK_DEBIAN_PACKAGE_PRIORITY "extra")
|
SET(CPACK_DEBIAN_PACKAGE_PRIORITY "extra")
|
||||||
SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6, libsdl2-2.0-0, libboost-system${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}, libboost-filesystem${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}, libfreeimage3, libfreetype6, libcurl3, libasound2")
|
SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6, libsdl2-2.0-0, libboost-system${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}, libboost-filesystem${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}, libfreeimage3, libfreetype6, libcurl3, libasound2")
|
||||||
SET(CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS "debhelper (>= 8.0.0), cmake, g++ (>= 4.8), libsdl2-dev, libboost-system-dev, libboost-filesystem-dev, libboost-date-time-dev, libfreeimage-dev, libfreetype6-dev, libeigen3-dev, libcurl4-openssl-dev, libasound2-dev, libgl1-mesa-dev")
|
SET(CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS "debhelper (>= 8.0.0), cmake, g++ (>= 4.8), libsdl2-dev, libboost-system-dev, libboost-filesystem-dev, libboost-date-time-dev, libfreeimage-dev, libfreetype6-dev, libcurl4-openssl-dev, libasound2-dev, libgl1-mesa-dev")
|
||||||
|
|
||||||
SET(CPACK_PACKAGE_VENDOR "emulationstation.org")
|
SET(CPACK_PACKAGE_VENDOR "emulationstation.org")
|
||||||
SET(CPACK_PACKAGE_VERSION "2.0.0~rc1")
|
SET(CPACK_PACKAGE_VERSION "2.0.0~rc1")
|
||||||
|
|
|
@ -209,20 +209,20 @@ void SystemScreenSaver::renderScreenSaver()
|
||||||
if (mVideoScreensaver && screensaver_behavior == "random video")
|
if (mVideoScreensaver && screensaver_behavior == "random video")
|
||||||
{
|
{
|
||||||
// Render black background
|
// Render black background
|
||||||
Renderer::setMatrix(Eigen::Affine3f::Identity());
|
Renderer::setMatrix(Transform4x4f::Identity());
|
||||||
Renderer::drawRect(0, 0, Renderer::getScreenWidth(), Renderer::getScreenHeight(), (unsigned char)(255));
|
Renderer::drawRect(0, 0, Renderer::getScreenWidth(), Renderer::getScreenHeight(), (unsigned char)(255));
|
||||||
|
|
||||||
// Only render the video if the state requires it
|
// Only render the video if the state requires it
|
||||||
if ((int)mState >= STATE_FADE_IN_VIDEO)
|
if ((int)mState >= STATE_FADE_IN_VIDEO)
|
||||||
{
|
{
|
||||||
Eigen::Affine3f transform = Eigen::Affine3f::Identity();
|
Transform4x4f transform = Transform4x4f::Identity();
|
||||||
mVideoScreensaver->render(transform);
|
mVideoScreensaver->render(transform);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (mImageScreensaver && screensaver_behavior == "slideshow")
|
else if (mImageScreensaver && screensaver_behavior == "slideshow")
|
||||||
{
|
{
|
||||||
// Render black background
|
// Render black background
|
||||||
Renderer::setMatrix(Eigen::Affine3f::Identity());
|
Renderer::setMatrix(Transform4x4f::Identity());
|
||||||
Renderer::drawRect(0, 0, Renderer::getScreenWidth(), Renderer::getScreenHeight(), (unsigned char)(255));
|
Renderer::drawRect(0, 0, Renderer::getScreenWidth(), Renderer::getScreenHeight(), (unsigned char)(255));
|
||||||
|
|
||||||
// Only render the video if the state requires it
|
// Only render the video if the state requires it
|
||||||
|
@ -232,7 +232,7 @@ void SystemScreenSaver::renderScreenSaver()
|
||||||
{
|
{
|
||||||
mImageScreensaver->setOpacity(255- (unsigned char) (mOpacity * 255));
|
mImageScreensaver->setOpacity(255- (unsigned char) (mOpacity * 255));
|
||||||
|
|
||||||
Eigen::Affine3f transform = Eigen::Affine3f::Identity();
|
Transform4x4f transform = Transform4x4f::Identity();
|
||||||
mImageScreensaver->render(transform);
|
mImageScreensaver->render(transform);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -248,7 +248,7 @@ void SystemScreenSaver::renderScreenSaver()
|
||||||
}
|
}
|
||||||
else if (mState != STATE_INACTIVE)
|
else if (mState != STATE_INACTIVE)
|
||||||
{
|
{
|
||||||
Renderer::setMatrix(Eigen::Affine3f::Identity());
|
Renderer::setMatrix(Transform4x4f::Identity());
|
||||||
unsigned char opacity = screensaver_behavior == "dim" ? 0xA0 : 0xFF;
|
unsigned char opacity = screensaver_behavior == "dim" ? 0xA0 : 0xFF;
|
||||||
Renderer::drawRect(0, 0, Renderer::getScreenWidth(), Renderer::getScreenHeight(), 0x00000000 | opacity);
|
Renderer::drawRect(0, 0, Renderer::getScreenWidth(), Renderer::getScreenHeight(), 0x00000000 | opacity);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "animations/Animation.h"
|
#include "animations/Animation.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
#include "math/Scale3x3f.h"
|
||||||
|
|
||||||
// let's look at the game launch effect:
|
// let's look at the game launch effect:
|
||||||
// -move camera to center on point P (interpolation method: linear)
|
// -move camera to center on point P (interpolation method: linear)
|
||||||
|
@ -31,34 +32,34 @@ class LaunchAnimation : public Animation
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//Target is a centerpoint
|
//Target is a centerpoint
|
||||||
LaunchAnimation(Eigen::Affine3f& camera, float& fade, const Eigen::Vector3f& target, int duration) :
|
LaunchAnimation(Transform4x4f& camera, float& fade, const Vector3f& target, int duration) :
|
||||||
mCameraStart(camera), mTarget(target), mDuration(duration), cameraOut(camera), fadeOut(fade) {}
|
mCameraStart(camera), mTarget(target), mDuration(duration), cameraOut(camera), fadeOut(fade) {}
|
||||||
|
|
||||||
int getDuration() const override { return mDuration; }
|
int getDuration() const override { return mDuration; }
|
||||||
|
|
||||||
void apply(float t) override
|
void apply(float t) override
|
||||||
{
|
{
|
||||||
cameraOut = Eigen::Affine3f::Identity();
|
cameraOut = Transform4x4f::Identity();
|
||||||
|
|
||||||
float zoom = lerp<float>(1.0, 4.25f, t*t);
|
float zoom = lerp<float>(1.0, 4.25f, t*t);
|
||||||
cameraOut.scale(Eigen::Vector3f(zoom, zoom, 1));
|
cameraOut *= Scale3x3f(Vector3f(zoom, zoom, 1));
|
||||||
|
|
||||||
const float sw = (float)Renderer::getScreenWidth() / zoom;
|
const float sw = (float)Renderer::getScreenWidth() / zoom;
|
||||||
const float sh = (float)Renderer::getScreenHeight() / zoom;
|
const float sh = (float)Renderer::getScreenHeight() / zoom;
|
||||||
|
|
||||||
Eigen::Vector3f centerPoint = lerp<Eigen::Vector3f>(-mCameraStart.translation() + Eigen::Vector3f(Renderer::getScreenWidth() / 2.0f, Renderer::getScreenHeight() / 2.0f, 0),
|
Vector3f centerPoint = lerp<Vector3f>(-mCameraStart.translation() + Vector3f(Renderer::getScreenWidth() / 2.0f, Renderer::getScreenHeight() / 2.0f, 0),
|
||||||
mTarget, smoothStep(0.0, 1.0, t));
|
mTarget, smoothStep(0.0, 1.0, t));
|
||||||
|
|
||||||
cameraOut.translate(Eigen::Vector3f((sw / 2) - centerPoint.x(), (sh / 2) - centerPoint.y(), 0));
|
cameraOut.translate(Vector3f((sw / 2) - centerPoint.x(), (sh / 2) - centerPoint.y(), 0));
|
||||||
|
|
||||||
fadeOut = lerp<float>(0.0, 1.0, t*t);
|
fadeOut = lerp<float>(0.0, 1.0, t*t);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Eigen::Affine3f mCameraStart;
|
Transform4x4f mCameraStart;
|
||||||
Eigen::Vector3f mTarget;
|
Vector3f mTarget;
|
||||||
int mDuration;
|
int mDuration;
|
||||||
|
|
||||||
Eigen::Affine3f& cameraOut;
|
Transform4x4f& cameraOut;
|
||||||
float& fadeOut;
|
float& fadeOut;
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
class MoveCameraAnimation : public Animation
|
class MoveCameraAnimation : public Animation
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MoveCameraAnimation(Eigen::Affine3f& camera, const Eigen::Vector3f& target) : mCameraStart(camera), mTarget(target), cameraOut(camera) {}
|
MoveCameraAnimation(Transform4x4f& camera, const Vector3f& target) : mCameraStart(camera), mTarget(target), cameraOut(camera) {}
|
||||||
|
|
||||||
int getDuration() const override { return 400; }
|
int getDuration() const override { return 400; }
|
||||||
|
|
||||||
|
@ -13,12 +13,12 @@ public:
|
||||||
{
|
{
|
||||||
// cubic ease out
|
// cubic ease out
|
||||||
t -= 1;
|
t -= 1;
|
||||||
cameraOut.translation() = -lerp<Eigen::Vector3f>(-mCameraStart.translation(), mTarget, t*t*t + 1);
|
cameraOut.translation() = -lerp<Vector3f>(-mCameraStart.translation(), mTarget, t*t*t + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Eigen::Affine3f mCameraStart;
|
Transform4x4f mCameraStart;
|
||||||
Eigen::Vector3f mTarget;
|
Vector3f mTarget;
|
||||||
|
|
||||||
Eigen::Affine3f& cameraOut;
|
Transform4x4f& cameraOut;
|
||||||
};
|
};
|
||||||
|
|
|
@ -33,13 +33,13 @@ void AsyncReqComponent::update(int deltaTime)
|
||||||
mTime += deltaTime;
|
mTime += deltaTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AsyncReqComponent::render(const Eigen::Affine3f& parentTrans)
|
void AsyncReqComponent::render(const Transform4x4f& parentTrans)
|
||||||
{
|
{
|
||||||
Eigen::Affine3f trans = Eigen::Affine3f::Identity();
|
Transform4x4f trans = Transform4x4f::Identity();
|
||||||
trans = trans.translate(Eigen::Vector3f(Renderer::getScreenWidth() / 2.0f, Renderer::getScreenHeight() / 2.0f, 0));
|
trans = trans.translate(Vector3f(Renderer::getScreenWidth() / 2.0f, Renderer::getScreenHeight() / 2.0f, 0));
|
||||||
Renderer::setMatrix(trans);
|
Renderer::setMatrix(trans);
|
||||||
|
|
||||||
Eigen::Vector3f point(cos(mTime * 0.01f) * 12, sin(mTime * 0.01f) * 12, 0);
|
Vector3f point(cos(mTime * 0.01f) * 12, sin(mTime * 0.01f) * 12, 0);
|
||||||
Renderer::drawRect((int)point.x(), (int)point.y(), 8, 8, 0x0000FFFF);
|
Renderer::drawRect((int)point.x(), (int)point.y(), 8, 8, 0x0000FFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ public:
|
||||||
|
|
||||||
bool input(InputConfig* config, Input input) override;
|
bool input(InputConfig* config, Input input) override;
|
||||||
void update(int deltaTime) override;
|
void update(int deltaTime) override;
|
||||||
void render(const Eigen::Affine3f& parentTrans) override;
|
void render(const Transform4x4f& parentTrans) override;
|
||||||
|
|
||||||
virtual std::vector<HelpPrompt> getHelpPrompts() override;
|
virtual std::vector<HelpPrompt> getHelpPrompts() override;
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -8,7 +8,7 @@ RatingComponent::RatingComponent(Window* window) : GuiComponent(window), mColorS
|
||||||
mFilledTexture = TextureResource::get(":/star_filled.svg", true);
|
mFilledTexture = TextureResource::get(":/star_filled.svg", true);
|
||||||
mUnfilledTexture = TextureResource::get(":/star_unfilled.svg", true);
|
mUnfilledTexture = TextureResource::get(":/star_unfilled.svg", true);
|
||||||
mValue = 0.5f;
|
mValue = 0.5f;
|
||||||
mSize << 64 * NUM_RATING_STARS, 64;
|
mSize = Vector2f(64 * NUM_RATING_STARS, 64);
|
||||||
updateVertices();
|
updateVertices();
|
||||||
updateColors();
|
updateColors();
|
||||||
}
|
}
|
||||||
|
@ -81,26 +81,26 @@ void RatingComponent::updateVertices()
|
||||||
const float w = round(h * mValue * numStars);
|
const float w = round(h * mValue * numStars);
|
||||||
const float fw = round(h * numStars);
|
const float fw = round(h * numStars);
|
||||||
|
|
||||||
mVertices[0].pos << 0.0f, 0.0f;
|
mVertices[0].pos = Vector2f(0.0f, 0.0f);
|
||||||
mVertices[0].tex << 0.0f, 1.0f;
|
mVertices[0].tex = Vector2f(0.0f, 1.0f);
|
||||||
mVertices[1].pos << w, h;
|
mVertices[1].pos = Vector2f(w, h);
|
||||||
mVertices[1].tex << mValue * numStars, 0.0f;
|
mVertices[1].tex = Vector2f(mValue * numStars, 0.0f);
|
||||||
mVertices[2].pos << 0.0f, h;
|
mVertices[2].pos = Vector2f(0.0f, h);
|
||||||
mVertices[2].tex << 0.0f, 0.0f;
|
mVertices[2].tex = Vector2f(0.0f, 0.0f);
|
||||||
|
|
||||||
mVertices[3] = mVertices[0];
|
mVertices[3] = mVertices[0];
|
||||||
mVertices[4].pos << w, 0.0f;
|
mVertices[4].pos = Vector2f(w, 0.0f);
|
||||||
mVertices[4].tex << mValue * numStars, 1.0f;
|
mVertices[4].tex = Vector2f(mValue * numStars, 1.0f);
|
||||||
mVertices[5] = mVertices[1];
|
mVertices[5] = mVertices[1];
|
||||||
|
|
||||||
mVertices[6] = mVertices[4];
|
mVertices[6] = mVertices[4];
|
||||||
mVertices[7].pos << fw, h;
|
mVertices[7].pos = Vector2f(fw, h);
|
||||||
mVertices[7].tex << numStars, 0.0f;
|
mVertices[7].tex = Vector2f(numStars, 0.0f);
|
||||||
mVertices[8] = mVertices[1];
|
mVertices[8] = mVertices[1];
|
||||||
|
|
||||||
mVertices[9] = mVertices[6];
|
mVertices[9] = mVertices[6];
|
||||||
mVertices[10].pos << fw, 0.0f;
|
mVertices[10].pos = Vector2f(fw, 0.0f);
|
||||||
mVertices[10].tex << numStars, 1.0f;
|
mVertices[10].tex = Vector2f(numStars, 1.0f);
|
||||||
mVertices[11] = mVertices[7];
|
mVertices[11] = mVertices[7];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,9 +109,10 @@ void RatingComponent::updateColors()
|
||||||
Renderer::buildGLColorArray(mColors, mColorShift, 12);
|
Renderer::buildGLColorArray(mColors, mColorShift, 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RatingComponent::render(const Eigen::Affine3f& parentTrans)
|
void RatingComponent::render(const Transform4x4f& parentTrans)
|
||||||
{
|
{
|
||||||
Eigen::Affine3f trans = roundMatrix(parentTrans * getTransform());
|
Transform4x4f trans = parentTrans * getTransform();
|
||||||
|
trans.round();
|
||||||
Renderer::setMatrix(trans);
|
Renderer::setMatrix(trans);
|
||||||
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
|
|
@ -19,7 +19,7 @@ public:
|
||||||
void setValue(const std::string& value) override; // Should be a normalized float (in the range [0..1]) - if it's not, it will be clamped.
|
void setValue(const std::string& value) override; // Should be a normalized float (in the range [0..1]) - if it's not, it will be clamped.
|
||||||
|
|
||||||
bool input(InputConfig* config, Input input) override;
|
bool input(InputConfig* config, Input input) override;
|
||||||
void render(const Eigen::Affine3f& parentTrans);
|
void render(const Transform4x4f& parentTrans);
|
||||||
|
|
||||||
void onSizeChanged() override;
|
void onSizeChanged() override;
|
||||||
|
|
||||||
|
@ -40,8 +40,8 @@ private:
|
||||||
|
|
||||||
struct Vertex
|
struct Vertex
|
||||||
{
|
{
|
||||||
Eigen::Vector2f pos;
|
Vector2f pos;
|
||||||
Eigen::Vector2f tex;
|
Vector2f tex;
|
||||||
} mVertices[12];
|
} mVertices[12];
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,15 +15,13 @@
|
||||||
#include "guis/GuiTextEditPopup.h"
|
#include "guis/GuiTextEditPopup.h"
|
||||||
|
|
||||||
ScraperSearchComponent::ScraperSearchComponent(Window* window, SearchType type) : GuiComponent(window),
|
ScraperSearchComponent::ScraperSearchComponent(Window* window, SearchType type) : GuiComponent(window),
|
||||||
mGrid(window, Eigen::Vector2i(4, 3)), mBusyAnim(window),
|
mGrid(window, Vector2i(4, 3)), mBusyAnim(window),
|
||||||
mSearchType(type)
|
mSearchType(type)
|
||||||
{
|
{
|
||||||
addChild(&mGrid);
|
addChild(&mGrid);
|
||||||
|
|
||||||
mBlockAccept = false;
|
mBlockAccept = false;
|
||||||
|
|
||||||
using namespace Eigen;
|
|
||||||
|
|
||||||
// left spacer (empty component, needed for borders)
|
// left spacer (empty component, needed for borders)
|
||||||
mGrid.setEntry(std::make_shared<GuiComponent>(mWindow), Vector2i(0, 0), false, false, Vector2i(1, 3), GridFlags::BORDER_TOP | GridFlags::BORDER_BOTTOM);
|
mGrid.setEntry(std::make_shared<GuiComponent>(mWindow), Vector2i(0, 0), false, false, Vector2i(1, 3), GridFlags::BORDER_TOP | GridFlags::BORDER_BOTTOM);
|
||||||
|
|
||||||
|
@ -171,8 +169,6 @@ void ScraperSearchComponent::resizeMetadata()
|
||||||
|
|
||||||
void ScraperSearchComponent::updateViewStyle()
|
void ScraperSearchComponent::updateViewStyle()
|
||||||
{
|
{
|
||||||
using namespace Eigen;
|
|
||||||
|
|
||||||
// unlink description and result list and result name
|
// unlink description and result list and result name
|
||||||
mGrid.removeEntry(mResultName);
|
mGrid.removeEntry(mResultName);
|
||||||
mGrid.removeEntry(mResultDesc);
|
mGrid.removeEntry(mResultDesc);
|
||||||
|
@ -345,9 +341,9 @@ bool ScraperSearchComponent::input(InputConfig* config, Input input)
|
||||||
return GuiComponent::input(config, input);
|
return GuiComponent::input(config, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScraperSearchComponent::render(const Eigen::Affine3f& parentTrans)
|
void ScraperSearchComponent::render(const Transform4x4f& parentTrans)
|
||||||
{
|
{
|
||||||
Eigen::Affine3f trans = parentTrans * getTransform();
|
Transform4x4f trans = parentTrans * getTransform();
|
||||||
|
|
||||||
renderChildren(trans);
|
renderChildren(trans);
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ public:
|
||||||
|
|
||||||
bool input(InputConfig* config, Input input) override;
|
bool input(InputConfig* config, Input input) override;
|
||||||
void update(int deltaTime) override;
|
void update(int deltaTime) override;
|
||||||
void render(const Eigen::Affine3f& parentTrans) override;
|
void render(const Transform4x4f& parentTrans) override;
|
||||||
std::vector<HelpPrompt> getHelpPrompts() override;
|
std::vector<HelpPrompt> getHelpPrompts() override;
|
||||||
void onSizeChanged() override;
|
void onSizeChanged() override;
|
||||||
void onFocusGained() override;
|
void onFocusGained() override;
|
||||||
|
|
|
@ -42,7 +42,7 @@ public:
|
||||||
|
|
||||||
bool input(InputConfig* config, Input input) override;
|
bool input(InputConfig* config, Input input) override;
|
||||||
void update(int deltaTime) override;
|
void update(int deltaTime) override;
|
||||||
void render(const Eigen::Affine3f& parentTrans) override;
|
void render(const Transform4x4f& parentTrans) override;
|
||||||
void applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view, const std::string& element, unsigned int properties) override;
|
void applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view, const std::string& element, unsigned int properties) override;
|
||||||
|
|
||||||
void add(const std::string& name, const T& obj, unsigned int colorId);
|
void add(const std::string& name, const T& obj, unsigned int colorId);
|
||||||
|
@ -132,9 +132,9 @@ TextListComponent<T>::TextListComponent(Window* window) :
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void TextListComponent<T>::render(const Eigen::Affine3f& parentTrans)
|
void TextListComponent<T>::render(const Transform4x4f& parentTrans)
|
||||||
{
|
{
|
||||||
Eigen::Affine3f trans = parentTrans * getTransform();
|
Transform4x4f trans = parentTrans * getTransform();
|
||||||
|
|
||||||
std::shared_ptr<Font>& font = mFont;
|
std::shared_ptr<Font>& font = mFont;
|
||||||
|
|
||||||
|
@ -176,10 +176,10 @@ void TextListComponent<T>::render(const Eigen::Affine3f& parentTrans)
|
||||||
}
|
}
|
||||||
|
|
||||||
// clip to inside margins
|
// clip to inside margins
|
||||||
Eigen::Vector3f dim(mSize.x(), mSize.y(), 0);
|
Vector3f dim(mSize.x(), mSize.y(), 0);
|
||||||
dim = trans * dim - trans.translation();
|
dim = trans * dim - trans.translation();
|
||||||
Renderer::pushClipRect(Eigen::Vector2i((int)(trans.translation().x() + mHorizontalMargin), (int)trans.translation().y()),
|
Renderer::pushClipRect(Vector2i((int)(trans.translation().x() + mHorizontalMargin), (int)trans.translation().y()),
|
||||||
Eigen::Vector2i((int)(dim.x() - mHorizontalMargin*2), (int)dim.y()));
|
Vector2i((int)(dim.x() - mHorizontalMargin*2), (int)dim.y()));
|
||||||
|
|
||||||
for(int i = startEntry; i < listCutoff; i++)
|
for(int i = startEntry; i < listCutoff; i++)
|
||||||
{
|
{
|
||||||
|
@ -196,7 +196,7 @@ void TextListComponent<T>::render(const Eigen::Affine3f& parentTrans)
|
||||||
|
|
||||||
entry.data.textCache->setColor(color);
|
entry.data.textCache->setColor(color);
|
||||||
|
|
||||||
Eigen::Vector3f offset(0, y, 0);
|
Vector3f offset(0, y, 0);
|
||||||
|
|
||||||
switch(mAlignment)
|
switch(mAlignment)
|
||||||
{
|
{
|
||||||
|
@ -219,7 +219,7 @@ void TextListComponent<T>::render(const Eigen::Affine3f& parentTrans)
|
||||||
if(mCursor == i)
|
if(mCursor == i)
|
||||||
offset[0] -= mMarqueeOffset;
|
offset[0] -= mMarqueeOffset;
|
||||||
|
|
||||||
Eigen::Affine3f drawTrans = trans;
|
Transform4x4f drawTrans = trans;
|
||||||
drawTrans.translate(offset);
|
drawTrans.translate(offset);
|
||||||
Renderer::setMatrix(drawTrans);
|
Renderer::setMatrix(drawTrans);
|
||||||
|
|
||||||
|
@ -285,7 +285,7 @@ void TextListComponent<T>::update(int deltaTime)
|
||||||
//if we're not scrolling and this object's text goes outside our size, marquee it!
|
//if we're not scrolling and this object's text goes outside our size, marquee it!
|
||||||
const std::string& text = mEntries.at((unsigned int)mCursor).name;
|
const std::string& text = mEntries.at((unsigned int)mCursor).name;
|
||||||
|
|
||||||
Eigen::Vector2f textSize = mFont->sizeText(text);
|
Vector2f textSize = mFont->sizeText(text);
|
||||||
|
|
||||||
//it's long enough to marquee
|
//it's long enough to marquee
|
||||||
if(textSize.x() - mMarqueeOffset > mSize.x() - 12 - mHorizontalMargin * 2)
|
if(textSize.x() - mMarqueeOffset > mSize.x() - 12 - mHorizontalMargin * 2)
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
|
|
||||||
GuiGameScraper::GuiGameScraper(Window* window, ScraperSearchParams params, std::function<void(const ScraperSearchResult&)> doneFunc) : GuiComponent(window),
|
GuiGameScraper::GuiGameScraper(Window* window, ScraperSearchParams params, std::function<void(const ScraperSearchResult&)> doneFunc) : GuiComponent(window),
|
||||||
mGrid(window, Eigen::Vector2i(1, 7)),
|
mGrid(window, Vector2i(1, 7)),
|
||||||
mBox(window, ":/frame.png"),
|
mBox(window, ":/frame.png"),
|
||||||
mSearchParams(params),
|
mSearchParams(params),
|
||||||
mClose(false)
|
mClose(false)
|
||||||
|
@ -23,19 +23,19 @@ GuiGameScraper::GuiGameScraper(Window* window, ScraperSearchParams params, std::
|
||||||
|
|
||||||
mGameName = std::make_shared<TextComponent>(mWindow, strToUpper(mSearchParams.game->getPath().filename().generic_string()),
|
mGameName = std::make_shared<TextComponent>(mWindow, strToUpper(mSearchParams.game->getPath().filename().generic_string()),
|
||||||
Font::get(FONT_SIZE_MEDIUM), 0x777777FF, ALIGN_CENTER);
|
Font::get(FONT_SIZE_MEDIUM), 0x777777FF, ALIGN_CENTER);
|
||||||
mGrid.setEntry(mGameName, Eigen::Vector2i(0, 1), false, true);
|
mGrid.setEntry(mGameName, Vector2i(0, 1), false, true);
|
||||||
|
|
||||||
// row 2 is a spacer
|
// row 2 is a spacer
|
||||||
|
|
||||||
mSystemName = std::make_shared<TextComponent>(mWindow, strToUpper(mSearchParams.system->getFullName()), Font::get(FONT_SIZE_SMALL),
|
mSystemName = std::make_shared<TextComponent>(mWindow, strToUpper(mSearchParams.system->getFullName()), Font::get(FONT_SIZE_SMALL),
|
||||||
0x888888FF, ALIGN_CENTER);
|
0x888888FF, ALIGN_CENTER);
|
||||||
mGrid.setEntry(mSystemName, Eigen::Vector2i(0, 3), false, true);
|
mGrid.setEntry(mSystemName, Vector2i(0, 3), false, true);
|
||||||
|
|
||||||
// row 4 is a spacer
|
// row 4 is a spacer
|
||||||
|
|
||||||
// ScraperSearchComponent
|
// ScraperSearchComponent
|
||||||
mSearch = std::make_shared<ScraperSearchComponent>(window, ScraperSearchComponent::NEVER_AUTO_ACCEPT);
|
mSearch = std::make_shared<ScraperSearchComponent>(window, ScraperSearchComponent::NEVER_AUTO_ACCEPT);
|
||||||
mGrid.setEntry(mSearch, Eigen::Vector2i(0, 5), true);
|
mGrid.setEntry(mSearch, Vector2i(0, 5), true);
|
||||||
|
|
||||||
// buttons
|
// buttons
|
||||||
std::vector< std::shared_ptr<ButtonComponent> > buttons;
|
std::vector< std::shared_ptr<ButtonComponent> > buttons;
|
||||||
|
@ -47,7 +47,7 @@ GuiGameScraper::GuiGameScraper(Window* window, ScraperSearchParams params, std::
|
||||||
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "CANCEL", "cancel", [&] { delete this; }));
|
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "CANCEL", "cancel", [&] { delete this; }));
|
||||||
mButtonGrid = makeButtonGrid(mWindow, buttons);
|
mButtonGrid = makeButtonGrid(mWindow, buttons);
|
||||||
|
|
||||||
mGrid.setEntry(mButtonGrid, Eigen::Vector2i(0, 6), true, false);
|
mGrid.setEntry(mButtonGrid, Vector2i(0, 6), true, false);
|
||||||
|
|
||||||
// we call this->close() instead of just delete this; in the accept callback:
|
// we call this->close() instead of just delete this; in the accept callback:
|
||||||
// this is because of how GuiComponent::update works. if it was just delete this, this would happen when the metadata resolver is done:
|
// this is because of how GuiComponent::update works. if it was just delete this, this would happen when the metadata resolver is done:
|
||||||
|
@ -83,7 +83,7 @@ GuiGameScraper::GuiGameScraper(Window* window, ScraperSearchParams params, std::
|
||||||
|
|
||||||
void GuiGameScraper::onSizeChanged()
|
void GuiGameScraper::onSizeChanged()
|
||||||
{
|
{
|
||||||
mBox.fitTo(mSize, Eigen::Vector3f::Zero(), Eigen::Vector2f(-32, -32));
|
mBox.fitTo(mSize, Vector3f::Zero(), Vector2f(-32, -32));
|
||||||
|
|
||||||
mGrid.setRowHeightPerc(0, 0.04f, false);
|
mGrid.setRowHeightPerc(0, 0.04f, false);
|
||||||
mGrid.setRowHeightPerc(1, mGameName->getFont()->getLetterHeight() / mSize.y(), false); // game name
|
mGrid.setRowHeightPerc(1, mGameName->getFont()->getLetterHeight() / mSize.y(), false); // game name
|
||||||
|
|
|
@ -43,15 +43,15 @@ GuiInfoPopup::GuiInfoPopup(Window* window, std::string message, int duration) :
|
||||||
setPosition(posX, posY, 0);
|
setPosition(posX, posY, 0);
|
||||||
|
|
||||||
mFrame->setImagePath(":/frame.png");
|
mFrame->setImagePath(":/frame.png");
|
||||||
mFrame->fitTo(mSize, Eigen::Vector3f::Zero(), Eigen::Vector2f(-32, -32));
|
mFrame->fitTo(mSize, Vector3f::Zero(), Vector2f(-32, -32));
|
||||||
addChild(mFrame);
|
addChild(mFrame);
|
||||||
|
|
||||||
// we only init the actual time when we first start to render
|
// we only init the actual time when we first start to render
|
||||||
mStartTime = 0;
|
mStartTime = 0;
|
||||||
|
|
||||||
mGrid = new ComponentGrid(window, Eigen::Vector2i(1, 3));
|
mGrid = new ComponentGrid(window, Vector2i(1, 3));
|
||||||
mGrid->setSize(mSize);
|
mGrid->setSize(mSize);
|
||||||
mGrid->setEntry(s, Eigen::Vector2i(0, 1), false, true);
|
mGrid->setEntry(s, Vector2i(0, 1), false, true);
|
||||||
addChild(mGrid);
|
addChild(mGrid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,10 +60,10 @@ GuiInfoPopup::~GuiInfoPopup()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiInfoPopup::render(const Eigen::Affine3f& parentTrans)
|
void GuiInfoPopup::render(const Transform4x4f& parentTrans)
|
||||||
{
|
{
|
||||||
// we use identity as we want to render on a specific window position, not on the view
|
// we use identity as we want to render on a specific window position, not on the view
|
||||||
Eigen::Affine3f trans = getTransform() * Eigen::Affine3f::Identity();
|
Transform4x4f trans = getTransform() * Transform4x4f::Identity();
|
||||||
if(running && updateState())
|
if(running && updateState())
|
||||||
{
|
{
|
||||||
// if we're still supposed to be rendering it
|
// if we're still supposed to be rendering it
|
||||||
|
|
|
@ -13,7 +13,7 @@ class GuiInfoPopup : public GuiComponent, public Window::InfoPopup
|
||||||
public:
|
public:
|
||||||
GuiInfoPopup(Window* window, std::string message, int duration);
|
GuiInfoPopup(Window* window, std::string message, int duration);
|
||||||
~GuiInfoPopup();
|
~GuiInfoPopup();
|
||||||
void render(const Eigen::Affine3f& parentTrans) override;
|
void render(const Transform4x4f& parentTrans) override;
|
||||||
inline void stop() { running = false; };
|
inline void stop() { running = false; };
|
||||||
private:
|
private:
|
||||||
std::string mMessage;
|
std::string mMessage;
|
||||||
|
|
|
@ -14,8 +14,6 @@
|
||||||
#include "components/SwitchComponent.h"
|
#include "components/SwitchComponent.h"
|
||||||
#include "guis/GuiTextEditPopup.h"
|
#include "guis/GuiTextEditPopup.h"
|
||||||
|
|
||||||
using namespace Eigen;
|
|
||||||
|
|
||||||
GuiMetaDataEd::GuiMetaDataEd(Window* window, MetaDataList* md, const std::vector<MetaDataDecl>& mdd, ScraperSearchParams scraperParams,
|
GuiMetaDataEd::GuiMetaDataEd(Window* window, MetaDataList* md, const std::vector<MetaDataDecl>& mdd, ScraperSearchParams scraperParams,
|
||||||
const std::string& header, std::function<void()> saveCallback, std::function<void()> deleteFunc) : GuiComponent(window),
|
const std::string& header, std::function<void()> saveCallback, std::function<void()> deleteFunc) : GuiComponent(window),
|
||||||
mScraperParams(scraperParams),
|
mScraperParams(scraperParams),
|
||||||
|
@ -115,7 +113,7 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window, MetaDataList* md, const std::vector
|
||||||
|
|
||||||
auto bracket = std::make_shared<ImageComponent>(mWindow);
|
auto bracket = std::make_shared<ImageComponent>(mWindow);
|
||||||
bracket->setImage(":/arrow.svg");
|
bracket->setImage(":/arrow.svg");
|
||||||
bracket->setResize(Eigen::Vector2f(0, lbl->getFont()->getLetterHeight()));
|
bracket->setResize(Vector2f(0, lbl->getFont()->getLetterHeight()));
|
||||||
row.addElement(bracket, false);
|
row.addElement(bracket, false);
|
||||||
|
|
||||||
bool multiLine = iter->type == MD_MULTILINE_STRING;
|
bool multiLine = iter->type == MD_MULTILINE_STRING;
|
||||||
|
|
|
@ -11,8 +11,6 @@
|
||||||
#include "components/MenuComponent.h" // for makeButtonGrid
|
#include "components/MenuComponent.h" // for makeButtonGrid
|
||||||
#include "guis/GuiMsgBox.h"
|
#include "guis/GuiMsgBox.h"
|
||||||
|
|
||||||
using namespace Eigen;
|
|
||||||
|
|
||||||
GuiScraperMulti::GuiScraperMulti(Window* window, const std::queue<ScraperSearchParams>& searches, bool approveResults) :
|
GuiScraperMulti::GuiScraperMulti(Window* window, const std::queue<ScraperSearchParams>& searches, bool approveResults) :
|
||||||
GuiComponent(window), mBackground(window, ":/frame.png"), mGrid(window, Vector2i(1, 5)),
|
GuiComponent(window), mBackground(window, ":/frame.png"), mGrid(window, Vector2i(1, 5)),
|
||||||
mSearchQueue(searches)
|
mSearchQueue(searches)
|
||||||
|
|
|
@ -101,7 +101,7 @@ void GuiSlideshowScreensaverOptions::addEditableTextComponent(ComponentListRow r
|
||||||
|
|
||||||
auto bracket = std::make_shared<ImageComponent>(mWindow);
|
auto bracket = std::make_shared<ImageComponent>(mWindow);
|
||||||
bracket->setImage(":/arrow.svg");
|
bracket->setImage(":/arrow.svg");
|
||||||
bracket->setResize(Eigen::Vector2f(0, lbl->getFont()->getLetterHeight()));
|
bracket->setResize(Vector2f(0, lbl->getFont()->getLetterHeight()));
|
||||||
row.addElement(bracket, false);
|
row.addElement(bracket, false);
|
||||||
|
|
||||||
auto updateVal = [ed](const std::string& newVal) { ed->setValue(newVal); }; // ok callback (apply new value to ed)
|
auto updateVal = [ed](const std::string& newVal) { ed->setValue(newVal); }; // ok callback (apply new value to ed)
|
||||||
|
|
|
@ -92,7 +92,7 @@ void SystemView::populate()
|
||||||
e.data.logo->setOrigin(0.5, 0.5);
|
e.data.logo->setOrigin(0.5, 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
Eigen::Vector2f denormalized = mCarousel.logoSize.cwiseProduct(e.data.logo->getOrigin());
|
Vector2f denormalized = mCarousel.logoSize * e.data.logo->getOrigin();
|
||||||
e.data.logo->setPosition(denormalized.x(), denormalized.y(), 0.0);
|
e.data.logo->setPosition(denormalized.x(), denormalized.y(), 0.0);
|
||||||
|
|
||||||
// delete any existing extras
|
// delete any existing extras
|
||||||
|
@ -326,12 +326,12 @@ void SystemView::onCursorChanged(const CursorState& state)
|
||||||
setAnimation(anim, 0, nullptr, false, 0);
|
setAnimation(anim, 0, nullptr, false, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SystemView::render(const Eigen::Affine3f& parentTrans)
|
void SystemView::render(const Transform4x4f& parentTrans)
|
||||||
{
|
{
|
||||||
if(size() == 0)
|
if(size() == 0)
|
||||||
return; // nothing to render
|
return; // nothing to render
|
||||||
|
|
||||||
Eigen::Affine3f trans = getTransform() * parentTrans;
|
Transform4x4f trans = getTransform() * parentTrans;
|
||||||
|
|
||||||
auto systemInfoZIndex = mSystemInfo.getZIndex();
|
auto systemInfoZIndex = mSystemInfo.getZIndex();
|
||||||
auto minMax = std::minmax(mCarousel.zIndex, systemInfoZIndex);
|
auto minMax = std::minmax(mCarousel.zIndex, systemInfoZIndex);
|
||||||
|
@ -408,21 +408,21 @@ void SystemView::getViewElements(const std::shared_ptr<ThemeData>& theme)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render system carousel
|
// Render system carousel
|
||||||
void SystemView::renderCarousel(const Eigen::Affine3f& trans)
|
void SystemView::renderCarousel(const Transform4x4f& trans)
|
||||||
{
|
{
|
||||||
// background box behind logos
|
// background box behind logos
|
||||||
Eigen::Affine3f carouselTrans = trans;
|
Transform4x4f carouselTrans = trans;
|
||||||
carouselTrans.translate(Eigen::Vector3f(mCarousel.pos.x(), mCarousel.pos.y(), 0.0));
|
carouselTrans.translate(Vector3f(mCarousel.pos.x(), mCarousel.pos.y(), 0.0));
|
||||||
carouselTrans.translate(Eigen::Vector3f(mCarousel.origin.x() * mCarousel.size.x() * -1, mCarousel.origin.y() * mCarousel.size.y() * -1, 0.0f));
|
carouselTrans.translate(Vector3f(mCarousel.origin.x() * mCarousel.size.x() * -1, mCarousel.origin.y() * mCarousel.size.y() * -1, 0.0f));
|
||||||
|
|
||||||
Eigen::Vector2f clipPos(carouselTrans.translation().x(), carouselTrans.translation().y());
|
Vector2f clipPos(carouselTrans.translation().x(), carouselTrans.translation().y());
|
||||||
Renderer::pushClipRect(clipPos.cast<int>(), mCarousel.size.cast<int>());
|
Renderer::pushClipRect(Vector2i((int)clipPos.x(), (int)clipPos.y()), Vector2i((int)mCarousel.size.x(), (int)mCarousel.size.y()));
|
||||||
|
|
||||||
Renderer::setMatrix(carouselTrans);
|
Renderer::setMatrix(carouselTrans);
|
||||||
Renderer::drawRect(0.0, 0.0, mCarousel.size.x(), mCarousel.size.y(), mCarousel.color);
|
Renderer::drawRect(0.0, 0.0, mCarousel.size.x(), mCarousel.size.y(), mCarousel.color);
|
||||||
|
|
||||||
// draw logos
|
// draw logos
|
||||||
Eigen::Vector2f logoSpacing(0.0, 0.0); // NB: logoSpacing will include the size of the logo itself as well!
|
Vector2f logoSpacing(0.0, 0.0); // NB: logoSpacing will include the size of the logo itself as well!
|
||||||
float xOff = 0.0;
|
float xOff = 0.0;
|
||||||
float yOff = 0.0;
|
float yOff = 0.0;
|
||||||
|
|
||||||
|
@ -483,8 +483,8 @@ void SystemView::renderCarousel(const Eigen::Affine3f& trans)
|
||||||
while (index >= (int)mEntries.size())
|
while (index >= (int)mEntries.size())
|
||||||
index -= mEntries.size();
|
index -= mEntries.size();
|
||||||
|
|
||||||
Eigen::Affine3f logoTrans = carouselTrans;
|
Transform4x4f logoTrans = carouselTrans;
|
||||||
logoTrans.translate(Eigen::Vector3f(i * logoSpacing[0] + xOff, i * logoSpacing[1] + yOff, 0));
|
logoTrans.translate(Vector3f(i * logoSpacing[0] + xOff, i * logoSpacing[1] + yOff, 0));
|
||||||
|
|
||||||
float distance = i - mCamOffset;
|
float distance = i - mCamOffset;
|
||||||
|
|
||||||
|
@ -507,21 +507,21 @@ void SystemView::renderCarousel(const Eigen::Affine3f& trans)
|
||||||
Renderer::popClipRect();
|
Renderer::popClipRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SystemView::renderInfoBar(const Eigen::Affine3f& trans)
|
void SystemView::renderInfoBar(const Transform4x4f& trans)
|
||||||
{
|
{
|
||||||
Renderer::setMatrix(trans);
|
Renderer::setMatrix(trans);
|
||||||
mSystemInfo.render(trans);
|
mSystemInfo.render(trans);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw background extras
|
// Draw background extras
|
||||||
void SystemView::renderExtras(const Eigen::Affine3f& trans, float lower, float upper)
|
void SystemView::renderExtras(const Transform4x4f& trans, float lower, float upper)
|
||||||
{
|
{
|
||||||
int extrasCenter = (int)mExtrasCamOffset;
|
int extrasCenter = (int)mExtrasCamOffset;
|
||||||
|
|
||||||
// Adding texture loading buffers depending on scrolling speed and status
|
// Adding texture loading buffers depending on scrolling speed and status
|
||||||
int bufferIndex = getScrollingVelocity() + 1;
|
int bufferIndex = getScrollingVelocity() + 1;
|
||||||
|
|
||||||
Renderer::pushClipRect(Eigen::Vector2i::Zero(), mSize.cast<int>());
|
Renderer::pushClipRect(Vector2i::Zero(), Vector2i((int)mSize.x(), (int)mSize.y()));
|
||||||
|
|
||||||
for (int i = extrasCenter + logoBuffersLeft[bufferIndex]; i <= extrasCenter + logoBuffersRight[bufferIndex]; i++)
|
for (int i = extrasCenter + logoBuffersLeft[bufferIndex]; i <= extrasCenter + logoBuffersRight[bufferIndex]; i++)
|
||||||
{
|
{
|
||||||
|
@ -534,14 +534,14 @@ void SystemView::renderExtras(const Eigen::Affine3f& trans, float lower, float u
|
||||||
//Only render selected system when not showing
|
//Only render selected system when not showing
|
||||||
if (mShowing || index == mCursor)
|
if (mShowing || index == mCursor)
|
||||||
{
|
{
|
||||||
Eigen::Affine3f extrasTrans = trans;
|
Transform4x4f extrasTrans = trans;
|
||||||
if (mCarousel.type == HORIZONTAL)
|
if (mCarousel.type == HORIZONTAL)
|
||||||
extrasTrans.translate(Eigen::Vector3f((i - mExtrasCamOffset) * mSize.x(), 0, 0));
|
extrasTrans.translate(Vector3f((i - mExtrasCamOffset) * mSize.x(), 0, 0));
|
||||||
else
|
else
|
||||||
extrasTrans.translate(Eigen::Vector3f(0, (i - mExtrasCamOffset) * mSize.y(), 0));
|
extrasTrans.translate(Vector3f(0, (i - mExtrasCamOffset) * mSize.y(), 0));
|
||||||
|
|
||||||
Renderer::pushClipRect(Eigen::Vector2i(extrasTrans.translation()[0], extrasTrans.translation()[1]),
|
Renderer::pushClipRect(Vector2i((int)extrasTrans.translation()[0], (int)extrasTrans.translation()[1]),
|
||||||
mSize.cast<int>());
|
Vector2i((int)mSize.x(), (int)mSize.y()));
|
||||||
SystemViewData data = mEntries.at(index).data;
|
SystemViewData data = mEntries.at(index).data;
|
||||||
for (unsigned int j = 0; j < data.backgroundExtras.size(); j++) {
|
for (unsigned int j = 0; j < data.backgroundExtras.size(); j++) {
|
||||||
GuiComponent *extra = data.backgroundExtras[j];
|
GuiComponent *extra = data.backgroundExtras[j];
|
||||||
|
@ -555,7 +555,7 @@ void SystemView::renderExtras(const Eigen::Affine3f& trans, float lower, float u
|
||||||
Renderer::popClipRect();
|
Renderer::popClipRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SystemView::renderFade(const Eigen::Affine3f& trans)
|
void SystemView::renderFade(const Transform4x4f& trans)
|
||||||
{
|
{
|
||||||
// fade extras if necessary
|
// fade extras if necessary
|
||||||
if (mExtrasFadeOpacity)
|
if (mExtrasFadeOpacity)
|
||||||
|
@ -610,17 +610,17 @@ void SystemView::getCarouselFromTheme(const ThemeData::ThemeElement* elem)
|
||||||
mCarousel.type = HORIZONTAL;
|
mCarousel.type = HORIZONTAL;
|
||||||
}
|
}
|
||||||
if (elem->has("size"))
|
if (elem->has("size"))
|
||||||
mCarousel.size = elem->get<Eigen::Vector2f>("size").cwiseProduct(mSize);
|
mCarousel.size = elem->get<Vector2f>("size") * mSize;
|
||||||
if (elem->has("pos"))
|
if (elem->has("pos"))
|
||||||
mCarousel.pos = elem->get<Eigen::Vector2f>("pos").cwiseProduct(mSize);
|
mCarousel.pos = elem->get<Vector2f>("pos") * mSize;
|
||||||
if (elem->has("origin"))
|
if (elem->has("origin"))
|
||||||
mCarousel.origin = elem->get<Eigen::Vector2f>("origin");
|
mCarousel.origin = elem->get<Vector2f>("origin");
|
||||||
if (elem->has("color"))
|
if (elem->has("color"))
|
||||||
mCarousel.color = elem->get<unsigned int>("color");
|
mCarousel.color = elem->get<unsigned int>("color");
|
||||||
if (elem->has("logoScale"))
|
if (elem->has("logoScale"))
|
||||||
mCarousel.logoScale = elem->get<float>("logoScale");
|
mCarousel.logoScale = elem->get<float>("logoScale");
|
||||||
if (elem->has("logoSize"))
|
if (elem->has("logoSize"))
|
||||||
mCarousel.logoSize = elem->get<Eigen::Vector2f>("logoSize").cwiseProduct(mSize);
|
mCarousel.logoSize = elem->get<Vector2f>("logoSize") * mSize;
|
||||||
if (elem->has("maxLogoCount"))
|
if (elem->has("maxLogoCount"))
|
||||||
mCarousel.maxLogoCount = (int) std::round(elem->get<float>("maxLogoCount"));
|
mCarousel.maxLogoCount = (int) std::round(elem->get<float>("maxLogoCount"));
|
||||||
if (elem->has("zIndex"))
|
if (elem->has("zIndex"))
|
||||||
|
@ -628,7 +628,7 @@ void SystemView::getCarouselFromTheme(const ThemeData::ThemeElement* elem)
|
||||||
if (elem->has("logoRotation"))
|
if (elem->has("logoRotation"))
|
||||||
mCarousel.logoRotation = elem->get<float>("logoRotation");
|
mCarousel.logoRotation = elem->get<float>("logoRotation");
|
||||||
if (elem->has("logoRotationOrigin"))
|
if (elem->has("logoRotationOrigin"))
|
||||||
mCarousel.logoRotationOrigin = elem->get<Eigen::Vector2f>("logoRotationOrigin");
|
mCarousel.logoRotationOrigin = elem->get<Vector2f>("logoRotationOrigin");
|
||||||
if (elem->has("logoAlignment"))
|
if (elem->has("logoAlignment"))
|
||||||
{
|
{
|
||||||
if (!(elem->get<std::string>("logoAlignment").compare("left")))
|
if (!(elem->get<std::string>("logoAlignment").compare("left")))
|
||||||
|
|
|
@ -26,16 +26,16 @@ struct SystemViewData
|
||||||
struct SystemViewCarousel
|
struct SystemViewCarousel
|
||||||
{
|
{
|
||||||
CarouselType type;
|
CarouselType type;
|
||||||
Eigen::Vector2f pos;
|
Vector2f pos;
|
||||||
Eigen::Vector2f size;
|
Vector2f size;
|
||||||
Eigen::Vector2f origin;
|
Vector2f origin;
|
||||||
float logoScale;
|
float logoScale;
|
||||||
float logoRotation;
|
float logoRotation;
|
||||||
Eigen::Vector2f logoRotationOrigin;
|
Vector2f logoRotationOrigin;
|
||||||
Alignment logoAlignment;
|
Alignment logoAlignment;
|
||||||
unsigned int color;
|
unsigned int color;
|
||||||
int maxLogoCount; // number of logos shown on the carousel
|
int maxLogoCount; // number of logos shown on the carousel
|
||||||
Eigen::Vector2f logoSize;
|
Vector2f logoSize;
|
||||||
float zIndex;
|
float zIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ public:
|
||||||
|
|
||||||
bool input(InputConfig* config, Input input) override;
|
bool input(InputConfig* config, Input input) override;
|
||||||
void update(int deltaTime) override;
|
void update(int deltaTime) override;
|
||||||
void render(const Eigen::Affine3f& parentTrans) override;
|
void render(const Transform4x4f& parentTrans) override;
|
||||||
|
|
||||||
void onThemeChanged(const std::shared_ptr<ThemeData>& theme);
|
void onThemeChanged(const std::shared_ptr<ThemeData>& theme);
|
||||||
|
|
||||||
|
@ -67,10 +67,10 @@ private:
|
||||||
void getDefaultElements(void);
|
void getDefaultElements(void);
|
||||||
void getCarouselFromTheme(const ThemeData::ThemeElement* elem);
|
void getCarouselFromTheme(const ThemeData::ThemeElement* elem);
|
||||||
|
|
||||||
void renderCarousel(const Eigen::Affine3f& parentTrans);
|
void renderCarousel(const Transform4x4f& parentTrans);
|
||||||
void renderExtras(const Eigen::Affine3f& parentTrans, float lower, float upper);
|
void renderExtras(const Transform4x4f& parentTrans, float lower, float upper);
|
||||||
void renderInfoBar(const Eigen::Affine3f& trans);
|
void renderInfoBar(const Transform4x4f& trans);
|
||||||
void renderFade(const Eigen::Affine3f& trans);
|
void renderFade(const Transform4x4f& trans);
|
||||||
|
|
||||||
|
|
||||||
SystemViewCarousel mCarousel;
|
SystemViewCarousel mCarousel;
|
||||||
|
|
|
@ -30,7 +30,7 @@ void ViewController::init(Window* window)
|
||||||
}
|
}
|
||||||
|
|
||||||
ViewController::ViewController(Window* window)
|
ViewController::ViewController(Window* window)
|
||||||
: GuiComponent(window), mCurrentView(nullptr), mCamera(Eigen::Affine3f::Identity()), mFadeOpacity(0), mLockInput(false)
|
: GuiComponent(window), mCurrentView(nullptr), mCamera(Transform4x4f::Identity()), mFadeOpacity(0), mLockInput(false)
|
||||||
{
|
{
|
||||||
mState.viewing = NOTHING;
|
mState.viewing = NOTHING;
|
||||||
mCurUIMode = Settings::getInstance()->getString("UIMode");
|
mCurUIMode = Settings::getInstance()->getString("UIMode");
|
||||||
|
@ -133,7 +133,7 @@ void ViewController::goToGameList(SystemData* system)
|
||||||
|
|
||||||
void ViewController::playViewTransition()
|
void ViewController::playViewTransition()
|
||||||
{
|
{
|
||||||
Eigen::Vector3f target(Eigen::Vector3f::Identity());
|
Vector3f target(Vector3f::Zero());
|
||||||
if(mCurrentView)
|
if(mCurrentView)
|
||||||
target = mCurrentView->getPosition();
|
target = mCurrentView->getPosition();
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ void ViewController::onFileChanged(FileData* file, FileChangeType change)
|
||||||
it->second->onFileChanged(file, change);
|
it->second->onFileChanged(file, change);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewController::launch(FileData* game, Eigen::Vector3f center)
|
void ViewController::launch(FileData* game, Vector3f center)
|
||||||
{
|
{
|
||||||
if(game->getType() != GAME)
|
if(game->getType() != GAME)
|
||||||
{
|
{
|
||||||
|
@ -204,7 +204,7 @@ void ViewController::launch(FileData* game, Eigen::Vector3f center)
|
||||||
if (mCurrentView)
|
if (mCurrentView)
|
||||||
mCurrentView->onHide();
|
mCurrentView->onHide();
|
||||||
|
|
||||||
Eigen::Affine3f origCamera = mCamera;
|
Transform4x4f origCamera = mCamera;
|
||||||
origCamera.translation() = -mCurrentView->getPosition();
|
origCamera.translation() = -mCurrentView->getPosition();
|
||||||
|
|
||||||
center += mCurrentView->getPosition();
|
center += mCurrentView->getPosition();
|
||||||
|
@ -369,13 +369,14 @@ void ViewController::update(int deltaTime)
|
||||||
updateSelf(deltaTime);
|
updateSelf(deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewController::render(const Eigen::Affine3f& parentTrans)
|
void ViewController::render(const Transform4x4f& parentTrans)
|
||||||
{
|
{
|
||||||
Eigen::Affine3f trans = mCamera * parentTrans;
|
Transform4x4f trans = mCamera * parentTrans;
|
||||||
|
Transform4x4f transInverse = trans.inverse();
|
||||||
|
|
||||||
// camera position, position + size
|
// camera position, position + size
|
||||||
Eigen::Vector3f viewStart = trans.inverse().translation();
|
Vector3f viewStart = transInverse.translation();
|
||||||
Eigen::Vector3f viewEnd = trans.inverse() * Eigen::Vector3f((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight(), 0);
|
Vector3f viewEnd = transInverse * Vector3f((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight(), 0);
|
||||||
|
|
||||||
// Keep track of UI mode changes.
|
// Keep track of UI mode changes.
|
||||||
monitorUIMode();
|
monitorUIMode();
|
||||||
|
@ -387,8 +388,8 @@ void ViewController::render(const Eigen::Affine3f& parentTrans)
|
||||||
for(auto it = mGameListViews.begin(); it != mGameListViews.end(); it++)
|
for(auto it = mGameListViews.begin(); it != mGameListViews.end(); it++)
|
||||||
{
|
{
|
||||||
// clipping
|
// clipping
|
||||||
Eigen::Vector3f guiStart = it->second->getPosition();
|
Vector3f guiStart = it->second->getPosition();
|
||||||
Eigen::Vector3f guiEnd = it->second->getPosition() + Eigen::Vector3f(it->second->getSize().x(), it->second->getSize().y(), 0);
|
Vector3f guiEnd = it->second->getPosition() + Vector3f(it->second->getSize().x(), it->second->getSize().y(), 0);
|
||||||
|
|
||||||
if(guiEnd.x() >= viewStart.x() && guiEnd.y() >= viewStart.y() &&
|
if(guiEnd.x() >= viewStart.x() && guiEnd.y() >= viewStart.y() &&
|
||||||
guiStart.x() <= viewEnd.x() && guiStart.y() <= viewEnd.y())
|
guiStart.x() <= viewEnd.x() && guiStart.y() <= viewEnd.y())
|
||||||
|
|
|
@ -41,11 +41,11 @@ public:
|
||||||
|
|
||||||
// Plays a nice launch effect and launches the game at the end of it.
|
// Plays a nice launch effect and launches the game at the end of it.
|
||||||
// Once the game terminates, plays a return effect.
|
// Once the game terminates, plays a return effect.
|
||||||
void launch(FileData* game, Eigen::Vector3f centerCameraOn = Eigen::Vector3f(Renderer::getScreenWidth() / 2.0f, Renderer::getScreenHeight() / 2.0f, 0));
|
void launch(FileData* game, Vector3f centerCameraOn = Vector3f(Renderer::getScreenWidth() / 2.0f, Renderer::getScreenHeight() / 2.0f, 0));
|
||||||
|
|
||||||
bool input(InputConfig* config, Input input) override;
|
bool input(InputConfig* config, Input input) override;
|
||||||
void update(int deltaTime) override;
|
void update(int deltaTime) override;
|
||||||
void render(const Eigen::Affine3f& parentTrans) override;
|
void render(const Transform4x4f& parentTrans) override;
|
||||||
|
|
||||||
enum ViewMode
|
enum ViewMode
|
||||||
{
|
{
|
||||||
|
@ -95,7 +95,7 @@ private:
|
||||||
std::map< SystemData*, std::shared_ptr<IGameListView> > mGameListViews;
|
std::map< SystemData*, std::shared_ptr<IGameListView> > mGameListViews;
|
||||||
std::shared_ptr<SystemView> mSystemListView;
|
std::shared_ptr<SystemView> mSystemListView;
|
||||||
|
|
||||||
Eigen::Affine3f mCamera;
|
Transform4x4f mCamera;
|
||||||
float mFadeOpacity;
|
float mFadeOpacity;
|
||||||
bool mLockInput;
|
bool mLockInput;
|
||||||
|
|
||||||
|
|
|
@ -116,8 +116,6 @@ void DetailedGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& them
|
||||||
|
|
||||||
void DetailedGameListView::initMDLabels()
|
void DetailedGameListView::initMDLabels()
|
||||||
{
|
{
|
||||||
using namespace Eigen;
|
|
||||||
|
|
||||||
std::vector<TextComponent*> components = getMDLabels();
|
std::vector<TextComponent*> components = getMDLabels();
|
||||||
|
|
||||||
const unsigned int colCount = 2;
|
const unsigned int colCount = 2;
|
||||||
|
@ -149,8 +147,6 @@ void DetailedGameListView::initMDLabels()
|
||||||
|
|
||||||
void DetailedGameListView::initMDValues()
|
void DetailedGameListView::initMDValues()
|
||||||
{
|
{
|
||||||
using namespace Eigen;
|
|
||||||
|
|
||||||
std::vector<TextComponent*> labels = getMDLabels();
|
std::vector<TextComponent*> labels = getMDLabels();
|
||||||
std::vector<GuiComponent*> values = getMDValues();
|
std::vector<GuiComponent*> values = getMDValues();
|
||||||
|
|
||||||
|
@ -241,9 +237,9 @@ void DetailedGameListView::updateInfoPanel()
|
||||||
|
|
||||||
void DetailedGameListView::launch(FileData* game)
|
void DetailedGameListView::launch(FileData* game)
|
||||||
{
|
{
|
||||||
Eigen::Vector3f target(Renderer::getScreenWidth() / 2.0f, Renderer::getScreenHeight() / 2.0f, 0);
|
Vector3f target(Renderer::getScreenWidth() / 2.0f, Renderer::getScreenHeight() / 2.0f, 0);
|
||||||
if(mImage.hasImage())
|
if(mImage.hasImage())
|
||||||
target << mImage.getCenter().x(), mImage.getCenter().y(), 0;
|
target = Vector3f(mImage.getCenter().x(), mImage.getCenter().y(), 0);
|
||||||
|
|
||||||
ViewController::get()->launch(game, target);
|
ViewController::get()->launch(game, target);
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,15 +42,15 @@ HelpStyle IGameListView::getHelpStyle()
|
||||||
return style;
|
return style;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IGameListView::render(const Eigen::Affine3f& parentTrans)
|
void IGameListView::render(const Transform4x4f& parentTrans)
|
||||||
{
|
{
|
||||||
Eigen::Affine3f trans = parentTrans * getTransform();
|
Transform4x4f trans = parentTrans * getTransform();
|
||||||
|
|
||||||
float scaleX = trans.linear()(0,0);
|
float scaleX = trans[0];
|
||||||
float scaleY = trans.linear()(1,1);
|
float scaleY = trans[5];
|
||||||
|
|
||||||
Eigen::Vector2i pos(trans.translation()[0], trans.translation()[1]);
|
Vector2i pos(trans.translation()[0], trans.translation()[1]);
|
||||||
Eigen::Vector2i size(mSize.x() * scaleX, mSize.y() * scaleY);
|
Vector2i size(mSize.x() * scaleX, mSize.y() * scaleY);
|
||||||
|
|
||||||
Renderer::pushClipRect(pos, size);
|
Renderer::pushClipRect(pos, size);
|
||||||
renderChildren(trans);
|
renderChildren(trans);
|
||||||
|
|
|
@ -39,7 +39,7 @@ public:
|
||||||
|
|
||||||
virtual HelpStyle getHelpStyle() override;
|
virtual HelpStyle getHelpStyle() override;
|
||||||
|
|
||||||
void render(const Eigen::Affine3f& parentTrans) override;
|
void render(const Transform4x4f& parentTrans) override;
|
||||||
protected:
|
protected:
|
||||||
FileData* mRoot;
|
FileData* mRoot;
|
||||||
std::shared_ptr<ThemeData> mTheme;
|
std::shared_ptr<ThemeData> mTheme;
|
||||||
|
|
|
@ -154,8 +154,6 @@ void VideoGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& theme)
|
||||||
|
|
||||||
void VideoGameListView::initMDLabels()
|
void VideoGameListView::initMDLabels()
|
||||||
{
|
{
|
||||||
using namespace Eigen;
|
|
||||||
|
|
||||||
std::vector<TextComponent*> components = getMDLabels();
|
std::vector<TextComponent*> components = getMDLabels();
|
||||||
|
|
||||||
const unsigned int colCount = 2;
|
const unsigned int colCount = 2;
|
||||||
|
@ -187,8 +185,6 @@ void VideoGameListView::initMDLabels()
|
||||||
|
|
||||||
void VideoGameListView::initMDValues()
|
void VideoGameListView::initMDValues()
|
||||||
{
|
{
|
||||||
using namespace Eigen;
|
|
||||||
|
|
||||||
std::vector<TextComponent*> labels = getMDLabels();
|
std::vector<TextComponent*> labels = getMDLabels();
|
||||||
std::vector<GuiComponent*> values = getMDValues();
|
std::vector<GuiComponent*> values = getMDValues();
|
||||||
|
|
||||||
|
@ -301,30 +297,30 @@ void VideoGameListView::launch(FileData* game)
|
||||||
float screenWidth = (float) Renderer::getScreenWidth();
|
float screenWidth = (float) Renderer::getScreenWidth();
|
||||||
float screenHeight = (float) Renderer::getScreenHeight();
|
float screenHeight = (float) Renderer::getScreenHeight();
|
||||||
|
|
||||||
Eigen::Vector3f target(screenWidth / 2.0f, screenHeight / 2.0f, 0);
|
Vector3f target(screenWidth / 2.0f, screenHeight / 2.0f, 0);
|
||||||
|
|
||||||
if(mMarquee.hasImage() &&
|
if(mMarquee.hasImage() &&
|
||||||
(mMarquee.getPosition().x() < screenWidth && mMarquee.getPosition().x() > 0.0f &&
|
(mMarquee.getPosition().x() < screenWidth && mMarquee.getPosition().x() > 0.0f &&
|
||||||
mMarquee.getPosition().y() < screenHeight && mMarquee.getPosition().y() > 0.0f))
|
mMarquee.getPosition().y() < screenHeight && mMarquee.getPosition().y() > 0.0f))
|
||||||
{
|
{
|
||||||
target << mMarquee.getCenter().x(), mMarquee.getCenter().y(), 0;
|
target = Vector3f(mMarquee.getCenter().x(), mMarquee.getCenter().y(), 0);
|
||||||
}
|
}
|
||||||
else if(mImage.hasImage() &&
|
else if(mImage.hasImage() &&
|
||||||
(mImage.getPosition().x() < screenWidth && mImage.getPosition().x() > 2.0f &&
|
(mImage.getPosition().x() < screenWidth && mImage.getPosition().x() > 2.0f &&
|
||||||
mImage.getPosition().y() < screenHeight && mImage.getPosition().y() > 2.0f))
|
mImage.getPosition().y() < screenHeight && mImage.getPosition().y() > 2.0f))
|
||||||
{
|
{
|
||||||
target << mImage.getCenter().x(), mImage.getCenter().y(), 0;
|
target = Vector3f(mImage.getCenter().x(), mImage.getCenter().y(), 0);
|
||||||
}
|
}
|
||||||
else if(mHeaderImage.hasImage() &&
|
else if(mHeaderImage.hasImage() &&
|
||||||
(mHeaderImage.getPosition().x() < screenWidth && mHeaderImage.getPosition().x() > 0.0f &&
|
(mHeaderImage.getPosition().x() < screenWidth && mHeaderImage.getPosition().x() > 0.0f &&
|
||||||
mHeaderImage.getPosition().y() < screenHeight && mHeaderImage.getPosition().y() > 0.0f))
|
mHeaderImage.getPosition().y() < screenHeight && mHeaderImage.getPosition().y() > 0.0f))
|
||||||
{
|
{
|
||||||
target << mHeaderImage.getCenter().x(), mHeaderImage.getCenter().y(), 0;
|
target = Vector3f(mHeaderImage.getCenter().x(), mHeaderImage.getCenter().y(), 0);
|
||||||
}
|
}
|
||||||
else if(mVideo->getPosition().x() < screenWidth && mVideo->getPosition().x() > 0.0f &&
|
else if(mVideo->getPosition().x() < screenWidth && mVideo->getPosition().x() > 0.0f &&
|
||||||
mVideo->getPosition().y() < screenHeight && mVideo->getPosition().y() > 0.0f)
|
mVideo->getPosition().y() < screenHeight && mVideo->getPosition().y() > 0.0f)
|
||||||
{
|
{
|
||||||
target << mVideo->getCenter().x(), mVideo->getCenter().y(), 0;
|
target = Vector3f(mVideo->getCenter().x(), mVideo->getCenter().y(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ViewController::get()->launch(game, target);
|
ViewController::get()->launch(game, target);
|
||||||
|
|
|
@ -4,10 +4,12 @@
|
||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
#include "animations/AnimationController.h"
|
#include "animations/AnimationController.h"
|
||||||
#include "ThemeData.h"
|
#include "ThemeData.h"
|
||||||
|
#include "math/Rotation3x3f.h"
|
||||||
|
#include "math/Scale3x3f.h"
|
||||||
|
|
||||||
GuiComponent::GuiComponent(Window* window) : mWindow(window), mParent(NULL), mOpacity(255),
|
GuiComponent::GuiComponent(Window* window) : mWindow(window), mParent(NULL), mOpacity(255),
|
||||||
mPosition(Eigen::Vector3f::Zero()), mOrigin(Eigen::Vector2f::Zero()), mRotationOrigin(0.5, 0.5),
|
mPosition(Vector3f::Zero()), mOrigin(Vector2f::Zero()), mRotationOrigin(0.5, 0.5),
|
||||||
mSize(Eigen::Vector2f::Zero()), mTransform(Eigen::Affine3f::Identity()), mIsProcessing(false)
|
mSize(Vector2f::Zero()), mTransform(Transform4x4f::Identity()), mIsProcessing(false)
|
||||||
{
|
{
|
||||||
for(unsigned char i = 0; i < MAX_ANIMATIONS; i++)
|
for(unsigned char i = 0; i < MAX_ANIMATIONS; i++)
|
||||||
mAnimationMap[i] = NULL;
|
mAnimationMap[i] = NULL;
|
||||||
|
@ -57,13 +59,13 @@ void GuiComponent::update(int deltaTime)
|
||||||
updateChildren(deltaTime);
|
updateChildren(deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiComponent::render(const Eigen::Affine3f& parentTrans)
|
void GuiComponent::render(const Transform4x4f& parentTrans)
|
||||||
{
|
{
|
||||||
Eigen::Affine3f trans = parentTrans * getTransform();
|
Transform4x4f trans = parentTrans * getTransform();
|
||||||
renderChildren(trans);
|
renderChildren(trans);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiComponent::renderChildren(const Eigen::Affine3f& transform) const
|
void GuiComponent::renderChildren(const Transform4x4f& transform) const
|
||||||
{
|
{
|
||||||
for(unsigned int i = 0; i < getChildCount(); i++)
|
for(unsigned int i = 0; i < getChildCount(); i++)
|
||||||
{
|
{
|
||||||
|
@ -71,46 +73,46 @@ void GuiComponent::renderChildren(const Eigen::Affine3f& transform) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Eigen::Vector3f GuiComponent::getPosition() const
|
Vector3f GuiComponent::getPosition() const
|
||||||
{
|
{
|
||||||
return mPosition;
|
return mPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiComponent::setPosition(float x, float y, float z)
|
void GuiComponent::setPosition(float x, float y, float z)
|
||||||
{
|
{
|
||||||
mPosition << x, y, z;
|
mPosition = Vector3f(x, y, z);
|
||||||
onPositionChanged();
|
onPositionChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
Eigen::Vector2f GuiComponent::getOrigin() const
|
Vector2f GuiComponent::getOrigin() const
|
||||||
{
|
{
|
||||||
return mOrigin;
|
return mOrigin;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiComponent::setOrigin(float x, float y)
|
void GuiComponent::setOrigin(float x, float y)
|
||||||
{
|
{
|
||||||
mOrigin << x, y;
|
mOrigin = Vector2f(x, y);
|
||||||
onOriginChanged();
|
onOriginChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
Eigen::Vector2f GuiComponent::getRotationOrigin() const
|
Vector2f GuiComponent::getRotationOrigin() const
|
||||||
{
|
{
|
||||||
return mRotationOrigin;
|
return mRotationOrigin;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiComponent::setRotationOrigin(float x, float y)
|
void GuiComponent::setRotationOrigin(float x, float y)
|
||||||
{
|
{
|
||||||
mRotationOrigin << x, y;;
|
mRotationOrigin = Vector2f(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
Eigen::Vector2f GuiComponent::getSize() const
|
Vector2f GuiComponent::getSize() const
|
||||||
{
|
{
|
||||||
return mSize;
|
return mSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiComponent::setSize(float w, float h)
|
void GuiComponent::setSize(float w, float h)
|
||||||
{
|
{
|
||||||
mSize << w, h;
|
mSize = Vector2f(w, h);
|
||||||
onSizeChanged();
|
onSizeChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,9 +156,9 @@ void GuiComponent::setDefaultZIndex(float z)
|
||||||
mDefaultZIndex = z;
|
mDefaultZIndex = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
Eigen::Vector2f GuiComponent::getCenter() const
|
Vector2f GuiComponent::getCenter() const
|
||||||
{
|
{
|
||||||
return Eigen::Vector2f(mPosition.x() - (getSize().x() * mOrigin.x()) + getSize().x() / 2,
|
return Vector2f(mPosition.x() - (getSize().x() * mOrigin.x()) + getSize().x() / 2,
|
||||||
mPosition.y() - (getSize().y() * mOrigin.y()) + getSize().y() / 2);
|
mPosition.y() - (getSize().y() * mOrigin.y()) + getSize().y() / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,13 +241,13 @@ void GuiComponent::setOpacity(unsigned char opacity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const Eigen::Affine3f& GuiComponent::getTransform()
|
const Transform4x4f& GuiComponent::getTransform()
|
||||||
{
|
{
|
||||||
mTransform.setIdentity();
|
mTransform = Transform4x4f::Identity();
|
||||||
mTransform.translate(mPosition);
|
mTransform.translate(mPosition);
|
||||||
if (mScale != 1.0)
|
if (mScale != 1.0)
|
||||||
{
|
{
|
||||||
mTransform *= Eigen::Scaling(mScale);
|
mTransform *= Scale3x3f(mScale);
|
||||||
}
|
}
|
||||||
if (mRotation != 0.0)
|
if (mRotation != 0.0)
|
||||||
{
|
{
|
||||||
|
@ -255,16 +257,16 @@ const Eigen::Affine3f& GuiComponent::getTransform()
|
||||||
|
|
||||||
// transform to offset point
|
// transform to offset point
|
||||||
if (xOff != 0.0 || yOff != 0.0)
|
if (xOff != 0.0 || yOff != 0.0)
|
||||||
mTransform.translate(Eigen::Vector3f(xOff * -1, yOff * -1, 0.0f));
|
mTransform.translate(Vector3f(xOff * -1, yOff * -1, 0.0f));
|
||||||
|
|
||||||
// apply rotation transorm
|
// apply rotation transorm
|
||||||
mTransform *= Eigen::AngleAxisf(mRotation, Eigen::Vector3f::UnitZ());
|
mTransform *= Rotation3x3f(mRotation, Vector3f::UnitZ());
|
||||||
|
|
||||||
// Tranform back to original point
|
// Tranform back to original point
|
||||||
if (xOff != 0.0 || yOff != 0.0)
|
if (xOff != 0.0 || yOff != 0.0)
|
||||||
mTransform.translate(Eigen::Vector3f(xOff, yOff, 0.0f));
|
mTransform.translate(Vector3f(xOff, yOff, 0.0f));
|
||||||
}
|
}
|
||||||
mTransform.translate(Eigen::Vector3f(mOrigin.x() * mSize.x() * -1, mOrigin.y() * mSize.y() * -1, 0.0f));
|
mTransform.translate(Vector3f(mOrigin.x() * mSize.x() * -1, mOrigin.y() * mSize.y() * -1, 0.0f));
|
||||||
return mTransform;
|
return mTransform;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,7 +391,7 @@ int GuiComponent::getAnimationTime(unsigned char slot) const
|
||||||
|
|
||||||
void GuiComponent::applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view, const std::string& element, unsigned int properties)
|
void GuiComponent::applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view, const std::string& element, unsigned int properties)
|
||||||
{
|
{
|
||||||
Eigen::Vector2f scale = getParent() ? getParent()->getSize() : Eigen::Vector2f((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight());
|
Vector2f scale = getParent() ? getParent()->getSize() : Vector2f((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight());
|
||||||
|
|
||||||
const ThemeData::ThemeElement* elem = theme->getElement(view, element, "");
|
const ThemeData::ThemeElement* elem = theme->getElement(view, element, "");
|
||||||
if(!elem)
|
if(!elem)
|
||||||
|
@ -398,22 +400,22 @@ void GuiComponent::applyTheme(const std::shared_ptr<ThemeData>& theme, const std
|
||||||
using namespace ThemeFlags;
|
using namespace ThemeFlags;
|
||||||
if(properties & POSITION && elem->has("pos"))
|
if(properties & POSITION && elem->has("pos"))
|
||||||
{
|
{
|
||||||
Eigen::Vector2f denormalized = elem->get<Eigen::Vector2f>("pos").cwiseProduct(scale);
|
Vector2f denormalized = elem->get<Vector2f>("pos") * scale;
|
||||||
setPosition(Eigen::Vector3f(denormalized.x(), denormalized.y(), 0));
|
setPosition(Vector3f(denormalized.x(), denormalized.y(), 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(properties & ThemeFlags::SIZE && elem->has("size"))
|
if(properties & ThemeFlags::SIZE && elem->has("size"))
|
||||||
setSize(elem->get<Eigen::Vector2f>("size").cwiseProduct(scale));
|
setSize(elem->get<Vector2f>("size") * scale);
|
||||||
|
|
||||||
// position + size also implies origin
|
// position + size also implies origin
|
||||||
if((properties & ORIGIN || (properties & POSITION && properties & ThemeFlags::SIZE)) && elem->has("origin"))
|
if((properties & ORIGIN || (properties & POSITION && properties & ThemeFlags::SIZE)) && elem->has("origin"))
|
||||||
setOrigin(elem->get<Eigen::Vector2f>("origin"));
|
setOrigin(elem->get<Vector2f>("origin"));
|
||||||
|
|
||||||
if(properties & ThemeFlags::ROTATION) {
|
if(properties & ThemeFlags::ROTATION) {
|
||||||
if(elem->has("rotation"))
|
if(elem->has("rotation"))
|
||||||
setRotationDegrees(elem->get<float>("rotation"));
|
setRotationDegrees(elem->get<float>("rotation"));
|
||||||
if(elem->has("rotationOrigin"))
|
if(elem->has("rotationOrigin"))
|
||||||
setRotationOrigin(elem->get<Eigen::Vector2f>("rotationOrigin"));
|
setRotationOrigin(elem->get<Vector2f>("rotationOrigin"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(properties & ThemeFlags::Z_INDEX && elem->has("zIndex"))
|
if(properties & ThemeFlags::Z_INDEX && elem->has("zIndex"))
|
||||||
|
|
|
@ -3,8 +3,9 @@
|
||||||
#include "InputConfig.h"
|
#include "InputConfig.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <Eigen/Dense>
|
#include <functional>
|
||||||
#include "HelpStyle.h"
|
#include "HelpStyle.h"
|
||||||
|
#include "math/Transform4x4f.h"
|
||||||
|
|
||||||
class Window;
|
class Window;
|
||||||
class Animation;
|
class Animation;
|
||||||
|
@ -31,30 +32,30 @@ public:
|
||||||
|
|
||||||
//Called when it's time to render. By default, just calls renderChildren(parentTrans * getTransform()).
|
//Called when it's time to render. By default, just calls renderChildren(parentTrans * getTransform()).
|
||||||
//You probably want to override this like so:
|
//You probably want to override this like so:
|
||||||
//1. Calculate the new transform that your control will draw at with Eigen::Affine3f t = parentTrans * getTransform().
|
//1. Calculate the new transform that your control will draw at with Transform4x4f t = parentTrans * getTransform().
|
||||||
//2. Set the renderer to use that new transform as the model matrix - Renderer::setMatrix(t);
|
//2. Set the renderer to use that new transform as the model matrix - Renderer::setMatrix(t);
|
||||||
//3. Draw your component.
|
//3. Draw your component.
|
||||||
//4. Tell your children to render, based on your component's transform - renderChildren(t).
|
//4. Tell your children to render, based on your component's transform - renderChildren(t).
|
||||||
virtual void render(const Eigen::Affine3f& parentTrans);
|
virtual void render(const Transform4x4f& parentTrans);
|
||||||
|
|
||||||
Eigen::Vector3f getPosition() const;
|
Vector3f getPosition() const;
|
||||||
inline void setPosition(const Eigen::Vector3f& offset) { setPosition(offset.x(), offset.y(), offset.z()); }
|
inline void setPosition(const Vector3f& offset) { setPosition(offset.x(), offset.y(), offset.z()); }
|
||||||
void setPosition(float x, float y, float z = 0.0f);
|
void setPosition(float x, float y, float z = 0.0f);
|
||||||
virtual void onPositionChanged() {};
|
virtual void onPositionChanged() {};
|
||||||
|
|
||||||
//Sets the origin as a percentage of this image (e.g. (0, 0) is top left, (0.5, 0.5) is the center)
|
//Sets the origin as a percentage of this image (e.g. (0, 0) is top left, (0.5, 0.5) is the center)
|
||||||
Eigen::Vector2f getOrigin() const;
|
Vector2f getOrigin() const;
|
||||||
void setOrigin(float originX, float originY);
|
void setOrigin(float originX, float originY);
|
||||||
inline void setOrigin(Eigen::Vector2f origin) { setOrigin(origin.x(), origin.y()); }
|
inline void setOrigin(Vector2f origin) { setOrigin(origin.x(), origin.y()); }
|
||||||
virtual void onOriginChanged() {};
|
virtual void onOriginChanged() {};
|
||||||
|
|
||||||
//Sets the rotation origin as a percentage of this image (e.g. (0, 0) is top left, (0.5, 0.5) is the center)
|
//Sets the rotation origin as a percentage of this image (e.g. (0, 0) is top left, (0.5, 0.5) is the center)
|
||||||
Eigen::Vector2f getRotationOrigin() const;
|
Vector2f getRotationOrigin() const;
|
||||||
void setRotationOrigin(float originX, float originY);
|
void setRotationOrigin(float originX, float originY);
|
||||||
inline void setRotationOrigin(Eigen::Vector2f origin) { setRotationOrigin(origin.x(), origin.y()); }
|
inline void setRotationOrigin(Vector2f origin) { setRotationOrigin(origin.x(), origin.y()); }
|
||||||
|
|
||||||
Eigen::Vector2f getSize() const;
|
Vector2f getSize() const;
|
||||||
inline void setSize(const Eigen::Vector2f& size) { setSize(size.x(), size.y()); }
|
inline void setSize(const Vector2f& size) { setSize(size.x(), size.y()); }
|
||||||
void setSize(float w, float h);
|
void setSize(float w, float h);
|
||||||
virtual void onSizeChanged() {};
|
virtual void onSizeChanged() {};
|
||||||
|
|
||||||
|
@ -72,7 +73,7 @@ public:
|
||||||
void setDefaultZIndex(float zIndex);
|
void setDefaultZIndex(float zIndex);
|
||||||
|
|
||||||
// Returns the center point of the image (takes origin into account).
|
// Returns the center point of the image (takes origin into account).
|
||||||
Eigen::Vector2f getCenter() const;
|
Vector2f getCenter() const;
|
||||||
|
|
||||||
void setParent(GuiComponent* parent);
|
void setParent(GuiComponent* parent);
|
||||||
GuiComponent* getParent() const;
|
GuiComponent* getParent() const;
|
||||||
|
@ -99,7 +100,7 @@ public:
|
||||||
virtual unsigned char getOpacity() const;
|
virtual unsigned char getOpacity() const;
|
||||||
virtual void setOpacity(unsigned char opacity);
|
virtual void setOpacity(unsigned char opacity);
|
||||||
|
|
||||||
const Eigen::Affine3f& getTransform();
|
const Transform4x4f& getTransform();
|
||||||
|
|
||||||
virtual std::string getValue() const;
|
virtual std::string getValue() const;
|
||||||
virtual void setValue(const std::string& value);
|
virtual void setValue(const std::string& value);
|
||||||
|
@ -130,7 +131,7 @@ public:
|
||||||
bool isProcessing() const;
|
bool isProcessing() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void renderChildren(const Eigen::Affine3f& transform) const;
|
void renderChildren(const Transform4x4f& transform) const;
|
||||||
void updateSelf(int deltaTime); // updates animations
|
void updateSelf(int deltaTime); // updates animations
|
||||||
void updateChildren(int deltaTime); // updates animations
|
void updateChildren(int deltaTime); // updates animations
|
||||||
|
|
||||||
|
@ -140,10 +141,10 @@ protected:
|
||||||
GuiComponent* mParent;
|
GuiComponent* mParent;
|
||||||
std::vector<GuiComponent*> mChildren;
|
std::vector<GuiComponent*> mChildren;
|
||||||
|
|
||||||
Eigen::Vector3f mPosition;
|
Vector3f mPosition;
|
||||||
Eigen::Vector2f mOrigin;
|
Vector2f mOrigin;
|
||||||
Eigen::Vector2f mRotationOrigin;
|
Vector2f mRotationOrigin;
|
||||||
Eigen::Vector2f mSize;
|
Vector2f mSize;
|
||||||
|
|
||||||
float mRotation = 0.0;
|
float mRotation = 0.0;
|
||||||
float mScale = 1.0;
|
float mScale = 1.0;
|
||||||
|
@ -157,6 +158,6 @@ public:
|
||||||
const static unsigned char MAX_ANIMATIONS = 4;
|
const static unsigned char MAX_ANIMATIONS = 4;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Eigen::Affine3f mTransform; //Don't access this directly! Use getTransform()!
|
Transform4x4f mTransform; //Don't access this directly! Use getTransform()!
|
||||||
AnimationController* mAnimationMap[MAX_ANIMATIONS];
|
AnimationController* mAnimationMap[MAX_ANIMATIONS];
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
HelpStyle::HelpStyle()
|
HelpStyle::HelpStyle()
|
||||||
{
|
{
|
||||||
position = Eigen::Vector2f(Renderer::getScreenWidth() * 0.012f, Renderer::getScreenHeight() * 0.9515f);
|
position = Vector2f(Renderer::getScreenWidth() * 0.012f, Renderer::getScreenHeight() * 0.9515f);
|
||||||
iconColor = 0x777777FF;
|
iconColor = 0x777777FF;
|
||||||
textColor = 0x777777FF;
|
textColor = 0x777777FF;
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ void HelpStyle::applyTheme(const std::shared_ptr<ThemeData>& theme, const std::s
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(elem->has("pos"))
|
if(elem->has("pos"))
|
||||||
position = elem->get<Eigen::Vector2f>("pos").cwiseProduct(Eigen::Vector2f((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight()));
|
position = elem->get<Vector2f>("pos") * Vector2f((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight());
|
||||||
|
|
||||||
if(elem->has("textColor"))
|
if(elem->has("textColor"))
|
||||||
textColor = elem->get<unsigned int>("textColor");
|
textColor = elem->get<unsigned int>("textColor");
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <Eigen/Dense>
|
#include "math/Vector2f.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ class Font;
|
||||||
|
|
||||||
struct HelpStyle
|
struct HelpStyle
|
||||||
{
|
{
|
||||||
Eigen::Vector2f position;
|
Vector2f position;
|
||||||
unsigned int iconColor;
|
unsigned int iconColor;
|
||||||
unsigned int textColor;
|
unsigned int textColor;
|
||||||
std::shared_ptr<Font> font;
|
std::shared_ptr<Font> font;
|
||||||
|
|
|
@ -4,8 +4,9 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include <Eigen/Dense>
|
|
||||||
#include GLHEADER
|
#include GLHEADER
|
||||||
|
#include "math/Transform4x4f.h"
|
||||||
|
#include "math/Vector2i.h"
|
||||||
|
|
||||||
class GuiComponent;
|
class GuiComponent;
|
||||||
class Font;
|
class Font;
|
||||||
|
@ -26,11 +27,10 @@ namespace Renderer
|
||||||
//graphics commands
|
//graphics commands
|
||||||
void swapBuffers();
|
void swapBuffers();
|
||||||
|
|
||||||
void pushClipRect(Eigen::Vector2i pos, Eigen::Vector2i dim);
|
void pushClipRect(Vector2i pos, Vector2i dim);
|
||||||
void popClipRect();
|
void popClipRect();
|
||||||
|
|
||||||
void setMatrix(float* mat);
|
void setMatrix(const Transform4x4f& transform);
|
||||||
void setMatrix(const Eigen::Affine3f& transform);
|
|
||||||
|
|
||||||
void drawRect(int x, int y, int w, int h, unsigned int color, GLenum blend_sfactor = GL_SRC_ALPHA, GLenum blend_dfactor = GL_ONE_MINUS_SRC_ALPHA);
|
void drawRect(int x, int y, int w, int h, unsigned int color, GLenum blend_sfactor = GL_SRC_ALPHA, GLenum blend_dfactor = GL_ONE_MINUS_SRC_ALPHA);
|
||||||
void drawRect(float x, float y, float w, float h, unsigned int color, GLenum blend_sfactor = GL_SRC_ALPHA, GLenum blend_dfactor = GL_ONE_MINUS_SRC_ALPHA);
|
void drawRect(float x, float y, float w, float h, unsigned int color, GLenum blend_sfactor = GL_SRC_ALPHA, GLenum blend_dfactor = GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
|
@ -9,7 +9,16 @@
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
|
||||||
namespace Renderer {
|
namespace Renderer {
|
||||||
std::stack<Eigen::Vector4i> clipStack;
|
struct ClipRect {
|
||||||
|
ClipRect(const int x, const int y, const int w, const int h) :
|
||||||
|
x(x), y(y), w(w), h(h) {};
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
int w;
|
||||||
|
int h;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::stack<ClipRect> clipStack;
|
||||||
|
|
||||||
void setColor4bArray(GLubyte* array, unsigned int color)
|
void setColor4bArray(GLubyte* array, unsigned int color)
|
||||||
{
|
{
|
||||||
|
@ -29,41 +38,41 @@ namespace Renderer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void pushClipRect(Eigen::Vector2i pos, Eigen::Vector2i dim)
|
void pushClipRect(Vector2i pos, Vector2i dim)
|
||||||
{
|
{
|
||||||
Eigen::Vector4i box(pos.x(), pos.y(), dim.x(), dim.y());
|
ClipRect box(pos.x(), pos.y(), dim.x(), dim.y());
|
||||||
if(box[2] == 0)
|
if(box.w == 0)
|
||||||
box[2] = Renderer::getScreenWidth() - box.x();
|
box.w = Renderer::getScreenWidth() - box.x;
|
||||||
if(box[3] == 0)
|
if(box.h == 0)
|
||||||
box[3] = Renderer::getScreenHeight() - box.y();
|
box.h = Renderer::getScreenHeight() - box.y;
|
||||||
|
|
||||||
//glScissor starts at the bottom left of the window
|
//glScissor starts at the bottom left of the window
|
||||||
//so (0, 0, 1, 1) is the bottom left pixel
|
//so (0, 0, 1, 1) is the bottom left pixel
|
||||||
//everything else uses y+ = down, so flip it to be consistent
|
//everything else uses y+ = down, so flip it to be consistent
|
||||||
//rect.pos.y = Renderer::getScreenHeight() - rect.pos.y - rect.size.y;
|
//rect.pos.y = Renderer::getScreenHeight() - rect.pos.y - rect.size.y;
|
||||||
box[1] = Renderer::getScreenHeight() - box.y() - box[3];
|
box.y = Renderer::getScreenHeight() - box.y - box.h;
|
||||||
|
|
||||||
//make sure the box fits within clipStack.top(), and clip further accordingly
|
//make sure the box fits within clipStack.top(), and clip further accordingly
|
||||||
if(clipStack.size())
|
if(clipStack.size())
|
||||||
{
|
{
|
||||||
Eigen::Vector4i& top = clipStack.top();
|
const ClipRect& top = clipStack.top();
|
||||||
if(top[0] > box[0])
|
if(top.x > box.x)
|
||||||
box[0] = top[0];
|
box.x = top.x;
|
||||||
if(top[1] > box[1])
|
if(top.y > box.y)
|
||||||
box[1] = top[1];
|
box.y = top.y;
|
||||||
if(top[0] + top[2] < box[0] + box[2])
|
if(top.x + top.w < box.x + box.w)
|
||||||
box[2] = (top[0] + top[2]) - box[0];
|
box.w = (top.x + top.w) - box.x;
|
||||||
if(top[1] + top[3] < box[1] + box[3])
|
if(top.y + top.h < box.y + box.h)
|
||||||
box[3] = (top[1] + top[3]) - box[1];
|
box.h = (top.y + top.h) - box.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(box[2] < 0)
|
if(box.w < 0)
|
||||||
box[2] = 0;
|
box.w = 0;
|
||||||
if(box[3] < 0)
|
if(box.h < 0)
|
||||||
box[3] = 0;
|
box.h = 0;
|
||||||
|
|
||||||
clipStack.push(box);
|
clipStack.push(box);
|
||||||
glScissor(box[0], box[1], box[2], box[3]);
|
glScissor(box.x, box.y, box.w, box.h);
|
||||||
glEnable(GL_SCISSOR_TEST);
|
glEnable(GL_SCISSOR_TEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,8 +89,8 @@ namespace Renderer {
|
||||||
{
|
{
|
||||||
glDisable(GL_SCISSOR_TEST);
|
glDisable(GL_SCISSOR_TEST);
|
||||||
}else{
|
}else{
|
||||||
Eigen::Vector4i top = clipStack.top();
|
const ClipRect& top = clipStack.top();
|
||||||
glScissor(top[0], top[1], top[2], top[3]);
|
glScissor(top.x, top.y, top.w, top.h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,13 +137,8 @@ namespace Renderer {
|
||||||
glDisableClientState(GL_COLOR_ARRAY);
|
glDisableClientState(GL_COLOR_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMatrix(float* matrix)
|
void setMatrix(const Transform4x4f& matrix)
|
||||||
{
|
{
|
||||||
glLoadMatrixf(matrix);
|
glLoadMatrixf((GLfloat*)&matrix);
|
||||||
}
|
|
||||||
|
|
||||||
void setMatrix(const Eigen::Affine3f& matrix)
|
|
||||||
{
|
|
||||||
setMatrix((float*)matrix.data());
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -419,7 +419,7 @@ void ThemeData::parseElement(const pugi::xml_node& root, const std::map<std::str
|
||||||
std::string first = str.substr(0, divider);
|
std::string first = str.substr(0, divider);
|
||||||
std::string second = str.substr(divider, std::string::npos);
|
std::string second = str.substr(divider, std::string::npos);
|
||||||
|
|
||||||
Eigen::Vector2f val(atof(first.c_str()), atof(second.c_str()));
|
Vector2f val(atof(first.c_str()), atof(second.c_str()));
|
||||||
|
|
||||||
element.properties[node.name()] = val;
|
element.properties[node.name()] = val;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
#include <boost/variant.hpp>
|
#include <boost/variant.hpp>
|
||||||
#include <boost/xpressive/xpressive.hpp>
|
#include <boost/xpressive/xpressive.hpp>
|
||||||
#include <Eigen/Dense>
|
|
||||||
#include "pugixml/src/pugixml.hpp"
|
#include "pugixml/src/pugixml.hpp"
|
||||||
#include "GuiComponent.h"
|
#include "GuiComponent.h"
|
||||||
|
|
||||||
|
@ -91,7 +90,7 @@ public:
|
||||||
bool extra;
|
bool extra;
|
||||||
std::string type;
|
std::string type;
|
||||||
|
|
||||||
std::map< std::string, boost::variant<Eigen::Vector2f, std::string, unsigned int, float, bool> > properties;
|
std::map< std::string, boost::variant<Vector2f, std::string, unsigned int, float, bool> > properties;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T get(const std::string& prop) const { return boost::get<T>(properties.at(prop)); }
|
T get(const std::string& prop) const { return boost::get<T>(properties.at(prop)); }
|
||||||
|
|
|
@ -26,7 +26,6 @@ std::string strToUpper(const std::string& str)
|
||||||
return strToUpper(str.c_str());
|
return strToUpper(str.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if defined(_WIN32) && _MSC_VER < 1800
|
#if defined(_WIN32) && _MSC_VER < 1800
|
||||||
float round(float num)
|
float round(float num)
|
||||||
{
|
{
|
||||||
|
@ -34,37 +33,6 @@ float round(float num)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Eigen::Affine3f& roundMatrix(Eigen::Affine3f& mat)
|
|
||||||
{
|
|
||||||
mat.translation()[0] = round(mat.translation()[0]);
|
|
||||||
mat.translation()[1] = round(mat.translation()[1]);
|
|
||||||
return mat;
|
|
||||||
}
|
|
||||||
|
|
||||||
Eigen::Affine3f roundMatrix(const Eigen::Affine3f& mat)
|
|
||||||
{
|
|
||||||
Eigen::Affine3f ret = mat;
|
|
||||||
roundMatrix(ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
Eigen::Vector3f roundVector(const Eigen::Vector3f& vec)
|
|
||||||
{
|
|
||||||
Eigen::Vector3f ret = vec;
|
|
||||||
ret[0] = round(ret[0]);
|
|
||||||
ret[1] = round(ret[1]);
|
|
||||||
ret[2] = round(ret[2]);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
Eigen::Vector2f roundVector(const Eigen::Vector2f& vec)
|
|
||||||
{
|
|
||||||
Eigen::Vector2f ret = vec;
|
|
||||||
ret[0] = round(ret[0]);
|
|
||||||
ret[1] = round(ret[1]);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
// embedded resources, e.g. ":/font.ttf", need to be properly handled too
|
// embedded resources, e.g. ":/font.ttf", need to be properly handled too
|
||||||
std::string getCanonicalPath(const std::string& path)
|
std::string getCanonicalPath(const std::string& path)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,20 +1,15 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <Eigen/Dense>
|
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
#include <boost/date_time.hpp>
|
#include <boost/date_time.hpp>
|
||||||
|
#include "math/Transform4x4f.h"
|
||||||
|
#include "math/Vector2f.h"
|
||||||
|
|
||||||
std::string strToUpper(const char* from);
|
std::string strToUpper(const char* from);
|
||||||
std::string& strToUpper(std::string& str);
|
std::string& strToUpper(std::string& str);
|
||||||
std::string strToUpper(const std::string& str);
|
std::string strToUpper(const std::string& str);
|
||||||
|
|
||||||
Eigen::Affine3f& roundMatrix(Eigen::Affine3f& mat);
|
|
||||||
Eigen::Affine3f roundMatrix(const Eigen::Affine3f& mat);
|
|
||||||
|
|
||||||
Eigen::Vector3f roundVector(const Eigen::Vector3f& vec);
|
|
||||||
Eigen::Vector2f roundVector(const Eigen::Vector2f& vec);
|
|
||||||
|
|
||||||
#if defined(_WIN32) && _MSC_VER < 1800
|
#if defined(_WIN32) && _MSC_VER < 1800
|
||||||
float round(float num);
|
float round(float num);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -228,7 +228,7 @@ void Window::update(int deltaTime)
|
||||||
|
|
||||||
void Window::render()
|
void Window::render()
|
||||||
{
|
{
|
||||||
Eigen::Affine3f transform = Eigen::Affine3f::Identity();
|
Transform4x4f transform = Transform4x4f::Identity();
|
||||||
|
|
||||||
mRenderedHelpPrompts = false;
|
mRenderedHelpPrompts = false;
|
||||||
|
|
||||||
|
@ -251,7 +251,7 @@ void Window::render()
|
||||||
|
|
||||||
if(Settings::getInstance()->getBool("DrawFramerate") && mFrameDataText)
|
if(Settings::getInstance()->getBool("DrawFramerate") && mFrameDataText)
|
||||||
{
|
{
|
||||||
Renderer::setMatrix(Eigen::Affine3f::Identity());
|
Renderer::setMatrix(Transform4x4f::Identity());
|
||||||
mDefaultFonts.at(1)->renderTextCache(mFrameDataText.get());
|
mDefaultFonts.at(1)->renderTextCache(mFrameDataText.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,7 +296,7 @@ void Window::setAllowSleep(bool sleep)
|
||||||
|
|
||||||
void Window::renderLoadingScreen()
|
void Window::renderLoadingScreen()
|
||||||
{
|
{
|
||||||
Eigen::Affine3f trans = Eigen::Affine3f::Identity();
|
Transform4x4f trans = Transform4x4f::Identity();
|
||||||
Renderer::setMatrix(trans);
|
Renderer::setMatrix(trans);
|
||||||
Renderer::drawRect(0, 0, Renderer::getScreenWidth(), Renderer::getScreenHeight(), 0x000000FF);
|
Renderer::drawRect(0, 0, Renderer::getScreenWidth(), Renderer::getScreenHeight(), 0x000000FF);
|
||||||
|
|
||||||
|
@ -308,7 +308,7 @@ void Window::renderLoadingScreen()
|
||||||
|
|
||||||
auto& font = mDefaultFonts.at(1);
|
auto& font = mDefaultFonts.at(1);
|
||||||
TextCache* cache = font->buildTextCache("LOADING...", 0, 0, 0x656565FF);
|
TextCache* cache = font->buildTextCache("LOADING...", 0, 0, 0x656565FF);
|
||||||
trans = trans.translate(Eigen::Vector3f(round((Renderer::getScreenWidth() - cache->metrics.size.x()) / 2.0f),
|
trans = trans.translate(Vector3f(round((Renderer::getScreenWidth() - cache->metrics.size.x()) / 2.0f),
|
||||||
round(Renderer::getScreenHeight() * 0.835f), 0.0f));
|
round(Renderer::getScreenHeight() * 0.835f), 0.0f));
|
||||||
Renderer::setMatrix(trans);
|
Renderer::setMatrix(trans);
|
||||||
font->renderTextCache(cache);
|
font->renderTextCache(cache);
|
||||||
|
@ -319,7 +319,7 @@ void Window::renderLoadingScreen()
|
||||||
|
|
||||||
void Window::renderHelpPromptsEarly()
|
void Window::renderHelpPromptsEarly()
|
||||||
{
|
{
|
||||||
mHelp->render(Eigen::Affine3f::Identity());
|
mHelp->render(Transform4x4f::Identity());
|
||||||
mRenderedHelpPrompts = true;
|
mRenderedHelpPrompts = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ public:
|
||||||
|
|
||||||
class InfoPopup {
|
class InfoPopup {
|
||||||
public:
|
public:
|
||||||
virtual void render(const Eigen::Affine3f& parentTrans) = 0;
|
virtual void render(const Transform4x4f& parentTrans) = 0;
|
||||||
virtual void stop() = 0;
|
virtual void stop() = 0;
|
||||||
virtual ~InfoPopup() {};
|
virtual ~InfoPopup() {};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <Eigen/Dense>
|
|
||||||
|
|
||||||
class Animation
|
class Animation
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -76,7 +76,7 @@ void AnimatedImageComponent::update(int deltaTime)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnimatedImageComponent::render(const Eigen::Affine3f& trans)
|
void AnimatedImageComponent::render(const Transform4x4f& trans)
|
||||||
{
|
{
|
||||||
if(mFrames.size())
|
if(mFrames.size())
|
||||||
mFrames.at(mCurrentFrame).first->render(getTransform() * trans);
|
mFrames.at(mCurrentFrame).first->render(getTransform() * trans);
|
||||||
|
|
|
@ -24,7 +24,7 @@ public:
|
||||||
void reset(); // set to frame 0
|
void reset(); // set to frame 0
|
||||||
|
|
||||||
void update(int deltaTime) override;
|
void update(int deltaTime) override;
|
||||||
void render(const Eigen::Affine3f& trans) override;
|
void render(const Transform4x4f& trans) override;
|
||||||
|
|
||||||
void onSizeChanged() override;
|
void onSizeChanged() override;
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,6 @@ AnimationFrame BUSY_ANIMATION_FRAMES[] = {
|
||||||
};
|
};
|
||||||
const AnimationDef BUSY_ANIMATION_DEF = { BUSY_ANIMATION_FRAMES, 4, true };
|
const AnimationDef BUSY_ANIMATION_DEF = { BUSY_ANIMATION_FRAMES, 4, true };
|
||||||
|
|
||||||
using namespace Eigen;
|
|
||||||
|
|
||||||
BusyComponent::BusyComponent(Window* window) : GuiComponent(window),
|
BusyComponent::BusyComponent(Window* window) : GuiComponent(window),
|
||||||
mBackground(window, ":/frame.png"), mGrid(window, Vector2i(5, 3))
|
mBackground(window, ":/frame.png"), mGrid(window, Vector2i(5, 3))
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,7 +18,7 @@ ButtonComponent::ButtonComponent(Window* window, const std::string& text, const
|
||||||
|
|
||||||
void ButtonComponent::onSizeChanged()
|
void ButtonComponent::onSizeChanged()
|
||||||
{
|
{
|
||||||
mBox.fitTo(mSize, Eigen::Vector3f::Zero(), Eigen::Vector2f(-32, -32));
|
mBox.fitTo(mSize, Vector3f::Zero(), Vector2f(-32, -32));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonComponent::setPressedFunc(std::function<void()> f)
|
void ButtonComponent::setPressedFunc(std::function<void()> f)
|
||||||
|
@ -84,16 +84,17 @@ void ButtonComponent::updateImage()
|
||||||
mBox.setImagePath(mFocused ? ":/button_filled.png" : ":/button.png");
|
mBox.setImagePath(mFocused ? ":/button_filled.png" : ":/button.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonComponent::render(const Eigen::Affine3f& parentTrans)
|
void ButtonComponent::render(const Transform4x4f& parentTrans)
|
||||||
{
|
{
|
||||||
Eigen::Affine3f trans = roundMatrix(parentTrans * getTransform());
|
Transform4x4f trans = parentTrans * getTransform();
|
||||||
|
trans.round();
|
||||||
|
|
||||||
mBox.render(trans);
|
mBox.render(trans);
|
||||||
|
|
||||||
if(mTextCache)
|
if(mTextCache)
|
||||||
{
|
{
|
||||||
Eigen::Vector3f centerOffset((mSize.x() - mTextCache->metrics.size.x()) / 2, (mSize.y() - mTextCache->metrics.size.y()) / 2, 0);
|
Vector3f centerOffset((mSize.x() - mTextCache->metrics.size.x()) / 2, (mSize.y() - mTextCache->metrics.size.y()) / 2, 0);
|
||||||
centerOffset = roundVector(centerOffset);
|
centerOffset.round();
|
||||||
trans = trans.translate(centerOffset);
|
trans = trans.translate(centerOffset);
|
||||||
|
|
||||||
Renderer::setMatrix(trans);
|
Renderer::setMatrix(trans);
|
||||||
|
|
|
@ -15,7 +15,7 @@ public:
|
||||||
void setEnabled(bool enable);
|
void setEnabled(bool enable);
|
||||||
|
|
||||||
bool input(InputConfig* config, Input input) override;
|
bool input(InputConfig* config, Input input) override;
|
||||||
void render(const Eigen::Affine3f& parentTrans) override;
|
void render(const Transform4x4f& parentTrans) override;
|
||||||
|
|
||||||
void setText(const std::string& text, const std::string& helpText);
|
void setText(const std::string& text, const std::string& helpText);
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
using namespace GridFlags;
|
using namespace GridFlags;
|
||||||
|
|
||||||
ComponentGrid::ComponentGrid(Window* window, const Eigen::Vector2i& gridDimensions) : GuiComponent(window),
|
ComponentGrid::ComponentGrid(Window* window, const Vector2i& gridDimensions) : GuiComponent(window),
|
||||||
mGridSize(gridDimensions), mCursor(0, 0)
|
mGridSize(gridDimensions), mCursor(0, 0)
|
||||||
{
|
{
|
||||||
assert(gridDimensions.x() > 0 && gridDimensions.y() > 0);
|
assert(gridDimensions.x() > 0 && gridDimensions.y() > 0);
|
||||||
|
@ -82,7 +82,7 @@ void ComponentGrid::setRowHeightPerc(int row, float height, bool update)
|
||||||
onSizeChanged();
|
onSizeChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComponentGrid::setEntry(const std::shared_ptr<GuiComponent>& comp, const Eigen::Vector2i& pos, bool canFocus, bool resize, const Eigen::Vector2i& size,
|
void ComponentGrid::setEntry(const std::shared_ptr<GuiComponent>& comp, const Vector2i& pos, bool canFocus, bool resize, const Vector2i& size,
|
||||||
unsigned int border, GridFlags::UpdateType updateType)
|
unsigned int border, GridFlags::UpdateType updateType)
|
||||||
{
|
{
|
||||||
assert(pos.x() >= 0 && pos.x() < mGridSize.x() && pos.y() >= 0 && pos.y() < mGridSize.y());
|
assert(pos.x() >= 0 && pos.x() < mGridSize.x() && pos.y() >= 0 && pos.y() < mGridSize.y());
|
||||||
|
@ -123,7 +123,7 @@ bool ComponentGrid::removeEntry(const std::shared_ptr<GuiComponent>& comp)
|
||||||
void ComponentGrid::updateCellComponent(const GridEntry& cell)
|
void ComponentGrid::updateCellComponent(const GridEntry& cell)
|
||||||
{
|
{
|
||||||
// size
|
// size
|
||||||
Eigen::Vector2f size(0, 0);
|
Vector2f size(0, 0);
|
||||||
for(int x = cell.pos.x(); x < cell.pos.x() + cell.dim.x(); x++)
|
for(int x = cell.pos.x(); x < cell.pos.x() + cell.dim.x(); x++)
|
||||||
size[0] += getColWidth(x);
|
size[0] += getColWidth(x);
|
||||||
for(int y = cell.pos.y(); y < cell.pos.y() + cell.dim.y(); y++)
|
for(int y = cell.pos.y(); y < cell.pos.y() + cell.dim.y(); y++)
|
||||||
|
@ -134,7 +134,7 @@ void ComponentGrid::updateCellComponent(const GridEntry& cell)
|
||||||
|
|
||||||
// position
|
// position
|
||||||
// find top left corner
|
// find top left corner
|
||||||
Eigen::Vector3f pos(0, 0, 0);
|
Vector3f pos(0, 0, 0);
|
||||||
for(int x = 0; x < cell.pos.x(); x++)
|
for(int x = 0; x < cell.pos.x(); x++)
|
||||||
pos[0] += getColWidth(x);
|
pos[0] += getColWidth(x);
|
||||||
for(int y = 0; y < cell.pos.y(); y++)
|
for(int y = 0; y < cell.pos.y(); y++)
|
||||||
|
@ -153,16 +153,16 @@ void ComponentGrid::updateSeparators()
|
||||||
|
|
||||||
bool drawAll = Settings::getInstance()->getBool("DebugGrid");
|
bool drawAll = Settings::getInstance()->getBool("DebugGrid");
|
||||||
|
|
||||||
Eigen::Vector2f pos;
|
Vector2f pos;
|
||||||
Eigen::Vector2f size;
|
Vector2f size;
|
||||||
for(auto it = mCells.begin(); it != mCells.end(); it++)
|
for(auto it = mCells.begin(); it != mCells.end(); it++)
|
||||||
{
|
{
|
||||||
if(!it->border && !drawAll)
|
if(!it->border && !drawAll)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// find component position + size
|
// find component position + size
|
||||||
pos << 0, 0;
|
pos = Vector2f(0, 0);
|
||||||
size << 0, 0;
|
size = Vector2f(0, 0);
|
||||||
for(int x = 0; x < it->pos.x(); x++)
|
for(int x = 0; x < it->pos.x(); x++)
|
||||||
pos[0] += getColWidth(x);
|
pos[0] += getColWidth(x);
|
||||||
for(int y = 0; y < it->pos.y(); y++)
|
for(int y = 0; y < it->pos.y(); y++)
|
||||||
|
@ -235,19 +235,19 @@ bool ComponentGrid::input(InputConfig* config, Input input)
|
||||||
|
|
||||||
if(config->isMappedTo("down", input))
|
if(config->isMappedTo("down", input))
|
||||||
{
|
{
|
||||||
return moveCursor(Eigen::Vector2i(0, 1));
|
return moveCursor(Vector2i(0, 1));
|
||||||
}
|
}
|
||||||
if(config->isMappedTo("up", input))
|
if(config->isMappedTo("up", input))
|
||||||
{
|
{
|
||||||
return moveCursor(Eigen::Vector2i(0, -1));
|
return moveCursor(Vector2i(0, -1));
|
||||||
}
|
}
|
||||||
if(config->isMappedTo("left", input))
|
if(config->isMappedTo("left", input))
|
||||||
{
|
{
|
||||||
return moveCursor(Eigen::Vector2i(-1, 0));
|
return moveCursor(Vector2i(-1, 0));
|
||||||
}
|
}
|
||||||
if(config->isMappedTo("right", input))
|
if(config->isMappedTo("right", input))
|
||||||
{
|
{
|
||||||
return moveCursor(Eigen::Vector2i(1, 0));
|
return moveCursor(Vector2i(1, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -262,7 +262,7 @@ void ComponentGrid::resetCursor()
|
||||||
{
|
{
|
||||||
if(it->canFocus)
|
if(it->canFocus)
|
||||||
{
|
{
|
||||||
Eigen::Vector2i origCursor = mCursor;
|
Vector2i origCursor = mCursor;
|
||||||
mCursor = it->pos;
|
mCursor = it->pos;
|
||||||
onCursorMoved(origCursor, mCursor);
|
onCursorMoved(origCursor, mCursor);
|
||||||
break;
|
break;
|
||||||
|
@ -270,21 +270,21 @@ void ComponentGrid::resetCursor()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ComponentGrid::moveCursor(Eigen::Vector2i dir)
|
bool ComponentGrid::moveCursor(Vector2i dir)
|
||||||
{
|
{
|
||||||
assert(dir.x() || dir.y());
|
assert(dir.x() || dir.y());
|
||||||
|
|
||||||
const Eigen::Vector2i origCursor = mCursor;
|
const Vector2i origCursor = mCursor;
|
||||||
|
|
||||||
GridEntry* currentCursorEntry = getCellAt(mCursor);
|
GridEntry* currentCursorEntry = getCellAt(mCursor);
|
||||||
|
|
||||||
Eigen::Vector2i searchAxis(dir.x() == 0, dir.y() == 0);
|
Vector2i searchAxis(dir.x() == 0, dir.y() == 0);
|
||||||
|
|
||||||
while(mCursor.x() >= 0 && mCursor.y() >= 0 && mCursor.x() < mGridSize.x() && mCursor.y() < mGridSize.y())
|
while(mCursor.x() >= 0 && mCursor.y() >= 0 && mCursor.x() < mGridSize.x() && mCursor.y() < mGridSize.y())
|
||||||
{
|
{
|
||||||
mCursor = mCursor + dir;
|
mCursor = mCursor + dir;
|
||||||
|
|
||||||
Eigen::Vector2i curDirPos = mCursor;
|
Vector2i curDirPos = mCursor;
|
||||||
|
|
||||||
GridEntry* cursorEntry;
|
GridEntry* cursorEntry;
|
||||||
//spread out on search axis+
|
//spread out on search axis+
|
||||||
|
@ -355,9 +355,9 @@ void ComponentGrid::update(int deltaTime)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComponentGrid::render(const Eigen::Affine3f& parentTrans)
|
void ComponentGrid::render(const Transform4x4f& parentTrans)
|
||||||
{
|
{
|
||||||
Eigen::Affine3f trans = parentTrans * getTransform();
|
Transform4x4f trans = parentTrans * getTransform();
|
||||||
|
|
||||||
renderChildren(trans);
|
renderChildren(trans);
|
||||||
|
|
||||||
|
@ -389,7 +389,7 @@ void ComponentGrid::textInput(const char* text)
|
||||||
selectedEntry->component->textInput(text);
|
selectedEntry->component->textInput(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComponentGrid::onCursorMoved(Eigen::Vector2i from, Eigen::Vector2i to)
|
void ComponentGrid::onCursorMoved(Vector2i from, Vector2i to)
|
||||||
{
|
{
|
||||||
GridEntry* cell = getCellAt(from);
|
GridEntry* cell = getCellAt(from);
|
||||||
if(cell)
|
if(cell)
|
||||||
|
@ -408,7 +408,7 @@ void ComponentGrid::setCursorTo(const std::shared_ptr<GuiComponent>& comp)
|
||||||
{
|
{
|
||||||
if(it->component == comp)
|
if(it->component == comp)
|
||||||
{
|
{
|
||||||
Eigen::Vector2i oldCursor = mCursor;
|
Vector2i oldCursor = mCursor;
|
||||||
mCursor = it->pos;
|
mCursor = it->pos;
|
||||||
onCursorMoved(oldCursor, mCursor);
|
onCursorMoved(oldCursor, mCursor);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "GuiComponent.h"
|
#include "GuiComponent.h"
|
||||||
|
#include "math/Vector2i.h"
|
||||||
|
|
||||||
namespace GridFlags
|
namespace GridFlags
|
||||||
{
|
{
|
||||||
|
@ -26,18 +27,18 @@ namespace GridFlags
|
||||||
class ComponentGrid : public GuiComponent
|
class ComponentGrid : public GuiComponent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ComponentGrid(Window* window, const Eigen::Vector2i& gridDimensions);
|
ComponentGrid(Window* window, const Vector2i& gridDimensions);
|
||||||
virtual ~ComponentGrid();
|
virtual ~ComponentGrid();
|
||||||
|
|
||||||
bool removeEntry(const std::shared_ptr<GuiComponent>& comp);
|
bool removeEntry(const std::shared_ptr<GuiComponent>& comp);
|
||||||
|
|
||||||
void setEntry(const std::shared_ptr<GuiComponent>& comp, const Eigen::Vector2i& pos, bool canFocus, bool resize = true,
|
void setEntry(const std::shared_ptr<GuiComponent>& comp, const Vector2i& pos, bool canFocus, bool resize = true,
|
||||||
const Eigen::Vector2i& size = Eigen::Vector2i(1, 1), unsigned int border = GridFlags::BORDER_NONE, GridFlags::UpdateType updateType = GridFlags::UPDATE_ALWAYS);
|
const Vector2i& size = Vector2i(1, 1), unsigned int border = GridFlags::BORDER_NONE, GridFlags::UpdateType updateType = GridFlags::UPDATE_ALWAYS);
|
||||||
|
|
||||||
void textInput(const char* text) override;
|
void textInput(const char* text) override;
|
||||||
bool input(InputConfig* config, Input input) override;
|
bool input(InputConfig* config, Input input) override;
|
||||||
void update(int deltaTime) override;
|
void update(int deltaTime) override;
|
||||||
void render(const Eigen::Affine3f& parentTrans) override;
|
void render(const Transform4x4f& parentTrans) override;
|
||||||
void onSizeChanged() override;
|
void onSizeChanged() override;
|
||||||
|
|
||||||
void resetCursor();
|
void resetCursor();
|
||||||
|
@ -49,7 +50,7 @@ public:
|
||||||
void setColWidthPerc(int col, float width, bool update = true); // if update is false, will not call an onSizeChanged() which triggers a (potentially costly) repositioning + resizing of every element
|
void setColWidthPerc(int col, float width, bool update = true); // if update is false, will not call an onSizeChanged() which triggers a (potentially costly) repositioning + resizing of every element
|
||||||
void setRowHeightPerc(int row, float height, bool update = true); // if update is false, will not call an onSizeChanged() which triggers a (potentially costly) repositioning + resizing of every element
|
void setRowHeightPerc(int row, float height, bool update = true); // if update is false, will not call an onSizeChanged() which triggers a (potentially costly) repositioning + resizing of every element
|
||||||
|
|
||||||
bool moveCursor(Eigen::Vector2i dir);
|
bool moveCursor(Vector2i dir);
|
||||||
void setCursorTo(const std::shared_ptr<GuiComponent>& comp);
|
void setCursorTo(const std::shared_ptr<GuiComponent>& comp);
|
||||||
|
|
||||||
inline std::shared_ptr<GuiComponent> getSelectedComponent()
|
inline std::shared_ptr<GuiComponent> getSelectedComponent()
|
||||||
|
@ -70,15 +71,15 @@ private:
|
||||||
class GridEntry
|
class GridEntry
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Eigen::Vector2i pos;
|
Vector2i pos;
|
||||||
Eigen::Vector2i dim;
|
Vector2i dim;
|
||||||
std::shared_ptr<GuiComponent> component;
|
std::shared_ptr<GuiComponent> component;
|
||||||
bool canFocus;
|
bool canFocus;
|
||||||
bool resize;
|
bool resize;
|
||||||
GridFlags::UpdateType updateType;
|
GridFlags::UpdateType updateType;
|
||||||
unsigned int border;
|
unsigned int border;
|
||||||
|
|
||||||
GridEntry(const Eigen::Vector2i& p = Eigen::Vector2i::Zero(), const Eigen::Vector2i& d = Eigen::Vector2i::Zero(),
|
GridEntry(const Vector2i& p = Vector2i::Zero(), const Vector2i& d = Vector2i::Zero(),
|
||||||
const std::shared_ptr<GuiComponent>& cmp = nullptr, bool f = false, bool r = true,
|
const std::shared_ptr<GuiComponent>& cmp = nullptr, bool f = false, bool r = true,
|
||||||
GridFlags::UpdateType u = GridFlags::UPDATE_ALWAYS, unsigned int b = GridFlags::BORDER_NONE) :
|
GridFlags::UpdateType u = GridFlags::UPDATE_ALWAYS, unsigned int b = GridFlags::BORDER_NONE) :
|
||||||
pos(p), dim(d), component(cmp), canFocus(f), resize(r), updateType(u), border(b)
|
pos(p), dim(d), component(cmp), canFocus(f), resize(r), updateType(u), border(b)
|
||||||
|
@ -108,12 +109,12 @@ private:
|
||||||
void updateSeparators();
|
void updateSeparators();
|
||||||
|
|
||||||
GridEntry* getCellAt(int x, int y);
|
GridEntry* getCellAt(int x, int y);
|
||||||
inline GridEntry* getCellAt(const Eigen::Vector2i& pos) { return getCellAt(pos.x(), pos.y()); }
|
inline GridEntry* getCellAt(const Vector2i& pos) { return getCellAt(pos.x(), pos.y()); }
|
||||||
|
|
||||||
Eigen::Vector2i mGridSize;
|
Vector2i mGridSize;
|
||||||
|
|
||||||
std::vector<GridEntry> mCells;
|
std::vector<GridEntry> mCells;
|
||||||
|
|
||||||
void onCursorMoved(Eigen::Vector2i from, Eigen::Vector2i to);
|
void onCursorMoved(Vector2i from, Vector2i to);
|
||||||
Eigen::Vector2i mCursor;
|
Vector2i mCursor;
|
||||||
};
|
};
|
||||||
|
|
|
@ -157,21 +157,22 @@ void ComponentList::updateCameraOffset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComponentList::render(const Eigen::Affine3f& parentTrans)
|
void ComponentList::render(const Transform4x4f& parentTrans)
|
||||||
{
|
{
|
||||||
if(!size())
|
if(!size())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Eigen::Affine3f trans = roundMatrix(parentTrans * getTransform());
|
Transform4x4f trans = parentTrans * getTransform();
|
||||||
|
trans.round();
|
||||||
|
|
||||||
// clip everything to be inside our bounds
|
// clip everything to be inside our bounds
|
||||||
Eigen::Vector3f dim(mSize.x(), mSize.y(), 0);
|
Vector3f dim(mSize.x(), mSize.y(), 0);
|
||||||
dim = trans * dim - trans.translation();
|
dim = trans * dim - trans.translation();
|
||||||
Renderer::pushClipRect(Eigen::Vector2i((int)trans.translation().x(), (int)trans.translation().y()),
|
Renderer::pushClipRect(Vector2i((int)trans.translation().x(), (int)trans.translation().y()),
|
||||||
Eigen::Vector2i((int)round(dim.x()), (int)round(dim.y() + 1)));
|
Vector2i((int)round(dim.x()), (int)round(dim.y() + 1)));
|
||||||
|
|
||||||
// scroll the camera
|
// scroll the camera
|
||||||
trans.translate(Eigen::Vector3f(0, -round(mCameraOffset), 0));
|
trans.translate(Vector3f(0, -round(mCameraOffset), 0));
|
||||||
|
|
||||||
// draw our entries
|
// draw our entries
|
||||||
std::vector<GuiComponent*> drawAfterCursor;
|
std::vector<GuiComponent*> drawAfterCursor;
|
||||||
|
|
|
@ -52,7 +52,7 @@ public:
|
||||||
void textInput(const char* text) override;
|
void textInput(const char* text) override;
|
||||||
bool input(InputConfig* config, Input input) override;
|
bool input(InputConfig* config, Input input) override;
|
||||||
void update(int deltaTime) override;
|
void update(int deltaTime) override;
|
||||||
void render(const Eigen::Affine3f& parentTrans) override;
|
void render(const Transform4x4f& parentTrans) override;
|
||||||
virtual std::vector<HelpPrompt> getHelpPrompts() override;
|
virtual std::vector<HelpPrompt> getHelpPrompts() override;
|
||||||
|
|
||||||
void onSizeChanged() override;
|
void onSizeChanged() override;
|
||||||
|
|
|
@ -134,16 +134,16 @@ void DateTimeComponent::update(int deltaTime)
|
||||||
GuiComponent::update(deltaTime);
|
GuiComponent::update(deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DateTimeComponent::render(const Eigen::Affine3f& parentTrans)
|
void DateTimeComponent::render(const Transform4x4f& parentTrans)
|
||||||
{
|
{
|
||||||
Eigen::Affine3f trans = parentTrans * getTransform();
|
Transform4x4f trans = parentTrans * getTransform();
|
||||||
|
|
||||||
if(mTextCache)
|
if(mTextCache)
|
||||||
{
|
{
|
||||||
// vertically center
|
// vertically center
|
||||||
Eigen::Vector3f off(0, (mSize.y() - mTextCache->metrics.size.y()) / 2, 0);
|
Vector3f off(0, (mSize.y() - mTextCache->metrics.size.y()) / 2, 0);
|
||||||
trans.translate(off);
|
trans.translate(off);
|
||||||
trans = roundMatrix(trans);
|
trans.round();
|
||||||
|
|
||||||
Renderer::setMatrix(trans);
|
Renderer::setMatrix(trans);
|
||||||
|
|
||||||
|
@ -269,22 +269,22 @@ void DateTimeComponent::updateTextCache()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//month
|
//month
|
||||||
Eigen::Vector2f start(0, 0);
|
Vector2f start(0, 0);
|
||||||
Eigen::Vector2f end = font->sizeText(dispString.substr(0, 2));
|
Vector2f end = font->sizeText(dispString.substr(0, 2));
|
||||||
Eigen::Vector2f diff = end - start;
|
Vector2f diff = end - start;
|
||||||
mCursorBoxes.push_back(Eigen::Vector4f(start[0], start[1], diff[0], diff[1]));
|
mCursorBoxes.push_back(Vector4f(start[0], start[1], diff[0], diff[1]));
|
||||||
|
|
||||||
//day
|
//day
|
||||||
start[0] = font->sizeText(dispString.substr(0, 3)).x();
|
start[0] = font->sizeText(dispString.substr(0, 3)).x();
|
||||||
end = font->sizeText(dispString.substr(0, 5));
|
end = font->sizeText(dispString.substr(0, 5));
|
||||||
diff = end - start;
|
diff = end - start;
|
||||||
mCursorBoxes.push_back(Eigen::Vector4f(start[0], start[1], diff[0], diff[1]));
|
mCursorBoxes.push_back(Vector4f(start[0], start[1], diff[0], diff[1]));
|
||||||
|
|
||||||
//year
|
//year
|
||||||
start[0] = font->sizeText(dispString.substr(0, 6)).x();
|
start[0] = font->sizeText(dispString.substr(0, 6)).x();
|
||||||
end = font->sizeText(dispString.substr(0, 10));
|
end = font->sizeText(dispString.substr(0, 10));
|
||||||
diff = end - start;
|
diff = end - start;
|
||||||
mCursorBoxes.push_back(Eigen::Vector4f(start[0], start[1], diff[0], diff[1]));
|
mCursorBoxes.push_back(Vector4f(start[0], start[1], diff[0], diff[1]));
|
||||||
|
|
||||||
//if mode == DISP_DATE_TIME do times too but I don't wanna do the logic for editing times because no one will ever use it so screw it
|
//if mode == DISP_DATE_TIME do times too but I don't wanna do the logic for editing times because no one will ever use it so screw it
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ public:
|
||||||
|
|
||||||
bool input(InputConfig* config, Input input) override;
|
bool input(InputConfig* config, Input input) override;
|
||||||
void update(int deltaTime) override;
|
void update(int deltaTime) override;
|
||||||
void render(const Eigen::Affine3f& parentTrans) override;
|
void render(const Transform4x4f& parentTrans) override;
|
||||||
void onSizeChanged() override;
|
void onSizeChanged() override;
|
||||||
|
|
||||||
// Set how the point in time will be displayed:
|
// Set how the point in time will be displayed:
|
||||||
|
@ -56,7 +56,7 @@ private:
|
||||||
int mRelativeUpdateAccumulator;
|
int mRelativeUpdateAccumulator;
|
||||||
|
|
||||||
std::unique_ptr<TextCache> mTextCache;
|
std::unique_ptr<TextCache> mTextCache;
|
||||||
std::vector<Eigen::Vector4f> mCursorBoxes;
|
std::vector<Vector4f> mCursorBoxes;
|
||||||
|
|
||||||
unsigned int mColor;
|
unsigned int mColor;
|
||||||
std::shared_ptr<Font> mFont;
|
std::shared_ptr<Font> mFont;
|
||||||
|
|
|
@ -14,8 +14,6 @@
|
||||||
#define ICON_TEXT_SPACING 8 // space between [icon] and [text] (px)
|
#define ICON_TEXT_SPACING 8 // space between [icon] and [text] (px)
|
||||||
#define ENTRY_SPACING 16 // space between [text] and next [icon] (px)
|
#define ENTRY_SPACING 16 // space between [text] and next [icon] (px)
|
||||||
|
|
||||||
using namespace Eigen;
|
|
||||||
|
|
||||||
static const std::map<std::string, const char*> ICON_PATH_MAP = boost::assign::map_list_of
|
static const std::map<std::string, const char*> ICON_PATH_MAP = boost::assign::map_list_of
|
||||||
("up/down", ":/help/dpad_updown.svg")
|
("up/down", ":/help/dpad_updown.svg")
|
||||||
("left/right", ":/help/dpad_leftright.svg")
|
("left/right", ":/help/dpad_leftright.svg")
|
||||||
|
@ -95,7 +93,7 @@ void HelpComponent::updateGrid()
|
||||||
mGrid->setEntry(labels.at(i), Vector2i(col + 2, 0), false, false);
|
mGrid->setEntry(labels.at(i), Vector2i(col + 2, 0), false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
mGrid->setPosition(Eigen::Vector3f(mStyle.position.x(), mStyle.position.y(), 0.0f));
|
mGrid->setPosition(Vector3f(mStyle.position.x(), mStyle.position.y(), 0.0f));
|
||||||
//mGrid->setPosition(OFFSET_X, Renderer::getScreenHeight() - mGrid->getSize().y() - OFFSET_Y);
|
//mGrid->setPosition(OFFSET_X, Renderer::getScreenHeight() - mGrid->getSize().y() - OFFSET_Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,9 +130,9 @@ void HelpComponent::setOpacity(unsigned char opacity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HelpComponent::render(const Eigen::Affine3f& parentTrans)
|
void HelpComponent::render(const Transform4x4f& parentTrans)
|
||||||
{
|
{
|
||||||
Eigen::Affine3f trans = parentTrans * getTransform();
|
Transform4x4f trans = parentTrans * getTransform();
|
||||||
|
|
||||||
if(mGrid)
|
if(mGrid)
|
||||||
mGrid->render(trans);
|
mGrid->render(trans);
|
||||||
|
|
|
@ -15,7 +15,7 @@ public:
|
||||||
void clearPrompts();
|
void clearPrompts();
|
||||||
void setPrompts(const std::vector<HelpPrompt>& prompts);
|
void setPrompts(const std::vector<HelpPrompt>& prompts);
|
||||||
|
|
||||||
void render(const Eigen::Affine3f& parent) override;
|
void render(const Transform4x4f& parent) override;
|
||||||
void setOpacity(unsigned char opacity) override;
|
void setOpacity(unsigned char opacity) override;
|
||||||
|
|
||||||
void setStyle(const HelpStyle& style);
|
void setStyle(const HelpStyle& style);
|
||||||
|
|
|
@ -247,7 +247,7 @@ protected:
|
||||||
scroll(mScrollVelocity);
|
scroll(mScrollVelocity);
|
||||||
}
|
}
|
||||||
|
|
||||||
void listRenderTitleOverlay(const Eigen::Affine3f& trans)
|
void listRenderTitleOverlay(const Transform4x4f& trans)
|
||||||
{
|
{
|
||||||
if(size() == 0 || !mTitleOverlayFont || mTitleOverlayOpacity == 0)
|
if(size() == 0 || !mTitleOverlayFont || mTitleOverlayOpacity == 0)
|
||||||
return;
|
return;
|
||||||
|
@ -255,11 +255,11 @@ protected:
|
||||||
// we don't bother caching this because it's only two letters and will change pretty much every frame if we're scrolling
|
// we don't bother caching this because it's only two letters and will change pretty much every frame if we're scrolling
|
||||||
const std::string text = getSelectedName().size() >= 2 ? getSelectedName().substr(0, 2) : "??";
|
const std::string text = getSelectedName().size() >= 2 ? getSelectedName().substr(0, 2) : "??";
|
||||||
|
|
||||||
Eigen::Vector2f off = mTitleOverlayFont->sizeText(text);
|
Vector2f off = mTitleOverlayFont->sizeText(text);
|
||||||
off[0] = (Renderer::getScreenWidth() - off.x()) * 0.5f;
|
off[0] = (Renderer::getScreenWidth() - off.x()) * 0.5f;
|
||||||
off[1] = (Renderer::getScreenHeight() - off.y()) * 0.5f;
|
off[1] = (Renderer::getScreenHeight() - off.y()) * 0.5f;
|
||||||
|
|
||||||
Eigen::Affine3f identTrans = Eigen::Affine3f::Identity();
|
Transform4x4f identTrans = Transform4x4f::Identity();
|
||||||
|
|
||||||
mGradient.setOpacity(mTitleOverlayOpacity);
|
mGradient.setOpacity(mTitleOverlayOpacity);
|
||||||
mGradient.render(identTrans);
|
mGradient.render(identTrans);
|
||||||
|
|
|
@ -7,12 +7,12 @@
|
||||||
#include "ThemeData.h"
|
#include "ThemeData.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
|
||||||
Eigen::Vector2i ImageComponent::getTextureSize() const
|
Vector2i ImageComponent::getTextureSize() const
|
||||||
{
|
{
|
||||||
if(mTexture)
|
if(mTexture)
|
||||||
return mTexture->getSize();
|
return mTexture->getSize();
|
||||||
else
|
else
|
||||||
return Eigen::Vector2i::Zero();
|
return Vector2i::Zero();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageComponent::ImageComponent(Window* window, bool forceLoad, bool dynamic) : GuiComponent(window),
|
ImageComponent::ImageComponent(Window* window, bool forceLoad, bool dynamic) : GuiComponent(window),
|
||||||
|
@ -31,8 +31,8 @@ void ImageComponent::resize()
|
||||||
if(!mTexture)
|
if(!mTexture)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const Eigen::Vector2f textureSize = mTexture->getSourceImageSize();
|
const Vector2f textureSize = mTexture->getSourceImageSize();
|
||||||
if(textureSize.isZero())
|
if(textureSize == Vector2f::Zero())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(mTexture->isTiled())
|
if(mTexture->isTiled())
|
||||||
|
@ -49,7 +49,7 @@ void ImageComponent::resize()
|
||||||
{
|
{
|
||||||
mSize = textureSize;
|
mSize = textureSize;
|
||||||
|
|
||||||
Eigen::Vector2f resizeScale((mTargetSize.x() / mSize.x()), (mTargetSize.y() / mSize.y()));
|
Vector2f resizeScale((mTargetSize.x() / mSize.x()), (mTargetSize.y() / mSize.y()));
|
||||||
|
|
||||||
if(resizeScale.x() < resizeScale.y())
|
if(resizeScale.x() < resizeScale.y())
|
||||||
{
|
{
|
||||||
|
@ -67,7 +67,7 @@ void ImageComponent::resize()
|
||||||
}else{
|
}else{
|
||||||
// if both components are set, we just stretch
|
// if both components are set, we just stretch
|
||||||
// if no components are set, we don't resize at all
|
// if no components are set, we don't resize at all
|
||||||
mSize = mTargetSize.isZero() ? textureSize : mTargetSize;
|
mSize = mTargetSize == Vector2f::Zero() ? textureSize : mTargetSize;
|
||||||
|
|
||||||
// if only one component is set, we resize in a way that maintains aspect ratio
|
// if only one component is set, we resize in a way that maintains aspect ratio
|
||||||
// for SVG rasterization, we always calculate width from rounded height (see comment above)
|
// for SVG rasterization, we always calculate width from rounded height (see comment above)
|
||||||
|
@ -131,14 +131,14 @@ void ImageComponent::setImage(const std::shared_ptr<TextureResource>& texture)
|
||||||
|
|
||||||
void ImageComponent::setResize(float width, float height)
|
void ImageComponent::setResize(float width, float height)
|
||||||
{
|
{
|
||||||
mTargetSize << width, height;
|
mTargetSize = Vector2f(width, height);
|
||||||
mTargetIsMax = false;
|
mTargetIsMax = false;
|
||||||
resize();
|
resize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageComponent::setMaxSize(float width, float height)
|
void ImageComponent::setMaxSize(float width, float height)
|
||||||
{
|
{
|
||||||
mTargetSize << width, height;
|
mTargetSize = Vector2f(width, height);
|
||||||
mTargetIsMax = true;
|
mTargetIsMax = true;
|
||||||
resize();
|
resize();
|
||||||
}
|
}
|
||||||
|
@ -178,16 +178,16 @@ void ImageComponent::updateVertices()
|
||||||
|
|
||||||
// we go through this mess to make sure everything is properly rounded
|
// we go through this mess to make sure everything is properly rounded
|
||||||
// if we just round vertices at the end, edge cases occur near sizes of 0.5
|
// if we just round vertices at the end, edge cases occur near sizes of 0.5
|
||||||
Eigen::Vector2f topLeft(0.0, 0.0);
|
Vector2f topLeft(0.0, 0.0);
|
||||||
Eigen::Vector2f bottomRight(round(mSize.x()), round(mSize.y()));
|
Vector2f bottomRight(round(mSize.x()), round(mSize.y()));
|
||||||
|
|
||||||
mVertices[0].pos << topLeft.x(), topLeft.y();
|
mVertices[0].pos = Vector2f(topLeft.x(), topLeft.y());
|
||||||
mVertices[1].pos << topLeft.x(), bottomRight.y();
|
mVertices[1].pos = Vector2f(topLeft.x(), bottomRight.y());
|
||||||
mVertices[2].pos << bottomRight.x(), topLeft.y();
|
mVertices[2].pos = Vector2f(bottomRight.x(), topLeft.y());
|
||||||
|
|
||||||
mVertices[3].pos << bottomRight.x(), topLeft.y();
|
mVertices[3].pos = Vector2f(bottomRight.x(), topLeft.y());
|
||||||
mVertices[4].pos << topLeft.x(), bottomRight.y();
|
mVertices[4].pos = Vector2f(topLeft.x(), bottomRight.y());
|
||||||
mVertices[5].pos << bottomRight.x(), bottomRight.y();
|
mVertices[5].pos = Vector2f(bottomRight.x(), bottomRight.y());
|
||||||
|
|
||||||
float px, py;
|
float px, py;
|
||||||
if(mTexture->isTiled())
|
if(mTexture->isTiled())
|
||||||
|
@ -199,13 +199,13 @@ void ImageComponent::updateVertices()
|
||||||
py = 1;
|
py = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
mVertices[0].tex << 0, py;
|
mVertices[0].tex = Vector2f(0, py);
|
||||||
mVertices[1].tex << 0, 0;
|
mVertices[1].tex = Vector2f(0, 0);
|
||||||
mVertices[2].tex << px, py;
|
mVertices[2].tex = Vector2f(px, py);
|
||||||
|
|
||||||
mVertices[3].tex << px, py;
|
mVertices[3].tex = Vector2f(px, py);
|
||||||
mVertices[4].tex << 0, 0;
|
mVertices[4].tex = Vector2f(0, 0);
|
||||||
mVertices[5].tex << px, 0;
|
mVertices[5].tex = Vector2f(px, 0);
|
||||||
|
|
||||||
if(mFlipX)
|
if(mFlipX)
|
||||||
{
|
{
|
||||||
|
@ -224,9 +224,9 @@ void ImageComponent::updateColors()
|
||||||
Renderer::buildGLColorArray(mColors, mColorShift, 6);
|
Renderer::buildGLColorArray(mColors, mColorShift, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageComponent::render(const Eigen::Affine3f& parentTrans)
|
void ImageComponent::render(const Transform4x4f& parentTrans)
|
||||||
{
|
{
|
||||||
Eigen::Affine3f trans = parentTrans * getTransform();
|
Transform4x4f trans = parentTrans * getTransform();
|
||||||
Renderer::setMatrix(trans);
|
Renderer::setMatrix(trans);
|
||||||
|
|
||||||
if(mTexture && mOpacity > 0)
|
if(mTexture && mOpacity > 0)
|
||||||
|
@ -324,25 +324,25 @@ void ImageComponent::applyTheme(const std::shared_ptr<ThemeData>& theme, const s
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Eigen::Vector2f scale = getParent() ? getParent()->getSize() : Eigen::Vector2f((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight());
|
Vector2f scale = getParent() ? getParent()->getSize() : Vector2f((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight());
|
||||||
|
|
||||||
if(properties & POSITION && elem->has("pos"))
|
if(properties & POSITION && elem->has("pos"))
|
||||||
{
|
{
|
||||||
Eigen::Vector2f denormalized = elem->get<Eigen::Vector2f>("pos").cwiseProduct(scale);
|
Vector2f denormalized = elem->get<Vector2f>("pos") * scale;
|
||||||
setPosition(Eigen::Vector3f(denormalized.x(), denormalized.y(), 0));
|
setPosition(Vector3f(denormalized.x(), denormalized.y(), 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(properties & ThemeFlags::SIZE)
|
if(properties & ThemeFlags::SIZE)
|
||||||
{
|
{
|
||||||
if(elem->has("size"))
|
if(elem->has("size"))
|
||||||
setResize(elem->get<Eigen::Vector2f>("size").cwiseProduct(scale));
|
setResize(elem->get<Vector2f>("size") * scale);
|
||||||
else if(elem->has("maxSize"))
|
else if(elem->has("maxSize"))
|
||||||
setMaxSize(elem->get<Eigen::Vector2f>("maxSize").cwiseProduct(scale));
|
setMaxSize(elem->get<Vector2f>("maxSize") * scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
// position + size also implies origin
|
// position + size also implies origin
|
||||||
if((properties & ORIGIN || (properties & POSITION && properties & ThemeFlags::SIZE)) && elem->has("origin"))
|
if((properties & ORIGIN || (properties & POSITION && properties & ThemeFlags::SIZE)) && elem->has("origin"))
|
||||||
setOrigin(elem->get<Eigen::Vector2f>("origin"));
|
setOrigin(elem->get<Vector2f>("origin"));
|
||||||
|
|
||||||
if(elem->has("default")) {
|
if(elem->has("default")) {
|
||||||
setDefaultImage(elem->get<std::string>("default"));
|
setDefaultImage(elem->get<std::string>("default"));
|
||||||
|
@ -361,7 +361,7 @@ void ImageComponent::applyTheme(const std::shared_ptr<ThemeData>& theme, const s
|
||||||
if(elem->has("rotation"))
|
if(elem->has("rotation"))
|
||||||
setRotationDegrees(elem->get<float>("rotation"));
|
setRotationDegrees(elem->get<float>("rotation"));
|
||||||
if(elem->has("rotationOrigin"))
|
if(elem->has("rotationOrigin"))
|
||||||
setRotationOrigin(elem->get<Eigen::Vector2f>("rotationOrigin"));
|
setRotationOrigin(elem->get<Vector2f>("rotationOrigin"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(properties & ThemeFlags::Z_INDEX && elem->has("zIndex"))
|
if(properties & ThemeFlags::Z_INDEX && elem->has("zIndex"))
|
||||||
|
|
|
@ -32,13 +32,13 @@ public:
|
||||||
// Can be set before or after an image is loaded.
|
// Can be set before or after an image is loaded.
|
||||||
// setMaxSize() and setResize() are mutually exclusive.
|
// setMaxSize() and setResize() are mutually exclusive.
|
||||||
void setResize(float width, float height);
|
void setResize(float width, float height);
|
||||||
inline void setResize(const Eigen::Vector2f& size) { setResize(size.x(), size.y()); }
|
inline void setResize(const Vector2f& size) { setResize(size.x(), size.y()); }
|
||||||
|
|
||||||
// Resize the image to be as large as possible but fit within a box of this size.
|
// Resize the image to be as large as possible but fit within a box of this size.
|
||||||
// Can be set before or after an image is loaded.
|
// Can be set before or after an image is loaded.
|
||||||
// Never breaks the aspect ratio. setMaxSize() and setResize() are mutually exclusive.
|
// Never breaks the aspect ratio. setMaxSize() and setResize() are mutually exclusive.
|
||||||
void setMaxSize(float width, float height);
|
void setMaxSize(float width, float height);
|
||||||
inline void setMaxSize(const Eigen::Vector2f& size) { setMaxSize(size.x(), size.y()); }
|
inline void setMaxSize(const Vector2f& size) { setMaxSize(size.x(), size.y()); }
|
||||||
|
|
||||||
// Multiply all pixels in the image by this color when rendering.
|
// Multiply all pixels in the image by this color when rendering.
|
||||||
void setColorShift(unsigned int color);
|
void setColorShift(unsigned int color);
|
||||||
|
@ -47,17 +47,17 @@ public:
|
||||||
void setFlipY(bool flip); // Mirror on the Y axis.
|
void setFlipY(bool flip); // Mirror on the Y axis.
|
||||||
|
|
||||||
// Returns the size of the current texture, or (0, 0) if none is loaded. May be different than drawn size (use getSize() for that).
|
// Returns the size of the current texture, or (0, 0) if none is loaded. May be different than drawn size (use getSize() for that).
|
||||||
Eigen::Vector2i getTextureSize() const;
|
Vector2i getTextureSize() const;
|
||||||
|
|
||||||
bool hasImage();
|
bool hasImage();
|
||||||
|
|
||||||
void render(const Eigen::Affine3f& parentTrans) override;
|
void render(const Transform4x4f& parentTrans) override;
|
||||||
|
|
||||||
virtual void applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view, const std::string& element, unsigned int properties) override;
|
virtual void applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view, const std::string& element, unsigned int properties) override;
|
||||||
|
|
||||||
virtual std::vector<HelpPrompt> getHelpPrompts() override;
|
virtual std::vector<HelpPrompt> getHelpPrompts() override;
|
||||||
private:
|
private:
|
||||||
Eigen::Vector2f mTargetSize;
|
Vector2f mTargetSize;
|
||||||
|
|
||||||
bool mFlipX, mFlipY, mTargetIsMax;
|
bool mFlipX, mFlipY, mTargetIsMax;
|
||||||
|
|
||||||
|
@ -67,8 +67,8 @@ private:
|
||||||
|
|
||||||
struct Vertex
|
struct Vertex
|
||||||
{
|
{
|
||||||
Eigen::Vector2f pos;
|
Vector2f pos;
|
||||||
Eigen::Vector2f tex;
|
Vector2f tex;
|
||||||
} mVertices[6];
|
} mVertices[6];
|
||||||
|
|
||||||
GLubyte mColors[6*4];
|
GLubyte mColors[6*4];
|
||||||
|
|
|
@ -37,16 +37,16 @@ public:
|
||||||
|
|
||||||
bool input(InputConfig* config, Input input) override;
|
bool input(InputConfig* config, Input input) override;
|
||||||
void update(int deltaTime) override;
|
void update(int deltaTime) override;
|
||||||
void render(const Eigen::Affine3f& parentTrans) override;
|
void render(const Transform4x4f& parentTrans) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Eigen::Vector2f getSquareSize(std::shared_ptr<TextureResource> tex = nullptr) const
|
Vector2f getSquareSize(std::shared_ptr<TextureResource> tex = nullptr) const
|
||||||
{
|
{
|
||||||
Eigen::Vector2f aspect(1, 1);
|
Vector2f aspect(1, 1);
|
||||||
|
|
||||||
if(tex)
|
if(tex)
|
||||||
{
|
{
|
||||||
const Eigen::Vector2i& texSize = tex->getSize();
|
const Vector2i& texSize = tex->getSize();
|
||||||
|
|
||||||
if(texSize.x() > texSize.y())
|
if(texSize.x() > texSize.y())
|
||||||
aspect[0] = (float)texSize.x() / texSize.y();
|
aspect[0] = (float)texSize.x() / texSize.y();
|
||||||
|
@ -54,17 +54,17 @@ private:
|
||||||
aspect[1] = (float)texSize.y() / texSize.x();
|
aspect[1] = (float)texSize.y() / texSize.x();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Eigen::Vector2f(156 * aspect.x(), 156 * aspect.y());
|
return Vector2f(156 * aspect.x(), 156 * aspect.y());
|
||||||
};
|
};
|
||||||
|
|
||||||
Eigen::Vector2f getMaxSquareSize() const
|
Vector2f getMaxSquareSize() const
|
||||||
{
|
{
|
||||||
Eigen::Vector2f squareSize(32, 32);
|
Vector2f squareSize(32, 32);
|
||||||
|
|
||||||
// calc biggest square size
|
// calc biggest square size
|
||||||
for(auto it = mEntries.begin(); it != mEntries.end(); it++)
|
for(auto it = mEntries.begin(); it != mEntries.end(); it++)
|
||||||
{
|
{
|
||||||
Eigen::Vector2f chkSize = getSquareSize(it->data.texture);
|
Vector2f chkSize = getSquareSize(it->data.texture);
|
||||||
if(chkSize.x() > squareSize.x())
|
if(chkSize.x() > squareSize.x())
|
||||||
squareSize[0] = chkSize[0];
|
squareSize[0] = chkSize[0];
|
||||||
if(chkSize.y() > squareSize.y())
|
if(chkSize.y() > squareSize.y())
|
||||||
|
@ -74,14 +74,14 @@ private:
|
||||||
return squareSize;
|
return squareSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
Eigen::Vector2i getGridSize() const
|
Vector2i getGridSize() const
|
||||||
{
|
{
|
||||||
Eigen::Vector2f squareSize = getMaxSquareSize();
|
Vector2f squareSize = getMaxSquareSize();
|
||||||
Eigen::Vector2i gridSize(mSize.x() / (squareSize.x() + getPadding().x()), mSize.y() / (squareSize.y() + getPadding().y()));
|
Vector2i gridSize(mSize.x() / (squareSize.x() + getPadding().x()), mSize.y() / (squareSize.y() + getPadding().y()));
|
||||||
return gridSize;
|
return gridSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
Eigen::Vector2f getPadding() const { return Eigen::Vector2f(24, 24); }
|
Vector2f getPadding() const { return Vector2f(24, 24); }
|
||||||
|
|
||||||
void buildImages();
|
void buildImages();
|
||||||
void updateImages();
|
void updateImages();
|
||||||
|
@ -115,7 +115,7 @@ bool ImageGridComponent<T>::input(InputConfig* config, Input input)
|
||||||
{
|
{
|
||||||
if(input.value != 0)
|
if(input.value != 0)
|
||||||
{
|
{
|
||||||
Eigen::Vector2i dir = Eigen::Vector2i::Zero();
|
Vector2i dir = Vector2i::Zero();
|
||||||
if(config->isMappedTo("up", input))
|
if(config->isMappedTo("up", input))
|
||||||
dir[1] = -1;
|
dir[1] = -1;
|
||||||
else if(config->isMappedTo("down", input))
|
else if(config->isMappedTo("down", input))
|
||||||
|
@ -125,7 +125,7 @@ bool ImageGridComponent<T>::input(InputConfig* config, Input input)
|
||||||
else if(config->isMappedTo("right", input))
|
else if(config->isMappedTo("right", input))
|
||||||
dir[0] = 1;
|
dir[0] = 1;
|
||||||
|
|
||||||
if(dir != Eigen::Vector2i::Zero())
|
if(dir != Vector2i::Zero())
|
||||||
{
|
{
|
||||||
listInput(dir.x() + dir.y() * getGridSize().x());
|
listInput(dir.x() + dir.y() * getGridSize().x());
|
||||||
return true;
|
return true;
|
||||||
|
@ -147,9 +147,9 @@ void ImageGridComponent<T>::update(int deltaTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void ImageGridComponent<T>::render(const Eigen::Affine3f& parentTrans)
|
void ImageGridComponent<T>::render(const Transform4x4f& parentTrans)
|
||||||
{
|
{
|
||||||
Eigen::Affine3f trans = getTransform() * parentTrans;
|
Transform4x4f trans = getTransform() * parentTrans;
|
||||||
|
|
||||||
if(mEntriesDirty)
|
if(mEntriesDirty)
|
||||||
{
|
{
|
||||||
|
@ -185,13 +185,13 @@ void ImageGridComponent<T>::buildImages()
|
||||||
{
|
{
|
||||||
mImages.clear();
|
mImages.clear();
|
||||||
|
|
||||||
Eigen::Vector2i gridSize = getGridSize();
|
Vector2i gridSize = getGridSize();
|
||||||
Eigen::Vector2f squareSize = getMaxSquareSize();
|
Vector2f squareSize = getMaxSquareSize();
|
||||||
Eigen::Vector2f padding = getPadding();
|
Vector2f padding = getPadding();
|
||||||
|
|
||||||
// attempt to center within our size
|
// attempt to center within our size
|
||||||
Eigen::Vector2f totalSize(gridSize.x() * (squareSize.x() + padding.x()), gridSize.y() * (squareSize.y() + padding.y()));
|
Vector2f totalSize(gridSize.x() * (squareSize.x() + padding.x()), gridSize.y() * (squareSize.y() + padding.y()));
|
||||||
Eigen::Vector2f offset(mSize.x() - totalSize.x(), mSize.y() - totalSize.y());
|
Vector2f offset(mSize.x() - totalSize.x(), mSize.y() - totalSize.y());
|
||||||
offset /= 2;
|
offset /= 2;
|
||||||
|
|
||||||
for(int y = 0; y < gridSize.y(); y++)
|
for(int y = 0; y < gridSize.y(); y++)
|
||||||
|
@ -215,7 +215,7 @@ void ImageGridComponent<T>::updateImages()
|
||||||
if(mImages.empty())
|
if(mImages.empty())
|
||||||
buildImages();
|
buildImages();
|
||||||
|
|
||||||
Eigen::Vector2i gridSize = getGridSize();
|
Vector2i gridSize = getGridSize();
|
||||||
|
|
||||||
int cursorRow = mCursor / gridSize.x();
|
int cursorRow = mCursor / gridSize.x();
|
||||||
|
|
||||||
|
@ -238,7 +238,7 @@ void ImageGridComponent<T>::updateImages()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Eigen::Vector2f squareSize = getSquareSize(mEntries.at(i).data.texture);
|
Vector2f squareSize = getSquareSize(mEntries.at(i).data.texture);
|
||||||
if(i == (unsigned int)mCursor)
|
if(i == (unsigned int)mCursor)
|
||||||
{
|
{
|
||||||
image.setColorShift(0xFFFFFFFF);
|
image.setColorShift(0xFFFFFFFF);
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
|
|
||||||
#define TITLE_HEIGHT (mTitle->getFont()->getLetterHeight() + TITLE_VERT_PADDING)
|
#define TITLE_HEIGHT (mTitle->getFont()->getLetterHeight() + TITLE_VERT_PADDING)
|
||||||
|
|
||||||
using namespace Eigen;
|
|
||||||
|
|
||||||
MenuComponent::MenuComponent(Window* window, const char* title, const std::shared_ptr<Font>& titleFont) : GuiComponent(window),
|
MenuComponent::MenuComponent(Window* window, const char* title, const std::shared_ptr<Font>& titleFont) : GuiComponent(window),
|
||||||
mBackground(window), mGrid(window, Vector2i(1, 3))
|
mBackground(window), mGrid(window, Vector2i(1, 3))
|
||||||
{
|
{
|
||||||
|
@ -69,7 +67,7 @@ void MenuComponent::updateSize()
|
||||||
|
|
||||||
void MenuComponent::onSizeChanged()
|
void MenuComponent::onSizeChanged()
|
||||||
{
|
{
|
||||||
mBackground.fitTo(mSize, Eigen::Vector3f::Zero(), Eigen::Vector2f(-32, -32));
|
mBackground.fitTo(mSize, Vector3f::Zero(), Vector2f(-32, -32));
|
||||||
|
|
||||||
// update grid row/col sizes
|
// update grid row/col sizes
|
||||||
mGrid.setRowHeightPerc(0, TITLE_HEIGHT / mSize.y());
|
mGrid.setRowHeightPerc(0, TITLE_HEIGHT / mSize.y());
|
||||||
|
|
|
@ -39,7 +39,7 @@ void NinePatchComponent::buildVertices()
|
||||||
|
|
||||||
mTexture = TextureResource::get(mPath);
|
mTexture = TextureResource::get(mPath);
|
||||||
|
|
||||||
if(mTexture->getSize() == Eigen::Vector2i::Zero())
|
if(mTexture->getSize() == Vector2i::Zero())
|
||||||
{
|
{
|
||||||
mVertices = NULL;
|
mVertices = NULL;
|
||||||
mColors = NULL;
|
mColors = NULL;
|
||||||
|
@ -51,22 +51,22 @@ void NinePatchComponent::buildVertices()
|
||||||
mColors = new GLubyte[6 * 9 * 4];
|
mColors = new GLubyte[6 * 9 * 4];
|
||||||
updateColors();
|
updateColors();
|
||||||
|
|
||||||
const Eigen::Vector2f ts = mTexture->getSize().cast<float>();
|
const Vector2f ts = Vector2f(mTexture->getSize().x(), mTexture->getSize().y());
|
||||||
|
|
||||||
//coordinates on the image in pixels, top left origin
|
//coordinates on the image in pixels, top left origin
|
||||||
const Eigen::Vector2f pieceCoords[9] = {
|
const Vector2f pieceCoords[9] = {
|
||||||
Eigen::Vector2f(0, 0),
|
Vector2f(0, 0),
|
||||||
Eigen::Vector2f(16, 0),
|
Vector2f(16, 0),
|
||||||
Eigen::Vector2f(32, 0),
|
Vector2f(32, 0),
|
||||||
Eigen::Vector2f(0, 16),
|
Vector2f(0, 16),
|
||||||
Eigen::Vector2f(16, 16),
|
Vector2f(16, 16),
|
||||||
Eigen::Vector2f(32, 16),
|
Vector2f(32, 16),
|
||||||
Eigen::Vector2f(0, 32),
|
Vector2f(0, 32),
|
||||||
Eigen::Vector2f(16, 32),
|
Vector2f(16, 32),
|
||||||
Eigen::Vector2f(32, 32),
|
Vector2f(32, 32),
|
||||||
};
|
};
|
||||||
|
|
||||||
const Eigen::Vector2f pieceSizes = getCornerSize();
|
const Vector2f pieceSizes = getCornerSize();
|
||||||
|
|
||||||
//corners never stretch, so we calculate a width and height for slices 1, 3, 5, and 7
|
//corners never stretch, so we calculate a width and height for slices 1, 3, 5, and 7
|
||||||
float borderWidth = mSize.x() - (pieceSizes.x() * 2); //should be pieceSizes[0] and pieceSizes[2]
|
float borderWidth = mSize.x() - (pieceSizes.x() * 2); //should be pieceSizes[0] and pieceSizes[2]
|
||||||
|
@ -79,20 +79,20 @@ void NinePatchComponent::buildVertices()
|
||||||
|
|
||||||
mVertices[0 * 6].pos = pieceCoords[0]; //top left
|
mVertices[0 * 6].pos = pieceCoords[0]; //top left
|
||||||
mVertices[1 * 6].pos = pieceCoords[1]; //top middle
|
mVertices[1 * 6].pos = pieceCoords[1]; //top middle
|
||||||
mVertices[2 * 6].pos = pieceCoords[1] + Eigen::Vector2f(borderWidth, 0); //top right
|
mVertices[2 * 6].pos = pieceCoords[1] + Vector2f(borderWidth, 0); //top right
|
||||||
|
|
||||||
mVertices[3 * 6].pos = mVertices[0 * 6].pos + Eigen::Vector2f(0, pieceSizes.y()); //mid left
|
mVertices[3 * 6].pos = mVertices[0 * 6].pos + Vector2f(0, pieceSizes.y()); //mid left
|
||||||
mVertices[4 * 6].pos = mVertices[3 * 6].pos + Eigen::Vector2f(pieceSizes.x(), 0); //mid middle
|
mVertices[4 * 6].pos = mVertices[3 * 6].pos + Vector2f(pieceSizes.x(), 0); //mid middle
|
||||||
mVertices[5 * 6].pos = mVertices[4 * 6].pos + Eigen::Vector2f(borderWidth, 0); //mid right
|
mVertices[5 * 6].pos = mVertices[4 * 6].pos + Vector2f(borderWidth, 0); //mid right
|
||||||
|
|
||||||
mVertices[6 * 6].pos = mVertices[3 * 6].pos + Eigen::Vector2f(0, borderHeight); //bot left
|
mVertices[6 * 6].pos = mVertices[3 * 6].pos + Vector2f(0, borderHeight); //bot left
|
||||||
mVertices[7 * 6].pos = mVertices[6 * 6].pos + Eigen::Vector2f(pieceSizes.x(), 0); //bot middle
|
mVertices[7 * 6].pos = mVertices[6 * 6].pos + Vector2f(pieceSizes.x(), 0); //bot middle
|
||||||
mVertices[8 * 6].pos = mVertices[7 * 6].pos + Eigen::Vector2f(borderWidth, 0); //bot right
|
mVertices[8 * 6].pos = mVertices[7 * 6].pos + Vector2f(borderWidth, 0); //bot right
|
||||||
|
|
||||||
int v = 0;
|
int v = 0;
|
||||||
for(int slice = 0; slice < 9; slice++)
|
for(int slice = 0; slice < 9; slice++)
|
||||||
{
|
{
|
||||||
Eigen::Vector2f size;
|
Vector2f size;
|
||||||
|
|
||||||
//corners
|
//corners
|
||||||
if(slice == 0 || slice == 2 || slice == 6 || slice == 8)
|
if(slice == 0 || slice == 2 || slice == 6 || slice == 8)
|
||||||
|
@ -100,32 +100,32 @@ void NinePatchComponent::buildVertices()
|
||||||
|
|
||||||
//vertical borders
|
//vertical borders
|
||||||
if(slice == 1 || slice == 7)
|
if(slice == 1 || slice == 7)
|
||||||
size << borderWidth, pieceSizes.y();
|
size = Vector2f(borderWidth, pieceSizes.y());
|
||||||
|
|
||||||
//horizontal borders
|
//horizontal borders
|
||||||
if(slice == 3 || slice == 5)
|
if(slice == 3 || slice == 5)
|
||||||
size << pieceSizes.x(), borderHeight;
|
size = Vector2f(pieceSizes.x(), borderHeight);
|
||||||
|
|
||||||
//center
|
//center
|
||||||
if(slice == 4)
|
if(slice == 4)
|
||||||
size << borderWidth, borderHeight;
|
size = Vector2f(borderWidth, borderHeight);
|
||||||
|
|
||||||
//no resizing will be necessary
|
//no resizing will be necessary
|
||||||
//mVertices[v + 0] is already correct
|
//mVertices[v + 0] is already correct
|
||||||
mVertices[v + 1].pos = mVertices[v + 0].pos + size;
|
mVertices[v + 1].pos = mVertices[v + 0].pos + size;
|
||||||
mVertices[v + 2].pos << mVertices[v + 0].pos.x(), mVertices[v + 1].pos.y();
|
mVertices[v + 2].pos = Vector2f(mVertices[v + 0].pos.x(), mVertices[v + 1].pos.y());
|
||||||
|
|
||||||
mVertices[v + 3].pos << mVertices[v + 1].pos.x(), mVertices[v + 0].pos.y();
|
mVertices[v + 3].pos = Vector2f(mVertices[v + 1].pos.x(), mVertices[v + 0].pos.y());
|
||||||
mVertices[v + 4].pos = mVertices[v + 1].pos;
|
mVertices[v + 4].pos = mVertices[v + 1].pos;
|
||||||
mVertices[v + 5].pos = mVertices[v + 0].pos;
|
mVertices[v + 5].pos = mVertices[v + 0].pos;
|
||||||
|
|
||||||
//texture coordinates
|
//texture coordinates
|
||||||
//the y = (1 - y) is to deal with texture coordinates having a bottom left corner origin vs. verticies having a top left origin
|
//the y = (1 - y) is to deal with texture coordinates having a bottom left corner origin vs. verticies having a top left origin
|
||||||
mVertices[v + 0].tex << pieceCoords[slice].x() / ts.x(), 1 - (pieceCoords[slice].y() / ts.y());
|
mVertices[v + 0].tex = Vector2f(pieceCoords[slice].x() / ts.x(), 1 - (pieceCoords[slice].y() / ts.y()));
|
||||||
mVertices[v + 1].tex << (pieceCoords[slice].x() + pieceSizes.x()) / ts.x(), 1 - ((pieceCoords[slice].y() + pieceSizes.y()) / ts.y());
|
mVertices[v + 1].tex = Vector2f((pieceCoords[slice].x() + pieceSizes.x()) / ts.x(), 1 - ((pieceCoords[slice].y() + pieceSizes.y()) / ts.y()));
|
||||||
mVertices[v + 2].tex << mVertices[v + 0].tex.x(), mVertices[v + 1].tex.y();
|
mVertices[v + 2].tex = Vector2f(mVertices[v + 0].tex.x(), mVertices[v + 1].tex.y());
|
||||||
|
|
||||||
mVertices[v + 3].tex << mVertices[v + 1].tex.x(), mVertices[v + 0].tex.y();
|
mVertices[v + 3].tex = Vector2f(mVertices[v + 1].tex.x(), mVertices[v + 0].tex.y());
|
||||||
mVertices[v + 4].tex = mVertices[v + 1].tex;
|
mVertices[v + 4].tex = mVertices[v + 1].tex;
|
||||||
mVertices[v + 5].tex = mVertices[v + 0].tex;
|
mVertices[v + 5].tex = mVertices[v + 0].tex;
|
||||||
|
|
||||||
|
@ -135,13 +135,14 @@ void NinePatchComponent::buildVertices()
|
||||||
// round vertices
|
// round vertices
|
||||||
for(int i = 0; i < 6*9; i++)
|
for(int i = 0; i < 6*9; i++)
|
||||||
{
|
{
|
||||||
mVertices[i].pos = roundVector(mVertices[i].pos);
|
mVertices[i].pos.round();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NinePatchComponent::render(const Eigen::Affine3f& parentTrans)
|
void NinePatchComponent::render(const Transform4x4f& parentTrans)
|
||||||
{
|
{
|
||||||
Eigen::Affine3f trans = roundMatrix(parentTrans * getTransform());
|
Transform4x4f trans = parentTrans * getTransform();
|
||||||
|
trans.round();
|
||||||
|
|
||||||
if(mTexture && mVertices != NULL)
|
if(mTexture && mVertices != NULL)
|
||||||
{
|
{
|
||||||
|
@ -179,18 +180,18 @@ void NinePatchComponent::onSizeChanged()
|
||||||
buildVertices();
|
buildVertices();
|
||||||
}
|
}
|
||||||
|
|
||||||
Eigen::Vector2f NinePatchComponent::getCornerSize() const
|
Vector2f NinePatchComponent::getCornerSize() const
|
||||||
{
|
{
|
||||||
return Eigen::Vector2f(16, 16);
|
return Vector2f(16, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NinePatchComponent::fitTo(Eigen::Vector2f size, Eigen::Vector3f position, Eigen::Vector2f padding)
|
void NinePatchComponent::fitTo(Vector2f size, Vector3f position, Vector2f padding)
|
||||||
{
|
{
|
||||||
size += padding;
|
size += padding;
|
||||||
position[0] -= padding.x() / 2;
|
position[0] -= padding.x() / 2;
|
||||||
position[1] -= padding.y() / 2;
|
position[1] -= padding.y() / 2;
|
||||||
|
|
||||||
setSize(size + Eigen::Vector2f(getCornerSize().x() * 2, getCornerSize().y() * 2));
|
setSize(size + Vector2f(getCornerSize().x() * 2, getCornerSize().y() * 2));
|
||||||
setPosition(-getCornerSize().x() + position.x(), -getCornerSize().y() + position.y());
|
setPosition(-getCornerSize().x() + position.x(), -getCornerSize().y() + position.y());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,11 +20,11 @@ public:
|
||||||
NinePatchComponent(Window* window, const std::string& path = "", unsigned int edgeColor = 0xFFFFFFFF, unsigned int centerColor = 0xFFFFFFFF);
|
NinePatchComponent(Window* window, const std::string& path = "", unsigned int edgeColor = 0xFFFFFFFF, unsigned int centerColor = 0xFFFFFFFF);
|
||||||
virtual ~NinePatchComponent();
|
virtual ~NinePatchComponent();
|
||||||
|
|
||||||
void render(const Eigen::Affine3f& parentTrans) override;
|
void render(const Transform4x4f& parentTrans) override;
|
||||||
|
|
||||||
void onSizeChanged() override;
|
void onSizeChanged() override;
|
||||||
|
|
||||||
void fitTo(Eigen::Vector2f size, Eigen::Vector3f position = Eigen::Vector3f::Zero(), Eigen::Vector2f padding = Eigen::Vector2f::Zero());
|
void fitTo(Vector2f size, Vector3f position = Vector3f::Zero(), Vector2f padding = Vector2f::Zero());
|
||||||
|
|
||||||
void setImagePath(const std::string& path);
|
void setImagePath(const std::string& path);
|
||||||
void setEdgeColor(unsigned int edgeColor); // Apply a color shift to the "edge" parts of the ninepatch.
|
void setEdgeColor(unsigned int edgeColor); // Apply a color shift to the "edge" parts of the ninepatch.
|
||||||
|
@ -33,15 +33,15 @@ public:
|
||||||
virtual void applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view, const std::string& element, unsigned int properties) override;
|
virtual void applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view, const std::string& element, unsigned int properties) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Eigen::Vector2f getCornerSize() const;
|
Vector2f getCornerSize() const;
|
||||||
|
|
||||||
void buildVertices();
|
void buildVertices();
|
||||||
void updateColors();
|
void updateColors();
|
||||||
|
|
||||||
struct Vertex
|
struct Vertex
|
||||||
{
|
{
|
||||||
Eigen::Vector2f pos;
|
Vector2f pos;
|
||||||
Eigen::Vector2f tex;
|
Vector2f tex;
|
||||||
};
|
};
|
||||||
|
|
||||||
Vertex* mVertices;
|
Vertex* mVertices;
|
||||||
|
|
|
@ -11,18 +11,18 @@ ScrollableContainer::ScrollableContainer(Window* window) : GuiComponent(window),
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollableContainer::render(const Eigen::Affine3f& parentTrans)
|
void ScrollableContainer::render(const Transform4x4f& parentTrans)
|
||||||
{
|
{
|
||||||
Eigen::Affine3f trans = parentTrans * getTransform();
|
Transform4x4f trans = parentTrans * getTransform();
|
||||||
|
|
||||||
Eigen::Vector2i clipPos((int)trans.translation().x(), (int)trans.translation().y());
|
Vector2i clipPos((int)trans.translation().x(), (int)trans.translation().y());
|
||||||
|
|
||||||
Eigen::Vector3f dimScaled = trans * Eigen::Vector3f(mSize.x(), mSize.y(), 0);
|
Vector3f dimScaled = trans * Vector3f(mSize.x(), mSize.y(), 0);
|
||||||
Eigen::Vector2i clipDim((int)dimScaled.x() - trans.translation().x(), (int)dimScaled.y() - trans.translation().y());
|
Vector2i clipDim((int)dimScaled.x() - trans.translation().x(), (int)dimScaled.y() - trans.translation().y());
|
||||||
|
|
||||||
Renderer::pushClipRect(clipPos, clipDim);
|
Renderer::pushClipRect(clipPos, clipDim);
|
||||||
|
|
||||||
trans.translate(-Eigen::Vector3f(mScrollPos.x(), mScrollPos.y(), 0));
|
trans.translate(-Vector3f(mScrollPos.x(), mScrollPos.y(), 0));
|
||||||
Renderer::setMatrix(trans);
|
Renderer::setMatrix(trans);
|
||||||
|
|
||||||
GuiComponent::renderChildren(trans);
|
GuiComponent::renderChildren(trans);
|
||||||
|
@ -34,24 +34,24 @@ void ScrollableContainer::setAutoScroll(bool autoScroll)
|
||||||
{
|
{
|
||||||
if(autoScroll)
|
if(autoScroll)
|
||||||
{
|
{
|
||||||
mScrollDir << 0, 1;
|
mScrollDir = Vector2f(0, 1);
|
||||||
mAutoScrollDelay = AUTO_SCROLL_DELAY;
|
mAutoScrollDelay = AUTO_SCROLL_DELAY;
|
||||||
mAutoScrollSpeed = AUTO_SCROLL_SPEED;
|
mAutoScrollSpeed = AUTO_SCROLL_SPEED;
|
||||||
reset();
|
reset();
|
||||||
}else{
|
}else{
|
||||||
mScrollDir << 0, 0;
|
mScrollDir = Vector2f(0, 0);
|
||||||
mAutoScrollDelay = 0;
|
mAutoScrollDelay = 0;
|
||||||
mAutoScrollSpeed = 0;
|
mAutoScrollSpeed = 0;
|
||||||
mAutoScrollAccumulator = 0;
|
mAutoScrollAccumulator = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Eigen::Vector2f ScrollableContainer::getScrollPos() const
|
Vector2f ScrollableContainer::getScrollPos() const
|
||||||
{
|
{
|
||||||
return mScrollPos;
|
return mScrollPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollableContainer::setScrollPos(const Eigen::Vector2f& pos)
|
void ScrollableContainer::setScrollPos(const Vector2f& pos)
|
||||||
{
|
{
|
||||||
mScrollPos = pos;
|
mScrollPos = pos;
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ void ScrollableContainer::update(int deltaTime)
|
||||||
if(mScrollPos.y() < 0)
|
if(mScrollPos.y() < 0)
|
||||||
mScrollPos[1] = 0;
|
mScrollPos[1] = 0;
|
||||||
|
|
||||||
const Eigen::Vector2f contentSize = getContentSize();
|
const Vector2f contentSize = getContentSize();
|
||||||
if(mScrollPos.x() + getSize().x() > contentSize.x())
|
if(mScrollPos.x() + getSize().x() > contentSize.x())
|
||||||
{
|
{
|
||||||
mScrollPos[0] = contentSize.x() - getSize().x();
|
mScrollPos[0] = contentSize.x() - getSize().x();
|
||||||
|
@ -104,13 +104,13 @@ void ScrollableContainer::update(int deltaTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
//this should probably return a box to allow for when controls don't start at 0,0
|
//this should probably return a box to allow for when controls don't start at 0,0
|
||||||
Eigen::Vector2f ScrollableContainer::getContentSize()
|
Vector2f ScrollableContainer::getContentSize()
|
||||||
{
|
{
|
||||||
Eigen::Vector2f max(0, 0);
|
Vector2f max(0, 0);
|
||||||
for(unsigned int i = 0; i < mChildren.size(); i++)
|
for(unsigned int i = 0; i < mChildren.size(); i++)
|
||||||
{
|
{
|
||||||
Eigen::Vector2f pos(mChildren.at(i)->getPosition()[0], mChildren.at(i)->getPosition()[1]);
|
Vector2f pos(mChildren.at(i)->getPosition()[0], mChildren.at(i)->getPosition()[1]);
|
||||||
Eigen::Vector2f bottomRight = mChildren.at(i)->getSize() + pos;
|
Vector2f bottomRight = mChildren.at(i)->getSize() + pos;
|
||||||
if(bottomRight.x() > max.x())
|
if(bottomRight.x() > max.x())
|
||||||
max.x() = bottomRight.x();
|
max.x() = bottomRight.x();
|
||||||
if(bottomRight.y() > max.y())
|
if(bottomRight.y() > max.y())
|
||||||
|
@ -122,7 +122,7 @@ Eigen::Vector2f ScrollableContainer::getContentSize()
|
||||||
|
|
||||||
void ScrollableContainer::reset()
|
void ScrollableContainer::reset()
|
||||||
{
|
{
|
||||||
mScrollPos << 0, 0;
|
mScrollPos = Vector2f(0, 0);
|
||||||
mAutoScrollResetAccumulator = 0;
|
mAutoScrollResetAccumulator = 0;
|
||||||
mAutoScrollAccumulator = -mAutoScrollDelay + mAutoScrollSpeed;
|
mAutoScrollAccumulator = -mAutoScrollDelay + mAutoScrollSpeed;
|
||||||
mAtEnd = false;
|
mAtEnd = false;
|
||||||
|
|
|
@ -7,19 +7,19 @@ class ScrollableContainer : public GuiComponent
|
||||||
public:
|
public:
|
||||||
ScrollableContainer(Window* window);
|
ScrollableContainer(Window* window);
|
||||||
|
|
||||||
Eigen::Vector2f getScrollPos() const;
|
Vector2f getScrollPos() const;
|
||||||
void setScrollPos(const Eigen::Vector2f& pos);
|
void setScrollPos(const Vector2f& pos);
|
||||||
void setAutoScroll(bool autoScroll);
|
void setAutoScroll(bool autoScroll);
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
void update(int deltaTime) override;
|
void update(int deltaTime) override;
|
||||||
void render(const Eigen::Affine3f& parentTrans) override;
|
void render(const Transform4x4f& parentTrans) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Eigen::Vector2f getContentSize();
|
Vector2f getContentSize();
|
||||||
|
|
||||||
Eigen::Vector2f mScrollPos;
|
Vector2f mScrollPos;
|
||||||
Eigen::Vector2f mScrollDir;
|
Vector2f mScrollDir;
|
||||||
int mAutoScrollDelay; // ms to wait before starting to autoscroll
|
int mAutoScrollDelay; // ms to wait before starting to autoscroll
|
||||||
int mAutoScrollSpeed; // ms to wait before scrolling down by mScrollDir
|
int mAutoScrollSpeed; // ms to wait before scrolling down by mScrollDir
|
||||||
int mAutoScrollAccumulator;
|
int mAutoScrollAccumulator;
|
||||||
|
|
|
@ -61,9 +61,10 @@ void SliderComponent::update(int deltaTime)
|
||||||
GuiComponent::update(deltaTime);
|
GuiComponent::update(deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SliderComponent::render(const Eigen::Affine3f& parentTrans)
|
void SliderComponent::render(const Transform4x4f& parentTrans)
|
||||||
{
|
{
|
||||||
Eigen::Affine3f trans = roundMatrix(parentTrans * getTransform());
|
Transform4x4f trans = parentTrans * getTransform();
|
||||||
|
trans.round();
|
||||||
Renderer::setMatrix(trans);
|
Renderer::setMatrix(trans);
|
||||||
|
|
||||||
// render suffix
|
// render suffix
|
||||||
|
@ -126,7 +127,7 @@ void SliderComponent::onValueChanged()
|
||||||
ss << mSuffix;
|
ss << mSuffix;
|
||||||
const std::string max = ss.str();
|
const std::string max = ss.str();
|
||||||
|
|
||||||
Eigen::Vector2f textSize = mFont->sizeText(max);
|
Vector2f textSize = mFont->sizeText(max);
|
||||||
mValueCache = std::shared_ptr<TextCache>(mFont->buildTextCache(val, mSize.x() - textSize.x(), (mSize.y() - textSize.y()) / 2, 0x777777FF));
|
mValueCache = std::shared_ptr<TextCache>(mFont->buildTextCache(val, mSize.x() - textSize.x(), (mSize.y() - textSize.y()) / 2, 0x777777FF));
|
||||||
mValueCache->metrics.size[0] = textSize.x(); // fudge the width
|
mValueCache->metrics.size[0] = textSize.x(); // fudge the width
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ public:
|
||||||
|
|
||||||
bool input(InputConfig* config, Input input) override;
|
bool input(InputConfig* config, Input input) override;
|
||||||
void update(int deltaTime) override;
|
void update(int deltaTime) override;
|
||||||
void render(const Eigen::Affine3f& parentTrans) override;
|
void render(const Transform4x4f& parentTrans) override;
|
||||||
|
|
||||||
void onSizeChanged() override;
|
void onSizeChanged() override;
|
||||||
|
|
||||||
|
|
|
@ -27,9 +27,9 @@ bool SwitchComponent::input(InputConfig* config, Input input)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwitchComponent::render(const Eigen::Affine3f& parentTrans)
|
void SwitchComponent::render(const Transform4x4f& parentTrans)
|
||||||
{
|
{
|
||||||
Eigen::Affine3f trans = parentTrans * getTransform();
|
Transform4x4f trans = parentTrans * getTransform();
|
||||||
|
|
||||||
mImage.render(trans);
|
mImage.render(trans);
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ public:
|
||||||
SwitchComponent(Window* window, bool state = false);
|
SwitchComponent(Window* window, bool state = false);
|
||||||
|
|
||||||
bool input(InputConfig* config, Input input) override;
|
bool input(InputConfig* config, Input input) override;
|
||||||
void render(const Eigen::Affine3f& parentTrans) override;
|
void render(const Transform4x4f& parentTrans) override;
|
||||||
void onSizeChanged() override;
|
void onSizeChanged() override;
|
||||||
|
|
||||||
bool getState() const;
|
bool getState() const;
|
||||||
|
|
|
@ -15,7 +15,7 @@ TextComponent::TextComponent(Window* window) : GuiComponent(window),
|
||||||
}
|
}
|
||||||
|
|
||||||
TextComponent::TextComponent(Window* window, const std::string& text, const std::shared_ptr<Font>& font, unsigned int color, Alignment align,
|
TextComponent::TextComponent(Window* window, const std::string& text, const std::shared_ptr<Font>& font, unsigned int color, Alignment align,
|
||||||
Eigen::Vector3f pos, Eigen::Vector2f size, unsigned int bgcolor) : GuiComponent(window),
|
Vector3f pos, Vector2f size, unsigned int bgcolor) : GuiComponent(window),
|
||||||
mFont(NULL), mUppercase(false), mColor(0x000000FF), mAutoCalcExtent(true, true),
|
mFont(NULL), mUppercase(false), mColor(0x000000FF), mAutoCalcExtent(true, true),
|
||||||
mHorizontalAlignment(align), mVerticalAlignment(ALIGN_CENTER), mLineSpacing(1.5f), mBgColor(0),
|
mHorizontalAlignment(align), mVerticalAlignment(ALIGN_CENTER), mLineSpacing(1.5f), mBgColor(0),
|
||||||
mRenderBackground(false)
|
mRenderBackground(false)
|
||||||
|
@ -30,7 +30,7 @@ TextComponent::TextComponent(Window* window, const std::string& text, const std:
|
||||||
|
|
||||||
void TextComponent::onSizeChanged()
|
void TextComponent::onSizeChanged()
|
||||||
{
|
{
|
||||||
mAutoCalcExtent << (getSize().x() == 0), (getSize().y() == 0);
|
mAutoCalcExtent = Vector2i((getSize().x() == 0), (getSize().y() == 0));
|
||||||
onTextChanged();
|
onTextChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,9 +95,9 @@ void TextComponent::setUppercase(bool uppercase)
|
||||||
onTextChanged();
|
onTextChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextComponent::render(const Eigen::Affine3f& parentTrans)
|
void TextComponent::render(const Transform4x4f& parentTrans)
|
||||||
{
|
{
|
||||||
Eigen::Affine3f trans = parentTrans * getTransform();
|
Transform4x4f trans = parentTrans * getTransform();
|
||||||
|
|
||||||
if (mRenderBackground)
|
if (mRenderBackground)
|
||||||
{
|
{
|
||||||
|
@ -107,7 +107,7 @@ void TextComponent::render(const Eigen::Affine3f& parentTrans)
|
||||||
|
|
||||||
if(mTextCache)
|
if(mTextCache)
|
||||||
{
|
{
|
||||||
const Eigen::Vector2f& textSize = mTextCache->metrics.size;
|
const Vector2f& textSize = mTextCache->metrics.size;
|
||||||
float yOff;
|
float yOff;
|
||||||
switch(mVerticalAlignment)
|
switch(mVerticalAlignment)
|
||||||
{
|
{
|
||||||
|
@ -121,7 +121,7 @@ void TextComponent::render(const Eigen::Affine3f& parentTrans)
|
||||||
yOff = (getSize().y() - textSize.y()) / 2.0f;
|
yOff = (getSize().y() - textSize.y()) / 2.0f;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Eigen::Vector3f off(0, yOff, 0);
|
Vector3f off(0, yOff, 0);
|
||||||
|
|
||||||
if(Settings::getInstance()->getBool("DebugText"))
|
if(Settings::getInstance()->getBool("DebugText"))
|
||||||
{
|
{
|
||||||
|
@ -131,7 +131,7 @@ void TextComponent::render(const Eigen::Affine3f& parentTrans)
|
||||||
}
|
}
|
||||||
|
|
||||||
trans.translate(off);
|
trans.translate(off);
|
||||||
trans = roundMatrix(trans);
|
trans.round();
|
||||||
Renderer::setMatrix(trans);
|
Renderer::setMatrix(trans);
|
||||||
|
|
||||||
// draw the text area, where the text actually is going
|
// draw the text area, where the text actually is going
|
||||||
|
@ -190,12 +190,12 @@ void TextComponent::onTextChanged()
|
||||||
addAbbrev = newline != std::string::npos;
|
addAbbrev = newline != std::string::npos;
|
||||||
}
|
}
|
||||||
|
|
||||||
Eigen::Vector2f size = f->sizeText(text);
|
Vector2f size = f->sizeText(text);
|
||||||
if(!isMultiline && mSize.x() && text.size() && (size.x() > mSize.x() || addAbbrev))
|
if(!isMultiline && mSize.x() && text.size() && (size.x() > mSize.x() || addAbbrev))
|
||||||
{
|
{
|
||||||
// abbreviate text
|
// abbreviate text
|
||||||
const std::string abbrev = "...";
|
const std::string abbrev = "...";
|
||||||
Eigen::Vector2f abbrevSize = f->sizeText(abbrev);
|
Vector2f abbrevSize = f->sizeText(abbrev);
|
||||||
|
|
||||||
while(text.size() && size.x() + abbrevSize.x() > mSize.x())
|
while(text.size() && size.x() + abbrevSize.x() > mSize.x())
|
||||||
{
|
{
|
||||||
|
@ -206,9 +206,9 @@ void TextComponent::onTextChanged()
|
||||||
|
|
||||||
text.append(abbrev);
|
text.append(abbrev);
|
||||||
|
|
||||||
mTextCache = std::shared_ptr<TextCache>(f->buildTextCache(text, Eigen::Vector2f(0, 0), (mColor >> 8 << 8) | mOpacity, mSize.x(), mHorizontalAlignment, mLineSpacing));
|
mTextCache = std::shared_ptr<TextCache>(f->buildTextCache(text, Vector2f(0, 0), (mColor >> 8 << 8) | mOpacity, mSize.x(), mHorizontalAlignment, mLineSpacing));
|
||||||
}else{
|
}else{
|
||||||
mTextCache = std::shared_ptr<TextCache>(f->buildTextCache(f->wrapText(text, mSize.x()), Eigen::Vector2f(0, 0), (mColor >> 8 << 8) | mOpacity, mSize.x(), mHorizontalAlignment, mLineSpacing));
|
mTextCache = std::shared_ptr<TextCache>(f->buildTextCache(f->wrapText(text, mSize.x()), Vector2f(0, 0), (mColor >> 8 << 8) | mOpacity, mSize.x(), mHorizontalAlignment, mLineSpacing));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ class TextComponent : public GuiComponent
|
||||||
public:
|
public:
|
||||||
TextComponent(Window* window);
|
TextComponent(Window* window);
|
||||||
TextComponent(Window* window, const std::string& text, const std::shared_ptr<Font>& font, unsigned int color = 0x000000FF, Alignment align = ALIGN_LEFT,
|
TextComponent(Window* window, const std::string& text, const std::shared_ptr<Font>& font, unsigned int color = 0x000000FF, Alignment align = ALIGN_LEFT,
|
||||||
Eigen::Vector3f pos = Eigen::Vector3f::Zero(), Eigen::Vector2f size = Eigen::Vector2f::Zero(), unsigned int bgcolor = 0x00000000);
|
Vector3f pos = Vector3f::Zero(), Vector2f size = Vector2f::Zero(), unsigned int bgcolor = 0x00000000);
|
||||||
|
|
||||||
void setFont(const std::shared_ptr<Font>& font);
|
void setFont(const std::shared_ptr<Font>& font);
|
||||||
void setUppercase(bool uppercase);
|
void setUppercase(bool uppercase);
|
||||||
|
@ -29,7 +29,7 @@ public:
|
||||||
void setBackgroundColor(unsigned int color);
|
void setBackgroundColor(unsigned int color);
|
||||||
void setRenderBackground(bool render);
|
void setRenderBackground(bool render);
|
||||||
|
|
||||||
void render(const Eigen::Affine3f& parentTrans) override;
|
void render(const Transform4x4f& parentTrans) override;
|
||||||
|
|
||||||
std::string getValue() const override;
|
std::string getValue() const override;
|
||||||
void setValue(const std::string& value) override;
|
void setValue(const std::string& value) override;
|
||||||
|
@ -55,7 +55,7 @@ private:
|
||||||
|
|
||||||
std::shared_ptr<Font> mFont;
|
std::shared_ptr<Font> mFont;
|
||||||
bool mUppercase;
|
bool mUppercase;
|
||||||
Eigen::Matrix<bool, 1, 2> mAutoCalcExtent;
|
Vector2i mAutoCalcExtent;
|
||||||
std::string mText;
|
std::string mText;
|
||||||
std::shared_ptr<TextCache> mTextCache;
|
std::shared_ptr<TextCache> mTextCache;
|
||||||
Alignment mHorizontalAlignment;
|
Alignment mHorizontalAlignment;
|
||||||
|
|
|
@ -37,7 +37,7 @@ void TextEditComponent::onFocusLost()
|
||||||
|
|
||||||
void TextEditComponent::onSizeChanged()
|
void TextEditComponent::onSizeChanged()
|
||||||
{
|
{
|
||||||
mBox.fitTo(mSize, Eigen::Vector3f::Zero(), Eigen::Vector2f(-34, -32 - TEXT_PADDING_VERT));
|
mBox.fitTo(mSize, Vector3f::Zero(), Vector2f(-34, -32 - TEXT_PADDING_VERT));
|
||||||
onTextChanged(); // wrap point probably changed
|
onTextChanged(); // wrap point probably changed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,7 +219,7 @@ void TextEditComponent::onCursorChanged()
|
||||||
{
|
{
|
||||||
if(isMultiline())
|
if(isMultiline())
|
||||||
{
|
{
|
||||||
Eigen::Vector2f textSize = mFont->getWrappedTextCursorOffset(mText, getTextAreaSize().x(), mCursor);
|
Vector2f textSize = mFont->getWrappedTextCursorOffset(mText, getTextAreaSize().x(), mCursor);
|
||||||
|
|
||||||
if(mScrollOffset.y() + getTextAreaSize().y() < textSize.y() + mFont->getHeight()) //need to scroll down?
|
if(mScrollOffset.y() + getTextAreaSize().y() < textSize.y() + mFont->getHeight()) //need to scroll down?
|
||||||
{
|
{
|
||||||
|
@ -229,7 +229,7 @@ void TextEditComponent::onCursorChanged()
|
||||||
mScrollOffset[1] = textSize.y();
|
mScrollOffset[1] = textSize.y();
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
Eigen::Vector2f cursorPos = mFont->sizeText(mText.substr(0, mCursor));
|
Vector2f cursorPos = mFont->sizeText(mText.substr(0, mCursor));
|
||||||
|
|
||||||
if(mScrollOffset.x() + getTextAreaSize().x() < cursorPos.x())
|
if(mScrollOffset.x() + getTextAreaSize().x() < cursorPos.x())
|
||||||
{
|
{
|
||||||
|
@ -241,22 +241,22 @@ void TextEditComponent::onCursorChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditComponent::render(const Eigen::Affine3f& parentTrans)
|
void TextEditComponent::render(const Transform4x4f& parentTrans)
|
||||||
{
|
{
|
||||||
Eigen::Affine3f trans = getTransform() * parentTrans;
|
Transform4x4f trans = getTransform() * parentTrans;
|
||||||
renderChildren(trans);
|
renderChildren(trans);
|
||||||
|
|
||||||
// text + cursor rendering
|
// text + cursor rendering
|
||||||
// offset into our "text area" (padding)
|
// offset into our "text area" (padding)
|
||||||
trans.translation() += Eigen::Vector3f(getTextAreaPos().x(), getTextAreaPos().y(), 0);
|
trans.translation() += Vector3f(getTextAreaPos().x(), getTextAreaPos().y(), 0);
|
||||||
|
|
||||||
Eigen::Vector2i clipPos((int)trans.translation().x(), (int)trans.translation().y());
|
Vector2i clipPos((int)trans.translation().x(), (int)trans.translation().y());
|
||||||
Eigen::Vector3f dimScaled = trans * Eigen::Vector3f(getTextAreaSize().x(), getTextAreaSize().y(), 0); // use "text area" size for clipping
|
Vector3f dimScaled = trans * Vector3f(getTextAreaSize().x(), getTextAreaSize().y(), 0); // use "text area" size for clipping
|
||||||
Eigen::Vector2i clipDim((int)dimScaled.x() - trans.translation().x(), (int)dimScaled.y() - trans.translation().y());
|
Vector2i clipDim((int)dimScaled.x() - trans.translation().x(), (int)dimScaled.y() - trans.translation().y());
|
||||||
Renderer::pushClipRect(clipPos, clipDim);
|
Renderer::pushClipRect(clipPos, clipDim);
|
||||||
|
|
||||||
trans.translate(Eigen::Vector3f(-mScrollOffset.x(), -mScrollOffset.y(), 0));
|
trans.translate(Vector3f(-mScrollOffset.x(), -mScrollOffset.y(), 0));
|
||||||
trans = roundMatrix(trans);
|
trans.round();
|
||||||
|
|
||||||
Renderer::setMatrix(trans);
|
Renderer::setMatrix(trans);
|
||||||
|
|
||||||
|
@ -271,7 +271,7 @@ void TextEditComponent::render(const Eigen::Affine3f& parentTrans)
|
||||||
// draw cursor
|
// draw cursor
|
||||||
if(mEditing)
|
if(mEditing)
|
||||||
{
|
{
|
||||||
Eigen::Vector2f cursorPos;
|
Vector2f cursorPos;
|
||||||
if(isMultiline())
|
if(isMultiline())
|
||||||
{
|
{
|
||||||
cursorPos = mFont->getWrappedTextCursorOffset(mText, getTextAreaSize().x(), mCursor);
|
cursorPos = mFont->getWrappedTextCursorOffset(mText, getTextAreaSize().x(), mCursor);
|
||||||
|
@ -290,14 +290,14 @@ bool TextEditComponent::isMultiline()
|
||||||
return (getSize().y() > mFont->getHeight() * 1.25f);
|
return (getSize().y() > mFont->getHeight() * 1.25f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Eigen::Vector2f TextEditComponent::getTextAreaPos() const
|
Vector2f TextEditComponent::getTextAreaPos() const
|
||||||
{
|
{
|
||||||
return Eigen::Vector2f(TEXT_PADDING_HORIZ / 2.0f, TEXT_PADDING_VERT / 2.0f);
|
return Vector2f(TEXT_PADDING_HORIZ / 2.0f, TEXT_PADDING_VERT / 2.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Eigen::Vector2f TextEditComponent::getTextAreaSize() const
|
Vector2f TextEditComponent::getTextAreaSize() const
|
||||||
{
|
{
|
||||||
return Eigen::Vector2f(mSize.x() - TEXT_PADDING_HORIZ, mSize.y() - TEXT_PADDING_VERT);
|
return Vector2f(mSize.x() - TEXT_PADDING_HORIZ, mSize.y() - TEXT_PADDING_VERT);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<HelpPrompt> TextEditComponent::getHelpPrompts()
|
std::vector<HelpPrompt> TextEditComponent::getHelpPrompts()
|
||||||
|
|
|
@ -15,7 +15,7 @@ public:
|
||||||
void textInput(const char* text) override;
|
void textInput(const char* text) override;
|
||||||
bool input(InputConfig* config, Input input) override;
|
bool input(InputConfig* config, Input input) override;
|
||||||
void update(int deltaTime) override;
|
void update(int deltaTime) override;
|
||||||
void render(const Eigen::Affine3f& parentTrans) override;
|
void render(const Transform4x4f& parentTrans) override;
|
||||||
|
|
||||||
void onFocusGained() override;
|
void onFocusGained() override;
|
||||||
void onFocusLost() override;
|
void onFocusLost() override;
|
||||||
|
@ -43,8 +43,8 @@ private:
|
||||||
void moveCursor(int amt);
|
void moveCursor(int amt);
|
||||||
|
|
||||||
bool isMultiline();
|
bool isMultiline();
|
||||||
Eigen::Vector2f getTextAreaPos() const;
|
Vector2f getTextAreaPos() const;
|
||||||
Eigen::Vector2f getTextAreaSize() const;
|
Vector2f getTextAreaSize() const;
|
||||||
|
|
||||||
std::string mText;
|
std::string mText;
|
||||||
bool mFocused;
|
bool mFocused;
|
||||||
|
@ -54,7 +54,7 @@ private:
|
||||||
int mCursorRepeatTimer;
|
int mCursorRepeatTimer;
|
||||||
int mCursorRepeatDir;
|
int mCursorRepeatDir;
|
||||||
|
|
||||||
Eigen::Vector2f mScrollOffset;
|
Vector2f mScrollOffset;
|
||||||
|
|
||||||
NinePatchComponent mBox;
|
NinePatchComponent mBox;
|
||||||
|
|
||||||
|
|
|
@ -153,9 +153,9 @@ void VideoComponent::setOpacity(unsigned char opacity)
|
||||||
mStaticImage.setOpacity(opacity);
|
mStaticImage.setOpacity(opacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoComponent::render(const Eigen::Affine3f& parentTrans)
|
void VideoComponent::render(const Transform4x4f& parentTrans)
|
||||||
{
|
{
|
||||||
Eigen::Affine3f trans = parentTrans * getTransform();
|
Transform4x4f trans = parentTrans * getTransform();
|
||||||
GuiComponent::renderChildren(trans);
|
GuiComponent::renderChildren(trans);
|
||||||
|
|
||||||
Renderer::setMatrix(trans);
|
Renderer::setMatrix(trans);
|
||||||
|
@ -167,7 +167,7 @@ void VideoComponent::render(const Eigen::Affine3f& parentTrans)
|
||||||
handleLooping();
|
handleLooping();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoComponent::renderSnapshot(const Eigen::Affine3f& parentTrans)
|
void VideoComponent::renderSnapshot(const Transform4x4f& parentTrans)
|
||||||
{
|
{
|
||||||
// This is the case where the video is not currently being displayed. Work out
|
// This is the case where the video is not currently being displayed. Work out
|
||||||
// if we need to display a static image
|
// if we need to display a static image
|
||||||
|
@ -189,26 +189,26 @@ void VideoComponent::applyTheme(const std::shared_ptr<ThemeData>& theme, const s
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Eigen::Vector2f scale = getParent() ? getParent()->getSize() : Eigen::Vector2f((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight());
|
Vector2f scale = getParent() ? getParent()->getSize() : Vector2f((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight());
|
||||||
|
|
||||||
if ((properties & POSITION) && elem->has("pos"))
|
if ((properties & POSITION) && elem->has("pos"))
|
||||||
{
|
{
|
||||||
Eigen::Vector2f denormalized = elem->get<Eigen::Vector2f>("pos").cwiseProduct(scale);
|
Vector2f denormalized = elem->get<Vector2f>("pos") * scale;
|
||||||
setPosition(Eigen::Vector3f(denormalized.x(), denormalized.y(), 0));
|
setPosition(Vector3f(denormalized.x(), denormalized.y(), 0));
|
||||||
mStaticImage.setPosition(Eigen::Vector3f(denormalized.x(), denormalized.y(), 0));
|
mStaticImage.setPosition(Vector3f(denormalized.x(), denormalized.y(), 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(properties & ThemeFlags::SIZE)
|
if(properties & ThemeFlags::SIZE)
|
||||||
{
|
{
|
||||||
if(elem->has("size"))
|
if(elem->has("size"))
|
||||||
setResize(elem->get<Eigen::Vector2f>("size").cwiseProduct(scale));
|
setResize(elem->get<Vector2f>("size") * scale);
|
||||||
else if(elem->has("maxSize"))
|
else if(elem->has("maxSize"))
|
||||||
setMaxSize(elem->get<Eigen::Vector2f>("maxSize").cwiseProduct(scale));
|
setMaxSize(elem->get<Vector2f>("maxSize") * scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
// position + size also implies origin
|
// position + size also implies origin
|
||||||
if (((properties & ORIGIN) || ((properties & POSITION) && (properties & ThemeFlags::SIZE))) && elem->has("origin"))
|
if (((properties & ORIGIN) || ((properties & POSITION) && (properties & ThemeFlags::SIZE))) && elem->has("origin"))
|
||||||
setOrigin(elem->get<Eigen::Vector2f>("origin"));
|
setOrigin(elem->get<Vector2f>("origin"));
|
||||||
|
|
||||||
if(elem->has("default"))
|
if(elem->has("default"))
|
||||||
mConfig.defaultVideoPath = elem->get<std::string>("default");
|
mConfig.defaultVideoPath = elem->get<std::string>("default");
|
||||||
|
@ -226,7 +226,7 @@ void VideoComponent::applyTheme(const std::shared_ptr<ThemeData>& theme, const s
|
||||||
if(elem->has("rotation"))
|
if(elem->has("rotation"))
|
||||||
setRotationDegrees(elem->get<float>("rotation"));
|
setRotationDegrees(elem->get<float>("rotation"));
|
||||||
if(elem->has("rotationOrigin"))
|
if(elem->has("rotationOrigin"))
|
||||||
setRotationOrigin(elem->get<Eigen::Vector2f>("rotationOrigin"));
|
setRotationOrigin(elem->get<Vector2f>("rotationOrigin"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(properties & ThemeFlags::Z_INDEX && elem->has("zIndex"))
|
if(properties & ThemeFlags::Z_INDEX && elem->has("zIndex"))
|
||||||
|
|
|
@ -52,8 +52,8 @@ public:
|
||||||
void onSizeChanged() override;
|
void onSizeChanged() override;
|
||||||
void setOpacity(unsigned char opacity) override;
|
void setOpacity(unsigned char opacity) override;
|
||||||
|
|
||||||
void render(const Eigen::Affine3f& parentTrans) override;
|
void render(const Transform4x4f& parentTrans) override;
|
||||||
void renderSnapshot(const Eigen::Affine3f& parentTrans);
|
void renderSnapshot(const Transform4x4f& parentTrans);
|
||||||
|
|
||||||
virtual void applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view, const std::string& element, unsigned int properties) override;
|
virtual void applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view, const std::string& element, unsigned int properties) override;
|
||||||
|
|
||||||
|
@ -66,13 +66,13 @@ public:
|
||||||
// Can be set before or after a video is loaded.
|
// Can be set before or after a video is loaded.
|
||||||
// setMaxSize() and setResize() are mutually exclusive.
|
// setMaxSize() and setResize() are mutually exclusive.
|
||||||
virtual void setResize(float width, float height) = 0;
|
virtual void setResize(float width, float height) = 0;
|
||||||
inline void setResize(const Eigen::Vector2f& size) { setResize(size.x(), size.y()); }
|
inline void setResize(const Vector2f& size) { setResize(size.x(), size.y()); }
|
||||||
|
|
||||||
// Resize the video to be as large as possible but fit within a box of this size.
|
// Resize the video to be as large as possible but fit within a box of this size.
|
||||||
// Can be set before or after a video is loaded.
|
// Can be set before or after a video is loaded.
|
||||||
// Never breaks the aspect ratio. setMaxSize() and setResize() are mutually exclusive.
|
// Never breaks the aspect ratio. setMaxSize() and setResize() are mutually exclusive.
|
||||||
virtual void setMaxSize(float width, float height) = 0;
|
virtual void setMaxSize(float width, float height) = 0;
|
||||||
inline void setMaxSize(const Eigen::Vector2f& size) { setMaxSize(size.x(), size.y()); }
|
inline void setMaxSize(const Vector2f& size) { setMaxSize(size.x(), size.y()); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Start the video Immediately
|
// Start the video Immediately
|
||||||
|
@ -94,7 +94,7 @@ private:
|
||||||
protected:
|
protected:
|
||||||
unsigned mVideoWidth;
|
unsigned mVideoWidth;
|
||||||
unsigned mVideoHeight;
|
unsigned mVideoHeight;
|
||||||
Eigen::Vector2f mTargetSize;
|
Vector2f mTargetSize;
|
||||||
std::shared_ptr<TextureResource> mTexture;
|
std::shared_ptr<TextureResource> mTexture;
|
||||||
float mFadeIn;
|
float mFadeIn;
|
||||||
std::string mStaticImagePath;
|
std::string mStaticImagePath;
|
||||||
|
|
|
@ -32,7 +32,7 @@ VideoPlayerComponent::~VideoPlayerComponent()
|
||||||
stopVideo();
|
stopVideo();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoPlayerComponent::render(const Eigen::Affine3f& parentTrans)
|
void VideoPlayerComponent::render(const Transform4x4f& parentTrans)
|
||||||
{
|
{
|
||||||
VideoComponent::render(parentTrans);
|
VideoComponent::render(parentTrans);
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ public:
|
||||||
VideoPlayerComponent(Window* window, std::string path);
|
VideoPlayerComponent(Window* window, std::string path);
|
||||||
virtual ~VideoPlayerComponent();
|
virtual ~VideoPlayerComponent();
|
||||||
|
|
||||||
void render(const Eigen::Affine3f& parentTrans) override;
|
void render(const Transform4x4f& parentTrans) override;
|
||||||
|
|
||||||
// Resize the video to fit this size. If one axis is zero, scale that axis to maintain aspect ratio.
|
// Resize the video to fit this size. If one axis is zero, scale that axis to maintain aspect ratio.
|
||||||
// If both are non-zero, potentially break the aspect ratio. If both are zero, no resizing.
|
// If both are non-zero, potentially break the aspect ratio. If both are zero, no resizing.
|
||||||
|
|
|
@ -52,7 +52,7 @@ VideoVlcComponent::~VideoVlcComponent()
|
||||||
|
|
||||||
void VideoVlcComponent::setResize(float width, float height)
|
void VideoVlcComponent::setResize(float width, float height)
|
||||||
{
|
{
|
||||||
mTargetSize << width, height;
|
mTargetSize = Vector2f(width, height);
|
||||||
mTargetIsMax = false;
|
mTargetIsMax = false;
|
||||||
mStaticImage.setResize(width, height);
|
mStaticImage.setResize(width, height);
|
||||||
resize();
|
resize();
|
||||||
|
@ -60,7 +60,7 @@ void VideoVlcComponent::setResize(float width, float height)
|
||||||
|
|
||||||
void VideoVlcComponent::setMaxSize(float width, float height)
|
void VideoVlcComponent::setMaxSize(float width, float height)
|
||||||
{
|
{
|
||||||
mTargetSize << width, height;
|
mTargetSize = Vector2f(width, height);
|
||||||
mTargetIsMax = true;
|
mTargetIsMax = true;
|
||||||
mStaticImage.setMaxSize(width, height);
|
mStaticImage.setMaxSize(width, height);
|
||||||
resize();
|
resize();
|
||||||
|
@ -71,9 +71,9 @@ void VideoVlcComponent::resize()
|
||||||
if(!mTexture)
|
if(!mTexture)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const Eigen::Vector2f textureSize(mVideoWidth, mVideoHeight);
|
const Vector2f textureSize(mVideoWidth, mVideoHeight);
|
||||||
|
|
||||||
if(textureSize.isZero())
|
if(textureSize == Vector2f::Zero())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// SVG rasterization is determined by height (see SVGResource.cpp), and rasterization is done in terms of pixels
|
// SVG rasterization is determined by height (see SVGResource.cpp), and rasterization is done in terms of pixels
|
||||||
|
@ -87,7 +87,7 @@ void VideoVlcComponent::resize()
|
||||||
|
|
||||||
mSize = textureSize;
|
mSize = textureSize;
|
||||||
|
|
||||||
Eigen::Vector2f resizeScale((mTargetSize.x() / mSize.x()), (mTargetSize.y() / mSize.y()));
|
Vector2f resizeScale((mTargetSize.x() / mSize.x()), (mTargetSize.y() / mSize.y()));
|
||||||
|
|
||||||
if(resizeScale.x() < resizeScale.y())
|
if(resizeScale.x() < resizeScale.y())
|
||||||
{
|
{
|
||||||
|
@ -105,7 +105,7 @@ void VideoVlcComponent::resize()
|
||||||
}else{
|
}else{
|
||||||
// if both components are set, we just stretch
|
// if both components are set, we just stretch
|
||||||
// if no components are set, we don't resize at all
|
// if no components are set, we don't resize at all
|
||||||
mSize = mTargetSize.isZero() ? textureSize : mTargetSize;
|
mSize = mTargetSize == Vector2f::Zero() ? textureSize : mTargetSize;
|
||||||
|
|
||||||
// if only one component is set, we resize in a way that maintains aspect ratio
|
// if only one component is set, we resize in a way that maintains aspect ratio
|
||||||
// for SVG rasterization, we always calculate width from rounded height (see comment above)
|
// for SVG rasterization, we always calculate width from rounded height (see comment above)
|
||||||
|
@ -126,12 +126,12 @@ void VideoVlcComponent::resize()
|
||||||
onSizeChanged();
|
onSizeChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoVlcComponent::render(const Eigen::Affine3f& parentTrans)
|
void VideoVlcComponent::render(const Transform4x4f& parentTrans)
|
||||||
{
|
{
|
||||||
VideoComponent::render(parentTrans);
|
VideoComponent::render(parentTrans);
|
||||||
float x, y;
|
float x, y;
|
||||||
|
|
||||||
Eigen::Affine3f trans = parentTrans * getTransform();
|
Transform4x4f trans = parentTrans * getTransform();
|
||||||
GuiComponent::renderChildren(trans);
|
GuiComponent::renderChildren(trans);
|
||||||
|
|
||||||
Renderer::setMatrix(trans);
|
Renderer::setMatrix(trans);
|
||||||
|
@ -151,9 +151,9 @@ void VideoVlcComponent::render(const Eigen::Affine3f& parentTrans)
|
||||||
// Define a structure to contain the data for each vertex
|
// Define a structure to contain the data for each vertex
|
||||||
struct Vertex
|
struct Vertex
|
||||||
{
|
{
|
||||||
Eigen::Vector2f pos;
|
Vector2f pos;
|
||||||
Eigen::Vector2f tex;
|
Vector2f tex;
|
||||||
Eigen::Vector4f colour;
|
Vector4f colour;
|
||||||
} vertices[6];
|
} vertices[6];
|
||||||
|
|
||||||
// We need two triangles to cover the rectangular area
|
// We need two triangles to cover the rectangular area
|
||||||
|
@ -315,7 +315,7 @@ void VideoVlcComponent::startVideo()
|
||||||
{
|
{
|
||||||
if(!Settings::getInstance()->getBool("CaptionsCompatibility")) {
|
if(!Settings::getInstance()->getBool("CaptionsCompatibility")) {
|
||||||
|
|
||||||
Eigen::Vector2f resizeScale((Renderer::getScreenWidth() / mVideoWidth), (Renderer::getScreenHeight() / mVideoHeight));
|
Vector2f resizeScale((Renderer::getScreenWidth() / mVideoWidth), (Renderer::getScreenHeight() / mVideoHeight));
|
||||||
|
|
||||||
if(resizeScale.x() < resizeScale.y())
|
if(resizeScale.x() < resizeScale.y())
|
||||||
{
|
{
|
||||||
|
|
|
@ -32,7 +32,7 @@ public:
|
||||||
VideoVlcComponent(Window* window, std::string subtitles);
|
VideoVlcComponent(Window* window, std::string subtitles);
|
||||||
virtual ~VideoVlcComponent();
|
virtual ~VideoVlcComponent();
|
||||||
|
|
||||||
void render(const Eigen::Affine3f& parentTrans) override;
|
void render(const Transform4x4f& parentTrans) override;
|
||||||
|
|
||||||
|
|
||||||
// Resize the video to fit this size. If one axis is zero, scale that axis to maintain aspect ratio.
|
// Resize the video to fit this size. If one axis is zero, scale that axis to maintain aspect ratio.
|
||||||
|
|
|
@ -14,8 +14,6 @@
|
||||||
|
|
||||||
#define HOLD_TIME 1000
|
#define HOLD_TIME 1000
|
||||||
|
|
||||||
using namespace Eigen;
|
|
||||||
|
|
||||||
namespace fs = boost::filesystem;
|
namespace fs = boost::filesystem;
|
||||||
|
|
||||||
GuiDetectDevice::GuiDetectDevice(Window* window, bool firstRun, const std::function<void()>& doneCallback) : GuiComponent(window), mFirstRun(firstRun),
|
GuiDetectDevice::GuiDetectDevice(Window* window, bool firstRun, const std::function<void()>& doneCallback) : GuiComponent(window), mFirstRun(firstRun),
|
||||||
|
|
|
@ -133,8 +133,6 @@ static const char* inputIcon[inputCount] =
|
||||||
//MasterVolUp and MasterVolDown are also hooked up, but do not appear on this screen.
|
//MasterVolUp and MasterVolDown are also hooked up, but do not appear on this screen.
|
||||||
//If you want, you can manually add them to es_input.cfg.
|
//If you want, you can manually add them to es_input.cfg.
|
||||||
|
|
||||||
using namespace Eigen;
|
|
||||||
|
|
||||||
#define HOLD_TO_SKIP_MS 1000
|
#define HOLD_TO_SKIP_MS 1000
|
||||||
|
|
||||||
GuiInputConfig::GuiInputConfig(Window* window, InputConfig* target, bool reconfigureAll, const std::function<void()>& okCallback) : GuiComponent(window),
|
GuiInputConfig::GuiInputConfig(Window* window, InputConfig* target, bool reconfigureAll, const std::function<void()>& okCallback) : GuiComponent(window),
|
||||||
|
|
|
@ -12,13 +12,13 @@ GuiMsgBox::GuiMsgBox(Window* window, const std::string& text,
|
||||||
const std::string& name1, const std::function<void()>& func1,
|
const std::string& name1, const std::function<void()>& func1,
|
||||||
const std::string& name2, const std::function<void()>& func2,
|
const std::string& name2, const std::function<void()>& func2,
|
||||||
const std::string& name3, const std::function<void()>& func3) : GuiComponent(window),
|
const std::string& name3, const std::function<void()>& func3) : GuiComponent(window),
|
||||||
mBackground(window, ":/frame.png"), mGrid(window, Eigen::Vector2i(1, 2))
|
mBackground(window, ":/frame.png"), mGrid(window, Vector2i(1, 2))
|
||||||
{
|
{
|
||||||
float width = Renderer::getScreenWidth() * 0.6f; // max width
|
float width = Renderer::getScreenWidth() * 0.6f; // max width
|
||||||
float minWidth = Renderer::getScreenWidth() * 0.3f; // minimum width
|
float minWidth = Renderer::getScreenWidth() * 0.3f; // minimum width
|
||||||
|
|
||||||
mMsg = std::make_shared<TextComponent>(mWindow, text, Font::get(FONT_SIZE_MEDIUM), 0x777777FF, ALIGN_CENTER);
|
mMsg = std::make_shared<TextComponent>(mWindow, text, Font::get(FONT_SIZE_MEDIUM), 0x777777FF, ALIGN_CENTER);
|
||||||
mGrid.setEntry(mMsg, Eigen::Vector2i(0, 0), false, false);
|
mGrid.setEntry(mMsg, Vector2i(0, 0), false, false);
|
||||||
|
|
||||||
// create the buttons
|
// create the buttons
|
||||||
mButtons.push_back(std::make_shared<ButtonComponent>(mWindow, name1, name1, std::bind(&GuiMsgBox::deleteMeAndCall, this, func1)));
|
mButtons.push_back(std::make_shared<ButtonComponent>(mWindow, name1, name1, std::bind(&GuiMsgBox::deleteMeAndCall, this, func1)));
|
||||||
|
@ -44,7 +44,7 @@ GuiMsgBox::GuiMsgBox(Window* window, const std::string& text,
|
||||||
|
|
||||||
// put the buttons into a ComponentGrid
|
// put the buttons into a ComponentGrid
|
||||||
mButtonGrid = makeButtonGrid(mWindow, mButtons);
|
mButtonGrid = makeButtonGrid(mWindow, mButtons);
|
||||||
mGrid.setEntry(mButtonGrid, Eigen::Vector2i(0, 1), true, false, Eigen::Vector2i(1, 1), GridFlags::BORDER_TOP);
|
mGrid.setEntry(mButtonGrid, Vector2i(0, 1), true, false, Vector2i(1, 1), GridFlags::BORDER_TOP);
|
||||||
|
|
||||||
// decide final width
|
// decide final width
|
||||||
if(mMsg->getSize().x() < width && mButtonGrid->getSize().x() < width)
|
if(mMsg->getSize().x() < width && mButtonGrid->getSize().x() < width)
|
||||||
|
@ -94,7 +94,7 @@ void GuiMsgBox::onSizeChanged()
|
||||||
mMsg->setSize(mSize.x() - HORIZONTAL_PADDING_PX*2, mGrid.getRowHeight(0));
|
mMsg->setSize(mSize.x() - HORIZONTAL_PADDING_PX*2, mGrid.getRowHeight(0));
|
||||||
mGrid.onSizeChanged();
|
mGrid.onSizeChanged();
|
||||||
|
|
||||||
mBackground.fitTo(mSize, Eigen::Vector3f::Zero(), Eigen::Vector2f(-32, -32));
|
mBackground.fitTo(mSize, Vector3f::Zero(), Vector2f(-32, -32));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiMsgBox::deleteMeAndCall(const std::function<void()>& func)
|
void GuiMsgBox::deleteMeAndCall(const std::function<void()>& func)
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
#include "guis/GuiTextEditPopup.h"
|
#include "guis/GuiTextEditPopup.h"
|
||||||
#include "components/MenuComponent.h"
|
#include "components/MenuComponent.h"
|
||||||
|
|
||||||
using namespace Eigen;
|
|
||||||
|
|
||||||
GuiTextEditPopup::GuiTextEditPopup(Window* window, const std::string& title, const std::string& initValue,
|
GuiTextEditPopup::GuiTextEditPopup(Window* window, const std::string& title, const std::string& initValue,
|
||||||
const std::function<void(const std::string&)>& okCallback, bool multiLine, const char* acceptBtnText)
|
const std::function<void(const std::string&)>& okCallback, bool multiLine, const char* acceptBtnText)
|
||||||
: GuiComponent(window), mBackground(window, ":/frame.png"), mGrid(window, Vector2i(1, 3)), mMultiLine(multiLine)
|
: GuiComponent(window), mBackground(window, ":/frame.png"), mGrid(window, Vector2i(1, 3)), mMultiLine(multiLine)
|
||||||
|
@ -39,7 +37,7 @@ GuiTextEditPopup::GuiTextEditPopup(Window* window, const std::string& title, con
|
||||||
|
|
||||||
void GuiTextEditPopup::onSizeChanged()
|
void GuiTextEditPopup::onSizeChanged()
|
||||||
{
|
{
|
||||||
mBackground.fitTo(mSize, Eigen::Vector3f::Zero(), Eigen::Vector2f(-32, -32));
|
mBackground.fitTo(mSize, Vector3f::Zero(), Vector2f(-32, -32));
|
||||||
|
|
||||||
mText->setSize(mSize.x() - 40, mText->getSize().y());
|
mText->setSize(mSize.x() - 40, mText->getSize().y());
|
||||||
|
|
||||||
|
|
77
es-core/src/math/Matrix3x3f.h
Normal file
77
es-core/src/math/Matrix3x3f.h
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
#ifndef _MATRIX3X3F_H_
|
||||||
|
#define _MATRIX3X3F_H_
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <math/Vector3f.h>
|
||||||
|
|
||||||
|
class Matrix3x3f
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
Matrix3x3f() { }
|
||||||
|
Matrix3x3f(const Vector3f& r0, const Vector3f& r1, const Vector3f& r2) : mR0(r0), mR1(r1), mR2(r2) { }
|
||||||
|
|
||||||
|
const bool operator==(const Matrix3x3f& other) const { return ((mR0 == other.mR0) && (mR1 == other.mR1) && (mR2 == other.mR2)); }
|
||||||
|
const bool operator!=(const Matrix3x3f& other) const { return ((mR0 != other.mR0) || (mR1 != other.mR1) || (mR2 != other.mR2)); }
|
||||||
|
|
||||||
|
const Matrix3x3f operator*(const Matrix3x3f& other) const
|
||||||
|
{
|
||||||
|
const float* tm = (float*)this;
|
||||||
|
const float* om = (float*)&other;
|
||||||
|
|
||||||
|
return
|
||||||
|
{
|
||||||
|
{
|
||||||
|
tm[0] * om[0] + tm[1] * om[3] + tm[2] * om[6],
|
||||||
|
tm[0] * om[1] + tm[1] * om[4] + tm[2] * om[7],
|
||||||
|
tm[0] * om[2] + tm[1] * om[5] + tm[2] * om[8]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tm[3] * om[0] + tm[4] * om[3] + tm[5] * om[6],
|
||||||
|
tm[3] * om[1] + tm[4] * om[4] + tm[5] * om[7],
|
||||||
|
tm[3] * om[2] + tm[4] * om[5] + tm[5] * om[8]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tm[6] * om[0] + tm[7] * om[3] + tm[8] * om[6],
|
||||||
|
tm[6] * om[1] + tm[7] * om[4] + tm[8] * om[7],
|
||||||
|
tm[6] * om[2] + tm[7] * om[5] + tm[8] * om[8]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const Vector3f operator*(const Vector3f& other) const
|
||||||
|
{
|
||||||
|
const float* tm = (float*)this;
|
||||||
|
const float* ov = (float*)&other;
|
||||||
|
|
||||||
|
return
|
||||||
|
{
|
||||||
|
tm[0] * ov[0] + tm[3] * ov[1] + tm[6] * ov[2],
|
||||||
|
tm[1] * ov[0] + tm[4] * ov[1] + tm[7] * ov[2],
|
||||||
|
tm[2] * ov[0] + tm[5] * ov[1] + tm[8] * ov[2]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Matrix3x3f& operator*=(const Matrix3x3f& other) { *this = *this * other; return *this; }
|
||||||
|
|
||||||
|
float& operator[](const int index) { assert(index < 9 && "index out of range"); return ((float*)&mR0)[index]; }
|
||||||
|
const float& operator[](const int index) const { assert(index < 9 && "index out of range"); return ((float*)&mR0)[index]; }
|
||||||
|
|
||||||
|
Vector3f& r0() { return mR0; }
|
||||||
|
Vector3f& r1() { return mR1; }
|
||||||
|
Vector3f& r2() { return mR2; }
|
||||||
|
const Vector3f& r0() const { return mR0; }
|
||||||
|
const Vector3f& r1() const { return mR1; }
|
||||||
|
const Vector3f& r2() const { return mR2; }
|
||||||
|
|
||||||
|
static const Matrix3x3f Identity() { return { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } }; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
Vector3f mR0;
|
||||||
|
Vector3f mR1;
|
||||||
|
Vector3f mR2;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
179
es-core/src/math/Matrix4x4f.h
Normal file
179
es-core/src/math/Matrix4x4f.h
Normal file
|
@ -0,0 +1,179 @@
|
||||||
|
#ifndef _MATRIX4X4F_H_
|
||||||
|
#define _MATRIX4X4F_H_
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <math/Matrix3x3f.h>
|
||||||
|
#include <math/Vector4f.h>
|
||||||
|
|
||||||
|
class Matrix4x4f
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
friend class Transform4x4f;
|
||||||
|
|
||||||
|
Matrix4x4f() { }
|
||||||
|
Matrix4x4f(const Vector4f& r0, const Vector4f& r1, const Vector4f& r2, const Vector4f& r3) : mR0(r0), mR1(r1), mR2(r2), mR3(r3) { }
|
||||||
|
|
||||||
|
const bool operator==(const Matrix4x4f& other) const { return ((mR0 == other.mR0) && (mR1 == other.mR1) && (mR2 == other.mR2) && (mR3 == other.mR3)); }
|
||||||
|
const bool operator!=(const Matrix4x4f& other) const { return ((mR0 != other.mR0) || (mR1 != other.mR1) || (mR2 != other.mR2) || (mR3 != other.mR3)); }
|
||||||
|
|
||||||
|
const Matrix4x4f operator*(const Matrix4x4f& other) const
|
||||||
|
{
|
||||||
|
const float* tm = (float*)this;
|
||||||
|
const float* om = (float*)&other;
|
||||||
|
|
||||||
|
return
|
||||||
|
{
|
||||||
|
{
|
||||||
|
tm[ 0] * om[ 0] + tm[ 1] * om[ 4] + tm[ 2] * om[ 8] + tm[ 3] * om[12],
|
||||||
|
tm[ 0] * om[ 1] + tm[ 1] * om[ 5] + tm[ 2] * om[ 9] + tm[ 3] * om[13],
|
||||||
|
tm[ 0] * om[ 2] + tm[ 1] * om[ 6] + tm[ 2] * om[10] + tm[ 3] * om[14],
|
||||||
|
tm[ 0] * om[ 3] + tm[ 1] * om[ 7] + tm[ 2] * om[11] + tm[ 3] * om[15]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tm[ 4] * om[ 0] + tm[ 5] * om[ 4] + tm[ 6] * om[ 8] + tm[ 7] * om[12],
|
||||||
|
tm[ 4] * om[ 1] + tm[ 5] * om[ 5] + tm[ 6] * om[ 9] + tm[ 7] * om[13],
|
||||||
|
tm[ 4] * om[ 2] + tm[ 5] * om[ 6] + tm[ 6] * om[10] + tm[ 7] * om[14],
|
||||||
|
tm[ 4] * om[ 3] + tm[ 5] * om[ 7] + tm[ 6] * om[11] + tm[ 7] * om[15]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tm[ 8] * om[ 0] + tm[ 9] * om[ 4] + tm[10] * om[ 8] + tm[11] * om[12],
|
||||||
|
tm[ 8] * om[ 1] + tm[ 9] * om[ 5] + tm[10] * om[ 9] + tm[11] * om[13],
|
||||||
|
tm[ 8] * om[ 2] + tm[ 9] * om[ 6] + tm[10] * om[10] + tm[11] * om[14],
|
||||||
|
tm[ 8] * om[ 3] + tm[ 9] * om[ 7] + tm[10] * om[11] + tm[11] * om[15]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tm[12] * om[ 0] + tm[13] * om[ 4] + tm[14] * om[ 8] + tm[15] * om[12],
|
||||||
|
tm[12] * om[ 1] + tm[13] * om[ 5] + tm[14] * om[ 9] + tm[15] * om[13],
|
||||||
|
tm[12] * om[ 2] + tm[13] * om[ 6] + tm[14] * om[10] + tm[15] * om[14],
|
||||||
|
tm[12] * om[ 3] + tm[13] * om[ 7] + tm[14] * om[11] + tm[15] * om[15]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const Matrix4x4f operator*(const Matrix3x3f& other) const
|
||||||
|
{
|
||||||
|
const float* tm = (float*)this;
|
||||||
|
const float* om = (float*)&other;
|
||||||
|
|
||||||
|
return
|
||||||
|
{
|
||||||
|
{
|
||||||
|
tm[ 0] * om[0] + tm[ 1] * om[3] + tm[ 2] * om[6],
|
||||||
|
tm[ 0] * om[1] + tm[ 1] * om[4] + tm[ 2] * om[7],
|
||||||
|
tm[ 0] * om[2] + tm[ 1] * om[5] + tm[ 2] * om[8],
|
||||||
|
tm[ 3]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tm[ 4] * om[0] + tm[ 5] * om[3] + tm[ 6] * om[6],
|
||||||
|
tm[ 4] * om[1] + tm[ 5] * om[4] + tm[ 6] * om[7],
|
||||||
|
tm[ 4] * om[2] + tm[ 5] * om[5] + tm[ 6] * om[8],
|
||||||
|
tm[ 7]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tm[ 8] * om[0] + tm[ 9] * om[3] + tm[10] * om[6],
|
||||||
|
tm[ 8] * om[1] + tm[ 9] * om[4] + tm[10] * om[7],
|
||||||
|
tm[ 8] * om[2] + tm[ 9] * om[5] + tm[10] * om[8],
|
||||||
|
tm[11]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tm[12],
|
||||||
|
tm[13],
|
||||||
|
tm[14],
|
||||||
|
tm[15]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Matrix4x4f& operator*=(const Matrix4x4f& other) { *this = *this * other; return *this; }
|
||||||
|
Matrix4x4f& operator*=(const Matrix3x3f& other) { *this = *this * other; return *this; }
|
||||||
|
|
||||||
|
float& operator[](const int index) { assert(index < 16 && "index out of range"); return ((float*)&mR0)[index]; }
|
||||||
|
const float& operator[](const int index) const { assert(index < 16 && "index out of range"); return ((float*)&mR0)[index]; }
|
||||||
|
|
||||||
|
Vector4f& r0() { return mR0; }
|
||||||
|
Vector4f& r1() { return mR1; }
|
||||||
|
Vector4f& r2() { return mR2; }
|
||||||
|
Vector4f& r3() { return mR3; }
|
||||||
|
const Vector4f& r0() const { return mR0; }
|
||||||
|
const Vector4f& r1() const { return mR1; }
|
||||||
|
const Vector4f& r2() const { return mR2; }
|
||||||
|
const Vector4f& r3() const { return mR3; }
|
||||||
|
|
||||||
|
Matrix4x4f& invert(const Matrix4x4f& other)
|
||||||
|
{
|
||||||
|
auto Determinant2x2 = [=](const float x1, const float x2,
|
||||||
|
const float y1, const float y2)
|
||||||
|
{
|
||||||
|
return x1 * y2 - x2 * y1;
|
||||||
|
};
|
||||||
|
|
||||||
|
auto Determinant3x3 = [=](const float x1, const float x2, const float x3,
|
||||||
|
const float y1, const float y2, const float y3,
|
||||||
|
const float z1, const float z2, const float z3)
|
||||||
|
{
|
||||||
|
return x1 * Determinant2x2(y2, y3, z2, z3) -
|
||||||
|
y1 * Determinant2x2(x2, x3, z2, z3) +
|
||||||
|
z1 * Determinant2x2(x2, x3, y2, y3);
|
||||||
|
};
|
||||||
|
|
||||||
|
float* tm = (float*)this;
|
||||||
|
const float* om = (float*)&other;
|
||||||
|
|
||||||
|
tm[ 0] = Determinant3x3(om[ 5], om[ 6], om[ 7], om[ 9], om[10], om[11], om[13], om[14], om[15]);
|
||||||
|
tm[ 1] = -Determinant3x3(om[ 1], om[ 2], om[ 3], om[ 9], om[10], om[11], om[13], om[14], om[15]);
|
||||||
|
tm[ 2] = Determinant3x3(om[ 1], om[ 2], om[ 3], om[ 5], om[ 6], om[ 7], om[13], om[14], om[15]);
|
||||||
|
tm[ 3] = -Determinant3x3(om[ 1], om[ 2], om[ 3], om[ 5], om[ 6], om[ 7], om[ 9], om[10], om[11]);
|
||||||
|
tm[ 4] = -Determinant3x3(om[ 4], om[ 6], om[ 7], om[ 8], om[10], om[11], om[12], om[14], om[15]);
|
||||||
|
tm[ 5] = Determinant3x3(om[ 0], om[ 2], om[ 3], om[ 8], om[10], om[11], om[12], om[14], om[15]);
|
||||||
|
tm[ 6] = -Determinant3x3(om[ 0], om[ 2], om[ 3], om[ 4], om[ 6], om[ 7], om[12], om[14], om[15]);
|
||||||
|
tm[ 7] = Determinant3x3(om[ 0], om[ 2], om[ 3], om[ 4], om[ 6], om[ 7], om[ 8], om[10], om[11]);
|
||||||
|
tm[ 8] = Determinant3x3(om[ 4], om[ 5], om[ 7], om[ 8], om[ 9], om[11], om[12], om[13], om[15]);
|
||||||
|
tm[ 9] = -Determinant3x3(om[ 0], om[ 1], om[ 3], om[ 8], om[ 9], om[11], om[12], om[13], om[15]);
|
||||||
|
tm[10] = Determinant3x3(om[ 0], om[ 1], om[ 3], om[ 4], om[ 5], om[ 7], om[12], om[13], om[15]);
|
||||||
|
tm[11] = -Determinant3x3(om[ 0], om[ 1], om[ 3], om[ 4], om[ 5], om[ 7], om[ 8], om[ 9], om[11]);
|
||||||
|
tm[12] = -Determinant3x3(om[ 4], om[ 5], om[ 6], om[ 8], om[ 9], om[10], om[12], om[13], om[14]);
|
||||||
|
tm[13] = Determinant3x3(om[ 0], om[ 1], om[ 2], om[ 8], om[ 9], om[10], om[12], om[13], om[14]);
|
||||||
|
tm[14] = -Determinant3x3(om[ 0], om[ 1], om[ 2], om[ 4], om[ 5], om[ 6], om[12], om[13], om[14]);
|
||||||
|
tm[15] = Determinant3x3(om[ 0], om[ 1], om[ 2], om[ 4], om[ 5], om[ 6], om[ 8], om[ 9], om[10]);
|
||||||
|
|
||||||
|
float Determinant = om[ 0] * tm[ 0] +
|
||||||
|
om[ 4] * tm[ 1] +
|
||||||
|
om[ 8] * tm[ 2] +
|
||||||
|
om[12] * tm[ 3];
|
||||||
|
|
||||||
|
if(Determinant != 0)
|
||||||
|
Determinant = 1 / Determinant;
|
||||||
|
|
||||||
|
mR0 *= Determinant;
|
||||||
|
mR1 *= Determinant;
|
||||||
|
mR2 *= Determinant;
|
||||||
|
mR3 *= Determinant;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Matrix4x4f& invert()
|
||||||
|
{
|
||||||
|
return invert(Matrix4x4f(*this));
|
||||||
|
}
|
||||||
|
|
||||||
|
Matrix4x4f inverse()
|
||||||
|
{
|
||||||
|
Matrix4x4f m;
|
||||||
|
m.invert(*this);
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const Matrix4x4f Identity() { return { { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, { 0, 0, 0, 1 } }; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
Vector4f mR0;
|
||||||
|
Vector4f mR1;
|
||||||
|
Vector4f mR2;
|
||||||
|
Vector4f mR3;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
39
es-core/src/math/Rotation3x3f.h
Normal file
39
es-core/src/math/Rotation3x3f.h
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
#ifndef _ROTATION3X3F_H_
|
||||||
|
#define _ROTATION3X3F_H_
|
||||||
|
|
||||||
|
class Rotation3x3f : public Matrix3x3f
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
Rotation3x3f(const float angle, const Vector3f& axis)
|
||||||
|
{
|
||||||
|
float* tm = (float*)this;
|
||||||
|
const float* av = (float*)&axis;
|
||||||
|
|
||||||
|
const float s = sin(-angle);
|
||||||
|
const float c = cos(-angle);
|
||||||
|
const float t = 1 - c;
|
||||||
|
const float x = av[0];
|
||||||
|
const float y = av[1];
|
||||||
|
const float z = av[2];
|
||||||
|
const float tx = t * x;
|
||||||
|
const float ty = t * y;
|
||||||
|
const float tz = t * z;
|
||||||
|
const float sx = s * x;
|
||||||
|
const float sy = s * y;
|
||||||
|
const float sz = s * z;
|
||||||
|
|
||||||
|
tm[0] = tx * x + c;
|
||||||
|
tm[1] = tx * y - sz;
|
||||||
|
tm[2] = tx * z + sy;
|
||||||
|
tm[3] = ty * x + sz;
|
||||||
|
tm[4] = ty * y + c;
|
||||||
|
tm[5] = ty * z - sy;
|
||||||
|
tm[6] = tz * x - sy;
|
||||||
|
tm[7] = tz * y + sx;
|
||||||
|
tm[8] = tz * z + c;
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
26
es-core/src/math/Scale3x3f.h
Normal file
26
es-core/src/math/Scale3x3f.h
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#ifndef _SCALE3X3F_H_
|
||||||
|
#define _SCALE3X3F_H_
|
||||||
|
|
||||||
|
class Scale3x3f : public Matrix3x3f
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
Scale3x3f(const Vector3f& scale)
|
||||||
|
{
|
||||||
|
float* tm = (float*)this;
|
||||||
|
const float* sv = (float*)&scale;
|
||||||
|
|
||||||
|
tm[0] = sv[0];
|
||||||
|
tm[1] = 0;
|
||||||
|
tm[2] = 0;
|
||||||
|
tm[3] = 0;
|
||||||
|
tm[4] = sv[1];
|
||||||
|
tm[5] = 0;
|
||||||
|
tm[6] = 0;
|
||||||
|
tm[7] = 0;
|
||||||
|
tm[8] = sv[2];
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
126
es-core/src/math/Transform4x4f.h
Normal file
126
es-core/src/math/Transform4x4f.h
Normal file
|
@ -0,0 +1,126 @@
|
||||||
|
#ifndef _TRANSFORM4X4F_H_
|
||||||
|
#define _TRANSFORM4X4F_H_
|
||||||
|
|
||||||
|
#include <math/Matrix4x4f.h>
|
||||||
|
#include <math/Vector3f.h>
|
||||||
|
|
||||||
|
class Transform4x4f : public Matrix4x4f
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
Transform4x4f() { }
|
||||||
|
Transform4x4f(const Matrix4x4f& m) : Matrix4x4f(m) { }
|
||||||
|
Transform4x4f(const Vector4f& r0, const Vector4f& r1, const Vector4f& r2, const Vector4f& r3) : Matrix4x4f(r0, r1, r2, r3) { }
|
||||||
|
|
||||||
|
const Transform4x4f operator*(const Matrix4x4f& other) const
|
||||||
|
{
|
||||||
|
const float* tm = (float*)this;
|
||||||
|
const float* om = (float*)&other;
|
||||||
|
|
||||||
|
return
|
||||||
|
{
|
||||||
|
{
|
||||||
|
tm[ 0] * om[ 0] + tm[ 1] * om[ 4] + tm[ 2] * om[ 8],
|
||||||
|
tm[ 0] * om[ 1] + tm[ 1] * om[ 5] + tm[ 2] * om[ 9],
|
||||||
|
tm[ 0] * om[ 2] + tm[ 1] * om[ 6] + tm[ 2] * om[10],
|
||||||
|
0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tm[ 4] * om[ 0] + tm[ 5] * om[ 4] + tm[ 6] * om[ 8],
|
||||||
|
tm[ 4] * om[ 1] + tm[ 5] * om[ 5] + tm[ 6] * om[ 9],
|
||||||
|
tm[ 4] * om[ 2] + tm[ 5] * om[ 6] + tm[ 6] * om[10],
|
||||||
|
0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tm[ 8] * om[ 0] + tm[ 9] * om[ 4] + tm[10] * om[ 8],
|
||||||
|
tm[ 8] * om[ 1] + tm[ 9] * om[ 5] + tm[10] * om[ 9],
|
||||||
|
tm[ 8] * om[ 2] + tm[ 9] * om[ 6] + tm[10] * om[10],
|
||||||
|
0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tm[ 0] * om[12] + tm[ 4] * om[13] + tm[ 8] * om[14] + tm[12],
|
||||||
|
tm[ 1] * om[12] + tm[ 5] * om[13] + tm[ 9] * om[14] + tm[13],
|
||||||
|
tm[ 2] * om[12] + tm[ 6] * om[13] + tm[10] * om[14] + tm[14],
|
||||||
|
1
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const Transform4x4f operator*(const Matrix3x3f& other) const
|
||||||
|
{
|
||||||
|
const float* tm = (float*)this;
|
||||||
|
const float* om = (float*)&other;
|
||||||
|
|
||||||
|
return
|
||||||
|
{
|
||||||
|
{
|
||||||
|
tm[ 0] * om[0] + tm[ 1] * om[3] + tm[ 2] * om[6],
|
||||||
|
tm[ 0] * om[1] + tm[ 1] * om[4] + tm[ 2] * om[7],
|
||||||
|
tm[ 0] * om[2] + tm[ 1] * om[5] + tm[ 2] * om[8],
|
||||||
|
0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tm[ 4] * om[0] + tm[ 5] * om[3] + tm[ 6] * om[6],
|
||||||
|
tm[ 4] * om[1] + tm[ 5] * om[4] + tm[ 6] * om[7],
|
||||||
|
tm[ 4] * om[2] + tm[ 5] * om[5] + tm[ 6] * om[8],
|
||||||
|
0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tm[ 8] * om[0] + tm[ 9] * om[3] + tm[10] * om[6],
|
||||||
|
tm[ 8] * om[1] + tm[ 9] * om[4] + tm[10] * om[7],
|
||||||
|
tm[ 8] * om[2] + tm[ 9] * om[5] + tm[10] * om[8],
|
||||||
|
0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tm[12],
|
||||||
|
tm[13],
|
||||||
|
tm[14],
|
||||||
|
1
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const Vector3f operator*(const Vector3f& other) const
|
||||||
|
{
|
||||||
|
const float* tm = (float*)this;
|
||||||
|
const float* ov = (float*)&other;
|
||||||
|
|
||||||
|
return
|
||||||
|
{
|
||||||
|
tm[ 0] * ov[0] + tm[ 4] * ov[1] + tm[ 8] * ov[2] + tm[12],
|
||||||
|
tm[ 1] * ov[0] + tm[ 5] * ov[1] + tm[ 9] * ov[2] + tm[13],
|
||||||
|
tm[ 2] * ov[0] + tm[ 6] * ov[1] + tm[10] * ov[2] + tm[14]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Transform4x4f& operator*=(const Matrix4x4f& other) { *this = *this * other; return *this; }
|
||||||
|
Transform4x4f& operator*=(const Matrix3x3f& other) { *this = *this * other; return *this; }
|
||||||
|
|
||||||
|
inline Vector3f& translation() { return mR3.v3(); }
|
||||||
|
inline const Vector3f& translation() const { return mR3.v3(); }
|
||||||
|
|
||||||
|
inline Transform4x4f& translate(const Vector3f& translation)
|
||||||
|
{
|
||||||
|
float* tm = (float*)this;
|
||||||
|
const float* tv = (float*)&translation;
|
||||||
|
|
||||||
|
tm[12] += tm[ 0] * tv[0] + tm[ 4] * tv[1] + tm[ 8] * tv[2];
|
||||||
|
tm[13] += tm[ 1] * tv[0] + tm[ 5] * tv[1] + tm[ 9] * tv[2];
|
||||||
|
tm[14] += tm[ 2] * tv[0] + tm[ 6] * tv[1] + tm[10] * tv[2];
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Transform4x4f& round()
|
||||||
|
{
|
||||||
|
float* tm = (float*)this;
|
||||||
|
|
||||||
|
tm[12] = (int)(tm[12] + 0.5f);
|
||||||
|
tm[13] = (int)(tm[13] + 0.5f);
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
65
es-core/src/math/Vector2f.h
Normal file
65
es-core/src/math/Vector2f.h
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
#ifndef _VECTOR2F_H_
|
||||||
|
#define _VECTOR2F_H_
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
class Vector3f;
|
||||||
|
class Vector4f;
|
||||||
|
|
||||||
|
class Vector2f
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
Vector2f() { }
|
||||||
|
Vector2f(const float f) : mX(f), mY(f) { }
|
||||||
|
Vector2f(const float x, const float y) : mX(x), mY(y) { }
|
||||||
|
explicit Vector2f(const Vector3f& v) : mX(((Vector2f&)v).mX), mY(((Vector2f&)v).mY) { }
|
||||||
|
explicit Vector2f(const Vector4f& v) : mX(((Vector2f&)v).mX), mY(((Vector2f&)v).mY) { }
|
||||||
|
|
||||||
|
const bool operator==(const Vector2f& other) const { return ((mX == other.mX) && (mY == other.mY)); }
|
||||||
|
const bool operator!=(const Vector2f& other) const { return ((mX != other.mX) || (mY != other.mY)); }
|
||||||
|
|
||||||
|
const Vector2f operator+(const Vector2f& other) const { return { mX + other.mX, mY + other.mY }; }
|
||||||
|
const Vector2f operator-(const Vector2f& other) const { return { mX - other.mX, mY - other.mY }; }
|
||||||
|
const Vector2f operator*(const Vector2f& other) const { return { mX * other.mX, mY * other.mY }; }
|
||||||
|
const Vector2f operator/(const Vector2f& other) const { return { mX / other.mX, mY / other.mY }; }
|
||||||
|
|
||||||
|
const Vector2f operator+(const float& other) const { return { mX + other, mY + other }; }
|
||||||
|
const Vector2f operator-(const float& other) const { return { mX - other, mY - other }; }
|
||||||
|
const Vector2f operator*(const float& other) const { return { mX * other, mY * other }; }
|
||||||
|
const Vector2f operator/(const float& other) const { return { mX / other, mY / other }; }
|
||||||
|
|
||||||
|
const Vector2f operator-() const { return { -mX , -mY }; }
|
||||||
|
|
||||||
|
Vector2f& operator+=(const Vector2f& other) { *this = *this + other; return *this; }
|
||||||
|
Vector2f& operator-=(const Vector2f& other) { *this = *this - other; return *this; }
|
||||||
|
Vector2f& operator*=(const Vector2f& other) { *this = *this * other; return *this; }
|
||||||
|
Vector2f& operator/=(const Vector2f& other) { *this = *this / other; return *this; }
|
||||||
|
|
||||||
|
Vector2f& operator+=(const float& other) { *this = *this + other; return *this; }
|
||||||
|
Vector2f& operator-=(const float& other) { *this = *this - other; return *this; }
|
||||||
|
Vector2f& operator*=(const float& other) { *this = *this * other; return *this; }
|
||||||
|
Vector2f& operator/=(const float& other) { *this = *this / other; return *this; }
|
||||||
|
|
||||||
|
float& operator[](const int index) { assert(index < 2 && "index out of range"); return (&mX)[index]; }
|
||||||
|
const float& operator[](const int index) const { assert(index < 2 && "index out of range"); return (&mX)[index]; }
|
||||||
|
|
||||||
|
float& x() { return mX; }
|
||||||
|
float& y() { return mY; }
|
||||||
|
const float& x() const { return mX; }
|
||||||
|
const float& y() const { return mY; }
|
||||||
|
|
||||||
|
inline Vector2f& round() { mX = (int)(mX + 0.5f); mY = (int)(mY + 0.5f); return *this; }
|
||||||
|
|
||||||
|
static const Vector2f Zero() { return { 0, 0 }; }
|
||||||
|
static const Vector2f UnitX() { return { 1, 0 }; }
|
||||||
|
static const Vector2f UnitY() { return { 0, 1 }; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
float mX;
|
||||||
|
float mY;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
58
es-core/src/math/Vector2i.h
Normal file
58
es-core/src/math/Vector2i.h
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
#ifndef _VECTOR2I_H_
|
||||||
|
#define _VECTOR2I_H_
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
class Vector2i
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
Vector2i() { }
|
||||||
|
Vector2i(const int i) : mX(i), mY(i) { }
|
||||||
|
Vector2i(const int x, const int y) : mX(x), mY(y) { }
|
||||||
|
|
||||||
|
const bool operator==(const Vector2i& other) const { return ((mX == other.mX) && (mY == other.mY)); }
|
||||||
|
const bool operator!=(const Vector2i& other) const { return ((mX != other.mX) || (mY != other.mY)); }
|
||||||
|
|
||||||
|
const Vector2i operator+(const Vector2i& other) const { return { mX + other.mX, mY + other.mY }; }
|
||||||
|
const Vector2i operator-(const Vector2i& other) const { return { mX - other.mX, mY - other.mY }; }
|
||||||
|
const Vector2i operator*(const Vector2i& other) const { return { mX * other.mX, mY * other.mY }; }
|
||||||
|
const Vector2i operator/(const Vector2i& other) const { return { mX / other.mX, mY / other.mY }; }
|
||||||
|
|
||||||
|
const Vector2i operator+(const int& other) const { return { mX + other, mY + other }; }
|
||||||
|
const Vector2i operator-(const int& other) const { return { mX - other, mY - other }; }
|
||||||
|
const Vector2i operator*(const int& other) const { return { mX * other, mY * other }; }
|
||||||
|
const Vector2i operator/(const int& other) const { return { mX / other, mY / other }; }
|
||||||
|
|
||||||
|
const Vector2i operator-() const { return { -mX , -mY }; }
|
||||||
|
|
||||||
|
Vector2i& operator+=(const Vector2i& other) { *this = *this + other; return *this; }
|
||||||
|
Vector2i& operator-=(const Vector2i& other) { *this = *this - other; return *this; }
|
||||||
|
Vector2i& operator*=(const Vector2i& other) { *this = *this * other; return *this; }
|
||||||
|
Vector2i& operator/=(const Vector2i& other) { *this = *this / other; return *this; }
|
||||||
|
|
||||||
|
Vector2i& operator+=(const int& other) { *this = *this + other; return *this; }
|
||||||
|
Vector2i& operator-=(const int& other) { *this = *this - other; return *this; }
|
||||||
|
Vector2i& operator*=(const int& other) { *this = *this * other; return *this; }
|
||||||
|
Vector2i& operator/=(const int& other) { *this = *this / other; return *this; }
|
||||||
|
|
||||||
|
int& operator[](const int index) { assert(index < 2 && "index out of range"); return (&mX)[index]; }
|
||||||
|
const int& operator[](const int index) const { assert(index < 2 && "index out of range"); return (&mX)[index]; }
|
||||||
|
|
||||||
|
int& x() { return mX; }
|
||||||
|
int& y() { return mY; }
|
||||||
|
const int& x() const { return mX; }
|
||||||
|
const int& y() const { return mY; }
|
||||||
|
|
||||||
|
static const Vector2i Zero() { return { 0, 0 }; }
|
||||||
|
static const Vector2i UnitX() { return { 1, 0 }; }
|
||||||
|
static const Vector2i UnitY() { return { 0, 1 }; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
int mX;
|
||||||
|
int mY;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
73
es-core/src/math/Vector3f.h
Normal file
73
es-core/src/math/Vector3f.h
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
#ifndef _VECTOR3F_H_
|
||||||
|
#define _VECTOR3F_H_
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
class Vector2f;
|
||||||
|
class Vector4f;
|
||||||
|
|
||||||
|
class Vector3f
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
Vector3f() { }
|
||||||
|
Vector3f(const float f) : mX(f), mY(f), mZ(f) { }
|
||||||
|
Vector3f(const float x, const float y, const float z) : mX(x), mY(y), mZ(z) { }
|
||||||
|
explicit Vector3f(const Vector2f& v) : mX(((Vector3f&)v).mX), mY(((Vector3f&)v).mY), mZ(0) { }
|
||||||
|
explicit Vector3f(const Vector2f& v, const float z) : mX(((Vector3f&)v).mX), mY(((Vector3f&)v).mY), mZ(z) { }
|
||||||
|
explicit Vector3f(const Vector4f& v) : mX(((Vector3f&)v).mX), mY(((Vector3f&)v).mY), mZ(((Vector3f&)v).mZ) { }
|
||||||
|
|
||||||
|
const bool operator==(const Vector3f& other) const { return ((mX == other.mX) && (mY == other.mY) && (mZ == other.mZ)); }
|
||||||
|
const bool operator!=(const Vector3f& other) const { return ((mX != other.mX) || (mY != other.mY) || (mZ != other.mZ)); }
|
||||||
|
|
||||||
|
const Vector3f operator+(const Vector3f& other) const { return { mX + other.mX, mY + other.mY, mZ + other.mZ }; }
|
||||||
|
const Vector3f operator-(const Vector3f& other) const { return { mX - other.mX, mY - other.mY, mZ - other.mZ }; }
|
||||||
|
const Vector3f operator*(const Vector3f& other) const { return { mX * other.mX, mY * other.mY, mZ * other.mZ }; }
|
||||||
|
const Vector3f operator/(const Vector3f& other) const { return { mX / other.mX, mY / other.mY, mZ / other.mZ }; }
|
||||||
|
|
||||||
|
const Vector3f operator+(const float& other) const { return { mX + other, mY + other, mZ + other }; }
|
||||||
|
const Vector3f operator-(const float& other) const { return { mX - other, mY - other, mZ - other }; }
|
||||||
|
const Vector3f operator*(const float& other) const { return { mX * other, mY * other, mZ * other }; }
|
||||||
|
const Vector3f operator/(const float& other) const { return { mX / other, mY / other, mZ / other }; }
|
||||||
|
|
||||||
|
const Vector3f operator-() const { return { -mX , -mY, -mZ }; }
|
||||||
|
|
||||||
|
Vector3f& operator+=(const Vector3f& other) { *this = *this + other; return *this; }
|
||||||
|
Vector3f& operator-=(const Vector3f& other) { *this = *this - other; return *this; }
|
||||||
|
Vector3f& operator*=(const Vector3f& other) { *this = *this * other; return *this; }
|
||||||
|
Vector3f& operator/=(const Vector3f& other) { *this = *this / other; return *this; }
|
||||||
|
|
||||||
|
Vector3f& operator+=(const float& other) { *this = *this + other; return *this; }
|
||||||
|
Vector3f& operator-=(const float& other) { *this = *this - other; return *this; }
|
||||||
|
Vector3f& operator*=(const float& other) { *this = *this * other; return *this; }
|
||||||
|
Vector3f& operator/=(const float& other) { *this = *this / other; return *this; }
|
||||||
|
|
||||||
|
float& operator[](const int index) { assert(index < 3 && "index out of range"); return (&mX)[index]; }
|
||||||
|
const float& operator[](const int index) const { assert(index < 3 && "index out of range"); return (&mX)[index]; }
|
||||||
|
|
||||||
|
float& x() { return mX; }
|
||||||
|
float& y() { return mY; }
|
||||||
|
float& z() { return mZ; }
|
||||||
|
const float& x() const { return mX; }
|
||||||
|
const float& y() const { return mY; }
|
||||||
|
const float& z() const { return mZ; }
|
||||||
|
|
||||||
|
inline Vector2f& v2() { return *(Vector2f*)this; }
|
||||||
|
inline const Vector2f& v2() const { return *(Vector2f*)this; }
|
||||||
|
|
||||||
|
inline Vector3f& round() { mX = (int)(mX + 0.5f); mY = (int)(mY + 0.5f); mZ = (int)(mZ + 0.5f); return *this; }
|
||||||
|
|
||||||
|
static const Vector3f Zero() { return { 0, 0, 0 }; }
|
||||||
|
static const Vector3f UnitX() { return { 1, 0, 0 }; }
|
||||||
|
static const Vector3f UnitY() { return { 0, 1, 0 }; }
|
||||||
|
static const Vector3f UnitZ() { return { 0, 0, 1 }; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
float mX;
|
||||||
|
float mY;
|
||||||
|
float mZ;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
82
es-core/src/math/Vector4f.h
Normal file
82
es-core/src/math/Vector4f.h
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
#ifndef _VECTOR4F_H_
|
||||||
|
#define _VECTOR4F_H_
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
class Vector2f;
|
||||||
|
class Vector3f;
|
||||||
|
|
||||||
|
class Vector4f
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
Vector4f() { }
|
||||||
|
Vector4f(const float f) : mX(f), mY(f), mZ(f), mW(f) { }
|
||||||
|
Vector4f(const float x, const float y, const float z, const float w) : mX(x), mY(y), mZ(z), mW(w) { }
|
||||||
|
explicit Vector4f(const Vector2f& v) : mX(((Vector4f&)v).mX), mY(((Vector4f&)v).mY), mZ(0), mW(0) { }
|
||||||
|
explicit Vector4f(const Vector2f& v, const float z) : mX(((Vector4f&)v).mX), mY(((Vector4f&)v).mY), mZ(z), mW(0) { }
|
||||||
|
explicit Vector4f(const Vector2f& v, const float z, const float w) : mX(((Vector4f&)v).mX), mY(((Vector4f&)v).mY), mZ(z), mW(w) { }
|
||||||
|
explicit Vector4f(const Vector3f& v) : mX(((Vector4f&)v).mX), mY(((Vector4f&)v).mY), mZ(((Vector4f&)v).mZ), mW(0) { }
|
||||||
|
explicit Vector4f(const Vector3f& v, const float w) : mX(((Vector4f&)v).mX), mY(((Vector4f&)v).mY), mZ(((Vector4f&)v).mZ), mW(w) { }
|
||||||
|
|
||||||
|
const bool operator==(const Vector4f& other) const { return ((mX == other.mX) && (mY == other.mY) && (mZ == other.mZ) && (mW == other.mW)); }
|
||||||
|
const bool operator!=(const Vector4f& other) const { return ((mX != other.mX) || (mY != other.mY) || (mZ != other.mZ) || (mW != other.mW)); }
|
||||||
|
|
||||||
|
const Vector4f operator+(const Vector4f& other) const { return { mX + other.mX, mY + other.mY, mZ + other.mZ, mW + other.mW }; }
|
||||||
|
const Vector4f operator-(const Vector4f& other) const { return { mX - other.mX, mY - other.mY, mZ - other.mZ, mW - other.mW }; }
|
||||||
|
const Vector4f operator*(const Vector4f& other) const { return { mX * other.mX, mY * other.mY, mZ * other.mZ, mW * other.mW }; }
|
||||||
|
const Vector4f operator/(const Vector4f& other) const { return { mX / other.mX, mY / other.mY, mZ / other.mZ, mW / other.mW }; }
|
||||||
|
|
||||||
|
const Vector4f operator+(const float& other) const { return { mX + other, mY + other, mZ + other, mW + other }; }
|
||||||
|
const Vector4f operator-(const float& other) const { return { mX - other, mY - other, mZ - other, mW - other }; }
|
||||||
|
const Vector4f operator*(const float& other) const { return { mX * other, mY * other, mZ * other, mW * other }; }
|
||||||
|
const Vector4f operator/(const float& other) const { return { mX / other, mY / other, mZ / other, mW / other }; }
|
||||||
|
|
||||||
|
const Vector4f operator-() const { return {-mX , -mY, -mZ, -mW }; }
|
||||||
|
|
||||||
|
Vector4f& operator+=(const Vector4f& other) { *this = *this + other; return *this; }
|
||||||
|
Vector4f& operator-=(const Vector4f& other) { *this = *this - other; return *this; }
|
||||||
|
Vector4f& operator*=(const Vector4f& other) { *this = *this * other; return *this; }
|
||||||
|
Vector4f& operator/=(const Vector4f& other) { *this = *this / other; return *this; }
|
||||||
|
|
||||||
|
Vector4f& operator+=(const float& other) { *this = *this + other; return *this; }
|
||||||
|
Vector4f& operator-=(const float& other) { *this = *this - other; return *this; }
|
||||||
|
Vector4f& operator*=(const float& other) { *this = *this * other; return *this; }
|
||||||
|
Vector4f& operator/=(const float& other) { *this = *this / other; return *this; }
|
||||||
|
|
||||||
|
float& operator[](const int index) { assert(index < 4 && "index out of range"); return (&mX)[index]; }
|
||||||
|
const float& operator[](const int index) const { assert(index < 4 && "index out of range"); return (&mX)[index]; }
|
||||||
|
|
||||||
|
float& x() { return mX; }
|
||||||
|
float& y() { return mY; }
|
||||||
|
float& z() { return mZ; }
|
||||||
|
float& w() { return mW; }
|
||||||
|
const float& x() const { return mX; }
|
||||||
|
const float& y() const { return mY; }
|
||||||
|
const float& z() const { return mZ; }
|
||||||
|
const float& w() const { return mW; }
|
||||||
|
|
||||||
|
inline Vector2f& v2() { return *(Vector2f*)this; }
|
||||||
|
inline const Vector2f& v2() const { return *(Vector2f*)this; }
|
||||||
|
|
||||||
|
inline Vector3f& v3() { return *(Vector3f*)this; }
|
||||||
|
inline const Vector3f& v3() const { return *(Vector3f*)this; }
|
||||||
|
|
||||||
|
inline Vector4f& round() { mX = (int)(mX + 0.5f); mY = (int)(mY + 0.5f); mZ = (int)(mZ + 0.5f); mW = (int)(mW + 0.5f); return *this; }
|
||||||
|
|
||||||
|
static const Vector4f Zero() { return { 0, 0, 0, 0 }; }
|
||||||
|
static const Vector4f UnitX() { return { 1, 0, 0, 0 }; }
|
||||||
|
static const Vector4f UnitY() { return { 0, 1, 0, 0 }; }
|
||||||
|
static const Vector4f UnitZ() { return { 0, 0, 1, 0 }; }
|
||||||
|
static const Vector4f UnitW() { return { 0, 0, 0, 1 }; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
float mX;
|
||||||
|
float mY;
|
||||||
|
float mZ;
|
||||||
|
float mW;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -254,8 +254,8 @@ void Font::unloadTextures()
|
||||||
Font::FontTexture::FontTexture()
|
Font::FontTexture::FontTexture()
|
||||||
{
|
{
|
||||||
textureId = 0;
|
textureId = 0;
|
||||||
textureSize << 2048, 512;
|
textureSize = Vector2i(2048, 512);
|
||||||
writePos = Eigen::Vector2i::Zero();
|
writePos = Vector2i::Zero();
|
||||||
rowHeight = 0;
|
rowHeight = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,7 +264,7 @@ Font::FontTexture::~FontTexture()
|
||||||
deinitTexture();
|
deinitTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Font::FontTexture::findEmpty(const Eigen::Vector2i& size, Eigen::Vector2i& cursor_out)
|
bool Font::FontTexture::findEmpty(const Vector2i& size, Vector2i& cursor_out)
|
||||||
{
|
{
|
||||||
if(size.x() >= textureSize.x() || size.y() >= textureSize.y())
|
if(size.x() >= textureSize.x() || size.y() >= textureSize.y())
|
||||||
return false;
|
return false;
|
||||||
|
@ -274,7 +274,7 @@ bool Font::FontTexture::findEmpty(const Eigen::Vector2i& size, Eigen::Vector2i&
|
||||||
{
|
{
|
||||||
// row full, but it should fit on the next row
|
// row full, but it should fit on the next row
|
||||||
// move cursor to next row
|
// move cursor to next row
|
||||||
writePos << 0, writePos.y() + rowHeight + 1; // leave 1px of space between glyphs
|
writePos = Vector2i(0, writePos.y() + rowHeight + 1); // leave 1px of space between glyphs
|
||||||
rowHeight = 0;
|
rowHeight = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,7 +322,7 @@ void Font::FontTexture::deinitTexture()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Font::getTextureForNewGlyph(const Eigen::Vector2i& glyphSize, FontTexture*& tex_out, Eigen::Vector2i& cursor_out)
|
void Font::getTextureForNewGlyph(const Vector2i& glyphSize, FontTexture*& tex_out, Vector2i& cursor_out)
|
||||||
{
|
{
|
||||||
if(mTextures.size())
|
if(mTextures.size())
|
||||||
{
|
{
|
||||||
|
@ -456,10 +456,10 @@ Font::Glyph* Font::getGlyph(UnicodeChar id)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Eigen::Vector2i glyphSize(g->bitmap.width, g->bitmap.rows);
|
Vector2i glyphSize(g->bitmap.width, g->bitmap.rows);
|
||||||
|
|
||||||
FontTexture* tex = NULL;
|
FontTexture* tex = NULL;
|
||||||
Eigen::Vector2i cursor;
|
Vector2i cursor;
|
||||||
getTextureForNewGlyph(glyphSize, tex, cursor);
|
getTextureForNewGlyph(glyphSize, tex, cursor);
|
||||||
|
|
||||||
// getTextureForNewGlyph can fail if the glyph is bigger than the max texture size (absurdly large font size)
|
// getTextureForNewGlyph can fail if the glyph is bigger than the max texture size (absurdly large font size)
|
||||||
|
@ -473,11 +473,11 @@ Font::Glyph* Font::getGlyph(UnicodeChar id)
|
||||||
Glyph& glyph = mGlyphMap[id];
|
Glyph& glyph = mGlyphMap[id];
|
||||||
|
|
||||||
glyph.texture = tex;
|
glyph.texture = tex;
|
||||||
glyph.texPos << cursor.x() / (float)tex->textureSize.x(), cursor.y() / (float)tex->textureSize.y();
|
glyph.texPos = Vector2f(cursor.x() / (float)tex->textureSize.x(), cursor.y() / (float)tex->textureSize.y());
|
||||||
glyph.texSize << glyphSize.x() / (float)tex->textureSize.x(), glyphSize.y() / (float)tex->textureSize.y();
|
glyph.texSize = Vector2f(glyphSize.x() / (float)tex->textureSize.x(), glyphSize.y() / (float)tex->textureSize.y());
|
||||||
|
|
||||||
glyph.advance << (float)g->metrics.horiAdvance / 64.0f, (float)g->metrics.vertAdvance / 64.0f;
|
glyph.advance = Vector2f((float)g->metrics.horiAdvance / 64.0f, (float)g->metrics.vertAdvance / 64.0f);
|
||||||
glyph.bearing << (float)g->metrics.horiBearingX / 64.0f, (float)g->metrics.horiBearingY / 64.0f;
|
glyph.bearing = Vector2f((float)g->metrics.horiBearingX / 64.0f, (float)g->metrics.horiBearingY / 64.0f);
|
||||||
|
|
||||||
// upload glyph bitmap to texture
|
// upload glyph bitmap to texture
|
||||||
glBindTexture(GL_TEXTURE_2D, tex->textureId);
|
glBindTexture(GL_TEXTURE_2D, tex->textureId);
|
||||||
|
@ -513,8 +513,8 @@ void Font::rebuildTextures()
|
||||||
FontTexture* tex = it->second.texture;
|
FontTexture* tex = it->second.texture;
|
||||||
|
|
||||||
// find the position/size
|
// find the position/size
|
||||||
Eigen::Vector2i cursor(it->second.texPos.x() * tex->textureSize.x(), it->second.texPos.y() * tex->textureSize.y());
|
Vector2i cursor(it->second.texPos.x() * tex->textureSize.x(), it->second.texPos.y() * tex->textureSize.y());
|
||||||
Eigen::Vector2i glyphSize(it->second.texSize.x() * tex->textureSize.x(), it->second.texSize.y() * tex->textureSize.y());
|
Vector2i glyphSize(it->second.texSize.x() * tex->textureSize.x(), it->second.texSize.y() * tex->textureSize.y());
|
||||||
|
|
||||||
// upload to texture
|
// upload to texture
|
||||||
glBindTexture(GL_TEXTURE_2D, tex->textureId);
|
glBindTexture(GL_TEXTURE_2D, tex->textureId);
|
||||||
|
@ -547,8 +547,8 @@ void Font::renderTextCache(TextCache* cache)
|
||||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
glEnableClientState(GL_COLOR_ARRAY);
|
glEnableClientState(GL_COLOR_ARRAY);
|
||||||
|
|
||||||
glVertexPointer(2, GL_FLOAT, sizeof(TextCache::Vertex), it->verts[0].pos.data());
|
glVertexPointer(2, GL_FLOAT, sizeof(TextCache::Vertex), &it->verts[0].pos);
|
||||||
glTexCoordPointer(2, GL_FLOAT, sizeof(TextCache::Vertex), it->verts[0].tex.data());
|
glTexCoordPointer(2, GL_FLOAT, sizeof(TextCache::Vertex), &it->verts[0].tex);
|
||||||
glColorPointer(4, GL_UNSIGNED_BYTE, 0, it->colors.data());
|
glColorPointer(4, GL_UNSIGNED_BYTE, 0, it->colors.data());
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, it->verts.size());
|
glDrawArrays(GL_TRIANGLES, 0, it->verts.size());
|
||||||
|
@ -562,7 +562,7 @@ void Font::renderTextCache(TextCache* cache)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Eigen::Vector2f Font::sizeText(std::string text, float lineSpacing)
|
Vector2f Font::sizeText(std::string text, float lineSpacing)
|
||||||
{
|
{
|
||||||
float lineWidth = 0.0f;
|
float lineWidth = 0.0f;
|
||||||
float highestWidth = 0.0f;
|
float highestWidth = 0.0f;
|
||||||
|
@ -593,7 +593,7 @@ Eigen::Vector2f Font::sizeText(std::string text, float lineSpacing)
|
||||||
if(lineWidth > highestWidth)
|
if(lineWidth > highestWidth)
|
||||||
highestWidth = lineWidth;
|
highestWidth = lineWidth;
|
||||||
|
|
||||||
return Eigen::Vector2f(highestWidth, y);
|
return Vector2f(highestWidth, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
float Font::getHeight(float lineSpacing) const
|
float Font::getHeight(float lineSpacing) const
|
||||||
|
@ -617,7 +617,7 @@ std::string Font::wrapText(std::string text, float xLen)
|
||||||
std::string line, word, temp;
|
std::string line, word, temp;
|
||||||
size_t space;
|
size_t space;
|
||||||
|
|
||||||
Eigen::Vector2f textSize;
|
Vector2f textSize;
|
||||||
|
|
||||||
while(text.length() > 0) //while there's text or we still have text to render
|
while(text.length() > 0) //while there's text or we still have text to render
|
||||||
{
|
{
|
||||||
|
@ -650,13 +650,13 @@ std::string Font::wrapText(std::string text, float xLen)
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
Eigen::Vector2f Font::sizeWrappedText(std::string text, float xLen, float lineSpacing)
|
Vector2f Font::sizeWrappedText(std::string text, float xLen, float lineSpacing)
|
||||||
{
|
{
|
||||||
text = wrapText(text, xLen);
|
text = wrapText(text, xLen);
|
||||||
return sizeText(text, lineSpacing);
|
return sizeText(text, lineSpacing);
|
||||||
}
|
}
|
||||||
|
|
||||||
Eigen::Vector2f Font::getWrappedTextCursorOffset(std::string text, float xLen, size_t stop, float lineSpacing)
|
Vector2f Font::getWrappedTextCursorOffset(std::string text, float xLen, size_t stop, float lineSpacing)
|
||||||
{
|
{
|
||||||
std::string wrappedText = wrapText(text, xLen);
|
std::string wrappedText = wrapText(text, xLen);
|
||||||
|
|
||||||
|
@ -693,7 +693,7 @@ Eigen::Vector2f Font::getWrappedTextCursorOffset(std::string text, float xLen, s
|
||||||
lineWidth += glyph->advance.x();
|
lineWidth += glyph->advance.x();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Eigen::Vector2f(lineWidth, y);
|
return Vector2f(lineWidth, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
//=============================================================================================================
|
//=============================================================================================================
|
||||||
|
@ -726,7 +726,7 @@ inline float font_round(float v)
|
||||||
return round(v);
|
return round(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
TextCache* Font::buildTextCache(const std::string& text, Eigen::Vector2f offset, unsigned int color, float xLen, Alignment alignment, float lineSpacing)
|
TextCache* Font::buildTextCache(const std::string& text, Vector2f offset, unsigned int color, float xLen, Alignment alignment, float lineSpacing)
|
||||||
{
|
{
|
||||||
float x = offset[0] + (xLen != 0 ? getNewlineStartOffset(text, 0, xLen, alignment) : 0);
|
float x = offset[0] + (xLen != 0 ? getNewlineStartOffset(text, 0, xLen, alignment) : 0);
|
||||||
|
|
||||||
|
@ -766,30 +766,30 @@ TextCache* Font::buildTextCache(const std::string& text, Eigen::Vector2f offset,
|
||||||
|
|
||||||
const float glyphStartX = x + glyph->bearing.x();
|
const float glyphStartX = x + glyph->bearing.x();
|
||||||
|
|
||||||
const Eigen::Vector2i& textureSize = glyph->texture->textureSize;
|
const Vector2i& textureSize = glyph->texture->textureSize;
|
||||||
|
|
||||||
// triangle 1
|
// triangle 1
|
||||||
// round to fix some weird "cut off" text bugs
|
// round to fix some weird "cut off" text bugs
|
||||||
tri[0].pos << font_round(glyphStartX), font_round(y + (glyph->texSize.y() * textureSize.y() - glyph->bearing.y()));
|
tri[0].pos = Vector2f(font_round(glyphStartX), font_round(y + (glyph->texSize.y() * textureSize.y() - glyph->bearing.y())));
|
||||||
tri[1].pos << font_round(glyphStartX + glyph->texSize.x() * textureSize.x()), font_round(y - glyph->bearing.y());
|
tri[1].pos = Vector2f(font_round(glyphStartX + glyph->texSize.x() * textureSize.x()), font_round(y - glyph->bearing.y()));
|
||||||
tri[2].pos << tri[0].pos.x(), tri[1].pos.y();
|
tri[2].pos = Vector2f(tri[0].pos.x(), tri[1].pos.y());
|
||||||
|
|
||||||
//tri[0].tex << 0, 0;
|
//tri[0].tex = Vector2f(0, 0);
|
||||||
//tri[0].tex << 1, 1;
|
//tri[0].tex = Vector2f(1, 1);
|
||||||
//tri[0].tex << 0, 1;
|
//tri[0].tex = Vector2f(0, 1);
|
||||||
|
|
||||||
tri[0].tex << glyph->texPos.x(), glyph->texPos.y() + glyph->texSize.y();
|
tri[0].tex = Vector2f(glyph->texPos.x(), glyph->texPos.y() + glyph->texSize.y());
|
||||||
tri[1].tex << glyph->texPos.x() + glyph->texSize.x(), glyph->texPos.y();
|
tri[1].tex = Vector2f(glyph->texPos.x() + glyph->texSize.x(), glyph->texPos.y());
|
||||||
tri[2].tex << tri[0].tex.x(), tri[1].tex.y();
|
tri[2].tex = Vector2f(tri[0].tex.x(), tri[1].tex.y());
|
||||||
|
|
||||||
// triangle 2
|
// triangle 2
|
||||||
tri[3].pos = tri[0].pos;
|
tri[3].pos = tri[0].pos;
|
||||||
tri[4].pos = tri[1].pos;
|
tri[4].pos = tri[1].pos;
|
||||||
tri[5].pos << tri[1].pos.x(), tri[0].pos.y();
|
tri[5].pos = Vector2f(tri[1].pos.x(), tri[0].pos.y());
|
||||||
|
|
||||||
tri[3].tex = tri[0].tex;
|
tri[3].tex = tri[0].tex;
|
||||||
tri[4].tex = tri[1].tex;
|
tri[4].tex = tri[1].tex;
|
||||||
tri[5].tex << tri[1].tex.x(), tri[0].tex.y();
|
tri[5].tex = Vector2f(tri[1].tex.x(), tri[0].tex.y());
|
||||||
|
|
||||||
// advance
|
// advance
|
||||||
x += glyph->advance.x();
|
x += glyph->advance.x();
|
||||||
|
@ -820,7 +820,7 @@ TextCache* Font::buildTextCache(const std::string& text, Eigen::Vector2f offset,
|
||||||
|
|
||||||
TextCache* Font::buildTextCache(const std::string& text, float offsetX, float offsetY, unsigned int color)
|
TextCache* Font::buildTextCache(const std::string& text, float offsetX, float offsetY, unsigned int color)
|
||||||
{
|
{
|
||||||
return buildTextCache(text, Eigen::Vector2f(offsetX, offsetY), color, 0.0f);
|
return buildTextCache(text, Vector2f(offsetX, offsetY), color, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextCache::setColor(unsigned int color)
|
void TextCache::setColor(unsigned int color)
|
||||||
|
|
|
@ -5,9 +5,9 @@
|
||||||
#include GLHEADER
|
#include GLHEADER
|
||||||
#include <ft2build.h>
|
#include <ft2build.h>
|
||||||
#include FT_FREETYPE_H
|
#include FT_FREETYPE_H
|
||||||
#include <Eigen/Dense>
|
|
||||||
#include "resources/ResourceManager.h"
|
#include "resources/ResourceManager.h"
|
||||||
#include "ThemeData.h"
|
#include "ThemeData.h"
|
||||||
|
#include "math/Vector2i.h"
|
||||||
|
|
||||||
class TextCache;
|
class TextCache;
|
||||||
|
|
||||||
|
@ -41,14 +41,14 @@ public:
|
||||||
|
|
||||||
virtual ~Font();
|
virtual ~Font();
|
||||||
|
|
||||||
Eigen::Vector2f sizeText(std::string text, float lineSpacing = 1.5f); // Returns the expected size of a string when rendered. Extra spacing is applied to the Y axis.
|
Vector2f sizeText(std::string text, float lineSpacing = 1.5f); // Returns the expected size of a string when rendered. Extra spacing is applied to the Y axis.
|
||||||
TextCache* buildTextCache(const std::string& text, float offsetX, float offsetY, unsigned int color);
|
TextCache* buildTextCache(const std::string& text, float offsetX, float offsetY, unsigned int color);
|
||||||
TextCache* buildTextCache(const std::string& text, Eigen::Vector2f offset, unsigned int color, float xLen, Alignment alignment = ALIGN_LEFT, float lineSpacing = 1.5f);
|
TextCache* buildTextCache(const std::string& text, Vector2f offset, unsigned int color, float xLen, Alignment alignment = ALIGN_LEFT, float lineSpacing = 1.5f);
|
||||||
void renderTextCache(TextCache* cache);
|
void renderTextCache(TextCache* cache);
|
||||||
|
|
||||||
std::string wrapText(std::string text, float xLen); // Inserts newlines into text to make it wrap properly.
|
std::string wrapText(std::string text, float xLen); // Inserts newlines into text to make it wrap properly.
|
||||||
Eigen::Vector2f sizeWrappedText(std::string text, float xLen, float lineSpacing = 1.5f); // Returns the expected size of a string after wrapping is applied.
|
Vector2f sizeWrappedText(std::string text, float xLen, float lineSpacing = 1.5f); // Returns the expected size of a string after wrapping is applied.
|
||||||
Eigen::Vector2f getWrappedTextCursorOffset(std::string text, float xLen, size_t cursor, float lineSpacing = 1.5f); // Returns the position of of the cursor after moving "cursor" characters.
|
Vector2f getWrappedTextCursorOffset(std::string text, float xLen, size_t cursor, float lineSpacing = 1.5f); // Returns the position of of the cursor after moving "cursor" characters.
|
||||||
|
|
||||||
float getHeight(float lineSpacing = 1.5f) const;
|
float getHeight(float lineSpacing = 1.5f) const;
|
||||||
float getLetterHeight();
|
float getLetterHeight();
|
||||||
|
@ -81,14 +81,14 @@ private:
|
||||||
struct FontTexture
|
struct FontTexture
|
||||||
{
|
{
|
||||||
GLuint textureId;
|
GLuint textureId;
|
||||||
Eigen::Vector2i textureSize;
|
Vector2i textureSize;
|
||||||
|
|
||||||
Eigen::Vector2i writePos;
|
Vector2i writePos;
|
||||||
int rowHeight;
|
int rowHeight;
|
||||||
|
|
||||||
FontTexture();
|
FontTexture();
|
||||||
~FontTexture();
|
~FontTexture();
|
||||||
bool findEmpty(const Eigen::Vector2i& size, Eigen::Vector2i& cursor_out);
|
bool findEmpty(const Vector2i& size, Vector2i& cursor_out);
|
||||||
|
|
||||||
// you must call initTexture() after creating a FontTexture to get a textureId
|
// you must call initTexture() after creating a FontTexture to get a textureId
|
||||||
void initTexture(); // initializes the OpenGL texture according to this FontTexture's settings, updating textureId
|
void initTexture(); // initializes the OpenGL texture according to this FontTexture's settings, updating textureId
|
||||||
|
@ -109,7 +109,7 @@ private:
|
||||||
|
|
||||||
std::vector<FontTexture> mTextures;
|
std::vector<FontTexture> mTextures;
|
||||||
|
|
||||||
void getTextureForNewGlyph(const Eigen::Vector2i& glyphSize, FontTexture*& tex_out, Eigen::Vector2i& cursor_out);
|
void getTextureForNewGlyph(const Vector2i& glyphSize, FontTexture*& tex_out, Vector2i& cursor_out);
|
||||||
|
|
||||||
std::map< unsigned int, std::unique_ptr<FontFace> > mFaceCache;
|
std::map< unsigned int, std::unique_ptr<FontFace> > mFaceCache;
|
||||||
FT_Face getFaceForChar(UnicodeChar id);
|
FT_Face getFaceForChar(UnicodeChar id);
|
||||||
|
@ -119,11 +119,11 @@ private:
|
||||||
{
|
{
|
||||||
FontTexture* texture;
|
FontTexture* texture;
|
||||||
|
|
||||||
Eigen::Vector2f texPos;
|
Vector2f texPos;
|
||||||
Eigen::Vector2f texSize; // in texels!
|
Vector2f texSize; // in texels!
|
||||||
|
|
||||||
Eigen::Vector2f advance;
|
Vector2f advance;
|
||||||
Eigen::Vector2f bearing;
|
Vector2f bearing;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::map<UnicodeChar, Glyph> mGlyphMap;
|
std::map<UnicodeChar, Glyph> mGlyphMap;
|
||||||
|
@ -149,8 +149,8 @@ class TextCache
|
||||||
protected:
|
protected:
|
||||||
struct Vertex
|
struct Vertex
|
||||||
{
|
{
|
||||||
Eigen::Vector2f pos;
|
Vector2f pos;
|
||||||
Eigen::Vector2f tex;
|
Vector2f tex;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VertexList
|
struct VertexList
|
||||||
|
@ -165,7 +165,7 @@ protected:
|
||||||
public:
|
public:
|
||||||
struct CacheMetrics
|
struct CacheMetrics
|
||||||
{
|
{
|
||||||
Eigen::Vector2f size;
|
Vector2f size;
|
||||||
} metrics;
|
} metrics;
|
||||||
|
|
||||||
void setColor(unsigned int color);
|
void setColor(unsigned int color);
|
||||||
|
|
|
@ -35,8 +35,8 @@ TextureResource::TextureResource(const std::string& path, bool tile, bool dynami
|
||||||
data->load();
|
data->load();
|
||||||
}
|
}
|
||||||
|
|
||||||
mSize << data->width(), data->height();
|
mSize = Vector2i(data->width(), data->height());
|
||||||
mSourceSize << data->sourceWidth(), data->sourceHeight();
|
mSourceSize = Vector2f(data->sourceWidth(), data->sourceHeight());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -62,8 +62,8 @@ void TextureResource::initFromPixels(const unsigned char* dataRGBA, size_t width
|
||||||
mTextureData->releaseRAM();
|
mTextureData->releaseRAM();
|
||||||
mTextureData->initFromRGBA(dataRGBA, width, height);
|
mTextureData->initFromRGBA(dataRGBA, width, height);
|
||||||
// Cache the image dimensions
|
// Cache the image dimensions
|
||||||
mSize << width, height;
|
mSize = Vector2i(width, height);
|
||||||
mSourceSize << mTextureData->sourceWidth(), mTextureData->sourceHeight();
|
mSourceSize = Vector2f(mTextureData->sourceWidth(), mTextureData->sourceHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureResource::initFromMemory(const char* data, size_t length)
|
void TextureResource::initFromMemory(const char* data, size_t length)
|
||||||
|
@ -74,11 +74,11 @@ void TextureResource::initFromMemory(const char* data, size_t length)
|
||||||
mTextureData->releaseRAM();
|
mTextureData->releaseRAM();
|
||||||
mTextureData->initImageFromMemory((const unsigned char*)data, length);
|
mTextureData->initImageFromMemory((const unsigned char*)data, length);
|
||||||
// Get the size from the texture data
|
// Get the size from the texture data
|
||||||
mSize << mTextureData->width(), mTextureData->height();
|
mSize = Vector2i(mTextureData->width(), mTextureData->height());
|
||||||
mSourceSize << mTextureData->sourceWidth(), mTextureData->sourceHeight();
|
mSourceSize = Vector2f(mTextureData->sourceWidth(), mTextureData->sourceHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
const Eigen::Vector2i TextureResource::getSize() const
|
const Vector2i TextureResource::getSize() const
|
||||||
{
|
{
|
||||||
return mSize;
|
return mSize;
|
||||||
}
|
}
|
||||||
|
@ -157,13 +157,13 @@ void TextureResource::rasterizeAt(size_t width, size_t height)
|
||||||
data = mTextureData;
|
data = mTextureData;
|
||||||
else
|
else
|
||||||
data = sTextureDataManager.get(this);
|
data = sTextureDataManager.get(this);
|
||||||
mSourceSize << (float)width, (float)height;
|
mSourceSize = Vector2f((float)width, (float)height);
|
||||||
data->setSourceSize((float)width, (float)height);
|
data->setSourceSize((float)width, (float)height);
|
||||||
if (mForceLoad || (mTextureData != nullptr))
|
if (mForceLoad || (mTextureData != nullptr))
|
||||||
data->load();
|
data->load();
|
||||||
}
|
}
|
||||||
|
|
||||||
Eigen::Vector2f TextureResource::getSourceImageSize() const
|
Vector2f TextureResource::getSourceImageSize() const
|
||||||
{
|
{
|
||||||
return mSourceSize;
|
return mSourceSize;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,12 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <Eigen/Dense>
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include "resources/TextureData.h"
|
#include "resources/TextureData.h"
|
||||||
#include "resources/TextureDataManager.h"
|
#include "resources/TextureDataManager.h"
|
||||||
#include GLHEADER
|
#include GLHEADER
|
||||||
|
#include "math/Vector2i.h"
|
||||||
|
#include "math/Vector2f.h"
|
||||||
|
|
||||||
// An OpenGL texture.
|
// An OpenGL texture.
|
||||||
// Automatically recreates the texture with renderer deinit/reinit.
|
// Automatically recreates the texture with renderer deinit/reinit.
|
||||||
|
@ -22,14 +23,14 @@ public:
|
||||||
|
|
||||||
// For scalable source images in textures we want to set the resolution to rasterize at
|
// For scalable source images in textures we want to set the resolution to rasterize at
|
||||||
void rasterizeAt(size_t width, size_t height);
|
void rasterizeAt(size_t width, size_t height);
|
||||||
Eigen::Vector2f getSourceImageSize() const;
|
Vector2f getSourceImageSize() const;
|
||||||
|
|
||||||
virtual ~TextureResource();
|
virtual ~TextureResource();
|
||||||
|
|
||||||
bool isInitialized() const;
|
bool isInitialized() const;
|
||||||
bool isTiled() const;
|
bool isTiled() const;
|
||||||
|
|
||||||
const Eigen::Vector2i getSize() const;
|
const Vector2i getSize() const;
|
||||||
bool bind();
|
bool bind();
|
||||||
|
|
||||||
static size_t getTotalMemUsage(); // returns an approximation of total VRAM used by textures (in bytes)
|
static size_t getTotalMemUsage(); // returns an approximation of total VRAM used by textures (in bytes)
|
||||||
|
@ -48,8 +49,8 @@ private:
|
||||||
// The texture data manager manages loading and unloading of filesystem based textures
|
// The texture data manager manages loading and unloading of filesystem based textures
|
||||||
static TextureDataManager sTextureDataManager;
|
static TextureDataManager sTextureDataManager;
|
||||||
|
|
||||||
Eigen::Vector2i mSize;
|
Vector2i mSize;
|
||||||
Eigen::Vector2f mSourceSize;
|
Vector2f mSourceSize;
|
||||||
bool mForceLoad;
|
bool mForceLoad;
|
||||||
|
|
||||||
typedef std::pair<std::string, bool> TextureKeyType;
|
typedef std::pair<std::string, bool> TextureKeyType;
|
||||||
|
|
Loading…
Reference in a new issue