Compare commits

..

No commits in common. "20859dbcd8ba1b4b14670207ee8d30e5a53dbc78" and "9fb86c4cf8bf068edc9c12294efa7902cfafcdfc" have entirely different histories.

6 changed files with 86 additions and 57 deletions

View file

@ -30,7 +30,7 @@ namespace Tri {
// so this should be called during update, not draw
inline void draw_help(Tri::State *state) {
if(state->get_flags().test(Tri::State::F_DISPLAY_HELP)) {
GuiSetAlpha(1.0f);
GuiFade(1.0f);
if(!GuiWindowBox({10.0f,
10.0f,
800.0f - 20.0f,
@ -81,7 +81,7 @@ namespace Tri {
inline void draw_notification(Tri::State *state) {
float alpha = state->get_notification_alpha();
if(alpha > 0.0f) {
GuiSetAlpha(alpha);
GuiFade(alpha);
GuiPanel({(800 - SHOW_HELP_WIDTH) / 2.0f,
(600 - SHOW_HELP_HEIGHT) / 2.0f,
SHOW_HELP_WIDTH,
@ -96,21 +96,23 @@ namespace Tri {
inline void draw_color_picker(Tri::State *state) {
if(state->get_flags().test(Tri::State::F_DISPLAY_COLOR_P)) {
GuiSetAlpha(1.0f);
if(!GuiWindowBox({4.0f, 4.0f, 242.0f, 328.0f}, "Tri Color Picker")) {
auto &color = state->get_color();
GuiColorPicker(
GuiFade(1.0f);
if(!GuiWindowBox({4.0f, 4.0f, 242.0f, 292.0f}, "Tri Color Picker")) {
auto &colorArray = state->get_color();
Color color = GuiColorPicker(
{8.0f, 32.0f, 206.0f, 240.0f},
nullptr,
&color);
float alpha = ((float)color.a) / 255.0F;
GuiColorBarAlpha(
{8.0F, 280.0F, 206.0F, 20.0F},
nullptr,
&alpha
);
color.a = alpha * 255.0F;
if(GuiButton({8.0f, 308.0f, 234.0f, 16.0f}, "Close")) {
{(unsigned char)(colorArray[0] * 255.0f),
(unsigned char)(colorArray[1] * 255.0f),
(unsigned char)(colorArray[2] * 255.0f),
(unsigned char)(colorArray[3] * 255.0f)});
colorArray = {
color.r / 255.0f,
color.g / 255.0f,
color.b / 255.0f,
color.a / 255.0f
};
if(GuiButton({8.0f, 272.0f, 234.0f, 16.0f}, "Close")) {
state->close_color_picker();
}
} else {
@ -121,14 +123,22 @@ namespace Tri {
inline void draw_bg_color_picker(Tri::State *state) {
if(state->get_flags().test(Tri::State::F_DISPLAY_BG_COLOR_P)) {
GuiSetAlpha(1.0f);
GuiFade(1.0f);
if(!GuiWindowBox({250.0f, 4.0f, 242.0f, 292.0f}, "BG Color Picker")) {
auto &colorArray = state->get_bg_color();
GuiColorPicker(
Color color = GuiColorPicker(
{254.0f, 32.0f, 206.0f, 240.0f},
nullptr,
&colorArray);
if(GuiButton({254.0f, 274.0f, 234.0f, 16.0f}, "Close")) {
{(unsigned char)(colorArray[0] * 255.0f),
(unsigned char)(colorArray[1] * 255.0f),
(unsigned char)(colorArray[2] * 255.0f),
255});
colorArray = {
color.r / 255.0f,
color.g / 255.0f,
color.b / 255.0f
};
if(GuiButton({254.0f, 272.0f, 234.0f, 16.0f}, "Close")) {
state->close_bg_color_picker();
}
} else {
@ -140,7 +150,7 @@ namespace Tri {
inline void draw_save(Tri::State *state) {
if(state->get_flags().test(Tri::State::F_DISPLAY_SAVE)) {
auto *filenameBuffer = state->get_save_filename_buffer();
GuiSetAlpha(1.0f);
GuiFade(1.0f);
if(!GuiWindowBox({4.0f, 300.0f, 292.0f, 292.0f}, "Save")) {
GuiTextBox(
{8.0f, 328.0f, 284.0f, 20.0f},
@ -164,7 +174,7 @@ namespace Tri {
inline void draw_change_size(Tri::State *state) {
if(state->get_flags().test(Tri::State::F_DISPLAY_CHANGE_SIZE)) {
GuiSetAlpha(1.0f);
GuiFade(1.0f);
if(!GuiWindowBox({300.0f, 300.0f, 292.0f, 292.0f}, "Change Size")) {
GuiValueBox(
{384.0f, 328.0f, 80.0f, 16.0f},
@ -254,21 +264,23 @@ namespace Tri {
inline void draw_edit_tri(Tri::State *state) {
if(state->get_flags().test(Tri::State::F_TRI_EDIT_MODE)) {
GuiSetAlpha(1.0f);
if(!GuiWindowBox({500.0f, 4.0f, 242.0f, 328.0f}, "Edit Tri Color Picker")) {
auto &color = state->get_selected_tri_color();
GuiColorPicker(
GuiFade(1.0f);
if(!GuiWindowBox({500.0f, 4.0f, 242.0f, 292.0f}, "Edit Tri Color Picker")) {
auto &colorArray = state->get_selected_tri_color();
Color color = GuiColorPicker(
{504.0f, 32.0f, 206.0f, 240.0f},
nullptr,
&color);
float alpha = ((float)color.a) / 255.0F;
GuiColorBarAlpha(
{504.0F, 280.0F, 206.0F, 20.0F},
nullptr,
&alpha
);
color.a = alpha * 255.0F;
if(GuiButton({504.0f, 308.0f, 234.0f, 16.0f}, "Close")) {
{(unsigned char)(colorArray[0] * 255.0f),
(unsigned char)(colorArray[1] * 255.0f),
(unsigned char)(colorArray[2] * 255.0f),
(unsigned char)(colorArray[3] * 255.0f)});
colorArray = {
color.r / 255.0f,
color.g / 255.0f,
color.b / 255.0f,
color.a / 255.0f
};
if(GuiButton({504.0f, 272.0f, 234.0f, 16.0f}, "Close")) {
state->close_selected_tri_mode();
}
} else {

View file

@ -3,7 +3,6 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#include <glm/ext/matrix_transform.hpp>
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/matrix_transform_2d.hpp>
#pragma GCC diagnostic pop

View file

@ -27,15 +27,15 @@ currentTri(),
currentTri_state(CurrentState::NONE),
currentTri_maxState(CurrentState::NONE),
pointCircle(),
colorPickerColor{255, 255, 255, 255},
bgColorPickerColor{0, 0, 0, 255},
colorPickerColor{1.0f, 1.0f, 1.0f, 1.0f},
bgColorPickerColor{0.0f, 0.0f, 0.0f},
bgColor(BLACK),
saveFilenameBuffer(),
failedMessage(),
drawCache(),
pi(std::acos(-1.0f)),
selectedTri(),
selectedTriColor{255, 255, 255, 255},
selectedTriColor(),
selectedTriBlinkTimer(),
inputWidth(800),
inputHeight(600)
@ -229,8 +229,10 @@ void Tri::State::handle_events() {
my = drawImage.height - my;
colorPickerColor = colors[mx + my * drawImage.width];
colorPickerColor[0] = (float)(colors[mx + my * drawImage.width].r) / 255.0F;
colorPickerColor[1] = (float)(colors[mx + my * drawImage.width].g) / 255.0F;
colorPickerColor[2] = (float)(colors[mx + my * drawImage.width].b) / 255.0F;
colorPickerColor[3] = 1.0f;
pointCircle.fillColor = colors[mx + my * drawImage.width];
flags.reset(F_COPY_COLOR_MODE);
set_notification_text("Color set");
@ -253,7 +255,10 @@ void Tri::State::handle_events() {
flags.set(F_TRI_EDIT_MODE);
flags.set(F_TRI_EDIT_DRAW_TRI);
selectedTriBlinkTimer = 1.0f;
selectedTriColor = tris[i].fillColor;
selectedTriColor[0] = tris[i].fillColor.r / 255.0f;
selectedTriColor[1] = tris[i].fillColor.g / 255.0f;
selectedTriColor[2] = tris[i].fillColor.b / 255.0f;
selectedTriColor[3] = tris[i].fillColor.a / 255.0f;
break;
}
}
@ -276,13 +281,18 @@ void Tri::State::update() {
if(flags.test(F_COLOR_P_COLOR_DIRTY)) {
flags.reset(F_COLOR_P_COLOR_DIRTY);
pointCircle.fillColor = colorPickerColor;
pointCircle.fillColor = Color{
(unsigned char)(255 * colorPickerColor[0]),
(unsigned char)(255 * colorPickerColor[1]),
(unsigned char)(255 * colorPickerColor[2]),
(unsigned char)(255 * colorPickerColor[3])};
}
if(flags.test(F_BG_COLOR_P_COLOR_DIRTY)) {
flags.reset(F_BG_COLOR_P_COLOR_DIRTY);
bgColor = bgColorPickerColor;
bgColor.a = 255;
bgColor.r = (unsigned char)(255 * bgColorPickerColor[0]);
bgColor.g = (unsigned char)(255 * bgColorPickerColor[1]);
bgColor.b = (unsigned char)(255 * bgColorPickerColor[2]);
}
if(flags.test(F_TRI_EDIT_MODE)) {
@ -403,12 +413,12 @@ void Tri::State::append_notification_text(const char *text) {
notificationAlpha = 1.0f;
}
Color& Tri::State::get_color() {
std::array<float, 4>& Tri::State::get_color() {
flags.set(F_COLOR_P_COLOR_DIRTY);
return colorPickerColor;
}
Color& Tri::State::get_bg_color() {
std::array<float, 3>& Tri::State::get_bg_color() {
flags.set(F_BG_COLOR_P_COLOR_DIRTY);
return bgColorPickerColor;
}
@ -533,13 +543,21 @@ float Tri::State::get_pi() const {
return pi;
}
Color& Tri::State::get_selected_tri_color() {
tris.at(selectedTri).fillColor = selectedTriColor;
std::array<float, 4>& Tri::State::get_selected_tri_color() {
tris.at(selectedTri).fillColor = Color{
(unsigned char)(255.0f * selectedTriColor[0]),
(unsigned char)(255.0f * selectedTriColor[1]),
(unsigned char)(255.0f * selectedTriColor[2]),
(unsigned char)(255.0f * selectedTriColor[3])};
return selectedTriColor;
}
void Tri::State::close_selected_tri_mode() {
tris.at(selectedTri).fillColor = selectedTriColor;
tris.at(selectedTri).fillColor = Color{
(unsigned char)(255.0f * selectedTriColor[0]),
(unsigned char)(255.0f * selectedTriColor[1]),
(unsigned char)(255.0f * selectedTriColor[2]),
(unsigned char)(255.0f * selectedTriColor[3])};
flags.set(F_DRAW_CACHE_DIRTY);
reset_modes();
}

View file

@ -57,8 +57,8 @@ namespace Tri {
CurrentState currentTri_maxState;
Circle pointCircle;
Color colorPickerColor;
Color bgColorPickerColor;
std::array<float, 4> colorPickerColor;
std::array<float, 3> bgColorPickerColor;
Color bgColor;
std::array<char, 256> saveFilenameBuffer;
@ -69,7 +69,7 @@ namespace Tri {
const float pi;
unsigned int selectedTri;
Color selectedTriColor;
std::array<float, 4> selectedTriColor;
float selectedTriBlinkTimer;
int inputWidth;
@ -97,8 +97,8 @@ namespace Tri {
void append_notification_text(const char *text);
public:
Color& get_color();
Color& get_bg_color();
std::array<float, 4>& get_color();
std::array<float, 3>& get_bg_color();
std::array<char, 256>* get_save_filename_buffer();
bool do_save();
@ -119,7 +119,7 @@ namespace Tri {
float get_pi() const;
Color& get_selected_tri_color();
std::array<float, 4>& get_selected_tri_color();
void close_selected_tri_mode();
private:

2
third_party/glm vendored

@ -1 +1 @@
Subproject commit 673a963a0f1eb82f5fcef00b7b873371555e5814
Subproject commit efec5db081e3aad807d0731e172ac597f6a39447

2
third_party/raygui vendored

@ -1 +1 @@
Subproject commit 25c8c65a6e5f0f4d4b564a0343861898c6f2778b
Subproject commit 4e2a878e715c4aafa6ad7bd58d851221503c6e60