Skip to content

Commit 09a8372

Browse files
committed
Re-added the event file, change how AppStates are constructed, made a changestate function
1 parent 59bf369 commit 09a8372

File tree

6 files changed

+113
-8
lines changed

6 files changed

+113
-8
lines changed

src/AppState.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
#ifndef _APPSTATE_H
22
#define _APPSTATE_H
33

4+
#include "Event.h"
45
#include <SFML/Graphics.hpp>
56

67
namespace chesspp
78
{
89
//pure virtual abstract base class for game state management.
9-
class AppState
10+
class AppState : public Event
1011
{
1112
public:
1213
AppState() {}
1314
virtual ~AppState() {}
1415

15-
virtual void OnEvent(sf::Event& event) {} //Nothing by default
1616
virtual int id() = 0;
1717
virtual void OnRender(sf::RenderWindow &display) = 0;
1818
};

src/AppStateGame.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@ namespace chesspp
1212
{
1313
class AppStateGame : public AppState
1414
{
15+
Application* app;
16+
1517
public:
16-
AppStateGame() {}
18+
AppStateGame(Application*);
1719
virtual ~AppStateGame() {}
1820

1921
virtual int id();
2022
virtual void OnRender(sf::RenderWindow &display);
21-
22-
private:
23-
//members of game can go here, board, etc etc.
2423
};
2524
}
2625

src/Application.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace chesspp
66
Application::Application()
77
: display(sf::VideoMode(640, 640), "ChessPlusPlus"),
88
running(true),
9-
state(new AppStateGame)
9+
state(new AppStateGame(this))
1010
{
1111
}
1212

src/Application.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ namespace chesspp
1414
public:
1515
Application();
1616
~Application();
17-
17+
18+
template <class NewState> void ChangeState()
19+
{
20+
delete state;
21+
state = new NewState;
22+
}
23+
1824
int Exec();
1925
};
2026
}

src/Event.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
namepspace chesspp {
2+
Event::Event()
3+
{
4+
}
5+
6+
Event::~Event()
7+
{
8+
}
9+
10+
//pure virtual, do nothing
11+
void Event::OnClosed() {
12+
}
13+
void Event::OnResized(uint w, uint h) {
14+
}
15+
void Event::OnLostFocus() {
16+
}
17+
void Event::OnGainedFocus() {
18+
}
19+
void Event::OnTextEntered(sf::Uint32 unicode) {
20+
}
21+
void Event::OnKeyPressed(sf::Keyboard::Key key, bool alt, bool control, bool shift, bool system) {
22+
}
23+
void Event::OnKeyReleased(sf::Keyboard::Key key, bool alt, bool control, bool shift, bool system) {
24+
}
25+
void Event::OnMouseWheelMoved(int delta, int x, int y) {
26+
}
27+
void Event::OnLButtonPressed(int x, int y) {
28+
}
29+
void Event::OnLButtonReleased(int x, int y) {
30+
}
31+
void Event::OnRButtonPressed(int x, int y) {
32+
}
33+
void Event::OnRButtonReleased(int x, int y) {
34+
}
35+
void Event::OnMButtonPressed(int x, int y) {
36+
}
37+
void Event::OnMButtonReleased(int x, int y) {
38+
}
39+
void Event::OnMouseButtonPressed(sf::Mouse::Button button, int x, int y) {
40+
}
41+
void Event::OnMouseButtonReleased(sf::Mouse::Button button, int x, int y) {
42+
}
43+
void Event::OnMouseMoved(int x, int y) {
44+
}
45+
void Event::OnMouseEnteredWindow() {
46+
}
47+
void Event::OnMouseLeftWindow() {
48+
}
49+
void Event::OnJoystickButtonPressed(uint joystickID, uint button) {
50+
}
51+
void Event::OnJoystickButtonReleased(uint joystickID, uint button) {
52+
}
53+
void Event::OnJoystickMoved(uint joystickID, sf::Joystick::Axis axis, float position) {
54+
}
55+
void Event::OnJoystickConnected(uint joystickID) {
56+
}
57+
void Event::OnJoystickDisconnected(uint joystickID) {
58+
}
59+
}

src/Event.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#ifndef _EVENT_H
2+
#define _EVENT_H
3+
4+
#include "SFML.hpp"
5+
6+
namespace chesspp
7+
{
8+
class Event
9+
{
10+
public:
11+
typedef unsigned int uint;
12+
13+
virtual void OnEvent(sf::Event *Event);
14+
virtual void OnClosed();
15+
virtual void OnResized(uint w, uint h);
16+
virtual void OnLostFocus();
17+
virtual void OnGainedFocus();
18+
virtual void OnTextEntered(sf::Uint32 unicode);
19+
virtual void OnKeyPressed(sf::Keyboard::Key key, bool alt, bool control, bool shift, bool system);
20+
virtual void OnKeyReleased(sf::Keyboard::Key key, bool alt, bool control, bool shift, bool system);
21+
virtual void OnMouseWheelMoved(int delta, int x, int y);
22+
virtual void OnLButtonPressed(int x, int y);
23+
virtual void OnLButtonReleased(int x, int y);
24+
virtual void OnRButtonPressed(int x, int y);
25+
virtual void OnRButtonReleased(int x, int y);
26+
virtual void OnMButtonPressed(int x, int y);
27+
virtual void OnMButtonReleased(int x, int y);
28+
virtual void OnMouseButtonPressed(sf::Mouse::Button button, int x, int y);
29+
virtual void OnMouseButtonReleased(sf::Mouse::Button button, int x, int y);
30+
virtual void OnMouseMoved(int x, int y);
31+
virtual void OnMouseEnteredWindow();
32+
virtual void OnMouseLeftWindow();
33+
virtual void OnJoystickButtonPressed(uint joystickID, uint button);
34+
virtual void OnJoystickButtonReleased(uint joystickID, uint button);
35+
virtual void OnJoystickMoved(uint joystickID, sf::Joystick::Axis axis, float position);
36+
virtual void OnJoystickConnected(uint joystickID);
37+
virtual void OnJoystickDisconnected(uint joystickID);
38+
};
39+
}
40+
41+
#endif

0 commit comments

Comments
 (0)