Compare commits

..

No commits in common. "b5efecd43d060136b5872821d18d6d9f5e430f12" and "b8d45212233ea396c3668092c8926e072bba9b7a" have entirely different histories.

3 changed files with 17 additions and 85 deletions

View file

@ -14,8 +14,6 @@
#define SHOW_HELP_WIDTH (state->get_width() / 2.0f) #define SHOW_HELP_WIDTH (state->get_width() / 2.0f)
#define SHOW_HELP_HEIGHT (state->get_height() / 2.0f) #define SHOW_HELP_HEIGHT (state->get_height() / 2.0f)
#define NOTIFICATION_FADE_RATE 0.2F
#define DEFAULT_WIDTH 800 #define DEFAULT_WIDTH 800
#define DEFAULT_HEIGHT 600 #define DEFAULT_HEIGHT 600
#define CHANGE_SIZE_MIN_X 800 #define CHANGE_SIZE_MIN_X 800
@ -23,12 +21,6 @@
#define CHANGE_SIZE_MIN_Y 600 #define CHANGE_SIZE_MIN_Y 600
#define CHANGE_SIZE_MAX_Y 1080 #define CHANGE_SIZE_MAX_Y 1080
#define TRI_GUI_BG_COLOR 0x505050FF
#define TRI_GUI_BASE_COLOR 0x404040FF
#define TRI_GUI_TEXT_COLOR 0xFFFFFFFF
#define CLICK_TIMEOUT_TIME 0.4F
#ifndef NDEBUG #ifndef NDEBUG
# include <cstdio> # include <cstdio>
#endif #endif
@ -276,8 +268,7 @@ namespace Tri {
&alpha &alpha
); );
color.a = alpha * 255.0F; color.a = alpha * 255.0F;
if(GuiButton({504.0f, 308.0f, 234.0f, 16.0f}, "Close") if(GuiButton({504.0f, 308.0f, 234.0f, 16.0f}, "Close")) {
&& state->get_click_timeout() == 0.0F) {
state->close_selected_tri_mode(); state->close_selected_tri_mode();
} }
} else { } else {
@ -300,11 +291,6 @@ namespace Tri {
tri[2] = t_a; tri[2] = t_a;
} }
} }
inline float sq_lerp(float start, float end, float amt) {
amt = amt * amt;
return start * (1.0F - amt) + end * amt;
}
} }
#endif #endif

View file

