#include #include "dirlist.h" #include "console.h" #include "screen.h" #include "tools.h" #include "charmap.h" #include "touchpad.h" #define ICON_HEIGHT 16 #define MAX_ICONLGN 15 char tnsimg[16*14]={ 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x1F, 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x0A,0x1C,0x1C,0x1C,0x00,0x00,0x1A,0x0A, 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x0A,0x1C,0x00,0x00,0x14,0x14,0x00,0x0A, 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x0A,0x00,0x14,0x14,0x14,0x14,0x00,0x0A, 0x1F,0x10,0x18,0x18,0x18,0x18,0x10,0x1C,0x00,0x14,0x14,0x14,0x00,0x0A, 0x10,0x10,0x1C,0x1C,0x1C,0x1C,0x10,0x00,0x14,0x14,0x00,0x14,0x00,0x0A, 0x10,0x10,0x00,0x1C,0x00,0x1C,0x00,0x14,0x14,0x00,0x18,0x00,0x18,0x0A, 0x10,0x10,0x1C,0x00,0x1C,0x00,0x00,0x00,0x00,0x1A,0x18,0x18,0x18,0x0A, 0x1F,0x10,0x18,0x18,0x18,0x18,0x10,0x10,0x1A,0x18,0x18,0x18,0x18,0x0A, 0x1F,0x10,0x02,0x18,0x18,0x08,0x10,0x1C,0x1A,0x18,0x18,0x18,0x18,0x0A, 0x1F,0x10,0x08,0x08,0x08,0x08,0x10,0x1A,0x18,0x18,0x18,0x18,0x18,0x0A, 0x1F,0x10,0x08,0x08,0x08,0x08,0x10,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A, 0x1F,0x10,0x08,0x1C,0x1C,0x08,0x10,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F, 0x1F,0x10,0x08,0x1C,0x1C,0x08,0x10,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F, 0x1F,0x10,0x08,0x1C,0x1C,0x08,0x10,0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0x1E,0x1E,0x1E,0x1E,0x1E,0x00,0x1E,0x00,0x1F, 0x00,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x00,0x1E,0x1E,0x00, 0x00,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x00,0x00,0x00,0x00, 0x00,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1C,0x1C,0x1A,0x00, 0x00,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1C,0x1C,0x1A,0x18,0x00, 0x00,0x1E,0x1E,0x1E,0x1E,0x1E,0x1C,0x1C,0x1A,0x18,0x18,0x00, 0x00,0x1E,0x1E,0x1E,0x1E,0x1C,0x1C,0x1A,0x18,0x18,0x18,0x00, 0x00,0x1E,0x1E,0x1E,0x1C,0x1C,0x1A,0x18,0x18,0x18,0x18,0x00, 0x00,0x1E,0x1E,0x1C,0x1C,0x1A,0x18,0x18,0x18,0x18,0x18,0x00, 0x00,0x1E,0x1C,0x1C,0x1A,0x18,0x18,0x18,0x18,0x18,0x18,0x00, 0x00,0x1C,0x1C,0x1A,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; char bmpimg[13*12]={ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F, 0x00,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x00,0x1E,0x00,0x1F, 0x00,0x1E,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x1E,0x1E,0x00, 0x00,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x00,0x00,0x00,0x00, 0x00,0x1E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x1A,0x00, 0x00,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1C,0x1C,0x1A,0x18,0x00, 0x00,0x1E,0x08,0x08,0x08,0x1E,0x00,0x00,0x08,0x08,0x18,0x00, 0x00,0x1E,0x1E,0x1E,0x1E,0x1C,0x00,0x08,0x08,0x10,0x18,0x00, 0x00,0x1E,0x08,0x08,0x08,0x1C,0x08,0x08,0x10,0x10,0x18,0x00, 0x00,0x1E,0x1E,0x1C,0x1C,0x1A,0x00,0x08,0x08,0x10,0x18,0x00, 0x00,0x1E,0x08,0x08,0x08,0x18,0x00,0x00,0x08,0x08,0x18,0x00, 0x00,0x1C,0x1C,0x1A,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; int chooseFile(char* path, char* initpath, char* title) { int j,i,li,s, refresh, shouldwait, t, cancelled=0, parent=0, validated=0, si=0; FILE* tmp; int touchedzone=0; char ext[5], dext[9]; initTP(); strcpy(path,initpath); char* p = strrchr(path,'/'); if(p) *(p+1)=0; char* filenames[1024]; int fileselected=0; while(!fileselected && !cancelled) { int numfiles = dirlist(path, "*.*", filenames); refresh=1; li=-1; si=0; if(!strcmp(filenames[0],".")) si+=2; s=si; i=s; shouldwait=0; validated=0; while (!validated && !cancelled) { parent=0; if( refresh ) { clrScr(); resetConsole(); drwStr(0,0,title,0); drwFullHoriz(ICON_HEIGHT-2); drwFullHoriz(ICON_HEIGHT-3); drwStr(20,ICON_HEIGHT+2,path,0); dispIMG(0,ICON_HEIGHT+1,ofoldimg,15,13,1); for (j = s; j < numfiles && j-s=4) strcpy(ext,filenames[j]+t-4); *dext=0; if(t>=4) strcpy(dext,filenames[j]+t-8); if(!tmp) dispIMG(20,(j-s+2)*ICON_HEIGHT+1,cfoldimg,15,13,1); else { if(!strcmp(ext,".tns")) if(!strcmp(dext,".bmp.tns")) dispIMG(22,(j-s+2)*ICON_HEIGHT+1,bmpimg,12,13,1); else dispIMG(20,(j-s+2)*ICON_HEIGHT,tnsimg,14,16,1); else dispIMG(22,(j-s+2)*ICON_HEIGHT+1,fileimg,12,13,1); fclose(tmp); } drwStr(40,ICON_HEIGHT*(j-s+2)+2,filenames[j],0); } drwBox(38,ICON_HEIGHT*(i-s+2),SCREEN_WIDTH-1,ICON_HEIGHT*(i-s+3)-1,0); if(s>si) putChar(0,ICON_HEIGHT*2+2,24); if(s+MAX_ICONLGN-20 ) { if (isKeyPressed(KEY_NSPIRE_UP) || isKeyPressed(KEY_NSPIRE_8) || touchedzone==8) { i--; if (i < si) i = numfiles-1; } if (isKeyPressed(KEY_NSPIRE_DOWN) || isKeyPressed(KEY_NSPIRE_2) || touchedzone==2) { i++; if (i >= numfiles) i = si; } if (i!=li) { while(i=MAX_ICONLGN-2) { s+=MAX_ICONLGN-2; refresh=1; if(s>numfiles-MAX_ICONLGN+1) s=numfiles-MAX_ICONLGN+2; } if(!refresh) { if(li>=0) drwBox(38,ICON_HEIGHT*(li-s+2),SCREEN_WIDTH-1,ICON_HEIGHT*(li-s+3)-1,0x1F); drwBox(38,ICON_HEIGHT*(i-s+2),SCREEN_WIDTH-1,ICON_HEIGHT*(i-s+3)-1,0); } li=i; wait(250); } } if(isKeyPressed(KEY_NSPIRE_ESC)) cancelled=1; if((isKeyPressed(KEY_NSPIRE_LEFT) && !isKeyPressed(KEY_NSPIRE_UP) && !isKeyPressed(KEY_NSPIRE_DOWN)) || isKeyPressed(KEY_NSPIRE_4) || touchedzone==4) { parent=1; validated=1; } if(numfiles-si>0 && (isKeyPressed(KEY_NSPIRE_ENTER) || isKeyPressed(KEY_NSPIRE_RET) || isKeyPressed(KEY_NSPIRE_CLICK) || isKeyPressed(KEY_NSPIRE_5) || isKeyPressed(KEY_NSPIRE_6) || (isKeyPressed(KEY_NSPIRE_RIGHT) && !isKeyPressed(KEY_NSPIRE_UP) && !isKeyPressed(KEY_NSPIRE_DOWN))) || touchedzone==6) validated=1; wait(10); } if(!cancelled) { char* selected = filenames[i]; if(strcmp(selected,".") || parent) { if(!strcmp(selected,"..") || parent) { t=strlen(path); if(t>1) { path[t-1]=0; p = strrchr(path,'/'); if(p) *(p+1)=0; } shouldwait=1; } else { strcat(path,selected); if(chdir(path)) { fileselected=1; } else { strcat(path,"/"); shouldwait=1; } } if(shouldwait) { wait(250); shouldwait=0; } } } for(i=0;i