From e1902300fca52737d77e4c3a1d7ed91887282599 Mon Sep 17 00:00:00 2001 From: anggape Date: Mon, 24 Jul 2023 18:57:15 +0700 Subject: [PATCH] use raylib multi touch sample for testing --- Raylib-cs.Android.Sample/MainActivity.cs | 46 +++++++++++++++++++++--- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/Raylib-cs.Android.Sample/MainActivity.cs b/Raylib-cs.Android.Sample/MainActivity.cs index 72dcadf..94e6d88 100644 --- a/Raylib-cs.Android.Sample/MainActivity.cs +++ b/Raylib-cs.Android.Sample/MainActivity.cs @@ -1,3 +1,4 @@ +using System.Numerics; using System.Runtime.InteropServices; using Android.Content; using Android.Content.PM; @@ -14,21 +15,56 @@ namespace Raylib_cs.Android; ScreenOrientation = ScreenOrientation.Landscape, ClearTaskOnLaunch = true ), - IntentFilter(new[] { Intent.ActionMain }), + IntentFilter(new[] { Intent.ActionMain, Intent.CategoryLauncher }), MetaData(NativeActivity.MetaDataLibName, Value = "raylib") ] public class MainActivity : RaylibActivity { + private const int MAX_TOUCH_POINTS = 10; + protected override void OnReady() { - Raylib.InitWindow(0, 0, "android_window"); + Raylib.InitWindow(0, 0, "raylib [core] example - input multitouch"); + var touchPositions = new Vector2[MAX_TOUCH_POINTS]; + while (!Raylib.WindowShouldClose()) { + int tCount = Raylib.GetTouchPointCount(); + if (tCount > MAX_TOUCH_POINTS) + tCount = MAX_TOUCH_POINTS; + for (int i = 0; i < tCount; ++i) + touchPositions[i] = Raylib.GetTouchPosition(i); + Raylib.BeginDrawing(); - Raylib.ClearBackground(Color.WHITE); - Raylib.DrawFPS(10, 10); - Raylib.DrawText("Hello Raylib-cs.Android", 20, 100, 100, Color.BLACK); + Raylib.ClearBackground(Color.RAYWHITE); + + for (int i = 0; i < tCount; ++i) + { + if ((touchPositions[i].X > 0) && (touchPositions[i].Y > 0)) + { + // for some reason this only works on release mode + Raylib.DrawCircleV(touchPositions[i], 34, Color.ORANGE); + Raylib.DrawText( + i.ToString(), + (int)touchPositions[i].X - 10, + (int)touchPositions[i].Y - 70, + 40, + Color.BLACK + ); + } + } + + Raylib.DrawText( + "touch the screen at multiple locations to get multiple balls", + 10, + 10, + 20, + Color.DARKGRAY + ); + Raylib.EndDrawing(); } + + Raylib.CloseWindow(); } }