掌叔
2009-06-05 08:02:53
摘自:[url]www.iacger.com[/url]
作者:newcreat
本节需要图片images/demo1_bg.jpg,和ttf字体fonts/msyh.ttf,msyh.ttf是微软雅黑
大小14.3 MB的那个,没有请用任意ttf字体重命名替换
本节例子用到上一节的目录遍历,和获得时间函数,请更新到nge2最新的版本165
注意中文名无法获得,小写名psp会变为大写。
[attach]1329[/attach]
[code=c]
#include "libnge2.h"
#include "nge_sys_compatible.h"
/**
* nge_test:测试nge2的按键输入字体
* 所需资源文件:拷贝到相应目录下
*/
int game_quit = 0;
image_p plist,pimage_bg;
static char clist[128];
PFont font ;
int line = 0;
void btn_down(int keycode)
{
switch(keycode)
{
case PSP_BUTTON_UP:
break;
case PSP_BUTTON_DOWN:
break;
case PSP_BUTTON_LEFT:
break;
case PSP_BUTTON_RIGHT:
break;
case PSP_BUTTON_TRIANGLE:
break;
case PSP_BUTTON_CIRCLE:
break;
case PSP_BUTTON_CROSS:
ScreenShot("screenshot.png");
break;
case PSP_BUTTON_SQUARE:
break;
case PSP_BUTTON_SELECT:
game_quit = 1;
break;
case PSP_BUTTON_START:
game_quit = 1;
break;
}
}
void btn_up(int keycode)
{
switch(keycode)
{
case PSP_BUTTON_UP:
break;
case PSP_BUTTON_DOWN:
break;
case PSP_BUTTON_LEFT:
break;
case PSP_BUTTON_RIGHT:
break;
case PSP_BUTTON_TRIANGLE:
break;
case PSP_BUTTON_CIRCLE:
break;
case PSP_BUTTON_CROSS:
break;
case PSP_BUTTON_SQUARE:
break;
case PSP_BUTTON_SELECT:
game_quit = 1;
break;
case PSP_BUTTON_START:
game_quit = 1;
break;
}
}
void DrawScene()
{
BeginScene(1);
ImageToScreen(pimage_bg,0,0);
ImageToScreen(plist,0,0);
EndScene();
}
void mycall(dir_desc_p dir_desc,void* data)
{
if(dir_desc!=NULL){
if(dir_desc->flag == FIO_F_FILE)
sprintf(clist,"[FILE]%s",dir_desc->name);
else if(dir_desc->flag == FIO_F_DIR){
sprintf(clist,"[DIR ]%s",dir_desc->name);
}
//只显示10项
if(line < 10 )
font_drawtext(font, clist, strlen(clist), plist, 0, 5+line*20, FONT_SHOW_SHADOW);
line++;
}
}
extern "C"
int main(int argc, char* argv[])
{
int i;
NGE_Init(INIT_VIDEO);
InitInput(btn_down,btn_up,1);
font = create_font_freetype("fonts/msyh.ttf",12, DISPLAY_PIXEL_FORMAT_8888);
pimage_bg = image_load("images/demo1_bg.jpg",DISPLAY_PIXEL_FORMAT_8888,1);
if(pimage_bg == NULL)
printf("can not open file
");
plist = image_create(512, 512, DISPLAY_PIXEL_FORMAT_8888);
font_setcolor(font, MAKE_RGBA_8888(255,255,255,255));
//获得当前系统时间
sys_time_t times;
sys_localtime(×);
io_dir_travel(".",mycall,NULL);
memset(clist,0,128);
sprintf(clist, "[现在时刻] %d-%.2d-%.2d %.2d:%.2d:%.2d",times.year,times.month,times.day,times.hour,times.minutes,times.seconds);
if(plist){
font_setcolor(font,MAKE_RGBA_8888(0xb6,0x04,0xf8,0xff));
font_drawtext(font, clist, strlen(clist), plist, 240, 250, FONT_SHOW_SHADOW);
}
while ( !game_quit )
{
ShowFps();
InputProc();
DrawScene();
}
font_destory(font);
image_free(pimage_bg);
image_free(plist);
NGE_Quit();
return 0;
}
[/code]
sadwind
2011-07-21 13:55:38
font_drawtext(pf[0],txt,50,pimage_text,20,(++m)*20,FONT_SHOW_NORMAL);
奇怪,我用这个语在屏幕显示目录文件名,中文能显示的。