Triangles/src/state.hpp

128 lines
3.2 KiB
C++
Raw Normal View History

2020-07-21 11:34:39 +00:00
#ifndef TRIANGLES_STATE_HPP
#define TRIANGLES_STATE_HPP
#define TRIANGLES_EDIT_TRI_BLINK_RATE 2.0f
2020-07-21 11:34:39 +00:00
#include <bitset>
2020-07-21 11:44:10 +00:00
#include <vector>
2020-07-22 09:19:34 +00:00
#include <array>
2020-07-21 11:34:39 +00:00
#include <SFML/System.hpp>
2020-07-21 11:44:10 +00:00
#include <SFML/Graphics.hpp>
2020-07-21 11:34:39 +00:00
namespace Tri {
2020-07-22 06:19:37 +00:00
class State {
public:
State(int argc, char **argv);
~State();
enum CurrentState {NONE = 0, FIRST = 1, SECOND = 2};
2020-08-02 10:59:18 +00:00
enum FlagName {
F_DISPLAY_HELP = 0,
F_IS_RUNNING = 1,
F_DISPLAY_COLOR_P = 2,
F_COLOR_P_COLOR_DIRTY = 3,
F_BG_COLOR_P_COLOR_DIRTY = 4,
F_DISPLAY_BG_COLOR_P = 5,
F_DISPLAY_SAVE = 6,
F_DRAW_CACHE_DIRTY = 7,
F_DRAW_CACHE_INITIALIZED = 8,
F_COPY_COLOR_MODE = 9,
F_DISPLAY_CHANGE_SIZE = 10,
F_SELECT_TRI_MODE = 11,
F_TRI_EDIT_MODE = 12,
F_TRI_EDIT_DRAW_TRI = 13,
2020-08-02 10:59:18 +00:00
};
private:
2020-08-02 10:59:18 +00:00
// use enum FlagName
2020-07-22 06:19:37 +00:00
typedef std::bitset<64> BitsetType;
BitsetType flags;
unsigned int width;
unsigned int height;
2020-07-21 11:34:39 +00:00
const sf::Time dt;
float notification_alpha;
typedef std::array<char, 256> NotificationBufferType;
NotificationBufferType notification_text;
2020-07-21 11:34:39 +00:00
sf::RenderWindow window;
2020-07-21 11:44:10 +00:00
std::vector<sf::ConvexShape> tris;
2020-07-22 06:33:09 +00:00
unsigned int trisIndex;
2020-07-22 06:28:36 +00:00
sf::Vector2f currentTri[3];
CurrentState currentTri_state;
CurrentState currentTri_maxState;
2020-07-22 06:28:36 +00:00
sf::CircleShape pointCircle;
2020-07-21 11:44:10 +00:00
sf::Event event;
float colorPickerColor[4];
float bgColorPickerColor[3];
sf::Color bgColor;
2020-07-22 09:19:34 +00:00
typedef std::array<char, 256> FilenameBufferType;
FilenameBufferType saveFilenameBuffer;
2020-07-30 11:11:57 +00:00
std::string failedMessage;
2020-07-22 09:19:34 +00:00
sf::RenderTexture drawCache;
sf::Sprite drawCacheSprite;
2020-07-30 11:11:57 +00:00
int inputWidthHeight[2];
const float pi;
unsigned int selectedTri;
float selectedTriColor[4];
float selectedTriBlinkTimer;
2020-07-22 06:19:37 +00:00
public:
void handle_events();
2020-07-21 11:34:39 +00:00
void update();
void draw();
2020-07-22 06:19:37 +00:00
2020-07-22 09:19:34 +00:00
private:
void draw_to_target(sf::RenderTarget *target);
2020-07-22 09:19:34 +00:00
public:
unsigned int get_width() const;
unsigned int get_height() const;
2020-07-22 06:19:37 +00:00
const BitsetType get_flags() const;
float get_notification_alpha() const;
const char* get_notification_text() const;
private:
void set_notification_text(const char *text);
public:
float* get_color();
float* get_bg_color();
2020-07-22 09:19:34 +00:00
FilenameBufferType* get_save_filename_buffer();
bool do_save();
2020-07-30 11:11:57 +00:00
std::string_view failed_message() const;
2020-07-22 09:19:34 +00:00
void close_save();
private:
bool can_draw() const;
void reset_modes();
public:
void close_help();
void close_color_picker();
void close_bg_color_picker();
2020-07-30 11:11:57 +00:00
bool change_width_height();
int* get_input_width_height();
void close_input_width_height_window();
float get_pi() const;
float* get_selected_tri_color();
void close_selected_tri_mode();
2020-07-21 11:34:39 +00:00
};
}
#endif