Better UI Scaling
This commit is contained in:
parent
cfac7d0a12
commit
814217a259
@ -53,6 +53,7 @@
|
|||||||
* `Proper Entity Shading` (Enabled By Default)
|
* `Proper Entity Shading` (Enabled By Default)
|
||||||
* `Fix Sugar Position In Hand` (Enabled By Default)
|
* `Fix Sugar Position In Hand` (Enabled By Default)
|
||||||
* `Fix Reloading Textures On Resize` (Enabled By Default)
|
* `Fix Reloading Textures On Resize` (Enabled By Default)
|
||||||
|
* `Improved UI Scaling` (Enabled By Default)
|
||||||
* Existing Functionality (All Enabled By Default)
|
* Existing Functionality (All Enabled By Default)
|
||||||
* `Fix Screen Rendering When Hiding HUD`
|
* `Fix Screen Rendering When Hiding HUD`
|
||||||
* `Sanitize Usernames`
|
* `Sanitize Usernames`
|
||||||
|
BIN
images/start.png
BIN
images/start.png
Binary file not shown.
Before Width: | Height: | Size: 115 KiB After Width: | Height: | Size: 125 KiB |
@ -1,5 +1,6 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
#include <libreborn/util.h>
|
#include <libreborn/util.h>
|
||||||
|
|
||||||
@ -138,14 +139,16 @@ 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
|
||||||
std::string scale_format = "%i";
|
const int precision = std::floor(state.gui_scale) == state.gui_scale ? 0 : 1;
|
||||||
scale_format += 'x';
|
std::string scale_format = "%." + std::to_string(precision) + "fx";
|
||||||
if (state.gui_scale <= AUTO_GUI_SCALE) {
|
if (state.gui_scale <= AUTO_GUI_SCALE) {
|
||||||
scale_format = "Auto";
|
scale_format = "Auto";
|
||||||
}
|
}
|
||||||
int gui_scale_int = int(state.gui_scale);
|
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;
|
||||||
}
|
}
|
||||||
|
@ -65,3 +65,6 @@ 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);
|
@ -44,6 +44,7 @@ CATEGORY User Interface
|
|||||||
TRUE Improved Button Hover Behavior
|
TRUE Improved Button Hover Behavior
|
||||||
TRUE Classic Item Count UI
|
TRUE Classic Item Count UI
|
||||||
TRUE Click Buttons On Mouse Down
|
TRUE Click Buttons On Mouse Down
|
||||||
|
TRUE Improved UI Scaling
|
||||||
CATEGORY Rendering
|
CATEGORY Rendering
|
||||||
CATEGORY Optimizations
|
CATEGORY Optimizations
|
||||||
TRUE Optimized Chunk Sorting
|
TRUE Optimized Chunk Sorting
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
#include <libreborn/util.h>
|
#include <libreborn/util.h>
|
||||||
#include <libreborn/config.h>
|
#include <libreborn/config.h>
|
||||||
@ -135,3 +136,8 @@ 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;
|
||||||
|
}
|
@ -1,8 +1,11 @@
|
|||||||
#include <libreborn/patch.h>
|
#include <libreborn/patch.h>
|
||||||
#include <libreborn/env.h>
|
#include <libreborn/env.h>
|
||||||
|
#include <libreborn/util.h>
|
||||||
|
|
||||||
#include <symbols/minecraft.h>
|
#include <symbols/minecraft.h>
|
||||||
|
|
||||||
|
#include <media-layer/core.h>
|
||||||
|
|
||||||
#include <GLES/gl.h>
|
#include <GLES/gl.h>
|
||||||
#include <SDL/SDL.h>
|
#include <SDL/SDL.h>
|
||||||
|
|
||||||
@ -245,6 +248,29 @@ static void LocalPlayer_openTextEdit_injection(__attribute__((unused)) LocalPlay
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Better GUI Scaling
|
||||||
|
static void set_gui_scale(const float new_scale) {
|
||||||
|
union {
|
||||||
|
float a;
|
||||||
|
void *b;
|
||||||
|
} pun = {};
|
||||||
|
pun.a = new_scale;
|
||||||
|
patch_address((void *) 0x17520, pun.b);
|
||||||
|
}
|
||||||
|
static float calculate_scale(const float value, const float default_value) {
|
||||||
|
constexpr float initial_scale = 2.5f;
|
||||||
|
const float scale = initial_scale * (value / default_value);
|
||||||
|
return step_value(scale);
|
||||||
|
}
|
||||||
|
static void Minecraft_setSize_injection(Minecraft_setSize_t original, Minecraft *self, const int width, const int height) {
|
||||||
|
// Calculate Scale
|
||||||
|
const float a = calculate_scale(float(width), DEFAULT_WIDTH);
|
||||||
|
const float b = calculate_scale(float(height), DEFAULT_HEIGHT);
|
||||||
|
set_gui_scale(std::min(a, b));
|
||||||
|
// Call Original Method
|
||||||
|
original(self, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
// Init
|
// Init
|
||||||
void _init_misc_ui() {
|
void _init_misc_ui() {
|
||||||
// Food Overlay
|
// Food Overlay
|
||||||
@ -303,18 +329,24 @@ void _init_misc_ui() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Custom GUI Scale
|
// Custom GUI Scale
|
||||||
|
bool patch_gui_scaling = false;
|
||||||
const char *gui_scale_str = getenv(MCPI_GUI_SCALE_ENV);
|
const char *gui_scale_str = getenv(MCPI_GUI_SCALE_ENV);
|
||||||
if (gui_scale_str != nullptr) {
|
if (gui_scale_str != nullptr) {
|
||||||
float gui_scale;
|
float gui_scale;
|
||||||
env_value_to_obj(gui_scale, gui_scale_str);
|
env_value_to_obj(gui_scale, gui_scale_str);
|
||||||
if (gui_scale > 0) {
|
if (gui_scale > 0) {
|
||||||
|
patch_gui_scaling = true;
|
||||||
|
set_gui_scale(gui_scale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (feature_has("Improved UI Scaling", server_disabled) && !patch_gui_scaling) {
|
||||||
|
overwrite_calls(Minecraft_setSize, Minecraft_setSize_injection);
|
||||||
|
patch_gui_scaling = true;
|
||||||
|
}
|
||||||
|
if (patch_gui_scaling) {
|
||||||
unsigned char nop_patch[4] = {0x00, 0xf0, 0x20, 0xe3}; // "nop"
|
unsigned char nop_patch[4] = {0x00, 0xf0, 0x20, 0xe3}; // "nop"
|
||||||
patch((void *) 0x173e8, nop_patch);
|
patch((void *) 0x173e8, nop_patch);
|
||||||
patch((void *) 0x173f0, nop_patch);
|
patch((void *) 0x173f0, nop_patch);
|
||||||
uint32_t gui_scale_raw;
|
|
||||||
memcpy(&gui_scale_raw, &gui_scale, sizeof (gui_scale_raw));
|
|
||||||
patch_address((void *) 0x17520, (void *) gui_scale_raw);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't Wrap Text On '\r' Or '\t' Because They Are Actual Characters In MCPI
|
// Don't Wrap Text On '\r' Or '\t' Because They Are Actual Characters In MCPI
|
||||||
|
@ -17,6 +17,7 @@ method LevelStorageSource *getLevelSource() = 0x16e84;
|
|||||||
method void handleMouseDown(int param_1, bool can_destroy) = 0x1584c;
|
method void handleMouseDown(int param_1, bool can_destroy) = 0x1584c;
|
||||||
method void handleBuildAction(uint *build_action_intention) = 0x15920;
|
method void handleBuildAction(uint *build_action_intention) = 0x15920;
|
||||||
method void joinMultiplayer(const PingedCompatibleServer &server) = 0x165f4;
|
method void joinMultiplayer(const PingedCompatibleServer &server) = 0x165f4;
|
||||||
|
method void setSize(int width, int height) = 0x173a4;
|
||||||
|
|
||||||
virtual-method void update() = 0x24;
|
virtual-method void update() = 0x24;
|
||||||
virtual-method int handleBack(bool do_nothing) = 0x34;
|
virtual-method int handleBack(bool do_nothing) = 0x34;
|
||||||
|
Loading…
Reference in New Issue
Block a user