Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions Common/Cpp/ColoredText.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* Colored Text
*
* From: https://github.com/PokemonAutomation/
*
*/

#include "ColoredText.h"

namespace PokemonAutomation{


#if 1
Color theme_friendly_darkblue(){
if (CURRENT_THEME == UiThemeMode::DARK_MODE){
return Color(0xff0080ff);
}
return COLOR_DARK_BLUE;
}
#endif
std::string html_color_text(const std::string& text, Color color){
if (color == Color()){
return text;
}
const char HEX[] = "0123456789abcdef";
uint32_t rgb = (uint32_t)color;
std::string str;
str += HEX[(rgb >> 20) & 15];
str += HEX[(rgb >> 16) & 15];
str += HEX[(rgb >> 12) & 15];
str += HEX[(rgb >> 8) & 15];
str += HEX[(rgb >> 4) & 15];
str += HEX[(rgb >> 0) & 15];
return "<font color=#" + str + ">" + text + "</font>";
}
std::string make_text_url(const std::string& url, const std::string& text){
#if 0
switch (CURRENT_THEME){
case 0:
return "<a href=\"" + url + "\">" + text + "</a>";
case 1:
return "<a href=\"" + url + "\" style=\"color: #0080ff\">" + text + "</a>";
}
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Invalid theme #.");
#endif
return "<a href=\"" + url + "\" style=\"color: #0080ff\">" + text + "</a>";
}






}
28 changes: 28 additions & 0 deletions Common/Cpp/ColoredText.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* Colored Text
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_ColoredText_H
#define PokemonAutomation_ColoredText_H

#include "Common/Cpp/Color.h"
#include <string>

