Circle
Title I. Purpose
采用littlegl绘制一个圈。
Title II, workflow solutions
2.1 Principle title scheme
littlegl中提供了一个画弧度的函数。我们可以采用此函数绘制一个圆。此UI系统中将各个对象外观,属性和行为都独立分开。
要绘制一个圆,我们至少要做两个操作,即圆绘制(包含了半径大小),另外一个为圆的一些属性(修饰或者风格),即颜色,边框宽度,以及叠影等。
Title draw an arc of functions:
lv_arc_set_angles(arc, start_angle, end_angle)
Title Configuration function attributes:
lv_arc_set_style(arc, LV_ARC_STYLE_MAIN, &style)
2.2 Title Process
- Round-configured style properties;
- Creates a circle arc, to determine its position and size of the display;
- Style attribute to the arc load configuration 1.
Title 3, Code
3.1 The title of the new arc case header and source files
在pc_simulator_sdl_visual_studio-master\visual_studio_2017_sdl\lv_examples\lv_tests中创建cr_test目录,并在其中创建cr_arc.h和cr_arc.c文件。
In main.c中添加对此头文件引用#include"lv_examples/lv_tests/cr_test/cr_arc.h"
**
3.2 title written source and header files
Title source file
#include <stdlib.h>
#include <Windows.h>
#include <SDL.h>
#include "lvgl/lvgl.h"
#include "lv_drivers/display/monitor.h"
#include "lv_drivers/indev/mouse.h"
#include "lv_drivers/indev/keyboard.h"
#include "lv_examples/lv_apps/demo/demo.h"
#include "lv_examples/lv_apps/benchmark/benchmark.h"
#include "lv_examples/lv_tests/lv_test_theme/lv_test_theme_1.h"
#include "lv_examples/lv_tutorial/10_keyboard/lv_tutorial_keyboard.h"
static void ArcTaskCb(lv_task_t *t)
{
static int16_t a = 0;
//1. 每20ms任务调度时,此a+3;
a += 3;
if(a > 360)a = 360;
//2. 给user_data这个传递过来的圆弧对象重绘制0度->a度的弧度
lv_arc_set_angles(t->user_data, 0 ,a);
if(a == 360){
//删除任务
lv_task_del(t);
a = 0;
printf("task cut!!\r\n");//debug
return ;
}
}
void DrawArc()
{
//1. style config
static lv_style_t style;
lv_style_copy(&style, &lv_style_plain);//复制默认常规属性lv_style_plain,这样属性不用大规模复制
style.line.color = LV_COLOR_NAVY; //深蓝色
style.line.width = 8; //宽度
//2. arc config
lv_obj_t * arc = lv_arc_create(lv_scr_act(), NULL);//在当前screen对象上创建一个arc,则arc父类为screen
lv_arc_set_angles(arc, 90, 190);//初始显示的弧度为一个90度到190度的100度半圆
lv_arc_set_style(arc, LV_ARC_STYLE_MAIN, &style);//配置圆弧风格
lv_obj_align(arc, NULL, LV_ALIGN_CENTER, 0, 0); //在其父对象(这里就是screen)上的中间显示
lv_task_create(ArcTaskCb, 20, LV_TASK_PRIO_LOWEST, arc);//创建了一个20ms,优先级为最低的ArcTaskCb重绘任务,并向任务的user_data参数传递arc指针
}
Title header file
Just declared DrawArc function.
#ifndef CR_ARC_H_
#define CR_ARC_H_
void DrawArc();
#endif
Title 3.3 main.c function call
在实现demo中,需要在lv_init()和hal_init()两个函数初始化后调用【具体原因见其他章节】。
int main(int argc, char** argv)
{
/*Initialize LittlevGL*/
lv_init();
/*Initialize the HAL for LittlevGL*/
hal_init();
/*
* Demo, benchmark, tests and tutorial.
*
* Uncomment any one (and only one) of the functions below to run that
* particular demo, test or tutorial.
*/
DrawArc();//调用
//ButtonTest(); SliderInit(); ListInit();
// demo_create();
//benchmark_create();
//lv_test_theme_1(lv_theme_night_init(210, NULL));
//lv_test_theme_1(lv_theme_night_init(100, NULL));
//lv_test_theme_1(lv_theme_material_init(210, NULL));
//lv_test_theme_1(lv_theme_alien_init(210, NULL));
//lv_test_theme_1(lv_theme_zen_init(210, NULL));
//lv_test_theme_1(lv_theme_nemo_init(210, NULL));
//lv_test_theme_1(lv_theme_mono_init(210, NULL));
//lv_test_theme_1(lv_theme_default_init(210, NULL));
//lv_tutorial_keyboard(kb_indev);
while (1) {
/* Periodically call the lv_task handler.
* It could be done in a timer interrupt or an OS task too.*/
lv_task_handler();
Sleep(8); /*Just to let the system breathe */
}
return 0;
}
Fourth, the results