Compare commits
21 Commits
Author | SHA1 | Date | |
---|---|---|---|
a8da7b6bdf | |||
50ccfe3860 | |||
|
3572ef01cd | ||
|
664d213c04 | ||
d3a971d598 | |||
|
52e1b6eb00 | ||
|
f47e6bc786 | ||
|
1d9169679f | ||
|
a7b7de93dd | ||
|
124cbedf4d | ||
|
4db3b5f908 | ||
9a4a4dddcc | |||
04fa303a81 | |||
4facfb11fa | |||
ef257765fe | |||
5696dd4ed8 | |||
|
9f0a511022 | ||
ffe49e4c67 | |||
28f904783f | |||
6969568549 | |||
bcc74ea3d4 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,4 @@
|
||||
/cmake-build-debug
|
||||
/.idea
|
||||
build/*
|
||||
.vscode/*
|
||||
|
135
CMakeLists.txt
135
CMakeLists.txt
@@ -1,56 +1,81 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
project(ReWindowLibrary
|
||||
VERSION 1.0
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
if (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
|
||||
message(FATAL_ERROR "In-Source builds are not allowed")
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
if (WIN32)
|
||||
set(CMAKE_CXX_FLAGS "-municode")
|
||||
endif()
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||
|
||||
|
||||
# Enable Package Managers
|
||||
include(cmake/CPM.cmake)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME J3ML
|
||||
URL https://git.redacted.cc/josh/j3ml/archive/Prerelease-18.zip
|
||||
)
|
||||
|
||||
find_package(OpenGL REQUIRED)
|
||||
include_directories({$OPENGL_INCLUDE_DIRS} ${J3ML_SOURCE_DIR}/include)
|
||||
file(GLOB_RECURSE HEADERS "include/*.h" "include/*.hpp")
|
||||
|
||||
if(UNIX AND NOT APPLE)
|
||||
file(GLOB_RECURSE SOURCES "src/rewindow/*.cpp" "src/linux/*.cpp")
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
file(GLOB_RECURSE SOURCES "src/rewindow/*.cpp" "src/windows/*.cpp")
|
||||
endif()
|
||||
|
||||
include_directories("include")
|
||||
add_library(ReWindowLibrary SHARED ${SOURCES}
|
||||
include/rewindow/types/cursors.h
|
||||
)
|
||||
# Why god???
|
||||
set_target_properties(ReWindowLibrary PROPERTIES LINKER_LANGUAGE CXX)
|
||||
|
||||
if(UNIX AND NOT APPLE)
|
||||
target_link_libraries(ReWindowLibrary PUBLIC X11 J3ML ${OPENGL_LIBRARIES})
|
||||
add_executable(ReWindowLibraryDemo main.cpp)
|
||||
#target_include_directories(ReWindowLibraryDemo PRIVATE ${JGL_SOURCE_DIR}/include)
|
||||
target_link_libraries(ReWindowLibraryDemo PUBLIC ReWindowLibrary)
|
||||
#target_link_libraries(ReWindowLibraryDemo PRIVATE JGL)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
project(ReWindowLibrary
|
||||
VERSION 1.0
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
if (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
|
||||
message(FATAL_ERROR "In-Source builds are not allowed")
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||
|
||||
|
||||
# Enable Package Managers
|
||||
include(cmake/CPM.cmake)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME J3ML
|
||||
URL https://git.redacted.cc/josh/j3ml/archive/Release-3.zip
|
||||
)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME Event
|
||||
URL https://git.redacted.cc/josh/Event/archive/Release-5.zip
|
||||
)
|
||||
|
||||
find_package(OpenGL REQUIRED)
|
||||
include_directories(${OPENGL_INCLUDE_DIRS})
|
||||
include_directories(${J3ML_SOURCE_DIR}/include)
|
||||
|
||||
|
||||
file(GLOB_RECURSE HEADERS "include/*.h" "include/*.hpp")
|
||||
|
||||
if(UNIX AND NOT APPLE)
|
||||
file(GLOB_RECURSE SOURCES "src/rewindow/*.cpp" "src/linux/*.cpp")
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
file(GLOB_RECURSE SOURCES "src/rewindow/*.cpp" "src/windows/*.cpp")
|
||||
endif()
|
||||
|
||||
include_directories("include")
|
||||
|
||||
if(UNIX)
|
||||
add_library(ReWindowLibrary SHARED ${SOURCES})
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
add_library(ReWindowLibrary STATIC ${SOURCES})
|
||||
endif()
|
||||
|
||||
target_include_directories(ReWindowLibrary PUBLIC ${Event_SOURCE_DIR}/include)
|
||||
|
||||
# Why god???
|
||||
set_target_properties(ReWindowLibrary PROPERTIES LINKER_LANGUAGE CXX)
|
||||
|
||||
if(UNIX AND NOT APPLE)
|
||||
target_link_libraries(ReWindowLibrary PUBLIC X11)
|
||||
target_link_libraries(ReWindowLibrary PUBLIC ${OPENGL_LIBRARIES})
|
||||
|
||||
target_link_libraries(ReWindowLibrary PUBLIC J3ML)
|
||||
target_link_libraries(ReWindowLibrary PUBLIC Event)
|
||||
|
||||
add_executable(ReWindowLibraryDemo main.cpp)
|
||||
#target_include_directories(ReWindowLibraryDemo PRIVATE ${JGL_SOURCE_DIR}/include)
|
||||
target_link_libraries(ReWindowLibraryDemo PUBLIC ReWindowLibrary)
|
||||
#target_link_libraries(ReWindowLibraryDemo PRIVATE JGL)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
#target_compile_options(ReWindowLibrary PRIVATE -Wno-multichar)
|
||||
target_link_libraries(ReWindowLibrary PUBLIC ${OPENGL_LIBRARIES})
|
||||
target_link_libraries(ReWindowLibrary PUBLIC J3ML)
|
||||
target_link_libraries(ReWindowLibrary PUBLIC Event)
|
||||
|
||||
add_executable(ReWindowLibraryDemo main.cpp)
|
||||
#target_compile_options(ReWindowLibraryDemo PRIVATE)
|
||||
target_link_libraries(ReWindowLibraryDemo PUBLIC ReWindowLibrary)
|
||||
endif()
|
98
build/CMakeCache.txt
Normal file
98
build/CMakeCache.txt
Normal file
@@ -0,0 +1,98 @@
|
||||
# This is the CMakeCache file.
|
||||
# For build in directory: d:/Work/ReWindow/build
|
||||
# It was generated by CMake: C:/Program Files/CMake/bin/cmake.exe
|
||||
# You can edit this file to change values found and used by cmake.
|
||||
# If you do not want to change any of the values, simply exit the editor.
|
||||
# If you do want to change a value, simply edit, save, and exit the editor.
|
||||
# The syntax for the file is as follows:
|
||||
# KEY:TYPE=VALUE
|
||||
# KEY is the name of a variable in the cache.
|
||||
# TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT TYPE!.
|
||||
# VALUE is the current value for the KEY.
|
||||
|
||||
########################
|
||||
# EXTERNAL cache entries
|
||||
########################
|
||||
|
||||
//Value Computed by CMake.
|
||||
CMAKE_FIND_PACKAGE_REDIRECTS_DIR:STATIC=D:/Work/ReWindow/build/CMakeFiles/pkgRedirects
|
||||
|
||||
//Program used to build from makefiles.
|
||||
CMAKE_MAKE_PROGRAM:STRING=nmake
|
||||
|
||||
//Value Computed by CMake
|
||||
CMAKE_PROJECT_DESCRIPTION:STATIC=
|
||||
|
||||
//Value Computed by CMake
|
||||
CMAKE_PROJECT_HOMEPAGE_URL:STATIC=
|
||||
|
||||
//Value Computed by CMake
|
||||
CMAKE_PROJECT_NAME:STATIC=ReWindowLibrary
|
||||
|
||||
//Value Computed by CMake
|
||||
CMAKE_PROJECT_VERSION:STATIC=1.0
|
||||
|
||||
//Value Computed by CMake
|
||||
CMAKE_PROJECT_VERSION_MAJOR:STATIC=1
|
||||
|
||||
//Value Computed by CMake
|
||||
CMAKE_PROJECT_VERSION_MINOR:STATIC=0
|
||||
|
||||
//Value Computed by CMake
|
||||
CMAKE_PROJECT_VERSION_PATCH:STATIC=
|
||||
|
||||
//Value Computed by CMake
|
||||
CMAKE_PROJECT_VERSION_TWEAK:STATIC=
|
||||
|
||||
//Value Computed by CMake
|
||||
ReWindowLibrary_BINARY_DIR:STATIC=D:/Work/ReWindow/build
|
||||
|
||||
//Value Computed by CMake
|
||||
ReWindowLibrary_IS_TOP_LEVEL:STATIC=ON
|
||||
|
||||
//Value Computed by CMake
|
||||
ReWindowLibrary_SOURCE_DIR:STATIC=D:/Work/ReWindow
|
||||
|
||||
|
||||
########################
|
||||
# INTERNAL cache entries
|
||||
########################
|
||||
|
||||
//This is the directory where this CMakeCache.txt was created
|
||||
CMAKE_CACHEFILE_DIR:INTERNAL=d:/Work/ReWindow/build
|
||||
//Major version of cmake used to create the current loaded cache
|
||||
CMAKE_CACHE_MAJOR_VERSION:INTERNAL=3
|
||||
//Minor version of cmake used to create the current loaded cache
|
||||
CMAKE_CACHE_MINOR_VERSION:INTERNAL=29
|
||||
//Patch version of cmake used to create the current loaded cache
|
||||
CMAKE_CACHE_PATCH_VERSION:INTERNAL=2
|
||||
//Path to CMake executable.
|
||||
CMAKE_COMMAND:INTERNAL=C:/Program Files/CMake/bin/cmake.exe
|
||||
//Path to cpack program executable.
|
||||
CMAKE_CPACK_COMMAND:INTERNAL=C:/Program Files/CMake/bin/cpack.exe
|
||||
//Path to ctest program executable.
|
||||
CMAKE_CTEST_COMMAND:INTERNAL=C:/Program Files/CMake/bin/ctest.exe
|
||||
//Path to cache edit program executable.
|
||||
CMAKE_EDIT_COMMAND:INTERNAL=C:/Program Files/CMake/bin/cmake-gui.exe
|
||||
//Name of external makefile project generator.
|
||||
CMAKE_EXTRA_GENERATOR:INTERNAL=
|
||||
//Name of generator.
|
||||
CMAKE_GENERATOR:INTERNAL=NMake Makefiles
|
||||
//Generator instance identifier.
|
||||
CMAKE_GENERATOR_INSTANCE:INTERNAL=
|
||||
//Name of generator platform.
|
||||
CMAKE_GENERATOR_PLATFORM:INTERNAL=
|
||||
//Name of generator toolset.
|
||||
CMAKE_GENERATOR_TOOLSET:INTERNAL=
|
||||
//Source directory with the top level CMakeLists.txt file for this
|
||||
// project
|
||||
CMAKE_HOME_DIRECTORY:INTERNAL=D:/Work/ReWindow
|
||||
//ADVANCED property for variable: CMAKE_MAKE_PROGRAM
|
||||
CMAKE_MAKE_PROGRAM-ADVANCED:INTERNAL=1
|
||||
//number of local generators
|
||||
CMAKE_NUMBER_OF_MAKEFILES:INTERNAL=1
|
||||
//Platform information initialized
|
||||
CMAKE_PLATFORM_INFO_INITIALIZED:INTERNAL=1
|
||||
//Path to CMake installation.
|
||||
CMAKE_ROOT:INTERNAL=C:/Program Files/CMake/share/cmake-3.29
|
||||
|
15
build/CMakeFiles/3.29.2/CMakeSystem.cmake
Normal file
15
build/CMakeFiles/3.29.2/CMakeSystem.cmake
Normal file
@@ -0,0 +1,15 @@
|
||||
set(CMAKE_HOST_SYSTEM "Windows-10.0.15063")
|
||||
set(CMAKE_HOST_SYSTEM_NAME "Windows")
|
||||
set(CMAKE_HOST_SYSTEM_VERSION "10.0.15063")
|
||||
set(CMAKE_HOST_SYSTEM_PROCESSOR "AMD64")
|
||||
|
||||
|
||||
|
||||
set(CMAKE_SYSTEM "Windows-10.0.15063")
|
||||
set(CMAKE_SYSTEM_NAME "Windows")
|
||||
set(CMAKE_SYSTEM_VERSION "10.0.15063")
|
||||
set(CMAKE_SYSTEM_PROCESSOR "AMD64")
|
||||
|
||||
set(CMAKE_CROSSCOMPILING "FALSE")
|
||||
|
||||
set(CMAKE_SYSTEM_LOADED 1)
|
11
build/CMakeFiles/CMakeConfigureLog.yaml
Normal file
11
build/CMakeFiles/CMakeConfigureLog.yaml
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
---
|
||||
events:
|
||||
-
|
||||
kind: "message-v1"
|
||||
backtrace:
|
||||
- "C:/Program Files/CMake/share/cmake-3.29/Modules/CMakeDetermineSystem.cmake:205 (message)"
|
||||
- "CMakeLists.txt:2 (project)"
|
||||
message: |
|
||||
The system is: Windows - 10.0.15063 - AMD64
|
||||
...
|
1
build/CMakeFiles/cmake.check_cache
Normal file
1
build/CMakeFiles/cmake.check_cache
Normal file
@@ -0,0 +1 @@
|
||||
# This file is generated by cmake for dependency checking of the CMakeCache.txt file
|
@@ -1,60 +1,80 @@
|
||||
#pragma once
|
||||
|
||||
#if __linux__
|
||||
#include <X11/cursorfont.h>
|
||||
#endif
|
||||
|
||||
namespace ReWindow
|
||||
{
|
||||
enum class X11CursorStyle
|
||||
{
|
||||
Default = XC_left_ptr,
|
||||
X = XC_X_cursor,
|
||||
Arrow = XC_arrow,
|
||||
IBeam = XC_xterm,
|
||||
BottomLeftCorner = XC_bottom_left_corner,
|
||||
BottomRightCorner = XC_bottom_right_corner,
|
||||
BottomSide = XC_bottom_side,
|
||||
Dot = XC_dot,
|
||||
DoubleArrow = XC_double_arrow,
|
||||
Exchange = XC_exchange,
|
||||
Hand = XC_hand2,
|
||||
LeftSide = XC_left_side,
|
||||
Plus = XC_plus,
|
||||
RightSide = XC_right_side,
|
||||
Pencil = XC_pencil
|
||||
};
|
||||
#if __linux__
|
||||
enum class X11CursorStyle
|
||||
{
|
||||
Default = XC_left_ptr,
|
||||
X = XC_X_cursor,
|
||||
Arrow = XC_arrow,
|
||||
IBeam = XC_xterm,
|
||||
BottomLeftCorner = XC_bottom_left_corner,
|
||||
BottomRightCorner = XC_bottom_right_corner,
|
||||
BottomSide = XC_bottom_side,
|
||||
Dot = XC_dot,
|
||||
DoubleArrow = XC_double_arrow,
|
||||
Exchange = XC_exchange,
|
||||
Hand = XC_hand2,
|
||||
LeftSide = XC_left_side,
|
||||
Plus = XC_plus,
|
||||
RightSide = XC_right_side,
|
||||
Pencil = XC_pencil
|
||||
};
|
||||
|
||||
// https://learn.microsoft.com/en-us/windows/win32/menurc/about-cursors
|
||||
enum class WindowsCursorStyle
|
||||
{
|
||||
Arrow,
|
||||
IBeam,
|
||||
Wait,
|
||||
Cross,
|
||||
Hand,
|
||||
AppStarting,
|
||||
};
|
||||
class CursorStyle
|
||||
{
|
||||
public:
|
||||
X11CursorStyle X11Cursor;
|
||||
CursorStyle(X11CursorStyle style) : X11Cursor(style) {}
|
||||
};
|
||||
class CursorStyle {
|
||||
public:
|
||||
X11CursorStyle X11Cursor;
|
||||
CursorStyle(X11CursorStyle style) : X11Cursor(style) {}
|
||||
};
|
||||
|
||||
namespace Cursors
|
||||
{
|
||||
static const CursorStyle Default {X11CursorStyle::Default};
|
||||
static const CursorStyle X {X11CursorStyle::X};
|
||||
static const CursorStyle Arrow {X11CursorStyle::Arrow};
|
||||
static const CursorStyle IBeam {X11CursorStyle::IBeam};
|
||||
static const CursorStyle BottomLeftCorner {X11CursorStyle::BottomLeftCorner};
|
||||
static const CursorStyle BottomRightCorner {X11CursorStyle::BottomRightCorner};
|
||||
static const CursorStyle BottomSide {X11CursorStyle::BottomSide};
|
||||
static const CursorStyle Dot {X11CursorStyle::Dot};
|
||||
static const CursorStyle DoubleArrow {X11CursorStyle::DoubleArrow};
|
||||
static const CursorStyle Exchange {X11CursorStyle::Exchange};
|
||||
static const CursorStyle Hand {X11CursorStyle::Hand};
|
||||
static const CursorStyle LeftSide {X11CursorStyle::LeftSide};
|
||||
static const CursorStyle Plus {X11CursorStyle::Plus};
|
||||
static const CursorStyle RightSide {X11CursorStyle::RightSide};
|
||||
static const CursorStyle Pencil {X11CursorStyle::Pencil};
|
||||
}
|
||||
namespace Cursors {
|
||||
static const CursorStyle Default {X11CursorStyle::Default};
|
||||
static const CursorStyle X {X11CursorStyle::X};
|
||||
static const CursorStyle Arrow {X11CursorStyle::Arrow};
|
||||
static const CursorStyle IBeam {X11CursorStyle::IBeam};
|
||||
static const CursorStyle BottomLeftCorner {X11CursorStyle::BottomLeftCorner};
|
||||
static const CursorStyle BottomRightCorner {X11CursorStyle::BottomRightCorner};
|
||||
static const CursorStyle BottomSide {X11CursorStyle::BottomSide};
|
||||
static const CursorStyle Dot {X11CursorStyle::Dot};
|
||||
static const CursorStyle DoubleArrow {X11CursorStyle::DoubleArrow};
|
||||
static const CursorStyle Exchange {X11CursorStyle::Exchange};
|
||||
static const CursorStyle Hand {X11CursorStyle::Hand};
|
||||
static const CursorStyle LeftSide {X11CursorStyle::LeftSide};
|
||||
static const CursorStyle Plus {X11CursorStyle::Plus};
|
||||
static const CursorStyle RightSide {X11CursorStyle::RightSide};
|
||||
static const CursorStyle Pencil {X11CursorStyle::Pencil};
|
||||
}
|
||||
|
||||
#else
|
||||
// https://learn.microsoft.com/en-us/windows/win32/menurc/about-cursors
|
||||
enum WindowsCursorStyle {
|
||||
Arrow,
|
||||
IBeam,
|
||||
Wait,
|
||||
Cross,
|
||||
Hand,
|
||||
AppStarting,
|
||||
};
|
||||
|
||||
class CursorStyle {
|
||||
public:
|
||||
WindowsCursorStyle WindowsCursor;
|
||||
CursorStyle (WindowsCursorStyle style): WindowsCursor(style) {}
|
||||
};
|
||||
|
||||
namespace Cursors {
|
||||
static const CursorStyle Default {WindowsCursorStyle::Arrow};
|
||||
static const CursorStyle Arrow {WindowsCursorStyle::Arrow};
|
||||
static const CursorStyle IBeam {WindowsCursorStyle::IBeam};
|
||||
static const CursorStyle Cross {WindowsCursorStyle::Cross};
|
||||
static const CursorStyle Wait {WindowsCursorStyle::Wait};
|
||||
static const CursorStyle Hand {WindowsCursorStyle::Hand};
|
||||
static const CursorStyle AppStarting {WindowsCursorStyle::AppStarting};
|
||||
}
|
||||
#endif
|
||||
}
|
@@ -1,81 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
|
||||
|
||||
template <typename ... Args>
|
||||
class Event;
|
||||
|
||||
template <typename ... Args>
|
||||
class EventConnection {
|
||||
private:
|
||||
using delegate = std::function<void(Args...)>;
|
||||
public:
|
||||
EventConnection(Event<Args...> *creator, delegate cb) : owner(creator), callback(std::move(cb)) {}
|
||||
bool Disconnect(); // Breaks the event connection, but does not destroy the instance
|
||||
void Invoke(Args... e);
|
||||
private:
|
||||
Event<Args...> * owner;
|
||||
delegate callback;
|
||||
bool active = true;
|
||||
};
|
||||
|
||||
template <typename ... Args>
|
||||
class Event {
|
||||
public:
|
||||
using delegate = std::function<void(Args...)>;
|
||||
using connection = EventConnection<Args ...>;
|
||||
using event_ptr = std::shared_ptr<connection>;
|
||||
public:
|
||||
void Await(Args& ... arg);
|
||||
void Invoke(Args... args);
|
||||
void operator()(Args... args);
|
||||
connection Connect(delegate callback);
|
||||
void Disconnect(connection &conn);
|
||||
connection operator+=(delegate callback);
|
||||
private:
|
||||
std::vector<event_ptr> listeners;
|
||||
uint64_t listenerCounter = 0;
|
||||
};
|
||||
|
||||
|
||||
template<typename... Args>
|
||||
EventConnection<Args...> Event<Args...>::operator+=(Event::delegate callback) { return Connect(callback); }
|
||||
|
||||
template<typename... Args>
|
||||
void Event<Args...>::operator()(Args... args) { Invoke(args...);}
|
||||
|
||||
template <typename... Args>
|
||||
void EventConnection<Args...>::Invoke(Args... e) { callback(e...); }
|
||||
|
||||
template <typename ... Args>
|
||||
bool EventConnection<Args...>::Disconnect() {
|
||||
if (active) {
|
||||
owner->Disconnect(this);
|
||||
active = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename ... Args>
|
||||
void Event<Args...>::Invoke(Args... args) {
|
||||
for (event_ptr &connection_ptr: this->listeners) {
|
||||
connection_ptr->Invoke(args...);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ... Args>
|
||||
EventConnection<Args...> Event<Args...>::Connect(delegate callback)
|
||||
{
|
||||
event_ptr retval(new connection(this, callback));
|
||||
this->listeners.push_back(retval);
|
||||
return *retval;
|
||||
}
|
||||
|
||||
template <typename ... Args>
|
||||
void Event<Args...>::Disconnect(connection &conn) {
|
||||
listeners.erase(std::remove(listeners.begin(), listeners.end(), 99), listeners.end());
|
||||
}
|
||||
|
@@ -2,7 +2,6 @@
|
||||
// ~DAWSH
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <J3ML/LinearAlgebra/Vector2.h>
|
||||
|
||||
@@ -52,8 +51,8 @@ namespace Keys {
|
||||
static const Key F12 {'\u000f', X11Scancode::F12, WindowsScancode::F12};
|
||||
|
||||
static const Key NumPad1 {'\b', X11Scancode::KP_1, WindowsScancode::NUMPAD_ONE};
|
||||
static const Key NumPad2 {'\b', X11Scancode::KP_2, WindowsScancode::NUMPAD_ONE};
|
||||
static const Key NumPad3 {'\b', X11Scancode::KP_3, WindowsScancode::NUMPAD_ONE};
|
||||
static const Key NumPad2 {'\b', X11Scancode::KP_2, WindowsScancode::NUMPAD_TWO};
|
||||
static const Key NumPad3 {'\b', X11Scancode::KP_3, WindowsScancode::NUMPAD_THREE};
|
||||
static const Key NumPad4 {'\b', X11Scancode::KP_4, WindowsScancode::NUMPAD_ONE};
|
||||
static const Key NumPad5 {'\b', X11Scancode::KP_5, WindowsScancode::NUMPAD_ONE};
|
||||
static const Key NumPad6 {'\b', X11Scancode::KP_6, WindowsScancode::NUMPAD_ONE};
|
||||
@@ -152,8 +151,6 @@ namespace GamepadButtons {
|
||||
static const GamepadButton B;
|
||||
}
|
||||
|
||||
|
||||
|
||||
namespace MouseButtons
|
||||
{
|
||||
static const MouseButton Left;
|
||||
@@ -163,10 +160,10 @@ namespace MouseButtons
|
||||
static const MouseButton Side2;
|
||||
}
|
||||
|
||||
static MouseButton GetMouseButtonFromXButton(unsigned int button)
|
||||
{
|
||||
switch(button)
|
||||
{
|
||||
#if __linux__
|
||||
|
||||
static MouseButton GetMouseButtonFromXButton(unsigned int button) {
|
||||
switch(button) {
|
||||
case Button1: return MouseButtons::Left;
|
||||
case Button2: return MouseButtons::Right;
|
||||
case Button3: return MouseButtons::Middle;
|
||||
@@ -180,8 +177,7 @@ static MouseButton GetMouseButtonFromXButton(unsigned int button)
|
||||
}
|
||||
}
|
||||
|
||||
static Key GetKeyFromX11Scancode(X11Scancode code)
|
||||
{
|
||||
static Key GetKeyFromX11Scancode(X11Scancode code) {
|
||||
for (auto& key : Key::GetKeyboard()) {
|
||||
if (key.x11ScanCode == code)
|
||||
return key;
|
||||
@@ -189,8 +185,10 @@ static Key GetKeyFromX11Scancode(X11Scancode code)
|
||||
std::cout << "Unavaliable Scancode: " + std::to_string((int)code) << std::endl;
|
||||
return Keys::Space;
|
||||
}
|
||||
static Key GetKeyFromWindowsScancode(WindowsScancode code)
|
||||
{
|
||||
|
||||
#else
|
||||
|
||||
static Key GetKeyFromWindowsScancode(WindowsScancode code) {
|
||||
for (auto& key : Key::GetKeyboard()) {
|
||||
if (key.winScanCode == code)
|
||||
return key;
|
||||
@@ -198,3 +196,5 @@ static Key GetKeyFromWindowsScancode(WindowsScancode code)
|
||||
std::cout << "Unavaliable Scancode: " + std::to_string((int)code) << std::endl;
|
||||
return Keys::Space;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -2,230 +2,266 @@
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <rewindow/types/event.h>
|
||||
#include <Event.h>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <thread>
|
||||
#include <rewindow/types/key.h>
|
||||
|
||||
#if WIN32
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
#include <wingdi.h>
|
||||
#endif
|
||||
|
||||
#if __linux__
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glx.h>
|
||||
#include "cursors.h"
|
||||
|
||||
#endif
|
||||
|
||||
#include <rewindow/types/cursors.h>
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
using precision_clock = std::chrono::high_resolution_clock;
|
||||
using precision_timestamp = precision_clock::time_point;
|
||||
|
||||
enum class RWindowFlags: uint8_t {
|
||||
IN_FOCUS = 0,
|
||||
FULLSCREEN = 1,
|
||||
RESIZABLE = 2,
|
||||
VSYNC = 4
|
||||
IN_FOCUS,
|
||||
FULLSCREEN,
|
||||
RESIZABLE,
|
||||
VSYNC,
|
||||
QUIT,
|
||||
MAX_FLAG
|
||||
};
|
||||
|
||||
enum class RenderingAPI: uint8_t {
|
||||
OPENGL = 0,
|
||||
//Vulkan is unimplemented.
|
||||
VULKAN = 1,
|
||||
OPENGL = 0,
|
||||
//Vulkan is unimplemented.
|
||||
VULKAN = 1,
|
||||
};
|
||||
|
||||
|
||||
enum class KeyState { Pressed, Released };
|
||||
enum class KeyState {Pressed, Released};
|
||||
|
||||
namespace ReWindow
|
||||
{
|
||||
using J3ML::LinearAlgebra::Vector2;
|
||||
using J3ML::LinearAlgebra::Vector2;
|
||||
|
||||
class TimestampedEvent {
|
||||
private:
|
||||
class TimestampedEvent {
|
||||
private:
|
||||
|
||||
public:
|
||||
precision_timestamp Timestamp;
|
||||
TimestampedEvent() : Timestamp(precision_clock::now())
|
||||
{ }
|
||||
};
|
||||
public:
|
||||
precision_timestamp Timestamp;
|
||||
TimestampedEvent() : Timestamp(precision_clock::now())
|
||||
{ }
|
||||
};
|
||||
|
||||
class RWindowEvent : public TimestampedEvent {
|
||||
public:
|
||||
RWindowEvent() : TimestampedEvent() { }
|
||||
};
|
||||
const RWindowEvent EmptyRWindowEvent;
|
||||
class RWindowEvent : public TimestampedEvent {
|
||||
public:
|
||||
RWindowEvent() : TimestampedEvent() { }
|
||||
};
|
||||
const RWindowEvent EmptyRWindowEvent;
|
||||
|
||||
namespace WindowEvents
|
||||
{
|
||||
class KeyboardState {
|
||||
public:
|
||||
std::map<Key, bool> PressedKeys;
|
||||
};
|
||||
namespace WindowEvents
|
||||
{
|
||||
class KeyboardState {
|
||||
public:
|
||||
std::map<Key, bool> PressedKeys;
|
||||
};
|
||||
|
||||
class GamepadState {
|
||||
public:
|
||||
std::map<GamepadButton, bool> PressedButtons;
|
||||
};
|
||||
class GamepadState {
|
||||
public:
|
||||
std::map<GamepadButton, bool> PressedButtons;
|
||||
};
|
||||
|
||||
class InputState {
|
||||
public:
|
||||
KeyboardState Keyboard;
|
||||
GamepadState Gamepad;
|
||||
};
|
||||
class InputState {
|
||||
public:
|
||||
KeyboardState Keyboard;
|
||||
GamepadState Gamepad;
|
||||
};
|
||||
|
||||
class KeyboardEvent : public RWindowEvent {
|
||||
public:
|
||||
Key key;
|
||||
KeyState state;
|
||||
KeyboardEvent(Key key, KeyState state) : RWindowEvent(), key(key), state(state) {}
|
||||
};
|
||||
class MouseEvent : public RWindowEvent {};
|
||||
class GamepadEvent : public RWindowEvent {};
|
||||
class KeyboardEvent : public RWindowEvent {
|
||||
public:
|
||||
Key key;
|
||||
KeyState state;
|
||||
KeyboardEvent(Key key, KeyState state) : RWindowEvent(), key(key), state(state) {}
|
||||
};
|
||||
class MouseEvent : public RWindowEvent {};
|
||||
class GamepadEvent : public RWindowEvent {};
|
||||
|
||||
class MouseMoveEvent : public MouseEvent {
|
||||
public:
|
||||
Vector2 Position;
|
||||
Vector2 Delta;
|
||||
MouseMoveEvent(const Vector2 &pos) : MouseEvent(), Position(pos)
|
||||
{}
|
||||
MouseMoveEvent(int x, int y) : MouseEvent(), Position(Vector2(x, y))
|
||||
{}
|
||||
};
|
||||
class MouseMoveEvent : public MouseEvent {
|
||||
public:
|
||||
Vector2 Position;
|
||||
Vector2 Delta;
|
||||
MouseMoveEvent(const Vector2 &pos) : MouseEvent(), Position(pos)
|
||||
{}
|
||||
MouseMoveEvent(int x, int y) : MouseEvent(), Position(Vector2(x, y))
|
||||
{}
|
||||
};
|
||||
|
||||
class KeyDownEvent : public KeyboardEvent {
|
||||
public:
|
||||
KeyDownEvent(Key key) : KeyboardEvent(key, KeyState::Pressed) {}
|
||||
};
|
||||
class KeyDownEvent : public KeyboardEvent {
|
||||
public:
|
||||
KeyDownEvent(Key key) : KeyboardEvent(key, KeyState::Pressed) {}
|
||||
};
|
||||
|
||||
class KeyUpEvent : public KeyboardEvent {
|
||||
public:
|
||||
KeyUpEvent(Key key) : KeyboardEvent(key, KeyState::Released) {}
|
||||
};
|
||||
class KeyUpEvent : public KeyboardEvent {
|
||||
public:
|
||||
KeyUpEvent(Key key) : KeyboardEvent(key, KeyState::Released) {}
|
||||
};
|
||||
|
||||
|
||||
class MouseButtonDownEvent : public MouseEvent {
|
||||
public:
|
||||
MouseButton Button;
|
||||
};
|
||||
class MouseButtonDownEvent : public MouseEvent {
|
||||
public:
|
||||
MouseButton Button;
|
||||
};
|
||||
|
||||
class MouseButtonUpEvent : public MouseEvent {
|
||||
public:
|
||||
MouseButton Button;
|
||||
};
|
||||
class MouseButtonUpEvent : public MouseEvent {
|
||||
public:
|
||||
MouseButton Button;
|
||||
};
|
||||
|
||||
class WindowResizeRequestEvent : public RWindowEvent
|
||||
{
|
||||
public:
|
||||
Vector2 Size;
|
||||
};
|
||||
}
|
||||
class WindowResizeRequestEvent : public RWindowEvent
|
||||
{
|
||||
public:
|
||||
Vector2 Size;
|
||||
};
|
||||
}
|
||||
|
||||
using namespace WindowEvents;
|
||||
using namespace WindowEvents;
|
||||
|
||||
class RWindow {
|
||||
public:
|
||||
class RWindow {
|
||||
public:
|
||||
|
||||
virtual void OnFocusLost(const RWindowEvent& e) {}
|
||||
virtual void OnFocusGain(const RWindowEvent& e) {}
|
||||
virtual void OnRefresh(float elapsed) {}
|
||||
virtual void OnResizeSuccess() {}
|
||||
virtual bool OnResizeRequest(const WindowResizeRequestEvent& e) {}
|
||||
virtual void OnKeyDown(const KeyDownEvent&) {}
|
||||
virtual void OnKeyUp(const KeyUpEvent&) {}
|
||||
virtual void OnMouseMove(const MouseMoveEvent&) {}
|
||||
virtual void OnMouseButtonDown(const MouseButtonDownEvent&) {}
|
||||
virtual void OnMouseButtonUp(const MouseButtonUpEvent&) {}
|
||||
#pragma region Callbacks
|
||||
/// Bindable Non-intrusive event handlers
|
||||
/// Use these when you can't override the base window class
|
||||
Event<RWindowEvent> OnFocusLostEvent;
|
||||
Event<RWindowEvent> OnFocusGainEvent;
|
||||
Event<float> OnRefreshEvent;
|
||||
Event<WindowResizeRequestEvent> OnResizeRequestEvent;
|
||||
Event<KeyDownEvent> OnKeyDownEvent;
|
||||
Event<KeyUpEvent> OnKeyUpEvent;
|
||||
Event<MouseMoveEvent> OnMouseMoveEvent;
|
||||
Event<MouseButtonDownEvent> OnMouseButtonDownEvent;
|
||||
Event<MouseButtonUpEvent> OnMouseButtonUpEvent;
|
||||
#pragma endregion
|
||||
|
||||
RWindow()
|
||||
{
|
||||
title = "ReWindow Application";
|
||||
width = 640;
|
||||
height = 480;
|
||||
}
|
||||
RWindow(const std::string& title, int width, int height);
|
||||
RWindow(const std::string& title, int width, int height, RenderingAPI renderer);
|
||||
#pragma region Overrides
|
||||
virtual void OnFocusLost(const RWindowEvent& e) {}
|
||||
virtual void OnFocusGain(const RWindowEvent& e) {}
|
||||
virtual void OnRefresh(float elapsed) {}
|
||||
virtual void OnResizeSuccess() {}
|
||||
virtual bool OnResizeRequest(const WindowResizeRequestEvent& e) { return true;}
|
||||
virtual void OnKeyDown(const KeyDownEvent&) {}
|
||||
virtual void OnKeyUp(const KeyUpEvent&) {}
|
||||
virtual void OnMouseMove(const MouseMoveEvent&) {}
|
||||
virtual void OnMouseButtonDown(const MouseButtonDownEvent&) {}
|
||||
virtual void OnMouseButtonUp(const MouseButtonUpEvent&) {}
|
||||
#pragma endregion
|
||||
|
||||
void SetRenderer(RenderingAPI api)
|
||||
{
|
||||
renderer = api;
|
||||
}
|
||||
void Open();
|
||||
void Close();
|
||||
void CloseAndReopenInPlace();
|
||||
RWindow();
|
||||
RWindow(const std::string& title, int width, int height);
|
||||
RWindow(const std::string& title, int width, int height, RenderingAPI renderer);
|
||||
|
||||
// TODO: Must be implemented from scratch as a Motif Window in x11
|
||||
void MessageBox();
|
||||
Vector2 GetMouseCoordinates() const {
|
||||
return getCursorPos();
|
||||
}
|
||||
|
||||
bool isFocused() const;
|
||||
bool isFullscreen() const;
|
||||
bool isResizable() const;
|
||||
bool isVsyncEnabled() const;
|
||||
void liftKey (Key key) {
|
||||
currentKeyboard.PressedKeys[key] = false;
|
||||
auto event = ReWindow::WindowEvents::KeyUpEvent(key);
|
||||
OnKeyUp(event);
|
||||
}
|
||||
|
||||
bool isAlive() const;
|
||||
void pressKey (Key key) {
|
||||
currentKeyboard.PressedKeys[key] = true;
|
||||
auto eventData = KeyDownEvent(key);
|
||||
OnKeyDown(eventData);
|
||||
}
|
||||
#ifndef __linux___
|
||||
//RWindow(HINSTANCE hInst);
|
||||
|
||||
void setMouseVisible(bool visible);
|
||||
void setMouseLocked();
|
||||
void setMouseCenter();
|
||||
void restoreMouseFromLastCenter(); // Feels nicer for users
|
||||
void setRect (int nx, int ny, int nw, int nh) {
|
||||
setPos(nx, ny);
|
||||
width = nw;
|
||||
height = nh;
|
||||
}
|
||||
#endif
|
||||
void setRenderer(RenderingAPI api);
|
||||
void Open();
|
||||
void Close();
|
||||
void CloseAndReopenInPlace();
|
||||
|
||||
bool isKeyDown(Key key) const;
|
||||
bool isMouseButtonDown(MouseButton button) const;
|
||||
// TODO: Must be implemented from scratch as a Motif Window in x11
|
||||
void MessageBox();
|
||||
|
||||
void setFullscreen(bool fs);
|
||||
void setResizable(bool resizable);
|
||||
void setVsyncEnabled(bool);
|
||||
void setTitle(const std::string& title);
|
||||
std::string getTitle() const;
|
||||
void fullscreen();
|
||||
void restoreFromFullscreen();
|
||||
bool getFlag(RWindowFlags flag) const;
|
||||
void setFlag(RWindowFlags flag, bool state);
|
||||
//void init(RenderingAPI api, const char* title, int width, int height, bool vsync);
|
||||
void destroyWindow();
|
||||
void pollEvents();
|
||||
void refresh();
|
||||
void setSize(int width, int height);
|
||||
void setSize(const Vector2& size);
|
||||
/// Returns the position of the window's top-left corner relative to the display
|
||||
Vector2 getPos() const;
|
||||
Vector2 getSize() const;
|
||||
void setPos(int x, int y);
|
||||
void setPos(const Vector2& pos);
|
||||
Vector2 getCursorPos() const;
|
||||
void raise() const;
|
||||
void lower() const;
|
||||
void setCursorStyle(CursorStyle style) const;
|
||||
void setCursorCustomIcon() const;
|
||||
bool isFocused() const;
|
||||
bool isFullscreen() const;
|
||||
bool isResizable() const;
|
||||
bool isVsyncEnabled() const;
|
||||
|
||||
static void glSwapBuffers();
|
||||
//Initialize to false because it's not guaranteed that they will be cleared first
|
||||
private:
|
||||
Vector2 lastKnownWindowSize {0, 0};
|
||||
bool flags[4];
|
||||
std::vector<RWindowEvent> eventLog;
|
||||
KeyboardState currentKeyboard; // Current Frame's Keyboard State
|
||||
KeyboardState previousKeyboard; // Previous Frame's Keyboard State
|
||||
bool fullscreenmode = false;
|
||||
std::string title;
|
||||
int width;
|
||||
int height;
|
||||
RenderingAPI renderer;
|
||||
bool open = false;
|
||||
bool resizable;
|
||||
bool isAlive() const;
|
||||
|
||||
void setMouseVisible(bool visible);
|
||||
void setMouseLocked();
|
||||
void setMouseCenter();
|
||||
void restoreMouseFromLastCenter(); // Feels nicer for users
|
||||
|
||||
bool isKeyDown(Key key) const;
|
||||
bool isMouseButtonDown(MouseButton button) const;
|
||||
|
||||
void setFullscreen(bool fs);
|
||||
void setResizable(bool resizable);
|
||||
void setVsyncEnabled(bool);
|
||||
void setTitle(const std::string& title);
|
||||
std::string getTitle() const;
|
||||
void fullscreen();
|
||||
void restoreFromFullscreen();
|
||||
bool getFlag(RWindowFlags flag) const;
|
||||
void setFlag(RWindowFlags flag, bool state);
|
||||
//void init(RenderingAPI api, const char* title, int width, int height, bool vsync);
|
||||
void destroyWindow();
|
||||
void pollEvents();
|
||||
void refresh();
|
||||
void setSize(int width, int height);
|
||||
void setSize(const Vector2& size);
|
||||
/// Returns the position of the window's top-left corner relative to the display
|
||||
Vector2 getPos() const;
|
||||
Vector2 getSize() const;
|
||||
void setPos(int x, int y);
|
||||
void setPos(const Vector2& pos);
|
||||
Vector2 getCursorPos() const;
|
||||
void raise() const;
|
||||
void lower() const;
|
||||
void setCursorStyle(CursorStyle style) const;
|
||||
void setCursorCustomIcon() const;
|
||||
|
||||
static void glSwapBuffers();
|
||||
//Initialize to false because it's not guaranteed that they will be cleared first
|
||||
private:
|
||||
Vector2 lastKnownWindowSize {0, 0};
|
||||
bool flags[5];
|
||||
std::vector<RWindowEvent> eventLog;
|
||||
KeyboardState currentKeyboard; // Current Frame's Keyboard State
|
||||
KeyboardState previousKeyboard; // Previous Frame's Keyboard State
|
||||
bool fullscreenmode = false;
|
||||
std::string title;
|
||||
#ifndef __linux__
|
||||
int x;
|
||||
int y;
|
||||
#endif
|
||||
int width;
|
||||
int height;
|
||||
RenderingAPI renderer;
|
||||
bool open = false;
|
||||
bool resizable;
|
||||
};
|
||||
|
||||
|
||||
};
|
||||
class WindowsImplementationRWindow: public RWindow {
|
||||
};
|
||||
|
||||
|
||||
class WindowsImplementationRWindow : public RWindow
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
class X11ImplementationRWindow : public RWindow
|
||||
{
|
||||
|
||||
};
|
||||
class X11ImplementationRWindow: public RWindow {
|
||||
};
|
||||
}
|
166
main.cpp
166
main.cpp
@@ -1,64 +1,75 @@
|
||||
#include <iostream>
|
||||
#include <rewindow/types/window.h>
|
||||
|
||||
#if __linux__
|
||||
|
||||
Vector2 mouse_pos;
|
||||
|
||||
// TODO: Move to J3ML::LinearAlgebra::Vector2
|
||||
std::ostream& operator<<(std::ostream& os, const Vector2& v)
|
||||
{
|
||||
return os << "{" << v.x << ", " << v.y << "}";
|
||||
std::ostream& operator<<(std::ostream& os, const Vector2& v) {
|
||||
return os << "{" << v.x << ", " << v.y << "}";
|
||||
}
|
||||
|
||||
class MyWindow : public ReWindow::RWindow
|
||||
{
|
||||
public:
|
||||
MyWindow(const std::string& title, int w, int h) : ReWindow::RWindow(title, w, h)
|
||||
{}
|
||||
class MyWindow : public ReWindow::RWindow {
|
||||
public:
|
||||
MyWindow(const std::string& title, int w, int h) : ReWindow::RWindow(title, w, h)
|
||||
{}
|
||||
|
||||
void OnMouseMove(const ReWindow::MouseMoveEvent& e) override {
|
||||
}
|
||||
|
||||
void OnMouseMove(const ReWindow::MouseMoveEvent& e) override
|
||||
{
|
||||
void OnKeyDown(const ReWindow::KeyDownEvent& e) override {
|
||||
}
|
||||
|
||||
}
|
||||
void OnKeyDown(const ReWindow::KeyDownEvent& e) override
|
||||
{
|
||||
void OnRefresh(float elapsed) override {
|
||||
glSwapBuffers ();
|
||||
auto pos = getCursorPos ();
|
||||
//std::cout << pos.x << ", " << pos.y << std::endl;
|
||||
|
||||
}
|
||||
void OnRefresh(float elapsed) override
|
||||
{
|
||||
glSwapBuffers();
|
||||
auto pos = getCursorPos();
|
||||
//std::cout << pos.x << ", " << pos.y << std::endl;
|
||||
#if __linux__
|
||||
if (isKeyDown(Keys::L)) {
|
||||
this->setCursorStyle (ReWindow::Cursors::Pencil);
|
||||
}
|
||||
else this->setCursorStyle (ReWindow::Cursors::Default);
|
||||
#else
|
||||
if (isKeyDown (Keys::L)) {
|
||||
this->setCursorStyle (ReWindow::Cursors::Cross);
|
||||
}
|
||||
else this->setCursorStyle (ReWindow::Cursors::Arrow);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (isKeyDown(Keys::L))
|
||||
this->setCursorStyle(ReWindow::Cursors::Pencil);
|
||||
else
|
||||
this->setCursorStyle(ReWindow::Cursors::Default);
|
||||
}
|
||||
bool OnResizeRequest(const ReWindow::WindowResizeRequestEvent& e) override
|
||||
{
|
||||
std::cout << "resized to " << e.Size.x << ", " << e.Size.y << std::endl;
|
||||
return true;
|
||||
}
|
||||
bool OnResizeRequest(const ReWindow::WindowResizeRequestEvent& e) override {
|
||||
std::cout << "resized to " << e.Size.x << ", " << e.Size.y << std::endl;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
#if __linux__
|
||||
|
||||
int main() {
|
||||
auto* window = new MyWindow("Test Window", 600, 480);
|
||||
auto* window = new MyWindow("Test Window", 600, 480);
|
||||
|
||||
window->SetRenderer(RenderingAPI::OPENGL);
|
||||
window->Open();
|
||||
// TODO: Cannot set flags until after window is open
|
||||
// Make this work somehow
|
||||
window->setFullscreen(false);
|
||||
window->setVsyncEnabled(true);
|
||||
window->setResizable(true);
|
||||
window->setRenderer(RenderingAPI::OPENGL);
|
||||
window->Open();
|
||||
|
||||
while (window->isAlive()) {
|
||||
window->pollEvents();
|
||||
window->refresh();
|
||||
}
|
||||
// TODO: Cannot set flags until after window is open
|
||||
// Make this work somehow
|
||||
window->setFullscreen(false);
|
||||
window->setVsyncEnabled(false);
|
||||
window->setResizable(false);
|
||||
|
||||
window->OnKeyDownEvent += [&] (ReWindow::KeyDownEvent e)
|
||||
{
|
||||
if (e.key == Keys::LeftArrow)
|
||||
{
|
||||
std::cout << "Left Arrow Hit" << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
while (window->isAlive()) {
|
||||
window->pollEvents();
|
||||
window->refresh();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -70,67 +81,22 @@ int main() {
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||
int wmain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine, int nCmdShow) {
|
||||
auto* window = new MyWindow ("Test Window", 600, 480);
|
||||
window->raise ();
|
||||
|
||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
|
||||
{
|
||||
auto* window = new RWindow();
|
||||
window->init(RenderingAPI::OPENGL, "mame", 100, 100);
|
||||
window->setFlag
|
||||
window->OnKeyDownEvent += [&] (ReWindow::KeyDownEvent e) {
|
||||
if (e.key == Keys::LeftArrow) {
|
||||
std::cout << "Left Arrow Hit" << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
// Register the window class.
|
||||
const wchar_t CLASS_NAME[] = L"Sample Window Class";
|
||||
while (window->isAlive()) {
|
||||
window->pollEvents();
|
||||
window->refresh();
|
||||
}
|
||||
|
||||
WNDCLASS wc = { };
|
||||
wc.lpfnWndProc = WindowProc;
|
||||
wc.hInstance = hInstance;
|
||||
wc.lpszClassName = CLASS_NAME;
|
||||
|
||||
RegisterClass(&wc);
|
||||
|
||||
// Create the window.
|
||||
HWND hwnd = CreateWindowEx(
|
||||
0,
|
||||
CLASS_NAME,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
NULL, // Parent Window
|
||||
NULL, // Menu
|
||||
hInstance, // Instancehandle
|
||||
NULL
|
||||
);
|
||||
if (hwnd == NULL)
|
||||
return 0;
|
||||
|
||||
ShowWindow(hwnd, nCmdShow);
|
||||
|
||||
// Run the message loop
|
||||
MSG msg = {};
|
||||
while (GetMessage(&msg, NULL, 0, 0) > 0)
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch(uMsg) {
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
case WM_PAINT:
|
||||
{
|
||||
PAINTSTRUCT ps;
|
||||
HDC hdc = BeginPaint(hwnd, &ps);
|
||||
|
||||
// All painting occurs here, between BeginPaint and EndPaint
|
||||
FillRect(hdc, &ps.rcPaint, (HBRUSH) (COLOR_WINDOW+1));
|
||||
EndPaint(hwnd, &ps);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return DefWindowProc(hwnd, uMsg, wParam, lParam);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
@@ -1 +0,0 @@
|
||||
#include "../include/rewindow/types/event.h"
|
@@ -10,6 +10,8 @@
|
||||
#include <cstring>
|
||||
#include <thread>
|
||||
#include "rewindow/types/cursors.h"
|
||||
#include "../../include/rewindow/types/window.h"
|
||||
|
||||
|
||||
// TODO: Move all "global" members to be instantiated class members of Window
|
||||
// Doing this would break the intended "Platform-Specific" Encapsulation
|
||||
@@ -29,15 +31,27 @@ GLXContext glContext;
|
||||
|
||||
namespace ReWindow {
|
||||
|
||||
RWindow::RWindow() {
|
||||
title = "ReWindow Application";
|
||||
width = 640;
|
||||
height = 480;
|
||||
//RWindow::singleton = this;
|
||||
}
|
||||
|
||||
RWindow::RWindow(const std::string& title, int width, int height) : flags(false,false,false,false) {
|
||||
this->title = title;
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
|
||||
//RWindow::singleton = this;
|
||||
|
||||
}
|
||||
|
||||
RWindow::RWindow(const std::string& title, int width, int height, RenderingAPI renderer) :
|
||||
title(title), width(width), height(height), renderer(renderer)
|
||||
{ }
|
||||
{
|
||||
//RWindow::singleton = this;
|
||||
}
|
||||
|
||||
void RWindow::raise() const { XRaiseWindow(display, window); }
|
||||
void RWindow::lower() const { XLowerWindow(display, window); }
|
||||
@@ -115,18 +129,14 @@ namespace ReWindow {
|
||||
if (xev.type == KeyRelease) {
|
||||
auto scancode = (X11Scancode) xev.xkey.keycode;
|
||||
auto key = GetKeyFromX11Scancode(scancode);
|
||||
currentKeyboard.PressedKeys[key] = false;
|
||||
KeyUpEvent eventData = KeyUpEvent(key);
|
||||
OnKeyUp(eventData);
|
||||
liftKey (key);
|
||||
}
|
||||
|
||||
if (xev.type == KeyPress) {
|
||||
auto scancode = (X11Scancode) xev.xkey.keycode;
|
||||
auto key = GetKeyFromX11Scancode(scancode);
|
||||
currentKeyboard.PressedKeys[key] = true;
|
||||
KeyDownEvent eventData = KeyDownEvent(key);
|
||||
OnKeyDown(eventData);
|
||||
eventLog.push_back(eventData);
|
||||
pressKey (key);
|
||||
//eventLog.push_back(eventData);
|
||||
}
|
||||
|
||||
if (xev.type == ButtonRelease) {
|
||||
@@ -173,10 +183,10 @@ namespace ReWindow {
|
||||
// Might make the window go off the screen on some window managers.
|
||||
void RWindow::setSize(int newWidth, int newHeight)
|
||||
{
|
||||
this->width = newWidth;
|
||||
this->height = newHeight;
|
||||
if (!getFlag(RWindowFlags::RESIZABLE))
|
||||
return;
|
||||
this->width = newWidth;
|
||||
this->height = newHeight;
|
||||
XResizeWindow(display, window, width, height);
|
||||
}
|
||||
|
||||
@@ -307,16 +317,15 @@ namespace ReWindow {
|
||||
}
|
||||
|
||||
void RWindow::setVsyncEnabled(bool b) {
|
||||
PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT = nullptr;
|
||||
PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT;
|
||||
glXSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddressARB((const GLubyte*)"glXSwapIntervalEXT");
|
||||
glXSwapIntervalEXT(display, None, b);
|
||||
glXSwapIntervalEXT(display, window, b);
|
||||
}
|
||||
|
||||
bool RWindow::isFullscreen() const {
|
||||
return fullscreenmode;
|
||||
}
|
||||
|
||||
using J3ML::u32;
|
||||
void RWindow::setCursorStyle(CursorStyle style) const {
|
||||
u32 x11_cursor_resolved_enum = static_cast<u32>(style.X11Cursor);
|
||||
Cursor c = XCreateFontCursor(display, x11_cursor_resolved_enum);
|
||||
@@ -383,7 +392,11 @@ namespace ReWindow {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RWindow::setRenderer(RenderingAPI api) {
|
||||
renderer = api;
|
||||
}
|
||||
|
||||
// TODO: Implement ControllerButton map
|
||||
|
||||
|
||||
}
|
@@ -1,31 +1,389 @@
|
||||
#include <rewindow/types/window.h>
|
||||
#include <rewindow/types/cursors.h>
|
||||
#include <GL/gl.h>
|
||||
|
||||
typedef BOOL (APIENTRY* PFNWGLSWAPINTERVALEXTPROC)(int interval);
|
||||
|
||||
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||
LRESULT CALLBACK ReWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
||||
ReWindow::RWindow* subject = (ReWindow::RWindow*) GetWindowLongPtrA (hwnd, GWLP_USERDATA);
|
||||
|
||||
switch (uMsg) {
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage (0);
|
||||
break;
|
||||
|
||||
LPTSTR szClassName = TEXT("GenericProgramWindowClass");
|
||||
case WM_SETFOCUS: {
|
||||
ReWindow::RWindowEvent event {};
|
||||
subject->OnFocusGain (event);
|
||||
subject->setFlag (RWindowFlags::IN_FOCUS, true);
|
||||
break;
|
||||
}
|
||||
|
||||
WNDCLASS wc = { };
|
||||
wc.lpfnWndProc = WindowProc;
|
||||
case WM_KILLFOCUS: {
|
||||
ReWindow::RWindowEvent event {};
|
||||
subject->OnFocusLost (event);
|
||||
subject->setFlag (RWindowFlags::IN_FOCUS, false);
|
||||
break;
|
||||
}
|
||||
|
||||
HWND hwnd;
|
||||
case WM_KEYDOWN: {
|
||||
auto key = GetKeyFromWindowsScancode ((WindowsScancode) wParam);
|
||||
subject->pressKey (key);
|
||||
break;
|
||||
}
|
||||
|
||||
RWindow::RWindow()
|
||||
{
|
||||
hwnd = CreateWindow();
|
||||
case WM_KEYUP: {
|
||||
auto key = GetKeyFromWindowsScancode ((WindowsScancode) wParam);
|
||||
subject->liftKey (key);
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_LBUTTONDOWN: {
|
||||
auto event = ReWindow::WindowEvents::MouseButtonDownEvent();
|
||||
event.Button = MouseButtons::Left;
|
||||
subject->OnMouseButtonDown(event);
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_RBUTTONDOWN: {
|
||||
auto event = ReWindow::WindowEvents::MouseButtonDownEvent();
|
||||
event.Button = MouseButtons::Right;
|
||||
subject->OnMouseButtonDown(event);
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_MBUTTONDOWN: {
|
||||
auto event = ReWindow::WindowEvents::MouseButtonDownEvent();
|
||||
event.Button = MouseButtons::Middle;
|
||||
subject->OnMouseButtonDown(event);
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_LBUTTONUP: {
|
||||
auto event = ReWindow::WindowEvents::MouseButtonUpEvent();
|
||||
event.Button = MouseButtons::Left;
|
||||
subject->OnMouseButtonUp(event);
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_RBUTTONUP: {
|
||||
auto event = ReWindow::WindowEvents::MouseButtonUpEvent();
|
||||
event.Button = MouseButtons::Right;
|
||||
subject->OnMouseButtonUp(event);
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_MBUTTONUP: {
|
||||
auto event = ReWindow::WindowEvents::MouseButtonUpEvent();
|
||||
event.Button = MouseButtons::Middle;
|
||||
subject->OnMouseButtonUp(event);
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_MOUSEMOVE: {
|
||||
auto event = ReWindow::WindowEvents::MouseMoveEvent (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam));
|
||||
subject->OnMouseMove(event);
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_SHOWWINDOW:
|
||||
if (wParam) {
|
||||
// as for Expose event in linux
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case WM_WINDOWPOSCHANGED: {
|
||||
WINDOWPOS *pos = (WINDOWPOS *) lParam;
|
||||
subject->setRect (pos->x, pos->y, pos->cx, pos->cy);
|
||||
auto event = ReWindow::WindowEvents::WindowResizeRequestEvent();
|
||||
event.Size = {(float) pos->cx, (float) pos->cy};
|
||||
subject->OnResizeRequest (event);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
return DefWindowProcA (hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static HWND hwnd = NULL;
|
||||
static HDC hdc = NULL;
|
||||
static ATOM reClass = 0;
|
||||
static HGLRC glrc = NULL;
|
||||
static DEVMODEA mode;
|
||||
|
||||
void RWindow::raise() const {
|
||||
SendMessage(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0); // Restore
|
||||
SetForegroundWindow(hwnd);
|
||||
SetActiveWindow(hwnd);
|
||||
SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
|
||||
// Redraw to prevent the window blank
|
||||
RedrawWindow(hwnd, NULL, 0, RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN);
|
||||
void registerClass () {
|
||||
if (!reClass) {
|
||||
HINSTANCE module = GetModuleHandleA (NULL);
|
||||
|
||||
WNDCLASSA rewc = {CS_HREDRAW | CS_VREDRAW,
|
||||
ReWindowProc, 0, 0, module, NULL, LoadCursor (NULL, IDC_ARROW),
|
||||
(HBRUSH) GetStockObject (BLACK_BRUSH), NULL, "ReWindowClass"
|
||||
};
|
||||
|
||||
reClass = RegisterClassA (&rewc);
|
||||
}
|
||||
}
|
||||
|
||||
void RWindow::lower() const {
|
||||
ReWindow::RWindow::RWindow() {
|
||||
registerClass ();
|
||||
|
||||
}
|
||||
for (int num = 0; num < (int) RWindowFlags::MAX_FLAG; ++num) {
|
||||
flags[num] = false;
|
||||
}
|
||||
|
||||
hwnd = CreateWindowA ("ReWindowClass", "ReWindow", WS_TILEDWINDOW,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
NULL, NULL, NULL, 0);
|
||||
SetWindowLongPtrA (hwnd, GWLP_USERDATA, (LONG_PTR) this);
|
||||
}
|
||||
|
||||
ReWindow::RWindow::RWindow (const std::string& title, int width, int height) {
|
||||
registerClass ();
|
||||
|
||||
for (int num = 0; num < (int) RWindowFlags::MAX_FLAG; ++num) {
|
||||
flags[num] = false;
|
||||
}
|
||||
|
||||
hwnd = CreateWindowA ("ReWindowClass", title.c_str (), WS_TILEDWINDOW,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT, width, height,
|
||||
NULL, NULL, NULL, 0);
|
||||
|
||||
SetWindowLongPtrA (hwnd, GWLP_USERDATA, (LONG_PTR) this);
|
||||
}
|
||||
|
||||
void ReWindow::RWindow::raise() const {
|
||||
SetForegroundWindow (hwnd);
|
||||
SetActiveWindow (hwnd);
|
||||
SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
|
||||
ShowWindow (hwnd, SW_SHOW);
|
||||
// Redraw to prevent the window blank
|
||||
RedrawWindow (hwnd, NULL, 0, RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN);
|
||||
}
|
||||
|
||||
void ReWindow::RWindow::lower() const {
|
||||
ShowWindow (hwnd, SW_MINIMIZE);
|
||||
}
|
||||
|
||||
void ReWindow::RWindow::destroyWindow() {
|
||||
if (hwnd) {
|
||||
if (hdc) {
|
||||
if (glrc) {
|
||||
wglMakeCurrent (NULL, NULL);
|
||||
wglDeleteContext (glrc);
|
||||
}
|
||||
|
||||
ReleaseDC (hwnd, hdc);
|
||||
}
|
||||
|
||||
DestroyWindow (hwnd);
|
||||
}
|
||||
|
||||
delete this;
|
||||
}
|
||||
|
||||
void ReWindow::RWindow::refresh() {
|
||||
// TODO: Implement refresh time keeping
|
||||
OnRefresh (0.f);
|
||||
|
||||
// TODO: Check if mouse coords have changed, only then fire OnMouseMove event
|
||||
Vector2 mouse_coords = getCursorPos();
|
||||
|
||||
auto eventData = MouseMoveEvent(mouse_coords);
|
||||
OnMouseMove(eventData);
|
||||
|
||||
std::this_thread::sleep_for(1ms);
|
||||
}
|
||||
|
||||
bool ReWindow::RWindow::getFlag (RWindowFlags flag) const {
|
||||
return (flags[(int) flag]);
|
||||
}
|
||||
|
||||
void ReWindow::RWindow::setFlag (RWindowFlags flag, bool state) {
|
||||
DWORD style = GetWindowLongA (hwnd, GWL_STYLE);
|
||||
flags[(int) flag] = state;
|
||||
|
||||
if (flag == RWindowFlags::RESIZABLE) {
|
||||
if (style & WS_THICKFRAME) {
|
||||
if (!state) {
|
||||
style &= ~WS_THICKFRAME;
|
||||
SetWindowLongA (hwnd, GWL_STYLE, style);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (state) {
|
||||
style |= WS_THICKFRAME;
|
||||
SetWindowLongA (hwnd, GWL_STYLE, style);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ReWindow::RWindow::pollEvents() {
|
||||
MSG msg;
|
||||
|
||||
while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) {
|
||||
if (msg.message == WM_QUIT) {
|
||||
setFlag (RWindowFlags::QUIT, true);
|
||||
}
|
||||
|
||||
TranslateMessage (&msg);
|
||||
DispatchMessage (&msg);
|
||||
}
|
||||
}
|
||||
|
||||
// Might make the window go off the screen on some window managers.
|
||||
void ReWindow::RWindow::setSize (int w, int h) {
|
||||
if (!getFlag (RWindowFlags::RESIZABLE)) return;
|
||||
MoveWindow (hwnd, x, y, w, h, TRUE);
|
||||
}
|
||||
|
||||
void ReWindow::RWindow::setSize(const Vector2& size) {
|
||||
if (!getFlag (RWindowFlags::RESIZABLE)) return;
|
||||
MoveWindow (hwnd, x, y, size.x, size.y, TRUE);
|
||||
}
|
||||
|
||||
Vector2 ReWindow::RWindow::getCursorPos() const {
|
||||
POINT pos;
|
||||
GetCursorPos (&pos);
|
||||
|
||||
// TODO: normalize coordinates from displaySpace to windowSpace
|
||||
// TODO: fire mouse movement event
|
||||
//std::cout << win_x_ret << ", " << win_y_ret << std::endl;
|
||||
// TODO: Compensate for height of window TitleBar + window border width
|
||||
Vector2 mouse_coords_raw = {(float) pos.x, (float) pos.y};
|
||||
auto window_pos = getPos();
|
||||
return mouse_coords_raw - window_pos;
|
||||
}
|
||||
|
||||
// TODO: implement integer vector2/3 types
|
||||
Vector2 ReWindow::RWindow::getSize() const {
|
||||
return {(float) width, (float) height};
|
||||
}
|
||||
|
||||
// TODO: implement integer vector2/3 types
|
||||
Vector2 ReWindow::RWindow::getPos() const {
|
||||
return Vector2 ((float) x, (float) y);
|
||||
}
|
||||
|
||||
void ReWindow::RWindow::setPos(int nx, int ny) {
|
||||
MoveWindow (hwnd, nx, ny, width, height, TRUE);
|
||||
}
|
||||
|
||||
void ReWindow::RWindow::setPos(const Vector2& pos) {
|
||||
MoveWindow (hwnd, pos.x, pos.y, width, height, TRUE);
|
||||
}
|
||||
|
||||
void ReWindow::RWindow::glSwapBuffers() {
|
||||
SwapBuffers (hdc);
|
||||
}
|
||||
|
||||
bool ReWindow::RWindow::isResizable() const {
|
||||
return this->getFlag (RWindowFlags::RESIZABLE);
|
||||
}
|
||||
|
||||
bool ReWindow::RWindow::isAlive() const {
|
||||
return !getFlag (RWindowFlags::QUIT);
|
||||
}
|
||||
|
||||
void ReWindow::RWindow::setResizable(bool resizable) {
|
||||
this->resizable = resizable;
|
||||
this->setFlag(RWindowFlags::RESIZABLE, resizable);
|
||||
}
|
||||
|
||||
void ReWindow::RWindow::setFullscreen(bool fs) {
|
||||
if (fs) {
|
||||
fullscreen();
|
||||
}
|
||||
else restoreFromFullscreen();
|
||||
}
|
||||
|
||||
void ReWindow::RWindow::fullscreen() {
|
||||
DEVMODEA screen = {sizeof (DEVMODEA)};
|
||||
screen.dmBitsPerPel = 32;
|
||||
screen.dmPelsWidth = width;
|
||||
screen.dmPelsHeight = height;
|
||||
screen.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
|
||||
|
||||
if (ChangeDisplaySettingsA (&screen, 0) == DISP_CHANGE_SUCCESSFUL) {
|
||||
fullscreenmode = true;
|
||||
}
|
||||
}
|
||||
|
||||
void ReWindow::RWindow::restoreFromFullscreen() {
|
||||
if (ChangeDisplaySettingsA (&mode, 0) == DISP_CHANGE_SUCCESSFUL) {
|
||||
fullscreenmode = false;
|
||||
}
|
||||
}
|
||||
|
||||
void ReWindow::RWindow::setVsyncEnabled (bool b) {
|
||||
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT;
|
||||
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
|
||||
wglSwapIntervalEXT(b);
|
||||
}
|
||||
|
||||
bool ReWindow::RWindow::isFullscreen() const {
|
||||
return fullscreenmode;
|
||||
}
|
||||
|
||||
void ReWindow::RWindow::setCursorStyle (CursorStyle style) const {
|
||||
int idcs[] ={32512, 32513, 32514, 325123, 32649, 32650};
|
||||
SetClassLongPtr (hwnd, GCLP_HCURSOR, (LONG_PTR) LoadCursor (NULL, MAKEINTRESOURCE (idcs[style.WindowsCursor])));
|
||||
}
|
||||
|
||||
void ReWindow::RWindow::Open() {
|
||||
if (hwnd) {
|
||||
hdc = GetDC (hwnd);
|
||||
|
||||
PIXELFORMATDESCRIPTOR pfd = {
|
||||
sizeof (PIXELFORMATDESCRIPTOR),
|
||||
1, PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW,
|
||||
PFD_TYPE_RGBA, 24, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 32,
|
||||
0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
int ipf = ChoosePixelFormat (hdc, &pfd);
|
||||
|
||||
if (ipf) {
|
||||
SetPixelFormat (hdc, ipf, &pfd);
|
||||
glrc = wglCreateContext (hdc);
|
||||
|
||||
if (glrc) {
|
||||
wglMakeCurrent (hdc, glrc);
|
||||
EnumDisplaySettingsA (NULL, ENUM_CURRENT_SETTINGS, &mode);
|
||||
open = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ReWindow::RWindow::setTitle (const std::string &title) {
|
||||
this->title = title;
|
||||
SetWindowTextA (hwnd, title.c_str ());
|
||||
}
|
||||
|
||||
std::string ReWindow::RWindow::getTitle () const {
|
||||
return this->title;
|
||||
}
|
||||
|
||||
bool ReWindow::RWindow::isKeyDown (Key key) const {
|
||||
auto find = currentKeyboard.PressedKeys.find (key);
|
||||
|
||||
if (find != currentKeyboard.PressedKeys.end ()) {
|
||||
return currentKeyboard.PressedKeys.at (key);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: Implement MouseButton map
|
||||
bool ReWindow::RWindow::isMouseButtonDown(MouseButton button) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void ReWindow::RWindow::setRenderer (RenderingAPI api) {
|
||||
renderer = api;
|
||||
}
|
||||
|
Reference in New Issue
Block a user