Skip to content

Commit b940333

Browse files
committed
feat: dark theme support
1 parent 145ffaa commit b940333

20 files changed

Lines changed: 122 additions & 104 deletions

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ qt_add_resources(${PROJECT_NAME} "resources"
2121
res/fonts/FontAwesomeSolid6.otf
2222
res/themes/light.json
2323
res/themes/dark.json
24+
res/about_logo_dark.png
25+
res/about_logo.png
2426
res/logo_dark.png
2527
res/logo.png
2628
)

res/about_logo.png

14.4 KB
Loading

res/about_logo_dark.png

14.1 KB
Loading

res/logo.png

-66 Bytes
Loading

res/logo_dark.png

264 Bytes
Loading

res/themes/dark.json

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,49 @@
11
{
22
"Shadow": "#2b2b2b",
3-
"Base": "#303030",
4-
"AlternateBase": "#3b3b3b",
5-
"Text": "#ecf0f1",
6-
"Window": "#3b3b3b",
7-
"WindowText": "#ecf0f1",
8-
"Button": "#3b3b3b",
9-
"ButtonText": "#ecf0f1",
10-
"Highlight": "#d95459",
11-
"HighlightedText": "#ecf0f1",
12-
"ToolTipBase": "#3b3b3b",
13-
"ToolTipText": "#ecf0f1",
14-
15-
"foreground": "#ecf0f1",
16-
"background": "#303030",
17-
"seek": "#3b3b3b",
18-
19-
"highlight_fg": "#3b3b3b",
20-
"highlight_bg": "#ef717a",
21-
22-
"segment": "#f47cc3",
23-
"function": "#3498db",
24-
"type": "#d95459",
25-
26-
"location": "#6a89b4",
27-
"number": "#bdc3c7",
28-
"reg": "#27ae60",
29-
"string": "#a38671",
30-
31-
"comment": "#2ecc71",
32-
33-
"stop": "#c0392b",
34-
"jump": "#5065a1",
35-
"jump_cond": "#e67e22",
3+
"Base": "#2f2f2f",
4+
"Text": "#f4f1d6",
5+
"Window": "#292929",
6+
"WindowText": "#f4f1d6",
7+
"Button": "#2f2f2f",
8+
"ButtonText": "#f4f1d6",
9+
"Highlight": "#ef717a",
10+
"HighlightedText": "#2f2f2f",
11+
"ToolTipBase": "#2f2f2f",
12+
"ToolTipText": "#f4f1d6",
13+
14+
"foreground": "#f4f1d6",
15+
"background": "#2f2f2f",
16+
"seek": "#202020",
17+
18+
"highlight_fg": "#2f2f2f",
19+
"highlight_bg": "#ff7575",
20+
"selection_fg": "#2f2f2f",
21+
"selection_bg": "#f4f1d6",
22+
23+
"segment": "#e28ee6",
24+
"function": "#13c3a0",
25+
"type": "#90caf9",
26+
27+
"location": "#7dafff",
28+
"number": "#ffb22e",
29+
"reg": "#96d952",
30+
"string": "#67bd61",
31+
32+
"comment": "#757575",
33+
34+
"stop": "#ff7575",
35+
"jump": "#4ce0c5",
36+
"jump_cond": "#c03131",
3637
"call": "#2ecc71",
37-
"call_cond": "#e74c3c",
38+
"call_cond": "#c03131",
3839

39-
"success": "#2ecc71",
40-
"fail": "#e74c3c",
41-
"warning": "#ffcd02",
42-
"muted": "#7f8c8d",
40+
"success": "#67bd61",
41+
"fail": "#ff7575",
42+
"warning": "#ffb22e",
43+
"muted": "#757575",
4344

44-
"flag_code": "#3366aa",
45-
"flag_data": "#337733",
45+
"flag_code": "#7dafff",
46+
"flag_data": "#67bd61",
4647

47-
"graph_bg": "#262626"
48+
"graph_bg": "#202020"
4849
}

src/dialogs/about.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55

