blob: 8f2ff11390d6e48760a105dc314c410bb1d5d294 [file] [log] [blame]
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _MINUI_H_
18#define _MINUI_H_
19
Doug Zongker830b3e32014-03-11 13:22:04 -070020#include <sys/types.h>
21
Dima Zavin4daf48a2011-08-30 11:59:20 -070022#include <stdbool.h>
23
Doug Zongker28ce47c2011-10-28 10:33:05 -070024#ifdef __cplusplus
25extern "C" {
26#endif
27
Elliott Hughes07138192015-04-10 09:40:53 -070028//
29// Graphics.
30//
31
Doug Zongker39cf4172014-03-06 16:16:05 -080032typedef struct {
33 int width;
34 int height;
35 int row_bytes;
36 int pixel_bytes;
37 unsigned char* data;
38} GRSurface;
39
40typedef GRSurface* gr_surface;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080041
42int gr_init(void);
43void gr_exit(void);
44
45int gr_fb_width(void);
46int gr_fb_height(void);
Doug Zongker39cf4172014-03-06 16:16:05 -080047
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080048void gr_flip(void);
Dima Zavin4daf48a2011-08-30 11:59:20 -070049void gr_fb_blank(bool blank);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080050
Doug Zongker39cf4172014-03-06 16:16:05 -080051void gr_clear(); // clear entire surface to current color
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080052void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
Doug Zongkerc560a672012-12-18 16:31:27 -080053void gr_fill(int x1, int y1, int x2, int y2);
Doug Zongker39cf4172014-03-06 16:16:05 -080054void gr_text(int x, int y, const char *s, int bold);
55void gr_texticon(int x, int y, gr_surface icon);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080056int gr_measure(const char *s);
Dima Zavin3c7f00e2011-08-30 11:58:24 -070057void gr_font_size(int *x, int *y);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080058
59void gr_blit(gr_surface source, int sx, int sy, int w, int h, int dx, int dy);
60unsigned int gr_get_width(gr_surface surface);
61unsigned int gr_get_height(gr_surface surface);
62
Elliott Hughes07138192015-04-10 09:40:53 -070063//
64// Input events.
65//
66
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080067struct input_event;
68
Elliott Hughes07138192015-04-10 09:40:53 -070069typedef int (*ev_callback)(int fd, uint32_t epevents, void* data);
70typedef int (*ev_set_key_callback)(int code, int value, void* data);
71typedef void (*ev_key_callback)(int code, void* data);
Dima Zavinbc290632011-08-30 11:59:45 -070072
Elliott Hughes07138192015-04-10 09:40:53 -070073int ev_init(ev_callback input_cb, void* data);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080074void ev_exit(void);
Elliott Hughes07138192015-04-10 09:40:53 -070075int ev_add_fd(int fd, ev_callback cb, void* data);
76int ev_sync_key_state(ev_set_key_callback set_key_cb, void* data);
77void ev_iterate_available_keys(ev_key_callback cb, void* data);
Dima Zavinbc290632011-08-30 11:59:45 -070078
Elliott Hughes07138192015-04-10 09:40:53 -070079// 'timeout' has the same semantics as poll(2).
80// 0 : don't block
81// < 0 : block forever
82// > 0 : block for 'timeout' milliseconds
Dima Zavinbc290632011-08-30 11:59:45 -070083int ev_wait(int timeout);
84
Todd Poynora5ef19f2013-09-17 13:39:10 -070085int ev_get_input(int fd, uint32_t epevents, struct input_event *ev);
Dima Zavinbc290632011-08-30 11:59:45 -070086void ev_dispatch(void);
Todd Poynor4665ede2013-09-10 17:03:45 -070087int ev_get_epollfd(void);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080088
Elliott Hughes07138192015-04-10 09:40:53 -070089//
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080090// Resources
Elliott Hughes07138192015-04-10 09:40:53 -070091//
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080092
Doug Zongkera418aa72014-03-17 12:10:02 -070093// res_create_*_surface() functions return 0 if no error, else
94// negative.
95//
96// A "display" surface is one that is intended to be drawn to the
97// screen with gr_blit(). An "alpha" surface is a grayscale image
98// interpreted as an alpha mask used to render text in the current
99// color (with gr_text() or gr_texticon()).
100//
101// All these functions load PNG images from "/res/images/${name}.png".
102
103// Load a single display surface from a PNG image.
104int res_create_display_surface(const char* name, gr_surface* pSurface);
105
106// Load an array of display surfaces from a single PNG image. The PNG
107// should have a 'Frames' text chunk whose value is the number of
108// frames this image represents. The pixel data itself is interlaced
109// by row.
110int res_create_multi_display_surface(const char* name,
111 int* frames, gr_surface** pSurface);
112
113// Load a single alpha surface from a grayscale PNG image.
114int res_create_alpha_surface(const char* name, gr_surface* pSurface);
115
116// Load part of a grayscale PNG image that is the first match for the
117// given locale. The image is expected to be a composite of multiple
118// translations of the same text, with special added rows that encode
119// the subimages' size and intended locale in the pixel data. See
120// development/tools/recovery_l10n for an app that will generate these
121// specialized images from Android resources.
122int res_create_localized_alpha_surface(const char* name, const char* locale,
123 gr_surface* pSurface);
124
125// Free a surface allocated by any of the res_create_*_surface()
126// functions.
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800127void res_free_surface(gr_surface surface);
128
Doug Zongker28ce47c2011-10-28 10:33:05 -0700129#ifdef __cplusplus
130}
131#endif
132
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800133#endif