Skip to content

Commit

Permalink
Add preliminary UI scaling support
Browse files Browse the repository at this point in the history
  • Loading branch information
andon authored and andon committed Feb 10, 2017
1 parent 6c13baf commit 9b2fbd4
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 44 deletions.
2 changes: 1 addition & 1 deletion include/DLL_VERSION.H
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#define TBF_MAJOR 0
#define TBF_MINOR 9
#define TBF_BUILD 2
#define TBF_BUILD 3
#define TBF_REV 0


Expand Down
15 changes: 8 additions & 7 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ extern std::wstring DEFAULT_BK2;
struct tbf_config_t
{
struct {
uint32_t sample_hz = -1;
uint32_t sample_hz = 48000;
uint32_t channels = 6;
bool compatibility = false;
bool enable_fix = true;
bool compatibility = true;
bool enable_fix = false;
} audio;

struct {
Expand All @@ -60,7 +60,7 @@ struct tbf_config_t
uintptr_t fovy_addr = 0x00D56498ULL;//0x00D5239C;
bool blackbar_videos = false; // OBSOLETE
bool aspect_correction = false;
float postproc_ratio = 0.0f;
float postproc_ratio = 0.5f;
bool clear_blackbars = false;
int32_t shadow_rescale = -2;
int32_t env_shadow_rescale = 1;
Expand All @@ -75,13 +75,13 @@ struct tbf_config_t
bool remaster = true;
bool cache = true;
bool uncompressed = false;
float lod_bias = -0.2666f;
float lod_bias = -0.1333f;
int32_t max_cache_in_mib = 2048L;
int32_t worker_threads = 3;
int32_t max_decomp_jobs = 6;
int32_t max_decomp_jobs = 3;
bool show_loading_text = false;
bool quick_load = false;
bool clamp_npot_coords = false;
bool clamp_npot_coords = true;
bool highlight_debug_tex = true;
} textures;

Expand All @@ -94,6 +94,7 @@ struct tbf_config_t
struct {
bool visible = false;
bool pause = true;
float scale = 1.0f;
} ui;
} input;

Expand Down
65 changes: 60 additions & 5 deletions src/ImGui/control_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ TBFix_DrawConfigUI (void)
ImGuiIO& io =
ImGui::GetIO ();

io.FontGlobalScale = config.input.ui.scale;
const LONG font_size = ImGui::GetFont ()->FontSize * io.FontGlobalScale;

ImGui::SetNextWindowPosCenter (ImGuiSetCond_Always);
ImGui::SetNextWindowSizeConstraints (ImVec2 (665, 50), ImVec2 ( ImGui::GetIO ().DisplaySize.x * 0.95f,
ImGui::GetIO ().DisplaySize.y * 0.95f ) );
Expand All @@ -263,6 +266,15 @@ TBFix_DrawConfigUI (void)

ImGui::PushItemWidth (ImGui::GetWindowWidth () * 0.666f);

if (ImGui::CollapsingHeader ("UI Scale"))
{
ImGui::TreePush ("");

ImGui::SliderFloat ("Scale (only 1.0 is officially supported)", &config.input.ui.scale, 1.0f, 3.0f);

ImGui::TreePop ();
}

if (ImGui::CollapsingHeader ("Framerate", ImGuiTreeNodeFlags_CollapsingHeader | ImGuiTreeNodeFlags_DefaultOpen))
{
ImGui::TreePush ("");
Expand Down Expand Up @@ -331,12 +343,12 @@ TBFix_DrawConfigUI (void)
szAvg,
0.0f,
2.0f * tbf::FrameRateFix::GetTargetFrametime (),
ImVec2 (0, 80) );
ImVec2 (0, font_size * 7) );

ImGui::SameLine ();

if (! config.framerate.replace_limiter) {
ImGui::BeginChild ( "LimitDisclaimer", ImVec2 ( 330.0f, 80.0f ) );
ImGui::BeginChild ( "LimitDisclaimer", ImVec2 ( font_size * 25, font_size * 7 ) );
ImGui::TextColored ( ImVec4 (1.0f, 1.0f, 0.0f, 1.0f),
"Working limiters do not resemble seismographs!" );

Expand All @@ -350,7 +362,7 @@ TBFix_DrawConfigUI (void)
}

