xref: /OK3568_Linux_fs/external/recovery/minui/minui.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright (C) 2007 The Android Open Source Project
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Licensed under the Apache License, Version 2.0 (the "License");
5*4882a593Smuzhiyun  * you may not use this file except in compliance with the License.
6*4882a593Smuzhiyun  * You may obtain a copy of the License at
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  *      http://www.apache.org/licenses/LICENSE-2.0
9*4882a593Smuzhiyun  *
10*4882a593Smuzhiyun  * Unless required by applicable law or agreed to in writing, software
11*4882a593Smuzhiyun  * distributed under the License is distributed on an "AS IS" BASIS,
12*4882a593Smuzhiyun  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*4882a593Smuzhiyun  * See the License for the specific language governing permissions and
14*4882a593Smuzhiyun  * limitations under the License.
15*4882a593Smuzhiyun  */
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun #ifndef _MINUI_H_
18*4882a593Smuzhiyun #define _MINUI_H_
19*4882a593Smuzhiyun #include <inttypes.h>
20*4882a593Smuzhiyun #include <sys/types.h>
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun #include <stdbool.h>
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun #ifdef __cplusplus
25*4882a593Smuzhiyun extern "C" {
26*4882a593Smuzhiyun #endif
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun typedef struct {
29*4882a593Smuzhiyun     int width;
30*4882a593Smuzhiyun     int height;
31*4882a593Smuzhiyun     int row_bytes;
32*4882a593Smuzhiyun     int pixel_bytes;
33*4882a593Smuzhiyun     unsigned char* data;
34*4882a593Smuzhiyun } GRSurface;
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun typedef GRSurface* gr_surface;
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun typedef enum GRRotation_e {
39*4882a593Smuzhiyun     ROTATION_NONE = 0,
40*4882a593Smuzhiyun     ROTATION_RIGHT = 1,
41*4882a593Smuzhiyun     ROTATION_DOWN = 2,
42*4882a593Smuzhiyun     ROTATION_LEFT = 3,
43*4882a593Smuzhiyun } GRRotation;
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun int gr_init(void);
46*4882a593Smuzhiyun void gr_exit(void);
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun int gr_fb_width(void);
49*4882a593Smuzhiyun int gr_fb_height(void);
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun void gr_flip(void);
52*4882a593Smuzhiyun void gr_fb_blank(bool blank);
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun void gr_clear();  // clear entire surface to current color
55*4882a593Smuzhiyun void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
56*4882a593Smuzhiyun void gr_fill(int x1, int y1, int x2, int y2);
57*4882a593Smuzhiyun void gr_text(int x, int y, const char *s);
58*4882a593Smuzhiyun void gr_texticon(int x, int y, gr_surface icon);
59*4882a593Smuzhiyun int gr_measure(const char *s);
60*4882a593Smuzhiyun void gr_font_size(int *x, int *y);
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun void gr_blit(gr_surface source, int sx, int sy, int w, int h, int dx, int dy);
63*4882a593Smuzhiyun unsigned int gr_get_width(gr_surface surface);
64*4882a593Smuzhiyun unsigned int gr_get_height(gr_surface surface);
65*4882a593Smuzhiyun // Set rotation, flips gr_fb_width/height if 90 degree rotation difference
66*4882a593Smuzhiyun void gr_rotate(GRRotation rotation);
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun // input event structure, include <linux/input.h> for the definition.
70*4882a593Smuzhiyun // see http://www.mjmwired.net/kernel/Documentation/input/ for info.
71*4882a593Smuzhiyun struct input_event;
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun typedef int (*ev_callback)(int fd, uint32_t epevents, void *data);
74*4882a593Smuzhiyun typedef int (*ev_set_key_callback)(int code, int value, void *data);
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun int ev_init(ev_callback input_cb, void *data);
77*4882a593Smuzhiyun void ev_exit(void);
78*4882a593Smuzhiyun int ev_add_fd(int fd, ev_callback cb, void *data);
79*4882a593Smuzhiyun int ev_sync_key_state(ev_set_key_callback set_key_cb, void *data);
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun /* timeout has the same semantics as for poll
82*4882a593Smuzhiyun  *    0 : don't block
83*4882a593Smuzhiyun  *  < 0 : block forever
84*4882a593Smuzhiyun  *  > 0 : block for 'timeout' milliseconds
85*4882a593Smuzhiyun  */
86*4882a593Smuzhiyun int ev_wait(int timeout);
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun int ev_get_input(int fd, uint32_t epevents, struct input_event *ev);
89*4882a593Smuzhiyun void ev_dispatch(void);
90*4882a593Smuzhiyun int ev_get_epollfd(void);
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun // Resources
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun // res_create_*_surface() functions return 0 if no error, else
95*4882a593Smuzhiyun // negative.
96*4882a593Smuzhiyun //
97*4882a593Smuzhiyun // A "display" surface is one that is intended to be drawn to the
98*4882a593Smuzhiyun // screen with gr_blit().  An "alpha" surface is a grayscale image
99*4882a593Smuzhiyun // interpreted as an alpha mask used to render text in the current
100*4882a593Smuzhiyun // color (with gr_text() or gr_texticon()).
101*4882a593Smuzhiyun //
102*4882a593Smuzhiyun // All these functions load PNG images from "/res/images/${name}.png".
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun // Load a single display surface from a PNG image.
105*4882a593Smuzhiyun int res_create_display_surface(const char* name, gr_surface* pSurface);
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun // Load an array of display surfaces from a single PNG image.  The PNG
108*4882a593Smuzhiyun // should have a 'Frames' text chunk whose value is the number of
109*4882a593Smuzhiyun // frames this image represents.  The pixel data itself is interlaced
110*4882a593Smuzhiyun // by row.
111*4882a593Smuzhiyun int res_create_multi_display_surface(const char* name,
112*4882a593Smuzhiyun                                      int* frames, gr_surface** pSurface);
113*4882a593Smuzhiyun 
114*4882a593Smuzhiyun // Load a single alpha surface from a grayscale PNG image.
115*4882a593Smuzhiyun int res_create_alpha_surface(const char* name, gr_surface* pSurface);
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun // Load part of a grayscale PNG image that is the first match for the
118*4882a593Smuzhiyun // given locale.  The image is expected to be a composite of multiple
119*4882a593Smuzhiyun // translations of the same text, with special added rows that encode
120*4882a593Smuzhiyun // the subimages' size and intended locale in the pixel data.  See
121*4882a593Smuzhiyun // development/tools/recovery_l10n for an app that will generate these
122*4882a593Smuzhiyun // specialized images from Android resources.
123*4882a593Smuzhiyun int res_create_localized_alpha_surface(const char* name, const char* locale,
124*4882a593Smuzhiyun                                        gr_surface* pSurface);
125*4882a593Smuzhiyun 
126*4882a593Smuzhiyun // Free a surface allocated by any of the res_create_*_surface()
127*4882a593Smuzhiyun // functions.
128*4882a593Smuzhiyun void res_free_surface(gr_surface surface);
129*4882a593Smuzhiyun 
130*4882a593Smuzhiyun void gr_set_rotate(int val);
131*4882a593Smuzhiyun #ifdef __cplusplus
132*4882a593Smuzhiyun }
133*4882a593Smuzhiyun #endif
134*4882a593Smuzhiyun 
135*4882a593Smuzhiyun #endif
136