Skip to content

Commit

Permalink
Add integer scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
Crystalwarrior committed Jul 21, 2024
1 parent 0e556a2 commit 91a1dab
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 29 deletions.
2 changes: 2 additions & 0 deletions include/aoapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class AOApplication : public QApplication {
Courtroom *w_courtroom;
AttorneyOnline::Discord *discord;

QFont default_font;

bool lobby_constructed = false;
bool courtroom_constructed = false;

Expand Down
3 changes: 3 additions & 0 deletions include/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class Options {
QString theme() const;
void setTheme(QString value);

int themeScalingFactor() const;
void setThemeScalingFactor(int value);

// Returns the value of oocname in config.ini
QString oocName() const;
void setOocName(QString value);
Expand Down
1 change: 1 addition & 0 deletions include/widgets/aooptionsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class AOOptionsDialog : public QDialog {
QWidget *ui_settings_widget;
QComboBox *ui_theme_combobox;
QComboBox *ui_subtheme_combobox;
QSpinBox *ui_theme_scaling_factor_sb;
QPushButton *ui_theme_reload_button;
QPushButton *ui_theme_folder_button;
QCheckBox *ui_evidence_double_click_cb;
Expand Down
35 changes: 28 additions & 7 deletions resource/ui/options_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>473</width>
<width>522</width>
<height>415</height>
</rect>
</property>
Expand Down Expand Up @@ -39,9 +39,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-393</y>
<width>412</width>
<height>729</height>
<y>-310</y>
<width>466</width>
<height>750</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
Expand Down Expand Up @@ -349,9 +349,13 @@
</widget>
</item>
<item row="18" column="1">
<widget class="QComboBox" name="scaling_combobox"/>
<widget class="QComboBox" name="scaling_combobox">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
</widget>
</item>
<item row="19" column="0" colspan="2">
<item row="20" column="0" colspan="2">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
Expand All @@ -367,7 +371,7 @@
</property>
</spacer>
</item>
<item row="20" column="0" colspan="2">
<item row="21" column="0" colspan="2">
<widget class="QWidget" name="gridWidget" native="true">
<layout class="QGridLayout" name="checkboxLayout">
<property name="sizeConstraint">
Expand Down Expand Up @@ -712,6 +716,23 @@
</layout>
</widget>
</item>
<item row="19" column="0">
<widget class="QLabel" name="theme_scaling_factor_lbl">
<property name="toolTip">
<string>The factor by which to scale the size of the UI</string>
</property>
<property name="text">
<string>UI Scaling Factor:</string>
</property>
</widget>
</item>
<item row="19" column="1">
<widget class="QSpinBox" name="theme_scaling_factor_sb">
<property name="value">
<number>1</number>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
Expand Down
17 changes: 11 additions & 6 deletions src/aocharbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,28 @@ AOCharButton::AOCharButton(QWidget *parent, AOApplication *p_ao_app, int x_pos,

taken = is_taken;

this->resize(60, 60);
int size = 60 * Options::getInstance().themeScalingFactor();
int selector_size = 62 * Options::getInstance().themeScalingFactor();

this->resize(size, size);
this->move(x_pos, y_pos);

ui_taken = new AOImage(this, ao_app, true);
ui_taken->resize(60, 60);
ui_taken->resize(size, size);
ui_taken->set_image("char_taken");
ui_taken->setAttribute(Qt::WA_TransparentForMouseEvents);
ui_taken->hide();

ui_passworded = new AOImage(this, ao_app, true);
ui_passworded->resize(60, 60);
ui_passworded->resize(size, size);
ui_passworded->set_image("char_passworded");
ui_passworded->setAttribute(Qt::WA_TransparentForMouseEvents);
ui_passworded->hide();

ui_selector = new AOImage(parent, ao_app, true);
ui_selector->resize(62, 62);
ui_selector->move(x_pos - 1, y_pos - 1);
ui_selector->resize(selector_size, selector_size);
int offset = Options::getInstance().themeScalingFactor();
ui_selector->move(x_pos - offset, y_pos - offset);
ui_selector->set_image("char_selector");
ui_selector->setAttribute(Qt::WA_TransparentForMouseEvents);
ui_selector->hide();
Expand Down Expand Up @@ -83,7 +87,8 @@ void AOCharButton::enterEvent(QEvent *e)
void AOCharButton::enterEvent(QEnterEvent *e)
#endif
{
ui_selector->move(this->x() - 1, this->y() - 1);
int offset = Options::getInstance().themeScalingFactor();
ui_selector->move(this->x() - offset, this->y() - offset);
ui_selector->raise();
ui_selector->show();

Expand Down
13 changes: 8 additions & 5 deletions src/charselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,13 @@ void Courtroom::set_char_select_page()
QPoint f_spacing =
ao_app->get_button_spacing("char_button_spacing", "courtroom_design.ini");

int s_button_size = button_width * Options::getInstance().themeScalingFactor();

char_columns =
((ui_char_buttons->width() - button_width) / (f_spacing.x() + button_width)) +
((ui_char_buttons->width() - s_button_size) / (f_spacing.x() + s_button_size)) +
1;
char_rows = ((ui_char_buttons->height() - button_height) /
(f_spacing.y() + button_height)) +
char_rows = ((ui_char_buttons->height() - s_button_size) /
(f_spacing.y() + s_button_size)) +
1;

max_chars_on_page = char_columns * char_rows;
Expand Down Expand Up @@ -289,9 +291,10 @@ void Courtroom::put_button_in_place(int starting, int chars_on_this_page)
int y_mod_count = 0;

int startout = starting;
int size = button_width * Options::getInstance().themeScalingFactor();
for (int n = starting; n < startout + chars_on_this_page; ++n) {
int x_pos = (button_width + f_spacing.x()) * x_mod_count;
int y_pos = (button_height + f_spacing.y()) * y_mod_count;
int x_pos = (size + f_spacing.x()) * x_mod_count;
int y_pos = (size + f_spacing.y()) * y_mod_count;

ui_char_button_list_filtered.at(n)->move(x_pos, y_pos);
ui_char_button_list_filtered.at(n)->show();
Expand Down
7 changes: 6 additions & 1 deletion src/courtroom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,11 @@ void Courtroom::set_widgets()

void Courtroom::set_fonts(QString p_char)
{
QFont new_font = ao_app->default_font;
int new_font_size = new_font.pointSize() * Options::getInstance().themeScalingFactor();
new_font.setPointSize(new_font_size);
ao_app->setFont(new_font);

set_font(ui_vp_showname, "", "showname", p_char);
set_font(ui_vp_message, "", "message", p_char);
set_font(ui_ic_chatlog, "", "ic_chatlog", p_char);
Expand All @@ -1495,7 +1500,7 @@ void Courtroom::set_font(QWidget *widget, QString class_name,
QString design_file = "courtroom_fonts.ini";
if (f_pointsize <= 0)
f_pointsize =
ao_app->get_design_element(p_identifier, design_file, ao_app->get_chat(p_char)).toInt();
ao_app->get_design_element(p_identifier, design_file, ao_app->get_chat(p_char)).toInt() * Options::getInstance().themeScalingFactor();
if (font_name == "")
font_name =
ao_app->get_design_element(p_identifier + "_font", design_file, ao_app->get_chat(p_char));
Expand Down
8 changes: 8 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ int main(int argc, char *argv[])
AOApplication::addLibraryPath(AOApplication::applicationDirPath() + "/lib");
QResource::registerResource(main_app.get_asset("themes/" + Options::getInstance().theme() + ".rcc"));

QFont main_font = main_app.font();
main_app.default_font = main_font;

QFont new_font = main_font;
int new_font_size = main_app.default_font.pointSize() * Options::getInstance().themeScalingFactor();
new_font.setPointSize(new_font_size);
main_app.setFont(new_font);

QFontDatabase fontDatabase;
QDirIterator it(get_base_path() + "fonts",
QDirIterator::Subdirectories);
Expand Down
11 changes: 11 additions & 0 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ QString Options::theme() const

void Options::setTheme(QString value) { config.setValue("theme", value); }

int Options::themeScalingFactor() const
{
int value = config.value("theme_scaling_factor", "1").toInt();
if (value <= 0) {
value = 1;
}
return value;
}

void Options::setThemeScalingFactor(int value) { config.setValue("theme_scaling_factor", value); }

int Options::blipRate() const { return config.value("blip_rate", 2).toInt(); }

void Options::setBlipRate(int value) { config.setValue("blip_rate", value); }
Expand Down
17 changes: 8 additions & 9 deletions src/text_file_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,8 @@ QPoint AOApplication::get_button_spacing(QString p_identifier, QString p_file)

if (sub_line_elements.size() < 2)
return return_value;

return_value.setX(sub_line_elements.at(0).toInt());
return_value.setY(sub_line_elements.at(1).toInt());
return_value.setX(sub_line_elements.at(0).toInt() * Options::getInstance().themeScalingFactor());
return_value.setY(sub_line_elements.at(1).toInt() * Options::getInstance().themeScalingFactor());

return return_value;
}
Expand All @@ -188,21 +187,21 @@ pos_size_type AOApplication::get_element_dimensions(QString p_identifier,

QStringList sub_line_elements = f_result.split(",");

pos_size_type return_value;
if (sub_line_elements.size() < 4) {
pos_size_type return_value;
return_value.x = 0;
return_value.y = 0;
return_value.width = -1;
return_value.height = -1;
return return_value;
}

pos_size_type return_value;
int scale = Options::getInstance().themeScalingFactor();

return_value.x = sub_line_elements[0].toInt();
return_value.y = sub_line_elements[1].toInt();
return_value.width = sub_line_elements[2].toInt();
return_value.height = sub_line_elements[3].toInt();
return_value.x = sub_line_elements.at(0).toInt() * scale;
return_value.y = sub_line_elements.at(1).toInt() * scale;
return_value.width = sub_line_elements.at(2).toInt() * scale;
return_value.height = sub_line_elements.at(3).toInt() * scale;

return return_value;
}
Expand Down
9 changes: 8 additions & 1 deletion src/widgets/aooptionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,10 @@ void AOOptionsDialog::updateValues()

void AOOptionsDialog::savePressed()
{
bool l_reload_theme_required = (ui_theme_combobox->currentText() != Options::getInstance().theme());
bool l_reload_theme_required =
(ui_theme_combobox->currentText() != Options::getInstance().theme()) ||
(ui_theme_scaling_factor_sb->value() !=
Options::getInstance().themeScalingFactor());
for (const OptionEntry &entry : qAsConst(optionEntries)) {
entry.save();
}
Expand Down Expand Up @@ -401,6 +404,7 @@ void AOOptionsDialog::setupUI()
QDesktopServices::openUrl(QUrl::fromLocalFile(p_path));
});

FROM_UI(QSpinBox, theme_scaling_factor_sb)
FROM_UI(QCheckBox, animated_theme_cb)
FROM_UI(QSpinBox, stay_time_spinbox)
FROM_UI(QCheckBox, instant_objection_cb)
Expand Down Expand Up @@ -434,6 +438,9 @@ void AOOptionsDialog::setupUI()
FROM_UI(QCheckBox, asset_streaming_cb)
FROM_UI(QCheckBox, image_streaming_cb)

registerOption<QSpinBox, int>("theme_scaling_factor_sb",
&Options::themeScalingFactor,
&Options::setThemeScalingFactor);
registerOption<QCheckBox, bool>("animated_theme_cb",
&Options::animatedThemeEnabled,
&Options::setAnimatedThemeEnabled);
Expand Down

0 comments on commit 91a1dab

Please sign in to comment.