2020-07-21 11:34:39 +00:00
|
|
|
#ifndef TRIANGLES_STATE_HPP
|
|
|
|
#define TRIANGLES_STATE_HPP
|
|
|
|
|
2020-08-04 12:13:17 +00:00
|
|
|
#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
|
|
|
|
2023-07-24 02:18:43 +00:00
|
|
|
#pragma GCC diagnostic push
|
2023-07-23 09:42:38 +00:00
|
|
|
#pragma GCC diagnostic ignored "-Weffc++"
|
2021-03-29 08:03:39 +00:00
|
|
|
#include "glm/glm.hpp"
|
2023-07-23 09:42:38 +00:00
|
|
|
#pragma GCC diagnostic pop
|
2021-03-29 08:03:39 +00:00
|
|
|
|
|
|
|
#include "triangle.hpp"
|
|
|
|
#include "circle.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);
|
2020-07-22 06:11:10 +00:00
|
|
|
~State();
|
2020-07-22 07:12:21 +00:00
|
|
|
|
|
|
|
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,
|
2020-08-04 12:13:17 +00:00
|
|
|
F_SELECT_TRI_MODE = 11,
|
|
|
|
F_TRI_EDIT_MODE = 12,
|
|
|
|
F_TRI_EDIT_DRAW_TRI = 13,
|
2021-03-30 03:51:46 +00:00
|
|
|
F_TAB_TOGGLE = 14,
|
2020-08-02 10:59:18 +00:00
|
|
|
};
|
|
|
|
|
2020-08-04 12:13:17 +00:00
|
|
|
private:
|
2024-01-24 08:24:56 +00:00
|
|
|
struct Action {
|
|
|
|
public:
|
|
|
|
typedef std::vector<Action>::size_type IndexT;
|
|
|
|
|
|
|
|
enum Type {
|
|
|
|
AT_TRI,
|
|
|
|
AT_TRI_DEL,
|
|
|
|
AT_POINT,
|
|
|
|
AT_NONE,
|
|
|
|
};
|
|
|
|
|
|
|
|
Action();
|
|
|
|
Action(const Type& type,
|
|
|
|
IndexT idx,
|
|
|
|
const Color& color,
|
|
|
|
float *data);
|
|
|
|
Action(Type&& type,
|
|
|
|
IndexT idx,
|
|
|
|
Color&& color,
|
|
|
|
float *data);
|
|
|
|
|
|
|
|
Type type;
|
|
|
|
IndexT idx;
|
|
|
|
Color color;
|
|
|
|
union Data {
|
|
|
|
float tri[6];
|
|
|
|
float point[2];
|
|
|
|
} data;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void init(float *data);
|
|
|
|
};
|
|
|
|
|
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;
|
2021-03-29 08:03:39 +00:00
|
|
|
float dt;
|
2021-03-30 07:38:25 +00:00
|
|
|
float notificationAlpha;
|
2024-02-29 07:25:16 +00:00
|
|
|
float notificationAmt;
|
2021-03-30 07:38:25 +00:00
|
|
|
std::array<char, 256> notificationText;
|
2020-07-21 11:34:39 +00:00
|
|
|
|
2021-03-29 08:03:39 +00:00
|
|
|
std::vector<Triangle> tris;
|
|
|
|
std::array<glm::vec2, 3> currentTri;
|
2020-07-22 07:12:21 +00:00
|
|
|
CurrentState currentTri_state;
|
2021-03-29 08:03:39 +00:00
|
|
|
Circle pointCircle;
|
2020-07-22 06:11:10 +00:00
|
|
|
|
2024-01-23 05:53:47 +00:00
|
|
|
Color colorPickerColor;
|
|
|
|
Color bgColorPickerColor;
|
2021-03-29 08:03:39 +00:00
|
|
|
Color bgColor;
|
2020-07-22 07:26:57 +00:00
|
|
|
|
2021-03-30 03:51:46 +00:00
|
|
|
std::array<char, 256> saveFilenameBuffer;
|
2020-07-30 11:11:57 +00:00
|
|
|
std::string failedMessage;
|
2020-07-22 09:19:34 +00:00
|
|
|
|
2021-03-29 08:03:39 +00:00
|
|
|
RenderTexture2D drawCache;
|
2020-07-30 11:11:57 +00:00
|
|
|
|
2020-08-04 12:13:17 +00:00
|
|
|
const float pi;
|
|
|
|
|
|
|
|
unsigned int selectedTri;
|
2024-01-23 05:53:47 +00:00
|
|
|
Color selectedTriColor;
|
2020-08-04 12:13:17 +00:00
|
|
|
float selectedTriBlinkTimer;
|
|
|
|
|
2021-03-29 08:03:39 +00:00
|
|
|
int inputWidth;
|
|
|
|
int inputHeight;
|
|
|
|
|
2024-01-24 08:24:56 +00:00
|
|
|
std::vector<Action> history;
|
|
|
|
Action::IndexT history_idx;
|
|
|
|
|
2024-02-29 07:25:16 +00:00
|
|
|
float clickTimeout;
|
|
|
|
|
2020-07-22 06:19:37 +00:00
|
|
|
public:
|
2020-07-22 06:11:10 +00:00
|
|
|
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:
|
2021-03-29 08:03:39 +00:00
|
|
|
void draw_to_target(RenderTexture2D *target);
|
2020-07-22 09:19:34 +00:00
|
|
|
|
|
|
|
public:
|
2020-07-22 07:12:21 +00:00
|
|
|
unsigned int get_width() const;
|
|
|
|
unsigned int get_height() const;
|
2020-07-22 06:19:37 +00:00
|
|
|
|
|
|
|
const BitsetType get_flags() const;
|
2020-07-22 07:12:21 +00:00
|
|
|
|
2020-07-29 08:53:39 +00:00
|
|
|
float get_notification_alpha() const;
|
2024-02-29 07:25:16 +00:00
|
|
|
void reset_notification_alpha();
|
|
|
|
void clear_notification_alpha();
|
|
|
|
|
2020-07-29 08:53:39 +00:00
|
|
|
const char* get_notification_text() const;
|
2020-07-22 07:26:57 +00:00
|
|
|
|
2020-08-04 12:13:17 +00:00
|
|
|
private:
|
|
|
|
void set_notification_text(const char *text);
|
2021-03-30 07:38:25 +00:00
|
|
|
void append_notification_text(const char *text);
|
2020-08-04 12:13:17 +00:00
|
|
|
|
|
|
|
public:
|
2024-01-23 05:53:47 +00:00
|
|
|
Color& get_color();
|
|
|
|
Color& get_bg_color();
|
2020-07-22 09:19:34 +00:00
|
|
|
|
2021-03-30 03:51:46 +00:00
|
|
|
std::array<char, 256>* get_save_filename_buffer();
|
2020-07-22 09:19:34 +00:00
|
|
|
bool do_save();
|
2021-03-29 08:03:39 +00:00
|
|
|
const std::string& failed_message() const;
|
2020-07-22 09:19:34 +00:00
|
|
|
void close_save();
|
2020-07-22 10:03:33 +00:00
|
|
|
|
|
|
|
private:
|
2020-07-29 08:53:39 +00:00
|
|
|
bool can_draw() const;
|
2020-08-04 12:13:17 +00:00
|
|
|
void reset_modes();
|
2020-07-24 08:55:39 +00:00
|
|
|
|
|
|
|
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();
|
|
|
|
void close_input_width_height_window();
|
|
|
|
|
2020-08-04 12:13:17 +00:00
|
|
|
float get_pi() const;
|
|
|
|
|
2024-01-23 05:53:47 +00:00
|
|
|
Color& get_selected_tri_color();
|
2020-08-04 12:13:17 +00:00
|
|
|
void close_selected_tri_mode();
|
|
|
|
|
2021-03-29 08:03:39 +00:00
|
|
|
private:
|
|
|
|
bool check_draw_cache();
|
|
|
|
|
|
|
|
public:
|
|
|
|
int* get_input_width();
|
|
|
|
int* get_input_height();
|
|
|
|
|
2024-01-24 08:24:56 +00:00
|
|
|
private:
|
|
|
|
void restore_points_on_tri_del(Action::IndexT end);
|
2024-02-29 07:25:16 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
float get_click_timeout() const;
|
2020-07-21 11:34:39 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|