diff --git a/README.md b/README.md index 26f671d..f0497cd 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,9 @@ # raylib-d [![DUB](https://img.shields.io/dub/v/raylib-d?style=for-the-badge)](https://code.dlang.org/packages/raylib-d) (static) D bindings for [raylib](https://www.raylib.com/), a simple and easy-to-use library to learn videogames programming. +# Differences from Raylib +All functions, types, and enum values are the same as in upstream Raylib. The only difference is that the `zoom` property of the `Camera2D` struct is initially set to `1.0f` instead of `0.0f`. + # Installation ## Adding the dependency diff --git a/dub.json b/dub.json index f5a92b9..d99b348 100644 --- a/dub.json +++ b/dub.json @@ -5,19 +5,19 @@ "authors": [ "ONROUNDIT" ], - "configurations" : [ - { - "name": "library" - }, - { - "name": "unittest", - "versions" : ["raylib_test"], - "libs" : ["raylib"], - "lflags-posix": ["-L."], - "lflags-osx": ["-rpath", "@executable_path/"], - "lflags-linux" : ["-rpath=$$ORIGIN"] - } - ], + "configurations" : [ + { + "name": "library" + }, + { + "name": "unittest", + "versions" : ["raylib_test"], + "libs" : ["raylib"], + "lflags-posix": ["-L."], + "lflags-osx": ["-rpath", "@executable_path/"], + "lflags-linux" : ["-rpath=$$ORIGIN"] + } + ], "copyright": "Copyright (c) Ramon Santamaria (@raysan5), Petro Romanovych (@onroundit), Jan Hoenig (@m3m0ry), Steven Schveighoffer (@schveiguy), Liam McGillivray (@LiamM32)", "excludedSourceFiles": ["source/rlgl.d", "source/raymath.d", "source/easings.d", "source/raymathext.d", "source/raylib_types.d"], "targetType": "sourceLibrary", diff --git a/source/raylib/package.d b/source/raylib/package.d index ddeb78f..5f73d4c 100644 --- a/source/raylib/package.d +++ b/source/raylib/package.d @@ -270,15 +270,6 @@ struct Camera3D alias Camera = Camera3D; // Camera type fallback, defaults to Camera3D -// Camera2D, defines position/orientation in 2d space -struct Camera2D -{ - Vector2 offset; // Camera offset (displacement from target) - Vector2 target; // Camera target (rotation and zoom origin) - float rotation; // Camera rotation in degrees - float zoom; // Camera zoom (scaling), should be 1.0f by default -} - // Mesh, vertex data and vao/vbo struct Mesh { diff --git a/source/raylib/raylib_types.d b/source/raylib/raylib_types.d index d1f4199..a294bc0 100644 --- a/source/raylib/raylib_types.d +++ b/source/raylib/raylib_types.d @@ -2,6 +2,9 @@ module raylib.raylib_types; import raylib; +debug import std.stdio; + +@safe: // Vector2 type struct Vector2 @@ -54,6 +57,17 @@ struct Matrix float m15 = 0.0f; } +// Camera2D, defines position/orientation in 2d space +struct Camera2D +{ + + Vector2 offset; // Camera offset (displacement from target) + Vector2 target; // Camera target (rotation and zoom origin) + float rotation; // Camera rotation in degrees + // Warning: In Raylib, & previous versions of Raylib-D, `zoom` is initially `0.0f`. + float zoom = 1f; // Camera zoom (scaling), should be 1.0f by default +} + // Rectangle type struct Rectangle { @@ -64,7 +78,19 @@ struct Rectangle alias w = width; alias h = height; - Vector2 origin() { // Rectangle function exclusive to raylib-d + // The following rectangle functions are exclusive to Raylib-D. + + float top() const {return y;} + float bottom() const {return y + height;} + float left() const {return x;} + float right() const {return x + width;} + + void top(const float yPosition) {y = yPosition;} + void bottom(const float yPosition) {y = yPosition - height;} + void left(const float xPosition) {x = xPosition;} + void right(const float xPosition) {x = xPosition - width;} + + Vector2 origin() { return Vector2(x, y); } alias position = origin; @@ -102,6 +128,8 @@ struct Rectangle result.opOpAssign!op(offset); return result; } + + Vector2 opCast(T)() if (is(T==Vector2)) => origin(); } enum Colors @@ -134,7 +162,7 @@ enum Colors BLACK = Color(0, 0, 0, 255), // Black BLANK = Color(0, 0, 0, 0), // Blank (Transparent) MAGENTA = Color(255, 0, 255, 255), // Magenta - RAYWHITE = Color(245, 245, 245, 255), // My own White (raylib logo) + RAYWHITE = Color(245, 245, 245, 255), // Grey-white colour from Raylib logo } unittest @@ -147,7 +175,10 @@ unittest float height = 20.0f; Rectangle rect = Rectangle(x, y, width, height); assert(rect.origin.x == 543.3f, "`rect.origin.x` should be 543.3, not "~to!string(rect.origin.x)); + assert(rect.left == 543.3f, "`rect.left` should be 543.3, not "~to!string(rect.left)); + assert(rect.right == 593.3f, "`rect.right` should be 593.3, not "~to!string(rect.right)); assert(rect.origin.y == 235.9f, "`rect.centre.y` should be 235.9, not "~to!string(rect.origin.y)); + assert(rect.bottom == 255.9f, "`rect.bottom` should be 255.9, not "~to!string(rect.bottom)); assert(rect.dimensions == Vector2(50.0f, 20.0f)); assert(rect.topLeft == Vector2(x:543.3f, y:235.9f), "`rect.topLeft` should be Vector2(543.3, 235.9), not "~to!string(rect.topLeft)); assert(rect.topRight.x == 593.3f); @@ -165,4 +196,11 @@ unittest rect -= Vector2(4.5f, 2.3f); assert(rect.x == 24.5f, "`rect.x` should be 24.5f. Instead it is "~to!string(rect.x)); assert(rect.y == 19.0f, "`rect.y` should be 20.7f. Instead it is "~to!string(rect.y)); + + rect.right = 100f; + rect.bottom = 60f; + assert(rect.x == 50.0f); + assert(rect.left == 50.0f); + assert(rect.y == 40.0f); + assert(rect.top == 40.0f); }