Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rcore] Porting raylib to iOS and implement rcore_ios.c #3880

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
d0a13c6
init
blueloveTH Mar 22, 2024
0caa413
create XCode15 project targeting iOS
blueloveTH Mar 23, 2024
b3b2d50
Update rcore_ios.c
blueloveTH Mar 23, 2024
dfc6dc2
some update
blueloveTH Mar 23, 2024
d1ffab4
the first working version
blueloveTH Mar 23, 2024
cae863a
some fix
blueloveTH Mar 23, 2024
2900607
prepare to add touch callbacks
blueloveTH Mar 23, 2024
74da3b7
Update rcore_ios.c
blueloveTH Mar 23, 2024
9f7dec6
support more touches
blueloveTH Mar 24, 2024
c66c9e9
some fix
blueloveTH Mar 24, 2024
a552997
change `pointId[]` to `long long`
blueloveTH Mar 24, 2024
5db5720
Update raylib_api.* by CI
github-actions[bot] Mar 24, 2024
c0ac347
Update rcore_ios.c
blueloveTH Mar 24, 2024
3a9649d
Update rcore_ios.c
blueloveTH Mar 24, 2024
67fb284
upgrade to `GRAPHICS_API_OPENGL_ES3`
blueloveTH Mar 24, 2024
0a9ea31
Update rlgl.h
blueloveTH Mar 25, 2024
cd1b81d
Update project.pbxproj
blueloveTH Mar 25, 2024
33ccfd9
Create ios.yml
blueloveTH Mar 25, 2024
ed861d0
Update ios.yml
blueloveTH Mar 25, 2024
da46011
Update ios.yml
blueloveTH Mar 25, 2024
2e29d3f
Update ios.yml
blueloveTH Mar 25, 2024
ee2a307
Update rcore_ios.c
blueloveTH Mar 27, 2024
e6afac8
Update rcore_ios.c
blueloveTH Mar 27, 2024
e5ecddf
Update rcore_ios.c
blueloveTH Mar 27, 2024
86b3ba2
Update rcore_ios.c
blueloveTH Mar 27, 2024
c124623
Update rcore_ios.c
blueloveTH Mar 27, 2024
f3c4d49
Update rcore_ios.c
blueloveTH Mar 27, 2024
d1a8b86
Revert "change `pointId[]` to `long long`"
blueloveTH Mar 27, 2024
faaa623
revert long long change
blueloveTH Mar 27, 2024
4a7b666
Update raylib_api.* by CI
github-actions[bot] Mar 27, 2024
bc34ea6
Update rcore_ios.c
blueloveTH Mar 27, 2024
3c12964
Update rcore_ios.c
blueloveTH Mar 27, 2024
b69cee5
Update rcore_ios.c
blueloveTH Mar 28, 2024
5241819
Update rcore_ios.c
blueloveTH Mar 28, 2024
d10d888
Update rcore_ios.c
blueloveTH Mar 28, 2024
8fbec6f
Revert "Update raylib_api.* by CI"
blueloveTH Apr 3, 2024
7f9400c
Revert "Update raylib_api.* by CI"
blueloveTH Apr 3, 2024
cd8f5f9
Update rcore_ios.c
blueloveTH Apr 4, 2024
c5c41f9
Update rcore_ios.c
blueloveTH Apr 4, 2024
c4a42a3
Update rcore_android.c
blueloveTH Apr 6, 2024
918c394
Update rcore_android.c
blueloveTH Apr 6, 2024
d68b8eb
Update main.c
blueloveTH Apr 11, 2024
a3873bf
Update project.pbxproj
blueloveTH Apr 11, 2024
1de43bf
Update rcore_ios.c
blueloveTH Apr 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/ios.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: iOS

on:
workflow_dispatch:
push:
paths:
- 'src/**'
- 'examples/**'
- '.github/workflows/android.yml'
pull_request:
paths:
- 'src/**'
- 'examples/**'
- '.github/workflows/android.yml'
release:
types: [published]

jobs:
build:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@master
- name: Build Xcode15 project
run: |
cd projects/Xcode15
curl -L https://github.com/raysan5/raylib/files/14743869/libEGL.xcframework.zip --output libEGL.xcframework.zip
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are those files located? It looks a bit dodgy... isn't there a better approach?

curl -L https://github.com/raysan5/raylib/files/14743873/libGLESv2.xcframework.zip --output libGLESv2.xcframework.zip
mkdir -p raylib/Frameworks
unzip -q libEGL.xcframework.zip -d raylib/Frameworks/libEGL.xcframework
unzip -q libGLESv2.xcframework.zip -d raylib/Frameworks/libGLESv2.xcframework
rm libEGL.xcframework.zip
rm libGLESv2.xcframework.zip
xcodebuild -project raylib.xcodeproj -scheme raylib -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 14' build

