Added the possibility to create new fonts.

Fonts cannot be created after a NewFrame call.
This commit is contained in:
Nemirtingas 2019-09-05 09:00:02 +02:00
parent e82579b82c
commit 6c09635600
8 changed files with 70 additions and 50 deletions

View File

@ -100,11 +100,11 @@ void OpenGLX_Hook::prepareForOverlay(Display* display, GLXDrawable drawable)
context = glXCreateContext(display, visual_info, nullptr, True);
this->display = display;
get_steam_client()->steam_overlay->CreateFonts();
initialized = true;
}
ImGuiIO& io = ImGui::GetIO();
auto oldContext = glXGetCurrentContext();
glXMakeCurrent(display, drawable, context);
@ -114,9 +114,7 @@ void OpenGLX_Hook::prepareForOverlay(Display* display, GLXDrawable drawable)
ImGui::NewFrame();
get_steam_client()->steam_overlay->OverlayProc(io.DisplaySize.x, io.DisplaySize.y);
ImGui::EndFrame();
get_steam_client()->steam_overlay->OverlayProc();
ImGui::Render();

View File

@ -86,7 +86,7 @@ void Steam_Overlay::SetupOverlay()
void Steam_Overlay::HookReady()
{
if (!is_ready) // If this is the first time we are ready, hook directinput and xinput, so we can intercept em and disable mouse.
if (!is_ready)
{
// TODO: Uncomment this and draw our own cursor (cosmetics)
//ImGuiIO &io = ImGui::GetIO();
@ -98,10 +98,6 @@ void Steam_Overlay::HookReady()
}
}
// https://niemand.com.ar/2019/01/01/how-to-hook-directx-11-imgui/
// https://github.com/spazzarama/Direct3DHook/blob/master/Capture/Hook
// https://github.com/unknownv2/LinuxDetours
void Steam_Overlay::OpenOverlayInvite(CSteamID lobbyId)
{
ShowOverlay(true);
@ -172,7 +168,7 @@ void Steam_Overlay::ShowOverlay(bool state)
void Steam_Overlay::NotifyUser(friend_window_state& friend_state, std::string const& message)
{
if (!(friend_state.window_state & window_state_show))
if (!(friend_state.window_state & window_state_show) || !show_overlay)
{
friend_state.window_state |= window_state_need_attention;
#ifdef __WINDOWS__
@ -385,10 +381,16 @@ void Steam_Overlay::BuildFriendWindow(Friend const& frd, friend_window_state& st
ImGui::End();
}
ImFont *font_default;
ImFont *font_notif;
void Steam_Overlay::BuildNotifications(int width, int height)
{
auto now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch());
int i = 0;
int font_size = ImGui::GetFontSize();
for (auto it = notifications.begin(); it != notifications.end(); ++it, ++i)
{
auto elapsed_notif = now - it->start_time;
@ -414,8 +416,8 @@ void Steam_Overlay::BuildNotifications(int width, int height)
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(255, 255, 255, Notification::max_alpha*2));
}
ImGui::SetNextWindowPos(ImVec2((float)width - Notification::width, (float)Notification::height * i ));
ImGui::SetNextWindowSize(ImVec2( Notification::width, Notification::height ));
ImGui::SetNextWindowPos(ImVec2((float)width - width * Notification::width, Notification::height * font_size * i ));
ImGui::SetNextWindowSize(ImVec2( width * Notification::width, Notification::height * font_size ));
ImGui::Begin(std::to_string(10000+i).c_str(), nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBringToFrontOnFocus |
ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMouseInputs);
@ -430,15 +432,38 @@ void Steam_Overlay::BuildNotifications(int width, int height)
}), notifications.end());
}
void Steam_Overlay::CreateFonts()
{
ImGuiIO& io = ImGui::GetIO();
ImFontConfig fontcfg;
fontcfg.OversampleH = fontcfg.OversampleV = 1;
fontcfg.PixelSnapH = true;
fontcfg.GlyphRanges = io.Fonts->GetGlyphRangesDefault();
fontcfg.SizePixels = std::round(io.DisplaySize.y / 68);
font_default = io.Fonts->AddFontDefault(&fontcfg);
fontcfg.SizePixels = std::round(io.DisplaySize.y / 60);
font_notif = io.Fonts->AddFontDefault(&fontcfg);
ImGuiStyle& style = ImGui::GetStyle();
style.WindowRounding = 0.0; // Disable round window
}
// Try to make this function as short as possible or it might affect game's fps.
void Steam_Overlay::OverlayProc( int width, int height )
void Steam_Overlay::OverlayProc()
{
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (!Ready())
return;
BuildNotifications(width, height);
ImGuiIO& io = ImGui::GetIO();
ImGui::PushFont(font_notif);
BuildNotifications(io.DisplaySize.x, io.DisplaySize.y);
ImGui::PopFont();
if (show_overlay)
{
@ -446,12 +471,12 @@ void Steam_Overlay::OverlayProc( int width, int height )
// Set the overlay windows to the size of the game window
ImGui::SetNextWindowPos({ 0,0 });
ImGui::SetNextWindowSize({ static_cast<float>(width),
static_cast<float>(height) });
ImGui::SetNextWindowSize({ static_cast<float>(io.DisplaySize.x),
static_cast<float>(io.DisplaySize.y) });
ImGui::SetNextWindowBgAlpha(0.50);
ImGuiStyle& style = ImGui::GetStyle();
style.WindowRounding = 0.0; // Disable round window
ImGui::PushFont(font_default);
if (ImGui::Begin("SteamOverlay", nullptr, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBringToFrontOnFocus))
{
@ -487,6 +512,8 @@ void Steam_Overlay::OverlayProc( int width, int height )
}
}
ImGui::End();
ImGui::PopFont();
}// if(show_overlay)
}
@ -507,7 +534,7 @@ void Steam_Overlay::Callback(Common_Message *msg)
friend_info->second.window_state |= window_state_need_attention;
}
AddNotification(friend_info->first.name() + " says: " + steam_message.message());
NotifyUser(friend_info->second, friend_info->first.name() + " says: " + steam_message.message());
}
}
}

