Minimum Transparent window

pull/130/head
Peter Repukat 3 years ago
parent 218ee65a7e
commit 08b9e923b7

3
.gitmodules vendored

@ -0,0 +1,3 @@
[submodule "deps/SFML"]
path = deps/SFML
url = git@github.com:SFML/SFML.git

@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.7.2)
project(
GlosSITarget
VERSION 1.0
LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
add_executable( GlosSITarget
main.cpp
SteamTarget.cpp
)

@ -72,15 +72,23 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<ExternalIncludePath>..\deps\SFML\include;$(ExternalIncludePath)</ExternalIncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<ExternalIncludePath>..\deps\SFML\include;$(ExternalIncludePath)</ExternalIncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<ExternalIncludePath>..\deps\SFML\include;$(ExternalIncludePath)</ExternalIncludePath>
<LibraryPath>..\deps\SFML\out\build\x64-Debug\lib;$(LibraryPath)</LibraryPath>
<CopyLocalProjectReference>false</CopyLocalProjectReference>
<CopyLocalDeploymentContent>true</CopyLocalDeploymentContent>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<ExternalIncludePath>..\deps\SFML\include;$(ExternalIncludePath)</ExternalIncludePath>
<LibraryPath>..\deps\SFML\out\build\x64-Release\lib;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
@ -116,10 +124,12 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>sfml-window-d.lib;sfml-system-d.lib;sfml-graphics-d.lib;dwmapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@ -130,6 +140,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -141,9 +152,22 @@
<ItemGroup>
<ClCompile Include="main.cpp" />
<ClCompile Include="SteamTarget.cpp" />
<ClCompile Include="TargetWindow.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="SteamTarget.h" />
<ClInclude Include="TargetWindow.h" />
</ItemGroup>
<ItemGroup>
<None Include="..\deps\SFML\out\build\x64-Debug\lib\sfml-graphics-d-2.dll">
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
</None>
<None Include="..\deps\SFML\out\build\x64-Debug\lib\sfml-system-d-2.dll">
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
</None>
<None Include="..\deps\SFML\out\build\x64-Debug\lib\sfml-window-d-2.dll">
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
</None>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

@ -21,10 +21,21 @@
<ClCompile Include="SteamTarget.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="TargetWindow.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="SteamTarget.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="TargetWindow.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\deps\SFML\out\build\x64-Debug\lib\sfml-system-d-2.dll" />
<None Include="..\deps\SFML\out\build\x64-Debug\lib\sfml-window-d-2.dll" />
<None Include="..\deps\SFML\out\build\x64-Debug\lib\sfml-graphics-d-2.dll" />
</ItemGroup>
</Project>

@ -2,10 +2,15 @@
#include <iostream>
SteamTarget::SteamTarget(int argc, char* argv[]) {
SteamTarget::SteamTarget(int argc, char* argv[]) : window_([this] { run_ = false; }) {
}
int SteamTarget::run() {
run_ = true;
window_.setFpsLimit(90);
while (run_) {
window_.update();
}
return 1;
}
}

@ -1,8 +1,15 @@
#pragma once
#include "TargetWindow.h"
class SteamTarget
{
public:
explicit SteamTarget(int argc, char* argv[]);
int run();
private:
bool run_ = false;
TargetWindow window_;
};

@ -0,0 +1,64 @@
#include "TargetWindow.h"
#include <utility>
#include <SFML/Window/Event.hpp>
#ifdef _WIN32
#include <Windows.h>
#include <dwmapi.h>
#endif
TargetWindow::TargetWindow(std::function<void()> on_close) : on_close_(std::move(on_close))
{
window_.create(sf::VideoMode::getDesktopMode(), "GlosSITarget", sf::Style::None);
window_.setActive(true);
#ifdef _WIN32
HWND hwnd = window_.getSystemHandle();
MARGINS margins;
margins.cxLeftWidth = -1;
DwmExtendFrameIntoClientArea(hwnd, &margins);
// window clickthough.
SetWindowLong(hwnd, GWL_EXSTYLE, WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_TOPMOST);
// always on top
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
#endif
}
void TargetWindow::setFpsLimit(unsigned int fps_limit)
{
window_.setFramerateLimit(fps_limit);
}
void TargetWindow::setClickThrough(bool click_through)
{
}
void TargetWindow::update()
{
sf::Event event{};
while (window_.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
window_.close();
on_close_();
}
}
window_.clear(sf::Color::Transparent);
//window_.clear(sf::Color(255,0,0,1));
window_.display();
}
void TargetWindow::close()
{
window_.close();
on_close_();
}

@ -0,0 +1,20 @@
#pragma once
#include <functional>
#include <SFML/Graphics/RenderWindow.hpp>
class TargetWindow
{
public:
explicit TargetWindow(std::function<void()> on_close = [](){});
void setFpsLimit(unsigned int fps_limit);
void setClickThrough(bool click_through);
void update();
void close();
private:
const std::function<void()> on_close_;
sf::RenderWindow window_;
};

@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
#ifdef _WIN32
#define NOMINMAX
#include <Windows.h>
#endif

1
deps/SFML vendored

@ -0,0 +1 @@
Subproject commit 3b1ff125b06e010ec1acf1bbec113adc0c8c57cd
Loading…
Cancel
Save