Compare commits
50 Commits
vA0.2.25
...
Prerelease
Author | SHA1 | Date | |
---|---|---|---|
7e5d85c88a | |||
9247472a13 | |||
7dad83bbc1 | |||
c18fd72b74 | |||
663109da75 | |||
c7a2b42f1d | |||
1f81c0b843 | |||
c25983a87d | |||
1b02dcc364 | |||
254f991c49 | |||
b4c4827c9c | |||
ebf939d747 | |||
04c82df9c5 | |||
2f0cedcd04 | |||
a215d9f398 | |||
a3697cd022 | |||
68a1f52515 | |||
|
8f8eabfe47 | ||
|
a4ec53fdd9 | ||
c0ecb08a3b | |||
7d2921f598 | |||
850fe4aabb | |||
80904cf4b1 | |||
b6bb00e0de | |||
cb03a67f17 | |||
|
f8f9e78dab | ||
214c3e72fd | |||
f6b9bae45f | |||
074f0235c0 | |||
adec224701 | |||
5b8788f94f | |||
56fdc3d90b | |||
3adef96da7 | |||
2956c0b350 | |||
50a7e2cfe1 | |||
10a63d738c | |||
|
b914e9b563 | ||
|
4fb237f11a | ||
|
dfbf018807 | ||
ee5b2f18cd | |||
4336b2bfc9 | |||
4d587f9448 | |||
|
b73cc46ecb | ||
|
f5be8b2707 | ||
39990e587b | |||
|
51d370e045 | ||
|
4ee4cafad7 | ||
|
e1c0cdd1a2 | ||
|
7b149594fe | ||
|
350b12aa6d |
23
.gitea/workflows/buildtest.yml
Normal file
23
.gitea/workflows/buildtest.yml
Normal file
@@ -0,0 +1,23 @@
|
||||
name: Run ReCI Build Test
|
||||
run-name: Run ReCI Build Test For ${{ gitea.repository }}.
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
Explore-Gitea-Actions:
|
||||
runs-on: ubuntu-22.04
|
||||
env:
|
||||
RECI_GIT: https://git.redacted.cc/maxine/ReCI
|
||||
RECI: /RECI
|
||||
steps:
|
||||
- run: echo "The job was automatically triggered by a ${{ gitea.event_name }} event."
|
||||
- run: echo "This job is now running on a ${{ runner.os }} server hosted by Gitea!"
|
||||
- run: echo "The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}."
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@v3
|
||||
- run: echo "The ${{ gitea.repository }} repository has been cloned to the runner."
|
||||
- run: echo "The workflow is now ready to run your tests on the runner."
|
||||
- run: echo "Install toolchain and run ReCI build test"
|
||||
- run: apt-get update && apt-get install -y lua5.3 git && git clone $RECI_GIT $RECI
|
||||
- run: lua $RECI/reci.lua -f $RECI/scripts/buildtools.reci -f reci/scripts/builddeps.reci -f $RECI/scripts/buildtest.reci
|
||||
- run: echo this exists so I can run the reci test
|
||||
- run: echo "This job's status is ${{ job.status }}."
|
157
CMakeLists.txt
157
CMakeLists.txt
@@ -1,81 +1,78 @@
|
||||
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)
|
||||
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-2.2.zip
|
||||
)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME Event
|
||||
URL https://git.redacted.cc/josh/Event/archive/Release-6.zip
|
||||
)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME jlog
|
||||
URL https://git.redacted.cc/josh/jlog/archive/Prerelease-9.zip
|
||||
)
|
||||
|
||||
find_package(OpenGL REQUIRED)
|
||||
include_directories(${OPENGL_INCLUDE_DIRS})
|
||||
include_directories(${J3ML_SOURCE_DIR}/include)
|
||||
include_directories(${jlog_SOURCE_DIR}/include)
|
||||
|
||||
|
||||
file(GLOB_RECURSE HEADERS "include/*.h" "include/*.hpp")
|
||||
|
||||
if(UNIX AND NOT APPLE)
|
||||
file(GLOB_RECURSE SOURCES "src/types/*.cpp" "src/platform/linux/*.cpp" "src/platform/shared/*.cpp")
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
file(GLOB_RECURSE SOURCES "src/types/*.cpp" "src/platform/windows/*.cpp" "src/platform/shared/*.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 J3ML Event jlog ${OPENGL_LIBRARIES})
|
||||
target_link_libraries(ReWindowLibrary PUBLIC)
|
||||
|
||||
add_executable(ReWindowLibraryDemo main.cpp)
|
||||
target_link_libraries(ReWindowLibraryDemo PUBLIC ReWindowLibrary)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
target_compile_options(ReWindowLibrary PUBLIC /utf-8)
|
||||
target_link_libraries(ReWindowLibrary PUBLIC J3ML Event jlog ${OPENGL_LIBRARIES})
|
||||
add_executable(ReWindowLibraryDemo main.cpp)
|
||||
target_link_libraries(ReWindowLibraryDemo PUBLIC ReWindowLibrary)
|
||||
endif()
|
@@ -1,98 +0,0 @@
|
||||
# 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
|
||||
|
@@ -1,15 +0,0 @@
|
||||
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)
|
@@ -1,11 +0,0 @@
|
||||
|
||||
---
|
||||
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 +0,0 @@
|
||||
# This file is generated by cmake for dependency checking of the CMakeCache.txt file
|
57
include/rewindow/data/GamepadScancodes.h
Normal file
57
include/rewindow/data/GamepadScancodes.h
Normal file
@@ -0,0 +1,57 @@
|
||||
// @file GamepadScancodes.h
|
||||
// @
|
||||
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* These scancodes were obtained from some knockoff Xbox controller from PowerA.
|
||||
* I expect these to be fairly generic, so it's a good base to start from.
|
||||
*
|
||||
* Something to keep in mind is the seperation here. On Linux linux/joystick.h
|
||||
* is used to read controller inputs. It's a generic driver/library/whatever the
|
||||
* fuck it's called.
|
||||
*
|
||||
* 2 constants are defined in linux/joystick.h
|
||||
*
|
||||
* JS_EVENT_BUTTON
|
||||
* JS_EVENT_AXIS
|
||||
*
|
||||
* This is why I made seperate enum classes. Both the Axis and the Button scancode
|
||||
* count start from 0x00. Having this seperation is easier to work with.
|
||||
*
|
||||
* I may write a program in the future to let us harvest scancodes from controllers.
|
||||
* I hacked up some C code to get the scancodes for this one without the annoying
|
||||
* stick drift spamming the screen, so with a little more work I could probably turn
|
||||
* it into a generic test program
|
||||
*
|
||||
* P.S Windows is gonna make this slightly more annoying and different from what I've
|
||||
* seen.
|
||||
*
|
||||
* - Maxine
|
||||
*/
|
||||
|
||||
enum class GamepadScancode_AXIS {
|
||||
ABS_X = 0x00, // Xbox Left Thumbstick Axis
|
||||
ABS_Y = 0x01, // <-'
|
||||
ABS_Z = 0x02, // Xbox Left Trigger Axis
|
||||
ABS_RX = 0x03, // Xbox Right Thumbstick Axis
|
||||
ABS_RY = 0x04, // <-'
|
||||
ABS_RZ = 0x05, // Xbox Right Trigger Axis (I know strange ain't it?)
|
||||
ABS_HAT0X = 0x06, // Xbox DPad Axis (The Dpad is basically seen as a 3rd thumbstick)
|
||||
ABS_HAT0Y = 0x07, // <-'
|
||||
}
|
||||
|
||||
enum class GamepadScancode_BTN {
|
||||
BTN_SOUTH = 0x00 // Xbox A Button
|
||||
BTN_EAST = 0x01 // Xbox B Button
|
||||
BTN_WEST = 0x02 // Xbox X Button
|
||||
BTN_NORTH = 0x03 // Xbox Y Button
|
||||
BTN_TL = 0x04, // Xbox Left Bumper
|
||||
BTN_TR = 0x05, // Xbox Right Bumper
|
||||
BTN_START = 0x06, // Xbox Start Button
|
||||
BTN_SELECT = 0x07, // Xbox Select Button
|
||||
BTN_HOME = 0x08, // Xbox Home/Logo Button
|
||||
BTN_THUMBL = 0x09, // Xbox Left Thumstick Button
|
||||
BTN_THUMBR = 0x0a, // Xbox Right Thumbstick Button
|
||||
}
|
||||
|
@@ -1,95 +1,107 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
enum class WindowsScancode {
|
||||
Nothing = 0,
|
||||
ESCAPE = 0x01,
|
||||
ONE = 0x02,
|
||||
TWO = 0x03,
|
||||
THREE = 0x04,
|
||||
FOUR = 0x05,
|
||||
FIVE = 0x06,
|
||||
SIX = 0x07,
|
||||
SEVEN = 0x08,
|
||||
EIGHT = 0x09,
|
||||
NINE = 0x0A,
|
||||
ZERO = 0x0B,
|
||||
MINUS = 0x0C,
|
||||
EQUALS = 0x0D,
|
||||
BACKSPACE = 0x0E,
|
||||
TAB = 0x0F,
|
||||
Q = 0x10,
|
||||
W = 0x11,
|
||||
E = 0x12,
|
||||
R = 0x13,
|
||||
T = 0x14,
|
||||
Y = 0x15,
|
||||
U = 0x16,
|
||||
I = 0x17,
|
||||
O = 0x18,
|
||||
P = 0x19,
|
||||
LEFT_BRACKET = 0x1A,
|
||||
RIGHT_BRACKET = 0x1B,
|
||||
ENTER = 0x1C,
|
||||
CTRL = 0x1D,
|
||||
A = 0x1E,
|
||||
S = 0x1F,
|
||||
D = 0x20,
|
||||
F = 0x21,
|
||||
G = 0x22,
|
||||
H = 0x23,
|
||||
J = 0x24,
|
||||
K = 0x25,
|
||||
L = 0x26,
|
||||
SEMICOLON = 0x27,
|
||||
SINGLEQUOTE = 0x28,
|
||||
GRAVE = 0x29,
|
||||
LEFT_SHIFT = 0x2A,
|
||||
BACKSLASH = 0x2B,
|
||||
Z = 0x2C,
|
||||
X = 0x2D,
|
||||
C = 0x2E,
|
||||
V = 0x2F,
|
||||
B = 0x30,
|
||||
N = 0x30,
|
||||
M = 0x32,
|
||||
COMMA = 0x33,
|
||||
PERIOD = 0x34,
|
||||
SLASH = 0x35,
|
||||
RIGHT_SHIFT = 0x36,
|
||||
PRINTSCREEN = 0x37,
|
||||
ALT = 0x38,
|
||||
SPACE = 0x39,
|
||||
CAPS_LOCK = 0x3A,
|
||||
F1 = 0x3B,
|
||||
F2 = 0x3C,
|
||||
F3 = 0x3D,
|
||||
F4 = 0x3E,
|
||||
F5 = 0x3F,
|
||||
F6 = 0x40,
|
||||
F7 = 0x41,
|
||||
F8 = 0x42,
|
||||
F9 = 0x43,
|
||||
F10 = 0x44,
|
||||
NUM_LOCK = 0x45,
|
||||
SCROLL_LOCK = 0x46,
|
||||
HOME = 0x47,
|
||||
UP_ARROW = 0x48,
|
||||
LEFT_ARROW,
|
||||
DOWN_ARROW,
|
||||
RIGHT_ARROW,
|
||||
PAGE_UP = 0x49,
|
||||
NUMPAD_MINUS = 0x4A,
|
||||
NUMPAD_4 = 0x4B,
|
||||
NUMPAD_5 = 0x4C,
|
||||
NUMPAD_6 = 0x4D,
|
||||
NUMPAD_PLUS = 0x4E,
|
||||
NUMPAD_ONE = 0x4F,
|
||||
NUMPAD_TWO = 0x50,
|
||||
NUMPAD_THREE = 0x51,
|
||||
NUMPAD_ZERO = 0x52,
|
||||
DELETE = 0x53,
|
||||
F11 = 0x85,
|
||||
F12 = 0x86, // FIX
|
||||
ESCAPE = 0x1B, // VK_ESCAPE
|
||||
ONE = 0x31, // '1'
|
||||
TWO = 0x32, // '2'
|
||||
THREE = 0x33, // '3'
|
||||
FOUR = 0x34, // '4'
|
||||
FIVE = 0x35, // '5'
|
||||
SIX = 0x36, // '6'
|
||||
SEVEN = 0x37, // '7'
|
||||
EIGHT = 0x38, // '8'
|
||||
NINE = 0x39, // '9'
|
||||
ZERO = 0x30, // '0'
|
||||
MINUS = 0xBD, // VK_OEM_MINUS
|
||||
EQUALS = 0xBB, // VK_OEM_PLUS
|
||||
BACKSPACE = 0x08, // VK_BACK
|
||||
TAB = 0x09, // VK_TAB
|
||||
Q = 0x51, // 'Q'
|
||||
W = 0x57, // 'W'
|
||||
E = 0x45, // 'E'
|
||||
R = 0x52, // 'R'
|
||||
T = 0x54, // 'T'
|
||||
Y = 0x59, // 'Y'
|
||||
U = 0x55, // 'U'
|
||||
I = 0x49, // 'I'
|
||||
O = 0x4F, // 'O'
|
||||
P = 0x50, // 'P'
|
||||
LEFT_BRACKET = 0xDB, // VK_OEM_4
|
||||
RIGHT_BRACKET = 0xDD, // VK_OEM_6
|
||||
ENTER = 0x0D, // VK_RETURN
|
||||
CTRL = 0x11, // VK_CONTROL
|
||||
A = 0x41, // 'A'
|
||||
S = 0x53, // 'S'
|
||||
D = 0x44, // 'D'
|
||||
F = 0x46, // 'F'
|
||||
G = 0x47, // 'G'
|
||||
H = 0x48, // 'H'
|
||||
J = 0x4A, // 'J'
|
||||
K = 0x4B, // 'K'
|
||||
L = 0x4C, // 'L'
|
||||
SEMICOLON = 0xBA, // VK_OEM_1
|
||||
SINGLEQUOTE = 0xDE, // VK_OEM_7
|
||||
GRAVE = 0xC0, // VK_OEM_3
|
||||
LEFT_SHIFT = 0x10, // VK_LSHIFT
|
||||
BACKSLASH = 0xDC, // VK_OEM_5
|
||||
Z = 0x5A, // 'Z'
|
||||
X = 0x58, // 'X'
|
||||
C = 0x43, // 'C'
|
||||
V = 0x56, // 'V'
|
||||
B = 0x42, // 'B'
|
||||
N = 0x4E, // 'N'
|
||||
M = 0x4D, // 'M'
|
||||
PERIOD = 0xBE, // VK_OEM_PERIOD
|
||||
SLASH = 0xBF, // VK_OEM_2
|
||||
RIGHT_SHIFT = 0xA1, // VK_RSHIFT
|
||||
PRINTSCREEN = 0x2C, // VK_SNAPSHOT
|
||||
ALT = 0x12, // VK_MENU
|
||||
SPACE = 0x20, // VK_SPACE
|
||||
CAPS_LOCK = 0x14, // VK_CAPITAL
|
||||
F1 = 0x70, // VK_F1
|
||||
F2 = 0x71, // VK_F2
|
||||
F3 = 0x72, // VK_F3
|
||||
F4 = 0x73, // VK_F4
|
||||
F5 = 0x74, // VK_F5
|
||||
F6 = 0x75, // VK_F6
|
||||
F7 = 0x76, // VK_F7
|
||||
F8 = 0x77, // VK_F8
|
||||
F9 = 0x78, // VK_F9
|
||||
F10 = 0x79, // VK_F10
|
||||
NUM_LOCK = 0x90, // VK_NUMLOCK
|
||||
SCROLL_LOCK = 0x91, // VK_SCROLL
|
||||
HOME = 0x24, // VK_HOME
|
||||
UP_ARROW = 0x26, // VK_UP
|
||||
PAGE_UP = 0x21, // VK_PRIOR
|
||||
LEFT_ARROW = 0x25, // VK_LEFT
|
||||
DOWN_ARROW = 0x28, // VK_DOWN
|
||||
RIGHT_ARROW = 0x27, // VK_RIGHT
|
||||
END = 0x23, // VK_END
|
||||
PAGE_DOWN = 0x22, // VK_NEXT
|
||||
INSERT = 0x2D, // VK_INSERT
|
||||
DEL = 0x2E, // VK_DELETE
|
||||
F11 = 0x7A, // VK_F11
|
||||
F12 = 0x7B, // VK_F12
|
||||
|
||||
NUMPAD_ZERO = 0x60, // VK_NUMPAD0
|
||||
NUMPAD_ONE = 0x61, // VK_NUMPAD1
|
||||
NUMPAD_TWO = 0x62, // VK_NUMPAD2
|
||||
NUMPAD_THREE = 0x63, // VK_NUMPAD3
|
||||
NUMPAD_FOUR = 0x64, // VK_NUMPAD4
|
||||
NUMPAD_FIVE = 0x65, // VK_NUMPAD5
|
||||
NUMPAD_SIX = 0x66, // VK_NUMPAD6
|
||||
NUMPAD_SEVEN = 0x67, // VK_NUMPAD7
|
||||
NUMPAD_EIGHT = 0x68, // VK_NUMPAD8
|
||||
NUMPAD_NINE = 0x69, // VK_NUMPAD9
|
||||
NUMPAD_PLUS = 0x6B, // VK_ADD
|
||||
NUMPAD_MINUS = 0x6D, // VK_SUBTRACT
|
||||
NUMPAD_ASTERISK = 0x6A,
|
||||
NUMPAD_SLASH = 0x6F,
|
||||
NUMPAD_PERIOD = 0x6E, // VK_DECIMAL
|
||||
NUMPAD_ENTER = 0x0D, // VK_RETURN
|
||||
SUPER = 0x5B,
|
||||
COMMA = 0xBC,
|
||||
MENU = 93,
|
||||
BREAK = 0x13
|
||||
};
|
@@ -24,9 +24,10 @@ enum class X11Scancode {
|
||||
PAGEUP = 112,
|
||||
PAGEDOWN = 117,
|
||||
HOME = 110,
|
||||
MENU = 135,
|
||||
END = 115,
|
||||
INSERT = 118,
|
||||
DELETE = 119,
|
||||
DEL = 119,
|
||||
UP = 111,
|
||||
DOWN = 116,
|
||||
LEFT = 113,
|
||||
|
26
include/rewindow/types/gamepad.h
Normal file
26
include/rewindow/types/gamepad.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/// ReWindowLibrary
|
||||
/// A C++20 Library for creating and managing windows in a platform-independent manner
|
||||
/// Developed and Maintained by the boys @ Redacted Software.
|
||||
/// (c) 2024 Redacted Software
|
||||
/// This work is dedicated to the public domain.
|
||||
|
||||
/// @file gamepad.h
|
||||
/// @desc A class that models the functionality of a gamepad / controller device.
|
||||
/// @edit 2024-07-29
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ReWindow
|
||||
{
|
||||
|
||||
class InputDevice {}; // TODO: Remember to break InputDevice into it's own file and not define it twice!!!
|
||||
|
||||
class Gamepad : public InputDevice
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
|
||||
class XboxGamepad : public Gamepad {};
|
||||
class PS4Gamepad : public Gamepad {};
|
||||
}
|
75
include/rewindow/types/gamepadbutton.h
Normal file
75
include/rewindow/types/gamepadbutton.h
Normal file
@@ -0,0 +1,75 @@
|
||||
/// ReWindowLibrary
|
||||
/// A C++20 Library for creating and managing windows in a platform-independent manner
|
||||
/// Developed and Maintained by the boys @ Redacted Software.
|
||||
/// (c) 2024 Redacted Software
|
||||
/// This work is dedicated to the public domain.
|
||||
|
||||
/// @file gamepadbutton.h
|
||||
/// @desc GamepadButton class and enumerations to define standard buttons found on a Gamepad
|
||||
/// @edit 2024-07-29
|
||||
|
||||
#include <string>
|
||||
#include <J3ML/LinearAlgebra.h>
|
||||
|
||||
class GamepadButton {
|
||||
protected:
|
||||
std::string mnemonic_btn_code;
|
||||
public:
|
||||
explicit GamepadButton(const std::string& mnemonic) : mnemonic_btn_code(mnemonic) { }
|
||||
[[nodiscard]] std::string GetMnemonicButtonCode() const { return mnemonic_btn_code; }
|
||||
|
||||
/// Compares two GamepadButtons by their mnemonic button codes, not their activation state.
|
||||
bool operator ==(const GamepadButton& rhs) const;
|
||||
};
|
||||
|
||||
class GamepadTrigger {
|
||||
public:
|
||||
|
||||
/// Returns a float value between 0-1 representing how much the trigger has been pushed in by.
|
||||
/// (0 being unpressed, 1 being fully pressed)
|
||||
float GetActuation() const;
|
||||
|
||||
/// TODO: Might be more appropriate in the Gamepad class representation.
|
||||
void SetActuationThreshold(float minimum = 0.01f) const;
|
||||
};
|
||||
|
||||
class GamepadThumbstick
|
||||
{
|
||||
public:
|
||||
/// Returns a Vector2 value representing the x,y coordinates of the joystick, with 0,0 being the center (at rest).
|
||||
/// This vector ranges from length = 0 to length = 1 (i.e. the unit circle).
|
||||
[[nodiscard]] Vector2 GetPosition() const;
|
||||
|
||||
|
||||
/// Sets the deadzone range of the thumbstick.
|
||||
/// Deadzone controls how far the stick must be moved before any movement is actually reported.
|
||||
/// This is because the thumbstick at-rest will often still report movement.
|
||||
/// If gamecode is architected to use the thumbstick position as a direction, without factoring in magnitude, this would cause problems.
|
||||
void SetDeadzone(float minimum = 0.01f) const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
using J3ML::LinearAlgebra::Vector2;
|
||||
|
||||
namespace GamepadButtons {
|
||||
static const GamepadButton X {"X"};
|
||||
static const GamepadButton Y {"Y"};
|
||||
static const GamepadButton A {"A"};
|
||||
static const GamepadButton B {"B"};
|
||||
|
||||
static const auto Triangle = Y;
|
||||
static const auto Square = X;
|
||||
static const auto Circle = A;
|
||||
static const auto Cross = B;
|
||||
|
||||
|
||||
static const GamepadButton LeftBumper {"LB"};
|
||||
static const GamepadButton RightBumper {"RB"};
|
||||
}
|
||||
|
||||
namespace GamepadTriggers
|
||||
{
|
||||
static const GamepadTrigger Left;
|
||||
static const GamepadTrigger Right;
|
||||
}
|
@@ -3,198 +3,154 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <J3ML/LinearAlgebra/Vector2.h>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
|
||||
#if __linux__
|
||||
#include <X11/X.h>
|
||||
#endif
|
||||
|
||||
#include "rewindow/data/X11Scancodes.h"
|
||||
#include "rewindow/data/WindowsScancodes.h"
|
||||
#include <string>
|
||||
#include <rewindow/data/X11Scancodes.h>
|
||||
#include <rewindow/data/WindowsScancodes.h>
|
||||
#include <J3ML/LinearAlgebra/Vector2.h>
|
||||
|
||||
using J3ML::LinearAlgebra::Vector2;
|
||||
|
||||
class Key
|
||||
{
|
||||
private:
|
||||
static std::vector<Key> keyboard;
|
||||
//CLion on Linux falsely marks this as being wrong.
|
||||
static inline std::vector<Key> keyboard{};
|
||||
|
||||
public:
|
||||
static std::vector<Key> GetKeyboard();
|
||||
Key();
|
||||
Key(char charcode, X11Scancode scancode, WindowsScancode wSc);
|
||||
char CharCode;
|
||||
Key(const char* charcode, X11Scancode scancode, WindowsScancode wSc);
|
||||
const char* CharCode;
|
||||
X11Scancode x11ScanCode;
|
||||
WindowsScancode winScanCode;
|
||||
bool operator==(const Key& rhs) const;
|
||||
bool operator<(const Key& rhs) const;
|
||||
Key(const Key&) = default;
|
||||
|
||||
};
|
||||
|
||||
namespace Keys {
|
||||
// TODO: Encode both Uppercase and Lowercase version for each keymap
|
||||
static const Key Escape {'\b', X11Scancode::ESCAPE, WindowsScancode::ESCAPE};
|
||||
static const Key F1 {'\u000f', X11Scancode::F1, WindowsScancode::F1};
|
||||
static const Key F2 {'\u000f', X11Scancode::F2, WindowsScancode::F2};
|
||||
static const Key F3 {'\u000f', X11Scancode::F3, WindowsScancode::F3};
|
||||
static const Key F4 {'\u000f', X11Scancode::F4, WindowsScancode::F4};
|
||||
static const Key F5 {'\u000f', X11Scancode::F5, WindowsScancode::F5};
|
||||
static const Key F6 {'\u000f', X11Scancode::F6, WindowsScancode::F6};
|
||||
static const Key F7 {'\u000f', X11Scancode::F7, WindowsScancode::F7};
|
||||
static const Key F8 {'\u000f', X11Scancode::F8, WindowsScancode::F8};
|
||||
static const Key F9 {'\u000f', X11Scancode::F9, WindowsScancode::F9};
|
||||
static const Key F10 {'\u000f', X11Scancode::F10, WindowsScancode::F10};
|
||||
static const Key F11 {'\u000f', X11Scancode::F11, WindowsScancode::F11};
|
||||
static const Key F12 {'\u000f', X11Scancode::F12, WindowsScancode::F12};
|
||||
static const Key Escape {"ESC", X11Scancode::ESCAPE, WindowsScancode::ESCAPE};
|
||||
static const Key F1 {"F1", X11Scancode::F1, WindowsScancode::F1};
|
||||
static const Key F2 {"F2", X11Scancode::F2, WindowsScancode::F2};
|
||||
static const Key F3 {"F3", X11Scancode::F3, WindowsScancode::F3};
|
||||
static const Key F4 {"F4", X11Scancode::F4, WindowsScancode::F4};
|
||||
static const Key F5 {"F5", X11Scancode::F5, WindowsScancode::F5};
|
||||
static const Key F6 {"F6", X11Scancode::F6, WindowsScancode::F6};
|
||||
static const Key F7 {"F7", X11Scancode::F7, WindowsScancode::F7};
|
||||
static const Key F8 {"F8", X11Scancode::F8, WindowsScancode::F8};
|
||||
static const Key F9 {"F9", X11Scancode::F9, WindowsScancode::F9};
|
||||
static const Key F10 {"F10", X11Scancode::F10, WindowsScancode::F10};
|
||||
static const Key F11 {"F11", X11Scancode::F11, WindowsScancode::F11};
|
||||
static const Key F12 {"F12", X11Scancode::F12, WindowsScancode::F12};
|
||||
static const Key Print {"PRINT", X11Scancode::PRINT, WindowsScancode::PRINTSCREEN};
|
||||
static const Key ScrollLock {"SCROLL_LOCK", X11Scancode::SCROLL_LOCK, WindowsScancode::SCROLL_LOCK};
|
||||
static const Key Break {"BREAK", X11Scancode::BREAK, WindowsScancode::BREAK};
|
||||
|
||||
static const Key NumPad1 {'\b', X11Scancode::KP_1, 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};
|
||||
static const Key NumPad7 {'\b', X11Scancode::KP_7, WindowsScancode::NUMPAD_ONE};
|
||||
static const Key NumPad8 {'\b', X11Scancode::KP_8, WindowsScancode::NUMPAD_ONE};
|
||||
static const Key NumPad9 {'\b', X11Scancode::KP_9, WindowsScancode::NUMPAD_ONE};
|
||||
static const Key NumPad0 {'\b', X11Scancode::KP_0, WindowsScancode::NUMPAD_ONE};
|
||||
//TODO On Windows, Return & KP_RETURN are the same thing.
|
||||
static const Key NumPadReturn {"KP_↵", X11Scancode::KP_RETURN, WindowsScancode::NUMPAD_ENTER};
|
||||
static const Key NumPadPlus {"KP_+", X11Scancode::KP_PLUS, WindowsScancode::NUMPAD_PLUS};
|
||||
static const Key NumPadMinus {"KP_-", X11Scancode::KP_MINUS, WindowsScancode::NUMPAD_MINUS};
|
||||
static const Key NumPadAsterisk {"KP_*", X11Scancode::KP_ASTERISK, WindowsScancode::NUMPAD_ASTERISK};
|
||||
static const Key NumPadForwardSlash {"KP_/", X11Scancode::KP_SLASH, WindowsScancode::NUMPAD_SLASH};
|
||||
static const Key NumPadPeriod {"KP_.", X11Scancode::KP_PERIOD, WindowsScancode::NUMPAD_PERIOD};
|
||||
static const Key NumPadNumLock {"KP_NUMLOCK", X11Scancode::KP_NUMLOCK, WindowsScancode::NUM_LOCK};
|
||||
|
||||
static const Key One {'1', X11Scancode::ONE, WindowsScancode::ONE};
|
||||
static const Key Two {'2', X11Scancode::TWO, WindowsScancode::TWO};
|
||||
static const Key Three {'3', X11Scancode::THREE, WindowsScancode::THREE};
|
||||
static const Key Four {'4', X11Scancode::FOUR, WindowsScancode::FOUR};
|
||||
static const Key Five {'5', X11Scancode::FIVE, WindowsScancode::FIVE};
|
||||
static const Key Six {'6', X11Scancode::SIX, WindowsScancode::SIX};
|
||||
static const Key Seven {'7', X11Scancode::SEVEN, WindowsScancode::SEVEN};
|
||||
static const Key Eight {'8', X11Scancode::EIGHT, WindowsScancode::EIGHT};
|
||||
static const Key Nine {'9', X11Scancode::NINE, WindowsScancode::NINE};
|
||||
static const Key Zero {'0', X11Scancode::ZERO, WindowsScancode::ZERO};
|
||||
static const Key NumPad1 {"KP_1", X11Scancode::KP_1, WindowsScancode::NUMPAD_ONE};
|
||||
static const Key NumPad2 {"KP_2", X11Scancode::KP_2, WindowsScancode::NUMPAD_TWO};
|
||||
static const Key NumPad3 {"KP_3", X11Scancode::KP_3, WindowsScancode::NUMPAD_THREE};
|
||||
static const Key NumPad4 {"KP_4", X11Scancode::KP_4, WindowsScancode::NUMPAD_FOUR};
|
||||
static const Key NumPad5 {"KP_5", X11Scancode::KP_5, WindowsScancode::NUMPAD_FIVE};
|
||||
static const Key NumPad6 {"KP_6", X11Scancode::KP_6, WindowsScancode::NUMPAD_SIX};
|
||||
static const Key NumPad7 {"KP_7", X11Scancode::KP_7, WindowsScancode::NUMPAD_SEVEN};
|
||||
static const Key NumPad8 {"kP_8", X11Scancode::KP_8, WindowsScancode::NUMPAD_EIGHT};
|
||||
static const Key NumPad9 {"KP_9", X11Scancode::KP_9, WindowsScancode::NUMPAD_NINE};
|
||||
static const Key NumPad0 {"KP_0", X11Scancode::KP_0, WindowsScancode::NUMPAD_ZERO};
|
||||
|
||||
static const Key Q {'Q', X11Scancode::Q, WindowsScancode::Q};
|
||||
static const Key W {'W', X11Scancode::W, WindowsScancode::W};
|
||||
static const Key E {'E', X11Scancode::E, WindowsScancode::E};
|
||||
static const Key R {'R', X11Scancode::R, WindowsScancode::R};
|
||||
static const Key T {'T', X11Scancode::T, WindowsScancode::T};
|
||||
static const Key Y {'Y', X11Scancode::Y, WindowsScancode::Y};
|
||||
static const Key U {'U', X11Scancode::U, WindowsScancode::U};
|
||||
static const Key I {'I', X11Scancode::I, WindowsScancode::I};
|
||||
static const Key O {'O', X11Scancode::O, WindowsScancode::O};
|
||||
static const Key P {'P', X11Scancode::P, WindowsScancode::P};
|
||||
static const Key A {'A', X11Scancode::A, WindowsScancode::A};
|
||||
static const Key S {'S', X11Scancode::S, WindowsScancode::S};
|
||||
static const Key D {'D', X11Scancode::D, WindowsScancode::D};
|
||||
static const Key F {'F', X11Scancode::F, WindowsScancode::F};
|
||||
static const Key G {'G', X11Scancode::G, WindowsScancode::G};
|
||||
static const Key H {'H', X11Scancode::H, WindowsScancode::H};
|
||||
static const Key J {'J', X11Scancode::J, WindowsScancode::J};
|
||||
static const Key K {'K', X11Scancode::K, WindowsScancode::K};
|
||||
static const Key L {'L', X11Scancode::L, WindowsScancode::L};
|
||||
static const Key Semicolon {';', X11Scancode::SEMICOLON, WindowsScancode::SEMICOLON};
|
||||
static const Key SingeQuote {'\'', X11Scancode::SINGLEQUOTE, WindowsScancode::SEMICOLON};
|
||||
static const Key Enter {'\n', X11Scancode::RETURN, WindowsScancode::ENTER};
|
||||
//static const Key KeyPadEnter {'\n', X11Scancode::KP_RETURN};
|
||||
static const Key Minus {'-', X11Scancode::MINUS, WindowsScancode::MINUS};
|
||||
//static const Key KeyPadMinus {'-', X11Scancode::KP_MINUS};
|
||||
static const Key Equals {'=', X11Scancode::EQUALS, WindowsScancode::EQUALS};
|
||||
static const Key Z {'Z', X11Scancode::Z, WindowsScancode::Z};
|
||||
static const Key X {'X', X11Scancode::X, WindowsScancode::X};
|
||||
static const Key C {'C', X11Scancode::C, WindowsScancode::C};
|
||||
static const Key V {'V', X11Scancode::V, WindowsScancode::V};
|
||||
static const Key B {'B', X11Scancode::B, WindowsScancode::B};
|
||||
static const Key N {'N', X11Scancode::N, WindowsScancode::N};
|
||||
static const Key M {'M', X11Scancode::M, WindowsScancode::M};
|
||||
static const Key Period {'.', X11Scancode::PERIOD, WindowsScancode::PERIOD};
|
||||
static const Key ForwardSlash {'/', X11Scancode::SLASH, WindowsScancode::SLASH};
|
||||
static const Key BackSlash {'\\', X11Scancode::BACKSLASH, WindowsScancode::BACKSLASH};
|
||||
static const Key Grave {"`", X11Scancode::GRAVE, WindowsScancode::GRAVE};
|
||||
static const Key One {"1", X11Scancode::ONE, WindowsScancode::ONE};
|
||||
static const Key Two {"2", X11Scancode::TWO, WindowsScancode::TWO};
|
||||
static const Key Three {"3", X11Scancode::THREE, WindowsScancode::THREE};
|
||||
static const Key Four {"4", X11Scancode::FOUR, WindowsScancode::FOUR};
|
||||
static const Key Five {"5", X11Scancode::FIVE, WindowsScancode::FIVE};
|
||||
static const Key Six {"6", X11Scancode::SIX, WindowsScancode::SIX};
|
||||
static const Key Seven {"7", X11Scancode::SEVEN, WindowsScancode::SEVEN};
|
||||
static const Key Eight {"8", X11Scancode::EIGHT, WindowsScancode::EIGHT};
|
||||
static const Key Nine {"9", X11Scancode::NINE, WindowsScancode::NINE};
|
||||
static const Key Zero {"0", X11Scancode::ZERO, WindowsScancode::ZERO};
|
||||
static const Key Minus {"-", X11Scancode::MINUS, WindowsScancode::MINUS};
|
||||
static const Key Equals {"+", X11Scancode::EQUALS, WindowsScancode::EQUALS};
|
||||
static const Key Backspace {"⌫", X11Scancode::BACKSPACE, WindowsScancode::BACKSPACE};
|
||||
|
||||
static const Key Space {' ', X11Scancode::SPACE, WindowsScancode::SPACE};
|
||||
static const Key Tab {"⇥", X11Scancode::TAB, WindowsScancode::TAB};
|
||||
static const Key Q {"Q", X11Scancode::Q, WindowsScancode::Q};
|
||||
static const Key W {"W", X11Scancode::W, WindowsScancode::W};
|
||||
static const Key E {"E", X11Scancode::E, WindowsScancode::E};
|
||||
static const Key R {"R", X11Scancode::R, WindowsScancode::R};
|
||||
static const Key T {"T", X11Scancode::T, WindowsScancode::T};
|
||||
static const Key Y {"Y", X11Scancode::Y, WindowsScancode::Y};
|
||||
static const Key U {"U", X11Scancode::U, WindowsScancode::U};
|
||||
static const Key I {"I", X11Scancode::I, WindowsScancode::I};
|
||||
static const Key O {"O", X11Scancode::O, WindowsScancode::O};
|
||||
static const Key P {"P", X11Scancode::P, WindowsScancode::P};
|
||||
static const Key LeftBracket {"[", X11Scancode::OPENING_SQUARE_BRACKET, WindowsScancode::LEFT_BRACKET};
|
||||
static const Key RightBracket {"]", X11Scancode::CLOSING_SQUARE_BRACKET, WindowsScancode::RIGHT_BRACKET};
|
||||
static const Key BackSlash {"\\", X11Scancode::BACKSLASH, WindowsScancode::BACKSLASH};
|
||||
|
||||
static const Key LControl {'\\', X11Scancode::LEFT_CTRL, WindowsScancode::CTRL};
|
||||
static const Key RControl {'\\', X11Scancode::RIGHT_CONTROL, WindowsScancode::CTRL};
|
||||
static const Key CapsLock = {"CAPS", X11Scancode::CAPSLOCK, WindowsScancode::CAPS_LOCK};
|
||||
static const Key A {"A", X11Scancode::A, WindowsScancode::A};
|
||||
static const Key S {"S", X11Scancode::S, WindowsScancode::S};
|
||||
static const Key D {"D", X11Scancode::D, WindowsScancode::D};
|
||||
static const Key F {"F", X11Scancode::F, WindowsScancode::F};
|
||||
static const Key G {"G", X11Scancode::G, WindowsScancode::G};
|
||||
static const Key H {"H", X11Scancode::H, WindowsScancode::H};
|
||||
static const Key J {"J", X11Scancode::J, WindowsScancode::J};
|
||||
static const Key K {"K", X11Scancode::K, WindowsScancode::K};
|
||||
static const Key L {"L", X11Scancode::L, WindowsScancode::L};
|
||||
static const Key Semicolon {";", X11Scancode::SEMICOLON, WindowsScancode::SEMICOLON};
|
||||
static const Key SingeQuote {"\'", X11Scancode::SINGLEQUOTE, WindowsScancode::SINGLEQUOTE};
|
||||
static const Key Return {"↵", X11Scancode::RETURN, WindowsScancode::ENTER};
|
||||
|
||||
static const Key LAlt {'\\', X11Scancode::LEFT_ALT, WindowsScancode::ALT};
|
||||
static const Key RAlt {'\\', X11Scancode::RIGHT_ALT, WindowsScancode::ALT};
|
||||
static const Key LeftShift {"⇧", X11Scancode::LEFT_SHIFT, WindowsScancode::LEFT_SHIFT};
|
||||
static const Key Z {"Z", X11Scancode::Z, WindowsScancode::Z};
|
||||
static const Key X {"X", X11Scancode::X, WindowsScancode::X};
|
||||
static const Key C {"C", X11Scancode::C, WindowsScancode::C};
|
||||
static const Key V {"V", X11Scancode::V, WindowsScancode::V};
|
||||
static const Key B {"B", X11Scancode::B, WindowsScancode::B};
|
||||
static const Key N {"N", X11Scancode::N, WindowsScancode::N};
|
||||
static const Key M {"M", X11Scancode::M, WindowsScancode::M};
|
||||
static const Key Comma = {",", X11Scancode::COMMA, WindowsScancode::COMMA};
|
||||
static const Key Period {".", X11Scancode::PERIOD, WindowsScancode::PERIOD};
|
||||
static const Key ForwardSlash {"/", X11Scancode::SLASH, WindowsScancode::SLASH};
|
||||
|
||||
static const Key LShift {'\\', X11Scancode::LEFT, WindowsScancode::LEFT_ARROW};
|
||||
static const Key RShift {'\\', X11Scancode::RIGHT, WindowsScancode::RIGHT_ARROW};
|
||||
static const Key LeftControl {"LCTRL", X11Scancode::LEFT_CTRL, WindowsScancode::CTRL};
|
||||
static const Key Super {"❖", X11Scancode::SUPER, WindowsScancode::SUPER};
|
||||
static const Key LeftAlt {"🄰", X11Scancode::LEFT_ALT, WindowsScancode::ALT};
|
||||
static const Key Space {" ", X11Scancode::SPACE, WindowsScancode::SPACE};
|
||||
static const Key RightAlt {"R🄰", X11Scancode::RIGHT_ALT, WindowsScancode::ALT};
|
||||
static const Key Menu = {"▤", X11Scancode::MENU, WindowsScancode::MENU};
|
||||
static const Key RightControl {"RCTRL", X11Scancode::RIGHT_CONTROL, WindowsScancode::CTRL};
|
||||
static const Key RightShift {"R⇧", X11Scancode::RIGHT_SHIFT, WindowsScancode::RIGHT_SHIFT};
|
||||
|
||||
// TODO: Get the right character codes for these
|
||||
static const Key UpArrow {'\u000a', X11Scancode::UP, WindowsScancode::UP_ARROW};
|
||||
static const Key DownArrow {'\u000a', X11Scancode::DOWN, WindowsScancode::DOWN_ARROW};
|
||||
static const Key LeftArrow {'\u000a', X11Scancode::LEFT, WindowsScancode::LEFT_ARROW};
|
||||
static const Key RightArrow {'\u000a', X11Scancode::RIGHT, WindowsScancode::RIGHT_ARROW};
|
||||
static const Key Insert {"INSERT", X11Scancode::INSERT, WindowsScancode::INSERT};
|
||||
static const Key Home {"HOME", X11Scancode::HOME, WindowsScancode::HOME};
|
||||
static const Key PageUp {"PAGEUP", X11Scancode::PAGEUP, WindowsScancode::PAGE_UP};
|
||||
static const Key Delete {"DELETE", X11Scancode::DEL, WindowsScancode::DEL};
|
||||
static const Key End {"End", X11Scancode::END, WindowsScancode::END};
|
||||
static const Key PageDown {"PAGEDOWN", X11Scancode::PAGEDOWN, WindowsScancode::PAGE_DOWN};
|
||||
|
||||
static const Key Super {'\000a', X11Scancode::SUPER, WindowsScancode::Nothing};
|
||||
static const Key Backspace {'\b', X11Scancode::BACKSPACE, WindowsScancode::BACKSPACE};
|
||||
static const Key UpArrow {reinterpret_cast<const char*>(u8"↑"), X11Scancode::UP, WindowsScancode::UP_ARROW};
|
||||
static const Key DownArrow {reinterpret_cast<const char*>(u8"↓"), X11Scancode::DOWN, WindowsScancode::DOWN_ARROW};
|
||||
static const Key LeftArrow {reinterpret_cast<const char*>(u8"←"), X11Scancode::LEFT, WindowsScancode::LEFT_ARROW};
|
||||
static const Key RightArrow {reinterpret_cast<const char*>(u8"→"), X11Scancode::RIGHT, WindowsScancode::RIGHT_ARROW};
|
||||
|
||||
static const Key LeftBracket {'[', X11Scancode::OPENING_SQUARE_BRACKET, WindowsScancode::LEFT_BRACKET};
|
||||
static const Key RightBracket {']', X11Scancode::CLOSING_SQUARE_BRACKET, WindowsScancode::RIGHT_BRACKET};
|
||||
}
|
||||
|
||||
class GamepadButton {};
|
||||
class MouseButton {};
|
||||
|
||||
using J3ML::LinearAlgebra::Vector2;
|
||||
|
||||
class InputService {
|
||||
public:
|
||||
static Vector2 GetLeftJoystick();
|
||||
static Vector2 GetRightJoystick();
|
||||
};
|
||||
|
||||
namespace GamepadButtons {
|
||||
static const GamepadButton X;
|
||||
static const GamepadButton Y;
|
||||
static const GamepadButton A;
|
||||
static const GamepadButton B;
|
||||
}
|
||||
|
||||
namespace MouseButtons
|
||||
{
|
||||
static const MouseButton Left;
|
||||
static const MouseButton Right;
|
||||
static const MouseButton Middle;
|
||||
static const MouseButton Side1;
|
||||
static const MouseButton Side2;
|
||||
}
|
||||
|
||||
#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;
|
||||
case Button4: return MouseButtons::Side1;
|
||||
case Button5: return MouseButtons::Side2;
|
||||
default:
|
||||
{
|
||||
throw std::runtime_error("Undefined XButtonCode: " + button);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static Key GetKeyFromX11Scancode(X11Scancode code) {
|
||||
for (auto& key : Key::GetKeyboard()) {
|
||||
if (key.x11ScanCode == code)
|
||||
return key;
|
||||
}
|
||||
std::cout << "Unavaliable Scancode: " + std::to_string((int)code) << std::endl;
|
||||
return Keys::Space;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static Key GetKeyFromWindowsScancode(WindowsScancode code) {
|
||||
for (auto& key : Key::GetKeyboard()) {
|
||||
if (key.winScanCode == code)
|
||||
return key;
|
||||
}
|
||||
std::cout << "Unavaliable Scancode: " + std::to_string((int)code) << std::endl;
|
||||
return Keys::Space;
|
||||
}
|
||||
|
||||
#endif
|
||||
Key GetKeyFromX11Scancode(X11Scancode code);
|
||||
Key GetKeyFromWindowsScancode(WindowsScancode code);
|
22
include/rewindow/types/keyboard.h
Normal file
22
include/rewindow/types/keyboard.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/// ReWindowLibrary
|
||||
/// A C++20 Library for creating and managing windows in a platform-independent manner
|
||||
/// Developed and Maintained by the boys @ Redacted Software.
|
||||
/// (c) 2024 Redacted Software
|
||||
/// This work is dedicated to the public domain.
|
||||
|
||||
/// @file keyboard.h
|
||||
/// @desc A class that models the functionality of a keyboard device.
|
||||
/// @edit 2024-07-29
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
namespace ReWindow
|
||||
{
|
||||
class InputDevice {};
|
||||
|
||||
class Keyboard : public InputDevice
|
||||
{
|
||||
|
||||
};
|
||||
}
|
26
include/rewindow/types/mouse.h
Normal file
26
include/rewindow/types/mouse.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/// ReWindowLibrary
|
||||
/// A C++20 Library for creating and managing windows in a platform-independent manner
|
||||
/// Developed and Maintained by the boys @ Redacted Software.
|
||||
/// (c) 2024 Redacted Software
|
||||
/// This work is dedicated to the public domain.
|
||||
|
||||
/// @file keyboard.h
|
||||
/// @desc A class that models the functionality of a mouse / pointer device.
|
||||
/// @edit 2024-07-29
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
namespace ReWindow
|
||||
{
|
||||
|
||||
class InputDevice {}; // TODO: Remember to break InputDevice into it's own file and not define it twice!!!
|
||||
|
||||
class Pointer : public InputDevice {};
|
||||
|
||||
|
||||
class Mouse : public Pointer
|
||||
{
|
||||
|
||||
};
|
||||
}
|
38
include/rewindow/types/mousebutton.h
Normal file
38
include/rewindow/types/mousebutton.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/// ReWindowLibrary
|
||||
/// A C++20 Library for creating and managing windows in a platform-independent manner
|
||||
/// Developed and Maintained by the boys @ Redacted Software.
|
||||
/// (c) 2024 Redacted Software
|
||||
/// This work is dedicated to the public domain.
|
||||
|
||||
/// @file mousebutton.hpp
|
||||
/// @desc MouseButton class and defined MouseButtons.
|
||||
/// @edit 2024-07-29
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
class MouseButton {
|
||||
public:
|
||||
MouseButton();
|
||||
explicit MouseButton(const char* charcode, unsigned int index);
|
||||
const char* CharCode;
|
||||
unsigned int ButtonIndex;
|
||||
bool operator == (const MouseButton& mb) const;
|
||||
};
|
||||
|
||||
|
||||
namespace MouseButtons
|
||||
{
|
||||
static const MouseButton Left {"l", 1};
|
||||
static const MouseButton Right {"r", 2};
|
||||
static const MouseButton Middle {"m", 3};
|
||||
static const MouseButton MWheelUp {"1", 4};
|
||||
static const MouseButton MWheelDown {"2", 5};
|
||||
static const MouseButton Mouse4 {"4", 8};
|
||||
static const MouseButton Mouse5 {"5", 9};
|
||||
static const MouseButton Unimplemented {"u", 0};
|
||||
}
|
||||
|
||||
MouseButton GetMouseButtonFromXButton(unsigned int button);
|
||||
|
||||
|
@@ -1,27 +1,13 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#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>
|
||||
#endif
|
||||
|
||||
#include <rewindow/types/cursors.h>
|
||||
#include <rewindow/types/mousebutton.h>
|
||||
#include <rewindow/types/gamepadbutton.h>
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
using precision_clock = std::chrono::high_resolution_clock;
|
||||
@@ -36,6 +22,8 @@ enum class RWindowFlags: uint8_t {
|
||||
MAX_FLAG
|
||||
};
|
||||
|
||||
std::string RWindowFlagToStr(RWindowFlags flag);
|
||||
|
||||
enum class RenderingAPI: uint8_t {
|
||||
OPENGL = 0,
|
||||
//Vulkan is unimplemented.
|
||||
@@ -63,8 +51,7 @@ namespace ReWindow
|
||||
};
|
||||
const RWindowEvent EmptyRWindowEvent;
|
||||
|
||||
namespace WindowEvents
|
||||
{
|
||||
namespace WindowEvents {
|
||||
class KeyboardState {
|
||||
public:
|
||||
std::map<Key, bool> PressedKeys;
|
||||
@@ -88,6 +75,7 @@ namespace ReWindow
|
||||
KeyboardEvent(Key key, KeyState state) : RWindowEvent(), key(key), state(state) {}
|
||||
};
|
||||
class MouseEvent : public RWindowEvent {};
|
||||
|
||||
class GamepadEvent : public RWindowEvent {};
|
||||
|
||||
class MouseMoveEvent : public MouseEvent {
|
||||
@@ -114,6 +102,7 @@ namespace ReWindow
|
||||
class MouseButtonDownEvent : public MouseEvent {
|
||||
public:
|
||||
MouseButton Button;
|
||||
MouseButtonDownEvent(MouseButton Button) : MouseEvent() {}
|
||||
};
|
||||
|
||||
class MouseButtonUpEvent : public MouseEvent {
|
||||
@@ -130,12 +119,23 @@ namespace ReWindow
|
||||
|
||||
using namespace WindowEvents;
|
||||
|
||||
|
||||
/// General To Do List
|
||||
/// TODO: Implement accurate timekeeping on refresh. Have mechanism to expose to user (hook into their game engine's timestepping)
|
||||
/// TODO: Clean up public API to express the cross-platform, multi-graphics-mode ethos of this project.
|
||||
///
|
||||
|
||||
class RWindow {
|
||||
public:
|
||||
|
||||
/// We keep and support both mechanisms for extending behavior to suit:
|
||||
/// 1. Derived windows with added functionality.
|
||||
/// 2. Binding functions to a pre-existing window.
|
||||
#pragma region Callbacks
|
||||
/// Bindable Non-intrusive event handlers
|
||||
/// Use these when you can't override the base window class
|
||||
Event<> OnOpenEvent;
|
||||
Event<> OnClosingEvent;
|
||||
Event<RWindowEvent> OnFocusLostEvent;
|
||||
Event<RWindowEvent> OnFocusGainEvent;
|
||||
Event<float> OnRefreshEvent;
|
||||
@@ -146,8 +146,14 @@ namespace ReWindow
|
||||
Event<MouseButtonDownEvent> OnMouseButtonDownEvent;
|
||||
Event<MouseButtonUpEvent> OnMouseButtonUpEvent;
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Overrides
|
||||
/// Intrusive virtual methods intended to be overridden in a derived class.
|
||||
/// Do not stuff any logic into these. Someone WILL override it and forget to call the base.
|
||||
|
||||
/// Called upon the window requesting to open.
|
||||
virtual void OnOpen() {}
|
||||
/// Called right before the window closes.
|
||||
virtual void OnClosing() {}
|
||||
virtual void OnFocusLost(const RWindowEvent& e) {}
|
||||
virtual void OnFocusGain(const RWindowEvent& e) {}
|
||||
virtual void OnRefresh(float elapsed) {}
|
||||
@@ -160,49 +166,44 @@ namespace ReWindow
|
||||
virtual void OnMouseButtonUp(const MouseButtonUpEvent&) {}
|
||||
#pragma endregion
|
||||
|
||||
/// The default constructor sets a default size and window title.
|
||||
RWindow();
|
||||
/// Constructs a window by explicitly setting title, width and height.
|
||||
RWindow(const std::string& title, int width, int height);
|
||||
/// Constructs a window as above with the additional argument of explicitly setting which render API is to be used.
|
||||
RWindow(const std::string& title, int width, int height, RenderingAPI renderer);
|
||||
|
||||
Vector2 GetMouseCoordinates() const {
|
||||
return getCursorPos();
|
||||
}
|
||||
/// Returns a Vector2 representing mouse coordinates relative to the top-left corner of the window.
|
||||
Vector2 GetMouseCoordinates() const;
|
||||
|
||||
void liftKey (Key key) {
|
||||
currentKeyboard.PressedKeys[key] = false;
|
||||
auto event = ReWindow::WindowEvents::KeyUpEvent(key);
|
||||
OnKeyUp(event);
|
||||
}
|
||||
// TODO: Is this part of the API interface? Can it be moved to protected?
|
||||
void liftKey (Key key);
|
||||
|
||||
void pressKey (Key key) {
|
||||
currentKeyboard.PressedKeys[key] = true;
|
||||
auto eventData = KeyDownEvent(key);
|
||||
OnKeyDown(eventData);
|
||||
}
|
||||
#ifndef __linux___
|
||||
//RWindow(HINSTANCE hInst);
|
||||
// TODO: Is this part of the API interface? Can it be moved to protected?
|
||||
void pressKey (Key key);
|
||||
|
||||
void setRect (int nx, int ny, int nw, int nh) {
|
||||
setPos(nx, ny);
|
||||
width = nw;
|
||||
height = nh;
|
||||
}
|
||||
#endif
|
||||
/// Sets which rendering API is to be used with this window.
|
||||
void setRenderer(RenderingAPI api);
|
||||
|
||||
/// Initializes all state with the window manager and rendering API, then opens the window.
|
||||
void Open();
|
||||
|
||||
/// Cleans up and closes the window without destroying the handle.
|
||||
void Close();
|
||||
|
||||
void CloseAndReopenInPlace();
|
||||
|
||||
// TODO: Must be implemented from scratch as a Motif Window in x11
|
||||
void MessageBox();
|
||||
void MessageBox(); // TODO: Must be implemented from scratch as a Motif Window in x11
|
||||
|
||||
/// Returns whether the window currently has mouse and/or keyboard focus.
|
||||
bool isFocused() const;
|
||||
bool isFullscreen() const;
|
||||
bool isResizable() const;
|
||||
bool isVsyncEnabled() const;
|
||||
|
||||
bool isAlive() const;
|
||||
bool isAlive() const; // TODO: Always returns true.
|
||||
|
||||
/// Sets whether the mouse is visible when inside the window.
|
||||
void setMouseVisible(bool visible);
|
||||
void setMouseLocked();
|
||||
void setMouseCenter();
|
||||
@@ -216,29 +217,59 @@ namespace ReWindow
|
||||
void setVsyncEnabled(bool);
|
||||
void setTitle(const std::string& title);
|
||||
std::string getTitle() const;
|
||||
int getWidth() const; // Honestly no idea if we'll keep these or still go with getSize.
|
||||
int getHeight() const; // getSize wasn't working for me for logging. -maxine
|
||||
|
||||
// TODO: Move out of public API, consumers should use setFullscreen()
|
||||
void fullscreen();
|
||||
// TODO: Move out of public API, consumers should use setFullscreen()
|
||||
void restoreFromFullscreen();
|
||||
|
||||
// TODO: Josh hates parameter-flags, it's not 1995 :/
|
||||
bool getFlag(RWindowFlags flag) const;
|
||||
// TODO: Josh hates parameter-flags, it's not 1995 :/
|
||||
void setFlag(RWindowFlags flag, bool state);
|
||||
//void init(RenderingAPI api, const char* title, int width, int height, bool vsync);
|
||||
|
||||
/// Tells the underlying window manager to destroy this window and drop the handle.
|
||||
/// The window, in theory, can not be re-opened after this.
|
||||
/// TODO: Create a destructor and move to there?
|
||||
/// TODO: What's the semantic difference between this and Close()?
|
||||
void destroyWindow();
|
||||
|
||||
/// Reads events from the underlying window manager.
|
||||
/// TODO: Move out of public API, consumers should call refresh or ideally an update() call.
|
||||
void pollEvents();
|
||||
|
||||
/// Updates the window and handles timing internally.
|
||||
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;
|
||||
// I want to know why this is made platform specific. Is that even necessary? -maxine
|
||||
// Because each OS / WM implements it with a different API. - josh
|
||||
// If we stored ourselves a copy (accurately) of the window's size, we could implement it into the shared layer
|
||||
// But this is at BEST, unreliable.
|
||||
Vector2 getSize() const;
|
||||
|
||||
void setPos(int x, int y);
|
||||
void setPos(const Vector2& pos);
|
||||
Vector2 getCursorPos() const;
|
||||
|
||||
/// Pull the window to the top, such that it is displayed on top of everything else.
|
||||
/// NOTE: The implementation is window-manager defined, and thus there is no guarantee of it always working.
|
||||
void raise() const;
|
||||
/// Push the window lower, such that it is effectively hidden behind other windows.
|
||||
/// NOTE: The implementation is window-manager defined, and thus there is no guarantee of it always working.
|
||||
void lower() const;
|
||||
void setCursorStyle(CursorStyle style) const;
|
||||
void setCursorCustomIcon() const;
|
||||
|
||||
/// Calls OpenGL's SwapBuffers routine.
|
||||
/// NOTE: This is only used when the underlying rendering API is set to OpenGL.
|
||||
static void glSwapBuffers();
|
||||
//Initialize to false because it's not guaranteed that they will be cleared first
|
||||
Vector2 getLastKnownResize() const;
|
||||
private:
|
||||
Vector2 lastKnownWindowSize {0, 0};
|
||||
bool flags[5];
|
||||
@@ -247,21 +278,12 @@ namespace ReWindow
|
||||
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 X11ImplementationRWindow: public RWindow {
|
||||
};
|
||||
};
|
||||
}
|
80
main.cpp
80
main.cpp
@@ -1,5 +1,6 @@
|
||||
#include <iostream>
|
||||
#include <rewindow/types/window.h>
|
||||
#include <jlog/jlog.hpp>
|
||||
|
||||
|
||||
Vector2 mouse_pos;
|
||||
@@ -11,31 +12,16 @@ std::ostream& operator<<(std::ostream& os, const Vector2& v) {
|
||||
|
||||
class MyWindow : public ReWindow::RWindow {
|
||||
public:
|
||||
MyWindow(const std::string& title, int w, int h) : ReWindow::RWindow(title, w, h)
|
||||
{}
|
||||
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 ();
|
||||
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
|
||||
}
|
||||
|
||||
bool OnResizeRequest(const ReWindow::WindowResizeRequestEvent& e) override {
|
||||
@@ -44,26 +30,36 @@ class MyWindow : public ReWindow::RWindow {
|
||||
}
|
||||
};
|
||||
|
||||
#if __linux__
|
||||
|
||||
int main() {
|
||||
auto* window = new MyWindow("Test Window", 600, 480);
|
||||
DEBUG(std::format("New window '{}' created. width={} height={}", window->getTitle(), window->getWidth(), window->getHeight()));
|
||||
|
||||
window->setRenderer(RenderingAPI::OPENGL);
|
||||
DEBUG(std::format("Rendering API OPENGL set for window '{}'", window->getTitle()));
|
||||
|
||||
window->Open();
|
||||
DEBUG(std::format("Opened window '{}'", window->getTitle()));
|
||||
|
||||
// TODO: Cannot set flags until after window is open
|
||||
// Make this work somehow
|
||||
DEBUG("TODO: Cannot set flags until after window is open")
|
||||
window->setFullscreen(false);
|
||||
window->setVsyncEnabled(false);
|
||||
window->setResizable(false);
|
||||
window->setResizable(true);
|
||||
DEBUG(std::format("Window '{}' flags: IN_FOCUS={} FULLSCREEN={} RESIZEABLE={} VSYNC={} QUIT={}",
|
||||
window->getTitle(),
|
||||
window->getFlag(RWindowFlags::IN_FOCUS),
|
||||
window->getFlag(RWindowFlags::FULLSCREEN),
|
||||
window->getFlag(RWindowFlags::RESIZABLE),
|
||||
window->getFlag(RWindowFlags::VSYNC),
|
||||
window->getFlag(RWindowFlags::QUIT)));
|
||||
|
||||
window->OnKeyDownEvent += [&] (ReWindow::KeyDownEvent e)
|
||||
{
|
||||
if (e.key == Keys::LeftArrow)
|
||||
{
|
||||
std::cout << "Left Arrow Hit" << std::endl;
|
||||
}
|
||||
window->OnKeyDownEvent += [&] (ReWindow::KeyDownEvent e) {
|
||||
DEBUG(e.key.CharCode);
|
||||
};
|
||||
|
||||
window->OnMouseButtonDownEvent += [&] (ReWindow::MouseButtonDownEvent e) {
|
||||
DEBUG(e.Button.CharCode);
|
||||
};
|
||||
|
||||
while (window->isAlive()) {
|
||||
@@ -72,31 +68,15 @@ int main() {
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
//Windows :(
|
||||
#ifdef _WIN32
|
||||
#ifndef UNICODE
|
||||
#define UNICODE
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
int wmain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine, int nCmdShow) {
|
||||
auto* window = new MyWindow ("Test Window", 600, 480);
|
||||
window->raise ();
|
||||
|
||||
window->OnKeyDownEvent += [&] (ReWindow::KeyDownEvent e) {
|
||||
if (e.key == Keys::LeftArrow) {
|
||||
std::cout << "Left Arrow Hit" << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
while (window->isAlive()) {
|
||||
window->pollEvents();
|
||||
window->refresh();
|
||||
extern "C" {
|
||||
int wmain(int argc, wchar_t* argv[]) {
|
||||
return main();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
1
reci/scripts/builddeps.reci
Normal file
1
reci/scripts/builddeps.reci
Normal file
@@ -0,0 +1 @@
|
||||
Main:new("Install build dependencies", "apt-get install -yq libx11 libx11-dev")
|
@@ -1,16 +1,15 @@
|
||||
#include <iostream>
|
||||
#include <rewindow/types/window.h>
|
||||
#include <rewindow/data/WindowsScancodes.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/cursorfont.h>
|
||||
|
||||
#include <GL/glx.h>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <thread>
|
||||
#include "rewindow/types/cursors.h"
|
||||
#include "../../include/rewindow/types/window.h"
|
||||
#include <rewindow/types/window.h>
|
||||
#include <rewindow/types/cursors.h>
|
||||
#include <J3ML/J3ML.h>
|
||||
#include <jlog/jlog.hpp>
|
||||
|
||||
|
||||
|
||||
// TODO: Move all "global" members to be instantiated class members of Window
|
||||
@@ -26,154 +25,149 @@ XVisualInfo* visual;
|
||||
XSetWindowAttributes xSetWindowAttributes;
|
||||
XWindowAttributes windowAttributes;
|
||||
Atom wmDeleteWindow;
|
||||
// Make it start as floating because fuck tiling WMs
|
||||
Atom windowTypeAtom;
|
||||
Atom windowTypeUtilityAtom;
|
||||
XSizeHints hints;
|
||||
GLXContext glContext;
|
||||
|
||||
namespace ReWindow {
|
||||
using namespace ReWindow;
|
||||
|
||||
RWindow::RWindow() {
|
||||
title = "ReWindow Application";
|
||||
width = 640;
|
||||
height = 480;
|
||||
//RWindow::singleton = this;
|
||||
void RWindow::raise() const {
|
||||
DEBUG(std::format("Raising window '{}'", this->title));
|
||||
XRaiseWindow(display, window);
|
||||
}
|
||||
|
||||
void RWindow::lower() const
|
||||
{
|
||||
DEBUG(std::format("Lowering window '{}'", this->title));
|
||||
XLowerWindow(display, window);
|
||||
}
|
||||
|
||||
void RWindow::destroyWindow() {
|
||||
DEBUG(std::format("Destroying window '{}'", this->title));
|
||||
XDestroySubwindows(display, window);
|
||||
DEBUG(std::format("Destroyed window '{}'", title));
|
||||
XDestroyWindow(display, window);
|
||||
delete this;
|
||||
}
|
||||
|
||||
void 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);
|
||||
}
|
||||
|
||||
void RWindow::setFlag(RWindowFlags flag, bool state) {
|
||||
XGetWindowAttributes(display,window,&windowAttributes);
|
||||
flags[(int) flag] = state;
|
||||
//Once you've done this you cannot make it resizable again.
|
||||
if (flag == RWindowFlags::RESIZABLE && !state) {
|
||||
DEBUG("Once you've done this you cannot make it resizable again.");
|
||||
hints.flags = PMinSize | PMaxSize;
|
||||
hints.min_width = hints.max_width = windowAttributes.width;
|
||||
hints.min_height = hints.max_height = windowAttributes.height;
|
||||
XSetWMNormalHints(display, window, &hints);
|
||||
}
|
||||
DEBUG(std::format("Set flag '{}' to state '{}' for window '{}'", RWindowFlagToStr(flag), state, this->title));
|
||||
}
|
||||
|
||||
RWindow::RWindow(const std::string& title, int width, int height) : flags(false,false,false,false) {
|
||||
this->title = title;
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
void RWindow::pollEvents() {
|
||||
while(XPending(display)) {
|
||||
XNextEvent(display, &xev);
|
||||
|
||||
//RWindow::singleton = this;
|
||||
if (xev.type == ClientMessage)
|
||||
DEBUG(std::format("Recieved event '{}'", "ClientMessage"));
|
||||
if (xev.xclient.message_type == XInternAtom(display, "WM_PROTOCOLS", False) && static_cast<Atom>(xev.xclient.data.l[0]) == wmDeleteWindow) {
|
||||
destroyWindow();
|
||||
system("xset r on");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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); }
|
||||
|
||||
|
||||
|
||||
|
||||
void RWindow::destroyWindow() {
|
||||
XDestroySubwindows(display, window);
|
||||
XAutoRepeatOn(display);
|
||||
XDestroyWindow(display, window);
|
||||
delete this;
|
||||
}
|
||||
|
||||
void 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 RWindow::getFlag(RWindowFlags flag) const
|
||||
{
|
||||
if (flags[(int)flag])
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void RWindow::setFlag(RWindowFlags flag, bool state) {
|
||||
XGetWindowAttributes(display,window,&windowAttributes);
|
||||
flags[(int) flag] = state;
|
||||
//Once you've done this you cannot make it resizable again.
|
||||
if (flag == RWindowFlags::RESIZABLE && !state) {
|
||||
hints.flags = PMinSize | PMaxSize;
|
||||
hints.min_width = hints.max_width = windowAttributes.width;
|
||||
hints.min_height = hints.max_height = windowAttributes.height;
|
||||
XSetWMNormalHints(display, window, &hints);
|
||||
if (xev.type == FocusIn) {
|
||||
DEBUG(std::format("Recieved event '{}'", "FocusIn"));
|
||||
XAutoRepeatOff(display);
|
||||
//focusGained.Invoke();
|
||||
RWindowEvent event {};
|
||||
OnFocusGain(event);
|
||||
OnFocusGainEvent(event);
|
||||
setFlag(RWindowFlags::IN_FOCUS, true);
|
||||
}
|
||||
}
|
||||
|
||||
void RWindow::pollEvents() {
|
||||
while(XPending(display)) {
|
||||
XNextEvent(display, &xev);
|
||||
|
||||
if (xev.type == ClientMessage) {
|
||||
if (xev.xclient.message_type == XInternAtom(display, "WM_PROTOCOLS", False) &&
|
||||
static_cast<Atom>(xev.xclient.data.l[0]) == wmDeleteWindow) {
|
||||
destroyWindow();
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (xev.type == FocusIn) {
|
||||
XAutoRepeatOff(display);
|
||||
//focusGained.Invoke();
|
||||
RWindowEvent event {};
|
||||
OnFocusGain(event);
|
||||
setFlag(RWindowFlags::IN_FOCUS, true);
|
||||
}
|
||||
|
||||
if (xev.type == FocusOut) {
|
||||
if (xev.type == FocusOut) {
|
||||
DEBUG(std::format("Recieved event '{}'", "FocusOut"));
|
||||
XAutoRepeatOn(display);
|
||||
//focusLost.Invoke();
|
||||
RWindowEvent event {};
|
||||
OnFocusLost(event);
|
||||
OnFocusLostEvent(event);
|
||||
setFlag(RWindowFlags::IN_FOCUS, false);
|
||||
}
|
||||
|
||||
if (xev.type == KeyRelease) {
|
||||
DEBUG(std::format("Recieved event '{}'", "KeyRelease"));
|
||||
auto scancode = (X11Scancode) xev.xkey.keycode;
|
||||
auto key = GetKeyFromX11Scancode(scancode);
|
||||
liftKey (key);
|
||||
OnKeyUpEvent(key);
|
||||
OnKeyUpEvent(key);
|
||||
liftKey(key);
|
||||
}
|
||||
|
||||
if (xev.type == KeyPress) {
|
||||
DEBUG(std::format("Recieved event '{}'", "KeyPress"));
|
||||
auto scancode = (X11Scancode) xev.xkey.keycode;
|
||||
auto key = GetKeyFromX11Scancode(scancode);
|
||||
pressKey (key);
|
||||
OnKeyDownEvent(key);
|
||||
OnKeyDown(key);
|
||||
pressKey(key);
|
||||
//eventLog.push_back(eventData);
|
||||
}
|
||||
|
||||
if (xev.type == ButtonRelease) {
|
||||
DEBUG(std::format("Recieved event '{}'", "ButtonRelease"));
|
||||
MouseButton button = GetMouseButtonFromXButton(xev.xbutton.button);
|
||||
auto eventData = MouseButtonUpEvent();
|
||||
eventData.Button = button;
|
||||
|
||||
OnMouseButtonUpEvent(eventData);
|
||||
OnMouseButtonUp(eventData);
|
||||
}
|
||||
|
||||
if (xev.type == ButtonPress)
|
||||
{
|
||||
if (xev.type == ButtonPress) {
|
||||
DEBUG(std::format("Recieved event '{}'", "ButtonPress"));
|
||||
MouseButton button = GetMouseButtonFromXButton(xev.xbutton.button);
|
||||
auto eventData = MouseButtonDownEvent();
|
||||
auto eventData = MouseButtonDownEvent(button);
|
||||
eventData.Button = button;
|
||||
|
||||
OnMouseButtonDownEvent(eventData);
|
||||
OnMouseButtonDown(eventData);
|
||||
}
|
||||
|
||||
if (xev.type == Expose) {
|
||||
if (xev.type == Expose)
|
||||
{
|
||||
DEBUG(std::format("Recieved event '{}'", "Expose"));
|
||||
}
|
||||
|
||||
// NOTE: This event is functionally useless, as it only informs of the very beginning and end of a mouse movement.
|
||||
if (xev.type == MotionNotify)
|
||||
{
|
||||
//auto eventData = MouseMoveEvent(xev.xmotion.x, xev.xmotion.y);
|
||||
|
||||
//OnMouseMove(eventData);
|
||||
DEBUG("NOTE: This event is functionally useless, as it only informs of the very beginning and end of a mouse movement.");
|
||||
DEBUG(std::format("Recieved event '{}'", "MotionNotify"));
|
||||
}
|
||||
|
||||
if (xev.type == ResizeRequest)
|
||||
{
|
||||
if (xev.type == ResizeRequest) {
|
||||
DEBUG(std::format("Recieved event '{}'", "ResizeRequest"));
|
||||
auto eventData = WindowResizeRequestEvent();
|
||||
lastKnownWindowSize = eventData.Size;
|
||||
eventData.Size = {(float)xev.xresizerequest.width, (float)xev.xresizerequest.height};
|
||||
lastKnownWindowSize = eventData.Size;
|
||||
OnResizeRequest(eventData);
|
||||
OnResizeRequestEvent(eventData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,20 +175,14 @@ namespace ReWindow {
|
||||
}
|
||||
|
||||
// Might make the window go off the screen on some window managers.
|
||||
void RWindow::setSize(int newWidth, int newHeight)
|
||||
{
|
||||
if (!getFlag(RWindowFlags::RESIZABLE))
|
||||
return;
|
||||
void RWindow::setSize(int newWidth, int newHeight) {
|
||||
if (!getFlag(RWindowFlags::RESIZABLE)) return;
|
||||
|
||||
this->width = newWidth;
|
||||
this->height = newHeight;
|
||||
XResizeWindow(display, window, width, height);
|
||||
}
|
||||
|
||||
void RWindow::setSize(const Vector2& size)
|
||||
{
|
||||
this->width = size.x;
|
||||
this->height = size.y;
|
||||
this->setSize(size.x, size.y);
|
||||
DEBUG("Might make the window go off the screen on some window managers.");
|
||||
DEBUG(std::format("Set size for window '{}'. width={} height={}", this->title, newWidth, newHeight));
|
||||
}
|
||||
|
||||
Vector2 RWindow::getCursorPos() const {
|
||||
@@ -209,8 +197,7 @@ namespace ReWindow {
|
||||
unsigned m;
|
||||
bool mouseAvailable = XQueryPointer(display, window, &root_return, &child_return, &root_x_ret, &root_y_ret, &win_x_ret, &win_y_ret, &mask_return);
|
||||
|
||||
if (mouseAvailable)
|
||||
{
|
||||
if (mouseAvailable) {
|
||||
// TODO: process retrieved mouse coordinates
|
||||
// TODO: normalize coordinates from displaySpace to windowSpace
|
||||
// TODO: fire mouse movement event
|
||||
@@ -226,28 +213,27 @@ namespace ReWindow {
|
||||
}
|
||||
|
||||
// TODO: implement integer vector2/3 types
|
||||
Vector2 RWindow::getSize() const
|
||||
{
|
||||
Vector2 RWindow::getSize() const {
|
||||
XGetWindowAttributes(display,window,&windowAttributes);
|
||||
return {(float)windowAttributes.width, (float)windowAttributes.height};
|
||||
}
|
||||
|
||||
// TODO: implement integer vector2/3 types
|
||||
Vector2 RWindow::getPos() const
|
||||
Vector2 RWindow::getLastKnownResize() const
|
||||
{
|
||||
return lastKnownWindowSize;
|
||||
}
|
||||
|
||||
// TODO: implement integer vector2/3 types
|
||||
Vector2 RWindow::getPos() const {
|
||||
XGetWindowAttributes(display,window,&windowAttributes);
|
||||
|
||||
return {(float)windowAttributes.x, (float)windowAttributes.y};
|
||||
}
|
||||
|
||||
void RWindow::setPos(int x, int y)
|
||||
{
|
||||
void RWindow::setPos(int x, int y) {
|
||||
XMoveWindow(display, window, x, y);
|
||||
}
|
||||
|
||||
void RWindow::setPos(const Vector2& pos)
|
||||
{
|
||||
void RWindow::setPos(const Vector2& pos) {
|
||||
this->setPos(pos.x, pos.y);
|
||||
}
|
||||
|
||||
@@ -260,33 +246,15 @@ namespace ReWindow {
|
||||
return this->getFlag(RWindowFlags::RESIZABLE);
|
||||
}
|
||||
|
||||
bool RWindow::isAlive() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void RWindow::setResizable(bool resizable) {
|
||||
this->resizable = resizable;
|
||||
this->setFlag(RWindowFlags::RESIZABLE, resizable);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RWindow::setFullscreen(bool fs) {
|
||||
if (fs)
|
||||
fullscreen();
|
||||
else
|
||||
restoreFromFullscreen();
|
||||
}
|
||||
|
||||
void RWindow::fullscreen() {
|
||||
DEBUG(std::format("Fullscreening window '{}'", this->title));
|
||||
fullscreenmode = true;
|
||||
|
||||
XEvent xev;
|
||||
Atom wm_state = XInternAtom (display, "_NET_WM_STATE", true );
|
||||
Atom wm_fullscreen = XInternAtom (display, "_NET_WM_STATE_FULLSCREEN", true );
|
||||
Atom wm_state = XInternAtom(display, "_NET_WM_STATE", true);
|
||||
Atom wm_fullscreen = XInternAtom(display, "_NET_WM_STATE_FULLSCREEN", true);
|
||||
|
||||
XChangeProperty(display, window, wm_state, XA_ATOM, 32,
|
||||
PropModeReplace, (unsigned char *)&wm_fullscreen, 1);
|
||||
XChangeProperty(display, window, wm_state, XA_ATOM, 32, PropModeReplace, (unsigned char *)&wm_fullscreen, 1);
|
||||
memset(&xev, 0, sizeof(xev));
|
||||
xev.type = ClientMessage;
|
||||
xev.xclient.window = window;
|
||||
@@ -295,11 +263,12 @@ namespace ReWindow {
|
||||
xev.xclient.data.l[0] = 1; // _NET_WM_STATE_ADD
|
||||
xev.xclient.data.l[1] = fullscreenmode;
|
||||
xev.xclient.data.l[2] = 0;
|
||||
XSendEvent(display, DefaultRootWindow(display), False,
|
||||
SubstructureNotifyMask | SubstructureRedirectMask, &xev);
|
||||
XSendEvent(display, DefaultRootWindow(display), False, SubstructureNotifyMask | SubstructureRedirectMask, &xev);
|
||||
DEBUG(std::format("Fullscreened window '{}'", this->title));
|
||||
}
|
||||
|
||||
void RWindow::restoreFromFullscreen() {
|
||||
DEBUG(std::format("Restoring window '{}' from fullscreen", this->title));
|
||||
fullscreenmode = false;
|
||||
XEvent xev;
|
||||
Atom wm_state = XInternAtom(display, "_NET_WM_STATE", False);
|
||||
@@ -312,8 +281,8 @@ namespace ReWindow {
|
||||
xev.xclient.data.l[0] = 0; // _NET_WM_STATE_REMOVE
|
||||
xev.xclient.data.l[1] = fullscreenmode;
|
||||
xev.xclient.data.l[2] = 0;
|
||||
XSendEvent(display, DefaultRootWindow(display), False,
|
||||
SubstructureNotifyMask | SubstructureRedirectMask, &xev);
|
||||
XSendEvent(display, DefaultRootWindow(display), False, SubstructureNotifyMask | SubstructureRedirectMask, &xev);
|
||||
DEBUG(std::format("Restored window '{}' from fullscreen", this->title));
|
||||
}
|
||||
|
||||
void RWindow::setVsyncEnabled(bool b) {
|
||||
@@ -338,19 +307,23 @@ namespace ReWindow {
|
||||
xSetWindowAttributes.override_redirect = True;
|
||||
xSetWindowAttributes.event_mask = ExposureMask;
|
||||
//setVsyncEnabled(vsync);
|
||||
if (renderer == RenderingAPI::OPENGL)
|
||||
{
|
||||
if (renderer == RenderingAPI::OPENGL) {
|
||||
GLint glAttributes[] = {GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None};
|
||||
visual = glXChooseVisual(display, defaultScreen, glAttributes);
|
||||
glContext = glXCreateContext(display, visual, nullptr, GL_TRUE);
|
||||
}
|
||||
|
||||
xSetWindowAttributes.colormap = XCreateColormap(display, RootWindow(display, defaultScreen), visual->visual,
|
||||
AllocNone);
|
||||
xSetWindowAttributes.colormap = XCreateColormap(display, RootWindow(display, defaultScreen), visual->visual, AllocNone);
|
||||
|
||||
window = XCreateWindow(display, RootWindow(display, defaultScreen), 0, 0, width, height, 0, visual->depth,
|
||||
InputOutput, visual->visual, CWBackPixel | CWColormap | CWBorderPixel | NoEventMask,
|
||||
&xSetWindowAttributes);
|
||||
// Set window to floating because fucking tiling WMs
|
||||
windowTypeAtom = XInternAtom(display, "_NET_WM_WINDOW_TYPE", False);
|
||||
windowTypeUtilityAtom = XInternAtom(display, "_NET_WM_WINDOW_TYPE_UTILITY", False);
|
||||
XChangeProperty(display, window, windowTypeAtom, XA_ATOM, 32, PropModeReplace,
|
||||
(unsigned char *)&windowTypeUtilityAtom, 1);
|
||||
//
|
||||
XSelectInput(display, window,
|
||||
ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
|
||||
PointerMotionMask |
|
||||
@@ -360,14 +333,9 @@ namespace ReWindow {
|
||||
XStoreName(display, window, title.c_str());
|
||||
wmDeleteWindow = XInternAtom(display, "WM_DELETE_WINDOW", False);
|
||||
XSetWMProtocols(display, window, &wmDeleteWindow, 1);
|
||||
|
||||
if (renderer == RenderingAPI::OPENGL)
|
||||
{
|
||||
glXMakeCurrent(display, window, glContext);
|
||||
}
|
||||
|
||||
//setVsyncEnabled(vsync);
|
||||
|
||||
|
||||
open = true;
|
||||
}
|
||||
|
||||
@@ -376,27 +344,13 @@ namespace ReWindow {
|
||||
XStoreName(display, window, title.c_str());
|
||||
}
|
||||
|
||||
std::string RWindow::getTitle() const {
|
||||
return this->title;
|
||||
}
|
||||
|
||||
bool RWindow::isKeyDown(Key key) const {
|
||||
if (!currentKeyboard.PressedKeys.contains(key))
|
||||
return false;
|
||||
return currentKeyboard.PressedKeys.at(key);
|
||||
}
|
||||
|
||||
// TODO: Implement MouseButton map
|
||||
bool RWindow::isMouseButtonDown(MouseButton button) const
|
||||
{
|
||||
bool RWindow::isMouseButtonDown(MouseButton button) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RWindow::setRenderer(RenderingAPI api) {
|
||||
renderer = api;
|
||||
}
|
||||
|
||||
// TODO: Implement ControllerButton map
|
||||
}
|
||||
// TODO: Implement ControllerButton map
|
||||
|
114
src/platform/shared/window.cpp
Normal file
114
src/platform/shared/window.cpp
Normal file
@@ -0,0 +1,114 @@
|
||||
#include <rewindow/types/window.h>
|
||||
#include <jlog/jlog.hpp>
|
||||
std::string RWindowFlagToStr(RWindowFlags flag) {
|
||||
switch (flag) {
|
||||
case RWindowFlags::IN_FOCUS: return "IN_FOCUS";
|
||||
case RWindowFlags::FULLSCREEN: return "FULLSCREEN";
|
||||
case RWindowFlags::RESIZABLE: return "RESIZEABLE";
|
||||
case RWindowFlags::VSYNC: return "VSYNC";
|
||||
case RWindowFlags::QUIT: return "QUIT";
|
||||
case RWindowFlags::MAX_FLAG: return "MAX_FLAG";
|
||||
default:
|
||||
FATAL("")
|
||||
return "unimplemented flag";
|
||||
}
|
||||
};
|
||||
|
||||
using 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) {}
|
||||
|
||||
Vector2 RWindow::GetMouseCoordinates() const {
|
||||
return getCursorPos();
|
||||
}
|
||||
|
||||
bool RWindow::getFlag(RWindowFlags flag) const {return flags[(int)flag];}
|
||||
|
||||
bool RWindow::isAlive() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void RWindow::setResizable(bool resizable) {
|
||||
this->resizable = resizable;
|
||||
this->setFlag(RWindowFlags::RESIZABLE, resizable);
|
||||
}
|
||||
|
||||
void RWindow::setFullscreen(bool fs) {
|
||||
if (fs)
|
||||
fullscreen();
|
||||
else
|
||||
restoreFromFullscreen();
|
||||
}
|
||||
|
||||
void RWindow::liftKey(Key key) {
|
||||
currentKeyboard.PressedKeys[key] = false;
|
||||
auto event = ReWindow::WindowEvents::KeyUpEvent(key);
|
||||
OnKeyUp(event);
|
||||
}
|
||||
|
||||
|
||||
std::string RWindow::getTitle() const {
|
||||
return this->title;
|
||||
}
|
||||
|
||||
/*
|
||||
Vector2 RWindow::getSize() const
|
||||
{
|
||||
return {this->width, this->height};
|
||||
}
|
||||
*/
|
||||
|
||||
int RWindow::getWidth() const
|
||||
{
|
||||
return this->width;
|
||||
}
|
||||
|
||||
int RWindow::getHeight() const
|
||||
{
|
||||
return this->height;
|
||||
}
|
||||
|
||||
|
||||
void RWindow::setRenderer(RenderingAPI api) {
|
||||
renderer = api;
|
||||
}
|
||||
|
||||
void RWindow::setSize(const Vector2& size) {
|
||||
this->width = size.x;
|
||||
this->height = size.y;
|
||||
this->setSize(size.x, size.y);
|
||||
}
|
||||
|
||||
bool RWindow::isKeyDown(Key key) const {
|
||||
for (const auto& pair : currentKeyboard.PressedKeys)
|
||||
if (pair.first == key && pair.second)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void RWindow::pressKey(Key key) {
|
||||
currentKeyboard.PressedKeys[key] = true;
|
||||
auto eventData = KeyDownEvent(key);
|
||||
OnKeyDown(eventData);
|
||||
}
|
||||
|
||||
|
||||
void RWindow::Close()
|
||||
{
|
||||
|
||||
}
|
200
src/platform/windows/window.cpp
Normal file
200
src/platform/windows/window.cpp
Normal file
@@ -0,0 +1,200 @@
|
||||
#include <Windows.h>
|
||||
#include <gl/GL.h>
|
||||
#include <rewindow/types/window.h>
|
||||
|
||||
using namespace ReWindow;
|
||||
|
||||
bool fullscreenmode = false;
|
||||
bool open = false;
|
||||
HINSTANCE hInstance = GetModuleHandle(NULL);
|
||||
HWND hwnd;
|
||||
HDC hdc;
|
||||
HGLRC glContext;
|
||||
|
||||
void raise() { SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); }
|
||||
void lower() { SetWindowPos(hwnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); }
|
||||
|
||||
void RWindow::setFlag(RWindowFlags flag, bool state) {
|
||||
flags[(int) flag] = state;
|
||||
if (flag == RWindowFlags::RESIZABLE && !state) {
|
||||
RECT rect;
|
||||
GetWindowRect(hwnd, &rect);
|
||||
LONG style = GetWindowLong(hwnd, GWL_STYLE);
|
||||
style &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX);
|
||||
SetWindowLong(hwnd, GWL_STYLE, style);
|
||||
SetWindowPos(hwnd, nullptr, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOOWNERZORDER);
|
||||
}
|
||||
}
|
||||
|
||||
void RWindow::pollEvents() {
|
||||
MSG msg;
|
||||
while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
}
|
||||
|
||||
void RWindow::setSize(int newWidth, int newHeight) {
|
||||
if (!getFlag(RWindowFlags::RESIZABLE)) return;
|
||||
this->width = newWidth;
|
||||
this->height = newHeight;
|
||||
SetWindowPos(hwnd, nullptr, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER);
|
||||
}
|
||||
|
||||
Vector2 RWindow::getCursorPos() const {
|
||||
POINT point;
|
||||
GetCursorPos(&point);
|
||||
ScreenToClient(hwnd, &point);
|
||||
return { (float)point.x, (float)point.y };
|
||||
}
|
||||
|
||||
Vector2 RWindow::getSize() const {
|
||||
RECT rect;
|
||||
GetClientRect(hwnd, &rect);
|
||||
return { (float)(rect.right - rect.left), (float)(rect.bottom - rect.top) };
|
||||
}
|
||||
|
||||
void RWindow::setPos(int x, int y) {
|
||||
SetWindowPos(hwnd, nullptr, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
|
||||
}
|
||||
|
||||
void RWindow::setPos(const Vector2& pos) {
|
||||
setPos(pos.x, pos.y);
|
||||
}
|
||||
|
||||
void RWindow::fullscreen() {
|
||||
// Implement fullscreen
|
||||
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_OVERLAPPEDWINDOW);
|
||||
SetWindowPos(hwnd, HWND_TOP, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), SWP_FRAMECHANGED | SWP_NOOWNERZORDER);
|
||||
}
|
||||
|
||||
void RWindow::restoreFromFullscreen() {
|
||||
// Implement restore from fullscreen
|
||||
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) | WS_OVERLAPPEDWINDOW);
|
||||
SetWindowPos(hwnd, nullptr, 0, 0, width, height, SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOOWNERZORDER);
|
||||
}
|
||||
|
||||
void RWindow::setVsyncEnabled(bool b) {
|
||||
typedef BOOL(WINAPI* PFNWGLSWAPINTERVALEXTPROC)(int interval);
|
||||
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = nullptr;
|
||||
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC) wglGetProcAddress("wglSwapIntervalEXT");
|
||||
|
||||
if (wglSwapIntervalEXT)
|
||||
wglSwapIntervalEXT(b ? 1 : 0);
|
||||
}
|
||||
|
||||
bool RWindow::isFullscreen() const {
|
||||
return fullscreenmode;
|
||||
}
|
||||
|
||||
RWindow* eWindow = nullptr;
|
||||
KeyboardState* pKeyboard = nullptr;
|
||||
KeyboardState* cKeyboard = nullptr;
|
||||
//Event loop.
|
||||
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
||||
switch (uMsg) {
|
||||
case WM_CLOSE:
|
||||
DestroyWindow(hwnd);
|
||||
case WM_DESTROY:
|
||||
exit(0);
|
||||
case WM_SIZE:
|
||||
break;
|
||||
case WM_KEYDOWN: {
|
||||
auto key = GetKeyFromWindowsScancode((WindowsScancode) wParam);
|
||||
//Key repeat fix.
|
||||
if (!pKeyboard->PressedKeys[key]) {
|
||||
eWindow->OnKeyDownEvent(key);
|
||||
eWindow->OnKeyDown(key);
|
||||
eWindow->pressKey(key);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WM_KEYUP: {
|
||||
auto key = GetKeyFromWindowsScancode((WindowsScancode) wParam);
|
||||
eWindow->OnKeyUpEvent(key);
|
||||
eWindow->OnKeyUp(key);
|
||||
eWindow->liftKey(key);
|
||||
break;
|
||||
}
|
||||
case WM_LBUTTONDOWN:
|
||||
break;
|
||||
case WM_LBUTTONUP:
|
||||
break;
|
||||
case WM_MOUSEMOVE:
|
||||
break;
|
||||
}
|
||||
if (pKeyboard != nullptr && cKeyboard != nullptr)
|
||||
pKeyboard = cKeyboard;
|
||||
|
||||
return DefWindowProc(hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
void RWindow::setCursorStyle(CursorStyle style) const {}
|
||||
|
||||
void RWindow::Open() {
|
||||
eWindow = this;
|
||||
pKeyboard = &previousKeyboard;
|
||||
cKeyboard = ¤tKeyboard;
|
||||
WNDCLASS wc = { };
|
||||
wc.lpfnWndProc = WindowProc;
|
||||
wc.hInstance = hInstance;
|
||||
wc.lpszClassName = "RWindowClass";
|
||||
RegisterClass(&wc);
|
||||
hwnd = CreateWindowEx(
|
||||
0,
|
||||
"RWindowClass",
|
||||
title.c_str(),
|
||||
WS_OVERLAPPEDWINDOW,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT, width, height,
|
||||
nullptr,
|
||||
nullptr,
|
||||
hInstance,
|
||||
nullptr
|
||||
);
|
||||
|
||||
if (renderer == RenderingAPI::OPENGL) {
|
||||
PIXELFORMATDESCRIPTOR pfd = {
|
||||
sizeof(PIXELFORMATDESCRIPTOR),
|
||||
1,
|
||||
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
|
||||
PFD_TYPE_RGBA,
|
||||
24,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0, 0, 0, 0,
|
||||
24,
|
||||
8,
|
||||
0,
|
||||
PFD_MAIN_PLANE,
|
||||
0,
|
||||
0, 0, 0
|
||||
};
|
||||
|
||||
hdc = GetDC(hwnd);
|
||||
int pixelFormat = ChoosePixelFormat(hdc, &pfd);
|
||||
SetPixelFormat(hdc, pixelFormat, &pfd);
|
||||
|
||||
glContext = wglCreateContext(hdc);
|
||||
wglMakeCurrent(hdc, glContext);
|
||||
}
|
||||
ShowWindow(hwnd, SW_SHOW);
|
||||
open = true;
|
||||
}
|
||||
|
||||
void RWindow::glSwapBuffers() {
|
||||
SwapBuffers(hdc);
|
||||
}
|
||||
|
||||
void 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);
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
#include <rewindow/types/key.h>
|
||||
|
||||
std::vector<Key> Key::keyboard = {};
|
||||
|
||||
std::vector<Key> Key::GetKeyboard() { return keyboard; }
|
||||
|
||||
Key::Key() {
|
||||
|
||||
keyboard.push_back(*this);
|
||||
}
|
||||
|
||||
Key::Key(char charcode, X11Scancode scancode, WindowsScancode sc)
|
||||
: CharCode(charcode), x11ScanCode(scancode), winScanCode(sc)
|
||||
{
|
||||
keyboard.push_back(*this);
|
||||
}
|
||||
|
||||
bool Key::operator==(const Key &rhs) const {
|
||||
return (this->CharCode == rhs.CharCode);
|
||||
}
|
||||
|
||||
bool Key::operator<(const Key &rhs) const {
|
||||
return (this->CharCode < rhs.CharCode);
|
||||
}
|
9
src/types/gamepadbutton.cpp
Normal file
9
src/types/gamepadbutton.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include <rewindow/types/gamepadbutton.h>
|
||||
|
||||
bool GamepadButton::operator==(const GamepadButton &rhs) const {
|
||||
return this->GetMnemonicButtonCode() == rhs.GetMnemonicButtonCode();
|
||||
}
|
||||
|
||||
void GamepadThumbstick::SetDeadzone(float minimum) const {
|
||||
|
||||
}
|
46
src/types/key.cpp
Normal file
46
src/types/key.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include <rewindow/types/key.h>
|
||||
#include <jlog/jlog.hpp>
|
||||
//std::vector<Key> Key::keyboard = {};
|
||||
|
||||
std::vector<Key> Key::GetKeyboard() { return keyboard; }
|
||||
|
||||
Key::Key() {
|
||||
keyboard.push_back(*this);
|
||||
}
|
||||
|
||||
Key::Key(const char* charcode, X11Scancode scancode, WindowsScancode sc)
|
||||
: CharCode(charcode), x11ScanCode(scancode), winScanCode(sc)
|
||||
{
|
||||
//TODO doing this is what crashes the program.
|
||||
keyboard.push_back(*this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Key::operator==(const Key &rhs) const {
|
||||
//This is not a good workaround.
|
||||
return (this->x11ScanCode == rhs.x11ScanCode);
|
||||
}
|
||||
|
||||
bool Key::operator<(const Key &rhs) const {
|
||||
return (this->CharCode < rhs.CharCode);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Key GetKeyFromX11Scancode(X11Scancode code) {
|
||||
for (auto& key : Key::GetKeyboard())
|
||||
if (key.x11ScanCode == code)
|
||||
return key;
|
||||
std::cout << "Unavaliable Scancode: " + std::to_string((int)code) << std::endl;
|
||||
return Keys::Space;
|
||||
}
|
||||
|
||||
Key GetKeyFromWindowsScancode(WindowsScancode code) {
|
||||
for (const auto& key : Key::GetKeyboard())
|
||||
if (key.winScanCode == code)
|
||||
return key;
|
||||
|
||||
std::cout << "Unavaliable Scancode: " + std::to_string((int) code) << std::endl;
|
||||
return Keys::Space;
|
||||
}
|
33
src/types/mousebutton.cpp
Normal file
33
src/types/mousebutton.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <rewindow/types/mousebutton.h>
|
||||
#include <string>
|
||||
#include <jlog/jlog.hpp>
|
||||
|
||||
MouseButton::MouseButton() {
|
||||
}
|
||||
|
||||
MouseButton::MouseButton(const char* charcode, unsigned int index) {
|
||||
this->CharCode = charcode;
|
||||
this->ButtonIndex = index;
|
||||
}
|
||||
|
||||
bool MouseButton::operator==(const MouseButton &mb) const {
|
||||
return (mb.CharCode == this->CharCode);
|
||||
}
|
||||
|
||||
|
||||
MouseButton GetMouseButtonFromXButton(unsigned int button) {
|
||||
switch(button) {
|
||||
case 1: return MouseButtons::Left;
|
||||
case 2: return MouseButtons::Middle;
|
||||
case 3: return MouseButtons::Right;
|
||||
case 4: return MouseButtons::MWheelUp;
|
||||
case 5: return MouseButtons::MWheelDown;
|
||||
//For *whatever* reason. These aren't in X.h
|
||||
case 8: return MouseButtons::Mouse4;
|
||||
case 9: return MouseButtons::Mouse5;
|
||||
default: {
|
||||
FATAL("Undefined XButtonCode: " + std::to_string((int) button));
|
||||
return MouseButtons::Unimplemented;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,389 +0,0 @@
|
||||
#include <rewindow/types/window.h>
|
||||
#include <rewindow/types/cursors.h>
|
||||
#include <GL/gl.h>
|
||||
|
||||
typedef BOOL (APIENTRY* PFNWGLSWAPINTERVALEXTPROC)(int interval);
|
||||
|
||||
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;
|
||||
|
||||
case WM_SETFOCUS: {
|
||||
ReWindow::RWindowEvent event {};
|
||||
subject->OnFocusGain (event);
|
||||
subject->setFlag (RWindowFlags::IN_FOCUS, true);
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_KILLFOCUS: {
|
||||
ReWindow::RWindowEvent event {};
|
||||
subject->OnFocusLost (event);
|
||||
subject->setFlag (RWindowFlags::IN_FOCUS, false);
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_KEYDOWN: {
|
||||
auto key = GetKeyFromWindowsScancode ((WindowsScancode) wParam);
|
||||
subject->pressKey (key);
|
||||
break;
|
||||
}
|
||||
|
||||
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 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);
|
||||
}
|
||||
}
|
||||
|
||||
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