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

Archive Download this file

Revision: 2183