Skip to content

Commit

Permalink
again
Browse files Browse the repository at this point in the history
  • Loading branch information
planetis-m committed Oct 25, 2024
1 parent 219a026 commit 81c92af
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 44 deletions.
10 changes: 5 additions & 5 deletions src/raylib.nim
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ const

{.push callconv: cdecl, header: "naylib.h".}
proc initWindowImpl(width: int32, height: int32, title: cstring) {.importc: "InitWindow", sideEffect.}
proc closeWindow*() {.importc: "CloseWindow", sideEffect.}
proc closeWindow*() {.importc: "rlCloseWindow", sideEffect.}
## Close window and unload OpenGL context
proc windowShouldClose*(): bool {.importc: "WindowShouldClose", sideEffect.}
## Check if application should close (KEY_ESCAPE pressed or windows close icon clicked)
Expand Down Expand Up @@ -885,7 +885,7 @@ proc enableEventWaiting*() {.importc: "EnableEventWaiting", sideEffect.}
## Enable waiting for events on EndDrawing(), no automatic event polling
proc disableEventWaiting*() {.importc: "DisableEventWaiting", sideEffect.}
## Disable waiting for events on EndDrawing(), automatic events polling
proc showCursor*() {.importc: "ShowCursor", sideEffect.}
proc showCursor*() {.importc: "rlShowCursor", sideEffect.}
## Shows cursor
proc hideCursor*() {.importc: "HideCursor", sideEffect.}
## Hides cursor
Expand Down Expand Up @@ -1231,7 +1231,7 @@ func checkCollisionLines*(startPos1: Vector2, endPos1: Vector2, startPos2: Vecto
## Check the collision between two lines defined by two points each, returns collision point by reference
func getCollisionRec*(rec1: Rectangle, rec2: Rectangle): Rectangle {.importc: "GetCollisionRec".}
## Get collision rectangle for two rectangles collision
proc loadImageImpl(fileName: cstring): Image {.importc: "LoadImage", sideEffect.}
proc loadImageImpl(fileName: cstring): Image {.importc: "rlLoadImage", sideEffect.}
proc loadImageRawImpl(fileName: cstring, width: int32, height: int32, format: PixelFormat, headerSize: int32): Image {.importc: "LoadImageRaw", sideEffect.}
proc loadImageAnimImpl(fileName: cstring, frames: out int32): Image {.importc: "LoadImageAnim", sideEffect.}
proc loadImageAnimFromMemoryImpl(fileType: cstring, fileData: ptr UncheckedArray[uint8], dataSize: int32, frames: ptr UncheckedArray[int32]): Image {.importc: "LoadImageAnimFromMemory", sideEffect.}
Expand Down Expand Up @@ -1433,8 +1433,8 @@ proc unloadFont(font: Font) {.importc: "UnloadFont", sideEffect.}
proc exportFontAsCodeImpl(font: Font, fileName: cstring): bool {.importc: "ExportFontAsCode", sideEffect.}
proc drawFPS*(posX: int32, posY: int32) {.importc: "DrawFPS", sideEffect.}
## Draw current FPS
proc drawTextImpl(text: cstring, posX: int32, posY: int32, fontSize: int32, color: Color) {.importc: "DrawText", sideEffect.}
proc drawTextImpl(font: Font, text: cstring, position: Vector2, fontSize: float32, spacing: float32, tint: Color) {.importc: "DrawTextEx", sideEffect.}
proc drawTextImpl(text: cstring, posX: int32, posY: int32, fontSize: int32, color: Color) {.importc: "rlDrawText", sideEffect.}
proc drawTextImpl(font: Font, text: cstring, position: Vector2, fontSize: float32, spacing: float32, tint: Color) {.importc: "rlDrawTextEx", sideEffect.}
proc drawTextImpl(font: Font, text: cstring, position: Vector2, origin: Vector2, rotation: float32, fontSize: float32, spacing: float32, tint: Color) {.importc: "DrawTextPro", sideEffect.}
proc drawTextCodepoint*(font: Font, codepoint: Rune, position: Vector2, fontSize: float32, tint: Color) {.importc: "DrawTextCodepoint", sideEffect.}
## Draw one character (codepoint)
Expand Down
91 changes: 52 additions & 39 deletions src/raylib/naylib.h
Original file line number Diff line number Diff line change
@@ -1,64 +1,77 @@
// Only redefine if the Windows names aren't already defined
#ifndef RECTANGLE_DEFINED
#define Rectangle rlRectangle
#define RECTANGLE_DEFINED
// raylib_wrapper.h
#pragma once // Prevent multiple inclusions

// First, save any existing Windows macros/definitions if they exist
#ifdef CloseWindow
#define PREV_CloseWindow CloseWindow
#undef CloseWindow
#endif

#ifndef CLOSEWINDOW_DEFINED
#define CloseWindow rlCloseWindow
#define CLOSEWINDOW_DEFINED
#ifdef Rectangle
#define PREV_Rectangle Rectangle
#undef Rectangle
#endif

#ifndef SHOWCURSOR_DEFINED
#define ShowCursor rlShowCursor
#define SHOWCURSOR_DEFINED
#ifdef ShowCursor
#define PREV_ShowCursor ShowCursor
#undef ShowCursor
#endif

#ifndef LOADIMAGE_DEFINED
#define LoadImage rlLoadImage
#define LOADIMAGE_DEFINED
#ifdef LoadImage
#define PREV_LoadImage LoadImage
#undef LoadImage
#endif

#ifndef DRAWTEXT_DEFINED
#define DrawText rlDrawText
#define DRAWTEXT_DEFINED
#ifdef DrawText
#define PREV_DrawText DrawText
#undef DrawText
#endif

#ifndef DRAWTEXTEX_DEFINED
#define DrawTextEx rlDrawTextEx
#define DRAWTEXTEX_DEFINED
#ifdef DrawTextEx
#define PREV_DrawTextEx DrawTextEx
#undef DrawTextEx
#endif

// Include raylib after setting up the defines
// Include raylib with our names
#include "raylib.h"

// Undefine to restore original Windows API names if necessary
#ifdef RECTANGLE_DEFINED
#undef Rectangle
#undef RECTANGLE_DEFINED
#define rlRectangle Rectangle
// Create our wrapped versions with unique names
static inline void rlCloseWindow(void) { CloseWindow(); }
static inline void rlShowCursor(void) { ShowCursor(); }
static inline Image rlLoadImage(const char* fileName) { return LoadImage(fileName); }
static inline void rlDrawText(const char* text, int x, int y, int fontSize, Color color) { DrawText(text, x, y, fontSize, color); }
static inline void rlDrawTextEx(Font font, const char* text, Vector2 position, float fontSize, float spacing, Color tint) {
DrawTextEx(font, text, position, fontSize, spacing, tint);
}

// Restore previous Windows definitions if they existed
#ifdef PREV_CloseWindow
#define CloseWindow PREV_CloseWindow
#undef PREV_CloseWindow
#endif

#ifdef CLOSEWINDOW_DEFINED
#undef CloseWindow
#undef CLOSEWINDOW_DEFINED
#ifdef PREV_Rectangle
#define Rectangle PREV_Rectangle
#undef PREV_Rectangle
#endif

#ifdef SHOWCURSOR_DEFINED
#undef ShowCursor
#undef SHOWCURSOR_DEFINED
#ifdef PREV_ShowCursor
#define ShowCursor PREV_ShowCursor
#undef PREV_ShowCursor
#endif

#ifdef LOADIMAGE_DEFINED
#undef LoadImage
#undef LOADIMAGE_DEFINED
#ifdef PREV_LoadImage
#define LoadImage PREV_LoadImage
#undef PREV_LoadImage
#endif

#ifdef DRAWTEXT_DEFINED
#undef DrawText
#undef DRAWTEXT_DEFINED
#ifdef PREV_DrawText
#define DrawText PREV_DrawText
#undef PREV_DrawText
#endif

#ifdef DRAWTEXTEX_DEFINED
#undef DrawTextEx
#undef DRAWTEXTEX_DEFINED
#ifdef PREV_DrawTextEx
#define DrawTextEx PREV_DrawTextEx
#undef PREV_DrawTextEx
#endif

0 comments on commit 81c92af

Please sign in to comment.