Chanmges:
Add CopyOtherTheme Add Mor Stuff to ThemeEditor
This commit is contained in:
		@@ -101,6 +101,9 @@ class Theme {
 | 
			
		||||
  using Ref = std::shared_ptr<Theme>;
 | 
			
		||||
  static Ref New() { return std::make_shared<Theme>(); }
 | 
			
		||||
 | 
			
		||||
  // Loader method
 | 
			
		||||
  void CopyOther(Theme::Ref theme);
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  struct change {
 | 
			
		||||
    change(RD7Color a, unsigned int f, unsigned int t)
 | 
			
		||||
 
 | 
			
		||||
@@ -38,5 +38,10 @@ class ThemeEditor : public RenderD7::Scene {
 | 
			
		||||
  mutable bool cm;
 | 
			
		||||
  mutable std::string inpt;
 | 
			
		||||
  mutable int menu = 0;
 | 
			
		||||
 | 
			
		||||
  // Keyboard
 | 
			
		||||
  mutable RD7KeyboardState kbd_state;
 | 
			
		||||
  mutable std::string kbd_text;
 | 
			
		||||
  mutable std::vector<std::string> theme_list;
 | 
			
		||||
};
 | 
			
		||||
}  // namespace RenderD7
 | 
			
		||||
@@ -20,6 +20,7 @@
 | 
			
		||||
#include <fstream>
 | 
			
		||||
#include <map>
 | 
			
		||||
#include <renderd7/Color.hpp>
 | 
			
		||||
#include <renderd7/Message.hpp>
 | 
			
		||||
#include <renderd7/external/json.hpp>
 | 
			
		||||
#include <renderd7/internal_db.hpp>
 | 
			
		||||
 | 
			
		||||
@@ -124,6 +125,14 @@ void RenderD7::Theme::Default() {
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void RenderD7::Theme::CopyOther(Theme::Ref theme) {
 | 
			
		||||
  this->clr_tab.clear();
 | 
			
		||||
  this->clr_tab.resize(RD7Color_Len);
 | 
			
		||||
  for (int i = 0; i < (int)RD7Color_Len; i++) {
 | 
			
		||||
    this->clr_tab[i] = theme->Get(i);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
unsigned int RenderD7::Theme::Get(RD7Color clr) {
 | 
			
		||||
  if (clr < 0 || clr >= RD7Color_Len) return 0;
 | 
			
		||||
  return this->clr_tab[clr];
 | 
			
		||||
@@ -172,11 +181,13 @@ void RenderD7::Theme::UndoAll() {
 | 
			
		||||
void RenderD7::Theme::Save(const std::string& path) {
 | 
			
		||||
  if (std::filesystem::path(path).filename().string() == "renderd7.theme") {
 | 
			
		||||
    if (!rd7i_amdt) {
 | 
			
		||||
      RenderD7::PushMessage("Theme", "Default Theme cannot\nbe overwritten!");
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  std::ofstream file(path);
 | 
			
		||||
  if (!file.is_open()) {
 | 
			
		||||
    RenderD7::PushMessage("Theme", "Unable to\ncreate file!");
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  nlohmann::json js;
 | 
			
		||||
 
 | 
			
		||||
@@ -16,7 +16,9 @@
 | 
			
		||||
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <filesystem>
 | 
			
		||||
#include <renderd7/Hid.hpp>
 | 
			
		||||
#include <renderd7/Message.hpp>
 | 
			
		||||
#include <renderd7/ThemeEditor.hpp>
 | 
			
		||||
#include <renderd7/UI7.hpp>
 | 
			
		||||
 | 
			
		||||
@@ -36,8 +38,8 @@ std::map<RD7Color, std::string> color_names = {
 | 
			
		||||
    {RD7Color_Progressbar, "Progressbar"},
 | 
			
		||||
    {RD7Color_Selector, "Selector"},
 | 
			
		||||
    {RD7Color_SelectorFade, "SelectorFade"},
 | 
			
		||||
    {RD7Color_Text2, "Text2"},
 | 
			
		||||
    {RD7Color_Text, "Text"},
 | 
			
		||||
    {RD7Color_Text2, "Text Light"},
 | 
			
		||||
    {RD7Color_Text, "Text Dark"},
 | 
			
		||||
    {RD7Color_TextDisabled, "Text Disabled"},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@@ -45,7 +47,7 @@ RenderD7::ThemeEditor::ThemeEditor() {
 | 
			
		||||
  // Backup active Theme and create New one to edit
 | 
			
		||||
  temp_theme = RenderD7::ThemeActive();
 | 
			
		||||
  edit_theme = RenderD7::Theme::New();
 | 
			
		||||
  edit_theme->Default();
 | 
			
		||||
  edit_theme->CopyOther(temp_theme);
 | 
			
		||||
  RenderD7::ThemeSet(edit_theme);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -56,7 +58,7 @@ RenderD7::ThemeEditor::~ThemeEditor() {
 | 
			
		||||
 | 
			
		||||
void RenderD7::ThemeEditor::Draw() const {
 | 
			
		||||
  RenderD7::OnScreen(Top);
 | 
			
		||||
  if (UI7::BeginMenu("Theme Editor")) {
 | 
			
		||||
  if (UI7::BeginMenu("RenderD7 -> Theme Editor")) {
 | 
			
		||||
    UI7::Label("Sample Text");
 | 
			
		||||
    UI7::Checkbox("Checkbox", cm);
 | 
			
		||||
    UI7::InputText("Input Text", inpt, "Input Text");
 | 
			
		||||
@@ -69,17 +71,86 @@ void RenderD7::ThemeEditor::Draw() const {
 | 
			
		||||
  RenderD7::OnScreen(Bottom);
 | 
			
		||||
  if (UI7::BeginMenu("Theme", R7Vec2(), UI7MenuFlags_Scrolling)) {
 | 
			
		||||
    if (menu == 0) {
 | 
			
		||||
      if (UI7::Button("Create New")) {
 | 
			
		||||
        menu = 1;
 | 
			
		||||
        edit_theme->Default();
 | 
			
		||||
      } else if (UI7::Button("Edit Current")) {
 | 
			
		||||
        menu = 1;
 | 
			
		||||
      } else if (UI7::Button("Select Theme")) {
 | 
			
		||||
        menu = 2;
 | 
			
		||||
        theme_list.clear();
 | 
			
		||||
        for (const auto& it : std::filesystem::directory_iterator(
 | 
			
		||||
                 RenderD7::GetAppDirectory() + "/themes")) {
 | 
			
		||||
          theme_list.push_back(it.path().filename().string());
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    } else if (menu == 1) {
 | 
			
		||||
      if (UI7::Button("Go back")) {
 | 
			
		||||
        edit_theme->CopyOther(temp_theme);
 | 
			
		||||
        menu = 0;
 | 
			
		||||
      } else if (UI7::Button("Save")) {
 | 
			
		||||
        RenderD7::AddOvl(std::make_unique<Ovl_Keyboard>(kbd_text, kbd_state,
 | 
			
		||||
                                                        "<name>.theme"));
 | 
			
		||||
      }
 | 
			
		||||
      for (auto& it : color_names) {
 | 
			
		||||
        UI7::ColorSelector(it.second, edit_theme->GetTableRef()[it.first]);
 | 
			
		||||
      }
 | 
			
		||||
    } else if (menu == 1) {
 | 
			
		||||
    } else if (menu == 2) {
 | 
			
		||||
      if (UI7::Button("Go back")) {
 | 
			
		||||
        menu = 0;
 | 
			
		||||
      }
 | 
			
		||||
      for (auto& it : theme_list) {
 | 
			
		||||
        if (UI7::Button(it)) {
 | 
			
		||||
          edit_theme->Load(RenderD7::GetAppDirectory() + "/themes/" + it);
 | 
			
		||||
          menu = 1;
 | 
			
		||||
        }
 | 
			
		||||
        UI7::SameLine();
 | 
			
		||||
        if (UI7::Button("Make Current")) {
 | 
			
		||||
          edit_theme->Load(RenderD7::GetAppDirectory() + "/themes/" + it);
 | 
			
		||||
          temp_theme->CopyOther(edit_theme);
 | 
			
		||||
          menu = 0;
 | 
			
		||||
        }
 | 
			
		||||
        UI7::SameLine();
 | 
			
		||||
        if (UI7::Button("Delete")) {
 | 
			
		||||
          if (std::string(it) != "renderd7.theme") {
 | 
			
		||||
            std::filesystem::remove(RenderD7::GetAppDirectory() + "/themes/" +
 | 
			
		||||
                                    it);
 | 
			
		||||
            theme_list.clear();
 | 
			
		||||
            for (const auto& it : std::filesystem::directory_iterator(
 | 
			
		||||
                     RenderD7::GetAppDirectory() + "/themes")) {
 | 
			
		||||
              theme_list.push_back(it.path().filename().string());
 | 
			
		||||
            }
 | 
			
		||||
          } else {
 | 
			
		||||
            RenderD7::PushMessage("ThemeEditor",
 | 
			
		||||
                                  "Cannot Delete\nrenderd7.theme!");
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    UI7::EndMenu();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void RenderD7::ThemeEditor::Logic() {
 | 
			
		||||
  if (kbd_state) {
 | 
			
		||||
    if (kbd_state == RD7KeyboardState_Confirm) {
 | 
			
		||||
      auto path =
 | 
			
		||||
          RenderD7::GetAppDirectory() + "/themes/" + kbd_text + ".theme";
 | 
			
		||||
      kbd_text = "";
 | 
			
		||||
      if (std::filesystem::exists(path)) {
 | 
			
		||||
        // Prompt Override
 | 
			
		||||
        return;
 | 
			
		||||
      }
 | 
			
		||||
      edit_theme->Save(path);
 | 
			
		||||
    }
 | 
			
		||||
    kbd_state = RD7KeyboardState_None;
 | 
			
		||||
  }
 | 
			
		||||
  if (Hid::IsEvent("cancel", Hid::Down)) {
 | 
			
		||||
    if (menu == 0) {
 | 
			
		||||
      RenderD7::Scene::Back();
 | 
			
		||||
    } else {
 | 
			
		||||
      if (menu == 1) edit_theme->CopyOther(temp_theme);
 | 
			
		||||
      menu = 0;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -553,6 +553,8 @@ void BrowserList(const std::vector<std::string> &entrys, int &selection,
 | 
			
		||||
  if (size.x == 0) size.x = (rd7i_current_screen ? 400 : 320) - (pos.x * 2);
 | 
			
		||||
  if (size.y == 0) size.y = (max_entrys * 15);
 | 
			
		||||
  UI7CtxCursorMove(size);
 | 
			
		||||
  int selindex = (selection < max_entrys ? selection : (max_entrys - 1));
 | 
			
		||||
 | 
			
		||||
  for (int i = 0; i < max_entrys; i++) {
 | 
			
		||||
    ui7_ctx->cm->main.push_back(
 | 
			
		||||
        DrawCmd::New(R7Vec4(pos + R7Vec2(0, 15 * i), R7Vec2(size.x, 15)),
 | 
			
		||||
@@ -562,7 +564,6 @@ void BrowserList(const std::vector<std::string> &entrys, int &selection,
 | 
			
		||||
       i < ((entrys.size() < (size_t)max_entrys) ? entrys.size()
 | 
			
		||||
                                                 : (size_t)max_entrys);
 | 
			
		||||
       i++) {
 | 
			
		||||
    int selindex = (selection < max_entrys ? selection : (max_entrys - 1));
 | 
			
		||||
    int list_index =
 | 
			
		||||
        (selection < max_entrys ? i : (i + selection - (max_entrys - 1)));
 | 
			
		||||
    if (i == (size_t)selindex) {
 | 
			
		||||
@@ -933,7 +934,7 @@ void ColorSelector(const std::string &label, unsigned int &color) {
 | 
			
		||||
                       0xff0000ff));
 | 
			
		||||
 | 
			
		||||
      auto ncmd = DrawCmd::New(npos + R7Vec2(2, cbs.y * 3 + 4),
 | 
			
		||||
                               std::to_string(clr.m_r), RD7Color_Text);
 | 
			
		||||
                               "R: " + std::to_string(clr.m_r), RD7Color_Text);
 | 
			
		||||
      ncmd->text_flags |= RD7TextFlags_AlignMid;
 | 
			
		||||
      ncmd->text_box = R7Vec2(50, 0);
 | 
			
		||||
      ui7_ctx->cm->front.push_back(ncmd);
 | 
			
		||||
@@ -948,7 +949,7 @@ void ColorSelector(const std::string &label, unsigned int &color) {
 | 
			
		||||
                              R7Vec2(50 * ((float)clr.m_g / 255.f), cbs.y)),
 | 
			
		||||
                       0xff00ff00));
 | 
			
		||||
      auto ncmd = DrawCmd::New(npos + R7Vec2(54, cbs.y * 3 + 4),
 | 
			
		||||
                               std::to_string(clr.m_g), RD7Color_Text);
 | 
			
		||||
                               "G: " + std::to_string(clr.m_g), RD7Color_Text);
 | 
			
		||||
      ncmd->text_flags |= RD7TextFlags_AlignMid;
 | 
			
		||||
      ncmd->text_box = R7Vec2(50, 0);
 | 
			
		||||
      ui7_ctx->cm->front.push_back(ncmd);
 | 
			
		||||
@@ -964,7 +965,7 @@ void ColorSelector(const std::string &label, unsigned int &color) {
 | 
			
		||||
                       0xffff0000));
 | 
			
		||||
 | 
			
		||||
      auto ncmd = DrawCmd::New(npos + R7Vec2(2, cbs.y * 4 + 4),
 | 
			
		||||
                               std::to_string(clr.m_b), RD7Color_Text);
 | 
			
		||||
                               "B: " + std::to_string(clr.m_b), RD7Color_Text);
 | 
			
		||||
      ncmd->text_flags |= RD7TextFlags_AlignMid;
 | 
			
		||||
      ncmd->text_box = R7Vec2(50, 0);
 | 
			
		||||
      ui7_ctx->cm->front.push_back(ncmd);
 | 
			
		||||
@@ -980,7 +981,7 @@ void ColorSelector(const std::string &label, unsigned int &color) {
 | 
			
		||||
                       0xffffffff));
 | 
			
		||||
 | 
			
		||||
      auto ncmd = DrawCmd::New(npos + R7Vec2(54, cbs.y * 4 + 4),
 | 
			
		||||
                               std::to_string(clr.m_a), RD7Color_Text);
 | 
			
		||||
                               "A: " + std::to_string(clr.m_a), RD7Color_Text);
 | 
			
		||||
      ncmd->text_flags |= RD7TextFlags_AlignMid;
 | 
			
		||||
      ncmd->text_box = R7Vec2(50, 0);
 | 
			
		||||
      ui7_ctx->cm->front.push_back(ncmd);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user