-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtouch_input.h
More file actions
37 lines (30 loc) · 896 Bytes
/
touch_input.h
File metadata and controls
37 lines (30 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#ifndef _TOUCH_INPUT_H_
#define _TOUCH_INPUT_H_
#include <SDL3/SDL.h>
struct TouchState {
float joystick_x; // -1.0 to 1.0 (rotation)
bool fire_pressed;
bool thrust_pressed;
};
class TouchInput {
public:
TouchInput();
void init(int screen_width, int screen_height);
void handle_event(const SDL_Event& event);
void draw();
TouchState state;
bool point_in_zone(float x, float y, const SDL_FRect& zone);
SDL_FRect fire_zone;
SDL_FRect thrust_zone;
private:
int screen_w, screen_h;
// Joystick tracking
SDL_FingerID joystick_finger;
bool joystick_active;
float joystick_origin_x, joystick_origin_y; // where finger first touched (pixels)
float joystick_current_x, joystick_current_y;
float joystick_max_radius; // max displacement in pixels
void draw_joystick_overlay();
void draw_button_overlays();
};
#endif