• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
20 #include <sys/types.h>
21 
22 #include <functional>
23 
24 //
25 // Graphics.
26 //
27 
28 struct GRSurface {
29     int width;
30     int height;
31     int row_bytes;
32     int pixel_bytes;
33     unsigned char* data;
34 };
35 
36 struct GRFont {
37     GRSurface* texture;
38     int char_width;
39     int char_height;
40 };
41 
42 int gr_init();
43 void gr_exit();
44 
45 int gr_fb_width();
46 int gr_fb_height();
47 
48 void gr_flip();
49 void gr_fb_blank(bool blank);
50 
51 void gr_clear();  // clear entire surface to current color
52 void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
53 void gr_fill(int x1, int y1, int x2, int y2);
54 
55 void gr_texticon(int x, int y, GRSurface* icon);
56 
57 const GRFont* gr_sys_font();
58 int gr_init_font(const char* name, GRFont** dest);
59 void gr_text(const GRFont* font, int x, int y, const char *s, bool bold);
60 int gr_measure(const GRFont* font, const char *s);
61 void gr_font_size(const GRFont* font, int *x, int *y);
62 
63 void gr_blit(GRSurface* source, int sx, int sy, int w, int h, int dx, int dy);
64 unsigned int gr_get_width(GRSurface* surface);
65 unsigned int gr_get_height(GRSurface* surface);
66 
67 //
68 // Input events.
69 //
70 
71 struct input_event;
72 
73 // TODO: move these over to std::function.
74 typedef int (*ev_callback)(int fd, uint32_t epevents, void* data);
75 typedef int (*ev_set_key_callback)(int code, int value, void* data);
76 
77 int ev_init(ev_callback input_cb, void* data);
78 void ev_exit();
79 int ev_add_fd(int fd, ev_callback cb, void* data);
80 void ev_iterate_available_keys(std::function<void(int)> f);
81 int ev_sync_key_state(ev_set_key_callback set_key_cb, void* data);
82 
83 // 'timeout' has the same semantics as poll(2).
84 //    0 : don't block
85 //  < 0 : block forever
86 //  > 0 : block for 'timeout' milliseconds
87 int ev_wait(int timeout);
88 
89 int ev_get_input(int fd, uint32_t epevents, input_event* ev);
90 void ev_dispatch();
91 int ev_get_epollfd();
92 
93 //
94 // Resources
95 //
96 
97 bool matches_locale(const char* prefix, const char* locale);
98 
99 // res_create_*_surface() functions return 0 if no error, else
100 // negative.
101 //
102 // A "display" surface is one that is intended to be drawn to the
103 // screen with gr_blit().  An "alpha" surface is a grayscale image
104 // interpreted as an alpha mask used to render text in the current
105 // color (with gr_text() or gr_texticon()).
106 //
107 // All these functions load PNG images from "/res/images/${name}.png".
108 
109 // Load a single display surface from a PNG image.
110 int res_create_display_surface(const char* name, GRSurface** pSurface);
111 
112 // Load an array of display surfaces from a single PNG image.  The PNG
113 // should have a 'Frames' text chunk whose value is the number of
114 // frames this image represents.  The pixel data itself is interlaced
115 // by row.
116 int res_create_multi_display_surface(const char* name, int* frames,
117                                      int* fps, GRSurface*** pSurface);
118 
119 // Load a single alpha surface from a grayscale PNG image.
120 int res_create_alpha_surface(const char* name, GRSurface** pSurface);
121 
122 // Load part of a grayscale PNG image that is the first match for the
123 // given locale.  The image is expected to be a composite of multiple
124 // translations of the same text, with special added rows that encode
125 // the subimages' size and intended locale in the pixel data.  See
126 // development/tools/recovery_l10n for an app that will generate these
127 // specialized images from Android resources.
128 int res_create_localized_alpha_surface(const char* name, const char* locale,
129                                        GRSurface** pSurface);
130 
131 // Free a surface allocated by any of the res_create_*_surface()
132 // functions.
133 void res_free_surface(GRSurface* surface);
134 
135 #endif
136