More Windows Update
Several minor changes to code and build setup Demo runs now
This commit is contained in:
@@ -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-2.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-2.zip
|
||||
)
|
||||
|
||||
find_package(OpenGL REQUIRED)
|
||||
@@ -67,6 +67,8 @@ if(WIN32)
|
||||
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 -mwindows)
|
||||
target_link_libraries(ReWindowLibraryDemo PUBLIC ReWindowLibrary)
|
||||
endif()
|
@@ -7,63 +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
|
||||
};
|
||||
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) {}
|
||||
};
|
||||
class CursorStyle {
|
||||
public:
|
||||
X11CursorStyle X11Cursor;
|
||||
CursorStyle(X11CursorStyle style) : X11Cursor(style) {}
|
||||
};
|
||||
|
||||
namespace Cursors {
|
||||
static const CursorStyle Default {X11CursorStyle::Default};
|
||||
static const CursorStyle X {X11CursorStyle::X};
|
||||
static const CursorStyle Arrow {X11CursorStyle::Arrow};
|
||||
static const CursorStyle IBeam {X11CursorStyle::IBeam};
|
||||
static const CursorStyle BottomLeftCorner {X11CursorStyle::BottomLeftCorner};
|
||||
static const CursorStyle BottomRightCorner {X11CursorStyle::BottomRightCorner};
|
||||
static const CursorStyle BottomSide {X11CursorStyle::BottomSide};
|
||||
static const CursorStyle Dot {X11CursorStyle::Dot};
|
||||
static const CursorStyle DoubleArrow {X11CursorStyle::DoubleArrow};
|
||||
static const CursorStyle Exchange {X11CursorStyle::Exchange};
|
||||
static const CursorStyle Hand {X11CursorStyle::Hand};
|
||||
static const CursorStyle LeftSide {X11CursorStyle::LeftSide};
|
||||
static const CursorStyle Plus {X11CursorStyle::Plus};
|
||||
static const CursorStyle RightSide {X11CursorStyle::RightSide};
|
||||
static const CursorStyle Pencil {X11CursorStyle::Pencil};
|
||||
}
|
||||
|
||||
namespace Cursors {
|
||||
static const CursorStyle Default {X11CursorStyle::Default};
|
||||
static const CursorStyle X {X11CursorStyle::X};
|
||||
static const CursorStyle Arrow {X11CursorStyle::Arrow};
|
||||
static const CursorStyle IBeam {X11CursorStyle::IBeam};
|
||||
static const CursorStyle BottomLeftCorner {X11CursorStyle::BottomLeftCorner};
|
||||
static const CursorStyle BottomRightCorner {X11CursorStyle::BottomRightCorner};
|
||||
static const CursorStyle BottomSide {X11CursorStyle::BottomSide};
|
||||
static const CursorStyle Dot {X11CursorStyle::Dot};
|
||||
static const CursorStyle DoubleArrow {X11CursorStyle::DoubleArrow};
|
||||
static const CursorStyle Exchange {X11CursorStyle::Exchange};
|
||||
static const CursorStyle Hand {X11CursorStyle::Hand};
|
||||
static const CursorStyle LeftSide {X11CursorStyle::LeftSide};
|
||||
static const CursorStyle Plus {X11CursorStyle::Plus};
|
||||
static const CursorStyle RightSide {X11CursorStyle::RightSide};
|
||||
static const CursorStyle Pencil {X11CursorStyle::Pencil};
|
||||
}
|
||||
#else
|
||||
// https://learn.microsoft.com/en-us/windows/win32/menurc/about-cursors
|
||||
enum WindowsCursorStyle {
|
||||
Arrow,
|
||||
IBeam,
|
||||
Wait,
|
||||
Cross,
|
||||
Hand,
|
||||
AppStarting,
|
||||
};
|
||||
// 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
|
||||
}
|
@@ -28,10 +28,12 @@ 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
|
||||
@@ -240,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
|
||||
|
141
main.cpp
141
main.cpp
@@ -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,38 +81,23 @@ int main() {
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) {
|
||||
auto* window = new ReWindow::RWindow(hInstance);
|
||||
window->setTitle ("Sample Window");
|
||||
window->raise ();
|
||||
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine, int nCmdShow) {
|
||||
auto* window = new MyWindow ("Test Window", 600, 480);
|
||||
window->raise ();
|
||||
|
||||
while (window->pollEvents ()) {
|
||||
window->OnKeyDownEvent += [&] (ReWindow::KeyDownEvent e) {
|
||||
if (e.key == Keys::LeftArrow) {
|
||||
std::cout << "Left Arrow Hit" << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
while (window->isAlive()) {
|
||||
window->pollEvents();
|
||||
window->refresh();
|
||||
}
|
||||
|
||||
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
|
@@ -115,16 +115,24 @@ static ATOM reClass = 0;
|
||||
static HGLRC glrc = NULL;
|
||||
static DEVMODEA mode;
|
||||
|
||||
ReWindow::RWindow::RWindow() {
|
||||
void registerClass () {
|
||||
if (!reClass) {
|
||||
HINSTANCE module = GetModuleHandleA (NULL);
|
||||
|
||||
WNDCLASS rewc = {CS_HREDRAW | CS_VREDRAW,
|
||||
WNDCLASSA rewc = {CS_HREDRAW | CS_VREDRAW,
|
||||
ReWindowProc, 0, 0, module, NULL, LoadCursor (NULL, IDC_ARROW),
|
||||
(HBRUSH) GetStockObject (BLACK_BRUSH), NULL, "ReWindowClass"
|
||||
};
|
||||
|
||||
reClass = RegisterClass (&rewc);
|
||||
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,
|
||||
@@ -133,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);
|
||||
@@ -200,18 +222,17 @@ void ReWindow::RWindow::refresh() {
|
||||
}
|
||||
}
|
||||
|
||||
bool ReWindow::RWindow::pollEvents() {
|
||||
void ReWindow::RWindow::pollEvents() {
|
||||
MSG msg;
|
||||
|
||||
while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) {
|
||||
if (msg.message == WM_QUIT) {
|
||||
return FALSE;
|
||||
setFlag (RWindowFlags::QUIT, true);
|
||||
}
|
||||
|
||||
TranslateMessage (&msg);
|
||||
DispatchMessage (&msg);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// Might make the window go off the screen on some window managers.
|
||||
@@ -265,7 +286,7 @@ void ReWindow::RWindow::refresh() {
|
||||
}
|
||||
|
||||
bool ReWindow::RWindow::isAlive() const {
|
||||
return true;
|
||||
return !getFlag (RWindowFlags::QUIT);
|
||||
}
|
||||
|
||||
void ReWindow::RWindow::setResizable(bool resizable) {
|
||||
@@ -309,8 +330,8 @@ void ReWindow::RWindow::refresh() {
|
||||
}
|
||||
|
||||
void ReWindow::RWindow::setCursorStyle (CursorStyle style) const {
|
||||
LPWSTR ids[] ={IDC_ARROW, IDC_IBEAM, IDC_WAIT, IDC_CROSS, IDC_HAND, IDC_APPSTARTING};
|
||||
SetClassLongPtr (hwnd, GCLP_HCURSOR, (LONG_PTR) LoadCursor (NULL, ids[style.WindowsCursor]));
|
||||
int idcs[] ={32512, 32513, 32514, 325123, 32649, 32650};
|
||||
SetClassLongPtr (hwnd, GCLP_HCURSOR, (LONG_PTR) LoadCursor (NULL, MAKEINTRESOURCE (idcs[style.WindowsCursor])));
|
||||
}
|
||||
|
||||
void ReWindow::RWindow::Open() {
|
||||
@@ -349,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
|
||||
|
Reference in New Issue
Block a user