Skip to content

Commit f445e19

Browse files
committed
WIP win32
1 parent 6351e7e commit f445e19

6 files changed

Lines changed: 918 additions & 896 deletions

File tree

extensions/pl_platform_ext.h

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ extern "C" {
5757
// [SECTION] forward declarations
5858
//-----------------------------------------------------------------------------
5959

60+
// basic types (windows)
61+
typedef struct _plWindow plWindow; // mostly opaque type for windows
62+
typedef struct _plWindowDesc plWindowDesc; // description for window creation
63+
typedef struct _plWindowEvent plWindowEvent; // future window event type
64+
typedef struct _plFullScreenDesc plFullScreenDesc; // full screen options
65+
typedef struct _plWindowCapabilities plWindowCapabilities; // window capabilities for various settings
66+
typedef union _plWindowAttributeValue plWindowAttributeValue; // catch all for windows attributes (basically a variant)
67+
6068
// basic types (atomics)
6169
typedef struct _plAtomicCounter plAtomicCounter; // opaque type
6270

@@ -80,6 +88,13 @@ typedef struct _plThreadKey plThreadKey; // opaque type (used by
8088

8189
typedef void* (*plThreadProcedure)(void*); // thread procedure signature
8290

91+
// enums (windows)
92+
typedef int plWindowEventType; // -> enum _plWindowEventType // Enum: A window event type (PL_WINDOW_EVENT_TYPE_XXX)
93+
typedef int plWindowAttribute; // -> enum _plWindowAttribute // Enum: window attribute (PL_WINDOW_ATTRIBUTE_XXX)
94+
typedef int plCursorMode; // -> enum _plCursorMode // Enum: window cursor mode (PL_CURSOR_MODE__XXX)
95+
typedef int plFullScreenMode; // -> enum _plFullScreenMode // Enum: window full screen mode (PL_FULLSCREEN_MODE_XXX)
96+
typedef int plWindowCapabilityFlags; // -> enum _plWindowCapabilityFlags // Flag: window capability flags (PL_WINDOW_CAPABILITY_FLAGS_XXX)
97+
8398
// enums (atomics)
8499
typedef int plAtomicsResult; // -> enum _plAtomicsResult // Enum:
85100

@@ -95,6 +110,9 @@ typedef int plNetworkResult; // -> enum _plNetworkResult // Enum:
95110
// enums (thread)
96111
typedef int plThreadResult; // -> enum _plThreadResult // Enum:
97112

113+
// callbacks (windows)
114+
typedef void (*plWindowEventCallback)(const plWindowEvent*, void* userData);
115+
98116
//-----------------------------------------------------------------------------
99117
// [SECTION] public apis
100118
//-----------------------------------------------------------------------------
@@ -103,6 +121,30 @@ typedef int plThreadResult; // -> enum _plThreadResult // Enum:
103121
PL_API void pl_load_platform_ext (plApiRegistryI*, bool reload);
104122
PL_API void pl_unload_platform_ext(plApiRegistryI*, bool reload);
105123

124+
//-------------------------------window api------------------------------------
125+
126+
// create/destroy
127+
PL_API plWindowResult pl_window_create (plWindowDesc, plWindow** windowPtrOut);
128+
PL_API void pl_window_destroy (plWindow*);
129+
PL_API void pl_window_show (plWindow*);
130+
PL_API const plWindowCapabilities* pl_window_get_capabilities(void);
131+
132+
// attributes
133+
PL_API bool pl_window_set_attribute (plWindow*, plWindowAttribute, const plWindowAttributeValue*);
134+
PL_API bool pl_window_get_attribute (plWindow*, plWindowAttribute, plWindowAttributeValue*);
135+
136+
// cursor modes
137+
PL_API bool pl_window_set_cursor_mode (plWindow*, plCursorMode);
138+
PL_API plCursorMode pl_window_get_cursor_mode (plWindow*);
139+
PL_API bool pl_window_set_raw_mouse_input (plWindow*, bool);
140+
141+
// full screen modes
142+
PL_API bool pl_window_set_fullscreen(plWindow*, const plFullScreenDesc*);
143+
144+
// future callback system
145+
PL_API void pl_window_set_callback(plWindow*, plWindowEventCallback, void* userData);
146+
PL_API plWindowEventCallback pl_window_get_callback(plWindow*);
147+
106148
//-----------------------------atomics api-------------------------------------
107149

108150
PL_API plAtomicsResult pl_atomics_create_counter (int64_t value, plAtomicCounter** counterPtrOut);
@@ -230,6 +272,32 @@ PL_API void pl_virtual_memory_free (void* address, size_t); // frees a
230272
// [SECTION] public api structs
231273
//-----------------------------------------------------------------------------
232274

275+
typedef struct _plWindowI
276+
{
277+
// create/destroy
278+
plWindowResult (*create) (plWindowDesc, plWindow** windowPtrOut);
279+
void (*destroy) (plWindow*);
280+
void (*show) (plWindow*);
281+
const plWindowCapabilities* (*get_capabilities)(void);
282+
283+
// attributes
284+
bool (*set_attribute) (plWindow*, plWindowAttribute, const plWindowAttributeValue*);
285+
bool (*get_attribute) (plWindow*, plWindowAttribute, plWindowAttributeValue*);
286+
287+
// cursor modes
288+
bool (*set_cursor_mode) (plWindow*, plCursorMode);
289+
plCursorMode (*get_cursor_mode) (plWindow*);
290+
bool (*set_raw_mouse_input) (plWindow*, bool);
291+
292+
// full screen modes
293+
bool (*set_fullscreen)(plWindow*, const plFullScreenDesc*);
294+
295+
// future callback system
296+
void (*set_callback)(plWindow*, plWindowEventCallback, void* userData);
297+
plWindowEventCallback (*get_callback)(plWindow*);
298+
299+
} plWindowI;
300+
233301
typedef struct _plAtomicsI
234302
{
235303

@@ -372,6 +440,77 @@ typedef struct _plVirtualMemoryI
372440
// [SECTION] enums
373441
//-----------------------------------------------------------------------------
374442

443+
enum _plWindowResult
444+
{
445+
PL_WINDOW_RESULT_FAIL = 0,
446+
PL_WINDOW_RESULT_SUCCESS = 1
447+
};
448+
449+
enum _plWindowFlags
450+
{
451+
PL_WINDOW_FLAG_NONE = 0,
452+
};
453+
454+
enum _plWindowEventType
455+
{
456+
457+
PL_WINDOW_EVENT_TYPE_NONE = 0,
458+
459+
// FUTURE
460+
461+
// PL_WINDOW_EVENT_TYPE_MOUSE_MOVE,
462+
// PL_WINDOW_EVENT_TYPE_MOUSE_BUTTON,
463+
// PL_WINDOW_EVENT_TYPE_MOUSE_SCROLL,
464+
// PL_WINDOW_EVENT_TYPE_KEY,
465+
// PL_WINDOW_EVENT_TYPE_CHAR,
466+
// PL_WINDOW_EVENT_TYPE_WINDOW_FOCUS,
467+
// PL_WINDOW_EVENT_TYPE_WINDOW_RESIZE,
468+
// PL_WINDOW_EVENT_TYPE_WINDOW_CLOSE
469+
};
470+
471+
enum _plWindowAttribute
472+
{
473+
PL_WINDOW_ATTRIBUTE_SIZE = 0,
474+
PL_WINDOW_ATTRIBUTE_POSITION,
475+
PL_WINDOW_ATTRIBUTE_RESIZABLE,
476+
PL_WINDOW_ATTRIBUTE_DECORATED,
477+
PL_WINDOW_ATTRIBUTE_TOP_MOST,
478+
PL_WINDOW_ATTRIBUTE_MINIMIZED,
479+
PL_WINDOW_ATTRIBUTE_MAXIMIZED,
480+
PL_WINDOW_ATTRIBUTE_VISIBLE,
481+
PL_WINDOW_ATTRIBUTE_FOCUSED,
482+
PL_WINDOW_ATTRIBUTE_HOVERED,
483+
PL_WINDOW_ATTRIBUTE_SIZE_LIMITS,
484+
485+
PL_WINDOW_ATTRIBUTE_COUNT
486+
};
487+
488+
enum _plCursorMode
489+
{
490+
491+
PL_CURSOR_MODE_NORMAL = 0,
492+
PL_CURSOR_MODE_HIDDEN,
493+
PL_CURSOR_MODE_CAPTURED,
494+
PL_CURSOR_MODE_DISABLED,
495+
496+
PL_CURSOR_MODE_COUNT
497+
};
498+
499+
enum _plFullScreenMode
500+
{
501+
PL_FULLSCREEN_MODE_NONE = 0,
502+
PL_FULLSCREEN_MODE_EXCLUSIVE,
503+
PL_FULLSCREEN_MODE_BORDERLESS,
504+
505+
L_FULLSCREEN_MODE_COUNT
506+
};
507+
508+
enum _plWindowCapabilityFlags
509+
{
510+
PL_WINDOW_CAPABILITY_FLAGS_NONE = 0,
511+
PL_WINDOW_CAPABILITY_FLAGS_RAW_MOUSE_INPUT = 1 << 0
512+
};
513+
375514
enum _plAtomicsResult
376515
{
377516
PL_ATOMICS_RESULT_FAIL = 0,
@@ -432,6 +571,64 @@ enum _plThreadResult
432571
// [SECTION] structs
433572
//-----------------------------------------------------------------------------
434573

574+
typedef struct _plWindowDesc
575+
{
576+
plWindowFlags tFlags;
577+
const char* pcTitle;
578+
uint32_t uWidth;
579+
uint32_t uHeight;
580+
int iXPos;
581+
int iYPos;
582+
const void* pNext;
583+
} plWindowDesc;
584+
585+
typedef struct _plWindow
586+
{
587+
void* pUserData;
588+
589+
// [INTERNAL]
590+
void* _pBackendData;
591+
void* _pBackendData2;
592+
plWindowInternalFlags _tInternalFlags;
593+
uint32_t _uRequestedWidth;
594+
uint32_t _uRequestedHeight;
595+
int _iRequestedMonitor;
596+
int _iXPos;
597+
int _iYPos;
598+
} plWindow;
599+
600+
typedef struct _plWindowEvent
601+
{
602+
plWindowEventType tType;
603+
plWindow* ptWindow;
604+
} plWindowEvent;
605+
606+
typedef union _plWindowAttributeValue
607+
{
608+
bool bValue;
609+
int iValue;
610+
struct { int x, y; } tiVec2;
611+
struct { uint32_t x, y; } tuVec2;
612+
struct { uint32_t x, y, z, w; } tuVec4;
613+
} plWindowAttributeValue;
614+
615+
typedef struct _plFullScreenDesc
616+
{
617+
plFullScreenMode tMode;
618+
int iMonitor; // -1 = automatic
619+
} plFullScreenDesc;
620+
621+
typedef struct _plWindowCapabilities
622+
{
623+
plWindowCapabilityFlags tFlags;
624+
const plCursorMode* atCursorModes;
625+
uint32_t uCursorModeCount;
626+
const plFullScreenMode* atFullScreenModes;
627+
uint32_t uFullScreenModeCount;
628+
const plWindowAttribute* atWindowAttributes;
629+
uint32_t uAttributeCount;
630+
} plWindowCapabilities;
631+
435632
typedef struct _plSocketReceiverInfo
436633
{
437634
char acAddressBuffer[100];

0 commit comments

Comments
 (0)