mirror of
https://github.com/raysan5/raylib.git
synced 2026-11-25 09:01:47 -05:00
Compare commits
2 Commits
ecd15c050a
...
ae81573550
| Author | SHA1 | Date | |
|---|---|---|---|
| ae81573550 | |||
| 436609a42f |
@ -50,10 +50,19 @@
|
||||
//#include <android/sensor.h> // Required for: Android sensors functions (accelerometer, gyroscope, light...)
|
||||
|
||||
#include <errno.h> // Required for: error types
|
||||
#include <jni.h> // Required for: JNIEnv and JavaVM [Used in OpenURL() and GetCurrentMonitor()]
|
||||
#include <jni.h> // Required for: JNIEnv and JavaVM [Used in OpenURL(), GetCurrentMonitor(), SetClipboardText(), GetClipboardText()]
|
||||
|
||||
#include <EGL/egl.h> // Native platform windowing system interface
|
||||
|
||||
#include <stdio.h> // Required for: NULL
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
//----------------------------------------------------------------------------------
|
||||
#ifndef MAX_CLIPBOARD_BUFFER_LENGTH
|
||||
#define MAX_CLIPBOARD_BUFFER_LENGTH 1024
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
@ -583,18 +592,22 @@ Vector2 GetWindowScaleDPI(void)
|
||||
}
|
||||
|
||||
// Set clipboard text content
|
||||
// NOTE: Implementation based on https://stackoverflow.com/questions/76759222/how-to-copy-to-clipboard-on-android-via-jni
|
||||
// REF: https://stackoverflow.com/questions/76759222/how-to-copy-to-clipboard-on-android-via-jni
|
||||
void SetClipboardText(const char *text)
|
||||
{
|
||||
JNIEnv *env = NULL;
|
||||
JavaVM *vm = platform.app->activity->vm;
|
||||
|
||||
jint result = (*vm)->AttachCurrentThread(vm, &env, NULL);
|
||||
if (result != JNI_OK) {
|
||||
if (result != JNI_OK)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "Failed to allocate a thread to set the clipboard text");
|
||||
return;
|
||||
}
|
||||
|
||||
jobject activity = platform.app->activity->clazz;
|
||||
if (!activity) {
|
||||
if (!activity)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "Failed to get Android activity class reference");
|
||||
(*vm)->DetachCurrentThread(vm);
|
||||
return;
|
||||
@ -623,11 +636,74 @@ void SetClipboardText(const char *text)
|
||||
}
|
||||
|
||||
// Get clipboard text content
|
||||
// NOTE: returned string is allocated and freed by GLFW
|
||||
const char *GetClipboardText(void)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "GetClipboardText() not implemented on target platform");
|
||||
return NULL;
|
||||
static char buffer[MAX_CLIPBOARD_BUFFER_LENGTH] = { 0 };
|
||||
|
||||
JNIEnv *env = NULL;
|
||||
JavaVM *vm = platform.app->activity->vm;
|
||||
|
||||
jint result = (*vm)->AttachCurrentThread(vm, &env, NULL);
|
||||
if (result != JNI_OK)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "Failed to allocate a thread to get the clipboard text");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
jobject activity = platform.app->activity->clazz;
|
||||
if (!activity)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "Failed to get Android activity class reference");
|
||||
(*vm)->DetachCurrentThread(vm);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Get clipboard manager service
|
||||
jclass activityClass = (*env)->GetObjectClass(env, activity);
|
||||
jmethodID getSystemService = (*env)->GetMethodID(env, activityClass, "getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;");
|
||||
jstring serviceName = (*env)->NewStringUTF(env, "clipboard");
|
||||
jobject clipboard = (*env)->CallObjectMethod(env, activity, getSystemService, serviceName);
|
||||
|
||||
// ClipData
|
||||
jclass clipboardClass = (*env)->GetObjectClass(env, clipboard);
|
||||
jmethodID getPrimaryClip = (*env)->GetMethodID(env, clipboardClass, "getPrimaryClip", "()Landroid/content/ClipData;");
|
||||
jobject clip = (*env)->CallObjectMethod(env, clipboard, getPrimaryClip);
|
||||
if (!clip)
|
||||
{
|
||||
(*vm)->DetachCurrentThread(vm);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// ClipData.Item
|
||||
jclass clipClass = (*env)->GetObjectClass(env, clip);
|
||||
jmethodID getItemAt = (*env)->GetMethodID(env, clipClass, "getItemAt", "(I)Landroid/content/ClipData$Item;");
|
||||
jobject item = (*env)->CallObjectMethod(env, clip, getItemAt, 0);
|
||||
|
||||
jclass itemClass = (*env)->GetObjectClass(env, item);
|
||||
jmethodID getText = (*env)->GetMethodID(env, itemClass, "getText", "()Ljava/lang/CharSequence;");
|
||||
jobject text = (*env)->CallObjectMethod(env, item, getText);
|
||||
if (!text)
|
||||
{
|
||||
(*vm)->DetachCurrentThread(vm);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
jclass charSequenceClass = (*env)->FindClass(env, "java/lang/CharSequence");
|
||||
jmethodID toString = (*env)->GetMethodID(env, charSequenceClass, "toString", "()Ljava/lang/String;");
|
||||
jstring string = (jstring)(*env)->CallObjectMethod(env, text, toString);
|
||||
|
||||
const char *chars = (*env)->GetStringUTFChars(env, string, NULL);
|
||||
int clipboardSize = snprintf(buffer, MAX_CLIPBOARD_BUFFER_LENGTH, "%s", chars);
|
||||
if (clipboardSize >= MAX_CLIPBOARD_BUFFER_LENGTH)
|
||||
{
|
||||
char *truncate = buffer + MAX_CLIPBOARD_BUFFER_LENGTH - 4;
|
||||
sprintf(truncate, "...");
|
||||
}
|
||||
|
||||
(*env)->ReleaseStringUTFChars(env, string, chars);
|
||||
(*vm)->DetachCurrentThread(vm);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// Get clipboard image
|
||||
|
||||
@ -1244,34 +1244,41 @@ const char *GetMonitorName(int monitor)
|
||||
// Get window position XY on monitor
|
||||
Vector2 GetWindowPosition(void)
|
||||
{
|
||||
if (platform.window == NULL)
|
||||
Vector2 position = { 0 };
|
||||
|
||||
if (platform.window != NULL)
|
||||
{
|
||||
return (Vector2){ 0.0f, 0.0f };
|
||||
int result = RGFW_window_getPosition(platform.window, &platform.window->x, &platform.window->y);
|
||||
|
||||
if (result != 0)
|
||||
{
|
||||
position.x = (float)platform.window->x;
|
||||
position.y = (float)platform.window->y;
|
||||
}
|
||||
}
|
||||
|
||||
if (RGFW_window_getPosition(platform.window, &platform.window->x, &platform.window->y)) {
|
||||
return (Vector2){ (float)platform.window->x, (float)platform.window->y };
|
||||
}
|
||||
|
||||
return (Vector2){ 0.0f, 0.0f };
|
||||
return position;
|
||||
}
|
||||
|
||||
// Get window scale DPI factor for current monitor
|
||||
Vector2 GetWindowScaleDPI(void)
|
||||
{
|
||||
Vector2 scaleDPI = { 0 };
|
||||
RGFW_monitor *monitor = NULL;
|
||||
|
||||
if (platform.window) monitor = RGFW_window_getMonitor(platform.window);
|
||||
else monitor = RGFW_getPrimaryMonitor();
|
||||
|
||||
#if defined(__APPLE__)
|
||||
// Apple does < 1.0f scaling, example: 0.66f, 0.5f
|
||||
// it needs to be convert to be consistent
|
||||
return (Vector2){ 1.0f/monitor->scaleX, 1.0f/monitor->scaleX };
|
||||
#else
|
||||
// Linux and Windows do >= 1.0f scaling, example: 1.0f, 1.25f, 2.0f
|
||||
return (Vector2){ monitor->scaleX, monitor->scaleX };
|
||||
#endif
|
||||
#if defined(__APPLE__)
|
||||
// Apple does < 1.0f scaling, example: 0.66f, 0.5f
|
||||
// it needs to be convert to be consistent
|
||||
scaleDPI = (Vector2){ 1.0f/monitor->scaleX, 1.0f/monitor->scaleX };
|
||||
#else
|
||||
// Linux and Windows do >= 1.0f scaling, example: 1.0f, 1.25f, 2.0f
|
||||
scaleDPI = (Vector2){ monitor->scaleX, monitor->scaleX };
|
||||
#endif
|
||||
|
||||
return scaleDPI;
|
||||
}
|
||||
|
||||
// Get monitor pixel ratio
|
||||
@ -1653,7 +1660,8 @@ void PollInputEvents(void)
|
||||
{
|
||||
int axis = mg_axisConvertTable[gamepad_event.axis];
|
||||
|
||||
switch (axis) {
|
||||
switch (axis)
|
||||
{
|
||||
case GAMEPAD_AXIS_LEFT_X:
|
||||
case GAMEPAD_AXIS_LEFT_Y:
|
||||
case GAMEPAD_AXIS_RIGHT_X:
|
||||
@ -1854,7 +1862,8 @@ int InitPlatform(void)
|
||||
CORE.Window.currentFbo.height = CORE.Window.render.height;
|
||||
|
||||
// adjust scale if using highdpi
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI)) {
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI))
|
||||
{
|
||||
Vector2 scaleDpi = GetWindowScaleDPI();
|
||||
|
||||
#if defined(__APPLE__)
|
||||
|
||||
@ -890,13 +890,17 @@ const char *GetClipboardText(void)
|
||||
Image GetClipboardImage(void)
|
||||
{
|
||||
Image image = { 0 };
|
||||
int w = 0, h = 0;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
|
||||
RequestClipboardData();
|
||||
unsigned char* data = GetLastPastedImage(&w, &h);
|
||||
if (data != NULL) {
|
||||
unsigned char *data = GetLastPastedImage(&width, &height);
|
||||
|
||||
if (data != NULL)
|
||||
{
|
||||
image.data = data;
|
||||
image.width = w;
|
||||
image.height = h;
|
||||
image.width = width;
|
||||
image.height = height;
|
||||
image.mipmaps = 1;
|
||||
image.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8;
|
||||
}
|
||||
|
||||
@ -903,6 +903,7 @@ EM_JS(unsigned char *, GetLastPastedImage, (int *width, int *height), {
|
||||
const char *GetClipboardText(void)
|
||||
{
|
||||
RequestClipboardData();
|
||||
|
||||
return GetLastPastedText();
|
||||
}
|
||||
|
||||
@ -910,13 +911,17 @@ const char *GetClipboardText(void)
|
||||
Image GetClipboardImage(void)
|
||||
{
|
||||
Image image = { 0 };
|
||||
int w = 0, h = 0;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
|
||||
RequestClipboardData();
|
||||
unsigned char* data = GetLastPastedImage(&w, &h);
|
||||
if (data != NULL) {
|
||||
unsigned char *data = GetLastPastedImage(&width, &height);
|
||||
|
||||
if (data != NULL)
|
||||
{
|
||||
image.data = data;
|
||||
image.width = w;
|
||||
image.height = h;
|
||||
image.width = width;
|
||||
image.height = height;
|
||||
image.mipmaps = 1;
|
||||
image.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8;
|
||||
}
|
||||
|
||||
@ -2607,7 +2607,8 @@ void DrawEllipseLinesEx(Vector2 center, float radiusH, float radiusV, float thic
|
||||
float outerRadiusV = radiusV;
|
||||
float innerRadiusV = radiusV - thick;
|
||||
|
||||
if (thick >= 0.0f) {
|
||||
if (thick >= 0.0f)
|
||||
{
|
||||
// Just a filled-in ellipse
|
||||
if ((innerRadiusH <= 0.0f) || (innerRadiusV <= 0.0f))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user