2
0
mirror of https://github.com/Alia5/GlosSI.git synced 2024-11-15 00:12:51 +00:00
GlosSI/GlosSITarget/TargetWindow.h

85 lines
2.2 KiB
C
Raw Normal View History

2021-10-15 15:10:57 +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>
// 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:
explicit TargetWindow(
std::function<void()> on_close = []() {},
2022-01-07 00:36:21 +00:00
std::function<void()> toggle_overlay_state = []() {},
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();
std::shared_ptr<Overlay> getOverlay() const;
2021-10-22 10:17:46 +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;
#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_;
std::vector<std::string> screenshot_keys_;
const std::function<void()> on_window_changed_;
2021-10-22 10:17:46 +00:00
sf::VideoMode old_desktop_mode_;
sf::Clock check_resolution_clock_;
static constexpr int RES_CHECK_SECONDS = 1;
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
};