mirror of
https://github.com/spice2x/spice2x.github.io.git
synced 2026-12-06 03:26:41 -08:00
clean up screen resize
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
1 parent
3d530bfee0
commit
69585ac43d
5 files changed
+207
-219
No files matched your search
@@ -1,6 +1,7 @@
|
||||
#include "screen_resize.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include "avs/game.h"
|
||||
#include "external/rapidjson/document.h"
|
||||
#include "external/rapidjson/pointer.h"
|
||||
@@ -99,21 +100,7 @@ namespace cfg {
|
||||
load_int_value(doc, root + prefix + "duplicate", duplicate);
|
||||
scene.duplicate = static_cast<cfg::ScreenDuplicateMode>(duplicate);
|
||||
|
||||
load_bool_value(doc, root + prefix + "split_mode", scene.split_mode);
|
||||
if (load_float_value(doc, root + prefix + "split_ratio", scene.split_ratio)) {
|
||||
scene.split_ratio = std::clamp(scene.split_ratio, 0.1f, 0.9f);
|
||||
}
|
||||
load_bool_value(doc, root + prefix + "split_swap_sides", scene.split_swap_sides);
|
||||
|
||||
auto load_split_region = [&](const std::string& sub, split_region_setting& region) {
|
||||
load_int_value(doc, root + prefix + sub + "/offset_x", region.offset_x);
|
||||
load_int_value(doc, root + prefix + sub + "/offset_y", region.offset_y);
|
||||
load_float_value(doc, root + prefix + sub + "/scale_x", region.scale_x);
|
||||
load_float_value(doc, root + prefix + sub + "/scale_y", region.scale_y);
|
||||
load_bool_value(doc, root + prefix + sub + "/keep_aspect_ratio", region.keep_aspect_ratio);
|
||||
};
|
||||
load_split_region("split_left", scene.split_left);
|
||||
load_split_region("split_right", scene.split_right);
|
||||
load_split_config(doc, root + prefix, scene.split);
|
||||
}
|
||||
this->need_surface_clean = true;
|
||||
|
||||
@@ -197,6 +184,70 @@ namespace cfg {
|
||||
return false;
|
||||
}
|
||||
|
||||
static void load_split_scale(
|
||||
const rapidjson::Document &doc, const std::string &path, float &scale) {
|
||||
const auto value = rapidjson::Pointer(path).Get(doc);
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
if (value->IsNumber()) {
|
||||
const double number = value->GetDouble();
|
||||
if (std::isfinite(number) && number >= split_region_setting::min_scale &&
|
||||
number <= split_region_setting::max_scale) {
|
||||
scale = static_cast<float>(number);
|
||||
return;
|
||||
}
|
||||
}
|
||||
log_warning("ScreenResize", "{} must be a number from {} to {}; using default",
|
||||
path, split_region_setting::min_scale, split_region_setting::max_scale);
|
||||
scale = split_region_setting::default_scale;
|
||||
}
|
||||
|
||||
void ScreenResize::load_split_region(
|
||||
rapidjson::Document &doc, const std::string &path, split_region_setting ®ion) {
|
||||
load_int_value(doc, path + "offset_x", region.offset_x);
|
||||
load_int_value(doc, path + "offset_y", region.offset_y);
|
||||
load_split_scale(doc, path + "scale_x", region.scale_x);
|
||||
load_split_scale(doc, path + "scale_y", region.scale_y);
|
||||
load_bool_value(doc, path + "keep_aspect_ratio", region.keep_aspect_ratio);
|
||||
}
|
||||
|
||||
void ScreenResize::load_split_config(
|
||||
rapidjson::Document &doc, const std::string &path, split_screen_setting &split) {
|
||||
load_bool_value(doc, path + "split_mode", split.enabled);
|
||||
const auto ratio = rapidjson::Pointer(path + "split_ratio").Get(doc);
|
||||
if (ratio) {
|
||||
if (ratio->IsNumber() && std::isfinite(ratio->GetDouble())) {
|
||||
split.ratio = static_cast<float>(std::clamp(
|
||||
ratio->GetDouble(), split_screen_setting::min_ratio,
|
||||
split_screen_setting::max_ratio));
|
||||
} else {
|
||||
log_warning("ScreenResize", "{}split_ratio must be a finite number", path);
|
||||
}
|
||||
}
|
||||
load_bool_value(doc, path + "split_swap_sides", split.swap_sides);
|
||||
load_split_region(doc, path + "split_left/", split.left);
|
||||
load_split_region(doc, path + "split_right/", split.right);
|
||||
}
|
||||
|
||||
static void save_split_region(
|
||||
rapidjson::Document &doc, const std::string &path, const split_region_setting ®ion) {
|
||||
rapidjson::Pointer(path + "offset_x").Set(doc, region.offset_x);
|
||||
rapidjson::Pointer(path + "offset_y").Set(doc, region.offset_y);
|
||||
rapidjson::Pointer(path + "scale_x").Set(doc, region.scale_x);
|
||||
rapidjson::Pointer(path + "scale_y").Set(doc, region.scale_y);
|
||||
rapidjson::Pointer(path + "keep_aspect_ratio").Set(doc, region.keep_aspect_ratio);
|
||||
}
|
||||
|
||||
static void save_split_config(
|
||||
rapidjson::Document &doc, const std::string &path, const split_screen_setting &split) {
|
||||
rapidjson::Pointer(path + "split_mode").Set(doc, split.enabled);
|
||||
rapidjson::Pointer(path + "split_ratio").Set(doc, split.ratio);
|
||||
rapidjson::Pointer(path + "split_swap_sides").Set(doc, split.swap_sides);
|
||||
save_split_region(doc, path + "split_left/", split.left);
|
||||
save_split_region(doc, path + "split_right/", split.right);
|
||||
}
|
||||
|
||||
void ScreenResize::config_save() {
|
||||
rapidjson::Document doc;
|
||||
std::string config = fileutils::text_read(this->config_path);
|
||||
@@ -231,19 +282,7 @@ namespace cfg {
|
||||
rapidjson::Pointer(root + prefix + "keep_aspect_ratio").Set(doc, scene.keep_aspect_ratio);
|
||||
rapidjson::Pointer(root + prefix + "duplicate").Set(doc, scene.duplicate);
|
||||
|
||||
rapidjson::Pointer(root + prefix + "split_mode").Set(doc, scene.split_mode);
|
||||
rapidjson::Pointer(root + prefix + "split_ratio").Set(doc, scene.split_ratio);
|
||||
rapidjson::Pointer(root + prefix + "split_swap_sides").Set(doc, scene.split_swap_sides);
|
||||
|
||||
auto save_split_region = [&](const std::string& sub, const split_region_setting& region) {
|
||||
rapidjson::Pointer(root + prefix + sub + "/offset_x").Set(doc, region.offset_x);
|
||||
rapidjson::Pointer(root + prefix + sub + "/offset_y").Set(doc, region.offset_y);
|
||||
rapidjson::Pointer(root + prefix + sub + "/scale_x").Set(doc, region.scale_x);
|
||||
rapidjson::Pointer(root + prefix + sub + "/scale_y").Set(doc, region.scale_y);
|
||||
rapidjson::Pointer(root + prefix + sub + "/keep_aspect_ratio").Set(doc, region.keep_aspect_ratio);
|
||||
};
|
||||
save_split_region("split_left", scene.split_left);
|
||||
save_split_region("split_right", scene.split_right);
|
||||
save_split_config(doc, root + prefix, scene.split);
|
||||
}
|
||||
|
||||
// windowed mode settings
|
||||
@@ -259,7 +298,10 @@ namespace cfg {
|
||||
// build JSON
|
||||
rapidjson::StringBuffer buffer;
|
||||
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
|
||||
doc.Accept(writer);
|
||||
if (!doc.Accept(writer)) {
|
||||
log_warning("ScreenResize", "unable to serialize config; existing file left unchanged");
|
||||
return;
|
||||
}
|
||||
|
||||
// save to file
|
||||
if (fileutils::write_config_file("ScreenResize", this->config_path, buffer.GetString())) {
|
||||
|
||||
@@ -22,13 +22,28 @@ namespace cfg {
|
||||
};
|
||||
|
||||
struct split_region_setting {
|
||||
static constexpr double min_scale = 0.6;
|
||||
static constexpr double max_scale = 3.0;
|
||||
static constexpr float default_scale = 1.0f;
|
||||
|
||||
int offset_x = 0;
|
||||
int offset_y = 0;
|
||||
float scale_x = 1.0f;
|
||||
float scale_y = 1.0f;
|
||||
float scale_x = default_scale;
|
||||
float scale_y = default_scale;
|
||||
bool keep_aspect_ratio = true;
|
||||
};
|
||||
|
||||
struct split_screen_setting {
|
||||
static constexpr double min_ratio = 0.1;
|
||||
static constexpr double max_ratio = 0.9;
|
||||
|
||||
bool enabled = false;
|
||||
float ratio = 0.5f;
|
||||
bool swap_sides = false;
|
||||
split_region_setting left;
|
||||
split_region_setting right;
|
||||
};
|
||||
|
||||
struct fullscreen_setting {
|
||||
int offset_x = 0;
|
||||
int offset_y = 0;
|
||||
@@ -37,12 +52,7 @@ namespace cfg {
|
||||
bool keep_aspect_ratio = true;
|
||||
ScreenDuplicateMode duplicate = ScreenDuplicateMode::None;
|
||||
|
||||
// dual-playfield / split-screen zoom settings (e.g. battle mode)
|
||||
bool split_mode = false;
|
||||
float split_ratio = 0.5f;
|
||||
bool split_swap_sides = false;
|
||||
split_region_setting split_left;
|
||||
split_region_setting split_right;
|
||||
split_screen_setting split;
|
||||
};
|
||||
|
||||
extern std::optional<std::string> SCREEN_RESIZE_CFG_PATH_OVERRIDE;
|
||||
@@ -56,6 +66,10 @@ namespace cfg {
|
||||
bool load_int_value(rapidjson::Document& doc, std::string path, int& value);
|
||||
bool load_uint32_value(rapidjson::Document& doc, std::string path, uint32_t& value);
|
||||
bool load_float_value(rapidjson::Document& doc, std::string path, float& value);
|
||||
void load_split_config(
|
||||
rapidjson::Document &doc, const std::string &path, split_screen_setting &split);
|
||||
void load_split_region(
|
||||
rapidjson::Document &doc, const std::string &path, split_region_setting ®ion);
|
||||
|
||||
public:
|
||||
ScreenResize();
|
||||
|
||||
@@ -1091,27 +1091,18 @@ static UINT backbuffer_height = 0;
|
||||
|
||||
static RECT compute_split_src_rect(
|
||||
const RECT &origin_rect,
|
||||
LONG dest_w,
|
||||
LONG dest_h,
|
||||
LONG player_width,
|
||||
LONG player_height,
|
||||
bool is_right_source,
|
||||
const cfg::split_region_setting ®ion) {
|
||||
const float safe_scale_x = std::max(region.scale_x, 0.01f);
|
||||
const float safe_scale_y = std::max(region.scale_y, 0.01f);
|
||||
|
||||
float w_new = static_cast<float>(dest_w) / safe_scale_x;
|
||||
float h_new = static_cast<float>(dest_h) / safe_scale_y;
|
||||
float w_new = static_cast<float>(player_width) / region.scale_x;
|
||||
float h_new = static_cast<float>(player_height) / region.scale_y;
|
||||
|
||||
const float max_w = static_cast<float>(topSurface_width);
|
||||
const float max_h = static_cast<float>(topSurface_height);
|
||||
|
||||
if (region.keep_aspect_ratio) {
|
||||
float limit = 1.0f;
|
||||
if (w_new > max_w) {
|
||||
limit = std::min(limit, max_w / w_new);
|
||||
}
|
||||
if (h_new > max_h) {
|
||||
limit = std::min(limit, max_h / h_new);
|
||||
}
|
||||
const float limit = std::min({1.0f, max_w / w_new, max_h / h_new});
|
||||
w_new *= limit;
|
||||
h_new *= limit;
|
||||
} else {
|
||||
@@ -1125,34 +1116,47 @@ static RECT compute_split_src_rect(
|
||||
static_cast<LONG>(std::lround(h_new)), 1, static_cast<LONG>(topSurface_height));
|
||||
|
||||
const float anchor_x = is_right_source
|
||||
? (static_cast<float>(origin_rect.right) - static_cast<float>(dest_w) * 0.5f)
|
||||
: (static_cast<float>(origin_rect.left) + static_cast<float>(dest_w) * 0.5f);
|
||||
? (static_cast<float>(origin_rect.right) - static_cast<float>(player_width) * 0.5f)
|
||||
: (static_cast<float>(origin_rect.left) + static_cast<float>(player_width) * 0.5f);
|
||||
const float anchor_y =
|
||||
(static_cast<float>(origin_rect.top) + static_cast<float>(origin_rect.bottom)) * 0.5f;
|
||||
|
||||
RECT src_rect {};
|
||||
src_rect.left = static_cast<LONG>(std::lround(anchor_x - static_cast<float>(src_w) * 0.5f)) - region.offset_x;
|
||||
src_rect.top = static_cast<LONG>(std::lround(anchor_y - static_cast<float>(src_h) * 0.5f)) - region.offset_y;
|
||||
src_rect.right = src_rect.left + src_w;
|
||||
src_rect.bottom = src_rect.top + src_h;
|
||||
// widen before applying offsets so even extreme settings stay within the surface
|
||||
const auto left = static_cast<int64_t>(std::lround(anchor_x - src_w * 0.5f)) - region.offset_x;
|
||||
const auto top = static_cast<int64_t>(std::lround(anchor_y - src_h * 0.5f)) - region.offset_y;
|
||||
const auto x = static_cast<LONG>(std::clamp<int64_t>(left, 0, topSurface_width - src_w));
|
||||
const auto y = static_cast<LONG>(std::clamp<int64_t>(top, 0, topSurface_height - src_h));
|
||||
return {x, y, x + src_w, y + src_h};
|
||||
}
|
||||
|
||||
// boundary check to prevent StretchRect failures
|
||||
if (src_rect.left < 0) {
|
||||
src_rect.left = 0;
|
||||
src_rect.right = src_w;
|
||||
} else if (src_rect.right > static_cast<LONG>(topSurface_width)) {
|
||||
src_rect.left = static_cast<LONG>(topSurface_width) - src_w;
|
||||
src_rect.right = static_cast<LONG>(topSurface_width);
|
||||
}
|
||||
if (src_rect.top < 0) {
|
||||
src_rect.top = 0;
|
||||
src_rect.bottom = src_h;
|
||||
} else if (src_rect.bottom > static_cast<LONG>(topSurface_height)) {
|
||||
src_rect.top = static_cast<LONG>(topSurface_height) - src_h;
|
||||
src_rect.bottom = static_cast<LONG>(topSurface_height);
|
||||
static void draw_split_region(
|
||||
IDirect3DDevice9 *device, const RECT &src, const RECT &dest,
|
||||
D3DTEXTUREFILTERTYPE filter, const char *player) {
|
||||
if (device->StretchRect(topSurface, &src, backbuffer, &dest, filter) != D3D_OK) {
|
||||
log_warning(
|
||||
"graphics::d3d9",
|
||||
"SurfaceHook - StretchRect split {} failed, src: {} {} {} {}, dst: {} {} {} {}",
|
||||
player, src.left, src.top, src.right, src.bottom,
|
||||
dest.left, dest.top, dest.right, dest.bottom);
|
||||
}
|
||||
}
|
||||
|
||||
return src_rect;
|
||||
static void draw_split_screen(
|
||||
IDirect3DDevice9 *device, const RECT &origin, LONG width, LONG height,
|
||||
const cfg::split_screen_setting &split, D3DTEXTUREFILTERTYPE filter) {
|
||||
const LONG left_width = std::clamp<LONG>(
|
||||
std::lround(static_cast<float>(width) * split.ratio), 1, width - 1);
|
||||
const LONG right_width = width - left_width;
|
||||
const RECT left_src = compute_split_src_rect(origin, left_width, height, false, split.left);
|
||||
const RECT right_src = compute_split_src_rect(origin, right_width, height, true, split.right);
|
||||
|
||||
// move each viewport with its original width, without changing its source crop
|
||||
const LONG left_x = split.swap_sides ? right_width : 0;
|
||||
const LONG right_x = split.swap_sides ? 0 : left_width;
|
||||
const RECT left_dest {left_x, 0, left_x + left_width, height};
|
||||
const RECT right_dest {right_x, 0, right_x + right_width, height};
|
||||
draw_split_region(device, left_src, left_dest, filter, "1P");
|
||||
draw_split_region(device, right_src, right_dest, filter, "2P");
|
||||
}
|
||||
|
||||
void SurfaceHook(IDirect3DDevice9 *pReal) {
|
||||
@@ -1211,14 +1215,14 @@ void SurfaceHook(IDirect3DDevice9 *pReal) {
|
||||
const int w = backbuffer_width;
|
||||
const int h = backbuffer_height;
|
||||
|
||||
const bool use_split_mode =
|
||||
cfg::SCREENRESIZE->enable_screen_resize
|
||||
&& cfg::SCREENRESIZE->scene_settings[cfg::SCREENRESIZE->screen_resize_current_scene].split_mode
|
||||
&& w >= 2 && h >= 1;
|
||||
const auto &resize = *cfg::SCREENRESIZE;
|
||||
const auto &scene = resize.scene_settings[resize.screen_resize_current_scene];
|
||||
const bool use_split_mode = resize.enable_screen_resize && scene.split.enabled &&
|
||||
w >= 2 && h >= 1;
|
||||
|
||||
const auto effective_duplicate =
|
||||
(cfg::SCREENRESIZE->enable_screen_resize && !use_split_mode)
|
||||
? cfg::SCREENRESIZE->scene_settings[cfg::SCREENRESIZE->screen_resize_current_scene].duplicate
|
||||
(resize.enable_screen_resize && !use_split_mode)
|
||||
? scene.duplicate
|
||||
: cfg::ScreenDuplicateMode::None;
|
||||
|
||||
// this code used to clear the surface using ColorFill on every call, but
|
||||
@@ -1292,58 +1296,11 @@ void SurfaceHook(IDirect3DDevice9 *pReal) {
|
||||
}
|
||||
}
|
||||
|
||||
bool use_linear_filter = true;
|
||||
if (cfg::SCREENRESIZE->enable_screen_resize) {
|
||||
use_linear_filter = cfg::SCREENRESIZE->enable_linear_filter;
|
||||
}
|
||||
const bool use_linear_filter = !resize.enable_screen_resize || resize.enable_linear_filter;
|
||||
const auto filter = use_linear_filter ? D3DTEXF_LINEAR : D3DTEXF_NONE;
|
||||
|
||||
// phase 2 & 3 (split mode) - independently zoom/offset left and right playfields onto
|
||||
// the left and right portions of the back buffer
|
||||
if (use_split_mode) {
|
||||
const auto& scene = cfg::SCREENRESIZE->scene_settings[cfg::SCREENRESIZE->screen_resize_current_scene];
|
||||
const float ratio = std::clamp(scene.split_ratio, 0.1f, 0.9f);
|
||||
const LONG split_x = std::clamp<LONG>(
|
||||
static_cast<LONG>(std::lround(static_cast<float>(w) * ratio)), 1, static_cast<LONG>(w) - 1);
|
||||
|
||||
const RECT destLeft { 0, 0, split_x, static_cast<LONG>(h) };
|
||||
const RECT destRight { split_x, 0, static_cast<LONG>(w), static_cast<LONG>(h) };
|
||||
|
||||
const bool left_uses_right_source = scene.split_swap_sides;
|
||||
const bool right_uses_right_source = !scene.split_swap_sides;
|
||||
const auto& left_region = scene.split_swap_sides ? scene.split_right : scene.split_left;
|
||||
const auto& right_region = scene.split_swap_sides ? scene.split_left : scene.split_right;
|
||||
|
||||
const RECT srcLeft = compute_split_src_rect(
|
||||
originRect,
|
||||
destLeft.right - destLeft.left,
|
||||
destLeft.bottom - destLeft.top,
|
||||
left_uses_right_source,
|
||||
left_region);
|
||||
const RECT srcRight = compute_split_src_rect(
|
||||
originRect,
|
||||
destRight.right - destRight.left,
|
||||
destRight.bottom - destRight.top,
|
||||
right_uses_right_source,
|
||||
right_region);
|
||||
|
||||
hr = pReal->StretchRect(topSurface, &srcLeft, backbuffer, &destLeft, filter);
|
||||
if (hr != D3D_OK) {
|
||||
log_warning(
|
||||
"graphics::d3d9",
|
||||
"SurfaceHook - StretchRect split left failed, src: {} {} {} {}, dst: {} {} {} {}",
|
||||
srcLeft.left, srcLeft.top, srcLeft.right, srcLeft.bottom,
|
||||
destLeft.left, destLeft.top, destLeft.right, destLeft.bottom);
|
||||
}
|
||||
|
||||
hr = pReal->StretchRect(topSurface, &srcRight, backbuffer, &destRight, filter);
|
||||
if (hr != D3D_OK) {
|
||||
log_warning(
|
||||
"graphics::d3d9",
|
||||
"SurfaceHook - StretchRect split right failed, src: {} {} {} {}, dst: {} {} {} {}",
|
||||
srcRight.left, srcRight.top, srcRight.right, srcRight.bottom,
|
||||
destRight.left, destRight.top, destRight.right, destRight.bottom);
|
||||
}
|
||||
draw_split_screen(pReal, originRect, w, h, scene.split, filter);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1355,8 +1312,7 @@ void SurfaceHook(IDirect3DDevice9 *pReal) {
|
||||
(LONG)(rectLeft + w),
|
||||
(LONG)(rectTop + h),
|
||||
};
|
||||
if (cfg::SCREENRESIZE->enable_screen_resize) {
|
||||
auto& scene = cfg::SCREENRESIZE->scene_settings[cfg::SCREENRESIZE->screen_resize_current_scene];
|
||||
if (resize.enable_screen_resize) {
|
||||
auto w_new = w / scene.scale_x;
|
||||
auto h_new = h / scene.scale_y;
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#include <algorithm>
|
||||
#include <climits>
|
||||
|
||||
#include <games/io.h>
|
||||
|
||||
#include "screen_resize.h"
|
||||
@@ -55,20 +58,8 @@ namespace overlay::windows {
|
||||
cfg::SCREENRESIZE->enable_screen_resize = false;
|
||||
cfg::SCREENRESIZE->screen_resize_current_scene = 0;
|
||||
cfg::SCREENRESIZE->enable_linear_filter = true;
|
||||
for (size_t i = 0; i < std::size(cfg::SCREENRESIZE->scene_settings); i++) {
|
||||
auto& scene = cfg::SCREENRESIZE->scene_settings[i];
|
||||
scene.keep_aspect_ratio = true;
|
||||
scene.offset_x = 0;
|
||||
scene.offset_y = 0;
|
||||
scene.scale_x = 1.f;
|
||||
scene.scale_y = 1.f;
|
||||
scene.duplicate = cfg::ScreenDuplicateMode::None;
|
||||
|
||||
scene.split_mode = false;
|
||||
scene.split_ratio = 0.5f;
|
||||
scene.split_swap_sides = false;
|
||||
scene.split_left = {};
|
||||
scene.split_right = {};
|
||||
for (auto &scene : cfg::SCREENRESIZE->scene_settings) {
|
||||
scene = {};
|
||||
}
|
||||
cfg::SCREENRESIZE->need_surface_clean = true;
|
||||
|
||||
@@ -108,45 +99,78 @@ namespace overlay::windows {
|
||||
build_footer();
|
||||
}
|
||||
|
||||
void ScreenResize::build_split_region_config(
|
||||
const char *id, const char *label, cfg::split_region_setting ®ion) {
|
||||
static bool split_scale_slider(const char *label, float &scale) {
|
||||
return ImGui::SliderFloat(
|
||||
label, &scale, cfg::split_region_setting::min_scale,
|
||||
cfg::split_region_setting::max_scale, "%.3f", ImGuiSliderFlags_AlwaysClamp);
|
||||
}
|
||||
|
||||
static void build_split_region_config(const char *label, cfg::split_region_setting ®ion) {
|
||||
if (!ImGui::TreeNodeEx(label, ImGuiTreeNodeFlags_DefaultOpen)) {
|
||||
return;
|
||||
}
|
||||
ImGui::PushID(id);
|
||||
|
||||
ImGui::InputInt("X Offset", ®ion.offset_x);
|
||||
ImGui::SameLine();
|
||||
ImGui::HelpMarker("Hint: ctrl + click on +/- buttons to move quickly.");
|
||||
|
||||
ImGui::InputInt("Y Offset", ®ion.offset_y);
|
||||
ImGui::SameLine();
|
||||
ImGui::HelpMarker("Hint: ctrl + click on +/- buttons to move quickly.");
|
||||
|
||||
if (ImGui::Checkbox("Keep Aspect Ratio", ®ion.keep_aspect_ratio)) {
|
||||
if (region.keep_aspect_ratio) {
|
||||
region.scale_y = region.scale_x;
|
||||
}
|
||||
if (ImGui::Checkbox("Keep Aspect Ratio", ®ion.keep_aspect_ratio) &&
|
||||
region.keep_aspect_ratio) {
|
||||
region.scale_y = region.scale_x;
|
||||
}
|
||||
if (region.keep_aspect_ratio) {
|
||||
if (ImGui::SliderFloat("Scale", ®ion.scale_x, 0.6f, 3.0f)) {
|
||||
if (split_scale_slider("Scale", region.scale_x)) {
|
||||
region.scale_y = region.scale_x;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::HelpMarker("Hint: ctrl + click on the slider to type in a numeric value.");
|
||||
} else {
|
||||
ImGui::SliderFloat("Width Scale", ®ion.scale_x, 0.6f, 3.0f);
|
||||
ImGui::SameLine();
|
||||
ImGui::HelpMarker("Hint: ctrl + click on the slider to type in a numeric value.");
|
||||
ImGui::SliderFloat("Height Scale", ®ion.scale_y, 0.6f, 3.0f);
|
||||
ImGui::SameLine();
|
||||
ImGui::HelpMarker("Hint: ctrl + click on the slider to type in a numeric value.");
|
||||
split_scale_slider("Width Scale", region.scale_x);
|
||||
split_scale_slider("Height Scale", region.scale_y);
|
||||
}
|
||||
|
||||
ImGui::PopID();
|
||||
ImGui::TreePop();
|
||||
}
|
||||
|
||||
static cfg::split_region_setting mirror_split_region(cfg::split_region_setting region) {
|
||||
region.offset_x = static_cast<int>(
|
||||
std::min<int64_t>(-static_cast<int64_t>(region.offset_x), INT_MAX));
|
||||
return region;
|
||||
}
|
||||
|
||||
static void build_split_config(cfg::split_screen_setting &split) {
|
||||
float divider = split.swap_sides ? 1.0f - split.ratio : split.ratio;
|
||||
if (ImGui::SliderFloat(
|
||||
"Split Position", ÷r, cfg::split_screen_setting::min_ratio,
|
||||
cfg::split_screen_setting::max_ratio, "%.2f", ImGuiSliderFlags_AlwaysClamp)) {
|
||||
split.ratio = split.swap_sides ? 1.0f - divider : divider;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::HelpMarker("Position of the divider from the left edge (0.50 = center).");
|
||||
|
||||
ImGui::Checkbox("Swap Sides", &split.swap_sides);
|
||||
ImGui::SameLine();
|
||||
ImGui::HelpMarker("Swap the playfields without changing their widths, zoom, or offsets.");
|
||||
|
||||
if (ImGui::Button("Mirror 1P -> 2P")) {
|
||||
split.right = mirror_split_region(split.left);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Mirror 2P -> 1P")) {
|
||||
split.left = mirror_split_region(split.right);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Reset Split")) {
|
||||
split = {};
|
||||
split.enabled = true;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::HelpMarker("Mirror copies zoom and offsets, but reverses the X offset.");
|
||||
|
||||
build_split_region_config(split.swap_sides
|
||||
? "1P Playfield (Displayed Right)###split_left"
|
||||
: "1P Playfield (Left)###split_left", split.left);
|
||||
build_split_region_config(split.swap_sides
|
||||
? "2P Playfield (Displayed Left)###split_right"
|
||||
: "2P Playfield (Right)###split_right", split.right);
|
||||
}
|
||||
|
||||
void ScreenResize::build_fullscreen_config() {
|
||||
|
||||
ImGui::TextColored(ImVec4(1, 0.5f, 0.5f, 1.f),
|
||||
@@ -184,7 +208,8 @@ namespace overlay::windows {
|
||||
|
||||
auto& scene = cfg::SCREENRESIZE->scene_settings[cfg::SCREENRESIZE->screen_resize_current_scene];
|
||||
|
||||
const bool split_changed = ImGui::Checkbox("Split Screen (Dual Playfield)", &scene.split_mode);
|
||||
const bool split_changed =
|
||||
ImGui::Checkbox("Split Screen (Dual Playfield)", &scene.split.enabled);
|
||||
ImGui::SameLine();
|
||||
ImGui::HelpMarker(
|
||||
"Split the screen into independent Left (1P) and Right (2P) zoom viewports, "
|
||||
@@ -193,51 +218,8 @@ namespace overlay::windows {
|
||||
cfg::SCREENRESIZE->need_surface_clean = true;
|
||||
}
|
||||
|
||||
if (scene.split_mode) {
|
||||
if (ImGui::SliderFloat("Split Position", &scene.split_ratio, 0.1f, 0.9f, "%.2f")) {
|
||||
scene.split_ratio = CLAMP(scene.split_ratio, 0.1f, 0.9f);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::HelpMarker(
|
||||
"Horizontal divider position between the left and right viewports (0.50 = 50/50). "
|
||||
"Ctrl + click to type in a numeric value.");
|
||||
|
||||
ImGui::Checkbox("Swap Sides", &scene.split_swap_sides);
|
||||
ImGui::SameLine();
|
||||
ImGui::HelpMarker(
|
||||
"Visually swap 1P (left) and 2P (right) playfields on screen "
|
||||
"while keeping each playfield's individual zoom and offset.");
|
||||
|
||||
if (ImGui::Button("Mirror 1P -> 2P")) {
|
||||
scene.split_right = scene.split_left;
|
||||
scene.split_right.offset_x = -scene.split_left.offset_x;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Mirror 2P -> 1P")) {
|
||||
scene.split_left = scene.split_right;
|
||||
scene.split_left.offset_x = -scene.split_right.offset_x;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Reset Split")) {
|
||||
scene.split_ratio = 0.5f;
|
||||
scene.split_swap_sides = false;
|
||||
scene.split_left = {};
|
||||
scene.split_right = {};
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::HelpMarker(
|
||||
"Mirror copies zoom and offset to the other playfield with an inverted X offset "
|
||||
"for symmetric Battle layouts.");
|
||||
|
||||
const char *left_label = scene.split_swap_sides
|
||||
? "1P Playfield (Displayed Right)###split_left"
|
||||
: "1P Playfield (Left)###split_left";
|
||||
const char *right_label = scene.split_swap_sides
|
||||
? "2P Playfield (Displayed Left)###split_right"
|
||||
: "2P Playfield (Right)###split_right";
|
||||
|
||||
this->build_split_region_config("split_left", left_label, scene.split_left);
|
||||
this->build_split_region_config("split_right", right_label, scene.split_right);
|
||||
if (scene.split.enabled) {
|
||||
build_split_config(scene.split);
|
||||
} else {
|
||||
// general settings
|
||||
ImGui::InputInt("X Offset", &scene.offset_x);
|
||||
|
||||
@@ -2,10 +2,6 @@
|
||||
|
||||
#include "overlay/window.h"
|
||||
|
||||
namespace cfg {
|
||||
struct split_region_setting;
|
||||
}
|
||||
|
||||
namespace overlay::windows {
|
||||
|
||||
class ScreenResize : public Window {
|
||||
@@ -24,8 +20,6 @@ namespace overlay::windows {
|
||||
uint32_t toggle_scene_state = ~0u;
|
||||
|
||||
void build_fullscreen_config();
|
||||
void build_split_region_config(
|
||||
const char *id, const char *label, cfg::split_region_setting ®ion);
|
||||
void build_windowed_config();
|
||||
void build_footer();
|
||||
std::string hwnd_preview(int index, HWND hwnd);
|
||||
|
||||
Reference in new issue
Block a user