Compare commits
No commits in common. "25dafb26b54c0738cabb0be8c642c04f6ba79f99" and "1da2ddb1250ce045925788c3a00a9c30773c38ea" have entirely different histories.
25dafb26b5
...
1da2ddb125
5 changed files with 78 additions and 339 deletions
|
@ -26,7 +26,6 @@ set(Triangles_LIB_SOURCES
|
||||||
src/triangle.cpp
|
src/triangle.cpp
|
||||||
src/circle.cpp
|
src/circle.cpp
|
||||||
src/raygui.cpp
|
src/raygui.cpp
|
||||||
src/helpers.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(TrianglesLib STATIC ${Triangles_LIB_SOURCES})
|
add_library(TrianglesLib STATIC ${Triangles_LIB_SOURCES})
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
#include "helpers.hpp"
|
|
||||||
|
|
||||||
bool operator==(const Color& a, const Color& b) {
|
|
||||||
return a.r == b.r
|
|
||||||
&& a.g == b.g
|
|
||||||
&& a.b == b.b
|
|
||||||
&& a.a == b.a;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator!=(const Color& a, const Color& b) {
|
|
||||||
return !(a == b);
|
|
||||||
}
|
|
|
@ -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,15 +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;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Color operator helpers
|
|
||||||
bool operator==(const Color& a, const Color& b);
|
|
||||||
bool operator!=(const Color& a, const Color& b);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
330
src/state.cpp
330
src/state.cpp
|
@ -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,12 +20,13 @@ 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(),
|
||||||
|
trisIndex(0),
|
||||||
currentTri(),
|
currentTri(),
|
||||||
currentTri_state(CurrentState::NONE),
|
currentTri_state(CurrentState::NONE),
|
||||||
pointCircle({7.0F, 7.0F}, 7.0F, WHITE),
|
currentTri_maxState(CurrentState::NONE),
|
||||||
|
pointCircle(),
|
||||||
colorPickerColor{255, 255, 255, 255},
|
colorPickerColor{255, 255, 255, 255},
|
||||||
bgColorPickerColor{0, 0, 0, 255},
|
bgColorPickerColor{0, 0, 0, 255},
|
||||||
bgColor(BLACK),
|
bgColor(BLACK),
|
||||||
|
@ -33,13 +36,9 @@ drawCache(),
|
||||||
pi(std::acos(-1.0f)),
|
pi(std::acos(-1.0f)),
|
||||||
selectedTri(),
|
selectedTri(),
|
||||||
selectedTriColor{255, 255, 255, 255},
|
selectedTriColor{255, 255, 255, 255},
|
||||||
prevTriColor{255, 255, 255, 255},
|
|
||||||
selectedTriBlinkTimer(),
|
selectedTriBlinkTimer(),
|
||||||
inputWidth(800),
|
inputWidth(800),
|
||||||
inputHeight(600),
|
inputHeight(600)
|
||||||
history(),
|
|
||||||
history_idx(0),
|
|
||||||
clickTimeout(0.0F)
|
|
||||||
{
|
{
|
||||||
InitWindow(width, height, "Triangles");
|
InitWindow(width, height, "Triangles");
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
|
@ -48,71 +47,21 @@ clickTimeout(0.0F)
|
||||||
|
|
||||||
set_notification_text("Press \"H\" for help");
|
set_notification_text("Press \"H\" for help");
|
||||||
|
|
||||||
|
pointCircle.setRadius(7.0f);
|
||||||
|
pointCircle.translate({7.0f, 7.0f});
|
||||||
|
pointCircle.fillColor = WHITE;
|
||||||
|
pointCircle.outlineColor = BLACK;
|
||||||
|
|
||||||
saveFilenameBuffer.fill(0);
|
saveFilenameBuffer.fill(0);
|
||||||
|
|
||||||
drawCache = LoadRenderTexture(width, height);
|
drawCache = LoadRenderTexture(width, height);
|
||||||
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
|
||||||
|
|
||||||
Tri::State::Action::Action() :
|
|
||||||
type(Tri::State::Action::AT_NONE),
|
|
||||||
idx(0),
|
|
||||||
color(BLACK),
|
|
||||||
data{{0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}}
|
|
||||||
{}
|
|
||||||
|
|
||||||
Tri::State::Action::Action(const Type& type, IndexT idx, const Color& color, float *data) :
|
|
||||||
type(type),
|
|
||||||
idx(idx),
|
|
||||||
color(color),
|
|
||||||
data()
|
|
||||||
{
|
|
||||||
init(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
Tri::State::Action::Action(Type&& type, IndexT idx, Color&& color, float *data) :
|
|
||||||
type(type),
|
|
||||||
idx(idx),
|
|
||||||
color(color),
|
|
||||||
data()
|
|
||||||
{
|
|
||||||
init(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
Tri::State::Action &Tri::State::Action::setNewColor(Color color) {
|
|
||||||
this->data.newColor = color;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Tri::State::Action::init(float *data) {
|
|
||||||
switch(type) {
|
|
||||||
case AT_TRI:
|
|
||||||
case AT_TRI_DEL:
|
|
||||||
for(unsigned int i = 0; i < 6; ++i) {
|
|
||||||
this->data.tri[i] = data[i];
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case AT_POINT:
|
|
||||||
this->data.point[0] = data[0];
|
|
||||||
this->data.point[1] = data[1];
|
|
||||||
break;
|
|
||||||
case AT_COLOR:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
type = AT_NONE;
|
|
||||||
idx = 0;
|
|
||||||
color = BLACK;
|
|
||||||
this->data = {{0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}};
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Tri::State::~State() {
|
Tri::State::~State() {
|
||||||
UnloadRenderTexture(drawCache);
|
UnloadRenderTexture(drawCache);
|
||||||
CloseWindow();
|
CloseWindow();
|
||||||
|
@ -131,102 +80,52 @@ 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(currentTri_state > 0) {
|
||||||
switch(history[history_idx-1].type) {
|
switch(currentTri_state) {
|
||||||
case Action::AT_TRI:
|
case FIRST:
|
||||||
tris.erase(
|
|
||||||
tris.cbegin() + history[history_idx-1].idx);
|
|
||||||
restore_points_on_tri_del(history_idx - 1);
|
|
||||||
break;
|
|
||||||
case Action::AT_TRI_DEL:
|
|
||||||
{
|
|
||||||
tris.emplace(
|
|
||||||
tris.cbegin() + history[history_idx].idx,
|
|
||||||
Triangle(
|
|
||||||
{{
|
|
||||||
{history[history_idx-1].data.tri[0],
|
|
||||||
history[history_idx-1].data.tri[1]},
|
|
||||||
{history[history_idx-1].data.tri[2],
|
|
||||||
history[history_idx-1].data.tri[3]},
|
|
||||||
{history[history_idx-1].data.tri[4],
|
|
||||||
history[history_idx-1].data.tri[5]},
|
|
||||||
}},
|
|
||||||
history[history_idx-1].color
|
|
||||||
)
|
|
||||||
);
|
|
||||||
currentTri_state = CurrentState::NONE;
|
currentTri_state = CurrentState::NONE;
|
||||||
break;
|
break;
|
||||||
}
|
case SECOND:
|
||||||
case Action::AT_POINT:
|
currentTri_state = CurrentState::FIRST;
|
||||||
assert(history[history_idx-1].idx + 1 == currentTri_state
|
|
||||||
&& "Point in history must match point index");
|
|
||||||
assert(currentTri_state > 0
|
|
||||||
&& "There must be a point to undo a point");
|
|
||||||
currentTri_state = static_cast<CurrentState>(currentTri_state - 1);
|
|
||||||
break;
|
|
||||||
case Action::AT_COLOR:
|
|
||||||
tris.at(history[history_idx-1].idx).fillColor = history[history_idx-1].color;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(!"Unreachable code");
|
assert(!"Unreachable code");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
--history_idx;
|
} else if(trisIndex > 0) {
|
||||||
|
--trisIndex;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case KEY_R:
|
case KEY_R:
|
||||||
flags.set(F_DRAW_CACHE_DIRTY);
|
flags.set(F_DRAW_CACHE_DIRTY);
|
||||||
if(history_idx < history.size()) {
|
if(currentTri_state != CurrentState::NONE
|
||||||
switch(history[history_idx].type) {
|
&& currentTri_state < currentTri_maxState) {
|
||||||
case Action::AT_TRI:
|
switch(currentTri_state) {
|
||||||
{
|
case NONE:
|
||||||
tris.emplace(
|
currentTri_state = CurrentState::FIRST;
|
||||||
tris.cbegin() + history[history_idx].idx,
|
|
||||||
Triangle(
|
|
||||||
{{
|
|
||||||
{history[history_idx].data.tri[0],
|
|
||||||
history[history_idx].data.tri[1]},
|
|
||||||
{history[history_idx].data.tri[2],
|
|
||||||
history[history_idx].data.tri[3]},
|
|
||||||
{history[history_idx].data.tri[4],
|
|
||||||
history[history_idx].data.tri[5]},
|
|
||||||
}},
|
|
||||||
history[history_idx].color
|
|
||||||
)
|
|
||||||
);
|
|
||||||
currentTri_state = CurrentState::NONE;
|
|
||||||
break;
|
break;
|
||||||
}
|
case FIRST:
|
||||||
break;
|
currentTri_state = CurrentState::SECOND;
|
||||||
case Action::AT_TRI_DEL:
|
break;
|
||||||
tris.erase(
|
default:
|
||||||
tris.cbegin() + history[history_idx].idx);
|
assert(!"Unreachable code");
|
||||||
restore_points_on_tri_del(history_idx);
|
break;
|
||||||
break;
|
}
|
||||||
case Action::AT_POINT:
|
} else if(tris.size() > trisIndex) {
|
||||||
assert(history[history_idx].idx == currentTri_state
|
++trisIndex;
|
||||||
&& "Point in history must match point index");
|
} else if(currentTri_state < currentTri_maxState) {
|
||||||
assert(currentTri_state < CurrentState::SECOND
|
switch(currentTri_state) {
|
||||||
&& "Current point state must be 0 or 1");
|
case NONE:
|
||||||
currentTri[currentTri_state].x = history[history_idx].data.point[0];
|
currentTri_state = CurrentState::FIRST;
|
||||||
currentTri[currentTri_state].y = history[history_idx].data.point[1];
|
break;
|
||||||
currentTri_state = static_cast<CurrentState>(
|
case FIRST:
|
||||||
currentTri_state + 1);
|
currentTri_state = CurrentState::SECOND;
|
||||||
pointCircle.fillColor = history[history_idx].color;
|
|
||||||
break;
|
|
||||||
case Action::AT_COLOR:
|
|
||||||
tris.at(history[history_idx].idx).fillColor = history[history_idx].data.newColor;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(!"Unreachable code");
|
assert(!"Unreachable code");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
++history_idx;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case KEY_C:
|
case KEY_C:
|
||||||
|
@ -256,7 +155,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:
|
||||||
|
@ -285,56 +184,37 @@ 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:
|
||||||
currentTri[0] = {GetMouseX(), GetMouseY()};
|
currentTri[0] = {GetMouseX(), GetMouseY()};
|
||||||
|
if(trisIndex < tris.size()) {
|
||||||
|
tris.resize(trisIndex);
|
||||||
|
}
|
||||||
currentTri_state = CurrentState::FIRST;
|
currentTri_state = CurrentState::FIRST;
|
||||||
if(history_idx < history.size()) {
|
currentTri_maxState = CurrentState::FIRST;
|
||||||
history.resize(history_idx);
|
break;
|
||||||
}
|
case CurrentState::FIRST:
|
||||||
float points[2] = {currentTri[0].x, currentTri[0].y};
|
|
||||||
history.push_back(Action(Action::AT_POINT,
|
|
||||||
0,
|
|
||||||
pointCircle.fillColor,
|
|
||||||
points));
|
|
||||||
++history_idx;
|
|
||||||
break; }
|
|
||||||
case CurrentState::FIRST: {
|
|
||||||
currentTri[1] = {GetMouseX(), GetMouseY()};
|
currentTri[1] = {GetMouseX(), GetMouseY()};
|
||||||
currentTri_state = CurrentState::SECOND;
|
if(trisIndex < tris.size()) {
|
||||||
if(history_idx < history.size()) {
|
tris.resize(trisIndex);
|
||||||
history.resize(history_idx);
|
|
||||||
}
|
}
|
||||||
float points[2] = {currentTri[1].x, currentTri[1].y};
|
currentTri_state = CurrentState::SECOND;
|
||||||
history.push_back(Action(Action::AT_POINT,
|
currentTri_maxState = CurrentState::SECOND;
|
||||||
1,
|
break;
|
||||||
pointCircle.fillColor,
|
case CurrentState::SECOND:
|
||||||
points));
|
|
||||||
++history_idx;
|
|
||||||
break; }
|
|
||||||
case CurrentState::SECOND: {
|
|
||||||
currentTri[2] = {GetMouseX(), GetMouseY()};
|
currentTri[2] = {GetMouseX(), GetMouseY()};
|
||||||
|
if(trisIndex < tris.size()) {
|
||||||
|
tris.resize(trisIndex);
|
||||||
|
}
|
||||||
|
++trisIndex;
|
||||||
make_counter_clockwise(currentTri);
|
make_counter_clockwise(currentTri);
|
||||||
tris.emplace_back(currentTri, pointCircle.fillColor);
|
tris.emplace_back(currentTri, pointCircle.fillColor);
|
||||||
currentTri_state = CurrentState::NONE;
|
currentTri_state = CurrentState::NONE;
|
||||||
|
currentTri_maxState = CurrentState::NONE;
|
||||||
flags.set(F_DRAW_CACHE_DIRTY);
|
flags.set(F_DRAW_CACHE_DIRTY);
|
||||||
|
break;
|
||||||
if(history_idx < history.size()) {
|
|
||||||
history.resize(history_idx);
|
|
||||||
}
|
|
||||||
float points[6] = {
|
|
||||||
currentTri[0].x, currentTri[0].y,
|
|
||||||
currentTri[1].x, currentTri[1].y,
|
|
||||||
currentTri[2].x, currentTri[2].y,
|
|
||||||
};
|
|
||||||
history.push_back(Action(Action::AT_TRI,
|
|
||||||
tris.size()-1,
|
|
||||||
pointCircle.fillColor,
|
|
||||||
points));
|
|
||||||
++history_idx;
|
|
||||||
break; }
|
|
||||||
}
|
}
|
||||||
} else if(flags.test(F_COPY_COLOR_MODE)) {
|
} else if(flags.test(F_COPY_COLOR_MODE)) {
|
||||||
check_draw_cache();
|
check_draw_cache();
|
||||||
|
@ -365,17 +245,15 @@ 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(unsigned int i = trisIndex; i-- > 0; ) {
|
||||||
if(is_within_shape(tris[i], {mx, my})) {
|
if(is_within_shape(tris.at(i), {mx, my})) {
|
||||||
|
selectedTri = i;
|
||||||
tris[i].outlineColor = invert_color(tris[i].fillColor);
|
tris[i].outlineColor = invert_color(tris[i].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 = tris[i].fillColor;
|
||||||
prevTriColor = tris[i].fillColor;
|
|
||||||
selectedTri = i;
|
|
||||||
clickTimeout = CLICK_TIMEOUT_TIME;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -390,11 +268,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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -416,13 +292,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() {
|
||||||
|
@ -450,13 +319,15 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(can_draw()) {
|
if(can_draw()) {
|
||||||
for(unsigned int i = 0; i < currentTri_state; ++i) {
|
for(unsigned int i = 0; i < currentTri_state; ++i) {
|
||||||
DrawCircle(currentTri[i].x, currentTri[i].y, pointCircle.getRadius(), pointCircle.fillColor);
|
pointCircle.resetTransform();
|
||||||
|
pointCircle.translate(currentTri[i]);
|
||||||
|
pointCircle.draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -477,7 +348,7 @@ void Tri::State::draw_to_target(RenderTexture2D *target) {
|
||||||
ClearBackground(bgColor);
|
ClearBackground(bgColor);
|
||||||
|
|
||||||
// draw tris
|
// draw tris
|
||||||
for(unsigned int i = 0; i < tris.size(); ++i) {
|
for(unsigned int i = 0; i < trisIndex; ++i) {
|
||||||
tris[i].draw();
|
tris[i].draw();
|
||||||
}
|
}
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
|
@ -486,7 +357,7 @@ void Tri::State::draw_to_target(RenderTexture2D *target) {
|
||||||
ClearBackground(bgColor);
|
ClearBackground(bgColor);
|
||||||
|
|
||||||
// draw tris
|
// draw tris
|
||||||
for(unsigned int i = 0; i < tris.size(); ++i) {
|
for(unsigned int i = 0; i < trisIndex; ++i) {
|
||||||
tris[i].draw();
|
tris[i].draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -508,16 +379,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();
|
||||||
}
|
}
|
||||||
|
@ -527,7 +388,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) {
|
||||||
|
@ -539,7 +400,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() {
|
||||||
|
@ -679,19 +540,8 @@ Color& Tri::State::get_selected_tri_color() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tri::State::close_selected_tri_mode() {
|
void Tri::State::close_selected_tri_mode() {
|
||||||
// Set tri's new color in history.
|
|
||||||
if (prevTriColor != selectedTriColor) {
|
|
||||||
if (history_idx < history.size()) {
|
|
||||||
history.resize(history_idx);
|
|
||||||
}
|
|
||||||
history.emplace_back(Action::AT_COLOR, selectedTri, prevTriColor, nullptr);
|
|
||||||
history.back().setNewColor(selectedTriColor);
|
|
||||||
++history_idx;
|
|
||||||
}
|
|
||||||
|
|
||||||
tris.at(selectedTri).fillColor = selectedTriColor;
|
tris.at(selectedTri).fillColor = selectedTriColor;
|
||||||
flags.set(F_DRAW_CACHE_DIRTY);
|
flags.set(F_DRAW_CACHE_DIRTY);
|
||||||
|
|
||||||
reset_modes();
|
reset_modes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -713,33 +563,3 @@ int* Tri::State::get_input_width() {
|
||||||
int* Tri::State::get_input_height() {
|
int* Tri::State::get_input_height() {
|
||||||
return &inputHeight;
|
return &inputHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tri::State::restore_points_on_tri_del(Action::IndexT end) {
|
|
||||||
assert(end < history.size()
|
|
||||||
&& "Index on history must be in range");
|
|
||||||
currentTri[2].x = history[end].data.tri[4];
|
|
||||||
currentTri[2].y = history[end].data.tri[5];
|
|
||||||
pointCircle.fillColor = history[end].color;
|
|
||||||
unsigned int currentTriIdx = 1;
|
|
||||||
while(end-- > 0) {
|
|
||||||
assert(history[end].type == Action::AT_POINT
|
|
||||||
&& "Latest history must be AT_POINT type");
|
|
||||||
assert(history[end].idx == currentTriIdx
|
|
||||||
&& "Last point must be second point");
|
|
||||||
currentTri[currentTriIdx].x = history[end].data.point[0];
|
|
||||||
currentTri[currentTriIdx].y = history[end].data.point[1];
|
|
||||||
if(currentTriIdx > 0) {
|
|
||||||
--currentTriIdx;
|
|
||||||
} else {
|
|
||||||
currentTri_state = CurrentState::SECOND;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(!"Unreachable code");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
float Tri::State::get_click_timeout() const {
|
|
||||||
return clickTimeout;
|
|
||||||
}
|
|
||||||
|
|
|
@ -41,43 +41,6 @@ namespace Tri {
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Action {
|
|
||||||
public:
|
|
||||||
typedef std::vector<Action>::size_type IndexT;
|
|
||||||
|
|
||||||
enum Type {
|
|
||||||
AT_TRI,
|
|
||||||
AT_TRI_DEL,
|
|
||||||
AT_POINT,
|
|
||||||
AT_COLOR,
|
|
||||||
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];
|
|
||||||
Color newColor;
|
|
||||||
} data;
|
|
||||||
|
|
||||||
Action &setNewColor(Color color);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void init(float *data);
|
|
||||||
};
|
|
||||||
|
|
||||||
// use enum FlagName
|
// use enum FlagName
|
||||||
typedef std::bitset<64> BitsetType;
|
typedef std::bitset<64> BitsetType;
|
||||||
BitsetType flags;
|
BitsetType flags;
|
||||||
|
@ -85,12 +48,13 @@ 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;
|
||||||
|
unsigned int trisIndex;
|
||||||
std::array<glm::vec2, 3> currentTri;
|
std::array<glm::vec2, 3> currentTri;
|
||||||
CurrentState currentTri_state;
|
CurrentState currentTri_state;
|
||||||
|
CurrentState currentTri_maxState;
|
||||||
Circle pointCircle;
|
Circle pointCircle;
|
||||||
|
|
||||||
Color colorPickerColor;
|
Color colorPickerColor;
|
||||||
|
@ -106,17 +70,11 @@ namespace Tri {
|
||||||
|
|
||||||
unsigned int selectedTri;
|
unsigned int selectedTri;
|
||||||
Color selectedTriColor;
|
Color selectedTriColor;
|
||||||
Color prevTriColor;
|
|
||||||
float selectedTriBlinkTimer;
|
float selectedTriBlinkTimer;
|
||||||
|
|
||||||
int inputWidth;
|
int inputWidth;
|
||||||
int inputHeight;
|
int inputHeight;
|
||||||
|
|
||||||
std::vector<Action> history;
|
|
||||||
Action::IndexT history_idx;
|
|
||||||
|
|
||||||
float clickTimeout;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void handle_events();
|
void handle_events();
|
||||||
void update();
|
void update();
|
||||||
|
@ -132,9 +90,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:
|
||||||
|
@ -174,11 +129,6 @@ namespace Tri {
|
||||||
int* get_input_width();
|
int* get_input_width();
|
||||||
int* get_input_height();
|
int* get_input_height();
|
||||||
|
|
||||||
private:
|
|
||||||
void restore_points_on_tri_del(Action::IndexT end);
|
|
||||||
|
|
||||||
public:
|
|
||||||
float get_click_timeout() const;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue