Chameleon

Chameleon Svn Source Tree

Root/branches/cparm/i386/modules/Libeg/tryme.c

  • Property svn:executable set to *
1/*
2 *
3 * Copyright (c) 2012-2013 Cadet-Petit Armel
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * * Neither the name of Cadet-Petit Armel nor the names of the
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#include "libegint.h"
36#include <xml.h>
37#include <IOGraphics.h>
38#include <pexpert/i386/modules.h>
39#include <sys/time.h>
40#include <ctype.h>
41#include <string.h>
42#include "pngfile.h"
43
44//#include "art.h"
45
46
47#ifndef DEBUG_TRYME
48#define DEBUG_TRYME 0
49#endif
50
51#if DEBUG_TRYME
52#define DBG(x...)printf(x)
53#else
54#define DBG(x...)
55#endif
56
57#ifndef MIN
58#define MIN(x, y) ((x) < (y) ? (x) : (y))
59#endif
60
61#ifndef MAX
62#define MAX(x, y) ((x) > (y) ? (x) : (y))
63#endif
64
65#define VIDEO(x) (((boot_args*)getBootArgs())->Video.v_ ## x)
66
67#define vram VIDEO(baseAddr)
68
69#define arc4random_unirange(lo,hi) arc4random_uniform(hi - lo + 1) + lo
70#define arc4random_range(lo,hi) (arc4random() % (hi - lo + 1)) + lo
71
72EG_PIXEL StdBackgroundPixel = { 0xbf, 0xbf, 0xbf, 0 };
73EG_PIXEL MenuBackgroundPixel = { 0xbf, 0xbf, 0xbf, 0 };
74EG_PIXEL BlackColor = { 0xff, 0xff, 0xff, 0 };
75
76extern long GetDirEntry(const char *dirSpec, long long *dirIndex, const char **name,
77 long *flags, long *time);
78extern long GetFileInfo(const char *dirSpec, const char *name,
79 long *flags, long *time);
80
81extern int getc(void);
82
83#define DEFAULT_SCREEN_WIDTH 1024
84#define DEFAULT_SCREEN_HEIGHT 768
85
86#define VGA_TEXT_MODE 0
87#define GRAPHICS_MODE 1
88#define FB_TEXT_MODE 2
89
90unsigned long screen_params[4] = {DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT, 32, 0};// here we store the used screen resolution
91config_file_t themeConfig; // theme.plist
92
93bool LoadEmbedGui(void);
94
95#define CHARACTERS_COUNT223
96
97/*
98 * Font structure.
99 */
100typedef struct {
101UINTNHeight;// Font Height
102UINTNWidth;// Font Width for monospace font only
103EG_IMAGE*chars[CHARACTERS_COUNT];
104UINTN count; // Number of chars in font
105} EG_FONT;
106
107typedef union {
108 struct {
109 UINT8 b;
110 UINT8 g;
111 UINT8 r;
112 UINT8 a;
113 } ch;
114 UINT8 channel[4];
115 UINT32 value;
116} EG_LEGACY_PIXEL;
117
118typedef struct {
119 UINT16height;
120 UINT16width;
121 EG_LEGACY_PIXEL*pixels;
122} EG_LEGACY_IMAGE;
123
124typedef struct {
125 UINT32 x;
126 UINT32 y;
127} EG_POSITION;
128
129#define PIXEL(p,x,y) ((p)->PixelData[(x) + (y) * (p)->Width])
130#define LEGACY_PIXEL(p,x,y,w) (((EG_LEGACY_PIXEL*)(p))[(x) + (y) * (w)])
131
132// File Permissions and Types
133enum {
134 kPermOtherExecute = 1 << 0,
135 kPermOtherWrite = 1 << 1,
136 kPermOtherRead = 1 << 2,
137 kPermGroupExecute = 1 << 3,
138 kPermGroupWrite = 1 << 4,
139 kPermGroupRead = 1 << 5,
140 kPermOwnerExecute = 1 << 6,
141 kPermOwnerWrite = 1 << 7,
142 kPermOwnerRead = 1 << 8,
143 kPermMask = 0x1FF,
144 kOwnerNotRoot = 1 << 9,
145 kFileTypeUnknown = 0x0 << 16,
146 kFileTypeFlat = 0x1 << 16,
147 kFileTypeDirectory = 0x2 << 16,
148 kFileTypeLink = 0x3 << 16,
149 kFileTypeMask = 0x3 << 16
150};
151
152static long long
153timeval_diff(struct timeval *difference,
154 struct timeval *end_time,
155 struct timeval *start_time
156 )
157{
158 struct timeval temp_diff;
159
160 if(difference==NULL)
161 {
162 difference=&temp_diff;
163 }
164
165 difference->tv_sec =end_time->tv_sec -start_time->tv_sec ;
166 difference->tv_usec=end_time->tv_usec-start_time->tv_usec;
167
168 /* Using while instead of if below makes the code slightly more robust. */
169
170 while(difference->tv_usec<0)
171 {
172 difference->tv_usec+=1000000;
173 difference->tv_sec -=1;
174 }
175
176 return 1000000LL*difference->tv_sec+
177 difference->tv_usec;
178
179}
180
181extern const char *getToken(const char *line, const char **begin, int *len);
182
183bool getValueForConfigTableKey(config_file_t *config, const char *key, const char **val, int *size)
184{
185
186if (config->dictionary != 0 ) {
187// Look up key in XML dictionary
188TagPtr value;
189value = XMLGetProperty(config->dictionary, key);
190if (value != 0) {
191if (value->type != kTagTypeString) {
192printf("Non-string tag '%s' found in config file\n",
193 key);
194abort();
195return false;
196}
197*val = value->string;
198*size = strlen(value->string);
199return true;
200}
201} else {
202
203// Legacy plist-style table
204
205}
206
207return false;
208}
209
210extern bool getValueForBootKey(const char *line, const char *match, const char **matchval, int *len);
211extern bool getValueForKey( const char *key, const char **val, int *size, config_file_t *config );
212extern bool getIntForKey(const char *key, int *val, config_file_t *configBuff);
213extern int loadConfigFile(const char *configFile, config_file_t *configBuff);
214
215static bool getDimensionForKey( const char *key, unsigned int *value, config_file_t *config, unsigned int dimension_max, unsigned int object_size )
216{
217const char *val;
218
219 int size = 0;
220int sum = 0;
221
222bool negative = false;
223bool percentage = false;
224
225 if (getValueForKey(key, &val, &size, config))
226{
227if ( size )
228{
229if (*val == '-')
230{
231negative = true;
232val++;
233size--;
234}
235
236if (val[size-1] == '%')
237{
238percentage = true;
239size--;
240}
241
242// convert string to integer
243for (sum = 0; size > 0; size--)
244{
245if (*val < '0' || *val > '9')
246return false;
247
248sum = (sum * 10) + (*val++ - '0');
249}
250
251if (percentage)
252sum = ( dimension_max * sum ) / 100;
253
254// calculate offset from opposite origin
255if (negative)
256sum = ( ( dimension_max - object_size ) - sum );
257
258} else {
259
260// null value calculate center
261sum = ( dimension_max - object_size ) / 2;
262
263}
264
265*value = (uint16_t) sum;
266return true;
267}
268
269// key not found
270 return false;
271}
272
273static bool getColorForKey( const char *key, unsigned int *value, config_file_t *config )
274{
275 const char *val;
276 int size;
277
278 if (getValueForKey(key, &val, &size, config))
279{
280if (*val == '#')
281{
282 val++;
283*value = strtol(val, NULL, 16);
284return true;
285 }
286 }
287 return false;
288}
289
290BOOLEAN LoadGui(VOID)
291{
292
293intval;
294long long index = 0;
295uint32_t color = 0 ;// color value formatted RRGGBB
296unsigned int pixel;
297 EG_IMAGE_VIEW * deviceView = NULL;
298 //EG_IMAGE_VIEW *PoofImageView[5] ;
299 EG_IMAGE_VIEW * iconeRef = NULL;
300EG_VIEW * screen = NULL;
301
302UINT8ImagesType = 0;
303
304long ret, length, flags, time;
305CONSTCHAR8 * name;
306
307CHAR8 dirspec[512];
308BOOLEAN THEMEDIR_FOUND = FALSE;
309
310ret = GetFileInfo("rd(0,0)/Extra/Themes/", "Default", &flags, &time);
311if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory))
312{
313snprintf(dirspec, sizeof(dirspec),"rd(0,0)/Extra/Themes/Default/");
314THEMEDIR_FOUND = TRUE;
315
316}
317else
318{
319
320ret = GetFileInfo("/Extra/Themes/", "Default", &flags, &time);
321if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory))
322{
323snprintf(dirspec, sizeof(dirspec), "/Extra/Themes/Default/");
324THEMEDIR_FOUND = TRUE;
325
326}
327else
328{
329ret = GetFileInfo("bt(0,0)/Extra/Themes/", "Default", &flags, &time);
330if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory))
331{
332snprintf(dirspec, sizeof(dirspec),"bt(0,0)/Extra/Themes/Default/");
333THEMEDIR_FOUND = TRUE;
334
335}
336}
337}
338
339if (THEMEDIR_FOUND == FALSE)
340{
341return FALSE;
342}
343
344{
345// parse themeconfig file
346CHAR8 configdirspec[1024];
347snprintf(configdirspec, sizeof(configdirspec), "%stheme.plist",dirspec);
348
349if (loadConfigFile (configdirspec, &themeConfig) != 0)
350{
351DBG("Unable to load embed theme plist datas.\n");
352
353return FALSE;
354}
355
356DBG("themeconfig file parsed\n");
357
358// parse display size parameters (if any)
359if (getIntForKey("screen_width", &val, &themeConfig) && val > 0) {
360screen_params[0] = val;
361}
362if (getIntForKey("screen_height", &val, &themeConfig) && val > 0) {
363screen_params[1] = val;
364}
365
366screen = egCreateView(screen_params[0], screen_params[1], TRUE);
367if (!screen) {
368
369return FALSE;
370}
371DBG("screen buffer created\n");
372
373if(getColorForKey("screen_bgcolor", &color, &themeConfig) && color)
374{
375color = (color & 0x00FFFFFF);
376EG_PIXEL Color;
377
378Color.r = ((color >> 16) & 0xFF) ;
379Color.g = ((color >> 8) & 0xFF) ;
380Color.b = ((color) & 0xFF) ;
381Color.a = 255;
382egViewSetBackgroundColor(screen,&Color);
383
384}
385else
386{
387// flush CompImage
388EG_PIXEL Color;
389Color.r = 0 ;
390Color.g = 0 ;
391Color.b = 0 ;
392Color.a = 0;
393egViewSetBackgroundColor(screen,&Color);
394
395}
396}
397
398while (1) {
399ret = GetDirEntry(dirspec, &index, &name, &flags, &time);
400if (ret == -1) break;
401
402if (!name) continue;
403
404DBG("testing %s\n", name);
405
406// Make sure this is a not directory.
407if ((flags & kFileTypeMask) != kFileTypeFlat) continue;
408
409length = AsciiStrLen(name);
410
411if (!length) continue;
412
413// Make sure the image file is supported.
414{
415if (AsciiStriCmp(name + length - 4, ".png") == 0)
416{
417ImagesType = 1 ;//"PNG"
418}
419else if (AsciiStriCmp(name + length - 4, ".bmp") == 0)
420{
421ImagesType = 2 ;//"BMP"
422
423}
424else if (AsciiStriCmp(name + length - 4, ".icns") == 0)
425{
426ImagesType = 3 ;//"ICNS"
427}
428else
429{
430DBG("Image %s format is not supported and will be ignored\n", name);
431continue;
432}
433}
434
435if (!(ImagesType > 0)) {
436continue;
437}
438
439CHAR8 FilePath8[1024];
440snprintf(FilePath8, sizeof(FilePath8), "%s%s",dirspec,name);
441
442//CHAR16 FilePath[1024];
443//AsciiStrToUnicodeStr(FilePath8, FilePath);
444
445DBG("loading %s\n", name);
446EG_IMAGE * image = NULL/*egLoadImage(FilePath, TRUE)*/;
447
448//if (!image) continue;
449
450{
451void *BkgColor = NULL;
452const char*pstrFileName = FilePath8;
453int piWidth = 0;
454int piHeight = 0;
455unsigned char *ppbImageData = NULL ;
456int piChannels = 0;
457bool ret ;
458ret = PngLoadImage (pstrFileName, &ppbImageData,
459&piWidth, &piHeight, &piChannels, BkgColor);
460
461if (ret != FALSE) {
462
463image = egCreateImageFromData((EG_PIXEL *)ppbImageData, piWidth, piHeight, (piChannels == 4) ? TRUE : FALSE, TRUE);
464
465if (!image) continue;
466}
467}
468
469DBG("Creating view for %s\n", name);
470
471CHAR16 name16[128];
472AsciiStrToUnicodeStr(name, name16);
473
474if (ImagesType == 1 ) //"PNG"
475{
476DBG("png file detected\n");
477
478if (strcmp(name,"logo.png") == 0)
479{
480DBG("computing logo.png\n");
481
482EG_POSITION pos ;
483/*
484pos.x = (screen_params[0] - MIN(image->Width, screen_params[0])) /2;
485pos.y = (screen_params[1] - MIN(image->Height, screen_params[1])) /2;
486
487if(getDimensionForKey("logo_pos_x", &pixel, &themeConfig, screen_params[0] , image->Width ) )
488pos.x = pixel;
489
490if(getDimensionForKey("logo_pos_y", &pixel, &themeConfig, screen_params[1] , image->Height ) )
491pos.y = pixel;
492*/
493pos.y = 20;
494pos.x = 20;
495
496
497EG_IMAGE_VIEW * TopImageView = egCreateImageViewFromData((EG_PIXEL *)image->PixelData, image->Width, image->Height, TRUE , pos.x, pos.y, name16, TRUE);
498
499if (TopImageView) {
500egViewAddImageView(screen, TopImageView);
501egFreeImageView(TopImageView);
502}
503
504egFreeImage(image);
505
506
507}
508else if (strcmp(name,"device_hfsplus.png")==0)
509{
510DBG("computing device_hfsplus.png\n");
511
512EG_POSITION pos ;
513pos.x = 0;
514pos.y = 0;
515
516if(getDimensionForKey("devices_pos_x", &pixel, &themeConfig, screen_params[0] , image->Width ) )
517pos.x = pixel;
518else
519pos.x = (screen_params[0] - MIN(image->Width, screen_params[0])) /2;
520
521if(getDimensionForKey("devices_pos_y", &pixel, &themeConfig, screen_params[1] , image->Height ) )
522pos.y = pixel;
523else
524pos.y = (screen_params[1] - MIN(image->Height, screen_params[1])) /2;
525
526EG_IMAGE_VIEW * TopImageView = egCreateImageViewFromData((EG_PIXEL *)image->PixelData, image->Width, image->Height, TRUE , pos.x, pos.y, name16, TRUE);
527
528if (TopImageView) {
529deviceView = egViewAddImageView(screen, TopImageView);
530egFreeImageView(TopImageView);
531}
532
533egFreeImage(image);
534
535
536}
537else
538DBG("file not handled\n");
539
540}
541else if (ImagesType == 3 ) //"ICNS"
542{
543DBG("icns file detected\n");
544
545EG_IMAGE * icnsImage = NULL;
546if ((icnsImage = egDecodeICNS((UINT8 *)image->PixelData, image->Width * image->Height * 4, 128, TRUE)))
547{
548
549EG_IMAGE_VIEW * iconeView = egCreateImageViewFromData((EG_PIXEL *)image->PixelData, image->Width, image->Height, TRUE , 20, 20, name16, TRUE);
550
551if (iconeView) {
552iconeRef = egViewAddImageView(screen, iconeView);
553egFreeImageView(iconeView);
554}
555
556egFreeImage(icnsImage);
557egFreeImage(image);
558
559
560}
561}
562
563}
564
565
566if (!screen) {
567return FALSE;
568}
569
570 __setVideoMode( GRAPHICS_MODE );
571 egViewUpdate(screen);
572
573 getc();
574DBG("LETS HAVE SOME FUN\n"); // you should never see this message
575
576
577/********************************
578 **
579 *LETS HAVE SOME FUN *
580 **
581 **
582 ********************************/
583
584#define TEXT_YMARGIN (2)
585#define LAYOUT_TEXT_WIDTH (512)
586#define LAYOUT_TOTAL_HEIGHT (368)
587#define FONT_CELL_HEIGHT (12)
588#define TEXT_LINE_HEIGHT (FONT_CELL_HEIGHT + TEXT_YMARGIN * 2)
589
590
591 UINTN px = (screen_params[0] - MIN(((LAYOUT_TEXT_WIDTH *2 )/ 10) , screen_params[0])) /2, i;
592 UINTN py = (screen_params[1] - MIN(((TEXT_LINE_HEIGHT * 8) / 10) , screen_params[1])) /2;
593 EG_IMAGE_VIEW * ConsoleImageView = egCreateImageView(LAYOUT_TEXT_WIDTH / 10, (TEXT_LINE_HEIGHT * 8) / 10, FALSE, px , py, L"SCREEN_Console");
594 assert(ConsoleImageView);
595 assert(ConsoleImageView->Image);
596
597 egFillImage(ConsoleImageView->Image, &MenuBackgroundPixel);
598
599 EG_IMAGE_VIEW * ConsoleImageViewRef = egViewAddImageView(screen, ConsoleImageView);
600 egFreeImageView(ConsoleImageView);
601 egViewUpdate(screen);
602
603 // ios/osx style window bounce effect
604 for (i = 1; ConsoleImageViewRef->Image->Width <= LAYOUT_TEXT_WIDTH *2*2; i++) {
605
606 if (ConsoleImageViewRef->Image->Height > TEXT_LINE_HEIGHT * 8 *2)
607 break;
608#define soustraction(x,y) ((x) - (y))
609 ConsoleImageViewRef->Image->Width += soustraction(i, (i==1)?0:1);
610 ConsoleImageViewRef->Image->Height += soustraction(i, (i==1)?0:1);
611 px = (screen_params[0] - MIN(ConsoleImageViewRef->Image->Width , screen_params[0])) /2;
612 py = (screen_params[1] - MIN(ConsoleImageViewRef->Image->Height , screen_params[1])) /2;
613
614 ConsoleImageViewRef->PosY = py ;
615 ConsoleImageViewRef->PosX = px ;
616
617 free(ConsoleImageViewRef->Image->PixelData);
618
619 ConsoleImageViewRef->Image->PixelData = (EG_PIXEL*)malloc(ConsoleImageViewRef->Image->Width * ConsoleImageViewRef->Image->Height * sizeof(EG_PIXEL));
620
621 egFillImage(ConsoleImageViewRef->Image, &MenuBackgroundPixel);
622 screen->isDirty = TRUE;
623 egViewUpdate(screen);
624
625
626 }
627
628 for (i = 0; i < 10; i++) {
629
630
631#define soustraction(x,y) ((x) - (y))
632 ConsoleImageViewRef->Image->Width -= i;
633 ConsoleImageViewRef->Image->Height -= i;
634 px = (screen_params[0] - MIN(ConsoleImageViewRef->Image->Width , screen_params[0])) /2;
635 py = (screen_params[1] - MIN(ConsoleImageViewRef->Image->Height , screen_params[1])) /2;
636
637 ConsoleImageViewRef->PosY = py ;
638 ConsoleImageViewRef->PosX = px ;
639
640 free(ConsoleImageViewRef->Image->PixelData);
641
642 ConsoleImageViewRef->Image->PixelData = (EG_PIXEL*)malloc(ConsoleImageViewRef->Image->Width * ConsoleImageViewRef->Image->Height * sizeof(EG_PIXEL));
643
644 egFillImage(ConsoleImageViewRef->Image, &MenuBackgroundPixel);
645
646 screen->isDirty = TRUE;
647 egViewUpdate(screen);
648
649
650 }
651egViewRemoveImageView(screen, ConsoleImageViewRef);
652
653 /*
654 UINTN TextWidth;
655
656 EG_POSITION pos ;
657 pos.x = (screen_params[0] - MIN(LAYOUT_TEXT_WIDTH, screen_params[0])) /2;
658 pos.y = (screen_params[1] - MIN(TEXT_LINE_HEIGHT, screen_params[1])) /2;
659 if (deviceView) {
660 pos.y = deviceView->PosY - 10;
661
662 }
663
664 EG_IMAGE_VIEW * TextImageView = egCreateImageView(LAYOUT_TEXT_WIDTH, TEXT_LINE_HEIGHT, FALSE, pos.x, pos.y , L"SCREEN_HEADER");
665
666 assert(TextImageView);
667 assert(TextImageView->Image);
668
669 egFillImage(TextImageView->Image, &MenuBackgroundPixel);
670
671 // render the text
672 egMeasureText(L"WELCOME TO THE EG GRAPHIC TEST... PRESS ANY KEY TO CONTINUE.", &TextWidth, NULL);
673 egRenderText(L"WELCOME TO THE EG GRAPHIC TEST... PRESS ANY KEY TO CONTINUE.", TextImageView->Image, (TextImageView->Image->Width - TextWidth) >> 1, 2);
674
675 egViewAddImageView(screen, TextImageView);
676 egFreeImageView(TextImageView);
677 egViewUpdate(screen);
678 getc();
679 egViewRemoveImageViewByName(screen, L"SCREEN_HEADER", sizeof(L"SCREEN_HEADER"));
680 */
681 egViewUpdate(screen);
682 getc();
683 deviceView = deviceView ? deviceView : iconeRef;
684 if (deviceView) {
685 struct timeval earlier;
686 struct timeval later;
687
688 uint32_t c;
689 uint32_t i;
690 uint32_t x,y;
691 uint32_t x2,y2;
692
693 for (c = 0; c < 5; c++) {
694 if(gettimeofday(&earlier,NULL))
695 {
696 assert(1);
697 }
698 int inc = 1,count = 0;
699 x = deviceView->PosX;
700 y = deviceView->PosY;
701
702 int inc2 = 1,count2 = 0;
703 x2 = iconeRef->PosX;
704 y2 = iconeRef->PosY;
705
706 // bounce left to right test (aka say NO)
707 for (i = 0; i<100; i++) {
708
709 if (count >= 5 && count2 >= 5) break;
710
711 if (count < 5) {
712 if (deviceView->PosX >= x )
713 {
714 if (deviceView->PosX == x )
715 {
716 count++;
717 if (count == 5) {
718 screen->isDirty = TRUE;
719 egViewUpdate(screen);
720 inc = -1;
721 } else inc = 1;
722 }
723
724 if (inc >= 0)
725 {
726 if (deviceView->PosX >= x+10 ) {
727 deviceView->PosX-=2;
728 inc = 0;
729 screen->isDirty = TRUE;
730
731 }
732 else
733 {
734 if (inc == 1) {
735 deviceView->PosX+=2;
736
737 } else deviceView->PosX-=2;
738 screen->isDirty = TRUE;
739
740
741 }
742 }
743
744
745
746
747 }
748 }
749
750 egViewUpdate(screen);
751
752 if (count2 < 5 && deviceView != iconeRef) {
753 if (iconeRef->PosX >= x2 )
754 {
755 if (iconeRef->PosX == x2 )
756 {
757 count2++;
758 if (count2 == 5) {
759 screen->isDirty = TRUE;
760 egViewUpdate(screen);
761 inc2 = -1;
762 } else inc2 = 1;
763 }
764
765 if (inc2 >= 0)
766 {
767 if (iconeRef->PosX >= x2+10 ) {
768 iconeRef->PosX-=2;
769 inc2 = 0;
770 screen->isDirty = TRUE;
771
772 }
773 else
774 {
775 if (inc2 == 1) {
776 iconeRef->PosX+=2;
777
778 } else iconeRef->PosX-=2;
779 screen->isDirty = TRUE;
780
781 }
782 }
783
784
785 }
786 }
787
788 }
789 if(gettimeofday(&later,NULL))
790 {
791
792 exit(1);
793 }
794
795 CHAR16 Destination[512];
796
797 SPrint (
798 Destination,
799 sizeof(Destination),
800 L"animation %d took %lld microseconds to finish", c,
801 timeval_diff(NULL,&later,&earlier));
802
803 UINTN TextWidth;
804
805 EG_POSITION pos ;
806 pos.x = (screen_params[0] - MIN(LAYOUT_TEXT_WIDTH, screen_params[0])) /2;
807 pos.y = (screen_params[1] - MIN(TEXT_LINE_HEIGHT, screen_params[1])) /2;
808 if (deviceView) {
809 pos.y = deviceView->PosY + 10;
810
811 }
812
813 EG_IMAGE_VIEW * TextImageView = egCreateImageView(300, TEXT_LINE_HEIGHT, FALSE, pos.x, pos.y , L"SCREEN_NOTIFICATION");
814
815 assert(TextImageView);
816 assert(TextImageView->Image);
817 MenuBackgroundPixel.a -=50;
818 egFillImage(TextImageView->Image, &MenuBackgroundPixel);
819
820 // render the text
821 egMeasureText(Destination, &TextWidth, NULL);
822 egRenderText(Destination, TextImageView->Image, (TextImageView->Image->Width - TextWidth) >> 1, 2);
823
824 egViewAddImageView(screen, TextImageView);
825 egFreeImageView(TextImageView);
826 egViewUpdate(screen);
827
828 getc();
829 egViewRemoveImageViewByName(screen, L"SCREEN_NOTIFICATION", sizeof(L"SCREEN_NOTIFICATION"));
830
831 }
832
833
834 // change background test
835 EG_PIXEL *bColor = egViewGetBackgroundColor(screen); // save original color
836 for (i = 0; i<15; i++) {
837 EG_PIXEL Color;
838 Color.r = arc4random_unirange(0,255) ;
839 Color.g = arc4random_unirange(0,255) ;
840 Color.b = arc4random_unirange(0,255) ;
841 Color.a = arc4random_unirange(0,255);
842
843 egViewSetBackgroundColor(screen, &Color);
844 delay(100000);
845 egViewUpdate(screen);
846 }
847 sleep(1);
848 egViewSetBackgroundColor(screen,bColor); // restore color
849 free(bColor);
850
851 // move image test
852 for (i = 0; i<100; i++) {
853
854
855
856 deviceView->PosX +=2;
857 deviceView->PosY +=2;
858
859 screen->isDirty = TRUE;
860
861 egViewUpdate(screen);
862 }
863
864 int incx , incy ;
865 int bxpl , bypl ;
866
867
868 incx = arc4random_unirange(0,1);
869 incy = arc4random_unirange(0,1);
870
871 bxpl = arc4random_unirange(3,6);
872 bypl = arc4random_unirange(3,6);
873
874
875 for (i = 0; i<5000; i++) {
876
877
878
879 if (deviceView->PosX >= bxpl && incx <= 0) {
880 deviceView->PosX -=bxpl;
881 incx = 0;
882
883 }
884 else if (deviceView->PosX + deviceView->Image->Width + bxpl < screen->CompImage->Width )
885 {
886 deviceView->PosX +=bxpl;
887 if (incx != 1) {
888 // will exit rect
889 bxpl = arc4random_unirange(3,6);
890
891 }
892 incx = 1;
893 }
894 else if (deviceView->PosX + deviceView->Image->Width + bxpl >= screen->CompImage->Width && incx != 0)
895 {
896 incx = -1;
897 bxpl = arc4random_unirange(3,6);
898
899 //continue;
900 }
901
902
903 if (deviceView->PosY >= bypl && incy <= 0) {
904 deviceView->PosY -=bypl;
905 incy = 0;
906
907 }
908 else if (deviceView->PosY + deviceView->Image->Height + bypl < screen->CompImage->Height )
909 {
910 deviceView->PosY += bypl;
911
912 if (incy != 1) {
913 // will exit rect (top)
914 bypl = arc4random_unirange(3,6);
915
916 }
917
918 incy = 1;
919 }
920 else if (deviceView->PosY + deviceView->Image->Height + bypl >= screen->CompImage->Height && incy != 0)
921 {
922 // will exit rect ( bottom)
923
924 incy = -1;
925 bypl = arc4random_unirange(3,6);
926
927 //continue;
928 }
929
930 if (incy>= 0 && incx>=0) {
931 screen->isDirty = TRUE;
932
933 egViewUpdate(screen);
934 }
935
936
937
938 }
939
940 getc();
941
942 egViewRemoveImageViewByName(screen, L"plug_in_Icon", sizeof(L"plug_in_Icon"));
943 egViewUpdate(screen);
944 getc();
945
946 }
947
948 __setVideoMode(VGA_TEXT_MODE);
949
950 egFreeView(screen);
951
952return TRUE;
953
954}
955

Archive Download this file

Revision: 2182