mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-04-27 12:51:42 +00:00
Add Scale and Origin to ImGui shaders. Change text to be squashed.
This commit is contained in:
parent
7f85fb6ecb
commit
efd2c40cfd
7 changed files with 66 additions and 23 deletions
|
|
@ -10,7 +10,9 @@
|
||||||
enum class ImGuiCallback : int32_t
|
enum class ImGuiCallback : int32_t
|
||||||
{
|
{
|
||||||
SetGradient = -1,
|
SetGradient = -1,
|
||||||
SetShaderModifier = -2
|
SetShaderModifier = -2,
|
||||||
|
SetOrigin = -3,
|
||||||
|
SetScale = -4,
|
||||||
};
|
};
|
||||||
|
|
||||||
union ImGuiCallbackData
|
union ImGuiCallbackData
|
||||||
|
|
@ -27,6 +29,16 @@ union ImGuiCallbackData
|
||||||
{
|
{
|
||||||
uint32_t shaderModifier;
|
uint32_t shaderModifier;
|
||||||
} setShaderModifier;
|
} setShaderModifier;
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
float origin[2];
|
||||||
|
} setOrigin;
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
float scale[2];
|
||||||
|
} setScale;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ struct PushConstants
|
||||||
uint ShaderModifier;
|
uint ShaderModifier;
|
||||||
uint Texture2DDescriptorIndex;
|
uint Texture2DDescriptorIndex;
|
||||||
float2 InverseDisplaySize;
|
float2 InverseDisplaySize;
|
||||||
|
float2 Origin;
|
||||||
|
float2 Scale;
|
||||||
};
|
};
|
||||||
|
|
||||||
Texture2D<float4> g_Texture2DDescriptorHeap[] : register(t0, space0);
|
Texture2D<float4> g_Texture2DDescriptorHeap[] : register(t0, space0);
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
void main(in float2 position : POSITION, in float2 uv : TEXCOORD, in float4 color : COLOR, out Interpolators interpolators)
|
void main(in float2 position : POSITION, in float2 uv : TEXCOORD, in float4 color : COLOR, out Interpolators interpolators)
|
||||||
{
|
{
|
||||||
interpolators.Position = float4(position * g_PushConstants.InverseDisplaySize * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0);
|
float2 correctedPosition = g_PushConstants.Origin + (position - g_PushConstants.Origin) * g_PushConstants.Scale;
|
||||||
|
interpolators.Position = float4(correctedPosition * g_PushConstants.InverseDisplaySize * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0);
|
||||||
interpolators.UV = uv;
|
interpolators.UV = uv;
|
||||||
interpolators.Color = color;
|
interpolators.Color = color;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1057,6 +1057,8 @@ struct ImGuiPushConstants
|
||||||
uint32_t shaderModifier{};
|
uint32_t shaderModifier{};
|
||||||
uint32_t texture2DDescriptorIndex{};
|
uint32_t texture2DDescriptorIndex{};
|
||||||
ImVec2 inverseDisplaySize{};
|
ImVec2 inverseDisplaySize{};
|
||||||
|
ImVec2 origin{ 0.0f, 0.0f };
|
||||||
|
ImVec2 scale{ 1.0f, 1.0f };
|
||||||
};
|
};
|
||||||
|
|
||||||
static void CreateImGuiBackend()
|
static void CreateImGuiBackend()
|
||||||
|
|
@ -1812,6 +1814,12 @@ static void ProcDrawImGui(const RenderCommand& cmd)
|
||||||
case ImGuiCallback::SetShaderModifier:
|
case ImGuiCallback::SetShaderModifier:
|
||||||
commandList->setGraphicsPushConstants(0, &callbackData->setShaderModifier, offsetof(ImGuiPushConstants, shaderModifier), sizeof(callbackData->setShaderModifier));
|
commandList->setGraphicsPushConstants(0, &callbackData->setShaderModifier, offsetof(ImGuiPushConstants, shaderModifier), sizeof(callbackData->setShaderModifier));
|
||||||
break;
|
break;
|
||||||
|
case ImGuiCallback::SetOrigin:
|
||||||
|
commandList->setGraphicsPushConstants(0, &callbackData->setOrigin, offsetof(ImGuiPushConstants, origin), sizeof(callbackData->setOrigin));
|
||||||
|
break;
|
||||||
|
case ImGuiCallback::SetScale:
|
||||||
|
commandList->setGraphicsPushConstants(0, &callbackData->setScale, offsetof(ImGuiPushConstants, scale), sizeof(callbackData->setScale));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,7 @@ inline static std::unordered_map<std::string, std::unordered_map<ELanguage, std:
|
||||||
{
|
{
|
||||||
{ ELanguage::English, "NEXT" },
|
{ ELanguage::English, "NEXT" },
|
||||||
{ ELanguage::Spanish, "SIGUIENTE" },
|
{ ELanguage::Spanish, "SIGUIENTE" },
|
||||||
|
{ ELanguage::German, "WEITER" },
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -110,6 +111,7 @@ inline static std::unordered_map<std::string, std::unordered_map<ELanguage, std:
|
||||||
{
|
{
|
||||||
{ ELanguage::English, "SKIP" },
|
{ ELanguage::English, "SKIP" },
|
||||||
{ ELanguage::Spanish, "SALTAR" },
|
{ ELanguage::Spanish, "SALTAR" },
|
||||||
|
{ ELanguage::German, "ÜBERSPRINGEN" },
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,20 @@ static void SetShaderModifier(uint32_t shaderModifier)
|
||||||
callbackData->setShaderModifier.shaderModifier = shaderModifier;
|
callbackData->setShaderModifier.shaderModifier = shaderModifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void SetOrigin(ImVec2 origin)
|
||||||
|
{
|
||||||
|
auto callbackData = AddCallback(ImGuiCallback::SetOrigin);
|
||||||
|
callbackData->setOrigin.origin[0] = origin.x;
|
||||||
|
callbackData->setOrigin.origin[1] = origin.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void SetScale(ImVec2 scale)
|
||||||
|
{
|
||||||
|
auto callbackData = AddCallback(ImGuiCallback::SetScale);
|
||||||
|
callbackData->setScale.scale[0] = scale.x;
|
||||||
|
callbackData->setScale.scale[1] = scale.y;
|
||||||
|
}
|
||||||
|
|
||||||
// Aspect ratio aware.
|
// Aspect ratio aware.
|
||||||
static float Scale(float size)
|
static float Scale(float size)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -434,25 +434,21 @@ static void DrawButtonContainer(ImVec2 min, ImVec2 max, int baser, int baseg, fl
|
||||||
SetShaderModifier(IMGUI_SHADER_MODIFIER_NONE);
|
SetShaderModifier(IMGUI_SHADER_MODIFIER_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ImVec2 ComputeTextSizeAndRatio(ImFont *font, const char *text, float &size, float maxTextWidth = FLT_MAX)
|
static ImVec2 ComputeTextSize(ImFont *font, const char *text, float size, float &squashRatio, float maxTextWidth = FLT_MAX)
|
||||||
{
|
{
|
||||||
ImVec2 textSize = font->CalcTextSizeA(size, FLT_MAX, 0.0f, text);
|
ImVec2 textSize = font->CalcTextSizeA(size, FLT_MAX, 0.0f, text);
|
||||||
if (textSize.x > maxTextWidth)
|
if (textSize.x > maxTextWidth)
|
||||||
{
|
{
|
||||||
float shrinkRatio = maxTextWidth / textSize.x;
|
squashRatio = maxTextWidth / textSize.x;
|
||||||
size *= shrinkRatio;
|
}
|
||||||
textSize.x *= shrinkRatio;
|
else
|
||||||
textSize.y *= shrinkRatio;
|
{
|
||||||
|
squashRatio = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
return textSize;
|
return textSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ImVec2 ComputeTextSize(ImFont *font, const char *text, float size, float maxTextWidth = FLT_MAX)
|
|
||||||
{
|
|
||||||
return ComputeTextSizeAndRatio(font, text, size, maxTextWidth);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void DrawButton(ImVec2 min, ImVec2 max, const char *buttonText, bool sourceButton, bool buttonEnabled, bool &buttonPressed, float maxTextWidth = FLT_MAX)
|
static void DrawButton(ImVec2 min, ImVec2 max, const char *buttonText, bool sourceButton, bool buttonEnabled, bool &buttonPressed, float maxTextWidth = FLT_MAX)
|
||||||
{
|
{
|
||||||
buttonPressed = false;
|
buttonPressed = false;
|
||||||
|
|
@ -482,7 +478,8 @@ static void DrawButton(ImVec2 min, ImVec2 max, const char *buttonText, bool sour
|
||||||
|
|
||||||
ImFont *font = sourceButton ? g_newRodinFont : g_dfsogeistdFont;
|
ImFont *font = sourceButton ? g_newRodinFont : g_dfsogeistdFont;
|
||||||
float size = Scale(sourceButton ? 15.0f : 20.0f);
|
float size = Scale(sourceButton ? 15.0f : 20.0f);
|
||||||
ImVec2 textSize = ComputeTextSizeAndRatio(font, buttonText, size, Scale(maxTextWidth));
|
float squashRatio;
|
||||||
|
ImVec2 textSize = ComputeTextSize(font, buttonText, size, squashRatio, Scale(maxTextWidth));
|
||||||
min.x += ((max.x - min.x) - textSize.x) / 2.0f;
|
min.x += ((max.x - min.x) - textSize.x) / 2.0f;
|
||||||
min.y += ((max.y - min.y) - textSize.y) / 2.0f;
|
min.y += ((max.y - min.y) - textSize.y) / 2.0f;
|
||||||
|
|
||||||
|
|
@ -492,10 +489,12 @@ static void DrawButton(ImVec2 min, ImVec2 max, const char *buttonText, bool sour
|
||||||
min.y -= Scale(1.0f);
|
min.y -= Scale(1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SetOrigin({ min.x + textSize.x / 2.0f, min.y });
|
||||||
|
SetScale({ squashRatio, 1.0f });
|
||||||
SetGradient
|
SetGradient
|
||||||
(
|
(
|
||||||
min,
|
min,
|
||||||
{ min.x + textSize.x, min.y + textSize.y },
|
{ min.x + textSize.x, textSize.y },
|
||||||
IM_COL32(baser + 192, 255, 0, 255),
|
IM_COL32(baser + 192, 255, 0, 255),
|
||||||
IM_COL32(baser + 128, baseg + 170, 0, 255)
|
IM_COL32(baser + 128, baseg + 170, 0, 255)
|
||||||
);
|
);
|
||||||
|
|
@ -512,6 +511,8 @@ static void DrawButton(ImVec2 min, ImVec2 max, const char *buttonText, bool sour
|
||||||
);
|
);
|
||||||
|
|
||||||
ResetGradient();
|
ResetGradient();
|
||||||
|
SetScale({ 1.0f, 1.0f });
|
||||||
|
SetOrigin({ 0.0f, 0.0f });
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ButtonColumn
|
enum ButtonColumn
|
||||||
|
|
@ -735,24 +736,25 @@ static void DrawSourcePickers()
|
||||||
{
|
{
|
||||||
constexpr float ADD_BUTTON_MAX_TEXT_WIDTH = 160.0f;
|
constexpr float ADD_BUTTON_MAX_TEXT_WIDTH = 160.0f;
|
||||||
const std::string &addFilesText = Localise("Installer_Button_AddFiles");
|
const std::string &addFilesText = Localise("Installer_Button_AddFiles");
|
||||||
ImVec2 textSize = ComputeTextSize(g_dfsogeistdFont, addFilesText.c_str(), 20.0f, ADD_BUTTON_MAX_TEXT_WIDTH);
|
float squashRatio;
|
||||||
|
ImVec2 textSize = ComputeTextSize(g_dfsogeistdFont, addFilesText.c_str(), 20.0f, squashRatio, ADD_BUTTON_MAX_TEXT_WIDTH);
|
||||||
textSize.x += BUTTON_TEXT_GAP;
|
textSize.x += BUTTON_TEXT_GAP;
|
||||||
|
|
||||||
ImVec2 min = { Scale(AlignToNextGrid(CONTAINER_X) + BOTTOM_X_GAP), Scale(AlignToNextGrid(CONTAINER_Y + CONTAINER_HEIGHT) + BOTTOM_Y_GAP) };
|
ImVec2 min = { Scale(AlignToNextGrid(CONTAINER_X) + BOTTOM_X_GAP), Scale(AlignToNextGrid(CONTAINER_Y + CONTAINER_HEIGHT) + BOTTOM_Y_GAP) };
|
||||||
ImVec2 max = { Scale(AlignToNextGrid(CONTAINER_X) + BOTTOM_X_GAP + textSize.x), Scale(AlignToNextGrid(CONTAINER_Y + CONTAINER_HEIGHT) + BOTTOM_Y_GAP + BUTTON_HEIGHT) };
|
ImVec2 max = { Scale(AlignToNextGrid(CONTAINER_X) + BOTTOM_X_GAP + textSize.x * squashRatio), Scale(AlignToNextGrid(CONTAINER_Y + CONTAINER_HEIGHT) + BOTTOM_Y_GAP + BUTTON_HEIGHT) };
|
||||||
DrawButton(min, max, addFilesText.c_str(), false, true, buttonPressed, ADD_BUTTON_MAX_TEXT_WIDTH);
|
DrawButton(min, max, addFilesText.c_str(), false, true, buttonPressed, ADD_BUTTON_MAX_TEXT_WIDTH);
|
||||||
if (buttonPressed && ShowFilesPicker(paths))
|
if (buttonPressed && ShowFilesPicker(paths))
|
||||||
{
|
{
|
||||||
ParseSourcePaths(paths);
|
ParseSourcePaths(paths);
|
||||||
}
|
}
|
||||||
|
|
||||||
min.x += Scale(BOTTOM_X_GAP + textSize.x);
|
min.x += Scale(BOTTOM_X_GAP + textSize.x * squashRatio);
|
||||||
|
|
||||||
const std::string &addFolderText = Localise("Installer_Button_AddFolder");
|
const std::string &addFolderText = Localise("Installer_Button_AddFolder");
|
||||||
textSize = ComputeTextSize(g_dfsogeistdFont, addFolderText.c_str(), 20.0f, ADD_BUTTON_MAX_TEXT_WIDTH);
|
textSize = ComputeTextSize(g_dfsogeistdFont, addFolderText.c_str(), 20.0f, squashRatio, ADD_BUTTON_MAX_TEXT_WIDTH);
|
||||||
textSize.x += BUTTON_TEXT_GAP;
|
textSize.x += BUTTON_TEXT_GAP;
|
||||||
|
|
||||||
max.x = min.x + Scale(textSize.x);
|
max.x = min.x + Scale(textSize.x * squashRatio);
|
||||||
DrawButton(min, max, addFolderText.c_str(), false, true, buttonPressed, ADD_BUTTON_MAX_TEXT_WIDTH);
|
DrawButton(min, max, addFolderText.c_str(), false, true, buttonPressed, ADD_BUTTON_MAX_TEXT_WIDTH);
|
||||||
if (buttonPressed && ShowFoldersPicker(paths))
|
if (buttonPressed && ShowFoldersPicker(paths))
|
||||||
{
|
{
|
||||||
|
|
@ -856,15 +858,17 @@ static void DrawNextButton()
|
||||||
skipButton = std::all_of(g_dlcSourcePaths.begin(), g_dlcSourcePaths.end(), [](const std::filesystem::path &path) { return path.empty(); });
|
skipButton = std::all_of(g_dlcSourcePaths.begin(), g_dlcSourcePaths.end(), [](const std::filesystem::path &path) { return path.empty(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float squashRatio;
|
||||||
|
constexpr float NEXT_BUTTON_MAX_TEXT_WIDTH = 100.0f;
|
||||||
const std::string &buttonText = Localise(skipButton ? "Installer_Button_Skip" : "Installer_Button_Next");
|
const std::string &buttonText = Localise(skipButton ? "Installer_Button_Skip" : "Installer_Button_Next");
|
||||||
ImVec2 textSize = g_newRodinFont->CalcTextSizeA(20.0f, FLT_MAX, 0.0f, buttonText.c_str());
|
ImVec2 textSize = ComputeTextSize(g_newRodinFont, buttonText.c_str(), 20.0f, squashRatio, NEXT_BUTTON_MAX_TEXT_WIDTH);
|
||||||
textSize.x += BUTTON_TEXT_GAP;
|
textSize.x += BUTTON_TEXT_GAP;
|
||||||
|
|
||||||
ImVec2 min = { Scale(AlignToNextGrid(CONTAINER_X + CONTAINER_WIDTH) - textSize.x - BOTTOM_X_GAP), Scale(AlignToNextGrid(CONTAINER_Y + CONTAINER_HEIGHT) + BOTTOM_Y_GAP) };
|
ImVec2 min = { Scale(AlignToNextGrid(CONTAINER_X + CONTAINER_WIDTH) - textSize.x * squashRatio - BOTTOM_X_GAP), Scale(AlignToNextGrid(CONTAINER_Y + CONTAINER_HEIGHT) + BOTTOM_Y_GAP) };
|
||||||
ImVec2 max = { Scale(AlignToNextGrid(CONTAINER_X + CONTAINER_WIDTH) - BOTTOM_X_GAP), Scale(AlignToNextGrid(CONTAINER_Y + CONTAINER_HEIGHT) + BOTTOM_Y_GAP + BUTTON_HEIGHT) };
|
ImVec2 max = { Scale(AlignToNextGrid(CONTAINER_X + CONTAINER_WIDTH) - BOTTOM_X_GAP), Scale(AlignToNextGrid(CONTAINER_Y + CONTAINER_HEIGHT) + BOTTOM_Y_GAP + BUTTON_HEIGHT) };
|
||||||
|
|
||||||
bool buttonPressed = false;
|
bool buttonPressed = false;
|
||||||
DrawButton(min, max, buttonText.c_str(), false, nextButtonEnabled, buttonPressed);
|
DrawButton(min, max, buttonText.c_str(), false, nextButtonEnabled, buttonPressed, NEXT_BUTTON_MAX_TEXT_WIDTH);
|
||||||
|
|
||||||
if (buttonPressed)
|
if (buttonPressed)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue