?? ebook.c
字號:
#include <string.h>
#include "api.h"
#include "mp3app.h"
#include "key.h"
#include "lcd.h"
#define EBOOK_SCREEN_WITH 128
#define EBOOK_SCREEN_HIGHT 128
#define COLOR_BLACK RGB565(0x00,0x00,0x00)
#define COLOR_WHITE RGB565(0xFF,0xFF,0xFF)
#define COLOR_GOLD RGB565(0xFF,0xC1,0x25)
#define COLOR_GREEN RGB565(0x00,0x80,0x80)
extern BOOLEAN change_dir(FILE_INFORMATION *pDir);
extern void scan_dir_file(UINT8 search_mode, UINT8 *extstr, BOOLEAN select_dir);
extern UINT8 select;
extern UINT16 totdir, totfile, totitem;
extern BOOLEAN change_dir(FILE_INFORMATION *pDir);
extern void scan_dir_file(UINT8 search_mode, UINT8 *extstr, BOOLEAN select_dir);
extern UINT8 select;
extern FILE_INFORMATION curr_finfo, curr_dir, play_dir;
extern UINT16 totdir, totfile, totitem;
extern FILE_t *fp;
extern INT8U _buf[256];
UINT16 page=0,theSpChar=0;
BOOLEAN iEbook_end=FALSE,iOnlyPageOne=FALSE,isUp=FALSE;
int savePrePagePos[200];
int thePos=0;
void gfx_txt_display(UINT8 *str,int remainwords)
{
INT8S data r1;
UINT8 n, y,*tempstr;
fg_color = COLOR_WHITE;
bg_color = COLOR_BLACK;
r1 = 0;
n = 0;
y = 0;
api_s8GetFont16x16BMP(0, TRUE);
while(remainwords--){//(*str != '\0') {
tempstr=str+1;
if(*str==0x0D&&*tempstr==0x0A)
{
n=0;
y+=16;
str+=2;
remainwords--;
if(y>=128)
break;
continue;
}
if(n >=16) {
n = 0;
y += 16;
if(y >= 128)
break;
}
if(*str <= 0x80 && r1 != 1) {
if(lcd_putc_8x16((n * 8)+4, y, *str++))
n++;
continue;
}
else {
r1 = api_s8GetFont16x16BMP(*str++, FALSE);
if(r1 == 0) {
if(lcd_putc_16x16((n * 8)+4, y, 0))
n += 2;
}
}
}
}
/*void vcheckUpSpChar(FILE_t *fileFp)
{
INT8S data r1=0;
int remainwords=0,n=16,i=128;
UINT8 *tempStr,theinputStr[128],*tempStr1,y=128;
theSpChar=0;
api_bFileSeek(fileFp,-128, SEEK_CUR);
remainwords=api_u16FileRead(theinputStr, sizeof(theinputStr), fileFp);
if(remainwords!=sizeof(theinputStr))
api_bFileSeek(fileFp,-remainwords, SEEK_CUR);
else
api_bFileSeek(fileFp,-128, SEEK_CUR);
api_s8GetFont16x16BMP(0, TRUE);
tempStr1=theinputStr+remainwords;
while(1)
{
tempStr=tempStr1-1;
if(*tempStr1==0x0A&&*tempStr==0x0D)
{
y-=16;
i=i-n-2;//i-=2;
if(y<=0)
break;
tempStr1-=2;
n=16;
continue;
}
if(n<=0)
{
n=16;
y-=16;
if(y<=0)
break;
}
if(*tempStr1!=0x0A||*tempStr!=0x0D)
{
if(*tempStr1 <= 0x80 && r1 != 1)
{
n--;
tempStr1--;
i--;
}
else
{
i--;
r1 = api_s8GetFont16x16BMP(*tempStr1--, FALSE);
if(r1 == 0)
n -= 2;
//continue;
}
}
}
theSpChar=i;
}*/
void vcheckSpChar(FILE_t *fileFp)
{
INT8S data r1=0;
int remainwords=0,n=0,i=0;
UINT8 *tempStr,theinputStr[128],*tempStr1,y=0;
theSpChar=0;
api_bFileSeek(fileFp,0, SEEK_CUR);
remainwords=api_u16FileRead(theinputStr, sizeof(theinputStr), fileFp);
if(remainwords!=sizeof(theinputStr))
api_bFileSeek(fileFp,-remainwords, SEEK_CUR);
else
api_bFileSeek(fileFp,-128, SEEK_CUR);
api_s8GetFont16x16BMP(0, TRUE);
tempStr1=theinputStr;
while(1)
{
tempStr=tempStr1+1;
if(*tempStr1==0x0D&&*tempStr==0x0A)
{
y+=16;
if(y>=128)
break;
tempStr1+=2;
i+=2;
n=0;
continue;
}
if(n>=16)
{
n=0 ;
y+=16;
if(y>=128)
break;
}
if(*tempStr1!=0x0D||*tempStr!=0x0A)
{
if(*tempStr1 <= 0x80 && r1 != 1)
{
n++;
tempStr1++;
i++;
}
else
{
i++;
r1 = api_s8GetFont16x16BMP(*tempStr1++, FALSE);
if(r1 == 0)
n += 2;
//continue;
}
}
}
theSpChar=i;
}
void vchangePageUp(void)
{
int thePrewords=0;
if(!iOnlyPageOne)
{
if(thePos<=0)
{
thePos=0;
thePrewords=savePrePagePos[0];
}
else
{
thePos--;
thePrewords=savePrePagePos[thePos];
}
iEbook_end=FALSE;
api_bFileSeek(fp,-thePrewords, SEEK_CUR);
gfx_bg(COLOR_BLACK);
delay(10);
api_u16FileRead(time2seg, thePrewords,fp);
api_bFileSeek(fp,-thePrewords, SEEK_CUR);
gfx_txt_display(time2seg,thePrewords);
/*if(remainwords!= theSpChar)
{
iEbook_end=TRUE;
}
else
iEbook_end=FALSE; */
}
}
void vchangePageDown(void)
{
int remainwords=0,i=0;
if(!iOnlyPageOne)
{
gfx_bg(COLOR_BLACK);
vcheckSpChar(fp);
delay(10);
api_bFileSeek(fp,0, SEEK_CUR);
remainwords=api_u16FileRead(time2seg, theSpChar,fp);
if(thePos>=200)
{
for(i=0;i<199;i++)
savePrePagePos[i]=savePrePagePos[i+1];
savePrePagePos[i]=remainwords;
}
else
savePrePagePos[thePos++]=remainwords;
gfx_txt_display(time2seg,remainwords);
if(remainwords!= theSpChar)
{
iEbook_end=TRUE;
//api_bFileSeek(fp,-remainwords, SEEK_CUR);
}
else
iEbook_end=FALSE;
}
}
void vchangePage(void)
{
int remainwords=0;
gfx_bg(COLOR_BLACK);
thePos=0;
vcheckSpChar(fp);
api_bFileSeek(fp,0, SEEK_SET);
remainwords=api_u16FileRead(time2seg, theSpChar,fp);
savePrePagePos[thePos++]=remainwords;
gfx_txt_display(time2seg,remainwords);
if(remainwords!= theSpChar)
{
iOnlyPageOne=TRUE;
api_bFileSeek(fp,-remainwords, SEEK_CUR);
}
}
BOOLEAN bOpenTxt(UINT8 *filename)
{
fp = NULL;
if((fp = api_pFileOpen(filename)) == NULL)
return false;
vchangePage();
}
BOOLEAN find_txt(void)
{
my_sprintf(_buf,"%s.TXT",curr_finfo.pu8FileName);
bOpenTxt(_buf);
return true;
}
void screen_ebook_Init(void)
{
page=0;
iEbook_end=FALSE;
thePos=0;
api_bStop();
if(screen_level != SCREEN_LEVEL_MAINMENU) {
return;
}
change_dir(0);
scan_dir_file(SEARCH_MODE_CURRDIR,"TXT",0);
screen_map(SCREEN_FILEBROWSER);
}
void screen_ebook(UINT8 key)
{
switch(key) {
case KEY_MENU:
api_vFileClose(fp);
iOnlyPageOne=FALSE;
theSpChar=0;
screen_map(SCREEN_MAINMENU);
return;
case KEY_PLAY:
break;
case KEY_AB_REPEAT:
api_vFileClose(fp);
iOnlyPageOne=FALSE;
theSpChar=0;
screen_map(SCREEN_FILEBROWSER);
break;
case KEY_NEXT:
if(!iEbook_end)
{
page++;
vchangePageDown();
delay(10);
}
break;
case KEY_PREV:
page--;
if(page<=0)
page=0;
vchangePageUp();
delay(10);
break;
default:
return;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -