Skip to content

Commit

Permalink
Correctly init classes' member variables
Browse files Browse the repository at this point in the history
  • Loading branch information
BJMinhNhut committed May 11, 2023
1 parent 5348be1 commit 1dd0439
Show file tree
Hide file tree
Showing 23 changed files with 64 additions and 53 deletions.
1 change: 0 additions & 1 deletion inc/GUI/Input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class Input : public Component {
private:
sf::RectangleShape mCursor;
bool cursorDrawable;
sf::Time cursorLife;
sf::Time cursorCountdown;

const sf::Texture mNormalTexture;
Expand Down
3 changes: 3 additions & 0 deletions inc/States/SettingsState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
#define SETTINGSSTATE_HPP

#include <GUI/Container.hpp>
#include <Settings.hpp>
#include <States/State.hpp>

#include <SFML/Graphics/Sprite.hpp>

class SettingsState : public State {
public:
SettingsState(StateStack& stack, Context context);
Expand Down
1 change: 1 addition & 0 deletions src/Array/DynamicArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ DynamicArray::DynamicArray(const FontHolder& fonts,
mTextures(textures),
mColors(colors),
nodes(),
tempNodes(),
mHead(new Pointer(fonts, colors)),
mTemp(new Pointer(fonts, colors)) {
mHead->setLabel("arr");
Expand Down
3 changes: 2 additions & 1 deletion src/Array/VisualDynamicState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ VisualDynamicState::VisualDynamicState(StateStack& stack,
: VisualState(stack, context, "Dynamic Array"),
mArray(*context.fonts, *context.textures, *context.colors),
GUIValueInput(OptionCount),
GUIIndexInput(OptionCount) {
GUIIndexInput(OptionCount),
GUIArrayInput(nullptr) {
initGUIButtons();

loadNewGUI();
Expand Down
3 changes: 2 additions & 1 deletion src/Array/VisualStaticState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ VisualStaticState::VisualStaticState(StateStack& stack,
: VisualState(stack, context, "Static Array"),
mArray(*context.fonts, *context.textures, *context.colors),
GUIValueInput(OptionCount),
GUIIndexInput(OptionCount) {
GUIIndexInput(OptionCount),
GUIArrayInput(nullptr) {
initGUIButtons();

loadNewGUI();
Expand Down
5 changes: 3 additions & 2 deletions src/CLL/CircularLinkedList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ CircularLinkedList::CircularLinkedList(const FontHolder& fonts,
const ColorHolder& colors)
: mHead(new Pointer(fonts, colors)),
mTail(new Pointer(fonts, colors)),
mHighlight(),
mFonts(fonts),
mTextures(textures),
mColors(colors),
tempNode(nullptr),
highlightIndex(-1) {
mHighlight(),
highlightIndex(-1),
nodes() {
mHead->setLabel("head");
attachChild(std::unique_ptr<Pointer>(mHead));

Expand Down
3 changes: 2 additions & 1 deletion src/CLL/VisualCLLState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ VisualCLLState::VisualCLLState(StateStack& stack, Context context)
: VisualState(stack, context, "Circular Linked List"),
mCLL(*context.fonts, *context.textures, *context.colors),
GUIValueInput(OptionCount),
GUIIndexInput(OptionCount) {
GUIIndexInput(OptionCount),
GUIArrayInput(nullptr) {

initGUIButtons();

Expand Down
3 changes: 2 additions & 1 deletion src/DLL/DoublyLinkedList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ DoublyLinkedList::DoublyLinkedList(const FontHolder& fonts,
mTextures(textures),
mColors(colors),
tempNode(nullptr),
highlightIndex(-1) {
highlightIndex(-1),
nodes() {
mHead->setLabel("head");
mHead->setTargetPosition(sf::Vector2f(0.f, -7.f), None);
mHead->setLabelOffset(0.f, -17.f);
Expand Down
4 changes: 2 additions & 2 deletions src/DLL/DoublyNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ DoublyNode::DoublyNode(const FontHolder& fonts,
const ColorHolder& colors)
: mData(new NodeData(fonts, colors)),
mNext(new Pointer(fonts, colors)),
mPrev(new Pointer(fonts, colors)) {
mPrev(new Pointer(fonts, colors)),
mSprite(textures.get(Textures::DoublyNode)) {

attachChild(std::unique_ptr<NodeData>(mData));
attachChild(std::unique_ptr<Pointer>(mNext));
Expand All @@ -34,7 +35,6 @@ DoublyNode::DoublyNode(const FontHolder& fonts,
mPrev->resetDestination();
mPrev->setNull(Pointer::Right);

mSprite.setTexture(textures.get(Textures::DoublyNode), true);
centerOrigin(mSprite);
}

Expand Down
3 changes: 2 additions & 1 deletion src/DLL/VisualDLLState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ VisualDLLState::VisualDLLState(StateStack& stack, Context context)
: VisualState(stack, context, "Doubly Linked List"),
mDLL(*context.fonts, *context.textures, *context.colors),
GUIValueInput(OptionCount),
GUIIndexInput(OptionCount) {
GUIIndexInput(OptionCount),
GUIArrayInput(nullptr) {
initGUIButtons();

loadNewGUI();
Expand Down
7 changes: 3 additions & 4 deletions src/GUI/Button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ Button::Button(Type type, const FontHolder& fonts,
mIsToggle(false),
mNormalTexture(textures.get(getNormalTextureID(type))),
mSelectedTexture(textures.get(getSelectedTextureID(type))),
mPressedTexture(textures.get(getPressedTextureID(type))) {
mPressedTexture(textures.get(getPressedTextureID(type))),
mSprite(mNormalTexture),
mText() {
setFont(type, fonts, colors);
mSprite.setTexture(mNormalTexture);

centerOrigin(mSprite);
centerOrigin(mText);
}

Textures::ID Button::getNormalTextureID(Type type) const {
Expand Down
5 changes: 3 additions & 2 deletions src/GUI/Input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ Input::Input(const FontHolder& fonts, const TextureHolder& textures,
mText("", fonts.get(Fonts::Mono), 18),
cursorDrawable(true),
mCursor(getLineShape(sf::Vector2f(0.f, 16.f), 2.f)),
cursorCountdown(Constants::INPUT_CURSOR_LIFE) {
cursorCountdown(Constants::INPUT_CURSOR_LIFE),
mSprite(mNormalTexture),
mAllowedCharacters() {

allowChar('\n');

mText.setFillColor(colors.get(Colors::Text));
alignText();

mSprite.setTexture(mNormalTexture);
centerOrigin(mSprite);

mCursor.setFillColor(colors.get(Colors::Text));
Expand Down
7 changes: 2 additions & 5 deletions src/Graphics/NodeData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
#include <string>

NodeData::NodeData(const FontHolder& fonts, const ColorHolder& colors)
: mValue(0) {

mText.setFont(fonts.get(Fonts::Main));
mText.setString(std::to_string(mValue));
mText.setCharacterSize(20u);
: mValue(0),
mText(std::to_string(mValue), fonts.get(Fonts::Main), 20u) {
mText.setFillColor(colors.get(Colors::Text));
centerOrigin(mText);
}
Expand Down
13 changes: 9 additions & 4 deletions src/Graphics/Pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@
#include <iostream>

Pointer::Pointer(const FontHolder& fonts, const ColorHolder& colors)
: mColor(colors.get(Colors::Text)),
: mDestination(),
mTargetDestination(),
mColor(colors.get(Colors::Text)),
mCircle(4.f, 20),
mArrow(),
mArrowTip(),
mCircularArrow(),
isCircular(false),
mLabel("", fonts.get(Fonts::Main), 16u),
TextNULL("null", fonts.get(Fonts::Main), 16u),
mTarget(nullptr),
isCircular(false),
mType(Left),
mCircle(4.f, 20) {
mType(Left) {
centerOrigin(mLabel);
mLabel.setPosition(0.f, mCircle.getRadius() + 8.f);
mLabel.setFillColor(colors.get(Colors::Text));
Expand Down
3 changes: 2 additions & 1 deletion src/Queue/VisualQueueState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ VisualQueueState::VisualQueueState(StateStack& stack, Context context)
: VisualState(stack, context, "Queue"),
mQueue(*context.fonts, *context.textures, *context.colors),
GUIValueInput(OptionCount),
GUIIndexInput(OptionCount) {
GUIIndexInput(OptionCount),
GUIArrayInput(nullptr) {

centerSLL(SceneNode::None);
mQueue.refreshPointerTarget();
Expand Down
3 changes: 2 additions & 1 deletion src/SLL/SinglyLinkedList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ SinglyLinkedList::SinglyLinkedList(const FontHolder& fonts,
mTextures(textures),
mColors(colors),
tempNode(nullptr),
highlightIndex(-1) {
highlightIndex(-1),
nodes() {

std::unique_ptr<Pointer> headPtr(mHead);
mHead->setLabel("head");
Expand Down
4 changes: 2 additions & 2 deletions src/SLL/SinglyNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ SinglyNode::SinglyNode(const FontHolder& fonts,
const TextureHolder& textures,
const ColorHolder& colors)
: mData(new NodeData(fonts, colors)),
mPointer(new Pointer(fonts, colors)) {
mPointer(new Pointer(fonts, colors)),
mSprite(textures.get(Textures::SinglyNode)) {
std::unique_ptr<NodeData> dataPtr(mData);
std::unique_ptr<Pointer> nextNodePtr(mPointer);

Expand All @@ -32,7 +33,6 @@ SinglyNode::SinglyNode(const FontHolder& fonts,

mSprite.setOrigin(Constants::NODE_SIZE / 2.f,
Constants::NODE_SIZE / 2.f);
mSprite.setTexture(textures.get(Textures::SinglyNode), true);
}

void SinglyNode::updateCurrent(sf::Time dt) {}
Expand Down
3 changes: 2 additions & 1 deletion src/SLL/VisualSLLState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ VisualSLLState::VisualSLLState(StateStack& stack, Context context)
: VisualState(stack, context, "Singly Linked List"),
mSLL(*context.fonts, *context.textures, *context.colors),
GUIValueInput(OptionCount),
GUIIndexInput(OptionCount) {
GUIIndexInput(OptionCount),
GUIArrayInput(nullptr) {

centerSLL(SceneNode::None);
mSLL.refreshPointerTarget();
Expand Down
3 changes: 2 additions & 1 deletion src/Stack/VisualStackState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ VisualStackState::VisualStackState(StateStack& stack, Context context)
: VisualState(stack, context, "Stack"),
mStack(*context.fonts, *context.textures, *context.colors),
GUIValueInput(OptionCount),
GUIIndexInput(OptionCount) {
GUIIndexInput(OptionCount),
GUIArrayInput(nullptr) {

centerSLL(SceneNode::None);
mStack.refreshPointerTarget();
Expand Down
10 changes: 3 additions & 7 deletions src/States/AboutState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@
#include <SFML/Graphics/View.hpp>

AboutState::AboutState(StateStack& stack, Context context)
: State(stack, context), mGUIContainer() {
sf::Texture& texture =
context.textures->get(Textures::Background);
sf::Font& font = context.fonts->get(Fonts::Main);

mBackgroundSprite.setTexture(texture);
sf::Vector2u bounds = context.window->getSize();
: State(stack, context),
mGUIContainer(),
mBackgroundSprite(context.textures->get(Textures::Background)) {

auto backButton = std::make_shared<GUI::Button>(
GUI::Button::Back, *context.fonts, *context.textures,
Expand Down
6 changes: 3 additions & 3 deletions src/States/MenuDataState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include <memory>

MenuDataState::MenuDataState(StateStack& stack, Context context)
: State(stack, context), mGUIContainer() {
mBackgroundSprite.setTexture(
context.textures->get(Textures::Background));
: State(stack, context),
mGUIContainer(),
mBackgroundSprite(context.textures->get(Textures::Background)) {

auto backButton = std::make_shared<GUI::Button>(
GUI::Button::Back, *getContext().fonts,
Expand Down
10 changes: 2 additions & 8 deletions src/States/SettingsState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <GUI/Label.hpp>
#include <GUI/Panel.hpp>
#include <GUI/Sprite.hpp>
#include <Settings.hpp>
#include <States/SettingsState.hpp>

#include <SFML/Graphics/RenderWindow.hpp>
Expand All @@ -13,13 +12,8 @@ SettingsState::SettingsState(StateStack& stack, Context context)
: State(stack, context),
mGUIContainer(),
themeContainer(),
mSettings(getSettings()) {
sf::Texture& texture =
context.textures->get(Textures::Background);
sf::Font& font = context.fonts->get(Fonts::Main);

mBackgroundSprite.setTexture(texture);
sf::Vector2u bounds = context.window->getSize();
mSettings(getSettings()),
mBackgroundSprite(context.textures->get(Textures::Background)) {

auto backButton = std::make_shared<GUI::Button>(
GUI::Button::Back, *getContext().fonts,
Expand Down
14 changes: 10 additions & 4 deletions src/States/VisualState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,26 @@
VisualState::VisualState(StateStack& stack, Context context,
const std::string& title)
: State(stack, context),
currentOption(0),
mGUIContainer(),
GUIOptionContainer(),
GUICommandContainer(),
currentOption(0),
loadAnimationCallback(),
GUIPlay(),
GUIPause(),
GUIReplay(),
GUIConsole(),
GUIProgressBar(),
GUICodeBlock(),
GUISpeed(),
mBackgroundSprite(context.textures->get(Textures::Background)),
mAnimationList(),
mSpeedMap({{"x0.5", 0.5f},
{"x1.0", 1.f},
{"x2.0", 2.f},
{"x3.0", 3.f}}),
mSpeedID(1) {

mBackgroundSprite.setTexture(
context.textures->get(Textures::Background));

auto titleBar = std::make_shared<GUI::Sprite>(
context.textures->get(Textures::TitleBar));
titleBar->setPosition(800.f, 30.f);
Expand Down

0 comments on commit 1dd0439

Please sign in to comment.