diff options
Diffstat (limited to 'apps/plugins/lib/grey_parm.c')
-rw-r--r-- | apps/plugins/lib/grey_parm.c | 161 |
1 files changed, 152 insertions, 9 deletions
diff --git a/apps/plugins/lib/grey_parm.c b/apps/plugins/lib/grey_parm.c index 00193e12f2..9b4ba8c5f6 100644 --- a/apps/plugins/lib/grey_parm.c +++ b/apps/plugins/lib/grey_parm.c | |||
@@ -28,6 +28,9 @@ | |||
28 | #include "plugin.h" | 28 | #include "plugin.h" |
29 | #include "grey.h" | 29 | #include "grey.h" |
30 | 30 | ||
31 | /* Default greylib viewport struct */ | ||
32 | struct viewport _grey_default_vp; | ||
33 | |||
31 | /* Set position of the top left corner of the greyscale overlay | 34 | /* Set position of the top left corner of the greyscale overlay |
32 | Note that depending on the target LCD, either x or y gets rounded | 35 | Note that depending on the target LCD, either x or y gets rounded |
33 | to the nearest multiple of 4 or 8 */ | 36 | to the nearest multiple of 4 or 8 */ |
@@ -64,37 +67,37 @@ void grey_set_position(int x, int y) | |||
64 | /* Set the draw mode for subsequent drawing operations */ | 67 | /* Set the draw mode for subsequent drawing operations */ |
65 | void grey_set_drawmode(int mode) | 68 | void grey_set_drawmode(int mode) |
66 | { | 69 | { |
67 | _grey_info.drawmode = mode & (DRMODE_SOLID|DRMODE_INVERSEVID); | 70 | _grey_info.vp->drawmode = mode & (DRMODE_SOLID|DRMODE_INVERSEVID); |
68 | } | 71 | } |
69 | 72 | ||
70 | /* Return the current draw mode */ | 73 | /* Return the current draw mode */ |
71 | int grey_get_drawmode(void) | 74 | int grey_get_drawmode(void) |
72 | { | 75 | { |
73 | return _grey_info.drawmode; | 76 | return _grey_info.vp->drawmode; |
74 | } | 77 | } |
75 | 78 | ||
76 | /* Set the foreground shade for subsequent drawing operations */ | 79 | /* Set the foreground shade for subsequent drawing operations */ |
77 | void grey_set_foreground(unsigned brightness) | 80 | void grey_set_foreground(unsigned brightness) |
78 | { | 81 | { |
79 | _grey_info.fg_brightness = brightness; | 82 | _GREY_FG_BRIGHTNESS(_grey_info.vp) = brightness; |
80 | } | 83 | } |
81 | 84 | ||
82 | /* Return the current foreground shade */ | 85 | /* Return the current foreground shade */ |
83 | unsigned grey_get_foreground(void) | 86 | unsigned grey_get_foreground(void) |
84 | { | 87 | { |
85 | return _grey_info.fg_brightness; | 88 | return _GREY_FG_BRIGHTNESS(_grey_info.vp); |
86 | } | 89 | } |
87 | 90 | ||
88 | /* Set the background shade for subsequent drawing operations */ | 91 | /* Set the background shade for subsequent drawing operations */ |
89 | void grey_set_background(unsigned brightness) | 92 | void grey_set_background(unsigned brightness) |
90 | { | 93 | { |
91 | _grey_info.bg_brightness = brightness; | 94 | _GREY_BG_BRIGHTNESS(_grey_info.vp) = brightness; |
92 | } | 95 | } |
93 | 96 | ||
94 | /* Return the current background shade */ | 97 | /* Return the current background shade */ |
95 | unsigned grey_get_background(void) | 98 | unsigned grey_get_background(void) |
96 | { | 99 | { |
97 | return _grey_info.bg_brightness; | 100 | return _GREY_BG_BRIGHTNESS(_grey_info.vp); |
98 | } | 101 | } |
99 | 102 | ||
100 | /* Set draw mode, foreground and background shades at once */ | 103 | /* Set draw mode, foreground and background shades at once */ |
@@ -108,11 +111,151 @@ void grey_set_drawinfo(int mode, unsigned fg_brightness, unsigned bg_brightness) | |||
108 | /* Set font for the text output routines */ | 111 | /* Set font for the text output routines */ |
109 | void grey_setfont(int newfont) | 112 | void grey_setfont(int newfont) |
110 | { | 113 | { |
111 | _grey_info.curfont = newfont; | 114 | _grey_info.vp->font = newfont; |
112 | } | 115 | } |
113 | 116 | ||
114 | /* Get width and height of a text when printed with the current font */ | 117 | /* Get width and height of a text when printed with the current font */ |
115 | int grey_getstringsize(const unsigned char *str, int *w, int *h) | 118 | int grey_getstringsize(const unsigned char *str, int *w, int *h) |
119 | { | ||
120 | return rb->font_getstringsize(str, w, h, _grey_info.vp->font); | ||
121 | } | ||
122 | |||
123 | /* Helper to establish visible area between viewport and framebuffer */ | ||
124 | static void grey_update_clip_rect(void) | ||
125 | { | ||
126 | if (!(_grey_info.flags & GREY_BUFFERED)) | ||
127 | return; /* no chunky buffer */ | ||
128 | |||
129 | struct viewport *vp = _grey_info.vp; | ||
130 | |||
131 | if (!vp || !_grey_info.curbuffer) | ||
132 | return; | ||
133 | |||
134 | /* Get overall intersection of framebuffer and viewport in viewport | ||
135 | coordinates so that later clipping of drawing is kept as simple as | ||
136 | possible. If l <= r and/or b <= t after intersecting, draw routines | ||
137 | will see this as an empty area. */ | ||
138 | _grey_info.clip_l = _grey_info.cb_x - vp->x; | ||
139 | _grey_info.clip_t = _grey_info.cb_y - vp->y; | ||
140 | _grey_info.clip_r = _grey_info.clip_l + _grey_info.cb_width; | ||
141 | _grey_info.clip_b = _grey_info.clip_t + _grey_info.cb_height; | ||
142 | |||
143 | if (_grey_info.clip_l < 0) | ||
144 | _grey_info.clip_l = 0; | ||
145 | |||
146 | if (_grey_info.clip_t < 0) | ||
147 | _grey_info.clip_t = 0; | ||
148 | |||
149 | if (_grey_info.clip_r > vp->width) | ||
150 | _grey_info.clip_r = vp->width; | ||
151 | |||
152 | if (_grey_info.clip_b > vp->height) | ||
153 | _grey_info.clip_b = vp->height; | ||
154 | } | ||
155 | |||
156 | /* Set current grey viewport for draw routines */ | ||
157 | void grey_set_viewport(struct viewport *vp) | ||
158 | { | ||
159 | if (vp == NULL) | ||
160 | vp = &_grey_default_vp; | ||
161 | |||
162 | if (_grey_info.vp != vp) | ||
163 | { | ||
164 | _grey_info.vp = vp; | ||
165 | grey_update_clip_rect(); | ||
166 | } | ||
167 | } | ||
168 | |||
169 | /* Set viewport to default settings */ | ||
170 | void grey_viewport_set_fullscreen(struct viewport *vp, | ||
171 | const enum screen_type screen) | ||
172 | { | ||
173 | if (vp == NULL) | ||
174 | vp = &_grey_default_vp; | ||
175 | |||
176 | vp->x = 0; | ||
177 | vp->y = 0; | ||
178 | vp->width = _grey_info.width; | ||
179 | vp->height = _grey_info.height; | ||
180 | _GREY_FG_BRIGHTNESS(vp) = 0; | ||
181 | _GREY_BG_BRIGHTNESS(vp) = 255; | ||
182 | vp->drawmode = DRMODE_SOLID; | ||
183 | vp->font = FONT_SYSFIXED; | ||
184 | |||
185 | if (vp == _grey_info.vp) | ||
186 | grey_update_clip_rect(); /* is current one in use */ | ||
187 | |||
188 | (void)screen; | ||
189 | } | ||
190 | |||
191 | void grey_viewport_set_pos(struct viewport *vp, | ||
192 | int x, int y, int width, int height) | ||
193 | { | ||
194 | if (vp == NULL || vp == &_grey_default_vp) | ||
195 | return; /* Cannot be moved or resized */ | ||
196 | |||
197 | if (width < 0) | ||
198 | width = 0; /* 'tis okay */ | ||
199 | |||
200 | if (height < 0) | ||
201 | height = 0; | ||
202 | |||
203 | vp->x = x; | ||
204 | vp->y = y; | ||
205 | vp->width = width; | ||
206 | vp->height = height; | ||
207 | |||
208 | if (vp == _grey_info.vp) | ||
209 | grey_update_clip_rect(); /* is current one in use */ | ||
210 | } | ||
211 | |||
212 | /* Set current grey chunky buffer for draw routines */ | ||
213 | void grey_set_framebuffer(unsigned char *buffer) | ||
214 | { | ||
215 | if (!(_grey_info.flags & GREY_BUFFERED)) | ||
216 | return; /* no chunky buffer */ | ||
217 | |||
218 | if (buffer == NULL) | ||
219 | buffer = _grey_info.buffer; /* Default */ | ||
220 | |||
221 | if (buffer != _grey_info.curbuffer) | ||
222 | { | ||
223 | _grey_info.curbuffer = buffer; | ||
224 | |||
225 | if (buffer == _grey_info.buffer) | ||
226 | { | ||
227 | /* Setting to default fb resets dimensions */ | ||
228 | grey_framebuffer_set_pos(0, 0, 0, 0); | ||
229 | } | ||
230 | } | ||
231 | } | ||
232 | |||
233 | /* Specify the dimensions of the current framebuffer */ | ||
234 | void grey_framebuffer_set_pos(int x, int y, int width, int height) | ||
116 | { | 235 | { |
117 | return rb->font_getstringsize(str, w, h, _grey_info.curfont); | 236 | if (!(_grey_info.flags & GREY_BUFFERED)) |
237 | return; /* no chunky buffer */ | ||
238 | |||
239 | if (_grey_info.curbuffer == _grey_info.buffer) | ||
240 | { | ||
241 | /* This cannot be moved or resized */ | ||
242 | x = 0; | ||
243 | y = 0; | ||
244 | width = _grey_info.width; | ||
245 | height = _grey_info.height; | ||
246 | } | ||
247 | else if (width <= 0 || height <= 0) | ||
248 | return; | ||
249 | |||
250 | if (x == _grey_info.cb_x && y == _grey_info.cb_y && | ||
251 | width == _grey_info.cb_width && height == _grey_info.cb_height) | ||
252 | return; /* No change */ | ||
253 | |||
254 | _grey_info.cb_x = x; | ||
255 | _grey_info.cb_y = y; | ||
256 | _grey_info.cb_width = width; | ||
257 | _grey_info.cb_height = height; | ||
258 | |||
259 | grey_update_clip_rect(); | ||
118 | } | 260 | } |
261 | |||