Add .clang-format

pull/130/head
Peter Repukat 3 years ago
parent d6fb4d84bc
commit 98316efea4

@ -0,0 +1,6 @@
UseTab: false
IndentWidth: 4
BreakBeforeBraces: "Stroustrup"
AllowShortIfStatementsOnASingleLine: false
IndentCaseLabels: false
ColumnLimit: 0

@ -168,6 +168,7 @@
<None Include="..\deps\SFML\out\build\x64-Debug\lib\sfml-window-d-2.dll"> <None Include="..\deps\SFML\out\build\x64-Debug\lib\sfml-window-d-2.dll">
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent> <DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
</None> </None>
<None Include=".clang-format" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">

@ -37,5 +37,6 @@
<None Include="..\deps\SFML\out\build\x64-Debug\lib\sfml-system-d-2.dll" /> <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-window-d-2.dll" />
<None Include="..\deps\SFML\out\build\x64-Debug\lib\sfml-graphics-d-2.dll" /> <None Include="..\deps\SFML\out\build\x64-Debug\lib\sfml-graphics-d-2.dll" />
<None Include=".clang-format" />
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -1,12 +1,28 @@
/*
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 "SteamTarget.h" #include "SteamTarget.h"
#include <iostream> #include <iostream>
SteamTarget::SteamTarget(int argc, char* argv[]) : window_([this] { run_ = false; }) { SteamTarget::SteamTarget(int argc, char *argv[]) : window_([this] { run_ = false; })
{
} }
int SteamTarget::run() { int SteamTarget::run()
{
run_ = true; run_ = true;
window_.setFpsLimit(90); window_.setFpsLimit(90);
while (run_) { while (run_) {

@ -1,15 +1,28 @@
/*
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 #pragma once
#include "TargetWindow.h" #include "TargetWindow.h"
class SteamTarget class SteamTarget {
{ public:
public: explicit SteamTarget(int argc, char *argv[]);
explicit SteamTarget(int argc, char* argv[]);
int run(); int run();
private: private:
bool run_ = false; bool run_ = false;
TargetWindow window_; TargetWindow window_;
}; };

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

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

@ -32,7 +32,8 @@ limitations under the License.
// return SteamTarget::exec(); // return SteamTarget::exec();
//} //}
int main(int argc, char* argv[]) { int main(int argc, char *argv[])
SteamTarget target(argc, argv); {
return target.run(); SteamTarget target(argc, argv);
return target.run();
} }
Loading…
Cancel
Save