View File

@ -41,8 +41,8 @@ struct Friend_Less
struct Notification
{
static constexpr float width = 200.0;
static constexpr float height = 60.0;
static constexpr float width = 0.25;
static constexpr float height = 4.0;
static constexpr std::chrono::milliseconds fade_in = std::chrono::milliseconds(2000);
static constexpr std::chrono::milliseconds fade_out = std::chrono::milliseconds(2000);
static constexpr std::chrono::milliseconds show_time = std::chrono::milliseconds(6000) + fade_in + fade_out;
@ -117,7 +117,8 @@ public:
void HookReady();
void OverlayProc(int width, int height);
void CreateFonts();
void OverlayProc();
void OpenOverlayInvite(CSteamID lobbyId);
void OpenOverlay(const char* pchDialog);
@ -139,7 +140,7 @@ public:
class Steam_Overlay
{
public:
Steam_Overlay(Settings* settings, SteamCallResults* callback_results, SteamCallBacks* callbacks, RunEveryRunCB* run_every_runcb, Networking *network) {}
Steam_Overlay(Settings* settings, SteamCallResults* callback_results, SteamCallBacks* callbacks, RunEveryRunCB* run_every_runcb, Networking* network) {}
~Steam_Overlay() {}
bool Ready() const { return false; }
@ -151,13 +152,15 @@ public:
void SetNotificationInset(int nHorizontalInset, int nVerticalInset) {}
void SetupOverlay() {}
void HookReady(void* hWnd) {}
void HookReady() {}
void OverlayProc(int width, int height) {}
void CreateFonts() {}
void OverlayProc() {}
void OpenOverlayInvite(CSteamID lobbyId) {}
void OpenOverlay(const char* pchDialog) {}
bool ShowOverlay() const {}
void ShowOverlay(bool state) {}
void SetLobbyInvite(Friend friendId, uint64 lobbyId) {}

View File

@ -75,6 +75,8 @@ void DX10_Hook::prepareForOverlay(IDXGISwapChain* pSwapChain)
pDevice->Release();
get_steam_client()->steam_overlay->CreateFonts();
initialized = true;
}
@ -83,9 +85,7 @@ void DX10_Hook::prepareForOverlay(IDXGISwapChain* pSwapChain)
ImGui::NewFrame();
get_steam_client()->steam_overlay->OverlayProc(desc.BufferDesc.Width, desc.BufferDesc.Height);
ImGui::EndFrame();
get_steam_client()->steam_overlay->OverlayProc();
ImGui::Render();

View File

@ -87,6 +87,8 @@ void DX11_Hook::prepareForOverlay(IDXGISwapChain* pSwapChain)
pDevice->Release();
get_steam_client()->steam_overlay->CreateFonts();
initialized = true;
}
@ -95,9 +97,7 @@ void DX11_Hook::prepareForOverlay(IDXGISwapChain* pSwapChain)
ImGui::NewFrame();
get_steam_client()->steam_overlay->OverlayProc(desc.BufferDesc.Width, desc.BufferDesc.Height);
ImGui::EndFrame();
get_steam_client()->steam_overlay->OverlayProc();
ImGui::Render();

