Embrace Integer Scaling

This commit is contained in:
TheBrokenRail 2024-11-30 05:33:50 -05:00
parent 814217a259
commit 0ccf578478
7 changed files with 21 additions and 22 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 125 KiB

After

Width:  |  Height:  |  Size: 133 KiB

View File

@ -139,16 +139,13 @@ void ConfigurationUI::draw_main() const {
state.render_distance = render_distances[render_distance_index]; state.render_distance = render_distances[render_distance_index];
} }
// UI Scale // UI Scale
const int precision = std::floor(state.gui_scale) == state.gui_scale ? 0 : 1; int gui_scale_int = int(state.gui_scale); // Fractional GUI Scales Are Messy
std::string scale_format = "%." + std::to_string(precision) + "fx"; std::string scale_format = "%ix";
if (state.gui_scale <= AUTO_GUI_SCALE) { if (gui_scale_int <= AUTO_GUI_SCALE) {
scale_format = "Auto"; scale_format = "Auto";
} }
char display_gui_scale[64]; if (ImGui::SliderInt(labels[2], &gui_scale_int, 0, 8, scale_format.c_str())) {
sprintf(display_gui_scale, scale_format.c_str(), state.gui_scale); state.gui_scale = float(gui_scale_int);
float new_gui_scale = state.gui_scale;
if (ImGui::SliderFloat(labels[2], &new_gui_scale, 0, 8, display_gui_scale, ImGuiSliderFlags_NoRoundToFormat)) {
state.gui_scale = step_value(new_gui_scale);
if (state.gui_scale < AUTO_GUI_SCALE) { if (state.gui_scale < AUTO_GUI_SCALE) {
state.gui_scale = AUTO_GUI_SCALE; state.gui_scale = AUTO_GUI_SCALE;
} }

View File

@ -64,7 +64,4 @@ std::string format_time(const char *fmt, int time);
// Default MCPI Port // Default MCPI Port
// This Macro DOES NOT Control MCPI // This Macro DOES NOT Control MCPI
#define DEFAULT_MULTIPLAYER_PORT 19132 #define DEFAULT_MULTIPLAYER_PORT 19132
// Step Value
float step_value(float value, float step = 0.5f);

View File

@ -135,9 +135,4 @@ std::string format_time(const char *fmt) {
std::string format_time(const char *fmt, const int time) { std::string format_time(const char *fmt, const int time) {
// This Will Break In 2038 // This Will Break In 2038
return _format_time(fmt, time); return _format_time(fmt, time);
}
// Step
float step_value(const float value, const float step) {
return std::round(value / step) * step;
} }

View File

@ -1,3 +1,5 @@
#include <cmath>
#include <libreborn/patch.h> #include <libreborn/patch.h>
#include <libreborn/env.h> #include <libreborn/env.h>
#include <libreborn/util.h> #include <libreborn/util.h>
@ -258,9 +260,16 @@ static void set_gui_scale(const float new_scale) {
patch_address((void *) 0x17520, pun.b); patch_address((void *) 0x17520, pun.b);
} }
static float calculate_scale(const float value, const float default_value) { static float calculate_scale(const float value, const float default_value) {
constexpr float initial_scale = 2.5f; // y = mx + b
const float scale = initial_scale * (value / default_value); const std::pair point_one = {default_value, 2.25f};
return step_value(scale); const std::pair point_two = {default_value * 2, 4.5f};
const float slope = (point_one.second - point_two.second) / (point_one.first - point_two.first);
const float intercept = point_one.second - (slope * point_one.first);
// Calculate
float scale = (slope * value) + intercept;
scale = std::round(scale);
scale = std::max(scale, 1.0f);
return scale;
} }
static void Minecraft_setSize_injection(Minecraft_setSize_t original, Minecraft *self, const int width, const int height) { static void Minecraft_setSize_injection(Minecraft_setSize_t original, Minecraft *self, const int width, const int height) {
// Calculate Scale // Calculate Scale

View File

@ -25,7 +25,7 @@ minecraft-pi-reborn --default --no-cache &
PID="$!" PID="$!"
# Screenshot # Screenshot
sleep 2 sleep 3
gnome-screenshot --window --file=images/start.png gnome-screenshot --window --file=images/start.png
# Kill # Kill

View File

@ -1,3 +1,4 @@
method int width(const std::string &string) = 0x24d4c; method int width(const std::string &string) = 0x24d4c;
method void draw(const std::string &string, float x, float y, uint color) = 0x250e0; method void draw(const std::string &string, float x, float y, uint color) = 0x250e0;
method void drawShadow(const std::string &string, float x, float y, uint color) = 0x250ec; method void drawShadow(const std::string &string, float x, float y, uint color) = 0x250ec;
method void drawSlow(const char *text, float x, float y, uint color, bool param_1) = 0x24fa8;