Hack in ImGui::SFML focus on launch & cleanup

pull/130/head
Peter Repukat 3 years ago
parent b39c8f8956
commit db7b143527

@ -159,7 +159,6 @@
<ItemGroup>
<ClCompile Include="..\deps\imgui-sfml\imgui-SFML.cpp" />
<ClCompile Include="..\deps\imgui\imgui.cpp" />
<ClCompile Include="..\deps\imgui\imgui_demo.cpp" />
<ClCompile Include="..\deps\imgui\imgui_draw.cpp" />
<ClCompile Include="..\deps\imgui\imgui_tables.cpp" />
<ClCompile Include="..\deps\imgui\imgui_widgets.cpp" />

@ -72,9 +72,6 @@
<ClCompile Include="..\deps\imgui-sfml\imgui-SFML.cpp">
<Filter>Source Files\imgui-sfml</Filter>
</ClCompile>
<ClCompile Include="..\deps\imgui\imgui_demo.cpp">
<Filter>Source Files\imgui</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="SteamTarget.h">

@ -1,8 +1,30 @@
/*
Copyright 2021 Peter Repukat - FlatspotSoftware
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "Overlay.h"
Overlay::Overlay(sf::RenderWindow& window, const std::function<void()>& on_close) : window_(window), on_close_(on_close)
#include <utility>
Overlay::Overlay(sf::RenderWindow& window, std::function<void()> on_close) : window_(window), on_close_(std::move(on_close))
{
ImGui::SFML::Init(window_);
//Hack: Trick ImGui::SFML into thinking we already have focus (otherwise only notices after focus-lost)
const sf::Event ev(sf::Event::GainedFocus);
ProcessEvent(ev);
ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
@ -102,7 +124,7 @@ void Overlay::update()
std::ranges::for_each(OVERLAY_ELEMS_, [](const auto& fn) { fn(); });
ImGui::ShowDemoWindow();
// ImGui::ShowDemoWindow();
if (closeButton()) {
return;

@ -1,3 +1,18 @@
/*
Copyright 2021 Peter Repukat - FlatspotSoftware
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#pragma once
#include <functional>
#include <string>
@ -11,7 +26,7 @@
class Overlay {
public:
Overlay(sf::RenderWindow& window, const std::function<void()>& on_close);
Overlay(sf::RenderWindow& window, std::function<void()> on_close);
void setEnabled(bool enabled);
bool isEnabled() const;

@ -44,7 +44,7 @@ TargetWindow::TargetWindow(std::function<void()> on_close, std::vector<std::stri
// For some completely odd reason, the Background becomes black when enabled dpi-awareness and making the window desktop-size.
// Scaling down by 1px each direction is barely noticeable and works.
window_.create(sf::VideoMode(desktop_mode.width - 1, desktop_mode.height - 1, 32), "GlosSITarget", sf::Style::None);
//window_.create(sf::VideoMode(1920, 1080, 24), "GlosSITarget");
//window_.create(sf::VideoMode(1920, 1080, 32), "GlosSITarget");
#else
window_.create(desktop_mode, "GlosSITarget", sf::Style::None);
#endif
@ -54,6 +54,7 @@ TargetWindow::TargetWindow(std::function<void()> on_close, std::vector<std::stri
HWND hwnd = window_.getSystemHandle();
auto dpi = GetWindowDPI(hwnd);
spdlog::debug("Screen DPI: {}", dpi);
// transparent windows window...
auto style = GetWindowLong(hwnd, GWL_STYLE);
style &= ~WS_OVERLAPPED;

@ -0,0 +1,40 @@
[Window][Debug##Default]
Pos=60,60
Size=400,400
Collapsed=0
[Window][Log]
Pos=80,65
Size=583,843
Collapsed=0
[Window][##CloseButton]
Pos=2503,-24
Size=80,56
Collapsed=0
[Window][Hidden Devices]
Pos=751,66
Size=664,751
Collapsed=0
[Window][Dear ImGui Demo]
Pos=1531,148
Size=550,680
Collapsed=0
[Window][Dear ImGui Style Editor]
Pos=1022,358
Size=339,902
Collapsed=0
[Window][Example: Log]
Pos=397,318
Size=785,402
Collapsed=0
[Window][About Dear ImGui]
Pos=975,520
Size=570,442
Collapsed=0
Loading…
Cancel
Save