RetroArch/input/input_overlay.h

254 lines
6.8 KiB
C
Raw Normal View History

/* RetroArch - A frontend for libretro.
2014-01-01 01:50:59 +01:00
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
2015-01-07 17:46:50 +01:00
* Copyright (C) 2011-2015 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef INPUT_OVERLAY_H__
#define INPUT_OVERLAY_H__
#include <stdint.h>
#include <boolean.h>
2015-07-11 08:07:14 +02:00
#include <retro_miscellaneous.h>
2015-07-11 08:07:14 +02:00
#include "../libretro.h"
2013-06-05 10:47:19 +02:00
#ifdef __cplusplus
extern "C" {
#endif
2015-01-10 00:59:05 +01:00
#define OVERLAY_GET_KEY(state, key) (((state)->keys[(key) / 32] >> ((key) % 32)) & 1)
#define OVERLAY_SET_KEY(state, key) (state)->keys[(key) / 32] |= 1 << ((key) % 32)
#define OVERLAY_CLEAR_KEY(state, key) (state)->keys[(key) / 32] &= ~(1 << ((key) % 32))
2014-09-09 17:34:28 +02:00
/* Overlay driver acts as a medium between input drivers
* and video driver.
2014-09-02 16:50:28 +02:00
*
2014-09-09 17:34:28 +02:00
* Coordinates are fetched from input driver, and an
* overlay with pressable actions are displayed on-screen.
*
* This interface requires that the video driver has support
* for the overlay interface.
2014-09-02 16:50:28 +02:00
*/
typedef struct video_overlay_interface
{
void (*enable)(void *data, bool state);
bool (*load)(void *data,
const void *images, unsigned num_images);
void (*tex_geom)(void *data, unsigned image,
float x, float y, float w, float h);
void (*vertex_geom)(void *data, unsigned image,
float x, float y, float w, float h);
void (*full_screen)(void *data, bool enable);
void (*set_alpha)(void *data, unsigned image, float mod);
} video_overlay_interface_t;
enum overlay_hitbox
{
OVERLAY_HITBOX_RADIAL = 0,
OVERLAY_HITBOX_RECT
};
enum overlay_type
{
OVERLAY_TYPE_BUTTONS = 0,
OVERLAY_TYPE_ANALOG_LEFT,
OVERLAY_TYPE_ANALOG_RIGHT,
OVERLAY_TYPE_KEYBOARD
};
enum overlay_status
{
OVERLAY_STATUS_NONE = 0,
OVERLAY_STATUS_DEFERRED_LOAD,
OVERLAY_STATUS_DEFERRED_LOADING_IMAGE,
2015-02-23 06:03:53 +01:00
OVERLAY_STATUS_DEFERRED_LOADING_IMAGE_PROCESS,
OVERLAY_STATUS_DEFERRED_LOADING,
2015-02-27 01:25:08 +01:00
OVERLAY_STATUS_DEFERRED_LOADING_RESOLVE,
OVERLAY_STATUS_DEFERRED_DONE,
2015-07-11 23:45:23 +02:00
OVERLAY_STATUS_DEFERRED_ERROR
};
2015-02-23 06:03:53 +01:00
enum overlay_image_transfer_status
{
OVERLAY_IMAGE_TRANSFER_NONE = 0,
OVERLAY_IMAGE_TRANSFER_BUSY,
OVERLAY_IMAGE_TRANSFER_DONE,
OVERLAY_IMAGE_TRANSFER_DESC_IMAGE_ITERATE,
OVERLAY_IMAGE_TRANSFER_DESC_ITERATE,
OVERLAY_IMAGE_TRANSFER_DESC_DONE,
2015-06-26 15:53:18 +02:00
OVERLAY_IMAGE_TRANSFER_ERROR
2015-02-23 06:03:53 +01:00
};
2015-07-11 08:07:14 +02:00
typedef struct overlay_desc overlay_desc_t;
typedef struct input_overlay input_overlay_t;
2013-09-05 18:19:07 -04:00
typedef struct input_overlay_state
{
2014-09-02 16:50:28 +02:00
/* This is a bitmask of (1 << key_bind_id). */
uint64_t buttons;
/* Left X, Left Y, Right X, Right Y */
int16_t analog[4];
2015-01-10 00:59:05 +01:00
uint32_t keys[RETROK_LAST / 32 + 1];
2013-09-05 18:19:07 -04:00
} input_overlay_state_t;
2015-01-10 00:59:05 +01:00
/**
* input_overlay_new:
2015-01-10 01:03:05 +01:00
* @path : Path to overlay file.
* @enable : Enable the overlay after initializing it?
2015-01-10 00:59:05 +01:00
*
* Creates and initializes an overlay handle.
*
* Returns: Overlay handle on success, otherwise NULL.
**/
input_overlay_t *input_overlay_new(const char *path, bool enable,
float alpha_mod, float scale_factor);
2015-01-10 00:59:05 +01:00
bool input_overlay_load_overlays(input_overlay_t *ol);
bool input_overlay_load_overlays_image_iterate(input_overlay_t *ol);
bool input_overlay_load_overlays_iterate(input_overlay_t *ol);
2015-02-27 01:25:08 +01:00
bool input_overlay_load_overlays_resolve_iterate(input_overlay_t *ol);
bool input_overlay_new_done(input_overlay_t *ol);
2015-01-10 00:59:05 +01:00
/**
* input_overlay_free:
* @ol : Overlay handle.
*
* Frees overlay handle.
**/
void input_overlay_free(input_overlay_t *ol);
2015-01-10 00:59:05 +01:00
/**
* input_overlay_enable:
* @ol : Overlay handle.
* @enable : Enable or disable the overlay
*
* Enable or disable the overlay.
**/
2012-12-20 15:37:04 +01:00
void input_overlay_enable(input_overlay_t *ol, bool enable);
2015-01-10 00:59:05 +01:00
/**
* input_overlay_full_screen:
* @ol : Overlay handle.
*
* Checks if the overlay is fullscreen.
*
* Returns: true (1) if overlay is fullscreen, otherwise false (0).
**/
2013-01-11 16:23:04 +01:00
bool input_overlay_full_screen(input_overlay_t *ol);
2015-01-10 00:59:05 +01:00
/**
* input_overlay_poll:
* @ol : Overlay handle.
* @out : Polled output data.
* @norm_x : Normalized X coordinate.
* @norm_y : Normalized Y coordinate.
*
* Polls input overlay.
*
* @norm_x and @norm_y are the result of
* input_translate_coord_viewport().
**/
2014-09-02 16:50:28 +02:00
void input_overlay_poll(input_overlay_t *ol,
input_overlay_state_t *out, int16_t norm_x, int16_t norm_y);
2015-01-10 00:59:05 +01:00
/**
* input_overlay_post_poll:
* @ol : overlay handle
*
2015-01-10 00:59:05 +01:00
*
* Called after all the input_overlay_poll() calls to
2014-09-02 16:50:28 +02:00
* update the range modifiers for pressed/unpressed regions
2015-01-10 00:59:05 +01:00
* and alpha mods.
**/
void input_overlay_post_poll(input_overlay_t *ol, float opacity);
2015-01-10 00:59:05 +01:00
/**
* input_overlay_poll_clear:
* @ol : overlay handle
* @opacity : Opacity of overlay.
2015-01-10 00:59:05 +01:00
*
* Call when there is nothing to poll. Allows overlay to
* clear certain state.
**/
void input_overlay_poll_clear(input_overlay_t *ol, float opacity);
2015-01-10 00:59:05 +01:00
/**
* input_overlay_set_alpha_mod:
* @ol : Overlay handle.
* @mod : New modulating factor to apply.
*
* Sets a modulating factor for alpha channel. Default is 1.0.
* The alpha factor is applied for all overlays.
**/
2013-01-29 21:51:15 +01:00
void input_overlay_set_alpha_mod(input_overlay_t *ol, float mod);
2015-01-10 00:59:05 +01:00
/**
* input_overlay_set_scale_factor:
* @ol : Overlay handle.
* @scale : Factor of scale to apply.
*
* Scales the overlay by a factor of scale.
**/
2013-02-03 23:35:55 +01:00
void input_overlay_set_scale_factor(input_overlay_t *ol, float scale);
2015-01-10 00:59:05 +01:00
/**
* input_overlay_next:
* @ol : Overlay handle.
*
* Switch to the next available overlay
* screen.
**/
void input_overlay_next(input_overlay_t *ol, float opacity);
2015-07-09 01:10:30 +02:00
input_overlay_t *input_overlay_get_ptr(void);
input_overlay_state_t *input_overlay_get_state_ptr(void);
2015-07-11 23:45:23 +02:00
bool input_overlay_data_is_active(void);
2015-07-09 01:10:30 +02:00
void input_overlay_free_ptr(void);
int input_overlay_new_ptr(void);
2015-07-11 08:07:14 +02:00
enum overlay_status input_overlay_status(input_overlay_t *ol);
2015-07-12 06:47:39 +02:00
/*
* input_poll_overlay:
* @ol : pointer to overlay
*
* Poll pressed buttons/keys on currently active overlay.
**/
void input_poll_overlay(float opacity);
void input_state_overlay(int16_t *ret,
unsigned port, unsigned device, unsigned idx,
unsigned id);
2015-07-12 06:54:35 +02:00
bool input_overlay_key_pressed(int key);
2015-07-12 07:03:39 +02:00
bool input_overlay_is_alive(void);
2013-06-05 10:47:19 +02:00
#ifdef __cplusplus
}
#endif
#endif