Added unicode flags, cleaned up window platform

This commit is contained in:
2026-05-11 11:30:51 -05:00
parent 7bb8233fa6
commit 2864d518d3
6 changed files with 18 additions and 43 deletions

View File

@@ -20,7 +20,7 @@ ifeq ($(OS), Windows_NT)
PLATFORM := win32
PLATFORM_SRCS := $(wildcard $(SRC)/win32_*.c)
PLATFORM_OBJS := $(patsubst $(SRC)/%.c, $(OBJ)/%.o, $(PLATFORM_SRCS))
PLATFORM_FLAGS := -D WIN32
PLATFORM_FLAGS := -D WIN32 -DUNICODE -D_UNICODE
PLATFORM_LIBS := -mwindows
else
UNAME_S := $(shell uname -s)

View File

@@ -33,8 +33,12 @@ typedef int ci2_bool;
#if defined CI2_WINDOWS
#define CI2_WIN_APIVER 0x0600 // Windows Vista and Windows Server 2008
#define _WIN32_WINNT CI2_WIN_APIVER // Min version
#define NOMINMAX // Dont define min max macros
#ifndef _WIN32_WINNT
#define _WIN32_WINNT CI2_WIN_APIVER // Min version
#endif // _WIN32_WINNT
#define NOMINMAX // Dont define min max macros
#define _CRT_SECURE_NO_WARNINGS // No c warnings
#define _CRT_RAND_S
#define OEMRESOURCE // GUI

View File

@@ -25,6 +25,9 @@ SOFTWARE.
#include "./base/ci2_base.h"
// Forward declaration for window title and class name.
extern const ci2_sys_char *ci2_window_class;
// Opaque type for a window
typedef struct CI2_Window CI2_Window;

View File

@@ -27,6 +27,8 @@ SOFTWARE.
#include <stdlib.h>
#include <string.h>
const ci2_sys_char *ci2_window_class = "Linux CI2 Window";
struct CI2_Window {
Display* display;
Window window;

View File

@@ -23,6 +23,8 @@ SOFTWARE.
#include "../include/ci2.h"
#include <stdlib.h>
const ci2_sys_char *ci2_window_class = "Win32 CI2 Window";
struct CI2_Window {
HWND hwnd;
ci2_bool should_close;
@@ -42,14 +44,14 @@ CI2_Window* platform_create_window(const ci2_sys_char* title, int width, int hei
WNDCLASS wc = {0};
wc.lpfnWndProc = window_proc;
wc.hInstance = GetModuleHandle(NULL);
wc.lpszClassName = "CI2_WindowClass";
wc.lpszClassName = L"CI2_WindowClass";
RegisterClass(&wc);
class_registered = true;
}
HWND hwnd = CreateWindowEx(
0,
"CI2_WindowClass",
ci2_window_class,
title,
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT,

View File

@@ -24,23 +24,17 @@
#include "../include/ci2.h"
#ifdef CI2_WINDOWS
#ifdef CI2_GUI
/* CI2_WINDOWS CI2_GUI Entry */
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
(void)hPrevInstance; // unused
(void)lpCmdLine; // unused
// 1) Initialize ci2 (no-op in your implementation but call for symmetry)
if (!ci2_init()) {
MessageBoxA(NULL, "ci2_init failed", "Error", MB_OK | MB_ICONERROR);
return EXIT_FAILURE;
}
// 2) Create a window via the ci2 abstraction.
// Provide title and size; ci2_create_window returns a heap-allocated ci2Window*.
CI2_Window* window = ci2_create_window("Example App", 800, 600);
CI2_Window* window = ci2_create_window(ci2_window_class, 800, 600);
if (!window) {
MessageBoxA(NULL, "ci2_create_window failed", "Error", MB_OK | MB_ICONERROR);
ci2_shutdown();
@@ -65,35 +59,16 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
ci2_destroy_window(window);
ci2_shutdown();
// 6) Optional: retrieve exit code from any posted WM_QUIT message.
// Use PeekMessage/GetMessage to obtain the final WM_QUIT wParam if you need it.
// For simplicity return 0.
return 0;
}
}
#else
/* CI2_WINDOWS NON_GUI Entry*/
int wmain(int argc, ci2_sys_char *argv[])
{
/* Replace with actual console startup code */
wprintf(L"Starting console app (wmain). argc=%d\n", argc);
for (int i = 0; i < argc; ++i) {
wprintf(L"argv[%d]=%ls\n", i, argv[i]);
}
return 0;
}
#endif /* CI2_GUI && CI2_Windows*/
#else /* non-Windows (Linux, macOS, etc.) */
#if CI2_GUI
int main(int argc, ci2_sys_char *argv[])
{
UNUSED(argc);
UNUSED(argv);
if (!ci2_init()) return 1;
CI2_Window* window = ci2_create_window("Hello", 800, 600);
CI2_Window* window = ci2_create_window(ci2_window_class, 800, 600);
if (!window) return 1;
while (ci2_poll_events(window)) {
@@ -103,16 +78,5 @@ int main(int argc, ci2_sys_char *argv[])
ci2_destroy_window(window);
ci2_shutdown();
return 0;
}
#else
int main(int argc, ci2_sys_char *argv[])
{
return ci2_main(argc,argv);
}
#endif
#endif /* CI2_WINDOWS */