Mobile: Draw crosshairs at position of fingers being used for block place/delete input, instead of always at centre of the screen

This commit is contained in:
UnknownShadow200 2022-08-22 22:53:14 +10:00
parent 0fae073703
commit 4314a4c2cc
3 changed files with 51 additions and 9 deletions

View File

@ -312,6 +312,40 @@ void Pointer_SetPosition(int idx, int x, int y) {
} }
/*########################################################################################################################*
*--------------------------------------------------------Crosshairs-------------------------------------------------------*
*#########################################################################################################################*/
#define CH_EXTENT 16
#ifdef CC_BUILD_TOUCH
static int GetTouchCrosshairs(struct Crosshairs* buffer) {
int i, count = 0;
for (i = 0; i < Pointers_Count; i++) {
if (!(touches[i].type & TOUCH_TYPE_BLOCKS)) continue;
if ( touches[i].type == TOUCH_TYPE_ALL) continue;
buffer[count].centreX = Pointers[i].x;
buffer[count].centreY = Pointers[i].y;
buffer[count].radius = Display_ScaleX(80);
count++;
}
return count;
}
#endif
int Input_GetCrosshairs(struct Crosshairs* buffer) {
#ifdef CC_BUILD_TOUCH
if (Input_TouchMode) return GetTouchCrosshairs(buffer);
#endif
buffer->radius = (int)(CH_EXTENT * Gui_Scale(WindowInfo.Height / 480.0f));
buffer->centreX = WindowInfo.Width / 2;
buffer->centreY = WindowInfo.Height / 2;
return 1;
}
/*########################################################################################################################* /*########################################################################################################################*
*---------------------------------------------------------Keybinds--------------------------------------------------------* *---------------------------------------------------------Keybinds--------------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/

View File

@ -118,6 +118,10 @@ void Mouse_ScrollWheel(float delta);
void Pointer_SetPosition(int idx, int x, int y); void Pointer_SetPosition(int idx, int x, int y);
struct Crosshairs { int centreX, centreY, radius; };
int Input_GetCrosshairs(struct Crosshairs* buffer);
/* Enumeration of all key bindings. */ /* Enumeration of all key bindings. */
enum KeyBind_ { enum KeyBind_ {
KEYBIND_FORWARD, KEYBIND_BACK, KEYBIND_LEFT, KEYBIND_RIGHT, KEYBIND_FORWARD, KEYBIND_BACK, KEYBIND_LEFT, KEYBIND_RIGHT,

View File

@ -768,7 +768,6 @@ static struct ChatScreen {
struct Texture clientStatusTextures[CHAT_MAX_CLIENTSTATUS]; struct Texture clientStatusTextures[CHAT_MAX_CLIENTSTATUS];
struct Texture chatTextures[GUI_MAX_CHATLINES]; struct Texture chatTextures[GUI_MAX_CHATLINES];
} ChatScreen_Instance; } ChatScreen_Instance;
#define CH_EXTENT 16
static void ChatScreen_UpdateChatYOffsets(struct ChatScreen* s) { static void ChatScreen_UpdateChatYOffsets(struct ChatScreen* s) {
int pad, y; int pad, y;
@ -963,18 +962,23 @@ static void ChatScreen_ChatReceived(void* screen, const cc_string* msg, int type
static void ChatScreen_DrawCrosshairs(void) { static void ChatScreen_DrawCrosshairs(void) {
static struct Texture tex = { 0, Tex_Rect(0,0,0,0), Tex_UV(0.0f,0.0f, 15/256.0f,15/256.0f) }; static struct Texture tex = { 0, Tex_Rect(0,0,0,0), Tex_UV(0.0f,0.0f, 15/256.0f,15/256.0f) };
int extent; struct Crosshairs crosshairs[INPUT_MAX_POINTERS];
if (!Gui.IconsTex) return; int i, extent, numCrosshairs;
extent = (int)(CH_EXTENT * Gui_Scale(WindowInfo.Height / 480.0f)); if (!Gui.IconsTex) return;
numCrosshairs = Input_GetCrosshairs(crosshairs);
for (i = 0; i < numCrosshairs; i++) {
extent = crosshairs[i].radius;
tex.ID = Gui.IconsTex; tex.ID = Gui.IconsTex;
tex.X = (WindowInfo.Width / 2) - extent; tex.X = crosshairs[i].centreX - extent;
tex.Y = (WindowInfo.Height / 2) - extent; tex.Y = crosshairs[i].centreY - extent;
tex.Width = extent * 2; tex.Width = extent * 2;
tex.Height = extent * 2; tex.Height = extent * 2;
Texture_Render(&tex); Texture_Render(&tex);
} }
}
static void ChatScreen_DrawChatBackground(struct ChatScreen* s) { static void ChatScreen_DrawChatBackground(struct ChatScreen* s) {
int usedHeight = TextGroupWidget_UsedHeight(&s->chat); int usedHeight = TextGroupWidget_UsedHeight(&s->chat);