Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
ef57fb0732 | |||
2930391ee4 | |||
b1dfab70a1 | |||
bdc1427626 | |||
158fafaa79 |
@@ -39,6 +39,7 @@ endif()
|
||||
|
||||
include_directories("include")
|
||||
add_library(ReWindowLibrary SHARED ${SOURCES}
|
||||
include/rewindow/types/cursors.h
|
||||
)
|
||||
# Why god???
|
||||
set_target_properties(ReWindowLibrary PROPERTIES LINKER_LANGUAGE CXX)
|
||||
|
60
include/rewindow/types/cursors.h
Normal file
60
include/rewindow/types/cursors.h
Normal file
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
#include <X11/cursorfont.h>
|
||||
namespace ReWindow
|
||||
{
|
||||
enum class X11CursorStyle
|
||||
{
|
||||
Default = XC_left_ptr,
|
||||
X = XC_X_cursor,
|
||||
Arrow = XC_arrow,
|
||||
IBeam = XC_xterm,
|
||||
BottomLeftCorner = XC_bottom_left_corner,
|
||||
BottomRightCorner = XC_bottom_right_corner,
|
||||
BottomSide = XC_bottom_side,
|
||||
Dot = XC_dot,
|
||||
DoubleArrow = XC_double_arrow,
|
||||
Exchange = XC_exchange,
|
||||
Hand = XC_hand2,
|
||||
LeftSide = XC_left_side,
|
||||
Plus = XC_plus,
|
||||
RightSide = XC_right_side,
|
||||
Pencil = XC_pencil
|
||||
};
|
||||
|
||||
// https://learn.microsoft.com/en-us/windows/win32/menurc/about-cursors
|
||||
enum class WindowsCursorStyle
|
||||
{
|
||||
Arrow,
|
||||
IBeam,
|
||||
Wait,
|
||||
Cross,
|
||||
Hand,
|
||||
AppStarting,
|
||||
};
|
||||
class CursorStyle
|
||||
{
|
||||
public:
|
||||
X11CursorStyle X11Cursor;
|
||||
CursorStyle(X11CursorStyle style) : X11Cursor(style) {}
|
||||
};
|
||||
|
||||
namespace Cursors
|
||||
{
|
||||
static const CursorStyle Default {X11CursorStyle::Default};
|
||||
static const CursorStyle X {X11CursorStyle::X};
|
||||
static const CursorStyle Arrow {X11CursorStyle::Arrow};
|
||||
static const CursorStyle IBeam {X11CursorStyle::IBeam};
|
||||
static const CursorStyle BottomLeftCorner {X11CursorStyle::BottomLeftCorner};
|
||||
static const CursorStyle BottomRightCorner {X11CursorStyle::BottomRightCorner};
|
||||
static const CursorStyle BottomSide {X11CursorStyle::BottomSide};
|
||||
static const CursorStyle Dot {X11CursorStyle::Dot};
|
||||
static const CursorStyle DoubleArrow {X11CursorStyle::DoubleArrow};
|
||||
static const CursorStyle Exchange {X11CursorStyle::Exchange};
|
||||
static const CursorStyle Hand {X11CursorStyle::Hand};
|
||||
static const CursorStyle LeftSide {X11CursorStyle::LeftSide};
|
||||
static const CursorStyle Plus {X11CursorStyle::Plus};
|
||||
static const CursorStyle RightSide {X11CursorStyle::RightSide};
|
||||
static const CursorStyle Pencil {X11CursorStyle::Pencil};
|
||||
}
|
||||
|
||||
}
|
@@ -13,6 +13,8 @@
|
||||
#include <X11/Xutil.h>
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glx.h>
|
||||
#include "cursors.h"
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -33,23 +35,6 @@ enum class RenderingAPI: uint8_t {
|
||||
VULKAN = 1,
|
||||
};
|
||||
|
||||
enum class CursorStyle
|
||||
{
|
||||
Default,
|
||||
X,
|
||||
Arrow,
|
||||
IBeam,
|
||||
BottomLeftCorner,
|
||||
BottomRightCorner,
|
||||
BottomSide,
|
||||
Dot,
|
||||
DoubleArrow,
|
||||
Exchange,
|
||||
Hand,
|
||||
LeftSide,
|
||||
Plus,
|
||||
RightSide,
|
||||
};
|
||||
|
||||
enum class KeyState { Pressed, Released };
|
||||
|
||||
@@ -140,50 +125,41 @@ namespace ReWindow
|
||||
using namespace WindowEvents;
|
||||
|
||||
class RWindow {
|
||||
|
||||
private:
|
||||
Vector2 lastKnownWindowSize {0, 0};
|
||||
bool flags[4];
|
||||
std::vector<RWindowEvent> eventLog;
|
||||
KeyboardState currentKeyboard; // Current Frame's Keyboard State
|
||||
KeyboardState previousKeyboard; // Previous Frame's Keyboard State
|
||||
bool fullscreenmode = false;
|
||||
public:
|
||||
Event<> focusGained;
|
||||
Event<> focusLost;
|
||||
// TODO: Integrate J3ML
|
||||
Event<MouseMoveEvent&> mouseMoved;
|
||||
Event<MouseButton> mouseBtnPressed;
|
||||
Event<MouseButton> mouseBtnReleased;
|
||||
Event<KeyDownEvent> onKeyboardPress;
|
||||
Event<KeyUpEvent> onKeyboardRelease;
|
||||
|
||||
virtual void OnFocusLost(const RWindowEvent& e) {}
|
||||
virtual void OnFocusGain(const RWindowEvent& e) {}
|
||||
virtual void OnRefresh(float elapsed) {}
|
||||
virtual void OnResizeSuccess() {}
|
||||
virtual bool OnResizeRequest(const WindowResizeRequestEvent& e) {}
|
||||
virtual void OnKeyDownEvent(const KeyDownEvent&) {}
|
||||
virtual void OnKeyUpEvent(const KeyUpEvent&) {}
|
||||
virtual void OnKeyDown(const KeyDownEvent&) {}
|
||||
virtual void OnKeyUp(const KeyUpEvent&) {}
|
||||
virtual void OnMouseMove(const MouseMoveEvent&) {}
|
||||
virtual void OnMouseButtonDown(const MouseButtonDownEvent&) {}
|
||||
virtual void OnMouseButtonUp(const MouseButtonUpEvent&) {}
|
||||
|
||||
|
||||
RWindow();
|
||||
Vector2 GetSize() const
|
||||
RWindow()
|
||||
{
|
||||
|
||||
title = "ReWindow Application";
|
||||
width = 640;
|
||||
height = 480;
|
||||
}
|
||||
RWindow(const std::string& title, int width, int height);
|
||||
RWindow(const std::string& title, int width, int height, RenderingAPI renderer);
|
||||
|
||||
void SetRenderer(RenderingAPI api)
|
||||
{
|
||||
renderer = api;
|
||||
}
|
||||
void Open();
|
||||
void Close();
|
||||
void CloseAndReopenInPlace();
|
||||
|
||||
// TODO: Must be implemented from scratch as a Motif Window in x11
|
||||
void MessageBox();
|
||||
|
||||
bool isFocused() const;
|
||||
bool isFullscreen() const
|
||||
{
|
||||
return fullscreenmode;
|
||||
}
|
||||
bool isFullscreen() const;
|
||||
bool isResizable() const;
|
||||
bool isVsyncEnabled() const;
|
||||
|
||||
@@ -194,40 +170,51 @@ namespace ReWindow
|
||||
void setMouseCenter();
|
||||
void restoreMouseFromLastCenter(); // Feels nicer for users
|
||||
|
||||
bool isKeyDown(Key key) const;
|
||||
bool isMouseButtonDown(MouseButton button) const;
|
||||
|
||||
void setFullscreen(bool fs);
|
||||
void setResizable(bool resizable);
|
||||
void setVsyncEnabled(bool);
|
||||
void setTitle(const std::string& title);
|
||||
|
||||
std::string getTitle() const;
|
||||
void fullscreen();
|
||||
void restoreFromFullscreen();
|
||||
|
||||
bool getFlag(RWindowFlags flag) const;
|
||||
void setFlag(RWindowFlags flag, bool state);
|
||||
void init(RenderingAPI api, const char* title, int width, int height, bool vsync);
|
||||
//void init(RenderingAPI api, const char* title, int width, int height, bool vsync);
|
||||
void destroyWindow();
|
||||
void pollEvents();
|
||||
void refresh();
|
||||
|
||||
void setSize(int width, int height);
|
||||
void setSize(const Vector2& size);
|
||||
|
||||
/// Returns the position of the window's top-left corner relative to the display
|
||||
Vector2 getPos() const;
|
||||
Vector2 getSize() const;
|
||||
void setPos(int x, int y);
|
||||
void setPos(const Vector2& pos);
|
||||
|
||||
Vector2 getCursorPos() const;
|
||||
void raise() const;
|
||||
void lower() const;
|
||||
|
||||
void setCursor(CursorStyle style) const;
|
||||
|
||||
// TODO: Implement
|
||||
// void setCursor(Icon* icon) const;
|
||||
void setCursorStyle(CursorStyle style) const;
|
||||
void setCursorCustomIcon() const;
|
||||
|
||||
static void glSwapBuffers();
|
||||
//Initialize to false because it's not guaranteed that they will be cleared first
|
||||
private:
|
||||
Vector2 lastKnownWindowSize {0, 0};
|
||||
bool flags[4];
|
||||
std::vector<RWindowEvent> eventLog;
|
||||
KeyboardState currentKeyboard; // Current Frame's Keyboard State
|
||||
KeyboardState previousKeyboard; // Previous Frame's Keyboard State
|
||||
bool fullscreenmode = false;
|
||||
std::string title;
|
||||
int width;
|
||||
int height;
|
||||
RenderingAPI renderer;
|
||||
bool open = false;
|
||||
bool resizable;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
41
main.cpp
41
main.cpp
@@ -3,29 +3,39 @@
|
||||
|
||||
#if __linux__
|
||||
|
||||
void KeyDown(const ReWindow::WindowEvents::KeyDownEvent& e)
|
||||
{
|
||||
//std::cout << e.key.CharCode << " pressed" << std::endl;
|
||||
}
|
||||
|
||||
Vector2 mouse_pos;
|
||||
|
||||
// TODO: Move to J3ML::LinearAlgebra::Vector2
|
||||
std::ostream& operator<<(std::ostream& os, const Vector2& v)
|
||||
{
|
||||
return os << "{" << v.x << ", " << v.y << "}";
|
||||
}
|
||||
|
||||
|
||||
class MyWindow : public ReWindow::RWindow
|
||||
{
|
||||
public:
|
||||
MyWindow(const std::string& title, int w, int h) : ReWindow::RWindow(title, w, h)
|
||||
{}
|
||||
|
||||
|
||||
void OnMouseMove(const ReWindow::MouseMoveEvent& e) override
|
||||
{
|
||||
//std::cout << "Mouse Moved: " << e.Position << " @ " << std::endl;
|
||||
|
||||
}
|
||||
void OnKeyDown(const ReWindow::KeyDownEvent& e) override
|
||||
{
|
||||
|
||||
}
|
||||
void OnRefresh(float elapsed) override
|
||||
{
|
||||
glSwapBuffers();
|
||||
auto pos = getCursorPos();
|
||||
//std::cout << pos.x << ", " << pos.y << std::endl;
|
||||
|
||||
if (isKeyDown(Keys::L))
|
||||
this->setCursorStyle(ReWindow::Cursors::Pencil);
|
||||
else
|
||||
this->setCursorStyle(ReWindow::Cursors::Default);
|
||||
}
|
||||
bool OnResizeRequest(const ReWindow::WindowResizeRequestEvent& e) override
|
||||
{
|
||||
@@ -35,16 +45,15 @@ public:
|
||||
};
|
||||
|
||||
int main() {
|
||||
auto* window = new MyWindow();
|
||||
window->init(RenderingAPI::OPENGL, "name",100,100, true);
|
||||
window->setFlag(RWindowFlags::RESIZABLE, true);
|
||||
auto* window = new MyWindow("Test Window", 600, 480);
|
||||
|
||||
window->onKeyboardPress += KeyDown;
|
||||
window->onKeyboardRelease += [&](ReWindow::WindowEvents::KeyUpEvent e)
|
||||
{
|
||||
if (e.key == Keys::F)
|
||||
window->setFullscreen(!window->isFullscreen());
|
||||
};
|
||||
window->SetRenderer(RenderingAPI::OPENGL);
|
||||
window->Open();
|
||||
// TODO: Cannot set flags until after window is open
|
||||
// Make this work somehow
|
||||
window->setFullscreen(false);
|
||||
window->setVsyncEnabled(true);
|
||||
window->setResizable(true);
|
||||
|
||||
while (window->isAlive()) {
|
||||
window->pollEvents();
|
||||
|
@@ -4,10 +4,12 @@
|
||||
#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"
|
||||
|
||||
// TODO: Move all "global" members to be instantiated class members of Window
|
||||
// Doing this would break the intended "Platform-Specific" Encapsulation
|
||||
@@ -27,43 +29,21 @@ GLXContext glContext;
|
||||
|
||||
namespace ReWindow {
|
||||
|
||||
RWindow::RWindow() : flags(false,false,false,false) {
|
||||
|
||||
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::RWindow(const std::string& title, int width, int height, RenderingAPI renderer) :
|
||||
title(title), width(width), height(height), renderer(renderer)
|
||||
{ }
|
||||
|
||||
void RWindow::raise() const { XRaiseWindow(display, window); }
|
||||
void RWindow::lower() const { XLowerWindow(display, window); }
|
||||
|
||||
void RWindow::init(RenderingAPI api, const char* title, int width, int height, bool vsync) {
|
||||
if (api == RenderingAPI::OPENGL) {
|
||||
xSetWindowAttributes.border_pixel = BlackPixel(display, defaultScreen);
|
||||
xSetWindowAttributes.background_pixel = BlackPixel(display, defaultScreen);
|
||||
xSetWindowAttributes.override_redirect = True;
|
||||
xSetWindowAttributes.event_mask = ExposureMask;
|
||||
setVsyncEnabled(vsync);
|
||||
GLint glAttributes[] = {GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None};
|
||||
visual = glXChooseVisual(display, defaultScreen, glAttributes);
|
||||
glContext = glXCreateContext(display, visual, nullptr, GL_TRUE);
|
||||
vsync = sync;
|
||||
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);
|
||||
XSelectInput(display, window,
|
||||
ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
|
||||
PointerMotionMask |
|
||||
PointerMotionHintMask | FocusChangeMask | StructureNotifyMask | SubstructureRedirectMask |
|
||||
SubstructureNotifyMask | CWColormap | ResizeRequest | ResizeRedirectMask);
|
||||
XMapWindow(display, window);
|
||||
XStoreName(display, window, title);
|
||||
wmDeleteWindow = XInternAtom(display, "WM_DELETE_WINDOW", False);
|
||||
XSetWMProtocols(display, window, &wmDeleteWindow, 1);
|
||||
glXMakeCurrent(display, window, glContext);
|
||||
setVsyncEnabled(vsync);
|
||||
} else {exit(0);}
|
||||
}
|
||||
|
||||
|
||||
void RWindow::destroyWindow() {
|
||||
XDestroySubwindows(display, window);
|
||||
@@ -76,31 +56,11 @@ namespace ReWindow {
|
||||
// TODO: Implement refresh time keeping
|
||||
OnRefresh(0.f);
|
||||
|
||||
// TODO: Check if mouse coords have changed, only then fire OnMouseMove event
|
||||
Vector2 mouse_coords = getCursorPos();
|
||||
|
||||
Window root = XDefaultRootWindow(display);
|
||||
Window root_return;
|
||||
Window child_return;
|
||||
int root_x_ret;
|
||||
int root_y_ret;
|
||||
int win_x_ret;
|
||||
int win_y_ret;
|
||||
uint32_t mask_return;
|
||||
unsigned m;
|
||||
bool mouseAvailable = XQueryPointer(display, root, &root_return, &child_return, &root_x_ret, &root_y_ret, &win_x_ret, &win_y_ret, &mask_return);
|
||||
|
||||
if (mouseAvailable)
|
||||
{
|
||||
// TODO: process retrieved mouse coordinates
|
||||
// TODO: normalize coordinates from displaySpace to windowSpace
|
||||
// TODO: fire mouse movement event
|
||||
//std::cout << win_x_ret << ", " << win_y_ret << std::endl;
|
||||
Vector2 mouse_coords_raw = {(float)win_x_ret, (float)win_y_ret};
|
||||
auto window_pos = getPos();
|
||||
Vector2 mouse_coords = mouse_coords_raw - window_pos;
|
||||
|
||||
auto eventData = MouseMoveEvent(mouse_coords);
|
||||
OnMouseMove(eventData);
|
||||
}
|
||||
auto eventData = MouseMoveEvent(mouse_coords);
|
||||
OnMouseMove(eventData);
|
||||
|
||||
std::this_thread::sleep_for(1ms);
|
||||
}
|
||||
@@ -138,7 +98,7 @@ namespace ReWindow {
|
||||
|
||||
if (xev.type == FocusIn) {
|
||||
XAutoRepeatOff(display);
|
||||
focusGained.Invoke();
|
||||
//focusGained.Invoke();
|
||||
RWindowEvent event {};
|
||||
OnFocusGain(event);
|
||||
setFlag(RWindowFlags::IN_FOCUS, true);
|
||||
@@ -146,7 +106,7 @@ namespace ReWindow {
|
||||
|
||||
if (xev.type == FocusOut) {
|
||||
XAutoRepeatOn(display);
|
||||
focusLost.Invoke();
|
||||
//focusLost.Invoke();
|
||||
RWindowEvent event {};
|
||||
OnFocusLost(event);
|
||||
setFlag(RWindowFlags::IN_FOCUS, false);
|
||||
@@ -157,8 +117,7 @@ namespace ReWindow {
|
||||
auto key = GetKeyFromX11Scancode(scancode);
|
||||
currentKeyboard.PressedKeys[key] = false;
|
||||
KeyUpEvent eventData = KeyUpEvent(key);
|
||||
OnKeyUpEvent(eventData);
|
||||
|
||||
OnKeyUp(eventData);
|
||||
}
|
||||
|
||||
if (xev.type == KeyPress) {
|
||||
@@ -166,7 +125,7 @@ namespace ReWindow {
|
||||
auto key = GetKeyFromX11Scancode(scancode);
|
||||
currentKeyboard.PressedKeys[key] = true;
|
||||
KeyDownEvent eventData = KeyDownEvent(key);
|
||||
OnKeyDownEvent(eventData);
|
||||
OnKeyDown(eventData);
|
||||
eventLog.push_back(eventData);
|
||||
}
|
||||
|
||||
@@ -190,6 +149,7 @@ namespace ReWindow {
|
||||
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);
|
||||
@@ -211,8 +171,10 @@ namespace ReWindow {
|
||||
}
|
||||
|
||||
// Might make the window go off the screen on some window managers.
|
||||
void RWindow::setSize(int width, int height)
|
||||
void RWindow::setSize(int newWidth, int newHeight)
|
||||
{
|
||||
this->width = newWidth;
|
||||
this->height = newHeight;
|
||||
if (!getFlag(RWindowFlags::RESIZABLE))
|
||||
return;
|
||||
XResizeWindow(display, window, width, height);
|
||||
@@ -220,9 +182,39 @@ namespace ReWindow {
|
||||
|
||||
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;
|
||||
Window child_return;
|
||||
int root_x_ret;
|
||||
int root_y_ret;
|
||||
int win_x_ret;
|
||||
int win_y_ret;
|
||||
uint32_t mask_return;
|
||||
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)
|
||||
{
|
||||
// TODO: process retrieved mouse coordinates
|
||||
// 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
|
||||
float window_border_width = 2;
|
||||
float window_titlebar_height = 18;
|
||||
Vector2 mouse_coords_raw = {(float)win_x_ret+window_border_width, (float)win_y_ret+window_titlebar_height};
|
||||
auto window_pos = getPos();
|
||||
return mouse_coords_raw - window_pos;
|
||||
}
|
||||
return Vector2::Zero;
|
||||
}
|
||||
|
||||
// TODO: implement integer vector2/3 types
|
||||
Vector2 RWindow::getSize() const
|
||||
{
|
||||
@@ -233,8 +225,9 @@ namespace ReWindow {
|
||||
// TODO: implement integer vector2/3 types
|
||||
Vector2 RWindow::getPos() const
|
||||
{
|
||||
auto root = XDefaultRootWindow(display);
|
||||
XGetWindowAttributes(display,root,&windowAttributes);
|
||||
|
||||
XGetWindowAttributes(display,window,&windowAttributes);
|
||||
|
||||
return {(float)windowAttributes.x, (float)windowAttributes.y};
|
||||
}
|
||||
|
||||
@@ -262,6 +255,7 @@ namespace ReWindow {
|
||||
}
|
||||
|
||||
void RWindow::setResizable(bool resizable) {
|
||||
this->resizable = resizable;
|
||||
this->setFlag(RWindowFlags::RESIZABLE, resizable);
|
||||
}
|
||||
|
||||
@@ -318,6 +312,78 @@ namespace ReWindow {
|
||||
glXSwapIntervalEXT(display, None, b);
|
||||
}
|
||||
|
||||
bool RWindow::isFullscreen() const {
|
||||
return fullscreenmode;
|
||||
}
|
||||
|
||||
using J3ML::u32;
|
||||
void RWindow::setCursorStyle(CursorStyle style) const {
|
||||
u32 x11_cursor_resolved_enum = static_cast<u32>(style.X11Cursor);
|
||||
Cursor c = XCreateFontCursor(display, x11_cursor_resolved_enum);
|
||||
XDefineCursor(display, window, c);
|
||||
}
|
||||
|
||||
void RWindow::Open() {
|
||||
xSetWindowAttributes.border_pixel = BlackPixel(display, defaultScreen);
|
||||
xSetWindowAttributes.background_pixel = BlackPixel(display, defaultScreen);
|
||||
xSetWindowAttributes.override_redirect = True;
|
||||
xSetWindowAttributes.event_mask = ExposureMask;
|
||||
//setVsyncEnabled(vsync);
|
||||
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);
|
||||
|
||||
window = XCreateWindow(display, RootWindow(display, defaultScreen), 0, 0, width, height, 0, visual->depth,
|
||||
InputOutput, visual->visual, CWBackPixel | CWColormap | CWBorderPixel | NoEventMask,
|
||||
&xSetWindowAttributes);
|
||||
XSelectInput(display, window,
|
||||
ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
|
||||
PointerMotionMask |
|
||||
PointerMotionHintMask | FocusChangeMask | StructureNotifyMask | SubstructureRedirectMask |
|
||||
SubstructureNotifyMask | CWColormap | ResizeRequest | ResizeRedirectMask);
|
||||
XMapWindow(display, window);
|
||||
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;
|
||||
}
|
||||
|
||||
void RWindow::setTitle(const std::string &title) {
|
||||
this->title = title;
|
||||
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
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: Implement ControllerButton map
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user