Update style

This commit is contained in:
Grinch_ 2021-11-05 15:59:11 +06:00
parent ff34e6ac3d
commit ca4cbcb663
22 changed files with 2273 additions and 115 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,9 @@
"Washington Ammunation": "0, -65, -1479, 10", "Washington Ammunation": "0, -65, -1479, 10",
"Washington Beach Ammunation": "0, 200, -474, 11" "Washington Beach Ammunation": "0, 200, -474, 11"
}, },
"Custom": {
"Test": "0, -825, 1168, 10"
},
"Misc": { "Misc": {
"1102 Safe House": "0, 95, -808, 10", "1102 Safe House": "0, 95, -808, 10",
"Air Reserve Fort": "0, -1731, -307, 14", "Air Reserve Fort": "0, -1731, -307, 14",
@ -43,4 +46,4 @@
"Vice Point Pay n Spray": "0, 330, 429, 11", "Vice Point Pay n Spray": "0, 330, 429, 11",
"Vice Port Pay n Spray": "0, -912, -1269, 11" "Vice Port Pay n Spray": "0, -912, -1269, 11"
} }
} }

View File

@ -35,16 +35,21 @@ void CheatMenu::DrawWindow()
} }
ImGui::SetNextWindowSize(m_fMenuSize); ImGui::SetNextWindowSize(m_fMenuSize);
if (ImGui::Begin(MENU_TITLE, &m_bShowMenu, ImGuiWindowFlags_NoCollapse)) if (ImGui::Begin(MENU_TITLE, NULL, ImGuiWindowFlags_NoCollapse || ImGuiWindowFlags_NoTitleBar))
{ {
m_bShowMenu = !Ui::DrawTitleBar();
ImGui::PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(250, 350)); ImGui::PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(250, 350));
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImGui::PushStyleVar(ImGuiStyleVar_FramePadding,
ImVec2(ImGui::GetWindowWidth() / 85, ImGui::GetWindowHeight() / 200)); ImVec2(ImGui::GetWindowWidth() / 85, ImGui::GetWindowHeight() / 200));
if (Updater::m_State == UPDATER_UPDATE_FOUND) if (Updater::m_State == UPDATER_UPDATE_FOUND)
{
Updater::ShowUpdateScreen(); Updater::ShowUpdateScreen();
}
else else
{
Ui::DrawHeaders(header); Ui::DrawHeaders(header);
}
m_fMenuSize = ImGui::GetWindowSize(); m_fMenuSize = ImGui::GetWindowSize();
gConfig.SetValue("window.sizeX", m_fMenuSize.x); gConfig.SetValue("window.sizeX", m_fMenuSize.x);
@ -113,71 +118,63 @@ void CheatMenu::ApplyStyle()
ImGuiStyle* style = &ImGui::GetStyle(); ImGuiStyle* style = &ImGui::GetStyle();
ImVec4* colors = style->Colors; ImVec4* colors = style->Colors;
style->WindowRounding = 1; style->WindowPadding = ImVec2(8, 8);
style->ScrollbarRounding = 1; style->WindowRounding = 5.0f;
style->GrabRounding = 1; style->FramePadding = ImVec2(8, 8);
style->WindowRounding = 1; style->FrameRounding = 5.0f;
style->ChildRounding = 1; style->PopupRounding = 5.0f;
style->ScrollbarRounding = 1; style->ItemSpacing = ImVec2(7, 7);
style->GrabRounding = 1; style->ItemInnerSpacing = ImVec2(7, 7);
style->FrameRounding = 0; style->IndentSpacing = 25.0f;
style->TabRounding = 1.0; style->ScrollbarSize = 12.0f;
style->AntiAliasedLines = true; style->ScrollbarRounding = 10.0f;
style->AntiAliasedFill = true; style->GrabMinSize = 5.0f;
style->Alpha = 1; style->GrabRounding = 3.0f;
style->FrameBorderSize = 0;
style->ChildBorderSize = 0; style->ChildBorderSize = 0;
style->TabBorderSize = 0;
style->WindowBorderSize = 0; style->WindowBorderSize = 0;
style->FrameBorderSize = 0;
style->TabBorderSize = 0;
style->PopupBorderSize = 0; style->PopupBorderSize = 0;
colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); style->Colors[ImGuiCol_Text] = ImVec4(0.80f, 0.80f, 0.83f, 1.00f);
colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f); style->Colors[ImGuiCol_TextDisabled] = ImVec4(0.35f, 0.33f, 0.3f, 1.00f);
colors[ImGuiCol_WindowBg] = ImVec4(0.06f, 0.06f, 0.06f, 0.94f); style->Colors[ImGuiCol_WindowBg] = ImVec4(0.06f, 0.05f, 0.06f, 0.95f);
colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); style->Colors[ImGuiCol_ChildBg] = ImVec4(0.0f, 0.0f, 0.0f, 0.0f);
colors[ImGuiCol_PopupBg] = ImVec4(0.08f, 0.08f, 0.08f, 0.94f); style->Colors[ImGuiCol_PopupBg] = ImVec4(0.07f, 0.07f, 0.09f, 0.95f);
colors[ImGuiCol_Border] = ImVec4(0.43f, 0.43f, 0.50f, 0.50f); style->Colors[ImGuiCol_Border] = ImVec4(0.12f, 0.12f, 0.12f, 1.0f);
colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); style->Colors[ImGuiCol_BorderShadow] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
colors[ImGuiCol_FrameBg] = ImVec4(0.16f, 0.29f, 0.48f, 0.54f); style->Colors[ImGuiCol_FrameBg] = ImVec4(0.12f, 0.12f, 0.12f, 0.95f);
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.40f); style->Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f);
colors[ImGuiCol_FrameBgActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f); style->Colors[ImGuiCol_FrameBgActive] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f);
colors[ImGuiCol_TitleBg] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f); style->Colors[ImGuiCol_TitleBg] = ImVec4(0.12f, 0.12f, 0.12f, 0.94f);
colors[ImGuiCol_TitleBgActive] = ImVec4(0.16f, 0.29f, 0.48f, 1.00f); style->Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(1.00f, 0.98f, 0.95f, 0.75f);
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 0.51f); style->Colors[ImGuiCol_TitleBgActive] = ImVec4(0.07f, 0.07f, 0.09f, 1.00f);
colors[ImGuiCol_MenuBarBg] = ImVec4(0.14f, 0.14f, 0.14f, 1.00f); style->Colors[ImGuiCol_MenuBarBg] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f);
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.02f, 0.02f, 0.02f, 0.53f); style->Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f);
colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.31f, 0.31f, 0.31f, 1.00f); style->Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.80f, 0.80f, 0.83f, 0.31f);
colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); style->Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f);
colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.51f, 0.51f, 0.51f, 1.00f); style->Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
colors[ImGuiCol_CheckMark] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); style->Colors[ImGuiCol_CheckMark] = ImVec4(0.80f, 0.80f, 0.83f, 0.31f);
colors[ImGuiCol_SliderGrab] = ImVec4(0.24f, 0.52f, 0.88f, 1.00f); style->Colors[ImGuiCol_SliderGrab] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
colors[ImGuiCol_SliderGrabActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); style->Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
colors[ImGuiCol_Button] = ImVec4(0.26f, 0.59f, 0.98f, 0.40f); style->Colors[ImGuiCol_Separator] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f);
colors[ImGuiCol_ButtonHovered] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); style->Colors[ImGuiCol_Button] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f);
colors[ImGuiCol_ButtonActive] = ImVec4(0.06f, 0.53f, 0.98f, 1.00f); style->Colors[ImGuiCol_ButtonHovered] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f);
colors[ImGuiCol_Header] = ImVec4(0.26f, 0.59f, 0.98f, 0.0f); style->Colors[ImGuiCol_ButtonActive] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
colors[ImGuiCol_HeaderHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.80f); style->Colors[ImGuiCol_Tab] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f);
colors[ImGuiCol_HeaderActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); style->Colors[ImGuiCol_TabHovered] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f);
colors[ImGuiCol_Separator] = ImVec4(0.43f, 0.43f, 0.50f, 0.50f); style->Colors[ImGuiCol_TabActive] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.10f, 0.40f, 0.75f, 0.78f); style->Colors[ImGuiCol_Header] = ImVec4(0.0f, 0.0f, 0.0f, 0.0f);
colors[ImGuiCol_SeparatorActive] = ImVec4(0.10f, 0.40f, 0.75f, 1.00f); style->Colors[ImGuiCol_HeaderHovered] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f);
colors[ImGuiCol_ResizeGrip] = ImVec4(0.26f, 0.59f, 0.98f, 0.0f); style->Colors[ImGuiCol_HeaderActive] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f);
colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f); style->Colors[ImGuiCol_ResizeGrip] = ImVec4(0.12f, 0.12f, 0.12f, 0.00f);
colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f); style->Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f);
colors[ImGuiCol_Tab] = ImVec4(0.18f, 0.35f, 0.58f, 0.86f); style->Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
colors[ImGuiCol_TabHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.80f); style->Colors[ImGuiCol_PlotLines] = ImVec4(0.40f, 0.39f, 0.38f, 0.63f);
colors[ImGuiCol_TabActive] = ImVec4(0.20f, 0.41f, 0.68f, 1.00f); style->Colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.25f, 1.00f, 0.00f, 1.00f);
colors[ImGuiCol_TabUnfocused] = ImVec4(0.07f, 0.10f, 0.15f, 0.97f); style->Colors[ImGuiCol_PlotHistogram] = ImVec4(0.40f, 0.39f, 0.38f, 0.63f);
colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.14f, 0.26f, 0.42f, 1.00f); style->Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(0.25f, 1.00f, 0.00f, 1.00f);
colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f); style->Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f); style->Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.6f);
colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f);
colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f);
colors[ImGuiCol_NavHighlight] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f);
colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f);
colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f);
} }

42
src/fontmgr.cpp Normal file
View File

@ -0,0 +1,42 @@
#include "fontmgr.h"
#include "pch.h"
ImFont* FontMgr::GetFont(const char* fontName)
{
for (auto &data : m_vecFonts)
{
if (data.m_path == std::string(fontName))
{
return data.m_pFont;
}
}
return nullptr;
}
ImFont* FontMgr::LoadFont(const char* fontName, float fontMul)
{
ImGuiIO& io = ImGui::GetIO();
size_t fontSize = static_cast<int>(screen::GetScreenHeight() / 54.85f) * fontMul;
std::string fullPath = std::string(PLUGIN_PATH((char*)"CheatMenu/fonts/")) + fontName + ".ttf";
m_vecFonts.push_back({io.Fonts->AddFontFromFileTTF(fullPath.c_str(), fontSize), fontSize,
std::string(fontName)});
io.Fonts->Build();
return m_vecFonts.back().m_pFont;
}
void FontMgr::ReinitFonts()
{
ImGuiIO& io = ImGui::GetIO();
io.Fonts->Clear();
for (auto &data : m_vecFonts)
{
std::string fullPath = PLUGIN_PATH((char*)"CheatMenu/fonts/") + data.m_path + ".ttf";
data.m_pFont = io.Fonts->AddFontFromFileTTF(fullPath.c_str(), data.fontSize);
}
io.FontDefault = GetFont("text");
io.Fonts->Build();
}

