dotListBox.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #include "dotListBox.h"
  2. #include "gui.h"
  3. #include "uiEntry.h"
  4. #include "board.h"
  5. #include "log.h"
  6. #include "app.h"
  7. #define LIST_ITEM_NUM_MAX 100
  8. #define LIST_MAX_ROW_BYTE (20+1+2)
  9. #define LIST_MAX_SHOW_BYTE 16
  10. typedef struct{
  11. unsigned short itemnum; //item number
  12. unsigned short total; //user total
  13. unsigned short handle; //current item
  14. unsigned short page;
  15. char **item;
  16. char title[16+1];
  17. }SUT_DOT_LISTBOX;
  18. static SUT_DOT_LISTBOX dotHandle;
  19. void dotListBoxShow(void){
  20. unsigned short handle;
  21. char info[20];
  22. if(dotHandle.handle>=dotHandle.total){
  23. MSG_WARN(1,"handle over!", dotHandle.total, dotHandle.handle);
  24. dotHandle.handle=0;
  25. }
  26. handle=dotHandle.handle;
  27. if(dotHandle.total==0) snprintf(info, sizeof(info), "%d/%d", dotHandle.total,0);
  28. else snprintf(info, sizeof(info), "%d/%d", dotHandle.total, dotHandle.page*5+handle+1);
  29. newGuiClearMainPage();
  30. newGuiShowStr(0, STATUS_BAR_HEIGH, dotHandle.title,REVERSED_NO,FONT_MODE_16X16);
  31. newGuiShowStr(0, STATUS_BAR_HEIGH+16, info,REVERSED_NO,FONT_MODE_16X16);
  32. getRealShow(info, dotHandle.item[handle],LIST_MAX_SHOW_BYTE);//不显示超界,多的后面会滚动
  33. newGuiShowStr(0, STATUS_BAR_HEIGH+32, info,REVERSED_NO,FONT_MODE_16X16);
  34. }
  35. //title:标题
  36. //total: >=0 强制用于显示为总数,否则总数从计数条目得出
  37. //forcehandle: >=0 强制显示此索引项目
  38. void dotListBoxInit(char **itemlist,char *title,int total,int forcehandle,unsigned short pindex){
  39. UI_STACKDEF *uiPtr=getStackStruct();
  40. unsigned char i,ch,index;
  41. //统计item
  42. dotHandle.item = itemlist;
  43. i = 0;
  44. while(i<LIST_ITEM_NUM_MAX)
  45. {
  46. ch=dotHandle.item[i][0];
  47. if(ch==0)break;
  48. i ++;
  49. }
  50. i=i-1;
  51. dotHandle.itemnum = i+1;
  52. dotHandle.page=pindex;
  53. if(total>=0) dotHandle.total=total;
  54. else dotHandle.total=dotHandle.itemnum;
  55. if(uiPtr->esc || uiPtr->ok_back){
  56. uiPtr->esc=0;
  57. uiPtr->ok_back=0;
  58. dotHandle.handle=uiPullStack();
  59. if(dotHandle.handle<0) dotHandle.handle=0;
  60. }else dotHandle.handle=0;
  61. if(forcehandle>=0) dotHandle.handle=forcehandle;
  62. snprintf(dotHandle.title, sizeof(dotHandle.title), "%s",title);
  63. //显示
  64. dotListBoxShow();
  65. }
  66. unsigned short dotListBoxResponse(void){
  67. unsigned char needShow=1;
  68. unsigned short key=getKeyValue();
  69. if(dotHandle.itemnum<=0) return key;
  70. switch(key){
  71. case MKEY_VALUE_DOWN:
  72. if(++dotHandle.handle>=dotHandle.itemnum){
  73. dotHandle.handle=0;
  74. if(dotHandle.total>dotHandle.itemnum) needShow=0;//翻页时是否要显示
  75. }
  76. if(needShow) dotListBoxShow();
  77. break;
  78. default:
  79. return key;
  80. }
  81. return key;
  82. }
  83. void dotLeftMoveSelectedItem(void){
  84. static char item[LIST_MAX_ROW_BYTE];
  85. static unsigned short sum;
  86. unsigned short tsum;
  87. int len,i;
  88. char showMax[LIST_MAX_ROW_BYTE];
  89. char *str=dotHandle.item[dotHandle.handle];
  90. static unsigned int cnt=0xffff;
  91. if(++cnt<500/APP_SUB_DIV_TIME) return;
  92. cnt=0;
  93. if(strlen(str)<=LIST_MAX_SHOW_BYTE-1) return;
  94. snprintf(showMax, sizeof(showMax), "%s ", str);
  95. len=strlen(showMax);
  96. tsum=0;
  97. for(i=0;i<len;i++) tsum += showMax[i];
  98. if(len>LIST_MAX_SHOW_BYTE){
  99. if(sum != tsum){
  100. sum=tsum;
  101. memcpy(item, showMax, LIST_MAX_ROW_BYTE);
  102. }else leftMoveStr(item, strlen(item));
  103. getRealShow(showMax, item,LIST_MAX_SHOW_BYTE);
  104. newGuiClearPage(0, ROW_FOUR);
  105. newGuiShowStr(0, 48, showMax,REVERSED_NO,FONT_MODE_16X16);
  106. }
  107. }
  108. unsigned short dotListGetHandle(void){return dotHandle.handle;}
  109. unsigned short dotListGetItemNum(void){return dotHandle.itemnum;}