Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various code fixes #455

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions es-core/src/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "components/HelpComponent.h"
#include "components/ImageComponent.h"

Window::Window() : mNormalizeNextUpdate(false), mFrameTimeElapsed(0), mFrameCountElapsed(0), mAverageDeltaTime(10),
Window::Window() : mNormalizeNextUpdate(false), mFrameTimeElapsed(0), mFrameCountElapsed(0), mAverageDeltaTime(10),
mAllowSleep(true), mSleeping(false), mTimeSinceLastInput(0)
{
mHelp = new HelpComponent(this);
Expand All @@ -23,7 +23,7 @@ Window::~Window()
// delete all our GUIs
while(peekGui())
delete peekGui();

delete mHelp;
}

Expand Down Expand Up @@ -143,11 +143,11 @@ void Window::update(int deltaTime)
if(mFrameTimeElapsed > 500)
{
mAverageDeltaTime = mFrameTimeElapsed / mFrameCountElapsed;

if(Settings::getInstance()->getBool("DrawFramerate"))
{
std::stringstream ss;

// fps
ss << std::fixed << std::setprecision(1) << (1000.0f * (float)mFrameCountElapsed / (float)mFrameTimeElapsed) << "fps, ";
ss << std::fixed << std::setprecision(2) << ((float)mFrameTimeElapsed / (float)mFrameCountElapsed) << "ms";
Expand Down Expand Up @@ -238,7 +238,7 @@ void Window::renderLoadingScreen()

auto& font = mDefaultFonts.at(1);
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(Eigen::Vector3f(round((Renderer::getScreenWidth() - cache->metrics.size.x()) / 2.0f),
round(Renderer::getScreenHeight() * 0.835f), 0.0f));
Renderer::setMatrix(trans);
font->renderTextCache(cache);
Expand Down Expand Up @@ -274,8 +274,8 @@ void Window::setHelpPrompts(const std::vector<HelpPrompt>& prompts, const HelpSt
// yes, it has!

// can we combine? (dpad only)
if((it->first == "up/down" && addPrompts.at(mappedTo->second).first == "left/right") ||
(it->first == "left/right" && addPrompts.at(mappedTo->second).first == "up/down"))
if((strcmp(it->first, "up/down") == 0 && strcmp(addPrompts.at(mappedTo->second).first, "left/right") == 0) ||
(strcmp(it->first, "left/right") == 0 && strcmp(addPrompts.at(mappedTo->second).first, "up/down") == 0))
{
// yes!
addPrompts.at(mappedTo->second).first = "up/down/left/right";
Expand All @@ -294,16 +294,16 @@ void Window::setHelpPrompts(const std::vector<HelpPrompt>& prompts, const HelpSt

// sort prompts so it goes [dpad_all] [dpad_u/d] [dpad_l/r] [a/b/x/y/l/r] [start/select]
std::sort(addPrompts.begin(), addPrompts.end(), [](const HelpPrompt& a, const HelpPrompt& b) -> bool {

static const char* map[] = {
"up/down/left/right",
"up/down",
"left/right",
"a", "b", "x", "y", "l", "r",
"start", "select",
"a", "b", "x", "y", "l", "r",
"start", "select",
NULL
};

int i = 0;
int aVal = 0;
int bVal = 0;
Expand Down
2 changes: 2 additions & 0 deletions es-core/src/animations/LambdaAnimation.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class LambdaAnimation : public Animation
public:
LambdaAnimation(const std::function<void(float t)>& func, int duration) : mFunction(func), mDuration(duration) {}

virtual ~LambdaAnimation() {}

int getDuration() const override { return mDuration; }

void apply(float t) override
Expand Down
9 changes: 7 additions & 2 deletions es-core/src/components/AnimatedImageComponent.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#include "components/AnimatedImageComponent.h"
#include "Log.h"

AnimatedImageComponent::AnimatedImageComponent(Window* window) : GuiComponent(window), mEnabled(false)
AnimatedImageComponent::AnimatedImageComponent(Window* window) :
GuiComponent(window),
mLoop(false),
mEnabled(false),
mFrameAccumulator(0),
mCurrentFrame(0)
{
}

Expand All @@ -22,7 +27,7 @@ void AnimatedImageComponent::load(const AnimationDef* def)
auto img = std::unique_ptr<ImageComponent>(new ImageComponent(mWindow));
img->setResize(mSize.x(), mSize.y());
img->setImage(std::string(def->frames[i].path), false);

mFrames.push_back(ImageFrame(std::move(img), def->frames[i].time));
}

Expand Down
22 changes: 11 additions & 11 deletions es-core/src/components/ComponentGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

using namespace GridFlags;

ComponentGrid::ComponentGrid(Window* window, const Eigen::Vector2i& gridDimensions) : GuiComponent(window),
ComponentGrid::ComponentGrid(Window* window, const Eigen::Vector2i& gridDimensions) : GuiComponent(window),
mGridSize(gridDimensions), mCursor(0, 0)
{
assert(gridDimensions.x() > 0 && gridDimensions.y() > 0);
Expand Down Expand Up @@ -40,7 +40,7 @@ float ComponentGrid::getColWidth(int col)
if(mColWidths[x] == 0)
between++;
}

return (freeWidthPerc * mSize.x()) / between;
}

Expand All @@ -58,7 +58,7 @@ float ComponentGrid::getRowHeight(int row)
if(mRowHeights[y] == 0)
between++;
}

return (freeHeightPerc * mSize.y()) / between;
}

Expand Down Expand Up @@ -143,7 +143,7 @@ void ComponentGrid::updateCellComponent(const GridEntry& cell)
// center component
pos[0] = pos.x() + (size.x() - cell.component->getSize().x()) / 2;
pos[1] = pos.y() + (size.y() - cell.component->getSize().y()) / 2;

cell.component->setPosition(pos);
}

Expand Down Expand Up @@ -209,7 +209,7 @@ void ComponentGrid::onSizeChanged()
ComponentGrid::GridEntry* ComponentGrid::getCellAt(int x, int y)
{
assert(x >= 0 && x < mGridSize.x() && y >= 0 && y < mGridSize.y());

for(auto it = mCells.begin(); it != mCells.end(); it++)
{
int xmin = it->pos.x();
Expand Down Expand Up @@ -279,7 +279,7 @@ bool ComponentGrid::moveCursor(Eigen::Vector2i dir)
GridEntry* currentCursorEntry = getCellAt(mCursor);

Eigen::Vector2i searchAxis(dir.x() == 0, dir.y() == 0);

while(mCursor.x() >= 0 && mCursor.y() >= 0 && mCursor.x() < mGridSize.x() && mCursor.y() < mGridSize.y())
{
mCursor = mCursor + dir;
Expand Down Expand Up @@ -360,7 +360,7 @@ void ComponentGrid::render(const Eigen::Affine3f& parentTrans)
Eigen::Affine3f trans = parentTrans * getTransform();

renderChildren(trans);

// draw cell separators
if(mLines.size())
{
Expand Down Expand Up @@ -425,20 +425,20 @@ std::vector<HelpPrompt> ComponentGrid::getHelpPrompts()
GridEntry* e = getCellAt(mCursor);
if(e)
prompts = e->component->getHelpPrompts();

bool canScrollVert = mGridSize.y() > 1;
bool canScrollHoriz = mGridSize.x() > 1;
for(auto it = prompts.begin(); it != prompts.end(); it++)
{
if(it->first == "up/down/left/right")
if(strcmp(it->first, "up/down/left/right") == 0)
{
canScrollHoriz = false;
canScrollVert = false;
break;
}else if(it->first == "up/down")
}else if(strcmp(it->first, "up/down") == 0)
{
canScrollVert = false;
}else if(it->first == "left/right")
}else if(strcmp(it->first, "left/right") == 0)
{
canScrollHoriz = false;
}
Expand Down
16 changes: 8 additions & 8 deletions es-core/src/components/ComponentList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void ComponentList::onCursorChanged(const CursorState& state)
{
for(auto it = mEntries.begin(); it != mEntries.end(); it++)
it->data.elements.back().component->onFocusLost();

mEntries.at(mCursor).data.elements.back().component->onFocusGained();
}

Expand Down Expand Up @@ -166,7 +166,7 @@ void ComponentList::render(const Eigen::Affine3f& parentTrans)
// clip everything to be inside our bounds
Eigen::Vector3f dim(mSize.x(), mSize.y(), 0);
dim = trans * dim - trans.translation();
Renderer::pushClipRect(Eigen::Vector2i((int)trans.translation().x(), (int)trans.translation().y()),
Renderer::pushClipRect(Eigen::Vector2i((int)trans.translation().x(), (int)trans.translation().y()),
Eigen::Vector2i((int)round(dim.x()), (int)round(dim.y() + 1)));

// scroll the camera
Expand Down Expand Up @@ -200,20 +200,20 @@ void ComponentList::render(const Eigen::Affine3f& parentTrans)
// need a function that goes roughly 0x777777 -> 0xFFFFFF
// and 0xFFFFFF -> 0x777777
// (1 - dst) + 0x77

const float selectedRowHeight = getRowHeight(mEntries.at(mCursor).data);
Renderer::drawRect(0.0f, mSelectorBarOffset, mSize.x(), selectedRowHeight, 0xFFFFFFFF,
GL_ONE_MINUS_DST_COLOR, GL_ZERO);
Renderer::drawRect(0.0f, mSelectorBarOffset, mSize.x(), selectedRowHeight, 0x777777FF,
GL_ONE, GL_ONE);

// hack to draw 2px dark on left/right of the bar
Renderer::drawRect(0.0f, mSelectorBarOffset, 2.0f, selectedRowHeight, 0x878787FF);
Renderer::drawRect(mSize.x() - 2.0f, mSelectorBarOffset, 2.0f, selectedRowHeight, 0x878787FF);

for(auto it = drawAfterCursor.begin(); it != drawAfterCursor.end(); it++)
(*it)->render(trans);

// reset matrix if one of these components changed it
if(drawAfterCursor.size())
Renderer::setMatrix(trans);
Expand Down Expand Up @@ -318,7 +318,7 @@ std::vector<HelpPrompt> ComponentList::getHelpPrompts()
bool addMovePrompt = true;
for(auto it = prompts.begin(); it != prompts.end(); it++)
{
if(it->first == "up/down" || it->first == "up/down/left/right")
if(strcmp(it->first, "up/down") == 0 || strcmp(it->first, "up/down/left/right") == 0)
{
addMovePrompt = false;
break;
Expand All @@ -334,7 +334,7 @@ std::vector<HelpPrompt> ComponentList::getHelpPrompts()

bool ComponentList::moveCursor(int amt)
{
bool ret = listInput(amt);
listInput(0);
bool ret = listInput(amt);
listInput(0);
return ret;
}
10 changes: 8 additions & 2 deletions es-core/src/components/ScrollableContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@
#define AUTO_SCROLL_DELAY 8000 // ms to wait before we start to scroll
#define AUTO_SCROLL_SPEED 50 // ms between scrolls

ScrollableContainer::ScrollableContainer(Window* window) : GuiComponent(window),
mAutoScrollDelay(0), mAutoScrollSpeed(0), mAutoScrollAccumulator(0), mScrollPos(0, 0), mScrollDir(0, 0), mAutoScrollResetAccumulator(0)
ScrollableContainer::ScrollableContainer(Window* window) : GuiComponent(window),
mAutoScrollDelay(0),
mAutoScrollSpeed(0),
mAutoScrollAccumulator(0),
mScrollPos(0, 0),
mScrollDir(0, 0),
mAtEnd(false),
mAutoScrollResetAccumulator(0)
{
}

Expand Down
Loading