diff --git a/c/raylib/_demo/raylibdemo/raydemo.go b/c/raylib/_demo/raylibdemo/raydemo.go new file mode 100644 index 00000000..62baabc1 --- /dev/null +++ b/c/raylib/_demo/raylibdemo/raydemo.go @@ -0,0 +1,18 @@ +package main + +import ( + "github.com/goplus/llgo/c" + "github.com/goplus/llgo/c/raylib" +) + +func main() { + const screenWidth = 800 + const screenHeight = 450 + raylib.InitWindow(screenWidth, screenHeight, c.Str("Raylib DEMO")) + for !raylib.WindowShouldClose() { + raylib.BeginDrawing() + raylib.ClearBackground(raylib.RAYWHITE) + raylib.DrawRectangle(screenWidth/2-50, screenHeight/2-50, 100, 100, raylib.BLUE) + raylib.EndDrawing() + } +} diff --git a/c/raylib/llgo_autogen.lla b/c/raylib/llgo_autogen.lla new file mode 100644 index 00000000..63425947 Binary files /dev/null and b/c/raylib/llgo_autogen.lla differ diff --git a/c/raylib/raylib.go b/c/raylib/raylib.go index 8e2bbba9..d5dba1ca 100644 --- a/c/raylib/raylib.go +++ b/c/raylib/raylib.go @@ -53,9 +53,39 @@ type Vector4 struct { type Quaternion = Vector4 // Color, 4 components, R8G8B8A8 (32bit) -type Color struct { - R, G, B, A uint8 -} +// R, G, B, A uint8 +type Color uint32 + +const ( + LIGHTGRAY = Color(200 | 200<<8 | 200<<16 | 255<<24) // Light Gray + GRAY = Color(130 | 130<<8 | 130<<16 | 255<<24) // Gray + DARKGRAY = Color(80 | 80<<8 | 80<<16 | 255<<24) // Dark Gray + YELLOW = Color(253 | 249<<8 | 0<<16 | 255<<24) // Yellow + GOLD = Color(255 | 203<<8 | 0<<16 | 255<<24) // Gold + ORANGE = Color(255 | 161<<8 | 0<<16 | 255<<24) // Orange + PINK = Color(255 | 109<<8 | 194<<16 | 255<<24) // Pink + RED = Color(230 | 41<<8 | 55<<16 | 255<<24) // Red + MAROON = Color(190 | 33<<8 | 55<<16 | 255<<24) // Maroon + GREEN = Color(0 | 228<<8 | 48<<16 | 255<<24) // Green + LIME = Color(0 | 158<<8 | 47<<16 | 255<<24) // Lime + DARKGREEN = Color(0 | 117<<8 | 44<<16 | 255<<24) // Dark Green + SKYBLUE = Color(102 | 191<<8 | 255<<16 | 255<<24) // Sky Blue + BLUE = Color(0 | 121<<8 | 241<<16 | 255<<24) // Blue + + DARKBLUE = Color(0 | 82<<8 | 172<<16 | 255<<24) // Dark Blue + PURPLE = Color(200 | 122<<8 | 255<<16 | 255<<24) // Purple + VIOLET = Color(135 | 60<<8 | 190<<16 | 255<<24) // Violet + DARKPURPLE = Color(112 | 31<<8 | 126<<16 | 255<<24) // Dark Purple + BEIGE = Color(211 | 176<<8 | 131<<16 | 255<<24) // Beige + BROWN = Color(127 | 106<<8 | 79<<16 | 255<<24) // Brown + DARKBROWN = Color(76 | 63<<8 | 47<<16 | 255<<24) // Dark Brown + + WHITE = Color(255 | 255<<8 | 255<<16 | 255<<24) // White + BLACK = Color(0 | 0<<8 | 0<<16 | 255<<24) // Black + BLANK = Color(0 | 0<<8 | 0<<16 | 0<<24) // Blank (Transparent) + MAGENTA = Color(255 | 0<<8 | 255<<16 | 255<<24) // Magenta + RAYWHITE = Color(245 | 245<<8 | 245<<16 | 255<<24) // My own White (raylib logo) +) // Image, pixel data stored in CPU memory (RAM) type Image struct { @@ -297,3 +327,10 @@ func BeginScissorMode(x, y, width, height c.Int) func EndScissorMode() // ----------------------------------------------------------------------------- + +// Draw a color-filled rectangle +// +//go:linkname DrawRectangle C.DrawRectangle +func DrawRectangle(posX, posY, width, height c.Int, color Color) + +// ----------------------------------------------------------------------------- diff --git a/chore/_xtool/astdump/astdump.cpp b/chore/_xtool/astdump/astdump.cpp new file mode 100644 index 00000000..e466fce8 --- /dev/null +++ b/chore/_xtool/astdump/astdump.cpp @@ -0,0 +1,63 @@ +#include +#include +#include + +CXChildVisitResult visit(CXCursor c, CXCursor parent, CXClientData client_data); + +void printAST(CXCursor cursor, unsigned int depth = 0) { + CXString cursorKind = clang_getCursorKindSpelling(clang_getCursorKind(cursor)); + CXString cursorSpelling = clang_getCursorSpelling(cursor); + + for (unsigned int i = 0; i < depth; ++i) { + std::cout << " "; + } + + std::cout << clang_getCString(cursorKind) << ": " + << clang_getCString(cursorSpelling) << std::endl; + + clang_disposeString(cursorKind); + clang_disposeString(cursorSpelling); + + CXCursor child; + clang_visitChildren( + cursor, + visit, + &depth + ); +} + +CXChildVisitResult visit(CXCursor c, CXCursor parent, CXClientData client_data) { + unsigned int* depth = (unsigned int*)client_data; + printAST(c, *depth + 1); + return CXChildVisit_Continue; +} + +int main(int argc, char* argv[]) { + if (argc < 2) { + std::cerr << "Usage: " << argv[0] << " " << std::endl; + return 1; + } + + CXIndex index = clang_createIndex(0, 0); + CXTranslationUnit unit = clang_parseTranslationUnit( + index, + argv[1], + nullptr, 0, + nullptr, 0, + CXTranslationUnit_None + ); + + if (unit == nullptr) { + std::cerr << "Unable to parse translation unit. Quitting." << std::endl; + return 1; + } + + CXCursor cursor = clang_getTranslationUnitCursor(unit); + std::cout << "AST for " << argv[1] << ":" << std::endl; + printAST(cursor); + + clang_disposeTranslationUnit(unit); + clang_disposeIndex(index); + + return 0; +} \ No newline at end of file diff --git a/chore/_xtool/astdump/build.sh b/chore/_xtool/astdump/build.sh new file mode 100755 index 00000000..d255f327 --- /dev/null +++ b/chore/_xtool/astdump/build.sh @@ -0,0 +1,2 @@ +export LLVM_DIR=/opt/homebrew/Cellar/llvm@17/17.0.6 +clang -L$LLVM_DIR/lib -lclang -lc++ -I$LLVM_DIR/include astdump.cpp