Option to color notes according to quantization !

This commit is contained in:
Stepland 2022-11-21 01:24:15 +01:00
parent 09b47e16f1
commit 029b2b0222
7 changed files with 115 additions and 7 deletions

28
src/colors.cpp Normal file
View File

@ -0,0 +1,28 @@
#include "colors.hpp"
#include <SFML/Config.hpp>
#include <algorithm>
#include "hsluv/hsluv.h"
HSLuvColor color_to_hsluv(const sf::Color& rgb) {
HSLuvColor hsl;
rgb2hsluv(
static_cast<double>(rgb.r) / 255.0,
static_cast<double>(rgb.g) / 255.0,
static_cast<double>(rgb.b) / 255.0,
&hsl.h, &hsl.s, &hsl.l
);
return hsl;
}
sf::Color hslub_to_color(const HSLuvColor& hsl) {
double r, g, b;
hsluv2rgb(hsl.h, hsl.s, hsl.l, &r, &g, &b);
r = std::clamp(r, 0.0, 1.0);
g = std::clamp(g, 0.0, 1.0);
b = std::clamp(b, 0.0, 1.0);
return {
static_cast<sf::Uint8>(r*255),
static_cast<sf::Uint8>(g*255),
static_cast<sf::Uint8>(b*255)
};
}

View File