else {
ImGui::BeginChild ( "LimitDisclaimer", ImVec2 ( 310.0f, 80.0f ) );
ImGui::BeginChild ( "LimitDisclaimer", ImVec2 ( font_size * 25, font_size * 7 ) );
ImGui::TextColored ( ImVec4 ( 0.2f, 1.0f, 0.2f, 1.0f),
"This is how a framerate limiter should work." );

Expand Down Expand Up @@ -480,7 +492,7 @@ TBFix_DrawConfigUI (void)

ImGui::PushStyleVar(ImGuiStyleVar_ChildWindowRounding, 15.0f);
ImGui::TreePush ("");
ImGui::BeginChild ("Texture Details", ImVec2 (0, 130), true);
ImGui::BeginChild ("Texture Details", ImVec2 (0, font_size * 10), true);

ImGui::Columns ( 3 );
ImGui::PushStyleColor (ImGuiCol_Text, ImVec4 (1.0f, 1.0f, 1.0f, 1.0f));
Expand Down Expand Up @@ -592,6 +604,49 @@ TBFix_DrawConfigUI (void)
ImGui::TreePop ();
}

if (ImGui::CollapsingHeader ("Post-Processing"))
{
ImGui::TreePush ("");

int sel = config.render.postproc_ratio == 0.0f ?
0 : 1;
if (sel == 1) {
if (config.render.postproc_ratio < 1.0)
sel = 1;
else if (config.render.postproc_ratio < 2.0)
sel = 2;
else
sel = 3;
}

if ( ImGui::Combo ( "Post-Processing Resolution", &sel,
" Game Default -- Will cause shimmering\0"
" 50% Screen Resolution\0"
" 100% Screen Resolution\0"
" 200% Screen Resolution\0\0", 4 ) )
{
switch (sel) {
case 0:
config.render.postproc_ratio = 0.0f;
break;
default:
case 1:
config.render.postproc_ratio = 0.5f;
break;
case 2:
config.render.postproc_ratio = 1.0f;
break;
case 3:
config.render.postproc_ratio = 2.0f;
break;
}

tbf::RenderFix::need_reset.textures = true;
}

ImGui::TreePop ();
}

