blob: e3bc00548493179d9c7f51b20c5a49b4be9b912a [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
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070022#include <functional>
Doug Zongker28ce47c2011-10-28 10:33:05 -070023
Elliott Hughes07138192015-04-10 09:40:53 -070024//
25// Graphics.
26//
27
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070028struct GRSurface {
Doug Zongker39cf4172014-03-06 16:16:05 -080029 int width;
30 int height;
31 int row_bytes;
32 int pixel_bytes;
33 unsigned char* data;
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070034};
Doug Zongker39cf4172014-03-06 16:16:05 -080035
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070036int gr_init();
37void gr_exit();
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080038
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070039int gr_fb_width();
40int gr_fb_height();
Doug Zongker39cf4172014-03-06 16:16:05 -080041
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070042void gr_flip();
Dima Zavin4daf48a2011-08-30 11:59:20 -070043void gr_fb_blank(bool blank);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080044
Doug Zongker39cf4172014-03-06 16:16:05 -080045void gr_clear(); // clear entire surface to current color
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080046void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
Doug Zongkerc560a672012-12-18 16:31:27 -080047void gr_fill(int x1, int y1, int x2, int y2);
Elliott Hughes8fd86d72015-04-13 14:36:02 -070048void gr_text(int x, int y, const char *s, bool bold);
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -070049void gr_texticon(int x, int y, GRSurface* icon);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080050int gr_measure(const char *s);
Dima Zavin3c7f00e2011-08-30 11:58:24 -070051void gr_font_size(int *x, int *y);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080052
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -070053void gr_blit(GRSurface* source, int sx, int sy, int w, int h, int dx, int dy);
54unsigned int gr_get_width(GRSurface* surface);
55unsigned int gr_get_height(GRSurface* surface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080056
Elliott Hughes07138192015-04-10 09:40:53 -070057//
58// Input events.
59//
60
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080061struct input_event;
62
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070063// TODO: move these over to std::function.
Elliott Hughes07138192015-04-10 09:40:53 -070064typedef int (*ev_callback)(int fd, uint32_t epevents, void* data);
65typedef int (*ev_set_key_callback)(int code, int value, void* data);
Dima Zavinbc290632011-08-30 11:59:45 -070066
Elliott Hughes07138192015-04-10 09:40:53 -070067int ev_init(ev_callback input_cb, void* data);
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070068void ev_exit();
Elliott Hughes07138192015-04-10 09:40:53 -070069int ev_add_fd(int fd, ev_callback cb, void* data);
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070070void ev_iterate_available_keys(std::function<void(int)> f);
Elliott Hughes07138192015-04-10 09:40:53 -070071int ev_sync_key_state(ev_set_key_callback set_key_cb, void* data);
Dima Zavinbc290632011-08-30 11:59:45 -070072
Elliott Hughes07138192015-04-10 09:40:53 -070073// 'timeout' has the same semantics as poll(2).
74// 0 : don't block
75// < 0 : block forever
76// > 0 : block for 'timeout' milliseconds
Dima Zavinbc290632011-08-30 11:59:45 -070077int ev_wait(int timeout);
78
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070079int ev_get_input(int fd, uint32_t epevents, input_event* ev);
80void ev_dispatch();
81int ev_get_epollfd();
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080082
Elliott Hughes07138192015-04-10 09:40:53 -070083//
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080084// Resources
Elliott Hughes07138192015-04-10 09:40:53 -070085//
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080086
Doug Zongkera418aa72014-03-17 12:10:02 -070087// res_create_*_surface() functions return 0 if no error, else
88// negative.
89//
90// A "display" surface is one that is intended to be drawn to the
91// screen with gr_blit(). An "alpha" surface is a grayscale image
92// interpreted as an alpha mask used to render text in the current
93// color (with gr_text() or gr_texticon()).
94//
95// All these functions load PNG images from "/res/images/${name}.png".
96
97// Load a single display surface from a PNG image.
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -070098int res_create_display_surface(const char* name, GRSurface** pSurface);
Doug Zongkera418aa72014-03-17 12:10:02 -070099
100// Load an array of display surfaces from a single PNG image. The PNG
101// should have a 'Frames' text chunk whose value is the number of
102// frames this image represents. The pixel data itself is interlaced
103// by row.
Tao Baob723f4f2015-12-11 15:18:51 -0800104int res_create_multi_display_surface(const char* name, int* frames,
105 int* fps, GRSurface*** pSurface);
Doug Zongkera418aa72014-03-17 12:10:02 -0700106
107// Load a single alpha surface from a grayscale PNG image.
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700108int res_create_alpha_surface(const char* name, GRSurface** pSurface);
Doug Zongkera418aa72014-03-17 12:10:02 -0700109
110// Load part of a grayscale PNG image that is the first match for the
111// given locale. The image is expected to be a composite of multiple
112// translations of the same text, with special added rows that encode
113// the subimages' size and intended locale in the pixel data. See
114// development/tools/recovery_l10n for an app that will generate these
115// specialized images from Android resources.
116int res_create_localized_alpha_surface(const char* name, const char* locale,
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700117 GRSurface** pSurface);
Doug Zongkera418aa72014-03-17 12:10:02 -0700118
119// Free a surface allocated by any of the res_create_*_surface()
120// functions.
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700121void res_free_surface(GRSurface* surface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800122
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800123#endif