text.c
来自「redboy for gba 是BPNS为GBA编写的一个小软件。软件的邹形是B」· C语言 代码 · 共 673 行 · 第 1/2 页
C
673 行
}
else
{
xp=xp+12;
if (xp>=223+6)
{
sav[lines]=tp+2;
lines++;
xp=2;
}
}
tp+=2;
}
else if ((text[tp]>32 && text[tp]<127) || text[tp]==' ')//可显示英文
{
if (xp>217+6)
{
sav[lines]=tp;
lines++;
xp=9;
}
else
{
xp=xp+7;
if (xp>=223+6)
{
sav[lines]=tp+1;
lines++;
xp=2;
}
}
tp++;
}
else if (text[tp]=='\n')//自动换行
{
tp++;
sav[lines]=tp;
lines++;
//if (lines>5115) return lines;
xp=2;
}
else tp++;
}
//lines++;
return lines;
}
void text_pre_do_end(){}
void title(char *tit)
{
int i;
u32 loc=0;
for (i=0;i<16;i++)
{
DmaClear(3,tit_co[i],mVRAM+loc,480,16);
loc+=240;
}
r_box(0,0,239,16,28160,0);
cwrite(2,2,RGB(30,30,30),tit);
//Q_line(0,15,240,RGB(30,30,30));
}
void set_text_bg(u16 color)
{
r_box(1,17,229,159,color,1);
}
void show_text_line(char *text,u8 line,u16 color,u8 shadow)
{
u8 xp=2,yp=19+line*14;
int tp=0;
u8 lend=0;
while (!lend)
{
if (text[tp]>127)//汉字
{
if (xp>212+6) lend=1;
else
{
if (shadow) paint_ch(xp+1,yp+1,0,text+tp);
paint_ch(xp,yp,color,text+tp);
xp=xp+12;
tp++;
}
}
else if ((text[tp]>32 && text[tp]<127) || text[tp]==' ')//可显示英文
{
if (xp>217+6) lend=1;
else
{
if (text[tp]!=' ')
{
if (shadow) paint_eng(xp+1,yp+2,0,text[tp]);
paint_eng(xp,yp+1,color,text[tp]);
}
xp=xp+7;
}
}
else if (text[tp]=='\n' || text[tp]=='\0') lend=1;
if (xp>=223+6) lend=1;
tp++;
}
}
void show_page(char *text,u32 *sav,u32 line,u32 lines,u16 color,u16 bg,u8 shadow)
{
u32 nowline=line;
u32 count=0;
//set_text_bg(bg);
while(count<plines && nowline<lines)
{
Q_box(1,19+count*14,229,32+count*14,bg);
show_text_line(text+sav[nowline],count,color,shadow);
nowline++;
count++;
}
while (count<plines)
{
r_box(1,19+count*14,229,32+count*14,bg,1);
count++;
}
}
void text(char *text,u16 color,u16 bg,u32 *sav)//文本显示
{
u32 lines;
u32 nowline=0;
u32 lip=0;
u8 done=1;
u32 pages=0;
u16 colors[2];
u8 i;
u8 start=1;
u8 shadow=1,autop=0;
u8 csets=0;
u32 code[((u32)text_pre_do_end-(u32)text_pre_do)/4+1];
u32 (*fun)()=(u32)code+1;
DmaCopy(3,text_pre_do,code,(u32)text_pre_do_end-(u32)text_pre_do,32);
autop_set(&rb_xp,2);
rb_yp=0;
if (rb_xp>15) rb_xp=5;
colors[0]=color;
colors[1]=bg;
set_text_bg(bg);
lines=fun(text,sav);
//lines=text_pre_do(text,sav);
if (color==0) shadow=0;
if (lines==0) {write(0,17,RGB(30,0,30),"文本打开失败!");return;}
sys_deamon=text_deamon;
pages=lines/plines;
if (lines%plines) pages++;
if (is_basic_run)
{
is_basic_run=0;
done=1;
nowline=_line;
}
else _line=0;
while(1)
{
if (start) {start=0;CS_ReadKey();} else readkey();
if(CS_IsKeyHold(KEY_R) && CS_IsKeyDown(KEY_LEFT))//更改颜色方案
{
csets=(csets+5)%6;
color=text_colors[csets*2];
bg=text_colors[csets*2+1];
colors[0]=color;
colors[1]=bg;
txt_set(colors);
done=1;
}
else if(CS_IsKeyHold(KEY_R) && CS_IsKeyDown(KEY_RIGHT))//更改颜色方案
{
csets=(csets+1)%6;
color=text_colors[csets*2];
bg=text_colors[csets*2+1];
colors[0]=color;
colors[1]=bg;
txt_set(colors);
done=1;
}
else if(CS_IsKeyHold(KEY_R) && CS_IsKeyDown(KEY_A))//保存书签
{
list_bmark(find_bmark(_fid),1);
if (is_basic_run) return;
title(_file);
done=1;
}
else if(CS_IsKeyHold(KEY_R) && CS_IsKeyDown(KEY_UP))//调整自动滚屏速度
{
rb_xp=(rb_xp+1)%16;
show_speed(16-rb_xp);
autop_set(&rb_xp,1);
}
else if(CS_IsKeyHold(KEY_R) && CS_IsKeyDown(KEY_DOWN))
{
rb_xp=(rb_xp+15)%16;
show_speed(16-rb_xp);
autop_set(&rb_xp,1);
}
else if(CS_IsKeyHold(KEY_R) && CS_IsKeyHold(KEY_L))//帮助说明
{
if(!is_in_text_help)
{
text_help();
done=1;
}
}
else if(CS_IsKeyHold(KEY_L) && CS_IsKeyDown(KEY_A))//设置字体
{
done=menu(font_menus,3);
switch (done)
{
case 1://更改模式
chg_fnt_mod();
break;
case 2://选择字体
ebk_select_font();
title(_file);
break;
case 3://字距设置
fnt_dis();
break;
}
done=1;
}
else if(CS_IsKeyHold(KEY_L) && CS_IsKeyDown(KEY_B))//文本阴影
{
shadow=!shadow;
done=1;
}
else if((CS_IsKeyHold(KEY_L) && CS_IsKeyHold(KEY_DOWN)) ||CS_IsKeyDown(KEY_DOWN) || CS_IsKeyDown(KEY_A))
{
if (nowline<lines-1)
{
nowline=(nowline+plines<lines-1)?(nowline+plines):lines-1;
done=1;
}
}
else if(CS_IsKeyHold(KEY_R) && CS_IsKeyDown(KEY_B))//自动滚屏
{
autop=!autop;
if (autop) myobj_new_str("AUTO PGAE ON",1);
else myobj_new_str("AUTO PGAE OFF",1);
rb_error=5;
show_obj(30,100);
}
else if((CS_IsKeyHold(KEY_L) && CS_IsKeyHold(KEY_LEFT)) || CS_IsKeyDown(KEY_LEFT))
{
if (nowline>0)
{
done=2;
nowline--;
}
}
else if((CS_IsKeyHold(KEY_L) && CS_IsKeyHold(KEY_RIGHT)) || CS_IsKeyDown(KEY_RIGHT) || (rb_yp==0 && autop))
{
if (nowline<lines-1)
{
if (rb_yp==0) rb_yp=1;
done=3;
nowline++;
}
}
else if ((CS_IsKeyHold(KEY_L) && CS_IsKeyHold(KEY_UP)) || CS_IsKeyDown(KEY_UP))
{
if (nowline>0)
{
nowline=(nowline>plines)?(nowline-plines):0;
done=1;
}
}
else if(CS_IsKeyDown(KEY_B))
{
rb_yp=0;
sys_deamon=NULL;
myobj_new_str("<REDBOY FOR GBA",1);
return;
}
else if(CS_IsKeyDown(KEY_START))
{
text_set(colors);
color=colors[0];
bg=colors[1];
done=1;
}
else if(CS_IsKeyDown(KEY_SELECT))
{
nowline=quik_page(lines,nowline);
done=1;
}
if (done) _line=nowline;
if (done==1)
{
Q_box(1,17,229,20,bg);
show_page(text,sav,nowline,lines,color,bg,shadow);
done=0;
new_scroll(nowline,lines);
//show_scroll(pages,nowline*100/lines);
}
else if(done==2)
{
mov_scr(1,19,229,144,14,2);
Q_box(1,19,229,32,bg);
show_text_line(text+sav[nowline],0,color,shadow);
new_scroll(nowline,lines);
//show_scroll(pages,nowline*100/lines);
done=0;
}
else if(done==3)
{
mov_scr(1,32,229,159,14,1);
Q_box(1,145,229,158,bg);
if (nowline+9<lines) show_text_line(text+sav[nowline+plines-1],plines-1,color,shadow);
new_scroll(nowline,lines);
//show_scroll(pages,nowline*100/lines);
done=0;
}
}
}
void show_text(char *tit,char *txt)
{
u32 *sav=(u32 *)new_malloc(20*1024);
u16 color[2];
txt_get(color);
if (color[0]==color[1])
{
color[1]=RGB(0,9,16);
color[0]=RGB(30,30,30);
txt_set(color);
}
win_plate(tit,"文本浏览器V1.0",RGB(26,26,25));
text(txt,color[0],color[1],sav);
new_free(sav);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?