25
src/fontmgr.h Normal file
View File

@ -0,0 +1,25 @@
#pragma once
#include "pch.h"
class FontMgr
{
private:
struct FontInfo
{
ImFont *m_pFont;
size_t fontSize;
std::string m_path;
};
public:
static inline std::vector<FontInfo> m_vecFonts;
FontMgr() = delete;
FontMgr(FontMgr&) = delete;
static ImFont* GetFont(const char* fontName);
static ImFont* LoadFont(const char* fontName, float fontMul = 1.0f);
static void ReinitFonts();
};

View File

@ -50,10 +50,7 @@ void Hook::RenderFrame(void* ptr)
ImVec2 size(screen::GetScreenWidth(), screen::GetScreenHeight()); ImVec2 size(screen::GetScreenWidth(), screen::GetScreenHeight());
if (fScreenSize.x != size.x && fScreenSize.y != size.y) if (fScreenSize.x != size.x && fScreenSize.y != size.y)
{ {
int fontSize = static_cast<int>(size.y / 54.85f); // manually tested FontMgr::ReinitFonts();
io.FontDefault = io.Fonts->AddFontFromFileTTF("C:/Windows/Fonts/trebucbd.ttf", fontSize);
io.Fonts->Build();
if (gRenderer == Render_DirectX9) if (gRenderer == Render_DirectX9)
{ {
@ -68,11 +65,11 @@ void Hook::RenderFrame(void* ptr)
float scaleX = size.x / 1366.0f; float scaleX = size.x / 1366.0f;
float scaleY = size.y / 768.0f; float scaleY = size.y / 768.0f;
style->FramePadding = ImVec2(5 * scaleX, 3 * scaleY); style->FramePadding = ImVec2(5 * scaleX, 5 * scaleY);
style->ItemSpacing = ImVec2(8 * scaleX, 4 * scaleY); style->ItemSpacing = ImVec2(8 * scaleX, 4 * scaleY);
style->ScrollbarSize = 12 * scaleX; style->ScrollbarSize = 12 * scaleX;
style->IndentSpacing = 20 * scaleX; style->IndentSpacing = 20 * scaleX;
style->ItemInnerSpacing = ImVec2(4 * scaleX, 4 * scaleY); style->ItemInnerSpacing = ImVec2(5 * scaleX, 5 * scaleY);
fScreenSize = size; fScreenSize = size;
} }
@ -133,6 +130,11 @@ void Hook::RenderFrame(void* ptr)
ImGui_ImplWin32_EnableDpiAwareness(); ImGui_ImplWin32_EnableDpiAwareness();
// Loading fonts
io.FontDefault = FontMgr::LoadFont("text", 1.0f);
FontMgr::LoadFont("title", 2.0f);
FontMgr::LoadFont("header", 1.25f);
io.IniFilename = nullptr; io.IniFilename = nullptr;
io.LogFilename = nullptr; io.LogFilename = nullptr;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;

View File

@ -2,5 +2,5 @@
#define MENU_NAME "Cheat Menu" #define MENU_NAME "Cheat Menu"
#define MENU_VERSION_NUMBER "3.0" #define MENU_VERSION_NUMBER "3.0"
#define MENU_VERSION MENU_VERSION_NUMBER"-beta" #define MENU_VERSION MENU_VERSION_NUMBER"-beta"
#define BUILD_NUMBER "20211101" #define BUILD_NUMBER "20211106"
#define MENU_TITLE MENU_NAME " v" MENU_VERSION "(" BUILD_NUMBER ")" #define MENU_TITLE MENU_NAME " v" MENU_VERSION

View File

@ -5,6 +5,7 @@
#define SPAWN_PED_LIMIT 20 #define SPAWN_PED_LIMIT 20
#define DISCORD_INVITE "https://discord.gg/ZzW7kmf" #define DISCORD_INVITE "https://discord.gg/ZzW7kmf"
#define GITHUB_LINK "https://github.com/user-grinch/Cheat-Menu" #define GITHUB_LINK "https://github.com/user-grinch/Cheat-Menu"
#define IMGUI_DEFINE_MATH_OPERATORS
#ifdef GTASA #ifdef GTASA
#define BY_GAME(sa, vc, iii) sa #define BY_GAME(sa, vc, iii) sa
@ -71,6 +72,7 @@
#include "hotkeys.h" #include "hotkeys.h"
#include "vKeys.h" #include "vKeys.h"
#include "resourcestore.h" #include "resourcestore.h"
#include "fontmgr.h"
using CallbackTable = std::vector<std::pair<std::string, void(*)()>>; using CallbackTable = std::vector<std::pair<std::string, void(*)()>>;
using namespace plugin; using namespace plugin;

View File

@ -1,6 +1,123 @@
#include "pch.h" #include "pch.h"
#include "util.h" #include "util.h"
#include "ui.h" #include "ui.h"
#include "../depend/imgui/imgui_internal.h"
#include "menuinfo.h"
// Really messy code, cleanup someday
bool Ui::DrawTitleBar()
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
ImGuiID id = window->GetID("#CLOSE");
ImGui::PushFont(FontMgr::GetFont("title"));
CenterdText(MENU_TITLE);
if (!ImGui::IsWindowHovered(ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows
| ImGuiHoveredFlags_AllowWhenBlockedByPopup | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem))
{
ImGui::PopFont();
return false;
}
ImVec2 rectMin = ImGui::GetItemRectMin(); // get pos of title text
ImGuiStyle& Style = ImGui::GetStyle();
float framePadding = Style.FramePadding.x;
float fontSize = ImGui::GetFontSize();
ImRect title_bar_rect = window->TitleBarRect();
ImVec2 pos = ImVec2(title_bar_rect.Max.x - framePadding*2 - fontSize, title_bar_rect.Min.y);
// drawing the close button
const ImRect bb(pos, pos + ImVec2(g.FontSize, g.FontSize) + g.Style.FramePadding * 2.0f);
ImRect bb_interact = bb;
const float area_to_visible_ratio = window->OuterRectClipped.GetArea() / bb.GetArea();
if (area_to_visible_ratio < 1.5f)
{
bb_interact.Expand(ImFloor(bb_interact.GetSize() * -0.25f));
}
bool hovered, held;
bool pressed = ImGui::ButtonBehavior(bb_interact, id, &hovered, &held);
float cross_extent = (fontSize * 0.3f) - 1.0f;
ImVec2 closePos = ImVec2(bb.GetCenter().x - cross_extent, rectMin.y);
ImU32 closeCol = ImGui::GetColorU32(held || hovered ? ImVec4(0.80f, 0.0f, 0.0f, 1.0f) : ImVec4(0.80f, 0.80f, 0.80f, 1.00f));
window->DrawList->AddText(closePos, closeCol, " X ");
ImGui::PopFont();
return pressed;
}
bool Ui::RoundedImageButton(ImTextureID user_texture_id, ImVec2& size, const char* hover_text, int frame_padding, const ImVec4& bg_col, const ImVec4& tint_col)
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
if (window->SkipItems)
return false;
// Default to using texture ID as ID. User can still push string/integer prefixes.
ImGui::PushID((void*)(intptr_t)user_texture_id);
const ImGuiID id = window->GetID("#image");
ImGui::PopID();
ImVec2 padding = (frame_padding >= 0) ? ImVec2((float)frame_padding, (float)frame_padding) : g.Style.FramePadding;
if (window->SkipItems)
return false;
const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size + padding * 2);
ImGui::ItemSize(bb);
if (!ImGui::ItemAdd(bb, id))
return false;
bool hovered, held;
bool pressed = ImGui::ButtonBehavior(bb, id, &hovered, &held);
// Render
const ImU32 col = ImGui::GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
ImGui::RenderNavHighlight(bb, id);
ImGui::RenderFrame(bb.Min, bb.Max, col, true, ImClamp((float)ImMin(padding.x, padding.y), 0.0f, g.Style.FrameRounding));
if (bg_col.w > 0.0f)
window->DrawList->AddRectFilled(bb.Min + padding, bb.Max - padding, ImGui::GetColorU32(bg_col));
window->DrawList->AddImageRounded(user_texture_id, bb.Min + padding, bb.Max - padding, ImVec2(0, 0), ImVec2(1, 1), ImGui::GetColorU32(tint_col), 5.0f);
if (ImGui::IsItemHovered())
{
ImDrawList* drawlist = ImGui::GetWindowDrawList();
// Drawing selected overlay
ImVec2 btnMin = ImGui::GetItemRectMin();
ImVec2 btnMax = ImGui::GetItemRectMax();
drawlist->AddRectFilled(btnMin, btnMax, ImGui::GetColorU32(ImGuiCol_ModalWindowDimBg), 8.0f);
// Calculating and drawing text over the image
ImVec2 textSize = ImGui::CalcTextSize(hover_text);
if (textSize.x < size.x)
{
float offsetX = (ImGui::GetItemRectSize().x - textSize.x) / 2;
drawlist->AddText(ImVec2(btnMin.x + offsetX, btnMin.y + 10), ImGui::GetColorU32(ImGuiCol_Text), hover_text);
}
else
{
std::string buff = "";
std::stringstream ss(hover_text);
short count = 1;
while (ss >> buff)
{
textSize = ImGui::CalcTextSize(buff.c_str());
float offsetX = (ImGui::GetItemRectSize().x - textSize.x) / 2;
drawlist->AddText(ImVec2(btnMin.x + offsetX, btnMin.y + 10 * count),
ImGui::GetColorU32(ImGuiCol_Text), buff.c_str());
++count;
}
}
}
return pressed;
}
bool Ui::ListBox(const char* label, std::vector<std::string>& all_items, int& selected) bool Ui::ListBox(const char* label, std::vector<std::string>& all_items, int& selected)
{ {
@ -90,9 +207,12 @@ ImVec2 Ui::GetSize(short count, bool spacing)
void Ui::CenterdText(const std::string& text) void Ui::CenterdText(const std::string& text)
{ {
float font_size = ImGui::GetFontSize() * text.size() / 2; ImVec2 size = ImGui::CalcTextSize(text.c_str());
ImGui::NewLine(); ImGui::NewLine();
ImGui::SameLine(ImGui::GetWindowSize().x / 2 - font_size + (font_size / 1.8)); ImGui::SameLine(
((ImGui::GetWindowContentRegionWidth() - size.x) / 2)
);
ImGui::Text(text.c_str()); ImGui::Text(text.c_str());
} }
@ -104,6 +224,7 @@ void Ui::DrawHeaders(CallbackTable& data)
auto colors = ImGui::GetStyle().Colors; auto colors = ImGui::GetStyle().Colors;
ImVec4 btn_col = colors[ImGuiCol_Button]; ImVec4 btn_col = colors[ImGuiCol_Button];
static void* func; static void* func;
ImGui::PushFont(FontMgr::GetFont("header"));
for (auto it = data.begin(); it != data.end(); ++it) for (auto it = data.begin(); it != data.end(); ++it)
{ {
const char* btn_text = it->first.c_str(); const char* btn_text = it->first.c_str();
@ -128,6 +249,7 @@ void Ui::DrawHeaders(CallbackTable& data)
ImGui::SameLine(); ImGui::SameLine();
i++; i++;
} }
ImGui::PopFont();
ImGui::PopStyleVar(); ImGui::PopStyleVar();
ImGui::Dummy(ImVec2(0, 10)); ImGui::Dummy(ImVec2(0, 10));
@ -204,7 +326,7 @@ bool Ui::CheckboxWithHint(const char* label, bool* v, const char* hint, bool is_
// draw the button // draw the button
ImVec2 min = ImGui::GetItemRectMin(); ImVec2 min = ImGui::GetItemRectMin();
ImVec2 max = ImGui::GetItemRectMax(); ImVec2 max = ImGui::GetItemRectMax();
drawlist->AddRectFilled(min, max, color); drawlist->AddRectFilled(min, max, color, ImGui::GetStyle().FrameRounding);
int pad = static_cast<int>(square_sz / 6.0); int pad = static_cast<int>(square_sz / 6.0);
pad = (pad < 1) ? 1 : pad; pad = (pad < 1) ? 1 : pad;
@ -239,7 +361,7 @@ bool Ui::CheckboxWithHint(const char* label, bool* v, const char* hint, bool is_
*v = !*v; *v = !*v;
} }
min = ImGui::GetItemRectMin(); min = ImGui::GetItemRectMin();
drawlist->AddText(ImVec2(min.x, min.y + style.ItemInnerSpacing.y), ImGui::GetColorU32(ImGuiCol_Text), label); drawlist->AddText(ImVec2(min.x, min.y + style.ItemInnerSpacing.y / 2), ImGui::GetColorU32(ImGuiCol_Text), label);
// draw hint // draw hint
if (hint != nullptr) if (hint != nullptr)
@ -247,7 +369,7 @@ bool Ui::CheckboxWithHint(const char* label, bool* v, const char* hint, bool is_
ImGui::SameLine(0, style.ItemInnerSpacing.x); ImGui::SameLine(0, style.ItemInnerSpacing.x);
ImGui::InvisibleButton("?", ImGui::CalcTextSize("?", nullptr, true)); ImGui::InvisibleButton("?", ImGui::CalcTextSize("?", nullptr, true));
min = ImGui::GetItemRectMin(); min = ImGui::GetItemRectMin();
drawlist->AddText(ImVec2(min.x, min.y + style.ItemInnerSpacing.y), ImGui::GetColorU32(ImGuiCol_TextDisabled), drawlist->AddText(ImVec2(min.x, min.y + style.ItemInnerSpacing.y / 2), ImGui::GetColorU32(ImGuiCol_TextDisabled),
"?"); "?");
if (ImGui::IsItemHovered() && !is_disabled) if (ImGui::IsItemHovered() && !is_disabled)
@ -522,6 +644,14 @@ void Ui::DrawImages(ResourceStore &store, std::function<void(std::string&)> onLe
ImGui::Spacing(); ImGui::Spacing();
ImGui::BeginChild("DrawImages"); ImGui::BeginChild("DrawImages");
if (gRenderer == Render_DirectX9)
{
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(3, 3));
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(3, 3));
ImGui::PushStyleVar(ImGuiStyleVar_ItemInnerSpacing, ImVec2(3, 3));
ImGui::PushStyleVar(ImGuiStyleVar_IndentSpacing, 10.0f);
}
for (uint i = 0; i < store.m_ImagesList.size(); ++i) for (uint i = 0; i < store.m_ImagesList.size(); ++i)
{ {
std::string text = store.m_ImagesList[i]->m_FileName; std::string text = store.m_ImagesList[i]->m_FileName;
@ -545,7 +675,7 @@ void Ui::DrawImages(ResourceStore &store, std::function<void(std::string&)> onLe
} }
else else
{ {
if (ImGui::ImageButton(store.m_ImagesList[i]->m_pTexture, m_ImageSize, ImVec2(0, 0), ImVec2(1, 1), 1, ImVec4(1, 1, 1, 1), ImVec4(1, 1, 1, 1))) if (Ui::RoundedImageButton(store.m_ImagesList[i]->m_pTexture, m_ImageSize, modelName.c_str(), 0, ImVec4(0, 0, 0, 0), ImVec4(1, 1, 1, 1)))
{ {
onLeftClick(text); onLeftClick(text);
} }
@ -560,40 +690,6 @@ void Ui::DrawImages(ResourceStore &store, std::function<void(std::string&)> onLe
if (gRenderer != Render_DirectX11) if (gRenderer != Render_DirectX11)
{ {
if (ImGui::IsItemHovered())
{
ImDrawList* drawlist = ImGui::GetWindowDrawList();
// Drawing selected overlay
ImVec2 btnMin = ImGui::GetItemRectMin();
ImVec2 btnMax = ImGui::GetItemRectMax();
drawlist->AddRectFilled(btnMin, btnMax, ImGui::GetColorU32(ImGuiCol_ModalWindowDimBg));
// Calculating and drawing text over the image
ImVec2 textSize = ImGui::CalcTextSize(modelName.c_str());
if (textSize.x < m_ImageSize.x)
{
float offsetX = (ImGui::GetItemRectSize().x - textSize.x) / 2;
drawlist->AddText(ImVec2(btnMin.x + offsetX, btnMin.y + 10), ImGui::GetColorU32(ImGuiCol_Text),
modelName.c_str());
}
else
{
std::string buff = "";
std::stringstream ss(modelName);
short count = 1;
while (ss >> buff)
{
textSize = ImGui::CalcTextSize(buff.c_str());
float offsetX = (ImGui::GetItemRectSize().x - textSize.x) / 2;
drawlist->AddText(ImVec2(btnMin.x + offsetX, btnMin.y + 10 * count),
ImGui::GetColorU32(ImGuiCol_Text), buff.c_str());
++count;
}
}
}
if (imageCount % imagesInRow != 0) if (imageCount % imagesInRow != 0)
{ {
ImGui::SameLine(0.0, ImGui::GetStyle().ItemInnerSpacing.x); ImGui::SameLine(0.0, ImGui::GetStyle().ItemInnerSpacing.x);
@ -603,6 +699,11 @@ void Ui::DrawImages(ResourceStore &store, std::function<void(std::string&)> onLe
} }
} }
if (gRenderer == Render_DirectX9)
{
ImGui::PopStyleVar(4);
}
// Draw popup code // Draw popup code
if (imgPopup.function != nullptr) if (imgPopup.function != nullptr)
{ {

View File

@ -57,7 +57,7 @@ public:
std::function<std::string(std::string&)> get_name_func, std::function<std::string(std::string&)> get_name_func,
std::function<bool(std::string&)> verify_func = nullptr, std::function<bool(std::string&)> verify_func = nullptr,
const char** custom_names = nullptr, size_t length = 0); const char** custom_names = nullptr, size_t length = 0);
static bool DrawTitleBar();
template <typename T> template <typename T>
static void EditAddress(const char* label, int address, int min = 0, int def = 0, int max = 100); static void EditAddress(const char* label, int address, int min = 0, int def = 0, int max = 100);
static void EditBits(const char* label, int address, const std::vector<std::string>& names); static void EditBits(const char* label, int address, const std::vector<std::string>& names);
@ -81,7 +81,7 @@ public:
static void RadioButtonAddress(const char* label, std::vector<NamedMemory>& named_mem); static void RadioButtonAddress(const char* label, std::vector<NamedMemory>& named_mem);
static void RadioButtonAddressEx(const char* label, int addr, std::vector<NamedValue>& named_val); static void RadioButtonAddressEx(const char* label, int addr, std::vector<NamedValue>& named_val);
static bool RoundedImageButton(ImTextureID user_texture_id, ImVec2& size, const char* hover_text, int frame_padding, const ImVec4& bg_col, const ImVec4& tint_col);
static void ColorPickerAddress(const char* label, int base_addr, ImVec4&& default_color); static void ColorPickerAddress(const char* label, int base_addr, ImVec4&& default_color);
static void ShowTooltip(const char* text); static void ShowTooltip(const char* text);
}; };

View File

@ -80,6 +80,8 @@ project "CheatMenuIII"
"../src/ped.cpp", "../src/ped.cpp",
"../src/resourcestore.h", "../src/resourcestore.h",
"../src/resourcestore.cpp", "../src/resourcestore.cpp",
"../src/fontmgr.h",
"../src/fontmgr.cpp",
"../src/hotkeys.h", "../src/hotkeys.h",
"../src/hotkeys.cpp", "../src/hotkeys.cpp",
"../src/vehicle.h", "../src/vehicle.h",
@ -180,6 +182,8 @@ project "CheatMenuVC"
"../src/visual.cpp", "../src/visual.cpp",
"../src/resourcestore.h", "../src/resourcestore.h",
"../src/resourcestore.cpp", "../src/resourcestore.cpp",
"../src/fontmgr.h",
"../src/fontmgr.cpp",
"../src/filehandler.h", "../src/filehandler.h",
"../src/filehandler.cpp", "../src/filehandler.cpp",
"../src/hotkeys.h", "../src/hotkeys.h",