@@ -12,6 +12,16 @@ namespace mode {
1212template <class SPEC >
1313class FileColorMenu : public SPEC ::MenuBase {
1414public:
15+
16+ Color8 getColor (FileReader& f, int N) {
17+ Color8 ret;
18+ f.Seek (this ->pos_ * mult_);
19+ ret.r = f.ReadHex2 ();
20+ ret.g = f.ReadHex2 ();
21+ ret.b = f.ReadHex2 ();
22+ return ret;
23+ }
24+
1525 void init () {
1626 size_ = 0 ;
1727 dir_ = nullptr ;
@@ -28,8 +38,36 @@ class FileColorMenu : public SPEC::MenuBase {
2838 if (f.Read () <= 13 ) mult_++;
2939 size_ = f.FileSize () / mult_;
3040 }
41+ #if 0
42+ // This makes it go to the closest color, which might be nice,
43+ // or it might be super annoying...
44+
45+ int best_match = 0;
46+ int best_diff = 0x7ffffff;
47+ Color16 best_color;
48+ for (int n = 0; n < size_; n++) {
49+ Color16 tmp = getColor(f, n);
50+ int diff =
51+ std::abs<int>(tmp.r - saved_.r) +
52+ std::abs<int>(tmp.g - saved_.g) +
53+ std::abs<int>(tmp.b - saved_.b);
54+ if (diff < best_diff) {
55+ best_diff = diff;
56+ best_match = n;
57+ best_color = tmp;
58+ }
59+ }
60+ this->pos_ = best_match;
61+
62+ f.Close();
63+ LOCK_SD(false);
64+ ShowColorStyle::SetColor(best_color);
65+ #else
3166 f.Close ();
3267 LOCK_SD (false );
68+ ShowColorStyle::SetColor (get ());
69+ #endif
70+
3371 PVLOG_STATUS << " DIR = " << dir_ << " size = " << size_ << " \n " ;
3472 if (dir_) break ;
3573 }
@@ -42,10 +80,7 @@ class FileColorMenu : public SPEC::MenuBase {
4280 AudioStreamWork::scheduleFillBuffer ();
4381 LOCK_SD (true );
4482 if (f.Open (full_name)) {
45- f.Seek (this ->pos_ * mult_);
46- ret.r = f.ReadHex2 ();
47- ret.g = f.ReadHex2 ();
48- ret.b = f.ReadHex2 ();
83+ ret = getColor (f, this ->pos_ );
4984 }
5085 f.Close ();
5186 LOCK_SD (false );
@@ -66,7 +101,6 @@ class FileColorMenu : public SPEC::MenuBase {
66101
67102 void exit () override {
68103 ShowColorStyle::SetColor (saved_);
69- getSL<SPEC>()->SayCancel ();
70104 SPEC::MenuBase::exit ();
71105 }
72106
@@ -287,13 +321,19 @@ struct ColorSelectMode : public ColorSelectList<SPEC, ColorSelectMode<SPEC>> {
287321 void mode_activate (bool onreturn) override {
288322 if (!onreturn) {
289323 load ();
324+ PVLOG_DEBUG << " **Color override start: "
325+ << " r = " << ShowColorStyle::getColor ().r
326+ << " g = " << ShowColorStyle::getColor ().g
327+ << " b = " << ShowColorStyle::getColor ().b
328+ << " \n " ;
290329 show_color_all_.Start ();
291330 }
292331 ColorSelectList<SPEC, ColorSelectMode<SPEC>>::mode_activate (onreturn);
293332 }
294333
295334 void mode_deactivate () override {
296335 show_color_all_.Stop ();
336+ PVLOG_DEBUG << " **Color override stop\n " ;
297337 ColorSelectList<SPEC, ColorSelectMode<SPEC>>::mode_deactivate ();
298338 }
299339
0 commit comments