Skip to content

Commit

Permalink
Add raygui
Browse files Browse the repository at this point in the history
  • Loading branch information
pfeodrippe committed Aug 18, 2024
1 parent 4080e39 commit ebabb02
Show file tree
Hide file tree
Showing 9 changed files with 30,211 additions and 34,484 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@
[submodule "cimgui"]
path = cimgui
url = https://github.com/cimgui/cimgui.git
[submodule "raygui"]
path = raygui
url = https://github.com/raysan5/raygui.git
32 changes: 31 additions & 1 deletion bin/jextract-libs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -259,33 +259,63 @@ echo "Extracting Raylib"

cd raylib/src && \
make clean && \
RAYLIB_LIBTYPE=SHARED RAYMATH_IMPLEMENTATION=TRUE make PLATFORM=PLATFORM_DESKTOP && \
RAYLIB_LIBTYPE=SHARED RAYMATH_IMPLEMENTATION=TRUE make PLATFORM=PLATFORM_DESKTOP RAYLIB_MODULE_RAYGUI=TRUE && \
cd - && \
cp "raylib/src/${VYBE_LIB_PREFIX}raylib.$VYBE_EXTENSION" native

$VYBE_GCC \
-shared \
bin/vybe_raylib.c \
-I raylib/src \
-I raygui/src \
-o "native/${VYBE_LIB_PREFIX}vybe_raylib.$VYBE_EXTENSION" $VYBE_GCC_END $VYBE_GCC_RAYLIB

if [[ $VYBE_EXTENSION == "dll" ]]; then
# As the generated java code is huge by default because of some transitive libs,
# we have to filter it. So we do a jextract dump.
$VYBE_JEXTRACT \
-D_WIN32=TRUE \
-DRAYMATH_IMPLEMENTATION=TRUE \
-DBUILD_LIBTYPE_SHARED=TRUE \
-I raygui/src \
-I raylib/src \
--dump-includes .vybe-raylib-includes-original.txt \
bin/vybe_raylib.c

grep -e raylib.h -e rlgl.h -e raymath.h -e raygui.h .vybe-raylib-includes-original.txt > .vybe-raylib-includes.txt

$VYBE_JEXTRACT @.vybe-raylib-includes.txt \
--use-system-load-library \
--library raylib \
--library vybe_raylib \
-D_WIN32=TRUE \
-DRAYMATH_IMPLEMENTATION=TRUE \
-DBUILD_LIBTYPE_SHARED=TRUE \
-I raygui/src \
-I raylib/src \
--output src-java \
--header-class-name raylib \
-t org.vybe.raylib bin/vybe_raylib.c
else
# As the generated java code is huge by default because of some transitive libs,
# we have to filter it. So we do a jextract dump.
$VYBE_JEXTRACT \
-DRAYMATH_IMPLEMENTATION=TRUE \
-DBUILD_LIBTYPE_SHARED=TRUE \
-I raygui/src \
-I raylib/src \
--dump-includes .vybe-raylib-includes-original.txt \
bin/vybe_raylib.c

grep -e raylib.h -e rlgl.h -e raymath.h -e raygui.h .vybe-raylib-includes-original.txt > .vybe-raylib-includes.txt

$VYBE_JEXTRACT @.vybe-raylib-includes.txt \
-l ":${VYBE_TMP_PREFIX}/tmp/pfeodrippe_vybe_native/${VYBE_LIB_PREFIX}raylib.$VYBE_EXTENSION" \
-l ":${VYBE_TMP_PREFIX}/tmp/pfeodrippe_vybe_native/${VYBE_LIB_PREFIX}vybe_raylib.$VYBE_EXTENSION" \
-DRAYMATH_IMPLEMENTATION=TRUE \
-DBUILD_LIBTYPE_SHARED=TRUE \
-I raygui/src \
-I raylib/src \
--output src-java \
--header-class-name raylib \
-t org.vybe.raylib bin/vybe_raylib.c
Expand Down
3 changes: 2 additions & 1 deletion bin/vybe_raylib.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#define RAYGUI_IMPLEMENTATION TRUE
#include "../raylib/src/raylib.h"
#include "../raylib/src/rlgl.h"
#include "../raylib/src/raymath.h"
#include "../raylib/src/raylib.h"
#include "../raygui/src/raygui.h"
1 change: 1 addition & 0 deletions raygui
Submodule raygui added at 33f165
219 changes: 219 additions & 0 deletions src-java/org/vybe/raylib/GuiStyleProp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
// Generated by jextract

package org.vybe.raylib;

import java.lang.invoke.*;
import java.lang.foreign.*;
import java.nio.ByteOrder;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

import static java.lang.foreign.ValueLayout.*;
import static java.lang.foreign.MemoryLayout.PathElement.*;

