-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmre_display.c
438 lines (386 loc) · 14.1 KB
/
mre_display.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
/*
mre_display.c Display stuff, popups, alerts, updates etc Source
*/
#include "share.h"
#include "mre_display.h"
/*****************************************************************************
* FUNCTION
* mre_display_home_top_screen_ascii Definition
*
* DESCRIPTION
* Displays home screen,here string passed is in ascii format.
*
* PARAMETERS
* text [IN] string to be displayed in on screen
* layer_hdl The layer? (VMINT layer_hdl[2])
*
* RETURNS
* VOID
*****************************************************************************/
void mre_display_home_top_screen_ascii(VMCHAR *text, VMINT *layer_hdl)
{
VMWCHAR string[MRE_DEFAULT_STRING_SIZE];
VMUINT8* buffer;
int x_coordinate, y_coordinate, width;
/* function body */
vm_gb2312_to_ucs2(string, MRE_DEFAULT_STRING_SIZE, text);
/*Width of character string, in elemental area*/
width = vm_graphic_get_string_width(string);
/*x coordinate of screen where string is to be displayed*/
x_coordinate = (vm_graphic_get_screen_width() - width) / 2;
/*y coordinate of screen where string is to be displayed*/
y_coordinate = (vm_graphic_get_screen_height() - vm_graphic_get_character_height()) / 2;
vm_graphic_clear_layer_bg(layer_hdl[0]);
/* get the target buffer*/
buffer = vm_graphic_get_layer_buffer(layer_hdl[0]);
/* fill the screen*/
vm_graphic_fill_rect(buffer, MRE_SCREEN_START_X, MRE_SCREEN_START_Y, vm_graphic_get_screen_width(),
vm_graphic_get_screen_height(), VM_COLOR_BLACK, VM_COLOR_BLACK);
/* draw text */
vm_graphic_textout(buffer,x_coordinate, y_coordinate, string, wstrlen(string), VM_COLOR_WHITE);
/* flush the screen with data in the buffer*/
vm_graphic_flush_layer(layer_hdl, MRE_SINGLE_LAYER);
}
/*****************************************************************************
* FUNCTION
* mre_text_box_display_result
* DESCRIPTION
* This function takes text string and displays it on the screen
* PARAMETERS
* state [IN] state of input text box
* text [IN] Text string in ASCII or GB2312 format
* RETURNS
* none
*****************************************************************************/
void mre_text_box_display_result (VMINT state, VMWSTR text)
{
/* it is used to display content of a file */
}
/*****************************************************************************
* FUNCTION
* mre_display_file_contents
* DESCRIPTION
* This function displays file's content on display text box
* which is actually input textbox
* PARAMETERS
* file name [IN] name of file
* RETURNS
* result [OUT] some code for error and success
TODO: Modulate this accordingly
*****************************************************************************/
VMINT mre_display_file_contents (VMSTR file_name)
{
VMCHAR data[MRE_STR_SIZE_MAX + 1];
VMCHAR show_data[MRE_STR_SIZE_MAX + 1 + 10];
VMWCHAR default_ucs[MRE_STR_SIZE_MAX + 1];
VMCHAR show_text[MRE_STR_SIZE_MAX + 1];
VMINT read_file_result;
read_file_result = mre_read_file(file_name, data);
if (read_file_result < 0 ){
return read_file_result;
}
/* Displaying data in textbox editor*/
strcpy(show_data, "File Content:");
strcat(show_data, data);
vm_ascii_to_ucs2(default_ucs, (MRE_STR_SIZE_MAX + 1)*2 , show_data);
vm_input_text3 (default_ucs, MRE_STR_SIZE_MAX, VM_INPUT_METHOD_ALPHABETIC,
mre_text_box_display_result);
vm_log_debug ("Entered mre_display_file_contents and vm_input_text3 function ends ");
sprintf (show_text, "file content displayed : %s", file_name);
mre_show_text (show_text);
vm_log_debug ("Exiting mre_display_file_contents function ");
return MRE_SCILENT;
}
/*****************************************************************************
* FUNCTION
* mre_file_result
* DESCRIPTION
* This function decides if file type error found then displays error
* otherwise remain scilent
* PARAMETERS
* result [IN] result
* RETURNS
* none
*****************************************************************************/
void mre_file_result (VMINT result)
{
vm_log_debug ("Entering mre_file_result function");
switch (result)
{
case MRE_FILE_CREATE_FAILED:
mre_show_text ("file is not created");
break;
case MRE_FILE_OPEN_FAILED:
mre_show_text ("file can not be opened");
break;
case MRE_TEXT_BOX_FAILED:
mre_show_text ("input textbox can not be displayed");
break;
case MRE_FILE_NOT_WRITTEN:
mre_show_text ("file is not written");
break;
case MRE_ERROR:
mre_show_text ("some fatal error");
break;
case MRE_TEXTBOX_CANCEL:
mre_show_text ("text box canceled");
break;
case MRE_GET_FILE_TIME_FAILED:
mre_show_text ("can not get time for file");
case MRE_SCILENT:
break;
default:
mre_show_text ("unknown error");
break;
}
vm_log_debug ("Exiting mre_file_result function");
}
/*****************************************************************************
* FUNCTION
* mre_show_text_layer
* DESCRIPTION
* This function takes text string and displays it on the screen
* PARAMETERS
* text [IN] Text string in ASCII or GB2312 format
* RETURNS
* none
*****************************************************************************/
void mre_show_text_layer (VMSTR text, VMINT *handle_layer)
{
VMWCHAR s[MRE_STR_SIZE_MAX];
VMUINT8 *buf;
/*log information*/
vm_log_debug ("Entering mre_show_text_layer function ,input parameter is :%s",text);
mre_set_curr_x (MRE_SET_X + MRE_SET_MARGIN);
mre_set_curr_y (MRE_SET_Y + MRE_SET_MARGIN);
vm_gb2312_to_ucs2 (s, MRE_STR_SIZE_MAX, text);
/* get the target buffer*/
buf = vm_graphic_get_layer_buffer (handle_layer[0]);
/* fill the screen*/
vm_graphic_fill_rect (buf, 0, vm_graphic_get_screen_height () / 2, vm_graphic_get_screen_width (),
(vm_graphic_get_screen_height () / 2) - MRE_SET_MARGIN, VM_COLOR_WHITE, VM_COLOR_BLACK);
/* draw text */
vm_graphic_textout (buf, (MRE_SET_MARGIN * 2), (vm_graphic_get_screen_height () / 2) + MRE_SET_MARGIN, s, wstrlen (s), VM_COLOR_WHITE);
vm_graphic_flush_layer (handle_layer, 1);
vm_log_debug ("Exiting mre_show_text_layer function");
}
/*****************************************************************************
* FUNCTION DEFINITION
* mre_show_text
* DESCRIPTION
* This function takes text string and displays it on the screen
* PARAMETERS
* text [IN] Text string in ASCII or GB2312 format
* RETURNS
* none
*****************************************************************************/
void mre_show_text (VMSTR text)
{
VMWCHAR s[MRE_STR_SIZE_MAX];
VMUINT8 *buf;
/*log information*/
vm_log_debug ("Entering mre_show_text function ,input parameter is :%s",text);
mre_set_curr_x (MRE_SET_X + MRE_SET_MARGIN);
mre_set_curr_y (MRE_SET_Y + MRE_SET_MARGIN);
vm_gb2312_to_ucs2 (s, MRE_STR_SIZE_MAX, text);
/* get the target buffer*/
buf = vm_graphic_get_layer_buffer (layer_hdl[0]);
/* fill the screen*/
vm_graphic_fill_rect (buf, 0, vm_graphic_get_screen_height () / 2, vm_graphic_get_screen_width (),
(vm_graphic_get_screen_height () / 2) - MRE_SET_MARGIN, VM_COLOR_WHITE, VM_COLOR_BLACK);
/* draw text */
vm_graphic_textout (buf, (MRE_SET_MARGIN * 2), (vm_graphic_get_screen_height () / 2) + MRE_SET_MARGIN, s, wstrlen (s), VM_COLOR_WHITE);
vm_graphic_flush_layer (layer_hdl, 1);
vm_log_debug ("Exiting mre_show_text function");
}
/*****************************************************************************
* FUNCTION
* vertical_scrolling_text
* DESCRIPTION
* This function displays results of http conne
* PARAMETERS
* ascii_string [IN] - contains display string
* RETURNS
* none
*****************************************************************************/
void vertical_scrolling_text(VMSTR ascii_string)
{
/* local variables */
int max_height;
unsigned int i = MRE_INTIAL_VALUE;
static int last_y = MRE_INTIAL_VALUE;
max_height = vm_graphic_get_screen_height();
for (i = MRE_INTIAL_VALUE; i < strlen (ascii_string); i++)
{
int width, height;
vm_graphic_measure_character (ascii_string[i], &width, &height);
if(height > max_height)
{
max_height = height;
}
}
if ((last_y + max_height) > vm_graphic_get_screen_height() || last_y == MRE_INTIAL_VALUE)
{
last_y = MRE_INTIAL_VALUE;
vm_graphic_fill_rect(vm_graphic_get_layer_buffer(layer_handle[0]), MRE_SCREEN_START_X, MRE_SCREEN_START_Y,
vm_graphic_get_screen_width(), vm_graphic_get_screen_height(), VM_COLOR_BLACK, VM_COLOR_BLACK);
}
mre_show_text_coordinates(MRE_SCREEN_START_X, last_y, ascii_string);
last_y += max_height;
}
/*****************************************************************************
* FUNCTION DEFINITION
* mre_show_text_coordinates
* DESCRIPTION
* This function displayes ascii string on screen with x, y coordinates
* PARAMETERS
* none
* RETURNS
* none
*****************************************************************************/
static void mre_show_text_coordinates(int display_string_x_pos,
int display_string_y_pos, VMSTR ascii_string)
{
/* local variables */
VMWSTR display_string, exit_str;
VMINT size;
/* function body */
size = (strlen(ascii_string) + 1) * 2;
display_string = vm_malloc(size);
vm_graphic_clear_layer_bg (layer_handle[0]);
vm_ascii_to_ucs2(display_string, size, ascii_string);
/* draw text */
vm_graphic_textout(vm_graphic_get_layer_buffer(layer_handle[0]), display_string_x_pos, display_string_y_pos, display_string, wstrlen(display_string), VM_COLOR_WHITE);
/* display exit */
display_string_x_pos = vm_graphic_get_screen_width() - 3 * MRE_MARGIN;
display_string_y_pos = vm_graphic_get_screen_height() - MRE_MARGIN;
size = (strlen("Exit") + 1) * 2;
exit_str = vm_calloc(size);
vm_ascii_to_ucs2(exit_str, size, "Exit");
vm_graphic_textout(vm_graphic_get_layer_buffer(layer_handle[0]), display_string_x_pos, display_string_y_pos, exit_str, wstrlen(exit_str), VM_COLOR_WHITE);
/* flush the screen with data in the buffer*/
vm_graphic_flush_layer(layer_handle, MRE_FIRST_LAYER);
vm_free(display_string);
}
/*****************************************************************************
* FUNCTION
* mre_set_textbox_text
* DESCRIPTION
* This function saves the text of input textbox in a global variable
* PARAMETERS
* text [IN] text from input textbox
* RETURNS
* none
*****************************************************************************/
void mre_set_textbox_text (VMWSTR text)
{
if (text != NULL)
{
g_mre_textbox_text = (VMWSTR)vm_malloc (sizeof (VMWCHAR) * (vm_wstrlen (text)+1));
vm_wstrcpy (g_mre_textbox_text, text);
}
else
{
g_mre_textbox_text = NULL;
}
}
/*****************************************************************************
* FUNCTION
* mre_get_textbox_text
* DESCRIPTION
* This function returns pointer to text of input textbox saved in a global
* variable
* PARAMETERS
* none
* RETURNS
* g_mre_textbox_text [OUT] it is pointer to text stored in global
* vaiable
*****************************************************************************/
VMWSTR mre_get_textbox_text (void)
{
return g_mre_textbox_text;
}
/*****************************************************************************
* FUNCTION
* mre_set_textbox_state
* DESCRIPTION
* This function saves the state of input textbox in a global variable
* PARAMETERS
* state [IN] it is ok or cancel
* RETURNS
* none
*****************************************************************************/
void mre_set_textbox_state (VMINT state)
{
g_mre_textbox_state = state;
}
/*****************************************************************************
* FUNCTION
* mre_get_textbox_state
* DESCRIPTION
* This function returns the state of input textbox saved in a global variable
* PARAMETERS
* none
* RETURNS
* g_mre_textbox_state [OUT] it is ok or cancel
*****************************************************************************/
VMINT mre_get_textbox_state (void)
{
return g_mre_textbox_state;
}
/*****************************************************************************
* FUNCTION
* mre_set_curr_x
* DESCRIPTION
* This function sets current x cordinate to write strings on screen
* PARAMETERS
* x [IN] current x cordinate
* RETURNS
* none
*****************************************************************************/
void mre_set_curr_x (VMINT x)
{
g_mre_curr_x = x;
}
/*****************************************************************************
* FUNCTION
* mre_get_curr_x
* DESCRIPTION
* This function gets current x cordinate to write strings on screen
* PARAMETERS
* none
* RETURNS
* g_mre_curr_x [OUT] current x cordinate
*****************************************************************************/
VMINT mre_get_curr_x (void)
{
return g_mre_curr_x;
}
/*****************************************************************************
* FUNCTION
* mre_set_curr_y
* DESCRIPTION
* This function sets current y cordinate to write strings on screen
* PARAMETERS
* y [IN] current y cordinate
* RETURNS
* none
*****************************************************************************/
void mre_set_curr_y (VMINT y)
{
g_mre_curr_y = y;
}
/*****************************************************************************
* FUNCTION
* mre_get_curr_y
* DESCRIPTION
* This function gets current y cordinate to write strings on screen
* PARAMETERS
* none
* RETURNS
* g_mre_curr_y [OUT] current y cordinate
*****************************************************************************/
VMINT mre_get_curr_y (void)
{
return g_mre_curr_y;
}