-
Автор темы
- #1
Почему не работает ImGui::GetCurrentWindow().
Вот код файла:
Почему полоска всё-ранво не прикреплена к меню?
Вот код файла:
C++:
#include "Menu.hpp"
#define NOMINMAX
#include <Windows.h>
#include <chrono>
#include "valve_sdk/csgostructs.hpp"
#include "helpers/input.hpp"
#include "options.hpp"
#include "config.hpp"
#define IMGUI_DEFINE_MATH_OPERATORS
#include "imgui/imgui_internal.h"
#include "imgui/impl/imgui_impl_dx9.h"
#include "imgui/impl/imgui_impl_win32.h"
ImGuiWindow* _window;
#pragma region Function
namespace ImGuiEx {
inline bool ColorEdit4(const char* label, Color* v, bool show_alpha = true)
{
auto clr = ImVec4{
v->r() / 255.0f,
v->g() / 255.0f,
v->b() / 255.0f,
v->a() / 255.0f
};
if (ImGui::ColorEdit4(label, &clr.x, show_alpha)) {
v->SetColor(clr.x, clr.y, clr.z, clr.w);
return true;
}
return false;
}
inline bool ColorEdit3(const char* label, Color* v)
{
return ColorEdit4(label, v, false);
}
inline auto RgbaToImVec4(int r, int g, int b, int a) {
return ImVec4{ (float)r / 255, (float)g / 255, (float)b / 255, (float)a / 255 };
}
}
int get_fps()
{
using namespace std::chrono;
static int count = 0;
static auto last = high_resolution_clock::now();
auto now = high_resolution_clock::now();
static int fps = 0;
count++;
if (duration_cast<milliseconds>(now - last).count() > 1000) {
fps = count;
count = 0;
last = now;
}
return fps;
}
void test() {
_window->DrawList->AddRectFilled(ImVec2(), ImVec2(670, 50), ImColor(56, 56, 56));
}
#pragma endregion
//void RenderEmptyTab()
//{
// auto& style = ImGui::GetStyle();
// float group_w = ImGui::GetCurrentWindow()->Size.x - style.WindowPadding.x * 2;
//
// bool placeholder_true = true;
//
// ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
// ImGui::ToggleButton("AIM", &placeholder_true, ImVec2{ group_w, 25.0f });
// ImGui::PopStyleVar();
//
// ImGui::BeginGroupBox("##body_content");
// {
// auto message = "There's nothing here. Add something you want!";
//
// auto pos = ImGui::GetCurrentWindow()->Pos;
// auto wsize = ImGui::GetCurrentWindow()->Size;
//
// pos = pos + wsize / 2.0f;
//
// ImGui::RenderText(pos - ImGui::CalcTextSize(message) / 2.0f, message);
// }
// ImGui::EndGroupBox();
//}
void Menu::Initialize()
{
CreateStyle();
_visible = true;
}
void Menu::Shutdown()
{
ImGui_ImplDX9_Shutdown();
ImGui_ImplWin32_Shutdown();
ImGui::DestroyContext();
}
void Menu::OnDeviceLost()
{
ImGui_ImplDX9_InvalidateDeviceObjects();
}
void Menu::OnDeviceReset()
{
ImGui_ImplDX9_CreateDeviceObjects();
}
void Menu::Render()
{
ImGui::GetIO().MouseDrawCursor = _visible;
if(!_visible)
return;
ImGui::SetNextWindowPos(ImVec2{ 0, 0 }, ImGuiSetCond_Once);
ImGui::SetNextWindowSize(ImVec2{ 1000, 400 }, ImGuiSetCond_Once);
// https://github.com/spirthack/CSGOSimple/issues/63
// quick fix
if (ImGui::Begin("CSGOSimple", &_visible, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar)) {
_window = ImGui::GetCurrentWindow();
test();
ImGui::End();
}
}
void Menu::Toggle()
{
_visible = !_visible;
}
void Menu::CreateStyle()
{
ImGui::StyleColorsDark();
ImGui::SetColorEditOptions(ImGuiColorEditFlags_HEX);
_style.FrameRounding = 0.f;
_style.WindowRounding = 0.f;
_style.ChildRounding = 0.f;
_style.Colors[ImGuiCol_Button] = ImVec4(0.260f, 0.590f, 0.980f, 0.670f);
_style.Colors[ImGuiCol_Header] = ImVec4(0.260f, 0.590f, 0.980f, 0.670f);
_style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.260f, 0.590f, 0.980f, 1.000f);
//_style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.000f, 0.545f, 1.000f, 1.000f);
//_style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.060f, 0.416f, 0.980f, 1.000f);
_style.Colors[ImGuiCol_FrameBg] = ImVec4(0.20f, 0.25f, 0.30f, 1.0f);
_style.Colors[ImGuiCol_WindowBg] = ImVec4(0.000f, 0.009f, 0.120f, 0.940f);
_style.Colors[ImGuiCol_PopupBg] = ImVec4(0.076f, 0.143f, 0.209f, 1.000f);
ImGui::GetStyle() = _style;
}