@ -1,5 +1,6 @@
#pragma once
#include <hsluv/hsluv.h>
#include <SFML/Graphics/Color.hpp>
struct ButtonColors {
@ -49,3 +50,12 @@ namespace linear_view {
const linear_view::Colors default_colors = {};
};
struct HSLuvColor {
double h;
double s;
double l;
};
HSLuvColor color_to_hsluv(const sf::Color& rgb);
sf::Color hslub_to_color(const HSLuvColor& hsl);

View File

@ -228,6 +228,9 @@ void config::LinearView::load_from_v1_0_0_table(const toml::table& tbl) {
if (linear_view_table["zoom"].is_integer()) {
zoom = *linear_view_table["zoom"].value<int>();
}
if (linear_view_table["color_notes"].is_boolean()) {
color_notes = *linear_view_table["color_notes"].value<bool>();
}
}
void config::LinearView::dump_as_v1_0_0(toml::table& tbl) {
@ -236,6 +239,7 @@ void config::LinearView::dump_as_v1_0_0(toml::table& tbl) {
dump_linear_view_sizes_as_v1_0_0(sizes, linear_view);
dump_linear_view_lane_order_as_v1_0_0(lane_order, linear_view);
linear_view.insert_or_assign("zoom", zoom);
linear_view.insert_or_assign("color_notes", color_notes);
tbl.insert_or_assign("linear_view", linear_view);
}

View File

@ -40,6 +40,7 @@ namespace config {
linear_view::Sizes sizes;
linear_view::LaneOrder lane_order;
int zoom = 0;
bool color_notes = false;
void load_from_v1_0_0_table(const toml::table& tbl);
void dump_as_v1_0_0(toml::table& tbl);

View File

@ -9,6 +9,7 @@ sources += files(
'better_timing.cpp',
'chart_state.cpp',
'clipboard.cpp',
'colors.cpp',
'config.cpp',
'editor_state.cpp',
'file_dialogs.cpp',

View File

@ -1,5 +1,6 @@
#include "linear_view.hpp"
#include <SFML/Config.hpp>
#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <SFML/System/Vector2.hpp>
@ -14,6 +15,7 @@
#include <variant>
#include <fmt/core.h>
#include <hsluv/hsluv.h>
#include <imgui.h>
#include <imgui_stdlib.h>
#include <imgui-SFML.h>
@ -46,6 +48,7 @@ LinearView::LinearView(std::filesystem::path assets, config::Config& config_) :
collision_zone(config_.editor.collision_zone),
beats_to_pixels_proportional(0, 1, 0, 100),
zoom(config_.linear_view.zoom),
color_notes(config_.linear_view.color_notes),
lane_order(config_.linear_view.lane_order)
{
set_zoom(config_.linear_view.zoom);
@ -169,12 +172,22 @@ void LinearView::draw(
collizion_zone_width,
static_cast<float>(static_cast<double>(collision_zone_height))
};
auto collision_zone_color = colors.normal_collision_zone;
auto tap_note_color = colors.normal_tap_note;
if (chart_state.chart.notes->is_colliding(tap_note, timing, collision_zone)) {
collision_zone_color = colors.conflicting_collision_zone;
tap_note_color = colors.conflicting_tap_note;
}
const auto collision_zone_color = [&](){
if (chart_state.chart.notes->is_colliding(tap_note, timing, collision_zone)) {
return colors.conflicting_collision_zone;
} else {
return colors.normal_collision_zone;
}
}();
const auto tap_note_color = [&](){
if (chart_state.chart.notes->is_colliding(tap_note, timing, collision_zone)) {
return colors.conflicting_tap_note;
} else if (color_notes) {
return color_of_note(tap_note.get_time());
} else {
return colors.normal_tap_note;
}
}();
draw_rectangle(
draw_list,
origin + collision_zone_pos,
@ -224,7 +237,13 @@ void LinearView::draw(
static_cast<float>(static_cast<double>(collision_zone_height))
};
auto collision_zone_color = colors.normal_collision_zone;
auto tap_note_color = colors.normal_tap_note;
auto tap_note_color = [&](){
if (color_notes) {
return color_of_note(long_note.get_time());
} else {
return colors.normal_tap_note;
}
}();
auto long_note_color = colors.normal_long_note;
if (chart_state.chart.notes->is_colliding(long_note, timing, collision_zone)) {
collision_zone_color = colors.conflicting_collision_zone;
@ -398,6 +417,21 @@ void LinearView::display_settings() {
if (ImGui::SliderInt("Zoom##Linear View Settings", &zoom, -10, 10, "%d")) {
set_zoom(zoom);
}
if (ImGui::CollapsingHeader("Notes##Linear View Settings")) {
ImGui::Checkbox("Colored Quantization", &color_notes);
if (color_notes) {
for (auto& [quant, color] : note_colors) {
feis::ColorEdit4(
fmt::format(
"{}##Colored Quantization",
Toolbox::toOrdinal(quant*4)
).c_str(),
color
);
}
feis::ColorEdit4("Other", note_grey);
}
}
if (ImGui::CollapsingHeader("Lanes##Linear View Settings")) {
if (ImGui::BeginCombo("Order", lane_order_name().c_str())) {
if (ImGui::Selectable(
@ -490,6 +524,18 @@ void LinearView::reload_transforms() {
};
}
sf::Color LinearView::color_of_note(const Fraction& time) {
const auto denominator = time.denominator();
if (denominator > note_colors.rbegin()->first) {
return note_grey;
}
const auto& it = note_colors.find(static_cast<unsigned int>(denominator.get_ui()));
if (it == note_colors.end()) {
return note_grey;
}
return it->second;
}
std::string LinearView::lane_order_name() {
const auto name = VariantVisitor {
[](linear_view::lane_order::Default) { return "Default"; },

View File

@ -1,6 +1,7 @@
#pragma once
#include <filesystem>
#include <map>
#include <imgui.h>
#include <SFML/Graphics.hpp>
@ -23,6 +24,18 @@ struct SelectionRectangle {
void reset();
};
const std::map<unsigned int, sf::Color> reference_note_colors = {{
{1, {255, 40, 40}},
{2, {34, 140, 255}},
{3, {156, 0, 254}},
{4, {248, 236, 18}},
{6, {255, 131, 189}},
{8, {254, 135, 0}},
{12, {0, 254, 207}},
{16, {68, 254, 0}}
}};
const sf::Color reference_note_grey = {134, 110, 116};
class LinearView {
public:
LinearView(std::filesystem::path assets, config::Config& config);
@ -58,6 +71,11 @@ private:
int& zoom;
bool& color_notes;
std::map<unsigned int, sf::Color> note_colors = reference_note_colors;
sf::Color note_grey = reference_note_grey;
sf::Color color_of_note(const Fraction& time);
SelectionRectangle selection_rectangle;
bool started_selection_inside_window = false;
bool any_bpm_button_hovered = false;