Skip to content

Commit

Permalink
Auto format source files using clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
IrneRacoonovich committed May 15, 2024
1 parent b602cd4 commit d9a3136
Show file tree
Hide file tree
Showing 16 changed files with 1,060 additions and 935 deletions.
83 changes: 44 additions & 39 deletions source/FanSliderOverlay.hpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
#define NDEBUG
#define STBTT_STATIC
#define TESLA_INIT_IMPL
#include <tesla.hpp>
#include <HelpOverlay.hpp>
#include <tesla.hpp>
#include <utils.hpp>

class FanSliderOverlay : public tsl::Gui {
private:
std::string filePath, specificKey ;
std::string filePath, specificKey;
std::vector<std::vector<std::string>> commands;
std::string helpPath = "";


public:
FanSliderOverlay(const std::string& file, const std::string& key = "", const std::vector<std::vector<std::string>>& cmds = {})
: filePath(file), specificKey(key), commands(cmds) {}
~FanSliderOverlay() {}
FanSliderOverlay(const std::string& file, const std::string& key = "", const std::vector<std::vector<std::string>>& cmds = {})
: filePath(file)
, specificKey(key)
, commands(cmds)
{
}
~FanSliderOverlay() { }

virtual tsl::elm::Element* createUI() override {
virtual tsl::elm::Element* createUI() override
{
// log ("FanSliderOverlay");

size_t fifthSlashPos = filePath.find('/', filePath.find('/', filePath.find('/', filePath.find('/') + 1) + 1) + 1);
Expand All @@ -34,11 +38,10 @@ class FanSliderOverlay : public tsl::Gui {
helpPath += "/Help/" + getNameWithoutPrefix(getNameFromPath(filePath)) + ".txt";
}
if (isFileOrDirectory(helpPath)) {
hasHelp = true;
hasHelp = true;
} else {
helpPath = "";
}

}
auto rootFrame = new tsl::elm::OverlayFrame(specificKey.empty() ? getNameWithoutPrefix(getNameFromPath(filePath)) : specificKey,
"Uberhand Package", "", hasHelp, "\uE0E1 Back \uE0E0 Apply ");
Expand All @@ -47,13 +50,15 @@ class FanSliderOverlay : public tsl::Gui {
std::string sourceIni = "";
std::string sectionIni = "";
std::string keyIni = "";
enum fanModes {Both, Handheld, Console};
enum fanModes { Both,
Handheld,
Console };
fanModes fanMode = fanModes::Both;

for (const auto& cmd : commands) {
if (cmd.size() > 1) {
if (cmd[0] == "slider_ini") {
sourceIni = preprocessPath(cmd[1]);
sourceIni = preprocessPath(cmd[1]);
if (cmd[2] == "handheld") {
fanMode = fanModes::Handheld;
} else if (cmd[2] == "console") {
Expand All @@ -62,7 +67,7 @@ class FanSliderOverlay : public tsl::Gui {
fanMode = fanModes::Both;
}
}
}
}
}

if (!isFileOrDirectory(sourceIni)) {
Expand All @@ -83,47 +88,46 @@ class FanSliderOverlay : public tsl::Gui {
std::string iniString = readIniValue(sourceIni, "tc", (fanMode == fanModes::Console or fanMode == fanModes::Both) ? "tskin_rate_table_console_on_fwdbg" : "tskin_rate_table_handheld_on_fwdbg");
std::vector<std::vector<int>> iniValues = parseIntIniData(iniString);
for (const auto& arr : iniValues) {
std::string low = arr[0] < 0 ? "0" : std::to_string(arr[0]/1000) + "°C";
std::string high = arr[1] > 100000 ? "100°C" : std::to_string((arr[1]/1000) - 1) + "°C";
std::string low = arr[0] < 0 ? "0" : std::to_string(arr[0] / 1000) + "°C";
std::string high = arr[1] > 100000 ? "100°C" : std::to_string((arr[1] / 1000) - 1) + "°C";
std::string header = "Max fan speed at " + low + "-" + high + ": ";
double stepSize = 0.05 * 255;
int percentage = 0;
if (arr[3] > 0) {
percentage = static_cast<int>(ceil(arr[3] / stepSize));
}

auto slider = new tsl::elm::NamedStepTrackBar(" ",{header + "0%", header + "5%", header + "10%", header + "15%", header + "20%", header + "25%", header + "30%", header + "35%", header + "40%", header + "45%", header + "50%", header + "55%", header + "60%", header + "65%", header + "70%", header + "75%", header + "80%", header + "85%", header + "90%", header + "95%", header+"100%"});
auto slider = new tsl::elm::NamedStepTrackBar(" ", { header + "0%", header + "5%", header + "10%", header + "15%", header + "20%", header + "25%", header + "30%", header + "35%", header + "40%", header + "45%", header + "50%", header + "55%", header + "60%", header + "65%", header + "70%", header + "75%", header + "80%", header + "85%", header + "90%", header + "95%", header + "100%" });

slider->setProgress(percentage);
slider->setValueChangedListener([this, list, slider](u8 val) {
size_t listSize = list->getSize();
size_t sliderIndex = list->getIndexInList(slider);
if (sliderIndex != 0) {
for (size_t i = 0; i < sliderIndex; i++) {
if (list->getItemAtIndex(i)->getClass() == tsl::Class::TrackBar) {
tsl::elm::NamedStepTrackBar* prevSlider = dynamic_cast<tsl::elm::NamedStepTrackBar*>(list->getItemAtIndex(i));
if (prevSlider->getProgress() > val)
{
prevSlider->setProgressVal(val);
}
if (sliderIndex != 0) {
for (size_t i = 0; i < sliderIndex; i++) {
if (list->getItemAtIndex(i)->getClass() == tsl::Class::TrackBar) {
tsl::elm::NamedStepTrackBar* prevSlider = dynamic_cast<tsl::elm::NamedStepTrackBar*>(list->getItemAtIndex(i));
if (prevSlider->getProgress() > val) {
prevSlider->setProgressVal(val);
}
}
}
for (size_t i = sliderIndex; i < listSize; i++) {
if (list->getItemAtIndex(i)->getClass() == tsl::Class::TrackBar) {
tsl::elm::NamedStepTrackBar* curSlider = dynamic_cast<tsl::elm::NamedStepTrackBar*>(list->getItemAtIndex(i));
if (curSlider->getProgress() < val)
curSlider->setProgressVal(val);
}
}
for (size_t i = sliderIndex; i < listSize; i++) {
if (list->getItemAtIndex(i)->getClass() == tsl::Class::TrackBar) {
tsl::elm::NamedStepTrackBar* curSlider = dynamic_cast<tsl::elm::NamedStepTrackBar*>(list->getItemAtIndex(i));
if (curSlider->getProgress() < val)
curSlider->setProgressVal(val);
}
}
});
slider->setClickListener([this, list, iniString, sourceIni, iniValues, fanMode, stepSize](uint64_t keys) { // Add 'command' to the capture list
if (keys & KEY_A) {
std::vector<int> values;
size_t listSize = list->getSize();
for (size_t i = 0; i < listSize; i++) {
if (list->getItemAtIndex(i)->getClass() == tsl::Class::TrackBar) {
values.push_back(int(double(dynamic_cast<tsl::elm::NamedStepTrackBar*>(list->getItemAtIndex(i))->getProgressStep())*stepSize));
values.push_back(int(double(dynamic_cast<tsl::elm::NamedStepTrackBar*>(list->getItemAtIndex(i))->getProgressStep()) * stepSize));
}
}
if (fanMode == fanModes::Both) {
Expand All @@ -132,7 +136,7 @@ class FanSliderOverlay : public tsl::Gui {
} else {
setIniFileValue(sourceIni, "tc", (fanMode == fanModes::Handheld) ? "tskin_rate_table_handheld_on_fwdbg" : "tskin_rate_table_console_on_fwdbg", formString(values, parseIntIniData(iniString, false)));
}

applied = true;
tsl::goBack();
return true;
Expand All @@ -142,10 +146,11 @@ class FanSliderOverlay : public tsl::Gui {
list->addItem(slider);
}
rootFrame->setContent(list);
return rootFrame;
return rootFrame;
}

std::string formString(std::vector<int> newValues, const std::vector<std::vector<int>>& initialData) {
std::string formString(std::vector<int> newValues, const std::vector<std::vector<int>>& initialData)
{

std::stringstream result;
result << "\"str!\"[[";
Expand All @@ -168,16 +173,16 @@ class FanSliderOverlay : public tsl::Gui {
for (int j = 0; j < 3; j++) {
result << arr[j] << ", ";
}
if (i != initialData.size() -1)
result << arr[3] << "], [";
if (i != initialData.size() - 1)
result << arr[3] << "], [";
else
result << arr[3] << "]]\"\"";

}
return result.str();
}

virtual bool handleInput(u64 keysDown, u64 keysHeld, touchPosition touchInput, JoystickPosition leftJoyStick, JoystickPosition rightJoyStick) override {
virtual bool handleInput(u64 keysDown, u64 keysHeld, touchPosition touchInput, JoystickPosition leftJoyStick, JoystickPosition rightJoyStick) override
{
if (keysDown & KEY_B) {
tsl::goBack();
return true;
Expand Down
35 changes: 21 additions & 14 deletions source/HelpOverlay.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,48 @@ class HelpOverlay : public tsl::Gui {
std::string helpPath;

public:
HelpOverlay(const std::string& helpPath) : helpPath(helpPath) {}
~HelpOverlay() {}
HelpOverlay(const std::string& helpPath)
: helpPath(helpPath)
{
}
~HelpOverlay() { }

virtual tsl::elm::Element* createUI() override {
virtual tsl::elm::Element* createUI() override
{
// log ("HelpOverlay");

std::pair<std::string, int> textDataPair;
constexpr int lineHeight = 20; // Adjust the line height as needed
constexpr int fontSize = 19; // Adjust the font size as needed
constexpr int lineHeight = 20; // Adjust the line height as needed
constexpr int fontSize = 19; // Adjust the font size as needed

auto rootFrame = new tsl::elm::OverlayFrame("Help", "Uberhand Package","",false,"\uE0E1 Back ");
auto rootFrame = new tsl::elm::OverlayFrame("Help", "Uberhand Package", "", false, "\uE0E1 Back ");
auto list = new tsl::elm::List();

if (!isFileOrDirectory(helpPath)) {
list->addItem(new tsl::elm::CustomDrawer([lineHeight, fontSize](tsl::gfx::Renderer *renderer, s32 x, s32 y, s32 w, s32 h) {
renderer->drawString("Text file not found.\nContact the package dev.", false, x, y + lineHeight, fontSize, a(tsl::style::color::ColorText));
}), fontSize + lineHeight);
list->addItem(new tsl::elm::CustomDrawer([lineHeight, fontSize](tsl::gfx::Renderer* renderer, s32 x, s32 y, s32 w, s32 h) {
renderer->drawString("Text file not found.\nContact the package dev.", false, x, y + lineHeight, fontSize, a(tsl::style::color::ColorText));
}),
fontSize + lineHeight);
rootFrame->setContent(list);
return rootFrame;
} else {
textDataPair = readTextFromFile(helpPath);
std::string textdata = textDataPair.first;
int textsize = textDataPair.second;
if (!textdata.empty()) {
list->addItem(new tsl::elm::CustomDrawer([lineHeight, fontSize, textdata](tsl::gfx::Renderer *renderer, s32 x, s32 y, s32 w, s32 h) {
renderer->drawString(textdata.c_str(), false, x, y + lineHeight, fontSize, a(tsl::style::color::ColorText));
}), fontSize * textsize + lineHeight);
list->addItem(new tsl::elm::CustomDrawer([lineHeight, fontSize, textdata](tsl::gfx::Renderer* renderer, s32 x, s32 y, s32 w, s32 h) {
renderer->drawString(textdata.c_str(), false, x, y + lineHeight, fontSize, a(tsl::style::color::ColorText));
}),
fontSize * textsize + lineHeight);
rootFrame->setContent(list);
return rootFrame;
}
}
return rootFrame;
return rootFrame;
}

virtual bool handleInput(u64 keysDown, u64 keysHeld, touchPosition touchInput, JoystickPosition leftJoyStick, JoystickPosition rightJoyStick) override {
virtual bool handleInput(u64 keysDown, u64 keysHeld, touchPosition touchInput, JoystickPosition leftJoyStick, JoystickPosition rightJoyStick) override
{
if (keysDown & KEY_B) {
tsl::goBack();
return true;
Expand Down
25 changes: 14 additions & 11 deletions source/IniSection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
using IniKeyValue = std::unordered_map<std::string, std::string>;
using IniSectionInput = std::unordered_map<std::string, IniKeyValue>;

IniSectionInput readIniFile(const std::string& filename) {
IniSectionInput readIniFile(const std::string& filename)
{
IniSectionInput iniData;
std::ifstream inFile(filename);
std::string line;
Expand Down Expand Up @@ -33,7 +34,8 @@ IniSectionInput readIniFile(const std::string& filename) {
}

// Write the IniSectionInput structure back to a file
void writeIniFile(const std::string& filename, const IniSectionInput& iniData) {
void writeIniFile(const std::string& filename, const IniSectionInput& iniData)
{
std::ofstream outFile(filename);
for (const auto& [section, kvPairs] : iniData) {
outFile << "[" << section << "]\n";
Expand All @@ -46,26 +48,27 @@ void writeIniFile(const std::string& filename, const IniSectionInput& iniData) {
}

// Update values in the INI data
void updateIniData(IniSectionInput& iniData, const IniSectionInput& updates, bool remove=false) {
void updateIniData(IniSectionInput& iniData, const IniSectionInput& updates, bool remove = false)
{
if (remove) {
for (const auto& [section, kvPairs] : updates) {
for (const auto& [key, value] : kvPairs) {
//log(iniData[section][key]);
iniData[section].erase(key);
//log(iniData[section][key]);
iniData[section].erase(key);
}
}
} else {
for (const auto& [section, kvPairs] : updates) {
for (const auto& [key, value] : kvPairs) {
//log(iniData[section][key]);
iniData[section][key] = value;
//log(iniData[section][key]);
iniData[section][key] = value;
}
}
}
}


std::vector<std::string> splitSections(const std::string& str) {
std::vector<std::string> splitSections(const std::string& str)
{
std::vector<std::string> result;
std::string temp;
size_t pos = 0, lastPos = 0;
Expand All @@ -83,8 +86,8 @@ std::vector<std::string> splitSections(const std::string& str) {
return result;
}


IniSectionInput parseDesiredData(const std::string& input) {
IniSectionInput parseDesiredData(const std::string& input)
{
IniSectionInput desiredData;
std::vector<std::string> sections = splitSections(input);

Expand Down
Loading

0 comments on commit d9a3136

Please sign in to comment.