1+ #define IMGUI_DEFINE_MATH_OPERATORS
2+
13#define GLFW_INCLUDE_NONE
24#include < GLFW/glfw3.h>
35#include < algorithm>
@@ -55,6 +57,9 @@ int main(int argc, char **argv) {
5557 // return string "Enabled" as a void* (which is later used to infer the section)
5658 return (void *)" Enabled" ;
5759
60+ if (strcmp (name, " Gradient" ) == 0 )
61+ return (void *)" Gradient" ;
62+
5863 // check if name matches any feature slug
5964 for (const auto *f : globalAppState->hexDisplayFeatureManager ->getFeatures ()) {
6065 std::string slug = f->getSlug ();
@@ -66,39 +71,83 @@ int main(int argc, char **argv) {
6671 return nullptr ;
6772 };
6873 featuresHandler.ReadLineFn = [](ImGuiContext *, ImGuiSettingsHandler *, void *entry, const char *line) {
69- if (entry != (void *)" Enabled" ) {
70- auto *feature = static_cast <entropy::HexDisplayFeature *>(entry);
74+ if (entry == (void *)" Enabled" ) {
7175 std::string line_str = line;
7276 size_t eq_pos = line_str.find (' =' );
7377 if (eq_pos != std::string::npos) {
74- std::string key = line_str.substr (0 , eq_pos);
78+ std::string slug = line_str.substr (0 , eq_pos);
7579 std::string value = line_str.substr (eq_pos + 1 );
7680
77- feature->setConfig (key, value);
81+ std::string featureName;
82+ // Find feature by slug
83+ for (const auto *f : globalAppState->hexDisplayFeatureManager ->getFeatures ()) {
84+ std::string f_slug = f->getSlug ();
85+ if (f_slug == slug) {
86+ featureName = f->getName ();
87+ break ;
88+ }
89+ }
90+ if (featureName.empty ())
91+ return ; // Unknown feature
92+
93+ globalAppState->featureEnabled [featureName] = (value == " 1" );
7894 }
95+ }
7996
80- return ;
97+ if (entry == (void *)" Gradient" ) {
98+ std::string line_str = line;
99+ size_t eq_pos = line_str.find (' =' );
100+ if (eq_pos != std::string::npos) {
101+ std::string key = line_str.substr (0 , eq_pos);
102+ std::string value = line_str.substr (eq_pos + 1 );
103+
104+ if (key == " marks" ) {
105+ // Parse marks
106+ std::list<ImGG::Mark> marks;
107+ size_t start = 0 ;
108+ while (start < value.length ()) {
109+ size_t comma_pos = value.find (' ,' , start);
110+ std::string mark_str = (comma_pos == std::string::npos) ? value.substr (start) : value.substr (start, comma_pos - start);
111+
112+ size_t colon_pos = mark_str.find (' :' );
113+ if (colon_pos != std::string::npos) {
114+ float pos = std::stof (mark_str.substr (0 , colon_pos));
115+ std::string color_str = mark_str.substr (colon_pos + 1 );
116+ unsigned int color_value = 0 ;
117+ if (sscanf (color_str.c_str (), " 0x%X" , &color_value) == 1 ) {
118+ ImGG::Mark mark;
119+ mark.position = ImGG::RelativePosition{pos};
120+ mark.color = ImColor (color_value);
121+ marks.push_back (mark);
122+ }
123+ }
124+
125+ if (comma_pos == std::string::npos)
126+ break ;
127+ start = comma_pos + 1 ;
128+ }
129+
130+ globalAppState->gradient_widget .gradient () = ImGG::Gradient{marks};
131+ }
132+
133+ if (key == " interpolation" ) {
134+ int mode = std::stoi (value);
135+ globalAppState->gradient_widget .gradient ().interpolation_mode () = static_cast <ImGG::Interpolation>(mode);
136+ }
137+
138+ return ;
139+ }
81140 }
82141
142+ // Settings for each hex display feature
143+ auto *feature = static_cast <entropy::HexDisplayFeature *>(entry);
83144 std::string line_str = line;
84145 size_t eq_pos = line_str.find (' =' );
85146 if (eq_pos != std::string::npos) {
86- std::string slug = line_str.substr (0 , eq_pos);
147+ std::string key = line_str.substr (0 , eq_pos);
87148 std::string value = line_str.substr (eq_pos + 1 );
88149
89- std::string featureName;
90- // Find feature by slug
91- for (const auto *f : globalAppState->hexDisplayFeatureManager ->getFeatures ()) {
92- std::string f_slug = f->getSlug ();
93- if (f_slug == slug) {
94- featureName = f->getName ();
95- break ;
96- }
97- }
98- if (featureName.empty ())
99- return ; // Unknown feature
100-
101- globalAppState->featureEnabled [featureName] = (value == " 1" );
150+ feature->setConfig (key, value);
102151 }
103152 };
104153 featuresHandler.WriteAllFn = [](ImGuiContext *, ImGuiSettingsHandler *handler, ImGuiTextBuffer *buf) {
@@ -110,6 +159,23 @@ int main(int argc, char **argv) {
110159 }
111160 buf->appendf (" \n " );
112161
162+ // Gradient settings
163+ buf->appendf (" [%s][Gradient]\n " , handler->TypeName );
164+ const auto &gradient = globalAppState->gradient_widget .gradient ();
165+ buf->appendf (" marks=" );
166+ bool first = true ;
167+ for (const auto &mark : gradient.get_marks ()) {
168+ if (!first) {
169+ buf->appendf (" ," );
170+ }
171+ first = false ;
172+ unsigned int color_value = ImGui::ColorConvertFloat4ToU32 (mark.color );
173+ buf->appendf (" %.6f:0x%08X" , mark.position .get (), color_value);
174+ }
175+ buf->appendf (" \n " );
176+ buf->appendf (" interpolation=%d\n " , static_cast <int >(gradient.interpolation_mode ()));
177+ buf->appendf (" \n " );
178+
113179 // config for each feature
114180 for (const auto *f : globalAppState->hexDisplayFeatureManager ->getFeatures ()) {
115181 std::string slug = f->getSlug ();
@@ -129,6 +195,8 @@ int main(int argc, char **argv) {
129195
130196 ImGui::AddSettingsHandler (&featuresHandler);
131197
198+ appState.resetHexDisplayGradientColors ();
199+
132200 // Load settings
133201 ImGui::LoadIniSettingsFromDisk (ImGui::GetIO ().IniFilename );
134202
0 commit comments