mirror of
https://github.com/Lorenzooone/cc3dsfs.git
synced 2026-03-21 17:55:00 -05:00
Add Text Scaling factor
This commit is contained in:
parent
cea5a4e40b
commit
3a63c04f7f
|
|
@ -28,6 +28,7 @@ struct ScreenInfo {
|
|||
int top_scaling, bot_scaling;
|
||||
bool bfi;
|
||||
double bfi_divider;
|
||||
double menu_scaling_factor;
|
||||
};
|
||||
|
||||
struct DisplayData {
|
||||
|
|
@ -67,6 +68,7 @@ public:
|
|||
~TextRectangle();
|
||||
void setSize(int width, int height);
|
||||
void setRectangleKind(TextKind kind);
|
||||
void setTextFactor(float size_multiplier);
|
||||
void setDuration(float on_seconds);
|
||||
void startTimer(bool do_start);
|
||||
void setProportionalBox(bool proportional_box);
|
||||
|
|
@ -193,6 +195,7 @@ private:
|
|||
int get_screen_corner_modifier_x(int rotation, int width);
|
||||
int get_screen_corner_modifier_y(int rotation, int height);
|
||||
void print_notification_on_off(std::string base_text, bool value);
|
||||
void print_notification_float(std::string base_text, float value, int decimals);
|
||||
void poll_window();
|
||||
void prepare_screen_rendering();
|
||||
bool window_needs_work();
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include <chrono>
|
||||
|
||||
#define BASE_PIXEL_FONT_HEIGHT 24
|
||||
|
||||
TextRectangle::TextRectangle(bool font_load_success, sf::Font &text_font) {
|
||||
this->font_load_success = font_load_success;
|
||||
this->setSize(1, 1);
|
||||
|
|
@ -42,6 +44,11 @@ void TextRectangle::setRectangleKind(TextKind kind) {
|
|||
this->future_data.kind = kind;
|
||||
}
|
||||
|
||||
void TextRectangle::setTextFactor(float size_multiplier) {
|
||||
int new_pixel_height = BASE_PIXEL_FONT_HEIGHT * size_multiplier;
|
||||
this->future_data.font_pixel_height = new_pixel_height;
|
||||
}
|
||||
|
||||
void TextRectangle::setDuration(float on_seconds) {
|
||||
this->future_data.duration = on_seconds;
|
||||
}
|
||||
|
|
@ -124,7 +131,7 @@ void TextRectangle::reset_data(TextData &data) {
|
|||
data.proportional_box = true;
|
||||
data.printed_text = "Sample Text";
|
||||
data.duration = 2.5;
|
||||
data.font_pixel_height = 24;
|
||||
data.font_pixel_height = BASE_PIXEL_FONT_HEIGHT;
|
||||
}
|
||||
|
||||
void TextRectangle::setTextWithLineWrapping(int x_limit) {
|
||||
|
|
@ -182,7 +189,7 @@ void TextRectangle::updateText(int x_limit) {
|
|||
if((new_width != this->width) || (new_height != this->height))
|
||||
this->setSize(new_width, new_height);
|
||||
if(this->loaded_data.proportional_box) {
|
||||
this->actual_text.setPosition(5, 0);
|
||||
this->actual_text.setPosition((int)(5 * (((float)this->loaded_data.font_pixel_height) / BASE_PIXEL_FONT_HEIGHT)), 0);
|
||||
globalBounds = this->actual_text.getGlobalBounds();
|
||||
this->setSize(globalBounds.width + (globalBounds.left * 2), globalBounds.height + (globalBounds.top * 2));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include "frontend.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include <cmath>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include "font_ttf.h"
|
||||
|
|
@ -84,7 +85,7 @@ void WindowScreen::reload() {
|
|||
}
|
||||
|
||||
void WindowScreen::poll() {
|
||||
float old_scaling = 0.0;
|
||||
double old_scaling = 0.0;
|
||||
this->poll_window();
|
||||
while(!events_queue.empty()) {
|
||||
SFEvent event_data = events_queue.front();
|
||||
|
|
@ -146,7 +147,7 @@ void WindowScreen::poll() {
|
|||
if (this->m_info.scaling < 1.25)
|
||||
this->m_info.scaling = 1.0;
|
||||
if(old_scaling != this->m_info.scaling) {
|
||||
this->print_notification("Scaling: " + std::to_string(this->m_info.scaling));
|
||||
this->print_notification_float("Scaling", this->m_info.scaling, 1);
|
||||
this->future_operations.call_screen_settings_update = true;
|
||||
}
|
||||
break;
|
||||
|
|
@ -159,7 +160,7 @@ void WindowScreen::poll() {
|
|||
if (this->m_info.scaling > 44.75)
|
||||
this->m_info.scaling = 45.0;
|
||||
if(old_scaling != this->m_info.scaling) {
|
||||
this->print_notification("Scaling: " + std::to_string(this->m_info.scaling));
|
||||
this->print_notification_float("Scaling", this->m_info.scaling, 1);
|
||||
this->future_operations.call_screen_settings_update = true;
|
||||
}
|
||||
break;
|
||||
|
|
@ -252,6 +253,27 @@ void WindowScreen::poll() {
|
|||
|
||||
break;
|
||||
|
||||
case 'z':
|
||||
old_scaling = this->m_info.menu_scaling_factor;
|
||||
this->m_info.menu_scaling_factor -= 0.1;
|
||||
if(this->m_info.menu_scaling_factor < 0.35)
|
||||
this->m_info.menu_scaling_factor = 0.3;
|
||||
if(old_scaling != this->m_info.menu_scaling_factor) {
|
||||
this->print_notification_float("Menu Scaling", this->m_info.menu_scaling_factor, 1);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case 'x':
|
||||
old_scaling = this->m_info.menu_scaling_factor;
|
||||
this->m_info.menu_scaling_factor += 0.1;
|
||||
if(this->m_info.menu_scaling_factor > 4.95)
|
||||
this->m_info.menu_scaling_factor = 5.0;
|
||||
if(old_scaling != this->m_info.menu_scaling_factor) {
|
||||
this->print_notification_float("Menu Scaling", this->m_info.menu_scaling_factor, 1);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
audio_data->change_audio_mute();
|
||||
break;
|
||||
|
|
@ -362,6 +384,7 @@ void WindowScreen::draw(double frame_time, VideoOutputData* out_buf) {
|
|||
WindowScreen::reset_operations(future_operations);
|
||||
memcpy(this->saved_buf, out_buf, sizeof(VideoOutputData));
|
||||
loaded_info = m_info;
|
||||
this->notification->setTextFactor(this->loaded_info.menu_scaling_factor);
|
||||
this->notification->prepareRenderText();
|
||||
this->frame_time = frame_time;
|
||||
this->scheduled_work_on_window = this->window_needs_work();
|
||||
|
|
@ -462,6 +485,24 @@ void WindowScreen::print_notification_on_off(std::string base_text, bool value)
|
|||
this->print_notification(base_text + ": " + status_text);
|
||||
}
|
||||
|
||||
void WindowScreen::print_notification_float(std::string base_text, float value, int decimals) {
|
||||
float approx_factor = pow(0.1, decimals) * (0.5);
|
||||
int int_part = (int)(value + approx_factor);
|
||||
int dec_part = (int)((value + approx_factor - int_part) * pow(10, decimals));
|
||||
std::string status_text = std::to_string(int_part);
|
||||
|
||||
if(decimals > 0) {
|
||||
if(!dec_part) {
|
||||
status_text += ".";
|
||||
for(int i = 0; i < decimals; i++)
|
||||
status_text += "0";
|
||||
}
|
||||
else
|
||||
status_text += "." + std::to_string(dec_part);
|
||||
}
|
||||
this->print_notification(base_text + ": " + status_text);
|
||||
}
|
||||
|
||||
void WindowScreen::poll_window() {
|
||||
if(this->m_win.isOpen()) {
|
||||
sf::Event event;
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ void reset_screen_info(ScreenInfo &info) {
|
|||
info.bot_scaling = -1;
|
||||
info.bfi = false;
|
||||
info.bfi_divider = 2.0;
|
||||
info.menu_scaling_factor = 1.0;
|
||||
}
|
||||
|
||||
bool load_screen_info(std::string key, std::string value, std::string base, ScreenInfo &info) {
|
||||
|
|
@ -106,6 +107,14 @@ bool load_screen_info(std::string key, std::string value, std::string base, Scre
|
|||
info.bfi_divider = 1.0;
|
||||
return true;
|
||||
}
|
||||
if(key == (base + "menu_scaling_factor")) {
|
||||
info.menu_scaling_factor = std::stod(value);
|
||||
if(info.menu_scaling_factor < 0.3)
|
||||
info.menu_scaling_factor = 0.3;
|
||||
if(info.menu_scaling_factor > 5.0)
|
||||
info.menu_scaling_factor = 5.0;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -128,6 +137,7 @@ std::string save_screen_info(std::string base, const ScreenInfo &info) {
|
|||
out += base + "bot_scaling=" + std::to_string(info.bot_scaling) + "\n";
|
||||
out += base + "bfi=" + std::to_string(info.bfi) + "\n";
|
||||
out += base + "bfi_divider=" + std::to_string(info.bfi_divider) + "\n";
|
||||
out += base + "menu_scaling_factor=" + std::to_string(info.menu_scaling_factor) + "\n";
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user