博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
DirectFB 之 字体显示(2)
阅读量:4963 次
发布时间:2019-06-12

本文共 5934 字,大约阅读时间需要 19 分钟。

框架

示例代码

/********************************************** * Author: younger.liucn@hotmail.com * File name: dfbFont.c * Description:  dfbFont * Version, Desc *  1.1    Created *  1.2    add config **********************************************/#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include "dfbFont.h"/* config information *//********************************************************* * log flags and func of debug and error infor.[Begin] ********************************************************///#define DFB_SYS_LAYER//#define _DFB_DEBUG_#define DFB_FONT_TYPE_1 "/home/liuyiy/DFB/Font/data/decker.ttf"#define WINDOW_TEXT_LEN_X_PER (0.5)#define WINDOW_TEXT_LEN_Y_PER (0.1)#define WINDOW_TEXT_OFFSET_X_PER (0.25)#define WINDOW_TEXT_OFFSET_Y_PER (0.75)#ifdef _DFB_DEBUG_#define DFB_DEBUG(format, ...) do { \ printf("[BootAnimation:%4dL]DEBUG: "format, __LINE__, ##__VA_ARGS__); \} while (0)#else#define DFB_DEBUG(format, ...) do {} while (0)#endif#define DFB_NOTICE(format, ...) do { \ printf("[BootAnimation:%4dL]INFO: "format, __LINE__, ##__VA_ARGS__); \} while (0)#define DFB_ERROR(format, ...) do { \ printf("[BootAnimation:%4dL]ERROR: "format, __LINE__, ##__VA_ARGS__); \} while (0)/********************************************************* * log flags and func of debug and error infor.[End] ********************************************************//********************************************************* * Data structure and Global variants [Begin] ********************************************************//* 使用directFB画图所需的四个DFB资源 */struct AnimationDsc { IDirectFB *dfb; IDirectFBDisplayLayer *layer; IDirectFBWindow *window; IDirectFBSurface *surface; IDirectFBFont *font;};static struct AnimationDsc badsc;static char *testString = "Hello world! This is DirectFB!";/********************************************************* * Data structure and Global variants [End] ********************************************************/ /********************************************************* * Some functions help animation [Begin] ********************************************************//********************************************************* * Some functions help animation [End] ********************************************************/void freeResources(){ /* Release the window's surface. */ if(badsc.surface) badsc.surface->Release(badsc.surface); /* Release the window. */ if (badsc.window) badsc.window->Release(badsc.window); /* Release the layer. */ if (badsc.layer) badsc.layer->Release(badsc.layer); badsc.dfb->Release(badsc.dfb); return ;}static void initResources(int argc, char **argv){ DFBResult ret; badsc.window = NULL; badsc.surface = NULL; badsc.dfb = NULL; IDirectFB *dfb = NULL; DFBWindowDescription desc; DFBDisplayLayerConfig config; /* 初始化DirectFB */ DirectFBInit(&argc, &argv); DirectFBCreate(&dfb); if (!dfb) { DFB_ERROR("directfb interface is NULL\n"); return ; } badsc.dfb = dfb; /* 初始化 display layer:其中DFB_LAYERID_USING设置为0.*/ ret = badsc.dfb->GetDisplayLayer(badsc.dfb, DFB_LAYERID_USING, &(badsc.layer)); if(ret != (DFBResult)DFB_OK) { DFB_ERROR("Get layer(%d) failed!\n", DFB_LAYERID_USING); goto fail; } else { DFB_DEBUG("Get layer(%d) independently.\n", DFB_LAYERID_USING); } /* 获取display layer的配置,. */ badsc.layer->GetConfiguration(badsc.layer, &config); /* 设置window参数,并创建Window */ desc.flags = (DFBWindowDescriptionFlags)(DWDESC_POSX | DWDESC_POSY | DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_CAPS | DWDESC_OPTIONS); DFB_NOTICE("Layer Screen width %d, height %d !\n", config.width, config.height); desc.posx = WINDOW_TEXT_OFFSET_X_PER * config.width; desc.posy = WINDOW_TEXT_OFFSET_Y_PER * config.height; desc.width = WINDOW_TEXT_LEN_X_PER * config.width; desc.height = WINDOW_TEXT_LEN_Y_PER * config.height; desc.caps = (DFBWindowCapabilities)(DWCAPS_NODECORATION); desc.options = (DFBWindowOptions) (DWOP_GHOST); ret = badsc.layer->CreateWindow(badsc.layer, &desc, &(badsc.window)); if(ret != (DFBResult)DFB_OK) { DFB_ERROR("Create window failed!\n"); goto fail; } /* 设置透明度 */ ret = badsc.window->SetOpacity(badsc.window, 0xFF); if(ret != (DFBResult)DFB_OK) { DFB_ERROR("SetOpacity failed!\n"); goto fail; } /* 获取window的surface. */ ret = badsc.window->GetSurface(badsc.window, &(badsc.surface)); if(ret != (DFBResult)DFB_OK) { DFB_ERROR("SetOpacity failed!\n"); goto fail; } return ;fail: freeResources(); return ;}/* font init */static initFont(){ DFBFontDescription font_desc; font_desc.flags = DFDESC_HEIGHT; font_desc.height = 30; badsc.dfb->CreateFont(badsc.dfb, DFB_FONT_TYPE_1, &font_desc, &badsc.font); return ;}static void flipText(IDirectFBFont* font, IDirectFBSurface* surface, char* str) { int w = 0, h = 0; surface->GetSize(surface, &w, &h); surface->Clear(surface, 0x0, 0x0, 0x0, 0xff); surface->SetFont(surface, font); /* 设置前景颜色 */ surface->SetColor(surface, 0x00, 0xFF, 0x00, 0xFF); surface->DrawString(surface, str, strlen(str), w / 2, h / 2, DSTF_CENTER); /* 变换、更新surface buffer */ surface->Flip(surface, NULL, DSFLIP_WAITFORSYNC); return ;}static void doMovie(){ int ret = 0, i = 0; int width = 0, height = 0; struct timespec before_draw, after_draw; unsigned long elapsed_msec = 0, total_msec = 0; IDirectFBSurface *primary = badsc.surface; IDirectFBSurface *bg_sfc = NULL; DFB_NOTICE("Animation start ...\n"); flipText(badsc.font, primary, testString); usleep(2*1000*1000);out: primary->SetColor(primary, 0, 0, 0, 0); primary->Clear(primary, 0, 0, 0, 0); primary->Flip(primary, NULL, DSFLIP_WAITFORSYNC); DFB_NOTICE("Animation exit with black screen...\n"); return ;}int main(int argc, char **argv){ DFB_NOTICE("Animation entry.\n"); initResources(argc, argv); initFont(); doMovie(); freeResources(); DFB_NOTICE("Animation exit.\n"); return 0;}

