mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-22 22:11:55 +00:00
Harmony port: touch event
This commit is contained in:
parent
56ccf29d3c
commit
c951070638
4 changed files with 96 additions and 3 deletions
|
|
@ -1,3 +1,4 @@
|
|||
#include "SDL3/SDL_events.h"
|
||||
#include "SDL_internal.h"
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglplatform.h>
|
||||
|
|
@ -14,6 +15,7 @@
|
|||
#include "SDL_ohos.h"
|
||||
#include <ace/xcomponent/native_interface_xcomponent.h>
|
||||
#include "../../video/ohos/SDL_ohosvideo.h"
|
||||
#include "../../video/ohos/SDL_ohostouch.h"
|
||||
#include "SDL3/SDL_mutex.h"
|
||||
#include "../../video/ohos/SDL_ohoskeyboard.h"
|
||||
|
||||
|
|
@ -355,10 +357,51 @@ static void onKeyEvent(OH_NativeXComponent *component, void *window)
|
|||
}
|
||||
}
|
||||
|
||||
static void onNativeTouch(OH_NativeXComponent *component, void *window)
|
||||
{
|
||||
OH_NativeXComponent_TouchEvent touchEvent;
|
||||
OH_NativeXComponent_TouchPointToolType toolType = OH_NATIVEXCOMPONENT_TOOL_TYPE_UNKNOWN;
|
||||
|
||||
OHOS_LockPage();
|
||||
OH_NativeXComponent_GetTouchEvent(component, window, &touchEvent);
|
||||
OH_NativeXComponent_GetTouchPointToolType(component, 0, &toolType);
|
||||
|
||||
for (int i = 0; i < touchEvent.numPoints; i++)
|
||||
{
|
||||
SDL_OHOSTouchEvent e;
|
||||
e.timestamp = touchEvent.timeStamp;
|
||||
e.deviceId = touchEvent.deviceId;
|
||||
e.fingerId = touchEvent.touchPoints[i].id;
|
||||
e.area = touchEvent.touchPoints[i].size;
|
||||
e.x = touchEvent.touchPoints[i].x / (float)wid;
|
||||
e.y = touchEvent.touchPoints[i].y / (float)hei;
|
||||
e.p = touchEvent.touchPoints[i].force;
|
||||
|
||||
switch (touchEvent.touchPoints[i].type) {
|
||||
case OH_NATIVEXCOMPONENT_DOWN:
|
||||
e.type = SDL_EVENT_FINGER_DOWN;
|
||||
break;
|
||||
case OH_NATIVEXCOMPONENT_MOVE:
|
||||
e.type = SDL_EVENT_FINGER_MOTION;
|
||||
break;
|
||||
case OH_NATIVEXCOMPONENT_UP:
|
||||
e.type = SDL_EVENT_FINGER_UP;
|
||||
break;
|
||||
case OH_NATIVEXCOMPONENT_CANCEL:
|
||||
case OH_NATIVEXCOMPONENT_UNKNOWN:
|
||||
e.type = SDL_EVENT_FINGER_CANCELED;
|
||||
break;
|
||||
}
|
||||
|
||||
OHOS_OnTouch(e);
|
||||
}
|
||||
}
|
||||
static void OnDispatchTouchEventCB(OH_NativeXComponent *component, void *window)
|
||||
{
|
||||
onNativeTouch(component, window);
|
||||
}
|
||||
// TODO
|
||||
static void onNativeTouch(OH_NativeXComponent *component, void *window) {}
|
||||
static void onNativeMouse(OH_NativeXComponent *component, void *window) {}
|
||||
static void OnDispatchTouchEventCB(OH_NativeXComponent *component, void *window) {}
|
||||
static void OnHoverEvent(OH_NativeXComponent *component, bool isHover) {}
|
||||
static void OnFocusEvent(OH_NativeXComponent *component, void *window) {}
|
||||
static void OnBlurEvent(OH_NativeXComponent *component, void *window) {}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef SDL_OHOS_H
|
||||
#define SDL_OHOS_H
|
||||
|
||||
#include "SDL3/SDL_mutex.h"
|
||||
#include "SDL3/SDL_video.h"
|
||||
#include "video/SDL_sysvideo.h"
|
||||
#include <native_window/external_window.h>
|
||||
|
|
@ -19,4 +18,15 @@ typedef struct SDL_VideoData {
|
|||
int isPausing;
|
||||
} SDL_VideoData;
|
||||
|
||||
typedef struct SDL_OHOSTouchEvent {
|
||||
int64_t deviceId;
|
||||
int32_t fingerId;
|
||||
int type;
|
||||
float x;
|
||||
float y;
|
||||
float p;
|
||||
float area;
|
||||
int64_t timestamp;
|
||||
} SDL_OHOSTouchEvent;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
31
src/video/ohos/SDL_ohostouch.c
Normal file
31
src/video/ohos/SDL_ohostouch.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#include "../../core/ohos/SDL_ohos.h"
|
||||
#include "SDL3/SDL_events.h"
|
||||
#include "SDL3/SDL_touch.h"
|
||||
#include "events/SDL_events_c.h"
|
||||
void OHOS_OnTouch(SDL_OHOSTouchEvent event)
|
||||
{
|
||||
if (SDL_AddTouch(event.deviceId, SDL_TOUCH_DEVICE_DIRECT, "") < 0)
|
||||
{
|
||||
SDL_Log("Cannot add touch");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (event.type) {
|
||||
case SDL_EVENT_FINGER_DOWN: {
|
||||
SDL_SendTouch(event.timestamp, event.deviceId, event.fingerId, NULL, SDL_EVENT_FINGER_DOWN, event.x, event.y, event.p);
|
||||
break;
|
||||
}
|
||||
case SDL_EVENT_FINGER_MOTION: {
|
||||
SDL_SendTouchMotion(event.timestamp, event.deviceId, event.fingerId, NULL, event.x, event.y, event.p);
|
||||
break;
|
||||
}
|
||||
case SDL_EVENT_FINGER_UP: {
|
||||
SDL_SendTouch(event.timestamp, event.deviceId, event.fingerId, NULL, SDL_EVENT_FINGER_UP, event.x, event.y, event.p);
|
||||
break;
|
||||
}
|
||||
case SDL_EVENT_FINGER_CANCELED: {
|
||||
SDL_SendTouch(event.timestamp, event.deviceId, event.fingerId, NULL, SDL_EVENT_FINGER_CANCELED, event.x, event.y, event.p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
9
src/video/ohos/SDL_ohostouch.h
Normal file
9
src/video/ohos/SDL_ohostouch.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef SDL_OHOSTOUCH_H
|
||||
#define SDL_OHOSTOUCH_H
|
||||
|
||||
#include "SDL_internal.h"
|
||||
#include "../../core/ohos/SDL_ohos.h"
|
||||
|
||||
void OHOS_OnTouch(SDL_OHOSTouchEvent event);
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue