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--------------------------------------------------------*
*#########################################################################################################################*/

View File

@ -118,6 +118,10 @@ void Mouse_ScrollWheel(float delta);
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. */
enum KeyBind_ {
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 chatTextures[GUI_MAX_CHATLINES];
} ChatScreen_Instance;
#define CH_EXTENT 16
static void ChatScreen_UpdateChatYOffsets(struct ChatScreen* s) {
int pad, y;
@ -963,17 +962,22 @@ static void ChatScreen_ChatReceived(void* screen, const cc_string* msg, int type
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) };
int extent;
struct Crosshairs crosshairs[INPUT_MAX_POINTERS];
int i, extent, numCrosshairs;
if (!Gui.IconsTex) return;
numCrosshairs = Input_GetCrosshairs(crosshairs);
extent = (int)(CH_EXTENT * Gui_Scale(WindowInfo.Height / 480.0f));
tex.ID = Gui.IconsTex;
tex.X = (WindowInfo.Width / 2) - extent;
tex.Y = (WindowInfo.Height / 2) - extent;
for (i = 0; i < numCrosshairs; i++) {
extent = crosshairs[i].radius;
tex.ID = Gui.IconsTex;
tex.X = crosshairs[i].centreX - extent;
tex.Y = crosshairs[i].centreY - extent;
tex.Width = extent * 2;
tex.Height = extent * 2;
Texture_Render(&tex);
tex.Width = extent * 2;
tex.Height = extent * 2;
Texture_Render(&tex);
}
}
static void ChatScreen_DrawChatBackground(struct ChatScreen* s) {