DirectFB中显示键盘输入信息的方法.docxVIP

  • 1
  • 0
  • 约4.88千字
  • 约 5页
  • 2023-03-12 发布于湖北
  • 举报
本次做 T9 输入法中使用到了 DirectFB 这个图形库,只用了其中的几个 API,在这里讲解一下它们的使用方法。如有理解错误之处,恳请指教。 1、 初始化工作 在使用这个图形库时,需要创建一些全局变量以达到对图形操作的目的。首先在代码的开始处需要包含头文件#include directfb.h。我所做的程序段是关于键盘值的映射功能, 这还需要另一个头文件#include directfb_keynames.h。它能提供具有读取键盘的 API。全局变量的代码如下: /* the super interface */ /* the super interface */ static IDirectFB static IDirectFB *dfb; /* the primary surface (surface of primary layer) */ /* the primary surface (surface of primary layer) */ static IDirectFBSurface static IDirectFBSurface *primary; /* input interfaces: device and its buffer */ /* input interfaces: device and its buffer */ static IDirectFBEventBuffer *events; static IDirectFBEventBuffer *events; 如注释中所述,*dfb 是这个图形库的操作核心,是一个具有 DirectFB 主接口功能的变量。而*primary 是当前图形的操作对象。*events 则接收所有来自于操作DFB 所发生的事件。其他的还有: static int screen_width, screen_height; static int screen_width, screen_height; 这是用来表明屏幕坐标的操作变量。类似的还有很多,如字体大小变量,鼠标坐标的变量,这些都可以根据自己所需要的功能进行声明。 2、 关于 DFBCHECK /* macro for a safe call to DirectFB functions */在看过几个例程后,代码中都会有如下的宏定义: /* macro for a safe call to DirectFB functions */ #define DFBCHECK(x...) \ #define DFBCHECK(x...) \ { { \ err = x; err = x; \ if (err != DFB_OK) { if (err != DFB_OK) { \ fprintf( stderr, fprintf( stderr, %s %d:\n\t, FILE , LINE ); \ DirectFBErrorFatal( #x, err ); DirectFBErrorFatal( #x, err ); \ } } \ } } 这是官方给的程序中常见的反馈函数,它可以检测所调用的 API 是否正常执行。如: /* create the super interface */ DFBCHECK(DirectFBCreate( dfb )); 3、 按键事件的监测与触发响应 (1)在主程序中的一个循环中,不断的使用 GetEvent()来获得在 DFB 环境下所触发的事件。当满足条件时,就会执行这个 while 的内容,核心函数就是 show_event( evt ); 所创建的获取事件类型的结构体是由 DFBInputEvent 所创建的结构体变量 evt ,它是 DFB 输入事件的结构体。其代码片段如下: while (1) { while (1) { DFBInputEvent evt; DFBInputEvent evt; while (events -GetEvent( events, DFB_EVENT(evt) ) == DFB_OK) { { primary-Clear( primary, 0, 0, 0, 0 ); primary-Clear( primary, 0, 0, 0, 0 ); show_event( evt );/* show_event( evt );/*它处理各种按键事件的响应*/ primary-Flip( primary, NULL, 0 );//将响应结果显示到屏幕上 } } …… …… } } static void show_event( DFBInputEvent *evt )(2)在这个 show_event( evt ) 中,主要对输入对像 st

文档评论(0)

1亿VIP精品文档

相关文档