PumpkinBrush
App.hpp
Go to the documentation of this file.
1 
7 #ifndef APP_HPP
8 #define APP_HPP
9 
10 
11 
12 // Include our Third-Party SFML header
13 #include <SFML/Graphics.hpp>
14 #include <SFML/Graphics/Image.hpp>
15 #include <SFML/Graphics/Texture.hpp>
16 #include <SFML/Graphics/Sprite.hpp>
17 
18 #include <SFML/Network.hpp>
19 
20 // Include OpenGL
21 
22 
23 // Include standard library C++ libraries.
24 #include <queue>
25 #include <stack>
26 #include "Command.hpp"
27 
28 
29 #include "BrushFactory.hpp"
30 #include "Gui.hpp"
31 // Project header files
32 // #include ...
33 
34 // Singleton for our Application called 'App'.
35 class Gui;
36 
37 class App{
38 private:
39 // Member variables
40  // Queue stores the next command to do.
41  std::stack<Command*> m_redo;
42  // Stack that stores the last action to occur.
43  std::stack<Command*> m_undo;
44  // Main image
45  sf::Image* m_image;
46  // Create a sprite that we overaly
47  // on top of the texture.
48  sf::Sprite* m_sprite;
49  // Texture sent to the GPU for rendering
50  sf::Texture* m_texture;
51  // Render texture
52  // The Brush instance which can draw pixels
53  GeneralBrush* m_brush;
54  // Brush factory which can create different types of brushes
55  BrushFactory m_brushFactory;
56 
57  sf::Color* m_backgroundColor;
58 
59 
60 
61 // Member functions
62  // Default constructor which is hidden in the Singleton
63  // Store the address of our funcion pointer
64  // for each of the callback functions.
65  void (*m_initFunc)(void);
66  void (*m_updateFunc)(App&);
67  void (*m_drawFunc)(App&);
68 
69 
70 public:
71  //Networking
72  sf::TcpSocket clientSocketInApp;
73  sf::Socket::Status statusInApp;
74  sf::Packet packetInApp;
75 
76 // Member Variables
77  // Keeps track of the previous mouse and current mouse positions
78  // 'pmouse' is where the mouse previously was.
79  // 'mouse' records where the mouse currently is.
80  unsigned int pmouseX, pmouseY, mouseX, mouseY;
81 
82  // Command flag which will flip once the mouse button was released
83  int commandFlag = 1;
86  bool onErase = false;
87  sf::RenderWindow* m_window;
89 
90  App();
91  App(sf::IpAddress ipAddress, int port);
92  // void operator=(const App& app);
93 // Member functions
94 
95 
98  void setBrush(GeneralBrush* brush);
99  void addCommand(Command* c);
100  void executeCommand(Command* c);
101  void undoCommand(bool sendMessage);
102  void redoCommand(bool sendMessage);
103  void undoCommandNetwork();
104  void redoCommandNetwork();
105  sf::Image& getImage();
106  void setImage(sf::Image* newImage);
107  sf::Texture& getTexture();
108  sf::RenderWindow& getWindow();
109  std::stack<Command *> getUndoStack();
110  std::stack<Command *> getRedoStack();
111 
112 
113 
114  void destroy();
115  void init(void (*initFunction)(void));
116  void updateCallback(void (*updateFunction)(App& app));
117  void drawCallback(void (*drawFunction)(App& app));
118  void loop(App& app);
119  void setBackgroundColor(sf::Color *colorPassed);
120  sf::Color& getBackgroundColor();
121 
122 
123 };
124 
125 
126 #endif
127 //TODO: Write comments for the methods
App::destroy
void destroy()
destroy we manually call at end of our program.
Definition: App.cpp:262
App::getBrush
GeneralBrush & getBrush()
Return the current brush instance of the App.
Definition: App.cpp:225
App::pmouseY
unsigned int pmouseY
Definition: App.hpp:80
App::statusInApp
sf::Socket::Status statusInApp
Definition: App.hpp:73
App::UNDO
@ UNDO
Definition: App.hpp:84
App::m_gui
Gui * m_gui
Definition: App.hpp:88
Gui
Definition: Gui.hpp:16
App::DRAW
@ DRAW
Definition: App.hpp:84
App::clientSocketInApp
sf::TcpSocket clientSocketInApp
Definition: App.hpp:72
App::commandFlag
int commandFlag
Definition: App.hpp:83
Command
Definition: Command.hpp:18
App::onErase
bool onErase
Definition: App.hpp:86
App::CLEAR
@ CLEAR
Definition: App.hpp:84
App::REDO
@ REDO
Definition: App.hpp:84
App::getWindow
sf::RenderWindow & getWindow()
Return a reference to our m_window so that we do not have to publicly expose it.
Definition: App.cpp:208
App::undoCommand
void undoCommand(bool sendMessage)
The undoCommand function unodoes the the pixel in reverse chronological order from a stack recursivel...
Definition: App.cpp:99
App::getImage
sf::Image & getImage()
Return a reference to our m_image, so that we do not have to publicly expose it.
Definition: App.cpp:186
App::App
App()
The constructor of the App class that initializes certain crucial values for the application.
Definition: App.cpp:41
App::ERASE
@ ERASE
Definition: App.hpp:84
App::redoCommand
void redoCommand(bool sendMessage)
The redo commands redo an undo command until if there is an input in between.
Definition: App.cpp:147
App::mouseX
unsigned int mouseX
Definition: App.hpp:80
BrushFactory.hpp
App::getUndoStack
std::stack< Command * > getUndoStack()
returns the current undo stack where all the commands to be undone are stored
Definition: App.cpp:238
App::setBrush
void setBrush(GeneralBrush *brush)
Set the current brush.
Definition: App.cpp:232
App::getRedoStack
std::stack< Command * > getRedoStack()
returns the current redo stack where all the commands to be redone are stored
Definition: App.cpp:245
App::undoCommandNetwork
void undoCommandNetwork()
The undoCommand function unodoes the the pixel in reverse chronological order for the network i....
Definition: App.cpp:129
App::init
void init(void(*initFunction)(void))
Initializes the App and sets up the main rendering window(i.e. our canvas.)
Definition: App.cpp:273
Gui.hpp
A GUI class that renders a gui window and operation widgets for the mini paint app.
App::m_prevCommand
commandEnum m_prevCommand
Definition: App.hpp:85
App::m_window
sf::RenderWindow * m_window
Definition: App.hpp:87
App::redoCommandNetwork
void redoCommandNetwork()
The redo commands redo an undo command until if there is an input in between for the network i....
Definition: App.cpp:170
GeneralBrush
GeneralBrush class which represent the brush instance when drawing on the canvas.
Definition: GeneralBrush.hpp:13
App::drawCallback
void drawCallback(void(*drawFunction)(App &app))
Set a callback function which will be called each iteration of the main loop after update.
Definition: App.cpp:309
App::mouseY
unsigned int mouseY
Definition: App.hpp:80
App::pmouseX
unsigned int pmouseX
Definition: App.hpp:80
App::setBackgroundColor
void setBackgroundColor(sf::Color *colorPassed)
Set a reference to m_backgroundColor.
Definition: App.cpp:361
Command.hpp
Represents an actionable command by the user.
App::addCommand
void addCommand(Command *c)
The addCommand function servers two purpose, first is adding the command to the redo stack and the se...
Definition: App.cpp:31
App::setImage
void setImage(sf::Image *newImage)
Sets the image passed in from the parameter for the App class.
Definition: App.cpp:192
App::loop
void loop(App &app)
The main loop function which handles initialization and will be executed until the main window is clo...
Definition: App.cpp:319
BrushFactory
Brush factory class which initialize brush instance.
Definition: BrushFactory.hpp:6
App::updateCallback
void updateCallback(void(*updateFunction)(App &app))
Set a callback function which will be called each iteration of the main loop before drawing.
Definition: App.cpp:301
App::executeCommand
void executeCommand(Command *c)
The execute Command function helps execute the command to generate pixel upon input from the user,...
Definition: App.cpp:89
App::packetInApp
sf::Packet packetInApp
Definition: App.hpp:74
App
Definition: App.hpp:37
App::getTexture
sf::Texture & getTexture()
Return a reference to our m_Texture so that we do not have to publicly expose it.
Definition: App.cpp:200
App::getBackgroundColor
sf::Color & getBackgroundColor()
Return a reference to our m_backgroundColor so that we do not have to publicly expose it.
Definition: App.cpp:253
App::commandEnum
commandEnum
Definition: App.hpp:84
App::getBrushFactory
BrushFactory getBrushFactory()
Return the brush factory of App.
Definition: App.cpp:217