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 \"R\" to undo.");
ImGui::Text("Press \"C\" to change colors");
ImGui::Text("Press \"B\" to change background color");
ImGui::End();
}
}
@ -54,11 +55,19 @@ namespace Tri {
inline void draw_color_picker(Tri::State *state) {
if(state->get_flags().test(2)) {
ImGui::Begin("Color Picker");
ImGui::Begin("Tri Color Picker");
ImGui::ColorPicker4("Tri Color", state->get_color());
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

View file

@ -22,7 +22,9 @@ window(sf::VideoMode(800, 600), "Triangles", sf::Style::Titlebar | sf::Style::Cl
trisIndex(0),
currentTri_state(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
ImGui::SFML::Init(window);
@ -96,9 +98,11 @@ void Tri::State::handle_events() {
}
} else if(event.key.code == sf::Keyboard::C) {
flags.flip(2);
} else if(event.key.code == sf::Keyboard::B) {
flags.flip(5);
}
} else if(event.type == sf::Event::MouseButtonPressed) {
if(!flags.test(2)) {
if(!flags.test(2) && !flags.test(5)) {
switch(currentTri_state) {
case CurrentState::NONE:
currentTri[0] = sf::Vector2f(event.mouseButton.x, event.mouseButton.y);
@ -155,16 +159,24 @@ void Tri::State::update() {
(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
Tri::draw_show_help(this);
Tri::draw_color_picker(this);
Tri::draw_bg_color_picker(this);
Tri::draw_help(this);
ImGui::EndFrame();
}
void Tri::State::draw() {
window.clear();
window.clear(bgColor);
// draw tris
for(unsigned int i = 0; i < trisIndex; ++i) {
@ -203,3 +215,8 @@ float* Tri::State::get_color() {
flags.set(3);
return colorPickerColor;
}
float* Tri::State::get_bg_color() {
flags.set(4);
return bgColorPickerColor;
}

View file

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