Skip to content

Commit

Permalink
Fixed some bugs, added fade out for key press visualization
Browse files Browse the repository at this point in the history
  • Loading branch information
JekiTheMonkey committed Jan 8, 2022
1 parent 08d3bc9 commit b293a93
Show file tree
Hide file tree
Showing 11 changed files with 249 additions and 86 deletions.
1 change: 1 addition & 0 deletions Headers/Application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Application

static unsigned getWindowWidth();
static unsigned getWindowHeight();
static sf::IntRect getWindowRect();

static bool parameterIdMatches(LogicalParameter::ID id);

Expand Down
33 changes: 29 additions & 4 deletions Headers/GfxButton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
#include <SFML/Graphics/Transformable.hpp>
#include <SFML/Graphics/Sprite.hpp>
#include <SFML/Graphics/Text.hpp>
#include <SFML/Graphics/RectangleShape.hpp>

#include "ResourceIdentifiers.hpp"

#include <array>
#include <memory>

#include <SFML/Graphics/RectangleShape.hpp>


class GfxButton : public sf::Drawable, public sf::Transformable
Expand Down Expand Up @@ -60,8 +60,6 @@ class GfxButton : public sf::Drawable, public sf::Transformable
void resetAssets();
void scaleSprites();

void removeOutOfViewPressRects();

// Light animation
void lightKey();
void fadeKey();
Expand All @@ -79,10 +77,37 @@ class GfxButton : public sf::Drawable, public sf::Transformable
std::array<std::unique_ptr<sf::Text>, TextID::TextIdCounter> mTexts;


private:
class RectEmitter : public sf::Drawable
{
public:
RectEmitter();

void update(bool buttonPressed);
void draw(sf::RenderTarget &target, sf::RenderStates states) const override;

void setPosition(sf::Vector2f position);
void create(sf::Vector2f buttonSize);


private:
sf::Transform getPressRectTransform(sf::Transform transform) const;
float getVertexProgress(size_t vertexNumber, float vertexHeight) const;


private:
sf::VertexArray mVertecies;
std::vector<size_t> mAvailableRectIndices;
std::vector<size_t> mUsedRectIndices;
sf::Vector2f mEmitterPosition;
sf::Vector2f mLastRectSize;
};


private:
const TextureHolder &mTextures;
const FontHolder &mFonts;
std::vector<sf::RectangleShape> mPressRects;
RectEmitter mEmitter;
sf::RectangleShape mBounds;

bool mLastKeyState;
Expand Down
1 change: 1 addition & 0 deletions Headers/LogicalParameter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ struct LogicalParameter
KeyPressVisToggle,
KeyPressVisSpeed,
KeyPressVisRotation,
KeyPressVisFadeLineLen,
KeyPressVisOrig,
KeyPressVisColor,

Expand Down
1 change: 1 addition & 0 deletions Headers/ParameterLine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ class ParameterLine : public sf::Drawable, public sf::Transformable, public std:
KeyPressVisToggle,
KeyPressVisSpeed,
KeyPressVisRotation,
KeyPressVisFadeLineLen,
KeyPressVisOrig,
KeyPressVisColor,
KeyPressVisMty,
Expand Down
1 change: 1 addition & 0 deletions Headers/Settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ namespace Settings
extern bool KeyPressVisToggle;
extern float KeyPressVisSpeed;
extern float KeyPressVisRotation;
extern float KeyPressVisFadeLineLen;
extern sf::Vector2f KeyPressVisOrig;
extern sf::Color KeyPressVisColor;

Expand Down
6 changes: 6 additions & 0 deletions Source/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,12 @@ unsigned Application::getWindowHeight()
return height > 0 ? height : 100;
}

sf::IntRect Application::getWindowRect()
{
return { { }, sf::Vector2i(getWindowWidth(), getWindowHeight()) };
}


bool Application::parameterIdMatches(LogicalParameter::ID id)
{
return
Expand Down
4 changes: 3 additions & 1 deletion Source/Button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,7 @@ bool Button::parameterIdMatches(LogicalParameter::ID id)
id == LogicalParameter::ID::BtnGfxBtnos14 ||
id == LogicalParameter::ID::BtnGfxSz14 ||
id == LogicalParameter::ID::BtnGfxBtnos15 ||
id == LogicalParameter::ID::BtnGfxSz15;
id == LogicalParameter::ID::BtnGfxSz15 ||
id == LogicalParameter::ID::KeyPressVisRotation ||
id == LogicalParameter::ID::KeyPressVisFadeLineLen;
}
Loading

0 comments on commit b293a93

Please sign in to comment.