View File

@ -87,6 +87,8 @@ void DX12_Hook::prepareForOverlay(IDXGISwapChain* pSwapChain)
pDevice->Release();
get_steam_client()->steam_overlay->CreateFonts();
initialized = true;
}
}
@ -130,9 +132,7 @@ void STDMETHODCALLTYPE DX12_Hook::MyExecuteCommandLists(ID3D12CommandQueue *_thi
ImGui::NewFrame();
get_steam_client()->steam_overlay->OverlayProc(me->sc_desc.BufferDesc.Width, me->sc_desc.BufferDesc.Height);
ImGui::EndFrame();
get_steam_client()->steam_overlay->OverlayProc();
((ID3D12GraphicsCommandList*)ppCommandLists[i])->SetDescriptorHeaps(1, &me->pSrvDescHeap);
ImGui::Render();

View File

@ -55,12 +55,6 @@ void DX9_Hook::resetRenderState()
// Try to make this function and overlay's proc as short as possible or it might affect game's fps.
void DX9_Hook::prepareForOverlay(IDirect3DDevice9 *pDevice)
{
IDirect3DSwapChain9* pSwapChain;
pDevice->GetSwapChain(0, &pSwapChain);
D3DPRESENT_PARAMETERS PresentParameters;
pSwapChain->GetPresentParameters(&PresentParameters);
pSwapChain->Release();
D3DDEVICE_CREATION_PARAMETERS param;
pDevice->GetCreationParameters(&param);
@ -75,6 +69,9 @@ void DX9_Hook::prepareForOverlay(IDirect3DDevice9 *pDevice)
io.IniFilename = NULL;
ImGui_ImplDX9_Init(pDevice);
get_steam_client()->steam_overlay->CreateFonts();
initialized = true;
}
@ -83,9 +80,7 @@ void DX9_Hook::prepareForOverlay(IDirect3DDevice9 *pDevice)
ImGui::NewFrame();
get_steam_client()->steam_overlay->OverlayProc(PresentParameters.BackBufferWidth, PresentParameters.BackBufferHeight);
ImGui::EndFrame();
get_steam_client()->steam_overlay->OverlayProc();
ImGui::Render();

View File

@ -67,9 +67,6 @@ void OpenGL_Hook::resetRenderState()
void OpenGL_Hook::prepareForOverlay(HDC hDC)
{
HWND hWnd = WindowFromDC(hDC);
RECT rect;
GetClientRect(hWnd, &rect);
if (hWnd != Windows_Hook::Inst()->GetGameHwnd())
resetRenderState();
@ -82,6 +79,8 @@ void OpenGL_Hook::prepareForOverlay(HDC hDC)
ImGui_ImplOpenGL3_Init();
get_steam_client()->steam_overlay->CreateFonts();
initialized = true;
}
ImGui_ImplOpenGL3_NewFrame();
@ -89,9 +88,7 @@ void OpenGL_Hook::prepareForOverlay(HDC hDC)
ImGui::NewFrame();
get_steam_client()->steam_overlay->OverlayProc(rect.right, rect.bottom);
ImGui::EndFrame();
get_steam_client()->steam_overlay->OverlayProc();
ImGui::Render();