Compare commits

...

4 commits

Author SHA1 Message Date
20859dbcd8 Enable picking color alpha for triangles 2024-01-23 15:04:09 +09:00
c6dd68ae14 Refactor usage of colors and color picking
Member variables of state changed from an array of floats to a Color
struct.
2024-01-23 14:53:47 +09:00
2e3a2385f2 Update submodule glm 2024-01-23 14:35:57 +09:00
18bb4e5f59 Update raygui submodule to 4.0
TODO: Refactor color picking in src/helpers.hpp
2024-01-23 14:31:39 +09:00
6 changed files with 57 additions and 86 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)) {
GuiFade(1.0f);
GuiSetAlpha(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) {
GuiFade(alpha);
GuiSetAlpha(alpha);
GuiPanel({(800 - SHOW_HELP_WIDTH) / 2.0f,
(600 - SHOW_HELP_HEIGHT) / 2.0f,
SHOW_HELP_WIDTH,
@ -96,23 +96,21 @@ namespace Tri {
inline void draw_color_picker(Tri::State *state) {
if(state->get_flags().test(Tri::State::F_DISPLAY_COLOR_P)) {
GuiFade(1.0f);
if(!GuiWindowBox({4.0f, 4.0f, 242.0f, 292.0f}, "Tri Color Picker")) {
auto &colorArray = state->get_color();
Color color = GuiColorPicker(
GuiSetAlpha(1.0f);
if(!GuiWindowBox({4.0f, 4.0f, 242.0f, 328.0f}, "Tri Color Picker")) {
auto &color = state->get_color();
GuiColorPicker(
{8.0f, 32.0f, 206.0f, 240.0f},
nullptr,
{(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")) {
&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")) {
state->close_color_picker();
}
} else {
@ -123,22 +121,14 @@ namespace Tri {
inline void draw_bg_color_picker(Tri::State *state) {
if(state->get_flags().test(Tri::State::F_DISPLAY_BG_COLOR_P)) {
GuiFade(1.0f);
GuiSetAlpha(1.0f);
if(!GuiWindowBox({250.0f, 4.0f, 242.0f, 292.0f}, "BG Color Picker")) {
auto &colorArray = state->get_bg_color();
Color color = GuiColorPicker(
GuiColorPicker(
{254.0f, 32.0f, 206.0f, 240.0f},
nullptr,
{(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")) {
&colorArray);
if(GuiButton({254.0f, 274.0f, 234.0f, 16.0f}, "Close")) {
state->close_bg_color_picker();
}
} else {
@ -150,7 +140,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();
GuiFade(1.0f);
GuiSetAlpha(1.0f);
if(!GuiWindowBox({4.0f, 300.0f, 292.0f, 292.0f}, "Save")) {
GuiTextBox(
{8.0f, 328.0f, 284.0f, 20.0f},
@ -174,7 +164,7 @@ namespace Tri {
inline void draw_change_size(Tri::State *state) {
if(state->get_flags().test(Tri::State::F_DISPLAY_CHANGE_SIZE)) {
GuiFade(1.0f);
GuiSetAlpha(1.0f);
if(!GuiWindowBox({300.0f, 300.0f, 292.0f, 292.0f}, "Change Size")) {
GuiValueBox(
{384.0f, 328.0f, 80.0f, 16.0f},
@ -264,23 +254,21 @@ namespace Tri {
inline void draw_edit_tri(Tri::State *state) {
if(state->get_flags().test(Tri::State::F_TRI_EDIT_MODE)) {
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(
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(
{504.0f, 32.0f, 206.0f, 240.0f},
nullptr,
{(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")) {
&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")) {
state->close_selected_tri_mode();
}
} else {

View file

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

View file

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

2
third_party/glm vendored

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

2
third_party/raygui vendored

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