Skip to content

Commit b293a93

Browse files
author
JekiTheMonkey
committed
Fixed some bugs, added fade out for key press visualization
1 parent 08d3bc9 commit b293a93

File tree

11 files changed

+249
-86
lines changed

11 files changed

+249
-86
lines changed

Headers/Application.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Application
2626

2727
static unsigned getWindowWidth();
2828
static unsigned getWindowHeight();
29+
static sf::IntRect getWindowRect();
2930

3031
static bool parameterIdMatches(LogicalParameter::ID id);
3132

Headers/GfxButton.hpp

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
#include <SFML/Graphics/Transformable.hpp>
55
#include <SFML/Graphics/Sprite.hpp>
66
#include <SFML/Graphics/Text.hpp>
7+
#include <SFML/Graphics/RectangleShape.hpp>
78

89
#include "ResourceIdentifiers.hpp"
910

1011
#include <array>
1112
#include <memory>
1213

13-
#include <SFML/Graphics/RectangleShape.hpp>
1414

1515

1616
class GfxButton : public sf::Drawable, public sf::Transformable
@@ -60,8 +60,6 @@ class GfxButton : public sf::Drawable, public sf::Transformable
6060
void resetAssets();
6161
void scaleSprites();
6262

63-
void removeOutOfViewPressRects();
64-
6563
// Light animation
6664
void lightKey();
6765
void fadeKey();
@@ -79,10 +77,37 @@ class GfxButton : public sf::Drawable, public sf::Transformable
7977
std::array<std::unique_ptr<sf::Text>, TextID::TextIdCounter> mTexts;
8078

8179

80+
private:
81+
class RectEmitter : public sf::Drawable
82+
{
83+
public:
84+
RectEmitter();
85+
86+
void update(bool buttonPressed);
87+
void draw(sf::RenderTarget &target, sf::RenderStates states) const override;
88+
89+
void setPosition(sf::Vector2f position);
90+
void create(sf::Vector2f buttonSize);
91+
92+
93+
private:
94+
sf::Transform getPressRectTransform(sf::Transform transform) const;
95+
float getVertexProgress(size_t vertexNumber, float vertexHeight) const;
96+
97+
98+
private:
99+
sf::VertexArray mVertecies;
100+
std::vector<size_t> mAvailableRectIndices;
101+
std::vector<size_t> mUsedRectIndices;
102+
sf::Vector2f mEmitterPosition;
103+
sf::Vector2f mLastRectSize;
104+
};
105+
106+
82107
private:
83108
const TextureHolder &mTextures;
84109
const FontHolder &mFonts;
85-
std::vector<sf::RectangleShape> mPressRects;
110+
RectEmitter mEmitter;
86111
sf::RectangleShape mBounds;
87112

88113
bool mLastKeyState;

Headers/LogicalParameter.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ struct LogicalParameter
178178
KeyPressVisToggle,
179179
KeyPressVisSpeed,
180180
KeyPressVisRotation,
181+
KeyPressVisFadeLineLen,
181182
KeyPressVisOrig,
182183
KeyPressVisColor,
183184

Headers/ParameterLine.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ class ParameterLine : public sf::Drawable, public sf::Transformable, public std:
198198
KeyPressVisToggle,
199199
KeyPressVisSpeed,
200200
KeyPressVisRotation,
201+
KeyPressVisFadeLineLen,
201202
KeyPressVisOrig,
202203
KeyPressVisColor,
203204
KeyPressVisMty,

Headers/Settings.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ namespace Settings
118118
extern bool KeyPressVisToggle;
119119
extern float KeyPressVisSpeed;
120120
extern float KeyPressVisRotation;
121+
extern float KeyPressVisFadeLineLen;
121122
extern sf::Vector2f KeyPressVisOrig;
122123
extern sf::Color KeyPressVisColor;
123124

Source/Application.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,12 @@ unsigned Application::getWindowHeight()
486486
return height > 0 ? height : 100;
487487
}
488488

489+
sf::IntRect Application::getWindowRect()
490+
{
491+
return { { }, sf::Vector2i(getWindowWidth(), getWindowHeight()) };
492+
}
493+
494+
489495
bool Application::parameterIdMatches(LogicalParameter::ID id)
490496
{
491497
return

Source/Button.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,5 +194,7 @@ bool Button::parameterIdMatches(LogicalParameter::ID id)
194194
id == LogicalParameter::ID::BtnGfxBtnos14 ||
195195
id == LogicalParameter::ID::BtnGfxSz14 ||
196196
id == LogicalParameter::ID::BtnGfxBtnos15 ||
197-
id == LogicalParameter::ID::BtnGfxSz15;
197+
id == LogicalParameter::ID::BtnGfxSz15 ||
198+
id == LogicalParameter::ID::KeyPressVisRotation ||
199+
id == LogicalParameter::ID::KeyPressVisFadeLineLen;
198200
}

0 commit comments

Comments
 (0)