|
我用directfb做一个图形界面,功能具体如下:
有三个按钮,如何用焦点,事件实现键盘上的up,down来控制它们上下移动,搞了两三天了,写了一个程序,可是就是出不来,我的部分代码是:
/*********************button1 start**************************************/
DFBCHECK(dfb->GetDisplayLayer(dfb, DLID_PRIMARY, &layer));
layer->SetCooperativeLevel(layer, DLSCL_ADMINISTRATIVE);
if (!((gdesc.blitting_flags & DSBLIT_BLEND_ALPHACHANNEL) &&
(gdesc.blitting_flags & DSBLIT_BLEND_COLORALPHA))) {
layer_config.flags = DLCONF_BUFFERMODE;
layer_config.buffermode = DLBM_BACKSYSTEM;
layer->SetConfiguration(layer, &layer_config);
}
layer->GetConfiguration(layer, &layer_config);
layer->EnableCursor(layer, 1);
{
DFBWindowDescription desc;
desc.flags =
(DWDESC_POSX | DWDESC_POSY | DWDESC_WIDTH | DWDESC_HEIGHT |
DWDESC_CAPS);
desc.posx = 50;
desc.posy = 100;
desc.width = 191;
desc.height = 86;
desc.caps = DWCAPS_ALPHACHANNEL;
DFBCHECK(layer->CreateWindow(layer, &desc, &window1));
window1->GetSurface(window1, &window_surface1);
DFBCHECK(dfb->
CreateImageProvider(dfb,
"/data/directFB/DirectFB-examples-1.0.0/data/JB1.gif",
&provider));
provider->RenderTo(provider, window_surface1, NULL);
/* draw the background image */
primary->SetBlittingFlags(primary, DSBLIT_NOFX);
primary->Blit(primary, window_surface1, NULL, desc.posx,
desc.posy);
provider->Release(provider);
window1->CreateEventBuffer(window1,&buffer);
window1->AttachEventBuffer(window1, buffer);
window1->SetOpacity(window1, 0xFF);
window1->GetID(window1, &id1);
printf("window1 ID = %d\n",id1);
}
/* 获得焦点 */
printf("RequestFocus %d\n",window1->RequestFocus(window1));
printf("GrabKeyboard %d\n",window1->GrabKeyboard(window1));
window1->RaiseToTop(window1);
upper = window1;
/*********************button1 stop**************************************/
/*********************button2 start**************************************/
与button1相似,略
/*********************button2 stop**************************************/
/*********************button3 start**************************************/
与button1相似,略
/*********************button3 stop**************************************/
DFBWindowEvent evt;
static IDirectFBWindow *active = NULL;
//buffer->WaitForEventWithTimeout(buffer, 0, 10);
while (buffer->GetEvent(buffer, DFB_EVENT(&evt)) == DFB_OK) {
printf("Ente to while!\n");
printf("evt.window_id = %d\n",evt.window_id);
printf("id = %d\n",id1);
if (evt.window_id == id1)
window = window1;
else
window = window1;
printf("hello****************************\n");
if (evt.type == DWET_GOTFOCUS) {
printf("hello--------1-------------\n");
active = window;
printf("evt.key id = %d\n",evt.key_id);
switch (!evt.key_id) {
case DIKI_RIGHT:
printf("IN THE DWET_KEYDOWN!\n");
break;
case DIKI_LEFT:
printf("IN THE DWET_KEYDOWN!\n");
break;
case DIKI_UP:
printf("IN THE DWET_KEYDOWN!\n");
break;
case DIKI_DOWN:
printf("IN THE DWET_KEYDOWN!\n");
break;
default:
printf("IN THE default!\n");
break;
}
}
}
.
.
.
.
/*******************end***********************/
运行结果:
/*********************start***************************/
window1 ID = 1
RequestFocus 0
GrabKeyboard 0
Ente to while!
evt.window_id = 1
id = 1
hello****************************
Ente to while!
evt.window_id = 1
id = 1
hello****************************
Ente to while!
evt.window_id = 1
id = 1
hello****************************
Ente to while!
evt.window_id = 1
id = 1
hello****************************
hello--------1-------------
evt.key id = 0
IN THE default!
Ente to while!
evt.window_id = 1
id = 1
hello****************************
hello--------1-------------
evt.key id = 0
IN THE default!
/*****************************end***********************/
我知道是用那几个API,可是就是不会调 用,搞不出来,,郁闷,,哪个大哥帮忙看看,有这样的例子的话请贴一个上来.directfb的资料太少了,我都要疯了,,,,
求助,,无奈中,,,,,,, |
|