// the following routine is very heavily hacked, er, modified to accomodate this add-in's needs int PrintMiniFix( int x, int y, const char*Msg, const int flags, const short color, const short bcolor ) { int i = 0, dx; unsigned short width; void*p; while ( Msg[ i ] ) { if( Msg[i] == 9) { drawLine(x, y+24+7, x+11, y+24+7, color); drawLine(x, y+24+8, x+11, y+24+8, color); x+=12; i++; continue; } else if( Msg[i] == 30) { // getline start indicator int tx = x+2, ty=y; PrintMini(&tx, &ty, (unsigned char*)"\xe6\x9e", 0, 0xFFFFFFFF, 0, 0, COLOR_BLUE, bcolor, 1, 0); x+=12; i++; continue; } else if( Msg[i] == 31) { // small dot for multiply int tx = x+2, ty=y; PrintMini(&tx, &ty, (unsigned char*)"\xe6\xaa", 0, 0xFFFFFFFF, 0, 0, color, bcolor, 1, 0); x+=12; i++; continue; } else p = GetMiniGlyphPtr( Msg[ i ], &width ); dx = ( 12 - width ) / 2; if ( dx > 0 ) { PrintMiniGlyph( x, y, (void*)empty, flags, dx, 0, 0, 0, 0, color, bcolor, 0 ); } else dx = 0; int actualcolor = color; if(enable_bracket_coloring) { if(Msg[ i ] == '(') { bracket_level++; actualcolor = last_bracket_color; last_bracket_color = getNextColorInSequence(last_bracket_color); } else if(Msg[ i ] == ')' && bracket_level > 0) { last_bracket_color = getPreviousColorInSequence(last_bracket_color); actualcolor = last_bracket_color; bracket_level--; } } PrintMiniGlyph( x + dx, y, p, flags, width, 0, 0, 0, 0, actualcolor, bcolor, 0 ); if ( width + dx < 12 ) { PrintMiniGlyph( x + width + dx, y, (void*)empty, flags, 12 - width - dx, 0, 0, 0, 0, color, bcolor, 0 ); } x += 12; i++; } return x; }
/* 输出屏幕底部的菜单(最多5个字符) */ void PrintIcon (int index, char* text, int sel) { index*=21; if (sel) { PrintMini(index+1+2*(5-strlen(text)), 59, (unsigned char*)text, 0); Bdisp_DrawLineVRAM(index,58,index+19,58); Bdisp_DrawLineVRAM(index,58,index,63); } else{ PrintMini(index+2*(5-strlen(text)), 59, (unsigned char*)text, 0); Bdisp_AreaReverseVRAM(index,58,index+19,63); } }
void abort(void){ int x=0,y=160; PrintMini(&x,&y,"Abort called",0,0xFFFFFFFF,0,0,0xFFFF,0,1,0); int key; for(;;) GetKey(&key); }
void draw_dash() { unsigned char text[4] = "test"; unsigned char *text_pointer = text; int x = 1; int *x_pointer = &x; fillArea(0, LCD_HEIGHT_PX-dash_height, LCD_WIDTH_PX, dash_height, COLOR_BLACK); PrintMini(x_pointer, x_pointer, text_pointer, 0, 0, 0, 0, 0, 0, 0, 0); }
int PrintTableIndexPM (int y,int index) { char buffer[8]; if (index<0 || index>999) return 0; sprintf(buffer,"%d",index); y *= 8; Bdisp_AreaReverseVRAM(0,y,15,y+7); PrintMini(1,y+2,buffer,MINI_REV); }
void display_menu( menu_entry menu_entries[][AL_ENTRIES_PER_MENU], unsigned int menu_id ) { unsigned int i = 0; clear_menu(); for( i = 0; i < AL_ENTRIES_PER_MENU; i++ ) { switch( menu_entries[menu_id][i].type ) { case AL_MENU_TYPE_PARENT: draw_parent( i ); PrintMini( ( i * 21 ) + 4, 58, ( const unsigned char * )menu_entries[menu_id][i].name, MINI_REV ); break; case AL_MENU_TYPE_CHILD: draw_child( i ); PrintMini( ( i * 21 ) + 4, 58, ( const unsigned char * )menu_entries[menu_id][i].name, 0 ); break; case AL_MENU_TYPE_UP: draw_child( i ); PrintMini( ( i * 21 ) + 10, 58, ( const unsigned char * )AL_MENU_UP, 0 ); break; case AL_MENU_TYPE_PAGE_PREV: draw_child( i ); PrintMini( ( i * 21 ) + 10, 58, ( const unsigned char * )AL_MENU_PREV, 0 ); break; case AL_MENU_TYPE_PAGE_NEXT: draw_child( i ); PrintMini( ( i * 21 ) + 10, 58, ( const unsigned char * )AL_MENU_NEXT, 0 ); break; case AL_MENU_TYPE_EMPTY: default: break; } } }
int PrintTablesPM(short x,short y,char * str,short sel,short lbl) { int len; const int width = 28; len = strlen(str); x *= width; y *= 8; x += 16; if (sel) { Bdisp_AreaReverseVRAM(x,y,x+width-1,y+7); PrintMini(x+1+(lbl ? (width-5*len)/2:0),y+1,str,MINI_REV); } else { Bdisp_DrawLineVRAM(x+width-1,y,x+width-1,y+7); Bdisp_DrawLineVRAM(x,y+7,x+width-1,y+7); PrintMini(x+1+(lbl ? (width-5*len)/2:0),y+1,str,MINI_OVER); } }
void main(void){ int x,y; char buf[1024];//In this example nothing is done with the buffer, I leave it as an exercise to the reader to do something with the inputted text. Bdisp_EnableColor(0); Bdisp_AllClr_VRAM(); //Print the "explanation" PrintXY(1,1," Stop!",0,0); x=0; y=32; PrintMini(&x,&y,"Who would cross the Bridge of Death",0,0xFFFFFFFF,0,0,0,0xFFFF,1,0); x=0; y=56; PrintMini(&x,&y,"must answer me these questions three,",0,0xFFFFFFFF,0,0,0,0xFFFF,1,0); x=0; y=80; PrintMini(&x,&y,"ere the other side he see.",0,0xFFFFFFFF,0,0,0,0xFFFF,1,0); PrintXY(1,5," What... is",0,0); for(;;){ askQ(" your name?",buf,1024); askQ(" your quest?",buf,1024); askQ(" your favorite color?",buf,1024);//The text fits by using American spelling. Yes I know Monty Python is a British show. } }
void Mini(char* chaine, int n ) // fonc defini le numero de la fonction { int i; short j; for(i=56 ; i<64 ; i++) Bdisp_DrawLineVRAM(n*21+2, i, n*21+20, i); while(chaine[j]) j++; // on calcul la longeur de la chaine if(j<4) i=4; else i=3; PrintMini(n*21+i, 58, chaine, 18); //ML_display_vram(); }
void choix_famille(choix) { char i=0,y; for(i;i<118;++i) { if (choix==ajout[i].famille) { y=(i>55 && i<71 ? 9 : i>87 && i<103 ? 10 : elements[i].periode); (i>55 && i<71 || i>87 && i<103 ? ML_bmp_or(select,5*elements[i].groupe-4,5*y-7,4,4) : ML_bmp_or(select,5*elements[i].groupe-4,5*y-4,4,4)); ML_bmp_or(select,20,50,4,4); PrintMini(30,50,family[choix],0); } } }
int doMenu(Menu* menu, MenuItemIcon* icontable) { // returns code telling what user did. selection is on menu->selection. menu->selection starts at 1! int itemsStartY=menu->startY; // char Y where to start drawing the menu items. Having a title increases this by one int itemsHeight=menu->height; int showtitle = menu->title != NULL; if (showtitle) { itemsStartY++; itemsHeight--; } if(menu->selection > menu->scroll+(menu->numitems>itemsHeight ? itemsHeight : menu->numitems)) menu->scroll = menu->selection -(menu->numitems>itemsHeight ? itemsHeight : menu->numitems); if(menu->selection-1 < menu->scroll) menu->scroll = menu->selection -1; while(1) { if(menu->statusText != NULL) DefineStatusMessage(menu->statusText, 1, 0, 0); // Clear the area of the screen we are going to draw on if(0 == menu->pBaRtR) drawRectangle(18*(menu->startX-1), 24*(menu->miniMiniTitle ? itemsStartY:menu->startY), 18*menu->width+(menu->scrollbar && menu->scrollout?6:0), 24*menu->height-(menu->miniMiniTitle ? 24:0), COLOR_WHITE); if (menu->numitems>0) { for(int curitem=0; curitem < menu->numitems; curitem++) { // print the menu item only when appropriate if(menu->scroll < curitem+1 && menu->scroll > curitem-itemsHeight) { char menuitem[70] = ""; if(menu->type == MENUTYPE_MULTISELECT) strcpy(menuitem, " "); //allow for the folder and selection icons on MULTISELECT menus (e.g. file browser) strncat(menuitem, menu->items[curitem].text, 68); if(menu->items[curitem].type != MENUITEM_SEPARATOR) { //make sure we have a string big enough to have background when item is selected: // MB_ElementCount is used instead of strlen because multibyte chars count as two with strlen, while graphically they are just one char, making fillerRequired become wrong int fillerRequired = menu->width - MB_ElementCount(menu->items[curitem].text) - (menu->type == MENUTYPE_MULTISELECT ? 2 : 0); for(int i = 0; i < fillerRequired; i++) strcat(menuitem, " "); mPrintXY(menu->startX,curitem+itemsStartY-menu->scroll,(char*)menuitem, (menu->selection == curitem+1 ? TEXT_MODE_INVERT : TEXT_MODE_TRANSPARENT_BACKGROUND), menu->items[curitem].color); } else { /*int textX = (menu->startX-1) * 18; int textY = curitem*24+itemsStartY*24-menu->scroll*24-24+6; clearLine(menu->startX, curitem+itemsStartY-menu->scroll, (menu->selection == curitem+1 ? textColorToFullColor(menu->items[curitem].color) : COLOR_WHITE)); drawLine(textX, textY+24-4, LCD_WIDTH_PX-2, textY+24-4, COLOR_GRAY); PrintMini(&textX, &textY, (unsigned char*)menuitem, 0, 0xFFFFFFFF, 0, 0, (menu->selection == curitem+1 ? COLOR_WHITE : textColorToFullColor(menu->items[curitem].color)), (menu->selection == curitem+1 ? textColorToFullColor(menu->items[curitem].color) : COLOR_WHITE), 1, 0);*/ } // deal with menu items of type MENUITEM_CHECKBOX if(menu->items[curitem].type == MENUITEM_CHECKBOX) { mPrintXY(menu->startX+menu->width-1,curitem+itemsStartY-menu->scroll, (menu->items[curitem].value == MENUITEM_VALUE_CHECKED ? (char*)"\xe6\xa9" : (char*)"\xe6\xa5"), (menu->selection == curitem+1 ? TEXT_MODE_INVERT : (menu->pBaRtR == 1? TEXT_MODE_TRANSPARENT_BACKGROUND : TEXT_MODE_NORMAL)), menu->items[curitem].color); } // deal with multiselect menus if(menu->type == MENUTYPE_MULTISELECT) { if((curitem+itemsStartY-menu->scroll)>=itemsStartY && (curitem+itemsStartY-menu->scroll)<=(itemsStartY+itemsHeight) && icontable != NULL ) { if (menu->items[curitem].isfolder == 1) { // assumes first icon in icontable is the folder icon CopySpriteMasked(icontable[0].data, (menu->startX)*18, (curitem+itemsStartY-menu->scroll)*24, 0x12, 0x18, 0xf81f ); } else { if(menu->items[curitem].icon >= 0) CopySpriteMasked(icontable[menu->items[curitem].icon].data, (menu->startX)*18, (curitem+itemsStartY-menu->scroll)*24, 0x12, 0x18, 0xf81f ); } } if (menu->items[curitem].isselected) { if (menu->selection == curitem+1) { mPrintXY(menu->startX,curitem+itemsStartY-menu->scroll,(char*)"\xe6\x9b", TEXT_MODE_TRANSPARENT_BACKGROUND, (menu->items[curitem].color == TEXT_COLOR_GREEN ? TEXT_COLOR_BLUE : TEXT_COLOR_GREEN)); } else { mPrintXY(menu->startX,curitem+itemsStartY-menu->scroll,(char*)"\xe6\x9b", TEXT_MODE_NORMAL, TEXT_COLOR_PURPLE); } } } } } if (menu->scrollbar) { TScrollbar sb; sb.I1 = 0; sb.I5 = 0; sb.indicatormaximum = menu->numitems; sb.indicatorheight = itemsHeight; sb.indicatorpos = menu->scroll; sb.barheight = itemsHeight*24; sb.bartop = (itemsStartY-1)*24; sb.barleft = menu->startX*18+menu->width*18 - 18 - (menu->scrollout ? 0 : 5); sb.barwidth = 6; Scrollbar(&sb); } //if(menu->type==MENUTYPE_MULTISELECT && menu->fkeypage == 0) drawFkeyLabels(0x0037); // SELECT (white) } else { printCentered((unsigned char*)menu->nodatamsg, (itemsStartY*24)+(itemsHeight*24)/2-12, COLOR_BLACK, COLOR_WHITE); } if(showtitle) { if(menu->miniMiniTitle) { int textX = 0, textY=(menu->startY-1)*24; PrintMiniMini( &textX, &textY, (unsigned char*)menu->title, 16, menu->titleColor, 0 ); } else mPrintXY(menu->startX, menu->startY, menu->title, TEXT_MODE_TRANSPARENT_BACKGROUND, menu->titleColor); if(menu->subtitle != NULL) { int textX=(MB_ElementCount(menu->title)+menu->startX-1)*18+10, textY=6; PrintMini(&textX, &textY, (unsigned char*)menu->subtitle, 0, 0xFFFFFFFF, 0, 0, COLOR_BLACK, COLOR_WHITE, 1, 0); } } /*if(menu->darken) { DrawFrame(COLOR_BLACK); VRAMInvertArea(menu->startX*18-18, menu->startY*24, menu->width*18-(menu->scrollout || !menu->scrollbar ? 0 : 5), menu->height*24); }*/ if(menu->type == MENUTYPE_NO_KEY_HANDLING) return MENU_RETURN_INSTANT; // we don't want to handle keys int key; GetKey(&key); switch(key) { case KEY_CTRL_DOWN: if(menu->selection == menu->numitems) { if(menu->returnOnInfiniteScrolling) { return MENU_RETURN_SCROLLING; } else { menu->selection = 1; menu->scroll = 0; } } else { menu->selection++; if(menu->selection > menu->scroll+(menu->numitems>itemsHeight ? itemsHeight : menu->numitems)) menu->scroll = menu->selection -(menu->numitems>itemsHeight ? itemsHeight : menu->numitems); } if(menu->pBaRtR==1) return MENU_RETURN_INSTANT; break; case KEY_CTRL_UP: if(menu->selection == 1) { if(menu->returnOnInfiniteScrolling) { return MENU_RETURN_SCROLLING; } else { menu->selection = menu->numitems; menu->scroll = menu->selection-(menu->numitems>itemsHeight ? itemsHeight : menu->numitems); } } else { menu->selection--; if(menu->selection-1 < menu->scroll) menu->scroll = menu->selection -1; } if(menu->pBaRtR==1) return MENU_RETURN_INSTANT; break; case KEY_CTRL_F1: if(menu->type==MENUTYPE_MULTISELECT && menu->fkeypage == 0 && menu->numitems > 0) { /*if(menu->items[menu->selection-1].isselected) { menu->items[menu->selection-1].isselected=0; menu->numselitems = menu->numselitems-1; } else { menu->items[menu->selection-1].isselected=1; menu->numselitems = menu->numselitems+1; } return key; //return on F1 too so that parent subroutines have a chance to e.g. redraw fkeys*/ } else if (menu->type == MENUTYPE_FKEYS) { return key; } break; case KEY_CTRL_F2: case KEY_CTRL_F3: case KEY_CTRL_F4: case KEY_CTRL_F5: case KEY_CTRL_F6: if (menu->type == MENUTYPE_FKEYS || menu->type==MENUTYPE_MULTISELECT) return key; // MULTISELECT also returns on Fkeys break; case KEY_CTRL_PASTE: if (menu->type==MENUTYPE_MULTISELECT) return key; // MULTISELECT also returns on paste case KEY_CTRL_OPTN: if (menu->type==MENUTYPE_FKEYS || menu->type==MENUTYPE_MULTISELECT) return key; break; case KEY_CTRL_FORMAT: if (menu->type==MENUTYPE_FKEYS) return key; // return on the Format key so that event lists can prompt to change event category break; case KEY_CTRL_RIGHT: if(menu->type != MENUTYPE_MULTISELECT) break; // else fallthrough case KEY_CTRL_EXE: if(menu->numitems>0) return MENU_RETURN_SELECTION; break; case KEY_CTRL_LEFT: if(menu->type != MENUTYPE_MULTISELECT) break; // else fallthrough case KEY_CTRL_EXIT: return MENU_RETURN_EXIT; break; case KEY_CHAR_1: case KEY_CHAR_2: case KEY_CHAR_3: case KEY_CHAR_4: case KEY_CHAR_5: case KEY_CHAR_6: case KEY_CHAR_7: case KEY_CHAR_8: case KEY_CHAR_9: if(menu->numitems>=(key-0x30)) {menu->selection = (key-0x30); return MENU_RETURN_SELECTION; } break; case KEY_CHAR_0: if(menu->numitems>=10) {menu->selection = 10; return MENU_RETURN_SELECTION; } break; case KEY_CTRL_XTT: if(menu->numitems>=11) {menu->selection = 11; return MENU_RETURN_SELECTION; } break; case KEY_CHAR_LOG: if(menu->numitems>=12) {menu->selection = 12; return MENU_RETURN_SELECTION; } break; case KEY_CHAR_LN: if(menu->numitems>=13) {menu->selection = 13; return MENU_RETURN_SELECTION; } break; case KEY_CHAR_SIN: case KEY_CHAR_COS: case KEY_CHAR_TAN: if(menu->numitems>=(key-115)) {menu->selection = (key-115); return MENU_RETURN_SELECTION; } break; case KEY_CHAR_FRAC: if(menu->numitems>=17) {menu->selection = 17; return MENU_RETURN_SELECTION; } break; case KEY_CTRL_FD: if(menu->numitems>=18) {menu->selection = 18; return MENU_RETURN_SELECTION; } break; case KEY_CHAR_LPAR: case KEY_CHAR_RPAR: if(menu->numitems>=(key-21)) {menu->selection = (key-21); return MENU_RETURN_SELECTION; } break; case KEY_CHAR_COMMA: if(menu->numitems>=21) {menu->selection = 21; return MENU_RETURN_SELECTION; } break; case KEY_CHAR_STORE: if(menu->numitems>=22) {menu->selection = 22; return MENU_RETURN_SELECTION; } break; } } return MENU_RETURN_EXIT; }
int ProjSet() { unsigned int key = 0 ; unsigned int back_key = 0 ; BYTE row = 0 ; BYTE exit_flag = FALSE ; Bdisp_AllClr_DDVRAM() ; /* clear screen */ Print_zh(" 设置 ", 2, 0, VERT_REV) ; PrintMini(2, 58, (unsigned char*)" F1 ", MINI_REV) ; PrintMini(21, 58, (unsigned char*)" F2 ", MINI_REV) ; //PrintMini(40, 58, (unsigned char*)" F3 ", MINI_REV) ; PrintMini(105, 58, (unsigned char*)" EXIT ", MINI_REV) ; while (exit_flag != TRUE) { switch (key) { case KEY_CTRL_F1: default: back_key = key ; Bdisp_AreaClr_DDVRAM(&clear_area) ; locatestr(27,2) ;printf("放样:增减桩距 ") ; locatestr(67,16) ;printf("%.3f", allset.stake_d) ; locatestr(27,29) ;printf("反算:最大路宽 ") ; locatestr(67,43) ;printf("%.3f", allset.width_max) ; PrintXY(120, 6, (unsigned char*)"\xE6\x9C ", 0) ; PrintXY(120, 49, (unsigned char*)"\xE6\x9D ", 0) ; if (row > 1) { /* 判断是否进入下一个菜单 */ key = KEY_CTRL_F2 ; row = 0 ; break ; } key = InputVal(53, 17+row*27) ; switch (row) { case 0: allset.stake_d = number ? number : allset.stake_d ;break ; case 1: allset.width_max = number ? number : allset.width_max ;break ; default: break ; } break ; case KEY_CTRL_F2: back_key = key ; Bdisp_AreaClr_DDVRAM(&clear_area) ; locatestr(27,2) ;printf("1=交点 2=线元 ") ; locatestr(77,16) ;printf("%.3f", allset.xl_type) ; locatestr(27,29) ;printf("1=正交 2=任意 ") ; locatestr(77,43) ;printf("%.3f", allset.pj_mode) ; PrintXY(120, 6, (unsigned char*)"\xE6\x9C ", 0) ; PrintXY(120, 46, (unsigned char*)"\xE6\x9D ", 0) ; if (row > 1) { /* 判断是否进入下一个菜单 */ if ( SaveProj() != -1 ) Warning("设置成功 ", 2) ; else Warning("设置失败 ", 2) ; exit_flag = TRUE ; break; } key = InputVal(53, 17+row*27) ; switch (row) { case 0: allset.xl_type = (number==1 || number==2) ? number : allset.xl_type ;break ; case 1: allset.pj_mode = (number==1 || number==2) ? number : allset.pj_mode ;break ; default: break ; } break ; case KEY_CTRL_UP: if (row > 0) --row ; key = back_key ; break ; case KEY_CTRL_DOWN: case KEY_CTRL_EXE: ++row ; key = back_key ; break ; case KEY_CTRL_DEL: key = back_key ; break ; case KEY_CTRL_EXIT : exit_flag = TRUE ; break ; } } }
int fileBrowserSub(char* browserbasepath, char* filename, char* filter, char* filter2, char* title) { Menu menu; MenuItemIcon icontable[12]; buildIconTable(icontable); // first get file count so we know how much to alloc GetFiles(NULL, NULL, browserbasepath, &menu.numitems, filter, filter2); MenuItem* menuitems = NULL; File* files = NULL; if(menu.numitems > 0) { menuitems = (MenuItem*)alloca(menu.numitems*sizeof(MenuItem)); files = (File*)alloca(menu.numitems*sizeof(File)); // populate arrays GetFiles(files, menuitems, browserbasepath, &menu.numitems, filter, filter2); menu.items = menuitems; } char titleBuffer[120]; char titleBufferBuf[120]; int smemfree; unsigned short smemMedia[10]={'\\','\\','f','l','s','0',0}; Bfile_GetMediaFree_OS( smemMedia, &smemfree ); char friendlypath[MAX_FILENAME_SIZE]; strcpy(friendlypath, browserbasepath+6); friendlypath[strlen(friendlypath)-1] = '\0'; //remove ending slash like OS does // test to see if friendlypath is too big int jump4=0; while(1) { int temptextX=7*18+10; // px length of menu title + 10, like menuGUI goes. int temptextY=0; PrintMini(&temptextX, &temptextY, (char*)friendlypath, 0, 0xFFFFFFFF, 0, 0, COLOR_BLACK, COLOR_WHITE, 0, 0); // fake draw if(temptextX>LCD_WIDTH_PX-6) { char newfriendlypath[MAX_FILENAME_SIZE]; shortenDisplayPath(friendlypath, newfriendlypath, (jump4 ? 4 : 1)); if(strlen(friendlypath) > strlen(newfriendlypath) && strlen(newfriendlypath) > 3) { // check if len > 3 because shortenDisplayPath may return just "..." when the folder name is too big // shortenDisplayPath still managed to shorten, copy and continue jump4 = 1; //it has been shortened already, so next time jump the first four characters strcpy(friendlypath, newfriendlypath); } else { // shortenDisplayPath can't shorten any more even if it still // doesn't fit in the screen, so give up. break; } } else break; } menu.subtitle = friendlypath; menu.type = MENUTYPE_MULTISELECT; menu.scrollout=1; menu.nodatamsg = (char*)"No Data"; menu.title = title; menu.height=7; while(1) { Bdisp_AllClr_VRAM(); drawFkeyLabels((menu.numitems ? 0x03B1 : 0), -1, -1, -1, -1, 0x03DF); // OPEN, VERSION itoa(smemfree, (unsigned char*)titleBuffer); LocalizeMessage1( 340, titleBufferBuf ); //"bytes free" strncat((char*)titleBuffer, (char*)titleBufferBuf, 65); menu.statusText = (char*)titleBuffer; int res = doMenu(&menu, icontable); switch(res) { case MENU_RETURN_EXIT: if(!strcmp(browserbasepath,"\\\\fls0\\")) { //check that we aren't already in the root folder //we are, return 0 so we exit //return 0; // in this add-in, the file browser shouldn't return } else { int i=strlen(browserbasepath)-2; while (i>=0 && browserbasepath[i] != '\\') i--; if (browserbasepath[i] == '\\') { char tmp[MAX_FILENAME_SIZE] = ""; memcpy(tmp,browserbasepath,i+1); tmp[i+1] = '\0'; strcpy(browserbasepath, tmp); } return 1; //reload at new folder } break; case KEY_CTRL_F1: case MENU_RETURN_SELECTION: if(!menu.numitems) break; if(menuitems[menu.selection-1].isfolder) { strcpy(browserbasepath, files[menu.selection-1].filename); //switch to selected folder strcat(browserbasepath, "\\"); return 1; //reload at new folder } else { strcpy(filename,files[menu.selection-1].filename); return 2; } break; case KEY_CTRL_F6: showAbout(); break; } } return 1; }
int tableauElement(chang) { short decalx=0,decaly=0; short x,y; short i; while(1) { Bdisp_AllClr_DDVRAM(); chang=(chang>=118 ? 0 : chang<=-1 ? 117 : chang); decalx=-(((12*elements[chang].groupe)-13)*108)/240; // on fait un decalage lorsque l'on bouge decaly=(elements[chang].periode==5 ? -7 : elements[chang].periode>5 ? -14 : 0); for(i=0;i<118;i++) { x=elements[i].groupe; y=(i>55 && i<71 ? 9 : i>87 && i<103 ? 10 : elements[i].periode); PrintMini(12*x+decalx-12,7*y+decaly-6,elements[i].symbol,0); PrintMini(12*3-11+decalx,7*6-7+decaly,"1",0); PrintMini(12*3-11+decalx,7*7-7+decaly,"2",0); PrintMini(12*3-11+decalx,7*9+decaly-5,"1",0); PrintMini(12*3-11+decalx,7*10+decaly-5,"2",0); } if (chang>55 && chang<71) { ML_rectangle(12*elements[chang].groupe-13+decalx,7*9-7+decaly,12*elements[chang].groupe-1+decalx,7*9+decaly,1,1,2); } else if (chang>87 && chang<103) { ML_rectangle(12*elements[chang].groupe-13+decalx,7*10-7+decaly,12*elements[chang].groupe-1+decalx,7*10+decaly,1,1,2); } else { ML_rectangle(12*elements[chang].groupe-13+decalx,7*elements[chang].periode-7+decaly,12*elements[chang].groupe+decalx,7*elements[chang].periode+decaly,1,1,2); } ML_rectangle(0,56,128,64,0,0,0); // on fait un rectangle blanc pour qu'il n'y ait rien Mini("mini",0); Mini("find",1); Mini("mol",2); Mini("sign",3); Mini("det",5); GetKey(&key); switch(key) { case 27 : chang+=1; break; case 38 : chang-=1; break; case 37 : chang=elements[chang].dessous; break; case 28 : chang=elements[chang].dessus; break; case 79 : chang=tableauEleMini(chang); break; case 69 : chang=find(chang); break; case 59 : calcul_mole(); break; case KEY_CTRL_F4 : nb_sign(); break; case 29 : case 31 : case 78 : chang=detailsElement(chang); break; case 47 : return; } } }
int Explorer( int size, char *folder ) { int top, redraw; int i; unsigned int key; redraw = 1; top = index; while(1) { if( redraw ) { Bdisp_AllClr_VRAM(); //DrawPicture( 1, 56, 61, 8, graph_bar ); PrintMini(1, 58, (unsigned char*)" EXE ", MINI_REV) ; PrintMini(105, 58, (unsigned char*)" EXIT ", MINI_REV) ; locate(1, 1);Print((unsigned char*)"File List [ ]"); locate(13, 1);Print( strlen(folder) ? (unsigned char*)folder : (unsigned char*)"Root"); if( size < 1 ){ locate( 8, 4 ); Print( (unsigned char*)"No Data" ); } else{ if( top > index ) top = index; if( index > top + N_LINE - 1 ) top = index - N_LINE + 1; if( top < 0 ) top = 0; for(i = 0;i < N_LINE && i + top < size; ++i ){ locate( 1, i + 2 ); if( files[i + top].filesize == -1 ) pPrintf( " [%s]", files[i + top].filename ); else pPrintf( " %-12s:%6u ", files[i + top].filename, files[i + top].filesize ); } Bdisp_AreaReverseVRAM( 0, (index-top+1)*8 , 127, (index-top+2)*8-1 ); if( top > 0 ) PrintXY( 120, 8, (unsigned char*)"\xE6\x92", top == index ); if( top + N_LINE < size ) PrintXY( 120, N_LINE*8, (unsigned char*)"\xE6\x93" , top + N_LINE - 1 == index ); } redraw = 0; } GetKey(&key); if( key==KEY_CTRL_UP ){ if( --index < 0 ) index = size - 1; redraw = 1; } else if( key==KEY_CTRL_DOWN ){ if( ++index > size - 1 ) index = 0; redraw = 1; } else if( key==KEY_CTRL_EXE || key == KEY_CTRL_F1) break; else if( key == KEY_CTRL_F2 ){ //Help(); redraw = 1; } else if( key == KEY_CTRL_F3 ){ //About(); redraw = 1; } else if( key==KEY_CTRL_EXIT){ index = size; break; } } }
void doTextArea(textArea* text) { int scroll = 0; int key; while(1) { drawRectangle(text->x, text->y+24, text->width, LCD_HEIGHT_PX-24, COLOR_WHITE); int cur = 0; int textX = text->x; int textY = scroll+(text->showtitle ? 24 : 0); // 24 pixels for title (or not) int temptextY = 0; int temptextX = 0; while(cur <= text->numelements-1) { if(text->elements[cur].newLine) { textX=text->x; textY=textY+text->lineHeight+text->elements[cur].lineSpacing; } unsigned char* singleword = (unsigned char*)malloc(strlen(text->elements[cur].text)); // because of this, a single text element can't have more bytes than malloc can provide unsigned char* src = (unsigned char*)text->elements[cur].text; while(*src) { temptextX = 0; src = toksplit(src, ' ', (unsigned char*)singleword, strlen(text->elements[cur].text)); //break into words; next word //check if printing this word would go off the screen, with fake PrintMini drawing: PrintMini(&temptextX, &temptextY, (unsigned char*)singleword, 0, 0xFFFFFFFF, 0, 0, text->elements[cur].color, COLOR_WHITE, 0, 0); if(temptextX + textX > text->width-6) { //time for a new line textX=text->x; textY=textY+text->lineHeight; PrintMini(&textX, &textY, (unsigned char*)singleword, 0, 0xFFFFFFFF, 0, 0, text->elements[cur].color, COLOR_WHITE, 1, 0); } else { //still fits, print new word normally PrintMini(&textX, &textY, (unsigned char*)singleword, 0, 0xFFFFFFFF, 0, 0, text->elements[cur].color, COLOR_WHITE, 1, 0); } //add a space, since it was removed from token if(*src || text->elements[cur].spaceAtEnd) PrintMini(&textX, &textY, (unsigned char*)" ", 0, 0xFFFFFFFF, 0, 0, COLOR_BLACK, COLOR_WHITE, 1, 0); } free(singleword); cur++; } if(text->showtitle) { unsigned char buffer[50] = ""; unsigned char buffer2[50] = ""; strcpy((char*)buffer, " "); strcpy((char*)buffer2, ""); strcat((char*)buffer, (char*)text->title); PrintXY(1, 1, (char*)" ", TEXT_MODE_NORMAL, TEXT_COLOR_BLUE); PrintXY(1, 1, (char*)buffer, TEXT_MODE_TRANSPARENT_BACKGROUND, TEXT_COLOR_BLUE); } //draw a scrollbar: if(text->scrollbar) { TScrollbar sb; sb.I1 = 0; sb.I5 = 0; sb.indicatormaximum = (textY-scroll); sb.indicatorheight = 10*17; sb.indicatorpos = -scroll; sb.barheight = LCD_HEIGHT_PX-24*(text->showtitle ? 2 : 1); sb.bartop = (text->showtitle ? 24 : 0); sb.barleft = text->width - 6; sb.barwidth = 6; Scrollbar(&sb); } GetKey(&key); switch(key) { case KEY_CTRL_UP: if (scroll < 0) { scroll = scroll + 17; } break; case KEY_CTRL_DOWN: if (textY > LCD_HEIGHT_PX-24*2) { scroll = scroll - 17; } break; case KEY_CTRL_EXIT: return; break; } } }
void calcul_mole() { char *str = NULL, *p=str; char characts[20]={'\0'}; char i=0; float result=0, masse; const char buffer[50]={0}; char cap; while(1) { Bdisp_AllClr_DDVRAM(); PrintMini(1,1,"Entrez votre formule : ",0); Mini("A a",0); EI_init(); EI_manage_config(EI_SET_COLUMN, 1); EI_manage_config(EI_SET_ROW, 2); EI_manage_config(EI_SET_START_MODE, EI_NORMAL); str=EI_input_string(25,(const char*)"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"); Bdisp_AllClr_DDVRAM(); sprintf(buffer,"%s",str); PrintXY(64-3*strlen(str),10,buffer,36); while(*str) // on va jusqu'a la fin de la chaine { i=0; while(isalpha(*str)) // on prends seulement les lettres { characts[i]=tolower(*str); // on copie la lettre en minuscule directement dans characts ++i; ++str; } characts[0]=toupper(characts[0]); // on met le 1er caractère en majuscule for(i=0;i<118;i++) // on se déplace dans les éléments de la structure { if(!strcmp(characts,elements[i].symbol)) { masse=elements[i].masse_mol; // on a la masse molaire break; } } for(i=0;i<20;++i) // on remet tout à zéro : évite les erreurs characts[i]='\0'; i=0; while(isdigit(*str)) // on prends seulement les chiffres { characts[i]=*str; // on copie la lettre dans characts ++i; ++str; } result += atoi(characts)*masse; for(i=0;i<4;++i) // on remet tout à zéro : évite les erreurs characts[i]='\0'; } free(p); PrintMini(1,30,"la masse molaire est de",0); sprintf(buffer,"%.3f g/mol",result); PrintMini(1,40,buffer,0); Mini("calc",0); Mini("ret",5); GetKey(&key); switch(key) { case 29 : return; } } }
int find(chang) { char *numero=NULL; char i=0,j; const char buffer[50]; Bdisp_AllClr_DDVRAM(); PrintXY(10,1,"Vous cherchez :",0); PrintMini(10,15,"1. numero de l'element",0); PrintMini(10,25,"2. masse molaire",0); PrintMini(10,35,"3. Symbole de l'element",0); PrintMini(10,45,"4. Nom de l'element",0); while (1) { EI_init(); EI_manage_config(EI_SET_COLUMN, 1); EI_manage_config(EI_SET_ROW, 3); EI_manage_config(EI_SET_START_MODE, EI_NORMAL); GetKey(&key); switch(key) { case 72 : { while(1) { Bdisp_AllClr_DDVRAM(); PrintMini(1,1,"Vous cherchez l'element n :",0); numero=EI_input_string(3,(const char*)"0123456789"); // ça coupe ici if (atoi(numero)>0 && atoi(numero)<119) // ça arrête le curseur { return atoi(numero)-1; } } } case 62 : { while(1) { Bdisp_AllClr_DDVRAM(); PrintMini(1,1,"Vous cherchez une masse",0); PrintMini(1,7,"molaire de :",0); numero=EI_input_string(3,(const char*)"0123456789"); for (i=0;i<118;i++) { if (atoi(numero)==floor(elements[i].masse_mol+0.5)) { return i; } } } } case 52 : { while(1) { Bdisp_AllClr_DDVRAM(); PrintMini(1,1,"Vous cherchez le symbole ?",0); EI_manage_config(EI_SET_START_MODE, EI_ALPHA_LOCKED); numero=EI_input_string(3,(const char*)"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"); numero[0]=toupper (numero[0]); // on met le 1er caractère en majuscule for (i=0;i<118;i++) { for (j = 1 ; numero[j] != '\0' ; j++) { numero[j] = tolower(numero[j]); // on met certains caractères en minuscule pour la recherche } if (!strcmp(numero,elements[i].symbol)) { return i; } } } } case 73 : { while(1) { Bdisp_AllClr_DDVRAM(); PrintMini(1,1,"Vous cherchez le nom ?",0); EI_manage_config(EI_SET_START_MODE, EI_ALPHA_LOCKED); numero=EI_input_string(13,(const char*)"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"); numero[0]=toupper(numero[0]); // on met le 1er caractère en majuscule for (i=0;i<118;i++) { for (j = 1 ; numero[j] != '\0' ; j++) { numero[j] = tolower(numero[j]);// on met certains caractères en minuscule pour la recherche } if (!strcmp(numero,elements[i].nom)) { return i; } } } } case 47 : return chang; } } }
int detailsElement(a) { const char buffer[50]; char descente=-9; while (1) { Bdisp_AllClr_DDVRAM(); PrintXY(20,descente+13,elements[a].symbol,0); sprintf(buffer,"%s",elements[a].nom); PrintMini(40,descente+13,buffer,0); sprintf(buffer,"%d",a+1); // détail des éléments PrintMini((10-a/25),descente+15,buffer,0); sprintf(buffer,"masse molaire %.3f g/mol",elements[a].masse_mol); PrintMini(1,descente+23,buffer,0); PrintMini(20,descente+40,"propriete de base :",0); // if (elements[a].groupe>=1) { sprintf(buffer,"groupe : %d ",elements[a].groupe); PrintMini(1,descente+50,buffer,0); } if ((a>55 && a<71) || (a>87 && a<103)) PrintMini(1,descente+50,"pas de groupe",0); sprintf(buffer,"periode : %d ",elements[a].periode); PrintMini(1,descente+60,buffer,0); sprintf(buffer,"couch electro %s",elements[a].config_electro); PrintMini(1,descente+70,buffer,0); sprintf(buffer,"famille %s",family[ajout[a].famille]); PrintMini(1,descente+80,buffer,0); sprintf(buffer,"decouvert en %d",ajout[a].annee); PrintMini(1,descente+90,buffer,0); sprintf(buffer,"etat a 293.15 K : %s",etat[ajout[a].etat]); PrintMini(1,descente+100,buffer,0); PrintMini(20,descente+120,"reactivite :",0); // if (elements[a].electro_neg==0) { PrintMini(1,descente+130,"electro neg inconnue",0); } else { sprintf(buffer,"electro neg : %f ",elements[a].electro_neg); PrintMini(1,descente+130,buffer,0); } if (elements[a].valence>=0) { sprintf(buffer,"valence : %d ",elements[a].valence); PrintMini(1,descente+140,buffer,0); } else { PrintMini(1,descente+140,"valence inconnue",0); } Mini("ret",5); GetKey(&key); switch (key) { case 38 : a-=1,descente=-9; break; case 27 : a+=1,descente=-9; break; case 37 : descente-=4; break; case 28 : descente+=4; break; case 29 : case 31 : case 47 : return a; } a=(a<0 ? 117 : a>117 ? 0 : a); descente=(descente>-9 ? -9 : descente<-85 ? -85 : descente); // on fixe les limites de la page } }
int tableauEleMini(chang) { char buffer[50]; char y; char menu=0; char choix=-1; while(1) { Bdisp_AllClr_DDVRAM(); ML_bmp_or(TABLEAU_MINI,0,0,91,48); choix_famille(choix); // on met en place le choix sur les familles chang=(chang>=118 ? 0 : chang<=-1 ? 117 : chang); y=(chang>55 && chang<71 ? 9 : chang>87 && chang<103 ? 10 : elements[chang].periode); if (chang>55 && chang<71 || chang>87 && chang<103) { ML_rectangle(5*elements[chang].groupe-4,5*y-7,5*elements[chang].groupe-1,5*y-4,0,1,2); } else { ML_rectangle(5*elements[chang].groupe-4,5*y-4,5*elements[chang].groupe-1,5*y-1,0,1,2); } PrintXY(110-3*strlen(elements[chang].symbol),13,elements[chang].symbol,0); sprintf(buffer,"%d",chang+1); // détail des éléments sur la droite PrintMini(110-2*strlen(buffer),5,buffer,0); sprintf(buffer,"%.3f",elements[chang].masse_mol); PrintMini(110-2*strlen(buffer),23,buffer,0); if(menu==0) { Mini("maxi",0); Mini("find",1); Mini("mol",2); Mini("fami",4); Mini("det",5); GetKey(&key); switch(key) { case 79 : case 47 : return chang; case 69 : chang=find(chang); break; case 59 : calcul_mole(); break; case 39 : menu=1; break; case 29 : chang=detailsElement(chang); break; } } else if (menu==1) { Mini("n-me",0); Mini("halo",1); Mini("g-ra",2); Mini("m-ti",3); Mini("m-al",4); Mini(" -->",5); GetKey(&key); switch(key) { case 47 : menu=0; choix=-1; break; case 79 : choix=0; break; case 69 : choix=1; break; case 59 : choix=2; break; case 49 : choix=3; break; case 39 : choix=4; break; case 29 : menu=2; break; // on change dans les 2 menus } } else if (menu==2) { Mini("m-at",0); Mini("lant",1); Mini("acta",2); Mini("m-tr",3); Mini("p-tr",4); Mini(" -->",5); GetKey(&key); switch(key) { case 47 : menu=0; choix=-1;break; case 79 : choix=5; break; case 69 : choix=6; break; case 59 : choix=7; break; case 49 : choix=8; break; case 39 : choix=9; break; case 29 : menu=1; break; // on change dans les 2 menus } } switch(key) // pour les touches principales à chaque fois { case 27 : chang+=1; break; case 38 : chang-=1; break; case 37 : chang=elements[chang].dessous; break; case 28 : chang=elements[chang].dessus; break; case 31 : case 78 : chang=detailsElement(chang); break; } } }