Skip to content

Commit

Permalink
Changed title scrolling to work better with multithreading
Browse files Browse the repository at this point in the history
  • Loading branch information
WerWolv committed Aug 17, 2018
1 parent 451daef commit 32d6255
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions source/gui_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
#include <sstream>
#include <math.h>

float xOffset;
float xOffsetNext;

bool drawingDone = false;
float xOffset, xOffsetNext, xOffsetDone;

enum {
TITLE_SELECT,
Expand All @@ -36,23 +33,18 @@ GuiMain::~GuiMain() {
void GuiMain::update() {
Gui::update();

if (!drawingDone) return;

float deltaOffset = xOffsetNext - xOffset;
float scrollSpeed = deltaOffset / 24.0F;
float deltaOffset = xOffsetNext - xOffsetDone;
float scrollSpeed = deltaOffset / 150.0F;

if (xOffset != xOffsetNext) {
if (xOffsetNext > xOffset)
xOffset += ceil((abs(deltaOffset) > scrollSpeed) ? scrollSpeed : deltaOffset);
if (xOffsetDone != xOffsetNext) {
if (xOffsetNext > xOffsetDone)
xOffsetDone += ceil((abs(deltaOffset) > scrollSpeed) ? scrollSpeed : deltaOffset);
else
xOffset += floor((abs(deltaOffset) > scrollSpeed) ? scrollSpeed : deltaOffset);
xOffsetDone += floor((abs(deltaOffset) > scrollSpeed) ? scrollSpeed : deltaOffset);
}

}

void GuiMain::draw() {
drawingDone = false;

Gui::beginDraw();

Gui::drawRectangle(0, 0, Gui::g_framebuffer_width, Gui::g_framebuffer_height, currTheme.backgroundColor);
Expand Down Expand Up @@ -115,7 +107,8 @@ void GuiMain::draw() {
}
}

drawingDone = true;
if (xOffset != xOffsetNext)
xOffset = xOffsetDone;

Gui::endDraw();
}
Expand Down

0 comments on commit 32d6255

Please sign in to comment.