123 changes: 123 additions & 0 deletions projects/Xcode15/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*******************************************************************************************
*
* raylib [core] example - Input Gestures Detection
*
* Example originally created with raylib 1.4, last time updated with raylib 4.2
*
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2016-2024 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#ifndef RL_IOS_NO_EXAMPLE

#include "raylib.h"

int MAX_GESTURE_STRINGS = 20;
int screenWidth = 0;
int screenHeight = 0;
Vector2 touchPosition;
Rectangle touchArea;
int gesturesCount = 0;
char gestureStrings[100][32];
int currentGesture = GESTURE_NONE;
int lastGesture = GESTURE_NONE;

void ios_ready(){
InitWindow(0, 0, "raylib [core] example - input gestures");

screenWidth = GetScreenWidth();
screenHeight = GetScreenHeight();

touchPosition = (Vector2){ 0, 0 };
touchArea = (Rectangle){ 220, 10, screenWidth - 230.0f, screenHeight - 20.0f };

//SetGesturesEnabled(0b0000000000001001); // Enable only some gestures to be detected
SetTargetFPS(60);
MAX_GESTURE_STRINGS = (screenHeight - 50) / 20;
}

static void add_gesture(const char* title){
if (gesturesCount >= MAX_GESTURE_STRINGS)
{
for (int i = 0; i < MAX_GESTURE_STRINGS; i++) TextCopy(gestureStrings[i], "\0");
gesturesCount = 0;
}
TextCopy(gestureStrings[gesturesCount], title);
gesturesCount++;
}

void ios_update()
{
lastGesture = currentGesture;
currentGesture = GetGestureDetected();
touchPosition = GetTouchPosition(0);

if(IsMouseButtonPressed(0)) add_gesture("MouseButtonPressed");
if(IsMouseButtonReleased(0)) add_gesture("MouseButtonReleased");

if (CheckCollisionPointRec(touchPosition, touchArea) && (currentGesture != GESTURE_NONE))
{
if (currentGesture != lastGesture)
{
// Store gesture string
switch (currentGesture)
{
case GESTURE_TAP: add_gesture( "GESTURE TAP"); break;
case GESTURE_DOUBLETAP: add_gesture( "GESTURE DOUBLETAP"); break;
case GESTURE_HOLD: add_gesture( "GESTURE HOLD"); break;
case GESTURE_DRAG: add_gesture( "GESTURE DRAG"); break;
case GESTURE_SWIPE_RIGHT: add_gesture( "GESTURE SWIPE RIGHT"); break;
case GESTURE_SWIPE_LEFT: add_gesture( "GESTURE SWIPE LEFT"); break;
case GESTURE_SWIPE_UP: add_gesture( "GESTURE SWIPE UP"); break;
case GESTURE_SWIPE_DOWN: add_gesture( "GESTURE SWIPE DOWN"); break;
case GESTURE_PINCH_IN: add_gesture( "GESTURE PINCH IN"); break;
case GESTURE_PINCH_OUT: add_gesture( "GESTURE PINCH OUT"); break;
default: break;
}
}
}

// Draw
//----------------------------------------------------------------------------------
BeginDrawing();

ClearBackground(RAYWHITE);

DrawRectangleRec(touchArea, GRAY);
DrawRectangle(225, 15, screenWidth - 240, screenHeight - 30, RAYWHITE);

DrawText("GESTURES TEST AREA", screenWidth - 270, screenHeight - 40, 20, Fade(GRAY, 0.5f));

for (int i = 0; i < gesturesCount; i++)
{
if (i % 2 == 0){
DrawRectangle(10, 30 + 20*i, 200, 20, Fade(LIGHTGRAY, 0.5f));
}else{
DrawRectangle(10, 30 + 20*i, 200, 20, Fade(LIGHTGRAY, 0.3f));
}
if (i < gesturesCount - 1){
DrawText(gestureStrings[i], 35, 36 + 20*i, 10, DARKGRAY);
}else{
DrawText(gestureStrings[i], 35, 36 + 20*i, 10, MAROON);
}
}

DrawRectangleLines(10, 29, 200, screenHeight - 50, GRAY);
DrawText(
TextFormat("TOUCH COUNT: %d", GetTouchPointCount()),
50, 15, 10, GRAY
);

for(int i=0; i < GetTouchPointCount(); i++){
DrawCircleV(GetTouchPosition(i), 30, MAROON);
}
EndDrawing();
}

void ios_destroy(){
CloseWindow(); // Close window and OpenGL context
}

#endif
Loading
Loading