Compare commits

...

4 Commits

Author SHA1 Message Date
a8da7b6bdf Update 2024-05-22 07:23:57 -07:00
50ccfe3860 Update J3ML 2024-05-21 13:16:06 -04:00
orange bowler hat
3572ef01cd More Windows Update
Several minor changes to code and build setup
Demo runs now
2024-05-13 23:14:04 +01:00
orange bowler hat
664d213c04 Several smaller updates
Windows version of ReWindow now compiling
Added to gitignore
2024-05-13 13:40:11 +01:00
8 changed files with 205 additions and 220 deletions

4
.gitignore vendored
View File

@@ -1,4 +1,4 @@
/cmake-build-debug
/.idea
build/CMakeCache.txt
build/CMakeCache.txt
build/*
.vscode/*

View File

@@ -17,13 +17,13 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(cmake/CPM.cmake)
CPMAddPackage(
NAME J3ML
URL https://git.redacted.cc/josh/j3ml/archive/Release-2.zip
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-2.zip
NAME Event
URL https://git.redacted.cc/josh/Event/archive/Release-5.zip
)
find_package(OpenGL REQUIRED)
@@ -42,7 +42,14 @@ if(WIN32)
endif()
include_directories("include")
add_library(ReWindowLibrary SHARED ${SOURCES})
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)
@@ -63,10 +70,12 @@ if(UNIX AND NOT APPLE)
endif()
if(WIN32)
target_compile_options(ReWindowLibrary PRIVATE -Wno-multichar)
#target_compile_options(ReWindowLibrary PRIVATE -Wno-multichar)
target_link_libraries(ReWindowLibrary PUBLIC ${OPENGL_LIBRARIES})
target_link_libraries(ReWindowLibrary PUBLIC J3ML)
target_link_libraries(ReWindowLibrary PUBLIC Event)
add_executable(ReWindowLibraryDemo main.cpp)
#target_compile_options(ReWindowLibraryDemo PRIVATE)
target_link_libraries(ReWindowLibraryDemo PUBLIC ReWindowLibrary)
endif()

View File

@@ -7,64 +7,74 @@
namespace ReWindow
{
#if __linux__
enum class X11CursorStyle
{
Default = XC_left_ptr,
X = XC_X_cursor,
Arrow = XC_arrow,
IBeam = XC_xterm,
BottomLeftCorner = XC_bottom_left_corner,
BottomRightCorner = XC_bottom_right_corner,
BottomSide = XC_bottom_side,
Dot = XC_dot,
DoubleArrow = XC_double_arrow,
Exchange = XC_exchange,
Hand = XC_hand2,
LeftSide = XC_left_side,
Plus = XC_plus,
RightSide = XC_right_side,
Pencil = XC_pencil
};
class CursorStyle {
public:
X11CursorStyle X11Cursor;
CursorStyle(X11CursorStyle style) : X11Cursor(style) {}
};
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
};
class CursorStyle {
public:
X11CursorStyle X11Cursor;
CursorStyle(X11CursorStyle style) : X11Cursor(style) {}
};
namespace Cursors {
static const CursorStyle Default {X11CursorStyle::Default};
static const CursorStyle X {X11CursorStyle::X};
static const CursorStyle Arrow {X11CursorStyle::Arrow};
static const CursorStyle IBeam {X11CursorStyle::IBeam};
static const CursorStyle BottomLeftCorner {X11CursorStyle::BottomLeftCorner};
static const CursorStyle BottomRightCorner {X11CursorStyle::BottomRightCorner};
static const CursorStyle BottomSide {X11CursorStyle::BottomSide};
static const CursorStyle Dot {X11CursorStyle::Dot};
static const CursorStyle DoubleArrow {X11CursorStyle::DoubleArrow};
static const CursorStyle Exchange {X11CursorStyle::Exchange};
static const CursorStyle Hand {X11CursorStyle::Hand};
static const CursorStyle LeftSide {X11CursorStyle::LeftSide};
static const CursorStyle Plus {X11CursorStyle::Plus};
static const CursorStyle RightSide {X11CursorStyle::RightSide};
static const CursorStyle Pencil {X11CursorStyle::Pencil};
}
namespace Cursors {
static const CursorStyle Default {X11CursorStyle::Default};
static const CursorStyle X {X11CursorStyle::X};
static const CursorStyle Arrow {X11CursorStyle::Arrow};
static const CursorStyle IBeam {X11CursorStyle::IBeam};
static const CursorStyle BottomLeftCorner {X11CursorStyle::BottomLeftCorner};
static const CursorStyle BottomRightCorner {X11CursorStyle::BottomRightCorner};
static const CursorStyle BottomSide {X11CursorStyle::BottomSide};
static const CursorStyle Dot {X11CursorStyle::Dot};
static const CursorStyle DoubleArrow {X11CursorStyle::DoubleArrow};
static const CursorStyle Exchange {X11CursorStyle::Exchange};
static const CursorStyle Hand {X11CursorStyle::Hand};
static const CursorStyle LeftSide {X11CursorStyle::LeftSide};
static const CursorStyle Plus {X11CursorStyle::Plus};
static const CursorStyle RightSide {X11CursorStyle::RightSide};
static const CursorStyle Pencil {X11CursorStyle::Pencil};
}
#else
// https://learn.microsoft.com/en-us/windows/win32/menurc/about-cursors
enum class WindowsCursorStyle {
Arrow,
IBeam,
Wait,
Cross,
Hand,
AppStarting,
};
// https://learn.microsoft.com/en-us/windows/win32/menurc/about-cursors
enum WindowsCursorStyle {
Arrow,
IBeam,
Wait,
Cross,
Hand,
AppStarting,
};
class CursorStyle {
public:
WindowsCursorStyle WindowsCursor;
CursorStyle (WindowsCursorStyle style): WindowsCursor(style) {}
};
class CursorStyle {
public:
WindowsCursorStyle WindowsCursor;
CursorStyle (WindowsCursorStyle style): WindowsCursor(style) {}
};
namespace Cursors {
static const CursorStyle Default {WindowsCursorStyle::Arrow};
static const CursorStyle Arrow {WindowsCursorStyle::Arrow};
static const CursorStyle IBeam {WindowsCursorStyle::IBeam};
static const CursorStyle Cross {WindowsCursorStyle::Cross};
static const CursorStyle Wait {WindowsCursorStyle::Wait};
static const CursorStyle Hand {WindowsCursorStyle::Hand};
static const CursorStyle AppStarting {WindowsCursorStyle::AppStarting};
}
#endif
}

View File

@@ -51,8 +51,8 @@ namespace Keys {
static const Key F12 {'\u000f', X11Scancode::F12, WindowsScancode::F12};
static const Key NumPad1 {'\b', X11Scancode::KP_1, WindowsScancode::NUMPAD_ONE};
static const Key NumPad2 {'\b', X11Scancode::KP_2, WindowsScancode::NUMPAD_ONE};
static const Key NumPad3 {'\b', X11Scancode::KP_3, WindowsScancode::NUMPAD_ONE};
static const Key NumPad2 {'\b', X11Scancode::KP_2, WindowsScancode::NUMPAD_TWO};
static const Key NumPad3 {'\b', X11Scancode::KP_3, WindowsScancode::NUMPAD_THREE};
static const Key NumPad4 {'\b', X11Scancode::KP_4, WindowsScancode::NUMPAD_ONE};
static const Key NumPad5 {'\b', X11Scancode::KP_5, WindowsScancode::NUMPAD_ONE};
static const Key NumPad6 {'\b', X11Scancode::KP_6, WindowsScancode::NUMPAD_ONE};

View File

@@ -19,19 +19,21 @@
#include <X11/Xutil.h>
#include <GL/gl.h>
#include <GL/glx.h>
#include <rewindow/types/cursors.h>
#endif
#include <rewindow/types/cursors.h>
using namespace std::chrono_literals;
using precision_clock = std::chrono::high_resolution_clock;
using precision_timestamp = precision_clock::time_point;
enum class RWindowFlags: uint8_t {
IN_FOCUS = 0,
FULLSCREEN = 1,
RESIZABLE = 2,
VSYNC = 4
IN_FOCUS,
FULLSCREEN,
RESIZABLE,
VSYNC,
QUIT,
MAX_FLAG
};
enum class RenderingAPI: uint8_t {
@@ -40,7 +42,6 @@ enum class RenderingAPI: uint8_t {
VULKAN = 1,
};
enum class KeyState {Pressed, Released};
namespace ReWindow
@@ -179,6 +180,8 @@ namespace ReWindow
OnKeyDown(eventData);
}
#ifndef __linux___
//RWindow(HINSTANCE hInst);
void setRect (int nx, int ny, int nw, int nh) {
setPos(nx, ny);
width = nw;
@@ -238,7 +241,7 @@ namespace ReWindow
//Initialize to false because it's not guaranteed that they will be cleared first
private:
Vector2 lastKnownWindowSize {0, 0};
bool flags[4];
bool flags[5];
std::vector<RWindowEvent> eventLog;
KeyboardState currentKeyboard; // Current Frame's Keyboard State
KeyboardState previousKeyboard; // Previous Frame's Keyboard State
@@ -253,16 +256,12 @@ namespace ReWindow
RenderingAPI renderer;
bool open = false;
bool resizable;
//You can't do this because you can't initialize a static member inside the class constructor.
//static RWindow* singleton;
};
class WindowsImplementationRWindow : public RWindow {
class WindowsImplementationRWindow: public RWindow {
};
class X11ImplementationRWindow : public RWindow {
class X11ImplementationRWindow: public RWindow {
};
}

171
main.cpp
View File

@@ -1,73 +1,75 @@
#include <iostream>
#include <rewindow/types/window.h>
#if __linux__
Vector2 mouse_pos;
// TODO: Move to J3ML::LinearAlgebra::Vector2
std::ostream& operator<<(std::ostream& os, const Vector2& v)
{
return os << "{" << v.x << ", " << v.y << "}";
std::ostream& operator<<(std::ostream& os, const Vector2& v) {
return os << "{" << v.x << ", " << v.y << "}";
}
class MyWindow : public ReWindow::RWindow
{
public:
MyWindow(const std::string& title, int w, int h) : ReWindow::RWindow(title, w, h)
{}
class MyWindow : public ReWindow::RWindow {
public:
MyWindow(const std::string& title, int w, int h) : ReWindow::RWindow(title, w, h)
{}
void OnMouseMove(const ReWindow::MouseMoveEvent& e) override {
}
void OnMouseMove(const ReWindow::MouseMoveEvent& e) override
{
void OnKeyDown(const ReWindow::KeyDownEvent& e) override {
}
}
void OnKeyDown(const ReWindow::KeyDownEvent& e) override
{
void OnRefresh(float elapsed) override {
glSwapBuffers ();
auto pos = getCursorPos ();
//std::cout << pos.x << ", " << pos.y << std::endl;
}
void OnRefresh(float elapsed) override
{
glSwapBuffers();
auto pos = getCursorPos();
//std::cout << pos.x << ", " << pos.y << std::endl;
#if __linux__
if (isKeyDown(Keys::L)) {
this->setCursorStyle (ReWindow::Cursors::Pencil);
}
else this->setCursorStyle (ReWindow::Cursors::Default);
#else
if (isKeyDown (Keys::L)) {
this->setCursorStyle (ReWindow::Cursors::Cross);
}
else this->setCursorStyle (ReWindow::Cursors::Arrow);
#endif
}
if (isKeyDown(Keys::L))
this->setCursorStyle(ReWindow::Cursors::Pencil);
else
this->setCursorStyle(ReWindow::Cursors::Default);
}
bool OnResizeRequest(const ReWindow::WindowResizeRequestEvent& e) override
{
std::cout << "resized to " << e.Size.x << ", " << e.Size.y << std::endl;
return true;
}
bool OnResizeRequest(const ReWindow::WindowResizeRequestEvent& e) override {
std::cout << "resized to " << e.Size.x << ", " << e.Size.y << std::endl;
return true;
}
};
#if __linux__
int main() {
auto* window = new MyWindow("Test Window", 600, 480);
auto* window = new MyWindow("Test Window", 600, 480);
window->setRenderer(RenderingAPI::OPENGL);
window->Open();
window->setRenderer(RenderingAPI::OPENGL);
window->Open();
// TODO: Cannot set flags until after window is open
// Make this work somehow
window->setFullscreen(false);
window->setVsyncEnabled(false);
window->setResizable(false);
// TODO: Cannot set flags until after window is open
// Make this work somehow
window->setFullscreen(false);
window->setVsyncEnabled(false);
window->setResizable(false);
window->OnKeyDownEvent += [&] (ReWindow::KeyDownEvent e)
{
if (e.key == Keys::LeftArrow)
{
std::cout << "Left Arrow Hit" << std::endl;
}
};
window->OnKeyDownEvent += [&] (ReWindow::KeyDownEvent e)
{
if (e.key == Keys::LeftArrow)
{
std::cout << "Left Arrow Hit" << std::endl;
}
};
while (window->isAlive()) {
window->pollEvents();
window->refresh();
}
while (window->isAlive()) {
window->pollEvents();
window->refresh();
}
}
#endif
@@ -79,67 +81,22 @@ int main() {
#endif
#include <windows.h>
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int wmain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine, int nCmdShow) {
auto* window = new MyWindow ("Test Window", 600, 480);
window->raise ();
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
auto* window = new RWindow();
window->init(RenderingAPI::OPENGL, "mame", 100, 100);
window->setFlag
window->OnKeyDownEvent += [&] (ReWindow::KeyDownEvent e) {
if (e.key == Keys::LeftArrow) {
std::cout << "Left Arrow Hit" << std::endl;
}
};
// Register the window class.
const wchar_t CLASS_NAME[] = L"Sample Window Class";
while (window->isAlive()) {
window->pollEvents();
window->refresh();
}
WNDCLASS wc = { };
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);
// Create the window.
HWND hwnd = CreateWindowEx(
0,
CLASS_NAME,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, // Parent Window
NULL, // Menu
hInstance, // Instancehandle
NULL
);
if (hwnd == NULL)
return 0;
ShowWindow(hwnd, nCmdShow);
// Run the message loop
MSG msg = {};
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg) {
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
// All painting occurs here, between BeginPaint and EndPaint
FillRect(hdc, &ps.rcPaint, (HBRUSH) (COLOR_WINDOW+1));
EndPaint(hwnd, &ps);
}
return 0;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
return 0;
}
#endif

View File

@@ -1,23 +0,0 @@
project ('ReWindow', 'cpp', version: '0.1.0')
sources = ['spng.c', 'nx/nxObject.m', 'nx/nxApp.m', 'nx/nxWindow.m', 'nx/nxUtil.m', 'nx/nxClipboard.m', 'nx/nxMultiTouch.m', 'nx/nxNav.m', 'State.m', 'Geom.m', 'Surface.m', 'Chunk.m', 'Resource.m', 'gx.m', 'gxMath.c', 'gxTile.m', 'Heap.c', 'uiMenu.m', 'uiFrame.m', 'uiSplit.m', 'uiTool.m', 'main.m', 'Section.m', 'Track.m', 'Plan.m', 'Profile.m', 'Book.m', 'Elevate.m']
includes = include_directories ('/usr/include/gtk-3.0', '/usr/include/libevdev-1.0')
libs = [
dependency ('gio-2.0', version: '>= 2.50'),
dependency ('gdk-3.0', version: '>= 3.20'),
dependency ('gtk+-3.0', version: '>= 3.22'),
dependency ('cairo', version: '>= 1.00'),
compiler.find_library ('m'),
compiler.find_library ('GL'),
compiler.find_library ('objc'),
compiler.find_library ('jpeg'),
compiler.find_library ('evdev'),
]
verse = executable ('verse', [sources, resource],
include_directories: includes,
dependencies: libs,
install: true
)

View File

@@ -115,15 +115,25 @@ static ATOM reClass = 0;
static HGLRC glrc = NULL;
static DEVMODEA mode;
ReWindow::RWindow::RWindow() {
void registerClass () {
if (!reClass) {
WNDCLASSA rewc = {
ReWindowProc, 0, 0, NULL, NULL, , NULL, NULL,
GetStockObject (BLACK_BRUSH), NULL, "ReWindowClass"
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,
@@ -131,6 +141,20 @@ ReWindow::RWindow::RWindow() {
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);
@@ -202,6 +226,10 @@ void ReWindow::RWindow::refresh() {
MSG msg;
while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) {
if (msg.message == WM_QUIT) {
setFlag (RWindowFlags::QUIT, true);
}
TranslateMessage (&msg);
DispatchMessage (&msg);
}
@@ -258,7 +286,7 @@ void ReWindow::RWindow::refresh() {
}
bool ReWindow::RWindow::isAlive() const {
return true;
return !getFlag (RWindowFlags::QUIT);
}
void ReWindow::RWindow::setResizable(bool resizable) {
@@ -280,13 +308,13 @@ void ReWindow::RWindow::refresh() {
screen.dmPelsHeight = height;
screen.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
if (ChangeDisplaySettings (&screen, 0) == DISP_CHANGE_SUCCESSFUL) {
if (ChangeDisplaySettingsA (&screen, 0) == DISP_CHANGE_SUCCESSFUL) {
fullscreenmode = true;
}
}
void ReWindow::RWindow::restoreFromFullscreen() {
if (ChangeDisplaySettings (&mode, 0) == DISP_CHANGE_SUCCESSFUL) {
if (ChangeDisplaySettingsA (&mode, 0) == DISP_CHANGE_SUCCESSFUL) {
fullscreenmode = false;
}
}
@@ -302,8 +330,8 @@ void ReWindow::RWindow::refresh() {
}
void ReWindow::RWindow::setCursorStyle (CursorStyle style) const {
uint ids = [IDC_ARROW, IDC_IBEAM, IDC_WAIT, IDC_CROSS, IDC_HAND, IDC_APPSTARTING];
SetClassLongPtr (hwnd, GCLIP_HCURSOR, LoadCursor (NULL, ids[style]));
int idcs[] ={32512, 32513, 32514, 325123, 32649, 32650};
SetClassLongPtr (hwnd, GCLP_HCURSOR, (LONG_PTR) LoadCursor (NULL, MAKEINTRESOURCE (idcs[style.WindowsCursor])));
}
void ReWindow::RWindow::Open() {
@@ -325,7 +353,7 @@ void ReWindow::RWindow::refresh() {
if (glrc) {
wglMakeCurrent (hdc, glrc);
EnumDisplaySettings (NULL, ENUM_CURRENT_SETTINGS, &mode);
EnumDisplaySettingsA (NULL, ENUM_CURRENT_SETTINGS, &mode);
open = true;
}
}
@@ -342,8 +370,13 @@ void ReWindow::RWindow::refresh() {
}
bool ReWindow::RWindow::isKeyDown (Key key) const {
return currentKeyboard.PressedKeys.contains(key) ?
currentKeyboard.PressedKeys.at(key) : false;
auto find = currentKeyboard.PressedKeys.find (key);
if (find != currentKeyboard.PressedKeys.end ()) {
return currentKeyboard.PressedKeys.at (key);
}
return false;
}
// TODO: Implement MouseButton map