#if 0
if (ImGui::CollapsingHeader ("Shader Options"))
{It
Expand Down Expand Up @@ -783,7 +838,7 @@ TBFix_DrawConfigUI (void)
if (tbf::SoundFix::wasapi_init)
{
ImGui::PushStyleVar (ImGuiStyleVar_ChildWindowRounding, 16.0f);
ImGui::BeginChild ("Audio Details", ImVec2 (0, 80), true);
ImGui::BeginChild ("Audio Details", ImVec2 (0, font_size * 6), true);

ImGui::Columns (3);
ImGui::Text (""); ImGui::NextColumn ();
Expand Down
31 changes: 19 additions & 12 deletions src/ImGui/mod_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
void
TBF_DrawFileList (void)
{
const LONG font_size = ImGui::GetFont ()->FontSize * ImGui::GetIO ().FontGlobalScale;

ImGui::PushItemWidth (500.0f);

struct enumerated_source_s
Expand Down Expand Up @@ -105,8 +107,8 @@ TBF_DrawFileList (void)
ImGui::PushStyleVar (ImGuiStyleVar_ChildWindowRounding, 0.0f);
ImGui::PushStyleColor (ImGuiCol_Border, ImVec4 (0.4f, 0.6f, 0.9f, 1.0f));

#define FILE_LIST_WIDTH 250UL
#define FILE_LIST_HEIGHT 100UL
#define FILE_LIST_WIDTH font_size * 20
#define FILE_LIST_HEIGHT font_size * (sources.size () + 3)

ImGui::BeginChild ( "Source List",
ImVec2 ( FILE_LIST_WIDTH, FILE_LIST_HEIGHT ),
Expand Down Expand Up @@ -189,7 +191,7 @@ TBF_DrawFileList (void)

ImGui::PushStyleColor (ImGuiCol_Border, ImVec4 (0.5f, 0.5f, 0.5f, 1.0f));
ImGui::BeginChild ( "Texture Selection",
ImVec2 (300.0f, list_size.y - 24),
ImVec2 (font_size * 30, list_size.y - font_size * 2),
true );

for ( auto it : sources [sel].checksums )
Expand Down Expand Up @@ -236,6 +238,8 @@ TBF_DrawFileList (void)
bool
TBFix_TextureModDlg (void)
{
const LONG font_size = ImGui::GetFont ()->FontSize * ImGui::GetIO ().FontGlobalScale;

bool show_dlg = true;

ImGui::Begin ( "Tales Engine Texture Mod Toolkit (v " TBF_VERSION_STR_A ")",
Expand All @@ -246,7 +250,7 @@ TBFix_TextureModDlg (void)

if (ImGui::CollapsingHeader ("Preliminary Documentation"))
{
ImGui::BeginChild ("ModDescription", ImVec2 (750, 325), true);
ImGui::BeginChild ("ModDescription", ImVec2 (font_size * 66, font_size * 25), true);
ImGui::TextColored (ImVec4 (0.9f, 0.7f, 0.5f, 1.0f), "Texture Modding Overview"); ImGui::SameLine ();
ImGui::Text (" (Full Writeup Pending)");

Expand Down Expand Up @@ -299,7 +303,7 @@ TBFix_TextureModDlg (void)
extern uint32_t tex_dbg_idx;
extern uint32_t debug_tex_id;

ImGui::BeginChild ("ToolHeadings", ImVec2 (750, 32), false, ImGuiWindowFlags_AlwaysUseWindowPadding);
ImGui::BeginChild ("ToolHeadings", ImVec2 (font_size * 66, font_size * 2.5), false, ImGuiWindowFlags_AlwaysUseWindowPadding);

if (ImGui::Button ("Refresh Textures"))
{
Expand Down Expand Up @@ -354,6 +358,9 @@ TBFix_TextureModDlg (void)
list_contents.clear ();
sel = tex_dbg_idx;

if (debug_tex_id == 0)
last_ht = 0;

for ( auto it : textures_used_last_dump )
{
char szDesc [16] = { };
Expand All @@ -370,7 +377,7 @@ TBFix_TextureModDlg (void)
ImGui::PushStyleColor (ImGuiCol_Border, ImVec4 (0.9f, 0.7f, 0.5f, 1.0f));

ImGui::BeginChild ( "Item List",
ImVec2 ( 90, std::max (512L, last_ht) + 128 ),
ImVec2 ( font_size * 6, std::max (font_size * 15, last_ht)),
true, ImGuiWindowFlags_AlwaysAutoResize );

if (textures_used_last_dump.size ())
Expand Down Expand Up @@ -443,10 +450,10 @@ TBFix_TextureModDlg (void)
{
ImGui::PushStyleColor (ImGuiCol_Border, ImVec4 (0.5f, 0.5f, 0.5f, 1.0f));
ImGui::BeginChild ( "Item Selection",
ImVec2 (std::max (256L, (LONG)desc.Width + 24), std::max (512L, (LONG)desc.Height) + 128), true, ImGuiWindowFlags_AlwaysAutoResize );
ImVec2 (std::max (font_size * 19, (LONG)desc.Width + 24), desc.Height + font_size * 10), true, ImGuiWindowFlags_AlwaysAutoResize );

last_width = desc.Width;
last_ht = desc.Height;
last_ht = desc.Height + font_size * 10;

extern std::wstring
SK_D3D9_FormatToStr (D3DFORMAT Format, bool include_ordinal = true);
Expand Down Expand Up @@ -503,7 +510,7 @@ TBFix_TextureModDlg (void)
{
ImGui::PushStyleColor (ImGuiCol_Border, ImVec4 (0.5f, 0.5f, 0.5f, 1.0f));
ImGui::BeginChild ( "Item Selection2",
ImVec2 (std::max (256L, (LONG)desc.Width + 24), std::max (512L, (LONG)desc.Height) + 128), true, ImGuiWindowFlags_AlwaysAutoResize );
ImVec2 (std::max (font_size * 19, (LONG)desc.Width + 24), desc.Height + font_size * 10), true, ImGuiWindowFlags_AlwaysAutoResize );

extern std::wstring
SK_D3D9_FormatToStr (D3DFORMAT Format, bool include_ordinal = true);
Expand Down Expand Up @@ -563,7 +570,7 @@ TBFix_TextureModDlg (void)
ImGui::PopStyleVar (2);
}

if (ImGui::CollapsingHeader ("Live Render Target View", ImGuiTreeNodeFlags_CollapsingHeader | ImGuiTreeNodeFlags_DefaultOpen))
if (ImGui::CollapsingHeader ("Live Render Target View"))
{
static LONG last_ht = 256L;
static LONG last_width = 256L;
Expand Down Expand Up @@ -601,7 +608,7 @@ TBFix_TextureModDlg (void)
ImGui::PushStyleColor (ImGuiCol_Border, ImVec4 (0.9f, 0.7f, 0.5f, 1.0f));

ImGui::BeginChild ( "Item List2",
ImVec2 ( 90, std::max (512L, last_ht)),
ImVec2 ( font_size * 6, std::max (font_size * 15, last_ht)),
true, ImGuiWindowFlags_AlwaysAutoResize );

if (render_textures.size ())
Expand Down Expand Up @@ -684,7 +691,7 @@ TBFix_TextureModDlg (void)
ImGuiWindowFlags_AlwaysAutoResize );

last_width = desc.Width / 2;
last_ht = std::max (256L, (LONG)desc.Height / 2) + 64 + shaders * 19;
last_ht = (LONG)(desc.Height / 2) + font_size * 3 + shaders * font_size;

extern std::wstring
SK_D3D9_FormatToStr (D3DFORMAT Format, bool include_ordinal = true);
Expand Down
34 changes: 33 additions & 1 deletion src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@
*
**/

#define NOMINMAX

#include "config.h"
#include "parameter.h"
#include "ini.h"
#include "log.h"

#include "DLL_VERSION.H"

#include <algorithm>

extern HMODULE hInjectorDLL;

std::wstring TBF_VER_STR = TBF_VERSION_STR_W;
Expand Down Expand Up @@ -75,6 +79,7 @@ struct {
tbf::ParameterBool* fix_map_res;
tbf::ParameterBool* pause_on_ui;
tbf::ParameterBool* show_osd_disclaimer;
tbf::ParameterFloat* ui_scale;
} render;

struct {
Expand Down Expand Up @@ -351,9 +356,19 @@ TBF_LoadConfig (std::wstring name)
L"Resolution.Experimental",
L"FixMap" );

render.postproc_ratio =
static_cast <tbf::ParameterFloat *>
(g_ParameterFactory.create_parameter <float> (
L"Post-Process Ratio")
);
render.postproc_ratio->register_to_ini (
render_ini,
L"Resolution.Experimental",
L"PostProcessRatio" );

render.pause_on_ui =
static_cast <tbf::ParameterBool *>
(g_ParameterFactory.create_parameter <bool>(
(g_ParameterFactory.create_parameter <bool> (
L"Config Menu Pauses Game")
);

Expand All @@ -362,6 +377,17 @@ TBF_LoadConfig (std::wstring name)
L"ImGui.Settings",
L"PauseOnActivate" );

render.ui_scale =
static_cast <tbf::ParameterFloat *>
(g_ParameterFactory.create_parameter <float> (
L"Config Menu Scale Factor")
);

render.ui_scale->register_to_ini (
render_ini,
L"ImGui.Settings",
L"FontScale" );

render.show_osd_disclaimer =
static_cast <tbf::ParameterBool *>
(g_ParameterFactory.create_parameter <bool>(
Expand Down Expand Up @@ -508,8 +534,12 @@ TBF_LoadConfig (std::wstring name)

render.dump_shaders->load (config.render.dump_shaders);
render.fix_map_res->load (config.render.fix_map_res);
render.postproc_ratio->load (config.render.postproc_ratio);
render.pause_on_ui->load (config.input.ui.pause);
render.show_osd_disclaimer->load (config.render.osd_disclaimer);
render.ui_scale->load (config.input.ui.scale);

config.input.ui.scale = std::min (std::max (1.0f, config.input.ui.scale), 3.0f);

framerate.replace_limiter->load (config.framerate.replace_limiter);
framerate.tolerance->load (config.framerate.tolerance);
Expand Down Expand Up @@ -550,8 +580,10 @@ TBF_SaveConfig (std::wstring name, bool close_config)
render.rescale_shadows->store (config.render.shadow_rescale);
render.rescale_env_shadows->store (config.render.env_shadow_rescale);
render.fix_map_res->store (config.render.fix_map_res);
render.postproc_ratio->store (config.render.postproc_ratio);
render.pause_on_ui->store (config.input.ui.pause);
render.show_osd_disclaimer->store (config.render.osd_disclaimer);
render.ui_scale->store (config.input.ui.scale);

textures.remaster->store (config.textures.remaster);
textures.uncompressed->store (config.textures.uncompressed);
Expand Down
Loading

0 comments on commit 9b2fbd4

Please sign in to comment.