Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "GUI.h"
#include "garage.c"
#include "Wheel2.c"
#include "Wheel3.c"
#include "Wheel4.c"
#include "Wheel5.c"
Private define
#define MAG
#define TITLE_SIZE
#define MIN_TIME_PER_FRAME_SHIFT
#define MIN_TIME_PER_FRAME_ENLARGE
#define BORDER_SIZE
#define FINAL_STEP
Private variables
IMAGE
_aImage
_NumImages
_GetImage(IMAGE *)
_RotateAndZoomImage()
_ShiftRotateAndZoomImage()
MainTask()
Files
loading...
SourceVuSTM32 Libraries and SamplesSTemWin_MemoryDeviceSTemWin/App/memory_device_app.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
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file memory_device_app.c * @author MCD Application Team * @brief This file provides main GUI application program functions ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "GUI.h" /* Bitmap resources */ #include "garage.c" #include "Wheel2.c" #include "Wheel3.c" #include "Wheel4.c" #include "Wheel5.c" 6 includes Includes/* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ #define MAG 300 #define TITLE_SIZE 40 #define MIN_TIME_PER_FRAME_SHIFT 10 #define MIN_TIME_PER_FRAME_ENLARGE 10 #define BORDER_SIZE 4 #define FINAL_STEP 10 6 defines Private define/* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ typedef struct { const GUI_BITMAP GUI_UNI_PTR * pBitmap; GUI_MEMDEV_Handle hMem; int xSize; int ySize; ...} IMAGE; /* Table of pictures to be used */ static IMAGE _aImage[] = { { &bmWheel4 }, { &bmWheel3 }, { &bmWheel2 }, { &bmWheel5 } ...}; /* Calculate the number of images used */ static int _NumImages = sizeof(_aImage) / sizeof(_aImage[0]); Private variables /* Private function prototypes -----------------------------------------------*/ /** * @brief Create the pictures memdev and draw them inside * @param pImage: pointer to the pictures structure * @retval int *//* ... */ static int _GetImage(IMAGE * pImage) { /* Get the picture sizes */ pImage->xSize = pImage->pBitmap->XSize; pImage->ySize = pImage->pBitmap->YSize; /* Allocate the needed memdev pictures */ pImage->hMem = GUI_MEMDEV_CreateFixed(0, 0, pImage->xSize, pImage->ySize, GUI_MEMDEV_NOTRANS, GUI_MEMDEV_APILIST_32, GUICC_M8888I); /* Exit if any issue occurred on the memdev creation */ if (pImage->hMem == 0) { return 1; }if (pImage->hMem == 0) { ... } /* Select the memdev created and paint the picturte on it */ GUI_MEMDEV_Select(pImage->hMem); GUI_SetBkColor(GUI_TRANSPARENT); GUI_Clear(); GUI_DrawBitmap(pImage->pBitmap, 0, 0); /* Select the display after finishing the job */ GUI_MEMDEV_Select(0); return 0; }{ ... } /** * @brief Create the needed memdevs and do the automated rotate & zoom of the pictures * @param None * @retval int *//* ... */ static int _RotateAndZoomImage(void) { static GUI_MEMDEV_Handle hDst = 0; static GUI_MEMDEV_Handle hLCD = 0; static int Index = 0; IMAGE *pImage; int TimeContinue; int TimeNow; int xSize; int ySize; int Mag; int a; int i; /* Declaration of a function pointer for the rotate function */ void (*pfRotate)(GUI_MEMDEV_Handle hSrc, GUI_MEMDEV_Handle hDst, int dx, int dy, int a, int Mag); /* Assign the function pointer: use the rotation High Quality memdev rotation */ pfRotate = GUI_MEMDEV_Rotate; pImage = &_aImage[Index]; /* Get the respective width and height of the screen */ xSize = LCD_GetXSize(); ySize = LCD_GetYSize(); /* Clean up LCD context, draw a given background */ GUI_DrawBitmap(&bmgarage, 0, 0); /* Create the LCD memory devices if not existent */ if (hLCD == 0) { hLCD = GUI_MEMDEV_CreateFixed(0, 0, xSize, ySize, GUI_MEMDEV_NOTRANS, GUI_MEMDEV_APILIST_32, GUICC_M8888I); /* Exit if any issue when creating the memdev */ if (hLCD == 0) { return 1; }if (hLCD == 0) { ... } /* Initialise the memdev with what's displayed */ GUI_MEMDEV_CopyFromLCD(hLCD); }if (hLCD == 0) { ... } /* Create the Destination memory devices if not existent */ if (hDst == 0) { /* Exit if any issue when creating the memdev */ hDst = GUI_MEMDEV_CreateFixed(0, 0, xSize, ySize, GUI_MEMDEV_NOTRANS, GUI_MEMDEV_APILIST_32, GUICC_M8888I); if (hDst == 0) { return 1; }if (hDst == 0) { ... } }if (hDst == 0) { ... } /* Reserve a part to display the title of the application */ ySize -= TITLE_SIZE; /* Rotate and enlarge while moving in */ for (i = 2; (i <= 100); i += 6) { TimeContinue = GUI_GetTime() + MIN_TIME_PER_FRAME_ENLARGE; GUI_MEMDEV_Select(hDst); GUI_MEMDEV_Write(hLCD); pfRotate(pImage->hMem, hDst, (xSize - pImage->xSize) / 2 - (xSize * (100 - i)) / 300, TITLE_SIZE + (ySize - pImage->ySize) / 2, (i - 100) * 450, i * 10); GUI_MEMDEV_Select(0); /* Display the result on the screen */ GUI_MULTIBUF_Begin(); GUI_MEMDEV_CopyToLCD(hDst); GUI_MULTIBUF_End(); /* Add some delay to achieve minimum timing */ TimeNow = GUI_GetTime(); if (TimeContinue > TimeNow) { GUI_Delay(TimeContinue - TimeNow); }if (TimeContinue > TimeNow) { ... } else { GUI_Exec(); }else { ... } }for (i = 2; (i <= 100); i += 6) { ... } /* Rotate, enlarge and shrink on spot */ Mag = 1000; for (a = 5; a <= 360; a += 30) { TimeContinue = GUI_GetTime() + MIN_TIME_PER_FRAME_ENLARGE; /* Calculate magnification */ if (a <= 180) { Mag = (Mag * 1050) / 1000; }if (a <= 180) { ... } else { Mag = (Mag * 1000) / 1050; }else { ... } /* Do animation: write the result every time to the LCD */ GUI_MEMDEV_Select(hDst); GUI_MEMDEV_Write(hLCD); pfRotate(pImage->hMem, hDst, (xSize - pImage->xSize) / 2, TITLE_SIZE + (ySize - pImage->ySize) / 2, a * 1000, 1000); GUI_MEMDEV_Select(0); /* Display the result on the screen */ GUI_MULTIBUF_Begin(); GUI_MEMDEV_CopyToLCD(hDst); GUI_MULTIBUF_End(); /* Add some delay to achieve minimum timing */ TimeNow = GUI_GetTime(); if (TimeContinue > TimeNow) { GUI_Delay(TimeContinue - TimeNow); }if (TimeContinue > TimeNow) { ... } else { GUI_Exec(); }else { ... } }for (a = 5; a <= 360; a += 30) { ... } /* Clean up LCD context, Draw the Bkc again */ GUI_MEMDEV_Select(hLCD); GUI_DrawBitmap(&bmgarage, 0, 0); /* Rotate and enlarge while moving out */ for (i = 2; (i <= 100); i += 6) { TimeContinue = GUI_GetTime() + MIN_TIME_PER_FRAME_ENLARGE; GUI_MEMDEV_Select(hDst); GUI_MEMDEV_Write(hLCD); pfRotate(pImage->hMem, hDst, (xSize - pImage->xSize) / 2 + (xSize * i) / 300, TITLE_SIZE + (ySize - pImage->ySize) / 2, i * 450, (100 - i) * 10); GUI_MEMDEV_Select(0); /* Display the result on the screen */ GUI_MULTIBUF_Begin(); GUI_MEMDEV_CopyToLCD(hDst); GUI_MULTIBUF_End(); /* Add some delay to achieve minimum timing */ TimeNow = GUI_GetTime(); if (TimeContinue > TimeNow) { GUI_Delay(TimeContinue - TimeNow); }if (TimeContinue > TimeNow) { ... } else { GUI_Exec(); }else { ... } }for (i = 2; (i <= 100); i += 6) { ... } /* Display the result on the screen */ GUI_MULTIBUF_Begin(); GUI_MEMDEV_CopyToLCD(hLCD); GUI_MULTIBUF_End(); /* Go to the next picture */ Index = (Index + 1) % _NumImages; /* Delete the MEMDEVS used */ GUI_MEMDEV_Delete(hLCD); GUI_MEMDEV_Delete(hDst); hDst = 0; hLCD = 0; return 0; }{ ... } /** * @brief Create the needed memdevs and do the automated rotate & shift of the pictures * @param None * @retval int *//* ... */ static int _ShiftRotateAndZoomImage(void) { static GUI_MEMDEV_Handle hDstEnlarge = 0; static GUI_MEMDEV_Handle hLCDEnlarge = 0; static GUI_MEMDEV_Handle hDstShift = 0; static GUI_MEMDEV_Handle hLCD = 0; static int Index = 0; IMAGE *pImage; int TimeContinue; int DispSpaceX; int DispSpaceY; int TimeNow; int Index0; int Index1; int Index2; int Index3; int xSize; int ySize; int Step; int Add; int Mag; int a; int i; /* Declaration of a function pointer for the rotate function */ void (*pfRotate)(GUI_MEMDEV_Handle hSrc, GUI_MEMDEV_Handle hDst, int dx, int dy, int a, int Mag); /* Get the respective width and height of the screen */ xSize = LCD_GetXSize(); ySize = LCD_GetYSize() - TITLE_SIZE; DispSpaceX = xSize / 3; DispSpaceY = (ySize * 3) / 5; /* Clean up LCD context, draw the Bkc */ GUI_DrawBitmap(&bmgarage, 0, 0); /* Create LCD memory device if not existing */ if (hLCD == 0) { hLCD = GUI_MEMDEV_CreateFixed(0, TITLE_SIZE + ySize / 5, xSize, DispSpaceY, GUI_MEMDEV_NOTRANS, GUI_MEMDEV_APILIST_32, GUICC_M8888I); /* Exit if any issue on the creation of the memdev */ if (hLCD == 0) { return 1; }if (hLCD == 0) { ... } /* Initialiose the memdev with what's on the screen */ GUI_MEMDEV_CopyFromLCD(hLCD); }if (hLCD == 0) { ... } /* Create destination memory device if not existing */ if (hDstShift == 0) { hDstShift = GUI_MEMDEV_CreateFixed(0, TITLE_SIZE + ySize / 5, xSize, DispSpaceY, GUI_MEMDEV_NOTRANS, GUI_MEMDEV_APILIST_32, GUICC_M8888I); /* Exit if any issue on the creation of the memdev */ if (hDstShift == 0) { return 1; }if (hDstShift == 0) { ... } }if (hDstShift == 0) { ... } /* Create the zoom destination memory device if not existing */ if (hDstEnlarge == 0) { hDstEnlarge = GUI_MEMDEV_CreateFixed(xSize / 6, TITLE_SIZE, (xSize * 2) / 3, ySize, GUI_MEMDEV_NOTRANS, GUI_MEMDEV_APILIST_32, GUICC_M8888I); /* Exit if any issue on the creation of the memdev */ if (hDstEnlarge == 0) { return 1; }if (hDstEnlarge == 0) { ... } }if (hDstEnlarge == 0) { ... } /* Create the zoom LCD memory device if not existing */ if (hLCDEnlarge == 0) { hLCDEnlarge = GUI_MEMDEV_CreateFixed(xSize / 6, TITLE_SIZE, (xSize * 2) / 3, ySize, GUI_MEMDEV_NOTRANS, GUI_MEMDEV_APILIST_32, GUICC_M8888I); /* Exit if any issue on the creation of the memdev */ if (hLCDEnlarge == 0) { return 1; }if (hLCDEnlarge == 0) { ... } }if (hLCDEnlarge == 0) { ... } /* Select the display screen */ GUI_MEMDEV_Select(0); /* Get image indices */ Index0 = (Index + 0) % _NumImages; Index1 = (Index + 1) % _NumImages; Index2 = (Index + 2) % _NumImages; Index3 = (Index + 3) % _NumImages; /* Choose the rotation API to use: HQ rotation isn't used here */ pfRotate = GUI_MEMDEV_Rotate; /* Perform shifting */ for (i = 1; i <= FINAL_STEP; i++) { TimeContinue = GUI_GetTime() + MIN_TIME_PER_FRAME_SHIFT; Step = (DispSpaceX * i) / FINAL_STEP; /* Calculate rotation */ a = (-Step * 360 * 1000) / DispSpaceX; /* Do the animation */ GUI_MEMDEV_Select(hDstShift); GUI_MEMDEV_Write(hLCD); pImage = &_aImage[Index0]; pfRotate(pImage->hMem, hDstShift, ((xSize - pImage->xSize) / 2) - (DispSpaceX * 2) + Step, (DispSpaceY - pImage->ySize) / 2, a, MAG); pImage = &_aImage[Index1]; pfRotate(pImage->hMem, hDstShift, ((xSize - pImage->xSize) / 2) - DispSpaceX + Step, (DispSpaceY - pImage->ySize) / 2, a, MAG); pImage = &_aImage[Index2]; pfRotate(pImage->hMem, hDstShift, ((xSize - pImage->xSize) / 2) + Step, (DispSpaceY - pImage->ySize) / 2, a, MAG); pImage = &_aImage[Index3]; pfRotate(pImage->hMem, hDstShift, ((xSize - pImage->xSize) / 2) + DispSpaceX + Step, (DispSpaceY - pImage->ySize) / 2, a, MAG); /* Display the result */ GUI_MULTIBUF_Begin(); GUI_MEMDEV_CopyToLCD(hDstShift); GUI_MULTIBUF_End(); /* Add some delay to achieve minimum timing */ TimeNow = GUI_GetTime(); if (TimeContinue > TimeNow) { GUI_Delay(TimeContinue - TimeNow); }if (TimeContinue > TimeNow) { ... } else { GUI_Exec(); }else { ... } }for (i = 1; i <= FINAL_STEP; i++) { ... } /* Enlarge & shrink */ pImage = &_aImage[Index1]; GUI_MEMDEV_CopyFromLCD(hLCDEnlarge); GUI_MEMDEV_Select(hDstEnlarge); Add = 1; Mag = MAG; i = 0; do { TimeContinue = GUI_GetTime() + MIN_TIME_PER_FRAME_ENLARGE; /* Use HQ or not */ if (i == 0) { pfRotate = GUI_MEMDEV_RotateHQ; }if (i == 0) { ... } else { pfRotate = GUI_MEMDEV_Rotate; }else { ... } /* Calculate magnification */ if (Add > 0) { Mag = (Mag * 1050) / 1000; }if (Add > 0) { ... } else { Mag = (Mag * 1000) / 1050; }else { ... } if (Mag < MAG) { Mag = MAG; }if (Mag < MAG) { ... } /* Do the animation */ GUI_MEMDEV_Write(hLCDEnlarge); pfRotate(pImage->hMem, hDstEnlarge, (((xSize * 2) / 3) - pImage->xSize) / 2, (ySize - pImage->ySize) / 2, 0, Mag); /* Display the result */ GUI_MULTIBUF_Begin(); GUI_MEMDEV_CopyToLCD(hDstEnlarge); GUI_MULTIBUF_End(); i += Add; if (i == 20) { Add = -Add; }if (i == 20) { ... } /* Add some delay to achieve minimum timing */ TimeNow = GUI_GetTime(); if (TimeContinue > TimeNow) { GUI_Delay(TimeContinue - TimeNow); }if (TimeContinue > TimeNow) { ... } ...} while (i > 0); /* Modify the pictures positions */ if (Index == 0) { Index = _NumImages - 1; }if (Index == 0) { ... } else { Index--; }else { ... } /* Delete the MEMDEVS used */ GUI_MEMDEV_Delete(hLCD); GUI_MEMDEV_Delete(hDstShift); GUI_MEMDEV_Delete(hDstEnlarge); GUI_MEMDEV_Delete(hLCDEnlarge); hLCD = 0; hDstShift = 0; hDstEnlarge = 0; hLCDEnlarge = 0; return 0; }{ ... } /** * @brief Main application * @param None * @retval None *//* ... */ void MainTask(void) { int xSize; int ySize; int i; /* Get the screen size */ xSize = LCD_GetXSize(); ySize = LCD_GetYSize(); /* Get the used images and write them to their respective memdevs */ for (i = 0; i < _NumImages; i++) { if (_GetImage(&_aImage[i])) { return; }if (_GetImage(&_aImage[i])) { ... } }for (i = 0; i < _NumImages; i++) { ... } /* Loop infinetly on the animations */ while (1) { /* Rotation & zoom animation */ if (_RotateAndZoomImage()) { break; }if (_RotateAndZoomImage()) { ... } /* Then the shift, rotate & zoom one */ if (_ShiftRotateAndZoomImage()) { break; }if (_ShiftRotateAndZoomImage()) { ... } }while (1) { ... } /* In case of an error will be here */ GUI_SetBkColor(GUI_BLACK); GUI_SetColor(GUI_WHITE); GUI_Clear(); GUI_DispStringHCenterAt("Error occurred. Application stopped!", xSize / 2, ySize / 2); /* Loop on the error message */ while (1) { GUI_Delay(100); }while (1) { ... } }{ ... }
Details