1 /*  RetroArch - A frontend for libretro.
2  *  Copyright (C) 2010-2014 - Hans-Kristian Arntzen
3  *  Copyright (C) 2011-2017 - Daniel De Matteis
4  *
5  *  RetroArch is free software: you can redistribute it and/or modify it under the terms
6  *  of the GNU General Public License as published by the Free Software Found-
7  *  ation, either version 3 of the License, or (at your option) any later version.
8  *
9  *  RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10  *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  *  PURPOSE.  See the GNU General Public License for more details.
12  *
13  *  You should have received a copy of the GNU General Public License along with RetroArch.
14  *  If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef INPUT_OVERLAY_H__
18 #define INPUT_OVERLAY_H__
19 
20 #include <stdint.h>
21 #include <boolean.h>
22 
23 #include <retro_common_api.h>
24 #include <retro_miscellaneous.h>
25 #include <formats/image.h>
26 #include <queues/task_queue.h>
27 
28 #include "input_driver.h"
29 
30 RETRO_BEGIN_DECLS
31 
32 /* Overlay driver acts as a medium between input drivers
33  * and video driver.
34  *
35  * Coordinates are fetched from input driver, and an
36  * overlay with pressable actions are displayed on-screen.
37  *
38  * This interface requires that the video driver has support
39  * for the overlay interface.
40  */
41 
42 typedef struct video_overlay_interface
43 {
44    void (*enable)(void *data, bool state);
45    bool (*load)(void *data,
46          const void *images, unsigned num_images);
47    void (*tex_geom)(void *data, unsigned image,
48          float x, float y, float w, float h);
49    void (*vertex_geom)(void *data, unsigned image,
50          float x, float y, float w, float h);
51    void (*full_screen)(void *data, bool enable);
52    void (*set_alpha)(void *data, unsigned image, float mod);
53 } video_overlay_interface_t;
54 
55 enum overlay_hitbox
56 {
57    OVERLAY_HITBOX_RADIAL = 0,
58    OVERLAY_HITBOX_RECT
59 };
60 
61 enum overlay_type
62 {
63    OVERLAY_TYPE_BUTTONS = 0,
64    OVERLAY_TYPE_ANALOG_LEFT,
65    OVERLAY_TYPE_ANALOG_RIGHT,
66    OVERLAY_TYPE_KEYBOARD
67 };
68 
69 enum overlay_status
70 {
71    OVERLAY_STATUS_NONE = 0,
72    OVERLAY_STATUS_DEFERRED_LOAD,
73    OVERLAY_STATUS_DEFERRED_LOADING_IMAGE,
74    OVERLAY_STATUS_DEFERRED_LOADING_IMAGE_PROCESS,
75    OVERLAY_STATUS_DEFERRED_LOADING,
76    OVERLAY_STATUS_DEFERRED_LOADING_RESOLVE,
77    OVERLAY_STATUS_DEFERRED_DONE,
78    OVERLAY_STATUS_DEFERRED_ERROR
79 };
80 
81 enum overlay_image_transfer_status
82 {
83    OVERLAY_IMAGE_TRANSFER_NONE = 0,
84    OVERLAY_IMAGE_TRANSFER_BUSY,
85    OVERLAY_IMAGE_TRANSFER_DONE,
86    OVERLAY_IMAGE_TRANSFER_DESC_IMAGE_ITERATE,
87    OVERLAY_IMAGE_TRANSFER_DESC_ITERATE,
88    OVERLAY_IMAGE_TRANSFER_DESC_DONE,
89    OVERLAY_IMAGE_TRANSFER_ERROR
90 };
91 
92 enum overlay_visibility
93 {
94    OVERLAY_VISIBILITY_DEFAULT = 0,
95    OVERLAY_VISIBILITY_VISIBLE,
96    OVERLAY_VISIBILITY_HIDDEN
97 };
98 
99 enum overlay_orientation
100 {
101    OVERLAY_ORIENTATION_NONE = 0,
102    OVERLAY_ORIENTATION_LANDSCAPE,
103    OVERLAY_ORIENTATION_PORTRAIT
104 };
105 
106 enum overlay_show_input_type
107 {
108    OVERLAY_SHOW_INPUT_NONE = 0,
109    OVERLAY_SHOW_INPUT_TOUCHED,
110    OVERLAY_SHOW_INPUT_PHYSICAL,
111    OVERLAY_SHOW_INPUT_LAST
112 };
113 
114 struct overlay
115 {
116    struct overlay_desc *descs;
117    struct texture_image *load_images;
118 
119    struct texture_image image;
120 
121    unsigned load_images_size;
122    unsigned id;
123    unsigned pos_increment;
124 
125    size_t size;
126    size_t pos;
127 
128    float mod_x, mod_y, mod_w, mod_h;
129    float x, y, w, h;
130    float center_x, center_y;
131    float aspect_ratio;
132 
133    struct
134    {
135       float alpha_mod;
136       float range_mod;
137 
138       struct
139       {
140          unsigned size;
141          char key[64];
142       } descs;
143 
144       struct
145       {
146          char key[64];
147          char path[PATH_MAX_LENGTH];
148       } paths;
149 
150       struct
151       {
152          char key[64];
153       } names;
154 
155       struct
156       {
157          char array[256];
158          char key[64];
159       } rect;
160 
161       bool normalized;
162    } config;
163 
164    bool full_screen;
165    bool block_scale;
166    bool block_x_separation;
167    bool block_y_separation;
168 
169    char name[64];
170 };
171 
172 struct overlay_desc
173 {
174    struct texture_image image;
175 
176    enum overlay_hitbox hitbox;
177    enum overlay_type type;
178 
179    bool updated;
180    bool movable;
181 
182    unsigned next_index;
183    unsigned image_index;
184 
185    float alpha_mod;
186    float range_mod;
187    float analog_saturate_pct;
188    float range_x, range_y;
189    float range_x_mod, range_y_mod;
190    float mod_x, mod_y, mod_w, mod_h;
191    float delta_x, delta_y;
192    float x;
193    float y;
194    /* These are 'raw' x/y values shifted
195     * by a user-configured offset (c.f.
196     * OVERLAY_X/Y_SEPARATION). Used to determine
197     * correct hitbox locations. By default,
198     * will be equal to x/y */
199    float x_shift;
200    float y_shift;
201 
202    /* This is a retro_key value for keyboards */
203    unsigned retro_key_idx;
204 
205    /* This is a bit mask of all input binds to set with this overlay control */
206    input_bits_t button_mask;
207 
208    char next_index_name[64];
209 };
210 
211 /* Holds general layout information for an
212  * overlay (overall scaling + positional
213  * offset factors) */
214 typedef struct
215 {
216    float scale_landscape;
217    float aspect_adjust_landscape;
218    float x_separation_landscape;
219    float y_separation_landscape;
220    float x_offset_landscape;
221    float y_offset_landscape;
222    float scale_portrait;
223    float aspect_adjust_portrait;
224    float x_separation_portrait;
225    float y_separation_portrait;
226    float x_offset_portrait;
227    float y_offset_portrait;
228    float touch_scale;
229    bool auto_scale;
230 } overlay_layout_desc_t;
231 
232 /* Holds derived overlay layout information
233  * for a specific display orientation */
234 typedef struct
235 {
236    float x_scale;
237    float y_scale;
238    float x_separation;
239    float y_separation;
240    float x_offset;
241    float y_offset;
242 } overlay_layout_t;
243 
244 typedef struct overlay_desc overlay_desc_t;
245 
246 typedef struct input_overlay input_overlay_t;
247 
248 typedef struct
249 {
250    struct overlay *overlays;
251    struct overlay *active;
252    size_t size;
253    float overlay_opacity;
254    overlay_layout_desc_t layout_desc;
255    bool overlay_enable;
256    bool hide_in_menu;
257    bool hide_when_gamepad_connected;
258 } overlay_task_data_t;
259 
260 void input_overlay_free_overlay(struct overlay *overlay);
261 
262 void input_overlay_set_visibility(int overlay_idx,enum overlay_visibility vis);
263 
264 RETRO_END_DECLS
265 
266 #endif
267