2024-01-29 02:29:22 +01:00
|
|
|
#ifndef TOUCH_H
|
|
|
|
#define TOUCH_H
|
|
|
|
|
|
|
|
#include <SDL.h>
|
|
|
|
|
2024-03-25 14:41:06 +01:00
|
|
|
#include <string>
|
2024-01-29 02:29:22 +01:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
struct VVV_Finger
|
|
|
|
{
|
|
|
|
float x;
|
|
|
|
float y;
|
|
|
|
bool pressed;
|
|
|
|
bool on_button;
|
|
|
|
SDL_FingerID id;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum TouchButtonID
|
|
|
|
{
|
|
|
|
/* General */
|
|
|
|
TOUCH_BUTTON_LEFT,
|
|
|
|
TOUCH_BUTTON_RIGHT,
|
|
|
|
|
|
|
|
/* Gameplay */
|
|
|
|
TOUCH_BUTTON_MAP,
|
|
|
|
|
|
|
|
/* Menus */
|
|
|
|
TOUCH_BUTTON_CANCEL,
|
|
|
|
TOUCH_BUTTON_CONFIRM,
|
|
|
|
|
2024-03-25 14:41:06 +01:00
|
|
|
/* Map */
|
|
|
|
TOUCH_BUTTON_MAP_MAP,
|
|
|
|
TOUCH_BUTTON_MAP_CREW,
|
|
|
|
TOUCH_BUTTON_MAP_STATS,
|
|
|
|
TOUCH_BUTTON_MAP_QUIT,
|
|
|
|
|
|
|
|
/* Map - Warp to ship */
|
|
|
|
TOUCH_BUTTON_MAP_SHIP_WARP,
|
|
|
|
|
|
|
|
/* Map - Quit buttons */
|
|
|
|
TOUCH_BUTTON_MAP_QUIT_SAVE,
|
|
|
|
TOUCH_BUTTON_MAP_QUIT_EXIT,
|
|
|
|
|
|
|
|
/* Map - Back */
|
|
|
|
TOUCH_BUTTON_MAP_BACK,
|
|
|
|
|
|
|
|
/* Quit */
|
|
|
|
TOUCH_BUTTON_QUIT_YES,
|
|
|
|
TOUCH_BUTTON_QUIT_NO,
|
|
|
|
|
2024-01-29 02:29:22 +01:00
|
|
|
NUM_TOUCH_BUTTONS
|
|
|
|
};
|
|
|
|
|
2024-03-25 14:41:06 +01:00
|
|
|
enum TouchButtonType
|
|
|
|
{
|
|
|
|
TOUCH_BUTTON_TYPE_NONE,
|
|
|
|
TOUCH_BUTTON_TYPE_MENU,
|
2024-04-10 21:43:46 +02:00
|
|
|
TOUCH_BUTTON_TYPE_MENU_LANGUAGE,
|
2024-04-09 17:56:38 +02:00
|
|
|
TOUCH_BUTTON_TYPE_MENU_TOGGLE,
|
2024-04-09 22:39:23 +02:00
|
|
|
TOUCH_BUTTON_TYPE_MENU_SLIDER,
|
2024-03-25 14:41:06 +01:00
|
|
|
TOUCH_BUTTON_TYPE_MAP
|
|
|
|
};
|
|
|
|
|
2024-01-29 02:29:22 +01:00
|
|
|
struct TouchButton
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int width;
|
|
|
|
int height;
|
2024-03-25 14:41:06 +01:00
|
|
|
bool down; // Whether the button is currently being pressed
|
|
|
|
bool pressed; // Whether the button was pressed down and not dragged onto
|
|
|
|
bool active; // Whether the button is currently active, i.e. visible and usable
|
|
|
|
bool core; // Whether the button is a "core" button, one which always exists (but not necessarily active)
|
|
|
|
bool ui; // Whether the button is on the UI layer or not
|
|
|
|
int id; // The ID for the button, mainly used for menu buttons
|
|
|
|
bool disabled; // Whether the button is disabled or not (gray and can't use), different from active
|
2024-04-09 17:56:38 +02:00
|
|
|
bool checked; // If this is a checkbox, whether it's checked or not
|
2024-04-09 22:39:23 +02:00
|
|
|
int min; // If this is a slider, this is the minimum value
|
|
|
|
int max; // If this is a slider, this is the maximum value
|
|
|
|
int* var; // If this is a slider, this is the variable to modify
|
2024-03-25 14:41:06 +01:00
|
|
|
std::string text; // The text for the button, if it doesn't have an image
|
2024-04-10 21:43:46 +02:00
|
|
|
Uint8 flags; // Print flags
|
2024-03-25 14:41:06 +01:00
|
|
|
SDL_Texture* image; // The image that gets displayed on the button, can be NULL
|
2024-01-29 02:29:22 +01:00
|
|
|
SDL_FingerID fingerId;
|
2024-03-25 14:41:06 +01:00
|
|
|
TouchButtonType type;
|
2024-01-29 02:29:22 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
namespace touch
|
|
|
|
{
|
|
|
|
extern std::vector<VVV_Finger> fingers;
|
|
|
|
extern TouchButton buttons[NUM_TOUCH_BUTTONS];
|
2024-03-25 14:41:06 +01:00
|
|
|
extern std::vector<TouchButton> dynamic_buttons;
|
|
|
|
extern std::vector<TouchButton*> all_buttons;
|
2024-04-12 00:58:49 +02:00
|
|
|
extern int scale;
|
2024-04-09 17:56:38 +02:00
|
|
|
extern bool scroll;
|
2024-01-29 02:29:22 +01:00
|
|
|
|
|
|
|
void refresh_buttons(void);
|
2024-04-09 22:39:23 +02:00
|
|
|
void update_sliders();
|
2024-01-29 02:29:22 +01:00
|
|
|
void reset(void);
|
2024-04-09 17:56:38 +02:00
|
|
|
void on_menu_create(void);
|
2024-01-29 02:29:22 +01:00
|
|
|
void update_buttons(void);
|
|
|
|
|
2024-03-25 18:38:04 +01:00
|
|
|
TouchButton create_button(int x, int y, int width, int height, std::string text);
|
|
|
|
void register_button(TouchButton button);
|
|
|
|
|
|
|
|
void create_menu_button(int x, int y, int width, int height, std::string text, int id);
|
2024-04-10 21:43:46 +02:00
|
|
|
void create_menu_button_flags(int x, int y, int width, int height, std::string text, int id, Uint8 flags);
|
2024-03-25 18:38:04 +01:00
|
|
|
void create_menu_button(int x, int y, int width, int height, std::string text, int id, bool disabled);
|
2024-04-09 22:39:23 +02:00
|
|
|
void create_slider_button(int x, int y, int width, int height, std::string text, int* var, int minvalue, int maxvalue);
|
2024-04-09 17:56:38 +02:00
|
|
|
void create_toggle_button(int x, int y, int width, int height, std::string text, int id, bool checked);
|
2024-03-25 18:38:04 +01:00
|
|
|
|
|
|
|
void remove_dynamic_buttons(void);
|
|
|
|
|
2024-03-25 14:41:06 +01:00
|
|
|
void on_button_up(TouchButton* button);
|
|
|
|
|
2024-01-29 02:29:22 +01:00
|
|
|
void init(void);
|
2024-03-25 14:41:06 +01:00
|
|
|
void render_buttons(void);
|
|
|
|
void render_buttons(int r, int g, int b);
|
|
|
|
void render_buttons(int r, int g, int b, bool textbox_style);
|
|
|
|
void render_buttons(int scale, bool ui, int r, int g, int b);
|
2024-01-29 02:29:22 +01:00
|
|
|
void render(void);
|
|
|
|
|
|
|
|
bool button_tapped(TouchButtonID button);
|
|
|
|
bool touching_right(void);
|
2024-04-12 00:55:03 +02:00
|
|
|
bool screen_down(void);
|
2024-01-29 02:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* TOUCH_H */
|