Dear All
While I'm doing some chinese font rendering test,
I realized there may be a bug in SDL input buffer
here I attact a programe I test with some chinese
font and text it work fine in console but when I
do system=sdl, input event didn't seem to work
correctly .... is it my sdl problem?
Thanks
#include <stdio.h>
#include <directfb.h>
#define VERSION "0.0.1"
static IDirectFB *dfb = NULL;
static IDirectFBSurface *primary = NULL;
static IDirectFBInputDevice *keyboard = NULL;
static int screen_width = 0;
static int screen_height = 0;
#define DFBCHECK(x...) \
{ \
DFBResult err = x; \
\
if (err != DFB_OK) \
{ \
fprintf( stderr, "%s <%d>:\n\t", __FILE__, __LINE__ ); \
DirectFBErrorFatal( #x, err ); \
} \
}
static IDirectFBFont *font = NULL;
static DFBInputDeviceKeyState escape = DIKS_UP;
static IDirectFBEventBuffer *buffer = NULL;
static char *text = "è·³éé£åªæ¶çï¼ è·³è¿é£åªæç!";
static char *fontname = "/usr/X11R6/lib/X11/fonts/truetype/FZKaiTi.ttf";
static void
print_usage (const char *prg_name)
{
int i;
fprintf (stderr, "\nDirectFB Font Test (version %s)\n\n", VERSION);
fprintf (stderr, "Usage: %s [options]\n\n", prg_name);
fprintf (stderr, "Options:\n");
fprintf (stderr, " -f --font Full path font name\n");
fprintf (stderr, " -t --text Text to be displayed\n");
fprintf (stderr, "\n");
}
static int render(int loopindex, int screen_width, int screen_height, int width)
{
int i=loopindex;
if( i > -width )
{
DFBCHECK (primary->SetColor (primary, 0x0, 0x0, 0x0, 0xFF));
DFBCHECK (primary->FillRectangle (primary, 0, 0, screen_width, screen_height));
DFBCHECK (primary->SetColor (primary, 0x80, 0x0, 0x20, 0xFF));
DFBCHECK (primary->DrawString (primary, text, -1, i, screen_height / 2, DSTF_LEFT));
//DFBCHECK (primary->Flip (primary, NULL, DSFLIP_WAITFORSYNC));
DFBCHECK (primary->Flip (primary, NULL, 0 ));
i--;
} else {
i=screen_width;
}
return i;
}
int main (int argc, char **argv)
{
int width, quit=0, loopindex;
DFBFontDescription font_dsc;
DFBSurfaceDescription dsc;
if( argc < 1 )
print_usage( argv[0] );
else if( argc >= 3 ) {
if( strcmp( "-f", argv[1] )==0 || strcmp( "--font", argv[1] )==0 ){
fontname = argv[2];
} else if (strcmp ( "-t", argv[1] )==0 || strcmp( "--text", argv[1] )==0 ){
text = argv[2];
}
}
if( argc >= 5 ) {
if( strcmp( "-f", argv[3] )==0 || strcmp( "--font", argv[3] )==0 ){
fontname = argv[4];
} else if (strcmp ( "-t", argv[3] )==0 || strcmp( "--text", argv[3] )==0 ){
text = argv[4];
}
}
DFBCHECK (DirectFBInit (&argc, &argv));
DFBCHECK (DirectFBCreate (&dfb));
// DFBCHECK (dfb->SetCooperativeLevel (dfb, DFSCL_FULLSCREEN));
dsc.flags = DSDESC_CAPS;
dsc.caps = DSCAPS_PRIMARY | DSCAPS_FLIPPING;
DFBCHECK (dfb->CreateSurface( dfb, &dsc, &primary ));
DFBCHECK (primary->GetSize (primary, &screen_width, &screen_height));
loopindex = screen_width;
font_dsc.flags = DFDESC_HEIGHT;
font_dsc.height = 48;
DFBCHECK (dfb->GetInputDevice (dfb, DIDID_KEYBOARD, &keyboard));
DFBCHECK (keyboard->CreateEventBuffer (keyboard, &buffer));
DFBCHECK (dfb->CreateFont (dfb, fontname , &font_dsc, &font));
DFBCHECK (primary->SetFont (primary, font));
DFBCHECK (font->GetStringWidth (font, text, -1, &width));
DFBInputEvent event;
while (!quit){
if ( buffer->HasEvent(buffer) == DFB_OK )
{
if( buffer->GetEvent (buffer, DFB_EVENT(&event)) == DFB_OK )
{
if (event.type == DIET_KEYPRESS) {
printf("key press %d\n", event.key_id );
if (event.key_id == DIKI_ESCAPE || event.key_id == DIKI_Q )
quit = 1;
}
}
} else {
loopindex = render(loopindex, screen_width, screen_height, width );
}
}
font->Release (font);
buffer->Release (buffer);
keyboard->Release (keyboard);
primary->Release (primary);
dfb->Release (dfb);
return 23;
}
_______________________________________________
directfb-dev mailing list
[email protected]
http://mail.directfb.org/cgi-bin/mailman/listinfo/directfb-dev