[DFB] 移动鼠标绘制线条

/*1。surface的绘图函数
2。如何在surface中获取类似framebuffer的绘制内存地址(去掉代码中的注释)
3。eventbuffer的使用,按escape退出,按c 键清屏 ,移动鼠标绘线条 (平滑度有待改进)*/


#include <stdio.h>

#include <directfb/directfb.h>

static IDirectFB                *dfb = NULL;
static IDirectFBDisplayLayer    *layer = NULL;
static IDirectFBSurface            *surface = NULL;
static IDirectFBEventBuffer        *events = NULL;

static int screen_width = 0;
static int screen_height = 0;

int main(int argc, char *argv[])
{
    int pitch;
    int i,j;
    int quit = 0;
    int x = 0, y = 0, old_x = 0, old_y = 0;

    DirectFBInit(&argc, &argv);
    DirectFBCreate(&dfb);

    dfb->GetDisplayLayer(dfb, DLID_PRIMARY, &layer);
    dfb->CreateInputEventBuffer(dfb, DICAPS_ALL, DFB_TRUE, &events);
    layer->SetCooperativeLevel(layer, DLSCL_EXCLUSIVE);
    layer->GetSurface(layer, &surface);

    surface->GetSize(surface, &screen_width, &screen_height);

    surface->SetColor(surface, 0, 56, 0 , 0xff);
    surface->FillRectangle(surface, 0, 0, screen_width, screen_height);

    while(!quit){
        DFBEvent    evt;
        events->WaitForEvent(events);    //等待事件

        while(!quit && events->GetEvent(events, &evt) == DFB_OK){
            if(evt.clazz == DFEC_INPUT){
                    switch(evt.input.type){
                        case    DIET_KEYPRESS: //响应键盘事件
                            if(evt.input.key_symbol == DIKS_ESCAPE){//退出程序
                                quit = 1;
                            }else     if(evt.input.key_symbol == DIKS_SMALL_C){//清屏
                                surface->SetColor(surface, 0, 0, 0 , 0xff);//设置当前色
                                surface->FillRectangle(surface, 0, 0, screen_width, screen_height);
                            }
                            break;

                        case    DIET_AXISMOTION:
                            if(evt.input.flags & DIEF_AXISREL){
                                switch(evt.input.axis){
                                    case DIAI_X:
                                         x+=evt.input.axisrel;
                                         break;
                                    case DIAI_Y:
                                         y+=evt.input.axisrel;
                                         break;
                                    default :
                                         break;
                                }//switch(evt.input.axis){

                                if(x < 0){x = 0;}
                                if(y < 0){y = 0;}
                            }

                            surface->SetColor(surface, 0, 0xff, 0, 0xff);
                            surface->DrawLine(surface, old_x, old_y, x, y);
                            old_x = x;
                            old_y = y;
                            break;

                        default:
                            break;
                    }//switch
                }//if
            }//while(!quit && events->GetEvent(events, &evt) == DFB_OK){
    }//while(!quit){

    surface->Release(surface);
    layer->Release(layer);
    dfb->Release(dfb);

    return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值