Compare commits
No commits in common. "b5efecd43d060136b5872821d18d6d9f5e430f12" and "b8d45212233ea396c3668092c8926e072bba9b7a" have entirely different histories.
b5efecd43d
...
b8d4521223
3 changed files with 17 additions and 85 deletions
|
@ -14,8 +14,6 @@
|
|||
#define SHOW_HELP_WIDTH (state->get_width() / 2.0f)
|
||||
#define SHOW_HELP_HEIGHT (state->get_height() / 2.0f)
|
||||
|
||||
#define NOTIFICATION_FADE_RATE 0.2F
|
||||
|
||||
#define DEFAULT_WIDTH 800
|
||||
#define DEFAULT_HEIGHT 600
|
||||
#define CHANGE_SIZE_MIN_X 800
|
||||
|
@ -23,12 +21,6 @@
|
|||
#define CHANGE_SIZE_MIN_Y 600
|
||||
#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
|
||||
# include <cstdio>
|
||||
#endif
|
||||
|
@ -276,8 +268,7 @@ namespace Tri {
|
|||
&alpha
|
||||
);
|
||||
color.a = alpha * 255.0F;
|
||||
if(GuiButton({504.0f, 308.0f, 234.0f, 16.0f}, "Close")
|
||||
&& state->get_click_timeout() == 0.0F) {
|
||||
if(GuiButton({504.0f, 308.0f, 234.0f, 16.0f}, "Close")) {
|
||||
state->close_selected_tri_mode();
|
||||
}
|
||||
} else {
|
||||
|
@ -300,11 +291,6 @@ namespace Tri {
|
|||
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
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
#include "helpers.hpp"
|
||||
|
||||
#define STARTING_HELP_FADE_RATE 0.2f
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||
Tri::State::State(int argc, char **argv) :
|
||||
|
@ -18,7 +20,6 @@ width(DEFAULT_WIDTH),
|
|||
height(DEFAULT_HEIGHT),
|
||||
dt(1.0f/60.0f),
|
||||
notificationAlpha(1.0f),
|
||||
notificationAmt(0.0F),
|
||||
notificationText(),
|
||||
tris(),
|
||||
currentTri(),
|
||||
|
@ -37,8 +38,7 @@ selectedTriBlinkTimer(),
|
|||
inputWidth(800),
|
||||
inputHeight(600),
|
||||
history(),
|
||||
history_idx(0),
|
||||
clickTimeout(0.0F)
|
||||
history_idx(0)
|
||||
{
|
||||
InitWindow(width, height, "Triangles");
|
||||
SetTargetFPS(60);
|
||||
|
@ -53,9 +53,7 @@ clickTimeout(0.0F)
|
|||
flags.set(F_DRAW_CACHE_INITIALIZED);
|
||||
flags.set(F_DRAW_CACHE_DIRTY);
|
||||
|
||||
GuiSetStyle(DEFAULT, BACKGROUND_COLOR, TRI_GUI_BG_COLOR);
|
||||
GuiSetStyle(DEFAULT, BASE_COLOR_NORMAL, TRI_GUI_BASE_COLOR);
|
||||
GuiSetStyle(DEFAULT, TEXT_COLOR_NORMAL, TRI_GUI_TEXT_COLOR);
|
||||
GuiSetStyle(DEFAULT, BACKGROUND_COLOR, 0x303030);
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
|
@ -123,10 +121,6 @@ void Tri::State::handle_events() {
|
|||
flags.flip(F_DISPLAY_HELP);
|
||||
break;
|
||||
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);
|
||||
if (history_idx > 0) {
|
||||
switch(history[history_idx-1].type) {
|
||||
|
@ -242,7 +236,7 @@ void Tri::State::handle_events() {
|
|||
"to what was\n"
|
||||
"clicked on");
|
||||
} else {
|
||||
clear_notification_alpha();
|
||||
notificationAlpha = 0.0f;
|
||||
}
|
||||
break;
|
||||
case KEY_I:
|
||||
|
@ -271,7 +265,7 @@ void Tri::State::handle_events() {
|
|||
keyPressed = GetKeyPressed();
|
||||
}
|
||||
|
||||
if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && clickTimeout == 0.0F) {
|
||||
if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) {
|
||||
if(can_draw()) {
|
||||
switch(currentTri_state) {
|
||||
case CurrentState::NONE: {
|
||||
|
@ -351,16 +345,14 @@ void Tri::State::handle_events() {
|
|||
if(my < 0) { my = 0; }
|
||||
else if(my >= (int)height) { my = height - 1; }
|
||||
|
||||
for (unsigned int i = 0; i < tris.size(); ++i) {
|
||||
if(is_within_shape(tris[i], {mx, my})) {
|
||||
tris[i].outlineColor = invert_color(tris[i].fillColor);
|
||||
for (auto &tri : tris) {
|
||||
if(is_within_shape(tri, {mx, my})) {
|
||||
tri.outlineColor = invert_color(tri.fillColor);
|
||||
flags.reset(F_SELECT_TRI_MODE);
|
||||
flags.set(F_TRI_EDIT_MODE);
|
||||
flags.set(F_TRI_EDIT_DRAW_TRI);
|
||||
selectedTriBlinkTimer = 1.0f;
|
||||
selectedTriColor = tris[i].fillColor;
|
||||
selectedTri = i;
|
||||
clickTimeout = CLICK_TIMEOUT_TIME;
|
||||
selectedTriColor = tri.fillColor;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -375,11 +367,9 @@ void Tri::State::update() {
|
|||
dt = GetFrameTime();
|
||||
|
||||
if(notificationAlpha > 0.0f) {
|
||||
notificationAmt += dt * NOTIFICATION_FADE_RATE;
|
||||
if (notificationAmt > 1.0F) {
|
||||
clear_notification_alpha();
|
||||
} else {
|
||||
notificationAlpha = Tri::sq_lerp(1.0F, 0.0F, notificationAmt);
|
||||
notificationAlpha -= dt * STARTING_HELP_FADE_RATE;
|
||||
if(notificationAlpha < 0.0f) {
|
||||
notificationAlpha = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -401,13 +391,6 @@ void Tri::State::update() {
|
|||
flags.flip(F_TRI_EDIT_DRAW_TRI);
|
||||
}
|
||||
}
|
||||
|
||||
if (clickTimeout > 0.0F) {
|
||||
clickTimeout -= dt;
|
||||
if (clickTimeout < 0.0F) {
|
||||
clickTimeout = 0.0F;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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)) {
|
||||
// tris.at(selectedTri).setOutlineThickness(4.0f);
|
||||
tris.at(selectedTri).draw();
|
||||
tris[selectedTri].draw();
|
||||
// tris.at(selectedTri).setOutlineThickness(0.0f);
|
||||
}
|
||||
|
||||
|
@ -493,16 +476,6 @@ float Tri::State::get_notification_alpha() const {
|
|||
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 {
|
||||
return notificationText.data();
|
||||
}
|
||||
|
@ -512,7 +485,7 @@ void Tri::State::set_notification_text(const char *text) {
|
|||
std::strncpy(notificationText.data(),
|
||||
text,
|
||||
notificationText.max_size() - 1);
|
||||
reset_notification_alpha();
|
||||
notificationAlpha = 1.0f;
|
||||
}
|
||||
|
||||
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,
|
||||
text,
|
||||
notificationText.max_size() - length - 1);
|
||||
reset_notification_alpha();
|
||||
notificationAlpha = 1.0f;
|
||||
}
|
||||
|
||||
Color& Tri::State::get_color() {
|
||||
|
@ -666,20 +639,6 @@ Color& Tri::State::get_selected_tri_color() {
|
|||
void Tri::State::close_selected_tri_mode() {
|
||||
tris.at(selectedTri).fillColor = selectedTriColor;
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -727,7 +686,3 @@ void Tri::State::restore_points_on_tri_del(Action::IndexT end) {
|
|||
assert(!"Unreachable code");
|
||||
return;
|
||||
}
|
||||
|
||||
float Tri::State::get_click_timeout() const {
|
||||
return clickTimeout;
|
||||
}
|
||||
|
|
|
@ -81,7 +81,6 @@ namespace Tri {
|
|||
unsigned int height;
|
||||
float dt;
|
||||
float notificationAlpha;
|
||||
float notificationAmt;
|
||||
std::array<char, 256> notificationText;
|
||||
|
||||
std::vector<Triangle> tris;
|
||||
|
@ -110,8 +109,6 @@ namespace Tri {
|
|||
std::vector<Action> history;
|
||||
Action::IndexT history_idx;
|
||||
|
||||
float clickTimeout;
|
||||
|
||||
public:
|
||||
void handle_events();
|
||||
void update();
|
||||
|
@ -127,9 +124,6 @@ namespace Tri {
|
|||
const BitsetType get_flags() const;
|
||||
|
||||
float get_notification_alpha() const;
|
||||
void reset_notification_alpha();
|
||||
void clear_notification_alpha();
|
||||
|
||||
const char* get_notification_text() const;
|
||||
|
||||
private:
|
||||
|
@ -171,9 +165,6 @@ namespace Tri {
|
|||
|
||||
private:
|
||||
void restore_points_on_tri_del(Action::IndexT end);
|
||||
|
||||
public:
|
||||
float get_click_timeout() const;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue