Merge branch 'windows-test'

This commit is contained in:
2024-06-18 01:20:13 -04:00
10 changed files with 456 additions and 723 deletions

View File

@@ -18,7 +18,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
CPMAddPackage(
NAME J3ML
URL https://git.redacted.cc/josh/j3ml/archive/Release-7.zip
URL https://git.redacted.cc/josh/j3ml/archive/Release-2.1.zip
)
CPMAddPackage(
@@ -28,7 +28,7 @@ CPMAddPackage(
CPMAddPackage(
NAME jlog
URL https://git.redacted.cc/josh/jlog/archive/Prerelease-3.zip
URL https://git.redacted.cc/josh/jlog/archive/Prerelease-6.zip
)
find_package(OpenGL REQUIRED)
@@ -40,11 +40,11 @@ include_directories(${jlog_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")
file(GLOB_RECURSE SOURCES "src/rewindow/*.cpp" "src/platform/linux/*.cpp" "src/platform/shared/*.cpp")
endif()
if(WIN32)
file(GLOB_RECURSE SOURCES "src/rewindow/*.cpp" "src/windows/*.cpp")
file(GLOB_RECURSE SOURCES "src/rewindow/*.cpp" "src/platform/windows/*.cpp" "src/platform/shared/*.cpp")
endif()
include_directories("include")
@@ -63,29 +63,16 @@ target_include_directories(ReWindowLibrary PUBLIC ${Event_SOURCE_DIR}/include)
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)
target_link_libraries(ReWindowLibrary PUBLIC jlog)
target_link_libraries(ReWindowLibrary PUBLIC X11 J3ML Event jlog ${OPENGL_LIBRARIES})
target_link_libraries(ReWindowLibrary PUBLIC)
add_executable(ReWindowLibraryDemo main.cpp)
#target_include_directories(ReWindowLibraryDemo PRIVATE ${JGL_SOURCE_DIR}/include)
target_link_libraries(ReWindowLibraryDemo PUBLIC ReWindowLibrary jlog)
#target_link_libraries(ReWindowLibraryDemo PRIVATE JGL)
target_link_libraries(ReWindowLibraryDemo PUBLIC ReWindowLibrary)
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)
target_link_libraries(ReWindowLibrary PUBLIC jlog)
target_link_libraries(ReWindowLibrary PUBLIC J3ML Event jlog ${OPENGL_LIBRARIES})
add_executable(ReWindowLibraryDemo main.cpp)
#target_compile_options(ReWindowLibraryDemo PRIVATE)
target_link_libraries(ReWindowLibraryDemo PUBLIC ReWindowLibrary jlog)
target_link_libraries(ReWindowLibraryDemo PUBLIC ReWindowLibrary)
endif()

View File

@@ -1,95 +1,102 @@
#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
Nothing = 0,
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 = 0xA0, // 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'
COMMA = 0xBC, // VK_OEM_COMMA
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
DELETE = 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_DECIMAL = 0x6E, // VK_DECIMAL
NUMPAD_ENTER = 0x0D // VK_RETURN
};

View File

@@ -4,25 +4,25 @@
#include <vector>
#include <J3ML/LinearAlgebra/Vector2.h>
#include <jlog/jlog.hpp>
#include <stdexcept>
#include <iostream>
#if __linux__
#include <X11/X.h>
#endif
#include "rewindow/data/X11Scancodes.h"
#include "rewindow/data/WindowsScancodes.h"
//#include "jlog/jlog.hpp"
#include <string>
#include <rewindow/data/X11Scancodes.h>
#include <rewindow/data/WindowsScancodes.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();
@@ -33,7 +33,6 @@ public:
bool operator==(const Key& rhs) const;
bool operator<(const Key& rhs) const;
Key(const Key&) = default;
};
namespace Keys {
@@ -55,13 +54,13 @@ namespace Keys {
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};
static const Key NumPad4 {"\b", X11Scancode::KP_4, WindowsScancode::NUMPAD_FOUR};
static const Key NumPad5 {"\b", X11Scancode::KP_5, WindowsScancode::NUMPAD_FIVE};
static const Key NumPad6 {"\b", X11Scancode::KP_6, WindowsScancode::NUMPAD_SIX};
static const Key NumPad7 {"\b", X11Scancode::KP_7, WindowsScancode::NUMPAD_SEVEN};
static const Key NumPad8 {"\b", X11Scancode::KP_8, WindowsScancode::NUMPAD_EIGHT};
static const Key NumPad9 {"\b", X11Scancode::KP_9, WindowsScancode::NUMPAD_NINE};
static const Key NumPad0 {"\b", X11Scancode::KP_0, WindowsScancode::NUMPAD_ZERO};
static const Key One {"1", X11Scancode::ONE, WindowsScancode::ONE};
static const Key Two {"2", X11Scancode::TWO, WindowsScancode::TWO};
@@ -94,7 +93,7 @@ namespace Keys {
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 SingeQuote {"\"", X11Scancode::SINGLEQUOTE, WindowsScancode::SINGLEQUOTE};
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};
@@ -163,24 +162,27 @@ namespace MouseButtons
static const MouseButton Left {"l"};
static const MouseButton Right {"r"};
static const MouseButton Middle {"m"};
static const MouseButton Side1 {"1"};
static const MouseButton Side2 {"2"};
static const MouseButton MWheelUp {"1"};
static const MouseButton MWheelDown {"2"};
static const MouseButton Mouse4 {"4"};
static const MouseButton Mouse5 {"5"};
static const MouseButton Unimplemented {"u"};
}
#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);
//FATAL("Undefined XButtonCode:" + button);
std::cout << "Undefined XButtonCode:" + button << std::endl;
case Button2: return MouseButtons::Middle;
case Button3: return MouseButtons::Right;
case Button4: return MouseButtons::MWheelUp;
case Button5: 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;
break;
}
}

View File

@@ -1,7 +1,6 @@
#pragma once
#include <cstdint>
#include <vector>
#include <memory>
#include <Event.h>
#include <functional>
#include <map>
@@ -181,8 +180,6 @@ namespace ReWindow
OnKeyDown(eventData);
}
#ifndef __linux___
//RWindow(HINSTANCE hInst);
void setRect (int nx, int ny, int nw, int nh) {
setPos(nx, ny);
width = nw;

View File

@@ -12,17 +12,14 @@ 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 ();
glSwapBuffers();
auto pos = getCursorPos();
//std::cout << pos.x << ", " << pos.y << std::endl;
}
@@ -65,16 +62,15 @@ int main() {
}
}
//Windows :(
#ifdef _WIN32
#ifndef UNICODE
#define UNICODE
#endif
#include <windows.h>
extern "C" {
int wmain(int argc, wchar_t* argv[]) {
return main();
}
int wmain(int argc, wchar_t* argv[]) {
return main();
}
}
#endif
#endif

View File

@@ -1,16 +1,13 @@
#include <iostream>
#include <rewindow/types/window.h>
#include <rewindow/data/WindowsScancodes.h>
#include <rewindow/types/cursors.h>
#include <J3ML/J3ML.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/cursorfont.h>
#include <cstdlib>
#include <cstring>
#include <thread>
#include "rewindow/types/cursors.h"
#include "../../include/rewindow/types/window.h"
// TODO: Move all "global" members to be instantiated class members of Window
@@ -32,96 +29,61 @@ 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 { 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);
}
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);
}
}
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)
if (xev.xclient.message_type == XInternAtom(display, "WM_PROTOCOLS", False) && static_cast<Atom>(xev.xclient.data.l[0]) == wmDeleteWindow) {
destroyWindow();
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) {
XAutoRepeatOff(display);
//focusGained.Invoke();
RWindowEvent event {};
OnFocusGain(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) {
XAutoRepeatOn(display);
//focusLost.Invoke();
RWindowEvent event {};
@@ -134,7 +96,7 @@ namespace ReWindow {
auto key = GetKeyFromX11Scancode(scancode);
OnKeyUpEvent(key);
OnKeyUpEvent(key);
liftKey (key);
liftKey(key);
}
if (xev.type == KeyPress) {
@@ -142,7 +104,7 @@ namespace ReWindow {
auto key = GetKeyFromX11Scancode(scancode);
OnKeyDownEvent(key);
OnKeyDown(key);
pressKey (key);
pressKey(key);
//eventLog.push_back(eventData);
}
@@ -154,8 +116,7 @@ namespace ReWindow {
OnMouseButtonUp(eventData);
}
if (xev.type == ButtonPress)
{
if (xev.type == ButtonPress) {
MouseButton button = GetMouseButtonFromXButton(xev.xbutton.button);
auto eventData = MouseButtonDownEvent(button);
eventData.Button = button;
@@ -164,19 +125,12 @@ namespace ReWindow {
OnMouseButtonDown(eventData);
}
if (xev.type == Expose) {
}
if (xev.type == 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);
if (xev.type == MotionNotify) {}
//OnMouseMove(eventData);
}
if (xev.type == ResizeRequest)
{
if (xev.type == ResizeRequest) {
auto eventData = WindowResizeRequestEvent();
lastKnownWindowSize = eventData.Size;
eventData.Size = {(float)xev.xresizerequest.width, (float)xev.xresizerequest.height};
@@ -189,22 +143,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);
}
Vector2 RWindow::getCursorPos() const {
Window root = XDefaultRootWindow(display);
Window root_return;
@@ -217,8 +163,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
@@ -234,28 +179,22 @@ 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::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);
}
@@ -268,33 +207,14 @@ 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() {
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;
@@ -303,8 +223,7 @@ 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);
}
void RWindow::restoreFromFullscreen() {
@@ -320,8 +239,7 @@ 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);
}
void RWindow::setVsyncEnabled(bool b) {
@@ -346,15 +264,13 @@ 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,
@@ -374,14 +290,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)
{
if (renderer == RenderingAPI::OPENGL) {
glXMakeCurrent(display, window, glContext);
}
//setVsyncEnabled(vsync);
open = true;
}
@@ -390,10 +301,6 @@ 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;
@@ -401,16 +308,9 @@ namespace ReWindow {
}
// 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
}

View File

@@ -0,0 +1,52 @@
#include <rewindow/types/window.h>
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) {}
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();
}
std::string RWindow::getTitle() const {
return this->title;
}
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);
}

View File

@@ -0,0 +1,181 @@
#include <rewindow/types/window.h>
#include <gl/GL.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);
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_THICKFRAME);
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;
}
//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: {
if (wParam == 112)
std::cout << "F1 was pressed." << std::endl;
}
case WM_KEYUP:
break;
case WM_LBUTTONDOWN:
break;
case WM_LBUTTONUP:
break;
case WM_MOUSEMOVE:
break;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
void RWindow::setCursorStyle(CursorStyle style) const {}
void RWindow::Open() {
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);
}

View File

@@ -1,17 +1,17 @@
#include <rewindow/types/key.h>
std::vector<Key> Key::keyboard = {};
#include <memory>
//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);
}

View File

@@ -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;
}