From 7a14562f2537fa55966c885b7cff203f55f195ed Mon Sep 17 00:00:00 2001 From: TSnake41 Date: Tue, 31 Mar 2020 21:32:36 +0200 Subject: [PATCH] Add various raylib modules. --- makefile | 7 +- src/raylib.lua | 160 ++++++++++++++++++++++++++++++++++++++++++++++ tools/camera.h | 6 ++ tools/easings.h | 28 ++++++++ tools/genbind.lua | 3 +- tools/gestures.h | 2 + tools/raygui.h | 59 +++++++++++++++++ tools/raymath.h | 79 +++++++++++++++++++++++ 8 files changed, 340 insertions(+), 4 deletions(-) create mode 100644 tools/camera.h create mode 100644 tools/easings.h create mode 100644 tools/gestures.h create mode 100644 tools/raygui.h create mode 100644 tools/raymath.h diff --git a/makefile b/makefile index 2bbe645..5c6c3d9 100644 --- a/makefile +++ b/makefile @@ -4,10 +4,10 @@ LDFLAGS := -O2 -s -lm AR ?= ar LUA ?= luajit/src/luajit -CFLAGS += -Iluajit/src -Iraylib/src +CFLAGS += -Iluajit/src -Iraylib/src -Iraygui/src LDFLAGS += -Lluajit/src -lluajit -Lraylib/src -lraylib -MODULES := rlgl physac +MODULES := raymath rlgl camera easings gestures physac raygui ifeq ($(OS),Windows_NT) LDFLAGS += -lopengl32 -lgdi32 -lwinmm -static @@ -53,7 +53,8 @@ src/autogen/builder.c: src/raylua_builder.lua $(LUA) tools/lua2str.lua $@ raylua_builder_lua $^ clean: - rm -rf raylua_s raylua_e src/raylua_e.o src/raylua_s.o src/raylua.o src/autogen/*.c src/lib/miniz.o + rm -rf raylua_s raylua_e src/raylua_e.o src/raylua_s.o src/raylua.o \ + src/raylua_builder.o src/autogen/*.c src/lib/miniz.o $(MAKE) -C luajit clean $(MAKE) -C raylib/src clean diff --git a/src/raylib.lua b/src/raylib.lua index d82f49f..b31d226 100644 --- a/src/raylib.lua +++ b/src/raylib.lua @@ -596,6 +596,12 @@ ffi.cdef [[ typedef void (*TraceLogCallback)(int logType, const char *text, va_list args); ]] +-- raymath cdef +ffi.cdef [[ + typedef struct float3 { float v[3]; } float3; + typedef struct float16 { float v[16]; } float16; +]] + -- Physac cdef ffi.cdef [[ typedef struct PhysicsBodyData *PhysicsBody; @@ -648,6 +654,160 @@ ffi.cdef [[ } PhysicsBodyData; ]] +-- gestures cdef +ffi.cdef [[ + typedef enum { TOUCH_UP, TOUCH_DOWN, TOUCH_MOVE } TouchAction; + + typedef struct { + int touchAction; + int pointCount; + int pointerId[4]; + Vector2 position[4]; + } GestureEvent; +]] + +-- raygui cdef +ffi.cdef [[ + typedef struct GuiStyleProp { + unsigned short controlId; + unsigned short propertyId; + int propertyValue; + } GuiStyleProp; + + typedef enum { + GUI_STATE_NORMAL = 0, + GUI_STATE_FOCUSED, + GUI_STATE_PRESSED, + GUI_STATE_DISABLED, + } GuiControlState; + + typedef enum { + GUI_TEXT_ALIGN_LEFT = 0, + GUI_TEXT_ALIGN_CENTER, + GUI_TEXT_ALIGN_RIGHT, + } GuiTextAlignment; + + typedef enum { + DEFAULT = 0, + LABEL, + BUTTON, + TOGGLE, + SLIDER, + PROGRESSBAR, + CHECKBOX, + COMBOBOX, + DROPDOWNBOX, + TEXTBOX, + VALUEBOX, + SPINNER, + LISTVIEW, + COLORPICKER, + SCROLLBAR, + STATUSBAR + } GuiControl; + + typedef enum { + BORDER_COLOR_NORMAL = 0, + BASE_COLOR_NORMAL, + TEXT_COLOR_NORMAL, + BORDER_COLOR_FOCUSED, + BASE_COLOR_FOCUSED, + TEXT_COLOR_FOCUSED, + BORDER_COLOR_PRESSED, + BASE_COLOR_PRESSED, + TEXT_COLOR_PRESSED, + BORDER_COLOR_DISABLED, + BASE_COLOR_DISABLED, + TEXT_COLOR_DISABLED, + BORDER_WIDTH, + TEXT_PADDING, + TEXT_ALIGNMENT, + RESERVED + } GuiControlProperty; + + typedef enum { + TEXT_SIZE = 16, + TEXT_SPACING, + LINE_COLOR, + BACKGROUND_COLOR, + } GuiDefaultProperty; + + typedef enum { + GROUP_PADDING = 16, + } GuiToggleProperty; + + typedef enum { + SLIDER_WIDTH = 16, + SLIDER_PADDING + } GuiSliderProperty; + + typedef enum { + PROGRESS_PADDING = 16, + } GuiProgressBarProperty; + + typedef enum { + CHECK_PADDING = 16 + } GuiCheckBoxProperty; + + typedef enum { + COMBO_BUTTON_WIDTH = 16, + COMBO_BUTTON_PADDING + } GuiComboBoxProperty; + + typedef enum { + ARROW_PADDING = 16, + DROPDOWN_ITEMS_PADDING + } GuiDropdownBoxProperty; + + typedef enum { + TEXT_INNER_PADDING = 16, + TEXT_LINES_PADDING, + COLOR_SELECTED_FG, + COLOR_SELECTED_BG + } GuiTextBoxProperty; + + typedef enum { + SPIN_BUTTON_WIDTH = 16, + SPIN_BUTTON_PADDING, + } GuiSpinnerProperty; + + typedef enum { + ARROWS_SIZE = 16, + ARROWS_VISIBLE, + SCROLL_SLIDER_PADDING, + SCROLL_SLIDER_SIZE, + SCROLL_PADDING, + SCROLL_SPEED, + } GuiScrollBarProperty; + + typedef enum { + SCROLLBAR_LEFT_SIDE = 0, + SCROLLBAR_RIGHT_SIDE + } GuiScrollBarSide; + + typedef enum { + LIST_ITEMS_HEIGHT = 16, + LIST_ITEMS_PADDING, + SCROLLBAR_WIDTH, + SCROLLBAR_SIDE, + } GuiListViewProperty; + + typedef enum { + COLOR_SELECTOR_SIZE = 16, + HUEBAR_WIDTH, + HUEBAR_PADDING, + HUEBAR_SELECTOR_HEIGHT, + HUEBAR_SELECTOR_OVERFLOW + } GuiColorPickerProperty; + + typedef struct GuiTextBoxState { + int cursor; + int start; + int index; + int select; + } GuiTextBoxState; +]] + -- Load bind entry ffi.cdef [[ struct raylua_bind_entry { diff --git a/tools/camera.h b/tools/camera.h new file mode 100644 index 0000000..7042d5a --- /dev/null +++ b/tools/camera.h @@ -0,0 +1,6 @@ +void SetCameraMode(Camera camera, int mode) +void UpdateCamera(Camera *camera) +void SetCameraPanControl(int panKey) +void SetCameraAltControl(int altKey) +void SetCameraSmoothZoomControl(int szoomKey); +void SetCameraMoveControls(int frontKey, int backKey, int rightKey, int leftKey, int upKey, int downKey); diff --git a/tools/easings.h b/tools/easings.h new file mode 100644 index 0000000..0e9dc28 --- /dev/null +++ b/tools/easings.h @@ -0,0 +1,28 @@ +float EaseLinearNone(float t, float b, float c, float d) +float EaseLinearIn(float t, float b, float c, float d) +float EaseLinearOut(float t, float b, float c, float d) +float EaseLinearInOut(float t,float b, float c, float d) +float EaseSineIn(float t, float b, float c, float d) +float EaseSineOut(float t, float b, float c, float d) +float EaseSineInOut(float t, float b, float c, float d) +float EaseCircIn(float t, float b, float c, float d) +float EaseCircOut(float t, float b, float c, float d) +float EaseCircInOut(float t, float b, float c, float d) +float EaseCubicIn(float t, float b, float c, float d) +float EaseCubicOut(float t, float b, float c, float d) +float EaseCubicInOut(float t, float b, float c, float d) +float EaseQuadIn(float t, float b, float c, float d) +float EaseQuadOut(float t, float b, float c, float d) +float EaseQuadInOut(float t, float b, float c, float d) +float EaseExpoIn(float t, float b, float c, float d) +float EaseExpoOut(float t, float b, float c, float d) +float EaseExpoInOut(float t, float b, float c, float d) +float EaseBackIn(float t, float b, float c, float d) +float EaseBackOut(float t, float b, float c, float d) +float EaseBackInOut(float t, float b, float c, float d) +float EaseBounceOut(float t, float b, float c, float d) +float EaseBounceIn(float t, float b, float c, float d) +float EaseBounceInOut(float t, float b, float c, float d) +float EaseElasticIn(float t, float b, float c, float d) +float EaseElasticOut(float t, float b, float c, float d) +float EaseElasticInOut(float t, float b, float c, float d) diff --git a/tools/genbind.lua b/tools/genbind.lua index adaca25..a03f189 100644 --- a/tools/genbind.lua +++ b/tools/genbind.lua @@ -13,7 +13,8 @@ local structs = { "Material", "Model", "Transform", "BoneInfo", "ModelAnimation", "Ray", "RayHitInfo", "BoundingBox", "Wave", "Sound", "Music", "AudioStream", "VrDeviceInfo", "Camera3D", "RenderTexture2D", - "TextureCubemap", "TraceLogCallback", "PhysicsBody" + "TextureCubemap", "TraceLogCallback", "PhysicsBody", + "GestureEvent", "GuiStyle", "GuiTextBoxState" } local functions = {} diff --git a/tools/gestures.h b/tools/gestures.h new file mode 100644 index 0000000..05f5c88 --- /dev/null +++ b/tools/gestures.h @@ -0,0 +1,2 @@ +void ProcessGestureEvent(GestureEvent event) +void UpdateGestures(void) diff --git a/tools/raygui.h b/tools/raygui.h new file mode 100644 index 0000000..6269e46 --- /dev/null +++ b/tools/raygui.h @@ -0,0 +1,59 @@ +void GuiEnable(void) +void GuiDisable(void) +void GuiLock(void) +void GuiUnlock(void) +void GuiFade(float alpha) +void GuiSetState(int state) +int GuiGetState(void) +void GuiSetFont(Font font) +Font GuiGetFont(void) +void GuiSetStyle(int control, int property, int value) +int GuiGetStyle(int control, int property) +void GuiEnableTooltip(void) +void GuiDisableTooltip(void) +void GuiSetTooltip(const char *tooltip) +void GuiClearTooltip(void) +bool GuiWindowBox(Rectangle bounds, const char *title) +void GuiGroupBox(Rectangle bounds, const char *text) +void GuiLine(Rectangle bounds, const char *text) +void GuiPanel(Rectangle bounds) +Rectangle GuiScrollPanel(Rectangle bounds, Rectangle content, Vector2 *scroll) +void GuiLabel(Rectangle bounds, const char *text) +bool GuiButton(Rectangle bounds, const char *text) +bool GuiLabelButton(Rectangle bounds, const char *text) +bool GuiImageButton(Rectangle bounds, const char *text, Texture2D texture) +bool GuiImageButtonEx(Rectangle bounds, const char *text, Texture2D texture, Rectangle texSource) +bool GuiToggle(Rectangle bounds, const char *text, bool active) +int GuiToggleGroup(Rectangle bounds, const char *text, int active) +bool GuiCheckBox(Rectangle bounds, const char *text, bool checked) +int GuiComboBox(Rectangle bounds, const char *text, int active) +bool GuiDropdownBox(Rectangle bounds, const char *text, int *active, bool editMode) +bool GuiSpinner(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode) +bool GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode) +bool GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode) +bool GuiTextBoxMulti(Rectangle bounds, char *text, int textSize, bool editMode) +float GuiSlider(Rectangle bounds, const char *textLeft, const char *textRight, float value, float minValue, float maxValue) +float GuiSliderBar(Rectangle bounds, const char *textLeft, const char *textRight, float value, float minValue, float maxValue) +float GuiProgressBar(Rectangle bounds, const char *textLeft, const char *textRight, float value, float minValue, float maxValue) +void GuiStatusBar(Rectangle bounds, const char *text) +void GuiDummyRec(Rectangle bounds, const char *text) +int GuiScrollBar(Rectangle bounds, int value, int minValue, int maxValue) +Vector2 GuiGrid(Rectangle bounds, float spacing, int subdivs) +int GuiListView(Rectangle bounds, const char *text, int *scrollIndex, int active) +int GuiListViewEx(Rectangle bounds, const char **text, int count, int *focus, int *scrollIndex, int active) +int GuiMessageBox(Rectangle bounds, const char *title, const char *message, const char *buttons) +int GuiTextInputBox(Rectangle bounds, const char *title, const char *message, const char *buttons, char *text) +Color GuiColorPicker(Rectangle bounds, Color color) +Color GuiColorPanel(Rectangle bounds, Color color) +float GuiColorBarAlpha(Rectangle bounds, float alpha) +float GuiColorBarHue(Rectangle bounds, float value) +void GuiLoadStyle(const char *fileName) +void GuiLoadStyleDefault(void) +const char *GuiIconText(int iconId, const char *text) +void GuiDrawIcon(int iconId, Vector2 position, int pixelSize, Color color); +unsigned int *GuiGetIcons(void) +unsigned int *GuiGetIconData(int iconId) +void GuiSetIconData(int iconId, unsigned int *data) +void GuiSetIconPixel(int iconId, int x, int y) +void GuiClearIconPixel(int iconId, int x, int y) +bool GuiCheckIconPixel(int iconId, int x, int y) diff --git a/tools/raymath.h b/tools/raymath.h new file mode 100644 index 0000000..ed1eb45 --- /dev/null +++ b/tools/raymath.h @@ -0,0 +1,79 @@ +float Clamp(float value, float min, float max); +float Lerp(float start, float end, float amount); +Vector2 Vector2Zero(void); +Vector2 Vector2One(void); +Vector2 Vector2Add(Vector2 v1, Vector2 v2); +Vector2 Vector2Subtract(Vector2 v1, Vector2 v2); +float Vector2Length(Vector2 v); +float Vector2DotProduct(Vector2 v1, Vector2 v2); +float Vector2Distance(Vector2 v1, Vector2 v2); +float Vector2Angle(Vector2 v1, Vector2 v2); +Vector2 Vector2Scale(Vector2 v, float scale); +Vector2 Vector2MultiplyV(Vector2 v1, Vector2 v2); +Vector2 Vector2Negate(Vector2 v); +Vector2 Vector2Divide(Vector2 v, float div); +Vector2 Vector2DivideV(Vector2 v1, Vector2 v2); +Vector2 Vector2Normalize(Vector2 v); +Vector2 Vector2Lerp(Vector2 v1, Vector2 v2, float amount); +Vector2 Vector2Rotate(Vector2 v, float degs); +Vector3 Vector3Zero(void); +Vector3 Vector3One(void); +Vector3 Vector3Add(Vector3 v1, Vector3 v2); +Vector3 Vector3Subtract(Vector3 v1, Vector3 v2); +Vector3 Vector3Scale(Vector3 v, float scalar); +Vector3 Vector3Multiply(Vector3 v1, Vector3 v2); +Vector3 Vector3CrossProduct(Vector3 v1, Vector3 v2); +Vector3 Vector3Perpendicular(Vector3 v); +float Vector3Length(const Vector3 v); +float Vector3DotProduct(Vector3 v1, Vector3 v2); +float Vector3Distance(Vector3 v1, Vector3 v2); +Vector3 Vector3Negate(Vector3 v); +Vector3 Vector3Divide(Vector3 v, float div); +Vector3 Vector3DivideV(Vector3 v1, Vector3 v2); +Vector3 Vector3Normalize(Vector3 v); +void Vector3OrthoNormalize(Vector3 *v1, Vector3 *v2); +Vector3 Vector3Transform(Vector3 v, Matrix mat); +Vector3 Vector3RotateByQuaternion(Vector3 v, Quaternion q); +Vector3 Vector3Lerp(Vector3 v1, Vector3 v2, float amount); +Vector3 Vector3Reflect(Vector3 v, Vector3 normal); +Vector3 Vector3Min(Vector3 v1, Vector3 v2); +Vector3 Vector3Max(Vector3 v1, Vector3 v2); +Vector3 Vector3Barycenter(Vector3 p, Vector3 a, Vector3 b, Vector3 c); +float3 Vector3ToFloatV(Vector3 v); +float MatrixDeterminant(Matrix mat); +float MatrixTrace(Matrix mat); +Matrix MatrixTranspose(Matrix mat); +Matrix MatrixInvert(Matrix mat); +Matrix MatrixNormalize(Matrix mat); +Matrix MatrixIdentity(void); +Matrix MatrixAdd(Matrix left, Matrix right); +Matrix MatrixSubtract(Matrix left, Matrix right); +Matrix MatrixTranslate(float x, float y, float z); +Matrix MatrixRotate(Vector3 axis, float angle); +Matrix MatrixRotateXYZ(Vector3 ang); +Matrix MatrixRotateX(float angle); +Matrix MatrixRotateY(float angle); +Matrix MatrixRotateZ(float angle); +Matrix MatrixScale(float x, float y, float z); +Matrix MatrixMultiply(Matrix left, Matrix right); +Matrix MatrixFrustum(double left, double right, double bottom, double top, double near, double far); +Matrix MatrixPerspective(double fovy, double aspect, double near, double far); +Matrix MatrixOrtho(double left, double right, double bottom, double top, double near, double far); +Matrix MatrixLookAt(Vector3 eye, Vector3 target, Vector3 up); +float16 MatrixToFloatV(Matrix mat); +Quaternion QuaternionIdentity(void); +float QuaternionLength(Quaternion q); +Quaternion QuaternionNormalize(Quaternion q); +Quaternion QuaternionInvert(Quaternion q); +Quaternion QuaternionMultiply(Quaternion q1, Quaternion q2); +Quaternion QuaternionLerp(Quaternion q1, Quaternion q2, float amount); +Quaternion QuaternionNlerp(Quaternion q1, Quaternion q2, float amount); +Quaternion QuaternionSlerp(Quaternion q1, Quaternion q2, float amount); +Quaternion QuaternionFromVector3ToVector3(Vector3 from, Vector3 to); +Quaternion QuaternionFromMatrix(Matrix mat); +Matrix QuaternionToMatrix(Quaternion q); +Quaternion QuaternionFromAxisAngle(Vector3 axis, float angle); +void QuaternionToAxisAngle(Quaternion q, Vector3 *outAxis, float *outAngle); +Quaternion QuaternionFromEuler(float roll, float pitch, float yaw); +Vector3 QuaternionToEuler(Quaternion q); +Quaternion QuaternionTransform(Quaternion q, Matrix mat);