2021-10-15 15:10:57 +00:00
|
|
|
/*
|
2022-01-06 23:38:21 +00:00
|
|
|
Copyright 2021-2022 Peter Repukat - FlatspotSoftware
|
2021-10-15 15:10:57 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2021-10-15 13:02:36 +00:00
|
|
|
#pragma once
|
2021-10-22 10:17:46 +00:00
|
|
|
#include "Overlay.h"
|
|
|
|
|
2021-10-15 13:02:36 +00:00
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
#include <SFML/Graphics/RenderWindow.hpp>
|
|
|
|
|
2021-10-17 16:20:16 +00:00
|
|
|
// Redfine window handle, should impl. change
|
2021-10-17 01:46:18 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <Windows.h>
|
|
|
|
using WindowHandle = HWND;
|
|
|
|
#else
|
|
|
|
using WindowHandle = int; // ???
|
|
|
|
#endif
|
|
|
|
|
2021-10-15 15:10:57 +00:00
|
|
|
class TargetWindow {
|
|
|
|
public:
|
2021-10-17 19:04:41 +00:00
|
|
|
explicit TargetWindow(
|
2021-10-28 11:38:16 +00:00
|
|
|
std::function<void()> on_close = []() {},
|
2022-01-07 00:36:21 +00:00
|
|
|
std::function<void()> toggle_overlay_state = []() {},
|
2021-10-28 11:38:16 +00:00
|
|
|
std::vector<std::string> screenshot_hotkey = {"KEY_F12"},
|
|
|
|
std::function<void()> on_window_changed = []() {}
|
|
|
|
);
|
2021-10-15 13:02:36 +00:00
|
|
|
|
|
|
|
void setFpsLimit(unsigned int fps_limit);
|
|
|
|
void setClickThrough(bool click_through);
|
|
|
|
void update();
|
|
|
|
void close();
|
|
|
|
|
2021-10-28 11:38:16 +00:00
|
|
|
std::shared_ptr<Overlay> getOverlay() const;
|
2021-10-22 10:17:46 +00:00
|
|
|
|
2021-10-17 19:04:41 +00:00
|
|
|
/*
|
|
|
|
* Run once per frame
|
|
|
|
* - detects steam configured screenshot hotkey
|
|
|
|
* - takes actual screenshot
|
|
|
|
* - renders it to window
|
|
|
|
* - simulates screenshot keys
|
|
|
|
* - Wait a few millis...
|
|
|
|
* (- steam takes screenshot)
|
|
|
|
* - return to normal
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void screenShotWorkaround();
|
|
|
|
|
2021-10-17 01:46:18 +00:00
|
|
|
WindowHandle getSystemHandle() const;
|
|
|
|
|
2021-10-22 20:11:09 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
static WORD GetWindowDPI(HWND hWnd);
|
|
|
|
#endif
|
|
|
|
|
2021-10-15 15:10:57 +00:00
|
|
|
private:
|
2021-10-15 13:02:36 +00:00
|
|
|
const std::function<void()> on_close_;
|
2022-01-07 00:36:21 +00:00
|
|
|
const std::function<void()> toggle_overlay_state_;
|
2021-10-15 13:02:36 +00:00
|
|
|
sf::RenderWindow window_;
|
2021-10-17 19:04:41 +00:00
|
|
|
std::vector<std::string> screenshot_keys_;
|
2021-10-28 11:38:16 +00:00
|
|
|
const std::function<void()> on_window_changed_;
|
2021-10-22 10:17:46 +00:00
|
|
|
|
2021-10-30 14:14:09 +00:00
|
|
|
sf::VideoMode old_desktop_mode_;
|
|
|
|
sf::Clock check_resolution_clock_;
|
|
|
|
static constexpr int RES_CHECK_SECONDS = 1;
|
|
|
|
|
2021-10-28 11:38:16 +00:00
|
|
|
|
|
|
|
std::shared_ptr<Overlay> overlay_;
|
|
|
|
|
|
|
|
void createWindow(bool window_mode);
|
|
|
|
|
|
|
|
bool windowed_ = false;
|
|
|
|
bool toggle_window_mode_after_frame_ = false;
|
2021-10-15 13:02:36 +00:00
|
|
|
};
|