@ -10,6 +10,8 @@
#include "helpers.hpp" #include "helpers.hpp"
#define STARTING_HELP_FADE_RATE 0.2f
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter" #pragma GCC diagnostic ignored "-Wunused-parameter"
Tri::State::State(int argc, char **argv) : Tri::State::State(int argc, char **argv) :
@ -18,7 +20,6 @@ width(DEFAULT_WIDTH),
height(DEFAULT_HEIGHT), height(DEFAULT_HEIGHT),
dt(1.0f/60.0f), dt(1.0f/60.0f),
notificationAlpha(1.0f), notificationAlpha(1.0f),
notificationAmt(0.0F),
notificationText(), notificationText(),
tris(), tris(),
currentTri(), currentTri(),
@ -37,8 +38,7 @@ selectedTriBlinkTimer(),
inputWidth(800), inputWidth(800),
inputHeight(600), inputHeight(600),
history(), history(),
history_idx(0), history_idx(0)
clickTimeout(0.0F)
{ {
InitWindow(width, height, "Triangles"); InitWindow(width, height, "Triangles");
SetTargetFPS(60); SetTargetFPS(60);
@ -53,9 +53,7 @@ clickTimeout(0.0F)
flags.set(F_DRAW_CACHE_INITIALIZED); flags.set(F_DRAW_CACHE_INITIALIZED);
flags.set(F_DRAW_CACHE_DIRTY); flags.set(F_DRAW_CACHE_DIRTY);
GuiSetStyle(DEFAULT, BACKGROUND_COLOR, TRI_GUI_BG_COLOR); GuiSetStyle(DEFAULT, BACKGROUND_COLOR, 0x303030);
GuiSetStyle(DEFAULT, BASE_COLOR_NORMAL, TRI_GUI_BASE_COLOR);
GuiSetStyle(DEFAULT, TEXT_COLOR_NORMAL, TRI_GUI_TEXT_COLOR);
} }
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
@ -123,10 +121,6 @@ void Tri::State::handle_events() {
flags.flip(F_DISPLAY_HELP); flags.flip(F_DISPLAY_HELP);
break; break;
case KEY_U: case KEY_U:
if (flags.test(F_TRI_EDIT_MODE)) {
set_notification_text("Cannot undo during editing tri!");
break;
}
flags.set(F_DRAW_CACHE_DIRTY); flags.set(F_DRAW_CACHE_DIRTY);
if (history_idx > 0) { if (history_idx > 0) {
switch(history[history_idx-1].type) { switch(history[history_idx-1].type) {
@ -242,7 +236,7 @@ void Tri::State::handle_events() {
"to what was\n" "to what was\n"
"clicked on"); "clicked on");
} else { } else {
clear_notification_alpha(); notificationAlpha = 0.0f;
} }
break; break;
case KEY_I: case KEY_I:
@ -271,7 +265,7 @@ void Tri::State::handle_events() {
keyPressed = GetKeyPressed(); keyPressed = GetKeyPressed();
} }
if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && clickTimeout == 0.0F) { if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) {
if(can_draw()) { if(can_draw()) {
switch(currentTri_state) { switch(currentTri_state) {
case CurrentState::NONE: { case CurrentState::NONE: {
@ -351,16 +345,14 @@ void Tri::State::handle_events() {
if(my < 0) { my = 0; } if(my < 0) { my = 0; }
else if(my >= (int)height) { my = height - 1; } else if(my >= (int)height) { my = height - 1; }
for (unsigned int i = 0; i < tris.size(); ++i) { for (auto &tri : tris) {
if(is_within_shape(tris[i], {mx, my})) { if(is_within_shape(tri, {mx, my})) {
tris[i].outlineColor = invert_color(tris[i].fillColor); tri.outlineColor = invert_color(tri.fillColor);
flags.reset(F_SELECT_TRI_MODE); flags.reset(F_SELECT_TRI_MODE);
flags.set(F_TRI_EDIT_MODE); flags.set(F_TRI_EDIT_MODE);
flags.set(F_TRI_EDIT_DRAW_TRI); flags.set(F_TRI_EDIT_DRAW_TRI);
selectedTriBlinkTimer = 1.0f; selectedTriBlinkTimer = 1.0f;
selectedTriColor = tris[i].fillColor; selectedTriColor = tri.fillColor;
selectedTri = i;
clickTimeout = CLICK_TIMEOUT_TIME;
break; break;
} }
} }
@ -375,11 +367,9 @@ void Tri::State::update() {
dt = GetFrameTime(); dt = GetFrameTime();
if(notificationAlpha > 0.0f) { if(notificationAlpha > 0.0f) {
notificationAmt += dt * NOTIFICATION_FADE_RATE; notificationAlpha -= dt * STARTING_HELP_FADE_RATE;
if (notificationAmt > 1.0F) { if(notificationAlpha < 0.0f) {
clear_notification_alpha(); notificationAlpha = 0.0f;
} else {
notificationAlpha = Tri::sq_lerp(1.0F, 0.0F, notificationAmt);
} }
} }
@ -401,13 +391,6 @@ void Tri::State::update() {
flags.flip(F_TRI_EDIT_DRAW_TRI); flags.flip(F_TRI_EDIT_DRAW_TRI);
} }
} }
if (clickTimeout > 0.0F) {
clickTimeout -= dt;
if (clickTimeout < 0.0F) {
clickTimeout = 0.0F;
}
}
} }
void Tri::State::draw() { void Tri::State::draw() {
@ -435,7 +418,7 @@ void Tri::State::draw() {
if(flags.test(F_TRI_EDIT_MODE) && flags.test(F_TRI_EDIT_DRAW_TRI)) { if(flags.test(F_TRI_EDIT_MODE) && flags.test(F_TRI_EDIT_DRAW_TRI)) {
// tris.at(selectedTri).setOutlineThickness(4.0f); // tris.at(selectedTri).setOutlineThickness(4.0f);
tris.at(selectedTri).draw(); tris[selectedTri].draw();
// tris.at(selectedTri).setOutlineThickness(0.0f); // tris.at(selectedTri).setOutlineThickness(0.0f);
} }
@ -493,16 +476,6 @@ float Tri::State::get_notification_alpha() const {
return notificationAlpha; return notificationAlpha;
} }
void Tri::State::reset_notification_alpha() {
notificationAlpha = 1.0F;
notificationAmt = 0.0F;
}
void Tri::State::clear_notification_alpha() {
notificationAlpha = 0.0F;
notificationAmt = 1.0F;
}
const char* Tri::State::get_notification_text() const { const char* Tri::State::get_notification_text() const {
return notificationText.data(); return notificationText.data();
} }
@ -512,7 +485,7 @@ void Tri::State::set_notification_text(const char *text) {
std::strncpy(notificationText.data(), std::strncpy(notificationText.data(),
text, text,
notificationText.max_size() - 1); notificationText.max_size() - 1);
reset_notification_alpha(); notificationAlpha = 1.0f;
} }
void Tri::State::append_notification_text(const char *text) { void Tri::State::append_notification_text(const char *text) {
@ -524,7 +497,7 @@ void Tri::State::append_notification_text(const char *text) {
notificationText.data() + length, notificationText.data() + length,
text, text,
notificationText.max_size() - length - 1); notificationText.max_size() - length - 1);
reset_notification_alpha(); notificationAlpha = 1.0f;
} }
Color& Tri::State::get_color() { Color& Tri::State::get_color() {
@ -666,20 +639,6 @@ Color& Tri::State::get_selected_tri_color() {
void Tri::State::close_selected_tri_mode() { void Tri::State::close_selected_tri_mode() {
tris.at(selectedTri).fillColor = selectedTriColor; tris.at(selectedTri).fillColor = selectedTriColor;
flags.set(F_DRAW_CACHE_DIRTY); flags.set(F_DRAW_CACHE_DIRTY);
// Set tri's new color in history.
for (auto &action : history) {
if (action.type == Action::AT_TRI
&& tris.at(selectedTri).vertices.at(0).x == action.data.tri[0]
&& tris.at(selectedTri).vertices.at(0).y == action.data.tri[1]
&& tris.at(selectedTri).vertices.at(1).x == action.data.tri[2]
&& tris.at(selectedTri).vertices.at(1).y == action.data.tri[3]
&& tris.at(selectedTri).vertices.at(2).x == action.data.tri[4]
&& tris.at(selectedTri).vertices.at(2).y == action.data.tri[5]) {
action.color = selectedTriColor;
break;
}
}
reset_modes(); reset_modes();
} }
@ -727,7 +686,3 @@ void Tri::State::restore_points_on_tri_del(Action::IndexT end) {
assert(!"Unreachable code"); assert(!"Unreachable code");
return; return;
} }
float Tri::State::get_click_timeout() const {
return clickTimeout;
}

View file

@ -81,7 +81,6 @@ namespace Tri {
unsigned int height; unsigned int height;
float dt; float dt;
float notificationAlpha; float notificationAlpha;
float notificationAmt;
std::array<char, 256> notificationText; std::array<char, 256> notificationText;
std::vector<Triangle> tris; std::vector<Triangle> tris;
@ -110,8 +109,6 @@ namespace Tri {
std::vector<Action> history; std::vector<Action> history;
Action::IndexT history_idx; Action::IndexT history_idx;
float clickTimeout;
public: public:
void handle_events(); void handle_events();
void update(); void update();
@ -127,9 +124,6 @@ namespace Tri {
const BitsetType get_flags() const; const BitsetType get_flags() const;
float get_notification_alpha() const; float get_notification_alpha() const;
void reset_notification_alpha();
void clear_notification_alpha();
const char* get_notification_text() const; const char* get_notification_text() const;
private: private:
@ -171,9 +165,6 @@ namespace Tri {
private: private:
void restore_points_on_tri_del(Action::IndexT end); void restore_points_on_tri_del(Action::IndexT end);
public:
float get_click_timeout() const;
}; };
} }