namespace PokemonAutomation{

enum class UiThemeMode{
DEFAULT_MODE,
DARK_MODE,
};

inline UiThemeMode CURRENT_THEME = UiThemeMode::DEFAULT_MODE;

Color theme_friendly_darkblue();
std::string html_color_text(const std::string& text, Color color);
std::string make_text_url(const std::string& url, const std::string& text);

}
#endif

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "CommonFramework/GlobalSettingsPanel.h"
#include "CommonFramework/Logging/Logger.h"
#include "CommonFramework/Notifications/ProgramNotifications.h"
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
#include "Common/Cpp/ColoredText.h"
#include "CommonFramework/Recording/StreamHistorySession.h"
#include "CommonFramework/Tools/GlobalThreadPools.h"
#include "ProgramDumper.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <QCryptographicHash>
#include <QDesktopServices>
#include <QUrl>
#include "Common/Cpp/ColoredText.h"
#include "Common/Cpp/Containers/Pimpl.tpp"
#include "Common/Cpp/LifetimeSanitizer.h"
#include "Common/Cpp/Json/JsonValue.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@
namespace PokemonAutomation{


size_t current_theme = 0;


void set_theme(size_t index){
if (index == current_theme){
void set_theme(UiThemeMode theme_mode){
if (theme_mode == CURRENT_THEME){
return;
}
QString stylesheet;
switch (index){
case 0:
switch (theme_mode){
case UiThemeMode::DEFAULT_MODE:
break;
case 1:
case UiThemeMode::DARK_MODE:
stylesheet = ":qdarkstyle/dark/darkstyle.qss";
break;
}
Expand All @@ -42,73 +40,33 @@ void set_theme(size_t index){
QApplication* app = static_cast<QApplication*>(QApplication::instance());
app->setStyleSheet(stylesheet);

current_theme = index;
CURRENT_THEME = theme_mode;
}


ThemeSelectorOption::ThemeSelectorOption()
: IntegerEnumDropdownOption(
: EnumDropdownOption<UiThemeMode>(
"<b>Theme:</b>",
{
{0, "default", "Default"},
{1, "dark", "Dark Mode"},
{UiThemeMode::DEFAULT_MODE, "default", "Default"},
{UiThemeMode::DARK_MODE, "dark", "Dark Mode"},
},
LockMode::LOCK_WHILE_RUNNING,
0
UiThemeMode::DEFAULT_MODE
)
{}

bool ThemeSelectorOption::set_value(size_t index){
if (!IntegerEnumDropdownOption::set_value(index)){
return false;
}
set_theme(index);
set_theme(static_cast<UiThemeMode>(index));
return true;
}
void ThemeSelectorOption::load_json(const JsonValue& json){
IntegerEnumDropdownOption::load_json(json);
set_theme(current_value());
}



#if 1
Color theme_friendly_darkblue(){
if (current_theme == 1){
return Color(0xff0080ff);
}
return COLOR_DARK_BLUE;
set_theme(static_cast<UiThemeMode>(current_value()));
}
#endif
std::string html_color_text(const std::string& text, Color color){
if (color == Color()){
return text;
}
const char HEX[] = "0123456789abcdef";
uint32_t rgb = (uint32_t)color;
std::string str;
str += HEX[(rgb >> 20) & 15];
str += HEX[(rgb >> 16) & 15];
str += HEX[(rgb >> 12) & 15];
str += HEX[(rgb >> 8) & 15];
str += HEX[(rgb >> 4) & 15];
str += HEX[(rgb >> 0) & 15];
return "<font color=#" + str + ">" + text + "</font>";
}
std::string make_text_url(const std::string& url, const std::string& text){
#if 0
switch (current_theme){
case 0:
return "<a href=\"" + url + "\">" + text + "</a>";
case 1:
return "<a href=\"" + url + "\" style=\"color: #0080ff\">" + text + "</a>";
}
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Invalid theme #.");
#endif
return "<a href=\"" + url + "\" style=\"color: #0080ff\">" + text + "</a>";
}





Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
#ifndef PokemonAutomation_ThemeSelectorOption_H
#define PokemonAutomation_ThemeSelectorOption_H

#include "Common/Cpp/Color.h"
#include "Common/Cpp/ColoredText.h"
#include "Common/Cpp/Options/EnumDropdownOption.h"

namespace PokemonAutomation{


class ThemeSelectorOption : public IntegerEnumDropdownOption{
class ThemeSelectorOption : public EnumDropdownOption<UiThemeMode>{
public:
ThemeSelectorOption();

Expand All @@ -22,9 +22,6 @@ class ThemeSelectorOption : public IntegerEnumDropdownOption{
};


Color theme_friendly_darkblue();
std::string html_color_text(const std::string& text, Color color);
std::string make_text_url(const std::string& url, const std::string& text);



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <QLabel>
#include <QPushButton>
#include "CommonFramework/Globals.h"
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
#include "Common/Cpp/ColoredText.h"
#include "PanelElements.h"

namespace PokemonAutomation{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "Common/Cpp/Json/JsonObject.h"
#include "CommonFramework/Exceptions/OperationFailedException.h"
#include "CommonFramework/Options/CheckForUpdatesOption.h"
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
#include "Common/Cpp/ColoredText.h"
#include "CommonFramework/Tools/FileDownloader.h"
#include "CommonFramework/Globals.h"
#include "CommonFramework/GlobalSettingsPanel.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "CommonFramework/Logging/LoggerWindow.h"
#include "CommonFramework/Startup/NewVersionCheck.h"
#include "CommonFramework/Options/ResolutionOption.h"
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
#include "Common/Cpp/ColoredText.h"
#include "CommonFramework/Windows/DpiScaler.h"
#include "PanelLists.h"
#include "WindowTracker.h"
Expand Down
2 changes: 1 addition & 1 deletion SerialPrograms/Source/Controllers/ControllerConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
*/

#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
#include "Common/Cpp/ColoredText.h"
#include "ControllerConnection.h"

//#include <iostream>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "Common/PABotBase2/PABotBase2CC_MessageDumper.h"
#include "CommonFramework/Globals.h"
#include "CommonFramework/Logging/Logger.h"
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
#include "Common/Cpp/ColoredText.h"
#include "Controllers/ControllerTypeStrings.h"
#include "Controllers/ControllerSettings.h"
#include "Controllers/SerialPABotBase/SerialPABotBase.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "Common/PABotBase2/ReliableConnectionLayer/PABotBase2_PacketProtocol.h"
#include "CommonFramework/Globals.h"
#include "CommonFramework/Logging/Logger.h"
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
#include "Common/Cpp/ColoredText.h"
#include "CommonFramework/Tools/GlobalThreadPools.h"
#include "Controllers/SerialPortPollerQt.h"
#include "SerialPABotBase2_Connection.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "Common/Cpp/SerialConnection/SerialConnection.h"
#include "CommonFramework/Globals.h"
#include "CommonFramework/GlobalSettingsPanel.h"
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
#include "Common/Cpp/ColoredText.h"
#include "CommonFramework/Tools/GlobalThreadPools.h"
#include "Controllers/ControllerTypeStrings.h"
#include "Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_Errors.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "Common/SerialPABotBase/SerialPABotBase_Protocol_IDs.h"
#include "Common/PABotBase2/Controllers/PABotBase2_Controller_HID_Keyboard.h"
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
#include "Common/Cpp/ColoredText.h"
#include "StandardHid_Keyboard_PABotBase2.h"

namespace PokemonAutomation{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <QHBoxLayout>
#include "CommonFramework/StaticGlobals.h"
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
#include "Common/Cpp/ColoredText.h"
#include "ML_ImageAnnotationCommandRow.h"

//#include <iostream>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

#include "Common/PABotBase2/Controllers/PABotBase2_Controller_NS1_OemController.h"
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
#include "Common/Cpp/ColoredText.h"
#include "Controllers/SerialPABotBase/SerialPABotBase.h"
#include "NintendoSwitch/NintendoSwitch_Settings.h"
#include "NintendoSwitch_PABotBase2_OemController.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "Common/SerialPABotBase/SerialPABotBase_Protocol_IDs.h"
#include "Common/PABotBase2/Controllers/PABotBase2_Controller_NS_WiredController.h"
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
#include "Common/Cpp/ColoredText.h"
#include "Controllers/JoystickTools.h"
#include "NintendoSwitch_PABotBase2_WiredController.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

#include "Common/Cpp/Exceptions.h"
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
#include "Common/Cpp/ColoredText.h"
#include "Controllers/JoystickTools.h"
#include "Controllers/SerialPABotBase/SerialPABotBase.h"
#include "Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_ControllerMode.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <QEventLoop>
#include "Common/Cpp/Time.h"
#include "CommonFramework/Logging/Logger.h"
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
#include "Common/Cpp/ColoredText.h"
#include "CommonFramework/Tools/GlobalThreadPools.h"
#include "NintendoSwitch/NintendoSwitch_Settings.h"
#include "SysbotBase_Connection.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "Common/Qt/Options/ConfigWidget.h"
#include "CommonFramework/StaticGlobals.h"
#include "CommonFramework/GlobalSettingsPanel.h"
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
#include "Common/Cpp/ColoredText.h"
#include "CommonFramework/Panels/ConsoleSettingsStretch.h"
#include "CommonFramework/Recording/StreamHistoryOption.h"
#include "ControllerInput/ControllerInput.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <sstream>
#include "CommonFramework/Exceptions/ProgramFinishedException.h"
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
#include "Common/Cpp/ColoredText.h"
#include "CommonFramework/Notifications/ProgramNotifications.h"
#include "CommonFramework/VideoPipeline/VideoFeed.h"
#include "CommonFramework/Tools/ProgramEnvironment.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "CommonFramework/Exceptions/FatalProgramException.h"
#include "CommonFramework/Exceptions/OperationFailedException.h"
//#include "CommonFramework/Exceptions/UnexpectedBattleException.h"
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
#include "Common/Cpp/ColoredText.h"
#include "CommonFramework/Notifications/ProgramNotifications.h"
#include "CommonFramework/ProgramStats/StatsTracking.h"
#include "CommonFramework/VideoPipeline/VideoFeed.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "Common/Cpp/Time.h"
#include "CommonFramework/Exceptions/ProgramFinishedException.h"
#include "CommonFramework/Notifications/ProgramNotifications.h"
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
#include "Common/Cpp/ColoredText.h"
#include "CommonFramework/VideoPipeline/VideoFeed.h"
#include "CommonTools/Async/InferenceRoutines.h"
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
Expand Down
2 changes: 2 additions & 0 deletions SerialPrograms/cmake/SourceFiles.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ file(GLOB LIBRARY_SOURCES
../Common/Cpp/CancellableScope.h
../Common/Cpp/Color.cpp
../Common/Cpp/Color.h
../Common/Cpp/ColoredText.cpp
../Common/Cpp/ColoredText.h
../Common/Cpp/Concurrency/AsyncTask.h
../Common/Cpp/Concurrency/Backends/AsyncTask_Default.h
../Common/Cpp/Concurrency/Backends/Thread_Qt.tpp
Expand Down
Loading