/**
* {@snippet lang=c :
* struct GuiStyleProp {
* unsigned short controlId;
* unsigned short propertyId;
* int propertyValue;
* }
* }
*/
public class GuiStyleProp {

GuiStyleProp() {
// Should not be called directly
}

private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
raylib.C_SHORT.withName("controlId"),
raylib.C_SHORT.withName("propertyId"),
raylib.C_INT.withName("propertyValue")
).withName("GuiStyleProp");

/**
* The layout of this struct
*/
public static final GroupLayout layout() {
return $LAYOUT;
}

private static final OfShort controlId$LAYOUT = (OfShort)$LAYOUT.select(groupElement("controlId"));

/**
* Layout for field:
* {@snippet lang=c :
* unsigned short controlId
* }
*/
public static final OfShort controlId$layout() {
return controlId$LAYOUT;
}

private static final long controlId$OFFSET = 0;

/**
* Offset for field:
* {@snippet lang=c :
* unsigned short controlId
* }
*/
public static final long controlId$offset() {
return controlId$OFFSET;
}

/**
* Getter for field:
* {@snippet lang=c :
* unsigned short controlId
* }
*/
public static short controlId(MemorySegment struct) {
return struct.get(controlId$LAYOUT, controlId$OFFSET);
}

/**
* Setter for field:
* {@snippet lang=c :
* unsigned short controlId
* }
*/
public static void controlId(MemorySegment struct, short fieldValue) {
struct.set(controlId$LAYOUT, controlId$OFFSET, fieldValue);
}

private static final OfShort propertyId$LAYOUT = (OfShort)$LAYOUT.select(groupElement("propertyId"));

/**
* Layout for field:
* {@snippet lang=c :
* unsigned short propertyId
* }
*/
public static final OfShort propertyId$layout() {
return propertyId$LAYOUT;
}

private static final long propertyId$OFFSET = 2;

/**
* Offset for field:
* {@snippet lang=c :
* unsigned short propertyId
* }
*/
public static final long propertyId$offset() {
return propertyId$OFFSET;
}

/**
* Getter for field:
* {@snippet lang=c :
* unsigned short propertyId
* }
*/
public static short propertyId(MemorySegment struct) {
return struct.get(propertyId$LAYOUT, propertyId$OFFSET);
}

/**
* Setter for field:
* {@snippet lang=c :
* unsigned short propertyId
* }
*/
public static void propertyId(MemorySegment struct, short fieldValue) {
struct.set(propertyId$LAYOUT, propertyId$OFFSET, fieldValue);
}

private static final OfInt propertyValue$LAYOUT = (OfInt)$LAYOUT.select(groupElement("propertyValue"));

/**
* Layout for field:
* {@snippet lang=c :
* int propertyValue
* }
*/
public static final OfInt propertyValue$layout() {
return propertyValue$LAYOUT;
}

private static final long propertyValue$OFFSET = 4;

/**
* Offset for field:
* {@snippet lang=c :
* int propertyValue
* }
*/
public static final long propertyValue$offset() {
return propertyValue$OFFSET;
}

/**
* Getter for field:
* {@snippet lang=c :
* int propertyValue
* }
*/
public static int propertyValue(MemorySegment struct) {
return struct.get(propertyValue$LAYOUT, propertyValue$OFFSET);
}

/**
* Setter for field:
* {@snippet lang=c :
* int propertyValue
* }
*/
public static void propertyValue(MemorySegment struct, int fieldValue) {
struct.set(propertyValue$LAYOUT, propertyValue$OFFSET, fieldValue);
}

/**
* Obtains a slice of {@code arrayParam} which selects the array element at {@code index}.
* The returned segment has address {@code arrayParam.address() + index * layout().byteSize()}
*/
public static MemorySegment asSlice(MemorySegment array, long index) {
return array.asSlice(layout().byteSize() * index);
}

/**
* The size (in bytes) of this struct
*/
public static long sizeof() { return layout().byteSize(); }

/**
* Allocate a segment of size {@code layout().byteSize()} using {@code allocator}
*/
public static MemorySegment allocate(SegmentAllocator allocator) {
return allocator.allocate(layout());
}

/**
* Allocate an array of size {@code elementCount} using {@code allocator}.
* The returned segment has size {@code elementCount * layout().byteSize()}.
*/
public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) {
return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout()));
}

/**
* Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
* The returned segment has size {@code layout().byteSize()}
*/
public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer<MemorySegment> cleanup) {
return reinterpret(addr, 1, arena, cleanup);
}

/**
* Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
* The returned segment has size {@code elementCount * layout().byteSize()}
*/
public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer<MemorySegment> cleanup) {
return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup);
}
}

Loading

0 comments on commit ebabb02

Please sign in to comment.