Palace.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /********************************************************************************
  2. * File Name: Palace.c
  3. * Function Describe:宫格菜单
  4. * Relate Module:
  5. * Writer: Shliangwen
  6. * Date: 2019-1-15
  7. *******************************************************************************/
  8. #include "gui.h"
  9. #include "Palace.h"
  10. #include "includes.h"
  11. /*
  12. flag=0 全部刷新
  13. flag>0 刷index图标 突出显示
  14. flag<0 刷index图标 恢复正常
  15. */
  16. void PalaceShow(SUT_PALACE *sutPalace,int flag,int index)
  17. {
  18. int r,c,x,y;
  19. char filename[20];
  20. #if(PALACE_ICON_TYPE==USE_ICON_PALACE)
  21. if(flag==0){
  22. guiClearAll(guiGetBackColor());
  23. sutPalace->Index=0;
  24. guiShowCaption(0,sutPalace->Title[sutPalace->Index],UI_STATUS_BAR_HEIGH,guiGetBackColor(),guiGetForeColor(),FONT_MODE_12X12);
  25. for(r=0;r<PALACE_ROW;r++){
  26. for(c=0;c<PALACE_COL;c++){
  27. x=PALACE_LEFT+c*sutPalace->wide+sutPalace->ox;
  28. y=PALACE_TOP+r*sutPalace->high+sutPalace->oy;
  29. if(r==0 && c==0){//if(sutPalace->Index==r*PALACE_COL+c)
  30. sprintf(filename,"%s%dP.bmp",sutPalace->FileNamePrefix,r*PALACE_COL+c);
  31. //logTrace(filename,1);
  32. }else{
  33. sprintf(filename,"%s%d.bmp",sutPalace->FileNamePrefix,r*PALACE_COL+c);
  34. }
  35. guiShowBmp(x,y,filename);
  36. }
  37. }
  38. }else{
  39. guiShowCaption(0,sutPalace->Title[sutPalace->Index],18,guiGetBackColor(),guiGetForeColor(),FONT_MODE_12X12);
  40. r=index/PALACE_COL;
  41. c=index%PALACE_COL;
  42. x=PALACE_LEFT+c*sutPalace->wide+sutPalace->ox;
  43. y=PALACE_TOP+r*sutPalace->high+sutPalace->oy;
  44. if(flag>0){
  45. sprintf(filename,"%s%dP.bmp",sutPalace->FileNamePrefix,r*PALACE_COL+c);
  46. }else{
  47. sprintf(filename,"%s%d.bmp",sutPalace->FileNamePrefix,r*PALACE_COL+c);
  48. }
  49. guiShowBmp(x,y,filename);
  50. }
  51. #else
  52. if(flag==0){
  53. guiClearAll(guiGetBackColor());
  54. guiShowCaption(0,sutPalace->Title[sutPalace->Index],UI_STATUS_BAR_HEIGH,guiGetBackColor(),guiGetForeColor(),FONT_MODE_12X12);
  55. for(r=0;r<PALACE_ROW;r++){
  56. for(c=0;c<PALACE_COL;c++){
  57. x=PALACE_LEFT+c*sutPalace->wide+sutPalace->ox;
  58. y=PALACE_TOP+r*sutPalace->high+sutPalace->oy;
  59. sprintf(filename,"%s%d.bmp",sutPalace->FileNamePrefix,r*PALACE_COL+c);
  60. if(sutPalace->Index==r*PALACE_COL+c){//if(r==0 && c==0){//if(sutPalace->Index==r*PALACE_COL+c)
  61. guiShowBmp(x,y,filename);
  62. guiFillRect(x-PALACE_SURROUND_SIZE,y-PALACE_SURROUND_SIZE,x+PALACE_ICON_WIDE+PALACE_SURROUND_SIZE,y,COLOR_RED);
  63. guiFillRect(x-PALACE_SURROUND_SIZE,y+PALACE_ICON_HIGH,x+PALACE_ICON_WIDE+PALACE_SURROUND_SIZE,y+PALACE_ICON_HIGH+PALACE_SURROUND_SIZE,COLOR_RED);
  64. guiFillRect(x-PALACE_SURROUND_SIZE,y,x,y+PALACE_ICON_HIGH,COLOR_RED);
  65. guiFillRect(x+PALACE_ICON_WIDE,y,x+PALACE_ICON_WIDE+PALACE_SURROUND_SIZE,y+PALACE_ICON_HIGH,COLOR_RED);
  66. }else{
  67. guiClearRect(x-PALACE_SURROUND_SIZE+1,y-PALACE_SURROUND_SIZE,x+PALACE_ICON_WIDE+PALACE_SURROUND_SIZE,y+PALACE_ICON_HIGH+PALACE_SURROUND_SIZE,guiGetBackColor());
  68. guiShowBmp(x,y,filename);
  69. }
  70. }
  71. }
  72. sutPalace->showAlreadyFlag=1;
  73. }else{
  74. guiShowCaption(0,sutPalace->Title[sutPalace->Index],UI_STATUS_BAR_HEIGH,guiGetBackColor(),guiGetForeColor(),FONT_MODE_12X12);
  75. r=index/PALACE_COL;
  76. c=index%PALACE_COL;
  77. x=PALACE_LEFT+c*sutPalace->wide+sutPalace->ox;
  78. y=PALACE_TOP+r*sutPalace->high+sutPalace->oy;
  79. if(flag>0){
  80. guiFillRect(x-PALACE_SURROUND_SIZE,y-PALACE_SURROUND_SIZE,x+PALACE_ICON_WIDE+PALACE_SURROUND_SIZE,y,COLOR_RED);
  81. guiFillRect(x-PALACE_SURROUND_SIZE,y+PALACE_ICON_HIGH,x+PALACE_ICON_WIDE+PALACE_SURROUND_SIZE,y+PALACE_ICON_HIGH+PALACE_SURROUND_SIZE,COLOR_RED);
  82. guiFillRect(x-PALACE_SURROUND_SIZE,y,x,y+PALACE_ICON_HIGH,COLOR_RED);
  83. guiFillRect(x+PALACE_ICON_WIDE,y,x+PALACE_ICON_WIDE+PALACE_SURROUND_SIZE,y+PALACE_ICON_HIGH,COLOR_RED);
  84. }else{
  85. guiClearRect(x-PALACE_SURROUND_SIZE,y-PALACE_SURROUND_SIZE,x+PALACE_ICON_WIDE+PALACE_SURROUND_SIZE,y,guiGetBackColor());
  86. guiClearRect(x-PALACE_SURROUND_SIZE,y+PALACE_ICON_HIGH,x+PALACE_ICON_WIDE+PALACE_SURROUND_SIZE,y+PALACE_ICON_HIGH+PALACE_SURROUND_SIZE,guiGetBackColor());
  87. guiClearRect(x-PALACE_SURROUND_SIZE,y,x,y+PALACE_ICON_HIGH,guiGetBackColor());
  88. guiClearRect(x+PALACE_ICON_WIDE,y,x+PALACE_ICON_WIDE+PALACE_SURROUND_SIZE,y+PALACE_ICON_HIGH,guiGetBackColor());
  89. }
  90. if(sutPalace->showAlreadyFlag==0){
  91. sprintf(filename,"%s%d.bmp",sutPalace->FileNamePrefix,r*PALACE_COL+c);
  92. guiShowBmp(x,y,filename);
  93. }
  94. }
  95. #endif
  96. }
  97. void PalaceInit(SUT_PALACE *sutPalace,const char **title , const char *prefix, const char *mainInfo)
  98. {
  99. int a,b;
  100. unsigned char index;
  101. if(getKeyValue()==MKEY_VALUE_ESC)//||UI_Stack.OK_back)
  102. {
  103. index=uiPullStack();
  104. if(index>4){
  105. //p->page=1;
  106. sutPalace->Index=index;//
  107. }else{
  108. //p->page=0;
  109. sutPalace->Index=index;
  110. }
  111. //UI_Stack.OK_back=0;
  112. }else if(getKeyValue()==MKEY_VALUE_MENU){
  113. sutPalace->Index=0;
  114. }
  115. sutPalace->mainTile=mainInfo;
  116. //sutPalace->Index=0;
  117. sutPalace->Title=title;
  118. sutPalace->FileNamePrefix=prefix;
  119. sutPalace->wide=(GLCD_WIDTH-PALACE_LEFT*2)/PALACE_COL;
  120. sutPalace->high=(GLCD_HEIGHT-PALACE_TOP)/PALACE_ROW;
  121. if(sutPalace->wide>PALACE_ICON_WIDE)sutPalace->ox=(sutPalace->wide-PALACE_ICON_WIDE)/2;
  122. else sutPalace->ox=0;
  123. if(sutPalace->high>PALACE_ICON_HIGH)sutPalace->oy=(sutPalace->high-PALACE_ICON_HIGH)/2;
  124. else sutPalace->oy=0;
  125. PalaceShow(sutPalace,0,0);
  126. }
  127. unsigned short PalaceResponse(SUT_PALACE *sutPalace)
  128. {
  129. switch(getKeyValue())
  130. {
  131. case MKEY_VALUE_UP:
  132. PalaceShow(sutPalace,-1,sutPalace->Index);
  133. if(sutPalace->Index>0)sutPalace->Index--;
  134. else sutPalace->Index = (PALACE_COL*PALACE_ROW)-1;
  135. PalaceShow(sutPalace,1,sutPalace->Index);
  136. break;
  137. case MKEY_VALUE_DOWN:
  138. PalaceShow(sutPalace,-1,sutPalace->Index);
  139. if(sutPalace->Index<(PALACE_COL*PALACE_ROW-1))sutPalace->Index++;
  140. else sutPalace->Index=0;
  141. PalaceShow(sutPalace,1,sutPalace->Index);
  142. break;
  143. case MKEY_VALUE_MENU:
  144. break;
  145. case MKEY_VALUE_ESC:
  146. sutPalace->showAlreadyFlag=0;
  147. break;
  148. }
  149. return getKeyValue();
  150. }