66
namespace {
77

8-
constexpr int SCALE_LOGO = 128;
9-
constexpr int SCALE_TEXT = 32;
10-
118
void compile_config(QTextBrowser* txb) {
129
const QString VERSION_CONTENT = R"(
1310
<div><b>Qt Version:</b> %1</div>
@@ -189,9 +186,8 @@ void compile_commands(QTextBrowser* txb) {
189186
AboutDialog::AboutDialog(QWidget* parent): QDialog{parent}, m_ui{this} {
190187
this->setWindowTitle("About REDasm");
191188

192-
m_ui.lbllogo->setPixmap(utils::get_logo().scaledToHeight(SCALE_LOGO));
193-
m_ui.lbltitle->setText("The OpenSource Disassembler");
194-
m_ui.lbltitle->setStyleSheet(QString{"font-size: %1px"}.arg(SCALE_TEXT));
189+
m_ui.lblaboutlogo->setAlignment(Qt::AlignCenter);
190+
m_ui.lblaboutlogo->setPixmap(utils::get_about_logo());
195191

196192
compile_config(m_ui.txbconfig);
197193
compile_modules(m_ui.txbmodules);

src/main.cpp

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "mainwindow.h"
2-
#include "support/surfacerenderer.h"
32
#include "support/themeprovider.h"
43
#include "support/utils.h"
54
#include <QApplication>
@@ -11,12 +10,6 @@
1110

1211
namespace {
1312

14-
void on_log(RDLogLevel level, const char* tag, const char* msg,
15-
void* userdata) {
16-
auto* mw = reinterpret_cast<MainWindow*>(userdata);
17-
mw->log(level, QString::fromUtf8(tag), QString::fromUtf8(msg));
18-
}
19-
2013
void configure_searchpaths() {
2114
#if !defined(_WIN32)
2215
const char* appimage_dir = std::getenv("APPDIR");
@@ -124,29 +117,22 @@ int main(int argc, char** argv) {
124117
app.setApplicationName("redasm");
125118
app.setApplicationDisplayName(QString{"REDasm %1"}.arg(rd_version()));
126119

127-
theme_provider::apply_theme();
128-
surface_renderer::init();
129120
int res = 0;
130121

131122
{ // Scoping makes sure that widgets and context are freed before deinit
132-
MainWindow mw;
133-
mw.show();
134-
135-
configure_searchpaths();
136-
rd_set_log_callback(on_log, &mw);
123+
theme_provider::init();
137124

138125
QVector<const char*> kb_paths = get_kb_searchpaths();
139-
140126
RDInitParams params = {};
141127
params.kb_paths = kb_paths.data();
142-
rd_init(&params);
143128

129+
MainWindow mw{params};
130+
configure_searchpaths();
144131
load_modules();
145132

133+
mw.show();
146134
res = app.exec();
147-
rd_set_log_callback(nullptr, nullptr);
148135
}
149136

150-
rd_deinit();
151137
return res;
152138
}

src/mainwindow.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "models/segments.h"
1414
#include "models/strings.h"
1515
#include "support/actions.h"
16+
#include "support/surfacerenderer.h"
1617
// #include "rdui/qtui.h"
1718
#include "statusbar.h"
1819
#include "support/settings.h"
@@ -24,9 +25,24 @@
2425
#include <QMessageBox>
2526
#include <QMimeData>
2627

27-
MainWindow::MainWindow(QWidget* parent): QMainWindow{parent}, m_ui{this} {
28+
namespace {
29+
30+
void on_log(RDLogLevel level, const char* tag, const char* msg,
31+
void* userdata) {
32+
auto* mw = reinterpret_cast<MainWindow*>(userdata);
33+
mw->log(level, QString::fromUtf8(tag), QString::fromUtf8(msg));
34+
}
35+
36+
} // namespace
37+
38+
MainWindow::MainWindow(const RDInitParams& params, QWidget* parent)
39+
: QMainWindow{parent}, m_ui{this} {
2840
utils::mainwindow = this;
2941

42+
rd_set_log_callback(on_log, this);
43+
surface_renderer::init();
44+
rd_init(&params);
45+
3046
this->setWindowIcon(utils::get_logo());
3147
this->load_window_state();
3248
this->load_recents();
@@ -103,6 +119,12 @@ MainWindow::MainWindow(QWidget* parent): QMainWindow{parent}, m_ui{this} {
103119
});
104120
}
105121

122+
MainWindow::~MainWindow() {
123+
delete this->context_view(); // delete immediately
124+
rd_deinit();
125+
rd_set_log_callback(nullptr, nullptr);
126+
}
127+
106128
void MainWindow::dragEnterEvent(QDragEnterEvent* e) {
107129
if(!e->mimeData()->hasUrls()) return;
108130
e->acceptProposedAction();

src/mainwindow.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ class MainWindow: public QMainWindow {
88
Q_OBJECT
99

1010
public:
11-
explicit MainWindow(QWidget* parent = nullptr);
11+
explicit MainWindow(const RDInitParams& params, QWidget* parent = nullptr);
12+
~MainWindow() override;
1213
[[nodiscard]] ContextView* context_view() const;
1314
void log(RDLogLevel level, const QString& tag, const QString& msg);
1415

0 commit comments

Comments
 (0)