-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathegi.c
879 lines (729 loc) · 23.4 KB
/
egi.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
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
/*----------------------------------------------------------------------------
embedded graphic interface based on frame buffer, 16bit color tft-LCD.
Very simple concept:
0. Basic philosophy: Loop and Roll-back.
1. The basic elements of egi objects are egi_element boxes(ebox).
2. All types of EGI objects are inherited from basic eboxes. so later it will be
easy to orgnize and manage them.
3. Only one egi_page is active on the screen.
4. An active egi_page occupys the whole screen.
5. An egi_page hosts several type of egi_ebox, such as type_txt,type_button,...etc.
6. First init egi_data_xxx for different type, then init the egi_element_box with it.
7. some ideas about egi_page ....
7.0 Life-circle of a page:
create a page ---> activate the page ---> run page routine ---> exit the routine ---> free the page.
7.1 Home egi_page (wallpaper, app buttons, head informations ...etc.)
7.2 Current active egi_page (current running/displaying egi_page, accept all pad-touch events)
7.3 Back Running egi_page (running in back groud, no pad-touch reaction. )
7.4 A egi page
TODO:
0. egi_txtbox_filltxt(),fill txt buffer of txt_data->txt.
1. different symbol types in a txt_data......
2. egi_init_data_txt(): llen according to ebox->height and width.---not necessary if multiline auto. adjusting.
3. To read FBDE vinfo to get all screen/fb parameters as in fblines.c, it's improper in other source files.
Midas Zhou
[email protected](Not in use since 2022_03_01)
------------------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h> /*malloc*/
#include <string.h> /*memset*/
#include <unistd.h> /*usleep*/
#include "egi.h"
#include "egi_timer.h"
#include "egi_txt.h"
#include "egi_btn.h"
#include "egi_list.h"
#include "egi_pic.h"
#include "egi_slider.h"
#include "egi_debug.h"
#include "sys_list.h"
#include "egi_symbol.h"
#include "egi_color.h"
/* button touch status and events:
* corresponding to enum egi_touch_status in egi.h
*/
static const char *str_touch_status[]=
{
"unkown", /* during reading or fails */
"releasing", /* status transforming from pressed_hold to released_hold */
"pressing", /* status transforming from released_hold to pressed_hold */
"released_hold",
"pressed_hold",
"db_releasing", /* double click, the last releasing */
"db_pressing", /* double click, the last pressing */
"undefined",
};
/* convert touch status to string */
const char *egi_str_touch_status(enum egi_touch_status touch_status)
{
enum egi_touch_status status_unkown=unkown;
enum egi_touch_status status_undefined=undefined;
if( touch_status >=status_unkown && touch_status < status_undefined )
return str_touch_status[touch_status];
else
return str_touch_status[status_undefined];
}
/*---- !!! OBOSELETE: See to egi_math.c: mat_random_range() !!! ---------
return a random value not great than max
Example:
egi_random_max(5): 1,2,3,4,5
egi_random_max(-5): -3,-2,-1,0,1
max>0: 1<= ret <=max
max=0: 1
max<0: max+2 <= ret <=1
------------------------------------------------------------*/
int egi_random_max(int max)
{
int ret;
struct timeval tmval;
gettimeofday(&tmval,NULL);
srand(tmval.tv_usec);
ret = 1+(int)((float)max*rand()/(RAND_MAX+1.0));
//printf("random max ret=%d\n",ret);
return ret;
}
/*---------------------------------------------------------------------
allocate memory for ebox->bkimg with specified H and W, in 16bit color.
!!! height/width and ebox->height/width MAY NOT be the same.
ebox: pointer to an ebox
height: height of an image.
width: width of an image.
Return:
pointer to the mem. OK
NULL fail
------ --------------------------------------------------------------*/
void *egi_alloc_bkimg(EGI_EBOX *ebox, int width, int height)
{
/* 1. check data */
if( height<=0 || width <=0 )
{
printf("egi_alloc_bkimg(): ebox height(%d) or width(%d) is <=0!\n",height,width);
return NULL;
}
/* 2. malloc exbo->bkimg for bk image storing */
if( ebox->bkimg != NULL)
{
printf("egi_alloc_bkimg(): ebox->bkimg is not NULL, fail to malloc!\n");
return NULL;
}
/* 3. alloc memory */
EGI_PDEBUG(DBG_EGI,"egi_alloc_bkimg(): start to malloc() ....!\n");
ebox->bkimg=malloc(height*width*sizeof(uint16_t));
if(ebox->bkimg == NULL)
{
printf("egi_alloc_bkimg(): fail to malloc for ebox->bkimg!\n");
return NULL;
}
EGI_PDEBUG(DBG_EGI,"egi_alloc_bkimg(): finish!\n");
return ebox->bkimg;
}
/*-------------------------------------------------------------------------
re_allocate memory for ebox->bkimg with specified H and W, in 16bit color.
NOTE:
1. "The contents will be unchanged in the range from the start of the region
up to the minimum of the old and new sizes. If the new size is larger than
the old size, the added memory will not be initialized." - man realloc
2. If it fails, the original mem of ebox->bkimg will not be changed or moved.
ebox: pointer to an ebox
height: height of an image.
width: width of an image.
Return:
pointer to the mem. OK
NULL fail
-------------------------------------------------------------------------*/
void *egi_realloc_bkimg(EGI_EBOX *ebox, int width, int height)
{
/* 1. check data */
if( height<=0 || width <=0 )
{
printf("egi_realloc_bkimg(): ebox height(%d) or width(%d) is <=0!\n",height,width);
return NULL;
}
/* 2. reallocate memory */
EGI_PDEBUG(DBG_EGI,"egi_realloc_bkimg(): start to realloc() ....!\n");
ebox->bkimg=realloc(ebox->bkimg, height*width*sizeof(uint16_t));
if(ebox->bkimg == NULL)
{
printf("egi_realloc_bkimg(): fail to realloc for ebox->bkimg!\n");
return NULL;
}
EGI_PDEBUG(DBG_EGI,"egi_realloc_bkimg(): finish!\n");
return ebox->bkimg;
}
/*---------- obselete!!!, substitued by egi_getindex_ebox() now!!! ----------------
check if (px,py) in the ebox
return true or false
!!!--- ebox local coordinate original is NOT sensitive in this function ---!!!
--------------------------------------------------------------------------------*/
bool egi_point_inbox(int px,int py, EGI_EBOX *ebox)
{
int xl,xh,yl,yh;
int x1=ebox->x0;
int y1=ebox->y0;
int x2=x1+ebox->width;
int y2=y1+ebox->height;
if(x1>=x2){
xh=x1;xl=x2;
}
else {
xl=x1;xh=x2;
}
if(y1>=y2){
yh=y1;yl=y2;
}
else {
yh=y2;yl=y1;
}
if( (px>=xl && px<=xh) && (py>=yl && py<=yh))
return true;
else
return false;
}
/*------------------------------------------------------------------
1. find the ebox index according to given x,y
2. a sleeping ebox will be ignored.
x,y: point at request
ebox: ebox pointer
num: total number of eboxes referred by *ebox.
return:
>=0 Ok, as ebox pointer index
<0 not in eboxes
-------------------------------------------------------------------*/
int egi_get_boxindex(int x,int y, EGI_EBOX *ebox, int num)
{
int i=num;
/* Now we only consider button ebox*/
if(ebox->type==type_btn)
{
for(i=0;i<num;i++)
{
if(ebox[i].status==status_sleep)continue; /* ignore sleeping ebox */
if( x>=ebox[i].x0 && x<=ebox[i].x0+ebox[i].width \
&& y>=ebox[i].y0 && y<=ebox[i].y0+ebox[i].height )
return i;
}
}
return -1;
}
/*-----------------------------------------------------------------------------
1. In a page, find the ebox index according to given x,y
2. A sleeping/hidden ebox will be ignored.
3. Type may be multiple, like: type_txt|type_slider|type_btn ...etc.
@x,y: Point under request, under default coordinate system!!!
!!! TBD&TODO: Current ONLY for default gv_fb_dev coord. mapping !!!
@page: An egi page containing eboxes
return:
pointer to an ebox Ok
NULL fail or no ebox is hit.
------------------------------------------------------------------------------*/
EGI_EBOX *egi_hit_pagebox(int px, int py, EGI_PAGE *page, enum egi_ebox_type type)
{
int x=0,y=0;
struct list_head *tnode;
int xres= gv_fb_dev.vinfo.xres;
int yres= gv_fb_dev.vinfo.yres;
EGI_EBOX *ebox;
EGI_POINT *sxy;
EGI_POINT *exy;
/* check page */
if(page==NULL)
{
printf("egi_get_pagebtn(): page is NULL!\n");
return NULL;
}
/* check list */
if(list_empty(&page->list_head))
{
printf("egi_get_pagebtn(): page '%s' has no child ebox.\n",page->ebox->tag);
return NULL;
}
/* check FB.pos_rotate
* Map default touch coordinates to current pos_rotate coordinates.
*/
switch(gv_fb_dev.pos_rotate) {
case 0: /* FB defaul position */
x=px;
y=py;
break;
case 1: /* Clockwise 90 deg */
x=py;
y=(xres-1)-px;
break;
case 2: /* Clockwise 180 deg */
x=(xres-1)-px;
y=(yres-1)-py;
break;
case 3: /* Clockwise 270 deg */
x=(yres-1)-py;
y=px;
break;
}
/* traverse the list, not safe */
list_for_each(tnode, &page->list_head)
{
ebox=list_entry(tnode, EGI_EBOX, node);
//EGI_PDEBUG(DBG_EGI,"egi_get_pagebtn(): find child --- ebox: '%s' --- \n",ebox->tag);
sxy=&(ebox->touchbox.startxy);
exy=&(ebox->touchbox.endxy);
if(ebox->type & type)
{
/* ignore sleeping and hidden ebox */
if(ebox->status==status_sleep || ebox->status==status_hidden )
continue;
/* check whether the ebox is hit */
if( sxy->x==0 && exy->x==0 ) { /* 1. If touch box NOT defined */
if( x > ebox->x0 && x < ebox->x0+ebox->width \
&& y > ebox->y0 && y < ebox->y0+ebox->height )
return ebox;
}
else { /* 2. If touch box defined */
if( x > sxy->x && x < exy->x && y > sxy->y && y < exy->y )
return ebox;
}
}
}
return NULL;
}
/*------------------------------------------------
OBSOLETE!!!
all eboxes to be public !!!
return ebox status
-------------------------------------------------*/
enum egi_ebox_status egi_get_ebox_status(const EGI_EBOX *ebox)
{
return ebox->status;
}
///xxxxxxxxxxxxxxxxxxxxxxxxxx((( OK )))xxxxxxxxxxxxxxxxxxxxxxxxx
/*------------------------------------------------------------
put tag for an ebox
--------------------------------------------------------------*/
inline void egi_ebox_settag(EGI_EBOX *ebox, const char *tag)
{
/* 1. clear tag */
memset(ebox->tag,0,EGI_TAG_LENGTH+1);
/* 2. check data */
if(ebox == NULL)
{
printf("egi_ebox_settag(): EGI_EBOX *ebox is NULL, fail to set tag.\n");
return;
}
/* 3. set NULL */
if(tag == NULL)
{
// OK, set NULL, printf("egi_ebox_settag(): char *tag is NULL, fail to set tag.\n");
return;
}
/* 4. copy string to tag */
strncpy(ebox->tag,tag,EGI_TAG_LENGTH);
}
/*-------------------------------------------------------------------
put need_refresh flag true
!!! WARNING: The Caller must alert to avoid PAGE.pgmutex deadlock !!!
-------------------------------------------------------------------*/
inline void egi_ebox_needrefresh(EGI_EBOX *ebox)
{
if(ebox == NULL)
return;
/* Get pgmutex for parent PAGE resource access/synch */
if(ebox->container != NULL) {
if(pthread_mutex_lock(&(ebox->container)->pgmutex) !=0) {
printf("%s: Fail to get PAGE.pgmutex!\n",__func__);
return;
}
}
/* Race condition may still exist? */
ebox->need_refresh=true;
if(ebox->container != NULL)
pthread_mutex_unlock(&(ebox->container)->pgmutex);
}
/*---------------------------------------
set touch area
---------------------------------------*/
inline void egi_ebox_set_touchbox(EGI_EBOX *ebox, EGI_BOX box)
{
if(ebox != NULL)
ebox->touchbox=box;
}
/*----------------------------------------------------
ebox refresh: default method
reutrn:
1 use default method
0 OK
<0 fail
------------------------------------------------------*/
int egi_ebox_refresh(EGI_EBOX *ebox)
{
/* 1. check data */
if( ebox==NULL || ebox->egi_data==NULL )
{
printf("egi_ebox_refresh(): input ebox is invalid or NULL!\n");
return -1;
}
/* 2. put default methods here ...*/
if(ebox->method.refresh == NULL)
{
EGI_PDEBUG(DBG_EGI,"ebox '%s' has no defined method of refresh()!\n",ebox->tag);
return 1;
}
/* 3. ebox object defined method */
else
{
return ebox->method.refresh(ebox); /*only if need_refresh flag is true */
}
}
/*----------- NOT GOOD! ---------------
Force an ebox to refresh
----------------------------------------*/
int egi_ebox_forcerefresh(EGI_EBOX *ebox)
{
int ret;
if(ebox==NULL)
return -1;
/* Get pgmutex for parent PAGE resource access/synch */
if(ebox->container != NULL) {
if(pthread_mutex_lock(&(ebox->container)->pgmutex) !=0) {
printf("%s: Fail to get PAGE.pgmutex!\n",__func__);
return -2;
}
}
ebox->need_refresh=true;
if(egi_ebox_refresh(ebox)!=0)
ret=-3;
/* Put parent PAGE.pgmutex */
if(ebox->container != NULL)
pthread_mutex_unlock(&(ebox->container)->pgmutex);
return ret;
}
/*----------------------------------------------------
ebox activate: default method
reutrn:
1 use default method
0 OK
<0 fail
------------------------------------------------------*/
int egi_ebox_activate(EGI_EBOX *ebox)
{
/* 1. put default methods here ...*/
if(ebox->method.activate == NULL)
{
EGI_PDEBUG(DBG_EGI,"ebox '%s' has no defined method of activate()!\n",ebox->tag);
return 1;
}
/* 2. ebox object defined method */
else
return ebox->method.activate(ebox);
}
/*----------------------------------------------------
ebox refresh: default method
reutrn:
1 use default method
0 OK
<0 fail
------------------------------------------------------*/
int egi_ebox_sleep(EGI_EBOX *ebox)
{
/* 1. put default methods here ...*/
if(ebox->method.sleep == NULL)
{
EGI_PDEBUG(DBG_EGI,"ebox '%s' has no defined method of sleep()!\n",ebox->tag);
return 1;
}
/* 2. ebox object defined method */
else
return ebox->method.sleep(ebox);
}
/*----------------------------------------------------
ebox decorate: default method
reutrn:
1 use default method
0 OK
<0 fail
------------------------------------------------------*/
int egi_ebox_decorate(EGI_EBOX *ebox)
{
/* 1. put default methods here ...*/
if(ebox->method.decorate == NULL)
{
EGI_PDEBUG(DBG_EGI,"ebox '%s' has no defined method of decorate()!\n",ebox->tag);
return 1;
}
/* 2. ebox object defined method */
else
{
EGI_PDEBUG(DBG_EGI,"egi_ebox_decorate(): start ebox->method.decorate(ebox)...\n");
return ebox->method.decorate(ebox);
}
}
/*----------------------------------------------------
ebox refresh: default method
reutrn:
1 use default method
0 OK
<0 fail
------------------------------------------------------*/
int egi_ebox_free(EGI_EBOX *ebox)
{
/* check ebox */
if(ebox == NULL)
{
printf("egi_ebox_free(): pointer ebox is NULL! fail to free it.\n");
return -1;
}
/* 1. put default methods here ...*/
if(ebox->method.free == NULL)
{
EGI_PDEBUG(DBG_EGI,"ebox '%s' has no defined method of free(), now use default to free it ...!\n",ebox->tag);
/* 1.1 free ebox tyep data */
switch(ebox->type)
{
case type_txt:
if(ebox->egi_data != NULL)
{
EGI_PDEBUG(DBG_EGI,"egi_ebox_free():start to egi_free_data_txt(ebox->egi_data) \
for '%s' ebox\n", ebox->tag);
egi_free_data_txt(ebox->egi_data);
}
break;
case type_btn:
if(ebox->egi_data != NULL)
{
EGI_PDEBUG(DBG_EGI,"egi_ebox_free():start to egi_free_data_btn(ebox->egi_data) \
for '%s' ebox\n", ebox->tag);
egi_free_data_btn(ebox->egi_data);
}
break;
case type_list:
if(ebox->egi_data != NULL)
{
EGI_PDEBUG(DBG_EGI,"egi_ebox_free():start to egi_free_date_list(ebox->egi_data) \
for '%s' ebox\n", ebox->tag);
egi_free_data_list(ebox->egi_data);
}
break;
case type_pic:
if(ebox->egi_data != NULL)
{
EGI_PDEBUG(DBG_EGI,"egi_ebox_free():start to egi_free_date_pic(ebox->egi_data) \
for '%s' ebox\n", ebox->tag);
egi_free_data_pic(ebox->egi_data);
}
break;
case type_slider:
if(ebox->egi_data != NULL)
{
EGI_PDEBUG(DBG_EGI,"egi_ebox_free():start to egi_free_data_slider(ebox->egi_data) \
for '%s' ebox\n", ebox->tag);
egi_free_data_slider(ebox->egi_data);
}
break;
case type_page:
/* The PAGE has its own free method, however it will call egi_ebox_free()
* to release/free member page->ebox.
*/
break;
default:
printf("egi_ebox_free(): ebox '%s' type %d has not been created yet!\n",
ebox->tag,ebox->type);
return -2;
break;
}
/* 1.2 free frame_img */
if(ebox->frame_img != NULL) {
egi_imgbuf_free(ebox->frame_img);
ebox->frame_img=NULL;
}
/* 1.3 free ebox bkimg */
if(ebox->bkimg != NULL) {
free(ebox->bkimg);
ebox->bkimg=NULL;
}
/* 1.4 free concept ebox */
free(ebox);
ebox=NULL; /* ineffective though...*/
return 0;
}
/* 2. else, use ebox object defined method */
else
{
printf("use ebox '%s' selfe_defined free method to free it ...!\n",ebox->tag);
return ebox->method.free(ebox);
}
}
/*-------------------------------------------------------------------------------------
create a new ebox according to its type and parameters
WARNING: Memory for egi_data NOT allocated her, it's caller's job to allocate
and assign it to the new ebox. they'll be freed all together in egi_ebox_free().
return:
NULL fail
pointer OK
-------------------------------------------------------------------------------------*/
EGI_EBOX * egi_ebox_new(enum egi_ebox_type type) //, void *egi_data)
{
/* malloc ebox */
EGI_PDEBUG(DBG_EGI,"egi_ebox_new(): start to malloc for a new ebox....\n");
EGI_EBOX *ebox=malloc(sizeof(EGI_EBOX));
if(ebox==NULL)
{
printf("egi_ebox_new(): fail to malloc for a new ebox!\n");
return NULL;
}
memset(ebox,0,sizeof(EGI_EBOX)); /* clear data */
ebox->type=type;
/* assign default methods for new ebox */
EGI_PDEBUG(DBG_EGI,"egi_ebox_new(): assing default method to ebox ....\n");
ebox->activate=egi_ebox_activate;
ebox->refresh=egi_ebox_refresh;
ebox->decorate=egi_ebox_decorate;
ebox->sleep=egi_ebox_sleep;
ebox->free=egi_ebox_free;
/* other params are as default, after memset with 0:
* inmovable
* status=no_body
* frame=simple type
* prmcolor=BLACK
* bkimg=NULL
*/
EGI_PDEBUG(DBG_EGI,"egi_ebox_new(): end the call. \n");
return ebox;
}
/*------------------------------------------------------------------
disappearing effect for a full egi page, zoom out the page image to the top
left point
return:
0 OK
<0 fail
--------------------------------------------------------------------*/
int egi_page_disappear(EGI_EBOX *ebox)
{
int wid,hgt;
int bkwid,bkhgt; /* wid and hgt for backup */
int screensize=gv_fb_dev.screensize;
int xres=gv_fb_dev.vinfo.xres;
int yres=gv_fb_dev.vinfo.yres;
uint16_t *buf;
uint16_t *sbuf; /* for scaled image */
uint16_t *bkimg; /* bkimg for scaled area */
/* check ebox is a full egi page */
/* malloc buf */
buf=malloc(screensize);
if(buf==NULL)
{
printf("egi_page_disappear(): fail to malloc buf.\n");
return -1;
}
sbuf=malloc(screensize);
if(sbuf==NULL)
{
printf("egi_page_disappear(): fail to malloc sbuf.\n");
return -2;
}
bkimg=malloc(screensize);
if(bkimg==NULL)
{
printf("egi_page_disappear(): fail to malloc bkimg.\n");
return -3;
}
/* 1. grap current page image */
printf("start fb_cpyto_buf\n");
fb_cpyto_buf(&gv_fb_dev, 0, 0, xres-1, yres-1, buf);
printf("start for...\n");
/* 2. restore original page image */
fb_cpyfrom_buf(&gv_fb_dev,ebox->bkbox.startxy.x,ebox->bkbox.startxy.y,
ebox->bkbox.endxy.x,ebox->bkbox.endxy.y,ebox->bkimg);
fb_cpyto_buf(&gv_fb_dev,0,0,xres-1,yres-1,bkimg);
bkwid=xres;bkhgt=yres;
/* 3. zoom out to left top point */
for(wid=xres*3/4;wid>0;wid-=4)
{
/* 2.1 scale the image */
hgt=wid*yres/xres; //4/3;
fb_scale_pixbuf(xres,yres,wid,hgt,buf,sbuf);
/* 2.2 restore ebox bk image */
fb_cpyfrom_buf(&gv_fb_dev,0,0,bkwid-1,bkhgt-1,bkimg);
// fb_cpyfrom_buf(&gv_fb_dev,ebox->bkbox.startxy.x,ebox->bkbox.startxy.y,
// ebox->bkbox.endxy.x,ebox->bkbox.endxy.y,ebox->bkimg);
/* 2.3 store the area which will be replaced by scaled image */
fb_cpyto_buf(&gv_fb_dev,0,0,wid-1,hgt-1,bkimg);
bkwid=wid;bkhgt=hgt;
/* 2.3 put scaled image */
fb_cpyfrom_buf(&gv_fb_dev,0,0,wid-1,hgt-1,sbuf);
// usleep(100000);
}
/* 3. */
free(buf);
free(sbuf);
return 0;
}
#if 0 /////////////////////////////////////////////////////////////////
/*------------------------------------------------------------------
Duplicate a new ebox and its egi_data from an input ebox.
return:
EGI_EBOX pointer OK
NULL fail
--------------------------------------------------------------------*/
EGI_EBOX *egi_copy_btn_ebox(EGI_EBOX *ebox)
{
/* check data */
if( ebox==NULL || ebox->egi_data==NULL )
{
printf("egi_copy_btn_ebox(): input ebox is invalid or NULL!\n");
return NULL;
}
/* confirm ebox type */
if(ebox->type != type_btn)
{
printf("egi_copy_btn_ebox(): Not button type ebox!\n");
return NULL;
}
/* copy data_btn */
EGI_DATA_BTN *data_btn=(EGI_DATA_BTN *)malloc(sizeof(EGI_DATA_BTN));
if(data_btn==NULL)
{
printf("egi_copy_btn_ebox(): malloc data_btn fails!\n");
return NULL;
}
*data_btn=*((EGI_DATA_BTN *)(ebox->egi_data));
/* copy EGI_EBOX */
EGI_EBOX *newbox=(EGI_EBOX *)malloc(sizeof(EGI_EBOX));
if(newbox==NULL)
{
printf("egi_copy_btn_ebox(): malloc newbox fails!\n");
return NULL;
}
*newbox=*ebox;
/* assign egi_data */
newbox->egi_data=(void *)data_btn;
return newbox;
}
/*--------------------------------------------------------------------
Set icon substitue color for a button ebox
Note:
Pure BLACK set as transparent color, so here black subcolor should
not be 0 !!!
return:
0 OK
<0 fail
--------------------------------------------------------------------*/
int egi_btnbox_setsubcolor(EGI_EBOX *ebox, EGI_16BIT_COLOR subcolor)
{
/* check data */
if( ebox==NULL || ebox->egi_data==NULL )
{
printf("egi_btnbox_setsubcolor(): input ebox is invalid or NULL!\n");
return -1;
}
/* confirm ebox type */
if(ebox->type != type_btn)
{
printf("egi_btnbox_setsubcolor(): Not button type ebox!\n");
return -2;
}
/* Pure BLACK set as transparent color, so here black subcolor should NOT be 0 */
if(subcolor==0)subcolor=1;
/* set subcolor in icon_code: SUBCOLOR(16bits) + CODE(16bits) */
EGI_DATA_BTN *data_btn=(EGI_DATA_BTN *)(ebox->egi_data);
data_btn->icon_code = ((data_btn->icon_code)&0x0000ffff)+(subcolor<<16);
//printf("%s(): subcolor=0x%04X, set icon_code=0x%08X \n",__func__, subcolor, data_btn->icon_code);
return 0;
}
#endif ///////////////////////////////