//字体显示
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <directfb/directfb.h>
static IDirectFB *dfb = NULL;
static IDirectFBSurface *primary = NULL;
static IDirectFBFont *font = NULL;//IDerectFBFont为测量字符的接口,用于计量字符串或单个字符,查询/选择编码等
static char *text = "DirectFB Chinsung !";//此为需要显示的字符
static int screen_width = 0;
static int screen_height = 0;
int main()
{
int i, width;
DFBFontDescription font_dsc;
DFBSurfaceDescription dsc;
DirectFBInit(0, 0);
DirectFBCreate(&dfb);
dfb->SetCooperativeLevel(dfb, DFSCL_FULLSCREEN);
dsc.flags = DSDESC_CAPS; //建立用于创建primary的描述
dsc.caps = DSCAPS_PRIMARY | DSCAPS_FLIPPING;
dfb->CreateSurface(dfb, &dsc, &primary);//利用先前的dsc描述创建一个IDirectFBSurface
primary->GetSize(primary, &screen_width, &screen_height);//将primary刚才获取到的屏幕长宽赋给screen_width和screen_height
font_dsc.flags = DFDESC_HEIGHT;
font_dsc.height = 48; //设置DFBFontDescription相应属性,这里将字高设为 48
dfb->CreateFont(dfb, "./simkai.ttf", &font_dsc, &font);//利用刚刚设置好的DFBFontDescription创建字体对象
primary->SetFont(primary, font); //设置primary要使用的字体对象,这里为font
font->GetStringWidth(font, text, -1, &width);//设置要使用的字体的宽度,并将其结果赋给width
//走马灯效果
for(i = screen_width; i > -width; --i){
//清空屏幕
primary->SetColor(primary, 0x0, 0x0, 0x0, 0xff);
primary->FillRectangle(primary, 0, 0, screen_width, screen_height);
//显示字符串
primary->SetColor (primary, 0x80, 0x0, 0x20, 0x80);
primary->DrawString (primary, text, -1, i, screen_height/2, DSTF_LEFT);
primary->Flip (primary, NULL, DSFLIP_WAITFORSYNC); //最后Flip一下使前面的操作在屏幕上可见
}
font->Release(font);
primary->Release(primary);
dfb->Release(dfb);
return 0;
}
[DFB] 显示字符串 走马灯效果
最新推荐文章于 2021-07-29 23:11:45 发布