Triangles/src/state.hpp
Stephen Seo d30a792aca Impl edit tri color, and more
Added way to select and edit colors of placed Tris.
Added third_party catch unit test framework that builds the UnitTest in
Debug builds.
Refactor internal use of notification_text.
Rename src/imgui_helper.hpp to src/helpers.hpp
Added some helper functions, including "is_within_shape" (used for
selecting a Tri).
Fixed use of flags in helpers not using enum values.
2020-08-04 21:13:17 +09:00

128 lines
3.2 KiB
C++

#ifndef TRIANGLES_STATE_HPP
#define TRIANGLES_STATE_HPP
#define TRIANGLES_EDIT_TRI_BLINK_RATE 2.0f
#include <bitset>
#include <vector>
#include <array>
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
namespace Tri {
class State {
public:
State(int argc, char **argv);
~State();
enum CurrentState {NONE = 0, FIRST = 1, SECOND = 2};
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,
};
private:
// use enum FlagName
typedef std::bitset<64> BitsetType;
BitsetType flags;
unsigned int width;
unsigned int height;
const sf::Time dt;
float notification_alpha;
typedef std::array<char, 256> NotificationBufferType;
NotificationBufferType notification_text;
sf::RenderWindow window;
std::vector<sf::ConvexShape> tris;
unsigned int trisIndex;
sf::Vector2f currentTri[3];
CurrentState currentTri_state;
CurrentState currentTri_maxState;
sf::CircleShape pointCircle;
sf::Event event;
float colorPickerColor[4];
float bgColorPickerColor[3];
sf::Color bgColor;
typedef std::array<char, 256> FilenameBufferType;
FilenameBufferType saveFilenameBuffer;
std::string failedMessage;
sf::RenderTexture drawCache;
sf::Sprite drawCacheSprite;
int inputWidthHeight[2];
const float pi;
unsigned int selectedTri;
float selectedTriColor[4];
float selectedTriBlinkTimer;
public:
void handle_events();
void update();
void draw();
private:
void draw_to_target(sf::RenderTarget *target);
public:
unsigned int get_width() const;
unsigned int get_height() const;
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();
FilenameBufferType* get_save_filename_buffer();
bool do_save();
std::string_view failed_message() const;
void close_save();
private:
bool can_draw() const;
void reset_modes();
public:
void close_help();
void close_color_picker();
void close_bg_color_picker();
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();
};
}
#endif