作者:Younger Liu,

本作品采用进行许可。

转载于:https://www.cnblogs.com/youngerchina/p/5624447.html

你可能感兴趣的文章
spring data mongodb 配置遇到的几个问题
查看>>
Flume-ng源码解析之Channel组件
查看>>
技术博客
查看>>
设计模式之工厂方法模式
查看>>
在Lua里写unity游戏笔记
查看>>
Maven项目搭建(二):Maven搭建SSM框架
查看>>
我常用的delphi 第三方控件
查看>>
jQuery序列化表单 serialize() serializeArray()
查看>>
java python oracle推断字符串是否为数字的函数
查看>>
Ruby On Rails 4 hello world,Ruby On Rails上手
查看>>
linux杂谈(二十):apache服务配置
查看>>
FastDFS的配置、部署与API使用解读(6)FastDFS配置详解之Storage配置
查看>>
善用#waring,#pragma mark 标记
查看>>
Android 设置启动界面
查看>>
oracle常用命令
查看>>
超级干货 :一文读懂数据可视化 ZT
查看>>
Wyn BI的机会在哪里:越靠近消费者的行业,比如零售、文娱和金融,信息化投入越大 ZT...
查看>>
POJ 2823 Sliding Window
查看>>
P3119 [USACO15JAN]草鉴定Grass Cownoisseur
查看>>
JavaSE教程-04Java中循环语句for,while,do···while-思维导图
查看>>