Fix clicking on special/alt input not working

This commit is contained in:
UnknownShadow200 2019-09-02 17:09:42 +10:00
parent c168cb24a3
commit 4bea005354
6 changed files with 80 additions and 76 deletions

View File

@ -121,6 +121,65 @@ void Pointer_SetPosition(int idx, int x, int y) {
Event_RaiseMove(&PointerEvents.Moved, idx, deltaX, deltaY);
}
/*########################################################################################################################*
*------------------------------------------------------Touch support------------------------------------------------------*
*#########################################################################################################################*/
#ifdef CC_BUILD_TOUCH
static long touchIds[INPUT_MAX_POINTERS];
int Pointers_Count;
void Input_AddTouch(long id, int x, int y) {
int i = Pointers_Count;
touchIds[i] = id;
Pointers_Count++;
Pointer_SetPosition(i, x, y);
/* TODO: redo this */
if (i == 0) {
Input_SetPressed(KEY_LMOUSE, true);
} else {
Pointer_SetPressed(i, true);
}
}
void Input_UpdateTouch(long id, int x, int y) {
int i;
for (i = 0; i < Pointers_Count; i++) {
if (touchIds[i] != id) continue;
if (win_rawMouse) {
Event_RaiseMove(&PointerEvents.RawMoved, i, x - Pointers[i].x, y - Pointers[i].y);
}
Pointer_SetPosition(i, x, y);
return;
}
}
void Input_RemoveTouch(long id, int x, int y) {
int i;
for (i = 0; i < Pointers_Count; i++) {
if (touchIds[i] != id) continue;
Pointer_SetPosition(i, x, y);
/* TODO: redo this */
if (i == 0) {
Input_SetPressed(KEY_LMOUSE, false);
} else {
Pointer_SetPressed(i, false);
}
/* found the touch, remove it*/
for (; i < Pointers_Count - 1; i++) {
touchIds[i] = touchIds[i + 1];
Pointers[i] = Pointers[i + 1];
}
Pointers_Count--;
return;
}
}
#endif
/*########################################################################################################################*
*---------------------------------------------------------Keybinds--------------------------------------------------------*

View File

@ -74,8 +74,17 @@ typedef int MouseButton;
/* Wheel position of the mouse. Use Mouse_SetWheel to change. */
extern float Mouse_Wheel;
#ifdef CC_BUILD_TOUCH
#define INPUT_MAX_POINTERS 32
extern int Pointers_Count;
void Input_AddTouch(long id, int x, int y);
void Input_UpdateTouch(long id, int x, int y);
void Input_RemoveTouch(long id, int x, int y);
#else
#define INPUT_MAX_POINTERS 1
#define Pointers_Count 1
#endif
/* Data for mouse and touch */
extern struct Pointer { int x, y; } Pointers[INPUT_MAX_POINTERS];

View File

@ -729,7 +729,7 @@ static const char* cpe_clientExtensions[31] = {
static void CPE_SetMapEnvUrl(cc_uint8* data);
#define Ext_Deg2Packed(x) ((int)((x) * 65536.0f / 360.0f))
void CPE_SendPlayerClick(MouseButton button, bool pressed, cc_uint8 targetId, struct PickedPos* pos) {
void CPE_SendPlayerClick(int button, bool pressed, cc_uint8 targetId, struct PickedPos* pos) {
struct Entity* p = &LocalPlayer_Instance.Base;
cc_uint8 data[15];

View File

@ -18,5 +18,5 @@ void Classic_SendChat(const String* text, bool partial);
void Classic_WritePosition(Vec3 pos, float rotY, float headX);
void Classic_WriteSetBlock(int x, int y, int z, bool place, BlockID block);
void Classic_SendLogin(const String* username, const String* verKey);
void CPE_SendPlayerClick(MouseButton button, bool pressed, cc_uint8 targetId, struct PickedPos* pos);
void CPE_SendPlayerClick(int button, bool pressed, cc_uint8 targetId, struct PickedPos* pos);
#endif

View File

@ -2719,7 +2719,7 @@ static void SpecialInputWidget_Reposition(void* widget) {
w->tex.X = w->x; w->tex.Y = w->y;
}
static bool SpecialInputWidget_MouseDown(void* widget, int x, int y, MouseButton btn) {
static bool SpecialInputWidget_PointerDown(void* widget, int id, int x, int y) {
struct SpecialInputWidget* w = (struct SpecialInputWidget*)widget;
x -= w->x; y -= w->y;
@ -2748,9 +2748,9 @@ void SpecialInputWidget_SetActive(struct SpecialInputWidget* w, bool active) {
}
static const struct WidgetVTABLE SpecialInputWidget_VTABLE = {
Widget_NullFunc, SpecialInputWidget_Render, SpecialInputWidget_Free,
Widget_Key, Widget_Key, Widget_MouseScroll,
SpecialInputWidget_MouseDown, Widget_Pointer, Widget_PointerMove,
Widget_NullFunc, SpecialInputWidget_Render, SpecialInputWidget_Free,
Widget_Key, Widget_Key, Widget_MouseScroll,
SpecialInputWidget_PointerDown, Widget_Pointer, Widget_PointerMove,
SpecialInputWidget_Reposition
};
void SpecialInputWidget_Create(struct SpecialInputWidget* w, struct FontDesc* font, struct InputWidget* target) {

View File

@ -91,70 +91,6 @@ void GraphicsMode_MakeDefault(struct GraphicsMode* m) {
}
/*########################################################################################################################*
*------------------------------------------------------Touch support------------------------------------------------------*
*#########################################################################################################################*/
#ifdef CC_BUILD_TOUCH
static struct TouchData { long id; int x, y; } touches[32];
static int touchesCount;
static void Window_AddTouch(long id, int x, int y) {
int i = touchesCount;
touches[i].id = id;
touches[i].x = x;
touches[i].y = y;
touchesCount++;
Pointer_SetPosition(i, x, y);
/* TODO: redo this */
if (i == 0) {
Input_SetPressed(KEY_LMOUSE, true);
} else {
Pointer_SetPressed(i, true);
}
}
static void Window_UpdateTouch(long id, int x, int y) {
int i;
for (i = 0; i < touchesCount; i++) {
if (touches[i].id != id) continue;
if (win_rawMouse) {
Event_RaiseMove(&PointerEvents.RawMoved, i, x - touches[i].x, y - touches[i].y);
}
Pointer_SetPosition(i, x, y);
touches[i].x = x;
touches[i].y = y;
return;
}
}
static void Window_RemoveTouch(long id, int x, int y) {
int i;
for (i = 0; i < touchesCount; i++) {
if (touches[i].id != id) continue;
/* found the touch, remove it*/
for (; i < touchesCount - 1; i++) {
touches[i] = touches[i + 1];
}
touchesCount--;
Pointer_SetPosition(i, x, y);
/* TODO: redo this */
if (i == 0) {
Input_SetPressed(KEY_LMOUSE, false);
} else {
Pointer_SetPressed(i, false);
}
return;
}
}
#endif
/*########################################################################################################################*
*------------------------------------------------------Win32 window-------------------------------------------------------*
*#########################################################################################################################*/
@ -2442,7 +2378,7 @@ static EM_BOOL Window_TouchStart(int type, const EmscriptenTouchEvent* ev, void*
int i;
for (i = 0; i < ev->numTouches; ++i) {
t = &ev->touches[i];
if (t->isChanged) Window_AddTouch(t->identifier, t->canvasX, t->canvasY);
if (t->isChanged) Input_AddTouch(t->identifier, t->canvasX, t->canvasY);
}
return true;
}
@ -2452,7 +2388,7 @@ static EM_BOOL Window_TouchMove(int type, const EmscriptenTouchEvent* ev, void*
int i;
for (i = 0; i < ev->numTouches; ++i) {
t = &ev->touches[i];
if (t->isChanged) Window_UpdateTouch(t->identifier, t->canvasX, t->canvasY);
if (t->isChanged) Input_UpdateTouch(t->identifier, t->canvasX, t->canvasY);
}
return true;
}
@ -2462,7 +2398,7 @@ static EM_BOOL Window_TouchEnd(int type, const EmscriptenTouchEvent* ev, void* d
int i;
for (i = 0; i < ev->numTouches; ++i) {
t = &ev->touches[i];
if (t->isChanged) Window_RemoveTouch(t->identifier, t->canvasX, t->canvasY);
if (t->isChanged) Input_RemoveTouch(t->identifier, t->canvasX, t->canvasY);
}
return true;
}
@ -2874,17 +2810,17 @@ static void JNICALL java_processKeyChar(JNIEnv* env, jobject o, jint code) {
static void JNICALL java_processMouseDown(JNIEnv* env, jobject o, jint id, jint x, jint y) {
Platform_Log3("MOUSE %i - DOWN %i,%i", &id, &x, &y);
Window_AddTouch(id, x, y);
Input_AddTouch(id, x, y);
}
static void JNICALL java_processMouseUp(JNIEnv* env, jobject o, jint id, jint x, jint y) {
Platform_Log3("MOUSE %i - UP %i,%i", &id, &x, &y);
Window_RemoveTouch(id, x, y);
Input_RemoveTouch(id, x, y);
}
static void JNICALL java_processMouseMove(JNIEnv* env, jobject o, jint id, jint x, jint y) {
Platform_Log3("MOUSE %i - MOVE %i,%i", &id, &x, &y);
Window_UpdateTouch(id, x, y);
Input_UpdateTouch(id, x, y);
}
static void JNICALL java_processSurfaceCreated(JNIEnv* env, jobject o, jobject surface) {