Impl changing background color, with "B"

This commit is contained in:
Stephen Seo 2020-07-22 17:46:20 +09:00
parent 4a90dd41e6
commit 099b0e65d6
3 changed files with 35 additions and 4 deletions

View file

@ -28,6 +28,7 @@ namespace Tri {
ImGui::Text("Press \"U\" to undo. Clicking will remove all future undo history"); ImGui::Text("Press \"U\" to undo. Clicking will remove all future undo history");
ImGui::Text("Press \"R\" to undo."); ImGui::Text("Press \"R\" to undo.");
ImGui::Text("Press \"C\" to change colors"); ImGui::Text("Press \"C\" to change colors");
ImGui::Text("Press \"B\" to change background color");
ImGui::End(); ImGui::End();
} }
} }
@ -54,11 +55,19 @@ namespace Tri {
inline void draw_color_picker(Tri::State *state) { inline void draw_color_picker(Tri::State *state) {
if(state->get_flags().test(2)) { if(state->get_flags().test(2)) {
ImGui::Begin("Color Picker"); ImGui::Begin("Tri Color Picker");
ImGui::ColorPicker4("Tri Color", state->get_color()); ImGui::ColorPicker4("Tri Color", state->get_color());
ImGui::End(); ImGui::End();
} }
} }
inline void draw_bg_color_picker(Tri::State *state) {
if(state->get_flags().test(5)) {
ImGui::Begin("BG Color Picker");
ImGui::ColorPicker3("BG Color", state->get_bg_color());
ImGui::End();
}
}
} }
#endif #endif

View file

@ -22,7 +22,9 @@ window(sf::VideoMode(800, 600), "Triangles", sf::Style::Titlebar | sf::Style::Cl
trisIndex(0), trisIndex(0),
currentTri_state(CurrentState::NONE), currentTri_state(CurrentState::NONE),
currentTri_maxState(CurrentState::NONE), currentTri_maxState(CurrentState::NONE),
colorPickerColor{1.0f, 1.0f, 1.0f, 1.0f} colorPickerColor{1.0f, 1.0f, 1.0f, 1.0f},
bgColorPickerColor{0.0f, 0.0f, 0.0f},
bgColor(sf::Color::Black)
{ {
flags.set(1); // is running flags.set(1); // is running
ImGui::SFML::Init(window); ImGui::SFML::Init(window);
@ -96,9 +98,11 @@ void Tri::State::handle_events() {
} }
} else if(event.key.code == sf::Keyboard::C) { } else if(event.key.code == sf::Keyboard::C) {
flags.flip(2); flags.flip(2);
} else if(event.key.code == sf::Keyboard::B) {
flags.flip(5);
} }
} else if(event.type == sf::Event::MouseButtonPressed) { } else if(event.type == sf::Event::MouseButtonPressed) {
if(!flags.test(2)) { if(!flags.test(2) && !flags.test(5)) {
switch(currentTri_state) { switch(currentTri_state) {
case CurrentState::NONE: case CurrentState::NONE:
currentTri[0] = sf::Vector2f(event.mouseButton.x, event.mouseButton.y); currentTri[0] = sf::Vector2f(event.mouseButton.x, event.mouseButton.y);
@ -155,16 +159,24 @@ void Tri::State::update() {
(unsigned char)(255 * colorPickerColor[3]))); (unsigned char)(255 * colorPickerColor[3])));
} }
if(flags.test(4)) {
flags.reset(4);
bgColor.r = (unsigned char)(255 * bgColorPickerColor[0]);
bgColor.g = (unsigned char)(255 * bgColorPickerColor[1]);
bgColor.b = (unsigned char)(255 * bgColorPickerColor[2]);
}
// Seems misleading, but imgui handles setting up the window during update // Seems misleading, but imgui handles setting up the window during update
Tri::draw_show_help(this); Tri::draw_show_help(this);
Tri::draw_color_picker(this); Tri::draw_color_picker(this);
Tri::draw_bg_color_picker(this);
Tri::draw_help(this); Tri::draw_help(this);
ImGui::EndFrame(); ImGui::EndFrame();
} }
void Tri::State::draw() { void Tri::State::draw() {
window.clear(); window.clear(bgColor);
// draw tris // draw tris
for(unsigned int i = 0; i < trisIndex; ++i) { for(unsigned int i = 0; i < trisIndex; ++i) {
@ -203,3 +215,8 @@ float* Tri::State::get_color() {
flags.set(3); flags.set(3);
return colorPickerColor; return colorPickerColor;
} }
float* Tri::State::get_bg_color() {
flags.set(4);
return bgColorPickerColor;
}

View file

@ -20,6 +20,8 @@ namespace Tri {
* 1 - is running * 1 - is running
* 2 - display color picker * 2 - display color picker
* 3 - color picker color dirty * 3 - color picker color dirty
* 4 - bg color picker color dirty
* 5 - display bg color picker
*/ */
typedef std::bitset<64> BitsetType; typedef std::bitset<64> BitsetType;
BitsetType flags; BitsetType flags;
@ -39,6 +41,8 @@ namespace Tri {
sf::Event event; sf::Event event;
float colorPickerColor[4]; float colorPickerColor[4];
float bgColorPickerColor[3];
sf::Color bgColor;
public: public:
void handle_events(); void handle_events();
@ -53,6 +57,7 @@ namespace Tri {
float get_starting_help_alpha() const; float get_starting_help_alpha() const;
float* get_color(); float* get_color();
float* get_bg_color();
}; };
} }