1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

fix conflicts

This commit is contained in:
Gabor Kiss-Vamosi 2019-06-27 18:34:49 +02:00
commit 0bd3a9f4d0
267 changed files with 49272 additions and 178122 deletions

97
.clang-format Normal file
View File

@ -0,0 +1,97 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: true
BinPackParameters: true
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: true
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: false
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '$'
IndentCaseLabels: true
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Middle
ReflowComments: true
SortIncludes: false
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: Never
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
UseTab: Never
...

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
**/*.o
**/*.swp
**/*.swo
tags
docs/api_doc

View File

@ -73,24 +73,33 @@ In the most simple case you need to do these steps:
1. Copy `lv_conf_templ.h` as `lv_conf.h` next to `lvgl` and set at least `LV_HOR_RES`, `LV_VER_RES` and `LV_COLOR_DEPTH`.
2. Call `lv_tick_inc(x)` every `x` milliseconds **in a Timer or Task** (`x` should be between 1 and 10). It is required for the internal timing of LittlevGL. **It's very important that you don't call `lv_task_handler` in the same loop.**
3. Call `lv_init()`
4. Register a function which can **copy a pixel array** to an area of the screen:
4. Create a buffer for LittlevGL
```c
static lv_disp_buf_t disp_buf;
static lv_color_t buf[LV_HOR_RES_MAX * 10]; /*Declare a buffer for 10 lines*/
lv_disp_buf_init(&disp_buf, buf, NULL, LV_HOR_RES_MAX * 10); /*Initialize the display buffer*/
```
4. Implement and register a function which can **copy a pixel array** to an area of your diplay:
```c
lv_disp_drv_t disp_drv; /*Descriptor of a display driver*/
lv_disp_drv_init(&disp_drv); /*Basic initialization*/
disp_drv.disp_flush = disp_flush; /*Set your driver function*/
disp_drv.hor_res = 480; /*Set the horizontal resolution*/
disp_drv.ver_res = 320; /*Set the vertical resolution*/
disp_drv.flush_cb = my_disp_flush; /*Set your driver function*/
disp_drv.buffer = &disp_buf; /*Assign the buffer to teh display*/
lv_disp_drv_register(&disp_drv); /*Finally register the driver*/
void disp_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p)
void my_disp_flush(lv_disp_t * disp, const lv_area_t * area, lv_color_t * color_p)
{
int32_t x, y;
for(y = y1; y <= y2; y++) {
for(x = x1; x <= x2; x++) {
sep_pixel(x, y, *color_p); /* Put a pixel to the display.*/
for(y = area->y1; y <= area->y2; y++) {
for(x = area->x1; x <= area->x2; x++) {
set_pixel(x, y, *color_p); /* Put a pixel to the display.*/
color_p++;
}
}
lv_flush_ready(); /* Tell you are ready with the flushing*/
lv_disp_flush_ready(disp); /* Tell you are ready with the flushing*/
}
```
@ -98,10 +107,10 @@ void disp_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t
```c
lv_indev_drv_init(&indev_drv); /*Descriptor of a input device driver*/
indev_drv.type = LV_INDEV_TYPE_POINTER; /*Touch pad is a pointer-like device*/
indev_drv.read = touchpad_read; /*Set your driver function*/
indev_drv.read_cb = my_touchpad_read; /*Set your driver function*/
lv_indev_drv_register(&indev_drv); /*Finally register the driver*/
bool touchpad_read(lv_indev_data_t * data)
bool my_touchpad_read(lv_indev_t * indev, lv_indev_data_t * data)
{
static lv_coord_t last_x = 0;
static lv_coord_t last_y = 0;
@ -119,7 +128,7 @@ bool touchpad_read(lv_indev_data_t * data)
```
6. Call `lv_task_handler()` periodically every few milliseconds in the main `while(1)` loop, in Timer interrupt or in an Operation system task. It will redraw the screen if required, handle input devices etc. **It's very important that you don't call `lv_tick_inc` in the same loop.**
For a detailed description check the [Documentation](https://docs.littlevgl.com/#Porting) or the [Porting tutorial](https://github.com/littlevgl/lv_examples/blob/master/lv_tutorial/0_porting/lv_tutorial_porting.c)
For a detailed description check the [Documentation](https://docs.littlevgl.com/#Porting) or the [Porting examples](https://github.com/littlevgl/lvgl/tree/multi-disp/lv_porting).
### Code examples

View File

@ -1 +0,0 @@
--style=kr --convert-tabs --indent=spaces=4 --indent-switches --pad-oper --unpad-paren --align-pointer=middle --suffix=.bak --lineend=linux --min-conditional-indent=

View File

@ -1 +0,0 @@
--convert-tabs --indent=spaces=4

View File

@ -1,655 +0,0 @@
/**
* GENERATED FILE, DO NOT EDIT IT!
* @file lv_conf_checker.h
* Make sure all the defines of lv_conf.h have a default value
**/
#ifndef LV_CONF_CHECKER_H
#define LV_CONF_CHECKER_H
/*===================
Dynamic memory
*===================*/
/* Memory size which will be used by the library
* to store the graphical objects and other data */
#ifndef LV_MEM_CUSTOM
#define LV_MEM_CUSTOM 0 /*1: use custom malloc/free, 0: use the built-in lv_mem_alloc/lv_mem_free*/
#endif
#if LV_MEM_CUSTOM == 0
#ifndef LV_MEM_SIZE
# define LV_MEM_SIZE (64U * 1024U) /*Size memory used by `lv_mem_alloc` in bytes (>= 2kB)*/
#endif
#ifndef LV_MEM_ATTR
# define LV_MEM_ATTR /*Complier prefix for big array declaration*/
#endif
#ifndef LV_MEM_ADR
# define LV_MEM_ADR 0 /*Set an address for memory pool instead of allocation it as an array. Can be in external SRAM too.*/
#endif
#ifndef LV_MEM_AUTO_DEFRAG
# define LV_MEM_AUTO_DEFRAG 1 /*Automatically defrag on free*/
#endif
#else /*LV_MEM_CUSTOM*/
#ifndef LV_MEM_CUSTOM_INCLUDE
# define LV_MEM_CUSTOM_INCLUDE <stdlib.h> /*Header for the dynamic memory function*/
#endif
#ifndef LV_MEM_CUSTOM_ALLOC
# define LV_MEM_CUSTOM_ALLOC malloc /*Wrapper to malloc*/
#endif
#ifndef LV_MEM_CUSTOM_FREE
# define LV_MEM_CUSTOM_FREE free /*Wrapper to free*/
#endif
#endif /*LV_MEM_CUSTOM*/
/* Garbage Collector settings
* Used if lvgl is binded to higher language and the memory is managed by that language */
#ifndef LV_ENABLE_GC
#define LV_ENABLE_GC 0
#endif
#if LV_ENABLE_GC != 0
#ifndef LV_MEM_CUSTOM_REALLOC
# define LV_MEM_CUSTOM_REALLOC your_realloc /*Wrapper to realloc*/
#endif
#ifndef LV_MEM_CUSTOM_GET_SIZE
# define LV_MEM_CUSTOM_GET_SIZE your_mem_get_size /*Wrapper to lv_mem_get_size*/
#endif
#ifndef LV_GC_INCLUDE
# define LV_GC_INCLUDE "gc.h" /*Include Garbage Collector related things*/
#endif
#endif /* LV_ENABLE_GC */
/*===================
Graphical settings
*===================*/
/* Horizontal and vertical resolution of the library.*/
#ifndef LV_HOR_RES
#define LV_HOR_RES (480)
#endif
#ifndef LV_VER_RES
#define LV_VER_RES (320)
#endif
/* Dot Per Inch: used to initialize default sizes. E.g. a button with width = LV_DPI / 2 -> half inch wide
* (Not so important, you can adjust it to modify default sizes and spaces)*/
#ifndef LV_DPI
#define LV_DPI 100
#endif
/* Enable anti-aliasing (lines, and radiuses will be smoothed) */
#ifndef LV_ANTIALIAS
#define LV_ANTIALIAS 1 /*1: Enable anti-aliasing*/
#endif
/*Screen refresh period in milliseconds*/
#ifndef LV_REFR_PERIOD
#define LV_REFR_PERIOD 30
#endif
/*-----------------
* VDB settings
*----------------*/
/* VDB (Virtual Display Buffer) is an internal graphics buffer.
* The GUI will be drawn into this buffer first and then
* the buffer will be passed to your `disp_drv.disp_flush` function to
* copy it to your frame buffer.
* VDB is required for: buffered drawing, opacity, anti-aliasing and shadows
* Learn more: https://docs.littlevgl.com/#Drawing*/
/* Size of the VDB in pixels. Typical size: ~1/10 screen. Must be >= LV_HOR_RES
* Setting it to 0 will disable VDB and `disp_drv.disp_fill` and `disp_drv.disp_map` functions
* will be called to draw to the frame buffer directly*/
#ifndef LV_VDB_SIZE
#define LV_VDB_SIZE ((LV_VER_RES * LV_HOR_RES) / 10)
#endif
/* Bit-per-pixel of VDB. Useful for monochrome or non-standard color format displays.
* Special formats are handled with `disp_drv.vdb_wr`)*/
#ifndef LV_VDB_PX_BPP
#define LV_VDB_PX_BPP LV_COLOR_SIZE /*LV_COLOR_SIZE comes from LV_COLOR_DEPTH below to set 8, 16 or 32 bit pixel size automatically */
#endif
/* Place VDB to a specific address (e.g. in external RAM)
* 0: allocate automatically into RAM
* LV_VDB_ADR_INV: to replace it later with `lv_vdb_set_adr()`*/
#ifndef LV_VDB_ADR
#define LV_VDB_ADR 0
#endif
/* Use two Virtual Display buffers (VDB) to parallelize rendering and flushing
* The flushing should use DMA to write the frame buffer in the background */
#ifndef LV_VDB_DOUBLE
#define LV_VDB_DOUBLE 0
#endif
/* Place VDB2 to a specific address (e.g. in external RAM)
* 0: allocate automatically into RAM
* LV_VDB_ADR_INV: to replace it later with `lv_vdb_set_adr()`*/
#ifndef LV_VDB2_ADR
#define LV_VDB2_ADR 0
#endif
/* Using true double buffering in `disp_drv.disp_flush` you will always get the image of the whole screen.
* Your only task is to set the rendered image (`color_p` parameter) as frame buffer address or send it to your display.
* The best if you do in the blank period of you display to avoid tearing effect.
* Requires:
* - LV_VDB_SIZE = LV_HOR_RES * LV_VER_RES
* - LV_VDB_DOUBLE = 1
*/
#ifndef LV_VDB_TRUE_DOUBLE_BUFFERED
#define LV_VDB_TRUE_DOUBLE_BUFFERED 0
#endif
/*=================
Misc. setting
*=================*/
/*Input device settings*/
#ifndef LV_INDEV_READ_PERIOD
#define LV_INDEV_READ_PERIOD 50 /*Input device read period in milliseconds*/
#endif
#ifndef LV_INDEV_POINT_MARKER
#define LV_INDEV_POINT_MARKER 0 /*Mark the pressed points (required: USE_LV_REAL_DRAW = 1)*/
#endif
#ifndef LV_INDEV_DRAG_LIMIT
#define LV_INDEV_DRAG_LIMIT 10 /*Drag threshold in pixels */
#endif
#ifndef LV_INDEV_DRAG_THROW
#define LV_INDEV_DRAG_THROW 20 /*Drag throw slow-down in [%]. Greater value means faster slow-down */
#endif
#ifndef LV_INDEV_LONG_PRESS_TIME
#define LV_INDEV_LONG_PRESS_TIME 400 /*Long press time in milliseconds*/
#endif
#ifndef LV_INDEV_LONG_PRESS_REP_TIME
#define LV_INDEV_LONG_PRESS_REP_TIME 100 /*Repeated trigger period in long press [ms] */
#endif
/*Color settings*/
#ifndef LV_COLOR_DEPTH
#define LV_COLOR_DEPTH 16 /*Color depth: 1/8/16/32*/
#endif
#ifndef LV_COLOR_16_SWAP
#define LV_COLOR_16_SWAP 0 /*Swap the 2 bytes of RGB565 color. Useful if the display has a 8 bit interface (e.g. SPI)*/
#endif
#ifndef LV_COLOR_SCREEN_TRANSP
#define LV_COLOR_SCREEN_TRANSP 0 /*1: Enable screen transparency. Useful for OSD or other overlapping GUIs. Requires ARGB8888 colors*/
#endif
#ifndef LV_COLOR_TRANSP
#define LV_COLOR_TRANSP LV_COLOR_LIME /*Images pixels with this color will not be drawn (with chroma keying)*/
#endif
/*Text settings*/
#ifndef LV_TXT_UTF8
#define LV_TXT_UTF8 1 /*Enable UTF-8 coded Unicode character usage */
#endif
#ifndef LV_TXT_BREAK_CHARS
#define LV_TXT_BREAK_CHARS " ,.;:-_" /*Can break texts on these chars*/
#endif
#ifndef LV_TXT_LINE_BREAK_LONG_LEN
#define LV_TXT_LINE_BREAK_LONG_LEN 12 /* If a character is at least this long, will break wherever "prettiest" */
#endif
#ifndef LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN
#define LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN 3 /* Minimum number of characters of a word to put on a line before a break */
#endif
#ifndef LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN
#define LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN 1 /* Minimum number of characters of a word to put on a line after a break */
#endif
/*Feature usage*/
#ifndef USE_LV_ANIMATION
#define USE_LV_ANIMATION 1 /*1: Enable all animations*/
#endif
#ifndef USE_LV_SHADOW
#define USE_LV_SHADOW 1 /*1: Enable shadows*/
#endif
#ifndef USE_LV_GROUP
#define USE_LV_GROUP 1 /*1: Enable object groups (for keyboards)*/
#endif
#ifndef USE_LV_GPU
#define USE_LV_GPU 1 /*1: Enable GPU interface*/
#endif
#ifndef USE_LV_REAL_DRAW
#define USE_LV_REAL_DRAW 1 /*1: Enable function which draw directly to the frame buffer instead of VDB (required if LV_VDB_SIZE = 0)*/
#endif
#ifndef USE_LV_FILESYSTEM
#define USE_LV_FILESYSTEM 1 /*1: Enable file system (might be required for images*/
#endif
#ifndef USE_LV_MULTI_LANG
#define USE_LV_MULTI_LANG 0 /* Number of languages for labels to store (0: to disable this feature)*/
#endif
/*Compiler settings*/
#ifndef LV_ATTRIBUTE_TICK_INC
#define LV_ATTRIBUTE_TICK_INC /* Define a custom attribute to `lv_tick_inc` function */
#endif
#ifndef LV_ATTRIBUTE_TASK_HANDLER
#define LV_ATTRIBUTE_TASK_HANDLER /* Define a custom attribute to `lv_task_handler` function */
#endif
#ifndef LV_ATTRIBUTE_MEM_ALIGN
#define LV_ATTRIBUTE_MEM_ALIGN /* With size optimization (-Os) the compiler might not align data to 4 or 8 byte boundary. This alignment will be explicitly applied where needed.*/
#endif
#ifndef LV_COMPILER_VLA_SUPPORTED
#define LV_COMPILER_VLA_SUPPORTED 1 /* 1: Variable length array is supported*/
#endif
#ifndef LV_COMPILER_NON_CONST_INIT_SUPPORTED
#define LV_COMPILER_NON_CONST_INIT_SUPPORTED 1 /* 1: Initialization with non constant values are supported */
#endif
/*HAL settings*/
#ifndef LV_TICK_CUSTOM
#define LV_TICK_CUSTOM 0 /*1: use a custom tick source (removing the need to manually update the tick with `lv_tick_inc`) */
#endif
#if LV_TICK_CUSTOM == 1
#ifndef LV_TICK_CUSTOM_INCLUDE
#define LV_TICK_CUSTOM_INCLUDE "sonething.h" /*Header for the sys time function*/
#endif
#ifndef LV_TICK_CUSTOM_SYS_TIME_EXPR
#define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current systime in ms*/
#endif
#endif /*LV_TICK_CUSTOM*/
/*Log settings*/
#ifndef USE_LV_LOG
#define USE_LV_LOG 1 /*Enable/disable the log module*/
#endif
#if USE_LV_LOG
/* How important log should be added:
* LV_LOG_LEVEL_TRACE A lot of logs to give detailed information
* LV_LOG_LEVEL_INFO Log important events
* LV_LOG_LEVEL_WARN Log if something unwanted happened but didn't caused problem
* LV_LOG_LEVEL_ERROR Only critical issue, when the system may fail
*/
#ifndef LV_LOG_LEVEL
# define LV_LOG_LEVEL LV_LOG_LEVEL_WARN
#endif
/* 1: Print the log with 'printf'; 0: user need to register a callback*/
#ifndef LV_LOG_PRINTF
# define LV_LOG_PRINTF 0
#endif
#endif /*USE_LV_LOG*/
/*================
* THEME USAGE
*================*/
#ifndef LV_THEME_LIVE_UPDATE
#define LV_THEME_LIVE_UPDATE 1 /*1: Allow theme switching at run time. Uses 8..10 kB of RAM*/
#endif
#ifndef USE_LV_THEME_TEMPL
#define USE_LV_THEME_TEMPL 0 /*Just for test*/
#endif
#ifndef USE_LV_THEME_DEFAULT
#define USE_LV_THEME_DEFAULT 1 /*Built mainly from the built-in styles. Consumes very few RAM*/
#endif
#ifndef USE_LV_THEME_ALIEN
#define USE_LV_THEME_ALIEN 1 /*Dark futuristic theme*/
#endif
#ifndef USE_LV_THEME_NIGHT
#define USE_LV_THEME_NIGHT 1 /*Dark elegant theme*/
#endif
#ifndef USE_LV_THEME_MONO
#define USE_LV_THEME_MONO 1 /*Mono color theme for monochrome displays*/
#endif
#ifndef USE_LV_THEME_MATERIAL
#define USE_LV_THEME_MATERIAL 1 /*Flat theme with bold colors and light shadows*/
#endif
#ifndef USE_LV_THEME_ZEN
#define USE_LV_THEME_ZEN 1 /*Peaceful, mainly light theme */
#endif
#ifndef USE_LV_THEME_NEMO
#define USE_LV_THEME_NEMO 1 /*Water-like theme based on the movie "Finding Nemo"*/
#endif
/*==================
* FONT USAGE
*===================*/
/* More info about fonts: https://docs.littlevgl.com/#Fonts
* To enable a built-in font use 1,2,4 or 8 values
* which will determine the bit-per-pixel. Higher value means smoother fonts */
#ifndef USE_LV_FONT_DEJAVU_10
#define USE_LV_FONT_DEJAVU_10 4
#endif
#ifndef USE_LV_FONT_DEJAVU_10_LATIN_SUP
#define USE_LV_FONT_DEJAVU_10_LATIN_SUP 4
#endif
#ifndef USE_LV_FONT_DEJAVU_10_CYRILLIC
#define USE_LV_FONT_DEJAVU_10_CYRILLIC 4
#endif
#ifndef USE_LV_FONT_SYMBOL_10
#define USE_LV_FONT_SYMBOL_10 4
#endif
#ifndef USE_LV_FONT_DEJAVU_20
#define USE_LV_FONT_DEJAVU_20 4
#endif
#ifndef USE_LV_FONT_DEJAVU_20_LATIN_SUP
#define USE_LV_FONT_DEJAVU_20_LATIN_SUP 4
#endif
#ifndef USE_LV_FONT_DEJAVU_20_CYRILLIC
#define USE_LV_FONT_DEJAVU_20_CYRILLIC 4
#endif
#ifndef USE_LV_FONT_SYMBOL_20
#define USE_LV_FONT_SYMBOL_20 4
#endif
#ifndef USE_LV_FONT_DEJAVU_30
#define USE_LV_FONT_DEJAVU_30 4
#endif
#ifndef USE_LV_FONT_DEJAVU_30_LATIN_SUP
#define USE_LV_FONT_DEJAVU_30_LATIN_SUP 4
#endif
#ifndef USE_LV_FONT_DEJAVU_30_CYRILLIC
#define USE_LV_FONT_DEJAVU_30_CYRILLIC 4
#endif
#ifndef USE_LV_FONT_SYMBOL_30
#define USE_LV_FONT_SYMBOL_30 4
#endif
#ifndef USE_LV_FONT_DEJAVU_40
#define USE_LV_FONT_DEJAVU_40 4
#endif
#ifndef USE_LV_FONT_DEJAVU_40_LATIN_SUP
#define USE_LV_FONT_DEJAVU_40_LATIN_SUP 4
#endif
#ifndef USE_LV_FONT_DEJAVU_40_CYRILLIC
#define USE_LV_FONT_DEJAVU_40_CYRILLIC 4
#endif
#ifndef USE_LV_FONT_SYMBOL_40
#define USE_LV_FONT_SYMBOL_40 4
#endif
#ifndef USE_LV_FONT_MONOSPACE_8
#define USE_LV_FONT_MONOSPACE_8 1
#endif
/* Optionally declare your custom fonts here.
* You can use these fonts as default font too
* and they will be available globally. E.g.
* #define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(my_font_1) \
* LV_FONT_DECLARE(my_font_2) \
*/
#ifndef LV_FONT_CUSTOM_DECLARE
#define LV_FONT_CUSTOM_DECLARE
#endif
#ifndef LV_FONT_DEFAULT
#define LV_FONT_DEFAULT &lv_font_dejavu_20 /*Always set a default font from the built-in fonts*/
#endif
/*===================
* LV_OBJ SETTINGS
*==================*/
#ifndef LV_OBJ_FREE_NUM_TYPE
#define LV_OBJ_FREE_NUM_TYPE uint32_t /*Type of free number attribute (comment out disable free number)*/
#endif
#ifndef LV_OBJ_FREE_PTR
#define LV_OBJ_FREE_PTR 1 /*Enable the free pointer attribute*/
#endif
#ifndef LV_OBJ_REALIGN
#define LV_OBJ_REALIGN 1 /*Enable `lv_obj_realaign()` based on `lv_obj_align()` parameters*/
#endif
/*==================
* LV OBJ X USAGE
*================*/
/*
* Documentation of the object types: https://docs.littlevgl.com/#Object-types
*/
/*****************
* Simple object
*****************/
/*Label (dependencies: -*/
#ifndef USE_LV_LABEL
#define USE_LV_LABEL 1
#endif
#if USE_LV_LABEL != 0
#ifndef LV_LABEL_SCROLL_SPEED
# define LV_LABEL_SCROLL_SPEED 25 /*Hor, or ver. scroll speed [px/sec] in 'LV_LABEL_LONG_SCROLL/ROLL' mode*/
#endif
#endif
/*Image (dependencies: lv_label*/
#ifndef USE_LV_IMG
#define USE_LV_IMG 1
#endif
#if USE_LV_IMG != 0
#ifndef LV_IMG_CF_INDEXED
# define LV_IMG_CF_INDEXED 1 /*Enable indexed (palette) images*/
#endif
#ifndef LV_IMG_CF_ALPHA
# define LV_IMG_CF_ALPHA 1 /*Enable alpha indexed images*/
#endif
#endif
/*Line (dependencies: -*/
#ifndef USE_LV_LINE
#define USE_LV_LINE 1
#endif
/*Arc (dependencies: -)*/
#ifndef USE_LV_ARC
#define USE_LV_ARC 1
#endif
/*******************
* Container objects
*******************/
/*Container (dependencies: -*/
#ifndef USE_LV_CONT
#define USE_LV_CONT 1
#endif
/*Page (dependencies: lv_cont)*/
#ifndef USE_LV_PAGE
#define USE_LV_PAGE 1
#endif
/*Window (dependencies: lv_cont, lv_btn, lv_label, lv_img, lv_page)*/
#ifndef USE_LV_WIN
#define USE_LV_WIN 1
#endif
/*Tab (dependencies: lv_page, lv_btnm)*/
#ifndef USE_LV_TABVIEW
#define USE_LV_TABVIEW 1
#endif
# if USE_LV_TABVIEW != 0
#ifndef LV_TABVIEW_ANIM_TIME
# define LV_TABVIEW_ANIM_TIME 300 /*Time of slide animation [ms] (0: no animation)*/
#endif
#endif
/*Tileview (dependencies: lv_page) */
#ifndef USE_LV_TILEVIEW
#define USE_LV_TILEVIEW 1
#endif
#if USE_LV_TILEVIEW
#ifndef LV_TILEVIEW_ANIM_TIME
# define LV_TILEVIEW_ANIM_TIME 300 /*Time of slide animation [ms] (0: no animation)*/
#endif
#endif
/*************************
* Data visualizer objects
*************************/
/*Bar (dependencies: -)*/
#ifndef USE_LV_BAR
#define USE_LV_BAR 1
#endif
/*Line meter (dependencies: *;)*/
#ifndef USE_LV_LMETER
#define USE_LV_LMETER 1
#endif
/*Gauge (dependencies:lv_bar, lv_lmeter)*/
#ifndef USE_LV_GAUGE
#define USE_LV_GAUGE 1
#endif
/*Chart (dependencies: -)*/
#ifndef USE_LV_CHART
#define USE_LV_CHART 1
#endif
/*Table (dependencies: lv_label)*/
#ifndef USE_LV_TABLE
#define USE_LV_TABLE 1
#endif
#if USE_LV_TABLE
#ifndef LV_TABLE_COL_MAX
# define LV_TABLE_COL_MAX 12
#endif
#endif
/*LED (dependencies: -)*/
#ifndef USE_LV_LED
#define USE_LV_LED 1
#endif
/*Message box (dependencies: lv_rect, lv_btnm, lv_label)*/
#ifndef USE_LV_MBOX
#define USE_LV_MBOX 1
#endif
/*Text area (dependencies: lv_label, lv_page)*/
#ifndef USE_LV_TA
#define USE_LV_TA 1
#endif
#if USE_LV_TA != 0
#ifndef LV_TA_CURSOR_BLINK_TIME
# define LV_TA_CURSOR_BLINK_TIME 400 /*ms*/
#endif
#ifndef LV_TA_PWD_SHOW_TIME
# define LV_TA_PWD_SHOW_TIME 1500 /*ms*/
#endif
#endif
/*Spinbox (dependencies: lv_ta)*/
#ifndef USE_LV_SPINBOX
#define USE_LV_SPINBOX 1
#endif
/*Calendar (dependencies: -)*/
#ifndef USE_LV_CALENDAR
#define USE_LV_CALENDAR 1
#endif
/*Preload (dependencies: lv_arc)*/
#ifndef USE_LV_PRELOAD
#define USE_LV_PRELOAD 1
#endif
#if USE_LV_PRELOAD != 0
#ifndef LV_PRELOAD_DEF_ARC_LENGTH
# define LV_PRELOAD_DEF_ARC_LENGTH 60 /*[deg]*/
#endif
#ifndef LV_PRELOAD_DEF_SPIN_TIME
# define LV_PRELOAD_DEF_SPIN_TIME 1000 /*[ms]*/
#endif
#ifndef LV_PRELOAD_DEF_ANIM
# define LV_PRELOAD_DEF_ANIM LV_PRELOAD_TYPE_SPINNING_ARC
#endif
#endif
/*Canvas (dependencies: lv_img)*/
#ifndef USE_LV_CANVAS
#define USE_LV_CANVAS 1
#endif
/*************************
* User input objects
*************************/
/*Button (dependencies: lv_cont*/
#ifndef USE_LV_BTN
#define USE_LV_BTN 1
#endif
#if USE_LV_BTN != 0
#ifndef LV_BTN_INK_EFFECT
# define LV_BTN_INK_EFFECT 1 /*Enable button-state animations - draw a circle on click (dependencies: USE_LV_ANIMATION)*/
#endif
#endif
/*Image Button (dependencies: lv_btn*/
#ifndef USE_LV_IMGBTN
#define USE_LV_IMGBTN 1
#endif
#if USE_LV_IMGBTN
#ifndef LV_IMGBTN_TILED
# define LV_IMGBTN_TILED 0 /*1: The imgbtn requires left, mid and right parts and the width can be set freely*/
#endif
#endif
/*Button matrix (dependencies: -)*/
#ifndef USE_LV_BTNM
#define USE_LV_BTNM 1
#endif
/*Keyboard (dependencies: lv_btnm)*/
#ifndef USE_LV_KB
#define USE_LV_KB 1
#endif
/*Check box (dependencies: lv_btn, lv_label)*/
#ifndef USE_LV_CB
#define USE_LV_CB 1
#endif
/*List (dependencies: lv_page, lv_btn, lv_label, (lv_img optionally for icons ))*/
#ifndef USE_LV_LIST
#define USE_LV_LIST 1
#endif
#if USE_LV_LIST != 0
#ifndef LV_LIST_FOCUS_TIME
# define LV_LIST_FOCUS_TIME 100 /*Default animation time of focusing to a list element [ms] (0: no animation) */
#endif
#endif
/*Drop down list (dependencies: lv_page, lv_label, lv_symbol_def.h)*/
#ifndef USE_LV_DDLIST
#define USE_LV_DDLIST 1
#endif
#if USE_LV_DDLIST != 0
#ifndef LV_DDLIST_ANIM_TIME
# define LV_DDLIST_ANIM_TIME 200 /*Open and close default animation time [ms] (0: no animation)*/
#endif
#endif
/*Roller (dependencies: lv_ddlist)*/
#ifndef USE_LV_ROLLER
#define USE_LV_ROLLER 1
#endif
#if USE_LV_ROLLER != 0
#ifndef LV_ROLLER_ANIM_TIME
# define LV_ROLLER_ANIM_TIME 200 /*Focus animation time [ms] (0: no animation)*/
#endif
#endif
/*Slider (dependencies: lv_bar)*/
#ifndef USE_LV_SLIDER
#define USE_LV_SLIDER 1
#endif
/*Switch (dependencies: lv_slider)*/
#ifndef USE_LV_SW
#define USE_LV_SW 1
#endif
/*************************
* Non-user section
*************************/
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) /* Disable warnings for Visual Studio*/
#ifndef _CRT_SECURE_NO_WARNINGS
# define _CRT_SECURE_NO_WARNINGS
#endif
#endif
#endif /*LV_CONF_CHECKER_H*/

View File

@ -1,403 +0,0 @@
/**
* @file lv_conf.h
*
*/
/*
* COPY THIS FILE AS lv_conf.h
*/
#if 0 /*Set it to "1" to enable content*/
#ifndef LV_CONF_H
#define LV_CONF_H
/*===================
Dynamic memory
*===================*/
/* Memory size which will be used by the library
* to store the graphical objects and other data */
#define LV_MEM_CUSTOM 0 /*1: use custom malloc/free, 0: use the built-in lv_mem_alloc/lv_mem_free*/
#if LV_MEM_CUSTOM == 0
# define LV_MEM_SIZE (64U * 1024U) /*Size memory used by `lv_mem_alloc` in bytes (>= 2kB)*/
# define LV_MEM_ATTR /*Complier prefix for big array declaration*/
# define LV_MEM_ADR 0 /*Set an address for memory pool instead of allocation it as an array. Can be in external SRAM too.*/
# define LV_MEM_AUTO_DEFRAG 1 /*Automatically defrag on free*/
#else /*LV_MEM_CUSTOM*/
# define LV_MEM_CUSTOM_INCLUDE <stdlib.h> /*Header for the dynamic memory function*/
# define LV_MEM_CUSTOM_ALLOC malloc /*Wrapper to malloc*/
# define LV_MEM_CUSTOM_FREE free /*Wrapper to free*/
#endif /*LV_MEM_CUSTOM*/
/* Garbage Collector settings
* Used if lvgl is binded to higher language and the memory is managed by that language */
#define LV_ENABLE_GC 0
#if LV_ENABLE_GC != 0
# define LV_MEM_CUSTOM_REALLOC your_realloc /*Wrapper to realloc*/
# define LV_MEM_CUSTOM_GET_SIZE your_mem_get_size /*Wrapper to lv_mem_get_size*/
# define LV_GC_INCLUDE "gc.h" /*Include Garbage Collector related things*/
#endif /* LV_ENABLE_GC */
/*===================
Graphical settings
*===================*/
/* Horizontal and vertical resolution of the library.*/
#define LV_HOR_RES (480)
#define LV_VER_RES (320)
/* Dot Per Inch: used to initialize default sizes. E.g. a button with width = LV_DPI / 2 -> half inch wide
* (Not so important, you can adjust it to modify default sizes and spaces)*/
#define LV_DPI 100
/* Enable anti-aliasing (lines, and radiuses will be smoothed) */
#define LV_ANTIALIAS 1 /*1: Enable anti-aliasing*/
/*Screen refresh period in milliseconds*/
#define LV_REFR_PERIOD 30
/*-----------------
* VDB settings
*----------------*/
/* VDB (Virtual Display Buffer) is an internal graphics buffer.
* The GUI will be drawn into this buffer first and then
* the buffer will be passed to your `disp_drv.disp_flush` function to
* copy it to your frame buffer.
* VDB is required for: buffered drawing, opacity, anti-aliasing and shadows
* Learn more: https://docs.littlevgl.com/#Drawing*/
/* Size of the VDB in pixels. Typical size: ~1/10 screen. Must be >= LV_HOR_RES
* Setting it to 0 will disable VDB and `disp_drv.disp_fill` and `disp_drv.disp_map` functions
* will be called to draw to the frame buffer directly*/
#define LV_VDB_SIZE ((LV_VER_RES * LV_HOR_RES) / 10)
/* Bit-per-pixel of VDB. Useful for monochrome or non-standard color format displays.
* Special formats are handled with `disp_drv.vdb_wr`)*/
#define LV_VDB_PX_BPP LV_COLOR_SIZE /*LV_COLOR_SIZE comes from LV_COLOR_DEPTH below to set 8, 16 or 32 bit pixel size automatically */
/* Place VDB to a specific address (e.g. in external RAM)
* 0: allocate automatically into RAM
* LV_VDB_ADR_INV: to replace it later with `lv_vdb_set_adr()`*/
#define LV_VDB_ADR 0
/* Use two Virtual Display buffers (VDB) to parallelize rendering and flushing
* The flushing should use DMA to write the frame buffer in the background */
#define LV_VDB_DOUBLE 0
/* Place VDB2 to a specific address (e.g. in external RAM)
* 0: allocate automatically into RAM
* LV_VDB_ADR_INV: to replace it later with `lv_vdb_set_adr()`*/
#define LV_VDB2_ADR 0
/* Using true double buffering in `disp_drv.disp_flush` you will always get the image of the whole screen.
* Your only task is to set the rendered image (`color_p` parameter) as frame buffer address or send it to your display.
* The best if you do in the blank period of you display to avoid tearing effect.
* Requires:
* - LV_VDB_SIZE = LV_HOR_RES * LV_VER_RES
* - LV_VDB_DOUBLE = 1
*/
#define LV_VDB_TRUE_DOUBLE_BUFFERED 0
/*=================
Misc. setting
*=================*/
/*Input device settings*/
#define LV_INDEV_READ_PERIOD 50 /*Input device read period in milliseconds*/
#define LV_INDEV_POINT_MARKER 0 /*Mark the pressed points (required: USE_LV_REAL_DRAW = 1)*/
#define LV_INDEV_DRAG_LIMIT 10 /*Drag threshold in pixels */
#define LV_INDEV_DRAG_THROW 20 /*Drag throw slow-down in [%] (must be > 0). Greater value means faster slow-down */
#define LV_INDEV_LONG_PRESS_TIME 400 /*Long press time in milliseconds*/
#define LV_INDEV_LONG_PRESS_REP_TIME 100 /*Repeated trigger period in long press [ms] */
/*Color settings*/
#define LV_COLOR_DEPTH 16 /*Color depth: 1/8/16/32*/
#define LV_COLOR_16_SWAP 0 /*Swap the 2 bytes of RGB565 color. Useful if the display has a 8 bit interface (e.g. SPI)*/
#define LV_COLOR_SCREEN_TRANSP 0 /*1: Enable screen transparency. Useful for OSD or other overlapping GUIs. Requires ARGB8888 colors*/
#define LV_COLOR_TRANSP LV_COLOR_LIME /*Images pixels with this color will not be drawn (with chroma keying)*/
/*Text settings*/
#define LV_TXT_UTF8 1 /*Enable UTF-8 coded Unicode character usage */
#define LV_TXT_BREAK_CHARS " ,.;:-_" /*Can break texts on these chars*/
#define LV_TXT_LINE_BREAK_LONG_LEN 12 /* If a character is at least this long, will break wherever "prettiest" */
#define LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN 3 /* Minimum number of characters of a word to put on a line before a break */
#define LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN 1 /* Minimum number of characters of a word to put on a line after a break */
/*Feature usage*/
#define USE_LV_ANIMATION 1 /*1: Enable all animations*/
#define USE_LV_SHADOW 1 /*1: Enable shadows*/
#define USE_LV_GROUP 1 /*1: Enable object groups (for keyboards)*/
#define USE_LV_GPU 1 /*1: Enable GPU interface*/
#define USE_LV_REAL_DRAW 1 /*1: Enable function which draw directly to the frame buffer instead of VDB (required if LV_VDB_SIZE = 0)*/
#define USE_LV_FILESYSTEM 1 /*1: Enable file system (might be required for images*/
#define USE_LV_MULTI_LANG 0 /* Number of languages for labels to store (0: to disable this feature)*/
/*Compiler settings*/
#define LV_ATTRIBUTE_TICK_INC /* Define a custom attribute to `lv_tick_inc` function */
#define LV_ATTRIBUTE_TASK_HANDLER /* Define a custom attribute to `lv_task_handler` function */
#define LV_ATTRIBUTE_MEM_ALIGN /* With size optimization (-Os) the compiler might not align data to 4 or 8 byte boundary. This alignment will be explicitly applied where needed.*/
#define LV_COMPILER_VLA_SUPPORTED 1 /* 1: Variable length array is supported*/
#define LV_COMPILER_NON_CONST_INIT_SUPPORTED 1 /* 1: Initialization with non constant values are supported */
/*HAL settings*/
#define LV_TICK_CUSTOM 0 /*1: use a custom tick source (removing the need to manually update the tick with `lv_tick_inc`) */
#if LV_TICK_CUSTOM == 1
#define LV_TICK_CUSTOM_INCLUDE "something.h" /*Header for the sys time function*/
#define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current systime in ms*/
#endif /*LV_TICK_CUSTOM*/
/*Log settings*/
#define USE_LV_LOG 1 /*Enable/disable the log module*/
#if USE_LV_LOG
/* How important log should be added:
* LV_LOG_LEVEL_TRACE A lot of logs to give detailed information
* LV_LOG_LEVEL_INFO Log important events
* LV_LOG_LEVEL_WARN Log if something unwanted happened but didn't caused problem
* LV_LOG_LEVEL_ERROR Only critical issue, when the system may fail
*/
# define LV_LOG_LEVEL LV_LOG_LEVEL_WARN
/* 1: Print the log with 'printf'; 0: user need to register a callback*/
# define LV_LOG_PRINTF 0
#endif /*USE_LV_LOG*/
/*================
* THEME USAGE
*================*/
#define LV_THEME_LIVE_UPDATE 1 /*1: Allow theme switching at run time. Uses 8..10 kB of RAM*/
#define USE_LV_THEME_TEMPL 0 /*Just for test*/
#define USE_LV_THEME_DEFAULT 1 /*Built mainly from the built-in styles. Consumes very few RAM*/
#define USE_LV_THEME_ALIEN 1 /*Dark futuristic theme*/
#define USE_LV_THEME_NIGHT 1 /*Dark elegant theme*/
#define USE_LV_THEME_MONO 1 /*Mono color theme for monochrome displays*/
#define USE_LV_THEME_MATERIAL 1 /*Flat theme with bold colors and light shadows*/
#define USE_LV_THEME_ZEN 1 /*Peaceful, mainly light theme */
#define USE_LV_THEME_NEMO 1 /*Water-like theme based on the movie "Finding Nemo"*/
/*==================
* FONT USAGE
*===================*/
/* More info about fonts: https://docs.littlevgl.com/#Fonts
* To enable a built-in font use 1,2,4 or 8 values
* which will determine the bit-per-pixel. Higher value means smoother fonts */
#define USE_LV_FONT_DEJAVU_10 4
#define USE_LV_FONT_DEJAVU_10_LATIN_SUP 4
#define USE_LV_FONT_DEJAVU_10_CYRILLIC 4
#define USE_LV_FONT_SYMBOL_10 4
#define USE_LV_FONT_DEJAVU_20 4
#define USE_LV_FONT_DEJAVU_20_LATIN_SUP 4
#define USE_LV_FONT_DEJAVU_20_CYRILLIC 4
#define USE_LV_FONT_SYMBOL_20 4
#define USE_LV_FONT_DEJAVU_30 4
#define USE_LV_FONT_DEJAVU_30_LATIN_SUP 4
#define USE_LV_FONT_DEJAVU_30_CYRILLIC 4
#define USE_LV_FONT_SYMBOL_30 4
#define USE_LV_FONT_DEJAVU_40 4
#define USE_LV_FONT_DEJAVU_40_LATIN_SUP 4
#define USE_LV_FONT_DEJAVU_40_CYRILLIC 4
#define USE_LV_FONT_SYMBOL_40 4
#define USE_LV_FONT_MONOSPACE_8 1
/* Optionally declare your custom fonts here.
* You can use these fonts as default font too
* and they will be available globally. E.g.
* #define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(my_font_1) \
* LV_FONT_DECLARE(my_font_2) \
*/
#define LV_FONT_CUSTOM_DECLARE
#define LV_FONT_DEFAULT &lv_font_dejavu_20 /*Always set a default font from the built-in fonts*/
/*===================
* LV_OBJ SETTINGS
*==================*/
#define LV_OBJ_FREE_NUM_TYPE uint32_t /*Type of free number attribute (comment out disable free number)*/
#define LV_OBJ_FREE_PTR 1 /*Enable the free pointer attribute*/
#define LV_OBJ_REALIGN 1 /*Enable `lv_obj_realaign()` based on `lv_obj_align()` parameters*/
/*==================
* LV OBJ X USAGE
*================*/
/*
* Documentation of the object types: https://docs.littlevgl.com/#Object-types
*/
/*****************
* Simple object
*****************/
/*Label (dependencies: -*/
#define USE_LV_LABEL 1
#if USE_LV_LABEL != 0
# define LV_LABEL_SCROLL_SPEED 25 /*Hor, or ver. scroll speed [px/sec] in 'LV_LABEL_LONG_SCROLL/ROLL' mode*/
#endif
/*Image (dependencies: lv_label*/
#define USE_LV_IMG 1
#if USE_LV_IMG != 0
# define LV_IMG_CF_INDEXED 1 /*Enable indexed (palette) images*/
# define LV_IMG_CF_ALPHA 1 /*Enable alpha indexed images*/
#endif
/*Line (dependencies: -*/
#define USE_LV_LINE 1
/*Arc (dependencies: -)*/
#define USE_LV_ARC 1
/*******************
* Container objects
*******************/
/*Container (dependencies: -*/
#define USE_LV_CONT 1
/*Page (dependencies: lv_cont)*/
#define USE_LV_PAGE 1
/*Window (dependencies: lv_cont, lv_btn, lv_label, lv_img, lv_page)*/
#define USE_LV_WIN 1
/*Tab (dependencies: lv_page, lv_btnm)*/
#define USE_LV_TABVIEW 1
# if USE_LV_TABVIEW != 0
# define LV_TABVIEW_ANIM_TIME 300 /*Time of slide animation [ms] (0: no animation)*/
#endif
/*Tileview (dependencies: lv_page) */
#define USE_LV_TILEVIEW 1
#if USE_LV_TILEVIEW
# define LV_TILEVIEW_ANIM_TIME 300 /*Time of slide animation [ms] (0: no animation)*/
#endif
/*************************
* Data visualizer objects
*************************/
/*Bar (dependencies: -)*/
#define USE_LV_BAR 1
/*Line meter (dependencies: *;)*/
#define USE_LV_LMETER 1
/*Gauge (dependencies:lv_bar, lv_lmeter)*/
#define USE_LV_GAUGE 1
/*Chart (dependencies: -)*/
#define USE_LV_CHART 1
/*Table (dependencies: lv_label)*/
#define USE_LV_TABLE 1
#if USE_LV_TABLE
# define LV_TABLE_COL_MAX 12
#endif
/*LED (dependencies: -)*/
#define USE_LV_LED 1
/*Message box (dependencies: lv_rect, lv_btnm, lv_label)*/
#define USE_LV_MBOX 1
/*Text area (dependencies: lv_label, lv_page)*/
#define USE_LV_TA 1
#if USE_LV_TA != 0
# define LV_TA_CURSOR_BLINK_TIME 400 /*ms*/
# define LV_TA_PWD_SHOW_TIME 1500 /*ms*/
#endif
/*Spinbox (dependencies: lv_ta)*/
#define USE_LV_SPINBOX 1
/*Calendar (dependencies: -)*/
#define USE_LV_CALENDAR 1
/*Preload (dependencies: lv_arc)*/
#define USE_LV_PRELOAD 1
#if USE_LV_PRELOAD != 0
# define LV_PRELOAD_DEF_ARC_LENGTH 60 /*[deg]*/
# define LV_PRELOAD_DEF_SPIN_TIME 1000 /*[ms]*/
# define LV_PRELOAD_DEF_ANIM LV_PRELOAD_TYPE_SPINNING_ARC
#endif
/*Canvas (dependencies: lv_img)*/
#define USE_LV_CANVAS 1
/*************************
* User input objects
*************************/
/*Button (dependencies: lv_cont*/
#define USE_LV_BTN 1
#if USE_LV_BTN != 0
# define LV_BTN_INK_EFFECT 1 /*Enable button-state animations - draw a circle on click (dependencies: USE_LV_ANIMATION)*/
#endif
/*Image Button (dependencies: lv_btn*/
#define USE_LV_IMGBTN 1
#if USE_LV_IMGBTN
# define LV_IMGBTN_TILED 0 /*1: The imgbtn requires left, mid and right parts and the width can be set freely*/
#endif
/*Button matrix (dependencies: -)*/
#define USE_LV_BTNM 1
/*Keyboard (dependencies: lv_btnm)*/
#define USE_LV_KB 1
/*Check box (dependencies: lv_btn, lv_label)*/
#define USE_LV_CB 1
/*List (dependencies: lv_page, lv_btn, lv_label, (lv_img optionally for icons ))*/
#define USE_LV_LIST 1
#if USE_LV_LIST != 0
# define LV_LIST_FOCUS_TIME 100 /*Default animation time of focusing to a list element [ms] (0: no animation) */
#endif
/*Drop down list (dependencies: lv_page, lv_label, lv_symbol_def.h)*/
#define USE_LV_DDLIST 1
#if USE_LV_DDLIST != 0
# define LV_DDLIST_ANIM_TIME 200 /*Open and close default animation time [ms] (0: no animation)*/
#endif
/*Roller (dependencies: lv_ddlist)*/
#define USE_LV_ROLLER 1
#if USE_LV_ROLLER != 0
# define LV_ROLLER_ANIM_TIME 200 /*Focus animation time [ms] (0: no animation)*/
#endif
/*Slider (dependencies: lv_bar)*/
#define USE_LV_SLIDER 1
/*Switch (dependencies: lv_slider)*/
#define USE_LV_SW 1
/*************************
* Non-user section
*************************/
#if LV_INDEV_DRAG_THROW <= 0
#warning "LV_INDEV_DRAG_THROW must be greater than 0"
#undef LV_INDEV_DRAG_THROW
#define LV_INDEV_DRAG_THROW 1
#endif
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) /* Disable warnings for Visual Studio*/
# define _CRT_SECURE_NO_WARNINGS
#endif
/*--END OF LV_CONF_H--*/
/*Be sure every define has a default value*/
#include "lvgl/lv_conf_checker.h"
#endif /*LV_CONF_H*/
#endif /*End of "Content enable"*/

489
lv_conf_template.h Normal file
View File

@ -0,0 +1,489 @@
/**
* @file lv_conf.h
*
*/
/*
* COPY THIS FILE AS `lv_conf.h` NEXT TO the `lvgl` FOLDER
*/
#if 0 /*Set it to "1" to enable content*/
#ifndef LV_CONF_H
#define LV_CONF_H
/* clang-format off */
#include <stdint.h>
/*====================
Graphical settings
*====================*/
/* Maximal horizontal and vertical resolution to support by the library.*/
#define LV_HOR_RES_MAX (480)
#define LV_VER_RES_MAX (320)
/* Color depth:
* - 1: 1 byte per pixel
* - 8: RGB233
* - 16: RGB565
* - 32: ARGB8888
*/
#define LV_COLOR_DEPTH 16
/* Swap the 2 bytes of RGB565 color.
* Useful if the display has a 8 bit interface (e.g. SPI)*/
#define LV_COLOR_16_SWAP 0
/* 1: Enable screen transparency.
* Useful for OSD or other overlapping GUIs.
* Requires `LV_COLOR_DEPTH = 32` colors and the screen's style should be modified: `style.body.opa = ...`*/
#define LV_COLOR_SCREEN_TRANSP 0
/*Images pixels with this color will not be drawn (with chroma keying)*/
#define LV_COLOR_TRANSP LV_COLOR_LIME /*LV_COLOR_LIME: pure green*/
/* Enable anti-aliasing (lines, and radiuses will be smoothed) */
#define LV_ANTIALIAS 1
/* Default display refresh period.
* Can be changed in the display driver (`lv_disp_drv_t`).*/
#define LV_DISP_DEF_REFR_PERIOD 30 /*[ms]*/
/* Dot Per Inch: used to initialize default sizes.
* E.g. a button with width = LV_DPI / 2 -> half inch wide
* (Not so important, you can adjust it to modify default sizes and spaces)*/
#define LV_DPI 100 /*[px]*/
/* Type of coordinates. Should be `int16_t` (or `int32_t` for extreme cases) */
typedef int16_t lv_coord_t;
/*=========================
Memory manager settings
*=========================*/
/* LittelvGL's internal memory manager's settings.
* The graphical objects and other related data are stored here. */
/* 1: use custom malloc/free, 0: use the built-in `lv_mem_alloc` and `lv_mem_free` */
#define LV_MEM_CUSTOM 0
#if LV_MEM_CUSTOM == 0
/* Size of the memory used by `lv_mem_alloc` in bytes (>= 2kB)*/
# define LV_MEM_SIZE (32U * 1024U)
/* Complier prefix for a big array declaration */
# define LV_MEM_ATTR
/* Set an address for the memory pool instead of allocating it as an array.
* Can be in external SRAM too. */
# define LV_MEM_ADR 0
/* Automatically defrag. on free. Defrag. means joining the adjacent free cells. */
# define LV_MEM_AUTO_DEFRAG 1
#else /*LV_MEM_CUSTOM*/
# define LV_MEM_CUSTOM_INCLUDE <stdlib.h> /*Header for the dynamic memory function*/
# define LV_MEM_CUSTOM_ALLOC malloc /*Wrapper to malloc*/
# define LV_MEM_CUSTOM_FREE free /*Wrapper to free*/
#endif /*LV_MEM_CUSTOM*/
/* Garbage Collector settings
* Used if lvgl is binded to higher level language and the memory is managed by that language */
#define LV_ENABLE_GC 0
#if LV_ENABLE_GC != 0
# define LV_GC_INCLUDE "gc.h" /*Include Garbage Collector related things*/
# define LV_MEM_CUSTOM_REALLOC your_realloc /*Wrapper to realloc*/
# define LV_MEM_CUSTOM_GET_SIZE your_mem_get_size /*Wrapper to lv_mem_get_size*/
#endif /* LV_ENABLE_GC */
/*=======================
Input device settings
*=======================*/
/* Input device default settings.
* Can be changed in the Input device driver (`lv_indev_drv_t`)*/
/* Input device read period in milliseconds */
#define LV_INDEV_DEF_READ_PERIOD 30
/* Drag threshold in pixels */
#define LV_INDEV_DEF_DRAG_LIMIT 10
/* Drag throw slow-down in [%]. Greater value -> faster slow-down */
#define LV_INDEV_DEF_DRAG_THROW 20
/* Long press time in milliseconds.
* Time to send `LV_EVENT_LONG_PRESSSED`) */
#define LV_INDEV_DEF_LONG_PRESS_TIME 400
/* Repeated trigger period in long press [ms]
* Time between `LV_EVENT_LONG_PRESSED_REPEAT */
#define LV_INDEV_DEF_LONG_PRESS_REP_TIME 100
/*==================
* Feature usage
*==================*/
/*1: Enable the Animations */
#define LV_USE_ANIMATION 1
#if LV_USE_ANIMATION
/*Declare the type of the user data of animations (can be e.g. `void *`, `int`, `struct`)*/
typedef void * lv_anim_user_data_t;
#endif
/* 1: Enable shadow drawing*/
#define LV_USE_SHADOW 1
/* 1: Enable object groups (for keyboard/encoder navigation) */
#define LV_USE_GROUP 1
#if LV_USE_GROUP
typedef void * lv_group_user_data_t;
#endif /*LV_USE_GROUP*/
/* 1: Enable GPU interface*/
#define LV_USE_GPU 1
/* 1: Enable file system (might be required for images */
#define LV_USE_FILESYSTEM 1
#if LV_USE_FILESYSTEM
/*Declare the type of the user data of file system drivers (can be e.g. `void *`, `int`, `struct`)*/
typedef void * lv_fs_drv_user_data_t;
#endif
/*1: Add a `user_data` to drivers and objects*/
#define LV_USE_USER_DATA 1
/*========================
* Image decoder and cache
*========================*/
/* 1: Enable indexed (palette) images */
#define LV_IMG_CF_INDEXED 1
/* 1: Enable alpha indexed images */
#define LV_IMG_CF_ALPHA 1
/* Default image cache size. Image caching keeps the images opened.
* If only the built-in image formats are used there is no real advantage of caching.
* (I.e. no new image decoder is added)
* With complex image decoders (e.g. PNG or JPG) caching can save the continuous open/decode of images.
* However the opened images might consume additional RAM.
* LV_IMG_CACHE_DEF_SIZE must be >= 1 */
#define LV_IMG_CACHE_DEF_SIZE 1
/*Declare the type of the user data of image decoder (can be e.g. `void *`, `int`, `struct`)*/
typedef void * lv_img_decoder_user_data_t;
/*=====================
* Compiler settings
*====================*/
/* Define a custom attribute to `lv_tick_inc` function */
#define LV_ATTRIBUTE_TICK_INC
/* Define a custom attribute to `lv_task_handler` function */
#define LV_ATTRIBUTE_TASK_HANDLER
/* With size optimization (-Os) the compiler might not align data to
* 4 or 8 byte boundary. This alignment will be explicitly applied where needed.
* E.g. __attribute__((aligned(4))) */
#define LV_ATTRIBUTE_MEM_ALIGN
/* Attribute to mark large constant arrays for example
* font's bitmaps */
#define LV_ATTRIBUTE_LARGE_CONST
/*===================
* HAL settings
*==================*/
/* 1: use a custom tick source.
* It removes the need to manually update the tick with `lv_tick_inc`) */
#define LV_TICK_CUSTOM 0
#if LV_TICK_CUSTOM == 1
#define LV_TICK_CUSTOM_INCLUDE "something.h" /*Header for the sys time function*/
#define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current systime in ms*/
#endif /*LV_TICK_CUSTOM*/
typedef void * lv_disp_drv_user_data_t; /*Type of user data in the display driver*/
typedef void * lv_indev_drv_user_data_t; /*Type of user data in the input device driver*/
/*================
* Log settings
*===============*/
/*1: Enable the log module*/
#define LV_USE_LOG 1
#if LV_USE_LOG
/* How important log should be added:
* LV_LOG_LEVEL_TRACE A lot of logs to give detailed information
* LV_LOG_LEVEL_INFO Log important events
* LV_LOG_LEVEL_WARN Log if something unwanted happened but didn't cause a problem
* LV_LOG_LEVEL_ERROR Only critical issue, when the system may fail
*/
# define LV_LOG_LEVEL LV_LOG_LEVEL_WARN
/* 1: Print the log with 'printf';
* 0: user need to register a callback with `lv_log_register_print`*/
# define LV_LOG_PRINTF 0
#endif /*LV_USE_LOG*/
/*================
* THEME USAGE
*================*/
#define LV_THEME_LIVE_UPDATE 0 /*1: Allow theme switching at run time. Uses 8..10 kB of RAM*/
#define LV_USE_THEME_TEMPL 1 /*Just for test*/
#define LV_USE_THEME_DEFAULT 1 /*Built mainly from the built-in styles. Consumes very few RAM*/
#define LV_USE_THEME_ALIEN 1 /*Dark futuristic theme*/
#define LV_USE_THEME_NIGHT 1 /*Dark elegant theme*/
#define LV_USE_THEME_MONO 1 /*Mono color theme for monochrome displays*/
#define LV_USE_THEME_MATERIAL 1 /*Flat theme with bold colors and light shadows*/
#define LV_USE_THEME_ZEN 1 /*Peaceful, mainly light theme */
#define LV_USE_THEME_NEMO 1 /*Water-like theme based on the movie "Finding Nemo"*/
/*==================
* FONT USAGE
*===================*/
/* The built-in fonts contains the ASCII range and some Symbols with 4 bit-per-pixel.
* The symbols are available via `LV_SYMBOL_...` defines
* More info about fonts: https://docs.littlevgl.com/#Fonts
* To create a new font go to: https://littlevgl.com/ttf-font-to-c-array
*/
/* Robot fonts with bpp = 4
* https://fonts.google.com/specimen/Roboto */
#define LV_FONT_ROBOTO_12 0
#define LV_FONT_ROBOTO_16 1
#define LV_FONT_ROBOTO_22 0
#define LV_FONT_ROBOTO_28 0
/*Pixel perfect monospace font
* http://pelulamu.net/unscii/ */
#define LV_FONT_UNSCII_8 0
/* Optionally declare your custom fonts here.
* You can use these fonts as default font too
* and they will be available globally. E.g.
* #define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(my_font_1) \
* LV_FONT_DECLARE(my_font_2)
*/
#define LV_FONT_CUSTOM_DECLARE
/*Always set a default font from the built-in fonts*/
#define LV_FONT_DEFAULT &lv_font_roboto_16
/*Declare the type of the user data of fonts (can be e.g. `void *`, `int`, `struct`)*/
typedef void * lv_font_user_data_t;
/*=================
* Text settings
*=================*/
/* Select a character encoding for strings.
* Your IDE or editor should have the same character encoding
* - LV_TXT_ENC_UTF8
* - LV_TXT_ENC_ASCII
* */
#define LV_TXT_ENC LV_TXT_ENC_UTF8
/*Can break (wrap) texts on these chars*/
#define LV_TXT_BREAK_CHARS " ,.;:-_"
/*===================
* LV_OBJ SETTINGS
*==================*/
/*Declare the type of the user data of object (can be e.g. `void *`, `int`, `struct`)*/
typedef void * lv_obj_user_data_t;
/*1: enable `lv_obj_realaign()` based on `lv_obj_align()` parameters*/
#define LV_USE_OBJ_REALIGN 1
/* Enable to make the object clickable on a larger area.
* LV_EXT_CLICK_AREA_OFF or 0: Disable this feature
* LV_EXT_CLICK_AREA_TINY: The extra area can be adjusted horizontally and vertically (0..255 px)
* LV_EXT_CLICK_AREA_FULL: The extra area can be adjusted in all 4 directions (-32k..+32k px)
*/
#define LV_USE_EXT_CLICK_AREA LV_EXT_CLICK_AREA_OFF
/*==================
* LV OBJ X USAGE
*================*/
/*
* Documentation of the object types: https://docs.littlevgl.com/#Object-types
*/
/*Arc (dependencies: -)*/
#define LV_USE_ARC 1
/*Bar (dependencies: -)*/
#define LV_USE_BAR 1
/*Button (dependencies: lv_cont*/
#define LV_USE_BTN 1
#if LV_USE_BTN != 0
/*Enable button-state animations - draw a circle on click (dependencies: LV_USE_ANIMATION)*/
# define LV_BTN_INK_EFFECT 1
#endif
/*Button matrix (dependencies: -)*/
#define LV_USE_BTNM 1
/*Calendar (dependencies: -)*/
#define LV_USE_CALENDAR 1
/*Canvas (dependencies: lv_img)*/
#define LV_USE_CANVAS 1
/*Check box (dependencies: lv_btn, lv_label)*/
#define LV_USE_CB 1
/*Chart (dependencies: -)*/
#define LV_USE_CHART 1
#if LV_USE_CHART
# define LV_CHART_AXIS_TICK_LABEL_MAX_LEN 20
#endif
/*Container (dependencies: -*/
#define LV_USE_CONT 1
/*Drop down list (dependencies: lv_page, lv_label, lv_symbol_def.h)*/
#define LV_USE_DDLIST 1
#if LV_USE_DDLIST != 0
/*Open and close default animation time [ms] (0: no animation)*/
# define LV_DDLIST_DEF_ANIM_TIME 200
#endif
/*Gauge (dependencies:lv_bar, lv_lmeter)*/
#define LV_USE_GAUGE 1
/*Image (dependencies: lv_label*/
#define LV_USE_IMG 1
/*Image Button (dependencies: lv_btn*/
#define LV_USE_IMGBTN 1
#if LV_USE_IMGBTN
/*1: The imgbtn requires left, mid and right parts and the width can be set freely*/
# define LV_IMGBTN_TILED 0
#endif
/*Keyboard (dependencies: lv_btnm)*/
#define LV_USE_KB 1
/*Label (dependencies: -*/
#define LV_USE_LABEL 1
#if LV_USE_LABEL != 0
/*Hor, or ver. scroll speed [px/sec] in 'LV_LABEL_LONG_ROLL/ROLL_CIRC' mode*/
# define LV_LABEL_DEF_SCROLL_SPEED 25
/* Waiting period at beginning/end of animation cycle */
# define LV_LABEL_WAIT_CHAR_COUNT 3
/*Enable selecting text of the label */
# define LV_LABEL_TEXT_SEL 0
/*Store extra some info in labels (12 bytes) to speed up drawing of very long texts*/
# define LV_LABEL_LONG_TXT_HINT 0
#endif
/*LED (dependencies: -)*/
#define LV_USE_LED 1
/*Line (dependencies: -*/
#define LV_USE_LINE 1
/*List (dependencies: lv_page, lv_btn, lv_label, (lv_img optionally for icons ))*/
#define LV_USE_LIST 1
#if LV_USE_LIST != 0
/*Default animation time of focusing to a list element [ms] (0: no animation) */
# define LV_LIST_DEF_ANIM_TIME 100
#endif
/*Line meter (dependencies: *;)*/
#define LV_USE_LMETER 1
/*Message box (dependencies: lv_rect, lv_btnm, lv_label)*/
#define LV_USE_MBOX 1
/*Page (dependencies: lv_cont)*/
#define LV_USE_PAGE 1
#if LV_USE_PAGE != 0
/*Focus default animation time [ms] (0: no animation)*/
# define LV_PAGE_DEF_ANIM_TIME 400
#endif
/*Preload (dependencies: lv_arc, lv_anim)*/
#define LV_USE_PRELOAD 1
#if LV_USE_PRELOAD != 0
# define LV_PRELOAD_DEF_ARC_LENGTH 60 /*[deg]*/
# define LV_PRELOAD_DEF_SPIN_TIME 1000 /*[ms]*/
# define LV_PRELOAD_DEF_ANIM LV_PRELOAD_TYPE_SPINNING_ARC
#endif
/*Roller (dependencies: lv_ddlist)*/
#define LV_USE_ROLLER 1
#if LV_USE_ROLLER != 0
/*Focus animation time [ms] (0: no animation)*/
# define LV_ROLLER_DEF_ANIM_TIME 200
/*Number of extra "pages" when the roller is infinite*/
# define LV_ROLLER_INF_PAGES 7
#endif
/*Slider (dependencies: lv_bar)*/
#define LV_USE_SLIDER 1
/*Spinbox (dependencies: lv_ta)*/
#define LV_USE_SPINBOX 1
/*Switch (dependencies: lv_slider)*/
#define LV_USE_SW 1
/*Text area (dependencies: lv_label, lv_page)*/
#define LV_USE_TA 1
#if LV_USE_TA != 0
# define LV_TA_DEF_CURSOR_BLINK_TIME 400 /*ms*/
# define LV_TA_DEF_PWD_SHOW_TIME 1500 /*ms*/
#endif
/*Table (dependencies: lv_label)*/
#define LV_USE_TABLE 1
#if LV_USE_TABLE
# define LV_TABLE_COL_MAX 12
#endif
/*Tab (dependencies: lv_page, lv_btnm)*/
#define LV_USE_TABVIEW 1
# if LV_USE_TABVIEW != 0
/*Time of slide animation [ms] (0: no animation)*/
# define LV_TABVIEW_DEF_ANIM_TIME 300
#endif
/*Tileview (dependencies: lv_page) */
#define LV_USE_TILEVIEW 1
#if LV_USE_TILEVIEW
/*Time of slide animation [ms] (0: no animation)*/
# define LV_TILEVIEW_DEF_ANIM_TIME 300
#endif
/*Window (dependencies: lv_cont, lv_btn, lv_label, lv_img, lv_page)*/
#define LV_USE_WIN 1
/*==================
* Non-user section
*==================*/
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) /* Disable warnings for Visual Studio*/
# define _CRT_SECURE_NO_WARNINGS
#endif
/*--END OF LV_CONF_H--*/
/*Be sure every define has a default value*/
#include "lvgl/src/lv_conf_checker.h"
#endif /*LV_CONF_H*/
#endif /*End of "Content enable"*/

View File

@ -1,12 +0,0 @@
CSRCS += lv_group.c
CSRCS += lv_indev.c
CSRCS += lv_obj.c
CSRCS += lv_refr.c
CSRCS += lv_style.c
CSRCS += lv_vdb.c
CSRCS += lv_lang.c
DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_core
VPATH += :$(LVGL_DIR)/lvgl/lv_core
CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_core"

View File

@ -1,965 +0,0 @@
/**
* @file lv_indev_proc.c
*
*/
/*********************
* INCLUDES
********************/
#include "lv_indev.h"
#include "../lv_hal/lv_hal_tick.h"
#include "../lv_core/lv_group.h"
#include "../lv_core/lv_refr.h"
#include "../lv_misc/lv_task.h"
#include "../lv_misc/lv_math.h"
#include "../lv_draw/lv_draw_rbasic.h"
#include "lv_obj.h"
/*********************
* DEFINES
*********************/
#if LV_INDEV_DRAG_THROW <= 0
#warning "LV_INDEV_DRAG_THROW must be greater than 0"
#endif
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
#if LV_INDEV_READ_PERIOD != 0
static void indev_proc_task(void * param);
static void indev_pointer_proc(lv_indev_t * i, lv_indev_data_t * data);
static void indev_keypad_proc(lv_indev_t * i, lv_indev_data_t * data);
static void indev_encoder_proc(lv_indev_t * i, lv_indev_data_t * data);
static void indev_button_proc(lv_indev_t * i, lv_indev_data_t * data);
static void indev_proc_press(lv_indev_proc_t * proc);
static void indev_proc_release(lv_indev_proc_t * proc);
static void indev_proc_reset_query_handler(lv_indev_t * indev);
static lv_obj_t * indev_search_obj(const lv_indev_proc_t * proc, lv_obj_t * obj);
static void indev_drag(lv_indev_proc_t * state);
static void indev_drag_throw(lv_indev_proc_t * state);
#endif
/**********************
* STATIC VARIABLES
**********************/
static lv_indev_t * indev_act;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the display input device subsystem
*/
void lv_indev_init(void)
{
#if LV_INDEV_READ_PERIOD != 0
lv_task_create(indev_proc_task, LV_INDEV_READ_PERIOD, LV_TASK_PRIO_MID, NULL);
#endif
lv_indev_reset(NULL); /*Reset all input devices*/
}
/**
* Get the currently processed input device. Can be used in action functions too.
* @return pointer to the currently processed input device or NULL if no input device processing right now
*/
lv_indev_t * lv_indev_get_act(void)
{
return indev_act;
}
/**
* Get the type of an input device
* @param indev pointer to an input device
* @return the type of the input device from `lv_hal_indev_type_t` (`LV_INDEV_TYPE_...`)
*/
lv_hal_indev_type_t lv_indev_get_type(const lv_indev_t * indev)
{
if(indev == NULL) return LV_INDEV_TYPE_NONE;
return indev->driver.type;
}
/**
* Reset one or all input devices
* @param indev pointer to an input device to reset or NULL to reset all of them
*/
void lv_indev_reset(lv_indev_t * indev)
{
if(indev) indev->proc.reset_query = 1;
else {
lv_indev_t * i = lv_indev_next(NULL);
while(i) {
i->proc.reset_query = 1;
i = lv_indev_next(i);
}
}
}
/**
* Reset the long press state of an input device
* @param indev pointer to an input device
*/
void lv_indev_reset_lpr(lv_indev_t * indev)
{
indev->proc.long_pr_sent = 0;
indev->proc.longpr_rep_timestamp = lv_tick_get();
indev->proc.pr_timestamp = lv_tick_get();
}
/**
* Enable input devices device by type
* @param type Input device type
* @param enable true: enable this type; false: disable this type
*/
void lv_indev_enable(lv_hal_indev_type_t type, bool enable)
{
lv_indev_t * i = lv_indev_next(NULL);
while(i) {
if(i->driver.type == type) i->proc.disabled = enable == false ? 1 : 0;
i = lv_indev_next(i);
}
}
/**
* Set a cursor for a pointer input device (for LV_INPUT_TYPE_POINTER and LV_INPUT_TYPE_BUTTON)
* @param indev pointer to an input device
* @param cur_obj pointer to an object to be used as cursor
*/
void lv_indev_set_cursor(lv_indev_t * indev, lv_obj_t * cur_obj)
{
if(indev->driver.type != LV_INDEV_TYPE_POINTER) return;
indev->cursor = cur_obj;
lv_obj_set_parent(indev->cursor, lv_layer_sys());
lv_obj_set_pos(indev->cursor, indev->proc.act_point.x, indev->proc.act_point.y);
}
#if USE_LV_GROUP
/**
* Set a destination group for a keypad input device (for LV_INDEV_TYPE_KEYPAD)
* @param indev pointer to an input device
* @param group point to a group
*/
void lv_indev_set_group(lv_indev_t * indev, lv_group_t * group)
{
if(indev->driver.type == LV_INDEV_TYPE_KEYPAD || indev->driver.type == LV_INDEV_TYPE_ENCODER) indev->group = group;
}
#endif
/**
* Set the an array of points for LV_INDEV_TYPE_BUTTON.
* These points will be assigned to the buttons to press a specific point on the screen
* @param indev pointer to an input device
* @param group point to a group
*/
void lv_indev_set_button_points(lv_indev_t * indev, const lv_point_t * points)
{
if(indev->driver.type == LV_INDEV_TYPE_BUTTON) indev->btn_points = points;
}
/**
* Set feedback callback for indev.
* @param indev pointer to an input device
* @param feedback feedback callback
*/
void lv_indev_set_feedback(lv_indev_t *indev, lv_indev_feedback_t feedback)
{
indev->feedback = feedback;
}
/**
* Get the last point of an input device (for LV_INDEV_TYPE_POINTER and LV_INDEV_TYPE_BUTTON)
* @param indev pointer to an input device
* @param point pointer to a point to store the result
*/
void lv_indev_get_point(const lv_indev_t * indev, lv_point_t * point)
{
if(indev->driver.type != LV_INDEV_TYPE_POINTER && indev->driver.type != LV_INDEV_TYPE_BUTTON) {
point->x = -1;
point->y = -1;
} else {
point->x = indev->proc.act_point.x;
point->y = indev->proc.act_point.y;
}
}
/**
* Get the last key of an input device (for LV_INDEV_TYPE_KEYPAD)
* @param indev pointer to an input device
* @return the last pressed key (0 on error)
*/
uint32_t lv_indev_get_key(const lv_indev_t * indev)
{
if(indev->driver.type != LV_INDEV_TYPE_KEYPAD) return 0;
else return indev->proc.last_key;
}
/**
* Check if there is dragging with an input device or not (for LV_INDEV_TYPE_POINTER and LV_INDEV_TYPE_BUTTON)
* @param indev pointer to an input device
* @return true: drag is in progress
*/
bool lv_indev_is_dragging(const lv_indev_t * indev)
{
if(indev == NULL) return false;
if(indev->driver.type != LV_INDEV_TYPE_POINTER && indev->driver.type != LV_INDEV_TYPE_BUTTON) return false;
return indev->proc.drag_in_prog == 0 ? false : true;
}
/**
* Get the vector of dragging of an input device (for LV_INDEV_TYPE_POINTER and LV_INDEV_TYPE_BUTTON)
* @param indev pointer to an input device
* @param point pointer to a point to store the vector
*/
void lv_indev_get_vect(const lv_indev_t * indev, lv_point_t * point)
{
if(indev == NULL) {
point->x = 0;
point->y = 0;
return;
}
if(indev->driver.type != LV_INDEV_TYPE_POINTER && indev->driver.type != LV_INDEV_TYPE_BUTTON) {
point->x = 0;
point->y = 0;
} else {
point->x = indev->proc.vect.x;
point->y = indev->proc.vect.y;
}
}
/**
* Get elapsed time since last press
* @param indev pointer to an input device (NULL to get the overall smallest inactivity)
* @return Elapsed ticks (milliseconds) since last press
*/
uint32_t lv_indev_get_inactive_time(const lv_indev_t * indev)
{
uint32_t t;
if(indev) return t = lv_tick_elaps(indev->last_activity_time);
lv_indev_t * i;
t = UINT16_MAX;
i = lv_indev_next(NULL);
while(i) {
t = LV_MATH_MIN(t, lv_tick_elaps(i->last_activity_time));
i = lv_indev_next(i);
}
return t;
}
/**
* Get feedback callback for indev.
* @param indev pointer to an input device
* @return feedback callback
*/
lv_indev_feedback_t lv_indev_get_feedback(const lv_indev_t *indev)
{
return indev->feedback;
}
/**
* Do nothing until the next release
* @param indev pointer to an input device
*/
void lv_indev_wait_release(lv_indev_t * indev)
{
indev->proc.wait_unil_release = 1;
}
/**********************
* STATIC FUNCTIONS
**********************/
#if LV_INDEV_READ_PERIOD != 0
/**
* Called periodically to handle the input devices
* @param param unused
*/
static void indev_proc_task(void * param)
{
(void)param;
LV_LOG_TRACE("indev task started");
lv_indev_data_t data;
lv_indev_t * i;
i = lv_indev_next(NULL);
/*Read and process all indevs*/
while(i) {
indev_act = i;
/*Handle reset query before processing the point*/
indev_proc_reset_query_handler(i);
if(i->proc.disabled == 0) {
bool more_to_read;
do {
/*Read the data*/
more_to_read = lv_indev_read(i, &data);
indev_proc_reset_query_handler(i); /*The active object might deleted even in the read function*/
i->proc.state = data.state;
if(i->proc.state == LV_INDEV_STATE_PR) {
i->last_activity_time = lv_tick_get();
}
if(i->driver.type == LV_INDEV_TYPE_POINTER) {
indev_pointer_proc(i, &data);
} else if(i->driver.type == LV_INDEV_TYPE_KEYPAD) {
indev_keypad_proc(i, &data);
} else if(i->driver.type == LV_INDEV_TYPE_ENCODER) {
indev_encoder_proc(i, &data);
} else if(i->driver.type == LV_INDEV_TYPE_BUTTON) {
indev_button_proc(i, &data);
}
/*Handle reset query if it happened in during processing*/
indev_proc_reset_query_handler(i);
} while(more_to_read);
}
i = lv_indev_next(i); /*Go to the next indev*/
}
indev_act = NULL; /*End of indev processing, so no act indev*/
LV_LOG_TRACE("indev task finished");
}
/**
* Process a new point from LV_INDEV_TYPE_POINTER input device
* @param i pointer to an input device
* @param data pointer to the data read from the input device
*/
static void indev_pointer_proc(lv_indev_t * i, lv_indev_data_t * data)
{
/*Move the cursor if set and moved*/
if(i->cursor != NULL &&
(i->proc.last_point.x != data->point.x ||
i->proc.last_point.y != data->point.y)) {
lv_obj_set_pos(i->cursor, data->point.x, data->point.y);
}
i->proc.act_point.x = data->point.x;
i->proc.act_point.y = data->point.y;
if(i->proc.state == LV_INDEV_STATE_PR) {
#if LV_INDEV_POINT_MARKER != 0
lv_area_t area;
area.x1 = i->proc.act_point.x - (LV_INDEV_POINT_MARKER >> 1);
area.y1 = i->proc.act_point.y - (LV_INDEV_POINT_MARKER >> 1);
area.x2 = i->proc.act_point.x + ((LV_INDEV_POINT_MARKER >> 1) | 0x1);
area.y2 = i->proc.act_point.y + ((LV_INDEV_POINT_MARKER >> 1) | 0x1);
lv_rfill(&area, NULL, LV_COLOR_MAKE(0xFF, 0, 0), LV_OPA_COVER);
#endif
indev_proc_press(&i->proc);
} else {
indev_proc_release(&i->proc);
}
i->proc.last_point.x = i->proc.act_point.x;
i->proc.last_point.y = i->proc.act_point.y;
}
/**
* Process a new point from LV_INDEV_TYPE_KEYPAD input device
* @param i pointer to an input device
* @param data pointer to the data read from the input device
*/
static void indev_keypad_proc(lv_indev_t * i, lv_indev_data_t * data)
{
#if USE_LV_GROUP
if(i->group == NULL) return;
/*Key press happened*/
if(data->state == LV_INDEV_STATE_PR &&
i->proc.last_state == LV_INDEV_STATE_REL) {
i->proc.pr_timestamp = lv_tick_get();
lv_obj_t * focused = lv_group_get_focused(i->group);
if(focused && data->key == LV_GROUP_KEY_ENTER) {
focused->signal_func(focused, LV_SIGNAL_PRESSED, indev_act);
}
}
/*Pressing*/
else if(data->state == LV_INDEV_STATE_PR && i->proc.last_state == LV_INDEV_STATE_PR) {
if(data->key == LV_GROUP_KEY_ENTER &&
i->proc.long_pr_sent == 0 &&
lv_tick_elaps(i->proc.pr_timestamp) > LV_INDEV_LONG_PRESS_TIME) {
/*On enter long press leave edit mode.*/
lv_obj_t * focused = lv_group_get_focused(i->group);
if(focused) {
focused->signal_func(focused, LV_SIGNAL_LONG_PRESS, indev_act);
i->proc.long_pr_sent = 1;
}
}
}
/*Release happened*/
else if(data->state == LV_INDEV_STATE_REL && i->proc.last_state == LV_INDEV_STATE_PR) {
/*The user might clear the key when it was released. Always release the pressed key*/
data->key = i->proc.last_key;
/* Edit mode is not used by KEYPAD devices.
* So leave edit mode if we are in it before focusing on the next/prev object*/
if(data->key == LV_GROUP_KEY_NEXT || data->key == LV_GROUP_KEY_PREV) {
lv_group_set_editing(i->group, false);
}
if(data->key == LV_GROUP_KEY_NEXT) {
lv_group_focus_next(i->group);
} else if(data->key == LV_GROUP_KEY_PREV) {
lv_group_focus_prev(i->group);
} else if(data->key == LV_GROUP_KEY_ENTER) {
if(!i->proc.long_pr_sent) {
lv_group_send_data(i->group, data->key);
}
} else {
lv_group_send_data(i->group, data->key);
}
if(i->proc.reset_query) return; /*The object might be deleted in `focus_cb` or due to any other user event*/
i->proc.pr_timestamp = 0;
i->proc.long_pr_sent = 0;
}
i->proc.last_state = data->state;
i->proc.last_key = data->key;
#else
(void)data; /*Unused*/
(void)i; /*Unused*/
#endif
}
/**
* Process a new point from LV_INDEV_TYPE_ENCODER input device
* @param i pointer to an input device
* @param data pointer to the data read from the input device
*/
static void indev_encoder_proc(lv_indev_t * i, lv_indev_data_t * data)
{
#if USE_LV_GROUP
if(i->group == NULL) return;
/*Process the steps first. They are valid only with released button*/
if(data->state == LV_INDEV_STATE_REL) {
/*In edit mode send LEFT/RIGHT keys*/
if(lv_group_get_editing(i->group)) {
int32_t s;
if(data->enc_diff < 0) {
for(s = 0; s < -data->enc_diff; s++) lv_group_send_data(i->group, LV_GROUP_KEY_LEFT);
} else if(data->enc_diff > 0) {
for(s = 0; s < data->enc_diff; s++) lv_group_send_data(i->group, LV_GROUP_KEY_RIGHT);
}
}
/*In navigate mode focus on the next/prev objects*/
else {
int32_t s;
if(data->enc_diff < 0) {
for(s = 0; s < -data->enc_diff; s++) lv_group_focus_prev(i->group);
} else if(data->enc_diff > 0) {
for(s = 0; s < data->enc_diff; s++) lv_group_focus_next(i->group);
}
}
}
/*Key press happened*/
if(data->state == LV_INDEV_STATE_PR &&
i->proc.last_state == LV_INDEV_STATE_REL) {
i->proc.pr_timestamp = lv_tick_get();
}
/*Pressing*/
else if(data->state == LV_INDEV_STATE_PR && i->proc.last_state == LV_INDEV_STATE_PR) {
if(i->proc.long_pr_sent == 0 &&
lv_tick_elaps(i->proc.pr_timestamp) > LV_INDEV_LONG_PRESS_TIME) {
/*On enter long press leave edit mode.*/
lv_obj_t * focused = lv_group_get_focused(i->group);
bool editable = false;
if(focused) focused->signal_func(focused, LV_SIGNAL_GET_EDITABLE, &editable);
if(editable) {
if(i->group->obj_ll.head != i->group->obj_ll.tail)
lv_group_set_editing(i->group, lv_group_get_editing(i->group) ? false : true); /*Toggle edit mode on long press*/
else if(focused)
focused->signal_func(focused, LV_SIGNAL_LONG_PRESS, indev_act);
}
/*If not editable then just send a long press signal*/
else {
if(focused)
focused->signal_func(focused, LV_SIGNAL_LONG_PRESS, indev_act);
}
i->proc.long_pr_sent = 1;
}
}
/*Release happened*/
else if(data->state == LV_INDEV_STATE_REL && i->proc.last_state == LV_INDEV_STATE_PR) {
lv_obj_t * focused = lv_group_get_focused(i->group);
bool editable = false;
if(focused) focused->signal_func(focused, LV_SIGNAL_GET_EDITABLE, &editable);
/*The button was released on a non-editable object. Just send enter*/
if(!editable) {
lv_group_send_data(i->group, LV_GROUP_KEY_ENTER);
}
/*An object is being edited and the button is releases. Just send enter */
else if(i->group->editing) {
if(!i->proc.long_pr_sent || i->group->obj_ll.head == i->group->obj_ll.tail)
lv_group_send_data(i->group, LV_GROUP_KEY_ENTER); /*Ignore long pressed enter release because it comes from mode switch*/
}
/*If the focused object is editable and now in navigate mode then enter edit mode*/
else if(editable && !i->group->editing && !i->proc.long_pr_sent) {
lv_group_set_editing(i->group, lv_group_get_editing(i->group) ? false : true); /*Toggle edit mode on long press*/
}
if(i->proc.reset_query) return; /*The object might be deleted in `focus_cb` or due to any other user event*/
i->proc.pr_timestamp = 0;
i->proc.long_pr_sent = 0;
}
i->proc.last_state = data->state;
i->proc.last_key = data->key;
#else
(void)data; /*Unused*/
(void)i; /*Unused*/
#endif
}
/**
* Process new points from a input device. indev->state.pressed has to be set
* @param indev pointer to an input device state
* @param x x coordinate of the next point
* @param y y coordinate of the next point
*/
static void indev_button_proc(lv_indev_t * i, lv_indev_data_t * data)
{
i->proc.act_point.x = i->btn_points[data->btn].x;
i->proc.act_point.y = i->btn_points[data->btn].y;
/*Still the same point is pressed*/
if(i->proc.last_point.x == i->proc.act_point.x &&
i->proc.last_point.y == i->proc.act_point.y &&
data->state == LV_INDEV_STATE_PR) {
#if LV_INDEV_POINT_MARKER != 0
lv_area_t area;
area.x1 = i->proc.act_point.x - (LV_INDEV_POINT_MARKER >> 1);
area.y1 = i->proc.act_point.y - (LV_INDEV_POINT_MARKER >> 1);
area.x2 = i->proc.act_point.x + ((LV_INDEV_POINT_MARKER >> 1) | 0x1);
area.y2 = i->proc.act_point.y + ((LV_INDEV_POINT_MARKER >> 1) | 0x1);
lv_rfill(&area, NULL, LV_COLOR_MAKE(0xFF, 0, 0), LV_OPA_COVER);
#endif
indev_proc_press(&i->proc);
} else {
/*If a new point comes always make a release*/
indev_proc_release(&i->proc);
}
i->proc.last_point.x = i->proc.act_point.x;
i->proc.last_point.y = i->proc.act_point.y;
}
/**
* Process the pressed state of LV_INDEV_TYPE_POINER input devices
* @param indev pointer to an input device 'proc'
*/
static void indev_proc_press(lv_indev_proc_t * proc)
{
lv_obj_t * pr_obj = proc->act_obj;
if(proc->wait_unil_release != 0) return;
/*If there is no last object then search*/
if(proc->act_obj == NULL) {
pr_obj = indev_search_obj(proc, lv_layer_top());
if(pr_obj == NULL) pr_obj = indev_search_obj(proc, lv_scr_act());
}
/*If there is last object but it is not dragged and not protected also search*/
else if(proc->drag_in_prog == 0 &&
lv_obj_is_protected(proc->act_obj, LV_PROTECT_PRESS_LOST) == false) {/*Now act_obj != NULL*/
pr_obj = indev_search_obj(proc, lv_layer_top());
if(pr_obj == NULL) pr_obj = indev_search_obj(proc, lv_scr_act());
}
/*If a dragable or a protected object was the last then keep it*/
else {
}
/*If a new object was found reset some variables and send a pressed signal*/
if(pr_obj != proc->act_obj) {
proc->last_point.x = proc->act_point.x;
proc->last_point.y = proc->act_point.y;
/*If a new object found the previous was lost, so send a signal*/
if(proc->act_obj != NULL) {
proc->act_obj->signal_func(proc->act_obj, LV_SIGNAL_PRESS_LOST, indev_act);
if(proc->reset_query != 0) return;
}
proc->act_obj = pr_obj; /*Save the pressed object*/
proc->last_obj = proc->act_obj; /*Refresh the last_obj*/
if(proc->act_obj != NULL) {
/* Save the time when the obj pressed.
* It is necessary to count the long press time.*/
proc->pr_timestamp = lv_tick_get();
proc->long_pr_sent = 0;
proc->drag_range_out = 0;
proc->drag_in_prog = 0;
proc->drag_sum.x = 0;
proc->drag_sum.y = 0;
proc->vect.x = 0;
proc->vect.y = 0;
/*Search for 'top' attribute*/
lv_obj_t * i = proc->act_obj;
lv_obj_t * last_top = NULL;
while(i != NULL) {
if(i->top != 0) last_top = i;
i = lv_obj_get_parent(i);
}
if(last_top != NULL) {
/*Move the last_top object to the foreground*/
lv_obj_t * par = lv_obj_get_parent(last_top);
/*After list change it will be the new head*/
lv_ll_chg_list(&par->child_ll, &par->child_ll, last_top);
lv_obj_invalidate(last_top);
}
/*Send a signal about the press*/
proc->act_obj->signal_func(proc->act_obj, LV_SIGNAL_PRESSED, indev_act);
if(proc->reset_query != 0) return;
}
}
/*Calculate the vector*/
proc->vect.x = proc->act_point.x - proc->last_point.x;
proc->vect.y = proc->act_point.y - proc->last_point.y;
/*If there is active object and it can be dragged run the drag*/
if(proc->act_obj != NULL) {
proc->act_obj->signal_func(proc->act_obj, LV_SIGNAL_PRESSING, indev_act);
if(proc->reset_query != 0) return;
indev_drag(proc);
if(proc->reset_query != 0) return;
/*If there is no drag then check for long press time*/
if(proc->drag_in_prog == 0 && proc->long_pr_sent == 0) {
/*Send a signal about the long press if enough time elapsed*/
if(lv_tick_elaps(proc->pr_timestamp) > LV_INDEV_LONG_PRESS_TIME) {
pr_obj->signal_func(pr_obj, LV_SIGNAL_LONG_PRESS, indev_act);
if(proc->reset_query != 0) return;
/*Mark the signal sending to do not send it again*/
proc->long_pr_sent = 1;
/*Save the long press time stamp for the long press repeat handler*/
proc->longpr_rep_timestamp = lv_tick_get();
}
}
/*Send long press repeated signal*/
if(proc->drag_in_prog == 0 && proc->long_pr_sent == 1) {
/*Send a signal about the long press repeate if enough time elapsed*/
if(lv_tick_elaps(proc->longpr_rep_timestamp) > LV_INDEV_LONG_PRESS_REP_TIME) {
pr_obj->signal_func(pr_obj, LV_SIGNAL_LONG_PRESS_REP, indev_act);
if(proc->reset_query != 0) return;
proc->longpr_rep_timestamp = lv_tick_get();
}
}
}
}
/**
* Process the released state of LV_INDEV_TYPE_POINER input devices
* @param proc pointer to an input device 'proc'
*/
static void indev_proc_release(lv_indev_proc_t * proc)
{
if(proc->wait_unil_release != 0) {
proc->act_obj = NULL;
proc->last_obj = NULL;
proc->pr_timestamp = 0;
proc->longpr_rep_timestamp = 0;
proc->wait_unil_release = 0;
}
/*Forgot the act obj and send a released signal */
if(proc->act_obj != NULL) {
/* If the object was protected against press lost then it possible that
* the object is already not pressed but still it is the `act_obj`.
* In this case send the `LV_SIGNAL_RELEASED` if the indev is ON the `act_obj` */
if(lv_obj_is_protected(proc->act_obj, LV_PROTECT_PRESS_LOST)) {
/* Search the object on the current current coordinates.
* The start object is the object itself. If not ON it the the result will be NULL*/
lv_obj_t * obj_on = indev_search_obj(proc, proc->act_obj);
if(obj_on == proc->act_obj) proc->act_obj->signal_func(proc->act_obj, LV_SIGNAL_RELEASED, indev_act);
else proc->act_obj->signal_func(proc->act_obj, LV_SIGNAL_PRESS_LOST, indev_act);
}
/* The simple case: `act_obj` was not protected against press lost.
* If it is already not pressed then was handled in `indev_proc_press`*/
else {
proc->act_obj->signal_func(proc->act_obj, LV_SIGNAL_RELEASED, indev_act);
}
if(proc->reset_query != 0) return;
/*Handle click focus*/
#if USE_LV_GROUP
/*Edit mode is not used by POINTER devices. So leave edit mode if we are in it*/
lv_group_t * act_g = lv_obj_get_group(proc->act_obj);
if(lv_group_get_editing(act_g)) {
lv_group_set_editing(act_g, false);
}
/*Check, if the parent is in a group focus on it.*/
if(lv_obj_is_protected(proc->act_obj, LV_PROTECT_CLICK_FOCUS) == false) { /*Respect the click protection*/
lv_group_t * g = lv_obj_get_group(proc->act_obj);
lv_obj_t * parent = proc->act_obj;
while(g == NULL) {
parent = lv_obj_get_parent(parent);
if(parent == NULL) break;
if(lv_obj_is_protected(parent, LV_PROTECT_CLICK_FOCUS)) { /*Ignore is the protected against click focus*/
parent = NULL;
break;
}
g = lv_obj_get_group(parent);
}
if(g != NULL && parent != NULL)
if(lv_group_get_click_focus(g)) {
lv_group_focus_obj(parent);
}
}
#endif
if(proc->reset_query != 0) return;
proc->act_obj = NULL;
proc->pr_timestamp = 0;
proc->longpr_rep_timestamp = 0;
}
/*The reset can be set in the signal function.
* In case of reset query ignore the remaining parts.*/
if(proc->last_obj != NULL && proc->reset_query == 0) {
indev_drag_throw(proc);
if(proc->reset_query != 0) return;
}
}
/**
* Process a new point from LV_INDEV_TYPE_BUTTON input device
* @param i pointer to an input device
* @param data pointer to the data read from the input device
* Reset input device if a reset query has been sent to it
* @param indev pointer to an input device
*/
static void indev_proc_reset_query_handler(lv_indev_t * indev)
{
if(indev->proc.reset_query) {
indev->proc.act_obj = NULL;
indev->proc.last_obj = NULL;
indev->proc.drag_range_out = 0;
indev->proc.drag_in_prog = 0;
indev->proc.long_pr_sent = 0;
indev->proc.pr_timestamp = 0;
indev->proc.longpr_rep_timestamp = 0;
indev->proc.drag_sum.x = 0;
indev->proc.drag_sum.y = 0;
indev->proc.reset_query = 0;
}
}
/**
* Search the most top, clickable object on the last point of an input device
* @param proc pointer to the `lv_indev_proc_t` part of the input device
* @param obj pointer to a start object, typically the screen
* @return pointer to the found object or NULL if there was no suitable object
*/
static lv_obj_t * indev_search_obj(const lv_indev_proc_t * proc, lv_obj_t * obj)
{
lv_obj_t * found_p = NULL;
/*If the point is on this object*/
/*Check its children too*/
if(lv_area_is_point_on(&obj->coords, &proc->act_point)) {
lv_obj_t * i;
LL_READ(obj->child_ll, i) {
found_p = indev_search_obj(proc, i);
/*If a child was found then break*/
if(found_p != NULL) {
break;
}
}
/*If then the children was not ok, and this obj is clickable
* and it or its parent is not hidden then save this object*/
if(found_p == NULL && lv_obj_get_click(obj) != false) {
lv_obj_t * hidden_i = obj;
while(hidden_i != NULL) {
if(lv_obj_get_hidden(hidden_i) == true) break;
hidden_i = lv_obj_get_parent(hidden_i);
}
/*No parent found with hidden == true*/
if(hidden_i == NULL) found_p = obj;
}
}
return found_p;
}
/**
* Handle the dragging of indev_proc_p->act_obj
* @param indev pointer to a input device state
*/
static void indev_drag(lv_indev_proc_t * state)
{
lv_obj_t * drag_obj = state->act_obj;
/*If drag parent is active check recursively the drag_parent attribute*/
while(lv_obj_get_drag_parent(drag_obj) != false &&
drag_obj != NULL) {
drag_obj = lv_obj_get_parent(drag_obj);
}
if(drag_obj == NULL) return;
if(lv_obj_get_drag(drag_obj) == false) return;
/*Count the movement by drag*/
state->drag_sum.x += state->vect.x;
state->drag_sum.y += state->vect.y;
/*Enough move?*/
if(state->drag_range_out == 0) {
/*If a move is greater then LV_DRAG_LIMIT then begin the drag*/
if(LV_MATH_ABS(state->drag_sum.x) >= LV_INDEV_DRAG_LIMIT ||
LV_MATH_ABS(state->drag_sum.y) >= LV_INDEV_DRAG_LIMIT) {
state->drag_range_out = 1;
}
}
/*If the drag limit is stepped over then handle the dragging*/
if(state->drag_range_out != 0) {
/*Set new position if the vector is not zero*/
if(state->vect.x != 0 ||
state->vect.y != 0) {
/*Get the coordinates of the object and modify them*/
lv_coord_t act_x = lv_obj_get_x(drag_obj);
lv_coord_t act_y = lv_obj_get_y(drag_obj);
uint16_t inv_buf_size = lv_refr_get_buf_size(); /*Get the number of currently invalidated areas*/
lv_coord_t prev_x = drag_obj->coords.x1;
lv_coord_t prev_y = drag_obj->coords.y1;
lv_coord_t prev_par_w = lv_obj_get_width(lv_obj_get_parent(drag_obj));
lv_coord_t prev_par_h = lv_obj_get_height(lv_obj_get_parent(drag_obj));
lv_obj_set_pos(drag_obj, act_x + state->vect.x, act_y + state->vect.y);
/*Set the drag in progress flag if the object is really moved*/
if(drag_obj->coords.x1 != prev_x || drag_obj->coords.y1 != prev_y) {
if(state->drag_range_out != 0) { /*Send the drag begin signal on first move*/
drag_obj->signal_func(drag_obj, LV_SIGNAL_DRAG_BEGIN, indev_act);
if(state->reset_query != 0) return;
}
state->drag_in_prog = 1;
}
/*If the object didn't moved then clear the invalidated areas*/
else {
/*In a special case if the object is moved on a page and
* the scrollable has fit == true and the object is dragged of the page then
* while its coordinate is not changing only the parent's size is reduced */
lv_coord_t act_par_w = lv_obj_get_width(lv_obj_get_parent(drag_obj));
lv_coord_t act_par_h = lv_obj_get_height(lv_obj_get_parent(drag_obj));
if(act_par_w == prev_par_w && act_par_h == prev_par_h) {
uint16_t new_inv_buf_size = lv_refr_get_buf_size();
lv_refr_pop_from_buf(new_inv_buf_size - inv_buf_size);
}
}
}
}
}
/**
* Handle throwing by drag if the drag is ended
* @param indev pointer to an input device state
*/
static void indev_drag_throw(lv_indev_proc_t * state)
{
if(state->drag_in_prog == 0) return;
/*Set new position if the vector is not zero*/
lv_obj_t * drag_obj = state->last_obj;
/*If drag parent is active check recursively the drag_parent attribute*/
while(lv_obj_get_drag_parent(drag_obj) != false &&
drag_obj != NULL) {
drag_obj = lv_obj_get_parent(drag_obj);
}
if(drag_obj == NULL) return;
/*Return if the drag throw is not enabled*/
if(lv_obj_get_drag_throw(drag_obj) == false) {
state->drag_in_prog = 0;
drag_obj->signal_func(drag_obj, LV_SIGNAL_DRAG_END, indev_act);
return;
}
/*Reduce the vectors*/
state->vect.x = state->vect.x * (100 - LV_INDEV_DRAG_THROW) / 100;
state->vect.y = state->vect.y * (100 - LV_INDEV_DRAG_THROW) / 100;
if(state->vect.x != 0 ||
state->vect.y != 0) {
/*Get the coordinates and modify them*/
lv_area_t coords_ori;
lv_obj_get_coords(drag_obj, &coords_ori);
lv_coord_t act_x = lv_obj_get_x(drag_obj) + state->vect.x;
lv_coord_t act_y = lv_obj_get_y(drag_obj) + state->vect.y;
lv_obj_set_pos(drag_obj, act_x, act_y);
lv_area_t coord_new;
lv_obj_get_coords(drag_obj, &coord_new);
/*If non of the coordinates are changed then do not continue throwing*/
if((coords_ori.x1 == coord_new.x1 || state->vect.x == 0) &&
(coords_ori.y1 == coord_new.y1 || state->vect.y == 0)) {
state->drag_in_prog = 0;
state->vect.x = 0;
state->vect.y = 0;
drag_obj->signal_func(drag_obj, LV_SIGNAL_DRAG_END, indev_act);
}
}
/*If the vectors become 0 -> drag_in_prog = 0 and send a drag end signal*/
else {
state->drag_in_prog = 0;
drag_obj->signal_func(drag_obj, LV_SIGNAL_DRAG_END, indev_act);
}
}
#endif

View File

@ -1,117 +0,0 @@
/**
* @file lv_lang.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_lang.h"
#if USE_LV_MULTI_LANG
#include "lv_obj.h"
#include "../lv_misc/lv_gc.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void lang_set_core(lv_obj_t * obj);
/**********************
* STATIC VARIABLES
**********************/
static uint8_t lang_act = 0;
static const void * (*get_txt)(uint16_t);
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Change the language
* @param lang_id the id of the
*/
void lv_lang_set(uint8_t lang_id)
{
lang_act = lang_id;
lv_obj_t * i;
LL_READ(LV_GC_ROOT(_lv_scr_ll), i) {
i->signal_func(i, LV_SIGNAL_LANG_CHG, NULL);
lang_set_core(i);
}
lang_set_core(lv_scr_act());
}
/**
* Set a function to get the texts of the set languages from a `txt_id`
* @param fp a function pointer to get the texts
*/
void lv_lang_set_text_func(const void * (*fp)(uint16_t))
{
get_txt = fp;
}
/**
* Use the function set by `lv_lang_set_text_func` to get the `txt_id` text in the set language
* @param txt_id an ID of the text to get
* @return the `txt_id` txt on the set language
*/
const void * lv_lang_get_text(uint16_t txt_id)
{
if(get_txt == NULL) {
LV_LOG_WARN("lv_lang_get_text: text_func is not specified");
return NULL; /*No text_get function specified */
}
if(txt_id == LV_LANG_TXT_ID_NONE) {
LV_LOG_WARN("lv_lang_get_text: attempts to get invalid text ID");
return NULL; /*Invalid txt_id*/
}
return get_txt(txt_id);
}
/**
* Return with ID of the currently selected language
* @return pointer to the active screen object (loaded by 'lv_scr_load()')
*/
uint8_t lv_lang_act(void)
{
return lang_act;
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Change the language of the children. (Called recursively)
* @param obj pointer to an object
*/
static void lang_set_core(lv_obj_t * obj)
{
lv_obj_t * i;
LL_READ(obj->child_ll, i) {
i->signal_func(i, LV_SIGNAL_LANG_CHG, NULL);
lang_set_core(i);
}
}
#endif /*USE_LV_MULTI_LANG*/

View File

@ -1,74 +0,0 @@
/**
* @file lv_lang.h
*
*/
#ifndef LV_LANG_H
#define LV_LANG_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_conf.h"
#else
#include "../../lv_conf.h"
#endif
#if USE_LV_MULTI_LANG
#include <stdint.h>
/*********************
* DEFINES
*********************/
#define LV_LANG_TXT_ID_NONE 0xFFFF /*Used to not assign any text IDs for a multi-language object.*/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Change the language
* @param lang_id the id of the
*/
void lv_lang_set(uint8_t lang_id);
/**
* Set a function to get the texts of the set languages from a `txt_id`
* @param fp a function pointer to get the texts
*/
void lv_lang_set_text_func(const void * (*fp)(uint16_t));
/**
* Use the function set by `lv_lang_set_text_func` to get the `txt_id` text in the set language
* @param txt_id an ID of the text to get
* @return the `txt_id` txt on the set language
*/
const void * lv_lang_get_text(uint16_t txt_id);
/**
* Return with ID of the currently selected language
* @return pointer to the active screen object (loaded by 'lv_scr_load()')
*/
uint8_t lv_lang_act(void);
/**********************
* MACROS
**********************/
#endif /*USE_LV_MULTI_LANG*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_LANG_H*/

View File

@ -1,614 +0,0 @@
/**
* @file lv_refr.c
*
*/
/*********************
* INCLUDES
*********************/
#include <stddef.h>
#include "lv_refr.h"
#include "lv_vdb.h"
#include "../lv_hal/lv_hal_tick.h"
#include "../lv_hal/lv_hal_disp.h"
#include "../lv_misc/lv_task.h"
#include "../lv_misc/lv_mem.h"
/*********************
* DEFINES
*********************/
#ifndef LV_INV_FIFO_SIZE
#define LV_INV_FIFO_SIZE 32 /*The average count of objects on a screen */
#endif
/**********************
* TYPEDEFS
**********************/
typedef struct {
lv_area_t area;
uint8_t joined;
} lv_join_t;
/**********************
* STATIC PROTOTYPES
**********************/
static void lv_refr_task(void * param);
static void lv_refr_join_area(void);
static void lv_refr_areas(void);
#if LV_VDB_SIZE == 0
static void lv_refr_area_no_vdb(const lv_area_t * area_p);
#else
static void lv_refr_area_with_vdb(const lv_area_t * area_p);
static void lv_refr_area_part_vdb(const lv_area_t * area_p);
#endif
static lv_obj_t * lv_refr_get_top_obj(const lv_area_t * area_p, lv_obj_t * obj);
static void lv_refr_obj_and_children(lv_obj_t * top_p, const lv_area_t * mask_p);
static void lv_refr_obj(lv_obj_t * obj, const lv_area_t * mask_ori_p);
/**********************
* STATIC VARIABLES
**********************/
static lv_join_t inv_buf[LV_INV_FIFO_SIZE];
static uint16_t inv_buf_p;
static void (*monitor_cb)(uint32_t, uint32_t); /*Monitor the rendering time*/
static void (*round_cb)(lv_area_t *); /*If set then called to modify invalidated areas for special display controllers*/
static uint32_t px_num;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the screen refresh subsystem
*/
void lv_refr_init(void)
{
inv_buf_p = 0;
memset(inv_buf, 0, sizeof(inv_buf));
lv_task_t * task;
task = lv_task_create(lv_refr_task, LV_REFR_PERIOD, LV_TASK_PRIO_MID, NULL);
lv_task_ready(task); /*Be sure the screen will be refreshed immediately on start up*/
}
/**
* Redraw the invalidated areas now.
* Normally the redrawing is periodically executed in `lv_task_handler` but a long blocking process can
* prevent the call of `lv_task_handler`. In this case if the the GUI is updated in the process (e.g. progress bar)
* this function can be called when the screen should be updated.
*/
void lv_refr_now(void)
{
lv_refr_task(NULL);
}
/**
* Invalidate an area
* @param area_p pointer to area which should be invalidated
*/
void lv_inv_area(const lv_area_t * area_p)
{
/*Clear the invalidate buffer if the parameter is NULL*/
if(area_p == NULL) {
inv_buf_p = 0;
return;
}
lv_area_t scr_area;
scr_area.x1 = 0;
scr_area.y1 = 0;
scr_area.x2 = LV_HOR_RES - 1;
scr_area.y2 = LV_VER_RES - 1;
lv_area_t com_area;
bool suc;
suc = lv_area_intersect(&com_area, area_p, &scr_area);
/*The area is truncated to the screen*/
if(suc != false) {
if(round_cb) round_cb(&com_area);
/*Save only if this area is not in one of the saved areas*/
uint16_t i;
for(i = 0; i < inv_buf_p; i++) {
if(lv_area_is_in(&com_area, &inv_buf[i].area) != false) return;
}
/*Save the area*/
if(inv_buf_p < LV_INV_FIFO_SIZE) {
lv_area_copy(&inv_buf[inv_buf_p].area, &com_area);
} else {/*If no place for the area add the screen*/
inv_buf_p = 0;
lv_area_copy(&inv_buf[inv_buf_p].area, &scr_area);
}
inv_buf_p ++;
}
}
/**
* Set a function to call after every refresh to announce the refresh time and the number of refreshed pixels
* @param cb pointer to a callback function (void my_refr_cb(uint32_t time_ms, uint32_t px_num))
* time_ms: refresh time in [ms]
* px_num: not the drawn pixels but the number of affected pixels of the screen
* (more pixels are drawn because of overlapping objects)
*/
void lv_refr_set_monitor_cb(void (*cb)(uint32_t, uint32_t))
{
monitor_cb = cb;
}
/**
* Called when an area is invalidated to modify the coordinates of the area.
* Special display controllers may require special coordinate rounding
* @param cb pointer to the a function which will modify the area
*/
void lv_refr_set_round_cb(void(*cb)(lv_area_t *))
{
round_cb = cb;
}
/**
* Get the number of areas in the buffer
* @return number of invalid areas
*/
uint16_t lv_refr_get_buf_size(void)
{
return inv_buf_p;
}
/**
* Pop (delete) the last 'num' invalidated areas from the buffer
* @param num number of areas to delete
*/
void lv_refr_pop_from_buf(uint16_t num)
{
if(inv_buf_p < num) inv_buf_p = 0;
else inv_buf_p -= num;
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Called periodically to handle the refreshing
* @param param unused
*/
static void lv_refr_task(void * param)
{
(void)param;
LV_LOG_TRACE("display refresh task started");
uint32_t start = lv_tick_get();
if(lv_disp_get_active() == NULL) {
LV_LOG_TRACE("No display is registered");
return;
}
lv_refr_join_area();
lv_refr_areas();
/*If refresh happened ...*/
if(inv_buf_p != 0) {
/*In true double buffered mode copy the refreshed areas to the new VDB to keep it up to date*/
#if LV_VDB_TRUE_DOUBLE_BUFFERED
lv_vdb_t * vdb_p = lv_vdb_get();
vdb_p->area.x1 = 0;
vdb_p->area.x2 = LV_HOR_RES-1;
vdb_p->area.y1 = 0;
vdb_p->area.y2 = LV_VER_RES - 1;
/*Flush the content of the VDB*/
lv_vdb_flush();
/* With true double buffering the flushing should be only the address change of the current frame buffer
* Wait until the address change is ready and copy the active content to the other frame buffer (new active VDB)
* The changes will be written to the new VDB.*/
lv_vdb_t * vdb_act = lv_vdb_get_active();
lv_vdb_t * vdb_ina = lv_vdb_get_inactive();
uint8_t * buf_act = (uint8_t *) vdb_act->buf;
uint8_t * buf_ina = (uint8_t *) vdb_ina->buf;
uint16_t a;
for(a = 0; a < inv_buf_p; a++) {
if(inv_buf[a].joined == 0) {
lv_coord_t y;
uint32_t start_offs = ((LV_HOR_RES * inv_buf[a].area.y1 + inv_buf[a].area.x1) * LV_VDB_PX_BPP) >> 3;
uint32_t line_length = (lv_area_get_width(&inv_buf[a].area) * LV_VDB_PX_BPP) >> 3;
for(y = inv_buf[a].area.y1; y <= inv_buf[a].area.y2; y++) {
memcpy(buf_act + start_offs, buf_ina + start_offs, line_length);
start_offs += (LV_HOR_RES * LV_VDB_PX_BPP) >> 3;
}
}
}
#endif
/*Clean up*/
memset(inv_buf, 0, sizeof(inv_buf));
inv_buf_p = 0;
/*Call monitor cb if present*/
if(monitor_cb != NULL) {
monitor_cb(lv_tick_elaps(start), px_num);
}
}
LV_LOG_TRACE("display refresh task finished");
}
/**
* Join the areas which has got common parts
*/
static void lv_refr_join_area(void)
{
uint32_t join_from;
uint32_t join_in;
lv_area_t joined_area;
for(join_in = 0; join_in < inv_buf_p; join_in++) {
if(inv_buf[join_in].joined != 0) continue;
/*Check all areas to join them in 'join_in'*/
for(join_from = 0; join_from < inv_buf_p; join_from++) {
/*Handle only unjoined areas and ignore itself*/
if(inv_buf[join_from].joined != 0 || join_in == join_from) {
continue;
}
/*Check if the areas are on each other*/
if(lv_area_is_on(&inv_buf[join_in].area,
&inv_buf[join_from].area) == false) {
continue;
}
lv_area_join(&joined_area, &inv_buf[join_in].area,
&inv_buf[join_from].area);
/*Join two area only if the joined area size is smaller*/
if(lv_area_get_size(&joined_area) <
(lv_area_get_size(&inv_buf[join_in].area) + lv_area_get_size(&inv_buf[join_from].area))) {
lv_area_copy(&inv_buf[join_in].area, &joined_area);
/*Mark 'join_form' is joined into 'join_in'*/
inv_buf[join_from].joined = 1;
}
}
}
}
/**
* Refresh the joined areas
*/
static void lv_refr_areas(void)
{
px_num = 0;
uint32_t i;
for(i = 0; i < inv_buf_p; i++) {
/*Refresh the unjoined areas*/
if(inv_buf[i].joined == 0) {
/*If there is no VDB do simple drawing*/
#if LV_VDB_SIZE == 0
lv_refr_area_no_vdb(&inv_buf[i].area);
#else
/*If VDB is used...*/
lv_refr_area_with_vdb(&inv_buf[i].area);
#endif
if(monitor_cb != NULL) px_num += lv_area_get_size(&inv_buf[i].area);
}
}
}
#if LV_VDB_SIZE == 0
/**
* Refresh an area if there is no Virtual Display Buffer
* @param area_p pointer to an area to refresh
*/
static void lv_refr_area_no_vdb(const lv_area_t * area_p)
{
lv_obj_t * top_p;
/*Get top object which is not covered by others*/
top_p = lv_refr_get_top_obj(area_p, lv_scr_act());
/*Do the refreshing*/
lv_refr_obj_and_children(top_p, area_p);
/*Also refresh top and sys layer unconditionally*/
lv_refr_obj_and_children(lv_layer_top(), area_p);
lv_refr_obj_and_children(lv_layer_sys(), area_p);
}
#else
/**
* Refresh an area if there is Virtual Display Buffer
* @param area_p pointer to an area to refresh
*/
static void lv_refr_area_with_vdb(const lv_area_t * area_p)
{
#if LV_VDB_TRUE_DOUBLE_BUFFERED == 0
/*Calculate the max row num*/
lv_coord_t w = lv_area_get_width(area_p);
lv_coord_t h = lv_area_get_height(area_p);
lv_coord_t y2 = area_p->y2 >= LV_VER_RES ? y2 = LV_VER_RES - 1 : area_p->y2;
int32_t max_row = (uint32_t) LV_VDB_SIZE / w;
if(max_row > h) max_row = h;
/*Round down the lines of VDB if rounding is added*/
if(round_cb) {
lv_area_t tmp;
tmp.x1 = 0;
tmp.x2 = 0;
tmp.y1 = 0;
lv_coord_t y_tmp = max_row - 1;
do {
tmp.y2 = y_tmp;
round_cb(&tmp);
/*If this height fits into `max_row` then fine*/
if(lv_area_get_height(&tmp) <= max_row) break;
/*Decrement the height of the area until it fits into `max_row` after rounding*/
y_tmp --;
} while(y_tmp != 0);
if(y_tmp == 0) {
LV_LOG_WARN("Can't set VDB height using the round function. (Wrong round_cb or to small VDB)");
return;
} else {
max_row = tmp.y2 + 1;
}
}
/*Always use the full row*/
lv_coord_t row;
lv_coord_t row_last = 0;
for(row = area_p->y1; row + max_row - 1 <= y2; row += max_row) {
lv_vdb_t * vdb_p = lv_vdb_get();
if(!vdb_p) {
LV_LOG_WARN("Invalid VDB pointer");
return;
}
/*Calc. the next y coordinates of VDB*/
vdb_p->area.x1 = area_p->x1;
vdb_p->area.x2 = area_p->x2;
vdb_p->area.y1 = row;
vdb_p->area.y2 = row + max_row - 1;
if(vdb_p->area.y2 > y2) vdb_p->area.y2 = y2;
row_last = vdb_p->area.y2;
lv_refr_area_part_vdb(area_p);
}
/*If the last y coordinates are not handled yet ...*/
if(y2 != row_last) {
lv_vdb_t * vdb_p = lv_vdb_get();
if(!vdb_p) {
LV_LOG_WARN("Invalid VDB pointer");
return;
}
/*Calc. the next y coordinates of VDB*/
vdb_p->area.x1 = area_p->x1;
vdb_p->area.x2 = area_p->x2;
vdb_p->area.y1 = row;
vdb_p->area.y2 = y2;
/*Refresh this part too*/
lv_refr_area_part_vdb(area_p);
}
#else
lv_vdb_t * vdb_p = lv_vdb_get();
vdb_p->area.x1 = 0;
vdb_p->area.x2 = LV_HOR_RES-1;
vdb_p->area.y1 = 0;
vdb_p->area.y2 = LV_VER_RES - 1;
lv_refr_area_part_vdb(area_p);
#endif
}
/**
* Refresh a part of an area which is on the actual Virtual Display Buffer
* @param area_p pointer to an area to refresh
*/
static void lv_refr_area_part_vdb(const lv_area_t * area_p)
{
lv_vdb_t * vdb_p = lv_vdb_get();
if(!vdb_p) {
LV_LOG_WARN("Invalid VDB pointer");
return;
}
lv_obj_t * top_p;
/*Get the new mask from the original area and the act. VDB
It will be a part of 'area_p'*/
lv_area_t start_mask;
lv_area_intersect(&start_mask, area_p, &vdb_p->area);
/*Get the most top object which is not covered by others*/
top_p = lv_refr_get_top_obj(&start_mask, lv_scr_act());
/*Do the refreshing from the top object*/
lv_refr_obj_and_children(top_p, &start_mask);
/*Also refresh top and sys layer unconditionally*/
lv_refr_obj_and_children(lv_layer_top(), &start_mask);
lv_refr_obj_and_children(lv_layer_sys(), &start_mask);
/* In true double buffered mode flush only once when all areas were rendered.
* In normal mode flush after every area */
#if LV_VDB_TRUE_DOUBLE_BUFFERED == 0
/*Flush the content of the VDB*/
lv_vdb_flush();
#endif
}
#endif /*LV_VDB_SIZE == 0*/
/**
* Search the most top object which fully covers an area
* @param area_p pointer to an area
* @param obj the first object to start the searching (typically a screen)
* @return
*/
static lv_obj_t * lv_refr_get_top_obj(const lv_area_t * area_p, lv_obj_t * obj)
{
lv_obj_t * i;
lv_obj_t * found_p = NULL;
/*If this object is fully cover the draw area check the children too */
if(lv_area_is_in(area_p, &obj->coords) && obj->hidden == 0) {
LL_READ(obj->child_ll, i) {
found_p = lv_refr_get_top_obj(area_p, i);
/*If a children is ok then break*/
if(found_p != NULL) {
break;
}
}
/*If no better children check this object*/
if(found_p == NULL) {
lv_style_t * style = lv_obj_get_style(obj);
if(style->body.opa == LV_OPA_COVER &&
obj->design_func(obj, area_p, LV_DESIGN_COVER_CHK) != false &&
lv_obj_get_opa_scale(obj) == LV_OPA_COVER) {
found_p = obj;
}
}
}
return found_p;
}
/**
* Make the refreshing from an object. Draw all its children and the youngers too.
* @param top_p pointer to an objects. Start the drawing from it.
* @param mask_p pointer to an area, the objects will be drawn only here
*/
static void lv_refr_obj_and_children(lv_obj_t * top_p, const lv_area_t * mask_p)
{
/* Normally always will be a top_obj (at least the screen)
* but in special cases (e.g. if the screen has alpha) it won't.
* In this case use the screen directly */
if(top_p == NULL) top_p = lv_scr_act();
/*Refresh the top object and its children*/
lv_refr_obj(top_p, mask_p);
/*Draw the 'younger' sibling objects because they can be on top_obj */
lv_obj_t * par;
lv_obj_t * i;
lv_obj_t * border_p = top_p;
par = lv_obj_get_parent(top_p);
/*Do until not reach the screen*/
while(par != NULL) {
/*object before border_p has to be redrawn*/
i = lv_ll_get_prev(&(par->child_ll), border_p);
while(i != NULL) {
/*Refresh the objects*/
lv_refr_obj(i, mask_p);
i = lv_ll_get_prev(&(par->child_ll), i);
}
/*The new border will be there last parents,
*so the 'younger' brothers of parent will be refreshed*/
border_p = par;
/*Go a level deeper*/
par = lv_obj_get_parent(par);
}
/*Call the post draw design function of the parents of the to object*/
par = lv_obj_get_parent(top_p);
while(par != NULL) {
par->design_func(par, mask_p, LV_DESIGN_DRAW_POST);
par = lv_obj_get_parent(par);
}
}
/**
* Refresh an object an all of its children. (Called recursively)
* @param obj pointer to an object to refresh
* @param mask_ori_p pointer to an area, the objects will be drawn only here
*/
static void lv_refr_obj(lv_obj_t * obj, const lv_area_t * mask_ori_p)
{
/*Do not refresh hidden objects*/
if(obj->hidden != 0) return;
bool union_ok; /* Store the return value of area_union */
/* Truncate the original mask to the coordinates of the parent
* because the parent and its children are visible only here */
lv_area_t obj_mask;
lv_area_t obj_ext_mask;
lv_area_t obj_area;
lv_coord_t ext_size = obj->ext_size;
lv_obj_get_coords(obj, &obj_area);
obj_area.x1 -= ext_size;
obj_area.y1 -= ext_size;
obj_area.x2 += ext_size;
obj_area.y2 += ext_size;
union_ok = lv_area_intersect(&obj_ext_mask, mask_ori_p, &obj_area);
/*Draw the parent and its children only if they ore on 'mask_parent'*/
if(union_ok != false) {
/* Redraw the object */
obj->design_func(obj, &obj_ext_mask, LV_DESIGN_DRAW_MAIN);
//usleep(5 * 1000); /*DEBUG: Wait after every object draw to see the order of drawing*/
/*Create a new 'obj_mask' without 'ext_size' because the children can't be visible there*/
lv_obj_get_coords(obj, &obj_area);
union_ok = lv_area_intersect(&obj_mask, mask_ori_p, &obj_area);
if(union_ok != false) {
lv_area_t mask_child; /*Mask from obj and its child*/
lv_obj_t * child_p;
lv_area_t child_area;
LL_READ_BACK(obj->child_ll, child_p) {
lv_obj_get_coords(child_p, &child_area);
ext_size = child_p->ext_size;
child_area.x1 -= ext_size;
child_area.y1 -= ext_size;
child_area.x2 += ext_size;
child_area.y2 += ext_size;
/* Get the union (common parts) of original mask (from obj)
* and its child */
union_ok = lv_area_intersect(&mask_child, &obj_mask, &child_area);
/*If the parent and the child has common area then refresh the child */
if(union_ok) {
/*Refresh the next children*/
lv_refr_obj(child_p, &mask_child);
}
}
}
/* If all the children are redrawn make 'post draw' design */
obj->design_func(obj, &obj_ext_mask, LV_DESIGN_DRAW_POST);
}
}

View File

@ -1,95 +0,0 @@
/**
* @file lv_refr.h
*
*/
#ifndef LV_REFR_H
#define LV_REFR_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lv_obj.h"
#include <stdbool.h>
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the screen refresh subsystem
*/
void lv_refr_init(void);
/**
* Redraw the invalidated areas now.
* Normally the redrawing is periodically executed in `lv_task_handler` but a long blocking process can
* prevent the call of `lv_task_handler`. In this case if the the GUI is updated in the process (e.g. progress bar)
* this function can be called when the screen should be updated.
*/
void lv_refr_now(void);
/**
* Invalidate an area
* @param area_p pointer to area which should be invalidated
*/
void lv_inv_area(const lv_area_t * area_p);
/**
* Set a function to call after every refresh to announce the refresh time and the number of refreshed pixels
* @param cb pointer to a callback function (void my_refr_cb(uint32_t time_ms, uint32_t px_num))
*/
void lv_refr_set_monitor_cb(void (*cb)(uint32_t, uint32_t));
/**
* Called when an area is invalidated to modify the coordinates of the area.
* Special display controllers may require special coordinate rounding
* @param cb pointer to the a function which will modify the area
*/
void lv_refr_set_round_cb(void(*cb)(lv_area_t*));
/**
* Get the number of areas in the buffer
* @return number of invalid areas
*/
uint16_t lv_refr_get_buf_size(void);
/**
* Pop (delete) the last 'num' invalidated areas from the buffer
* @param num number of areas to delete
*/
void lv_refr_pop_from_buf(uint16_t num);
/**********************
* STATIC FUNCTIONS
**********************/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_REFR_H*/

View File

@ -1,346 +0,0 @@
/**
* @file lv_style.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_obj.h"
#include "../lv_misc/lv_mem.h"
/*********************
* DEFINES
*********************/
#define STYLE_MIX_MAX 256
#define STYLE_MIX_SHIFT 8 /*log2(STYLE_MIX_MAX)*/
#define VAL_PROP(v1, v2, r) v1 + (((v2-v1) * r) >> STYLE_MIX_SHIFT)
#define STYLE_ATTR_MIX(attr, r) if(start->attr != end->attr) {res->attr = VAL_PROP(start->attr, end->attr, r);} else {res->attr = start->attr;}
/**********************
* TYPEDEFS
**********************/
#if USE_LV_ANIMATION
typedef struct {
lv_style_t style_start; /*Save not only pointers because can be same as 'style_anim' then it will be modified too*/
lv_style_t style_end;
lv_style_t * style_anim;
void (*end_cb)(void *);
} lv_style_anim_dsc_t;
#endif
/**********************
* STATIC PROTOTYPES
**********************/
#if USE_LV_ANIMATION
static void style_animator(lv_style_anim_dsc_t * dsc, int32_t val);
static void style_animation_common_end_cb(void * ptr);
#endif
/**********************
* STATIC VARIABLES
**********************/
lv_style_t lv_style_scr;
lv_style_t lv_style_transp;
lv_style_t lv_style_transp_fit;
lv_style_t lv_style_transp_tight;
lv_style_t lv_style_plain;
lv_style_t lv_style_plain_color;
lv_style_t lv_style_pretty;
lv_style_t lv_style_pretty_color;
lv_style_t lv_style_btn_rel;
lv_style_t lv_style_btn_pr;
lv_style_t lv_style_btn_tgl_rel;
lv_style_t lv_style_btn_tgl_pr;
lv_style_t lv_style_btn_ina;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Init the basic styles
*/
void lv_style_init(void)
{
/* Not White/Black/Gray colors are created by HSV model with
* HUE = 210*/
/*Screen style*/
lv_style_scr.glass = 0;
lv_style_scr.body.opa = LV_OPA_COVER;
lv_style_scr.body.main_color = LV_COLOR_WHITE;
lv_style_scr.body.grad_color = LV_COLOR_WHITE;
lv_style_scr.body.radius = 0;
lv_style_scr.body.padding.ver = LV_DPI / 12;
lv_style_scr.body.padding.hor = LV_DPI / 12;
lv_style_scr.body.padding.inner = LV_DPI / 12;
lv_style_scr.body.border.color = LV_COLOR_BLACK;
lv_style_scr.body.border.opa = LV_OPA_COVER;
lv_style_scr.body.border.width = 0;
lv_style_scr.body.border.part = LV_BORDER_FULL;
lv_style_scr.body.shadow.color = LV_COLOR_GRAY;
lv_style_scr.body.shadow.type = LV_SHADOW_FULL;
lv_style_scr.body.shadow.width = 0;
lv_style_scr.text.opa = LV_OPA_COVER;
lv_style_scr.text.color = LV_COLOR_MAKE(0x30, 0x30, 0x30);
lv_style_scr.text.font = LV_FONT_DEFAULT;
lv_style_scr.text.letter_space = 2;
lv_style_scr.text.line_space = 2;
lv_style_scr.image.opa = LV_OPA_COVER;
lv_style_scr.image.color = LV_COLOR_MAKE(0x20, 0x20, 0x20);
lv_style_scr.image.intense = LV_OPA_TRANSP;
lv_style_scr.line.opa = LV_OPA_COVER;
lv_style_scr.line.color = LV_COLOR_MAKE(0x20, 0x20, 0x20);
lv_style_scr.line.width = 2;
lv_style_scr.line.rounded = 0;
/*Plain style (by default near the same as the screen style)*/
memcpy(&lv_style_plain, &lv_style_scr, sizeof(lv_style_t));
/*Plain color style*/
memcpy(&lv_style_plain_color, &lv_style_plain, sizeof(lv_style_t));
lv_style_plain_color.text.color = LV_COLOR_MAKE(0xf0, 0xf0, 0xf0);
lv_style_plain_color.image.color = LV_COLOR_MAKE(0xf0, 0xf0, 0xf0);
lv_style_plain_color.line.color = LV_COLOR_MAKE(0xf0, 0xf0, 0xf0);
lv_style_plain_color.body.main_color = LV_COLOR_MAKE(0x55, 0x96, 0xd8);
lv_style_plain_color.body.grad_color = lv_style_plain_color.body.main_color;
/*Pretty style */
memcpy(&lv_style_pretty, &lv_style_plain, sizeof(lv_style_t));
lv_style_pretty.text.color = LV_COLOR_MAKE(0x20, 0x20, 0x20);
lv_style_pretty.image.color = LV_COLOR_MAKE(0x20, 0x20, 0x20);
lv_style_pretty.line.color = LV_COLOR_MAKE(0x20, 0x20, 0x20);
lv_style_pretty.body.main_color = LV_COLOR_WHITE;
lv_style_pretty.body.grad_color = LV_COLOR_SILVER;
lv_style_pretty.body.radius = LV_DPI / 15;
lv_style_pretty.body.border.color = LV_COLOR_MAKE(0x40, 0x40, 0x40);
lv_style_pretty.body.border.width = LV_DPI / 50 >= 1 ? LV_DPI / 50 : 1;
lv_style_pretty.body.border.opa = LV_OPA_30;
/*Pretty color style*/
memcpy(&lv_style_pretty_color, &lv_style_pretty, sizeof(lv_style_t));
lv_style_pretty_color.text.color = LV_COLOR_MAKE(0xe0, 0xe0, 0xe0);
lv_style_pretty_color.image.color = LV_COLOR_MAKE(0xe0, 0xe0, 0xe0);
lv_style_pretty_color.line.color = LV_COLOR_MAKE(0xc0, 0xc0, 0xc0);
lv_style_pretty_color.body.main_color = LV_COLOR_MAKE(0x6b, 0x9a, 0xc7);
lv_style_pretty_color.body.grad_color = LV_COLOR_MAKE(0x2b, 0x59, 0x8b);
lv_style_pretty_color.body.border.color = LV_COLOR_MAKE(0x15, 0x2c, 0x42);
/*Transparent style*/
memcpy(&lv_style_transp, &lv_style_plain, sizeof(lv_style_t));
lv_style_transp.body.empty = 1;
lv_style_transp.glass = 1;
lv_style_transp.body.border.width = 0;
/*Transparent fitting size*/
memcpy(&lv_style_transp_fit, &lv_style_transp, sizeof(lv_style_t));
lv_style_transp_fit.body.padding.hor = 0;
lv_style_transp_fit.body.padding.ver = 0;
/*Transparent tight style*/
memcpy(&lv_style_transp_tight, &lv_style_transp_fit, sizeof(lv_style_t));
lv_style_transp_tight.body.padding.inner = 0;
/*Button released style*/
memcpy(&lv_style_btn_rel, &lv_style_plain, sizeof(lv_style_t));
lv_style_btn_rel.body.main_color = LV_COLOR_MAKE(0x76, 0xa2, 0xd0);
lv_style_btn_rel.body.grad_color = LV_COLOR_MAKE(0x19, 0x3a, 0x5d);
lv_style_btn_rel.body.radius = LV_DPI / 15;
lv_style_btn_rel.body.padding.hor = LV_DPI / 4;
lv_style_btn_rel.body.padding.ver = LV_DPI / 6;
lv_style_btn_rel.body.padding.inner = LV_DPI / 10;
lv_style_btn_rel.body.border.color = LV_COLOR_MAKE(0x0b, 0x19, 0x28);
lv_style_btn_rel.body.border.width = LV_DPI / 50 >= 1 ? LV_DPI / 50 : 1;
lv_style_btn_rel.body.border.opa = LV_OPA_70;
lv_style_btn_rel.body.shadow.color = LV_COLOR_GRAY;
lv_style_btn_rel.body.shadow.width = 0;
lv_style_btn_rel.text.color = LV_COLOR_MAKE(0xff, 0xff, 0xff);
lv_style_btn_rel.image.color = LV_COLOR_MAKE(0xff, 0xff, 0xff);
/*Button pressed style*/
memcpy(&lv_style_btn_pr, &lv_style_btn_rel, sizeof(lv_style_t));
lv_style_btn_pr.body.main_color = LV_COLOR_MAKE(0x33, 0x62, 0x94);
lv_style_btn_pr.body.grad_color = LV_COLOR_MAKE(0x10, 0x26, 0x3c);
lv_style_btn_pr.text.color = LV_COLOR_MAKE(0xa4, 0xb5, 0xc6);
lv_style_btn_pr.image.color = LV_COLOR_MAKE(0xa4, 0xb5, 0xc6);
lv_style_btn_pr.line.color = LV_COLOR_MAKE(0xa4, 0xb5, 0xc6);
/*Button toggle released style*/
memcpy(&lv_style_btn_tgl_rel, &lv_style_btn_rel, sizeof(lv_style_t));
lv_style_btn_tgl_rel.body.main_color = LV_COLOR_MAKE(0x0a, 0x11, 0x22);
lv_style_btn_tgl_rel.body.grad_color = LV_COLOR_MAKE(0x37, 0x62, 0x90);
lv_style_btn_tgl_rel.body.border.color = LV_COLOR_MAKE(0x01, 0x07, 0x0d);
lv_style_btn_tgl_rel.text.color = LV_COLOR_MAKE(0xc8, 0xdd, 0xf4);
lv_style_btn_tgl_rel.image.color = LV_COLOR_MAKE(0xc8, 0xdd, 0xf4);
lv_style_btn_tgl_rel.line.color = LV_COLOR_MAKE(0xc8, 0xdd, 0xf4);
/*Button toggle pressed style*/
memcpy(&lv_style_btn_tgl_pr, &lv_style_btn_tgl_rel, sizeof(lv_style_t));
lv_style_btn_tgl_pr.body.main_color = LV_COLOR_MAKE(0x02, 0x14, 0x27);
lv_style_btn_tgl_pr.body.grad_color = LV_COLOR_MAKE(0x2b, 0x4c, 0x70);
lv_style_btn_tgl_pr.text.color = LV_COLOR_MAKE(0xa4, 0xb5, 0xc6);
lv_style_btn_tgl_pr.image.color = LV_COLOR_MAKE(0xa4, 0xb5, 0xc6);
lv_style_btn_tgl_pr.line.color = LV_COLOR_MAKE(0xa4, 0xb5, 0xc6);
/*Button inactive style*/
memcpy(&lv_style_btn_ina, &lv_style_btn_rel, sizeof(lv_style_t));
lv_style_btn_ina.body.main_color = LV_COLOR_MAKE(0xd8, 0xd8, 0xd8);
lv_style_btn_ina.body.grad_color = LV_COLOR_MAKE(0xd8, 0xd8, 0xd8);
lv_style_btn_ina.body.border.color = LV_COLOR_MAKE(0x90, 0x90, 0x90);
lv_style_btn_ina.text.color = LV_COLOR_MAKE(0x70, 0x70, 0x70);
lv_style_btn_ina.image.color = LV_COLOR_MAKE(0x70, 0x70, 0x70);
lv_style_btn_ina.line.color = LV_COLOR_MAKE(0x70, 0x70, 0x70);
}
/**
* Copy a style to an other
* @param dest pointer to the destination style
* @param src pointer to the source style
*/
void lv_style_copy(lv_style_t * dest, const lv_style_t * src)
{
memcpy(dest, src, sizeof(lv_style_t));
}
/**
* Mix two styles according to a given ratio
* @param start start style
* @param end end style
* @param res store the result style here
* @param ratio the ratio of mix [0..256]; 0: `start` style; 256: `end` style
*/
void lv_style_mix(const lv_style_t * start, const lv_style_t * end, lv_style_t * res, uint16_t ratio)
{
STYLE_ATTR_MIX(body.opa, ratio);
STYLE_ATTR_MIX(body.radius, ratio);
STYLE_ATTR_MIX(body.border.width, ratio);
STYLE_ATTR_MIX(body.border.opa, ratio);
STYLE_ATTR_MIX(body.shadow.width, ratio);
STYLE_ATTR_MIX(body.padding.hor, ratio);
STYLE_ATTR_MIX(body.padding.ver, ratio);
STYLE_ATTR_MIX(body.padding.inner, ratio);
STYLE_ATTR_MIX(text.line_space, ratio);
STYLE_ATTR_MIX(text.letter_space, ratio);
STYLE_ATTR_MIX(text.opa, ratio);
STYLE_ATTR_MIX(line.width, ratio);
STYLE_ATTR_MIX(line.opa, ratio);
STYLE_ATTR_MIX(image.intense, ratio);
STYLE_ATTR_MIX(image.opa, ratio);
lv_opa_t opa = ratio == STYLE_MIX_MAX ? LV_OPA_COVER : ratio;
res->body.main_color = lv_color_mix(end->body.main_color, start->body.main_color, opa);
res->body.grad_color = lv_color_mix(end->body.grad_color, start->body.grad_color, opa);
res->body.border.color = lv_color_mix(end->body.border.color, start->body.border.color, opa);
res->body.shadow.color = lv_color_mix(end->body.shadow.color, start->body.shadow.color, opa);
res->text.color = lv_color_mix(end->text.color, start->text.color, opa);
res->image.color = lv_color_mix(end->image.color, start->image.color, opa);
res->line.color = lv_color_mix(end->line.color, start->line.color, opa);
if(ratio < (STYLE_MIX_MAX >> 1)) {
res->body.empty = start->body.empty;
res->body.border.part = start->body.border.part;
res->glass = start->glass;
res->text.font = start->text.font;
res->body.shadow.type = start->body.shadow.type;
res->line.rounded = start->line.rounded;
} else {
res->body.empty = end->body.empty;
res->body.border.part = end->body.border.part;
res->glass = end->glass;
res->text.font = end->text.font;
res->body.shadow.type = end->body.shadow.type;
res->line.rounded = end->line.rounded;
}
}
#if USE_LV_ANIMATION
/**
* Create an animation from a pre-configured 'lv_style_anim_t' variable
* @param anim pointer to a pre-configured 'lv_style_anim_t' variable (will be copied)
* @return pointer to a descriptor. Really this variable will be animated. (Can be used in `lv_anim_del(dsc, NULL)`)
*/
void * lv_style_anim_create(lv_style_anim_t * anim)
{
lv_style_anim_dsc_t * dsc;
dsc = lv_mem_alloc(sizeof(lv_style_anim_dsc_t));
lv_mem_assert(dsc);
if(dsc == NULL) return NULL;
dsc->style_anim = anim->style_anim;
memcpy(&dsc->style_start, anim->style_start, sizeof(lv_style_t));
memcpy(&dsc->style_end, anim->style_end, sizeof(lv_style_t));
memcpy(dsc->style_anim, anim->style_start, sizeof(lv_style_t));
dsc->end_cb = anim->end_cb;
lv_anim_t a;
a.var = (void *)dsc;
a.start = 0;
a.end = STYLE_MIX_MAX;
a.fp = (lv_anim_fp_t)style_animator;
a.path = lv_anim_path_linear;
a.end_cb = style_animation_common_end_cb;
a.act_time = anim->act_time;
a.time = anim->time;
a.playback = anim->playback;
a.playback_pause = anim->playback_pause;
a.repeat = anim->repeat;
a.repeat_pause = anim->repeat_pause;
lv_anim_create(&a);
return dsc;
}
#endif
/**********************
* STATIC FUNCTIONS
**********************/
#if USE_LV_ANIMATION
/**
* Used by the style animations to set the values of a style according to start and end style.
* @param dsc the 'animated variable' set by lv_style_anim_create()
* @param val the current state of the animation between 0 and LV_STYLE_ANIM_RES
*/
static void style_animator(lv_style_anim_dsc_t * dsc, int32_t val)
{
const lv_style_t * start = &dsc->style_start;
const lv_style_t * end = &dsc->style_end;
lv_style_t * act = dsc->style_anim;
lv_style_mix(start, end, act, val);
lv_obj_report_style_mod(dsc->style_anim);
}
/**
* Called when a style animation is ready
* It called the user defined call back and free the allocated memories
* @param ptr the 'animated variable' set by lv_style_anim_create()
*/
static void style_animation_common_end_cb(void * ptr)
{
lv_style_anim_dsc_t * dsc = ptr; /*To avoid casting*/
if(dsc->end_cb) dsc->end_cb(dsc);
lv_mem_free(dsc);
}
#endif

View File

@ -1,199 +0,0 @@
/**
* @file lv_style.h
*
*/
#ifndef LV_STYLE_H
#define LV_STYLE_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include <stdbool.h>
#include "../lv_misc/lv_color.h"
#include "../lv_misc/lv_area.h"
#include "../lv_misc/lv_font.h"
#include "../lv_misc/lv_anim.h"
/*********************
* DEFINES
*********************/
#define LV_RADIUS_CIRCLE (LV_COORD_MAX) /*A very big radius to always draw as circle*/
/**********************
* TYPEDEFS
**********************/
/*Border types (Use 'OR'ed values)*/
enum
{
LV_BORDER_NONE = 0x00,
LV_BORDER_BOTTOM = 0x01,
LV_BORDER_TOP = 0x02,
LV_BORDER_LEFT = 0x04,
LV_BORDER_RIGHT = 0x08,
LV_BORDER_FULL = 0x0F,
LV_BORDER_INTERNAL = 0x10, /*FOR matrix-like objects (e.g. Button matrix)*/
};
typedef uint8_t lv_border_part_t;
/*Shadow types*/
enum
{
LV_SHADOW_BOTTOM = 0,
LV_SHADOW_FULL,
};
typedef uint8_t lv_shadow_type_t;
typedef struct
{
uint8_t glass :1; /*1: Do not inherit this style*/
struct {
lv_color_t main_color;
lv_color_t grad_color; /*`grad_color` will be removed in v6.0, use `aux_color` instead*/
lv_coord_t radius;
lv_opa_t opa;
struct {
lv_color_t color;
lv_coord_t width;
lv_border_part_t part;
lv_opa_t opa;
} border;
struct {
lv_color_t color;
lv_coord_t width;
lv_shadow_type_t type;
} shadow;
struct {
lv_coord_t ver;
lv_coord_t hor;
lv_coord_t inner;
} padding;
uint8_t empty :1; /*Transparent background (border still drawn)*/
} body;
struct {
lv_color_t color;
const lv_font_t * font;
lv_coord_t letter_space;
lv_coord_t line_space;
lv_opa_t opa;
} text;
struct {
lv_color_t color;
lv_opa_t intense;
lv_opa_t opa;
} image;
struct {
lv_color_t color;
lv_coord_t width;
lv_opa_t opa;
uint8_t rounded :1; /*1: rounded line endings*/
} line;
} lv_style_t;
#if USE_LV_ANIMATION
typedef struct {
const lv_style_t * style_start; /*Pointer to the starting style*/
const lv_style_t * style_end; /*Pointer to the destination style*/
lv_style_t * style_anim; /*Pointer to a style to animate*/
lv_anim_cb_t end_cb; /*Call it when the animation is ready (NULL if unused)*/
int16_t time; /*Animation time in ms*/
int16_t act_time; /*Current time in animation. Set to negative to make delay.*/
uint16_t playback_pause; /*Wait before play back*/
uint16_t repeat_pause; /*Wait before repeat*/
uint8_t playback :1; /*When the animation is ready play it back*/
uint8_t repeat :1; /*Repeat the animation infinitely*/
} lv_style_anim_t;
/* Example initialization
lv_style_anim_t a;
a.style_anim = &style_to_anim;
a.style_start = &style_1;
a.style_end = &style_2;
a.act_time = 0;
a.time = 1000;
a.playback = 0;
a.playback_pause = 0;
a.repeat = 0;
a.repeat_pause = 0;
a.end_cb = NULL;
lv_style_anim_create(&a);
*/
#endif
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Init the basic styles
*/
void lv_style_init (void);
/**
* Copy a style to an other
* @param dest pointer to the destination style
* @param src pointer to the source style
*/
void lv_style_copy(lv_style_t * dest, const lv_style_t * src);
/**
* Mix two styles according to a given ratio
* @param start start style
* @param end end style
* @param res store the result style here
* @param ratio the ratio of mix [0..256]; 0: `start` style; 256: `end` style
*/
void lv_style_mix(const lv_style_t * start, const lv_style_t * end, lv_style_t * res, uint16_t ratio);
#if USE_LV_ANIMATION
/**
* Create an animation from a pre-configured 'lv_style_anim_t' variable
* @param anim pointer to a pre-configured 'lv_style_anim_t' variable (will be copied)
* @return pointer to a descriptor. Really this variable will be animated. (Can be used in `lv_anim_del(dsc, NULL)`)
*/
void * lv_style_anim_create(lv_style_anim_t * anim);
#endif
/*************************
* GLOBAL VARIABLES
*************************/
extern lv_style_t lv_style_scr;
extern lv_style_t lv_style_transp;
extern lv_style_t lv_style_transp_fit;
extern lv_style_t lv_style_transp_tight;
extern lv_style_t lv_style_plain;
extern lv_style_t lv_style_plain_color;
extern lv_style_t lv_style_pretty;
extern lv_style_t lv_style_pretty_color;
extern lv_style_t lv_style_btn_rel;
extern lv_style_t lv_style_btn_pr;
extern lv_style_t lv_style_btn_tgl_rel;
extern lv_style_t lv_style_btn_tgl_pr;
extern lv_style_t lv_style_btn_ina;
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_STYLE_H*/

View File

@ -1,207 +0,0 @@
/**
* @file lv_vdb.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_vdb.h"
#if LV_VDB_SIZE != 0
#include "../lv_hal/lv_hal_disp.h"
#include "../lv_misc/lv_log.h"
#include <stddef.h>
/*********************
* DEFINES
*********************/
#ifndef LV_ATTRIBUTE_FLUSH_READY
#define LV_ATTRIBUTE_FLUSH_READY
#endif
#ifndef LV_ATTRIBUTE_MEM_ALIGN
#define LV_ATTRIBUTE_MEM_ALIGN
#endif
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
/*Simple VDB*/
#if LV_VDB_DOUBLE == 0
# if LV_VDB_ADR == 0
/*If the buffer address is not specified simply allocate it*/
static LV_ATTRIBUTE_MEM_ALIGN uint8_t vdb_buf[LV_VDB_SIZE_IN_BYTES];
static lv_vdb_t vdb = {.buf = (lv_color_t *)vdb_buf};
# else /*LV_VDB_ADR != 0*/
/*If the buffer address is specified use that address*/
static lv_vdb_t vdb = {.buf = (lv_color_t *)LV_VDB_ADR};
# endif
/*LV_VDB_DOUBLE != 0*/
#else
/*Double VDB*/
static uint8_t vdb_active = 0;
# if LV_VDB_ADR == 0
/*If the buffer address is not specified simply allocate it*/
static LV_ATTRIBUTE_MEM_ALIGN uint8_t vdb_buf1[LV_VDB_SIZE_IN_BYTES];
static LV_ATTRIBUTE_MEM_ALIGN uint8_t vdb_buf2[LV_VDB_SIZE_IN_BYTES];
static lv_vdb_t vdb[2] = {{.buf = (lv_color_t *) vdb_buf1}, {.buf = (lv_color_t *) vdb_buf2}};
# else /*LV_VDB_ADR != 0*/
/*If the buffer address is specified use that address*/
static lv_vdb_t vdb[2] = {{.buf = (lv_color_t *)LV_VDB_ADR}, {.buf = (lv_color_t *)LV_VDB2_ADR}};
# endif
#endif
static volatile bool vdb_flushing = false;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Get the 'vdb' variable or allocate one in LV_VDB_DOUBLE mode
* @return pointer to a 'vdb' variable
*/
lv_vdb_t * lv_vdb_get(void)
{
#if LV_VDB_DOUBLE == 0
/* Wait until VDB is flushing.
* (Until this user calls of 'lv_flush_ready()' in the display drivers's flush function*/
while(vdb_flushing);
return &vdb;
#else
/*If already there is an active do nothing*/
return &vdb[vdb_active];
#endif
}
/**
* Flush the content of the VDB
*/
void lv_vdb_flush(void)
{
lv_vdb_t * vdb_act = lv_vdb_get();
if(!vdb_act) {
LV_LOG_WARN("Invalid VDB pointer");
return;
}
/*Don't start a new flush while the previous is not finished*/
#if LV_VDB_DOUBLE
while(vdb_flushing);
#endif /*LV_VDB_DOUBLE*/
vdb_flushing = true;
/*Flush the rendered content to the display*/
lv_disp_flush(vdb_act->area.x1, vdb_act->area.y1, vdb_act->area.x2, vdb_act->area.y2, vdb_act->buf);
#if LV_VDB_DOUBLE
/*Make the other VDB active. The content of the current will be kept until the next flush*/
vdb_active++;
vdb_active &= 0x1;
/*If the screen is transparent initialize it when the new VDB is selected*/
# if LV_COLOR_SCREEN_TRANSP
memset(vdb[vdb_active].buf, 0x00, LV_VDB_SIZE_IN_BYTES);
# endif /*LV_COLOR_SCREEN_TRANSP*/
#endif /*#if LV_VDB_DOUBLE*/
}
/**
* Set the address of VDB buffer(s) manually. To use this set `LV_VDB_ADR` (and `LV_VDB2_ADR`) to `LV_VDB_ADR_INV` in `lv_conf.h`.
* It should be called before `lv_init()`. The size of the buffer should be: `LV_VDB_SIZE_IN_BYTES`
* @param buf1 address of the VDB.
* @param buf2 address of the second buffer. `NULL` if `LV_VDB_DOUBLE 0`
*/
void lv_vdb_set_adr(void * buf1, void * buf2)
{
#if LV_VDB_DOUBLE == 0
(void) buf2; /*unused*/
vdb.buf = buf1;
#else
vdb[0].buf = buf1;
vdb[1].buf = buf2;
#endif
}
/**
* Call in the display driver's 'disp_flush' function when the flushing is finished
*/
LV_ATTRIBUTE_FLUSH_READY void lv_flush_ready(void)
{
vdb_flushing = false;
/*If the screen is transparent initialize it when the flushing is ready*/
#if LV_VDB_DOUBLE == 0 && LV_COLOR_SCREEN_TRANSP
memset(vdb_buf, 0x00, LV_VDB_SIZE_IN_BYTES);
#endif
}
/**
* Get currently active VDB, where the drawing happens. Used with `LV_VDB_DOUBLE 1`
* @return pointer to the active VDB. If `LV_VDB_DOUBLE 0` give the single VDB
*/
lv_vdb_t * lv_vdb_get_active(void)
{
#if LV_VDB_DOUBLE == 0
return &vdb;
#else
return &vdb[vdb_active];
#endif
}
/**
* Get currently inactive VDB, which is being displayed or being flushed. Used with `LV_VDB_DOUBLE 1`
* @return pointer to the inactive VDB. If `LV_VDB_DOUBLE 0` give the single VDB
*/
lv_vdb_t * lv_vdb_get_inactive(void)
{
#if LV_VDB_DOUBLE == 0
return &vdb;
#else
return &vdb[(vdb_active + 1) & 0x1];
#endif
}
/**
* Whether the flushing is in progress or not
* @return true: flushing is in progress; false: flushing ready
*/
bool lv_vdb_is_flushing(void)
{
return vdb_flushing;
}
/**********************
* STATIC FUNCTIONS
**********************/
#else
/**
* Just for compatibility
*/
void lv_flush_ready(void)
{
/*Do nothing. It is used only for VDB*/
}
#endif

View File

@ -1,119 +0,0 @@
/**
* @file lv_vdb.h
*
*/
#ifndef LV_VDB_H
#define LV_VDB_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_conf.h"
#else
#include "../../lv_conf.h"
#endif
#if LV_VDB_SIZE != 0
#include "../lv_misc/lv_color.h"
#include "../lv_misc/lv_area.h"
/*********************
* DEFINES
*********************/
/*Can be used in `lv_conf.h` the set an invalid address for the VDB. It should be replaced later by a valid address using `lv_vdb_set_adr()`*/
#define LV_VDB_ADR_INV 8 /*8 is still too small to be valid but it's aligned on 64 bit machines as well*/
#ifndef LV_VDB_PX_BPP
#define LV_VDB_PX_BPP LV_COLOR_SIZE /* Default is LV_COLOR_SIZE */
#endif
#if LV_VDB_TRUE_DOUBLE_BUFFERED && (LV_VDB_SIZE != LV_HOR_RES * LV_VER_RES || LV_VDB_DOUBLE == 0)
#error "With LV_VDB_TRUE_DOUBLE_BUFFERED: (LV_VDB_SIZE = LV_HOR_RES * LV_VER_RES and LV_VDB_DOUBLE = 1 is required"
#endif
/* The size of VDB in bytes.
* (LV_VDB_SIZE * LV_VDB_PX_BPP) >> 3): just divide by 8 to convert bits to bytes
* (((LV_VDB_SIZE * LV_VDB_PX_BPP) & 0x7) ? 1 : 0): add an extra byte to round up.
* E.g. if LV_VDB_SIZE = 10 and LV_VDB_PX_BPP = 1 -> 10 bits -> 2 bytes*/
#define LV_VDB_SIZE_IN_BYTES ((LV_VDB_SIZE * LV_VDB_PX_BPP) >> 3) + (((LV_VDB_SIZE * LV_VDB_PX_BPP) & 0x7) ? 1 : 0)
/**********************
* TYPEDEFS
**********************/
typedef struct
{
lv_area_t area;
lv_color_t *buf;
} lv_vdb_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Get the 'vdb' variable or allocate one in LV_VDB_DOUBLE mode
* @return pointer to a 'vdb' variable
*/
lv_vdb_t * lv_vdb_get(void);
/**
* Flush the content of the vdb
*/
void lv_vdb_flush(void);
/**
* Set the address of VDB buffer(s) manually. To use this set `LV_VDB_ADR` (and `LV_VDB2_ADR`) to `LV_VDB_ADR_INV` in `lv_conf.h`.
* It should be called before `lv_init()`. The size of the buffer should be: `LV_VDB_SIZE_IN_BYTES`
* @param buf1 address of the VDB.
* @param buf2 address of the second buffer. `NULL` if `LV_VDB_DOUBLE 0`
*/
void lv_vdb_set_adr(void * buf1, void * buf2);
/**
* Call in the display driver's 'disp_flush' function when the flushing is finished
*/
void lv_flush_ready(void);
/**
* Get currently active VDB, where the drawing happens. Used with `LV_VDB_DOUBLE 1`
* @return pointer to the active VDB. If `LV_VDB_DOUBLE 0` give the single VDB
*/
lv_vdb_t * lv_vdb_get_active(void);
/**
* Get currently inactive VDB, which is being displayed or being flushed. Used with `LV_VDB_DOUBLE 1`
* @return pointer to the inactive VDB. If `LV_VDB_DOUBLE 0` give the single VDB
*/
lv_vdb_t * lv_vdb_get_inactive(void);
/**
* Whether the flushing is in progress or not
* @return true: flushing is in progress; false: flushing ready
*/
bool lv_vdb_is_flushing(void);
/**********************
* MACROS
**********************/
#else /*LV_VDB_SIZE != 0*/
/*Just for compatibility*/
void lv_flush_ready(void);
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_VDB_H*/

View File

@ -1,14 +0,0 @@
CSRCS += lv_draw_vbasic.c
CSRCS += lv_draw_rbasic.c
CSRCS += lv_draw.c
CSRCS += lv_draw_rect.c
CSRCS += lv_draw_label.c
CSRCS += lv_draw_line.c
CSRCS += lv_draw_img.c
CSRCS += lv_draw_arc.c
CSRCS += lv_draw_triangle.c
DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_draw
VPATH += :$(LVGL_DIR)/lvgl/lv_draw
CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_draw"

View File

@ -1,759 +0,0 @@
/**
* @file lv_draw_img.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_draw_img.h"
#include "../lv_misc/lv_fs.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mask,
const void * src, const lv_style_t * style, lv_opa_t opa_scale);
static const uint8_t * lv_img_decoder_open(const void * src, const lv_style_t * style);
static lv_res_t lv_img_decoder_read_line(lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf);
static void lv_img_decoder_close(void);
static lv_res_t lv_img_built_in_decoder_line_alpha(lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf);
static lv_res_t lv_img_built_in_decoder_line_indexed(lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf);
/**********************
* STATIC VARIABLES
**********************/
static bool decoder_custom;
static const void * decoder_src;
static lv_img_src_t decoder_src_type;
static lv_img_header_t decoder_header;
static const lv_style_t * decoder_style;
#if USE_LV_FILESYSTEM
static lv_fs_file_t decoder_file;
#endif
#if LV_IMG_CF_INDEXED
static lv_color_t decoder_index_map[256];
#endif
static lv_img_decoder_info_f_t lv_img_decoder_info_custom;
static lv_img_decoder_open_f_t lv_img_decoder_open_custom;
static lv_img_decoder_read_line_f_t lv_img_decoder_read_line_custom;
static lv_img_decoder_close_f_t lv_img_decoder_close_custom;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Draw an image
* @param coords the coordinates of the image
* @param mask the image will be drawn only in this area
* @param src pointer to a lv_color_t array which contains the pixels of the image
* @param style style of the image
* @param opa_scale scale down all opacities by the factor
*/
void lv_draw_img(const lv_area_t * coords, const lv_area_t * mask,
const void * src, const lv_style_t * style, lv_opa_t opa_scale)
{
if(src == NULL) {
LV_LOG_WARN("Image draw: src is NULL");
lv_draw_rect(coords, mask, &lv_style_plain, LV_OPA_COVER);
lv_draw_label(coords, mask, &lv_style_plain, LV_OPA_COVER, "No\ndata", LV_TXT_FLAG_NONE, NULL);
return;
}
lv_res_t res;
res = lv_img_draw_core(coords, mask, src, style, opa_scale);
if(res == LV_RES_INV) {
LV_LOG_WARN("Image draw error");
lv_draw_rect(coords, mask, &lv_style_plain, LV_OPA_COVER);
lv_draw_label(coords, mask, &lv_style_plain, LV_OPA_COVER, "No\ndata", LV_TXT_FLAG_NONE, NULL);
return;
}
}
/**
*
* @param src
* @param header
* @param style
* @return
*/
lv_res_t lv_img_dsc_get_info(const char * src, lv_img_header_t * header)
{
header->always_zero = 0;
/*Try to get info with the custom functions first*/
if(lv_img_decoder_info_custom) {
lv_res_t custom_res;
custom_res = lv_img_decoder_info_custom(src, header);
if(custom_res == LV_RES_OK) return LV_RES_OK; /*Custom info has supported this source*/
}
lv_img_src_t src_type = lv_img_src_get_type(src);
if(src_type == LV_IMG_SRC_VARIABLE) {
header->w = ((lv_img_dsc_t *)src)->header.w;
header->h = ((lv_img_dsc_t *)src)->header.h;
header->cf = ((lv_img_dsc_t *)src)->header.cf;
}
#if USE_LV_FILESYSTEM
else if(src_type == LV_IMG_SRC_FILE) {
lv_fs_file_t file;
lv_fs_res_t res;
uint32_t rn;
res = lv_fs_open(&file, src, LV_FS_MODE_RD);
if(res == LV_FS_RES_OK) {
res = lv_fs_read(&file, header, sizeof(lv_img_header_t), &rn);
}
/*Create a dummy header on fs error*/
if(res != LV_FS_RES_OK || rn != sizeof(lv_img_header_t)) {
header->w = LV_DPI;
header->h = LV_DPI;
header->cf = LV_IMG_CF_UNKOWN;
}
lv_fs_close(&file);
}
#endif
else if(src_type == LV_IMG_SRC_SYMBOL) {
/*The size depend on the font but it is unknown here. It should be handled outside of the function*/
header->w = 1;
header->h = 1;
/* Symbols always have transparent parts. Important because of cover check in the design function.
* The actual value doesn't matter because lv_draw_label will draw it*/
header->cf = LV_IMG_CF_ALPHA_1BIT;
} else {
LV_LOG_WARN("Image get info found unknown src type");
return false;
}
return true;
}
uint8_t lv_img_color_format_get_px_size(lv_img_cf_t cf)
{
uint8_t px_size = 0;
switch(cf) {
case LV_IMG_CF_UNKOWN:
case LV_IMG_CF_RAW:
px_size = 0;
break;
case LV_IMG_CF_TRUE_COLOR:
case LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED:
px_size = LV_COLOR_SIZE;
break;
case LV_IMG_CF_TRUE_COLOR_ALPHA:
px_size = LV_IMG_PX_SIZE_ALPHA_BYTE << 3;
break;
case LV_IMG_CF_INDEXED_1BIT:
case LV_IMG_CF_ALPHA_1BIT:
px_size = 1;
break;
case LV_IMG_CF_INDEXED_2BIT:
case LV_IMG_CF_ALPHA_2BIT:
px_size = 2;
break;
case LV_IMG_CF_INDEXED_4BIT:
case LV_IMG_CF_ALPHA_4BIT:
px_size = 4;
break;
case LV_IMG_CF_INDEXED_8BIT:
case LV_IMG_CF_ALPHA_8BIT:
px_size = 8;
break;
default:
px_size = 0;
break;
}
return px_size;
}
bool lv_img_color_format_is_chroma_keyed(lv_img_cf_t cf)
{
bool is_chroma_keyed = false;
switch(cf) {
case LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED:
case LV_IMG_CF_RAW_CHROMA_KEYED:
case LV_IMG_CF_INDEXED_1BIT:
case LV_IMG_CF_INDEXED_2BIT:
case LV_IMG_CF_INDEXED_4BIT:
case LV_IMG_CF_INDEXED_8BIT:
is_chroma_keyed = true;
break;
default:
is_chroma_keyed = false;
break;
}
return is_chroma_keyed;
}
bool lv_img_color_format_has_alpha(lv_img_cf_t cf)
{
bool has_alpha = false;
switch(cf) {
case LV_IMG_CF_TRUE_COLOR_ALPHA:
case LV_IMG_CF_RAW_ALPHA:
case LV_IMG_CF_ALPHA_1BIT:
case LV_IMG_CF_ALPHA_2BIT:
case LV_IMG_CF_ALPHA_4BIT:
case LV_IMG_CF_ALPHA_8BIT:
has_alpha = true;
break;
default:
has_alpha = false;
break;
}
return has_alpha;
}
/**
* Get the type of an image source
* @param src pointer to an image source:
* - pointer to an 'lv_img_t' variable (image stored internally and compiled into the code)
* - a path to a file (e.g. "S:/folder/image.bin")
* - or a symbol (e.g. SYMBOL_CLOSE)
* @return type of the image source LV_IMG_SRC_VARIABLE/FILE/SYMBOL/UNKOWN
*/
lv_img_src_t lv_img_src_get_type(const void * src)
{
lv_img_src_t img_src_type = LV_IMG_SRC_UNKNOWN;
if(src == NULL) return img_src_type;
const uint8_t * u8_p = src;
/*The first byte shows the type of the image source*/
if(u8_p[0] >= 0x20 && u8_p[0] <= 0x7F) {
img_src_type = LV_IMG_SRC_FILE; /*If it's an ASCII character then it's file name*/
} else if(u8_p[0] >= 0x80) {
img_src_type = LV_IMG_SRC_SYMBOL; /*Symbols begins after 0x7F*/
} else {
img_src_type = LV_IMG_SRC_VARIABLE; /*`lv_img_dsc_t` is design to the first byte < 0x20*/
}
if (LV_IMG_SRC_UNKNOWN == img_src_type) {
LV_LOG_WARN("lv_img_src_get_type: unknown image type");
}
return img_src_type;
}
/**
* Set custom decoder functions. See the typdefs of the function typed above for more info about them
* @param info_fp info get function
* @param open_fp open function
* @param read_fp read line function
* @param close_fp clode function
*/
void lv_img_decoder_set_custom(lv_img_decoder_info_f_t info_fp, lv_img_decoder_open_f_t open_fp,
lv_img_decoder_read_line_f_t read_fp, lv_img_decoder_close_f_t close_fp)
{
lv_img_decoder_info_custom = info_fp;
lv_img_decoder_open_custom = open_fp;
lv_img_decoder_read_line_custom = read_fp;
lv_img_decoder_close_custom = close_fp;
}
/**********************
* STATIC FUNCTIONS
**********************/
static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mask,
const void * src, const lv_style_t * style, lv_opa_t opa_scale)
{
lv_area_t mask_com; /*Common area of mask and coords*/
bool union_ok;
union_ok = lv_area_intersect(&mask_com, mask, coords);
if(union_ok == false) {
return LV_RES_OK; /*Out of mask. There is nothing to draw so the image is drawn successfully.*/
}
lv_opa_t opa = opa_scale == LV_OPA_COVER ? style->image.opa : (uint16_t)((uint16_t) style->image.opa * opa_scale) >> 8;
lv_img_header_t header;
lv_res_t header_res;
header_res = lv_img_dsc_get_info(src, &header);
if(header_res != LV_RES_OK) {
LV_LOG_WARN("Image draw can't get image info");
lv_img_decoder_close();
return LV_RES_INV;
}
bool chroma_keyed = lv_img_color_format_is_chroma_keyed(header.cf);
bool alpha_byte = lv_img_color_format_has_alpha(header.cf);
const uint8_t * img_data = lv_img_decoder_open(src, style);
if(img_data == LV_IMG_DECODER_OPEN_FAIL) {
LV_LOG_WARN("Image draw cannot open the image resource");
lv_img_decoder_close();
return LV_RES_INV;
}
/* The decoder open could open the image and gave the entire uncompressed image.
* Just draw it!*/
if(img_data) {
map_fp(coords, mask, img_data, opa, chroma_keyed, alpha_byte, style->image.color, style->image.intense);
}
/* The whole uncompressed image is not available. Try to read it line-by-line*/
else {
lv_coord_t width = lv_area_get_width(&mask_com);
#if LV_COMPILER_VLA_SUPPORTED
uint8_t buf[(lv_area_get_width(&mask_com) * ((LV_COLOR_DEPTH >> 3) + 1))];
#else
uint8_t buf[LV_HOR_RES * ((LV_COLOR_DEPTH >> 3) + 1)]; /*+1 because of the possible alpha byte*/
#endif
lv_area_t line;
lv_area_copy(&line, &mask_com);
lv_area_set_height(&line, 1);
lv_coord_t x = mask_com.x1 - coords->x1;
lv_coord_t y = mask_com.y1 - coords->y1;
lv_coord_t row;
lv_res_t read_res;
for(row = mask_com.y1; row <= mask_com.y2; row++) {
read_res = lv_img_decoder_read_line(x, y, width, buf);
if(read_res != LV_RES_OK) {
lv_img_decoder_close();
LV_LOG_WARN("Image draw can't read the line");
return LV_RES_INV;
}
map_fp(&line, mask, buf, opa, chroma_keyed, alpha_byte, style->image.color, style->image.intense);
line.y1++;
line.y2++;
y++;
}
}
lv_img_decoder_close();
return LV_RES_OK;
}
static const uint8_t * lv_img_decoder_open(const void * src, const lv_style_t * style)
{
decoder_custom = false;
/*Try to open with the custom functions first*/
if(lv_img_decoder_open_custom) {
const uint8_t * custom_res;
custom_res = lv_img_decoder_open_custom(src, style);
if(custom_res != LV_IMG_DECODER_OPEN_FAIL) {
decoder_custom = true; /*Mark that custom decoder function should be used for this img source.*/
return custom_res; /*Custom open supported this source*/
}
}
decoder_src = src;
decoder_style = style;
decoder_src_type = lv_img_src_get_type(src);
lv_res_t header_res;
header_res = lv_img_dsc_get_info(src, &decoder_header);
if(header_res == LV_RES_INV) {
decoder_src = NULL;
decoder_src_type = LV_IMG_SRC_UNKNOWN;
LV_LOG_WARN("Built-in image decoder can't get the header info");
return LV_IMG_DECODER_OPEN_FAIL;
}
/*Open the file if it's a file*/
if(decoder_src_type == LV_IMG_SRC_FILE) {
#if USE_LV_FILESYSTEM
lv_fs_res_t res = lv_fs_open(&decoder_file, src, LV_FS_MODE_RD);
if(res != LV_FS_RES_OK) {
LV_LOG_WARN("Built-in image decoder can't open the file");
return LV_IMG_DECODER_OPEN_FAIL;
}
#else
LV_LOG_WARN("Image built-in decoder can read file because USE_LV_FILESYSTEM = 0");
return LV_IMG_DECODER_OPEN_FAIL;
#endif
}
/*Process the different color formats*/
lv_img_cf_t cf = decoder_header.cf;
if(cf == LV_IMG_CF_TRUE_COLOR ||
cf == LV_IMG_CF_TRUE_COLOR_ALPHA ||
cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED) {
if(decoder_src_type == LV_IMG_SRC_VARIABLE) {
/*In case of uncompressed formats if the image stored in the ROM/RAM simply give it's pointer*/
return ((lv_img_dsc_t *)decoder_src)->data;
} else {
/*If it's file it need to be read line by line later*/
return NULL;
}
} else if(cf == LV_IMG_CF_INDEXED_1BIT ||
cf == LV_IMG_CF_INDEXED_2BIT ||
cf == LV_IMG_CF_INDEXED_4BIT ||
cf == LV_IMG_CF_INDEXED_8BIT) {
#if LV_IMG_CF_INDEXED
#if USE_LV_FILESYSTEM
lv_color32_t palette_file[256];
#endif
lv_color32_t * palette_p = NULL;
uint8_t px_size = lv_img_color_format_get_px_size(cf);
uint32_t palette_size = 1 << px_size;
if(decoder_src_type == LV_IMG_SRC_FILE) {
/*Read the palette from file*/
#if USE_LV_FILESYSTEM
lv_fs_seek(&decoder_file, 4); /*Skip the header*/
lv_fs_read(&decoder_file, palette_file, palette_size * sizeof(lv_color32_t), NULL);
palette_p = palette_file;
#else
LV_LOG_WARN("Image built-in decoder can read the palette because USE_LV_FILESYSTEM = 0");
return LV_IMG_DECODER_OPEN_FAIL;
#endif
} else {
/*The palette begins in the beginning of the image data. Just point to it.*/
palette_p = (lv_color32_t *)((lv_img_dsc_t *)decoder_src)->data;
}
uint32_t i;
for(i = 0; i < palette_size; i++) {
decoder_index_map[i] = LV_COLOR_MAKE(palette_p[i].red, palette_p[i].green, palette_p[i].blue);
}
return NULL;
#else
LV_LOG_WARN("Indexed (palette) images are not enabled in lv_conf.h. See LV_IMG_CF_INDEXED");
return LV_IMG_DECODER_OPEN_FAIL;
#endif
} else if(cf == LV_IMG_CF_ALPHA_1BIT ||
cf == LV_IMG_CF_ALPHA_2BIT ||
cf == LV_IMG_CF_ALPHA_4BIT ||
cf == LV_IMG_CF_ALPHA_8BIT) {
#if LV_IMG_CF_ALPHA
return NULL; /*Nothing to process*/
#else
LV_LOG_WARN("Alpha indexed images are not enabled in lv_conf.h. See LV_IMG_CF_ALPHA");
return LV_IMG_DECODER_OPEN_FAIL;
#endif
} else {
LV_LOG_WARN("Image decoder open: unknown color format")
return LV_IMG_DECODER_OPEN_FAIL;
}
}
static lv_res_t lv_img_decoder_read_line(lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf)
{
/*Try to read the line with the custom functions*/
if(decoder_custom) {
if(lv_img_decoder_read_line_custom) {
lv_res_t custom_res;
custom_res = lv_img_decoder_read_line_custom(x, y, len, buf);
return custom_res;
} else {
LV_LOG_WARN("Image open with custom decoder but read not supported")
}
return LV_RES_INV; /*It"s an error if not returned earlier*/
}
if(decoder_src_type == LV_IMG_SRC_FILE) {
#if USE_LV_FILESYSTEM
uint8_t px_size = lv_img_color_format_get_px_size(decoder_header.cf);
lv_fs_res_t res;
if(decoder_header.cf == LV_IMG_CF_TRUE_COLOR ||
decoder_header.cf == LV_IMG_CF_TRUE_COLOR_ALPHA ||
decoder_header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED) {
uint32_t pos = ((y * decoder_header.w + x) * px_size) >> 3;
pos += 4; /*Skip the header*/
res = lv_fs_seek(&decoder_file, pos);
if(res != LV_FS_RES_OK) {
LV_LOG_WARN("Built-in image decoder seek failed");
return false;
}
uint32_t btr = len * (px_size >> 3);
uint32_t br = 0;
lv_fs_read(&decoder_file, buf, btr, &br);
if(res != LV_FS_RES_OK || btr != br) {
LV_LOG_WARN("Built-in image decoder read failed");
return false;
}
} else if(decoder_header.cf == LV_IMG_CF_ALPHA_1BIT ||
decoder_header.cf == LV_IMG_CF_ALPHA_2BIT ||
decoder_header.cf == LV_IMG_CF_ALPHA_4BIT ||
decoder_header.cf == LV_IMG_CF_ALPHA_8BIT) {
lv_img_built_in_decoder_line_alpha(x, y, len, buf);
} else if(decoder_header.cf == LV_IMG_CF_INDEXED_1BIT ||
decoder_header.cf == LV_IMG_CF_INDEXED_2BIT ||
decoder_header.cf == LV_IMG_CF_INDEXED_4BIT ||
decoder_header.cf == LV_IMG_CF_INDEXED_8BIT) {
lv_img_built_in_decoder_line_indexed(x, y, len, buf);
} else {
LV_LOG_WARN("Built-in image decoder read not supports the color format");
return false;
}
#else
LV_LOG_WARN("Image built-in decoder can't read file because USE_LV_FILESYSTEM = 0");
return false;
#endif
} else if(decoder_src_type == LV_IMG_SRC_VARIABLE) {
const lv_img_dsc_t * img_dsc = decoder_src;
if(img_dsc->header.cf == LV_IMG_CF_ALPHA_1BIT ||
img_dsc->header.cf == LV_IMG_CF_ALPHA_2BIT ||
img_dsc->header.cf == LV_IMG_CF_ALPHA_4BIT ||
img_dsc->header.cf == LV_IMG_CF_ALPHA_8BIT) {
lv_img_built_in_decoder_line_alpha(x, y, len, buf);
} else if(img_dsc->header.cf == LV_IMG_CF_INDEXED_1BIT ||
img_dsc->header.cf == LV_IMG_CF_INDEXED_2BIT ||
img_dsc->header.cf == LV_IMG_CF_INDEXED_4BIT ||
img_dsc->header.cf == LV_IMG_CF_INDEXED_8BIT) {
lv_img_built_in_decoder_line_indexed(x, y, len, buf);
} else {
LV_LOG_WARN("Built-in image decoder not supports the color format");
return false;
}
}
return true;
}
static void lv_img_decoder_close(void)
{
/*Try to close with the custom functions*/
if(decoder_custom) {
if(lv_img_decoder_close_custom) lv_img_decoder_close_custom();
return;
}
/*It was opened with built-in decoder*/
if(decoder_src) {
#if USE_LV_FILESYSTEM
if(decoder_src_type == LV_IMG_SRC_FILE) {
lv_fs_close(&decoder_file);
}
#endif
decoder_src_type = LV_IMG_SRC_UNKNOWN;
decoder_src = NULL;
}
}
static lv_res_t lv_img_built_in_decoder_line_alpha(lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf)
{
#if LV_IMG_CF_ALPHA
const lv_opa_t alpha1_opa_table[2] = {0, 255}; /*Opacity mapping with bpp = 1 (Just for compatibility)*/
const lv_opa_t alpha2_opa_table[4] = {0, 85, 170, 255}; /*Opacity mapping with bpp = 2*/
const lv_opa_t alpha4_opa_table[16] = {0, 17, 34, 51, /*Opacity mapping with bpp = 4*/
68, 85, 102, 119,
136, 153, 170, 187,
204, 221, 238, 255
};
/*Simply fill the buffer with the color. Later only the alpha value will be modified.*/
lv_color_t bg_color = decoder_style->image.color;
lv_coord_t i;
for(i = 0; i < len; i++) {
#if LV_COLOR_DEPTH == 8 || LV_COLOR_DEPTH == 1
buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE] = bg_color.full;
#elif LV_COLOR_DEPTH == 16
/*Because of Alpha byte 16 bit color can start on odd address which can cause crash*/
buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE] = bg_color.full & 0xFF;
buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE + 1] = (bg_color.full >> 8) & 0xFF;
#elif LV_COLOR_DEPTH == 32
*((uint32_t *)&buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE]) = bg_color.full;
#else
#error "Invalid LV_COLOR_DEPTH. Check it in lv_conf.h"
#endif
}
const lv_opa_t * opa_table = NULL;
uint8_t px_size = lv_img_color_format_get_px_size(decoder_header.cf);
uint16_t mask = (1 << px_size) - 1; /*E.g. px_size = 2; mask = 0x03*/
lv_coord_t w = 0;
uint32_t ofs = 0;
int8_t pos = 0;
switch(decoder_header.cf) {
case LV_IMG_CF_ALPHA_1BIT:
w = (decoder_header.w >> 3); /*E.g. w = 20 -> w = 2 + 1*/
if(decoder_header.w & 0x7) w++;
ofs += w * y + (x >> 3); /*First pixel*/
pos = 7 - (x & 0x7);
opa_table = alpha1_opa_table;
break;
case LV_IMG_CF_ALPHA_2BIT:
w = (decoder_header.w >> 2); /*E.g. w = 13 -> w = 3 + 1 (bytes)*/
if(decoder_header.w & 0x3) w++;
ofs += w * y + (x >> 2); /*First pixel*/
pos = 6 - ((x & 0x3) * 2);
opa_table = alpha2_opa_table;
break;
case LV_IMG_CF_ALPHA_4BIT:
w = (decoder_header.w >> 1); /*E.g. w = 13 -> w = 6 + 1 (bytes)*/
if(decoder_header.w & 0x1) w++;
ofs += w * y + (x >> 1); /*First pixel*/
pos = 4 - ((x & 0x1) * 4);
opa_table = alpha4_opa_table;
break;
case LV_IMG_CF_ALPHA_8BIT:
w = decoder_header.w; /*E.g. x = 7 -> w = 7 (bytes)*/
ofs += w * y + x; /*First pixel*/
pos = 0;
break;
}
#if USE_LV_FILESYSTEM
# if LV_COMPILER_VLA_SUPPORTED
uint8_t fs_buf[w];
# else
uint8_t fs_buf[LV_HOR_RES];
# endif
#endif
const uint8_t * data_tmp = NULL;
if(decoder_src_type == LV_IMG_SRC_VARIABLE) {
const lv_img_dsc_t * img_dsc = decoder_src;
data_tmp = img_dsc->data + ofs;
} else {
#if USE_LV_FILESYSTEM
lv_fs_seek(&decoder_file, ofs + 4); /*+4 to skip the header*/
lv_fs_read(&decoder_file, fs_buf, w, NULL);
data_tmp = fs_buf;
#else
LV_LOG_WARN("Image built-in alpha line reader can't read file because USE_LV_FILESYSTEM = 0");
data_tmp = NULL; /*To avoid warnings*/
return LV_RES_INV;
#endif
}
uint8_t byte_act = 0;
uint8_t val_act;
for(i = 0; i < len; i ++) {
val_act = (data_tmp[byte_act] & (mask << pos)) >> pos;
buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE + LV_IMG_PX_SIZE_ALPHA_BYTE - 1] =
decoder_header.cf == LV_IMG_CF_ALPHA_8BIT ? val_act : opa_table[val_act];
pos -= px_size;
if(pos < 0) {
pos = 8 - px_size;
data_tmp++;
}
}
return LV_RES_OK;
#else
LV_LOG_WARN("Image built-in alpha line reader failed because LV_IMG_CF_ALPHA is 0 in lv_conf.h");
return LV_RES_INV;
#endif
}
static lv_res_t lv_img_built_in_decoder_line_indexed(lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf)
{
#if LV_IMG_CF_INDEXED
uint8_t px_size = lv_img_color_format_get_px_size(decoder_header.cf);
uint16_t mask = (1 << px_size) - 1; /*E.g. px_size = 2; mask = 0x03*/
lv_coord_t w = 0;
int8_t pos = 0;
uint32_t ofs = 0;
switch(decoder_header.cf) {
case LV_IMG_CF_INDEXED_1BIT:
w = (decoder_header.w >> 3); /*E.g. w = 20 -> w = 2 + 1*/
if(decoder_header.w & 0x7) w++;
ofs += w * y + (x >> 3); /*First pixel*/
ofs += 8; /*Skip the palette*/
pos = 7 - (x & 0x7);
break;
case LV_IMG_CF_INDEXED_2BIT:
w = (decoder_header.w >> 2); /*E.g. w = 13 -> w = 3 + 1 (bytes)*/
if(decoder_header.w & 0x3) w++;
ofs += w * y + (x >> 2); /*First pixel*/
ofs += 16; /*Skip the palette*/
pos = 6 - ((x & 0x3) * 2);
break;
case LV_IMG_CF_INDEXED_4BIT:
w = (decoder_header.w >> 1); /*E.g. w = 13 -> w = 6 + 1 (bytes)*/
if(decoder_header.w & 0x1) w++;
ofs += w * y + (x >> 1); /*First pixel*/
ofs += 64; /*Skip the palette*/
pos = 4 - ((x & 0x1) * 4);
break;
case LV_IMG_CF_INDEXED_8BIT:
w = decoder_header.w; /*E.g. x = 7 -> w = 7 (bytes)*/
ofs += w * y + x; /*First pixel*/
ofs += 1024; /*Skip the palette*/
pos = 0;
break;
}
#if USE_LV_FILESYSTEM
# if LV_COMPILER_VLA_SUPPORTED
uint8_t fs_buf[w];
# else
uint8_t fs_buf[LV_HOR_RES];
# endif
#endif
const uint8_t * data_tmp = NULL;
if(decoder_src_type == LV_IMG_SRC_VARIABLE) {
const lv_img_dsc_t * img_dsc = decoder_src;
data_tmp = img_dsc->data + ofs;
} else {
#if USE_LV_FILESYSTEM
lv_fs_seek(&decoder_file, ofs + 4); /*+4 to skip the header*/
lv_fs_read(&decoder_file, fs_buf, w, NULL);
data_tmp = fs_buf;
#else
LV_LOG_WARN("Image built-in indexed line reader can't read file because USE_LV_FILESYSTEM = 0");
data_tmp = NULL; /*To avoid warnings*/
return LV_RES_INV;
#endif
}
uint8_t byte_act = 0;
uint8_t val_act;
lv_coord_t i;
lv_color_t * cbuf = (lv_color_t *) buf;
for(i = 0; i < len; i ++) {
val_act = (data_tmp[byte_act] & (mask << pos)) >> pos;
cbuf[i] = decoder_index_map[val_act];
pos -= px_size;
if(pos < 0) {
pos = 8 - px_size;
data_tmp++;
}
}
return LV_RES_OK;
#else
LV_LOG_WARN("Image built-in indexed line reader failed because LV_IMG_CF_INDEXED is 0 in lv_conf.h");
return LV_RES_INV;
#endif
}

View File

@ -1,167 +0,0 @@
/**
* @file lv_draw_img.h
*
*/
#ifndef LV_DRAW_IMG_H
#define LV_DRAW_IMG_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lv_draw.h"
#include "../lv_core/lv_obj.h"
/*********************
* DEFINES
*********************/
#define LV_IMG_DECODER_OPEN_FAIL ((void*)(-1))
/**********************
* TYPEDEFS
**********************/
struct _lv_img_t;
typedef struct {
/* The first 8 bit is very important to distinguish the different source types.
* For more info see `lv_img_get_src_type()` in lv_img.c */
uint32_t cf :5; /* Color format: See `lv_img_color_format_t`*/
uint32_t always_zero :3; /*It the upper bits of the first byte. Always zero to look like a non-printable character*/
uint32_t reserved :2; /*Reserved to be used later*/
uint32_t w:11; /*Width of the image map*/
uint32_t h:11; /*Height of the image map*/
} lv_img_header_t;
/*Image color format*/
enum {
LV_IMG_CF_UNKOWN = 0,
LV_IMG_CF_RAW, /*Contains the file as it is. Needs custom decoder function*/
LV_IMG_CF_RAW_ALPHA, /*Contains the file as it is. The image has alpha. Needs custom decoder function*/
LV_IMG_CF_RAW_CHROMA_KEYED, /*Contains the file as it is. The image is chroma keyed. Needs custom decoder function*/
LV_IMG_CF_TRUE_COLOR, /*Color format and depth should match with LV_COLOR settings*/
LV_IMG_CF_TRUE_COLOR_ALPHA, /*Same as `LV_IMG_CF_TRUE_COLOR` but every pixel has an alpha byte*/
LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED, /*Same as `LV_IMG_CF_TRUE_COLOR` but LV_COLOR_TRANSP pixels will be transparent*/
LV_IMG_CF_INDEXED_1BIT, /*Can have 2 different colors in a palette (always chroma keyed)*/
LV_IMG_CF_INDEXED_2BIT, /*Can have 4 different colors in a palette (always chroma keyed)*/
LV_IMG_CF_INDEXED_4BIT, /*Can have 16 different colors in a palette (always chroma keyed)*/
LV_IMG_CF_INDEXED_8BIT, /*Can have 256 different colors in a palette (always chroma keyed)*/
LV_IMG_CF_ALPHA_1BIT, /*Can have one color and it can be drawn or not*/
LV_IMG_CF_ALPHA_2BIT, /*Can have one color but 4 different alpha value*/
LV_IMG_CF_ALPHA_4BIT, /*Can have one color but 16 different alpha value*/
LV_IMG_CF_ALPHA_8BIT, /*Can have one color but 256 different alpha value*/
};
typedef uint8_t lv_img_cf_t;
/* Image header it is compatible with
* the result image converter utility*/
typedef struct
{
lv_img_header_t header;
uint32_t data_size;
const uint8_t * data;
} lv_img_dsc_t;
/* Decoder function definitions */
/**
* Get info from an image and store in the `header`
* @param src the image source. Can be a pointer to a C array or a file name (Use `lv_img_src_get_type` to determine the type)
* @param header store the info here
* @return LV_RES_OK: info written correctly; LV_RES_INV: failed
*/
typedef lv_res_t (*lv_img_decoder_info_f_t)(const void * src, lv_img_header_t * header);
/**
* Open an image for decoding. Prepare it as it is required to read it later
* @param src the image source. Can be a pointer to a C array or a file name (Use `lv_img_src_get_type` to determine the type)
* @param style the style of image (maybe it will be required to determine a color or something)
* @return there are 3 possible return values:
* 1) buffer with the decoded image
* 2) if can decode the whole image NULL. decoder_read_line will be called to read the image line-by-line
* 3) LV_IMG_DECODER_OPEN_FAIL if the image format is unknown to the decoder or an error occurred
*/
typedef const uint8_t * (*lv_img_decoder_open_f_t)(const void * src, const lv_style_t * style);
/**
* Decode `len` pixels starting from the given `x`, `y` coordinates and store them in `buf`.
* Required only if the "open" function can't return with the whole decoded pixel array.
* @param x start x coordinate
* @param y startt y coordinate
* @param len number of pixels to decode
* @param buf a buffer to store the decoded pixels
* @return LV_RES_OK: ok; LV_RES_INV: failed
*/
typedef lv_res_t (*lv_img_decoder_read_line_f_t)(lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf);
/**
* Close the pending decoding. Free resources etc.
*/
typedef void (*lv_img_decoder_close_f_t)(void);
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Draw an image
* @param coords the coordinates of the image
* @param mask the image will be drawn only in this area
* @param src pointer to a lv_color_t array which contains the pixels of the image
* @param style style of the image
* @param opa_scale scale down all opacities by the factor
*/
void lv_draw_img(const lv_area_t * coords, const lv_area_t * mask,
const void * src, const lv_style_t * style, lv_opa_t opa_scale);
/**
* Get the type of an image source
* @param src pointer to an image source:
* - pointer to an 'lv_img_t' variable (image stored internally and compiled into the code)
* - a path to a file (e.g. "S:/folder/image.bin")
* - or a symbol (e.g. SYMBOL_CLOSE)
* @return type of the image source LV_IMG_SRC_VARIABLE/FILE/SYMBOL/UNKOWN
*/
lv_img_src_t lv_img_src_get_type(const void * src);
/**
* Set custom decoder functions. See the typdefs of the function typed above for more info about them
* @param info_fp info get function
* @param open_fp open function
* @param read_fp read line function
* @param close_fp clode function
*/
void lv_img_decoder_set_custom(lv_img_decoder_info_f_t info_fp, lv_img_decoder_open_f_t open_fp,
lv_img_decoder_read_line_f_t read_fp, lv_img_decoder_close_f_t close_fp);
lv_res_t lv_img_dsc_get_info(const char * src, lv_img_header_t * header);
uint8_t lv_img_color_format_get_px_size(lv_img_cf_t cf);
bool lv_img_color_format_is_chroma_keyed(lv_img_cf_t cf);
bool lv_img_color_format_has_alpha(lv_img_cf_t cf);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_TEMPL_H*/

View File

@ -1,53 +0,0 @@
/**
* @file lv_draw_label.h
*
*/
#ifndef LV_DRAW_LABEL_H
#define LV_DRAW_LABEL_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lv_draw.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Write a text
* @param coords coordinates of the label
* @param mask the label will be drawn only in this area
* @param style pointer to a style
* @param opa_scale scale down all opacities by the factor
* @param txt 0 terminated text to write
* @param flag settings for the text from 'txt_flag_t' enum
* @param offset text offset in x and y direction (NULL if unused)
*
*/
void lv_draw_label(const lv_area_t * coords,const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale,
const char * txt, lv_txt_flag_t flag, lv_point_t * offset);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_DRAW_LABEL_H*/

View File

@ -1,269 +0,0 @@
/**
* @file lv_draw_rbasic.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_draw_rbasic.h"
#if USE_LV_REAL_DRAW != 0
#include "../lv_hal/lv_hal_disp.h"
#include "../lv_misc/lv_font.h"
#include "lv_draw.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
static lv_color_t letter_bg_color;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Put a pixel to the display
* @param x x coordinate of the pixel
* @param y y coordinate of the pixel
* @param mask_p the pixel will be drawn on this area
* @param color color of the pixel
* @param opa opacity (ignored, only for compatibility with lv_vpx)
*/
void lv_rpx(lv_coord_t x, lv_coord_t y, const lv_area_t * mask_p, lv_color_t color, lv_opa_t opa)
{
(void)opa; /*Opa is used only for compatibility with lv_vpx*/
lv_area_t area;
area.x1 = x;
area.y1 = y;
area.x2 = x;
area.y2 = y;
lv_rfill(&area, mask_p, color, LV_OPA_COVER);
}
/**
* Fill an area on the display
* @param cords_p coordinates of the area to fill
* @param mask_p fill only o this mask
* @param color fill color
* @param opa opacity (ignored, only for compatibility with lv_vfill)
*/
void lv_rfill(const lv_area_t * cords_p, const lv_area_t * mask_p,
lv_color_t color, lv_opa_t opa)
{
(void)opa; /*Opa is used only for compatibility with lv_vfill*/
lv_area_t masked_area;
bool union_ok = true;
if(mask_p != NULL) {
union_ok = lv_area_intersect(&masked_area, cords_p, mask_p);
} else {
lv_area_t scr_area;
lv_area_set(&scr_area, 0, 0, LV_HOR_RES - 1, LV_VER_RES - 1);
union_ok = lv_area_intersect(&masked_area, cords_p, &scr_area);
}
if(union_ok != false) {
lv_disp_fill(masked_area.x1, masked_area.y1, masked_area.x2, masked_area.y2, color);
}
}
/**
* Draw a letter to the display
* @param pos_p left-top coordinate of the latter
* @param mask_p the letter will be drawn only on this area
* @param font_p pointer to font
* @param letter a letter to draw
* @param color color of letter
* @param opa opacity of letter (ignored, only for compatibility with lv_vletter)
*/
void lv_rletter(const lv_point_t * pos_p, const lv_area_t * mask_p,
const lv_font_t * font_p, uint32_t letter,
lv_color_t color, lv_opa_t opa)
{
(void)opa; /*Opa is used only for compatibility with lv_vletter*/
static uint8_t bpp1_opa_table[2] = {0, 255}; /*Opacity mapping with bpp = 1 (Just for compatibility)*/
static uint8_t bpp2_opa_table[4] = {0, 85, 170, 255}; /*Opacity mapping with bpp = 2*/
static uint8_t bpp4_opa_table[16] = {0, 17, 34, 51, /*Opacity mapping with bpp = 4*/
68, 85, 102, 119,
136, 153, 170, 187,
204, 221, 238, 255
};
if(font_p == NULL) return;
uint8_t letter_w = lv_font_get_width(font_p, letter);
uint8_t letter_h = lv_font_get_height(font_p);
uint8_t bpp = lv_font_get_bpp(font_p, letter); /*Bit per pixel (1,2, 4 or 8)*/
uint8_t * bpp_opa_table;
uint8_t mask_init;
uint8_t mask;
switch(bpp) {
case 1:
bpp_opa_table = bpp1_opa_table;
mask_init = 0x80;
break;
case 2:
bpp_opa_table = bpp2_opa_table;
mask_init = 0xC0;
break;
case 4:
bpp_opa_table = bpp4_opa_table;
mask_init = 0xF0;
break;
case 8:
bpp_opa_table = NULL;
mask_init = 0xFF;
break; /*No opa table, pixel value will be used directly*/
default:
return; /*Invalid bpp. Can't render the letter*/
}
const uint8_t * map_p = lv_font_get_bitmap(font_p, letter);
if(map_p == NULL) return;
/*If the letter is completely out of mask don't draw it */
if(pos_p->x + letter_w < mask_p->x1 || pos_p->x > mask_p->x2 ||
pos_p->y + letter_h < mask_p->y1 || pos_p->y > mask_p->y2) return;
lv_coord_t col, row;
uint8_t col_bit;
uint8_t col_byte_cnt;
uint8_t width_byte_scr = letter_w >> 3; /*Width in bytes (on the screen finally) (e.g. w = 11 -> 2 bytes wide)*/
if(letter_w & 0x7) width_byte_scr++;
uint8_t width_byte_bpp = (letter_w * bpp) >> 3; /*Letter width in byte. Real width in the font*/
if((letter_w * bpp) & 0x7) width_byte_bpp++;
/* Calculate the col/row start/end on the map*/
lv_coord_t col_start = pos_p->x >= mask_p->x1 ? 0 : mask_p->x1 - pos_p->x;
lv_coord_t col_end = pos_p->x + letter_w <= mask_p->x2 ? letter_w : mask_p->x2 - pos_p->x + 1;
lv_coord_t row_start = pos_p->y >= mask_p->y1 ? 0 : mask_p->y1 - pos_p->y;
lv_coord_t row_end = pos_p->y + letter_h <= mask_p->y2 ? letter_h : mask_p->y2 - pos_p->y + 1;
/*Move on the map too*/
map_p += (row_start * width_byte_bpp) + ((col_start * bpp) >> 3);
uint8_t letter_px;
for(row = row_start; row < row_end; row ++) {
col_byte_cnt = 0;
col_bit = (col_start * bpp) % 8;
mask = mask_init >> col_bit;
for(col = col_start; col < col_end; col ++) {
letter_px = (*map_p & mask) >> (8 - col_bit - bpp);
if(letter_px != 0) {
lv_rpx(pos_p->x + col, pos_p->y + row, mask_p, lv_color_mix(color, letter_bg_color, bpp == 8 ? letter_px : bpp_opa_table[letter_px]), LV_OPA_COVER);
}
if(col_bit < 8 - bpp) {
col_bit += bpp;
mask = mask >> bpp;
} else {
col_bit = 0;
col_byte_cnt ++;
mask = mask_init;
map_p ++;
}
}
map_p += (width_byte_bpp) - col_byte_cnt;
}
}
/**
* When the letter is ant-aliased it needs to know the background color
* @param bg_color the background color of the currently drawn letter
*/
void lv_rletter_set_background(lv_color_t color)
{
letter_bg_color = color;
}
/**
* Draw a color map to the display (image)
* @param cords_p coordinates the color map
* @param mask_p the map will drawn only on this area
* @param map_p pointer to a lv_color_t array
* @param opa opacity of the map (ignored, only for compatibility with 'lv_vmap')
* @param chroma_keyed true: enable transparency of LV_IMG_LV_COLOR_TRANSP color pixels
* @param alpha_byte true: extra alpha byte is inserted for every pixel (not supported, only l'v_vmap' can draw it)
* @param recolor mix the pixels with this color
* @param recolor_opa the intense of recoloring
*/
void lv_rmap(const lv_area_t * cords_p, const lv_area_t * mask_p,
const uint8_t * map_p, lv_opa_t opa, bool chroma_key, bool alpha_byte,
lv_color_t recolor, lv_opa_t recolor_opa)
{
if(alpha_byte) return; /*Pixel level opacity i not supported in real map drawing*/
(void)opa; /*opa is used only for compatibility with lv_vmap*/
lv_area_t masked_a;
bool union_ok;
union_ok = lv_area_intersect(&masked_a, cords_p, mask_p);
/*If there are common part of the mask and map then draw the map*/
if(union_ok == false) return;
/*Go to the first pixel*/
lv_coord_t map_width = lv_area_get_width(cords_p);
map_p += (masked_a.y1 - cords_p->y1) * map_width * sizeof(lv_color_t);
map_p += (masked_a.x1 - cords_p->x1) * sizeof(lv_color_t);
lv_coord_t row;
if(recolor_opa == LV_OPA_TRANSP && chroma_key == false) {
lv_coord_t mask_w = lv_area_get_width(&masked_a) - 1;
for(row = masked_a.y1; row <= masked_a.y2; row++) {
lv_disp_map(masked_a.x1, row, masked_a.x1 + mask_w, row, (lv_color_t *)map_p);
map_p += map_width * sizeof(lv_color_t); /*Next row on the map*/
}
} else {
lv_color_t chroma_key_color = LV_COLOR_TRANSP;
lv_coord_t col;
for(row = masked_a.y1; row <= masked_a.y2; row++) {
for(col = masked_a.x1; col <= masked_a.x2; col++) {
lv_color_t * px_color = (lv_color_t *) &map_p[(uint32_t)(col - masked_a.x1) * sizeof(lv_color_t)];
if(chroma_key && chroma_key_color.full == px_color->full) continue;
if(recolor_opa != LV_OPA_TRANSP) {
lv_color_t recolored_px = lv_color_mix(recolor, *px_color, recolor_opa);
lv_rpx(col, row, mask_p, recolored_px, LV_OPA_COVER);
} else {
lv_rpx(col, row, mask_p, *px_color, LV_OPA_COVER);
}
}
map_p += map_width * sizeof(lv_color_t); /*Next row on the map*/
}
}
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif /*USE_LV_REAL_DRAW*/

View File

@ -1,96 +0,0 @@
/**
* @file lv_draw_rbasic..h
*
*/
#ifndef LV_DRAW_RBASIC_H
#define LV_DRAW_RBASIC_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_conf.h"
#else
#include "../../lv_conf.h"
#endif
#if USE_LV_REAL_DRAW != 0
#include "../lv_misc/lv_color.h"
#include "../lv_misc/lv_area.h"
#include "../lv_misc/lv_font.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
void lv_rpx(lv_coord_t x, lv_coord_t y, const lv_area_t * mask_p, lv_color_t color, lv_opa_t opa);
/**
* Fill an area on the display
* @param cords_p coordinates of the area to fill
* @param mask_p fill only o this mask
* @param color fill color
* @param opa opacity (ignored, only for compatibility with lv_vfill)
*/
void lv_rfill(const lv_area_t * cords_p, const lv_area_t * mask_p,
lv_color_t color, lv_opa_t opa);
/**
* Draw a letter to the display
* @param pos_p left-top coordinate of the latter
* @param mask_p the letter will be drawn only on this area
* @param font_p pointer to font
* @param letter a letter to draw
* @param color color of letter
* @param opa opacity of letter (ignored, only for compatibility with lv_vletter)
*/
void lv_rletter(const lv_point_t * pos_p, const lv_area_t * mask_p,
const lv_font_t * font_p, uint32_t letter,
lv_color_t color, lv_opa_t opa);
/**
* When the letter is ant-aliased it needs to know the background color
* @param bg_color the background color of the currently drawn letter
*/
void lv_rletter_set_background(lv_color_t color);
/**
* Draw a color map to the display (image)
* @param cords_p coordinates the color map
* @param mask_p the map will drawn only on this area
* @param map_p pointer to a lv_color_t array
* @param opa opacity of the map (ignored, only for compatibility with 'lv_vmap')
* @param chroma_keyed true: enable transparency of LV_IMG_LV_COLOR_TRANSP color pixels
* @param alpha_byte true: extra alpha byte is inserted for every pixel (not supported, only l'v_vmap' can draw it)
* @param recolor mix the pixels with this color
* @param recolor_opa the intense of recoloring
*/
void lv_rmap(const lv_area_t * cords_p, const lv_area_t * mask_p,
const uint8_t * map_p, lv_opa_t opa, bool chroma_key, bool alpha_byte,
lv_color_t recolor, lv_opa_t recolor_opa);
/**********************
* MACROS
**********************/
#endif /*USE_LV_REAL_DRAW*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_DRAW_RBASIC_H*/

File diff suppressed because it is too large Load Diff

View File

@ -1,168 +0,0 @@
/**
* @file lv_draw_triangle.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_draw_triangle.h"
#include "../lv_misc/lv_math.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
static void point_swap(lv_point_t * p1, lv_point_t * p2);
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
#if USE_LV_TRIANGLE != 0
/**
*
* @param points pointer to an array with 3 points
* @param mask the triangle will be drawn only in this mask
* @param color color of the triangle
*/
void lv_draw_triangle(const lv_point_t * points, const lv_area_t * mask, lv_color_t color)
{
lv_point_t tri[3];
memcpy(tri, points, sizeof(tri));
/*Sort the vertices according to their y coordinate (0: y max, 1: y mid, 2:y min)*/
if(tri[1].y < tri[0].y) point_swap(&tri[1], &tri[0]);
if(tri[2].y < tri[1].y) point_swap(&tri[2], &tri[1]);
if(tri[1].y < tri[0].y) point_swap(&tri[1], &tri[0]);
/*Return is the triangle is degenerated*/
if(tri[0].x == tri[1].x && tri[0].y == tri[1].y) return;
if(tri[1].x == tri[2].x && tri[1].y == tri[2].y) return;
if(tri[0].x == tri[2].x && tri[0].y == tri[2].y) return;
if(tri[0].x == tri[1].x && tri[1].x == tri[2].x) return;
if(tri[0].y == tri[1].y && tri[1].y == tri[2].y) return;
/*Draw the triangle*/
lv_point_t edge1;
lv_coord_t dx1 = LV_MATH_ABS(tri[0].x - tri[1].x);
lv_coord_t sx1 = tri[0].x < tri[1].x ? 1 : -1;
lv_coord_t dy1 = LV_MATH_ABS(tri[0].y - tri[1].y);
lv_coord_t sy1 = tri[0].y < tri[1].y ? 1 : -1;
lv_coord_t err1 = (dx1 > dy1 ? dx1 : -dy1) / 2;
lv_coord_t err_tmp1;
lv_point_t edge2;
lv_coord_t dx2 = LV_MATH_ABS(tri[0].x - tri[2].x);
lv_coord_t sx2 = tri[0].x < tri[2].x ? 1 : -1;
lv_coord_t dy2 = LV_MATH_ABS(tri[0].y - tri[2].y);
lv_coord_t sy2 = tri[0].y < tri[2].y ? 1 : -1;
lv_coord_t err2 = (dx1 > dy2 ? dx2 : -dy2) / 2;
lv_coord_t err_tmp2;
lv_coord_t y1_tmp;
lv_coord_t y2_tmp;
edge1.x = tri[0].x;
edge1.y = tri[0].y;
edge2.x = tri[0].x;
edge2.y = tri[0].y;
lv_area_t act_area;
lv_area_t draw_area;
while(1) {
act_area.x1 = edge1.x;
act_area.x2 = edge2.x ;
act_area.y1 = edge1.y;
act_area.y2 = edge2.y ;
draw_area.x1 = LV_MATH_MIN(act_area.x1, act_area.x2);
draw_area.x2 = LV_MATH_MAX(act_area.x1, act_area.x2);
draw_area.y1 = LV_MATH_MIN(act_area.y1, act_area.y2);
draw_area.y2 = LV_MATH_MAX(act_area.y1, act_area.y2);
draw_area.x2--; /*Do not draw most right pixel because it will be drawn by the adjacent triangle*/
fill_fp(&draw_area, mask, color, LV_OPA_50);
/*Calc. the next point of edge1*/
y1_tmp = edge1.y;
do {
if(edge1.x == tri[1].x && edge1.y == tri[1].y) {
dx1 = LV_MATH_ABS(tri[1].x - tri[2].x);
sx1 = tri[1].x < tri[2].x ? 1 : -1;
dy1 = LV_MATH_ABS(tri[1].y - tri[2].y);
sy1 = tri[1].y < tri[2].y ? 1 : -1;
err1 = (dx1 > dy1 ? dx1 : -dy1) / 2;
} else if(edge1.x == tri[2].x && edge1.y == tri[2].y) return;
err_tmp1 = err1;
if(err_tmp1 > -dx1) {
err1 -= dy1;
edge1.x += sx1;
}
if(err_tmp1 < dy1) {
err1 += dx1;
edge1.y += sy1;
}
} while(edge1.y == y1_tmp);
/*Calc. the next point of edge2*/
y2_tmp = edge2.y;
do {
if(edge2.x == tri[2].x && edge2.y == tri[2].y) return;
err_tmp2 = err2;
if(err_tmp2 > -dx2) {
err2 -= dy2;
edge2.x += sx2;
}
if(err_tmp2 < dy2) {
err2 += dx2;
edge2.y += sy2;
}
} while(edge2.y == y2_tmp);
}
}
#endif
/**********************
* STATIC FUNCTIONS
**********************/
#if USE_LV_TRIANGLE != 0
/**
* Swap two points
* p1 pointer to the first point
* p2 pointer to the second point
*/
static void point_swap(lv_point_t * p1, lv_point_t * p2)
{
lv_point_t tmp;
tmp.x = p1->x;
tmp.y = p1->y;
p1->x = p2->x;
p1->y = p2->y;
p2->x = tmp.x;
p2->y = tmp.y;
}
#endif

View File

@ -1,165 +0,0 @@
/**
* @file lv_font_built_in.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_font_builtin.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the built-in fonts
*/
void lv_font_builtin_init(void)
{
/*DEJAVU 10*/
#if USE_LV_FONT_DEJAVU_10 != 0
lv_font_add(&lv_font_dejavu_10, NULL);
#endif
#if USE_LV_FONT_DEJAVU_10_LATIN_SUP != 0
#if USE_LV_FONT_DEJAVU_10 != 0
lv_font_add(&lv_font_dejavu_10_latin_sup, &lv_font_dejavu_10);
#else
lv_font_add(&lv_font_dejavu_10_latin_sup, NULL);
#endif
#endif
#if USE_LV_FONT_DEJAVU_10_CYRILLIC != 0
#if USE_LV_FONT_DEJAVU_10 != 0
lv_font_add(&lv_font_dejavu_10_cyrillic, &lv_font_dejavu_10);
#else
lv_font_add(&lv_font_dejavu_10_cyrillic, NULL);
#endif
#endif
/*SYMBOL 10*/
#if USE_LV_FONT_SYMBOL_10 != 0
#if USE_LV_FONT_DEJAVU_10 != 0
lv_font_add(&lv_font_symbol_10, &lv_font_dejavu_10);
#else
lv_font_add(&lv_font_symbol_10, NULL);
#endif
#endif
/*DEJAVU 20*/
#if USE_LV_FONT_DEJAVU_20 != 0
lv_font_add(&lv_font_dejavu_20, NULL);
#endif
#if USE_LV_FONT_DEJAVU_20_LATIN_SUP != 0
#if USE_LV_FONT_DEJAVU_20 != 0
lv_font_add(&lv_font_dejavu_20_latin_sup, &lv_font_dejavu_20);
#else
lv_font_add(&lv_font_symbol_20_latin_sup, NULL);
#endif
#endif
#if USE_LV_FONT_DEJAVU_20_CYRILLIC != 0
#if USE_LV_FONT_DEJAVU_20 != 0
lv_font_add(&lv_font_dejavu_20_cyrillic, &lv_font_dejavu_20);
#else
lv_font_add(&lv_font_dejavu_20_cyrillic, NULL);
#endif
#endif
/*SYMBOL 20*/
#if USE_LV_FONT_SYMBOL_20 != 0
#if USE_LV_FONT_DEJAVU_20 != 0
lv_font_add(&lv_font_symbol_20, &lv_font_dejavu_20);
#else
lv_font_add(&lv_font_symbol_20, NULL);
#endif
#endif
/*DEJAVU 30*/
#if USE_LV_FONT_DEJAVU_30 != 0
lv_font_add(&lv_font_dejavu_30, NULL);
#endif
#if USE_LV_FONT_DEJAVU_30_LATIN_SUP != 0
#if USE_LV_FONT_DEJAVU_30 != 0
lv_font_add(&lv_font_dejavu_30_latin_sup, &lv_font_dejavu_30);
#else
lv_font_add(&lv_font_dejavu_30_latin_sup, NULL);
#endif
#endif
#if USE_LV_FONT_DEJAVU_30_CYRILLIC != 0
#if USE_LV_FONT_DEJAVU_30 != 0
lv_font_add(&lv_font_dejavu_30_cyrillic, &lv_font_dejavu_30);
#else
lv_font_add(&lv_font_dejavu_30_cyrillic, NULL);
#endif
#endif
/*SYMBOL 30*/
#if USE_LV_FONT_SYMBOL_30 != 0
#if USE_LV_FONT_DEJAVU_30 != 0
lv_font_add(&lv_font_symbol_30, &lv_font_dejavu_30);
#else
lv_font_add(&lv_font_symbol_30, NULL);
#endif
#endif
/*DEJAVU 40*/
#if USE_LV_FONT_DEJAVU_40 != 0
lv_font_add(&lv_font_dejavu_40, NULL);
#endif
#if USE_LV_FONT_DEJAVU_40_LATIN_SUP != 0
#if USE_LV_FONT_DEJAVU_40 != 0
lv_font_add(&lv_font_dejavu_40_latin_sup, &lv_font_dejavu_40);
#else
lv_font_add(&lv_font_dejavu_40_latin_sup, NULL);
#endif
#endif
#if USE_LV_FONT_DEJAVU_40_CYRILLIC != 0
#if USE_LV_FONT_DEJAVU_40 != 0
lv_font_add(&lv_font_dejavu_40_cyrillic, &lv_font_dejavu_40);
#else
lv_font_add(&lv_font_dejavu_40_cyrillic, NULL);
#endif
#endif
/*SYMBOL 40*/
#if USE_LV_FONT_SYMBOL_40 != 0
#if USE_LV_FONT_DEJAVU_40 != 0
lv_font_add(&lv_font_symbol_40, &lv_font_dejavu_40);
#else
lv_font_add(&lv_font_symbol_40, NULL);
#endif
#endif
}
/**********************
* STATIC FUNCTIONS
**********************/

View File

@ -1,125 +0,0 @@
/**
* @file lv_font_builtin.h
*
*/
#ifndef LV_FONT_BUILTIN_H
#define LV_FONT_BUILTIN_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_conf.h"
#else
#include "../../lv_conf.h"
#endif
#include "../lv_misc/lv_font.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize the built-in fonts
*/
void lv_font_builtin_init(void);
/**********************
* MACROS
**********************/
/**********************
* FONT DECLARATIONS
**********************/
/*10 px */
#if USE_LV_FONT_DEJAVU_10
LV_FONT_DECLARE(lv_font_dejavu_10)
#endif
#if USE_LV_FONT_DEJAVU_10_LATIN_SUP
LV_FONT_DECLARE(lv_font_dejavu_10_latin_sup)
#endif
#if USE_LV_FONT_DEJAVU_10_CYRILLIC
LV_FONT_DECLARE(lv_font_dejavu_10_cyrillic)
#endif
#if USE_LV_FONT_SYMBOL_10
LV_FONT_DECLARE(lv_font_symbol_10)
#endif
/*20 px */
#if USE_LV_FONT_DEJAVU_20
LV_FONT_DECLARE(lv_font_dejavu_20)
#endif
#if USE_LV_FONT_DEJAVU_20_LATIN_SUP
LV_FONT_DECLARE(lv_font_dejavu_20_latin_sup)
#endif
#if USE_LV_FONT_DEJAVU_20_CYRILLIC
LV_FONT_DECLARE(lv_font_dejavu_20_cyrillic)
#endif
#if USE_LV_FONT_SYMBOL_20
LV_FONT_DECLARE(lv_font_symbol_20)
#endif
/*30 px */
#if USE_LV_FONT_DEJAVU_30
LV_FONT_DECLARE(lv_font_dejavu_30)
#endif
#if USE_LV_FONT_DEJAVU_30_LATIN_SUP
LV_FONT_DECLARE(lv_font_dejavu_30_latin_sup)
#endif
#if USE_LV_FONT_DEJAVU_30_CYRILLIC
LV_FONT_DECLARE(lv_font_dejavu_30_cyrillic)
#endif
#if USE_LV_FONT_SYMBOL_30
LV_FONT_DECLARE(lv_font_symbol_30)
#endif
/*40 px */
#if USE_LV_FONT_DEJAVU_40
LV_FONT_DECLARE(lv_font_dejavu_40)
#endif
#if USE_LV_FONT_DEJAVU_40_LATIN_SUP
LV_FONT_DECLARE(lv_font_dejavu_40_latin_sup)
#endif
#if USE_LV_FONT_DEJAVU_40_CYRILLIC
LV_FONT_DECLARE(lv_font_dejavu_40_cyrillic)
#endif
#if USE_LV_FONT_SYMBOL_40
LV_FONT_DECLARE(lv_font_symbol_40)
#endif
#if USE_LV_FONT_MONOSPACE_8
LV_FONT_DECLARE(lv_font_monospace_8)
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_FONT_BUILTIN_H*/

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,23 +0,0 @@
CSRCS += lv_font_builtin.c
CSRCS += lv_font_dejavu_10.c
CSRCS += lv_font_dejavu_20.c
CSRCS += lv_font_dejavu_30.c
CSRCS += lv_font_dejavu_40.c
CSRCS += lv_font_dejavu_10_cyrillic.c
CSRCS += lv_font_dejavu_20_cyrillic.c
CSRCS += lv_font_dejavu_30_cyrillic.c
CSRCS += lv_font_dejavu_40_cyrillic.c
CSRCS += lv_font_dejavu_10_latin_sup.c
CSRCS += lv_font_dejavu_20_latin_sup.c
CSRCS += lv_font_dejavu_30_latin_sup.c
CSRCS += lv_font_dejavu_40_latin_sup.c
CSRCS += lv_font_symbol_10.c
CSRCS += lv_font_symbol_20.c
CSRCS += lv_font_symbol_30.c
CSRCS += lv_font_symbol_40.c
CSRCS += lv_font_monospace_8.c
DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_fonts
VPATH += :$(LVGL_DIR)/lvgl/lv_fonts
CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_fonts"

View File

@ -1,8 +0,0 @@
CSRCS += lv_hal_disp.c
CSRCS += lv_hal_indev.c
CSRCS += lv_hal_tick.c
DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_hal
VPATH += :$(LVGL_DIR)/lvgl/lv_hal
CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_hal"

View File

@ -1,242 +0,0 @@
/**
* @file hal_disp.c
*
* @description HAL layer for display driver
*
*/
/*********************
* INCLUDES
*********************/
#include <stdint.h>
#include <stddef.h>
#include "../lv_hal/lv_hal_disp.h"
#include "../lv_misc/lv_mem.h"
#include "../lv_core/lv_obj.h"
#include "../lv_misc/lv_gc.h"
#if defined(LV_GC_INCLUDE)
# include LV_GC_INCLUDE
#endif /* LV_ENABLE_GC */
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
static lv_disp_t * active;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize a display driver with default values.
* It is used to surly have known values in the fields ant not memory junk.
* After it you can set the fields.
* @param driver pointer to driver variable to initialize
*/
void lv_disp_drv_init(lv_disp_drv_t * driver)
{
driver->disp_fill = NULL;
driver->disp_map = NULL;
driver->disp_flush = NULL;
#if USE_LV_GPU
driver->mem_blend = NULL;
driver->mem_fill = NULL;
#endif
#if LV_VDB_SIZE
driver->vdb_wr = NULL;
#endif
}
/**
* Register an initialized display driver.
* Automatically set the first display as active.
* @param driver pointer to an initialized 'lv_disp_drv_t' variable (can be local variable)
* @return pointer to the new display or NULL on error
*/
lv_disp_t * lv_disp_drv_register(lv_disp_drv_t * driver)
{
lv_disp_t * node;
node = lv_mem_alloc(sizeof(lv_disp_t));
lv_mem_assert(node);
if(node == NULL) return NULL;
memcpy(&node->driver, driver, sizeof(lv_disp_drv_t));
node->next = NULL;
/* Set first display as active by default */
if(LV_GC_ROOT(_lv_disp_list) == NULL) {
LV_GC_ROOT(_lv_disp_list) = node;
active = node;
lv_obj_invalidate(lv_scr_act());
} else {
((lv_disp_t*)LV_GC_ROOT(_lv_disp_list))->next = node;
}
return node;
}
/**
* Set the active display
* @param disp pointer to a display (return value of 'lv_disp_register')
*/
void lv_disp_set_active(lv_disp_t * disp)
{
active = disp;
lv_obj_invalidate(lv_scr_act());
}
/**
* Get a pointer to the active display
* @return pointer to the active display
*/
lv_disp_t * lv_disp_get_active(void)
{
return active;
}
/**
* Get the next display.
* @param disp pointer to the current display. NULL to initialize.
* @return the next display or NULL if no more. Give the first display when the parameter is NULL
*/
lv_disp_t * lv_disp_next(lv_disp_t * disp)
{
if(disp == NULL) {
return LV_GC_ROOT(_lv_disp_list);
} else {
if(((lv_disp_t*)LV_GC_ROOT(_lv_disp_list))->next == NULL) return NULL;
else return ((lv_disp_t*)LV_GC_ROOT(_lv_disp_list))->next;
}
}
/**
* Write the content of the internal buffer (VDB) to the display
* @param x1 left coordinate of the rectangle
* @param x2 right coordinate of the rectangle
* @param y1 top coordinate of the rectangle
* @param y2 bottom coordinate of the rectangle
* @param color_p fill color
*/
void lv_disp_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color)
{
if(active == NULL) return;
if(active->driver.disp_fill != NULL) active->driver.disp_fill(x1, y1, x2, y2, color);
}
/**
* Fill a rectangular area with a color on the active display
* @param x1 left coordinate of the rectangle
* @param x2 right coordinate of the rectangle
* @param y1 top coordinate of the rectangle
* @param y2 bottom coordinate of the rectangle
* @param color_p pointer to an array of colors
*/
void lv_disp_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t * color_p)
{
if(active == NULL) return;
if(active->driver.disp_flush != NULL) {
LV_LOG_TRACE("disp flush started");
active->driver.disp_flush(x1, y1, x2, y2, color_p);
LV_LOG_TRACE("disp flush ready");
} else {
LV_LOG_WARN("disp flush function registered");
}
}
/**
* Put a color map to a rectangular area on the active display
* @param x1 left coordinate of the rectangle
* @param x2 right coordinate of the rectangle
* @param y1 top coordinate of the rectangle
* @param y2 bottom coordinate of the rectangle
* @param color_map pointer to an array of colors
*/
void lv_disp_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_map)
{
if(active == NULL) return;
if(active->driver.disp_map != NULL) active->driver.disp_map(x1, y1, x2, y2, color_map);
}
#if USE_LV_GPU
/**
* Blend pixels to a destination memory from a source memory
* In 'lv_disp_drv_t' 'mem_blend' is optional. (NULL if not available)
* @param dest a memory address. Blend 'src' here.
* @param src pointer to pixel map. Blend it to 'dest'.
* @param length number of pixels in 'src'
* @param opa opacity (0, LV_OPA_TRANSP: transparent ... 255, LV_OPA_COVER, fully cover)
*/
void lv_disp_mem_blend(lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa)
{
if(active == NULL) return;
if(active->driver.mem_blend != NULL) active->driver.mem_blend(dest, src, length, opa);
}
/**
* Fill a memory with a color (GPUs may support it)
* In 'lv_disp_drv_t' 'mem_fill' is optional. (NULL if not available)
* @param dest a memory address. Copy 'src' here.
* @param src pointer to pixel map. Copy it to 'dest'.
* @param length number of pixels in 'src'
* @param opa opacity (0, LV_OPA_TRANSP: transparent ... 255, LV_OPA_COVER, fully cover)
*/
void lv_disp_mem_fill(lv_color_t * dest, uint32_t length, lv_color_t color)
{
if(active == NULL) return;
if(active->driver.mem_fill != NULL) active->driver.mem_fill(dest, length, color);
}
/**
* Shows if memory blending (by GPU) is supported or not
* @return false: 'mem_blend' is not supported in the driver; true: 'mem_blend' is supported in the driver
*/
bool lv_disp_is_mem_blend_supported(void)
{
if(active == NULL) return false;
if(active->driver.mem_blend) return true;
else return false;
}
/**
* Shows if memory fill (by GPU) is supported or not
* @return false: 'mem_fill' is not supported in the drover; true: 'mem_fill' is supported in the driver
*/
bool lv_disp_is_mem_fill_supported(void)
{
if(active == NULL) return false;
if(active->driver.mem_fill) return true;
else return false;
}
#endif
/**********************
* STATIC FUNCTIONS
**********************/

View File

@ -1,174 +0,0 @@
/**
* @file hal_disp.h
*
* @description Display Driver HAL interface header file
*
*/
#ifndef HAL_DISP_H
#define HAL_DISP_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include <stdint.h>
#include <stdbool.h>
#include "lv_hal.h"
#include "../lv_misc/lv_color.h"
#include "../lv_misc/lv_area.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**
* Display Driver structure to be registered by HAL
*/
typedef struct _disp_drv_t {
/*Write the internal buffer (VDB) to the display. 'lv_flush_ready()' has to be called when finished*/
void (*disp_flush)(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p);
/*Fill an area with a color on the display*/
void (*disp_fill)(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color);
/*Write pixel map (e.g. image) to the display*/
void (*disp_map)(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p);
/*Optional interface functions to use GPU*/
#if USE_LV_GPU
/*Blend two memories using opacity (GPU only)*/
void (*mem_blend)(lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa);
/*Fill a memory with a color (GPU only)*/
void (*mem_fill)(lv_color_t * dest, uint32_t length, lv_color_t color);
#endif
#if LV_VDB_SIZE
/*Optional: Set a pixel in a buffer according to the requirements of the display*/
void (*vdb_wr)(uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, lv_color_t color, lv_opa_t opa);
#endif
} lv_disp_drv_t;
typedef struct _disp_t {
lv_disp_drv_t driver;
struct _disp_t *next;
} lv_disp_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize a display driver with default values.
* It is used to surly have known values in the fields ant not memory junk.
* After it you can set the fields.
* @param driver pointer to driver variable to initialize
*/
void lv_disp_drv_init(lv_disp_drv_t *driver);
/**
* Register an initialized display driver.
* Automatically set the first display as active.
* @param driver pointer to an initialized 'lv_disp_drv_t' variable (can be local variable)
* @return pointer to the new display or NULL on error
*/
lv_disp_t * lv_disp_drv_register(lv_disp_drv_t *driver);
/**
* Set the active display
* @param disp pointer to a display (return value of 'lv_disp_register')
*/
void lv_disp_set_active(lv_disp_t * disp);
/**
* Get a pointer to the active display
* @return pointer to the active display
*/
lv_disp_t * lv_disp_get_active(void);
/**
* Get the next display.
* @param disp pointer to the current display. NULL to initialize.
* @return the next display or NULL if no more. Give the first display when the parameter is NULL
*/
lv_disp_t * lv_disp_next(lv_disp_t * disp);
/**
* Fill a rectangular area with a color on the active display
* @param x1 left coordinate of the rectangle
* @param x2 right coordinate of the rectangle
* @param y1 top coordinate of the rectangle
* @param y2 bottom coordinate of the rectangle
* @param color_p pointer to an array of colors
*/
void lv_disp_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t *color_p);
/**
* Fill a rectangular area with a color on the active display
* @param x1 left coordinate of the rectangle
* @param x2 right coordinate of the rectangle
* @param y1 top coordinate of the rectangle
* @param y2 bottom coordinate of the rectangle
* @param color fill color
*/
void lv_disp_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color);
/**
* Put a color map to a rectangular area on the active display
* @param x1 left coordinate of the rectangle
* @param x2 right coordinate of the rectangle
* @param y1 top coordinate of the rectangle
* @param y2 bottom coordinate of the rectangle
* @param color_map pointer to an array of colors
*/
void lv_disp_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_map);
#if USE_LV_GPU
/**
* Blend pixels to a destination memory from a source memory
* In 'lv_disp_drv_t' 'mem_blend' is optional. (NULL if not available)
* @param dest a memory address. Blend 'src' here.
* @param src pointer to pixel map. Blend it to 'dest'.
* @param length number of pixels in 'src'
* @param opa opacity (0, LV_OPA_TRANSP: transparent ... 255, LV_OPA_COVER, fully cover)
*/
void lv_disp_mem_blend(lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa);
/**
* Fill a memory with a color (GPUs may support it)
* In 'lv_disp_drv_t' 'mem_fill' is optional. (NULL if not available)
* @param dest a memory address. Copy 'src' here.
* @param src pointer to pixel map. Copy it to 'dest'.
* @param length number of pixels in 'src'
* @param opa opacity (0, LV_OPA_TRANSP: transparent ... 255, LV_OPA_COVER, fully cover)
*/
void lv_disp_mem_fill(lv_color_t * dest, uint32_t length, lv_color_t color);
/**
* Shows if memory blending (by GPU) is supported or not
* @return false: 'mem_blend' is not supported in the driver; true: 'mem_blend' is supported in the driver
*/
bool lv_disp_is_mem_blend_supported(void);
/**
* Shows if memory fill (by GPU) is supported or not
* @return false: 'mem_fill' is not supported in the drover; true: 'mem_fill' is supported in the driver
*/
bool lv_disp_is_mem_fill_supported(void);
#endif
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif

View File

@ -1,135 +0,0 @@
/**
* @file hal_indev.c
*
* @description Input device HAL interface
*
*/
/*********************
* INCLUDES
*********************/
#include "../lv_hal/lv_hal_indev.h"
#include "../lv_misc/lv_mem.h"
#include "../lv_misc/lv_gc.h"
#if defined(LV_GC_INCLUDE)
# include LV_GC_INCLUDE
#endif /* LV_ENABLE_GC */
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize an input device driver with default values.
* It is used to surly have known values in the fields ant not memory junk.
* After it you can set the fields.
* @param driver pointer to driver variable to initialize
*/
void lv_indev_drv_init(lv_indev_drv_t * driver)
{
driver->read = NULL;
driver->type = LV_INDEV_TYPE_NONE;
driver->user_data = NULL;
}
/**
* Register an initialized input device driver.
* @param driver pointer to an initialized 'lv_indev_drv_t' variable (can be local variable)
* @return pointer to the new input device or NULL on error
*/
lv_indev_t * lv_indev_drv_register(lv_indev_drv_t * driver)
{
lv_indev_t * node;
node = lv_mem_alloc(sizeof(lv_indev_t));
if(!node) return NULL;
memset(node, 0, sizeof(lv_indev_t));
memcpy(&node->driver, driver, sizeof(lv_indev_drv_t));
node->next = NULL;
node->proc.reset_query = 1;
node->cursor = NULL;
node->group = NULL;
node->btn_points = NULL;
if(LV_GC_ROOT(_lv_indev_list) == NULL) {
LV_GC_ROOT(_lv_indev_list) = node;
} else {
lv_indev_t * last = LV_GC_ROOT(_lv_indev_list);
while(last->next)
last = last->next;
last->next = node;
}
return node;
}
/**
* Get the next input device.
* @param indev pointer to the current input device. NULL to initialize.
* @return the next input devise or NULL if no more. Give the first input device when the parameter is NULL
*/
lv_indev_t * lv_indev_next(lv_indev_t * indev)
{
if(indev == NULL) {
return LV_GC_ROOT(_lv_indev_list);
} else {
if(indev->next == NULL) return NULL;
else return indev->next;
}
}
/**
* Read data from an input device.
* @param indev pointer to an input device
* @param data input device will write its data here
* @return false: no more data; true: there more data to read (buffered)
*/
bool lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data)
{
bool cont = false;
memset(data, 0, sizeof(lv_indev_data_t));
data->state = LV_INDEV_STATE_REL;
if(indev->driver.read) {
data->user_data = indev->driver.user_data;
LV_LOG_TRACE("idnev read started");
cont = indev->driver.read(data);
LV_LOG_TRACE("idnev read finished");
} else {
LV_LOG_WARN("indev function registered");
}
return cont;
}
/**********************
* STATIC FUNCTIONS
**********************/

View File

@ -1,166 +0,0 @@
/**
* @file hal_indev.h
*
* @description Input Device HAL interface layer header file
*
*/
#ifndef HAL_INDEV_H
#define HAL_INDEV_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include <stdbool.h>
#include <stdint.h>
#include "lv_hal.h"
#include "../lv_misc/lv_area.h"
#include "../lv_core/lv_obj.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/*Possible input device types*/
enum {
LV_INDEV_TYPE_NONE, /*Show uninitialized state*/
LV_INDEV_TYPE_POINTER, /*Touch pad, mouse, external button*/
LV_INDEV_TYPE_KEYPAD, /*Keypad or keyboard*/
LV_INDEV_TYPE_BUTTON, /*External (hardware button) which is assinged to a specific point of the screen*/
LV_INDEV_TYPE_ENCODER, /*Encoder with only Left, Right turn and a Button*/
};
typedef uint8_t lv_hal_indev_type_t;
/*States for input devices*/
enum {
LV_INDEV_STATE_REL = 0,
LV_INDEV_STATE_PR
};
typedef uint8_t lv_indev_state_t;
/*Data type when an input device is read */
typedef struct {
union {
lv_point_t point; /*For LV_INDEV_TYPE_POINTER the currently pressed point*/
uint32_t key; /*For LV_INDEV_TYPE_KEYPAD the currently pressed key*/
uint32_t btn; /*For LV_INDEV_TYPE_BUTTON the currently pressed button*/
int16_t enc_diff; /*For LV_INDEV_TYPE_ENCODER number of steps since the previous read*/
};
void *user_data; /*'lv_indev_drv_t.priv' for this driver*/
lv_indev_state_t state; /*LV_INDEV_STATE_REL or LV_INDEV_STATE_PR*/
} lv_indev_data_t;
/*Initialized by the user and registered by 'lv_indev_add()'*/
typedef struct {
lv_hal_indev_type_t type; /*Input device type*/
bool (*read)(lv_indev_data_t *data); /*Function pointer to read data. Return 'true' if there is still data to be read (buffered)*/
void *user_data; /*Pointer to user defined data, passed in 'lv_indev_data_t' on read*/
} lv_indev_drv_t;
struct _lv_obj_t;
/*Run time data of input devices*/
typedef struct _lv_indev_proc_t {
lv_indev_state_t state;
union {
struct { /*Pointer and button data*/
lv_point_t act_point;
lv_point_t last_point;
lv_point_t vect;
lv_point_t drag_sum; /*Count the dragged pixels to check LV_INDEV_DRAG_LIMIT*/
struct _lv_obj_t * act_obj;
struct _lv_obj_t * last_obj;
/*Flags*/
uint8_t drag_range_out :1;
uint8_t drag_in_prog :1;
uint8_t wait_unil_release :1;
};
struct { /*Keypad data*/
lv_indev_state_t last_state;
uint32_t last_key;
};
};
uint32_t pr_timestamp; /*Pressed time stamp*/
uint32_t longpr_rep_timestamp; /*Long press repeat time stamp*/
/*Flags*/
uint8_t long_pr_sent :1;
uint8_t reset_query :1;
uint8_t disabled :1;
} lv_indev_proc_t;
struct _lv_indev_t;
typedef void (*lv_indev_feedback_t)(struct _lv_indev_t *, lv_signal_t);
struct _lv_obj_t;
struct _lv_group_t;
/*The main input device descriptor with driver, runtime data ('proc') and some additional information*/
typedef struct _lv_indev_t {
lv_indev_drv_t driver;
lv_indev_proc_t proc;
lv_indev_feedback_t feedback;
uint32_t last_activity_time;
union {
struct _lv_obj_t *cursor; /*Cursor for LV_INPUT_TYPE_POINTER*/
struct _lv_group_t *group; /*Keypad destination group*/
const lv_point_t * btn_points; /*Array points assigned to the button ()screen will be pressed here by the buttons*/
};
struct _lv_indev_t *next;
} lv_indev_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize an input device driver with default values.
* It is used to surly have known values in the fields ant not memory junk.
* After it you can set the fields.
* @param driver pointer to driver variable to initialize
*/
void lv_indev_drv_init(lv_indev_drv_t *driver);
/**
* Register an initialized input device driver.
* @param driver pointer to an initialized 'lv_indev_drv_t' variable (can be local variable)
* @return pointer to the new input device or NULL on error
*/
lv_indev_t * lv_indev_drv_register(lv_indev_drv_t *driver);
/**
* Get the next input device.
* @param indev pointer to the current input device. NULL to initialize.
* @return the next input devise or NULL if no more. Gives the first input device when the parameter is NULL
*/
lv_indev_t * lv_indev_next(lv_indev_t * indev);
/**
* Read data from an input device.
* @param indev pointer to an input device
* @param data input device will write its data here
* @return false: no more data; true: there more data to read (buffered)
*/
bool lv_indev_read(lv_indev_t * indev, lv_indev_data_t *data);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif

View File

@ -1,177 +0,0 @@
/**
* @file anim.h
*
*/
#ifndef ANIM_H
#define ANIM_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_conf.h"
#else
#include "../../lv_conf.h"
#endif
#if USE_LV_ANIMATION
#include <stdint.h>
#include <stdbool.h>
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
struct _lv_anim_t;
typedef int32_t(*lv_anim_path_t)(const struct _lv_anim_t*);
typedef void (*lv_anim_fp_t)(void *, int32_t);
typedef void (*lv_anim_cb_t)(void *);
typedef struct _lv_anim_t
{
void * var; /*Variable to animate*/
lv_anim_fp_t fp; /*Animator function*/
lv_anim_cb_t end_cb; /*Call it when the animation is ready*/
lv_anim_path_t path; /*An array with the steps of animations*/
int32_t start; /*Start value*/
int32_t end; /*End value*/
uint16_t time; /*Animation time in ms*/
int16_t act_time; /*Current time in animation. Set to negative to make delay.*/
uint16_t playback_pause; /*Wait before play back*/
uint16_t repeat_pause; /*Wait before repeat*/
uint8_t playback :1; /*When the animation is ready play it back*/
uint8_t repeat :1; /*Repeat the animation infinitely*/
/*Animation system use these - user shouldn't set*/
uint8_t playback_now :1; /*Play back is in progress*/
uint32_t has_run :1; /*Indicates the animation has run it this round*/
} lv_anim_t;
/*Example initialization
lv_anim_t a;
a.var = obj;
a.start = lv_obj_get_height(obj);
a.end = new_height;
a.fp = (lv_anim_fp_t)lv_obj_set_height;
a.path = lv_anim_path_linear;
a.end_cb = NULL;
a.act_time = 0;
a.time = 200;
a.playback = 0;
a.playback_pause = 0;
a.repeat = 0;
a.repeat_pause = 0;
lv_anim_create(&a);
*/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Init. the animation module
*/
void lv_anim_init(void);
/**
* Create an animation
* @param anim_p an initialized 'anim_t' variable. Not required after call.
*/
void lv_anim_create(lv_anim_t * anim_p);
/**
* Delete an animation for a variable with a given animatior function
* @param var pointer to variable
* @param fp a function pointer which is animating 'var',
* or NULL to ignore it and delete all animation with 'var
* @return true: at least 1 animation is deleted, false: no animation is deleted
*/
bool lv_anim_del(void * var, lv_anim_fp_t fp);
/**
* Get the number of currently running animations
* @return the number of running animations
*/
uint16_t lv_anim_count_running(void);
/**
* Calculate the time of an animation with a given speed and the start and end values
* @param speed speed of animation in unit/sec
* @param start start value of the animation
* @param end end value of the animation
* @return the required time [ms] for the animation with the given parameters
*/
uint16_t lv_anim_speed_to_time(uint16_t speed, int32_t start, int32_t end);
/**
* Calculate the current value of an animation applying linear characteristic
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_linear(const lv_anim_t *a);
/**
* Calculate the current value of an animation slowing down the start phase
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_ease_in(const lv_anim_t * a);
/**
* Calculate the current value of an animation slowing down the end phase
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_ease_out(const lv_anim_t * a);
/**
* Calculate the current value of an animation applying an "S" characteristic (cosine)
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_ease_in_out(const lv_anim_t *a);
/**
* Calculate the current value of an animation with overshoot at the end
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_overshoot(const lv_anim_t * a);
/**
* Calculate the current value of an animation with 3 bounces
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_bounce(const lv_anim_t * a);
/**
* Calculate the current value of an animation applying step characteristic.
* (Set end value on the end of the animation)
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_step(const lv_anim_t *a);
/**********************
* MACROS
**********************/
#endif /*USE_LV_ANIMATION == 0*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_ANIM_H*/

View File

@ -1,441 +0,0 @@
/**
* @file lv_color.h
*
*/
#ifndef LV_COLOR_H
#define LV_COLOR_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_conf.h"
#else
#include "../../lv_conf.h"
#endif
/*Error checking*/
#if LV_COLOR_DEPTH == 24
#error "LV_COLOR_DEPTH 24 is deprecated. Use LV_COLOR_DEPTH 32 instead (lv_conf.h)"
#endif
#if LV_COLOR_DEPTH != 32 && LV_COLOR_SCREEN_TRANSP != 0
#error "LV_COLOR_SCREEN_TRANSP requires LV_COLOR_DEPTH == 32. Set it in lv_conf.h"
#endif
#if LV_COLOR_DEPTH != 16 && LV_COLOR_16_SWAP != 0
#error "LV_COLOR_16_SWAP requires LV_COLOR_DEPTH == 16. Set it in lv_conf.h"
#endif
#include <stdint.h>
/*********************
* DEFINES
*********************/
#define LV_COLOR_WHITE LV_COLOR_MAKE(0xFF,0xFF,0xFF)
#define LV_COLOR_SILVER LV_COLOR_MAKE(0xC0,0xC0,0xC0)
#define LV_COLOR_GRAY LV_COLOR_MAKE(0x80,0x80,0x80)
#define LV_COLOR_BLACK LV_COLOR_MAKE(0x00,0x00,0x00)
#define LV_COLOR_RED LV_COLOR_MAKE(0xFF,0x00,0x00)
#define LV_COLOR_MAROON LV_COLOR_MAKE(0x80,0x00,0x00)
#define LV_COLOR_YELLOW LV_COLOR_MAKE(0xFF,0xFF,0x00)
#define LV_COLOR_OLIVE LV_COLOR_MAKE(0x80,0x80,0x00)
#define LV_COLOR_LIME LV_COLOR_MAKE(0x00,0xFF,0x00)
#define LV_COLOR_GREEN LV_COLOR_MAKE(0x00,0x80,0x00)
#define LV_COLOR_CYAN LV_COLOR_MAKE(0x00,0xFF,0xFF)
#define LV_COLOR_AQUA LV_COLOR_CYAN
#define LV_COLOR_TEAL LV_COLOR_MAKE(0x00,0x80,0x80)
#define LV_COLOR_BLUE LV_COLOR_MAKE(0x00,0x00,0xFF)
#define LV_COLOR_NAVY LV_COLOR_MAKE(0x00,0x00,0x80)
#define LV_COLOR_MAGENTA LV_COLOR_MAKE(0xFF,0x00,0xFF)
#define LV_COLOR_PURPLE LV_COLOR_MAKE(0x80,0x00,0x80)
#define LV_COLOR_ORANGE LV_COLOR_MAKE(0xFF,0xA5,0x00)
enum {
LV_OPA_TRANSP = 0,
LV_OPA_0 = 0,
LV_OPA_10 = 25,
LV_OPA_20 = 51,
LV_OPA_30 = 76,
LV_OPA_40 = 102,
LV_OPA_50 = 127,
LV_OPA_60 = 153,
LV_OPA_70 = 178,
LV_OPA_80 = 204,
LV_OPA_90 = 229,
LV_OPA_100 = 255,
LV_OPA_COVER = 255,
};
#define LV_OPA_MIN 16 /*Opacities below this will be transparent*/
#define LV_OPA_MAX 251 /*Opacities above this will fully cover*/
#if LV_COLOR_DEPTH == 1
#define LV_COLOR_SIZE 8
#elif LV_COLOR_DEPTH == 8
#define LV_COLOR_SIZE 8
#elif LV_COLOR_DEPTH == 16
#define LV_COLOR_SIZE 16
#elif LV_COLOR_DEPTH == 32
#define LV_COLOR_SIZE 32
#else
#error "Invalid LV_COLOR_DEPTH in lv_conf.h! Set it to 1, 8, 16 or 32!"
#endif
/**********************
* TYPEDEFS
**********************/
typedef union
{
uint8_t blue :1;
uint8_t green :1;
uint8_t red :1;
uint8_t full :1;
} lv_color1_t;
typedef union
{
struct
{
uint8_t blue :2;
uint8_t green :3;
uint8_t red :3;
};
uint8_t full;
} lv_color8_t;
typedef union
{
struct
{
#if LV_COLOR_16_SWAP == 0
uint16_t blue :5;
uint16_t green :6;
uint16_t red :5;
#else
uint16_t green_h :3;
uint16_t red :5;
uint16_t blue :5;
uint16_t green_l :3;
#endif
};
uint16_t full;
} lv_color16_t;
typedef union
{
struct
{
uint8_t blue;
uint8_t green;
uint8_t red;
uint8_t alpha;
};
uint32_t full;
} lv_color32_t;
#if LV_COLOR_DEPTH == 1
typedef uint8_t lv_color_int_t;
typedef lv_color1_t lv_color_t;
#elif LV_COLOR_DEPTH == 8
typedef uint8_t lv_color_int_t;
typedef lv_color8_t lv_color_t;
#elif LV_COLOR_DEPTH == 16
typedef uint16_t lv_color_int_t;
typedef lv_color16_t lv_color_t;
#elif LV_COLOR_DEPTH == 32
typedef uint32_t lv_color_int_t;
typedef lv_color32_t lv_color_t;
#else
#error "Invalid LV_COLOR_DEPTH in lv_conf.h! Set it to 1, 8, 16 or 32!"
#endif
typedef uint8_t lv_opa_t;
typedef struct
{
uint16_t h;
uint8_t s;
uint8_t v;
} lv_color_hsv_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/*In color conversations:
* - When converting to bigger color type the LSB weight of 1 LSB is calculated
* E.g. 16 bit Red has 5 bits
* 8 bit Red has 2 bits
* ----------------------
* 8 bit red LSB = (2^5 - 1) / (2^2 - 1) = 31 / 3 = 10
*
* - When calculating to smaller color type simply shift out the LSBs
* E.g. 8 bit Red has 2 bits
* 16 bit Red has 5 bits
* ----------------------
* Shift right with 5 - 3 = 2
*/
static inline uint8_t lv_color_to1(lv_color_t color)
{
#if LV_COLOR_DEPTH == 1
return color.full;
#elif LV_COLOR_DEPTH == 8
if((color.red & 0x4) ||
(color.green & 0x4) ||
(color.blue & 0x2)) {
return 1;
} else {
return 0;
}
#elif LV_COLOR_DEPTH == 16
# if LV_COLOR_16_SWAP == 0
if((color.red & 0x10) ||
(color.green & 0x20) ||
(color.blue & 0x10)) {
return 1;
# else
if((color.red & 0x10) ||
(color.green_h & 0x20) ||
(color.blue & 0x10)) {
return 1;
# endif
} else {
return 0;
}
#elif LV_COLOR_DEPTH == 32
if((color.red & 0x80) ||
(color.green & 0x80) ||
(color.blue & 0x80)) {
return 1;
} else {
return 0;
}
#endif
}
static inline uint8_t lv_color_to8(lv_color_t color)
{
#if LV_COLOR_DEPTH == 1
if(color.full == 0) return 0;
else return 0xFF;
#elif LV_COLOR_DEPTH == 8
return color.full;
#elif LV_COLOR_DEPTH == 16
# if LV_COLOR_16_SWAP == 0
lv_color8_t ret;
ret.red = color.red >> 2; /* 5 - 3 = 2*/
ret.green = color.green >> 3; /* 6 - 3 = 3*/
ret.blue = color.blue >> 3; /* 5 - 2 = 3*/
return ret.full;
# else
lv_color8_t ret;
ret.red = color.red >> 2; /* 5 - 3 = 2*/
ret.green = color.green_h; /* 6 - 3 = 3*/
ret.blue = color.blue >> 3; /* 5 - 2 = 3*/
return ret.full;
# endif
#elif LV_COLOR_DEPTH == 32
lv_color8_t ret;
ret.red = color.red >> 5; /* 8 - 3 = 5*/
ret.green = color.green >> 5; /* 8 - 3 = 5*/
ret.blue = color.blue >> 6; /* 8 - 2 = 6*/
return ret.full;
#endif
}
static inline uint16_t lv_color_to16(lv_color_t color)
{
#if LV_COLOR_DEPTH == 1
if(color.full == 0) return 0;
else return 0xFFFF;
#elif LV_COLOR_DEPTH == 8
lv_color16_t ret;
# if LV_COLOR_16_SWAP == 0
ret.red = color.red * 4; /*(2^5 - 1)/(2^3 - 1) = 31/7 = 4*/
ret.green = color.green * 9; /*(2^6 - 1)/(2^3 - 1) = 63/7 = 9*/
ret.blue = color.blue * 10; /*(2^5 - 1)/(2^2 - 1) = 31/3 = 10*/
# else
ret.red = color.red * 4;
uint8_t g_tmp = color.green * 9;
ret.green_h = (g_tmp & 0x1F) >> 3;
ret.green_l = g_tmp & 0x07;
ret.blue = color.blue * 10;
# endif
return ret.full;
#elif LV_COLOR_DEPTH == 16
return color.full;
#elif LV_COLOR_DEPTH == 32
lv_color16_t ret;
# if LV_COLOR_16_SWAP == 0
ret.red = color.red >> 3; /* 8 - 5 = 3*/
ret.green = color.green >> 2; /* 8 - 6 = 2*/
ret.blue = color.blue >> 3; /* 8 - 5 = 3*/
# else
ret.red = color.red >> 3;
ret.green_h = (color.green & 0xE0) >> 5;
ret.green_l = (color.green & 0x1C) >> 2;
ret.blue = color.blue >> 3;
# endif
return ret.full;
#endif
}
static inline uint32_t lv_color_to32(lv_color_t color)
{
#if LV_COLOR_DEPTH == 1
if(color.full == 0) return 0;
else return 0xFFFFFFFF;
#elif LV_COLOR_DEPTH == 8
lv_color32_t ret;
ret.red = color.red * 36; /*(2^8 - 1)/(2^3 - 1) = 255/7 = 36*/
ret.green = color.green * 36; /*(2^8 - 1)/(2^3 - 1) = 255/7 = 36*/
ret.blue = color.blue * 85; /*(2^8 - 1)/(2^2 - 1) = 255/3 = 85*/
ret.alpha = 0xFF;
return ret.full;
#elif LV_COLOR_DEPTH == 16
# if LV_COLOR_16_SWAP == 0
lv_color32_t ret;
ret.red = color.red * 8; /*(2^8 - 1)/(2^5 - 1) = 255/31 = 8*/
ret.green = color.green * 4; /*(2^8 - 1)/(2^6 - 1) = 255/63 = 4*/
ret.blue = color.blue * 8; /*(2^8 - 1)/(2^5 - 1) = 255/31 = 8*/
ret.alpha = 0xFF;
return ret.full;
# else
lv_color32_t ret;
ret.red = color.red * 8; /*(2^8 - 1)/(2^5 - 1) = 255/31 = 8*/
ret.green = ((color.green_h << 3) + color.green_l) * 4; /*(2^8 - 1)/(2^6 - 1) = 255/63 = 4*/
ret.blue = color.blue * 8; /*(2^8 - 1)/(2^5 - 1) = 255/31 = 8*/
ret.alpha = 0xFF;
return ret.full;
# endif
#elif LV_COLOR_DEPTH == 32
return color.full;
#endif
}
static inline lv_color_t lv_color_mix(lv_color_t c1, lv_color_t c2, uint8_t mix)
{
lv_color_t ret;
#if LV_COLOR_DEPTH != 1
/*LV_COLOR_DEPTH == 8, 16 or 32*/
ret.red = (uint16_t)((uint16_t) c1.red * mix + (c2.red * (255 - mix))) >> 8;
# if LV_COLOR_DEPTH == 16 && LV_COLOR_16_SWAP
/*If swapped Green is in 2 parts*/
uint16_t g_1 = (c1.green_h << 3) + c1.green_l;
uint16_t g_2 = (c2.green_h << 3) + c2.green_l;
uint16_t g_out = (uint16_t)((uint16_t) g_1 * mix + (g_2 * (255 - mix))) >> 8;
ret.green_h = g_out >> 3;
ret.green_l = g_out & 0x7;
# else
ret.green = (uint16_t)((uint16_t) c1.green * mix + (c2.green * (255 - mix))) >> 8;
# endif
ret.blue = (uint16_t)((uint16_t) c1.blue * mix + (c2.blue * (255 - mix))) >> 8;
# if LV_COLOR_DEPTH == 32
ret.alpha = 0xFF;
# endif
#else
/*LV_COLOR_DEPTH == 1*/
ret.full = mix > LV_OPA_50 ? c1.full : c2.full;
#endif
return ret;
}
/**
* Get the brightness of a color
* @param color a color
* @return the brightness [0..255]
*/
static inline uint8_t lv_color_brightness(lv_color_t color)
{
lv_color32_t c32;
c32.full = lv_color_to32(color);
uint16_t bright = 3 * c32.red + c32.blue + 4 * c32.green;
return (uint16_t) bright >> 3;
}
/* The most simple macro to create a color from R,G and B values
* The order of bit field is different on Big-endian and Little-endian machines*/
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#if LV_COLOR_DEPTH == 1
#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){(b8 >> 7 | g8 >> 7 | r8 >> 7)})
#elif LV_COLOR_DEPTH == 8
#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{b8 >> 6, g8 >> 5, r8 >> 5}})
#elif LV_COLOR_DEPTH == 16
# if LV_COLOR_16_SWAP == 0
# define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{b8 >> 3, g8 >> 2, r8 >> 3}})
# else
# define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{g8 >> 5, r8 >> 3, b8 >> 3, (g8 >> 2) & 0x7}})
# endif
#elif LV_COLOR_DEPTH == 32
#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{b8, g8, r8, 0xff}}) /*Fix 0xff alpha*/
#endif
#else
#if LV_COLOR_DEPTH == 1
#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){(r8 >> 7 | g8 >> 7 | b8 >> 7)})
#elif LV_COLOR_DEPTH == 8
#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{r8 >> 6, g8 >> 5, b8 >> 5}})
#elif LV_COLOR_DEPTH == 16
#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{r8 >> 3, g8 >> 2, b8 >> 3}})
#elif LV_COLOR_DEPTH == 32
#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{0xff, r8, g8, b8}}) /*Fix 0xff alpha*/
#endif
#endif
#define LV_COLOR_HEX(c) LV_COLOR_MAKE((uint8_t) ((uint32_t)((uint32_t)c >> 16) & 0xFF), \
(uint8_t) ((uint32_t)((uint32_t)c >> 8) & 0xFF), \
(uint8_t) ((uint32_t) c & 0xFF))
/*Usage LV_COLOR_HEX3(0x16C) which means LV_COLOR_HEX(0x1166CC)*/
#define LV_COLOR_HEX3(c) LV_COLOR_MAKE((uint8_t) (((c >> 4) & 0xF0) | ((c >> 8) & 0xF)), \
(uint8_t) ((uint32_t)(c & 0xF0) | ((c & 0xF0) >> 4)), \
(uint8_t) ((uint32_t)(c & 0xF) | ((c & 0xF) << 4)))
static inline lv_color_t lv_color_hex(uint32_t c){
return LV_COLOR_HEX(c);
}
static inline lv_color_t lv_color_hex3(uint32_t c){
return LV_COLOR_HEX3(c);
}
/**
* Convert a HSV color to RGB
* @param h hue [0..359]
* @param s saturation [0..100]
* @param v value [0..100]
* @return the given RGB color in RGB (with LV_COLOR_DEPTH depth)
*/
lv_color_t lv_color_hsv_to_rgb(uint16_t h, uint8_t s, uint8_t v);
/**
* Convert an RGB color to HSV
* @param r red
* @param g green
* @param b blue
* @return the given RGB color n HSV
*/
lv_color_hsv_t lv_color_rgb_to_hsv(uint8_t r, uint8_t g, uint8_t b);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*USE_COLOR*/

View File

@ -1,269 +0,0 @@
/**
* @file lv_font.c
*
*/
/*********************
* INCLUDES
*********************/
#include <stddef.h>
#include "lv_font.h"
#include "lv_log.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the fonts
*/
void lv_font_init(void)
{
lv_font_builtin_init();
}
/**
* Add a font to an other to extend the character set.
* @param child the font to add
* @param parent this font will be extended. Using it later will contain the characters from `child`
*/
void lv_font_add(lv_font_t * child, lv_font_t * parent)
{
if(parent == NULL) return;
while(parent->next_page != NULL) {
parent = parent->next_page; /*Got to the last page and add the new font there*/
}
parent->next_page = child;
}
/**
* Remove a font from a character set.
* @param child the font to remove
* @param parent remove `child` from here
*/
void lv_font_remove(lv_font_t * child, lv_font_t * parent)
{
if(parent == NULL) return;
if(child == NULL) return;
while(parent->next_page != child) {
parent = parent->next_page; /*Got to the last page and add the new font there*/
}
parent->next_page = child->next_page;
}
/**
* Tells if font which contains `letter` is monospace or not
* @param font_p point to font
* @param letter an UNICODE character code
* @return true: the letter is monospace; false not monospace
*/
bool lv_font_is_monospace(const lv_font_t * font_p, uint32_t letter)
{
const lv_font_t * font_i = font_p;
int16_t w;
while(font_i != NULL) {
w = font_i->get_width(font_i, letter);
if(w >= 0) {
/*Glyph found*/
if(font_i->monospace) return true;
return false;
}
font_i = font_i->next_page;
}
return 0;
}
/**
* Return with the bitmap of a font.
* @param font_p pointer to a font
* @param letter an UNICODE character code
* @return pointer to the bitmap of the letter
*/
const uint8_t * lv_font_get_bitmap(const lv_font_t * font_p, uint32_t letter)
{
const lv_font_t * font_i = font_p;
while(font_i != NULL) {
const uint8_t * bitmap = font_i->get_bitmap(font_i, letter);
if(bitmap) return bitmap;
font_i = font_i->next_page;
}
return NULL;
}
/**
* Get the width of a letter in a font. If `monospace` is set then return with it.
* @param font_p pointer to a font
* @param letter an UNICODE character code
* @return the width of a letter
*/
uint8_t lv_font_get_width(const lv_font_t * font_p, uint32_t letter)
{
const lv_font_t * font_i = font_p;
int16_t w;
while(font_i != NULL) {
w = font_i->get_width(font_i, letter);
if(w >= 0) {
/*Glyph found*/
uint8_t m = font_i->monospace;
if(m) w = m;
return w;
}
font_i = font_i->next_page;
}
return 0;
}
/**
* Get the width of the letter without overwriting it with the `monospace` attribute
* @param font_p pointer to a font
* @param letter an UNICODE character code
* @return the width of a letter
*/
uint8_t lv_font_get_real_width(const lv_font_t * font_p, uint32_t letter)
{
const lv_font_t * font_i = font_p;
int16_t w;
while(font_i != NULL) {
w = font_i->get_width(font_i, letter);
if(w >= 0) return w;
font_i = font_i->next_page;
}
return 0;
}
/**
* Get the bit-per-pixel of font
* @param font pointer to font
* @param letter a letter from font (font extensions can have different bpp)
* @return bpp of the font (or font extension)
*/
uint8_t lv_font_get_bpp(const lv_font_t * font, uint32_t letter)
{
const lv_font_t * font_i = font;
while(font_i != NULL) {
if(letter >= font_i->unicode_first && letter <= font_i->unicode_last) {
return font_i->bpp;
}
font_i = font_i->next_page;
}
return 0;
}
/**
* Generic bitmap get function used in 'font->get_bitmap' when the font contains all characters in the range
* @param font pointer to font
* @param unicode_letter an unicode letter which bitmap should be get
* @return pointer to the bitmap or NULL if not found
*/
const uint8_t * lv_font_get_bitmap_continuous(const lv_font_t * font, uint32_t unicode_letter)
{
/*Check the range*/
if(unicode_letter < font->unicode_first || unicode_letter > font->unicode_last) return NULL;
uint32_t index = (unicode_letter - font->unicode_first);
return &font->glyph_bitmap[font->glyph_dsc[index].glyph_index];
}
/**
* Generic bitmap get function used in 'font->get_bitmap' when the font NOT contains all characters in the range (sparse)
* @param font pointer to font
* @param unicode_letter an unicode letter which bitmap should be get
* @return pointer to the bitmap or NULL if not found
*/
const uint8_t * lv_font_get_bitmap_sparse(const lv_font_t * font, uint32_t unicode_letter)
{
/*Check the range*/
if(unicode_letter < font->unicode_first || unicode_letter > font->unicode_last) return NULL;
uint32_t i;
for(i = 0; font->unicode_list[i] != 0; i++) {
if(font->unicode_list[i] == unicode_letter) {
return &font->glyph_bitmap[font->glyph_dsc[i].glyph_index];
}
}
return NULL;
}
/**
* Generic glyph width get function used in 'font->get_width' when the font contains all characters in the range
* @param font pointer to font
* @param unicode_letter an unicode letter which width should be get
* @return width of the gylph or -1 if not found
*/
int16_t lv_font_get_width_continuous(const lv_font_t * font, uint32_t unicode_letter)
{
/*Check the range*/
if(unicode_letter < font->unicode_first || unicode_letter > font->unicode_last) {
return -1;
}
uint32_t index = (unicode_letter - font->unicode_first);
return font->glyph_dsc[index].w_px;
}
/**
* Generic glyph width get function used in 'font->get_bitmap' when the font NOT contains all characters in the range (sparse)
* @param font pointer to font
* @param unicode_letter an unicode letter which width should be get
* @return width of the glyph or -1 if not found
*/
int16_t lv_font_get_width_sparse(const lv_font_t * font, uint32_t unicode_letter)
{
/*Check the range*/
if(unicode_letter < font->unicode_first || unicode_letter > font->unicode_last) return -1;
uint32_t i;
for(i = 0; font->unicode_list[i] != 0; i++) {
if(font->unicode_list[i] == unicode_letter) {
return font->glyph_dsc[i].w_px;
}
}
return -1;
}
/**********************
* STATIC FUNCTIONS
**********************/

View File

@ -1,192 +0,0 @@
/**
* @file lv_font.h
*
*/
#ifndef LV_FONT_H
#define LV_FONT_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_conf.h"
#else
#include "../../lv_conf.h"
#endif
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "lv_symbol_def.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef struct
{
uint32_t w_px :8;
uint32_t glyph_index :24;
} lv_font_glyph_dsc_t;
typedef struct
{
uint32_t unicode :21;
uint32_t glyph_dsc_index :11;
} lv_font_unicode_map_t;
typedef struct _lv_font_struct
{
uint32_t unicode_first;
uint32_t unicode_last;
const uint8_t * glyph_bitmap;
const lv_font_glyph_dsc_t * glyph_dsc;
const uint32_t * unicode_list;
const uint8_t * (*get_bitmap)(const struct _lv_font_struct *,uint32_t); /*Get a glyph's bitmap from a font*/
int16_t (*get_width)(const struct _lv_font_struct *,uint32_t); /*Get a glyph's with with a given font*/
struct _lv_font_struct * next_page; /*Pointer to a font extension*/
uint32_t h_px :8;
uint32_t bpp :4; /*Bit per pixel: 1, 2 or 4*/
uint32_t monospace :8; /*Fix width (0: normal width)*/
uint16_t glyph_cnt; /*Number of glyphs (letters) in the font*/
} lv_font_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize the fonts
*/
void lv_font_init(void);
/**
* Add a font to an other to extend the character set.
* @param child the font to add
* @param parent this font will be extended. Using it later will contain the characters from `child`
*/
void lv_font_add(lv_font_t *child, lv_font_t *parent);
/**
* Remove a font from a character set.
* @param child the font to remove
* @param parent remove `child` from here
*/
void lv_font_remove(lv_font_t * child, lv_font_t * parent);
/**
* Tells if font which contains `letter` is monospace or not
* @param font_p point to font
* @param letter an UNICODE character code
* @return true: the letter is monospace; false not monospace
*/
bool lv_font_is_monospace(const lv_font_t * font_p, uint32_t letter);
/**
* Return with the bitmap of a font.
* @param font_p pointer to a font
* @param letter an UNICODE character code
* @return pointer to the bitmap of the letter
*/
const uint8_t * lv_font_get_bitmap(const lv_font_t * font_p, uint32_t letter);
/**
* Get the width of a letter in a font. If `monospace` is set then return with it.
* @param font_p pointer to a font
* @param letter an UNICODE character code
* @return the width of a letter
*/
uint8_t lv_font_get_width(const lv_font_t * font_p, uint32_t letter);
/**
* Get the width of the letter without overwriting it with the `monospace` attribute
* @param font_p pointer to a font
* @param letter an UNICODE character code
* @return the width of a letter
*/
uint8_t lv_font_get_real_width(const lv_font_t * font_p, uint32_t letter);
/**
* Get the height of a font
* @param font_p pointer to a font
* @return the height of a font
*/
static inline uint8_t lv_font_get_height(const lv_font_t * font_p)
{
return font_p->h_px;
}
/**
* Get the bit-per-pixel of font
* @param font pointer to font
* @param letter a letter from font (font extensions can have different bpp)
* @return bpp of the font (or font extension)
*/
uint8_t lv_font_get_bpp(const lv_font_t * font, uint32_t letter);
/**
* Generic bitmap get function used in 'font->get_bitmap' when the font contains all characters in the range
* @param font pointer to font
* @param unicode_letter an unicode letter which bitmap should be get
* @return pointer to the bitmap or NULL if not found
*/
const uint8_t * lv_font_get_bitmap_continuous(const lv_font_t * font, uint32_t unicode_letter);
/**
* Generic bitmap get function used in 'font->get_bitmap' when the font NOT contains all characters in the range (sparse)
* @param font pointer to font
* @param unicode_letter an unicode letter which bitmap should be get
* @return pointer to the bitmap or NULL if not found
*/
const uint8_t * lv_font_get_bitmap_sparse(const lv_font_t * font, uint32_t unicode_letter);
/**
* Generic glyph width get function used in 'font->get_width' when the font contains all characters in the range
* @param font pointer to font
* @param unicode_letter an unicode letter which width should be get
* @return width of the gylph or -1 if not found
*/
int16_t lv_font_get_width_continuous(const lv_font_t * font, uint32_t unicode_letter);
/**
* Generic glyph width get function used in 'font->get_bitmap' when the font NOT contains all characters in the range (sparse)
* @param font pointer to font
* @param unicode_letter an unicode letter which width should be get
* @return width of the glyph or -1 if not found
*/
int16_t lv_font_get_width_sparse(const lv_font_t * font, uint32_t unicode_letter);
/**********************
* MACROS
**********************/
#define LV_FONT_DECLARE(font_name) extern lv_font_t font_name;
/**********************
* ADD BUILT IN FONTS
**********************/
#include "../lv_fonts/lv_font_builtin.h"
/*Declare the custom (user defined) fonts*/
#ifdef LV_FONT_CUSTOM_DECLARE
LV_FONT_CUSTOM_DECLARE
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*USE_FONT*/

View File

@ -1,77 +0,0 @@
/**
* @file lv_gc.h
*
*/
#ifndef LV_GC_H
#define LV_GC_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_conf.h"
#else
#include "../../lv_conf.h"
#endif
#include <stdint.h>
#include <stdbool.h>
#include "lv_mem.h"
#include "lv_ll.h"
/*********************
* DEFINES
*********************/
#define LV_GC_ROOTS(prefix) \
prefix lv_ll_t _lv_task_ll; /*Linked list to store the lv_tasks*/ \
prefix lv_ll_t _lv_scr_ll; /*Linked list of screens*/ \
prefix lv_ll_t _lv_drv_ll;\
prefix lv_ll_t _lv_file_ll;\
prefix lv_ll_t _lv_anim_ll;\
prefix void * _lv_def_scr;\
prefix void * _lv_act_scr;\
prefix void * _lv_top_layer;\
prefix void * _lv_sys_layer;\
prefix void * _lv_task_act;\
prefix void * _lv_indev_list;\
prefix void * _lv_disp_list;\
#define LV_NO_PREFIX
#define LV_ROOTS LV_GC_ROOTS(LV_NO_PREFIX)
#if LV_ENABLE_GC == 1
# if LV_MEM_CUSTOM != 1
# error "GC requires CUSTOM_MEM"
# endif /* LV_MEM_CUSTOM */
#else /* LV_ENABLE_GC */
# define LV_GC_ROOT(x) x
LV_GC_ROOTS(extern)
#endif /* LV_ENABLE_GC */
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_GC_H*/

View File

@ -1,86 +0,0 @@
/**
* @file lv_log.h
*
*/
#ifndef LV_LOG_H
#define LV_LOG_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_conf.h"
#else
#include "../../lv_conf.h"
#endif
#include <stdint.h>
/*********************
* DEFINES
*********************/
/*Possible log level. For compatibility declare it independently from `USE_LV_LOG`*/
#define LV_LOG_LEVEL_TRACE 0 /*A lot of logs to give detailed information*/
#define LV_LOG_LEVEL_INFO 1 /*Log important events*/
#define LV_LOG_LEVEL_WARN 2 /*Log if something unwanted happened but didn't caused problem*/
#define LV_LOG_LEVEL_ERROR 3 /*Only critical issue, when the system may fail*/
#define _LV_LOG_LEVEL_NUM 4
typedef int8_t lv_log_level_t;
#if USE_LV_LOG
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Register custom print (or anything else) function to call when log is added
* @param f a function pointer:
* `void my_print (lv_log_level_t level, const char * file, uint32_t line, const char * dsc)`
*/
void lv_log_register_print(void f(lv_log_level_t, const char *, uint32_t, const char *));
/**
* Add a log
* @param level the level of log. (From `lv_log_level_t` enum)
* @param file name of the file when the log added
* @param line line number in the source code where the log added
* @param dsc description of the log
*/
void lv_log_add(lv_log_level_t level, const char * file, int line, const char * dsc);
/**********************
* MACROS
**********************/
#define LV_LOG_TRACE(dsc) lv_log_add(LV_LOG_LEVEL_TRACE, __FILE__, __LINE__, dsc);
#define LV_LOG_INFO(dsc) lv_log_add(LV_LOG_LEVEL_INFO, __FILE__, __LINE__, dsc);
#define LV_LOG_WARN(dsc) lv_log_add(LV_LOG_LEVEL_WARN, __FILE__, __LINE__, dsc);
#define LV_LOG_ERROR(dsc) lv_log_add(LV_LOG_LEVEL_ERROR, __FILE__, __LINE__, dsc);
#else /*USE_LV_LOG*/
/*Do nothing if `USE_LV_LOG 0`*/
#define lv_log_add(level, file, line, dsc) {;}
#define LV_LOG_TRACE(dsc) {;}
#define LV_LOG_INFO(dsc) {;}
#define LV_LOG_WARN(dsc) {;}
#define LV_LOG_ERROR(dsc) {;}
#endif /*USE_LV_LOG*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_LOG_H*/

View File

@ -1,166 +0,0 @@
/**
* @file lv_math.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_math.h"
#include <stdbool.h>
#include <stdlib.h>
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
static int16_t sin0_90_table[] = {
0, 572, 1144, 1715, 2286, 2856, 3425, 3993, 4560, 5126,
5690, 6252, 6813, 7371, 7927, 8481, 9032, 9580, 10126, 10668,
11207, 11743, 12275, 12803, 13328, 13848, 14364, 14876, 15383, 15886,
16383, 16876, 17364, 17846, 18323, 18794, 19260, 19720, 20173, 20621,
21062, 21497, 21925, 22347, 22762, 23170, 23571, 23964, 24351, 24730,
25101, 25465, 25821, 26169, 26509, 26841, 27165, 27481, 27788, 28087,
28377, 28659, 28932, 29196, 29451, 29697, 29934, 30162, 30381, 30591,
30791, 30982, 31163, 31335, 31498, 31650, 31794, 31927, 32051, 32165,
32269, 32364, 32448, 32523, 32587, 32642, 32687, 32722, 32747, 32762,
32767
};
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Convert a number to string
* @param num a number
* @param buf pointer to a `char` buffer. The result will be stored here (max 10 elements)
* @return same as `buf` (just for convenience)
*/
char * lv_math_num_to_str(int32_t num, char * buf)
{
char * buf_ori = buf;
if(num == 0) {
buf[0] = '0';
buf[1] = '\0';
return buf;
} else if(num < 0) {
(*buf) = '-';
buf++;
num = LV_MATH_ABS(num);
}
uint32_t output = 0;
int8_t i;
for(i = 31; i >= 0; i--) {
if((output & 0xF) >= 5)
output += 3;
if(((output & 0xF0) >> 4) >= 5)
output += (3 << 4);
if(((output & 0xF00) >> 8) >= 5)
output += (3 << 8);
if(((output & 0xF000) >> 12) >= 5)
output += (3 << 12);
if(((output & 0xF0000) >> 16) >= 5)
output += (3 << 16);
if(((output & 0xF00000) >> 20) >= 5)
output += (3 << 20);
if(((output & 0xF000000) >> 24) >= 5)
output += (3 << 24);
if(((output & 0xF0000000) >> 28) >= 5)
output += (3 << 28);
output = (output << 1) | ((num >> i) & 1);
}
uint8_t digit;
bool leading_zero_ready = false;
for(i = 28; i >= 0; i -= 4) {
digit = ((output >> i) & 0xF) + '0';
if(digit == '0' && leading_zero_ready == false) continue;
leading_zero_ready = true;
(*buf) = digit;
buf++;
}
(*buf) = '\0';
return buf_ori;
}
/**
* Return with sinus of an angle
* @param angle
* @return sinus of 'angle'. sin(-90) = -32767, sin(90) = 32767
*/
int16_t lv_trigo_sin(int16_t angle)
{
int16_t ret = 0;
angle = angle % 360;
if(angle < 0) angle = 360 + angle;
if(angle < 90) {
ret = sin0_90_table[angle];
} else if(angle >= 90 && angle < 180) {
angle = 180 - angle;
ret = sin0_90_table[angle];
} else if(angle >= 180 && angle < 270) {
angle = angle - 180;
ret = - sin0_90_table[angle];
} else { /*angle >=270*/
angle = 360 - angle;
ret = - sin0_90_table[angle];
}
return ret;
}
/**
* Calculate a value of a Cubic Bezier function.
* @param t time in range of [0..LV_BEZIER_VAL_MAX]
* @param u0 start values in range of [0..LV_BEZIER_VAL_MAX]
* @param u1 control value 1 values in range of [0..LV_BEZIER_VAL_MAX]
* @param u2 control value 2 in range of [0..LV_BEZIER_VAL_MAX]
* @param u3 end values in range of [0..LV_BEZIER_VAL_MAX]
* @return the value calculated from the given parameters in range of [0..LV_BEZIER_VAL_MAX]
*/
int32_t lv_bezier3(uint32_t t, int32_t u0, int32_t u1, int32_t u2, int32_t u3)
{
uint32_t t_rem = 1024 - t;
uint32_t t_rem2 = (t_rem * t_rem) >> 10;
uint32_t t_rem3 = (t_rem2 * t_rem) >> 10;
uint32_t t2 = (t * t) >> 10;
uint32_t t3 = (t2 * t) >> 10;
uint32_t v1 = ((uint32_t)t_rem3 * u0) >> 10;
uint32_t v2 = ((uint32_t)3 * t_rem2 * t * u1) >> 20;
uint32_t v3 = ((uint32_t)3 * t_rem * t2 * u2) >> 20;
uint32_t v4 = ((uint32_t)t3 * u3) >> 10;
return v1 + v2 + v3 + v4;
}
/**********************
* STATIC FUNCTIONS
**********************/

View File

@ -1,207 +0,0 @@
#ifndef LV_SYMBOL_DEF_H
#define LV_SYMBOL_DEF_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_conf.h"
#else
#include "../../lv_conf.h"
#endif
/*
* With no UTF-8 support (192- 255) (192..241 is used)
*
* With UTF-8 support (in Supplemental Private Use Area-A): 0xF800 .. 0xF831
* - Basic symbols: 0xE000..0xE01F
* - File symbols: 0xE020..0xE03F
* - Feedback symbols: 0xE040..0xE05F
* - Reserved: 0xE060..0xE07F
*/
#if LV_TXT_UTF8 == 0
#define LV_SYMBOL_GLYPH_FIRST 0xC0
#define SYMBOL_AUDIO _SYMBOL_VALUE1(C0)
#define SYMBOL_VIDEO _SYMBOL_VALUE1(C1)
#define SYMBOL_LIST _SYMBOL_VALUE1(C2)
#define SYMBOL_OK _SYMBOL_VALUE1(C3)
#define SYMBOL_CLOSE _SYMBOL_VALUE1(C4)
#define SYMBOL_POWER _SYMBOL_VALUE1(C5)
#define SYMBOL_SETTINGS _SYMBOL_VALUE1(C6)
#define SYMBOL_TRASH _SYMBOL_VALUE1(C7)
#define SYMBOL_HOME _SYMBOL_VALUE1(C8)
#define SYMBOL_DOWNLOAD _SYMBOL_VALUE1(C9)
#define SYMBOL_DRIVE _SYMBOL_VALUE1(CA)
#define SYMBOL_REFRESH _SYMBOL_VALUE1(CB)
#define SYMBOL_MUTE _SYMBOL_VALUE1(CC)
#define SYMBOL_VOLUME_MID _SYMBOL_VALUE1(CD)
#define SYMBOL_VOLUME_MAX _SYMBOL_VALUE1(CE)
#define SYMBOL_IMAGE _SYMBOL_VALUE1(CF)
#define SYMBOL_EDIT _SYMBOL_VALUE1(D0)
#define SYMBOL_PREV _SYMBOL_VALUE1(D1)
#define SYMBOL_PLAY _SYMBOL_VALUE1(D2)
#define SYMBOL_PAUSE _SYMBOL_VALUE1(D3)
#define SYMBOL_STOP _SYMBOL_VALUE1(D4)
#define SYMBOL_NEXT _SYMBOL_VALUE1(D5)
#define SYMBOL_EJECT _SYMBOL_VALUE1(D6)
#define SYMBOL_LEFT _SYMBOL_VALUE1(D7)
#define SYMBOL_RIGHT _SYMBOL_VALUE1(D8)
#define SYMBOL_PLUS _SYMBOL_VALUE1(D9)
#define SYMBOL_MINUS _SYMBOL_VALUE1(DA)
#define SYMBOL_WARNING _SYMBOL_VALUE1(DB)
#define SYMBOL_SHUFFLE _SYMBOL_VALUE1(DC)
#define SYMBOL_UP _SYMBOL_VALUE1(DD)
#define SYMBOL_DOWN _SYMBOL_VALUE1(DE)
#define SYMBOL_LOOP _SYMBOL_VALUE1(DF)
#define SYMBOL_DIRECTORY _SYMBOL_VALUE1(E0)
#define SYMBOL_UPLOAD _SYMBOL_VALUE1(E1)
#define SYMBOL_CALL _SYMBOL_VALUE1(E2)
#define SYMBOL_CUT _SYMBOL_VALUE1(E3)
#define SYMBOL_COPY _SYMBOL_VALUE1(E4)
#define SYMBOL_SAVE _SYMBOL_VALUE1(E5)
#define SYMBOL_CHARGE _SYMBOL_VALUE1(E6)
#define SYMBOL_BELL _SYMBOL_VALUE1(E7)
#define SYMBOL_KEYBOARD _SYMBOL_VALUE1(E8)
#define SYMBOL_GPS _SYMBOL_VALUE1(E9)
#define SYMBOL_FILE _SYMBOL_VALUE1(EA)
#define SYMBOL_WIFI _SYMBOL_VALUE1(EB)
#define SYMBOL_BATTERY_FULL _SYMBOL_VALUE1(EC)
#define SYMBOL_BATTERY_3 _SYMBOL_VALUE1(ED)
#define SYMBOL_BATTERY_2 _SYMBOL_VALUE1(EE)
#define SYMBOL_BATTERY_1 _SYMBOL_VALUE1(EF)
#define SYMBOL_BATTERY_EMPTY _SYMBOL_VALUE1(F0)
#define SYMBOL_BLUETOOTH _SYMBOL_VALUE1(F1)
#define LV_SYMBOL_GLYPH_LAST 0xF1
#define SYMBOL_DUMMY _SYMBOL_VALUE1(FF) /*Invalid symbol. If written before a string then `lv_img` will show it as a label*/
#else
#define LV_SYMBOL_GLYPH_FIRST 0xF800
#define SYMBOL_AUDIO _SYMBOL_VALUE3(EF,A0,80)
#define SYMBOL_VIDEO _SYMBOL_VALUE3(EF,A0,81)
#define SYMBOL_LIST _SYMBOL_VALUE3(EF,A0,82)
#define SYMBOL_OK _SYMBOL_VALUE3(EF,A0,83)
#define SYMBOL_CLOSE _SYMBOL_VALUE3(EF,A0,84)
#define SYMBOL_POWER _SYMBOL_VALUE3(EF,A0,85)
#define SYMBOL_SETTINGS _SYMBOL_VALUE3(EF,A0,86)
#define SYMBOL_TRASH _SYMBOL_VALUE3(EF,A0,87)
#define SYMBOL_HOME _SYMBOL_VALUE3(EF,A0,88)
#define SYMBOL_DOWNLOAD _SYMBOL_VALUE3(EF,A0,89)
#define SYMBOL_DRIVE _SYMBOL_VALUE3(EF,A0,8A)
#define SYMBOL_REFRESH _SYMBOL_VALUE3(EF,A0,8B)
#define SYMBOL_MUTE _SYMBOL_VALUE3(EF,A0,8C)
#define SYMBOL_VOLUME_MID _SYMBOL_VALUE3(EF,A0,8D)
#define SYMBOL_VOLUME_MAX _SYMBOL_VALUE3(EF,A0,8E)
#define SYMBOL_IMAGE _SYMBOL_VALUE3(EF,A0,8F)
#define SYMBOL_EDIT _SYMBOL_VALUE3(EF,A0,90)
#define SYMBOL_PREV _SYMBOL_VALUE3(EF,A0,91)
#define SYMBOL_PLAY _SYMBOL_VALUE3(EF,A0,92)
#define SYMBOL_PAUSE _SYMBOL_VALUE3(EF,A0,93)
#define SYMBOL_STOP _SYMBOL_VALUE3(EF,A0,94)
#define SYMBOL_NEXT _SYMBOL_VALUE3(EF,A0,95)
#define SYMBOL_EJECT _SYMBOL_VALUE3(EF,A0,96)
#define SYMBOL_LEFT _SYMBOL_VALUE3(EF,A0,97)
#define SYMBOL_RIGHT _SYMBOL_VALUE3(EF,A0,98)
#define SYMBOL_PLUS _SYMBOL_VALUE3(EF,A0,99)
#define SYMBOL_MINUS _SYMBOL_VALUE3(EF,A0,9A)
#define SYMBOL_WARNING _SYMBOL_VALUE3(EF,A0,9B)
#define SYMBOL_SHUFFLE _SYMBOL_VALUE3(EF,A0,9C)
#define SYMBOL_UP _SYMBOL_VALUE3(EF,A0,9D)
#define SYMBOL_DOWN _SYMBOL_VALUE3(EF,A0,9E)
#define SYMBOL_LOOP _SYMBOL_VALUE3(EF,A0,9F)
#define SYMBOL_DIRECTORY _SYMBOL_VALUE3(EF,A0,A0)
#define SYMBOL_UPLOAD _SYMBOL_VALUE3(EF,A0,A1)
#define SYMBOL_CALL _SYMBOL_VALUE3(EF,A0,A2)
#define SYMBOL_CUT _SYMBOL_VALUE3(EF,A0,A3)
#define SYMBOL_COPY _SYMBOL_VALUE3(EF,A0,A4)
#define SYMBOL_SAVE _SYMBOL_VALUE3(EF,A0,A5)
#define SYMBOL_CHARGE _SYMBOL_VALUE3(EF,A0,A6)
#define SYMBOL_BELL _SYMBOL_VALUE3(EF,A0,A7)
#define SYMBOL_KEYBOARD _SYMBOL_VALUE3(EF,A0,A8)
#define SYMBOL_GPS _SYMBOL_VALUE3(EF,A0,A9)
#define SYMBOL_FILE _SYMBOL_VALUE3(EF,A0,AA)
#define SYMBOL_WIFI _SYMBOL_VALUE3(EF,A0,AB)
#define SYMBOL_BATTERY_FULL _SYMBOL_VALUE3(EF,A0,AC)
#define SYMBOL_BATTERY_3 _SYMBOL_VALUE3(EF,A0,AD)
#define SYMBOL_BATTERY_2 _SYMBOL_VALUE3(EF,A0,AE)
#define SYMBOL_BATTERY_1 _SYMBOL_VALUE3(EF,A0,AF)
#define SYMBOL_BATTERY_EMPTY _SYMBOL_VALUE3(EF,A0,B0)
#define SYMBOL_BLUETOOTH _SYMBOL_VALUE3(EF,A0,B1)
#define LV_SYMBOL_GLYPH_LAST 0xF831
#define SYMBOL_DUMMY _SYMBOL_VALUE3(EF,A3,BF) /*Invalid symbol at (U+F831). If written before a string then `lv_img` will show it as a label*/
#endif
#define _SYMBOL_VALUE1(x) (0x ## x)
#define _SYMBOL_VALUE3(x, y, z) (0x ## z ## y ## x)
#define _SYMBOL_NUMSTR(sym) LV_ ## sym ## _NUMSTR = sym
enum
{
_SYMBOL_NUMSTR(SYMBOL_AUDIO),
_SYMBOL_NUMSTR(SYMBOL_VIDEO),
_SYMBOL_NUMSTR(SYMBOL_LIST),
_SYMBOL_NUMSTR(SYMBOL_OK),
_SYMBOL_NUMSTR(SYMBOL_CLOSE),
_SYMBOL_NUMSTR(SYMBOL_POWER),
_SYMBOL_NUMSTR(SYMBOL_SETTINGS),
_SYMBOL_NUMSTR(SYMBOL_TRASH),
_SYMBOL_NUMSTR(SYMBOL_HOME),
_SYMBOL_NUMSTR(SYMBOL_DOWNLOAD),
_SYMBOL_NUMSTR(SYMBOL_DRIVE),
_SYMBOL_NUMSTR(SYMBOL_REFRESH),
_SYMBOL_NUMSTR(SYMBOL_MUTE),
_SYMBOL_NUMSTR(SYMBOL_VOLUME_MID),
_SYMBOL_NUMSTR(SYMBOL_VOLUME_MAX),
_SYMBOL_NUMSTR(SYMBOL_IMAGE),
_SYMBOL_NUMSTR(SYMBOL_EDIT),
_SYMBOL_NUMSTR(SYMBOL_PREV),
_SYMBOL_NUMSTR(SYMBOL_PLAY),
_SYMBOL_NUMSTR(SYMBOL_PAUSE),
_SYMBOL_NUMSTR(SYMBOL_STOP),
_SYMBOL_NUMSTR(SYMBOL_NEXT),
_SYMBOL_NUMSTR(SYMBOL_EJECT),
_SYMBOL_NUMSTR(SYMBOL_LEFT),
_SYMBOL_NUMSTR(SYMBOL_RIGHT),
_SYMBOL_NUMSTR(SYMBOL_PLUS),
_SYMBOL_NUMSTR(SYMBOL_MINUS),
_SYMBOL_NUMSTR(SYMBOL_WARNING),
_SYMBOL_NUMSTR(SYMBOL_SHUFFLE),
_SYMBOL_NUMSTR(SYMBOL_UP),
_SYMBOL_NUMSTR(SYMBOL_DOWN),
_SYMBOL_NUMSTR(SYMBOL_LOOP),
_SYMBOL_NUMSTR(SYMBOL_DIRECTORY),
_SYMBOL_NUMSTR(SYMBOL_UPLOAD),
_SYMBOL_NUMSTR(SYMBOL_CALL),
_SYMBOL_NUMSTR(SYMBOL_CUT),
_SYMBOL_NUMSTR(SYMBOL_COPY),
_SYMBOL_NUMSTR(SYMBOL_SAVE),
_SYMBOL_NUMSTR(SYMBOL_CHARGE),
_SYMBOL_NUMSTR(SYMBOL_BELL),
_SYMBOL_NUMSTR(SYMBOL_KEYBOARD),
_SYMBOL_NUMSTR(SYMBOL_GPS),
_SYMBOL_NUMSTR(SYMBOL_FILE),
_SYMBOL_NUMSTR(SYMBOL_WIFI),
_SYMBOL_NUMSTR(SYMBOL_BATTERY_FULL),
_SYMBOL_NUMSTR(SYMBOL_BATTERY_3),
_SYMBOL_NUMSTR(SYMBOL_BATTERY_2),
_SYMBOL_NUMSTR(SYMBOL_BATTERY_1),
_SYMBOL_NUMSTR(SYMBOL_BATTERY_EMPTY),
_SYMBOL_NUMSTR(SYMBOL_BLUETOOTH),
_SYMBOL_NUMSTR(SYMBOL_DUMMY),
};
#undef _SYMBOL_VALUE1
#undef _SYMBOL_VALUE3
#define _SYMBOL_STR_(x) #x
#define _SYMBOL_STR(x) _SYMBOL_STR_(x)
#define _SYMBOL_CHAR(c) \x ## c
#define _SYMBOL_VALUE1(x) _SYMBOL_STR(_SYMBOL_CHAR(x))
#define _SYMBOL_VALUE3(x, y, z) _SYMBOL_STR(_SYMBOL_CHAR(x)_SYMBOL_CHAR(y)_SYMBOL_CHAR(z))
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_SYMBOL_DEF_H*/

View File

@ -1,516 +0,0 @@
/**
* @file lv_ufs.c
* Implementation of RAM file system which do NOT support directories.
* The API is compatible with the lv_fs_int module.
*/
/*********************
* INCLUDES
*********************/
#include "lv_ufs.h"
#if USE_LV_FILESYSTEM
#include "lv_ll.h"
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include "lv_gc.h"
#if defined(LV_GC_INCLUDE)
# include LV_GC_INCLUDE
#endif /* LV_ENABLE_GC */
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static lv_ufs_ent_t * lv_ufs_ent_get(const char * fn);
static lv_ufs_ent_t * lv_ufs_ent_new(const char * fn);
/**********************
* STATIC VARIABLES
**********************/
static bool inited = false;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Create a driver for ufs and initialize it.
*/
void lv_ufs_init(void)
{
lv_ll_init(&LV_GC_ROOT(_lv_file_ll), sizeof(lv_ufs_ent_t));
lv_fs_drv_t ufs_drv;
memset(&ufs_drv, 0, sizeof(lv_fs_drv_t)); /*Initialization*/
ufs_drv.file_size = sizeof(lv_ufs_file_t);
ufs_drv.rddir_size = sizeof(lv_ufs_dir_t);
ufs_drv.letter = UFS_LETTER;
ufs_drv.ready = lv_ufs_ready;
ufs_drv.open = lv_ufs_open;
ufs_drv.close = lv_ufs_close;
ufs_drv.remove = lv_ufs_remove;
ufs_drv.read = lv_ufs_read;
ufs_drv.write = lv_ufs_write;
ufs_drv.seek = lv_ufs_seek;
ufs_drv.tell = lv_ufs_tell;
ufs_drv.size = lv_ufs_size;
ufs_drv.trunc = lv_ufs_trunc;
ufs_drv.free = lv_ufs_free;
ufs_drv.dir_open = lv_ufs_dir_open;
ufs_drv.dir_read = lv_ufs_dir_read;
ufs_drv.dir_close = lv_ufs_dir_close;
lv_fs_add_drv(&ufs_drv);
inited = true;
}
/**
* Give the state of the ufs
* @return true if ufs is initialized and can be used else false
*/
bool lv_ufs_ready(void)
{
return inited;
}
/**
* Open a file in ufs
* @param file_p pointer to a lv_ufs_file_t variable
* @param fn name of the file. There are no directories so e.g. "myfile.txt"
* @param mode element of 'fs_mode_t' enum or its 'OR' connection (e.g. FS_MODE_WR | FS_MODE_RD)
* @return LV_FS_RES_OK: no error, the file is opened
* any error from lv__fs_res_t enum
*/
lv_fs_res_t lv_ufs_open(void * file_p, const char * fn, lv_fs_mode_t mode)
{
lv_ufs_file_t * fp = file_p; /*Convert type*/
lv_ufs_ent_t * ent = lv_ufs_ent_get(fn);
fp->ent = NULL;
/*If the file not exists ...*/
if(ent == NULL) {
if((mode & LV_FS_MODE_WR) != 0) { /*Create the file if opened for write*/
ent = lv_ufs_ent_new(fn);
if(ent == NULL) return LV_FS_RES_FULL; /*No space for the new file*/
} else {
return LV_FS_RES_NOT_EX; /*Can not read not existing file*/
}
}
/*Can not write already opened and const data files*/
if((mode & LV_FS_MODE_WR) != 0) {
if(ent->oc != 0) return LV_FS_RES_LOCKED;
if(ent->const_data != 0) return LV_FS_RES_DENIED;
}
/*No error, the file can be opened*/
fp->ent = ent;
fp->ar = mode & LV_FS_MODE_RD ? 1 : 0;
fp->aw = mode & LV_FS_MODE_WR ? 1 : 0;
fp->rwp = 0;
ent->oc ++;
return LV_FS_RES_OK;
}
/**
* Create a file with a constant data
* @param fn name of the file (directories are not supported)
* @param const_p pointer to a constant data
* @param len length of the data pointed by 'const_p' in bytes
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv__fs_res_t enum
*/
lv_fs_res_t lv_ufs_create_const(const char * fn, const void * const_p, uint32_t len)
{
lv_ufs_file_t file;
lv_fs_res_t res;
/*Error if the file already exists*/
res = lv_ufs_open(&file, fn, LV_FS_MODE_RD);
if(res == LV_FS_RES_OK) {
lv_ufs_close(&file);
return LV_FS_RES_DENIED;
}
lv_ufs_close(&file);
res = lv_ufs_open(&file, fn, LV_FS_MODE_WR);
if(res != LV_FS_RES_OK) return res;
lv_ufs_ent_t * ent = file.ent;
if(ent->data_d != NULL) return LV_FS_RES_DENIED;
ent->data_d = (void *) const_p;
ent->size = len;
ent->const_data = 1;
res = lv_ufs_close(&file);
if(res != LV_FS_RES_OK) return res;
return LV_FS_RES_OK;
}
/**
* Close an opened file
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open)
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv__fs_res_t enum
*/
lv_fs_res_t lv_ufs_close(void * file_p)
{
lv_ufs_file_t * fp = file_p; /*Convert type*/
if(fp->ent == NULL) return LV_FS_RES_OK;
/*Decrement the Open counter*/
if(fp->ent->oc > 0) {
fp->ent->oc--;
}
return LV_FS_RES_OK;
}
/**
* Remove a file. The file can not be opened.
* @param fn '\0' terminated string
* @return LV_FS_RES_OK: no error, the file is removed
* LV_FS_RES_DENIED: the file was opened, remove failed
*/
lv_fs_res_t lv_ufs_remove(const char * fn)
{
lv_ufs_ent_t * ent = lv_ufs_ent_get(fn);
if(ent == NULL) return LV_FS_RES_DENIED; /*File not exists*/
/*Can not be deleted is opened*/
if(ent->oc != 0) return LV_FS_RES_DENIED;
lv_ll_rem(&LV_GC_ROOT(_lv_file_ll), ent);
lv_mem_free(ent->fn_d);
ent->fn_d = NULL;
if(ent->const_data == 0) {
lv_mem_free(ent->data_d);
ent->data_d = NULL;
}
lv_mem_free(ent);
return LV_FS_RES_OK;
}
/**
* Read data from an opened file
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
* @param buf pointer to a memory block where to store the read data
* @param btr number of Bytes To Read
* @param br the real number of read bytes (Byte Read)
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv__fs_res_t enum
*/
lv_fs_res_t lv_ufs_read(void * file_p, void * buf, uint32_t btr, uint32_t * br)
{
lv_ufs_file_t * fp = file_p; /*Convert type*/
lv_ufs_ent_t * ent = fp->ent;
*br = 0;
if(ent->data_d == NULL || ent->size == 0) { /*Don't read empty files*/
return LV_FS_RES_OK;
} else if(fp->ar == 0) { /*The file is not opened for read*/
return LV_FS_RES_DENIED;
}
/*No error, read the file*/
if(fp->rwp + btr > ent->size) { /*Check too much bytes read*/
*br = ent->size - fp->rwp;
} else {
*br = btr;
}
/*Read the data*/
uint8_t * data8_p;
if(ent->const_data == 0) {
data8_p = (uint8_t *) ent->data_d;
} else {
data8_p = ent->data_d;
}
data8_p += fp->rwp;
memcpy(buf, data8_p, *br);
fp->rwp += *br; /*Refresh the read write pointer*/
return LV_FS_RES_OK;
}
/**
* Write data to an opened file
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open)
* @param buf pointer to a memory block which content will be written
* @param btw the number Bytes To Write
* @param bw The real number of written bytes (Byte Written)
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv__fs_res_t enum
*/
lv_fs_res_t lv_ufs_write(void * file_p, const void * buf, uint32_t btw, uint32_t * bw)
{
lv_ufs_file_t * fp = file_p; /*Convert type*/
*bw = 0;
if(fp->aw == 0) return LV_FS_RES_DENIED; /*Not opened for write*/
lv_ufs_ent_t * ent = fp->ent;
/*Reallocate data array if it necessary*/
uint32_t new_size = fp->rwp + btw;
if(new_size > ent->size) {
uint8_t * new_data = lv_mem_realloc(ent->data_d, new_size);
lv_mem_assert(new_data);
if(new_data == NULL) return LV_FS_RES_FULL; /*Cannot allocate the new memory*/
ent->data_d = new_data;
ent->size = new_size;
}
/*Write the file*/
uint8_t * data8_p = (uint8_t *) ent->data_d;
data8_p += fp->rwp;
memcpy(data8_p, buf, btw);
*bw = btw;
fp->rwp += *bw;
return LV_FS_RES_OK;
}
/**
* Set the read write pointer. Also expand the file size if necessary.
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
* @param pos the new position of read write pointer
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv__fs_res_t enum
*/
lv_fs_res_t lv_ufs_seek(void * file_p, uint32_t pos)
{
lv_ufs_file_t * fp = file_p; /*Convert type*/
lv_ufs_ent_t * ent = fp->ent;
/*Simply move the rwp before EOF*/
if(pos < ent->size) {
fp->rwp = pos;
} else { /*Expand the file size*/
if(fp->aw == 0) return LV_FS_RES_DENIED; /*Not opened for write*/
uint8_t * new_data = lv_mem_realloc(ent->data_d, pos);
lv_mem_assert(new_data);
if(new_data == NULL) return LV_FS_RES_FULL; /*Out of memory*/
ent->data_d = new_data;
ent->size = pos;
fp->rwp = pos;
}
return LV_FS_RES_OK;
}
/**
* Give the position of the read write pointer
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
* @param pos_p pointer to to store the result
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv__fs_res_t enum
*/
lv_fs_res_t lv_ufs_tell(void * file_p, uint32_t * pos_p)
{
lv_ufs_file_t * fp = file_p; /*Convert type*/
*pos_p = fp->rwp;
return LV_FS_RES_OK;
}
/**
* Truncate the file size to the current position of the read write pointer
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv__fs_res_t enum
*/
lv_fs_res_t lv_ufs_trunc(void * file_p)
{
lv_ufs_file_t * fp = file_p; /*Convert type*/
lv_ufs_ent_t * ent = fp->ent;
if(fp->aw == 0) return LV_FS_RES_DENIED; /*Not opened for write*/
void * new_data = lv_mem_realloc(ent->data_d, fp->rwp);
lv_mem_assert(new_data);
if(new_data == NULL) return LV_FS_RES_FULL; /*Out of memory*/
ent->data_d = new_data;
ent->size = fp->rwp;
return LV_FS_RES_OK;
}
/**
* Give the size of the file in bytes
* @param file_p file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
* @param size_p pointer to store the size
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv__fs_res_t enum
*/
lv_fs_res_t lv_ufs_size(void * file_p, uint32_t * size_p)
{
lv_ufs_file_t * fp = file_p; /*Convert type*/
lv_ufs_ent_t * ent = fp->ent;
*size_p = ent->size;
return LV_FS_RES_OK;
}
/**
* Initialize a lv_ufs_read_dir_t variable to directory reading
* @param rddir_p pointer to a 'ufs_dir_t' variable
* @param path uFS doesn't support folders so it has to be ""
* @return LV_FS_RES_OK or any error from lv__fs_res_t enum
*/
lv_fs_res_t lv_ufs_dir_open(void * rddir_p, const char * path)
{
lv_ufs_dir_t * lv_ufs_rddir_p = rddir_p;
lv_ufs_rddir_p->last_ent = NULL;
if(path[0] != '\0') return LV_FS_RES_NOT_EX; /*Must be "" */
else return LV_FS_RES_OK;
}
/**
* Read the next file name
* @param dir_p pointer to an initialized 'ufs_dir_t' variable
* @param fn pointer to buffer to sore the file name
* @return LV_FS_RES_OK or any error from lv__fs_res_t enum
*/
lv_fs_res_t lv_ufs_dir_read(void * dir_p, char * fn)
{
lv_ufs_dir_t * ufs_dir_p = dir_p;
if(ufs_dir_p->last_ent == NULL) {
ufs_dir_p->last_ent = lv_ll_get_head(&LV_GC_ROOT(_lv_file_ll));
} else {
ufs_dir_p->last_ent = lv_ll_get_next(&LV_GC_ROOT(_lv_file_ll), ufs_dir_p->last_ent);
}
if(ufs_dir_p->last_ent != NULL) {
strcpy(fn, ufs_dir_p->last_ent->fn_d);
} else {
fn[0] = '\0';
}
return LV_FS_RES_OK;
}
/**
* Close the directory reading
* @param rddir_p pointer to an initialized 'ufs_dir_t' variable
* @return LV_FS_RES_OK or any error from lv__fs_res_t enum
*/
lv_fs_res_t lv_ufs_dir_close(void * rddir_p)
{
(void)rddir_p;
return LV_FS_RES_OK;
}
/**
* Give the size of a drive
* @param total_p pointer to store the total size [kB]
* @param free_p pointer to store the free site [kB]
* @return LV_FS_RES_OK or any error from 'lv_fs_res_t'
*/
lv_fs_res_t lv_ufs_free(uint32_t * total_p, uint32_t * free_p)
{
#if LV_MEM_CUSTOM == 0
lv_mem_monitor_t mon;
lv_mem_monitor(&mon);
*total_p = LV_MEM_SIZE >> 10; /*Convert bytes to kB*/
*free_p = mon.free_size >> 10;
#else
*free_p = 0;
#endif
return LV_FS_RES_OK;
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Gives the lv_ufs_entry from a filename
* @param fn filename ('\0' terminated string)
* @return pointer to the dynamically allocated entry with 'fn' filename.
* NULL if no entry found with that name.
*/
static lv_ufs_ent_t * lv_ufs_ent_get(const char * fn)
{
lv_ufs_ent_t * fp;
LL_READ(LV_GC_ROOT(_lv_file_ll), fp) {
if(strcmp(fp->fn_d, fn) == 0) {
return fp;
}
}
return NULL;
}
/**
* Create a new entry with 'fn' filename
* @param fn filename ('\0' terminated string)
* @return pointer to the dynamically allocated new entry.
* NULL if no space for the entry.
*/
static lv_ufs_ent_t * lv_ufs_ent_new(const char * fn)
{
lv_ufs_ent_t * new_ent = NULL;
new_ent = lv_ll_ins_head(&LV_GC_ROOT(_lv_file_ll)); /*Create a new file*/
lv_mem_assert(new_ent);
if(new_ent == NULL) return NULL;
new_ent->fn_d = lv_mem_alloc(strlen(fn) + 1); /*Save the name*/
lv_mem_assert(new_ent->fn_d);
if(new_ent->fn_d == NULL) return NULL;
strcpy(new_ent->fn_d, fn);
new_ent->data_d = NULL;
new_ent->size = 0;
new_ent->oc = 0;
new_ent->const_data = 0;
return new_ent;
}
#endif /*USE_LV_FILESYSTEM*/

View File

@ -1,214 +0,0 @@
/**
* @file lv_ufs.h
* Implementation of RAM file system which do NOT support directories.
* The API is compatible with the lv_fs_int module.
*/
#ifndef LV_UFS_H
#define LV_UFS_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_conf.h"
#else
#include "../../lv_conf.h"
#endif
#if USE_LV_FILESYSTEM
#include <stdbool.h>
#include "lv_fs.h"
#include "lv_mem.h"
/*********************
* DEFINES
*********************/
#define UFS_LETTER 'U'
/**********************
* TYPEDEFS
**********************/
/*Description of a file entry */
typedef struct
{
char * fn_d;
void * data_d;
uint32_t size; /*Data length in bytes*/
uint16_t oc; /*Open Count*/
uint8_t const_data :1;
} lv_ufs_ent_t;
/*File descriptor, used to handle opening an entry more times simultaneously
Contains unique informations about the specific opening*/
typedef struct
{
lv_ufs_ent_t* ent; /*Pointer to the entry*/
uint32_t rwp; /*Read Write Pointer*/
uint8_t ar :1; /*1: Access for read is enabled */
uint8_t aw :1; /*1: Access for write is enabled */
} lv_ufs_file_t;
/* Read directory descriptor.
* It is used to to iterate through the entries in a directory*/
typedef struct
{
lv_ufs_ent_t * last_ent;
} lv_ufs_dir_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Create a driver for ufs and initialize it.
*/
void lv_ufs_init(void);
/**
* Give the state of the ufs
* @return true if ufs is initialized and can be used else false
*/
bool lv_ufs_ready(void);
/**
* Open a file in ufs
* @param file_p pointer to a lv_ufs_file_t variable
* @param fn name of the file. There are no directories so e.g. "myfile.txt"
* @param mode element of 'fs_mode_t' enum or its 'OR' connection (e.g. FS_MODE_WR | FS_MODE_RD)
* @return LV_FS_RES_OK: no error, the file is opened
* any error from lv_fs_res_t enum
*/
lv_fs_res_t lv_ufs_open (void * file_p, const char * fn, lv_fs_mode_t mode);
/**
* Create a file with a constant data
* @param fn name of the file (directories are not supported)
* @param const_p pointer to a constant data
* @param len length of the data pointed by 'const_p' in bytes
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv_fs_res_t enum
*/
lv_fs_res_t lv_ufs_create_const(const char * fn, const void * const_p, uint32_t len);
/**
* Close an opened file
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open)
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv_fs_res_t enum
*/
lv_fs_res_t lv_ufs_close (void * file_p);
/**
* Remove a file. The file can not be opened.
* @param fn '\0' terminated string
* @return LV_FS_RES_OK: no error, the file is removed
* LV_FS_RES_DENIED: the file was opened, remove failed
*/
lv_fs_res_t lv_ufs_remove(const char * fn);
/**
* Read data from an opened file
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
* @param buf pointer to a memory block where to store the read data
* @param btr number of Bytes To Read
* @param br the real number of read bytes (Byte Read)
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv_fs_res_t enum
*/
lv_fs_res_t lv_ufs_read (void * file_p, void * buf, uint32_t btr, uint32_t * br);
/**
* Write data to an opened file
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open)
* @param buf pointer to a memory block which content will be written
* @param btw the number Bytes To Write
* @param bw The real number of written bytes (Byte Written)
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv_fs_res_t enum
*/
lv_fs_res_t lv_ufs_write (void * file_p, const void * buf, uint32_t btw, uint32_t * bw);
/**
* Set the read write pointer. Also expand the file size if necessary.
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
* @param pos the new position of read write pointer
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv_fs_res_t enum
*/
lv_fs_res_t lv_ufs_seek (void * file_p, uint32_t pos);
/**
* Give the position of the read write pointer
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
* @param pos_p pointer to to store the result
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv_fs_res_t enum
*/
lv_fs_res_t lv_ufs_tell (void * file_p, uint32_t * pos_p);
/**
* Truncate the file size to the current position of the read write pointer
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv_fs_res_t enum
*/
lv_fs_res_t lv_ufs_trunc (void * file_p);
/**
* Give the size of the file in bytes
* @param file_p file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
* @param size_p pointer to store the size
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv_fs_res_t enum
*/
lv_fs_res_t lv_ufs_size (void * file_p, uint32_t * size_p);
/**
* Initialize a lv_ufs_read_dir_t variable to directory reading
* @param rddir_p pointer to a 'ufs_read_dir_t' variable
* @param path uFS doesn't support folders so it has to be ""
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
lv_fs_res_t lv_ufs_dir_open(void * rddir_p, const char * path);
/**
* Read the next file name
* @param dir_p pointer to an initialized 'ufs_read_dir_t' variable
* @param fn pointer to buffer to sore the file name
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
lv_fs_res_t lv_ufs_dir_read(void * dir_p, char * fn);
/**
* Close the directory reading
* @param rddir_p pointer to an initialized 'ufs_read_dir_t' variable
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
lv_fs_res_t lv_ufs_dir_close(void * rddir_p);
/**
* Give the size of a drive
* @param total_p pointer to store the total size [kB]
* @param free_p pointer to store the free site [kB]
* @return LV_FS_RES_OK or any error from 'fs_res_t'
*/
lv_fs_res_t lv_ufs_free (uint32_t * total_p, uint32_t * free_p);
/**********************
* MACROS
**********************/
#endif /*USE_LV_FILESYSTEM*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif

View File

@ -1,881 +0,0 @@
/**
* @file lv_btnm.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_btnm.h"
#if USE_LV_BTNM != 0
#include "../lv_core/lv_group.h"
#include "../lv_draw/lv_draw.h"
#include "../lv_core/lv_refr.h"
#include "../lv_themes/lv_theme.h"
#include "../lv_misc/lv_txt.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static lv_res_t lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param);
static bool lv_btnm_design(lv_obj_t * btnm, const lv_area_t * mask, lv_design_mode_t mode);
static uint8_t get_button_width(const char * btn_str);
static bool button_is_hidden(const char * btn_str);
static bool button_is_repeat_disabled(const char * btn_str);
static bool button_is_inactive(const char * btn_str);
const char * cut_ctrl_byte(const char * btn_str);
static uint16_t get_button_from_point(lv_obj_t * btnm, lv_point_t * p);
static uint16_t get_button_text(lv_obj_t * btnm, uint16_t btn_id);
static void allocate_btn_areas(lv_obj_t * btnm, const char ** map);
/**********************
* STATIC VARIABLES
**********************/
static const char * lv_btnm_def_map[] = {"Btn1", "Btn2", "Btn3", "\n",
"\002Btn4", "Btn5", ""
};
static lv_design_func_t ancestor_design_f;
static lv_signal_func_t ancestor_signal;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Create a button matrix objects
* @param par pointer to an object, it will be the parent of the new button matrix
* @param copy pointer to a button matrix object, if not NULL then the new object will be copied from it
* @return pointer to the created button matrix
*/
lv_obj_t * lv_btnm_create(lv_obj_t * par, const lv_obj_t * copy)
{
LV_LOG_TRACE("button matrix create started");
/*Create the ancestor object*/
lv_obj_t * new_btnm = lv_obj_create(par, copy);
lv_mem_assert(new_btnm);
if(new_btnm == NULL) return NULL;
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_btnm);
/*Allocate the object type specific extended data*/
lv_btnm_ext_t * ext = lv_obj_allocate_ext_attr(new_btnm, sizeof(lv_btnm_ext_t));
lv_mem_assert(ext);
if(ext == NULL) return NULL;
ext->btn_cnt = 0;
ext->btn_id_pr = LV_BTNM_PR_NONE;
ext->btn_id_tgl = LV_BTNM_PR_NONE;
ext->button_areas = NULL;
ext->action = NULL;
ext->map_p = NULL;
ext->toggle = 0;
ext->recolor = 0;
ext->styles_btn[LV_BTN_STATE_REL] = &lv_style_btn_rel;
ext->styles_btn[LV_BTN_STATE_PR] = &lv_style_btn_pr;
ext->styles_btn[LV_BTN_STATE_TGL_REL] = &lv_style_btn_tgl_rel;
ext->styles_btn[LV_BTN_STATE_TGL_PR] = &lv_style_btn_tgl_pr;
ext->styles_btn[LV_BTN_STATE_INA] = &lv_style_btn_ina;
if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_func(new_btnm);
lv_obj_set_signal_func(new_btnm, lv_btnm_signal);
lv_obj_set_design_func(new_btnm, lv_btnm_design);
/*Init the new button matrix object*/
if(copy == NULL) {
lv_obj_set_size(new_btnm, LV_HOR_RES / 2, LV_VER_RES / 4);
lv_btnm_set_map(new_btnm, lv_btnm_def_map);
/*Set the default styles*/
lv_theme_t * th = lv_theme_get_current();
if(th) {
lv_btnm_set_style(new_btnm, LV_BTNM_STYLE_BG, th->btnm.bg);
lv_btnm_set_style(new_btnm, LV_BTNM_STYLE_BTN_REL, th->btnm.btn.rel);
lv_btnm_set_style(new_btnm, LV_BTNM_STYLE_BTN_PR, th->btnm.btn.pr);
lv_btnm_set_style(new_btnm, LV_BTNM_STYLE_BTN_TGL_REL, th->btnm.btn.tgl_rel);
lv_btnm_set_style(new_btnm, LV_BTNM_STYLE_BTN_TGL_PR, th->btnm.btn.tgl_pr);
lv_btnm_set_style(new_btnm, LV_BTNM_STYLE_BTN_INA, th->btnm.btn.ina);
} else {
lv_obj_set_style(new_btnm, &lv_style_pretty);
}
}
/*Copy an existing object*/
else {
lv_btnm_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
memcpy(ext->styles_btn, copy_ext->styles_btn, sizeof(ext->styles_btn));
ext->action = copy_ext->action;
ext->toggle = copy_ext->toggle;
ext->btn_id_tgl = copy_ext->btn_id_tgl;
lv_btnm_set_map(new_btnm, lv_btnm_get_map(copy));
}
LV_LOG_INFO("button matrix created");
return new_btnm;
}
/*=====================
* Setter functions
*====================*/
/**
* Set a new map. Buttons will be created/deleted according to the map.
* @param btnm pointer to a button matrix object
* @param map pointer a string array. The last string has to be: "".
* Use "\n" to begin a new line.
* The first byte can be a control data:
* - bit 7: always 1
* - bit 6: always 0
* - bit 5: inactive (disabled) (\24x)
* - bit 4: no repeat (on long press) (\22x)
* - bit 3: hidden (\21x)
* - bit 2..0: button relative width
* Example (practically use octal numbers): "\224abc": "abc" text with 4 width and no long press
*/
void lv_btnm_set_map(lv_obj_t * btnm, const char ** map)
{
if(map == NULL) return;
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
ext->map_p = map;
/*Analyze the map and create the required number of buttons*/
allocate_btn_areas(btnm, map);
/*Set size and positions of the buttons*/
lv_style_t * style_bg = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BG);
lv_coord_t max_w = lv_obj_get_width(btnm) - 2 * style_bg->body.padding.hor;
lv_coord_t max_h = lv_obj_get_height(btnm) - 2 * style_bg->body.padding.ver;
lv_coord_t act_y = style_bg->body.padding.ver;
/*Count the lines to calculate button height*/
uint8_t line_cnt = 1;
uint8_t li;
for(li = 0; strlen(map[li]) != 0; li++) {
if(strcmp(map[li], "\n") == 0) line_cnt ++;
}
lv_coord_t btn_h = max_h - ((line_cnt - 1) * style_bg->body.padding.inner);
btn_h = btn_h / line_cnt;
btn_h --; /*-1 because e.g. height = 100 means 101 pixels (0..100)*/
/* Count the units and the buttons in a line
* (A button can be 1,2,3... unit wide)*/
uint16_t unit_cnt; /*Number of units in a row*/
uint16_t unit_act_cnt; /*Number of units currently put in a row*/
uint16_t btn_cnt; /*Number of buttons in a row*/
uint16_t i_tot = 0; /*Act. index in the str map*/
uint16_t btn_i = 0; /*Act. index of button areas*/
const char ** map_p_tmp = map;
/*Count the units and the buttons in a line*/
while(1) {
unit_cnt = 0;
btn_cnt = 0;
/*Count the buttons in a line*/
while(strcmp(map_p_tmp[btn_cnt], "\n") != 0 &&
strlen(map_p_tmp[btn_cnt]) != 0) { /*Check a line*/
unit_cnt += get_button_width(map_p_tmp[btn_cnt]);
btn_cnt ++;
}
/*Make sure the last row is at the bottom of 'btnm'*/
if(map_p_tmp[btn_cnt][0] == '\0') { /*Last row?*/
btn_h = max_h - act_y + style_bg->body.padding.ver - 1;
}
/*Only deal with the non empty lines*/
if(btn_cnt != 0) {
/*Calculate the width of all units*/
lv_coord_t all_unit_w = max_w - ((btn_cnt - 1) * style_bg->body.padding.inner);
/*Set the button size and positions and set the texts*/
uint16_t i;
lv_coord_t act_x = style_bg->body.padding.hor;
lv_coord_t act_unit_w;
unit_act_cnt = 0;
for(i = 0; i < btn_cnt; i++) {
/* one_unit_w = all_unit_w / unit_cnt
* act_unit_w = one_unit_w * button_width
* do this two operations but the multiply first to divide a greater number */
act_unit_w = (all_unit_w * get_button_width(map_p_tmp[i])) / unit_cnt;
act_unit_w --; /*-1 because e.g. width = 100 means 101 pixels (0..100)*/
/*Always recalculate act_x because of rounding errors */
act_x = (unit_act_cnt * all_unit_w) / unit_cnt + i * style_bg->body.padding.inner + style_bg->body.padding.hor;
/* Set the button's area.
* If inner padding is zero then use the prev. button x2 as x1 to avoid rounding errors*/
if(style_bg->body.padding.inner == 0 && act_x != style_bg->body.padding.hor) {
lv_area_set(&ext->button_areas[btn_i], ext->button_areas[btn_i - 1].x2, act_y,
act_x + act_unit_w, act_y + btn_h);
} else {
lv_area_set(&ext->button_areas[btn_i], act_x, act_y,
act_x + act_unit_w, act_y + btn_h);
}
unit_act_cnt += get_button_width(map_p_tmp[i]);
i_tot ++;
btn_i ++;
}
}
act_y += btn_h + style_bg->body.padding.inner;
if(strlen(map_p_tmp[btn_cnt]) == 0) break; /*Break on end of map*/
map_p_tmp = &map_p_tmp[btn_cnt + 1]; /*Set the map to the next line*/
i_tot ++; /*Skip the '\n'*/
}
lv_obj_invalidate(btnm);
}
/**
* Set a new callback function for the buttons (It will be called when a button is released)
* @param btnm: pointer to button matrix object
* @param cb pointer to a callback function
*/
void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_action_t action)
{
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
ext->action = action;
}
/**
* Enable or disable button toggling
* @param btnm pointer to button matrix object
* @param en true: enable toggling; false: disable toggling
* @param id index of the currently toggled button (ignored if 'en' == false)
*/
void lv_btnm_set_toggle(lv_obj_t * btnm, bool en, uint16_t id)
{
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
ext->toggle = en == false ? 0 : 1;
if(ext->toggle != 0) {
if(id >= ext->btn_cnt) id = ext->btn_cnt - 1;
ext->btn_id_tgl = id;
} else {
ext->btn_id_tgl = LV_BTNM_PR_NONE;
}
lv_obj_invalidate(btnm);
}
/**
* Set a style of a button matrix
* @param btnm pointer to a button matrix object
* @param type which style should be set
* @param style pointer to a style
*/
void lv_btnm_set_style(lv_obj_t * btnm, lv_btnm_style_t type, lv_style_t * style)
{
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
switch(type) {
case LV_BTNM_STYLE_BG:
lv_obj_set_style(btnm, style);
break;
case LV_BTNM_STYLE_BTN_REL:
ext->styles_btn[LV_BTN_STATE_REL] = style;
lv_obj_invalidate(btnm);
break;
case LV_BTNM_STYLE_BTN_PR:
ext->styles_btn[LV_BTN_STATE_PR] = style;
lv_obj_invalidate(btnm);
break;
case LV_BTNM_STYLE_BTN_TGL_REL:
ext->styles_btn[LV_BTN_STATE_TGL_REL] = style;
lv_obj_invalidate(btnm);
break;
case LV_BTNM_STYLE_BTN_TGL_PR:
ext->styles_btn[LV_BTN_STATE_TGL_PR] = style;
lv_obj_invalidate(btnm);
break;
case LV_BTNM_STYLE_BTN_INA:
ext->styles_btn[LV_BTN_STATE_INA] = style;
lv_obj_invalidate(btnm);
break;
}
}
void lv_btnm_set_recolor(const lv_obj_t * btnm, bool en)
{
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
ext->recolor = en;
lv_obj_invalidate(btnm);
}
/*=====================
* Getter functions
*====================*/
/**
* Get the current map of a button matrix
* @param btnm pointer to a button matrix object
* @return the current map
*/
const char ** lv_btnm_get_map(const lv_obj_t * btnm)
{
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
return ext->map_p;
}
/**
* Get a the callback function of the buttons on a button matrix
* @param btnm: pointer to button matrix object
* @return pointer to the callback function
*/
lv_btnm_action_t lv_btnm_get_action(const lv_obj_t * btnm)
{
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
return ext->action;
}
/**
* Get the pressed button
* @param btnm pointer to button matrix object
* @return index of the currently pressed button (LV_BTNM_PR_NONE: if unset)
*/
uint16_t lv_btnm_get_pressed(const lv_obj_t * btnm)
{
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
return ext->btn_id_pr;
}
/**
* Get the toggled button
* @param btnm pointer to button matrix object
* @return index of the currently toggled button (LV_BTNM_PR_NONE: if unset)
*/
uint16_t lv_btnm_get_toggled(const lv_obj_t * btnm)
{
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
if(ext->toggle == 0) return LV_BTNM_PR_NONE;
else return ext->btn_id_tgl;
}
/**
* Get a style of a button matrix
* @param btnm pointer to a button matrix object
* @param type which style should be get
* @return style pointer to a style
*/
lv_style_t * lv_btnm_get_style(const lv_obj_t * btnm, lv_btnm_style_t type)
{
lv_style_t * style = NULL;
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
switch(type) {
case LV_BTNM_STYLE_BG:
style = lv_obj_get_style(btnm);
break;
case LV_BTNM_STYLE_BTN_REL:
style = ext->styles_btn[LV_BTN_STATE_REL];
break;
case LV_BTNM_STYLE_BTN_PR:
style = ext->styles_btn[LV_BTN_STATE_PR];
break;
case LV_BTNM_STYLE_BTN_TGL_REL:
style = ext->styles_btn[LV_BTN_STATE_TGL_REL];
break;
case LV_BTNM_STYLE_BTN_TGL_PR:
style = ext->styles_btn[LV_BTN_STATE_TGL_PR];
break;
case LV_BTNM_STYLE_BTN_INA:
style = ext->styles_btn[LV_BTN_STATE_INA];
break;
default:
style = NULL;
break;
}
return style;
}
bool lv_btnm_get_recolor(const lv_obj_t * btnm)
{
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
return ext->recolor;
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Handle the drawing related tasks of the button matrixs
* @param btnm pointer to a button matrix object
* @param mask the object will be drawn only in this area
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
* (return 'true' if yes)
* LV_DESIGN_DRAW: draw the object (always return 'true')
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
* @param return true/false, depends on 'mode'
*/
static bool lv_btnm_design(lv_obj_t * btnm, const lv_area_t * mask, lv_design_mode_t mode)
{
if(mode == LV_DESIGN_COVER_CHK) {
return ancestor_design_f(btnm, mask, mode);
/*Return false if the object is not covers the mask_p area*/
}
/*Draw the object*/
else if(mode == LV_DESIGN_DRAW_MAIN) {
ancestor_design_f(btnm, mask, mode);
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
lv_style_t * bg_style = lv_obj_get_style(btnm);
lv_style_t * btn_style;
lv_opa_t opa_scale = lv_obj_get_opa_scale(btnm);
lv_area_t area_btnm;
lv_obj_get_coords(btnm, &area_btnm);
lv_area_t area_tmp;
lv_coord_t btn_w;
lv_coord_t btn_h;
uint16_t btn_i = 0;
uint16_t txt_i = 0;
lv_style_t style_tmp;
lv_txt_flag_t txt_flag = LV_TXT_FLAG_NONE;
if(ext->recolor) txt_flag = LV_TXT_FLAG_RECOLOR;
for(btn_i = 0; btn_i < ext->btn_cnt; btn_i ++, txt_i ++) {
/*Search the next valid text in the map*/
while(strcmp(ext->map_p[txt_i], "\n") == 0) {
txt_i ++;
}
/*Skip hidden buttons*/
if(button_is_hidden(ext->map_p[txt_i])) continue;
lv_area_copy(&area_tmp, &ext->button_areas[btn_i]);
area_tmp.x1 += area_btnm.x1;
area_tmp.y1 += area_btnm.y1;
area_tmp.x2 += area_btnm.x1;
area_tmp.y2 += area_btnm.y1;
btn_w = lv_area_get_width(&area_tmp);
btn_h = lv_area_get_height(&area_tmp);
/*Load the style*/
if(button_is_inactive(ext->map_p[txt_i])) btn_style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BTN_INA);
else if(btn_i != ext->btn_id_pr && btn_i != ext->btn_id_tgl) btn_style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BTN_REL);
else if(btn_i == ext->btn_id_pr && btn_i != ext->btn_id_tgl) btn_style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BTN_PR);
else if(btn_i != ext->btn_id_pr && btn_i == ext->btn_id_tgl) btn_style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BTN_TGL_REL);
else if(btn_i == ext->btn_id_pr && btn_i == ext->btn_id_tgl) btn_style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BTN_TGL_PR);
else btn_style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BTN_REL); /*Not possible option, just to be sure*/
lv_style_copy(&style_tmp, btn_style);
/*Remove borders on the edges if `LV_BORDER_INTERNAL`*/
if(style_tmp.body.border.part & LV_BORDER_INTERNAL) {
if(area_tmp.y1 == btnm->coords.y1 + bg_style->body.padding.ver) {
style_tmp.body.border.part &= ~LV_BORDER_TOP;
}
if(area_tmp.y2 == btnm->coords.y2 - bg_style->body.padding.ver) {
style_tmp.body.border.part &= ~LV_BORDER_BOTTOM;
}
if(txt_i == 0) {
style_tmp.body.border.part &= ~LV_BORDER_LEFT;
}
else if(strcmp(ext->map_p[txt_i - 1],"\n") == 0) {
style_tmp.body.border.part &= ~LV_BORDER_LEFT;
}
if(ext->map_p[txt_i + 1][0] == '\0' || strcmp(ext->map_p[txt_i + 1], "\n") == 0) {
style_tmp.body.border.part &= ~LV_BORDER_RIGHT;
}
}
lv_draw_rect(&area_tmp, mask, &style_tmp, opa_scale);
/*Calculate the size of the text*/
if(btn_style->glass) btn_style = bg_style;
const lv_font_t * font = btn_style->text.font;
lv_point_t txt_size;
lv_txt_get_size(&txt_size, ext->map_p[txt_i], font,
btn_style->text.letter_space, btn_style->text.line_space,
lv_area_get_width(&area_btnm), txt_flag);
area_tmp.x1 += (btn_w - txt_size.x) / 2;
area_tmp.y1 += (btn_h - txt_size.y) / 2;
area_tmp.x2 = area_tmp.x1 + txt_size.x;
area_tmp.y2 = area_tmp.y1 + txt_size.y;
lv_draw_label(&area_tmp, mask, btn_style, opa_scale, ext->map_p[txt_i], txt_flag, NULL);
}
}
return true;
}
/**
* Signal function of the button matrix
* @param btnm pointer to a button matrix object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
*/
static lv_res_t lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param)
{
lv_res_t res;
/* Include the ancient signal function */
res = ancestor_signal(btnm, sign, param);
if(res != LV_RES_OK) return res;
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
lv_area_t btnm_area;
lv_area_t btn_area;
lv_point_t p;
if(sign == LV_SIGNAL_CLEANUP) {
lv_mem_free(ext->button_areas);
} else if(sign == LV_SIGNAL_STYLE_CHG || sign == LV_SIGNAL_CORD_CHG) {
lv_btnm_set_map(btnm, ext->map_p);
} else if(sign == LV_SIGNAL_PRESSING) {
uint16_t btn_pr;
/*Search the pressed area*/
lv_indev_get_point(param, &p);
btn_pr = get_button_from_point(btnm, &p);
/*Invalidate to old and the new areas*/;
lv_obj_get_coords(btnm, &btnm_area);
if(btn_pr != ext->btn_id_pr) {
lv_indev_reset_lpr(param);
if(ext->btn_id_pr != LV_BTNM_PR_NONE) {
lv_area_copy(&btn_area, &ext->button_areas[ext->btn_id_pr]);
btn_area.x1 += btnm_area.x1;
btn_area.y1 += btnm_area.y1;
btn_area.x2 += btnm_area.x1;
btn_area.y2 += btnm_area.y1;
lv_inv_area(&btn_area);
}
if(btn_pr != LV_BTNM_PR_NONE) {
lv_area_copy(&btn_area, &ext->button_areas[btn_pr]);
btn_area.x1 += btnm_area.x1;
btn_area.y1 += btnm_area.y1;
btn_area.x2 += btnm_area.x1;
btn_area.y2 += btnm_area.y1;
lv_inv_area(&btn_area);
}
}
ext->btn_id_pr = btn_pr;
}
else if(sign == LV_SIGNAL_LONG_PRESS_REP) {
if(ext->action && ext->btn_id_pr != LV_BTNM_PR_NONE) {
uint16_t txt_i = get_button_text(btnm, ext->btn_id_pr);
if(txt_i != LV_BTNM_PR_NONE) {
if(button_is_repeat_disabled(ext->map_p[txt_i]) == false &&
button_is_inactive(ext->map_p[txt_i]) == false) {
res = ext->action(btnm, cut_ctrl_byte(ext->map_p[txt_i]));
}
}
}
} else if(sign == LV_SIGNAL_RELEASED) {
if(ext->btn_id_pr != LV_BTNM_PR_NONE) {
uint16_t txt_i = get_button_text(btnm, ext->btn_id_pr);
if(button_is_inactive(ext->map_p[txt_i]) == false && txt_i != LV_BTNM_PR_NONE) { /*Ignore the inactive buttons anf click between the buttons*/
if(ext->action) res = ext->action(btnm, cut_ctrl_byte(ext->map_p[txt_i]));
if(res == LV_RES_OK) {
/*Invalidate to old pressed area*/;
lv_obj_get_coords(btnm, &btnm_area);
lv_area_copy(&btn_area, &ext->button_areas[ext->btn_id_pr]);
btn_area.x1 += btnm_area.x1;
btn_area.y1 += btnm_area.y1;
btn_area.x2 += btnm_area.x1;
btn_area.y2 += btnm_area.y1;
lv_inv_area(&btn_area);
if(ext->toggle != 0) {
/*Invalidate to old toggled area*/;
lv_area_copy(&btn_area, &ext->button_areas[ext->btn_id_tgl]);
btn_area.x1 += btnm_area.x1;
btn_area.y1 += btnm_area.y1;
btn_area.x2 += btnm_area.x1;
btn_area.y2 += btnm_area.y1;
lv_inv_area(&btn_area);
ext->btn_id_tgl = ext->btn_id_pr;
}
#if USE_LV_GROUP
/*Leave the clicked button when releases if this not the focused object in a group*/
lv_group_t * g = lv_obj_get_group(btnm);
if(lv_group_get_focused(g) != btnm) {
ext->btn_id_pr = LV_BTNM_PR_NONE;
}
#else
ext->btn_id_pr = LV_BTNM_PR_NONE;
#endif
}
}
}
} else if(sign == LV_SIGNAL_PRESS_LOST || sign == LV_SIGNAL_DEFOCUS) {
ext->btn_id_pr = LV_BTNM_PR_NONE;
lv_obj_invalidate(btnm);
} else if(sign == LV_SIGNAL_FOCUS) {
#if USE_LV_GROUP
lv_indev_t * indev = lv_indev_get_act();
lv_hal_indev_type_t indev_type = lv_indev_get_type(indev);
if(indev_type == LV_INDEV_TYPE_POINTER) {
/*Select the clicked button*/
lv_point_t p1;
lv_indev_get_point(indev, &p1);
uint16_t btn_i = get_button_from_point(btnm, &p1);
ext->btn_id_pr = btn_i;
} else if(indev_type == LV_INDEV_TYPE_ENCODER) {
/*In navigation mode don't select any button but in edit mode select the fist*/
if(lv_group_get_editing(lv_obj_get_group(btnm))) ext->btn_id_pr = 0;
else ext->btn_id_pr = LV_BTNM_PR_NONE;
} else {
ext->btn_id_pr = 0;
}
#else
ext->btn_id_pr = 0;
#endif
lv_obj_invalidate(btnm);
} else if(sign == LV_SIGNAL_CONTROLL) {
char c = *((char *)param);
if(c == LV_GROUP_KEY_RIGHT) {
if(ext->btn_id_pr == LV_BTNM_PR_NONE) ext->btn_id_pr = 0;
else ext->btn_id_pr++;
if(ext->btn_id_pr >= ext->btn_cnt - 1) ext->btn_id_pr = ext->btn_cnt - 1;
lv_obj_invalidate(btnm);
} else if(c == LV_GROUP_KEY_LEFT) {
if(ext->btn_id_pr == LV_BTNM_PR_NONE) ext->btn_id_pr = 0;
if(ext->btn_id_pr > 0) ext->btn_id_pr--;
lv_obj_invalidate(btnm);
} else if(c == LV_GROUP_KEY_DOWN) {
lv_style_t * style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BG);
/*Find the area below the the current*/
if(ext->btn_id_pr == LV_BTNM_PR_NONE) {
ext->btn_id_pr = 0;
} else {
uint16_t area_below;
lv_coord_t pr_center = ext->button_areas[ext->btn_id_pr].x1 + (lv_area_get_width(&ext->button_areas[ext->btn_id_pr]) >> 1);
for(area_below = ext->btn_id_pr; area_below < ext->btn_cnt; area_below ++) {
if(ext->button_areas[area_below].y1 > ext->button_areas[ext->btn_id_pr].y1 &&
pr_center >= ext->button_areas[area_below].x1 &&
pr_center <= ext->button_areas[area_below].x2 + style->body.padding.hor) {
break;
}
}
if(area_below < ext->btn_cnt) ext->btn_id_pr = area_below;
}
lv_obj_invalidate(btnm);
} else if(c == LV_GROUP_KEY_UP) {
lv_style_t * style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BG);
/*Find the area below the the current*/
if(ext->btn_id_pr == LV_BTNM_PR_NONE) {
ext->btn_id_pr = 0;
} else {
int16_t area_above;
lv_coord_t pr_center = ext->button_areas[ext->btn_id_pr].x1 + (lv_area_get_width(&ext->button_areas[ext->btn_id_pr]) >> 1);
for(area_above = ext->btn_id_pr; area_above >= 0; area_above --) {
if(ext->button_areas[area_above].y1 < ext->button_areas[ext->btn_id_pr].y1 &&
pr_center >= ext->button_areas[area_above].x1 - style->body.padding.hor &&
pr_center <= ext->button_areas[area_above].x2) {
break;
}
}
if(area_above >= 0) ext->btn_id_pr = area_above;
}
lv_obj_invalidate(btnm);
} else if(c == LV_GROUP_KEY_ENTER) {
if(ext->action != NULL) {
uint16_t txt_i = get_button_text(btnm, ext->btn_id_pr);
if(txt_i != LV_BTNM_PR_NONE) {
res = ext->action(btnm, cut_ctrl_byte(ext->map_p[txt_i]));
}
}
}
} else if(sign == LV_SIGNAL_GET_EDITABLE) {
bool * editable = (bool *)param;
*editable = true;
} else if(sign == LV_SIGNAL_GET_TYPE) {
lv_obj_type_t * buf = param;
uint8_t i;
for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/
if(buf->type[i] == NULL) break;
}
buf->type[i] = "lv_btnm";
}
return res;
}
/**
* Create the required number of buttons according to a map
* @param btnm pointer to button matrix object
* @param map_p pointer to a string array
*/
static void allocate_btn_areas(lv_obj_t * btnm, const char ** map)
{
/*Count the buttons in the map*/
uint16_t btn_cnt = 0;
uint16_t i = 0;
while(strlen(map[i]) != 0) {
if(strcmp(map[i], "\n") != 0) { /*Do not count line breaks*/
btn_cnt ++;
}
i++;
}
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
if(ext->button_areas != NULL) {
lv_mem_free(ext->button_areas);
ext->button_areas = NULL;
}
ext->button_areas = lv_mem_alloc(sizeof(lv_area_t) * btn_cnt);
lv_mem_assert(ext->button_areas);
if(ext->button_areas == NULL) btn_cnt = 0;
ext->btn_cnt = btn_cnt;
}
/**
* Get the width of a button in units. It comes from the first "letter".
* @param btn_str The descriptor string of a button. E.g. "apple" or "\004banana"
* @return the width of the button in units
*/
static uint8_t get_button_width(const char * btn_str)
{
if((btn_str[0] & LV_BTNM_CTRL_MASK) == LV_BTNM_CTRL_CODE) {
return btn_str[0] & LV_BTNM_WIDTH_MASK;
}
return 1; /*Default width is 1*/
}
static bool button_is_hidden(const char * btn_str)
{
/*If control byte presents and hidden bit is '1' then the button is hidden*/
if(((btn_str[0] & LV_BTNM_CTRL_MASK) == LV_BTNM_CTRL_CODE) &&
(btn_str[0] & LV_BTNM_HIDE_MASK)) {
return true;
}
return false;
}
static bool button_is_repeat_disabled(const char * btn_str)
{
/*If control byte presents and hidden bit is '1' then the button is hidden*/
if(((btn_str[0] & LV_BTNM_CTRL_MASK) == LV_BTNM_CTRL_CODE) &&
(btn_str[0] & LV_BTNM_REPEAT_DISABLE_MASK)) {
return true;
}
return false;
}
static bool button_is_inactive(const char * btn_str)
{
/*If control byte presents and hidden bit is '1' then the button is hidden*/
if(((btn_str[0] & LV_BTNM_CTRL_MASK) == LV_BTNM_CTRL_CODE) &&
(btn_str[0] & LV_BTNM_INACTIVE_MASK)) {
return true;
}
return false;
}
const char * cut_ctrl_byte(const char * btn_str)
{
/*Cut the control byte if present*/
if((btn_str[0] & LV_BTNM_CTRL_MASK) == LV_BTNM_CTRL_CODE) return &btn_str[1];
else return btn_str;
}
/**
* Gives the button id of a button under a given point
* @param btnm pointer to a button matrix object
* @param p a point with absolute coordinates
* @return the id of the button or LV_BTNM_PR_NONE.
*/
static uint16_t get_button_from_point(lv_obj_t * btnm, lv_point_t * p)
{
lv_area_t btnm_cords;
lv_area_t btn_area;
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
uint16_t i;
lv_obj_get_coords(btnm, &btnm_cords);
for(i = 0; i < ext->btn_cnt; i++) {
lv_area_copy(&btn_area, &ext->button_areas[i]);
btn_area.x1 += btnm_cords.x1;
btn_area.y1 += btnm_cords.y1;
btn_area.x2 += btnm_cords.x1;
btn_area.y2 += btnm_cords.y1;
if(lv_area_is_point_on(&btn_area, p) != false) {
break;
}
}
if(i == ext->btn_cnt) i = LV_BTNM_PR_NONE;
return i;
}
/**
* Get the text of a button
* @param btnm pointer to a button matrix object
* @param btn_id button id
* @return text id in ext->map_p or LV_BTNM_PR_NONE if 'btn_id' was invalid
*/
static uint16_t get_button_text(lv_obj_t * btnm, uint16_t btn_id)
{
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
if(btn_id > ext->btn_cnt) return LV_BTNM_PR_NONE;
uint16_t txt_i = 0;
uint16_t btn_i = 0;
/* Search the text of ext->btn_pr the buttons text in the map
* Skip "\n"-s*/
while(btn_i != btn_id) {
btn_i ++;
txt_i ++;
if(strcmp(ext->map_p[txt_i], "\n") == 0) txt_i ++;
}
if(btn_i == ext->btn_cnt) return LV_BTNM_PR_NONE;
return txt_i;
}
#endif

View File

@ -1,197 +0,0 @@
/**
* @file lv_btnm.h
*
*/
#ifndef LV_BTNM_H
#define LV_BTNM_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_conf.h"
#else
#include "../../lv_conf.h"
#endif
#if USE_LV_BTNM != 0
#include "../lv_core/lv_obj.h"
#include "lv_label.h"
#include "lv_btn.h"
/*********************
* DEFINES
*********************/
/*Control byte*/
#define LV_BTNM_CTRL_CODE 0x80 /*The control byte has to begin (if present) with 0b10xxxxxx*/
#define LV_BTNM_CTRL_MASK 0xC0
#define LV_BTNM_WIDTH_MASK 0x07
#define LV_BTNM_HIDE_MASK 0x08
#define LV_BTNM_REPEAT_DISABLE_MASK 0x10
#define LV_BTNM_INACTIVE_MASK 0x20
#define LV_BTNM_PR_NONE 0xFFFF
/**********************
* TYPEDEFS
**********************/
/* Type of callback function which is called when a button is released or long pressed on the button matrix
* Parameters: button matrix, text of the released button
* return LV_ACTION_RES_INV if the button matrix is deleted else LV_ACTION_RES_OK*/
typedef lv_res_t (*lv_btnm_action_t) (lv_obj_t *, const char *txt);
/*Data of button matrix*/
typedef struct
{
/*No inherited ext.*/ /*Ext. of ancestor*/
/*New data for this type */
const char ** map_p; /*Pointer to the current map*/
lv_area_t *button_areas; /*Array of areas of buttons*/
lv_btnm_action_t action; /*A function to call when a button is releases*/
lv_style_t *styles_btn[LV_BTN_STATE_NUM]; /*Styles of buttons in each state*/
uint16_t btn_cnt; /*Number of button in 'map_p'(Handled by the library)*/
uint16_t btn_id_pr; /*Index of the currently pressed button (in `button_areas`) or LV_BTNM_PR_NONE*/
uint16_t btn_id_tgl; /*Index of the currently toggled button (in `button_areas`) or LV_BTNM_PR_NONE */
uint8_t toggle :1; /*Enable toggling*/
uint8_t recolor :1; /*Enable button recoloring*/
} lv_btnm_ext_t;
enum {
LV_BTNM_STYLE_BG,
LV_BTNM_STYLE_BTN_REL,
LV_BTNM_STYLE_BTN_PR,
LV_BTNM_STYLE_BTN_TGL_REL,
LV_BTNM_STYLE_BTN_TGL_PR,
LV_BTNM_STYLE_BTN_INA,
};
typedef uint8_t lv_btnm_style_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Create a button matrix objects
* @param par pointer to an object, it will be the parent of the new button matrix
* @param copy pointer to a button matrix object, if not NULL then the new object will be copied from it
* @return pointer to the created button matrix
*/
lv_obj_t * lv_btnm_create(lv_obj_t * par, const lv_obj_t * copy);
/*=====================
* Setter functions
*====================*/
/**
* Set a new map. Buttons will be created/deleted according to the map.
* @param btnm pointer to a button matrix object
* @param map pointer a string array. The last string has to be: "".
* Use "\n" to begin a new line.
* The first byte can be a control data:
* - bit 7: always 1
* - bit 6: always 0
* - bit 5: inactive (disabled)
* - bit 4: no repeat (on long press)
* - bit 3: hidden
* - bit 2..0: button relative width
* Example (practically use octal numbers): "\224abc": "abc" text with 4 width and no long press
*/
void lv_btnm_set_map(lv_obj_t * btnm, const char ** map);
/**
* Set a new callback function for the buttons (It will be called when a button is released)
* @param btnm: pointer to button matrix object
* @param action pointer to a callback function
*/
void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_action_t action);
/**
* Enable or disable button toggling
* @param btnm pointer to button matrix object
* @param en true: enable toggling; false: disable toggling
* @param id index of the currently toggled button (ignored if 'en' == false)
*/
void lv_btnm_set_toggle(lv_obj_t * btnm, bool en, uint16_t id);
/**
* Set a style of a button matrix
* @param btnm pointer to a button matrix object
* @param type which style should be set
* @param style pointer to a style
*/
void lv_btnm_set_style(lv_obj_t *btnm, lv_btnm_style_t type, lv_style_t *style);
/**
* Set whether recoloring is enabled
* @param btnm pointer to button matrix object
* @param en whether recoloring is enabled
*/
void lv_btnm_set_recolor(const lv_obj_t * btnm, bool en);
/*=====================
* Getter functions
*====================*/
/**
* Get the current map of a button matrix
* @param btnm pointer to a button matrix object
* @return the current map
*/
const char ** lv_btnm_get_map(const lv_obj_t * btnm);
/**
* Get a the callback function of the buttons on a button matrix
* @param btnm: pointer to button matrix object
* @return pointer to the callback function
*/
lv_btnm_action_t lv_btnm_get_action(const lv_obj_t * btnm);
/**
* Get the pressed button
* @param btnm pointer to button matrix object
* @return index of the currently pressed button (LV_BTNM_PR_NONE: if unset)
*/
uint16_t lv_btnm_get_pressed(const lv_obj_t * btnm);
/**
* Get the toggled button
* @param btnm pointer to button matrix object
* @return index of the currently toggled button (LV_BTNM_PR_NONE: if unset)
*/
uint16_t lv_btnm_get_toggled(const lv_obj_t * btnm);
/**
* Get a style of a button matrix
* @param btnm pointer to a button matrix object
* @param type which style should be get
* @return style pointer to a style
*/
lv_style_t * lv_btnm_get_style(const lv_obj_t *btnm, lv_btnm_style_t type);
/**
* Find whether recoloring is enabled
* @param btnm pointer to button matrix object
* @return whether recoloring is enabled
*/
bool lv_btnm_get_recolor(const lv_obj_t * btnm);
/**********************
* MACROS
**********************/
#endif /*USE_LV_BTNM*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_BTNM_H*/

View File

@ -1,594 +0,0 @@
/**
* @file lv_canvas.c
*
*/
/*********************
* INCLUDES
*********************/
#include <stdlib.h>
#include "lv_canvas.h"
#if USE_LV_CANVAS != 0
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static lv_res_t lv_canvas_signal(lv_obj_t * canvas, lv_signal_t sign, void * param);
/**********************
* STATIC VARIABLES
**********************/
static lv_signal_func_t ancestor_signal;
static lv_design_func_t ancestor_design;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Create a canvas object
* @param par pointer to an object, it will be the parent of the new canvas
* @param copy pointer to a canvas object, if not NULL then the new object will be copied from it
* @return pointer to the created canvas
*/
lv_obj_t * lv_canvas_create(lv_obj_t * par, const lv_obj_t * copy)
{
LV_LOG_TRACE("canvas create started");
/*Create the ancestor of canvas*/
lv_obj_t * new_canvas = lv_img_create(par, copy);
lv_mem_assert(new_canvas);
if(new_canvas == NULL) return NULL;
/*Allocate the canvas type specific extended data*/
lv_canvas_ext_t * ext = lv_obj_allocate_ext_attr(new_canvas, sizeof(lv_canvas_ext_t));
lv_mem_assert(ext);
if(ext == NULL) return NULL;
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_canvas);
if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_canvas);
/*Initialize the allocated 'ext' */
ext->dsc.header.always_zero = 0;
ext->dsc.header.cf = LV_IMG_CF_TRUE_COLOR;
ext->dsc.header.h = 0;
ext->dsc.header.w = 0;
ext->dsc.data_size = 0;
ext->dsc.data = NULL;
lv_img_set_src(new_canvas, &ext->dsc);
/*The signal and design functions are not copied so set them here*/
lv_obj_set_signal_func(new_canvas, lv_canvas_signal);
/*Init the new canvas canvas*/
if(copy == NULL) {
}
/*Copy an existing canvas*/
else {
//lv_canvas_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
/*Refresh the style with new signal function*/
lv_obj_refresh_style(new_canvas);
}
LV_LOG_INFO("canvas created");
return new_canvas;
}
/*=====================
* Setter functions
*====================*/
/**
* Set a buffer for the canvas.
* @param buf a buffer where the content of the canvas will be.
* The required size is (lv_img_color_format_get_px_size(cf) * w * h) / 8)
* It can be allocated with `lv_mem_alloc()` or
* it can be statically allocated array (e.g. static lv_color_t buf[100*50]) or
* it can be an address in RAM or external SRAM
* @param canvas pointer to a canvas object
* @param w width of the canvas
* @param h height of the canvas
* @param cf color format. The following formats are supported:
* LV_IMG_CF_TRUE_COLOR, LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED, LV_IMG_CF_INDEXES_1/2/4/8BIT
*
*/
void lv_canvas_set_buffer(lv_obj_t * canvas, void * buf, lv_coord_t w, lv_coord_t h, lv_img_cf_t cf)
{
lv_canvas_ext_t * ext = lv_obj_get_ext_attr(canvas);
ext->dsc.header.cf = cf;
ext->dsc.header.w = w;
ext->dsc.header.h = h;
ext->dsc.data = buf;
ext->dsc.data_size = (lv_img_color_format_get_px_size(cf) * w * h) / 8;
lv_img_set_src(canvas, &ext->dsc);
}
/**
* Set the color of a pixel on the canvas
* @param canvas
* @param x x coordinate of the point to set
* @param y x coordinate of the point to set
* @param c color of the point
*/
void lv_canvas_set_px(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_color_t c)
{
lv_canvas_ext_t * ext = lv_obj_get_ext_attr(canvas);
if(x >= ext->dsc.header.w || y >= ext->dsc.header.h) {
LV_LOG_WARN("lv_canvas_set_px: x or y out of the canvas");
return;
}
uint8_t * buf_u8 = (uint8_t *) ext->dsc.data;
if(ext->dsc.header.cf == LV_IMG_CF_TRUE_COLOR ||
ext->dsc.header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED)
{
uint32_t px = ext->dsc.header.w * y * sizeof(lv_color_t) + x * sizeof(lv_color_t);
memcpy(&buf_u8[px], &c, sizeof(lv_color_t));
}
else if(ext->dsc.header.cf == LV_IMG_CF_INDEXED_1BIT) {
buf_u8 += 4 * 2;
uint8_t bit = x & 0x7;
x = x >> 3;
uint32_t px = (ext->dsc.header.w >> 3) * y + x;
buf_u8[px] = buf_u8[px] & ~(1 << (7 - bit));
buf_u8[px] = buf_u8[px] | ((c.full & 0x1) << (7 - bit));
}
else if(ext->dsc.header.cf == LV_IMG_CF_INDEXED_2BIT) {
buf_u8 += 4 * 4;
uint8_t bit = (x & 0x3) * 2;
x = x >> 2;
uint32_t px = (ext->dsc.header.w >> 2) * y + x;
buf_u8[px] = buf_u8[px] & ~(3 << (6 - bit));
buf_u8[px] = buf_u8[px] | ((c.full & 0x3) << (6 - bit));
}
else if(ext->dsc.header.cf == LV_IMG_CF_INDEXED_4BIT) {
buf_u8 += 4 * 16;
uint8_t bit = (x & 0x1) * 4;
x = x >> 1;
uint32_t px = (ext->dsc.header.w >> 1) * y + x;
buf_u8[px] = buf_u8[px] & ~(0xF << (4 - bit));
buf_u8[px] = buf_u8[px] | ((c.full & 0xF) << (4 - bit));
}
else if(ext->dsc.header.cf == LV_IMG_CF_INDEXED_8BIT) {
buf_u8 += 4 * 256;
uint32_t px = ext->dsc.header.w * y + x;
buf_u8[px] = c.full;
}
}
/**
* Set a style of a canvas.
* @param canvas pointer to canvas object
* @param type which style should be set
* @param style pointer to a style
*/
void lv_canvas_set_style(lv_obj_t * canvas, lv_canvas_style_t type, lv_style_t * style)
{
switch(type) {
case LV_CANVAS_STYLE_MAIN:
lv_img_set_style(canvas, style);
break;
}
}
/*=====================
* Getter functions
*====================*/
/**
* Get the color of a pixel on the canvas
* @param canvas
* @param x x coordinate of the point to set
* @param y x coordinate of the point to set
* @return color of the point
*/
lv_color_t lv_canvas_get_px(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y)
{
lv_color_t p_color = LV_COLOR_BLACK;
lv_canvas_ext_t * ext = lv_obj_get_ext_attr(canvas);
if(x >= ext->dsc.header.w || y >= ext->dsc.header.h) {
LV_LOG_WARN("lv_canvas_get_px: x or y out of the canvas");
return p_color;
}
uint8_t * buf_u8 = (uint8_t *) ext->dsc.data;
if(ext->dsc.header.cf == LV_IMG_CF_TRUE_COLOR ||
ext->dsc.header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED)
{
uint32_t px = ext->dsc.header.w * y * sizeof(lv_color_t) + x * sizeof(lv_color_t);
memcpy(&p_color, &buf_u8[px], sizeof(lv_color_t));
}
else if(ext->dsc.header.cf == LV_IMG_CF_INDEXED_1BIT) {
buf_u8 += 4 * 2;
uint8_t bit = x & 0x7;
x = x >> 3;
uint32_t px = (ext->dsc.header.w >> 3) * y + x;
p_color.full = (buf_u8[px] & (1 << (7 - bit))) >> (7 - bit);
}
else if(ext->dsc.header.cf == LV_IMG_CF_INDEXED_2BIT) {
buf_u8 += 4 * 4;
uint8_t bit = (x & 0x3) * 2;
x = x >> 2;
uint32_t px = (ext->dsc.header.w >> 2) * y + x;
p_color.full = (buf_u8[px] & (3 << (6 - bit))) >> (6 - bit);
}
else if(ext->dsc.header.cf == LV_IMG_CF_INDEXED_4BIT) {
buf_u8 += 4 * 16;
uint8_t bit = (x & 0x1) * 4;
x = x >> 1;
uint32_t px = (ext->dsc.header.w >> 1) * y + x;
p_color.full = (buf_u8[px] & (0xF << (4 - bit))) >> (4 - bit);
}
else if(ext->dsc.header.cf == LV_IMG_CF_INDEXED_8BIT) {
buf_u8 += 4 * 256;
uint32_t px = ext->dsc.header.w * y + x;
p_color.full = buf_u8[px];
}
return p_color;
}
/**
* Get style of a canvas.
* @param canvas pointer to canvas object
* @param type which style should be get
* @return style pointer to the style
*/
lv_style_t * lv_canvas_get_style(const lv_obj_t * canvas, lv_canvas_style_t type)
{
// lv_canvas_ext_t * ext = lv_obj_get_ext_attr(canvas);
lv_style_t * style = NULL;
switch(type) {
case LV_CANVAS_STYLE_MAIN:
style = lv_img_get_style(canvas);
break;
default:
style = NULL;
}
return style;
}
/*=====================
* Other functions
*====================*/
/**
* Copy a buffer to the canvas
* @param canvas pointer to a canvas object
* @param to_copy buffer to copy. The color format has to match with the canvas's buffer color format
* @param w width of the buffer to copy
* @param h height of the buffer to copy
* @param x left side of the destination position
* @param y top side of the destination position
*/
void lv_canvas_copy_buf(lv_obj_t * canvas, const void * to_copy, lv_coord_t w, lv_coord_t h, lv_coord_t x, lv_coord_t y)
{
lv_canvas_ext_t * ext = lv_obj_get_ext_attr(canvas);
if(x + w >= ext->dsc.header.w || y + h >= ext->dsc.header.h) {
LV_LOG_WARN("lv_canvas_copy_buf: x or y out of the canvas");
return;
}
uint32_t px_size = lv_img_color_format_get_px_size(ext->dsc.header.cf) >> 3;
uint32_t px = ext->dsc.header.w * y * px_size + x * px_size;
uint8_t * to_copy8 = (uint8_t *) to_copy;
lv_coord_t i;
for(i = 0; i < h; i++) {
memcpy((void*)&ext->dsc.data[px], to_copy8, w * px_size);
px += ext->dsc.header.w * px_size;
to_copy8 += w * px_size;
}
}
/**
* Multiply a buffer with the canvas
* @param canvas pointer to a canvas object
* @param to_copy buffer to copy (multiply). LV_IMG_CF_TRUE_COLOR_ALPHA is not supported
* @param w width of the buffer to copy
* @param h height of the buffer to copy
* @param x left side of the destination position
* @param y top side of the destination position
*/
void lv_canvas_mult_buf(lv_obj_t * canvas, void * to_copy, lv_coord_t w, lv_coord_t h, lv_coord_t x, lv_coord_t y)
{
lv_canvas_ext_t * ext = lv_obj_get_ext_attr(canvas);
if(x + w >= ext->dsc.header.w || y + h >= ext->dsc.header.h) {
LV_LOG_WARN("lv_canvas_mult_buf: x or y out of the canvas");
return;
}
if(ext->dsc.header.cf == LV_IMG_CF_TRUE_COLOR_ALPHA) {
LV_LOG_WARN("lv_canvas_mult_buf: LV_IMG_CF_TRUE_COLOR_ALPHA is not supported");
return;
}
uint32_t px_size = lv_img_color_format_get_px_size(ext->dsc.header.cf) >> 3;
uint32_t px = ext->dsc.header.w * y * px_size + x * px_size;
lv_color_t * copy_buf_color = (lv_color_t *) to_copy;
lv_color_t * canvas_buf_color = (lv_color_t *) &ext->dsc.data[px];
lv_coord_t i;
lv_coord_t j;
for(i = 0; i < h; i++) {
for(j = 0; j < w; j++) {
#if LV_COLOR_DEPTH == 32
canvas_buf_color[j].red = (uint16_t) ((uint16_t) canvas_buf_color[j].red * copy_buf_color[j].red) >> 8;
canvas_buf_color[j].green = (uint16_t) ((uint16_t) canvas_buf_color[j].green * copy_buf_color[j].green) >> 8;
canvas_buf_color[j].blue = (uint16_t) ((uint16_t) canvas_buf_color[j].blue * copy_buf_color[j].blue) >> 8;
#elif LV_COLOR_DEPTH == 16
canvas_buf_color[j].red = (uint16_t) ((uint16_t) canvas_buf_color[j].red * copy_buf_color[j].red) >> 5;
canvas_buf_color[j].blue = (uint16_t) ((uint16_t) canvas_buf_color[j].blue * copy_buf_color[j].blue) >> 5;
# if LV_COLOR_16_SWAP == 0
canvas_buf_color[j].green = (uint16_t) ((uint16_t) canvas_buf_color[j].green * copy_buf_color[j].green) >> 6;
# else
uint8_t green_canvas = (canvas_buf_color[j].green_h << 3) + (canvas_buf_color[j].green_l);
uint8_t green_buf = (copy_buf_color[j].green_h << 3) + (copy_buf_color[j].green_l);
uint8_t green_res = (uint16_t)((uint16_t)green_canvas * green_buf) >> 6;
canvas_buf_color[j].green_h = (green_res >> 3) & 0x07;
canvas_buf_color[j].green_l = green_res & 0x07;
# endif /*LV_COLOR_16_SWAP*/
#elif LV_COLOR_DEPTH == 8
canvas_buf_color[j].red = (uint16_t) ((uint16_t) canvas_buf_color[j].red * copy_buf_color[j].red) >> 3;
canvas_buf_color[j].green = (uint16_t) ((uint16_t) canvas_buf_color[j].green * copy_buf_color[j].green) >> 3;
canvas_buf_color[j].blue = (uint16_t) ((uint16_t) canvas_buf_color[j].blue * copy_buf_color[j].blue) >> 2;
#endif
}
copy_buf_color += w;
canvas_buf_color += ext->dsc.header.w;
}
}
/**
* Draw circle function of the canvas
* @param canvas pointer to a canvas object
* @param x0 x coordinate of the circle
* @param y0 y coordinate of the circle
* @param radius radius of the circle
* @param color border color of the circle
*/
void lv_canvas_draw_circle(lv_obj_t * canvas, lv_coord_t x0, lv_coord_t y0, lv_coord_t radius, lv_color_t color)
{
int x = radius;
int y = 0;
int err = 0;
while (x >= y)
{
lv_canvas_set_px(canvas, x0 + x, y0 + y, color);
lv_canvas_set_px(canvas, x0 + y, y0 + x, color);
lv_canvas_set_px(canvas, x0 - y, y0 + x, color);
lv_canvas_set_px(canvas, x0 - x, y0 + y, color);
lv_canvas_set_px(canvas, x0 - x, y0 - y, color);
lv_canvas_set_px(canvas, x0 - y, y0 - x, color);
lv_canvas_set_px(canvas, x0 + y, y0 - x, color);
lv_canvas_set_px(canvas, x0 + x, y0 - y, color);
if (err <= 0)
{
y += 1;
err += 2*y + 1;
}
if (err > 0)
{
x -= 1;
err -= 2*x + 1;
}
}
}
/**
* Draw line function of the canvas
* @param canvas pointer to a canvas object
* @param point1 start point of the line
* @param point2 end point of the line
* @param color color of the line
*
* NOTE: The lv_canvas_draw_line function originates from https://github.com/jb55/bresenham-line.c.
*/
/*
* NOTE: The lv_canvas_draw_line function originates from https://github.com/jb55/bresenham-line.c.
*/
void lv_canvas_draw_line(lv_obj_t * canvas, lv_point_t point1, lv_point_t point2, lv_color_t color)
{
lv_coord_t x0, y0, x1, y1;
x0 = point1.x;
y0 = point1.y;
x1 = point2.x;
y1 = point2.y;
int dx = abs(x1-x0), sx = x0<x1 ? 1 : -1;
int dy = abs(y1-y0), sy = y0<y1 ? 1 : -1;
int err = (dx>dy ? dx : -dy)/2, e2;
for(;;){
lv_canvas_set_px(canvas, x0, y0, color);
if (x0==x1 && y0==y1) break;
e2 = err;
if (e2 >-dx) { err -= dy; x0 += sx; }
if (e2 < dy) { err += dx; y0 += sy; }
}
}
/**
* Draw triangle function of the canvas
* @param canvas pointer to a canvas object
* @param points edge points of the triangle
* @param color line color of the triangle
*/
void lv_canvas_draw_triangle(lv_obj_t * canvas, lv_point_t * points, lv_color_t color)
{
lv_canvas_draw_polygon(canvas, points, 3, color);
}
/**
* Draw rectangle function of the canvas
* @param canvas pointer to a canvas object
* @param points edge points of the rectangle
* @param color line color of the rectangle
*/
void lv_canvas_draw_rect(lv_obj_t * canvas, lv_point_t * points, lv_color_t color)
{
lv_canvas_draw_polygon(canvas, points, 4, color);
}
/**
* Draw polygon function of the canvas
* @param canvas pointer to a canvas object
* @param points edge points of the polygon
* @param size edge count of the polygon
* @param color line color of the polygon
*/
void lv_canvas_draw_polygon(lv_obj_t * canvas, lv_point_t * points, size_t size, lv_color_t color)
{
uint8_t i;
for(i=0; i < (size - 1); i++) {
lv_canvas_draw_line(canvas, points[i], points[i + 1], color);
}
lv_canvas_draw_line(canvas, points[size - 1], points[0], color);
}
/**
* Fill polygon function of the canvas
* @param canvas pointer to a canvas object
* @param points edge points of the polygon
* @param size edge count of the polygon
* @param boundary_color line color of the polygon
* @param fill_color fill color of the polygon
*/
void lv_canvas_fill_polygon(lv_obj_t * canvas, lv_point_t * points, size_t size, lv_color_t boundary_color, lv_color_t fill_color)
{
uint32_t x = 0, y = 0;
uint8_t i;
for(i=0; i<size; i++) {
x += points[i].x;
y += points[i].y;
}
x = x / size;
y = y / size;
lv_canvas_boundary_fill4(canvas, (lv_coord_t) x, (lv_coord_t) y, boundary_color, fill_color);
}
/**
* Boundary fill function of the canvas
* @param canvas pointer to a canvas object
* @param x x coordinate of the start position (seed)
* @param y y coordinate of the start position (seed)
* @param boundary_color edge/boundary color of the area
* @param fill_color fill color of the area
*/
void lv_canvas_boundary_fill4(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_color_t boundary_color, lv_color_t fill_color)
{
lv_color_t c;
c = lv_canvas_get_px(canvas, x, y);
if(c.full != boundary_color.full &&
c.full != fill_color.full)
{
lv_canvas_set_px(canvas, x, y, fill_color);
lv_canvas_boundary_fill4(canvas, x + 1, y, boundary_color, fill_color);
lv_canvas_boundary_fill4(canvas, x, y + 1, boundary_color, fill_color);
lv_canvas_boundary_fill4(canvas, x - 1, y, boundary_color, fill_color);
lv_canvas_boundary_fill4(canvas, x, y - 1, boundary_color, fill_color);
}
}
/**
* Flood fill function of the canvas
* @param canvas pointer to a canvas object
* @param x x coordinate of the start position (seed)
* @param y y coordinate of the start position (seed)
* @param fill_color fill color of the area
* @param bg_color background color of the area
*/
void lv_canvas_flood_fill(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_color_t fill_color, lv_color_t bg_color)
{
lv_color_t c;
c = lv_canvas_get_px(canvas, x, y);
if(c.full == bg_color.full)
{
lv_canvas_set_px(canvas, x, y, fill_color);
lv_canvas_flood_fill(canvas, x+1, y, fill_color, bg_color);
lv_canvas_flood_fill(canvas, x, y+1, fill_color, bg_color);
lv_canvas_flood_fill(canvas, x-1, y, fill_color, bg_color);
lv_canvas_flood_fill(canvas, x, y-1, fill_color, bg_color);
}
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Signal function of the canvas
* @param canvas pointer to a canvas object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
*/
static lv_res_t lv_canvas_signal(lv_obj_t * canvas, lv_signal_t sign, void * param)
{
lv_res_t res;
/* Include the ancient signal function */
res = ancestor_signal(canvas, sign, param);
if(res != LV_RES_OK) return res;
if(sign == LV_SIGNAL_CLEANUP) {
/*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
} else if(sign == LV_SIGNAL_GET_TYPE) {
lv_obj_type_t * buf = param;
uint8_t i;
for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/
if(buf->type[i] == NULL) break;
}
buf->type[i] = "lv_canvas";
}
return res;
}
#endif

View File

@ -1,229 +0,0 @@
/**
* @file lv_canvas.h
*
*/
#ifndef LV_CANVAS_H
#define LV_CANVAS_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_conf.h"
#else
#include "../../lv_conf.h"
#endif
#if USE_LV_CANVAS != 0
#include "../lv_core/lv_obj.h"
#include "../lv_objx/lv_img.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/*Data of canvas*/
typedef struct {
lv_img_ext_t img; /*Ext. of ancestor*/
/*New data for this type */
lv_img_dsc_t dsc;
} lv_canvas_ext_t;
/*Styles*/
enum {
LV_CANVAS_STYLE_MAIN,
};
typedef uint8_t lv_canvas_style_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Create a canvas object
* @param par pointer to an object, it will be the parent of the new canvas
* @param copy pointer to a canvas object, if not NULL then the new object will be copied from it
* @return pointer to the created canvas
*/
lv_obj_t * lv_canvas_create(lv_obj_t * par, const lv_obj_t * copy);
/*=====================
* Setter functions
*====================*/
/**
* Set a buffer for the canvas.
* @param buf a buffer where the content of the canvas will be.
* The required size is (lv_img_color_format_get_px_size(cf) * w * h) / 8)
* It can be allocated with `lv_mem_alloc()` or
* it can be statically allocated array (e.g. static lv_color_t buf[100*50]) or
* it can be an address in RAM or external SRAM
* @param canvas pointer to a canvas object
* @param w width of the canvas
* @param h height of the canvas
* @param cf color format. The following formats are supported:
* LV_IMG_CF_TRUE_COLOR, LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED, LV_IMG_CF_INDEXES_1/2/4/8BIT
*/
void lv_canvas_set_buffer(lv_obj_t * canvas, void * buf, lv_coord_t w, lv_coord_t h, lv_img_cf_t cf);
/**
* Set the color of a pixel on the canvas
* @param canvas
* @param x x coordinate of the point to set
* @param y x coordinate of the point to set
* @param c color of the point
*/
void lv_canvas_set_px(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_color_t c);
/**
* Set a style of a canvas.
* @param canvas pointer to canvas object
* @param type which style should be set
* @param style pointer to a style
*/
void lv_canvas_set_style(lv_obj_t * canvas, lv_canvas_style_t type, lv_style_t * style);
/*=====================
* Getter functions
*====================*/
/**
* Get the color of a pixel on the canvas
* @param canvas
* @param x x coordinate of the point to set
* @param y x coordinate of the point to set
* @return color of the point
*/
lv_color_t lv_canvas_get_px(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y);
/**
* Get style of a canvas.
* @param canvas pointer to canvas object
* @param type which style should be get
* @return style pointer to the style
*/
lv_style_t * lv_canvas_get_style(const lv_obj_t * canvas, lv_canvas_style_t type);
/*=====================
* Other functions
*====================*/
/**
* Copy a buffer to the canvas
* @param canvas pointer to a canvas object
* @param to_copy buffer to copy. The color format has to match with the canvas's buffer color format
* @param w width of the buffer to copy
* @param h height of the buffer to copy
* @param x left side of the destination position
* @param y top side of the destination position
*/
void lv_canvas_copy_buf(lv_obj_t * canvas, const void * to_copy, lv_coord_t w, lv_coord_t h, lv_coord_t x, lv_coord_t y);
/**
* Multiply a buffer with the canvas
* @param canvas pointer to a canvas object
* @param to_copy buffer to copy (multiply). LV_IMG_CF_TRUE_COLOR_ALPHA is not supported
* @param w width of the buffer to copy
* @param h height of the buffer to copy
* @param x left side of the destination position
* @param y top side of the destination position
*/
void lv_canvas_mult_buf(lv_obj_t * canvas, void * to_copy, lv_coord_t w, lv_coord_t h, lv_coord_t x, lv_coord_t y);
/**
* Draw circle function of the canvas
* @param canvas pointer to a canvas object
* @param x0 x coordinate of the circle
* @param y0 y coordinate of the circle
* @param radius radius of the circle
* @param color border color of the circle
*/
void lv_canvas_draw_circle(lv_obj_t * canvas, lv_coord_t x0, lv_coord_t y0, lv_coord_t radius, lv_color_t color);
/**
* Draw line function of the canvas
* @param canvas pointer to a canvas object
* @param point1 start point of the line
* @param point2 end point of the line
* @param color color of the line
*
* NOTE: The lv_canvas_draw_line function originates from https://github.com/jb55/bresenham-line.c.
*/
void lv_canvas_draw_line(lv_obj_t * canvas, lv_point_t point1, lv_point_t point2, lv_color_t color);
/**
* Draw triangle function of the canvas
* @param canvas pointer to a canvas object
* @param points edge points of the triangle
* @param color line color of the triangle
*/
void lv_canvas_draw_triangle(lv_obj_t * canvas, lv_point_t * points, lv_color_t color);
/**
* Draw rectangle function of the canvas
* @param canvas pointer to a canvas object
* @param points edge points of the rectangle
* @param color line color of the rectangle
*/
void lv_canvas_draw_rect(lv_obj_t * canvas, lv_point_t * points, lv_color_t color);
/**
* Draw polygon function of the canvas
* @param canvas pointer to a canvas object
* @param points edge points of the polygon
* @param size edge count of the polygon
* @param color line color of the polygon
*/
void lv_canvas_draw_polygon(lv_obj_t * canvas, lv_point_t * points, size_t size, lv_color_t color);
/**
* Fill polygon function of the canvas
* @param canvas pointer to a canvas object
* @param points edge points of the polygon
* @param size edge count of the polygon
* @param boundary_color line color of the polygon
* @param fill_color fill color of the polygon
*/
void lv_canvas_fill_polygon(lv_obj_t * canvas, lv_point_t * points, size_t size, lv_color_t boundary_color, lv_color_t fill_color);
/**
* Boundary fill function of the canvas
* @param canvas pointer to a canvas object
* @param x x coordinate of the start position (seed)
* @param y y coordinate of the start position (seed)
* @param boundary_color edge/boundary color of the area
* @param fill_color fill color of the area
*/
void lv_canvas_boundary_fill4(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_color_t boundary_color, lv_color_t fill_color);
/**
* Flood fill function of the canvas
* @param canvas pointer to a canvas object
* @param x x coordinate of the start position (seed)
* @param y y coordinate of the start position (seed)
* @param fill_color fill color of the area
* @param bg_color background color of the area
*/
void lv_canvas_flood_fill(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_color_t fill_color, lv_color_t bg_color);
/**********************
* MACROS
**********************/
#endif /*USE_LV_CANVAS*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_CANVAS_H*/

View File

@ -1,824 +0,0 @@
/**
* @file lv_chart.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_chart.h"
#if USE_LV_CHART != 0
#include "../lv_draw/lv_draw.h"
#include "../lv_themes/lv_theme.h"
/*********************
* DEFINES
*********************/
#define LV_CHART_YMIN_DEF 0
#define LV_CHART_YMAX_DEF 100
#define LV_CHART_HDIV_DEF 3
#define LV_CHART_VDIV_DEF 5
#define LV_CHART_PNUM_DEF 10
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static bool lv_chart_design(lv_obj_t * chart, const lv_area_t * mask, lv_design_mode_t mode);
static lv_res_t lv_chart_signal(lv_obj_t * chart, lv_signal_t sign, void * param);
static void lv_chart_draw_div(lv_obj_t * chart, const lv_area_t * mask);
static void lv_chart_draw_lines(lv_obj_t * chart, const lv_area_t * mask);
static void lv_chart_draw_points(lv_obj_t * chart, const lv_area_t * mask);
static void lv_chart_draw_cols(lv_obj_t * chart, const lv_area_t * mask);
static void lv_chart_draw_vertical_lines(lv_obj_t * chart, const lv_area_t * mask);
/**********************
* STATIC VARIABLES
**********************/
static lv_design_func_t ancestor_design_f;
static lv_signal_func_t ancestor_signal;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Create a chart background objects
* @param par pointer to an object, it will be the parent of the new chart background
* @param copy pointer to a chart background object, if not NULL then the new object will be copied from it
* @return pointer to the created chart background
*/
lv_obj_t * lv_chart_create(lv_obj_t * par, const lv_obj_t * copy)
{
LV_LOG_TRACE("chart create started");
/*Create the ancestor basic object*/
lv_obj_t * new_chart = lv_obj_create(par, copy);
lv_mem_assert(new_chart);
if(new_chart == NULL) return NULL;
/*Allocate the object type specific extended data*/
lv_chart_ext_t * ext = lv_obj_allocate_ext_attr(new_chart, sizeof(lv_chart_ext_t));
lv_mem_assert(ext);
if(ext == NULL) return NULL;
lv_ll_init(&ext->series_ll, sizeof(lv_chart_series_t));
ext->series.num = 0;
ext->ymin = LV_CHART_YMIN_DEF;
ext->ymax = LV_CHART_YMAX_DEF;
ext->hdiv_cnt = LV_CHART_HDIV_DEF;
ext->vdiv_cnt = LV_CHART_VDIV_DEF;
ext->point_cnt = LV_CHART_PNUM_DEF;
ext->type = LV_CHART_TYPE_LINE;
ext->series.opa = LV_OPA_COVER;
ext->series.dark = LV_OPA_50;
ext->series.width = 2;
if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_func(new_chart);
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_chart);
lv_obj_set_signal_func(new_chart, lv_chart_signal);
lv_obj_set_design_func(new_chart, lv_chart_design);
/*Init the new chart background object*/
if(copy == NULL) {
lv_obj_set_size(new_chart, LV_HOR_RES / 3, LV_VER_RES / 3);
/*Set the default styles*/
lv_theme_t * th = lv_theme_get_current();
if(th) {
lv_chart_set_style(new_chart, th->chart);
} else {
lv_chart_set_style(new_chart, &lv_style_pretty);
}
} else {
lv_chart_ext_t * ext_copy = lv_obj_get_ext_attr(copy);
ext->type = ext_copy->type;
ext->ymin = ext_copy->ymin;
ext->ymax = ext_copy->ymax;
ext->hdiv_cnt = ext_copy->hdiv_cnt;
ext->vdiv_cnt = ext_copy->vdiv_cnt;
ext->point_cnt = ext_copy->point_cnt;
ext->series.opa = ext_copy->series.opa;
/*Refresh the style with new signal function*/
lv_obj_refresh_style(new_chart);
}
LV_LOG_INFO("chart created");
return new_chart;
}
/*======================
* Add/remove functions
*=====================*/
/**
* Allocate and add a data series to the chart
* @param chart pointer to a chart object
* @param color color of the data series
* @return pointer to the allocated data series
*/
lv_chart_series_t * lv_chart_add_series(lv_obj_t * chart, lv_color_t color)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
lv_chart_series_t * ser = lv_ll_ins_head(&ext->series_ll);
lv_mem_assert(ser);
if(ser == NULL) return NULL;
lv_coord_t def = LV_CHART_POINT_DEF;
if(ser == NULL) return NULL;
ser->color = color;
ser->points = lv_mem_alloc(sizeof(lv_coord_t) * ext->point_cnt);
lv_mem_assert(ser->points);
if(ser->points == NULL) {
lv_ll_rem(&ext->series_ll, ser);
lv_mem_free(ser);
return NULL;
}
ser->start_point = 0;
uint16_t i;
lv_coord_t * p_tmp = ser->points;
for(i = 0; i < ext->point_cnt; i++) {
*p_tmp = def;
p_tmp++;
}
ext->series.num++;
return ser;
}
/**
* Clear the point of a serie
* @param chart pointer to a chart object
* @param serie pointer to the chart's serie to clear
*/
void lv_chart_clear_serie(lv_obj_t * chart, lv_chart_series_t * serie)
{
if(chart == NULL || serie == NULL)
return;
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
if(ext == NULL) return;
uint32_t i;
for(i = 0; i < ext->point_cnt; i++)
{
serie->points[i] = LV_CHART_POINT_DEF;
}
serie->start_point = 0;
}
/*=====================
* Setter functions
*====================*/
/**
* Set the number of horizontal and vertical division lines
* @param chart pointer to a graph background object
* @param hdiv number of horizontal division lines
* @param vdiv number of vertical division lines
*/
void lv_chart_set_div_line_count(lv_obj_t * chart, uint8_t hdiv, uint8_t vdiv)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
if(ext->hdiv_cnt == hdiv && ext->vdiv_cnt == vdiv) return;
ext->hdiv_cnt = hdiv;
ext->vdiv_cnt = vdiv;
lv_obj_invalidate(chart);
}
/**
* Set the minimal and maximal y values
* @param chart pointer to a graph background object
* @param ymin y minimum value
* @param ymax y maximum value
*/
void lv_chart_set_range(lv_obj_t * chart, lv_coord_t ymin, lv_coord_t ymax)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
if(ext->ymin == ymin && ext->ymax == ymax) return;
ext->ymin = ymin;
ext->ymax = ymax;
lv_chart_refresh(chart);
}
/**
* Set a new type for a chart
* @param chart pointer to a chart object
* @param type new type of the chart (from 'lv_chart_type_t' enum)
*/
void lv_chart_set_type(lv_obj_t * chart, lv_chart_type_t type)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
if(ext->type == type) return;
ext->type = type;
lv_chart_refresh(chart);
}
/**
* Set the number of points on a data line on a chart
* @param chart pointer r to chart object
* @param point_cnt new number of points on the data lines
*/
void lv_chart_set_point_count(lv_obj_t * chart, uint16_t point_cnt)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
if(ext->point_cnt == point_cnt) return;
lv_chart_series_t * ser;
uint16_t point_cnt_old = ext->point_cnt;
uint16_t i;
lv_coord_t def = LV_CHART_POINT_DEF;
if(point_cnt < 1) point_cnt = 1;
LL_READ_BACK(ext->series_ll, ser) {
if(ser->start_point != 0) {
lv_coord_t * new_points = lv_mem_alloc(sizeof(lv_coord_t) * point_cnt);
lv_mem_assert(new_points);
if(new_points == NULL) return;
if(point_cnt >= point_cnt_old) {
for(i = 0; i < point_cnt_old; i++) {
new_points[i] = ser->points[(i + ser->start_point) % point_cnt_old]; /*Copy old contents to new array*/
}
for(i = point_cnt_old; i < point_cnt; i++) {
new_points[i] = def; /*Fill up the rest with default value*/
}
} else {
for(i = 0; i < point_cnt; i++) {
new_points[i] = ser->points[(i + ser->start_point) % point_cnt_old]; /*Copy old contents to new array*/
}
}
/*Switch over pointer from old to new*/
lv_mem_free(ser->points);
ser->points = new_points;
} else {
ser->points = lv_mem_realloc(ser->points, sizeof(lv_coord_t) * point_cnt);
lv_mem_assert(ser->points);
if(ser->points == NULL) return;
/*Initialize the new points*/
if(point_cnt > point_cnt_old) {
for(i = point_cnt_old - 1; i < point_cnt; i++) {
ser->points[i] = def;
}
}
}
ser->start_point = 0;
}
ext->point_cnt = point_cnt;
lv_chart_refresh(chart);
}
/**
* Set the opacity of the data series
* @param chart pointer to a chart object
* @param opa opacity of the data series
*/
void lv_chart_set_series_opa(lv_obj_t * chart, lv_opa_t opa)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
if(ext->series.opa == opa) return;
ext->series.opa = opa;
lv_obj_invalidate(chart);
}
/**
* Set the line width or point radius of the data series
* @param chart pointer to a chart object
* @param width the new width
*/
void lv_chart_set_series_width(lv_obj_t * chart, lv_coord_t width)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
if(ext->series.width == width) return;
ext->series.width = width;
lv_obj_invalidate(chart);
}
/**
* Set the dark effect on the bottom of the points or columns
* @param chart pointer to a chart object
* @param dark_eff dark effect level (LV_OPA_TRANSP to turn off)
*/
void lv_chart_set_series_darking(lv_obj_t * chart, lv_opa_t dark_eff)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
if(ext->series.dark == dark_eff) return;
ext->series.dark = dark_eff;
lv_obj_invalidate(chart);
}
/**
* Initialize all data points with a value
* @param chart pointer to chart object
* @param ser pointer to a data series on 'chart'
* @param y the new value for all points
*/
void lv_chart_init_points(lv_obj_t * chart, lv_chart_series_t * ser, lv_coord_t y)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
uint16_t i;
for(i = 0; i < ext->point_cnt; i++) {
ser->points[i] = y;
}
ser->start_point = 0;
lv_chart_refresh(chart);
}
/**
* Set the value s of points from an array
* @param chart pointer to chart object
* @param ser pointer to a data series on 'chart'
* @param y_array array of 'lv_coord_t' points (with 'points count' elements )
*/
void lv_chart_set_points(lv_obj_t * chart, lv_chart_series_t * ser, lv_coord_t * y_array)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
memcpy(ser->points, y_array, ext->point_cnt * (sizeof(lv_coord_t)));
ser->start_point = 0;
lv_chart_refresh(chart);
}
/**
* Shift all data left and set the rightmost data on a data line
* @param chart pointer to chart object
* @param ser pointer to a data series on 'chart'
* @param y the new value of the rightmost data
*/
void lv_chart_set_next(lv_obj_t * chart, lv_chart_series_t * ser, lv_coord_t y)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
ser->points[ser->start_point] = y; /*This was the place of the former left most value, after shifting it is the rightmost*/
ser->start_point = (ser->start_point + 1) % ext->point_cnt;
lv_chart_refresh(chart);
}
/*=====================
* Getter functions
*====================*/
/**
* Get the type of a chart
* @param chart pointer to chart object
* @return type of the chart (from 'lv_chart_t' enum)
*/
lv_chart_type_t lv_chart_get_type(const lv_obj_t * chart)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
return ext->type;
}
/**
* Get the data point number per data line on chart
* @param chart pointer to chart object
* @return point number on each data line
*/
uint16_t lv_chart_get_point_cnt(const lv_obj_t * chart)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
return ext->point_cnt;
}
/**
* Get the opacity of the data series
* @param chart pointer to chart object
* @return the opacity of the data series
*/
lv_opa_t lv_chart_get_series_opa(const lv_obj_t * chart)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
return ext->series.opa;
}
/**
* Get the data series width
* @param chart pointer to chart object
* @return the width the data series (lines or points)
*/
lv_coord_t lv_chart_get_series_width(const lv_obj_t * chart)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
return ext->series.width;
}
/**
* Get the dark effect level on the bottom of the points or columns
* @param chart pointer to chart object
* @return dark effect level (LV_OPA_TRANSP to turn off)
*/
lv_opa_t lv_chart_get_series_darking(const lv_obj_t * chart)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
return ext->series.dark;
}
/*=====================
* Other functions
*====================*/
/**
* Refresh a chart if its data line has changed
* @param chart pointer to chart object
*/
void lv_chart_refresh(lv_obj_t * chart)
{
lv_obj_invalidate(chart);
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Handle the drawing related tasks of the chart backgrounds
* @param chart pointer to an object
* @param mask the object will be drawn only in this area
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
* (return 'true' if yes)
* LV_DESIGN_DRAW: draw the object (always return 'true')
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
* @param return true/false, depends on 'mode'
*/
static bool lv_chart_design(lv_obj_t * chart, const lv_area_t * mask, lv_design_mode_t mode)
{
if(mode == LV_DESIGN_COVER_CHK) {
/*Return false if the object is not covers the mask_p area*/
return ancestor_design_f(chart, mask, mode);
} else if(mode == LV_DESIGN_DRAW_MAIN) {
/*Draw the background*/
lv_draw_rect(&chart->coords, mask, lv_obj_get_style(chart), lv_obj_get_opa_scale(chart));
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
lv_chart_draw_div(chart, mask);
if(ext->type & LV_CHART_TYPE_LINE) lv_chart_draw_lines(chart, mask);
if(ext->type & LV_CHART_TYPE_COLUMN) lv_chart_draw_cols(chart, mask);
if(ext->type & LV_CHART_TYPE_POINT) lv_chart_draw_points(chart, mask);
if(ext->type & LV_CHART_TYPE_VERTICAL_LINE) lv_chart_draw_vertical_lines(chart, mask);
}
return true;
}
/**
* Signal function of the chart background
* @param chart pointer to a chart background object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
*/
static lv_res_t lv_chart_signal(lv_obj_t * chart, lv_signal_t sign, void * param)
{
lv_res_t res;
/* Include the ancient signal function */
res = ancestor_signal(chart, sign, param);
if(res != LV_RES_OK) return res;
if(sign == LV_SIGNAL_CLEANUP) {
lv_coord_t ** datal;
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
LL_READ(ext->series_ll, datal) {
lv_mem_free(*datal);
}
lv_ll_clear(&ext->series_ll);
} else if(sign == LV_SIGNAL_GET_TYPE) {
lv_obj_type_t * buf = param;
uint8_t i;
for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/
if(buf->type[i] == NULL) break;
}
buf->type[i] = "lv_chart";
}
return res;
}
/**
* Draw the division lines on chart background
* @param chart pointer to chart object
* @param mask mask, inherited from the design function
*/
static void lv_chart_draw_div(lv_obj_t * chart, const lv_area_t * mask)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
lv_style_t * style = lv_obj_get_style(chart);
lv_opa_t opa_scale = lv_obj_get_opa_scale(chart);
uint8_t div_i;
uint8_t div_i_end;
uint8_t div_i_start;
lv_point_t p1;
lv_point_t p2;
lv_coord_t w = lv_obj_get_width(chart);
lv_coord_t h = lv_obj_get_height(chart);
lv_coord_t x_ofs = chart->coords.x1;
lv_coord_t y_ofs = chart->coords.y1;
if(ext->hdiv_cnt != 0) {
/*Draw slide lines if no border*/
if(style->body.border.width != 0) {
div_i_start = 1;
div_i_end = ext->hdiv_cnt;
} else {
div_i_start = 0;
div_i_end = ext->hdiv_cnt + 1;
}
p1.x = 0 + x_ofs;
p2.x = w + x_ofs;
for(div_i = div_i_start; div_i <= div_i_end; div_i++) {
p1.y = (int32_t)((int32_t)h * div_i) / (ext->hdiv_cnt + 1);
p1.y += y_ofs;
if(div_i == div_i_start) p1.y += (style->line.width >> 1) + 1; /*The first line might not be visible*/
if(div_i == div_i_end) p1.y -= (style->line.width >> 1) + 1; /*The last line might not be visible*/
p2.y = p1.y;
lv_draw_line(&p1, &p2, mask, style, opa_scale);
}
}
if(ext->vdiv_cnt != 0) {
/*Draw slide lines if no border*/
if(style->body.border.width != 0) {
div_i_start = 1;
div_i_end = ext->vdiv_cnt;
} else {
div_i_start = 0;
div_i_end = ext->vdiv_cnt + 1;
}
p1.y = 0 + y_ofs;
p2.y = h + y_ofs;
for(div_i = div_i_start; div_i <= div_i_end; div_i ++) {
p1.x = (int32_t)((int32_t)w * div_i) / (ext->vdiv_cnt + 1);
p1.x += x_ofs;
if(div_i == div_i_start) p1.x += (style->line.width >> 1) + 1; /*The first line might not be visible*/
if(div_i == div_i_end) p1.x -= (style->line.width >> 1) + 1; /*The last line might not be visible*/
p2.x = p1.x;
lv_draw_line(&p1, &p2, mask, style, opa_scale);
}
}
}
/**
* Draw the data lines as lines on a chart
* @param obj pointer to chart object
*/
static void lv_chart_draw_lines(lv_obj_t * chart, const lv_area_t * mask)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
uint16_t i;
lv_point_t p1;
lv_point_t p2;
lv_coord_t w = lv_obj_get_width(chart);
lv_coord_t h = lv_obj_get_height(chart);
lv_coord_t x_ofs = chart->coords.x1;
lv_coord_t y_ofs = chart->coords.y1;
int32_t y_tmp;
lv_coord_t p_prev;
lv_coord_t p_act;
lv_chart_series_t * ser;
lv_opa_t opa_scale = lv_obj_get_opa_scale(chart);
lv_style_t style;
lv_style_copy(&style, &lv_style_plain);
style.line.opa = ext->series.opa;
style.line.width = ext->series.width;
/*Go through all data lines*/
LL_READ_BACK(ext->series_ll, ser) {
style.line.color = ser->color;
p1.x = 0 + x_ofs;
p2.x = 0 + x_ofs;
p_prev = ser->start_point;
y_tmp = (int32_t)((int32_t) ser->points[p_prev] - ext->ymin) * h;
y_tmp = y_tmp / (ext->ymax - ext->ymin);
p2.y = h - y_tmp + y_ofs;
for(i = 1; i < ext->point_cnt; i ++) {
p1.x = p2.x;
p1.y = p2.y;
p2.x = ((w * i) / (ext->point_cnt - 1)) + x_ofs;
p_act = (ser->start_point + i) % ext->point_cnt;
y_tmp = (int32_t)((int32_t) ser->points[p_act] - ext->ymin) * h;
y_tmp = y_tmp / (ext->ymax - ext->ymin);
p2.y = h - y_tmp + y_ofs;
if(ser->points[p_prev] != LV_CHART_POINT_DEF && ser->points[p_act] != LV_CHART_POINT_DEF)
lv_draw_line(&p1, &p2, mask, &style, opa_scale);
p_prev = p_act;
}
}
}
/**
* Draw the data lines as points on a chart
* @param chart pointer to chart object
* @param mask mask, inherited from the design function
*/
static void lv_chart_draw_points(lv_obj_t * chart, const lv_area_t * mask)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
uint16_t i;
lv_area_t cir_a;
lv_coord_t w = lv_obj_get_width(chart);
lv_coord_t h = lv_obj_get_height(chart);
lv_coord_t x_ofs = chart->coords.x1;
lv_coord_t y_ofs = chart->coords.y1;
int32_t y_tmp;
lv_coord_t p_act;
lv_chart_series_t * ser;
uint8_t series_cnt = 0;
lv_style_t style_point;
lv_style_copy(&style_point, &lv_style_plain);
style_point.body.border.width = 0;
style_point.body.empty = 0;
style_point.body.radius = LV_RADIUS_CIRCLE;
style_point.body.opa = ext->series.opa;
style_point.body.radius = ext->series.width;
/*Go through all data lines*/
LL_READ_BACK(ext->series_ll, ser) {
style_point.body.main_color = ser->color;
style_point.body.grad_color = lv_color_mix(LV_COLOR_BLACK, ser->color, ext->series.dark);
for(i = 0; i < ext->point_cnt; i ++) {
cir_a.x1 = ((w * i) / (ext->point_cnt - 1)) + x_ofs;
cir_a.x2 = cir_a.x1 + style_point.body.radius;
cir_a.x1 -= style_point.body.radius;
p_act = (ser->start_point + i) % ext->point_cnt;
y_tmp = (int32_t)((int32_t) ser->points[p_act] - ext->ymin) * h;
y_tmp = y_tmp / (ext->ymax - ext->ymin);
cir_a.y1 = h - y_tmp + y_ofs;
cir_a.y2 = cir_a.y1 + style_point.body.radius;
cir_a.y1 -= style_point.body.radius;
if(ser->points[p_act] != LV_CHART_POINT_DEF)
lv_draw_rect(&cir_a, mask, &style_point, lv_obj_get_opa_scale(chart));
}
series_cnt++;
}
}
/**
* Draw the data lines as columns on a chart
* @param chart pointer to chart object
* @param mask mask, inherited from the design function
*/
static void lv_chart_draw_cols(lv_obj_t * chart, const lv_area_t * mask)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
uint16_t i;
lv_area_t col_a;
lv_area_t col_mask;
bool mask_ret;
lv_coord_t w = lv_obj_get_width(chart);
lv_coord_t h = lv_obj_get_height(chart);
int32_t y_tmp;
lv_chart_series_t * ser;
lv_style_t rects;
lv_coord_t col_w = w / ((ext->series.num + 1) * ext->point_cnt); /* Suppose + 1 series as separator*/
lv_coord_t x_ofs = col_w / 2; /*Shift with a half col.*/
lv_style_copy(&rects, &lv_style_plain);
rects.body.border.width = 0;
rects.body.empty = 0;
rects.body.radius = 0;
rects.body.opa = ext->series.opa;
col_a.y2 = chart->coords.y2;
lv_coord_t x_act;
/*Go through all points*/
for(i = 0; i < ext->point_cnt; i ++) {
x_act = (int32_t)((int32_t) w * i) / ext->point_cnt;
x_act += chart->coords.x1 + x_ofs;
/*Draw the current point of all data line*/
LL_READ_BACK(ext->series_ll, ser) {
rects.body.main_color = ser->color;
rects.body.grad_color = lv_color_mix(LV_COLOR_BLACK, ser->color, ext->series.dark);
col_a.x1 = x_act;
col_a.x2 = col_a.x1 + col_w;
x_act += col_w;
lv_coord_t p_act = (ser->start_point + i) % ext->point_cnt;
y_tmp = (int32_t)((int32_t) ser->points[p_act] - ext->ymin) * h;
y_tmp = y_tmp / (ext->ymax - ext->ymin);
col_a.y1 = h - y_tmp + chart->coords.y1;
mask_ret = lv_area_intersect(&col_mask, mask, &col_a);
if(mask_ret != false && ser->points[p_act] != LV_CHART_POINT_DEF) {
lv_draw_rect(&chart->coords, &col_mask, &rects, lv_obj_get_opa_scale(chart));
}
}
}
}
/**
* Draw the data lines as vertical lines on a chart if there is only 1px between point
* @param obj pointer to chart object
*/
static void lv_chart_draw_vertical_lines(lv_obj_t * chart, const lv_area_t * mask)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
lv_coord_t w = lv_obj_get_width(chart);
/*Vertical lines works only if the width == point count. Else use the normal line type*/
if(ext->point_cnt != w) {
lv_chart_draw_lines(chart, mask);
return;
}
uint16_t i;
lv_point_t p1;
lv_point_t p2;
lv_coord_t h = lv_obj_get_height(chart);
lv_coord_t x_ofs = chart->coords.x1;
lv_coord_t y_ofs = chart->coords.y1;
int32_t y_tmp;
lv_chart_series_t * ser;
lv_opa_t opa_scale = lv_obj_get_opa_scale(chart);
lv_style_t style;
lv_style_copy(&style, &lv_style_plain);
style.line.opa = ext->series.opa;
style.line.width = ext->series.width;
/*Go through all data lines*/
LL_READ_BACK(ext->series_ll, ser) {
style.line.color = ser->color;
p1.x = 0 + x_ofs;
p2.x = 0 + x_ofs;
y_tmp = (int32_t)((int32_t) ser->points[0] - ext->ymin) * h;
y_tmp = y_tmp / (ext->ymax - ext->ymin);
p2.y = h - y_tmp + y_ofs;
p1.y = p2.y;
for(i = 0; i < ext->point_cnt; i++)
{
y_tmp = (int32_t)((int32_t) ser->points[i] - ext->ymin) * h;
y_tmp = y_tmp / (ext->ymax - ext->ymin);
p2.y = h - y_tmp + y_ofs;
if(p1.y == p2.y)
{
p2.x++;
}
if(ser->points[i] != LV_CHART_POINT_DEF) {
lv_draw_line(&p1, &p2, mask, &style, opa_scale);
}
p2.x = ((w * i) / (ext->point_cnt - 1)) + x_ofs;
p1.x = p2.x;
p1.y = p2.y;
}
}
}
#endif

View File

@ -1,163 +0,0 @@
/**
* @file lv_cont.h
*
*/
#ifndef LV_CONT_H
#define LV_CONT_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_conf.h"
#else
#include "../../lv_conf.h"
#endif
#if USE_LV_CONT != 0
#include "../lv_core/lv_obj.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/*Layout options*/
enum
{
LV_LAYOUT_OFF = 0,
LV_LAYOUT_CENTER,
LV_LAYOUT_COL_L, /*Column left align*/
LV_LAYOUT_COL_M, /*Column middle align*/
LV_LAYOUT_COL_R, /*Column right align*/
LV_LAYOUT_ROW_T, /*Row top align*/
LV_LAYOUT_ROW_M, /*Row middle align*/
LV_LAYOUT_ROW_B, /*Row bottom align*/
LV_LAYOUT_PRETTY, /*Put as many object as possible in row and begin a new row*/
LV_LAYOUT_GRID, /*Align same-sized object into a grid*/
};
typedef uint8_t lv_layout_t;
typedef struct
{
/*Inherited from 'base_obj' so no inherited ext. */ /*Ext. of ancestor*/
/*New data for this type */
uint8_t layout :4; /*A layout from 'lv_cont_layout_t' enum*/
uint8_t hor_fit :1; /*1: Enable horizontal fit to involve all children*/
uint8_t ver_fit :1; /*1: Enable horizontal fit to involve all children*/
} lv_cont_ext_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Create a container objects
* @param par pointer to an object, it will be the parent of the new container
* @param copy pointer to a container object, if not NULL then the new object will be copied from it
* @return pointer to the created container
*/
lv_obj_t * lv_cont_create(lv_obj_t * par, const lv_obj_t * copy);
/*=====================
* Setter functions
*====================*/
/**
* Set a layout on a container
* @param cont pointer to a container object
* @param layout a layout from 'lv_cont_layout_t'
*/
void lv_cont_set_layout(lv_obj_t * cont, lv_layout_t layout);
/**
* Enable the horizontal or vertical fit.
* The container size will be set to involve the children horizontally or vertically.
* @param cont pointer to a container object
* @param hor_en true: enable the horizontal fit
* @param ver_en true: enable the vertical fit
*/
void lv_cont_set_fit(lv_obj_t * cont, bool hor_en, bool ver_en);
/**
* Set the style of a container
* @param cont pointer to a container object
* @param style pointer to the new style
*/
static inline void lv_cont_set_style(lv_obj_t *cont, lv_style_t * style)
{
lv_obj_set_style(cont, style);
}
/*=====================
* Getter functions
*====================*/
/**
* Get the layout of a container
* @param cont pointer to container object
* @return the layout from 'lv_cont_layout_t'
*/
lv_layout_t lv_cont_get_layout(const lv_obj_t * cont);
/**
* Get horizontal fit enable attribute of a container
* @param cont pointer to a container object
* @return true: horizontal fit is enabled; false: disabled
*/
bool lv_cont_get_hor_fit(const lv_obj_t * cont);
/**
* Get vertical fit enable attribute of a container
* @param cont pointer to a container object
* @return true: vertical fit is enabled; false: disabled
*/
bool lv_cont_get_ver_fit(const lv_obj_t * cont);
/**
* Get that width reduced by the horizontal padding. Useful if a layout is used.
* @param cont pointer to a container object
* @return the width which still fits into the container
*/
lv_coord_t lv_cont_get_fit_width(lv_obj_t * cont);
/**
* Get that height reduced by the vertical padding. Useful if a layout is used.
* @param cont pointer to a container object
* @return the height which still fits into the container
*/
lv_coord_t lv_cont_get_fit_height(lv_obj_t * cont);
/**
* Get the style of a container
* @param cont pointer to a container object
* @return pointer to the container's style
*/
static inline lv_style_t * lv_cont_get_style(const lv_obj_t *cont)
{
return lv_obj_get_style(cont);
}
/**********************
* MACROS
**********************/
#endif /*USE_LV_CONT*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_CONT_H*/

View File

@ -1,465 +0,0 @@
/**
* @file lv_kb.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_kb.h"
#if USE_LV_KB != 0
#include "lv_ta.h"
#include "../lv_themes/lv_theme.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static lv_res_t lv_kb_signal(lv_obj_t * kb, lv_signal_t sign, void * param);
static lv_res_t lv_kb_def_action(lv_obj_t * kb, const char * txt);
/**********************
* STATIC VARIABLES
**********************/
static lv_signal_func_t ancestor_signal;
static const char * kb_map_lc[] = {
"\2051#", "\204q", "\204w", "\204e", "\204r", "\204t", "\204y", "\204u", "\204i", "\204o", "\204p", "\207Bksp", "\n",
"\226ABC", "\203a", "\203s", "\203d", "\203f", "\203g", "\203h", "\203j", "\203k", "\203l", "\207Enter", "\n",
"_", "-", "z", "x", "c", "v", "b", "n", "m", ".", ",", ":", "\n",
"\202"SYMBOL_CLOSE, "\202"SYMBOL_LEFT, "\206 ", "\202"SYMBOL_RIGHT, "\202"SYMBOL_OK, ""
};
static const char * kb_map_uc[] = {
"\2051#", "\204Q", "\204W", "\204E", "\204R", "\204T", "\204Y", "\204U", "\204I", "\204O", "\204P", "\207Bksp", "\n",
"\226abc", "\203A", "\203S", "\203D", "\203F", "\203G", "\203H", "\203J", "\203K", "\203L", "\207Enter", "\n",
"_", "-", "Z", "X", "C", "V", "B", "N", "M", ".", ",", ":", "\n",
"\202"SYMBOL_CLOSE, "\202"SYMBOL_LEFT, "\206 ", "\202"SYMBOL_RIGHT, "\202"SYMBOL_OK, ""
};
static const char * kb_map_spec[] = {
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "\202Bksp", "\n",
"\222abc", "+", "-", "/", "*", "=", "%", "!", "?", "#", "<", ">", "\n",
"\\", "@", "$", "(", ")", "{", "}", "[", "]", ";", "\"", "'", "\n",
"\202"SYMBOL_CLOSE, "\202"SYMBOL_LEFT, "\206 ", "\202"SYMBOL_RIGHT, "\202"SYMBOL_OK, ""
};
static const char * kb_map_num[] = {
"1", "2", "3", "\202"SYMBOL_CLOSE, "\n",
"4", "5", "6", "\202"SYMBOL_OK, "\n",
"7", "8", "9", "\202Bksp", "\n",
"+/-", "0", ".", SYMBOL_LEFT, SYMBOL_RIGHT, ""
};
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Create a keyboard objects
* @param par pointer to an object, it will be the parent of the new keyboard
* @param copy pointer to a keyboard object, if not NULL then the new object will be copied from it
* @return pointer to the created keyboard
*/
lv_obj_t * lv_kb_create(lv_obj_t * par, const lv_obj_t * copy)
{
LV_LOG_TRACE("keyboard create started");
/*Create the ancestor of keyboard*/
lv_obj_t * new_kb = lv_btnm_create(par, copy);
lv_mem_assert(new_kb);
if(new_kb == NULL) return NULL;
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_kb);
/*Allocate the keyboard type specific extended data*/
lv_kb_ext_t * ext = lv_obj_allocate_ext_attr(new_kb, sizeof(lv_kb_ext_t));
lv_mem_assert(ext);
if(ext == NULL) return NULL;
/*Initialize the allocated 'ext' */
ext->ta = NULL;
ext->mode = LV_KB_MODE_TEXT;
ext->cursor_mng = 0;
ext->hide_action = NULL;
ext->ok_action = NULL;
/*The signal and design functions are not copied so set them here*/
lv_obj_set_signal_func(new_kb, lv_kb_signal);
/*Init the new keyboard keyboard*/
if(copy == NULL) {
lv_obj_set_size(new_kb, LV_HOR_RES, LV_VER_RES / 2);
lv_obj_align(new_kb, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
lv_btnm_set_action(new_kb, lv_kb_def_action);
lv_btnm_set_map(new_kb, kb_map_lc);
/*Set the default styles*/
lv_theme_t * th = lv_theme_get_current();
if(th) {
lv_kb_set_style(new_kb, LV_KB_STYLE_BG, th->kb.bg);
lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_REL, th->kb.btn.rel);
lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_PR, th->kb.btn.pr);
lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_TGL_REL, th->kb.btn.tgl_rel);
lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_TGL_PR, th->kb.btn.tgl_pr);
lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_INA, th->kb.btn.ina);
} else {
/*Let the button matrix's styles*/
}
}
/*Copy an existing keyboard*/
else {
lv_kb_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
ext->ta = NULL;
ext->ta = copy_ext->ta;
ext->mode = copy_ext->mode;
ext->cursor_mng = copy_ext->cursor_mng;
ext->hide_action = copy_ext->hide_action;
ext->ok_action = copy_ext->ok_action;
/*Refresh the style with new signal function*/
lv_obj_refresh_style(new_kb);
}
LV_LOG_INFO("keyboard created");
return new_kb;
}
/*=====================
* Setter functions
*====================*/
/**
* Assign a Text Area to the Keyboard. The pressed characters will be put there.
* @param kb pointer to a Keyboard object
* @param ta pointer to a Text Area object to write there
*/
void lv_kb_set_ta(lv_obj_t * kb, lv_obj_t * ta)
{
lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb);
lv_cursor_type_t cur_type;
/*Hide the cursor of the old Text area if cursor management is enabled*/
if(ext->ta && ext->cursor_mng) {
cur_type = lv_ta_get_cursor_type(ext->ta);
lv_ta_set_cursor_type(ext->ta, cur_type | LV_CURSOR_HIDDEN);
}
ext->ta = ta;
/*Show the cursor of the new Text area if cursor management is enabled*/
if(ext->ta && ext->cursor_mng) {
cur_type = lv_ta_get_cursor_type(ext->ta);
lv_ta_set_cursor_type(ext->ta, cur_type & (~LV_CURSOR_HIDDEN));
}
}
/**
* Set a new a mode (text or number map)
* @param kb pointer to a Keyboard object
* @param mode the mode from 'lv_kb_mode_t'
*/
void lv_kb_set_mode(lv_obj_t * kb, lv_kb_mode_t mode)
{
lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb);
if(ext->mode == mode) return;
ext->mode = mode;
if(mode == LV_KB_MODE_TEXT) lv_btnm_set_map(kb, kb_map_lc);
else if(mode == LV_KB_MODE_NUM) lv_btnm_set_map(kb, kb_map_num);
}
/**
* Automatically hide or show the cursor of Text Area
* @param kb pointer to a Keyboard object
* @param en true: show cursor on the current text area, false: hide cursor
*/
void lv_kb_set_cursor_manage(lv_obj_t * kb, bool en)
{
lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb);
if(ext->cursor_mng == en) return;
ext->cursor_mng = en == false ? 0 : 1;
if(ext->ta) {
lv_cursor_type_t cur_type;
cur_type = lv_ta_get_cursor_type(ext->ta);
if(ext->cursor_mng) {
lv_ta_set_cursor_type(ext->ta, cur_type & (~LV_CURSOR_HIDDEN));
} else {
lv_ta_set_cursor_type(ext->ta, cur_type | LV_CURSOR_HIDDEN);
}
}
}
/**
* Set call back to call when the "Ok" button is pressed
* @param kb pointer to Keyboard object
* @param action a callback with 'lv_action_t' type
*/
void lv_kb_set_ok_action(lv_obj_t * kb, lv_action_t action)
{
lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb);
ext->ok_action = action;
}
/**
* Set call back to call when the "Hide" button is pressed
* @param kb pointer to Keyboard object
* @param action a callback with 'lv_action_t' type
*/
void lv_kb_set_hide_action(lv_obj_t * kb, lv_action_t action)
{
lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb);
ext->hide_action = action;
}
/**
* Set a style of a keyboard
* @param kb pointer to a keyboard object
* @param type which style should be set
* @param style pointer to a style
*/
void lv_kb_set_style(lv_obj_t * kb, lv_kb_style_t type, lv_style_t * style)
{
switch(type) {
case LV_KB_STYLE_BG:
lv_btnm_set_style(kb, LV_BTNM_STYLE_BG, style);
break;
case LV_KB_STYLE_BTN_REL:
lv_btnm_set_style(kb, LV_BTNM_STYLE_BTN_REL, style);
break;
case LV_KB_STYLE_BTN_PR:
lv_btnm_set_style(kb, LV_BTNM_STYLE_BTN_PR, style);
break;
case LV_KB_STYLE_BTN_TGL_REL:
lv_btnm_set_style(kb, LV_BTNM_STYLE_BTN_TGL_REL, style);
break;
case LV_KB_STYLE_BTN_TGL_PR:
lv_btnm_set_style(kb, LV_BTNM_STYLE_BTN_TGL_PR, style);
break;
case LV_KB_STYLE_BTN_INA:
lv_btnm_set_style(kb, LV_BTNM_STYLE_BTN_INA, style);
break;
}
}
/*=====================
* Getter functions
*====================*/
/**
* Assign a Text Area to the Keyboard. The pressed characters will be put there.
* @param kb pointer to a Keyboard object
* @return pointer to the assigned Text Area object
*/
lv_obj_t * lv_kb_get_ta(const lv_obj_t * kb)
{
lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb);
return ext->ta;
}
/**
* Set a new a mode (text or number map)
* @param kb pointer to a Keyboard object
* @return the current mode from 'lv_kb_mode_t'
*/
lv_kb_mode_t lv_kb_get_mode(const lv_obj_t * kb)
{
lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb);
return ext->mode;
}
/**
* Get the current cursor manage mode.
* @param kb pointer to a Keyboard object
* @return true: show cursor on the current text area, false: hide cursor
*/
bool lv_kb_get_cursor_manage(const lv_obj_t * kb)
{
lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb);
return ext->cursor_mng == 0 ? false : true;
}
/**
* Get the callback to call when the "Ok" button is pressed
* @param kb pointer to Keyboard object
* @return the ok callback
*/
lv_action_t lv_kb_get_ok_action(const lv_obj_t * kb)
{
lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb);
return ext->ok_action;
}
/**
* Get the callback to call when the "Hide" button is pressed
* @param kb pointer to Keyboard object
* @return the close callback
*/
lv_action_t lv_kb_get_hide_action(const lv_obj_t * kb)
{
lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb);
return ext->hide_action;
}
/**
* Get a style of a keyboard
* @param kb pointer to a keyboard object
* @param type which style should be get
* @return style pointer to a style
*/
lv_style_t * lv_kb_get_style(const lv_obj_t * kb, lv_kb_style_t type)
{
lv_style_t * style = NULL;
switch(type) {
case LV_KB_STYLE_BG:
style = lv_btnm_get_style(kb, LV_BTNM_STYLE_BG);
break;
case LV_KB_STYLE_BTN_REL:
style = lv_btnm_get_style(kb, LV_BTNM_STYLE_BTN_REL);
break;
case LV_KB_STYLE_BTN_PR:
style = lv_btnm_get_style(kb, LV_BTNM_STYLE_BTN_PR);
break;
case LV_KB_STYLE_BTN_TGL_REL:
style = lv_btnm_get_style(kb, LV_BTNM_STYLE_BTN_TGL_REL);
break;
case LV_KB_STYLE_BTN_TGL_PR:
style = lv_btnm_get_style(kb, LV_BTNM_STYLE_BTN_TGL_PR);
break;
case LV_KB_STYLE_BTN_INA:
style = lv_btnm_get_style(kb, LV_BTNM_STYLE_BTN_INA);
break;
default:
style = NULL;
break;
}
return style;
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Signal function of the keyboard
* @param kb pointer to a keyboard object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
*/
static lv_res_t lv_kb_signal(lv_obj_t * kb, lv_signal_t sign, void * param)
{
lv_res_t res;
/* Include the ancient signal function */
res = ancestor_signal(kb, sign, param);
if(res != LV_RES_OK) return res;
if(sign == LV_SIGNAL_CLEANUP) {
/*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
} else if(sign == LV_SIGNAL_GET_TYPE) {
lv_obj_type_t * buf = param;
uint8_t i;
for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/
if(buf->type[i] == NULL) break;
}
buf->type[i] = "lv_kb";
}
return res;
}
/**
* Called when a button of 'kb_btnm' is released
* @param btnm pointer to 'kb_btnm'
* @param i the index of the released button from the current btnm map
* @return LV_ACTION_RES_INV if the btnm is deleted else LV_ACTION_RES_OK
*/
static lv_res_t lv_kb_def_action(lv_obj_t * kb, const char * txt)
{
lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb);
lv_res_t res = LV_RES_OK;
/*Do the corresponding action according to the text of the button*/
if(strcmp(txt, "abc") == 0) {
lv_btnm_set_map(kb, kb_map_lc);
return LV_RES_OK;
} else if(strcmp(txt, "ABC") == 0) {
lv_btnm_set_map(kb, kb_map_uc);
return LV_RES_OK;
} else if(strcmp(txt, "1#") == 0) {
lv_btnm_set_map(kb, kb_map_spec);
return LV_RES_OK;
} else if(strcmp(txt, SYMBOL_CLOSE) == 0) {
if(ext->hide_action) res = ext->hide_action(kb);
else {
lv_kb_set_ta(kb, NULL); /*De-assign the text area to hide it cursor if needed*/
lv_obj_del(kb);
}
return res;
} else if(strcmp(txt, SYMBOL_OK) == 0) {
if(ext->ok_action) res = ext->ok_action(kb);
else {
lv_kb_set_ta(kb, NULL); /*De-assign the text area to hide it cursor if needed*/
res = lv_obj_del(kb);
}
return res;
}
if(res != LV_RES_OK) return res; /*The keyboard might be deleted in the actions*/
/*Add the characters to the text area if set*/
if(ext->ta == NULL) return res;
if(strcmp(txt, "Enter") == 0)lv_ta_add_char(ext->ta, '\n');
else if(strcmp(txt, SYMBOL_LEFT) == 0) lv_ta_cursor_left(ext->ta);
else if(strcmp(txt, SYMBOL_RIGHT) == 0) lv_ta_cursor_right(ext->ta);
else if(strcmp(txt, "Bksp") == 0) lv_ta_del_char(ext->ta);
else if(strcmp(txt, "+/-") == 0) {
uint16_t cur = lv_ta_get_cursor_pos(ext->ta);
const char * ta_txt = lv_ta_get_text(ext->ta);
if(ta_txt[0] == '-') {
lv_ta_set_cursor_pos(ext->ta, 1);
lv_ta_del_char(ext->ta);
lv_ta_add_char(ext->ta, '+');
lv_ta_set_cursor_pos(ext->ta, cur);
} else if(ta_txt[0] == '+') {
lv_ta_set_cursor_pos(ext->ta, 1);
lv_ta_del_char(ext->ta);
lv_ta_add_char(ext->ta, '-');
lv_ta_set_cursor_pos(ext->ta, cur);
} else {
lv_ta_set_cursor_pos(ext->ta, 0);
lv_ta_add_char(ext->ta, '-');
lv_ta_set_cursor_pos(ext->ta, cur + 1);
}
} else {
lv_ta_add_text(ext->ta, txt);
}
return LV_RES_OK;
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,582 +0,0 @@
/**
* @file lv_roller.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_roller.h"
#if USE_LV_ROLLER != 0
#include "../lv_draw/lv_draw.h"
#include "../lv_core/lv_group.h"
#include "../lv_themes/lv_theme.h"
/*********************
* DEFINES
*********************/
#if USE_LV_ANIMATION
# ifndef LV_ROLLER_ANIM_TIME
# define LV_ROLLER_ANIM_TIME 200 /*ms*/
# endif
#else
# undef LV_ROLLER_ANIM_TIME
# define LV_ROLLER_ANIM_TIME 0 /*No animation*/
#endif
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static bool lv_roller_design(lv_obj_t * roller, const lv_area_t * mask, lv_design_mode_t mode);
static lv_res_t lv_roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, void * param);
static lv_res_t lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * param);
static void refr_position(lv_obj_t * roller, bool anim_en);
static void draw_bg(lv_obj_t * roller, const lv_area_t * mask);
/**********************
* STATIC VARIABLES
**********************/
static lv_signal_func_t ancestor_signal;
static lv_signal_func_t ancestor_scrl_signal;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Create a roller object
* @param par pointer to an object, it will be the parent of the new roller
* @param copy pointer to a roller object, if not NULL then the new object will be copied from it
* @return pointer to the created roller
*/
lv_obj_t * lv_roller_create(lv_obj_t * par, const lv_obj_t * copy)
{
LV_LOG_TRACE("roller create started");
/*Create the ancestor of roller*/
lv_obj_t * new_roller = lv_ddlist_create(par, copy);
lv_mem_assert(new_roller);
if(new_roller == NULL) return NULL;
if(ancestor_scrl_signal == NULL) ancestor_scrl_signal = lv_obj_get_signal_func(lv_page_get_scrl(new_roller));
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_roller);
/*Allocate the roller type specific extended data*/
lv_roller_ext_t * ext = lv_obj_allocate_ext_attr(new_roller, sizeof(lv_roller_ext_t));
lv_mem_assert(ext);
if(ext == NULL) return NULL;
ext->ddlist.draw_arrow = 0; /*Do not draw arrow by default*/
/*The signal and design functions are not copied so set them here*/
lv_obj_set_signal_func(new_roller, lv_roller_signal);
lv_obj_set_design_func(new_roller, lv_roller_design);
/*Init the new roller roller*/
if(copy == NULL) {
lv_obj_t * scrl = lv_page_get_scrl(new_roller);
lv_obj_set_drag(scrl, true); /*In ddlist is might be disabled*/
lv_page_set_rel_action(new_roller, NULL); /*Roller don't uses it (like ddlist)*/
lv_page_set_scrl_fit(new_roller, true, false); /*Height is specified directly*/
lv_ddlist_open(new_roller, false);
lv_ddlist_set_anim_time(new_roller, LV_ROLLER_ANIM_TIME);
lv_roller_set_visible_row_count(new_roller, 3);
lv_label_set_align(ext->ddlist.label, LV_LABEL_ALIGN_CENTER);
lv_obj_set_signal_func(scrl, lv_roller_scrl_signal);
/*Set the default styles*/
lv_theme_t * th = lv_theme_get_current();
if(th) {
lv_roller_set_style(new_roller, LV_ROLLER_STYLE_BG, th->roller.bg);
lv_roller_set_style(new_roller, LV_ROLLER_STYLE_SEL, th->roller.sel);
} else {
/*Let the ddlist's style*/
lv_obj_refresh_style(new_roller); /*To set scrollable size automatically*/
}
}
/*Copy an existing roller*/
else {
lv_obj_t * scrl = lv_page_get_scrl(new_roller);
lv_ddlist_open(new_roller, false);
lv_obj_set_signal_func(scrl, lv_roller_scrl_signal);
lv_obj_refresh_style(new_roller); /*Refresh the style with new signal function*/
}
LV_LOG_INFO("roller created");
return new_roller;
}
/*=====================
* Setter functions
*====================*/
/**
* Set the align of the roller's options (left or center)
* @param roller - pointer to a roller object
* @param align - one of lv_label_align_t values (left, right, center)
*/
void lv_roller_set_align(lv_obj_t * roller, lv_label_align_t align)
{
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
lv_mem_assert(ext);
if(ext->ddlist.label == NULL) return; /*Probably the roller is being deleted if the label is NULL.*/
lv_label_set_align(ext->ddlist.label, align);
}
/**
* Set the selected option
* @param roller pointer to a roller object
* @param sel_opt id of the selected option (0 ... number of option - 1);
* @param anim_en true: set with animation; false set immediately
*/
void lv_roller_set_selected(lv_obj_t * roller, uint16_t sel_opt, bool anim_en)
{
#if USE_LV_ANIMATION == 0
anim_en = false;
#endif
if(lv_roller_get_selected(roller) == sel_opt) return;
lv_ddlist_set_selected(roller, sel_opt);
refr_position(roller, anim_en);
}
/**
* Set the height to show the given number of rows (options)
* @param roller pointer to a roller object
* @param row_cnt number of desired visible rows
*/
void lv_roller_set_visible_row_count(lv_obj_t * roller, uint8_t row_cnt)
{
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
lv_style_t * style_label = lv_obj_get_style(ext->ddlist.label);
uint8_t n_line_space = (row_cnt > 1) ? row_cnt - 1 : 1;
lv_ddlist_set_fix_height(roller, lv_font_get_height(style_label->text.font) * row_cnt + style_label->text.line_space * n_line_space);
}
/**
* Set a style of a roller
* @param roller pointer to a roller object
* @param type which style should be set
* @param style pointer to a style
*/
void lv_roller_set_style(lv_obj_t * roller, lv_roller_style_t type, lv_style_t * style)
{
switch(type) {
case LV_ROLLER_STYLE_BG:
lv_obj_set_style(roller, style);
break;
case LV_ROLLER_STYLE_SEL:
lv_ddlist_set_style(roller, LV_DDLIST_STYLE_SEL, style);
break;
}
}
/*=====================
* Getter functions
*====================*/
/**
* Get the align attribute. Default alignment after _create is LV_LABEL_ALIGN_CENTER
* @param roller pointer to a roller object
* @return LV_LABEL_ALIGN_LEFT, LV_LABEL_ALIGN_RIGHT or LV_LABEL_ALIGN_CENTER
*/
lv_label_align_t lv_roller_get_align(const lv_obj_t * roller)
{
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
lv_mem_assert(ext);
lv_mem_assert(ext->ddlist.label);
return lv_label_get_align(ext->ddlist.label);
}
/**
* Get the auto width set attribute
* @param roller pointer to a roller object
* @return true: auto size enabled; false: manual width settings enabled
*/
bool lv_roller_get_hor_fit(const lv_obj_t * roller)
{
return lv_page_get_scrl_hor_fit(roller);
}
/**
* Get a style of a roller
* @param roller pointer to a roller object
* @param type which style should be get
* @return style pointer to a style
* */
lv_style_t * lv_roller_get_style(const lv_obj_t * roller, lv_roller_style_t type)
{
switch(type) {
case LV_ROLLER_STYLE_BG:
return lv_obj_get_style(roller);
case LV_ROLLER_STYLE_SEL:
return lv_ddlist_get_style(roller, LV_DDLIST_STYLE_SEL);
default:
return NULL;
}
/*To avoid warning*/
return NULL;
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Handle the drawing related tasks of the rollers
* @param roller pointer to an object
* @param mask the object will be drawn only in this area
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
* (return 'true' if yes)
* LV_DESIGN_DRAW: draw the object (always return 'true')
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
* @param return true/false, depends on 'mode'
*/
static bool lv_roller_design(lv_obj_t * roller, const lv_area_t * mask, lv_design_mode_t mode)
{
/*Return false if the object is not covers the mask_p area*/
if(mode == LV_DESIGN_COVER_CHK) {
return false;
}
/*Draw the object*/
else if(mode == LV_DESIGN_DRAW_MAIN) {
draw_bg(roller, mask);
lv_style_t * style = lv_roller_get_style(roller, LV_ROLLER_STYLE_BG);
lv_opa_t opa_scale = lv_obj_get_opa_scale(roller);
const lv_font_t * font = style->text.font;
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
lv_coord_t font_h = lv_font_get_height(font);
lv_area_t rect_area;
rect_area.y1 = roller->coords.y1 + lv_obj_get_height(roller) / 2 - font_h / 2 - style->text.line_space / 2;
if((font_h & 0x1) && (style->text.line_space & 0x1)) rect_area.y1 --; /*Compensate the two rounding error*/
rect_area.y2 = rect_area.y1 + font_h + style->text.line_space - 1;
rect_area.x1 = roller->coords.x1;
rect_area.x2 = roller->coords.x2;
lv_draw_rect(&rect_area, mask, ext->ddlist.sel_style, opa_scale);
}
/*Post draw when the children are drawn*/
else if(mode == LV_DESIGN_DRAW_POST) {
lv_style_t * style = lv_roller_get_style(roller, LV_ROLLER_STYLE_BG);
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
const lv_font_t * font = style->text.font;
lv_coord_t font_h = lv_font_get_height(font);
lv_opa_t opa_scale = lv_obj_get_opa_scale(roller);
/*Redraw the text on the selected area with a different color*/
lv_area_t rect_area;
rect_area.y1 = roller->coords.y1 + lv_obj_get_height(roller) / 2 - font_h / 2 - style->text.line_space / 2;
if((font_h & 0x1) && (style->text.line_space & 0x1)) rect_area.y1 --; /*Compensate the two rounding error*/
rect_area.y2 = rect_area.y1 + font_h + style->text.line_space - 1;
rect_area.x1 = roller->coords.x1;
rect_area.x2 = roller->coords.x2;
lv_area_t mask_sel;
bool area_ok;
area_ok = lv_area_intersect(&mask_sel, mask, &rect_area);
if(area_ok) {
lv_style_t * sel_style = lv_roller_get_style(roller, LV_ROLLER_STYLE_SEL);
lv_style_t new_style;
lv_txt_flag_t txt_align = LV_TXT_FLAG_NONE;
{
lv_label_align_t label_align = lv_label_get_align(ext->ddlist.label);
if(LV_LABEL_ALIGN_CENTER == label_align) {
txt_align |= LV_TXT_FLAG_CENTER;
} else if(LV_LABEL_ALIGN_RIGHT == label_align) {
txt_align |= LV_TXT_FLAG_RIGHT;
}
}
lv_style_copy(&new_style, style);
new_style.text.color = sel_style->text.color;
new_style.text.opa = sel_style->text.opa;
lv_draw_label(&ext->ddlist.label->coords, &mask_sel, &new_style, opa_scale,
lv_label_get_text(ext->ddlist.label), txt_align, NULL);
}
}
return true;
}
/**
* Signal function of the roller
* @param roller pointer to a roller object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
*/
static lv_res_t lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * param)
{
lv_res_t res = LV_RES_OK;
/*Don't let the drop down list to handle the control signals. It works differently*/
if(sign != LV_SIGNAL_CONTROLL && sign != LV_SIGNAL_FOCUS && sign != LV_SIGNAL_DEFOCUS) {
/* Include the ancient signal function */
res = ancestor_signal(roller, sign, param);
if(res != LV_RES_OK) return res;
}
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
lv_align_t obj_align = LV_ALIGN_IN_LEFT_MID;
if(ext->ddlist.label) {
lv_label_align_t label_align = lv_label_get_align(ext->ddlist.label);
if(LV_LABEL_ALIGN_CENTER == label_align) obj_align = LV_ALIGN_CENTER;
else if(LV_LABEL_ALIGN_RIGHT == label_align) obj_align = LV_ALIGN_IN_RIGHT_MID;
}
if(sign == LV_SIGNAL_STYLE_CHG) {
lv_obj_set_height(lv_page_get_scrl(roller),
lv_obj_get_height(ext->ddlist.label) + lv_obj_get_height(roller));
lv_obj_align(ext->ddlist.label, NULL, obj_align, 0, 0);
lv_ddlist_set_selected(roller, ext->ddlist.sel_opt_id);
refr_position(roller, false);
} else if(sign == LV_SIGNAL_CORD_CHG) {
if(lv_obj_get_width(roller) != lv_area_get_width(param) ||
lv_obj_get_height(roller) != lv_area_get_height(param)) {
lv_ddlist_set_fix_height(roller, lv_obj_get_height(roller));
lv_obj_set_height(lv_page_get_scrl(roller),
lv_obj_get_height(ext->ddlist.label) + lv_obj_get_height(roller));
lv_obj_align(ext->ddlist.label, NULL, obj_align, 0, 0);
lv_ddlist_set_selected(roller, ext->ddlist.sel_opt_id);
refr_position(roller, false);
}
} else if(sign == LV_SIGNAL_FOCUS) {
#if USE_LV_GROUP
lv_group_t * g = lv_obj_get_group(roller);
bool editing = lv_group_get_editing(g);
lv_hal_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act());
/*Encoders need special handling*/
if(indev_type == LV_INDEV_TYPE_ENCODER) {
/*In navigate mode revert the original value*/
if(!editing) {
if(ext->ddlist.sel_opt_id != ext->ddlist.sel_opt_id_ori) {
ext->ddlist.sel_opt_id = ext->ddlist.sel_opt_id_ori;
refr_position(roller, true);
}
}
/*Save the current state when entered to edit mode*/
else {
ext->ddlist.sel_opt_id_ori = ext->ddlist.sel_opt_id;
}
} else {
ext->ddlist.sel_opt_id_ori = ext->ddlist.sel_opt_id; /*Save the current value. Used to revert this state if ENER wont't be pressed*/
}
#endif
} else if(sign == LV_SIGNAL_DEFOCUS) {
#if USE_LV_GROUP
/*Revert the original state*/
if(ext->ddlist.sel_opt_id != ext->ddlist.sel_opt_id_ori) {
ext->ddlist.sel_opt_id = ext->ddlist.sel_opt_id_ori;
refr_position(roller, true);
}
#endif
} else if(sign == LV_SIGNAL_CONTROLL) {
char c = *((char *)param);
if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_DOWN) {
if(ext->ddlist.sel_opt_id + 1 < ext->ddlist.option_cnt) {
lv_roller_set_selected(roller, ext->ddlist.sel_opt_id + 1, true);
}
} else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_UP) {
if(ext->ddlist.sel_opt_id > 0) {
lv_roller_set_selected(roller, ext->ddlist.sel_opt_id - 1, true);
}
} else if(c == LV_GROUP_KEY_ENTER) {
ext->ddlist.sel_opt_id_ori = ext->ddlist.sel_opt_id; /*Set the entered value as default*/
if(ext->ddlist.action) ext->ddlist.action(roller);
#if USE_LV_GROUP
lv_group_t * g = lv_obj_get_group(roller);
bool editing = lv_group_get_editing(g);
if(editing) lv_group_set_editing(g, false); /*In edit mode go to navigate mode if an option is selected*/
#endif
}
} else if(sign == LV_SIGNAL_GET_TYPE) {
lv_obj_type_t * buf = param;
uint8_t i;
for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/
if(buf->type[i] == NULL) break;
}
buf->type[i] = "lv_roller";
}
return res;
}
/**
* Signal function of the scrollable part of the roller.
* @param roller_scrl ointer to the scrollable part of roller (page)
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
*/
static lv_res_t lv_roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, void * param)
{
lv_res_t res;
/* Include the ancient signal function */
res = ancestor_scrl_signal(roller_scrl, sign, param);
if(res != LV_RES_OK) return res;
lv_indev_t * indev = lv_indev_get_act();
int32_t id = -1;
lv_obj_t * roller = lv_obj_get_parent(roller_scrl);
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
if(ext->ddlist.label == NULL) return LV_RES_INV; /*On delete the ddlist signal deletes the label so nothing left to do here*/
lv_style_t * style_label = lv_obj_get_style(ext->ddlist.label);
const lv_font_t * font = style_label->text.font;
lv_coord_t font_h = lv_font_get_height(font);
if(sign == LV_SIGNAL_DRAG_END) {
/*If dragged then align the list to there be an element in the middle*/
lv_coord_t label_y1 = ext->ddlist.label->coords.y1 - roller->coords.y1;
lv_coord_t label_unit = font_h + style_label->text.line_space;
lv_coord_t mid = (roller->coords.y2 - roller->coords.y1) / 2;
id = (mid - label_y1 + style_label->text.line_space / 2) / label_unit;
if(id < 0) id = 0;
if(id >= ext->ddlist.option_cnt) id = ext->ddlist.option_cnt - 1;
ext->ddlist.sel_opt_id = id;
if(ext->ddlist.action) ext->ddlist.action(roller);
} else if(sign == LV_SIGNAL_RELEASED) {
/*If picked an option by clicking then set it*/
if(!lv_indev_is_dragging(indev)) {
lv_point_t p;
lv_indev_get_point(indev, &p);
p.y = p.y - ext->ddlist.label->coords.y1;
id = p.y / (font_h + style_label->text.line_space);
if(id < 0) id = 0;
if(id >= ext->ddlist.option_cnt) id = ext->ddlist.option_cnt - 1;
ext->ddlist.sel_opt_id = id;
if(ext->ddlist.action) ext->ddlist.action(roller);
}
}
/*Position the scrollable according to the new selected option*/
if(id != -1) {
refr_position(roller, true);
}
return res;
}
/**
* Draw a rectangle which has gradient on its top and bottom
* @param roller pointer to a roller object
* @param mask pointer to the current mask (from the design function)
*/
static void draw_bg(lv_obj_t * roller, const lv_area_t * mask)
{
lv_style_t * style = lv_roller_get_style(roller, LV_ROLLER_STYLE_BG);
lv_area_t half_mask;
lv_area_t half_roller;
lv_coord_t h = lv_obj_get_height(roller);
bool union_ok;
lv_area_copy(&half_roller, &roller->coords);
half_roller.x1 -= roller->ext_size; /*Add ext size too (e.g. because of shadow draw) */
half_roller.x2 += roller->ext_size;
half_roller.y1 -= roller->ext_size;
half_roller.y2 = roller->coords.y1 + h / 2;
union_ok = lv_area_intersect(&half_mask, &half_roller, mask);
half_roller.x1 += roller->ext_size; /*Revert ext. size adding*/
half_roller.x2 -= roller->ext_size;
half_roller.y1 += roller->ext_size;
half_roller.y2 += style->body.radius;
if(union_ok) {
lv_draw_rect(&half_roller, &half_mask, style, lv_obj_get_opa_scale(roller));
}
half_roller.x1 -= roller->ext_size; /*Add ext size too (e.g. because of shadow draw) */
half_roller.x2 += roller->ext_size;
half_roller.y2 = roller->coords.y2 + roller->ext_size;
half_roller.y1 = roller->coords.y1 + h / 2;
if((h & 0x1) == 0) half_roller.y1++; /*With even height the pixels in the middle would be drawn twice*/
union_ok = lv_area_intersect(&half_mask, &half_roller, mask);
half_roller.x1 += roller->ext_size; /*Revert ext. size adding*/
half_roller.x2 -= roller->ext_size;
half_roller.y2 -= roller->ext_size;
half_roller.y1 -= style->body.radius;
if(union_ok) {
lv_color_t main_tmp = style->body.main_color;
lv_color_t grad_tmp = style->body.grad_color;
style->body.main_color = grad_tmp;
style->body.grad_color = main_tmp;
lv_draw_rect(&half_roller, &half_mask, style, lv_obj_get_opa_scale(roller));
style->body.main_color = main_tmp;
style->body.grad_color = grad_tmp;
}
}
/**
* Refresh the position of the roller. It uses the id stored in: ext->ddlist.selected_option_id
* @param roller pointer to a roller object
* @param anim_en true: refresh with animation; false: without animation
*/
static void refr_position(lv_obj_t * roller, bool anim_en)
{
#if USE_LV_ANIMATION == 0
anim_en = false;
#endif
lv_obj_t * roller_scrl = lv_page_get_scrl(roller);
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
lv_style_t * style_label = lv_obj_get_style(ext->ddlist.label);
const lv_font_t * font = style_label->text.font;
lv_coord_t font_h = lv_font_get_height(font);
lv_coord_t h = lv_obj_get_height(roller);
int32_t id = ext->ddlist.sel_opt_id;
lv_coord_t line_y1 = id * (font_h + style_label->text.line_space) + ext->ddlist.label->coords.y1 - roller_scrl->coords.y1;
lv_coord_t new_y = - line_y1 + (h - font_h) / 2;
if(ext->ddlist.anim_time == 0 || anim_en == false) {
lv_obj_set_y(roller_scrl, new_y);
} else {
#if USE_LV_ANIMATION
lv_anim_t a;
a.var = roller_scrl;
a.start = lv_obj_get_y(roller_scrl);
a.end = new_y;
a.fp = (lv_anim_fp_t)lv_obj_set_y;
a.path = lv_anim_path_linear;
a.end_cb = NULL;
a.act_time = 0;
a.time = ext->ddlist.anim_time;
a.playback = 0;
a.playback_pause = 0;
a.repeat = 0;
a.repeat_pause = 0;
lv_anim_create(&a);
#endif
}
}
#endif

View File

@ -1,445 +0,0 @@
/**
* @file lv_sw.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_sw.h"
#if USE_LV_SW != 0
/*Testing of dependencies*/
#if USE_LV_SLIDER == 0
#error "lv_sw: lv_slider is required. Enable it in lv_conf.h (USE_LV_SLIDER 1) "
#endif
#include "../lv_themes/lv_theme.h"
#include "../lv_misc/lv_math.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static lv_res_t lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param);
static void lv_sw_anim_to_value(lv_obj_t * sw, int16_t value);
/**********************
* STATIC VARIABLES
**********************/
static lv_signal_func_t ancestor_signal;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Create a switch objects
* @param par pointer to an object, it will be the parent of the new switch
* @param copy pointer to a switch object, if not NULL then the new object will be copied from it
* @return pointer to the created switch
*/
lv_obj_t * lv_sw_create(lv_obj_t * par, const lv_obj_t * copy)
{
LV_LOG_TRACE("switch create started");
/*Create the ancestor of switch*/
lv_obj_t * new_sw = lv_slider_create(par, copy);
lv_mem_assert(new_sw);
if(new_sw == NULL) return NULL;
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_sw);
/*Allocate the switch type specific extended data*/
lv_sw_ext_t * ext = lv_obj_allocate_ext_attr(new_sw, sizeof(lv_sw_ext_t));
lv_mem_assert(ext);
if(ext == NULL) return NULL;
/*Initialize the allocated 'ext' */
ext->changed = 0;
#if USE_LV_ANIMATION
ext->anim_time = 0;
#endif
ext->style_knob_off = ext->slider.style_knob;
ext->style_knob_on = ext->slider.style_knob;
/*The signal and design functions are not copied so set them here*/
lv_obj_set_signal_func(new_sw, lv_sw_signal);
/*Init the new switch switch*/
if(copy == NULL) {
lv_slider_set_range(new_sw, 0, 1);
lv_obj_set_size(new_sw, 2 * LV_DPI / 3, LV_DPI / 3);
lv_slider_set_knob_in(new_sw, true);
lv_slider_set_range(new_sw, 0, LV_SWITCH_SLIDER_ANIM_MAX);
/*Set the default styles*/
lv_theme_t * th = lv_theme_get_current();
if(th) {
lv_sw_set_style(new_sw, LV_SW_STYLE_BG, th->sw.bg);
lv_sw_set_style(new_sw, LV_SW_STYLE_INDIC, th->sw.indic);
lv_sw_set_style(new_sw, LV_SW_STYLE_KNOB_OFF, th->sw.knob_off);
lv_sw_set_style(new_sw, LV_SW_STYLE_KNOB_ON, th->sw.knob_on);
} else {
/*Let the slider' style*/
}
}
/*Copy an existing switch*/
else {
lv_sw_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
ext->style_knob_off = copy_ext->style_knob_off;
ext->style_knob_on = copy_ext->style_knob_on;
#if USE_LV_ANIMATION
ext->anim_time = copy_ext->anim_time;
#endif
if(lv_sw_get_state(new_sw)) lv_slider_set_style(new_sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_on);
else lv_slider_set_style(new_sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_off);
/*Refresh the style with new signal function*/
lv_obj_refresh_style(new_sw);
}
LV_LOG_INFO("switch created");
return new_sw;
}
/*=====================
* Setter functions
*====================*/
/**
* Turn ON the switch
* @param sw pointer to a switch object
*/
void lv_sw_on(lv_obj_t * sw)
{
lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw);
lv_slider_set_value(sw, LV_SWITCH_SLIDER_ANIM_MAX);
lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_on);
}
/**
* Turn OFF the switch
* @param sw pointer to a switch object
*/
void lv_sw_off(lv_obj_t * sw)
{
lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw);
lv_slider_set_value(sw, 0);
lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_off);
}
/**
* Toggle the position of the switch
* @param sw pointer to a switch object
* @return resulting state of the switch.
*/
bool lv_sw_toggle(lv_obj_t *sw) {
bool state = lv_sw_get_state(sw);
if(state) {
lv_sw_off(sw);
}
else {
lv_sw_on(sw);
}
return !state;
}
/**
* Turn ON the switch with an animation
* @param sw pointer to a switch object
*/
void lv_sw_on_anim(lv_obj_t * sw)
{
lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw);
if(lv_sw_get_anim_time(sw) > 0)lv_sw_anim_to_value(sw, LV_SWITCH_SLIDER_ANIM_MAX);
else lv_slider_set_value(sw, LV_SWITCH_SLIDER_ANIM_MAX);
lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_on);
}
/**
* Turn OFF the switch with an animation
* @param sw pointer to a switch object
*/
void lv_sw_off_anim(lv_obj_t * sw)
{
lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw);
if(lv_sw_get_anim_time(sw) > 0) lv_sw_anim_to_value(sw, 0);
else lv_slider_set_value(sw, 0);
lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_off);
}
/**
* Toggle the position of the switch with an animation
* @param sw pointer to a switch object
* @return resulting state of the switch.
*/
bool lv_sw_toggle_anim(lv_obj_t *sw) {
bool state = lv_sw_get_state(sw);
if(state) {
lv_sw_off_anim(sw);
}
else {
lv_sw_on_anim(sw);
}
return !state;
}
/**
* Set a style of a switch
* @param sw pointer to a switch object
* @param type which style should be set
* @param style pointer to a style
*/
void lv_sw_set_style(lv_obj_t * sw, lv_sw_style_t type, lv_style_t * style)
{
lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw);
switch(type) {
case LV_SLIDER_STYLE_BG:
lv_slider_set_style(sw, LV_SLIDER_STYLE_BG, style);
break;
case LV_SLIDER_STYLE_INDIC:
lv_bar_set_style(sw, LV_SLIDER_STYLE_INDIC, style);
break;
case LV_SW_STYLE_KNOB_OFF:
ext->style_knob_off = style;
if(lv_sw_get_state(sw) == 0) lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, style);
break;
case LV_SW_STYLE_KNOB_ON:
ext->style_knob_on = style;
if(lv_sw_get_state(sw) != 0) lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, style);
break;
}
}
void lv_sw_set_anim_time(lv_obj_t *sw, uint16_t anim_time)
{
#if USE_LV_ANIMATION
lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw);
ext->anim_time = anim_time;
#endif
}
/*=====================
* Getter functions
*====================*/
/**
* Get a style of a switch
* @param sw pointer to a switch object
* @param type which style should be get
* @return style pointer to a style
*/
lv_style_t * lv_sw_get_style(const lv_obj_t * sw, lv_sw_style_t type)
{
lv_style_t * style = NULL;
lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw);
switch(type) {
case LV_SW_STYLE_BG:
style = lv_slider_get_style(sw, LV_SLIDER_STYLE_BG);
break;
case LV_SW_STYLE_INDIC:
style = lv_slider_get_style(sw, LV_SLIDER_STYLE_INDIC);
break;
case LV_SW_STYLE_KNOB_OFF:
style = ext->style_knob_off;
break;
case LV_SW_STYLE_KNOB_ON:
style = ext->style_knob_on;
break;
default:
style = NULL;
break;
}
return style;
}
uint16_t lv_sw_get_anim_time(const lv_obj_t *sw)
{
#if USE_LV_ANIMATION
lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw);
return ext->anim_time;
#else
return 0;
#endif
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Signal function of the switch
* @param sw pointer to a switch object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
*/
static lv_res_t lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param)
{
lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw);
/*Save the current (old) value before slider signal modifies it*/
int16_t old_val;
if(sign == LV_SIGNAL_PRESSING) old_val = ext->slider.drag_value;
else old_val = lv_slider_get_value(sw);
/*Do not let the slider to call the callback. The Switch will do it if required*/
lv_action_t slider_action = ext->slider.action;
ext->slider.action = NULL;
lv_res_t res;
/* Include the ancient signal function */
res = ancestor_signal(sw, sign, param);
if(res != LV_RES_OK) return res;
if(sign == LV_SIGNAL_CLEANUP) {
/*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
}
else if(sign == LV_SIGNAL_PRESSED) {
/*Save the x coordinate of the pressed point to see if the switch was slid*/
lv_indev_t * indev = lv_indev_get_act();
if(indev) {
lv_point_t p;
lv_indev_get_point(indev, &p);
ext->start_x = p.x;
}
ext->slided = 0;
ext->changed = 0;
}
else if(sign == LV_SIGNAL_PRESSING) {
/*See if the switch was slid*/
lv_indev_t * indev = lv_indev_get_act();
if(indev) {
lv_point_t p = {0,0};
lv_indev_get_point(indev, &p);
if(LV_MATH_ABS(p.x - ext->start_x) > LV_INDEV_DRAG_LIMIT) ext->slided = 1;
}
/*If didn't slide then revert the min/max value. So click without slide won't move the switch as a slider*/
if(ext->slided == 0) {
if(lv_sw_get_state(sw)) ext->slider.drag_value = LV_SWITCH_SLIDER_ANIM_MAX;
else ext->slider.drag_value = 0;
}
/*If explicitly changed (by slide) don't need to be toggled on release*/
int16_t threshold = LV_SWITCH_SLIDER_ANIM_MAX / 2;
if((old_val < threshold && ext->slider.drag_value > threshold) ||
(old_val > threshold && ext->slider.drag_value < threshold))
{
ext->changed = 1;
}
}
else if(sign == LV_SIGNAL_PRESS_LOST) {
if(lv_sw_get_state(sw)) {
lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_on);
#if USE_LV_ANIMATION
lv_sw_anim_to_value(sw, LV_SWITCH_SLIDER_ANIM_MAX);
#endif
}
else {
lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_off);
#if USE_LV_ANIMATION
lv_sw_anim_to_value(sw, 0);
#endif
}
}
else if(sign == LV_SIGNAL_RELEASED) {
/*If not dragged then toggle the switch*/
if(ext->changed == 0) {
if(lv_sw_get_state(sw)) lv_sw_off_anim(sw);
else lv_sw_on_anim(sw);
if(slider_action != NULL) res = slider_action(sw);
}
/*If the switch was dragged then calculate the new state based on the current position*/
else {
int16_t v = lv_slider_get_value(sw);
if(v > LV_SWITCH_SLIDER_ANIM_MAX / 2) lv_sw_on_anim(sw);
else lv_sw_off_anim(sw);
if(slider_action != NULL) res = slider_action(sw);
}
} else if(sign == LV_SIGNAL_CONTROLL) {
char c = *((char *)param);
if(c == LV_GROUP_KEY_ENTER) {
if(old_val) lv_sw_off_anim(sw);
else lv_sw_on_anim(sw);
if(slider_action) res = slider_action(sw);
} else if(c == LV_GROUP_KEY_UP || c == LV_GROUP_KEY_RIGHT) {
lv_sw_on_anim(sw);
if(slider_action) res = slider_action(sw);
} else if(c == LV_GROUP_KEY_DOWN || c == LV_GROUP_KEY_LEFT) {
lv_sw_off_anim(sw);
if(slider_action) res = slider_action(sw);
}
} else if(sign == LV_SIGNAL_GET_EDITABLE) {
bool * editable = (bool *)param;
*editable = false; /*The ancestor slider is editable the switch is not*/
} else if(sign == LV_SIGNAL_GET_TYPE) {
lv_obj_type_t * buf = param;
uint8_t i;
for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/
if(buf->type[i] == NULL) break;
}
buf->type[i] = "lv_sw";
}
/*Restore the callback*/
if(res == LV_RES_OK) ext->slider.action = slider_action;
return res;
}
static void lv_sw_anim_to_value(lv_obj_t * sw, int16_t value)
{
#if USE_LV_ANIMATION
lv_anim_t a;
lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw);
a.var = sw;
a.start = ext->slider.bar.cur_value;
a.end = value;
a.fp = (lv_anim_fp_t)lv_slider_set_value;
a.path = lv_anim_path_linear;
a.end_cb = NULL;
a.act_time = 0;
a.time = lv_sw_get_anim_time(sw);
a.playback = 0;
a.playback_pause = 0;
a.repeat = 0;
a.repeat_pause = 0;
lv_anim_create(&a);
#endif
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,893 +0,0 @@
/**
* @file lv_tab.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_tabview.h"
#if USE_LV_TABVIEW != 0
#include "lv_btnm.h"
#include "../lv_themes/lv_theme.h"
#include "../lv_misc/lv_anim.h"
/*********************
* DEFINES
*********************/
#if USE_LV_ANIMATION
# ifndef LV_TABVIEW_ANIM_TIME
# define LV_TABVIEW_ANIM_TIME 300 /*Animation time of focusing to the a list element [ms] (0: no animation) */
# endif
#else
# undef LV_TABVIEW_ANIM_TIME
# define LV_TABVIEW_ANIM_TIME 0 /*No animations*/
#endif
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static lv_res_t lv_tabview_signal(lv_obj_t * tabview, lv_signal_t sign, void * param);
static lv_res_t tabpage_signal(lv_obj_t * tab_page, lv_signal_t sign, void * param);
static lv_res_t tabpage_scrl_signal(lv_obj_t * tab_scrl, lv_signal_t sign, void * param);
static void tabpage_pressed_handler(lv_obj_t * tabview, lv_obj_t * tabpage);
static void tabpage_pressing_handler(lv_obj_t * tabview, lv_obj_t * tabpage);
static void tabpage_press_lost_handler(lv_obj_t * tabview, lv_obj_t * tabpage);
static lv_res_t tab_btnm_action(lv_obj_t * tab_btnm, const char * tab_name);
static void tabview_realign(lv_obj_t * tabview);
/**********************
* STATIC VARIABLES
**********************/
static lv_signal_func_t ancestor_signal;
static lv_signal_func_t page_signal;
static lv_signal_func_t page_scrl_signal;
static const char * tab_def[] = {""};
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Create a Tab view object
* @param par pointer to an object, it will be the parent of the new tab
* @param copy pointer to a tab object, if not NULL then the new object will be copied from it
* @return pointer to the created tab
*/
lv_obj_t * lv_tabview_create(lv_obj_t * par, const lv_obj_t * copy)
{
LV_LOG_TRACE("tab view create started");
/*Create the ancestor of tab*/
lv_obj_t * new_tabview = lv_obj_create(par, copy);
lv_mem_assert(new_tabview);
if(new_tabview == NULL) return NULL;
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_tabview);
/*Allocate the tab type specific extended data*/
lv_tabview_ext_t * ext = lv_obj_allocate_ext_attr(new_tabview, sizeof(lv_tabview_ext_t));
lv_mem_assert(ext);
if(ext == NULL) return NULL;
/*Initialize the allocated 'ext' */
ext->drag_hor = 0;
ext->draging = 0;
ext->slide_enable = 1;
ext->tab_cur = 0;
ext->point_last.x = 0;
ext->point_last.y = 0;
ext->content = NULL;
ext->indic = NULL;
ext->btns = NULL;
ext->tab_load_action = NULL;
ext->btns_pos = LV_TABVIEW_BTNS_POS_TOP;
ext->anim_time = LV_TABVIEW_ANIM_TIME;
ext->btns_hide = 0;
/*The signal and design functions are not copied so set them here*/
lv_obj_set_signal_func(new_tabview, lv_tabview_signal);
/*Init the new tab tab*/
if(copy == NULL) {
ext->tab_name_ptr = lv_mem_alloc(sizeof(char *));
lv_mem_assert(ext->tab_name_ptr);
if(ext->tab_name_ptr == NULL) return NULL;
ext->tab_name_ptr[0] = "";
ext->tab_cnt = 0;
lv_obj_set_size(new_tabview, LV_HOR_RES, LV_VER_RES);
ext->btns = lv_btnm_create(new_tabview, NULL);
lv_obj_set_height(ext->btns, 3 * LV_DPI / 4);
lv_btnm_set_map(ext->btns, tab_def);
lv_btnm_set_action(ext->btns, tab_btnm_action);
lv_btnm_set_toggle(ext->btns, true, 0);
ext->indic = lv_obj_create(ext->btns, NULL);
lv_obj_set_width(ext->indic, LV_DPI);
lv_obj_align(ext->indic, ext->btns, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
lv_obj_set_click(ext->indic, false);
ext->content = lv_cont_create(new_tabview, NULL);
lv_cont_set_fit(ext->content, true, false);
lv_cont_set_layout(ext->content, LV_LAYOUT_ROW_T);
lv_cont_set_style(ext->content, &lv_style_transp_tight);
lv_obj_set_height(ext->content, LV_VER_RES - lv_obj_get_height(ext->btns));
lv_obj_align(ext->content, ext->btns, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
/*Set the default styles*/
lv_theme_t * th = lv_theme_get_current();
if(th) {
lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BG, th->tabview.bg);
lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_INDIC, th->tabview.indic);
lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_BG, th->tabview.btn.bg);
lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_REL, th->tabview.btn.rel);
lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_PR, th->tabview.btn.pr);
lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_TGL_REL, th->tabview.btn.tgl_rel);
lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_TGL_PR, th->tabview.btn.tgl_pr);
} else {
lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BG, &lv_style_plain);
lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_BG, &lv_style_transp);
lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_INDIC, &lv_style_plain_color);
}
}
/*Copy an existing tab view*/
else {
lv_tabview_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
ext->point_last.x = 0;
ext->point_last.y = 0;
ext->btns = lv_btnm_create(new_tabview, copy_ext->btns);
ext->indic = lv_obj_create(ext->btns, copy_ext->indic);
ext->content = lv_cont_create(new_tabview, copy_ext->content);
ext->anim_time = copy_ext->anim_time;
ext->tab_load_action = copy_ext->tab_load_action;
ext->tab_name_ptr = lv_mem_alloc(sizeof(char *));
lv_mem_assert(ext->tab_name_ptr);
if(ext->tab_name_ptr == NULL) return NULL;
ext->tab_name_ptr[0] = "";
lv_btnm_set_map(ext->btns, ext->tab_name_ptr);
uint16_t i;
lv_obj_t * new_tab;
lv_obj_t * copy_tab;
for(i = 0; i < copy_ext->tab_cnt; i++) {
new_tab = lv_tabview_add_tab(new_tabview, copy_ext->tab_name_ptr[i]);
copy_tab = lv_tabview_get_tab(copy, i);
lv_page_set_style(new_tab, LV_PAGE_STYLE_BG, lv_page_get_style(copy_tab, LV_PAGE_STYLE_BG));
lv_page_set_style(new_tab, LV_PAGE_STYLE_SCRL, lv_page_get_style(copy_tab, LV_PAGE_STYLE_SCRL));
lv_page_set_style(new_tab, LV_PAGE_STYLE_SB, lv_page_get_style(copy_tab, LV_PAGE_STYLE_SB));
}
/*Refresh the style with new signal function*/
lv_obj_refresh_style(new_tabview);
}
LV_LOG_INFO("tab view created");
return new_tabview;
}
/**
* Delete all children of the scrl object, without deleting scrl child.
* @param obj pointer to an object
*/
void lv_tabview_clean(lv_obj_t * obj)
{
lv_obj_t * scrl = lv_page_get_scrl(obj);
lv_obj_clean(scrl);
}
/*======================
* Add/remove functions
*=====================*/
/**
* Add a new tab with the given name
* @param tabview pointer to Tab view object where to ass the new tab
* @param name the text on the tab button
* @return pointer to the created page object (lv_page). You can create your content here
*/
lv_obj_t * lv_tabview_add_tab(lv_obj_t * tabview, const char * name)
{
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
/*Create the container page*/
lv_obj_t * h = lv_page_create(ext->content, NULL);
lv_obj_set_size(h, lv_obj_get_width(tabview), lv_obj_get_height(ext->content));
lv_page_set_sb_mode(h, LV_SB_MODE_AUTO);
lv_page_set_style(h, LV_PAGE_STYLE_BG, &lv_style_transp);
lv_page_set_style(h, LV_PAGE_STYLE_SCRL, &lv_style_transp);
if(page_signal == NULL) page_signal = lv_obj_get_signal_func(h);
if(page_scrl_signal == NULL) page_scrl_signal = lv_obj_get_signal_func(lv_page_get_scrl(h));
lv_obj_set_signal_func(h, tabpage_signal);
lv_obj_set_signal_func(lv_page_get_scrl(h), tabpage_scrl_signal);
/*Extend the button matrix map with the new name*/
char * name_dm;
if((name[0] & LV_BTNM_CTRL_MASK) == LV_BTNM_CTRL_CODE) { /*If control byte presented let is*/
name_dm = lv_mem_alloc(strlen(name) + 1); /*+1 for the the closing '\0' */
lv_mem_assert(name_dm);
if(name_dm == NULL) return NULL;
strcpy(name_dm, name);
} else { /*Set a no long press control byte is not presented*/
name_dm = lv_mem_alloc(strlen(name) + 2); /*+1 for the the closing '\0' and +1 for the control byte */
lv_mem_assert(name_dm);
if(name_dm == NULL) return NULL;
name_dm[0] = '\221';
strcpy(&name_dm[1], name);
}
ext->tab_cnt++;
ext->tab_name_ptr = lv_mem_realloc(ext->tab_name_ptr, sizeof(char *) * (ext->tab_cnt + 1));
lv_mem_assert(ext->tab_name_ptr);
if(ext->tab_name_ptr == NULL) return NULL;
ext->tab_name_ptr[ext->tab_cnt - 1] = name_dm;
ext->tab_name_ptr[ext->tab_cnt] = "";
lv_btnm_set_map(ext->btns, ext->tab_name_ptr);
/*Modify the indicator size*/
lv_style_t * style_tabs = lv_obj_get_style(ext->btns);
lv_coord_t indic_width = (lv_obj_get_width(tabview) - style_tabs->body.padding.inner * (ext->tab_cnt - 1) - 2 * style_tabs->body.padding.hor) / ext->tab_cnt;
lv_obj_set_width(ext->indic, indic_width);
lv_obj_set_x(ext->indic, indic_width * ext->tab_cur + style_tabs->body.padding.inner * ext->tab_cur + style_tabs->body.padding.hor);
/*Set the first btn as active*/
if(ext->tab_cnt == 1) {
ext->tab_cur = 0;
lv_tabview_set_tab_act(tabview, 0, false);
tabview_realign(tabview); /*To set the proper btns height*/
}
return h;
}
/*=====================
* Setter functions
*====================*/
/**
* Set a new tab
* @param tabview pointer to Tab view object
* @param id index of a tab to load
* @param anim_en true: set with sliding animation; false: set immediately
*/
void lv_tabview_set_tab_act(lv_obj_t * tabview, uint16_t id, bool anim_en)
{
#if USE_LV_ANIMATION == 0
anim_en = false;
#endif
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
lv_style_t * style = lv_obj_get_style(ext->content);
lv_res_t res = LV_RES_OK;
if(id >= ext->tab_cnt) id = ext->tab_cnt - 1;
if(ext->tab_load_action && id != ext->tab_cur) res = ext->tab_load_action(tabview, id);
if(res != LV_RES_OK) return; /*Prevent the tab loading*/
ext->tab_cur = id;
lv_coord_t cont_x = -(lv_obj_get_width(tabview) * id + style->body.padding.inner * id + style->body.padding.hor);
if(ext->anim_time == 0 || anim_en == false) {
lv_obj_set_x(ext->content, cont_x);
} else {
#if USE_LV_ANIMATION
lv_anim_t a;
a.var = ext->content;
a.start = lv_obj_get_x(ext->content);
a.end = cont_x;
a.fp = (lv_anim_fp_t)lv_obj_set_x;
a.path = lv_anim_path_linear;
a.end_cb = NULL;
a.act_time = 0;
a.time = ext->anim_time;
a.playback = 0;
a.playback_pause = 0;
a.repeat = 0;
a.repeat_pause = 0;
lv_anim_create(&a);
#endif
}
/*Move the indicator*/
lv_coord_t indic_width = lv_obj_get_width(ext->indic);
lv_style_t * tabs_style = lv_obj_get_style(ext->btns);
lv_coord_t indic_x = indic_width * id + tabs_style->body.padding.inner * id + tabs_style->body.padding.hor;
if(ext->anim_time == 0 || anim_en == false) {
lv_obj_set_x(ext->indic, indic_x);
} else {
#if USE_LV_ANIMATION
lv_anim_t a;
a.var = ext->indic;
a.start = lv_obj_get_x(ext->indic);
a.end = indic_x;
a.fp = (lv_anim_fp_t)lv_obj_set_x;
a.path = lv_anim_path_linear;
a.end_cb = NULL;
a.act_time = 0;
a.time = ext->anim_time;
a.playback = 0;
a.playback_pause = 0;
a.repeat = 0;
a.repeat_pause = 0;
lv_anim_create(&a);
#endif
}
lv_btnm_set_toggle(ext->btns, true, ext->tab_cur);
}
/**
* Set an action to call when a tab is loaded (Good to create content only if required)
* lv_tabview_get_act() still gives the current (old) tab (to remove content from here)
* @param tabview pointer to a tabview object
* @param action pointer to a function to call when a btn is loaded
*/
void lv_tabview_set_tab_load_action(lv_obj_t * tabview, lv_tabview_action_t action)
{
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
ext->tab_load_action = action;
}
/**
* Enable horizontal sliding with touch pad
* @param tabview pointer to Tab view object
* @param en true: enable sliding; false: disable sliding
*/
void lv_tabview_set_sliding(lv_obj_t * tabview, bool en)
{
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
ext->slide_enable = en == false ? 0 : 1;
}
/**
* Set the animation time of tab view when a new tab is loaded
* @param tabview pointer to Tab view object
* @param anim_time_ms time of animation in milliseconds
*/
void lv_tabview_set_anim_time(lv_obj_t * tabview, uint16_t anim_time)
{
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
#if USE_LV_ANIMATION == 0
anim_time = 0;
#endif
ext->anim_time = anim_time;
}
/**
* Set the style of a tab view
* @param tabview pointer to a tan view object
* @param type which style should be set
* @param style pointer to the new style
*/
void lv_tabview_set_style(lv_obj_t * tabview, lv_tabview_style_t type, lv_style_t * style)
{
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
switch(type) {
case LV_TABVIEW_STYLE_BG:
lv_obj_set_style(tabview, style);
break;
case LV_TABVIEW_STYLE_BTN_BG:
lv_btnm_set_style(ext->btns, LV_BTNM_STYLE_BG, style);
tabview_realign(tabview);
break;
case LV_TABVIEW_STYLE_BTN_REL:
lv_btnm_set_style(ext->btns, LV_BTNM_STYLE_BTN_REL, style);
tabview_realign(tabview);
break;
case LV_TABVIEW_STYLE_BTN_PR:
lv_btnm_set_style(ext->btns, LV_BTNM_STYLE_BTN_PR, style);
break;
case LV_TABVIEW_STYLE_BTN_TGL_REL:
lv_btnm_set_style(ext->btns, LV_BTNM_STYLE_BTN_TGL_REL, style);
break;
case LV_TABVIEW_STYLE_BTN_TGL_PR:
lv_btnm_set_style(ext->btns, LV_BTNM_STYLE_BTN_TGL_PR, style);
break;
case LV_TABVIEW_STYLE_INDIC:
lv_obj_set_style(ext->indic, style);
lv_obj_set_height(ext->indic, style->body.padding.inner);
tabview_realign(tabview);
break;
}
}
/**
* Set the position of tab select buttons
* @param tabview pointer to a tan view object
* @param btns_pos which button position
*/
void lv_tabview_set_btns_pos(lv_obj_t * tabview, lv_tabview_btns_pos_t btns_pos)
{
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
ext->btns_pos = btns_pos;
tabview_realign(tabview);
}
/**
* Set whether tab buttons are hidden
* @param tabview pointer to a tab view object
* @param en whether tab buttons are hidden
*/
void lv_tabview_set_btns_hidden(lv_obj_t *tabview, bool en)
{
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
ext->btns_hide = en;
tabview_realign(tabview);
}
/*=====================
* Getter functions
*====================*/
/**
* Get the index of the currently active tab
* @param tabview pointer to Tab view object
* @return the active btn index
*/
uint16_t lv_tabview_get_tab_act(const lv_obj_t * tabview)
{
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
return ext->tab_cur;
}
/**
* Get the number of tabs
* @param tabview pointer to Tab view object
* @return btn count
*/
uint16_t lv_tabview_get_tab_count(const lv_obj_t * tabview)
{
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
return ext->tab_cnt;
}
/**
* Get the page (content area) of a tab
* @param tabview pointer to Tab view object
* @param id index of the btn (>= 0)
* @return pointer to page (lv_page) object
*/
lv_obj_t * lv_tabview_get_tab(const lv_obj_t * tabview, uint16_t id)
{
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
uint16_t i = 0;
lv_obj_t * page = lv_obj_get_child_back(ext->content, NULL);
while(page != NULL && i != id) {
i++;
page = lv_obj_get_child_back(ext->content, page);
}
if(i == id) return page;
return NULL;
}
/**
* Get the tab load action
* @param tabview pointer to a tabview object
* @param return the current btn load action
*/
lv_tabview_action_t lv_tabview_get_tab_load_action(const lv_obj_t * tabview)
{
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
return ext->tab_load_action;
}
/**
* Get horizontal sliding is enabled or not
* @param tabview pointer to Tab view object
* @return true: enable sliding; false: disable sliding
*/
bool lv_tabview_get_sliding(const lv_obj_t * tabview)
{
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
return ext->slide_enable ? true : false;
}
/**
* Get the animation time of tab view when a new tab is loaded
* @param tabview pointer to Tab view object
* @return time of animation in milliseconds
*/
uint16_t lv_tabview_get_anim_time(const lv_obj_t * tabview)
{
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
return ext->anim_time;
}
/**
* Get a style of a tab view
* @param tabview pointer to a ab view object
* @param type which style should be get
* @return style pointer to a style
*/
lv_style_t * lv_tabview_get_style(const lv_obj_t * tabview, lv_tabview_style_t type)
{
lv_style_t * style = NULL;
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
switch(type) {
case LV_TABVIEW_STYLE_BG:
style = lv_obj_get_style(tabview);
break;
case LV_TABVIEW_STYLE_BTN_BG:
style = lv_btnm_get_style(ext->btns, LV_BTNM_STYLE_BG);
break;
case LV_TABVIEW_STYLE_BTN_REL:
style = lv_btnm_get_style(ext->btns, LV_BTNM_STYLE_BTN_REL);
break;
case LV_TABVIEW_STYLE_BTN_PR:
style = lv_btnm_get_style(ext->btns, LV_BTNM_STYLE_BTN_PR);
break;
case LV_TABVIEW_STYLE_BTN_TGL_REL:
style = lv_btnm_get_style(ext->btns, LV_BTNM_STYLE_BTN_TGL_REL);
break;
case LV_TABVIEW_STYLE_BTN_TGL_PR:
style = lv_btnm_get_style(ext->btns, LV_BTNM_STYLE_BTN_TGL_PR);
break;
default:
style = NULL;
break;
}
return style;
}
/**
* Get position of tab select buttons
* @param tabview pointer to a ab view object
*/
lv_tabview_btns_pos_t lv_tabview_get_btns_pos(const lv_obj_t * tabview)
{
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
return ext->btns_pos;
}
/**
* Get whether tab buttons are hidden
* @param tabview pointer to a tab view object
* @return whether tab buttons are hidden
*/
bool lv_tabview_get_btns_hidden(const lv_obj_t *tabview)
{
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
return ext->btns_hide;
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Signal function of the Tab view
* @param tabview pointer to a Tab view object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
*/
static lv_res_t lv_tabview_signal(lv_obj_t * tabview, lv_signal_t sign, void * param)
{
lv_res_t res;
/* Include the ancient signal function */
res = ancestor_signal(tabview, sign, param);
if(res != LV_RES_OK) return res;
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
if(sign == LV_SIGNAL_CLEANUP) {
uint8_t i;
for(i = 0; ext->tab_name_ptr[i][0] != '\0'; i++) lv_mem_free(ext->tab_name_ptr[i]);
lv_mem_free(ext->tab_name_ptr);
ext->tab_name_ptr = NULL;
ext->btns = NULL; /*These objects were children so they are already invalid*/
ext->content = NULL;
} else if(sign == LV_SIGNAL_CORD_CHG) {
if(ext->content != NULL &&
(lv_obj_get_width(tabview) != lv_area_get_width(param) ||
lv_obj_get_height(tabview) != lv_area_get_height(param))) {
tabview_realign(tabview);
}
} else if(sign == LV_SIGNAL_FOCUS || sign == LV_SIGNAL_DEFOCUS || sign == LV_SIGNAL_CONTROLL) {
/* The button matrix is not in a group (the tab view is in it) but it should handle the group signals.
* So propagate the related signals to the button matrix manually*/
if(ext->btns) {
ext->btns->signal_func(ext->btns, sign, param);
}
if(sign == LV_SIGNAL_FOCUS) {
lv_hal_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act());
/*With ENCODER select the first button only in edit mode*/
if(indev_type == LV_INDEV_TYPE_ENCODER) {
#if USE_LV_GROUP
lv_group_t * g = lv_obj_get_group(tabview);
if(lv_group_get_editing(g)) {
lv_btnm_ext_t * btnm_ext = lv_obj_get_ext_attr(ext->btns);
btnm_ext->btn_id_pr = 0;
lv_obj_invalidate(ext->btns);
}
#endif
} else {
lv_btnm_ext_t * btnm_ext = lv_obj_get_ext_attr(ext->btns);
btnm_ext->btn_id_pr = 0;
lv_obj_invalidate(ext->btns);
}
}
} else if(sign == LV_SIGNAL_GET_EDITABLE) {
bool * editable = (bool *)param;
*editable = true;
} else if(sign == LV_SIGNAL_GET_TYPE) {
lv_obj_type_t * buf = param;
uint8_t i;
for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/
if(buf->type[i] == NULL) break;
}
buf->type[i] = "lv_tabview";
}
return res;
}
/**
* Signal function of a tab's page
* @param tab pointer to a tab page object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
*/
static lv_res_t tabpage_signal(lv_obj_t * tab_page, lv_signal_t sign, void * param)
{
lv_res_t res;
/* Include the ancient signal function */
res = page_signal(tab_page, sign, param);
if(res != LV_RES_OK) return res;
lv_obj_t * cont = lv_obj_get_parent(tab_page);
lv_obj_t * tabview = lv_obj_get_parent(cont);
if(lv_tabview_get_sliding(tabview) == false) return res;
if(sign == LV_SIGNAL_PRESSED) {
tabpage_pressed_handler(tabview, tab_page);
} else if(sign == LV_SIGNAL_PRESSING) {
tabpage_pressing_handler(tabview, tab_page);
} else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) {
tabpage_press_lost_handler(tabview, tab_page);
}
return res;
}
/**
* Signal function of the tab page's scrollable object
* @param tab_scrl pointer to a tab page's scrollable object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
*/
static lv_res_t tabpage_scrl_signal(lv_obj_t * tab_scrl, lv_signal_t sign, void * param)
{
lv_res_t res;
/* Include the ancient signal function */
res = page_scrl_signal(tab_scrl, sign, param);
if(res != LV_RES_OK) return res;
lv_obj_t * tab_page = lv_obj_get_parent(tab_scrl);
lv_obj_t * cont = lv_obj_get_parent(tab_page);
lv_obj_t * tabview = lv_obj_get_parent(cont);
if(lv_tabview_get_sliding(tabview) == false) return res;
if(sign == LV_SIGNAL_PRESSED) {
tabpage_pressed_handler(tabview, tab_page);
} else if(sign == LV_SIGNAL_PRESSING) {
tabpage_pressing_handler(tabview, tab_page);
} else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) {
tabpage_press_lost_handler(tabview, tab_page);
}
return res;
}
/**
* Called when a tab's page or scrollable object is pressed
* @param tabview pointer to the btn view object
* @param tabpage pointer to the page of a btn
*/
static void tabpage_pressed_handler(lv_obj_t * tabview, lv_obj_t * tabpage)
{
(void)tabpage;
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
lv_indev_t * indev = lv_indev_get_act();
lv_indev_get_point(indev, &ext->point_last);
}
/**
* Called when a tab's page or scrollable object is being pressed
* @param tabview pointer to the btn view object
* @param tabpage pointer to the page of a btn
*/
static void tabpage_pressing_handler(lv_obj_t * tabview, lv_obj_t * tabpage)
{
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
lv_indev_t * indev = lv_indev_get_act();
lv_point_t point_act;
lv_indev_get_point(indev, &point_act);
lv_coord_t x_diff = point_act.x - ext->point_last.x;
lv_coord_t y_diff = point_act.y - ext->point_last.y;
if(ext->draging == 0) {
if(x_diff >= LV_INDEV_DRAG_LIMIT || x_diff <= -LV_INDEV_DRAG_LIMIT) {
ext->drag_hor = 1;
ext->draging = 1;
lv_obj_set_drag(lv_page_get_scrl(tabpage), false);
} else if(y_diff >= LV_INDEV_DRAG_LIMIT || y_diff <= -LV_INDEV_DRAG_LIMIT) {
ext->drag_hor = 0;
ext->draging = 1;
}
}
if(ext->drag_hor) {
lv_obj_set_x(ext->content, lv_obj_get_x(ext->content) + point_act.x - ext->point_last.x);
ext->point_last.x = point_act.x;
ext->point_last.y = point_act.y;
/*Move the indicator*/
lv_coord_t indic_width = lv_obj_get_width(ext->indic);
lv_style_t * tabs_style = lv_obj_get_style(ext->btns);
lv_style_t * indic_style = lv_obj_get_style(ext->indic);
lv_coord_t p = ((tabpage->coords.x1 - tabview->coords.x1) * (indic_width + tabs_style->body.padding.inner)) / lv_obj_get_width(tabview);
lv_obj_set_x(ext->indic, indic_width * ext->tab_cur + tabs_style->body.padding.inner * ext->tab_cur + indic_style->body.padding.hor - p);
}
}
/**
* Called when a tab's page or scrollable object is released or the press id lost
* @param tabview pointer to the btn view object
* @param tabpage pointer to the page of a btn
*/
static void tabpage_press_lost_handler(lv_obj_t * tabview, lv_obj_t * tabpage)
{
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
ext->drag_hor = 0;
ext->draging = 0;
lv_obj_set_drag(lv_page_get_scrl(tabpage), true);
lv_indev_t * indev = lv_indev_get_act();
lv_point_t point_act;
lv_indev_get_point(indev, &point_act);
lv_point_t vect;
lv_indev_get_vect(indev, &vect);
lv_coord_t x_predict = 0;
while(vect.x != 0) {
x_predict += vect.x;
vect.x = vect.x * (100 - LV_INDEV_DRAG_THROW) / 100;
}
lv_coord_t page_x1 = tabpage->coords.x1 - tabview->coords.x1 + x_predict;
lv_coord_t page_x2 = page_x1 + lv_obj_get_width(tabpage);
lv_coord_t treshold = lv_obj_get_width(tabview) / 2;
uint16_t tab_cur = ext->tab_cur;
if(page_x1 > treshold) {
if(tab_cur != 0) tab_cur--;
} else if(page_x2 < treshold) {
if(tab_cur < ext->tab_cnt - 1) tab_cur++;
}
lv_tabview_set_tab_act(tabview, tab_cur, true);
}
/**
* Called when a tab button is released
* @param tab_btnm pointer to the tab's button matrix object
* @param id the id of the tab (>= 0)
* @return LV_ACTION_RES_OK because the button matrix in not deleted in the function
*/
static lv_res_t tab_btnm_action(lv_obj_t * tab_btnm, const char * tab_name)
{
lv_obj_t * tab = lv_obj_get_parent(tab_btnm);
const char ** tabs_map = lv_btnm_get_map(tab_btnm);
uint8_t i = 0;
while(tabs_map[i][0] != '\0') {
if(strcmp(&tabs_map[i][1], tab_name) == 0) break; /*[1] to skip the control byte*/
i++;
}
lv_tabview_set_tab_act(tab, i, true);
return LV_RES_OK;
}
/**
* Realign and resize the elements of Tab view
* @param tabview pointer to a Tab view object
*/
static void tabview_realign(lv_obj_t * tabview)
{
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
lv_obj_set_width(ext->btns, lv_obj_get_width(tabview));
if(ext->btns_hide) {
lv_obj_set_hidden(ext->btns, true);
lv_obj_set_hidden(ext->indic, true);
lv_obj_set_height(ext->content, lv_obj_get_height(tabview));
lv_obj_align(ext->content, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);
}
else if(ext->tab_cnt != 0) {
lv_obj_set_hidden(ext->btns, false);
lv_obj_set_hidden(ext->indic, false);
lv_style_t * style_btn_bg = lv_tabview_get_style(tabview, LV_TABVIEW_STYLE_BTN_BG);
lv_style_t * style_btn_rel = lv_tabview_get_style(tabview, LV_TABVIEW_STYLE_BTN_REL);
/*Set the indicator widths*/
lv_coord_t indic_width = (lv_obj_get_width(tabview) - style_btn_bg->body.padding.inner * (ext->tab_cnt - 1) -
2 * style_btn_bg->body.padding.hor) / ext->tab_cnt;
lv_obj_set_width(ext->indic, indic_width);
/*Set the tabs height*/
lv_coord_t btns_height = lv_font_get_height(style_btn_rel->text.font) +
2 * style_btn_rel->body.padding.ver +
2 * style_btn_bg->body.padding.ver;
lv_obj_set_height(ext->btns, btns_height);
lv_obj_set_height(ext->content, lv_obj_get_height(tabview) - lv_obj_get_height(ext->btns));
switch(ext->btns_pos) {
case LV_TABVIEW_BTNS_POS_TOP:
lv_obj_align(ext->btns, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);
lv_obj_align(ext->content, ext->btns, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
break;
case LV_TABVIEW_BTNS_POS_BOTTOM:
lv_obj_align(ext->content, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);
lv_obj_align(ext->btns, ext->content, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
break;
}
}
lv_obj_t * pages = lv_obj_get_child(ext->content, NULL);
while(pages != NULL) {
if(lv_obj_get_signal_func(pages) == tabpage_signal) { /*Be sure adjust only the pages (user can other things)*/
lv_obj_set_size(pages, lv_obj_get_width(tabview), lv_obj_get_height(ext->content));
}
pages = lv_obj_get_child(ext->content, pages);
}
if(!ext->btns_hide) {
lv_obj_align(ext->indic, ext->btns, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
}
lv_tabview_set_tab_act(tabview, ext->tab_cur, false);
}
#endif

View File

@ -1,185 +0,0 @@
/**
* @file lv_port_disp_templ.c
*
*/
/*Copy this file as "lv_port_disp.c" and set this value to "1" to enable content*/
#if 0
/*********************
* INCLUDES
*********************/
#include "lv_port_disp_templ.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void disp_init(void);
static void disp_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p);
static void disp_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p);
static void disp_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color);
#if USE_LV_GPU
static void mem_blend(lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa);
static void mem_fill(lv_color_t * dest, uint32_t length, lv_color_t color);
#endif
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_port_disp_init(void)
{
/*-------------------------
* Initialize your display
* -----------------------*/
disp_init();
/*-----------------------------------
* Register the display in LittlevGL
*----------------------------------*/
lv_disp_drv_t disp_drv; /*Descriptor of a display driver*/
lv_disp_drv_init(&disp_drv); /*Basic initialization*/
/*Set up the functions to access to your display*/
/*Used in buffered mode (LV_VDB_SIZE != 0 in lv_conf.h)*/
disp_drv.disp_flush = disp_flush;
/*Used in unbuffered mode (LV_VDB_SIZE == 0 in lv_conf.h)*/
disp_drv.disp_fill = disp_fill;
/*Used in unbuffered mode (LV_VDB_SIZE == 0 in lv_conf.h)*/
disp_drv.disp_map = disp_map;
#if USE_LV_GPU
/*Optionally add functions to access the GPU. (Only in buffered mode, LV_VDB_SIZE != 0)*/
/*Blend two color array using opacity*/
disp_drv.mem_blend = mem_blend;
/*Fill a memory array with a color*/
disp_drv.mem_fill = mem_fill;
#endif
/*Finally register the driver*/
lv_disp_drv_register(&disp_drv);
}
/**********************
* STATIC FUNCTIONS
**********************/
/* Initialize your display and the required peripherals. */
static void disp_init(void)
{
/*You code here*/
}
/* Flush the content of the internal buffer the specific area on the display
* You can use DMA or any hardware acceleration to do this operation in the background but
* 'lv_flush_ready()' has to be called when finished
* This function is required only when LV_VDB_SIZE != 0 in lv_conf.h*/
static void disp_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p)
{
/*The most simple case (but also the slowest) to put all pixels to the screen one-by-one*/
int32_t x;
int32_t y;
for(y = y1; y <= y2; y++) {
for(x = x1; x <= x2; x++) {
/* Put a pixel to the display. For example: */
/* put_px(x, y, *color_p)*/
color_p++;
}
}
/* IMPORTANT!!!
* Inform the graphics library that you are ready with the flushing*/
lv_flush_ready();
}
/* Write a pixel array (called 'map') to the a specific area on the display
* This function is required only when LV_VDB_SIZE == 0 in lv_conf.h*/
static void disp_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p)
{
/*The most simple case (but also the slowest) to put all pixels to the screen one-by-one*/
int32_t x;
int32_t y;
for(y = y1; y <= y2; y++) {
for(x = x1; x <= x2; x++) {
/* Put a pixel to the display. For example: */
/* put_px(x, y, *color_p)*/
color_p++;
}
}
}
/* Write a pixel array (called 'map') to the a specific area on the display
* This function is required only when LV_VDB_SIZE == 0 in lv_conf.h*/
static void disp_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color)
{
/*The most simple case (but also the slowest) to put all pixels to the screen one-by-one*/
int32_t x;
int32_t y;
for(y = y1; y <= y2; y++) {
for(x = x1; x <= x2; x++) {
/* Put a pixel to the display. For example: */
/* put_px(x, y, *color)*/
}
}
(void)color; /*Just to avid warnings*/
}
/*OPTIONAL: GPU INTERFACE*/
#if USE_LV_GPU
/* If your MCU has hardware accelerator (GPU) then you can use it to blend to memories using opacity
* It can be used only in buffered mode (LV_VDB_SIZE != 0 in lv_conf.h)*/
static void mem_blend(lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa)
{
/*It's an example code which should be done by your GPU*/
uint32_t i;
for(i = 0; i < length; i++) {
dest[i] = lv_color_mix(dest[i], src[i], opa);
}
}
/* If your MCU has hardware accelerator (GPU) then you can use it to fill a memory with a color
* It can be used only in buffered mode (LV_VDB_SIZE != 0 in lv_conf.h)*/
static void mem_fill(lv_color_t * dest, uint32_t length, lv_color_t color)
{
/*It's an example code which should be done by your GPU*/
uint32_t i;
for(i = 0; i < length; i++) {
dest[i] = color;
}
}
#endif /*USE_LV_GPU*/
#endif

View File

@ -1,332 +0,0 @@
/**
*@file lv_themes.h
*
*/
#ifndef LV_THEMES_H
#define LV_THEMES_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_conf.h"
#else
#include "../../lv_conf.h"
#endif
#include "../lv_core/lv_style.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef struct {
lv_style_t *bg;
lv_style_t *panel;
#if USE_LV_CONT != 0
lv_style_t *cont;
#endif
#if USE_LV_BTN != 0
struct {
lv_style_t *rel;
lv_style_t *pr;
lv_style_t *tgl_rel;
lv_style_t *tgl_pr;
lv_style_t *ina;
} btn;
#endif
#if USE_LV_IMGBTN != 0
struct {
lv_style_t *rel;
lv_style_t *pr;
lv_style_t *tgl_rel;
lv_style_t *tgl_pr;
lv_style_t *ina;
} imgbtn;
#endif
#if USE_LV_LABEL != 0
struct {
lv_style_t *prim;
lv_style_t *sec;
lv_style_t *hint;
} label;
#endif
#if USE_LV_IMG != 0
struct {
lv_style_t *light;
lv_style_t *dark;
} img;
#endif
#if USE_LV_LINE != 0
struct {
lv_style_t *decor;
} line;
#endif
#if USE_LV_LED != 0
lv_style_t *led;
#endif
#if USE_LV_BAR != 0
struct {
lv_style_t *bg;
lv_style_t *indic;
} bar;
#endif
#if USE_LV_SLIDER != 0
struct {
lv_style_t *bg;
lv_style_t *indic;
lv_style_t *knob;
} slider;
#endif
#if USE_LV_LMETER != 0
lv_style_t *lmeter;
#endif
#if USE_LV_GAUGE != 0
lv_style_t *gauge;
#endif
#if USE_LV_ARC != 0
lv_style_t *arc;
#endif
#if USE_LV_PRELOAD != 0
lv_style_t *preload;
#endif
#if USE_LV_SW != 0
struct {
lv_style_t *bg;
lv_style_t *indic;
lv_style_t *knob_off;
lv_style_t *knob_on;
} sw;
#endif
#if USE_LV_CHART != 0
lv_style_t *chart;
#endif
#if USE_LV_CALENDAR != 0
struct {
lv_style_t *bg;
lv_style_t *header;
lv_style_t *header_pr;
lv_style_t *day_names;
lv_style_t *highlighted_days;
lv_style_t *inactive_days;
lv_style_t *week_box;
lv_style_t *today_box;
} calendar;
#endif
#if USE_LV_CB != 0
struct {
lv_style_t *bg;
struct {
lv_style_t *rel;
lv_style_t *pr;
lv_style_t *tgl_rel;
lv_style_t *tgl_pr;
lv_style_t *ina;
} box;
} cb;
#endif
#if USE_LV_BTNM != 0
struct {
lv_style_t *bg;
struct {
lv_style_t *rel;
lv_style_t *pr;
lv_style_t *tgl_rel;
lv_style_t *tgl_pr;
lv_style_t *ina;
} btn;
} btnm;
#endif
#if USE_LV_KB != 0
struct {
lv_style_t *bg;
struct {
lv_style_t *rel;
lv_style_t *pr;
lv_style_t *tgl_rel;
lv_style_t *tgl_pr;
lv_style_t *ina;
} btn;
} kb;
#endif
#if USE_LV_MBOX != 0
struct {
lv_style_t *bg;
struct {
lv_style_t *bg;
lv_style_t *rel;
lv_style_t *pr;
} btn;
} mbox;
#endif
#if USE_LV_PAGE != 0
struct {
lv_style_t *bg;
lv_style_t *scrl;
lv_style_t *sb;
} page;
#endif
#if USE_LV_TA != 0
struct {
lv_style_t *area;
lv_style_t *oneline;
lv_style_t *cursor;
lv_style_t *sb;
} ta;
#endif
#if USE_LV_SPINBOX != 0
struct {
lv_style_t *bg;
lv_style_t *cursor;
lv_style_t *sb;
} spinbox;
#endif
#if USE_LV_LIST
struct {
lv_style_t *bg;
lv_style_t *scrl;
lv_style_t *sb;
struct {
lv_style_t *rel;
lv_style_t *pr;
lv_style_t *tgl_rel;
lv_style_t *tgl_pr;
lv_style_t *ina;
} btn;
} list;
#endif
#if USE_LV_DDLIST != 0
struct {
lv_style_t *bg;
lv_style_t *sel;
lv_style_t *sb;
} ddlist;
#endif
#if USE_LV_ROLLER != 0
struct {
lv_style_t *bg;
lv_style_t *sel;
} roller;
#endif
#if USE_LV_TABVIEW != 0
struct {
lv_style_t *bg;
lv_style_t *indic;
struct {
lv_style_t *bg;
lv_style_t *rel;
lv_style_t *pr;
lv_style_t *tgl_rel;
lv_style_t *tgl_pr;
} btn;
} tabview;
#endif
#if USE_LV_TILEVIEW != 0
struct {
lv_style_t *bg;
lv_style_t *scrl;
lv_style_t *sb;
} tileview;
#endif
#if USE_LV_TABLE != 0
struct {
lv_style_t *bg;
lv_style_t *cell;
} table;
#endif
#if USE_LV_WIN != 0
struct {
lv_style_t *bg;
lv_style_t *sb;
lv_style_t *header;
struct {
lv_style_t *bg;
lv_style_t *scrl;
} content;
struct {
lv_style_t *rel;
lv_style_t *pr;
} btn;
} win;
#endif
} lv_theme_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Set a theme for the system.
* From now, all the created objects will use styles from this theme by default
* @param th pointer to theme (return value of: 'lv_theme_init_xxx()')
*/
void lv_theme_set_current(lv_theme_t *th);
/**
* Get the current system theme.
* @return pointer to the current system theme. NULL if not set.
*/
lv_theme_t * lv_theme_get_current(void);
/**********************
* MACROS
**********************/
/**********************
* POST INCLUDE
*********************/
#include "lv_theme_templ.h"
#include "lv_theme_default.h"
#include "lv_theme_alien.h"
#include "lv_theme_night.h"
#include "lv_theme_zen.h"
#include "lv_theme_mono.h"
#include "lv_theme_nemo.h"
#include "lv_theme_material.h"
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_THEMES_H*/

View File

@ -1,882 +0,0 @@
/**
* @file lv_theme_alien.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_theme.h"
#if USE_LV_THEME_ALIEN
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
static uint16_t _hue;
static lv_font_t * _font;
static lv_theme_t theme;
static lv_style_t def;
static lv_style_t bg;
static lv_style_t panel; /*General fancy background (e.g. to chart or ta)*/
static lv_style_t sb;
static lv_style_t btn_rel, btn_pr, btn_trel, btn_tpr, btn_ina;
#if USE_LV_BAR
static lv_style_t bar_bg, bar_indic;
#endif
#if USE_LV_SLIDER
static lv_style_t slider_knob;
#endif
#if USE_LV_LMETER
static lv_style_t lmeter_bg;
#endif
#if USE_LV_DDLIST
static lv_style_t ddlist_bg, ddlist_sel;
#endif
#if USE_LV_BTNM
static lv_style_t btnm_bg, btnm_rel, btnm_pr, btnm_trel, btnm_ina;
#endif
/**********************
* MACROS
**********************/
/**********************
* STATIC FUNCTIONS
**********************/
static void basic_init(void)
{
/*Default*/
lv_style_copy(&def, &lv_style_plain);
def.body.opa = LV_OPA_COVER;
def.glass = 0;
def.body.empty = 0;
def.body.main_color = LV_COLOR_HEX3(0x222);
def.body.grad_color = LV_COLOR_HEX3(0x222);
def.body.radius = 0;
def.body.padding.hor = LV_DPI / 8;
def.body.padding.ver = LV_DPI / 8;
def.body.padding.inner = LV_DPI / 8;
def.body.border.color = LV_COLOR_SILVER;
def.body.border.width = 1;
def.body.border.opa = LV_OPA_COVER;
def.body.shadow.color = LV_COLOR_SILVER;
def.body.shadow.width = 0;
def.body.shadow.type = LV_SHADOW_FULL;
def.text.color = LV_COLOR_HEX3(0xDDD);
def.text.font = _font;
def.text.letter_space = 1;
def.text.line_space = 2;
def.image.color = LV_COLOR_HEX3(0xDDD);
def.image.intense = LV_OPA_TRANSP;
def.line.color = LV_COLOR_HEX3(0xDDD);
def.line.width = 1;
/*Background*/
lv_style_copy(&bg, &def);
bg.body.main_color = LV_COLOR_HEX3(0x333);
bg.body.grad_color = LV_COLOR_HEX3(0x333);
bg.body.border.width = 2;
bg.body.border.color = LV_COLOR_HEX3(0x666);
bg.body.shadow.color = LV_COLOR_SILVER;
/*Panel*/
lv_style_copy(&panel, &def);
panel.body.radius = LV_DPI / 10;
panel.body.main_color = LV_COLOR_HEX3(0x666);
panel.body.grad_color = LV_COLOR_HEX3(0x666);
panel.body.border.color = LV_COLOR_HEX3(0xccc);
panel.body.border.width = 2;
panel.body.border.opa = LV_OPA_60;
panel.text.color = lv_color_hsv_to_rgb(_hue, 8, 96);
panel.image.color = lv_color_hsv_to_rgb(_hue, 8, 96);
panel.line.color = lv_color_hsv_to_rgb(_hue, 20, 70);
/*Scrollbar*/
lv_style_copy(&sb, &def);
sb.body.opa = LV_OPA_50;
sb.body.radius = LV_RADIUS_CIRCLE;
sb.body.border.color = LV_COLOR_SILVER;
sb.body.border.opa = LV_OPA_40;
sb.body.border.width = 1;
sb.body.main_color = lv_color_hsv_to_rgb(_hue, 33, 92);
sb.body.grad_color = lv_color_hsv_to_rgb(_hue, 33, 92);
sb.body.padding.hor = 1;
sb.body.padding.ver = 1;
sb.body.padding.inner = LV_DPI / 15; /*Scrollbar width*/
theme.bg = &bg;
theme.panel = &panel;
}
static void cont_init(void)
{
#if USE_LV_CONT != 0
theme.cont = &panel;
#endif
}
static void btn_init(void)
{
#if USE_LV_BTN != 0
lv_style_copy(&btn_rel, &def);
btn_rel.glass = 0;
btn_rel.body.empty = 1;
btn_rel.body.radius = LV_RADIUS_CIRCLE;
btn_rel.body.border.width = 2;
btn_rel.body.border.color = lv_color_hsv_to_rgb(_hue, 70, 90);
btn_rel.body.border.opa = LV_OPA_80;
btn_rel.body.padding.hor = LV_DPI / 4;
btn_rel.body.padding.ver = LV_DPI / 6;
btn_rel.body.padding.inner = LV_DPI / 10;
btn_rel.text.color = lv_color_hsv_to_rgb(_hue, 8, 96);
btn_rel.text.font = _font;
btn_rel.image.color = lv_color_hsv_to_rgb(_hue, 8, 96);
lv_style_copy(&btn_pr, &btn_rel);
btn_pr.body.opa = LV_OPA_COVER;
btn_pr.body.empty = 0;
btn_pr.body.main_color = lv_color_hsv_to_rgb(_hue, 50, 50);
btn_pr.body.grad_color = lv_color_hsv_to_rgb(_hue, 50, 50);
btn_pr.body.border.opa = LV_OPA_60;
btn_pr.text.font = _font;
btn_pr.text.color = lv_color_hsv_to_rgb(_hue, 10, 100);
btn_pr.image.color = lv_color_hsv_to_rgb(_hue, 10, 100);
lv_style_copy(&btn_trel, &btn_pr);
btn_trel.body.opa = LV_OPA_COVER;
btn_trel.body.empty = 0;
btn_trel.body.main_color = lv_color_hsv_to_rgb(_hue, 50, 60);
btn_trel.body.grad_color = lv_color_hsv_to_rgb(_hue, 50, 60);
btn_trel.body.border.opa = LV_OPA_60;
btn_trel.body.border.color = lv_color_hsv_to_rgb(_hue, 80, 90);
btn_trel.text.font = _font;
btn_trel.text.color = lv_color_hsv_to_rgb(_hue, 0, 100);
btn_trel.image.color = lv_color_hsv_to_rgb(_hue, 0, 100);
lv_style_copy(&btn_tpr, &btn_trel);
btn_tpr.body.opa = LV_OPA_COVER;
btn_tpr.body.empty = 0;
btn_tpr.body.main_color = lv_color_hsv_to_rgb(_hue, 50, 50);
btn_tpr.body.grad_color = lv_color_hsv_to_rgb(_hue, 50, 50);
btn_tpr.body.border.opa = LV_OPA_60;
btn_tpr.body.border.color = lv_color_hsv_to_rgb(_hue, 80, 70);
btn_tpr.text.font = _font;
btn_tpr.text.color = lv_color_hsv_to_rgb(_hue, 10, 90);
btn_tpr.image.color = lv_color_hsv_to_rgb(_hue, 10, 90);
lv_style_copy(&btn_ina, &btn_rel);
btn_ina.body.border.opa = LV_OPA_60;
btn_ina.body.border.color = lv_color_hsv_to_rgb(_hue, 10, 50);
btn_ina.text.font = _font;
btn_ina.text.color = lv_color_hsv_to_rgb(_hue, 10, 90);
theme.btn.rel = &btn_rel;
theme.btn.pr = &btn_pr;
theme.btn.tgl_rel = &btn_trel;
theme.btn.tgl_pr = &btn_tpr;
theme.btn.ina = &btn_ina;
#endif
}
static void label_init(void)
{
#if USE_LV_LABEL != 0
static lv_style_t label_prim, label_sec, label_hint;
lv_style_copy(&label_prim, &def);
label_prim.text.font = _font;
label_prim.text.color = lv_color_hsv_to_rgb(_hue, 80, 96);
lv_style_copy(&label_sec, &label_prim);
label_sec.text.color = lv_color_hsv_to_rgb(_hue, 40, 85);
lv_style_copy(&label_hint, &label_prim);
label_hint.text.color = lv_color_hsv_to_rgb(_hue, 20, 70);
theme.label.prim = &label_prim;
theme.label.sec = &label_sec;
theme.label.hint = &label_hint;
#endif
}
static void bar_init(void)
{
#if USE_LV_BAR
lv_style_copy(&bar_bg, &def);
bar_bg.body.opa = LV_OPA_30;
bar_bg.body.radius = LV_RADIUS_CIRCLE;
bar_bg.body.main_color = LV_COLOR_WHITE;
bar_bg.body.grad_color = LV_COLOR_SILVER;
bar_bg.body.border.width = 2;
bar_bg.body.border.color = LV_COLOR_SILVER;
bar_bg.body.border.opa = LV_OPA_20;
bar_bg.body.padding.hor = 0;
bar_bg.body.padding.ver = LV_DPI / 10;
bar_bg.body.padding.inner = 0;
lv_style_copy(&bar_indic, &def);
bar_indic.body.radius = LV_RADIUS_CIRCLE;
bar_indic.body.border.width = 2;
bar_indic.body.border.color = LV_COLOR_SILVER;
bar_indic.body.border.opa = LV_OPA_70;
bar_indic.body.padding.hor = 0;
bar_indic.body.padding.ver = 0;
bar_indic.body.shadow.width = LV_DPI / 20;
bar_indic.body.shadow.color = lv_color_hsv_to_rgb(_hue, 20, 90);
bar_indic.body.main_color = lv_color_hsv_to_rgb(_hue, 40, 80);
bar_indic.body.grad_color = lv_color_hsv_to_rgb(_hue, 40, 80);
theme.bar.bg = &bar_bg;
theme.bar.indic = &bar_indic;
#endif
}
static void img_init(void)
{
#if USE_LV_IMG != 0
static lv_style_t img_light, img_dark;
lv_style_copy(&img_light, &def);
img_light.image.color = lv_color_hsv_to_rgb(_hue, 15, 85);
img_light.image.intense = LV_OPA_80;
lv_style_copy(&img_dark, &def);
img_light.image.color = lv_color_hsv_to_rgb(_hue, 85, 65);
img_light.image.intense = LV_OPA_80;
theme.img.light = &img_light;
theme.img.dark = &img_dark;
#endif
}
static void line_init(void)
{
#if USE_LV_LINE != 0
static lv_style_t line_decor;
lv_style_copy(&line_decor, &def);
line_decor.line.color = lv_color_hsv_to_rgb(_hue, 50, 50);
line_decor.line.width = 1;
theme.line.decor = &line_decor;
#endif
}
static void led_init(void)
{
#if USE_LV_LED != 0
static lv_style_t led;
lv_style_copy(&led, &lv_style_pretty_color);
led.body.shadow.width = LV_DPI / 10;
led.body.radius = LV_RADIUS_CIRCLE;
led.body.border.width = LV_DPI / 30;
led.body.border.opa = LV_OPA_30;
led.body.main_color = lv_color_hsv_to_rgb(_hue, 100, 100);
led.body.grad_color = lv_color_hsv_to_rgb(_hue, 100, 40);
led.body.border.color = lv_color_hsv_to_rgb(_hue, 60, 60);
led.body.shadow.color = lv_color_hsv_to_rgb(_hue, 100, 100);
theme.led = &led;
#endif
}
static void slider_init(void)
{
#if USE_LV_SLIDER != 0
lv_style_copy(&slider_knob, &def);
slider_knob.body.opa = LV_OPA_60;
slider_knob.body.radius = LV_RADIUS_CIRCLE;
slider_knob.body.main_color = LV_COLOR_WHITE;
slider_knob.body.grad_color = LV_COLOR_SILVER;
slider_knob.body.border.width = 1;
slider_knob.body.border.color = LV_COLOR_GRAY;
slider_knob.body.border.opa = LV_OPA_50;
theme.slider.bg = &bar_bg;
theme.slider.indic = &bar_indic;
theme.slider.knob = &slider_knob;
#endif
}
static void sw_init(void)
{
#if USE_LV_SW != 0
static lv_style_t sw_bg, sw_indic, sw_knob;
lv_style_copy(&sw_bg, &bar_bg);
sw_bg.body.opa = LV_OPA_COVER;
sw_bg.body.padding.ver = -2 ;
sw_bg.body.padding.hor = -2 ;
sw_bg.body.main_color = LV_COLOR_HEX3(0x666);
sw_bg.body.grad_color = LV_COLOR_HEX3(0x999);
sw_bg.body.border.width = 2;
sw_bg.body.border.opa = LV_OPA_50;
lv_style_copy(&sw_indic, &bar_indic);
sw_indic.body.shadow .width = LV_DPI / 20;
sw_indic.body.padding.ver = 0;
sw_indic.body.padding.hor = 0;
lv_style_copy(&sw_knob, &slider_knob);
sw_knob.body.opa = LV_OPA_80;
theme.sw.bg = &sw_bg;
theme.sw.indic = &sw_indic;
theme.sw.knob_off = &sw_knob;
theme.sw.knob_on = &sw_knob;
#endif
}
static void lmeter_init(void)
{
#if USE_LV_LMETER != 0
lv_style_copy(&lmeter_bg, &def);
lmeter_bg.body.main_color = lv_color_hsv_to_rgb(_hue, 10, 70);
lmeter_bg.body.grad_color = lv_color_hsv_to_rgb(_hue, 80, 80);
lmeter_bg.body.padding.hor = LV_DPI / 8; /*Scale line length*/
lmeter_bg.line.color = LV_COLOR_HEX3(0x222);
lmeter_bg.line.width = 2;
theme.lmeter = &lmeter_bg;
#endif
}
static void gauge_init(void)
{
#if USE_LV_GAUGE != 0
static lv_style_t gauge_bg;
lv_style_copy(&gauge_bg, &def);
gauge_bg.body.main_color = lv_color_hsv_to_rgb(_hue, 10, 70);
gauge_bg.body.grad_color = gauge_bg.body.main_color;
gauge_bg.body.padding.hor = LV_DPI / 16; /*Scale line length*/
gauge_bg.body.padding.ver = LV_DPI / 10; /*Needle center size*/
gauge_bg.body.padding.inner = LV_DPI / 12; /*Label - scale distance*/
gauge_bg.body.border.color = LV_COLOR_HEX3(0x777);
gauge_bg.line.color = lv_color_hsv_to_rgb(_hue, 80, 75);
gauge_bg.line.width = 2;
gauge_bg.text.color = lv_color_hsv_to_rgb(_hue, 10, 90);
gauge_bg.text.font = _font;
theme.gauge = &gauge_bg;
#endif
}
static void arc_init(void)
{
#if USE_LV_ARC != 0
static lv_style_t arc;
lv_style_copy(&arc, &def);
arc.line.width = 8;
arc.line.color = lv_color_hsv_to_rgb(_hue, 70, 90);
arc.line.rounded = 1;
/*For preloader*/
arc.body.border.width = 2;
arc.body.border.color = LV_COLOR_HEX3(0x555);
arc.body.padding.hor = 3;
arc.body.padding.ver = 3;
theme.arc = &arc;
#endif
}
static void preload_init(void)
{
#if USE_LV_PRELOAD != 0
theme.preload = theme.arc;
#endif
}
static void chart_init(void)
{
#if USE_LV_CHART
theme.chart = &panel;
#endif
}
static void calendar_init(void)
{
#if USE_LV_CALENDAR
static lv_style_t header;
static lv_style_t color_text;
static lv_style_t gray_text;
static lv_style_t today_box;
lv_style_copy(&header, &def);
header.body.radius = 0;
header.body.padding.hor = LV_DPI / 12;
header.body.padding.ver = LV_DPI / 14;
header.body.main_color = lv_color_hsv_to_rgb(_hue, 30, 60);
header.body.grad_color = header.body.main_color;
header.body.border.opa = panel.body.border.opa;
header.body.border.width = panel.body.border.width;
header.body.border.color = lv_color_hsv_to_rgb(_hue, 20, 80);
header.text.color = lv_color_hsv_to_rgb(_hue, 5, 100);
lv_style_copy(&today_box, &header);
today_box.body.main_color = lv_color_hsv_to_rgb(_hue, 40, 70);
today_box.body.grad_color = today_box.body.main_color;
today_box.body.empty = 1;
lv_style_copy(&color_text, &def);
color_text.text.color = lv_color_hsv_to_rgb(_hue, 30, 80);
lv_style_copy(&gray_text, &def);
gray_text.text.color = lv_color_hsv_to_rgb(_hue, 10, 65);
theme.calendar.bg = &panel;
theme.calendar.header = &header;
theme.calendar.week_box = &header;
theme.calendar.today_box = &today_box;
theme.calendar.day_names = &color_text;
theme.calendar.highlighted_days = &color_text;
theme.calendar.inactive_days = &gray_text;
#endif
}
static void cb_init(void)
{
#if USE_LV_CB != 0
static lv_style_t cb_bg, cb_rel, cb_pr, cb_trel, cb_tpr, cb_ina;
lv_style_copy(&cb_rel, &bg);
cb_rel.body.radius = LV_DPI / 20;
cb_rel.body.border.width = 1;
cb_rel.body.border.color = LV_COLOR_GRAY;
cb_rel.body.main_color = LV_COLOR_WHITE;
cb_rel.body.grad_color = LV_COLOR_SILVER;
lv_style_copy(&cb_bg, &bg);
cb_bg.body.empty = 1;
cb_bg.body.border.width = 0;
cb_bg.body.padding.inner = LV_DPI / 8;
cb_bg.body.padding.hor = 0;
cb_bg.body.padding.ver = 0;
cb_bg.text.font = _font;
lv_style_copy(&cb_pr, &cb_rel);
cb_pr.body.main_color = lv_color_hsv_to_rgb(_hue, 10, 90);
cb_pr.body.main_color = lv_color_hsv_to_rgb(_hue, 10, 82);
lv_style_copy(&cb_trel, &cb_rel);
cb_trel.body.border.width = 4;
cb_trel.body.border.color = LV_COLOR_WHITE;
cb_trel.body.border.opa = LV_OPA_60;
cb_trel.body.main_color = lv_color_hsv_to_rgb(_hue, 50, 82);
cb_trel.body.grad_color = lv_color_hsv_to_rgb(_hue, 50, 62);
lv_style_copy(&cb_tpr, &cb_trel);
cb_tpr.body.border.color = LV_COLOR_SILVER;
cb_tpr.body.border.opa = LV_OPA_70;
cb_tpr.body.main_color = lv_color_hsv_to_rgb(_hue, 50, 72);
cb_tpr.body.grad_color = lv_color_hsv_to_rgb(_hue, 50, 52);
lv_style_copy(&cb_ina, &cb_trel);
cb_ina.body.border.width = 1;
cb_ina.body.border.color = LV_COLOR_GRAY;
cb_ina.body.main_color = LV_COLOR_SILVER;
cb_ina.body.grad_color = LV_COLOR_SILVER;
theme.cb.bg = &cb_bg;
theme.cb.box.rel = &cb_rel;
theme.cb.box.pr = &cb_pr;
theme.cb.box.tgl_rel = &cb_trel;
theme.cb.box.tgl_pr = &cb_tpr;
theme.cb.box.ina = &cb_ina;
#endif
}
static void btnm_init(void)
{
#if USE_LV_BTNM
lv_style_copy(&btnm_bg, &lv_style_transp_tight);
btnm_bg.body.border.width = 1;
btnm_bg.body.border.color = lv_color_hsv_to_rgb(_hue, 60, 80);
btnm_bg.body.border.opa = LV_OPA_COVER;
btnm_bg.body.radius = LV_DPI / 8;
lv_style_copy(&btnm_rel, &lv_style_plain);
btnm_rel.body.empty = 1;
btnm_rel.body.radius = LV_DPI / 8;
btnm_rel.text.color = lv_color_hsv_to_rgb(_hue, 60, 80);
btnm_rel.text.font = _font;
lv_style_copy(&btnm_pr, &lv_style_plain);
btnm_pr.body.main_color = lv_color_hsv_to_rgb(_hue, 40, 70);
btnm_pr.body.grad_color = lv_color_hsv_to_rgb(_hue, 40, 70);
btnm_pr.body.radius = LV_DPI / 8;
btnm_pr.text.color = lv_color_hsv_to_rgb(_hue, 40, 40);
btnm_pr.text.font = _font;
lv_style_copy(&btnm_trel, &btnm_rel);
btnm_trel.body.border.color = lv_color_hsv_to_rgb(_hue, 80, 80);
btnm_trel.body.border.width = 3;
lv_style_copy(&btnm_ina, &btnm_rel);
btnm_ina.text.color = lv_color_hsv_to_rgb(_hue, 10, 60);
theme.btnm.bg = &btnm_bg;
theme.btnm.btn.rel = &btnm_rel;
theme.btnm.btn.pr = &btnm_pr;
theme.btnm.btn.tgl_rel = &btnm_trel;
theme.btnm.btn.tgl_pr = &btnm_pr;
theme.btnm.btn.ina = &btnm_ina;
#endif
}
static void kb_init(void)
{
#if USE_LV_KB
theme.kb.bg = &btnm_bg;
theme.kb.btn.rel = &btnm_rel;
theme.kb.btn.pr = &btnm_pr;
theme.kb.btn.tgl_rel = &btnm_trel;
theme.kb.btn.tgl_pr = &btnm_pr;
theme.kb.btn.ina = &btnm_ina;
#endif
}
static void mbox_init(void)
{
#if USE_LV_MBOX
static lv_style_t mbox_bg;
lv_style_copy(&mbox_bg, &panel);
mbox_bg.body.shadow.width = LV_DPI / 12;
theme.mbox.bg = &mbox_bg;
theme.mbox.btn.bg = &lv_style_transp;
theme.mbox.btn.rel = &btn_trel;
theme.mbox.btn.pr = &btn_tpr;
#endif
}
static void page_init(void)
{
#if USE_LV_PAGE
theme.page.bg = &panel;
theme.page.scrl = &lv_style_transp_fit;
theme.page.sb = &sb;
#endif
}
static void ta_init(void)
{
#if USE_LV_TA
theme.ta.area = &panel;
theme.ta.oneline = &panel;
theme.ta.cursor = NULL;
theme.ta.sb = &sb;
#endif
}
static void spinbox_init(void)
{
#if USE_LV_SPINBOX
theme.spinbox.bg= &panel;
theme.spinbox.cursor = theme.ta.cursor;
theme.spinbox.sb = theme.ta.sb;
#endif
}
static void list_init(void)
{
#if USE_LV_LIST != 0
static lv_style_t list_bg, list_rel, list_pr, list_trel, list_tpr, list_ina;
lv_style_copy(&list_rel, &def);
list_rel.body.empty = 1;
list_rel.body.border.width = 1;
list_rel.body.border.color = lv_color_hsv_to_rgb(_hue, 50, 85);
list_rel.body.border.opa = LV_OPA_COVER;
list_rel.text.color = lv_color_hsv_to_rgb(_hue, 10, 94);
list_rel.text.font = _font;
list_rel.image.color = lv_color_hsv_to_rgb(_hue, 10, 94);
lv_style_copy(&list_pr, &list_rel);
list_pr.body.empty = 0;
list_pr.body.opa = LV_OPA_COVER;
list_pr.body.main_color = lv_color_hsv_to_rgb(_hue, 34, 41);
list_pr.body.grad_color = lv_color_hsv_to_rgb(_hue, 34, 41);
list_pr.text.color = lv_color_hsv_to_rgb(_hue, 7, 96);
list_pr.image.color = lv_color_hsv_to_rgb(_hue, 7, 96);
lv_style_copy(&list_trel, &list_rel);
lv_style_copy(&list_tpr, &list_pr);
lv_style_copy(&list_ina, &def);
lv_style_copy(&list_bg, &list_rel);
list_bg.body.padding.hor = 0;
list_bg.body.padding.ver = 0;
theme.list.sb = &sb;
theme.list.bg = &list_bg;
theme.list.scrl = &lv_style_transp_tight;
theme.list.btn.rel = &list_rel;
theme.list.btn.pr = &list_pr;
theme.list.btn.tgl_rel = &list_trel;
theme.list.btn.tgl_pr = &list_tpr;
theme.list.btn.ina = &list_ina;
#endif
}
static void ddlist_init(void)
{
#if USE_LV_DDLIST != 0
lv_style_copy(&ddlist_bg, &panel);
ddlist_bg.text.line_space = LV_DPI / 8;
ddlist_bg.body.padding.hor = LV_DPI / 6;
ddlist_bg.body.padding.ver = LV_DPI / 6;
lv_style_copy(&ddlist_sel, &panel);
ddlist_sel.body.main_color = lv_color_hsv_to_rgb(_hue, 45, 70);
ddlist_sel.body.grad_color = lv_color_hsv_to_rgb(_hue, 45, 70);
ddlist_sel.body.opa = LV_OPA_COVER;
ddlist_sel.body.radius = 0;
theme.ddlist.bg = &ddlist_bg;
theme.ddlist.sel = &ddlist_sel;
theme.ddlist.sb = &sb;
#endif
}
static void roller_init(void)
{
#if USE_LV_ROLLER != 0
static lv_style_t roller_bg, roller_sel;
lv_style_copy(&roller_bg, &ddlist_bg);
roller_bg.text.line_space = LV_DPI / 6;
roller_bg.body.radius = LV_DPI / 20;
roller_bg.body.main_color = LV_COLOR_HEX3(0x222);
roller_bg.body.grad_color = LV_COLOR_HEX3(0x666);
roller_bg.body.border.opa = LV_OPA_30;
roller_bg.text.opa = LV_OPA_70;
roller_bg.text.color = lv_color_hsv_to_rgb(_hue, 20, 70);
roller_bg.body.shadow.width = 0;
lv_style_copy(&roller_sel, &panel);
roller_sel.body.empty = 1;
roller_sel.body.radius = 0;
roller_sel.text.opa = LV_OPA_COVER;
roller_sel.text.color = lv_color_hsv_to_rgb(_hue, 70, 95);
theme.roller.bg = &roller_bg;
theme.roller.sel = &roller_sel;
#endif
}
static void tabview_init(void)
{
#if USE_LV_TABVIEW != 0
static lv_style_t tab_rel, tab_pr, tab_trel, tab_tpr, tab_indic;
lv_style_copy(&tab_rel, &def);
tab_rel.body.main_color = LV_COLOR_HEX3(0x666);
tab_rel.body.grad_color = LV_COLOR_HEX3(0x666);
tab_rel.body.padding.hor = 0;
tab_rel.body.padding.ver = LV_DPI / 6;
tab_rel.body.padding.inner = 0;
tab_rel.body.border.width = 1;
tab_rel.body.border.color = LV_COLOR_SILVER;
tab_rel.body.border.opa = LV_OPA_40;
tab_rel.text.color = LV_COLOR_HEX3(0xDDD);
tab_rel.text.font = _font;
lv_style_copy(&tab_pr, &tab_rel);
tab_pr.body.main_color = LV_COLOR_HEX3(0x444);
tab_pr.body.grad_color = LV_COLOR_HEX3(0x444);
lv_style_copy(&tab_trel, &def);
tab_trel.body.empty = 1;
tab_trel.body.padding.hor = 0;
tab_trel.body.padding.ver = LV_DPI / 6;
tab_trel.body.padding.inner = 0;
tab_trel.body.border.width = 1;
tab_trel.body.border.color = LV_COLOR_SILVER;
tab_trel.body.border.opa = LV_OPA_40;
tab_trel.text.color = lv_color_hsv_to_rgb(_hue, 10, 94);
tab_trel.text.font = _font;
lv_style_copy(&tab_tpr, &def);
tab_tpr.body.main_color = LV_COLOR_GRAY;
tab_tpr.body.grad_color = LV_COLOR_GRAY;
tab_tpr.body.padding.hor = 0;
tab_tpr.body.padding.ver = LV_DPI / 6;
tab_tpr.body.padding.inner = 0;
tab_tpr.body.border.width = 1;
tab_tpr.body.border.color = LV_COLOR_SILVER;
tab_tpr.body.border.opa = LV_OPA_40;
tab_tpr.text.color = lv_color_hsv_to_rgb(_hue, 10, 94);
tab_tpr.text.font = _font;
lv_style_copy(&tab_indic, &def);
tab_indic.body.border.width = 0;
tab_indic.body.main_color = lv_color_hsv_to_rgb(_hue, 80, 87);
tab_indic.body.grad_color = lv_color_hsv_to_rgb(_hue, 80, 87);
tab_indic.body.padding.inner = LV_DPI / 10; /*Indicator height*/
theme.tabview.bg = &bg;
theme.tabview.indic = &tab_indic;
theme.tabview.btn.bg = &lv_style_transp_tight;
theme.tabview.btn.rel = &tab_rel;
theme.tabview.btn.pr = &tab_pr;
theme.tabview.btn.tgl_rel = &tab_trel;
theme.tabview.btn.tgl_pr = &tab_tpr;
#endif
}
static void tileview_init(void)
{
#if USE_LV_TILEVIEW != 0
theme.tileview.bg = &lv_style_transp_tight;
theme.tileview.scrl = &lv_style_transp_tight;
theme.tileview.sb = theme.page.sb;
#endif
}
static void table_init(void)
{
#if USE_LV_TABLE != 0
static lv_style_t cell;
lv_style_copy(&cell, &panel);
cell.body.radius = 0;
cell.body.border.width = 1;
cell.body.padding.hor = LV_DPI / 12;
cell.body.padding.ver = LV_DPI / 12;
theme.table.bg = &lv_style_transp_tight;
theme.table.cell = &cell;
#endif
}
static void win_init(void)
{
#if USE_LV_WIN != 0
static lv_style_t header;
lv_style_copy(&header, &def);
header.body.radius = 0;
header.body.padding.hor = LV_DPI / 12;
header.body.padding.ver = LV_DPI / 20;
header.body.main_color = lv_color_hsv_to_rgb(_hue, 30, 60);
header.body.grad_color = header.body.main_color;
header.body.border.opa = panel.body.border.opa;
header.body.border.width = panel.body.border.width;
header.body.border.color = lv_color_hsv_to_rgb(_hue, 20, 80);
header.body.border.part = LV_BORDER_BOTTOM;
header.text.color = lv_color_hsv_to_rgb(_hue, 5, 100);
header.image.color = lv_color_hsv_to_rgb(_hue, 5, 100);
theme.win.bg = &bg;
theme.win.sb = &sb;
theme.win.header = &header;
theme.win.content.bg = &lv_style_transp;
theme.win.content.scrl = &lv_style_transp;
theme.win.btn.rel = &btn_rel;
theme.win.btn.pr = &btn_pr;
#endif
}
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the alien theme
* @param hue [0..360] hue value from HSV color space to define the theme's base color
* @param font pointer to a font (NULL to use the default)
* @return pointer to the initialized theme
*/
lv_theme_t * lv_theme_alien_init(uint16_t hue, lv_font_t * font)
{
if(font == NULL) font = LV_FONT_DEFAULT;
_hue = hue;
_font = font;
/*For backward compatibility initialize all theme elements with a default style */
uint16_t i;
lv_style_t ** style_p = (lv_style_t **) &theme;
for(i = 0; i < sizeof(lv_theme_t) / sizeof(lv_style_t *); i++) {
*style_p = &def;
style_p++;
}
basic_init();
cont_init();
btn_init();
label_init();
bar_init();
img_init();
line_init();
led_init();
slider_init();
sw_init();
lmeter_init();
gauge_init();
arc_init();
preload_init();
chart_init();
calendar_init();
cb_init();
btnm_init();
kb_init();
mbox_init();
page_init();
ta_init();
spinbox_init();
list_init();
ddlist_init();
roller_init();
tabview_init();
tileview_init();
table_init();
win_init();
return &theme;
}
/**
* Get a pointer to the theme
* @return pointer to the theme
*/
lv_theme_t * lv_theme_get_alien(void)
{
return &theme;
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif

View File

@ -1,426 +0,0 @@
/**
* @file lv_theme_default.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_theme.h"
#if USE_LV_THEME_DEFAULT
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
static lv_theme_t theme;
static lv_style_t def;
/*Static style definitions*/
static lv_style_t sb;
static lv_style_t plain_bordered;
static lv_style_t label_prim;
static lv_style_t label_sec;
static lv_style_t label_hint;
static lv_style_t slider_bg;
static lv_style_t sw_bg;
static lv_style_t lmeter;
/*Saved input parameters*/
static uint16_t _hue;
static lv_font_t * _font;
/**********************
* MACROS
**********************/
/**********************
* STATIC FUNCTIONS
**********************/
static void basic_init(void)
{
lv_style_copy(&def, &lv_style_pretty); /*Initialize the default style*/
lv_style_copy(&sb, &lv_style_pretty_color);
sb.body.grad_color = sb.body.main_color;
sb.body.padding.hor = sb.body.padding.hor / 2; /*Make closer to the edges*/
sb.body.padding.ver = sb.body.padding.ver / 2;
lv_style_copy(&plain_bordered, &lv_style_plain);
plain_bordered.body.border.width = 2;
plain_bordered.body.border.color = LV_COLOR_HEX3(0xbbb);
theme.bg = &lv_style_plain;
theme.panel = &lv_style_pretty;
}
static void btn_init(void)
{
#if USE_LV_BTN != 0
theme.btn.rel = &lv_style_btn_rel;
theme.btn.pr = &lv_style_btn_pr;
theme.btn.tgl_rel = &lv_style_btn_tgl_rel;
theme.btn.tgl_pr = &lv_style_btn_tgl_pr;
theme.btn.ina = &lv_style_btn_ina;
#endif
}
static void label_init(void)
{
#if USE_LV_LABEL != 0
lv_style_copy(&label_prim, &lv_style_plain);
lv_style_copy(&label_sec, &lv_style_plain);
lv_style_copy(&label_hint, &lv_style_plain);
label_prim.text.color = LV_COLOR_HEX3(0x111);
label_sec.text.color = LV_COLOR_HEX3(0x888);
label_hint.text.color = LV_COLOR_HEX3(0xaaa);
theme.label.prim = &label_prim;
theme.label.sec = &label_sec;
theme.label.hint = &label_hint;
#endif
}
static void img_init(void)
{
#if USE_LV_IMG != 0
theme.img.light = &def;
theme.img.dark = &def;
#endif
}
static void line_init(void)
{
#if USE_LV_LINE != 0
theme.line.decor = &def;
#endif
}
static void led_init(void)
{
#if USE_LV_LED != 0
static lv_style_t led;
lv_style_copy(&led, &lv_style_pretty_color);
led.body.shadow.width = LV_DPI / 10;
led.body.radius = LV_RADIUS_CIRCLE;
led.body.border.width = LV_DPI / 30;
led.body.border.opa = LV_OPA_30;
led.body.shadow.color = led.body.main_color;
theme.led = &led;
#endif
}
static void bar_init(void)
{
#if USE_LV_BAR
theme.bar.bg = &lv_style_pretty;
theme.bar.indic = &lv_style_pretty_color;
#endif
}
static void slider_init(void)
{
#if USE_LV_SLIDER != 0
lv_style_copy(&slider_bg, &lv_style_pretty);
slider_bg.body.padding.hor = LV_DPI / 20;
slider_bg.body.padding.ver = LV_DPI / 20;
theme.slider.bg = &slider_bg;
theme.slider.indic = &lv_style_pretty_color;
theme.slider.knob = &lv_style_pretty;
#endif
}
static void sw_init(void)
{
#if USE_LV_SW != 0
lv_style_copy(&sw_bg, &lv_style_pretty);
sw_bg.body.padding.hor = 3;
sw_bg.body.padding.ver = 3;
theme.sw.bg = &sw_bg;
theme.sw.indic = &lv_style_pretty_color;
theme.sw.knob_off = &lv_style_pretty;
theme.sw.knob_on = &lv_style_pretty;
#endif
}
static void lmeter_init(void)
{
#if USE_LV_LMETER != 0
lv_style_copy(&lmeter, &lv_style_pretty_color);
lmeter.line.color = LV_COLOR_HEX3(0xddd);
lmeter.line.width = 2;
lmeter.body.main_color = lv_color_mix(lmeter.body.main_color, LV_COLOR_WHITE, LV_OPA_50);
lmeter.body.grad_color = lv_color_mix(lmeter.body.grad_color, LV_COLOR_BLACK, LV_OPA_50);
theme.lmeter = &lmeter;
#endif
}
static void gauge_init(void)
{
#if USE_LV_GAUGE != 0
static lv_style_t gauge;
lv_style_copy(&gauge, &lmeter);
gauge.line.color = lmeter.body.grad_color;
gauge.line.width = 2;
gauge.body.main_color = LV_COLOR_HEX3(0x888);
gauge.body.grad_color = lmeter.body.main_color;
gauge.text.color = LV_COLOR_HEX3(0x888);
theme.gauge = &gauge;
#endif
}
static void chart_init(void)
{
#if USE_LV_CHART
theme.chart = &lv_style_pretty;
#endif
}
static void cb_init(void)
{
#if USE_LV_CB != 0
theme.cb.bg = &lv_style_transp;
theme.cb.box.rel = &lv_style_pretty;
theme.cb.box.pr = &lv_style_btn_pr;
theme.cb.box.tgl_rel = &lv_style_btn_tgl_rel;
theme.cb.box.tgl_pr = &lv_style_btn_tgl_pr;
theme.cb.box.ina = &lv_style_btn_ina;
#endif
}
static void btnm_init(void)
{
#if USE_LV_BTNM
theme.btnm.bg = &lv_style_pretty;
theme.btnm.btn.rel = &lv_style_btn_rel;
theme.btnm.btn.pr = &lv_style_btn_pr;
theme.btnm.btn.tgl_rel = &lv_style_btn_tgl_rel;
theme.btnm.btn.tgl_pr = &lv_style_btn_tgl_pr;
theme.btnm.btn.ina = &lv_style_btn_ina;
#endif
}
static void kb_init(void)
{
#if USE_LV_KB
theme.kb.bg = &lv_style_pretty;
theme.kb.btn.rel = &lv_style_btn_rel;
theme.kb.btn.pr = &lv_style_btn_pr;
theme.kb.btn.tgl_rel = &lv_style_btn_tgl_rel;
theme.kb.btn.tgl_pr = &lv_style_btn_tgl_pr;
theme.kb.btn.ina = &lv_style_btn_ina;
#endif
}
static void mbox_init(void)
{
#if USE_LV_MBOX
theme.mbox.bg = &lv_style_pretty;
theme.mbox.btn.bg = &lv_style_transp;
theme.mbox.btn.rel = &lv_style_btn_rel;
theme.mbox.btn.pr = &lv_style_btn_tgl_pr;
#endif
}
static void page_init(void)
{
#if USE_LV_PAGE
theme.page.bg = &lv_style_pretty;
theme.page.scrl = &lv_style_transp_tight;
theme.page.sb = &sb;
#endif
}
static void ta_init(void)
{
#if USE_LV_TA
theme.ta.area = &lv_style_pretty;
theme.ta.oneline = &lv_style_pretty;
theme.ta.cursor = NULL;
theme.ta.sb = &sb;
#endif
}
static void list_init(void)
{
#if USE_LV_LIST != 0
theme.list.bg = &lv_style_pretty;
theme.list.scrl = &lv_style_transp_fit;
theme.list.sb = &sb;
theme.list.btn.rel = &lv_style_btn_rel;
theme.list.btn.pr = &lv_style_btn_pr;
theme.list.btn.tgl_rel = &lv_style_btn_tgl_rel;
theme.list.btn.tgl_pr = &lv_style_btn_tgl_pr;
theme.list.btn.ina = &lv_style_btn_ina;
#endif
}
static void ddlist_init(void)
{
#if USE_LV_DDLIST != 0
theme.ddlist.bg = &lv_style_pretty;
theme.ddlist.sel = &lv_style_plain_color;
theme.ddlist.sb = &sb;
#endif
}
static void roller_init(void)
{
#if USE_LV_ROLLER != 0
theme.roller.bg = &lv_style_pretty;
theme.roller.sel = &lv_style_plain_color;
#endif
}
static void tabview_init(void)
{
#if USE_LV_TABVIEW != 0
theme.tabview.bg = &plain_bordered;
theme.tabview.indic = &lv_style_plain_color;
theme.tabview.btn.bg = &lv_style_transp;
theme.tabview.btn.rel = &lv_style_btn_rel;
theme.tabview.btn.pr = &lv_style_btn_pr;
theme.tabview.btn.tgl_rel = &lv_style_btn_tgl_rel;
theme.tabview.btn.tgl_pr = &lv_style_btn_tgl_pr;
#endif
}
static void win_init(void)
{
#if USE_LV_WIN != 0
theme.win.bg = &plain_bordered;
theme.win.sb = &sb;
theme.win.header = &lv_style_plain_color;
theme.win.content.bg = &lv_style_transp;
theme.win.content.scrl = &lv_style_transp;
theme.win.btn.rel = &lv_style_btn_rel;
theme.win.btn.pr = &lv_style_btn_pr;
#endif
}
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the default theme
* @param hue [0..360] hue value from HSV color space to define the theme's base color
* @param font pointer to a font (NULL to use the default)
* @return pointer to the initialized theme
*/
lv_theme_t * lv_theme_default_init(uint16_t hue, lv_font_t * font)
{
if(font == NULL) font = LV_FONT_DEFAULT;
_hue = hue;
_font = font;
/*For backward compatibility initialize all theme elements with a default style */
uint16_t i;
lv_style_t ** style_p = (lv_style_t **) &theme;
for(i = 0; i < sizeof(lv_theme_t) / sizeof(lv_style_t *); i++) {
*style_p = &def;
style_p++;
}
basic_init();
btn_init();
label_init();
img_init();
line_init();
led_init();
bar_init();
slider_init();
sw_init();
lmeter_init();
gauge_init();
chart_init();
cb_init();
btnm_init();
kb_init();
mbox_init();
page_init();
ta_init();
list_init();
ddlist_init();
roller_init();
tabview_init();
win_init();
return &theme;
}
/**
* Get a pointer to the theme
* @return pointer to the theme
*/
lv_theme_t * lv_theme_get_default(void)
{
return &theme;
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif

View File

@ -1,863 +0,0 @@
/**
* @file lv_theme_material.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_theme.h"
#if USE_LV_THEME_MATERIAL
/*********************
* DEFINES
*********************/
#define DEF_RADIUS 4
#define DEF_SHADOW_COLOR LV_COLOR_HEX3(0xaaa)
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
static lv_theme_t theme;
static lv_style_t def;
/*Static style definitions*/
static lv_style_t sb;
/*Saved input parameters*/
static uint16_t _hue;
static lv_font_t * _font;
/**********************
* MACROS
**********************/
/**********************
* STATIC FUNCTIONS
**********************/
static void basic_init(void)
{
static lv_style_t bg, panel;
lv_style_copy(&def, &lv_style_plain); /*Initialize the default style*/
def.text.font = _font;
def.body.radius = DEF_RADIUS;
lv_style_copy(&bg, &def);
bg.body.main_color = LV_COLOR_HEX(0xf0f0f0);
bg.body.grad_color = bg.body.main_color;
bg.body.radius = 0;
lv_style_copy(&panel, &def);
panel.body.radius = DEF_RADIUS;
panel.body.main_color = LV_COLOR_WHITE;
panel.body.grad_color = LV_COLOR_WHITE;
panel.body.border.width = 1;
panel.body.border.color = LV_COLOR_HEX3(0xbbb);
panel.body.border.opa = LV_OPA_COVER;
panel.body.shadow.color = DEF_SHADOW_COLOR;
panel.body.shadow.type = LV_SHADOW_BOTTOM;
panel.body.shadow.width = 4;
panel.body.padding.hor = LV_DPI / 8;
panel.body.padding.ver = LV_DPI / 8;
panel.body.padding.inner = LV_DPI / 12;
panel.text.color = LV_COLOR_HEX3(0x333);
panel.image.color = LV_COLOR_HEX3(0x333);
lv_style_copy(&sb, &def);
sb.body.main_color = LV_COLOR_BLACK;
sb.body.grad_color = LV_COLOR_BLACK;
sb.body.opa = LV_OPA_40;
sb.body.padding.hor = LV_DPI / 25;
theme.bg = &bg;
theme.panel = &panel;
}
static void cont_init(void)
{
#if USE_LV_CONT != 0
theme.cont = theme.panel;
#endif
}
static void btn_init(void)
{
#if USE_LV_BTN != 0
static lv_style_t rel, pr, tgl_rel, tgl_pr, ina;
lv_style_copy(&rel, &def);
rel.body.main_color = lv_color_hsv_to_rgb(_hue, 90, 70);
rel.body.grad_color = rel.body.main_color;
rel.body.radius = DEF_RADIUS;
rel.body.padding.hor = LV_DPI / 6;
rel.body.padding.ver = LV_DPI / 8;
rel.body.padding.inner = LV_DPI / 10;
rel.body.shadow.color = DEF_SHADOW_COLOR;
rel.body.shadow.type = LV_SHADOW_BOTTOM;
rel.body.shadow.width = 6;
rel.text.color = lv_color_hsv_to_rgb(_hue, 5, 95);
rel.image.color = lv_color_hsv_to_rgb(_hue, 5, 95);
lv_style_copy(&pr, &rel);
pr.body.main_color = lv_color_hsv_to_rgb(_hue, 90, 60);
pr.body.grad_color = pr.body.main_color;
pr.body.shadow.width = 4;
lv_style_copy(&tgl_rel, &rel);
tgl_rel.body.main_color = lv_color_hsv_to_rgb(_hue, 95, 50);
tgl_rel.body.grad_color = tgl_rel.body.main_color;
tgl_rel.body.shadow.width = 4;
lv_style_copy(&tgl_pr, &tgl_rel);
tgl_pr.body.main_color = lv_color_hsv_to_rgb(_hue, 95, 40);
tgl_pr.body.grad_color = tgl_pr.body.main_color;
tgl_pr.body.shadow.width = 2;
lv_style_copy(&ina, &rel);
ina.body.main_color = LV_COLOR_HEX3(0xccc);
ina.body.grad_color = ina.body.main_color;
ina.body.shadow.width = 0;
ina.text.color = lv_color_hsv_to_rgb(_hue, 95, 5);
ina.image.color = lv_color_hsv_to_rgb(_hue, 95, 5);
theme.btn.rel = &rel;
theme.btn.pr = &pr;
theme.btn.tgl_rel = &tgl_rel;
theme.btn.tgl_pr = &tgl_pr;
theme.btn.ina = &ina;
#endif
}
static void label_init(void)
{
#if USE_LV_LABEL != 0
static lv_style_t prim, sec, hint;
lv_style_copy(&prim, &def);
prim.text.font = _font;
prim.text.color = lv_color_hsv_to_rgb(_hue, 80, 10);
lv_style_copy(&sec, &prim);
sec.text.color = lv_color_hsv_to_rgb(_hue, 80, 75);
lv_style_copy(&hint, &prim);
hint.text.color = lv_color_hsv_to_rgb(_hue, 40, 90);
theme.label.prim = &prim;
theme.label.sec = &sec;
theme.label.hint = &hint;
#endif
}
static void img_init(void)
{
#if USE_LV_IMG != 0
static lv_style_t img_light, img_dark;
lv_style_copy(&img_light, &def);
img_light.image.color = lv_color_hsv_to_rgb(_hue, 15, 85);
img_light.image.intense = LV_OPA_80;
lv_style_copy(&img_dark, &def);
img_light.image.color = lv_color_hsv_to_rgb(_hue, 85, 65);
img_light.image.intense = LV_OPA_80;
theme.img.light = &def;
theme.img.dark = &def;
#endif
}
static void line_init(void)
{
#if USE_LV_LINE != 0
theme.line.decor = &def;
#endif
}
static void led_init(void)
{
#if USE_LV_LED != 0
static lv_style_t led;
lv_style_copy(&led, &def);
led.body.shadow.width = LV_DPI / 10;
led.body.radius = LV_RADIUS_CIRCLE;
led.body.border.width = LV_DPI / 30;
led.body.border.opa = LV_OPA_30;
led.body.main_color = lv_color_hsv_to_rgb(_hue, 100, 100);
led.body.grad_color = lv_color_hsv_to_rgb(_hue, 100, 100);
led.body.border.color = lv_color_hsv_to_rgb(_hue, 60, 60);
led.body.shadow.color = lv_color_hsv_to_rgb(_hue, 100, 100);
theme.led = &led;
#endif
}
static void bar_init(void)
{
#if USE_LV_BAR
static lv_style_t bar_bg, bar_indic;
lv_style_copy(&bar_bg, &def);
bar_bg.body.main_color = lv_color_hsv_to_rgb(_hue, 15, 95);
bar_bg.body.grad_color = bar_bg.body.main_color;
bar_bg.body.radius = 3;
bar_bg.body.border.width = 0;
bar_bg.body.padding.hor = LV_DPI / 12;
bar_bg.body.padding.ver = LV_DPI / 12;
lv_style_copy(&bar_indic, &bar_bg);
bar_indic.body.main_color = lv_color_hsv_to_rgb(_hue, 85, 70);
bar_indic.body.grad_color = bar_indic.body.main_color;
bar_indic.body.padding.hor = 0;
bar_indic.body.padding.ver = 0;
theme.bar.bg = &bar_bg;
theme.bar.indic = &bar_indic;
#endif
}
static void slider_init(void)
{
#if USE_LV_SLIDER != 0
static lv_style_t knob;
lv_style_copy(&knob, &def);
knob.body.radius = LV_RADIUS_CIRCLE;
knob.body.border.width = 0;
knob.body.main_color = theme.bar.indic->body.main_color;
knob.body.grad_color = knob.body.main_color;
theme.slider.bg = theme.bar.bg;
theme.slider.indic = theme.bar.indic;
theme.slider.knob = &knob;
#endif
}
static void sw_init(void)
{
#if USE_LV_SW != 0
static lv_style_t sw_bg, sw_indic, sw_knob_off, sw_knob_on;
lv_style_copy(&sw_bg, theme.slider.bg);
sw_bg.body.radius = LV_RADIUS_CIRCLE;
lv_style_copy(&sw_indic, theme.slider.bg);
sw_indic.body.radius = LV_RADIUS_CIRCLE;
lv_style_copy(&sw_knob_on, theme.slider.knob);
sw_knob_on.body.shadow.width = 3;
sw_knob_on.body.shadow.type = LV_SHADOW_BOTTOM;
sw_knob_on.body.shadow.color = DEF_SHADOW_COLOR;
lv_style_copy(&sw_knob_off, &sw_knob_on);
sw_knob_off.body.main_color = LV_COLOR_HEX(0xfafafa);
sw_knob_off.body.grad_color = sw_knob_off.body.main_color;
sw_knob_off.body.border.width = 1;
sw_knob_off.body.border.color = LV_COLOR_HEX3(0x999);
sw_knob_off.body.border.opa = LV_OPA_COVER;
theme.sw.bg = &sw_bg;
theme.sw.indic = &sw_indic;
theme.sw.knob_off = &sw_knob_off;
theme.sw.knob_on = &sw_knob_on;
#endif
}
static void lmeter_init(void)
{
#if USE_LV_LMETER != 0
static lv_style_t lmeter;
lv_style_copy(&lmeter, &def);
lmeter.body.main_color = lv_color_hsv_to_rgb(_hue, 75, 90);
lmeter.body.grad_color = lmeter.body.main_color;
lmeter.body.padding.hor = LV_DPI / 10; /*Scale line length*/
lmeter.line.color = LV_COLOR_HEX3(0x999);
lmeter.line.width = 2;
theme.lmeter = &lmeter;
#endif
}
static void gauge_init(void)
{
#if USE_LV_GAUGE != 0
static lv_style_t gauge;
lv_style_copy(&gauge, &def);
gauge.body.main_color = lv_color_hsv_to_rgb(_hue, 10, 60);
gauge.body.grad_color = gauge.body.main_color;
gauge.body.padding.hor = LV_DPI / 16; /*Scale line length*/
gauge.body.padding.inner = LV_DPI / 8;
gauge.body.border.color = LV_COLOR_HEX3(0x999);
gauge.text.color = LV_COLOR_HEX3(0x333);
gauge.line.width = 3;
gauge.line.color = lv_color_hsv_to_rgb(_hue, 95, 70);
theme.gauge = &gauge;
#endif
}
static void arc_init(void)
{
#if USE_LV_ARC != 0
static lv_style_t arc;
lv_style_copy(&arc, &def);
arc.line.width = 10;
arc.line.color = lv_color_hsv_to_rgb(_hue, 90, 90);
/*For prelaoder*/
arc.body.border.width = 10;
arc.body.border.color = lv_color_hsv_to_rgb(_hue, 30, 90);
arc.body.padding.hor = 0;
arc.body.padding.ver = 0;
theme.arc = &arc;
#endif
}
static void preload_init(void)
{
#if USE_LV_PRELOAD != 0
theme.preload = theme.arc;
#endif
}
static void chart_init(void)
{
#if USE_LV_CHART
theme.chart = theme.panel;
#endif
}
static void calendar_init(void)
{
#if USE_LV_CALENDAR
static lv_style_t ina_days;
lv_style_copy(&ina_days, &def);
ina_days.text.color = lv_color_hsv_to_rgb(_hue, 0, 70);
static lv_style_t high_days;
lv_style_copy(&high_days, &def);
high_days.text.color = lv_color_hsv_to_rgb(_hue, 80, 90);
static lv_style_t week_box;
lv_style_copy(&week_box, &def);
week_box.body.main_color = lv_color_hsv_to_rgb(_hue, 40, 100);
week_box.body.grad_color = lv_color_hsv_to_rgb(_hue, 40, 100);
week_box.body.padding.ver = LV_DPI / 20;
week_box.body.padding.hor = theme.panel->body.padding.hor;
week_box.body.border.color = theme.panel->body.border.color;
week_box.body.border.width = theme.panel->body.border.width;
week_box.body.border.part = LV_BORDER_LEFT | LV_BORDER_RIGHT;
week_box.body.radius = 0;
static lv_style_t today_box;
lv_style_copy(&today_box, &def);
today_box.body.main_color = LV_COLOR_WHITE;
today_box.body.grad_color = LV_COLOR_WHITE;
today_box.body.padding.ver = LV_DPI / 20;
today_box.body.radius = 0;
theme.calendar.bg = theme.panel;
theme.calendar.header = &lv_style_transp;
theme.calendar.inactive_days = &ina_days;
theme.calendar.highlighted_days = &high_days;
theme.calendar.week_box = &week_box;
theme.calendar.today_box = &today_box;
#endif
}
static void cb_init(void)
{
#if USE_LV_CB != 0
static lv_style_t rel, pr, tgl_rel, tgl_pr, ina;
lv_style_copy(&rel, theme.panel);
rel.body.shadow.type = LV_SHADOW_BOTTOM;
rel.body.shadow.width = 3;
lv_style_copy(&pr, &rel);
pr.body.main_color = LV_COLOR_HEX3(0xccc);
pr.body.grad_color = pr.body.main_color;
pr.body.shadow.width = 0;
lv_style_copy(&tgl_rel, &rel);
tgl_rel.body.main_color = lv_color_hsv_to_rgb(_hue, 75, 85);
tgl_rel.body.grad_color = tgl_rel.body.main_color;
tgl_rel.body.shadow.type = LV_SHADOW_FULL;
tgl_rel.body.shadow.width = 0;
lv_style_copy(&tgl_pr, &tgl_rel);
tgl_pr.body.main_color = lv_color_hsv_to_rgb(_hue, 75, 65);
tgl_pr.body.grad_color = tgl_pr.body.main_color;
tgl_pr.body.shadow.width = 0;
lv_style_copy(&ina, theme.btn.ina);
theme.cb.bg = &lv_style_transp;
theme.cb.box.rel = &rel;
theme.cb.box.pr = &pr;
theme.cb.box.tgl_rel = &tgl_rel;
theme.cb.box.tgl_pr = &tgl_pr;
theme.cb.box.ina = &ina;
#endif
}
static void btnm_init(void)
{
#if USE_LV_BTNM
static lv_style_t bg, rel, pr, tgl_rel, tgl_pr, ina;
lv_style_copy(&bg, theme.panel);
bg.body.padding.hor = 0;
bg.body.padding.ver = 0;
bg.body.padding.inner = 0;
bg.text.color = LV_COLOR_HEX3(0x555);
lv_style_copy(&rel, theme.panel);
rel.body.border.part = LV_BORDER_FULL | LV_BORDER_INTERNAL;
rel.body.border.width = 1;
rel.body.border.color = LV_COLOR_HEX3(0xbbb);
rel.body.empty = 1;
rel.body.shadow.width = 0;
lv_style_copy(&pr, &rel);
pr.glass = 0;
pr.body.main_color = LV_COLOR_HEX3(0xddd);
pr.body.grad_color = pr.body.main_color;
pr.body.border.width = 0;
pr.body.empty = 0;
lv_style_copy(&tgl_rel, &pr);
tgl_rel.body.main_color = lv_color_hsv_to_rgb(_hue, 90, 70);
tgl_rel.body.grad_color = tgl_rel.body.main_color;
tgl_rel.text.color = lv_color_hsv_to_rgb(_hue, 5, 95);
lv_style_copy(&tgl_pr, &tgl_rel);
tgl_pr.body.main_color = lv_color_hsv_to_rgb(_hue, 95, 65);
tgl_pr.body.grad_color = tgl_pr.body.main_color;
tgl_pr.body.border.width = 0;
lv_style_copy(&ina, &pr);
ina.body.main_color = LV_COLOR_HEX3(0xccc);
ina.body.grad_color = ina.body.main_color;
theme.btnm.bg = &bg;
theme.btnm.btn.rel = &rel;
theme.btnm.btn.pr = &pr;
theme.btnm.btn.tgl_rel = &tgl_rel;
theme.btnm.btn.tgl_pr = &tgl_pr;
theme.btnm.btn.ina = &def;
#endif
}
static void kb_init(void)
{
#if USE_LV_KB
static lv_style_t rel;
lv_style_copy(&rel, &lv_style_transp);
rel.text.font = _font;
theme.kb.bg = theme.btnm.bg;
theme.kb.btn.rel = &rel;
theme.kb.btn.pr = theme.btnm.btn.pr;
theme.kb.btn.tgl_rel = theme.btnm.btn.tgl_rel;
theme.kb.btn.tgl_pr = theme.btnm.btn.tgl_pr;
theme.kb.btn.ina = theme.btnm.btn.ina;
#endif
}
static void mbox_init(void)
{
#if USE_LV_MBOX
static lv_style_t pr, rel;
lv_style_copy(&rel, &lv_style_transp);
rel.glass = 0;
rel.text.font = _font;
rel.text.color = lv_color_hsv_to_rgb(_hue, 85, 75);
lv_style_copy(&pr, theme.btnm.btn.pr);
pr.text.color = lv_color_hsv_to_rgb(_hue, 85, 60);
theme.mbox.bg = theme.panel;
theme.mbox.btn.bg = &lv_style_transp;
theme.mbox.btn.rel = &rel;
theme.mbox.btn.pr = &pr;
#endif
}
static void page_init(void)
{
#if USE_LV_PAGE
theme.page.bg = theme.panel;
theme.page.scrl = &lv_style_transp;
theme.page.sb = &sb;
#endif
}
static void ta_init(void)
{
#if USE_LV_TA
static lv_style_t oneline;
lv_style_copy(&oneline, &def);
oneline.body.empty = 1;
oneline.body.radius = 0;
oneline.body.border.part = LV_BORDER_BOTTOM;
oneline.body.border.width = 3;
oneline.body.border.color = LV_COLOR_HEX3(0x333);
oneline.body.border.opa = LV_OPA_COVER;
oneline.text.color = LV_COLOR_HEX3(0x333);
theme.ta.area = theme.panel;
theme.ta.oneline = &oneline;
theme.ta.cursor = NULL; /*Let library to calculate the cursor's style*/
theme.ta.sb = &sb;
#endif
}
static void spinbox_init(void)
{
#if USE_LV_SPINBOX
theme.spinbox.bg= theme.panel;
theme.spinbox.cursor = theme.ta.cursor;
theme.spinbox.sb = theme.ta.sb;
#endif
}
static void list_init(void)
{
#if USE_LV_LIST != 0
static lv_style_t list_bg, rel, pr, tgl_rel, tgl_pr, ina;
lv_style_copy(&list_bg, theme.panel);
list_bg.body.padding.hor = 0;
list_bg.body.padding.ver = 0;
list_bg.body.padding.inner = 0;
lv_style_copy(&rel, &lv_style_transp);
rel.body.padding.hor = LV_DPI / 8;
rel.body.padding.ver = LV_DPI / 6;
rel.body.radius = 10;
rel.body.border.color = LV_COLOR_HEX3(0xbbb);
rel.body.border.width = 1;
rel.body.border.part = LV_BORDER_BOTTOM;
lv_style_copy(&pr, &rel);
pr.glass = 0;
pr.body.main_color = LV_COLOR_HEX3(0xddd);
pr.body.grad_color = pr.body.main_color;
pr.body.border.width = 0;
pr.body.empty = 0;
pr.body.radius = DEF_RADIUS;
pr.text.font = _font;
lv_style_copy(&tgl_rel, &pr);
tgl_rel.body.main_color = lv_color_hsv_to_rgb(_hue, 90, 70);
tgl_rel.body.grad_color = tgl_rel.body.main_color;
tgl_rel.text.color = lv_color_hsv_to_rgb(_hue, 5, 95);
lv_style_copy(&tgl_pr, &tgl_rel);
tgl_pr.body.main_color = lv_color_hsv_to_rgb(_hue, 90, 60);
tgl_pr.body.grad_color = tgl_pr.body.main_color;
tgl_pr.body.border.width = 0;
lv_style_copy(&ina, &pr);
ina.body.main_color = LV_COLOR_HEX3(0xccc);
ina.body.grad_color = ina.body.main_color;
theme.list.sb = &sb;
theme.list.bg = &list_bg;
theme.list.scrl = &lv_style_transp_tight;
theme.list.btn.rel = &rel;
theme.list.btn.pr = &pr;
theme.list.btn.tgl_rel = &tgl_rel;
theme.list.btn.tgl_pr = &tgl_pr;
theme.list.btn.ina = &ina;
#endif
}
static void ddlist_init(void)
{
#if USE_LV_DDLIST != 0
static lv_style_t bg, sel;
lv_style_copy(&bg, theme.panel);
bg.body.padding.hor = LV_DPI / 6;
bg.body.padding.ver = LV_DPI / 6;
bg.text.line_space = LV_DPI / 8;
lv_style_copy(&sel, &bg);
sel.body.main_color = lv_color_hsv_to_rgb(_hue, 90, 70);
sel.body.grad_color = sel.body.main_color;
sel.body.border.width = 0;
sel.body.shadow.width = 0;
sel.text.color = lv_color_hsv_to_rgb(_hue, 5, 95);
theme.ddlist.bg = &bg;
theme.ddlist.sel = &sel;
theme.ddlist.sb = &sb;
#endif
}
static void roller_init(void)
{
#if USE_LV_ROLLER != 0
static lv_style_t roller_bg, roller_sel;
lv_style_copy(&roller_bg, &lv_style_transp);
roller_bg.body.padding.hor = LV_DPI / 6;
roller_bg.body.padding.ver = LV_DPI / 6;
roller_bg.text.line_space = LV_DPI / 8;
roller_bg.text.font = _font;
roller_bg.glass = 0;
lv_style_copy(&roller_sel, &roller_bg);
roller_sel.text.color = lv_color_hsv_to_rgb(_hue, 90, 70);
theme.roller.bg = &roller_bg;
theme.roller.sel = &roller_sel;
#endif
}
static void tabview_init(void)
{
#if USE_LV_TABVIEW != 0
static lv_style_t indic, btn_bg, rel, pr, tgl_rel, tgl_pr;
lv_style_copy(&indic, &def);
indic.body.main_color = lv_color_hsv_to_rgb(_hue, 90, 70);
indic.body.grad_color = indic.body.main_color;
indic.body.radius = 0;
indic.body.border.width = 0;
indic.body.padding.inner = LV_DPI / 20;
lv_style_copy(&btn_bg, &def);
btn_bg.body.main_color = LV_COLOR_HEX3(0xccc);
btn_bg.body.grad_color = btn_bg.body.main_color;
btn_bg.body.radius = 0;
btn_bg.body.border.width = 1;
btn_bg.body.border.color = LV_COLOR_HEX3(0x888);
btn_bg.body.border.part = LV_BORDER_BOTTOM;
btn_bg.body.border.opa = LV_OPA_COVER;
btn_bg.body.shadow.width = 5;
btn_bg.body.shadow.color = DEF_SHADOW_COLOR;
btn_bg.body.shadow.type = LV_SHADOW_BOTTOM;
btn_bg.body.padding.inner = 0;
btn_bg.body.padding.hor = 0;
btn_bg.body.padding.ver = 0;
btn_bg.text.color = LV_COLOR_HEX3(0x333);
lv_style_copy(&rel, &lv_style_transp);
rel.body.padding.ver = LV_DPI / 8;
rel.text.font = _font;
lv_style_copy(&pr, &def);
pr.body.main_color = LV_COLOR_HEX3(0xbbb);
pr.body.grad_color = pr.body.main_color;
pr.body.border.width = 0;
pr.body.empty = 0;
pr.body.radius = 0;
pr.body.border.width = 1;
pr.body.border.color = LV_COLOR_HEX3(0x888);
pr.body.border.part = LV_BORDER_BOTTOM;
pr.body.border.opa = LV_OPA_COVER;
pr.text.color = LV_COLOR_HEX3(0x111);
lv_style_copy(&tgl_rel, &lv_style_transp);
tgl_rel.glass = 0;
tgl_rel.text.font = _font;
tgl_rel.text.color = lv_color_hsv_to_rgb(_hue, 90, 70);
lv_style_copy(&tgl_pr, &def);
tgl_pr.body.main_color = lv_color_hsv_to_rgb(_hue, 15, 85);
tgl_pr.body.grad_color = tgl_pr.body.main_color;
tgl_pr.body.border.width = 0;
tgl_pr.body.empty = 0;
tgl_pr.body.radius = 0;
tgl_pr.text.color = lv_color_hsv_to_rgb(_hue, 90, 60);
theme.tabview.bg = theme.bg;
theme.tabview.indic = &indic;
theme.tabview.btn.bg = &btn_bg;
theme.tabview.btn.rel = &rel;
theme.tabview.btn.pr = &pr;
theme.tabview.btn.tgl_rel = &tgl_rel;
theme.tabview.btn.tgl_pr = &tgl_pr;
#endif
}
static void tileview_init(void)
{
#if USE_LV_TILEVIEW != 0
theme.tileview.bg = &lv_style_transp_tight;
theme.tileview.scrl = &lv_style_transp_tight;
theme.tileview.sb = theme.page.sb;
#endif
}
static void table_init(void)
{
#if USE_LV_TABLE != 0
static lv_style_t cell;
lv_style_copy(&cell, theme.panel);
cell.body.radius = 0;
cell.body.border.width = 1;
cell.body.padding.hor = LV_DPI / 12;
cell.body.padding.ver = LV_DPI / 12;
theme.table.bg = &lv_style_transp_tight;
theme.table.cell = &cell;
#endif
}
static void win_init(void)
{
#if USE_LV_WIN != 0
static lv_style_t header, pr;
lv_style_copy(&header, &def);
header.body.main_color = LV_COLOR_HEX3(0xccc);
header.body.grad_color = header.body.main_color;
header.body.radius = 0;
header.body.border.width = 1;
header.body.border.color = LV_COLOR_HEX3(0xbbb);
header.body.border.part = LV_BORDER_BOTTOM;
header.body.border.opa = LV_OPA_COVER;
header.body.padding.inner = 0;
header.body.padding.hor = 0;
header.body.padding.ver = 0;
header.text.color = LV_COLOR_HEX3(0x333);
header.image.color = LV_COLOR_HEX3(0x333);
lv_style_copy(&pr, &def);
pr.body.main_color = LV_COLOR_HEX3(0xbbb);
pr.body.grad_color = pr.body.main_color;
pr.body.border.width = 0;
pr.body.empty = 0;
pr.body.radius = 0;
pr.text.color = LV_COLOR_HEX3(0x111);
pr.image.color = LV_COLOR_HEX3(0x111);
theme.win.bg = theme.panel;
theme.win.sb = &sb;
theme.win.header = &header;
theme.win.content.bg = &lv_style_transp;
theme.win.content.scrl = &lv_style_transp;
theme.win.btn.rel = &lv_style_transp;
theme.win.btn.pr = &pr;
#endif
}
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the material theme
* @param hue [0..360] hue value from HSV color space to define the theme's base color
* @param font pointer to a font (NULL to use the default)
* @return pointer to the initialized theme
*/
lv_theme_t * lv_theme_material_init(uint16_t hue, lv_font_t * font)
{
if(font == NULL) font = LV_FONT_DEFAULT;
_hue = hue;
_font = font;
/*For backward compatibility initialize all theme elements with a default style */
uint16_t i;
lv_style_t ** style_p = (lv_style_t **) &theme;
for(i = 0; i < sizeof(lv_theme_t) / sizeof(lv_style_t *); i++) {
*style_p = &def;
style_p++;
}
basic_init();
cont_init();
btn_init();
label_init();
img_init();
line_init();
led_init();
bar_init();
slider_init();
sw_init();
lmeter_init();
gauge_init();
chart_init();
arc_init();
preload_init();
calendar_init();
cb_init();
btnm_init();
kb_init();
mbox_init();
page_init();
ta_init();
spinbox_init();
list_init();
ddlist_init();
roller_init();
tabview_init();
tileview_init();
table_init();
win_init();
return &theme;
}
/**
* Get a pointer to the theme
* @return pointer to the theme
*/
lv_theme_t * lv_theme_get_material(void)
{
return &theme;
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif

View File

@ -1,487 +0,0 @@
/**
* @file lv_theme_templ.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_theme.h"
#if USE_LV_THEME_MONO
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
static lv_theme_t theme;
static lv_style_t def;
/*Static style definitions*/
static lv_style_t light_plain;
static lv_style_t dark_plain;
static lv_style_t light_frame;
static lv_style_t dark_frame;
/*Saved input parameters*/
static lv_font_t * _font;
/**********************
* MACROS
**********************/
/**********************
* STATIC FUNCTIONS
**********************/
static void basic_init(void)
{
lv_style_copy(&def, &lv_style_plain); /*Initialize the default style*/
def.body.main_color = LV_COLOR_WHITE;
def.body.grad_color = LV_COLOR_WHITE;
def.body.radius = 0;
def.body.opa = LV_OPA_COVER;
def.body.padding.hor = LV_DPI / 10;
def.body.padding.ver = LV_DPI / 10;
def.body.padding.inner = LV_DPI / 10;
def.body.border.color = LV_COLOR_BLACK;
def.body.border.width = 1;
def.body.border.opa = LV_OPA_COVER;
def.body.border.part = LV_BORDER_FULL;
def.text.font = _font;
def.text.color = LV_COLOR_BLACK;
def.text.letter_space = 1;
def.text.line_space = 1;
def.line.color = LV_COLOR_BLACK;
def.line.opa = LV_OPA_COVER;
def.line.width = 1;
def.image.color = LV_COLOR_BLACK;
def.image.intense = LV_OPA_TRANSP;
def.image.opa = LV_OPA_COVER;
lv_style_copy(&light_plain, &def);
lv_style_copy(&light_frame, &light_plain);
light_frame.body.radius = LV_DPI / 20;
lv_style_copy(&dark_plain, &light_plain);
dark_plain.body.main_color = LV_COLOR_BLACK;
dark_plain.body.grad_color = LV_COLOR_BLACK;
dark_plain.body.border.color = LV_COLOR_WHITE;
dark_plain.text.color = LV_COLOR_WHITE;
dark_plain.line.color = LV_COLOR_WHITE;
dark_plain.image.color = LV_COLOR_WHITE;
lv_style_copy(&dark_frame, &dark_plain);
dark_frame.body.radius = LV_DPI / 20;
theme.bg = &def;
theme.panel = &light_frame;
}
static void cont_init(void)
{
#if USE_LV_CONT != 0
theme.cont = &def;
#endif
}
static void btn_init(void)
{
#if USE_LV_BTN != 0
theme.btn.rel = &light_frame;
theme.btn.pr = &dark_frame;
theme.btn.tgl_rel = &dark_frame;
theme.btn.tgl_pr = &light_frame;
theme.btn.ina = &light_frame;
#endif
}
static void label_init(void)
{
#if USE_LV_LABEL != 0
theme.label.prim = NULL;
theme.label.sec = NULL;
theme.label.hint = NULL;
#endif
}
static void img_init(void)
{
#if USE_LV_IMG != 0
theme.img.light = &def;
theme.img.dark = &def;
#endif
}
static void line_init(void)
{
#if USE_LV_LINE != 0
theme.line.decor = NULL;
#endif
}
static void led_init(void)
{
#if USE_LV_LED != 0
static lv_style_t led;
lv_style_copy(&led, &light_frame);
led.body.radius = LV_RADIUS_CIRCLE;
led.body.shadow.width = LV_DPI / 8;
led.body.shadow.color = LV_COLOR_BLACK;
led.body.shadow.type = LV_SHADOW_FULL;
theme.led = &led;
#endif
}
static void bar_init(void)
{
#if USE_LV_BAR
static lv_style_t bar_bg;
static lv_style_t bar_indic;
lv_style_copy(&bar_bg, &light_frame);
bar_bg.body.padding.hor = LV_DPI / 15;
bar_bg.body.padding.ver = LV_DPI / 15;
bar_bg.body.radius = LV_RADIUS_CIRCLE;
lv_style_copy(&bar_indic, &dark_frame);
bar_indic.body.padding.hor = LV_DPI / 30;
bar_indic.body.padding.ver = LV_DPI / 30;
bar_indic.body.radius = LV_RADIUS_CIRCLE;
theme.bar.bg = &bar_bg;
theme.bar.indic = &bar_indic;
#endif
}
static void slider_init(void)
{
#if USE_LV_SLIDER != 0
static lv_style_t slider_knob;
lv_style_copy(&slider_knob, &light_frame);
slider_knob.body.radius = LV_RADIUS_CIRCLE;
slider_knob.body.padding.hor = LV_DPI / 30;
slider_knob.body.padding.ver = LV_DPI / 30;
theme.slider.bg = theme.bar.bg;
theme.slider.indic = theme.bar.indic;
theme.slider.knob = &slider_knob;
#endif
}
static void sw_init(void)
{
#if USE_LV_SW != 0
theme.sw.bg = theme.slider.bg;
theme.sw.indic = theme.slider.indic;
theme.sw.knob_off = theme.slider.knob;
theme.sw.knob_on = theme.slider.knob;
#endif
}
static void lmeter_init(void)
{
#if USE_LV_LMETER != 0
static lv_style_t lmeter_bg;
lv_style_copy(&lmeter_bg, &light_frame);
lmeter_bg.body.empty = 1;
lmeter_bg.body.main_color = LV_COLOR_BLACK;
lmeter_bg.body.grad_color = LV_COLOR_BLACK;
lmeter_bg.body.padding.hor = LV_DPI / 20;
lmeter_bg.body.padding.inner = LV_DPI / 8;
lmeter_bg.line.color = LV_COLOR_WHITE;
lmeter_bg.line.width = 1;
theme.lmeter = &lmeter_bg;
#endif
}
static void gauge_init(void)
{
#if USE_LV_GAUGE != 0
static lv_style_t gauge_bg;
lv_style_copy(&gauge_bg, theme.lmeter);
gauge_bg.line.color = LV_COLOR_BLACK;
gauge_bg.line.width = 1;
theme.gauge = &gauge_bg;
#endif
}
static void chart_init(void)
{
#if USE_LV_CHART
theme.chart = &light_frame;
#endif
}
static void calendar_init(void)
{
#if USE_LV_CALENDAR
static lv_style_t box;
lv_style_copy(&box, &light_plain);
box.body.padding.ver = LV_DPI / 20;
/*Can't handle highlighted dates in this theme*/
theme.calendar.week_box = &box;
theme.calendar.today_box = &box;
#endif
}
static void cb_init(void)
{
#if USE_LV_CB != 0
theme.cb.bg = &lv_style_transp;
theme.cb.box.rel = &light_frame;
theme.cb.box.pr = &dark_frame;
theme.cb.box.tgl_rel = &dark_frame;
theme.cb.box.tgl_pr = &light_frame;
theme.cb.box.ina = &light_frame;
#endif
}
static void btnm_init(void)
{
#if USE_LV_BTNM
theme.btnm.bg = &light_frame;
theme.btnm.btn.rel = &light_frame;
theme.btnm.btn.pr = &dark_frame;
theme.btnm.btn.tgl_rel = &dark_frame;
theme.btnm.btn.tgl_pr = &light_frame;
theme.btnm.btn.ina = &light_frame;
#endif
}
static void kb_init(void)
{
#if USE_LV_KB
theme.kb.bg = &lv_style_transp_fit;
theme.kb.btn.rel = &light_frame;
theme.kb.btn.pr = &light_frame;
theme.kb.btn.tgl_rel = &dark_frame;
theme.kb.btn.tgl_pr = &dark_frame;
theme.kb.btn.ina = &light_frame;
#endif
}
static void mbox_init(void)
{
#if USE_LV_MBOX
theme.mbox.bg = &dark_frame;
theme.mbox.btn.bg = &lv_style_transp_fit;
theme.mbox.btn.rel = &light_frame;
theme.mbox.btn.pr = &dark_frame;
#endif
}
static void page_init(void)
{
#if USE_LV_PAGE
theme.page.bg = &light_frame;
theme.page.scrl = &light_frame;
theme.page.sb = &dark_frame;
#endif
}
static void ta_init(void)
{
#if USE_LV_TA
theme.ta.area = &light_frame;
theme.ta.oneline = &light_frame;
theme.ta.cursor = NULL; /*Let library to calculate the cursor's style*/
theme.ta.sb = &dark_frame;
#endif
}
static void list_init(void)
{
#if USE_LV_LIST != 0
theme.list.sb = &dark_frame;
theme.list.bg = &light_frame;
theme.list.scrl = &lv_style_transp_fit;
theme.list.btn.rel = &light_plain;
theme.list.btn.pr = &dark_plain;
theme.list.btn.tgl_rel = &dark_plain;
theme.list.btn.tgl_pr = &light_plain;
theme.list.btn.ina = &light_plain;
#endif
}
static void ddlist_init(void)
{
#if USE_LV_DDLIST != 0
static lv_style_t bg;
lv_style_copy(&bg, &light_frame);
bg.text.line_space = LV_DPI / 12;
theme.ddlist.bg = &bg;
theme.ddlist.sel = &dark_plain;
theme.ddlist.sb = &dark_frame;
#endif
}
static void roller_init(void)
{
#if USE_LV_ROLLER != 0
static lv_style_t bg;
lv_style_copy(&bg, &light_frame);
bg.text.line_space = LV_DPI / 12;
theme.roller.bg = &bg;
theme.roller.sel = &dark_frame;
#endif
}
static void tabview_init(void)
{
#if USE_LV_TABVIEW != 0
theme.tabview.bg = &light_frame;
theme.tabview.indic = &light_plain;
theme.tabview.btn.bg = &lv_style_transp_fit;
theme.tabview.btn.rel = &light_frame;
theme.tabview.btn.pr = &dark_frame;
theme.tabview.btn.tgl_rel = &dark_frame;
theme.tabview.btn.tgl_pr = &light_frame;
#endif
}
static void win_init(void)
{
#if USE_LV_WIN != 0
static lv_style_t win_header;
lv_style_copy(&win_header, &dark_plain);
win_header.body.padding.hor = LV_DPI / 30;
win_header.body.padding.ver = LV_DPI / 30;
theme.win.bg = &light_frame;
theme.win.sb = &dark_frame;
theme.win.header = &win_header;
theme.win.content.bg = &lv_style_transp;
theme.win.content.scrl = &lv_style_transp;
theme.win.btn.rel = &light_frame;
theme.win.btn.pr = &dark_frame;
#endif
}
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the mono theme
* @param hue [0..360] hue value from HSV color space to define the theme's base color; is not used in lv_theme_mono
* @param font pointer to a font (NULL to use the default)
* @return pointer to the initialized theme
*/
lv_theme_t * lv_theme_mono_init(uint16_t hue, lv_font_t * font)
{
(void)hue; /*Unused*/
if(font == NULL) font = LV_FONT_DEFAULT;
_font = font;
/*For backward compatibility initialize all theme elements with a default style */
uint16_t i;
lv_style_t ** style_p = (lv_style_t **) &theme;
for(i = 0; i < sizeof(lv_theme_t) / sizeof(lv_style_t *); i++) {
*style_p = &def;
style_p++;
}
basic_init();
cont_init();
btn_init();
label_init();
img_init();
line_init();
led_init();
bar_init();
slider_init();
sw_init();
lmeter_init();
gauge_init();
chart_init();
calendar_init();
cb_init();
btnm_init();
kb_init();
mbox_init();
page_init();
ta_init();
list_init();
ddlist_init();
roller_init();
tabview_init();
win_init();
return &theme;
}
/**
* Get a pointer to the theme
* @return pointer to the theme
*/
lv_theme_t * lv_theme_get_mono(void)
{
return &theme;
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif

View File

@ -1,856 +0,0 @@
/**
* @file lv_theme_nemo.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_theme.h"
#if USE_LV_THEME_NEMO
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
static uint16_t _hue;
static lv_font_t * _font;
static lv_font_t * _font;
static lv_font_t * _font;
static lv_theme_t theme;
static lv_style_t def;
static lv_style_t bg;
static lv_style_t panel; /*General fancy background (e.g. to chart or ta)*/
static lv_style_t sb;
static lv_style_t btn_rel, btn_pr, btn_trel, btn_tpr, btn_ina;
#if USE_LV_BAR
static lv_style_t bar_bg, bar_indic;
#endif
#if USE_LV_SLIDER
static lv_style_t slider_knob;
#endif
#if USE_LV_LMETER
static lv_style_t lmeter_bg;
#endif
#if USE_LV_DDLIST
static lv_style_t ddlist_bg, ddlist_sel;
#endif
#if USE_LV_BTNM
static lv_style_t btnm_bg, btnm_rel, btnm_pr, btnm_trel, btnm_ina;
#endif
/**********************
* MACROS
**********************/
/**********************
* STATIC FUNCTIONS
**********************/
static void basic_init(void)
{
/*Default*/
lv_style_copy(&def, &lv_style_plain);
def.body.opa = LV_OPA_COVER;
def.glass = 0;
def.body.empty = 0;
def.body.main_color = LV_COLOR_HEX3(0x222);
def.body.grad_color = LV_COLOR_HEX3(0x222);
def.body.radius = 0;
def.body.padding.hor = LV_DPI / 8;
def.body.padding.ver = LV_DPI / 8;
def.body.padding.inner = LV_DPI / 8;
def.body.border.color = LV_COLOR_SILVER;
def.body.border.width = 1;
def.body.border.opa = LV_OPA_COVER;
def.body.shadow.color = LV_COLOR_SILVER;
def.body.shadow.width = 0;
def.body.shadow.type = LV_SHADOW_FULL;
def.text.color = LV_COLOR_HEX3(0xDDD);
def.text.font = _font;
def.text.letter_space = 1;
def.text.line_space = 2;
def.image.color = LV_COLOR_HEX3(0xDDD);
def.image.intense = LV_OPA_TRANSP;
def.line.color = LV_COLOR_HEX3(0xDDD);
def.line.width = 1;
/*Background*/
lv_style_copy(&bg, &def);
bg.body.main_color = LV_COLOR_HEX3(0x005);
bg.body.grad_color = LV_COLOR_HEX3(0x045);
bg.body.border.width = 2;
bg.body.border.color = LV_COLOR_HEX3(0x666);
bg.body.shadow.color = LV_COLOR_SILVER;
/*Panel*/
lv_style_copy(&panel, &def);
panel.body.radius = LV_DPI / 10;
panel.body.main_color = LV_COLOR_HEX3(0x500);
panel.body.grad_color = LV_COLOR_HEX3(0x505);
panel.body.border.color = LV_COLOR_HEX3(0xccc);
panel.body.border.width = 2;
panel.body.border.opa = LV_OPA_60;
panel.text.color = lv_color_hsv_to_rgb(_hue, 8, 96);
panel.line.color = lv_color_hsv_to_rgb(_hue, 20, 70);
/*Scrollbar*/
lv_style_copy(&sb, &def);
sb.body.opa = LV_OPA_50;
sb.body.radius = LV_RADIUS_CIRCLE;
sb.body.border.color = LV_COLOR_SILVER;
sb.body.border.opa = LV_OPA_40;
sb.body.border.width = 1;
sb.body.main_color = lv_color_hsv_to_rgb(_hue, 33, 92);
sb.body.grad_color = lv_color_hsv_to_rgb(_hue, 33, 92);
sb.body.padding.hor = 1;
sb.body.padding.ver = 1;
sb.body.padding.inner = LV_DPI / 15; /*Scrollbar width*/
theme.bg = &bg;
theme.panel = &panel;
}
static void btn_init(void)
{
#if USE_LV_BTN != 0
lv_style_copy(&btn_rel, &def);
btn_rel.glass = 0;
btn_rel.body.empty = 1;
btn_rel.body.radius = LV_RADIUS_CIRCLE;
btn_rel.body.border.width = 2;
btn_rel.body.border.color = lv_color_hsv_to_rgb(_hue, 70, 90);
btn_rel.body.border.opa = LV_OPA_80;
btn_rel.body.padding.hor = LV_DPI / 4;
btn_rel.body.padding.ver = LV_DPI / 6;
btn_rel.body.padding.inner = LV_DPI / 10;
btn_rel.text.color = lv_color_hsv_to_rgb(_hue, 8, 96);
btn_rel.text.font = _font;
lv_style_copy(&btn_pr, &btn_rel);
btn_pr.body.opa = LV_OPA_COVER;
btn_pr.body.empty = 0;
btn_pr.body.main_color = lv_color_hsv_to_rgb(_hue, 50, 50);
btn_pr.body.grad_color = lv_color_hsv_to_rgb(_hue, 50, 50);
btn_pr.body.border.opa = LV_OPA_60;
btn_pr.text.font = _font;
btn_pr.text.color = lv_color_hsv_to_rgb(_hue, 10, 100);
lv_style_copy(&btn_trel, &btn_pr);
btn_trel.body.opa = LV_OPA_COVER;
btn_trel.body.empty = 0;
btn_trel.body.main_color = lv_color_hsv_to_rgb(_hue, 50, 60);
btn_trel.body.grad_color = lv_color_hsv_to_rgb(_hue, 50, 60);
btn_trel.body.border.opa = LV_OPA_60;
btn_trel.body.border.color = lv_color_hsv_to_rgb(_hue, 80, 90);
btn_trel.text.font = _font;
btn_trel.text.color = lv_color_hsv_to_rgb(_hue, 0, 100);
lv_style_copy(&btn_tpr, &btn_trel);
btn_tpr.body.opa = LV_OPA_COVER;
btn_tpr.body.empty = 0;
btn_tpr.body.main_color = lv_color_hsv_to_rgb(_hue, 50, 50);
btn_tpr.body.grad_color = lv_color_hsv_to_rgb(_hue, 50, 50);
btn_tpr.body.border.opa = LV_OPA_60;
btn_tpr.body.border.color = lv_color_hsv_to_rgb(_hue, 80, 70);
btn_tpr.text.font = _font;
btn_tpr.text.color = lv_color_hsv_to_rgb(_hue, 10, 90);
lv_style_copy(&btn_ina, &btn_rel);
btn_ina.body.border.opa = LV_OPA_60;
btn_ina.body.border.color = lv_color_hsv_to_rgb(_hue, 10, 50);
btn_ina.text.font = _font;
btn_ina.text.color = lv_color_hsv_to_rgb(_hue, 10, 90);
theme.btn.rel = &btn_rel;
theme.btn.pr = &btn_pr;
theme.btn.tgl_rel = &btn_trel;
theme.btn.tgl_pr = &btn_tpr;
theme.btn.ina = &btn_ina;
#endif
}
static void label_init(void)
{
#if USE_LV_LABEL != 0
static lv_style_t label_prim, label_sec, label_hint;
lv_style_copy(&label_prim, &def);
label_prim.text.font = _font;
label_prim.text.color = lv_color_hsv_to_rgb(_hue, 5, 96);
label_prim.body.empty = 1;
label_prim.body.border.width = 0;
lv_style_copy(&label_sec, &label_prim);
label_sec.text.color = lv_color_hsv_to_rgb(_hue, 40, 85);
lv_style_copy(&label_hint, &label_prim);
label_hint.text.color = lv_color_hsv_to_rgb(_hue, 20, 70);
theme.label.prim = &label_prim;
theme.label.sec = &label_sec;
theme.label.hint = &label_hint;
#endif
}
static void bar_init(void)
{
#if USE_LV_BAR
lv_style_copy(&bar_bg, &def);
bar_bg.body.opa = LV_OPA_30;
bar_bg.body.radius = LV_RADIUS_CIRCLE;
bar_bg.body.main_color = LV_COLOR_WHITE;
bar_bg.body.grad_color = LV_COLOR_SILVER;
bar_bg.body.border.width = 2;
bar_bg.body.border.color = LV_COLOR_SILVER;
bar_bg.body.border.opa = LV_OPA_20;
bar_bg.body.padding.hor = 0;
bar_bg.body.padding.ver = LV_DPI / 10;
bar_bg.body.padding.inner = 0;
lv_style_copy(&bar_indic, &def);
bar_indic.body.radius = LV_RADIUS_CIRCLE;
bar_indic.body.border.width = 2;
bar_indic.body.border.color = LV_COLOR_SILVER;
bar_indic.body.border.opa = LV_OPA_70;
bar_indic.body.padding.hor = 0;
bar_indic.body.padding.ver = 0;
bar_indic.body.shadow.width = LV_DPI / 20;
bar_indic.body.shadow.color = lv_color_hsv_to_rgb(_hue, 20, 90);
bar_indic.body.main_color = lv_color_hsv_to_rgb(_hue, 40, 80);
bar_indic.body.grad_color = lv_color_hsv_to_rgb(_hue, 40, 80);
theme.bar.bg = &bar_bg;
theme.bar.indic = &bar_indic;
#endif
}
static void img_init(void)
{
#if USE_LV_IMG != 0
static lv_style_t img_light, img_dark;
lv_style_copy(&img_light, &def);
img_light.image.color = lv_color_hsv_to_rgb(_hue, 15, 85);
img_light.image.intense = LV_OPA_80;
lv_style_copy(&img_dark, &def);
img_light.image.color = lv_color_hsv_to_rgb(_hue, 85, 65);
img_light.image.intense = LV_OPA_80;
theme.img.light = &img_light;
theme.img.dark = &img_dark;
#endif
}
static void line_init(void)
{
#if USE_LV_LINE != 0
static lv_style_t line_decor;
lv_style_copy(&line_decor, &def);
line_decor.line.color = lv_color_hsv_to_rgb(_hue, 50, 50);
line_decor.line.width = 1;
theme.line.decor = &line_decor;
#endif
}
static void led_init(void)
{
#if USE_LV_LED != 0
static lv_style_t led;
lv_style_copy(&led, &lv_style_pretty_color);
led.body.shadow.width = LV_DPI / 10;
led.body.radius = LV_RADIUS_CIRCLE;
led.body.border.width = LV_DPI / 30;
led.body.border.opa = LV_OPA_30;
led.body.main_color = lv_color_hsv_to_rgb(_hue, 100, 100);
led.body.grad_color = lv_color_hsv_to_rgb(_hue, 100, 40);
led.body.border.color = lv_color_hsv_to_rgb(_hue, 60, 60);
led.body.shadow.color = lv_color_hsv_to_rgb(_hue, 100, 100);
theme.led = &led;
#endif
}
static void slider_init(void)
{
#if USE_LV_SLIDER != 0
lv_style_copy(&slider_knob, &def);
slider_knob.body.opa = LV_OPA_60;
slider_knob.body.radius = LV_RADIUS_CIRCLE;
slider_knob.body.main_color = LV_COLOR_PURPLE;
slider_knob.body.grad_color = LV_COLOR_SILVER;
slider_knob.body.border.width = 2;
slider_knob.body.border.color = LV_COLOR_ORANGE;
slider_knob.body.border.opa = LV_OPA_50;
theme.slider.bg = &bar_bg;
theme.slider.indic = &bar_indic;
theme.slider.knob = &slider_knob;
#endif
}
static void sw_init(void)
{
#if USE_LV_SW != 0
static lv_style_t sw_bg, sw_indic, sw_knob;
lv_style_copy(&sw_bg, &bar_bg);
sw_bg.body.opa = LV_OPA_COVER;
sw_bg.body.padding.ver = -2 ;
sw_bg.body.padding.hor = -2 ;
sw_bg.body.main_color = LV_COLOR_HEX3(0x666);
sw_bg.body.grad_color = LV_COLOR_HEX3(0x999);
sw_bg.body.border.width = 2;
sw_bg.body.border.opa = LV_OPA_50;
lv_style_copy(&sw_indic, &bar_indic);
sw_indic.body.shadow .width = LV_DPI / 20;
sw_indic.body.padding.ver = 0;
sw_indic.body.padding.hor = 0;
lv_style_copy(&sw_knob, &slider_knob);
sw_knob.body.opa = LV_OPA_80;
theme.sw.bg = &sw_bg;
theme.sw.indic = &sw_indic;
theme.sw.knob_off = &sw_knob;
theme.sw.knob_on = &sw_knob;
#endif
}
static void lmeter_init(void)
{
#if USE_LV_LMETER != 0
lv_style_copy(&lmeter_bg, &def);
lmeter_bg.body.main_color = lv_color_hsv_to_rgb(_hue, 10, 70);
lmeter_bg.body.grad_color = lv_color_hsv_to_rgb(_hue, 80, 80);
lmeter_bg.body.padding.hor = LV_DPI / 8; /*Scale line length*/
lmeter_bg.line.color = LV_COLOR_HEX3(0x500);
lmeter_bg.line.width = 2;
theme.lmeter = &lmeter_bg;
#endif
}
static void gauge_init(void)
{
#if USE_LV_GAUGE != 0
static lv_style_t gauge_bg;
lv_style_copy(&gauge_bg, &def);
gauge_bg.body.main_color = lv_color_hsv_to_rgb(_hue, 20, 100);
gauge_bg.body.grad_color = gauge_bg.body.main_color;
gauge_bg.body.padding.hor = LV_DPI / 16; /*Scale line length*/
gauge_bg.body.padding.ver = LV_DPI / 20; /*Needle center size*/
gauge_bg.body.padding.inner = LV_DPI / 12; /*Label - scale distance*/
gauge_bg.body.border.color = LV_COLOR_HEX3(0x500);
gauge_bg.line.color = lv_color_hsv_to_rgb(_hue, 80, 75);
gauge_bg.line.width = 2;
gauge_bg.text.color = lv_color_hsv_to_rgb(_hue, 10, 90);
gauge_bg.text.font = _font;
theme.gauge = &gauge_bg;
#endif
}
static void arc_init(void)
{
#if USE_LV_ARC != 0
static lv_style_t arc;
lv_style_copy(&arc, &def);
arc.line.width = 10;
arc.line.color = lv_color_hsv_to_rgb(_hue, 70, 90);
arc.line.rounded = 1;
/*For preloader*/
arc.body.border.width = 0;
theme.arc = &arc;
#endif
}
static void preload_init(void)
{
#if USE_LV_PRELOAD != 0
theme.preload = theme.arc;
#endif
}
static void chart_init(void)
{
#if USE_LV_CHART
theme.chart = &panel;
#endif
}
static void calendar_init(void)
{
#if USE_LV_CALENDAR != 0
static lv_style_t ina_days;
lv_style_copy(&ina_days, &def);
ina_days.text.color = lv_color_hsv_to_rgb(_hue, 0, 50);
static lv_style_t high_days;
lv_style_copy(&high_days, &def);
high_days.text.color = lv_color_hsv_to_rgb(_hue, 50, 90);
static lv_style_t week_box;
lv_style_copy(&week_box, &def);
week_box.body.empty = 1;
week_box.body.border.color = theme.panel->body.border.color;
week_box.body.padding.ver = LV_DPI / 20;
static lv_style_t today_box;
lv_style_copy(&today_box, &def);
today_box.body.main_color = LV_COLOR_WHITE;
today_box.body.grad_color = LV_COLOR_WHITE;
today_box.body.padding.ver = LV_DPI / 20;
today_box.body.radius = 0;
theme.calendar.bg = theme.panel;
theme.calendar.header = theme.label.prim;
theme.calendar.inactive_days = theme.label.hint;
theme.calendar.highlighted_days = theme.label.sec;
theme.calendar.week_box = &week_box;
theme.calendar.today_box = &week_box;
theme.calendar.header_pr = theme.label.prim;
#endif
}
static void cb_init(void)
{
#if USE_LV_CB != 0
static lv_style_t cb_bg, cb_rel, cb_pr, cb_trel, cb_tpr, cb_ina;
lv_style_copy(&cb_rel, &bg);
cb_rel.body.radius = LV_DPI / 20;
cb_rel.body.border.width = 1;
cb_rel.body.border.color = LV_COLOR_ORANGE;
cb_rel.body.main_color = LV_COLOR_PURPLE;
cb_rel.body.grad_color = LV_COLOR_SILVER;
lv_style_copy(&cb_bg, &bg);
cb_bg.body.empty = 1;
cb_bg.body.border.width = 0;
cb_bg.body.padding.inner = LV_DPI / 8;
cb_bg.body.padding.hor = 0;
cb_bg.body.padding.ver = 0;
cb_bg.text.font = _font;
lv_style_copy(&cb_pr, &cb_rel);
cb_pr.body.main_color = lv_color_hsv_to_rgb(_hue, 10, 90);
cb_pr.body.main_color = lv_color_hsv_to_rgb(_hue, 10, 82);
lv_style_copy(&cb_trel, &cb_rel);
cb_trel.body.border.width = 4;
cb_trel.body.border.color = LV_COLOR_WHITE;
cb_trel.body.border.opa = LV_OPA_60;
cb_trel.body.main_color = lv_color_hsv_to_rgb(_hue, 50, 82);
cb_trel.body.grad_color = lv_color_hsv_to_rgb(_hue, 50, 62);
lv_style_copy(&cb_tpr, &cb_trel);
cb_tpr.body.border.color = LV_COLOR_SILVER;
cb_tpr.body.border.opa = LV_OPA_70;
cb_tpr.body.main_color = lv_color_hsv_to_rgb(_hue, 50, 72);
cb_tpr.body.grad_color = lv_color_hsv_to_rgb(_hue, 50, 52);
lv_style_copy(&cb_ina, &cb_trel);
cb_ina.body.border.width = 1;
cb_ina.body.border.color = LV_COLOR_GRAY;
cb_ina.body.main_color = LV_COLOR_PURPLE;
cb_ina.body.grad_color = LV_COLOR_SILVER;
theme.cb.bg = &cb_bg;
theme.cb.box.rel = &cb_rel;
theme.cb.box.pr = &cb_pr;
theme.cb.box.tgl_rel = &cb_trel;
theme.cb.box.tgl_pr = &cb_tpr;
theme.cb.box.ina = &cb_ina;
#endif
}
static void btnm_init(void)
{
#if USE_LV_BTNM
lv_style_copy(&btnm_bg, &lv_style_transp_tight);
btnm_bg.body.border.width = 1;
btnm_bg.body.border.color = lv_color_hsv_to_rgb(_hue, 60, 80);
btnm_bg.body.border.opa = LV_OPA_COVER;
btnm_bg.body.radius = LV_DPI / 8;
lv_style_copy(&btnm_rel, &lv_style_plain);
btnm_rel.body.empty = 1;
btnm_rel.body.radius = LV_DPI / 8;
btnm_rel.text.color = lv_color_hsv_to_rgb(_hue, 60, 80);
btnm_rel.text.font = _font;
lv_style_copy(&btnm_pr, &lv_style_plain);
btnm_pr.body.main_color = lv_color_hsv_to_rgb(_hue, 40, 70);
btnm_pr.body.grad_color = lv_color_hsv_to_rgb(_hue, 40, 70);
btnm_pr.body.radius = LV_DPI / 8;
btnm_pr.text.color = lv_color_hsv_to_rgb(_hue, 40, 40);
btnm_pr.text.font = _font;
lv_style_copy(&btnm_trel, &btnm_rel);
btnm_trel.body.border.color = lv_color_hsv_to_rgb(_hue, 80, 80);
btnm_trel.body.border.width = 3;
lv_style_copy(&btnm_ina, &btnm_rel);
btnm_ina.text.color = lv_color_hsv_to_rgb(_hue, 10, 60);
theme.btnm.bg = &btnm_bg;
theme.btnm.btn.rel = &btnm_rel;
theme.btnm.btn.pr = &btnm_pr;
theme.btnm.btn.tgl_rel = &btnm_trel;
theme.btnm.btn.tgl_pr = &btnm_pr;
theme.btnm.btn.ina = &btnm_ina;
#endif
}
static void kb_init(void)
{
#if USE_LV_KB
theme.kb.bg = &btnm_bg;
theme.kb.btn.rel = &btnm_rel;
theme.kb.btn.pr = &btnm_pr;
theme.kb.btn.tgl_rel = &btnm_trel;
theme.kb.btn.tgl_pr = &btnm_pr;
theme.kb.btn.ina = &btnm_ina;
#endif
}
static void mbox_init(void)
{
#if USE_LV_MBOX
static lv_style_t mbox_bg;
lv_style_copy(&mbox_bg, &panel);
mbox_bg.body.shadow.width = LV_DPI / 12;
theme.mbox.bg = &mbox_bg;
theme.mbox.btn.bg = &lv_style_transp;
theme.mbox.btn.rel = &btn_trel;
theme.mbox.btn.pr = &btn_tpr;
#endif
}
static void page_init(void)
{
#if USE_LV_PAGE
theme.page.bg = &panel;
theme.page.scrl = &lv_style_transp_fit;
theme.page.sb = &sb;
#endif
}
static void ta_init(void)
{
#if USE_LV_TA
theme.ta.area = &panel;
theme.ta.oneline = &panel;
theme.ta.cursor = NULL;
theme.ta.sb = &sb;
#endif
}
static void spinbox_init(void)
{
#if USE_LV_SPINBOX
theme.spinbox.bg= &panel;
theme.spinbox.cursor = theme.ta.cursor;
theme.spinbox.sb = theme.ta.sb;
#endif
}
static void list_init(void)
{
#if USE_LV_LIST != 0
static lv_style_t list_bg, list_rel, list_pr, list_trel, list_tpr, list_ina;
lv_style_copy(&list_rel, &def);
list_rel.body.empty = 1;
list_rel.body.border.width = 1;
list_rel.body.border.color = lv_color_hsv_to_rgb(_hue, 50, 85);
list_rel.body.border.opa = LV_OPA_COVER;
list_rel.text.color = lv_color_hsv_to_rgb(_hue, 10, 94);
list_rel.text.font = _font;
lv_style_copy(&list_pr, &list_rel);
list_pr.body.empty = 0;
list_pr.body.opa = LV_OPA_COVER;
list_pr.body.main_color = lv_color_hsv_to_rgb(_hue, 34, 41);
list_pr.body.grad_color = lv_color_hsv_to_rgb(_hue, 34, 41);
list_pr.text.color = lv_color_hsv_to_rgb(_hue, 7, 96);
lv_style_copy(&list_trel, &list_rel);
lv_style_copy(&list_tpr, &list_pr);
lv_style_copy(&list_ina, &def);
lv_style_copy(&list_bg, &list_rel);
list_bg.body.padding.hor = 0;
list_bg.body.padding.ver = 0;
theme.list.sb = &sb;
theme.list.bg = &list_bg;
theme.list.scrl = &lv_style_transp_tight;
theme.list.btn.rel = &list_rel;
theme.list.btn.pr = &list_pr;
theme.list.btn.tgl_rel = &list_trel;
theme.list.btn.tgl_pr = &list_tpr;
theme.list.btn.ina = &list_ina;
#endif
}
static void ddlist_init(void)
{
#if USE_LV_DDLIST != 0
lv_style_copy(&ddlist_bg, &panel);
ddlist_bg.text.line_space = LV_DPI / 8;
ddlist_bg.body.padding.hor = LV_DPI / 6;
ddlist_bg.body.padding.ver = LV_DPI / 6;
lv_style_copy(&ddlist_sel, &panel);
ddlist_sel.body.main_color = lv_color_hsv_to_rgb(_hue, 45, 70);
ddlist_sel.body.grad_color = lv_color_hsv_to_rgb(_hue, 45, 70);
ddlist_sel.body.opa = LV_OPA_COVER;
ddlist_sel.body.radius = 0;
theme.ddlist.bg = &ddlist_bg;
theme.ddlist.sel = &ddlist_sel;
theme.ddlist.sb = &sb;
#endif
}
static void roller_init(void)
{
#if USE_LV_ROLLER != 0
static lv_style_t roller_bg, roller_sel;
lv_style_copy(&roller_bg, &ddlist_bg);
roller_bg.text.line_space = LV_DPI / 6;
roller_bg.body.radius = LV_DPI / 20;
roller_bg.body.main_color = LV_COLOR_HEX3(0x500);
roller_bg.body.grad_color = LV_COLOR_HEX3(0x005);
roller_bg.body.border.opa = LV_OPA_30;
roller_bg.text.opa = LV_OPA_70;
roller_bg.text.color = lv_color_hsv_to_rgb(_hue, 20, 70);
roller_bg.body.shadow.width = 0;
lv_style_copy(&roller_sel, &panel);
roller_sel.body.empty = 1;
roller_sel.body.radius = 0;
roller_sel.text.opa = LV_OPA_COVER;
roller_sel.text.color = lv_color_hsv_to_rgb(_hue, 70, 95);
theme.roller.bg = &roller_bg;
theme.roller.sel = &roller_sel;
#endif
}
static void tabview_init(void)
{
#if USE_LV_TABVIEW != 0
static lv_style_t tab_rel, tab_pr, tab_trel, tab_tpr, tab_indic;
lv_style_copy(&tab_rel, &def);
tab_rel.body.main_color = LV_COLOR_HEX3(0x500);
tab_rel.body.grad_color = LV_COLOR_HEX3(0x005);
tab_rel.body.padding.hor = 0;
tab_rel.body.padding.ver = LV_DPI / 6;
tab_rel.body.padding.inner = 0;
tab_rel.body.border.width = 1;
tab_rel.body.border.color = LV_COLOR_SILVER;
tab_rel.body.border.opa = LV_OPA_40;
tab_rel.text.color = LV_COLOR_HEX3(0xDDD);
tab_rel.text.font = _font;
lv_style_copy(&tab_pr, &tab_rel);
tab_pr.body.main_color = LV_COLOR_HEX3(0x005);
tab_pr.body.grad_color = LV_COLOR_HEX3(0x500);
lv_style_copy(&tab_trel, &def);
tab_trel.body.empty = 1;
tab_trel.body.padding.hor = 0;
tab_trel.body.padding.ver = LV_DPI / 6;
tab_trel.body.padding.inner = 0;
tab_trel.body.border.width = 1;
tab_trel.body.border.color = LV_COLOR_SILVER;
tab_trel.body.border.opa = LV_OPA_40;
tab_trel.text.color = lv_color_hsv_to_rgb(_hue, 10, 94);
tab_trel.text.font = _font;
lv_style_copy(&tab_tpr, &def);
tab_tpr.body.main_color = LV_COLOR_GRAY;
tab_tpr.body.grad_color = LV_COLOR_GRAY;
tab_tpr.body.padding.hor = 0;
tab_tpr.body.padding.ver = LV_DPI / 6;
tab_tpr.body.padding.inner = 0;
tab_tpr.body.border.width = 1;
tab_tpr.body.border.color = LV_COLOR_SILVER;
tab_tpr.body.border.opa = LV_OPA_40;
tab_tpr.text.color = lv_color_hsv_to_rgb(_hue, 10, 94);
tab_tpr.text.font = _font;
lv_style_copy(&tab_indic, &def);
tab_indic.body.border.width = 0;
tab_indic.body.main_color = lv_color_hsv_to_rgb(_hue, 80, 87);
tab_indic.body.grad_color = lv_color_hsv_to_rgb(_hue, 80, 87);
tab_indic.body.padding.inner = LV_DPI / 10; /*Indicator height*/
theme.tabview.bg = &bg;
theme.tabview.indic = &tab_indic;
theme.tabview.btn.bg = &lv_style_transp_tight;
theme.tabview.btn.rel = &tab_rel;
theme.tabview.btn.pr = &tab_pr;
theme.tabview.btn.tgl_rel = &tab_trel;
theme.tabview.btn.tgl_pr = &tab_tpr;
#endif
}
static void tileview_init(void)
{
#if USE_LV_TILEVIEW != 0
theme.tileview.bg = &lv_style_transp_tight;
theme.tileview.scrl = &lv_style_transp_tight;
theme.tileview.sb = theme.page.sb;
#endif
}
static void table_init(void)
{
#if USE_LV_TABLE != 0
static lv_style_t cell;
lv_style_copy(&cell, &panel);
cell.body.radius = 0;
cell.body.border.width = 1;
theme.table.bg = &lv_style_transp_tight;
theme.table.cell = &cell;
#endif
}
static void win_init(void)
{
#if USE_LV_WIN != 0
static lv_style_t win_header;
lv_style_copy(&win_header, &panel);
win_header.body.radius = 0;
win_header.body.padding.hor = LV_DPI / 12;
win_header.body.padding.ver = LV_DPI / 20;
win_header.body.border.opa = panel.body.border.opa;
win_header.body.border.width = panel.body.border.width;
win_header.body.border.color = lv_color_hsv_to_rgb(_hue, 20, 80);
win_header.text.color = lv_color_hsv_to_rgb(_hue, 5, 100);
theme.win.bg = &bg;
theme.win.sb = &sb;
theme.win.header = &win_header;
theme.win.content.bg = &lv_style_transp;
theme.win.content.scrl = &lv_style_transp;
theme.win.btn.rel = &btn_rel;
theme.win.btn.pr = &btn_pr;
#endif
}
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the nemo theme
* @param hue [0..360] hue value from HSV color space to define the theme's base color
* @param font pointer to a font (NULL to use the default)
* @return pointer to the initialized theme
*/
lv_theme_t * lv_theme_nemo_init(uint16_t hue, lv_font_t * font)
{
if(font == NULL) font = LV_FONT_DEFAULT;
_hue = hue;
_font = font;
/*For backward compatibility initialize all theme elements with a default style */
uint16_t i;
lv_style_t ** style_p = (lv_style_t **) &theme;
for(i = 0; i < sizeof(lv_theme_t) / sizeof(lv_style_t *); i++) {
*style_p = &def;
style_p++;
}
basic_init();
btn_init();
label_init();
bar_init();
img_init();
line_init();
led_init();
slider_init();
sw_init();
lmeter_init();
gauge_init();
arc_init();
preload_init();
chart_init();
calendar_init();
cb_init();
btnm_init();
kb_init();
mbox_init();
page_init();
ta_init();
spinbox_init();
list_init();
ddlist_init();
roller_init();
tabview_init();
tileview_init();
table_init();
win_init();
return &theme;
}
/**
* Get a pointer to the theme
* @return pointer to the theme
*/
lv_theme_t * lv_theme_get_nemo(void)
{
return &theme;
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif

View File

@ -1,773 +0,0 @@
/**
* @file lv_theme_night.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_theme.h"
#if USE_LV_THEME_NIGHT
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
static lv_theme_t theme;
static lv_style_t def;
/*Static style definitions*/
static lv_style_t bg, sb, panel;
static lv_style_t prim, sec, hint;
static lv_style_t btn_rel, btn_pr, btn_tgl_rel, btn_tgl_pr, btn_ina;
static lv_style_t bar_bg, bar_indic;
static lv_style_t slider_knob;
static lv_style_t ddlist_bg, ddlist_sel;
static lv_style_t lmeter_bg;
/*Saved input parameters*/
static uint16_t _hue;
static lv_font_t * _font;
/**********************
* MACROS
**********************/
/**********************
* STATIC FUNCTIONS
**********************/
static void basic_init(void)
{
lv_style_copy(&def, &lv_style_pretty); /*Initialize the default style*/
def.text.font = _font;
lv_style_copy(&bg, &lv_style_plain);
bg.body.main_color = lv_color_hsv_to_rgb(_hue, 11, 30);
bg.body.grad_color = lv_color_hsv_to_rgb(_hue, 11, 30);
bg.text.color = lv_color_hsv_to_rgb(_hue, 5, 95);
bg.text.font = _font;
bg.image.color = lv_color_hsv_to_rgb(_hue, 5, 95);
lv_style_copy(&sb, &def);
sb.body.main_color = lv_color_hsv_to_rgb(_hue, 30, 60);
sb.body.grad_color = lv_color_hsv_to_rgb(_hue, 30, 60);
sb.body.border.width = 0;
sb.body.padding.inner = LV_DPI / 10;
sb.body.padding.ver = 0;
sb.body.padding.hor = 0;
sb.body.radius = LV_DPI / 30;
sb.body.opa = LV_OPA_COVER;
lv_style_copy(&panel, &bg);
panel.body.main_color = lv_color_hsv_to_rgb(_hue, 11, 18);
panel.body.grad_color = lv_color_hsv_to_rgb(_hue, 11, 18);
panel.body.radius = LV_DPI / 20;
panel.body.border.color = lv_color_hsv_to_rgb(_hue, 10, 25);
panel.body.border.width = 1;
panel.body.border.opa = LV_OPA_COVER;
panel.body.padding.ver = LV_DPI / 10;
panel.body.padding.hor = LV_DPI / 10;
panel.line.color = lv_color_hsv_to_rgb(_hue, 20, 40);
panel.line.width = 1;
theme.bg = &bg;
theme.panel = &def;
}
static void cont_init(void)
{
#if USE_LV_CONT != 0
theme.cont = &panel;
#endif
}
static void btn_init(void)
{
#if USE_LV_BTN != 0
lv_style_copy(&btn_rel, &def);
btn_rel.body.main_color = lv_color_hsv_to_rgb(_hue, 10, 40);
btn_rel.body.grad_color = lv_color_hsv_to_rgb(_hue, 10, 20);
btn_rel.body.border.color = LV_COLOR_HEX3(0x111);
btn_rel.body.border.width = 1;
btn_rel.body.border.opa = LV_OPA_70;
btn_rel.body.padding.hor = LV_DPI / 4;
btn_rel.body.padding.ver = LV_DPI / 8;
btn_rel.body.shadow.type = LV_SHADOW_BOTTOM;
btn_rel.body.shadow.color = LV_COLOR_HEX3(0x111);
btn_rel.body.shadow.width = LV_DPI / 30;
btn_rel.text.color = LV_COLOR_HEX3(0xeee);
btn_rel.image.color = LV_COLOR_HEX3(0xeee);
lv_style_copy(&btn_pr, &btn_rel);
btn_pr.body.main_color = lv_color_hsv_to_rgb(_hue, 10, 30);
btn_pr.body.grad_color = lv_color_hsv_to_rgb(_hue, 10, 10);
lv_style_copy(&btn_tgl_rel, &btn_rel);
btn_tgl_rel.body.main_color = lv_color_hsv_to_rgb(_hue, 10, 20);
btn_tgl_rel.body.grad_color = lv_color_hsv_to_rgb(_hue, 10, 40);
btn_tgl_rel.body.shadow.width = LV_DPI / 40;
btn_tgl_rel.text.color = LV_COLOR_HEX3(0xddd);
btn_tgl_rel.image.color = LV_COLOR_HEX3(0xddd);
lv_style_copy(&btn_tgl_pr, &btn_rel);
btn_tgl_pr.body.main_color = lv_color_hsv_to_rgb(_hue, 10, 10);
btn_tgl_pr.body.grad_color = lv_color_hsv_to_rgb(_hue, 10, 30);
btn_tgl_pr.body.shadow.width = LV_DPI / 30;
btn_tgl_pr.text.color = LV_COLOR_HEX3(0xddd);
btn_tgl_pr.image.color = LV_COLOR_HEX3(0xddd);
lv_style_copy(&btn_ina, &btn_rel);
btn_ina.body.main_color = lv_color_hsv_to_rgb(_hue, 10, 20);
btn_ina.body.grad_color = lv_color_hsv_to_rgb(_hue, 10, 20);
btn_ina.body.shadow.width = 0;
btn_ina.text.color = LV_COLOR_HEX3(0xaaa);
btn_ina.image.color = LV_COLOR_HEX3(0xaaa);
theme.btn.rel = &btn_rel;
theme.btn.pr = &btn_pr;
theme.btn.tgl_rel = &btn_tgl_rel;
theme.btn.tgl_pr = &btn_tgl_pr;
theme.btn.ina = &btn_ina;
#endif
}
static void label_init(void)
{
#if USE_LV_LABEL != 0
lv_style_copy(&prim, &bg);
prim.text.color = lv_color_hsv_to_rgb(_hue, 5, 95);
lv_style_copy(&sec, &bg);
sec.text.color = lv_color_hsv_to_rgb(_hue, 15, 65);
lv_style_copy(&hint, &bg);
hint.text.color = lv_color_hsv_to_rgb(_hue, 20, 55);
theme.label.prim = &prim;
theme.label.sec = &sec;
theme.label.hint = &hint;
#endif
}
static void line_init(void)
{
#if USE_LV_LINE != 0
theme.line.decor = &def;
#endif
}
static void led_init(void)
{
#if USE_LV_LED != 0
static lv_style_t led;
lv_style_copy(&led, &def);
led.body.shadow.width = LV_DPI / 10;
led.body.radius = LV_RADIUS_CIRCLE;
led.body.border.width = LV_DPI / 30;
led.body.border.opa = LV_OPA_30;
led.body.main_color = lv_color_hsv_to_rgb(_hue, 100, 100);
led.body.grad_color = lv_color_hsv_to_rgb(_hue, 100, 40);
led.body.border.color = lv_color_hsv_to_rgb(_hue, 60, 60);
led.body.shadow.color = lv_color_hsv_to_rgb(_hue, 100, 100);
theme.led = &led;
#endif
}
static void img_init(void)
{
#if USE_LV_IMG != 0
theme.img.light = &def;
theme.img.dark = &def;
#endif
}
static void bar_init(void)
{
#if USE_LV_BAR
lv_style_copy(&bar_bg, &panel);
bar_bg.body.padding.ver = LV_DPI / 16;
bar_bg.body.padding.hor = LV_DPI / 16;
bar_bg.body.radius = LV_RADIUS_CIRCLE;
lv_style_copy(&bar_indic, &def);
bar_indic.body.main_color = lv_color_hsv_to_rgb(_hue, 80, 70);
bar_indic.body.grad_color = lv_color_hsv_to_rgb(_hue, 80, 70);
bar_indic.body.border.color = lv_color_hsv_to_rgb(_hue, 20, 15);
bar_indic.body.border.width = 1;
bar_indic.body.border.opa = LV_OPA_COVER;
bar_indic.body.radius = LV_RADIUS_CIRCLE;
bar_indic.body.padding.hor = 0;
bar_indic.body.padding.ver = 0;
theme.bar.bg = &bar_bg;
theme.bar.indic = &bar_indic;
#endif
}
static void slider_init(void)
{
#if USE_LV_SLIDER != 0
lv_style_copy(&slider_knob, &btn_rel);
slider_knob.body.radius = LV_RADIUS_CIRCLE;
theme.slider.bg = &bar_bg;
theme.slider.indic = &bar_indic;
theme.slider.knob = &slider_knob;
#endif
}
static void sw_init(void)
{
#if USE_LV_SW != 0
theme.sw.bg = &bar_bg;
theme.sw.indic = &bar_indic;
theme.sw.knob_off = &slider_knob;
theme.sw.knob_on = &slider_knob;
#endif
}
static void lmeter_init(void)
{
#if USE_LV_LMETER != 0
lv_style_copy(&lmeter_bg, &def);
lmeter_bg.body.main_color = lv_color_hsv_to_rgb(_hue, 10, 70);
lmeter_bg.body.grad_color = lv_color_hsv_to_rgb(_hue, 95, 90);
lmeter_bg.body.padding.hor = LV_DPI / 10; /*Scale line length*/
lmeter_bg.body.padding.inner = LV_DPI / 10; /*Text padding*/
lmeter_bg.body.border.color = LV_COLOR_HEX3(0x333);
lmeter_bg.line.color = LV_COLOR_HEX3(0x555);
lmeter_bg.line.width = 1;
lmeter_bg.text.color = LV_COLOR_HEX3(0xddd);
theme.lmeter = &lmeter_bg;
#endif
}
static void gauge_init(void)
{
#if USE_LV_GAUGE != 0
static lv_style_t gauge_bg;
lv_style_copy(&gauge_bg, &def);
gauge_bg.body.main_color = lv_color_hsv_to_rgb(_hue, 10, 70);
gauge_bg.body.grad_color = gauge_bg.body.main_color;
gauge_bg.line.color = lv_color_hsv_to_rgb(_hue, 80, 75);
gauge_bg.line.width = 1;
gauge_bg.text.color = LV_COLOR_HEX3(0xddd);
theme.gauge = &gauge_bg;
#endif
}
static void arc_init(void)
{
#if USE_LV_ARC != 0
static lv_style_t arc;
lv_style_copy(&arc, &def);
arc.line.width = 8;
arc.line.color = lv_color_hsv_to_rgb(_hue, 80, 70);
arc.line.rounded = 1;
/*For preloader*/
arc.body.border.width = 7;
arc.body.border.color = lv_color_hsv_to_rgb(_hue, 11, 48);
arc.body.padding.hor = 1;
arc.body.padding.ver = 1;
theme.arc = &arc;
#endif
}
static void preload_init(void)
{
#if USE_LV_PRELOAD != 0
theme.preload = theme.arc;
#endif
}
static void chart_init(void)
{
#if USE_LV_CHART
theme.chart = &panel;
#endif
}
static void calendar_init(void)
{
#if USE_LV_CALENDAR
static lv_style_t cal_bg;
lv_style_copy(&cal_bg, &bg);
cal_bg.body.main_color = lv_color_hsv_to_rgb(_hue, 10, 40);
cal_bg.body.grad_color = lv_color_hsv_to_rgb(_hue, 10, 40);
cal_bg.body.border.color = LV_COLOR_HEX3(0x333);
cal_bg.body.border.width = 1;
cal_bg.body.radius = LV_DPI / 20;
cal_bg.body.padding.hor = LV_DPI / 10;
cal_bg.body.padding.ver = LV_DPI / 10;
static lv_style_t cal_header;
lv_style_copy(&cal_header, &bg);
cal_header.body.main_color = lv_color_hsv_to_rgb(_hue, 10, 20);
cal_header.body.grad_color = lv_color_hsv_to_rgb(_hue, 10, 20);
cal_header.body.radius = 0;
cal_header.body.border.width = 1;
cal_header.body.border.color = LV_COLOR_HEX3(0x333);
cal_header.body.padding.hor = LV_DPI / 10;
cal_header.body.padding.ver = LV_DPI / 10;
static lv_style_t week_box;
lv_style_copy(&week_box, &panel);
week_box.body.main_color = lv_color_hsv_to_rgb(_hue, 30, 45);
week_box.body.grad_color = lv_color_hsv_to_rgb(_hue, 30, 45);
week_box.body.radius = LV_DPI / 20;
week_box.body.border.width = 1;
week_box.body.padding.hor = LV_DPI / 20;
week_box.body.padding.ver = LV_DPI / 25;
static lv_style_t today_box;
lv_style_copy(&today_box, &week_box);
today_box.body.main_color = lv_color_hsv_to_rgb(_hue, 80, 70);
today_box.body.grad_color = lv_color_hsv_to_rgb(_hue, 80, 70);
today_box.body.radius = LV_DPI / 20;
today_box.body.padding.hor = LV_DPI / 14;
today_box.body.padding.ver = LV_DPI / 14;
static lv_style_t highlighted_days;
lv_style_copy(&highlighted_days, &bg);
highlighted_days.text.color = lv_color_hsv_to_rgb(_hue, 40, 80);
static lv_style_t ina_days;
lv_style_copy(&ina_days, &bg);
ina_days.text.color = lv_color_hsv_to_rgb(_hue, 0, 60);
theme.calendar.bg = &cal_bg;
theme.calendar.header = &cal_header;
theme.calendar.week_box = &week_box;
theme.calendar.today_box = &today_box;
theme.calendar.highlighted_days = &highlighted_days;
theme.calendar.day_names = &cal_bg;
theme.calendar.inactive_days = &ina_days;
#endif
}
static void cb_init(void)
{
#if USE_LV_CB != 0
static lv_style_t rel, pr, tgl_rel, tgl_pr, ina;
lv_style_copy(&rel, &def);
rel.body.radius = LV_DPI / 20;
rel.body.main_color = lv_color_hsv_to_rgb(_hue, 10, 95);
rel.body.grad_color = lv_color_hsv_to_rgb(_hue, 10, 95);
rel.body.border.color = lv_color_hsv_to_rgb(_hue, 10, 50);
rel.body.border.width = 2;;
lv_style_copy(&pr, &rel);
pr.body.main_color = lv_color_hsv_to_rgb(_hue, 10, 80);
pr.body.grad_color = lv_color_hsv_to_rgb(_hue, 10, 80);
pr.body.border.color = lv_color_hsv_to_rgb(_hue, 10, 20);
pr.body.border.width = 1;;
lv_style_copy(&tgl_rel, &rel);
tgl_rel.body.main_color = lv_color_hsv_to_rgb(_hue, 80, 90);
tgl_rel.body.grad_color = lv_color_hsv_to_rgb(_hue, 80, 90);
tgl_rel.body.border.color = lv_color_hsv_to_rgb(_hue, 80, 50);
lv_style_copy(&tgl_pr, &tgl_rel);
tgl_pr.body.main_color = lv_color_hsv_to_rgb(_hue, 80, 70);
tgl_pr.body.grad_color = lv_color_hsv_to_rgb(_hue, 80, 70);
tgl_pr.body.border.color = lv_color_hsv_to_rgb(_hue, 80, 30);
tgl_pr.body.border.width = 1;;
lv_style_copy(&ina, &rel);
ina.body.main_color = LV_COLOR_HEX3(0x777);
ina.body.grad_color = LV_COLOR_HEX3(0x777);
ina.body.border.width = 0;
theme.cb.bg = &lv_style_transp;
theme.cb.box.rel = &rel;
theme.cb.box.pr = &pr;
theme.cb.box.tgl_rel = &tgl_rel;
theme.cb.box.tgl_pr = &tgl_pr;
theme.cb.box.ina = &def;
#endif
}
static void btnm_init(void)
{
#if USE_LV_BTNM
static lv_style_t btnm_bg, rel, pr, tgl_rel, tgl_pr, ina;
lv_style_copy(&btnm_bg, &btn_rel);
btnm_bg.body.padding.hor = 2;
btnm_bg.body.padding.ver = 2;
btnm_bg.body.padding.inner = 0;
btnm_bg.body.border.width = 1;
lv_style_copy(&rel, &btn_rel);
rel.body.border.part = LV_BORDER_FULL | LV_BORDER_INTERNAL;
rel.body.border.width = 1;
rel.body.radius = 2;
lv_style_copy(&pr, &btn_pr);
pr.body.border.part = rel.body.border.part;
pr.body.border.width = rel.body.border.width;
pr.body.radius = rel.body.radius;
lv_style_copy(&tgl_rel, &btn_tgl_rel);
tgl_rel.body.border.part = rel.body.border.part;
tgl_rel.body.border.width = rel.body.border.width;
tgl_rel.body.radius = rel.body.radius;
lv_style_copy(&tgl_pr, &btn_tgl_pr);
tgl_pr.body.border.part = rel.body.border.part;
tgl_pr.body.border.width = rel.body.border.width;
tgl_pr.body.radius = rel.body.radius;
lv_style_copy(&ina, &btn_ina);
ina.body.border.part = rel.body.border.part;
ina.body.border.width = rel.body.border.width;
ina.body.radius = rel.body.radius;
theme.btnm.bg = &btnm_bg;
theme.btnm.btn.rel = &rel;
theme.btnm.btn.pr = &pr;
theme.btnm.btn.tgl_rel = &tgl_rel;
theme.btnm.btn.tgl_pr = &tgl_pr;
theme.btnm.btn.ina = &ina;
#endif
}
static void kb_init(void)
{
#if USE_LV_KB
theme.kb.bg = &bg;
theme.kb.btn.rel = &btn_rel;
theme.kb.btn.pr = &btn_pr;
theme.kb.btn.tgl_rel = &btn_tgl_rel;
theme.kb.btn.tgl_pr = &btn_tgl_pr;
theme.kb.btn.ina = &btn_ina;
#endif
}
static void mbox_init(void)
{
#if USE_LV_MBOX
static lv_style_t mbox_bg;
lv_style_copy(&mbox_bg, &bg);
mbox_bg.body.main_color = lv_color_hsv_to_rgb(_hue, 30, 30);
mbox_bg.body.grad_color = lv_color_hsv_to_rgb(_hue, 30, 30);
mbox_bg.body.border.color = lv_color_hsv_to_rgb(_hue, 11, 20);
mbox_bg.body.border.width = 1;
mbox_bg.body.shadow.width = LV_DPI / 10;
mbox_bg.body.shadow.color = LV_COLOR_HEX3(0x222);
mbox_bg.body.radius = LV_DPI / 20;
theme.mbox.bg = &mbox_bg;
theme.mbox.btn.bg = &lv_style_transp;
theme.mbox.btn.rel = &btn_rel;
theme.mbox.btn.pr = &btn_pr;
#endif
}
static void page_init(void)
{
#if USE_LV_PAGE
static lv_style_t page_scrl;
lv_style_copy(&page_scrl, &bg);
page_scrl.body.main_color = lv_color_hsv_to_rgb(_hue, 10, 40);
page_scrl.body.grad_color = lv_color_hsv_to_rgb(_hue, 10, 40);
page_scrl.body.border.color = LV_COLOR_HEX3(0x333);
page_scrl.body.border.width = 1;
page_scrl.body.radius = LV_DPI / 20;
theme.page.bg = &panel;
theme.page.scrl = &page_scrl;
theme.page.sb = &sb;
#endif
}
static void ta_init(void)
{
#if USE_LV_TA
theme.ta.area = &panel;
theme.ta.oneline = &panel;
theme.ta.cursor = NULL;
theme.ta.sb = &def;
#endif
}
static void spinbox_init(void)
{
#if USE_LV_SPINBOX
theme.spinbox.bg= &panel;
theme.spinbox.cursor = theme.ta.cursor;
theme.spinbox.sb = theme.ta.sb;
#endif
}
static void list_init(void)
{
#if USE_LV_LIST != 0
static lv_style_t list_bg, list_btn_rel, list_btn_pr, list_btn_tgl_rel, list_btn_tgl_pr;
lv_style_copy(&list_bg, &panel);
list_bg.body.padding.ver = 0;
list_bg.body.padding.hor = 0;
list_bg.body.padding.inner = 0;
lv_style_copy(&list_btn_rel, &bg);
list_btn_rel.body.empty = 1;
list_btn_rel.body.border.part = LV_BORDER_BOTTOM;
list_btn_rel.body.border.color = lv_color_hsv_to_rgb(_hue, 10, 5);
list_btn_rel.body.border.width = 1;
list_btn_rel.body.radius = LV_DPI / 10;
list_btn_rel.text.color = lv_color_hsv_to_rgb(_hue, 5, 80);
list_btn_rel.image.color = lv_color_hsv_to_rgb(_hue, 5, 80);
list_btn_rel.body.padding.ver = LV_DPI / 6;
list_btn_rel.body.padding.hor = LV_DPI / 8;
lv_style_copy(&list_btn_pr, &btn_pr);
list_btn_pr.body.main_color = btn_pr.body.grad_color;
list_btn_pr.body.grad_color = btn_pr.body.main_color;
list_btn_pr.body.border.color = lv_color_hsv_to_rgb(_hue, 10, 5);
list_btn_pr.body.border.width = 0;
list_btn_pr.body.padding.ver = LV_DPI / 6;
list_btn_pr.body.padding.hor = LV_DPI / 8;
list_btn_pr.text.color = lv_color_hsv_to_rgb(_hue, 5, 80);
list_btn_pr.image.color = lv_color_hsv_to_rgb(_hue, 5, 80);
lv_style_copy(&list_btn_tgl_rel, &list_btn_rel);
list_btn_tgl_rel.body.empty = 0;
list_btn_tgl_rel.body.main_color = lv_color_hsv_to_rgb(_hue, 10, 8);
list_btn_tgl_rel.body.grad_color = lv_color_hsv_to_rgb(_hue, 10, 8);
lv_style_copy(&list_btn_tgl_pr, &list_btn_tgl_rel);
list_btn_tgl_pr.body.main_color = btn_tgl_pr.body.main_color;
list_btn_tgl_pr.body.grad_color = btn_tgl_pr.body.grad_color;
theme.list.sb = &sb;
theme.list.bg = &list_bg;
theme.list.scrl = &lv_style_transp_tight;
theme.list.btn.rel = &list_btn_rel;
theme.list.btn.pr = &list_btn_pr;
theme.list.btn.tgl_rel = &list_btn_tgl_rel;
theme.list.btn.tgl_pr = &list_btn_tgl_pr;
theme.list.btn.ina = &def;
#endif
}
static void ddlist_init(void)
{
#if USE_LV_DDLIST != 0
lv_style_copy(&ddlist_bg, &btn_rel);
ddlist_bg.text.line_space = LV_DPI / 8;
ddlist_bg.body.padding.ver = LV_DPI / 8;
ddlist_bg.body.padding.hor = LV_DPI / 8;
ddlist_bg.body.radius = LV_DPI / 30;
lv_style_copy(&ddlist_sel, &btn_rel);
ddlist_sel.body.main_color = lv_color_hsv_to_rgb(_hue, 20, 50);
ddlist_sel.body.grad_color = lv_color_hsv_to_rgb(_hue, 20, 50);
ddlist_sel.body.radius = 0;
theme.ddlist.bg = &ddlist_bg;
theme.ddlist.sel = &ddlist_sel;
theme.ddlist.sb = &def;
#endif
}
static void roller_init(void)
{
#if USE_LV_ROLLER != 0
static lv_style_t roller_bg;
lv_style_copy(&roller_bg, &ddlist_bg);
roller_bg.body.main_color = lv_color_hsv_to_rgb(_hue, 10, 20);
roller_bg.body.grad_color = lv_color_hsv_to_rgb(_hue, 10, 40);
roller_bg.text.color = lv_color_hsv_to_rgb(_hue, 5, 70);
roller_bg.text.opa = LV_OPA_60;
theme.roller.bg = &roller_bg;
theme.roller.sel = &ddlist_sel;
#endif
}
static void tabview_init(void)
{
#if USE_LV_TABVIEW != 0
theme.tabview.bg = &bg;
theme.tabview.indic = &lv_style_transp;
theme.tabview.btn.bg = &lv_style_transp;
theme.tabview.btn.rel = &btn_rel;
theme.tabview.btn.pr = &btn_pr;
theme.tabview.btn.tgl_rel = &btn_tgl_rel;
theme.tabview.btn.tgl_pr = &btn_tgl_pr;
#endif
}
static void tileview_init(void)
{
#if USE_LV_TILEVIEW != 0
theme.tileview.bg = &lv_style_transp_tight;
theme.tileview.scrl = &lv_style_transp_tight;
theme.tileview.sb = theme.page.sb;
#endif
}
static void table_init(void)
{
#if USE_LV_TABLE != 0
static lv_style_t cell;
lv_style_copy(&cell, &panel);
cell.body.radius = 0;
cell.body.border.width = 1;
cell.body.padding.hor = LV_DPI / 12;
cell.body.padding.ver = LV_DPI / 12;
theme.table.bg = &lv_style_transp_tight;
theme.table.cell = &cell;
#endif
}
static void win_init(void)
{
#if USE_LV_WIN != 0
static lv_style_t win_bg;
lv_style_copy(&win_bg, &bg);
win_bg.body.border.color = LV_COLOR_HEX3(0x333);
win_bg.body.border.width = 1;
static lv_style_t win_header;
lv_style_copy(&win_header, &win_bg);
win_header.body.main_color = lv_color_hsv_to_rgb(_hue, 10, 20);
win_header.body.grad_color = lv_color_hsv_to_rgb(_hue, 10, 20);
win_header.body.radius = 0;
win_header.body.padding.hor = 0;
win_header.body.padding.ver = 0;
win_header.body.padding.ver = 0;
static lv_style_t win_btn_pr;
lv_style_copy(&win_btn_pr, &def);
win_btn_pr.body.main_color = lv_color_hsv_to_rgb(_hue, 10, 10);
win_btn_pr.body.grad_color = lv_color_hsv_to_rgb(_hue, 10, 10);
win_btn_pr.text.color = LV_COLOR_HEX3(0xaaa);
win_btn_pr.image.color = LV_COLOR_HEX3(0xaaa);
theme.win.bg = &win_bg;
theme.win.sb = &sb;
theme.win.header = &win_header;
theme.win.content.bg = &lv_style_transp;
theme.win.content.scrl = &lv_style_transp;
theme.win.btn.rel = &lv_style_transp;
theme.win.btn.pr = &win_btn_pr;
#endif
}
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the night theme
* @param hue [0..360] hue value from HSV color space to define the theme's base color
* @param font pointer to a font (NULL to use the default)
* @return pointer to the initialized theme
*/
lv_theme_t * lv_theme_night_init(uint16_t hue, lv_font_t * font)
{
if(font == NULL) font = LV_FONT_DEFAULT;
_hue = hue;
_font = font;
/*For backward compatibility initialize all theme elements with a default style */
uint16_t i;
lv_style_t ** style_p = (lv_style_t **) &theme;
for(i = 0; i < sizeof(lv_theme_t) / sizeof(lv_style_t *); i++) {
*style_p = &def;
style_p++;
}
basic_init();
cont_init();
btn_init();
label_init();
img_init();
line_init();
led_init();
bar_init();
slider_init();
sw_init();
lmeter_init();
gauge_init();
arc_init();
preload_init();
chart_init();
calendar_init();
cb_init();
btnm_init();
kb_init();
mbox_init();
page_init();
ta_init();
spinbox_init();
list_init();
ddlist_init();
roller_init();
tabview_init();
tileview_init();
table_init();
win_init();
return &theme;
}
/**
* Get a pointer to the theme
* @return pointer to the theme
*/
lv_theme_t * lv_theme_get_night(void)
{
return &theme;
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif

View File

@ -1,439 +0,0 @@
/**
* @file lv_theme_templ.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_theme.h"
#if USE_LV_THEME_TEMPL
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
static lv_theme_t theme;
static lv_style_t def;
/*Static style definitions*/
/*Saved input parameters*/
static uint16_t _hue;
static lv_font_t * _font;
/**********************
* MACROS
**********************/
/**********************
* STATIC FUNCTIONS
**********************/
static void basic_init(void)
{
lv_style_copy(&def, &lv_style_pretty); /*Initialize the default style*/
def.text.font = _font;
theme.bg = &def;
theme.panel = &def;
}
static void cont_init(void)
{
#if USE_LV_CONT != 0
theme.cont = &def;
#endif
}
static void btn_init(void)
{
#if USE_LV_BTN != 0
theme.btn.rel = &def;
theme.btn.pr = &def;
theme.btn.tgl_rel = &def;
theme.btn.tgl_pr = &def;
theme.btn.ina = &def;
#endif
}
static void imgbtn_init(void)
{
#if USE_LV_IMGBTN != 0
theme.imgbtn.rel = &def;
theme.imgbtn.pr = &def;
theme.imgbtn.tgl_rel = &def;
theme.imgbtn.tgl_pr = &def;
theme.imgbtn.ina = &def;
#endif
}
static void label_init(void)
{
#if USE_LV_LABEL != 0
theme.label.prim = &def;
theme.label.sec = &def;
theme.label.hint = &def;
#endif
}
static void img_init(void)
{
#if USE_LV_IMG != 0
theme.img.light = &def;
theme.img.dark = &def;
#endif
}
static void line_init(void)
{
#if USE_LV_LINE != 0
theme.line.decor = &def;
#endif
}
static void led_init(void)
{
#if USE_LV_LED != 0
theme.led = &def;
#endif
}
static void bar_init(void)
{
#if USE_LV_BAR
theme.bar.bg = &def;
theme.bar.indic = &def;
#endif
}
static void slider_init(void)
{
#if USE_LV_SLIDER != 0
theme.slider.bg = &def;
theme.slider.indic = &def;
theme.slider.knob = &def;
#endif
}
static void sw_init(void)
{
#if USE_LV_SW != 0
theme.sw.bg = &def;
theme.sw.indic = &def;
theme.sw.knob_off = &def;
theme.sw.knob_on = &def;
#endif
}
static void lmeter_init(void)
{
#if USE_LV_LMETER != 0
theme.lmeter = &def;
#endif
}
static void gauge_init(void)
{
#if USE_LV_GAUGE != 0
theme.gauge = &def;
#endif
}
static void arc_init(void)
{
#if USE_LV_ARC != 0
theme.arc = &def;
#endif
}
static void preload_init(void)
{
#if USE_LV_PRELOAD != 0
theme.preload = &def;
#endif
}
static void chart_init(void)
{
#if USE_LV_CHART
theme.chart = &def;
#endif
}
static void calendar_init(void)
{
#if USE_LV_CALENDAR
theme.calendar.bg = theme.panel;
theme.calendar.header = &def;
theme.calendar.inactive_days = &def;
theme.calendar.highlighted_days = &def;
theme.calendar.week_box = &def;
theme.calendar.today_box = &def;
theme.calendar.header_pr = &def;
theme.calendar.day_names = &def;
#endif
}
static void cb_init(void)
{
#if USE_LV_CB != 0
theme.cb.bg = &def;
theme.cb.box.rel = &def;
theme.cb.box.pr = &def;
theme.cb.box.tgl_rel = &def;
theme.cb.box.tgl_pr = &def;
theme.cb.box.ina = &def;
#endif
}
static void btnm_init(void)
{
#if USE_LV_BTNM
theme.btnm.bg = &def;
theme.btnm.btn.rel = &def;
theme.btnm.btn.pr = &def;
theme.btnm.btn.tgl_rel = &def;
theme.btnm.btn.tgl_pr = &def;
theme.btnm.btn.ina = &def;
#endif
}
static void kb_init(void)
{
#if USE_LV_KB
theme.kb.bg = &def;
theme.kb.btn.rel = &def;
theme.kb.btn.pr = &def;
theme.kb.btn.tgl_rel = &def;
theme.kb.btn.tgl_pr = &def;
theme.kb.btn.ina = &def;
#endif
}
static void mbox_init(void)
{
#if USE_LV_MBOX
theme.mbox.bg = &def;
theme.mbox.btn.bg = &def;
theme.mbox.btn.rel = &def;
theme.mbox.btn.pr = &def;
#endif
}
static void page_init(void)
{
#if USE_LV_PAGE
theme.page.bg = &def;
theme.page.scrl = &def;
theme.page.sb = &def;
#endif
}
static void ta_init(void)
{
#if USE_LV_TA
theme.ta.area = &def;
theme.ta.oneline = &def;
theme.ta.cursor = NULL; /*Let library to calculate the cursor's style*/
theme.ta.sb = &def;
#endif
}
static void list_init(void)
{
#if USE_LV_LIST != 0
theme.list.sb = &def;
theme.list.bg = &def;
theme.list.scrl = &def;
theme.list.btn.rel = &def;
theme.list.btn.pr = &def;
theme.list.btn.tgl_rel = &def;
theme.list.btn.tgl_pr = &def;
theme.list.btn.ina = &def;
#endif
}
static void ddlist_init(void)
{
#if USE_LV_DDLIST != 0
theme.ddlist.bg = &def;
theme.ddlist.sel = &def;
theme.ddlist.sb = &def;
#endif
}
static void roller_init(void)
{
#if USE_LV_ROLLER != 0
theme.roller.bg = &def;
theme.roller.sel = &def;
#endif
}
static void tabview_init(void)
{
#if USE_LV_TABVIEW != 0
theme.tabview.bg = &def;
theme.tabview.indic = &def;
theme.tabview.btn.bg = &def;
theme.tabview.btn.rel = &def;
theme.tabview.btn.pr = &def;
theme.tabview.btn.tgl_rel = &def;
theme.tabview.btn.tgl_pr = &def;
#endif
}
static void win_init(void)
{
#if USE_LV_WIN != 0
theme.win.bg = &def;
theme.win.sb = &def;
theme.win.header = &def;
theme.win.content.bg = &def;
theme.win.content.scrl = &def;
theme.win.btn.rel = &def;
theme.win.btn.pr = &def;
#endif
}
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the templ theme
* @param hue [0..360] hue value from HSV color space to define the theme's base color
* @param font pointer to a font (NULL to use the default)
* @return pointer to the initialized theme
*/
lv_theme_t * lv_theme_templ_init(uint16_t hue, lv_font_t * font)
{
if(font == NULL) font = LV_FONT_DEFAULT;
_hue = hue;
_font = font;
/*For backward compatibility initialize all theme elements with a default style */
uint16_t i;
lv_style_t ** style_p = (lv_style_t **) &theme;
for(i = 0; i < sizeof(lv_theme_t) / sizeof(lv_style_t *); i++) {
*style_p = &def;
style_p++;
}
basic_init();
cont_init();
btn_init();
imgbtn_init();
label_init();
img_init();
line_init();
led_init();
bar_init();
slider_init();
sw_init();
lmeter_init();
gauge_init();
arc_init();
preload_init();
chart_init();
cb_init();
btnm_init();
kb_init();
mbox_init();
page_init();
ta_init();
list_init();
ddlist_init();
roller_init();
tabview_init();
win_init();
return &theme;
}
/**
* Get a pointer to the theme
* @return pointer to the theme
*/
lv_theme_t * lv_theme_get_templ(void)
{
return &theme;
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif

View File

@ -1,836 +0,0 @@
/**
* @file lv_theme_zen.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_theme.h"
#if USE_LV_THEME_ZEN
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
static lv_theme_t theme;
/*Static style definitions*/
static lv_style_t def;
static lv_style_t sb;
/*Saved input parameters*/
static uint16_t _hue;
static lv_font_t * _font;
/**********************
* MACROS
**********************/
/**********************
* STATIC FUNCTIONS
**********************/
static void basic_init(void)
{
static lv_style_t bg;
static lv_style_t panel;
lv_style_copy(&def, &lv_style_pretty); /*Initialize the default style*/
def.body.border.opa = LV_OPA_COVER;
def.text.font = _font;
def.text.color = LV_COLOR_HEX3(0x444);
def.image.color = LV_COLOR_HEX3(0x444);
lv_style_copy(&bg, &def);
bg.body.main_color = LV_COLOR_WHITE;
bg.body.grad_color = LV_COLOR_WHITE;
bg.body.radius = 0;
bg.body.border.width = 0;
bg.body.shadow.width = 0;
lv_style_copy(&panel, &bg);
panel.body.radius = LV_DPI / 10;
panel.body.border.width = 2;
panel.body.border.color = lv_color_hsv_to_rgb(_hue, 30, 90);
panel.body.border.opa = LV_OPA_COVER;
panel.body.shadow.width = 4;
panel.body.shadow.color = LV_COLOR_HEX3(0xddd);
panel.body.padding.hor = LV_DPI / 6;
panel.body.padding.ver = LV_DPI / 8;
panel.body.padding.inner = LV_DPI / 10;
lv_style_copy(&sb, &def);
sb.body.main_color = lv_color_hsv_to_rgb(_hue, 30, 90);
sb.body.grad_color = sb.body.main_color;
sb.body.border.width = 0;
sb.body.radius = LV_RADIUS_CIRCLE;
sb.body.padding.inner = LV_DPI / 10;
theme.bg = &bg;
theme.panel = &panel;
}
static void cont_init(void)
{
#if USE_LV_CONT != 0
theme.cont = theme.panel;
#endif
}
static void btn_init(void)
{
#if USE_LV_BTN != 0
static lv_style_t rel, pr, tgl_pr, ina;
lv_style_copy(&rel, &def);
rel.body.empty = 1;
rel.body.radius = LV_RADIUS_CIRCLE;
rel.body.border.width = 2;
rel.body.border.color = lv_color_hsv_to_rgb(_hue, 40, 90);
rel.body.border.opa = LV_OPA_COVER;
rel.body.shadow.width = 4;
rel.body.shadow.color = LV_COLOR_HEX3(0xddd);
rel.body.padding.hor = LV_DPI / 4;
rel.body.padding.ver = LV_DPI / 8;
rel.text.color = lv_color_hsv_to_rgb(_hue, 40, 90);
rel.image.color = lv_color_hsv_to_rgb(_hue, 40, 90);
lv_style_copy(&pr, &rel);
pr.body.border.color = lv_color_hsv_to_rgb(_hue, 40, 60);
pr.body.shadow.width = 0;
pr.text.color = lv_color_hsv_to_rgb(_hue, 40, 60);
pr.image.color = lv_color_hsv_to_rgb(_hue, 40, 60);
lv_style_copy(&tgl_pr, &pr);
tgl_pr.body.border.color = lv_color_hsv_to_rgb(_hue, 40, 50);
tgl_pr.text.color = lv_color_hsv_to_rgb(_hue, 40, 50);
tgl_pr.image.color = lv_color_hsv_to_rgb(_hue, 40, 50);
lv_style_copy(&ina, &tgl_pr);
ina.body.border.color = LV_COLOR_HEX3(0xbbb);
ina.text.color = LV_COLOR_HEX3(0xbbb);
ina.image.color = LV_COLOR_HEX3(0xbbb);
theme.btn.rel = &rel;
theme.btn.pr = &pr;
theme.btn.tgl_rel = &pr;
theme.btn.tgl_pr = &tgl_pr;
theme.btn.ina = &ina;
#endif
}
static void label_init(void)
{
#if USE_LV_LABEL != 0
static lv_style_t prim, sec, hint;
lv_style_copy(&prim, &def);
lv_style_copy(&sec, &def);
lv_style_copy(&hint, &def);
prim.text.color = LV_COLOR_HEX3(0x555);
sec.text.color = lv_color_hsv_to_rgb(_hue, 50, 80);
hint.text.color = lv_color_hsv_to_rgb(_hue, 25, 85);
theme.label.prim = &prim;
theme.label.sec = &sec;
theme.label.hint = &hint;
#endif
}
static void img_init(void)
{
#if USE_LV_IMG != 0
static lv_style_t img_light, img_dark;
lv_style_copy(&img_light, &def);
img_light.image.color = lv_color_hsv_to_rgb(_hue, 15, 85);
img_light.image.intense = LV_OPA_80;
lv_style_copy(&img_dark, &def);
img_light.image.color = lv_color_hsv_to_rgb(_hue, 85, 55);
img_light.image.intense = LV_OPA_80;
theme.img.light = &img_light;
theme.img.dark = &img_dark;
#endif
}
static void line_init(void)
{
#if USE_LV_LINE != 0
theme.line.decor = &def;
#endif
}
static void led_init(void)
{
#if USE_LV_LED != 0
static lv_style_t led;
lv_style_copy(&led, &lv_style_pretty_color);
led.body.shadow.width = LV_DPI / 10;
led.body.radius = LV_RADIUS_CIRCLE;
led.body.border.width = LV_DPI / 30;
led.body.border.opa = LV_OPA_30;
led.body.main_color = lv_color_hsv_to_rgb(_hue, 60, 100);
led.body.grad_color = lv_color_hsv_to_rgb(_hue, 60, 40);
led.body.border.color = lv_color_hsv_to_rgb(_hue, 60, 60);
led.body.shadow.color = lv_color_hsv_to_rgb(_hue, 80, 100);
theme.led = &led;
#endif
}
static void bar_init(void)
{
#if USE_LV_BAR
static lv_style_t bg, indic;
lv_style_copy(&bg, &def);
bg.body.empty = 1;
bg.body.radius = LV_RADIUS_CIRCLE;
bg.body.border.width = 2;
bg.body.border.opa = LV_OPA_COVER;
bg.body.border.color = lv_color_hsv_to_rgb(_hue, 40, 90);
lv_style_copy(&indic, &def);
indic.body.radius = LV_RADIUS_CIRCLE;
indic.body.main_color = lv_color_hsv_to_rgb(_hue, 40, 90);
indic.body.grad_color = indic.body.main_color;
indic.body.border.width = 0;
indic.body.padding.hor = LV_DPI / 20;
indic.body.padding.ver = LV_DPI / 20;
theme.bar.bg = &bg;
theme.bar.indic = &indic;
#endif
}
static void slider_init(void)
{
#if USE_LV_SLIDER != 0
static lv_style_t knob;
lv_style_copy(&knob, &def);
knob.body.main_color = theme.bar.indic->body.main_color;
knob.body.grad_color = knob.body.main_color;
knob.body.radius = LV_RADIUS_CIRCLE;
knob.body.border.width = 0;
theme.slider.bg = theme.bar.bg;
theme.slider.indic = theme.bar.indic;
theme.slider.knob = &knob;
#endif
}
static void sw_init(void)
{
#if USE_LV_SW != 0
static lv_style_t indic;
lv_style_copy(&indic, theme.slider.indic);
indic.body.radius = LV_RADIUS_CIRCLE;
indic.body.main_color = lv_color_hsv_to_rgb(_hue, 15, 95);
indic.body.grad_color = indic.body.main_color;
indic.body.border.width = theme.slider.bg->body.border.width;
indic.body.border.color = theme.slider.bg->body.border.color;
indic.body.border.opa = theme.slider.bg->body.border.opa;
indic.body.padding.hor = 0;
indic.body.padding.ver = 0;
theme.sw.bg = theme.slider.bg;
theme.sw.indic = &indic;
theme.sw.knob_off = theme.slider.knob;
theme.sw.knob_on = theme.slider.knob;
#endif
}
static void lmeter_init(void)
{
#if USE_LV_LMETER != 0
static lv_style_t lmeter;
lv_style_copy(&lmeter, &def);
lmeter.line.color = LV_COLOR_HEX3(0xddd);
lmeter.line.width = 2;
lmeter.body.main_color = lv_color_hsv_to_rgb(_hue, 80, 70);
lmeter.body.grad_color = lmeter.body.main_color;
lmeter.body.padding.hor = LV_DPI / 8;
theme.lmeter = &lmeter;
#endif
}
static void gauge_init(void)
{
#if USE_LV_GAUGE != 0
static lv_style_t gauge;
lv_style_copy(&gauge, &def);
gauge.line.color = lv_color_hsv_to_rgb(_hue, 50, 70);
gauge.line.width = 1;
gauge.body.main_color = LV_COLOR_HEX3(0x999);
gauge.body.grad_color = gauge.body.main_color;
gauge.body.padding.hor = LV_DPI / 16;
gauge.body.border.color = LV_COLOR_HEX3(0x666); /*Needle middle color*/
theme.gauge = &gauge;
#endif
}
static void arc_init(void)
{
#if USE_LV_ARC != 0
static lv_style_t arc;
lv_style_copy(&arc, &def);
arc.line.width = 10;
arc.line.color = lv_color_hsv_to_rgb(_hue, 40, 90);
arc.line.rounded = 1;
/*For preloader*/
arc.body.border.width = 0;
theme.arc = &arc;
#endif
}
static void preload_init(void)
{
#if USE_LV_PRELOAD != 0
theme.preload = theme.arc;
#endif
}
static void chart_init(void)
{
#if USE_LV_CHART
theme.chart = theme.panel;
#endif
}
static void calendar_init(void)
{
#if USE_LV_CALENDAR != 0
static lv_style_t ina_days;
lv_style_copy(&ina_days, &def);
ina_days.text.color = lv_color_hsv_to_rgb(_hue, 0, 70);
static lv_style_t high_days;
lv_style_copy(&high_days, &def);
high_days.text.color = lv_color_hsv_to_rgb(_hue, 50, 90);
static lv_style_t today_box;
lv_style_copy(&today_box, &def);
today_box.body.empty = 1;
today_box.body.border.color = theme.panel->body.border.color;
today_box.body.padding.ver = LV_DPI / 20;
today_box.body.radius = LV_RADIUS_CIRCLE;
theme.calendar.bg = theme.panel;
theme.calendar.header = &lv_style_transp;
theme.calendar.inactive_days = &ina_days;
theme.calendar.highlighted_days = &high_days;
theme.calendar.week_box = &lv_style_transp_fit;
theme.calendar.today_box = &today_box;
#endif
}
static void cb_init(void)
{
#if USE_LV_CB != 0
static lv_style_t rel, pr, tgl_rel, tgl_pr, ina;
lv_style_copy(&rel, &def);
rel.body.radius = LV_DPI / 20;
rel.body.shadow.width = 0;
rel.body.border.width = 3;
rel.body.border.opa = LV_OPA_COVER;
rel.body.border.color = lv_color_hsv_to_rgb(_hue, 35, 80);
rel.body.main_color = LV_COLOR_HEX3(0xfff);
rel.body.grad_color = rel.body.main_color;
lv_style_copy(&pr, &rel);
pr.body.border.color = lv_color_hsv_to_rgb(_hue, 35, 70);
lv_style_copy(&tgl_rel, &rel);
tgl_rel.body.border.color = lv_color_hsv_to_rgb(_hue, 45, 80);
tgl_rel.body.main_color = lv_color_hsv_to_rgb(_hue, 40, 90);
tgl_rel.body.grad_color = tgl_rel.body.main_color;
lv_style_copy(&tgl_pr, &rel);
tgl_pr.body.border.color = lv_color_hsv_to_rgb(_hue, 45, 70);
tgl_pr.body.main_color = lv_color_hsv_to_rgb(_hue, 40, 80);
tgl_pr.body.grad_color = tgl_pr.body.main_color;
lv_style_copy(&ina, &rel);
ina.body.border.color = LV_COLOR_HEX3(0xaaa);
theme.cb.bg = &lv_style_transp;
theme.cb.box.rel = &rel;
theme.cb.box.pr = &pr;
theme.cb.box.tgl_rel = &tgl_rel;
theme.cb.box.tgl_pr = &tgl_pr;
theme.cb.box.ina = &ina;
#endif
}
static void btnm_init(void)
{
#if USE_LV_BTNM
static lv_style_t bg, rel, pr, tgl_rel, tgl_pr, ina;
lv_style_copy(&bg, &lv_style_transp);
bg.glass = 0;
bg.body.padding.hor = 0;
bg.body.padding.ver = 0;
bg.body.padding.inner = LV_DPI / 15;
bg.text.font = _font;
lv_style_copy(&rel, &def);
rel.body.empty = 1;
rel.body.border.width = 0;
lv_style_copy(&pr, &def);
pr.body.empty = 1;
pr.body.radius = LV_DPI / 1;
pr.body.border.width = 2;
pr.body.border.color = lv_color_hsv_to_rgb(_hue, 40, 60);
pr.body.border.opa = LV_OPA_COVER;
pr.text.color = lv_color_hsv_to_rgb(_hue, 40, 60);
lv_style_copy(&tgl_rel, &pr);
tgl_rel.body.empty = 0;
tgl_rel.body.main_color = lv_color_hsv_to_rgb(_hue, 15, 95);
tgl_rel.body.grad_color = tgl_rel.body.main_color;
tgl_rel.body.border.width = 0;
tgl_rel.text.color = lv_color_hsv_to_rgb(_hue, 60, 40);
lv_style_copy(&tgl_pr, &tgl_rel);
tgl_pr.body.main_color = lv_color_hsv_to_rgb(_hue, 30, 70);
tgl_pr.body.grad_color = tgl_pr.body.main_color;
lv_style_copy(&ina, &pr);
ina.body.main_color = LV_COLOR_HEX3(0x888);
ina.body.grad_color = tgl_pr.body.main_color;
ina.text.color = LV_COLOR_HEX3(0x888);;
theme.btnm.bg = &bg;
theme.btnm.btn.rel = &rel;
theme.btnm.btn.pr = &pr;
theme.btnm.btn.tgl_rel = &tgl_rel;
theme.btnm.btn.tgl_pr = &tgl_pr;
theme.btnm.btn.ina = &ina;
#endif
}
static void kb_init(void)
{
#if USE_LV_KB
static lv_style_t bg, rel, pr, tgl_rel, tgl_pr, ina;
lv_style_copy(&bg, &def);
bg.body.main_color = LV_COLOR_HEX3(0x666);
bg.body.grad_color = bg.body.main_color;
bg.body.padding.hor = 0;
bg.body.padding.ver = 0;
bg.body.padding.inner = 0;
bg.body.radius = 0;
bg.body.border.width = 0;
lv_style_copy(&rel, &def);
rel.body.empty = 1;
rel.body.radius = 0;
rel.body.border.width = 1;
rel.body.border.color = LV_COLOR_HEX3(0x888);
rel.body.border.opa = LV_OPA_COVER;
rel.text.color = LV_COLOR_WHITE;
lv_style_copy(&pr, &def);
pr.body.main_color = LV_COLOR_HEX3(0xeee);
pr.body.grad_color = pr.body.main_color;
pr.body.border.color = LV_COLOR_HEX3(0x888);
pr.body.border.width = 1;
pr.body.border.opa = LV_OPA_COVER;
pr.body.radius = 0;
pr.text.color = LV_COLOR_HEX3(0x666);
lv_style_copy(&tgl_rel, &pr);
tgl_rel.body.main_color = LV_COLOR_HEX3(0x999);
tgl_rel.body.grad_color = tgl_rel.body.main_color;
tgl_rel.text.color = LV_COLOR_WHITE;
lv_style_copy(&tgl_pr, &pr);
tgl_pr.body.main_color = LV_COLOR_HEX3(0xbbb);
tgl_pr.body.grad_color = tgl_pr.body.main_color;
tgl_pr.text.color = LV_COLOR_HEX3(0xddd);
lv_style_copy(&ina, &pr);
ina.body.main_color = LV_COLOR_HEX3(0x777);
ina.body.grad_color = ina.body.main_color;
ina.text.color = LV_COLOR_HEX3(0xbbb);
theme.kb.bg = &bg;
theme.kb.btn.rel = &rel;
theme.kb.btn.pr = &pr;
theme.kb.btn.tgl_rel = &tgl_rel;
theme.kb.btn.tgl_pr = &tgl_pr;
theme.kb.btn.ina = &ina;
#endif
}
static void mbox_init(void)
{
#if USE_LV_MBOX
static lv_style_t bg, rel, pr;
lv_style_copy(&bg, theme.panel);
bg.body.main_color = lv_color_hsv_to_rgb(_hue, 10, 95);
bg.body.grad_color = bg.body.main_color;
bg.text.color = lv_color_hsv_to_rgb(_hue, 40, 25);
lv_style_copy(&rel, &def);
rel.body.main_color = lv_color_hsv_to_rgb(_hue, 25, 85);
rel.body.grad_color = rel.body.main_color;
rel.body.radius = LV_RADIUS_CIRCLE;
rel.body.border.width = 2;
rel.body.border.color = lv_color_hsv_to_rgb(_hue, 30, 70);
rel.body.padding.hor = LV_DPI / 4;
rel.body.padding.ver = LV_DPI / 8;
rel.text.color = bg.text.color;
lv_style_copy(&pr, &rel);
pr.body.border.color = lv_color_hsv_to_rgb(_hue, 30, 90);
pr.text.color = lv_color_hsv_to_rgb(_hue, 40, 40);
pr.body.main_color = lv_color_hsv_to_rgb(_hue, 20, 85);
pr.body.grad_color = pr.body.main_color;
theme.mbox.bg = &bg;
theme.mbox.btn.bg = &lv_style_transp;
theme.mbox.btn.rel = &rel;
theme.mbox.btn.pr = &pr;
#endif
}
static void page_init(void)
{
#if USE_LV_PAGE
theme.page.bg = theme.panel;
theme.page.scrl = &lv_style_transp;
theme.page.sb = &sb;
#endif
}
static void ta_init(void)
{
#if USE_LV_TA
static lv_style_t oneline;
lv_style_copy(&oneline, theme.panel);
oneline.body.radius = LV_RADIUS_CIRCLE;
oneline.body.padding.ver = LV_DPI / 10;
oneline.body.shadow.width = 0;
theme.ta.area = theme.panel;
theme.ta.oneline = &oneline;
theme.ta.cursor = NULL; /*Let library to calculate the cursor's style*/
theme.ta.sb = &def;
#endif
}
static void spinbox_init(void)
{
#if USE_LV_SPINBOX
theme.spinbox.bg= theme.panel;
theme.spinbox.cursor = theme.ta.cursor;
theme.spinbox.sb = theme.ta.sb;
#endif
}
static void list_init(void)
{
#if USE_LV_LIST != 0
static lv_style_t bg, rel, pr, tgl_rel, tgl_pr, ina;
lv_style_copy(&bg, theme.panel);
bg.body.padding.hor = 0;
bg.body.padding.ver = 0;
lv_style_copy(&rel, &def);
rel.body.empty = 1;
rel.body.border.width = 0;
rel.body.padding.hor = LV_DPI / 8;
rel.body.padding.ver = LV_DPI / 8;
rel.text.color = LV_COLOR_HEX3(0x666);
rel.image.color = LV_COLOR_HEX3(0x666);
lv_style_copy(&pr, &rel);
pr.text.color = theme.btn.pr->text.color;
pr.image.color = theme.btn.pr->image.color;
lv_style_copy(&tgl_rel, &rel);
tgl_rel.text.color = lv_color_hsv_to_rgb(_hue, 50, 90);
lv_style_copy(&tgl_pr, &rel);
tgl_pr.text.color = theme.btn.tgl_pr->text.color;
tgl_pr.image.color = theme.btn.tgl_pr->image.color;
lv_style_copy(&ina, &rel);
ina.text.color = theme.btn.ina->text.color;
ina.image.color = theme.btn.ina->image.color;
theme.list.sb = &sb;
theme.list.bg = &bg;
theme.list.scrl = &lv_style_transp_tight;
theme.list.btn.rel = &rel;
theme.list.btn.pr = &pr;
theme.list.btn.tgl_rel = &tgl_rel;
theme.list.btn.tgl_pr = &tgl_pr;
theme.list.btn.ina = &ina;
#endif
}
static void ddlist_init(void)
{
#if USE_LV_DDLIST != 0
static lv_style_t bg, sel;
lv_style_copy(&bg, theme.panel);
bg.text.line_space = LV_DPI / 8;
bg.body.padding.hor = LV_DPI / 6;
bg.body.padding.ver = LV_DPI / 8;
bg.text.color = LV_COLOR_HEX3(0x666);
lv_style_copy(&sel, &def);
sel.body.empty = 1;
sel.body.border.width = 0;
sel.text.color = lv_color_hsv_to_rgb(_hue, 50, 80);
theme.ddlist.bg = &bg;
theme.ddlist.sel = &sel;
theme.ddlist.sb = &def;
#endif
}
static void roller_init(void)
{
#if USE_LV_ROLLER != 0
static lv_style_t bg, sel;
lv_style_copy(&bg, &def);
bg.body.border.width = 0;
bg.body.empty = 1;
bg.text.line_space = LV_DPI / 6;
bg.text.color = LV_COLOR_HEX3(0x999);
lv_style_copy(&sel, theme.panel);
sel.body.radius = LV_RADIUS_CIRCLE;
sel.body.empty = 1;
theme.roller.bg = &bg;
theme.roller.sel = &sel;
#endif
}
static void tabview_init(void)
{
#if USE_LV_TABVIEW != 0
static lv_style_t btn_bg, indic, rel, pr, tgl_rel, tgl_pr;
lv_style_copy(&btn_bg, &def);
btn_bg.body.empty = 1;
btn_bg.body.border.width = 2;
btn_bg.body.border.part = LV_BORDER_BOTTOM;
btn_bg.body.border.color = lv_color_hsv_to_rgb(_hue, 10, 90);
lv_style_copy(&indic, &def);
indic.body.padding.inner = LV_DPI / 16;
indic.body.border.width = 0;
indic.body.radius = LV_RADIUS_CIRCLE;
indic.body.main_color = lv_color_hsv_to_rgb(_hue, 50, 80);
indic.body.grad_color = indic.body.main_color;
lv_style_copy(&rel, &def);
rel.body.empty = 1;
rel.body.border.width = 0;
rel.text.color = LV_COLOR_HEX3(0x999);
lv_style_copy(&pr, &rel);
pr.text.color = LV_COLOR_HEX3(0x777);
lv_style_copy(&tgl_rel, &rel);
tgl_rel.text.color = lv_color_hsv_to_rgb(_hue, 50, 80);
lv_style_copy(&tgl_pr, &rel);
tgl_pr.text.color = lv_color_hsv_to_rgb(_hue, 50, 70);
theme.tabview.bg = theme.bg;
theme.tabview.indic = &indic;
theme.tabview.btn.bg = &btn_bg;
theme.tabview.btn.rel = &rel;
theme.tabview.btn.pr = &pr;
theme.tabview.btn.tgl_rel = &tgl_rel;
theme.tabview.btn.tgl_pr = &tgl_pr;
#endif
}
static void tileview_init(void)
{
#if USE_LV_TILEVIEW != 0
theme.tileview.bg = &lv_style_transp_tight;
theme.tileview.scrl = &lv_style_transp_tight;
theme.tileview.sb = theme.page.sb;
#endif
}
static void table_init(void)
{
#if USE_LV_TABLE != 0
static lv_style_t cell;
lv_style_copy(&cell, theme.panel);
cell.body.radius = 0;
cell.body.border.width = 1;
cell.body.shadow.width = 0;
cell.body.padding.hor = LV_DPI / 12;
cell.body.padding.ver = LV_DPI / 12;
theme.table.bg = &lv_style_transp_tight;
theme.table.cell = &cell;
#endif
}
static void win_init(void)
{
#if USE_LV_WIN != 0
static lv_style_t header, rel, pr;
lv_style_copy(&header, &def);
header.body.empty = 1;
header.body.border.width = 2;
header.body.border.part = LV_BORDER_BOTTOM;
header.body.border.color = lv_color_hsv_to_rgb(_hue, 10, 90);
header.text.color = LV_COLOR_HEX3(0x666);
header.image.color = LV_COLOR_HEX3(0x666);
lv_style_copy(&rel, &def);
rel.body.empty = 1;
rel.body.border.width = 0;
rel.text.color = LV_COLOR_HEX3(0x666);
rel.image.color = LV_COLOR_HEX3(0x666);
lv_style_copy(&pr, &rel);
pr.text.color = LV_COLOR_HEX3(0x333);
pr.image.color = LV_COLOR_HEX3(0x333);
theme.win.bg = theme.panel;
theme.win.sb = &sb;
theme.win.header = &header;
theme.win.content.bg = &lv_style_transp;
theme.win.content.scrl = &lv_style_transp;
theme.win.btn.rel = &rel;
theme.win.btn.pr = &pr;
#endif
}
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the zen theme
* @param hue [0..360] hue value from HSV color space to define the theme's base color
* @param font pointer to a font (NULL to use the default)
* @return pointer to the initialized theme
*/
lv_theme_t * lv_theme_zen_init(uint16_t hue, lv_font_t * font)
{
if(font == NULL) font = LV_FONT_DEFAULT;
_hue = hue;
_font = font;
/*For backward compatibility initialize all theme elements with a default style */
uint16_t i;
lv_style_t ** style_p = (lv_style_t **) &theme;
for(i = 0; i < sizeof(lv_theme_t) / sizeof(lv_style_t *); i++) {
*style_p = &def;
style_p++;
}
basic_init();
cont_init();
btn_init();
label_init();
img_init();
line_init();
led_init();
bar_init();
slider_init();
sw_init();
lmeter_init();
gauge_init();
arc_init();
preload_init();
chart_init();
calendar_init();
cb_init();
btnm_init();
kb_init();
mbox_init();
page_init();
ta_init();
spinbox_init();
list_init();
ddlist_init();
roller_init();
tabview_init();
tileview_init();
table_init();
win_init();
return &theme;
}
/**
* Get a pointer to the theme
* @return pointer to the theme
*/
lv_theme_t * lv_theme_get_zen(void)
{
return &theme;
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif

90
lvgl.h
View File

@ -14,53 +14,59 @@ extern "C" {
* INCLUDES
*********************/
#include "lv_version.h"
#include "src/lv_version.h"
#include "lv_misc/lv_log.h"
#include "lv_misc/lv_task.h"
#include "src/lv_misc/lv_log.h"
#include "src/lv_misc/lv_task.h"
#include "src/lv_misc/lv_math.h"
#include "lv_hal/lv_hal.h"
#include "src/lv_hal/lv_hal.h"
#include "lv_core/lv_obj.h"
#include "lv_core/lv_group.h"
#include "lv_core/lv_lang.h"
#include "lv_core/lv_vdb.h"
#include "lv_core/lv_refr.h"
#include "src/lv_core/lv_obj.h"
#include "src/lv_core/lv_group.h"
#include "lv_themes/lv_theme.h"
#include "src/lv_core/lv_refr.h"
#include "src/lv_core/lv_disp.h"
#include "lv_objx/lv_btn.h"
#include "lv_objx/lv_imgbtn.h"
#include "lv_objx/lv_img.h"
#include "lv_objx/lv_label.h"
#include "lv_objx/lv_line.h"
#include "lv_objx/lv_page.h"
#include "lv_objx/lv_cont.h"
#include "lv_objx/lv_list.h"
#include "lv_objx/lv_chart.h"
#include "lv_objx/lv_table.h"
#include "lv_objx/lv_cb.h"
#include "lv_objx/lv_bar.h"
#include "lv_objx/lv_slider.h"
#include "lv_objx/lv_led.h"
#include "lv_objx/lv_btnm.h"
#include "lv_objx/lv_kb.h"
#include "lv_objx/lv_ddlist.h"
#include "lv_objx/lv_roller.h"
#include "lv_objx/lv_ta.h"
#include "lv_objx/lv_canvas.h"
#include "lv_objx/lv_win.h"
#include "lv_objx/lv_tabview.h"
#include "lv_objx/lv_tileview.h"
#include "lv_objx/lv_mbox.h"
#include "lv_objx/lv_gauge.h"
#include "lv_objx/lv_lmeter.h"
#include "lv_objx/lv_sw.h"
#include "lv_objx/lv_kb.h"
#include "lv_objx/lv_arc.h"
#include "lv_objx/lv_preload.h"
#include "lv_objx/lv_calendar.h"
#include "lv_objx/lv_spinbox.h"
#include "src/lv_themes/lv_theme.h"
#include "src/lv_font/lv_font.h"
#include "src/lv_font/lv_font_fmt_txt.h"
#include "src/lv_objx/lv_btn.h"
#include "src/lv_objx/lv_imgbtn.h"
#include "src/lv_objx/lv_img.h"
#include "src/lv_objx/lv_label.h"
#include "src/lv_objx/lv_line.h"
#include "src/lv_objx/lv_page.h"
#include "src/lv_objx/lv_cont.h"
#include "src/lv_objx/lv_list.h"
#include "src/lv_objx/lv_chart.h"
#include "src/lv_objx/lv_table.h"
#include "src/lv_objx/lv_cb.h"
#include "src/lv_objx/lv_bar.h"
#include "src/lv_objx/lv_slider.h"
#include "src/lv_objx/lv_led.h"
#include "src/lv_objx/lv_btnm.h"
#include "src/lv_objx/lv_kb.h"
#include "src/lv_objx/lv_ddlist.h"
#include "src/lv_objx/lv_roller.h"
#include "src/lv_objx/lv_ta.h"
#include "src/lv_objx/lv_canvas.h"
#include "src/lv_objx/lv_win.h"
#include "src/lv_objx/lv_tabview.h"
#include "src/lv_objx/lv_tileview.h"
#include "src/lv_objx/lv_mbox.h"
#include "src/lv_objx/lv_gauge.h"
#include "src/lv_objx/lv_lmeter.h"
#include "src/lv_objx/lv_sw.h"
#include "src/lv_objx/lv_kb.h"
#include "src/lv_objx/lv_arc.h"
#include "src/lv_objx/lv_preload.h"
#include "src/lv_objx/lv_calendar.h"
#include "src/lv_objx/lv_spinbox.h"
#include "src/lv_draw/lv_img_cache.h"
/*********************
* DEFINES

14
lvgl.mk
View File

@ -1,8 +1,8 @@
include $(LVGL_DIR)/lvgl/lv_core/lv_core.mk
include $(LVGL_DIR)/lvgl/lv_hal/lv_hal.mk
include $(LVGL_DIR)/lvgl/lv_objx/lv_objx.mk
include $(LVGL_DIR)/lvgl/lv_fonts/lv_fonts.mk
include $(LVGL_DIR)/lvgl/lv_misc/lv_misc.mk
include $(LVGL_DIR)/lvgl/lv_themes/lv_themes.mk
include $(LVGL_DIR)/lvgl/lv_draw/lv_draw.mk
include $(LVGL_DIR)/lvgl/src/lv_core/lv_core.mk
include $(LVGL_DIR)/lvgl/src/lv_hal/lv_hal.mk
include $(LVGL_DIR)/lvgl/src/lv_objx/lv_objx.mk
include $(LVGL_DIR)/lvgl/src/lv_font/lv_font.mk
include $(LVGL_DIR)/lvgl/src/lv_misc/lv_misc.mk
include $(LVGL_DIR)/lvgl/src/lv_themes/lv_themes.mk
include $(LVGL_DIR)/lvgl/src/lv_draw/lv_draw.mk

View File

@ -0,0 +1,202 @@
/**
* @file lv_port_disp_templ.c
*
*/
/*Copy this file as "lv_port_disp.c" and set this value to "1" to enable content*/
#if 0
/*********************
* INCLUDES
*********************/
#include "lv_port_disp_templ.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void disp_init(void);
static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p);
#if LV_USE_GPU
static void gpu_blend(lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa);
static void gpu_fill(lv_color_t * dest, uint32_t length, lv_color_t color);
#endif
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_port_disp_init(void)
{
/*-------------------------
* Initialize your display
* -----------------------*/
disp_init();
/*-----------------------------
* Create a buffer for drawing
*----------------------------*/
/* LittlevGL requires a buffer where it draws the objects. The buffer's has to be greater than 1 display row
*
* There are three buffering configurations:
* 1. Create ONE buffer with some rows:
* LittlevGL will draw the display's content here and writes it to your display
*
* 2. Create TWO buffer with some rows:
* LittlevGL will draw the display's content to a buffer and writes it your display.
* You should use DMA to write the buffer's content to the display.
* It will enable LittlevGL to draw the next part of the screen to the other buffer while
* the data is being sent form the first buffer. It makes rendering and flushing parallel.
*
* 3. Create TWO screen-sized buffer:
* Similar to 2) but the buffer have to be screen sized. When LittlevGL is ready it will give the
* whole frame to display. This way you only need to change the frame buffer's address instead of
* copying the pixels.
* */
/* Example for 1) */
static lv_disp_buf_t disp_buf_1;
static lv_color_t buf1_1[LV_HOR_RES_MAX * 10]; /*A buffer for 10 rows*/
lv_disp_buf_init(&disp_buf_1, buf1_1, NULL, LV_HOR_RES_MAX * 10); /*Initialize the display buffer*/
/* Example for 2) */
static lv_disp_buf_t disp_buf_2;
static lv_color_t buf2_1[LV_HOR_RES_MAX * 10]; /*A buffer for 10 rows*/
static lv_color_t buf2_2[LV_HOR_RES_MAX * 10]; /*An other buffer for 10 rows*/
lv_disp_buf_init(&disp_buf_2, buf2_1, buf2_2, LV_HOR_RES_MAX * 10); /*Initialize the display buffer*/
/* Example for 3) */
static lv_disp_buf_t disp_buf_3;
static lv_color_t buf3_1[LV_HOR_RES_MAX * LV_VER_RES_MAX]; /*A screen sized buffer*/
static lv_color_t buf3_2[LV_HOR_RES_MAX * LV_VER_RES_MAX]; /*An other screen sized buffer*/
lv_disp_buf_init(&disp_buf_3, buf3_1, buf3_2, LV_HOR_RES_MAX * LV_VER_RES_MAX); /*Initialize the display buffer*/
/*-----------------------------------
* Register the display in LittlevGL
*----------------------------------*/
lv_disp_drv_t disp_drv; /*Descriptor of a display driver*/
lv_disp_drv_init(&disp_drv); /*Basic initialization*/
/*Set up the functions to access to your display*/
/*Set the resolution of the display*/
disp_drv.hor_res = 480;
disp_drv.ver_res = 320;
/*Used to copy the buffer's content to the display*/
disp_drv.flush_cb = disp_flush;
/*Set a display buffer*/
disp_drv.buffer = &disp_buf_2;
#if LV_USE_GPU
/*Optionally add functions to access the GPU. (Only in buffered mode, LV_VDB_SIZE != 0)*/
/*Blend two color array using opacity*/
disp_drv.gpu_blend = gpu_blend;
/*Fill a memory array with a color*/
disp_drv.gpu_fill = gpu_fill;
#endif
/*Finally register the driver*/
lv_disp_drv_register(&disp_drv);
}
/**********************
* STATIC FUNCTIONS
**********************/
/* Initialize your display and the required peripherals. */
static void disp_init(void)
{
/*You code here*/
}
/* Flush the content of the internal buffer the specific area on the display
* You can use DMA or any hardware acceleration to do this operation in the background but
* 'lv_disp_flush_ready()' has to be called when finished. */
static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
{
/*The most simple case (but also the slowest) to put all pixels to the screen one-by-one*/
int32_t x;
int32_t y;
for(y = area->y1; y <= area->y2; y++) {
for(x = area->x1; x <= area->x2; x++) {
/* Put a pixel to the display. For example: */
/* put_px(x, y, *color_p)*/
color_p++;
}
}
/* IMPORTANT!!!
* Inform the graphics library that you are ready with the flushing*/
lv_disp_flush_ready(disp);
}
/*OPTIONAL: GPU INTERFACE*/
#if LV_USE_GPU
/* If your MCU has hardware accelerator (GPU) then you can use it to blend to memories using opacity
* It can be used only in buffered mode (LV_VDB_SIZE != 0 in lv_conf.h)*/
static void gpu_blend(lv_disp_drv_t * disp_drv, lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa)
{
/*It's an example code which should be done by your GPU*/
uint32_t i;
for(i = 0; i < length; i++) {
dest[i] = lv_color_mix(dest[i], src[i], opa);
}
}
/* If your MCU has hardware accelerator (GPU) then you can use it to fill a memory with a color
* It can be used only in buffered mode (LV_VDB_SIZE != 0 in lv_conf.h)*/
static void gpu_fill_cb(lv_disp_drv_t * disp_drv, lv_color_t * dest_buf, lv_coord_t dest_width,
const lv_area_t * fill_area, lv_color_t color);
{
/*It's an example code which should be done by your GPU*/
uint32_t x, y;
dest_buf += dest_width * fill_area->y1; /*Go to the first line*/
for(y = fill_area->y1; y < fill_area->y2; y++) {
for(x = fill_area->x1; x < fill_area->x2; x++) {
dest_buf[x] = color;
}
dest_buf+=dest_width; /*Go to the next line*/
}
uint32_t i;
for(i = 0; i < length; i++) {
dest[i] = color;
}
}
#endif /*LV_USE_GPU*/
#else /* Enable this file at the top */
/* This dummy typedef exists purely to silence -Wpedantic. */
typedef int keep_pedantic_happy;
#endif

View File

@ -358,4 +358,8 @@ static lv_fs_res_t fs_dir_close (void * rddir_p)
return res;
}
#else /* Enable this file at the top */
/* This dummy typedef exists purely to silence -Wpedantic. */
typedef int keep_pedantic_happy;
#endif

View File

@ -24,25 +24,25 @@
**********************/
static void touchpad_init(void);
static bool touchpad_read(lv_indev_data_t * data);
static bool touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
static bool touchpad_is_pressed(void);
static void touchpad_get_xy(lv_coord_t * x, lv_coord_t * y);
static void mouse_init(void);
static bool mouse_read(lv_indev_data_t * data);
static bool mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
static bool mouse_is_pressed(void);
static void mouse_get_xy(lv_coord_t * x, lv_coord_t * y);
static void keypad_init(void);
static bool keypad_read(lv_indev_data_t * data);
static bool keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
static uint32_t keypad_get_key(void);
static void encoder_init(void);
static bool encoder_read(lv_indev_data_t * data);
static bool encoder_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
static void encoder_handler(void);
static void button_init(void);
static bool button_read(lv_indev_data_t * data);
static bool button_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
static int8_t button_get_pressed_id(void);
static bool button_is_pressed(uint8_t id);
@ -92,7 +92,7 @@ void lv_port_indev_init(void)
/*Register a touchpad input device*/
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read = touchpad_read;
indev_drv.read_cb = touchpad_read;
indev_touchpad = lv_indev_drv_register(&indev_drv);
/*------------------
@ -105,12 +105,12 @@ void lv_port_indev_init(void)
/*Register a mouse input device*/
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read = mouse_read;
indev_drv.read_cb = mouse_read;
indev_mouse = lv_indev_drv_register(&indev_drv);
/*Set cursor. For simplicity set a HOME symbol now.*/
lv_obj_t * mouse_cursor = lv_img_create(lv_scr_act(), NULL);
lv_img_set_src(mouse_cursor, SYMBOL_HOME);
lv_obj_t * mouse_cursor = lv_img_create(lv_disp_get_scr_act(NULL), NULL);
lv_img_set_src(mouse_cursor, LV_SYMBOL_HOME);
lv_indev_set_cursor(indev_mouse, mouse_cursor);
/*------------------
@ -123,7 +123,7 @@ void lv_port_indev_init(void)
/*Register a keypad input device*/
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_KEYPAD;
indev_drv.read = keypad_read;
indev_drv.read_cb = keypad_read;
indev_keypad = lv_indev_drv_register(&indev_drv);
/* Later you should create group(s) with `lv_group_t * group = lv_group_create()`,
@ -141,7 +141,7 @@ void lv_port_indev_init(void)
/*Register a encoder input device*/
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_KEYPAD;
indev_drv.read = encoder_read;
indev_drv.read_cb = encoder_read;
indev_encoder = lv_indev_drv_register(&indev_drv);
/* Later you should create group(s) with `lv_group_t * group = lv_group_create()`,
@ -159,7 +159,7 @@ void lv_port_indev_init(void)
/*Register a button input device*/
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_BUTTON;
indev_drv.read = button_read;
indev_drv.read_cb = button_read;
indev_button = lv_indev_drv_register(&indev_drv);
/*Assign buttons to points on the screen*/
@ -187,7 +187,7 @@ static void touchpad_init(void)
}
/* Will be called by the library to read the touchpad */
static bool touchpad_read(lv_indev_data_t * data)
static bool touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
{
static lv_coord_t last_x = 0;
static lv_coord_t last_y = 0;
@ -237,7 +237,7 @@ static void mouse_init(void)
}
/* Will be called by the library to read the mouse */
static bool mouse_read(lv_indev_data_t * data)
static bool mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
{
/*Get the current x and y coordinates*/
mouse_get_xy(&data->point.x, &data->point.y);
@ -281,7 +281,7 @@ static void keypad_init(void)
}
/* Will be called by the library to read the mouse */
static bool keypad_read(lv_indev_data_t * data)
static bool keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
{
static uint32_t last_key = 0;
@ -296,19 +296,19 @@ static bool keypad_read(lv_indev_data_t * data)
/*Translate the keys to LittlevGL control characters according to your key definitions*/
switch(act_key) {
case 1:
act_key = LV_GROUP_KEY_NEXT;
act_key = LV_KEY_NEXT;
break;
case 2:
act_key = LV_GROUP_KEY_PREV;
act_key = LV_KEY_PREV;
break;
case 3:
act_key = LV_GROUP_KEY_LEFT;
act_key = LV_KEY_LEFT;
break;
case 4:
act_key = LV_GROUP_KEY_RIGHT;
act_key = LV_KEY_RIGHT;
break;
case 5:
act_key = LV_GROUP_KEY_ENTER;
act_key = LV_KEY_ENTER;
break;
}
@ -342,7 +342,7 @@ static void encoder_init(void)
}
/* Will be called by the library to read the encoder */
static bool encoder_read(lv_indev_data_t * data)
static bool encoder_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
{
data->enc_diff = encoder_diff;
@ -373,7 +373,7 @@ static void button_init(void)
}
/* Will be called by the library to read the button */
static bool button_read(lv_indev_data_t * data)
static bool button_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
{
static uint8_t last_btn = 0;
@ -389,7 +389,7 @@ static bool button_read(lv_indev_data_t * data)
}
/*Save the last pressed button's ID*/
data->btn = last_btn;
data->btn_id = last_btn;
/*Return `false` because we are not buffering and no more data to read*/
return false;
@ -421,4 +421,8 @@ static bool button_is_pressed(uint8_t id)
return false;
}
#else /* Enable this file at the top */
/* This dummy typedef exists purely to silence -Wpedantic. */
typedef int keep_pedantic_happy;
#endif

2455
scripts/Doxyfile Normal file

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,47 @@
import argparse
from argparse import RawTextHelpFormatter
import os
import sys
parser = argparse.ArgumentParser(description="""Create fonts for LittelvGL including the built-in symbols. lv_font_conv needs to be installed. See https://github.com/littlevgl/lv_font_conv
Example: python built_in_font_gen.py --size 16 -o lv_font_roboto_16.c --bpp 4 -r 0x20-0x7F""", formatter_class=RawTextHelpFormatter)
parser.add_argument('-s', '--size',
type=int,
metavar = 'px',
nargs='?',
help='Size of the font in px')
parser.add_argument('--bpp',
type=int,
metavar = '1,2,4',
nargs='?',
help='Bit per pixel')
parser.add_argument('-r', '--range',
nargs='+',
metavar = 'start-end',
default='0x20-0x7F',
help='Ranges and/or characters to include. Default is 0x20-7F (ASCII). E.g. -r 0x20-0x7F, 0x200, 324')
parser.add_argument('--font',
metavar = 'file',
nargs='?',
default='Roboto-Regular.woff',
help='A TTF or WOFF file')
parser.add_argument('-o', '--output',
nargs='?',
metavar='file',
help='Output file name. E.g. my_font_20.c')
parser.add_argument('--compressed', action='store_true',
help='Compress the bitmaps')
args = parser.parse_args()
if args.compressed == False:
compr = "--no-compress --no-prefilter"
else:
compr = ""
#Built in symbols
syms = "61441,61448,61451,61452,61453,61457,61459,61460,61461,61465,61468,61473,61478,61479,61480,61502,61504,61512,61515,61516,61517,61521,61522,61523,61524,61543,61544,61553,61556,61559,61560,61561,61563,61587,61589,61636,61637,61639,61671,61683,61724,61732,61787,61931,62016,62017,62018,62019,62020,62099"
#Run the command
cmd = "lv_font_conv {} --bpp {} --size {} --font ./Roboto-Regular.woff -r {} --font FontAwesome.ttf -r {} --format lvgl -o {} --force-fast-kern-format".format(compr, args.bpp, args.size, args.range[0], syms, args.output)
os.system(cmd)

13
scripts/clang-formatter.sh Executable file
View File

@ -0,0 +1,13 @@
clang-format-7 -style=file ../src/lv_core/*.c -i
clang-format-7 -style=file ../src/lv_draw/*.c -i
clang-format-7 -style=file ../src/lv_hal/*.c -i
clang-format-7 -style=file ../src/lv_misc/*.c -i
clang-format-7 -style=file ../src/lv_objx/*.c -i
clang-format-7 -style=file ../src/lv_themes/*.c -i
clang-format-7 -style=file ../src/lv_core/*.h -i
clang-format-7 -style=file ../src/lv_draw/*.h -i
clang-format-7 -style=file ../src/lv_hal/*.h -i
clang-format-7 -style=file ../src/lv_misc/*.h -i
clang-format-7 -style=file ../src/lv_objx/*.h -i
clang-format-7 -style=file ../src/lv_themes/*.h -i

2
scripts/cppcheck_run.sh Executable file
View File

@ -0,0 +1,2 @@
cppcheck --template="{severity}\t{file}:{line}\t{id}: {message}" --enable=all ../src/ --output-file=cppcheck_res.txt --suppress=unusedFunction --suppress=preprocessorErrorDirective --force

View File

@ -5,8 +5,8 @@ Generates a chechker file for lv_conf.h from lv_conf_templ.h define all the not
import re
fin = open("lv_conf_templ.h", "r");
fout = open("lv_conf_checker.h", "w");
fin = open("../lv_conf_template.h", "r");
fout = open("../src/lv_conf_checker.h", "w");
fout.write(
@ -42,6 +42,8 @@ for i in inlines:
fout.write('#ifndef ' + splitted[1] + '\n')
fout.write(i + '\n')
fout.write('#endif\n')
elif(re.search('^ *typedef .*;.*$', i)):
continue; #igonre typedefs to avoide redeclaration
else:
fout.write(i + '\n')

703
src/lv_conf_checker.h Normal file
View File

@ -0,0 +1,703 @@
/**
* GENERATED FILE, DO NOT EDIT IT!
* @file lv_conf_checker.h
* Make sure all the defines of lv_conf.h have a default value
**/
#ifndef LV_CONF_CHECKER_H
#define LV_CONF_CHECKER_H
/* clang-format off */
#include <stdint.h>
/*====================
Graphical settings
*====================*/
/* Maximal horizontal and vertical resolution to support by the library.*/
#ifndef LV_HOR_RES_MAX
#define LV_HOR_RES_MAX (480)
#endif
#ifndef LV_VER_RES_MAX
#define LV_VER_RES_MAX (320)
#endif
/* Color depth:
* - 1: 1 byte per pixel
* - 8: RGB233
* - 16: RGB565
* - 32: ARGB8888
*/
#ifndef LV_COLOR_DEPTH
#define LV_COLOR_DEPTH 16
#endif
/* Swap the 2 bytes of RGB565 color.
* Useful if the display has a 8 bit interface (e.g. SPI)*/
#ifndef LV_COLOR_16_SWAP
#define LV_COLOR_16_SWAP 0
#endif
/* 1: Enable screen transparency.
* Useful for OSD or other overlapping GUIs.
* Requires `LV_COLOR_DEPTH = 32` colors and the screen's style should be modified: `style.body.opa = ...`*/
#ifndef LV_COLOR_SCREEN_TRANSP
#define LV_COLOR_SCREEN_TRANSP 0
#endif
/*Images pixels with this color will not be drawn (with chroma keying)*/
#ifndef LV_COLOR_TRANSP
#define LV_COLOR_TRANSP LV_COLOR_LIME /*LV_COLOR_LIME: pure green*/
#endif
/* Enable anti-aliasing (lines, and radiuses will be smoothed) */
#ifndef LV_ANTIALIAS
#define LV_ANTIALIAS 1
#endif
/* Default display refresh period.
* Can be changed in the display driver (`lv_disp_drv_t`).*/
#ifndef LV_DISP_DEF_REFR_PERIOD
#define LV_DISP_DEF_REFR_PERIOD 30 /*[ms]*/
#endif
/* Dot Per Inch: used to initialize default sizes.
* E.g. a button with width = LV_DPI / 2 -> half inch wide
* (Not so important, you can adjust it to modify default sizes and spaces)*/
#ifndef LV_DPI
#define LV_DPI 100 /*[px]*/
#endif
/* Type of coordinates. Should be `int16_t` (or `int32_t` for extreme cases) */
/*=========================
Memory manager settings
*=========================*/
/* LittelvGL's internal memory manager's settings.
* The graphical objects and other related data are stored here. */
/* 1: use custom malloc/free, 0: use the built-in `lv_mem_alloc` and `lv_mem_free` */
#ifndef LV_MEM_CUSTOM
#define LV_MEM_CUSTOM 0
#endif
#if LV_MEM_CUSTOM == 0
/* Size of the memory used by `lv_mem_alloc` in bytes (>= 2kB)*/
#ifndef LV_MEM_SIZE
# define LV_MEM_SIZE (32U * 1024U)
#endif
/* Complier prefix for a big array declaration */
#ifndef LV_MEM_ATTR
# define LV_MEM_ATTR
#endif
/* Set an address for the memory pool instead of allocating it as an array.
* Can be in external SRAM too. */
#ifndef LV_MEM_ADR
# define LV_MEM_ADR 0
#endif
/* Automatically defrag. on free. Defrag. means joining the adjacent free cells. */
#ifndef LV_MEM_AUTO_DEFRAG
# define LV_MEM_AUTO_DEFRAG 1
#endif
#else /*LV_MEM_CUSTOM*/
#ifndef LV_MEM_CUSTOM_INCLUDE
# define LV_MEM_CUSTOM_INCLUDE <stdlib.h> /*Header for the dynamic memory function*/
#endif
#ifndef LV_MEM_CUSTOM_ALLOC
# define LV_MEM_CUSTOM_ALLOC malloc /*Wrapper to malloc*/
#endif
#ifndef LV_MEM_CUSTOM_FREE
# define LV_MEM_CUSTOM_FREE free /*Wrapper to free*/
#endif
#endif /*LV_MEM_CUSTOM*/
/* Garbage Collector settings
* Used if lvgl is binded to higher level language and the memory is managed by that language */
#ifndef LV_ENABLE_GC
#define LV_ENABLE_GC 0
#endif
#if LV_ENABLE_GC != 0
#ifndef LV_GC_INCLUDE
# define LV_GC_INCLUDE "gc.h" /*Include Garbage Collector related things*/
#endif
#ifndef LV_MEM_CUSTOM_REALLOC
# define LV_MEM_CUSTOM_REALLOC your_realloc /*Wrapper to realloc*/
#endif
#ifndef LV_MEM_CUSTOM_GET_SIZE
# define LV_MEM_CUSTOM_GET_SIZE your_mem_get_size /*Wrapper to lv_mem_get_size*/
#endif
#endif /* LV_ENABLE_GC */
/*=======================
Input device settings
*=======================*/
/* Input device default settings.
* Can be changed in the Input device driver (`lv_indev_drv_t`)*/
/* Input device read period in milliseconds */
#ifndef LV_INDEV_DEF_READ_PERIOD
#define LV_INDEV_DEF_READ_PERIOD 30
#endif
/* Drag threshold in pixels */
#ifndef LV_INDEV_DEF_DRAG_LIMIT
#define LV_INDEV_DEF_DRAG_LIMIT 10
#endif
/* Drag throw slow-down in [%]. Greater value -> faster slow-down */
#ifndef LV_INDEV_DEF_DRAG_THROW
#define LV_INDEV_DEF_DRAG_THROW 20
#endif
/* Long press time in milliseconds.
* Time to send `LV_EVENT_LONG_PRESSSED`) */
#ifndef LV_INDEV_DEF_LONG_PRESS_TIME
#define LV_INDEV_DEF_LONG_PRESS_TIME 400
#endif
/* Repeated trigger period in long press [ms]
* Time between `LV_EVENT_LONG_PRESSED_REPEAT */
#ifndef LV_INDEV_DEF_LONG_PRESS_REP_TIME
#define LV_INDEV_DEF_LONG_PRESS_REP_TIME 100
#endif
/*==================
* Feature usage
*==================*/
/*1: Enable the Animations */
#ifndef LV_USE_ANIMATION
#define LV_USE_ANIMATION 1
#endif
#if LV_USE_ANIMATION
/*Declare the type of the user data of animations (can be e.g. `void *`, `int`, `struct`)*/
#endif
/* 1: Enable shadow drawing*/
#ifndef LV_USE_SHADOW
#define LV_USE_SHADOW 1
#endif
/* 1: Enable object groups (for keyboard/encoder navigation) */
#ifndef LV_USE_GROUP
#define LV_USE_GROUP 1
#endif
#if LV_USE_GROUP
#endif /*LV_USE_GROUP*/
/* 1: Enable GPU interface*/
#ifndef LV_USE_GPU
#define LV_USE_GPU 1
#endif
/* 1: Enable file system (might be required for images */
#ifndef LV_USE_FILESYSTEM
#define LV_USE_FILESYSTEM 1
#endif
#if LV_USE_FILESYSTEM
/*Declare the type of the user data of file system drivers (can be e.g. `void *`, `int`, `struct`)*/
#endif
/*1: Add a `user_data` to drivers and objects*/
#ifndef LV_USE_USER_DATA
#define LV_USE_USER_DATA 1
#endif
/*========================
* Image decoder and cache
*========================*/
/* 1: Enable indexed (palette) images */
#ifndef LV_IMG_CF_INDEXED
#define LV_IMG_CF_INDEXED 1
#endif
/* 1: Enable alpha indexed images */
#ifndef LV_IMG_CF_ALPHA
#define LV_IMG_CF_ALPHA 1
#endif
/* Default image cache size. Image caching keeps the images opened.
* If only the built-in image formats are used there is no real advantage of caching.
* (I.e. no new image decoder is added)
* With complex image decoders (e.g. PNG or JPG) caching can save the continuous open/decode of images.
* However the opened images might consume additional RAM.
* LV_IMG_CACHE_DEF_SIZE must be >= 1 */
#ifndef LV_IMG_CACHE_DEF_SIZE
#define LV_IMG_CACHE_DEF_SIZE 1
#endif
/*Declare the type of the user data of image decoder (can be e.g. `void *`, `int`, `struct`)*/
/*=====================
* Compiler settings
*====================*/
/* Define a custom attribute to `lv_tick_inc` function */
#ifndef LV_ATTRIBUTE_TICK_INC
#define LV_ATTRIBUTE_TICK_INC
#endif
/* Define a custom attribute to `lv_task_handler` function */
#ifndef LV_ATTRIBUTE_TASK_HANDLER
#define LV_ATTRIBUTE_TASK_HANDLER
#endif
/* With size optimization (-Os) the compiler might not align data to
* 4 or 8 byte boundary. This alignment will be explicitly applied where needed.
* E.g. __attribute__((aligned(4))) */
#ifndef LV_ATTRIBUTE_MEM_ALIGN
#define LV_ATTRIBUTE_MEM_ALIGN
#endif
/* Attribute to mark large constant arrays for example
* font's bitmaps */
#ifndef LV_ATTRIBUTE_LARGE_CONST
#define LV_ATTRIBUTE_LARGE_CONST
#endif
/*===================
* HAL settings
*==================*/
/* 1: use a custom tick source.
* It removes the need to manually update the tick with `lv_tick_inc`) */
#ifndef LV_TICK_CUSTOM
#define LV_TICK_CUSTOM 0
#endif
#if LV_TICK_CUSTOM == 1
#ifndef LV_TICK_CUSTOM_INCLUDE
#define LV_TICK_CUSTOM_INCLUDE "something.h" /*Header for the sys time function*/
#endif
#ifndef LV_TICK_CUSTOM_SYS_TIME_EXPR
#define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current systime in ms*/
#endif
#endif /*LV_TICK_CUSTOM*/
/*================
* Log settings
*===============*/
/*1: Enable the log module*/
#ifndef LV_USE_LOG
#define LV_USE_LOG 1
#endif
#if LV_USE_LOG
/* How important log should be added:
* LV_LOG_LEVEL_TRACE A lot of logs to give detailed information
* LV_LOG_LEVEL_INFO Log important events
* LV_LOG_LEVEL_WARN Log if something unwanted happened but didn't cause a problem
* LV_LOG_LEVEL_ERROR Only critical issue, when the system may fail
*/
#ifndef LV_LOG_LEVEL
# define LV_LOG_LEVEL LV_LOG_LEVEL_WARN
#endif
/* 1: Print the log with 'printf';
* 0: user need to register a callback with `lv_log_register_print`*/
#ifndef LV_LOG_PRINTF
# define LV_LOG_PRINTF 0
#endif
#endif /*LV_USE_LOG*/
/*================
* THEME USAGE
*================*/
#ifndef LV_THEME_LIVE_UPDATE
#define LV_THEME_LIVE_UPDATE 0 /*1: Allow theme switching at run time. Uses 8..10 kB of RAM*/
#endif
#ifndef LV_USE_THEME_TEMPL
#define LV_USE_THEME_TEMPL 1 /*Just for test*/
#endif
#ifndef LV_USE_THEME_DEFAULT
#define LV_USE_THEME_DEFAULT 1 /*Built mainly from the built-in styles. Consumes very few RAM*/
#endif
#ifndef LV_USE_THEME_ALIEN
#define LV_USE_THEME_ALIEN 1 /*Dark futuristic theme*/
#endif
#ifndef LV_USE_THEME_NIGHT
#define LV_USE_THEME_NIGHT 1 /*Dark elegant theme*/
#endif
#ifndef LV_USE_THEME_MONO
#define LV_USE_THEME_MONO 1 /*Mono color theme for monochrome displays*/
#endif
#ifndef LV_USE_THEME_MATERIAL
#define LV_USE_THEME_MATERIAL 1 /*Flat theme with bold colors and light shadows*/
#endif
#ifndef LV_USE_THEME_ZEN
#define LV_USE_THEME_ZEN 1 /*Peaceful, mainly light theme */
#endif
#ifndef LV_USE_THEME_NEMO
#define LV_USE_THEME_NEMO 1 /*Water-like theme based on the movie "Finding Nemo"*/
#endif
/*==================
* FONT USAGE
*===================*/
/* The built-in fonts contains the ASCII range and some Symbols with 4 bit-per-pixel.
* The symbols are available via `LV_SYMBOL_...` defines
* More info about fonts: https://docs.littlevgl.com/#Fonts
* To create a new font go to: https://littlevgl.com/ttf-font-to-c-array
*/
/* Robot fonts with bpp = 4
* https://fonts.google.com/specimen/Roboto */
#ifndef LV_FONT_ROBOTO_12
#define LV_FONT_ROBOTO_12 0
#endif
#ifndef LV_FONT_ROBOTO_16
#define LV_FONT_ROBOTO_16 1
#endif
#ifndef LV_FONT_ROBOTO_22
#define LV_FONT_ROBOTO_22 0
#endif
#ifndef LV_FONT_ROBOTO_28
#define LV_FONT_ROBOTO_28 0
#endif
/*Pixel perfect monospace font
* http://pelulamu.net/unscii/ */
#ifndef LV_FONT_UNSCII_8
#define LV_FONT_UNSCII_8 0
#endif
/* Optionally declare your custom fonts here.
* You can use these fonts as default font too
* and they will be available globally. E.g.
* #define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(my_font_1) \
* LV_FONT_DECLARE(my_font_2)
*/
#ifndef LV_FONT_CUSTOM_DECLARE
#define LV_FONT_CUSTOM_DECLARE
#endif
/*Always set a default font from the built-in fonts*/
#ifndef LV_FONT_DEFAULT
#define LV_FONT_DEFAULT &lv_font_roboto_16
#endif
/*Declare the type of the user data of fonts (can be e.g. `void *`, `int`, `struct`)*/
/*=================
* Text settings
*=================*/
/* Select a character encoding for strings.
* Your IDE or editor should have the same character encoding
* - LV_TXT_ENC_UTF8
* - LV_TXT_ENC_ASCII
* */
#ifndef LV_TXT_ENC
#define LV_TXT_ENC LV_TXT_ENC_UTF8
#endif
/*Can break (wrap) texts on these chars*/
#ifndef LV_TXT_BREAK_CHARS
#define LV_TXT_BREAK_CHARS " ,.;:-_"
#endif
/*===================
* LV_OBJ SETTINGS
*==================*/
/*Declare the type of the user data of object (can be e.g. `void *`, `int`, `struct`)*/
/*1: enable `lv_obj_realaign()` based on `lv_obj_align()` parameters*/
#ifndef LV_USE_OBJ_REALIGN
#define LV_USE_OBJ_REALIGN 1
#endif
/* Enable to make the object clickable on a larger area.
* LV_EXT_CLICK_AREA_OFF or 0: Disable this feature
* LV_EXT_CLICK_AREA_TINY: The extra area can be adjusted horizontally and vertically (0..255 px)
* LV_EXT_CLICK_AREA_FULL: The extra area can be adjusted in all 4 directions (-32k..+32k px)
*/
#ifndef LV_USE_EXT_CLICK_AREA
#define LV_USE_EXT_CLICK_AREA LV_EXT_CLICK_AREA_OFF
#endif
/*==================
* LV OBJ X USAGE
*================*/
/*
* Documentation of the object types: https://docs.littlevgl.com/#Object-types
*/
/*Arc (dependencies: -)*/
#ifndef LV_USE_ARC
#define LV_USE_ARC 1
#endif
/*Bar (dependencies: -)*/
#ifndef LV_USE_BAR
#define LV_USE_BAR 1
#endif
/*Button (dependencies: lv_cont*/
#ifndef LV_USE_BTN
#define LV_USE_BTN 1
#endif
#if LV_USE_BTN != 0
/*Enable button-state animations - draw a circle on click (dependencies: LV_USE_ANIMATION)*/
#ifndef LV_BTN_INK_EFFECT
# define LV_BTN_INK_EFFECT 1
#endif
#endif
/*Button matrix (dependencies: -)*/
#ifndef LV_USE_BTNM
#define LV_USE_BTNM 1
#endif
/*Calendar (dependencies: -)*/
#ifndef LV_USE_CALENDAR
#define LV_USE_CALENDAR 1
#endif
/*Canvas (dependencies: lv_img)*/
#ifndef LV_USE_CANVAS
#define LV_USE_CANVAS 1
#endif
/*Check box (dependencies: lv_btn, lv_label)*/
#ifndef LV_USE_CB
#define LV_USE_CB 1
#endif
/*Chart (dependencies: -)*/
#ifndef LV_USE_CHART
#define LV_USE_CHART 1
#endif
#if LV_USE_CHART
#ifndef LV_CHART_AXIS_TICK_LABEL_MAX_LEN
# define LV_CHART_AXIS_TICK_LABEL_MAX_LEN 20
#endif
#endif
/*Container (dependencies: -*/
#ifndef LV_USE_CONT
#define LV_USE_CONT 1
#endif
/*Drop down list (dependencies: lv_page, lv_label, lv_symbol_def.h)*/
#ifndef LV_USE_DDLIST
#define LV_USE_DDLIST 1
#endif
#if LV_USE_DDLIST != 0
/*Open and close default animation time [ms] (0: no animation)*/
#ifndef LV_DDLIST_DEF_ANIM_TIME
# define LV_DDLIST_DEF_ANIM_TIME 200
#endif
#endif
/*Gauge (dependencies:lv_bar, lv_lmeter)*/
#ifndef LV_USE_GAUGE
#define LV_USE_GAUGE 1
#endif
/*Image (dependencies: lv_label*/
#ifndef LV_USE_IMG
#define LV_USE_IMG 1
#endif
/*Image Button (dependencies: lv_btn*/
#ifndef LV_USE_IMGBTN
#define LV_USE_IMGBTN 1
#endif
#if LV_USE_IMGBTN
/*1: The imgbtn requires left, mid and right parts and the width can be set freely*/
#ifndef LV_IMGBTN_TILED
# define LV_IMGBTN_TILED 0
#endif
#endif
/*Keyboard (dependencies: lv_btnm)*/
#ifndef LV_USE_KB
#define LV_USE_KB 1
#endif
/*Label (dependencies: -*/
#ifndef LV_USE_LABEL
#define LV_USE_LABEL 1
#endif
#if LV_USE_LABEL != 0
/*Hor, or ver. scroll speed [px/sec] in 'LV_LABEL_LONG_ROLL/ROLL_CIRC' mode*/
#ifndef LV_LABEL_DEF_SCROLL_SPEED
# define LV_LABEL_DEF_SCROLL_SPEED 25
#endif
/* Waiting period at beginning/end of animation cycle */
#ifndef LV_LABEL_WAIT_CHAR_COUNT
# define LV_LABEL_WAIT_CHAR_COUNT 3
#endif
/*Enable selecting text of the label */
#ifndef LV_LABEL_TEXT_SEL
# define LV_LABEL_TEXT_SEL 0
#endif
/*Store extra some info in labels (12 bytes) to speed up drawing of very long texts*/
#ifndef LV_LABEL_LONG_TXT_HINT
# define LV_LABEL_LONG_TXT_HINT 0
#endif
#endif
/*LED (dependencies: -)*/
#ifndef LV_USE_LED
#define LV_USE_LED 1
#endif
/*Line (dependencies: -*/
#ifndef LV_USE_LINE
#define LV_USE_LINE 1
#endif
/*List (dependencies: lv_page, lv_btn, lv_label, (lv_img optionally for icons ))*/
#ifndef LV_USE_LIST
#define LV_USE_LIST 1
#endif
#if LV_USE_LIST != 0
/*Default animation time of focusing to a list element [ms] (0: no animation) */
#ifndef LV_LIST_DEF_ANIM_TIME
# define LV_LIST_DEF_ANIM_TIME 100
#endif
#endif
/*Line meter (dependencies: *;)*/
#ifndef LV_USE_LMETER
#define LV_USE_LMETER 1
#endif
/*Message box (dependencies: lv_rect, lv_btnm, lv_label)*/
#ifndef LV_USE_MBOX
#define LV_USE_MBOX 1
#endif
/*Page (dependencies: lv_cont)*/
#ifndef LV_USE_PAGE
#define LV_USE_PAGE 1
#endif
#if LV_USE_PAGE != 0
/*Focus default animation time [ms] (0: no animation)*/
#ifndef LV_PAGE_DEF_ANIM_TIME
# define LV_PAGE_DEF_ANIM_TIME 400
#endif
#endif
/*Preload (dependencies: lv_arc, lv_anim)*/
#ifndef LV_USE_PRELOAD
#define LV_USE_PRELOAD 1
#endif
#if LV_USE_PRELOAD != 0
#ifndef LV_PRELOAD_DEF_ARC_LENGTH
# define LV_PRELOAD_DEF_ARC_LENGTH 60 /*[deg]*/
#endif
#ifndef LV_PRELOAD_DEF_SPIN_TIME
# define LV_PRELOAD_DEF_SPIN_TIME 1000 /*[ms]*/
#endif
#ifndef LV_PRELOAD_DEF_ANIM
# define LV_PRELOAD_DEF_ANIM LV_PRELOAD_TYPE_SPINNING_ARC
#endif
#endif
/*Roller (dependencies: lv_ddlist)*/
#ifndef LV_USE_ROLLER
#define LV_USE_ROLLER 1
#endif
#if LV_USE_ROLLER != 0
/*Focus animation time [ms] (0: no animation)*/
#ifndef LV_ROLLER_DEF_ANIM_TIME
# define LV_ROLLER_DEF_ANIM_TIME 200
#endif
/*Number of extra "pages" when the roller is infinite*/
#ifndef LV_ROLLER_INF_PAGES
# define LV_ROLLER_INF_PAGES 7
#endif
#endif
/*Slider (dependencies: lv_bar)*/
#ifndef LV_USE_SLIDER
#define LV_USE_SLIDER 1
#endif
/*Spinbox (dependencies: lv_ta)*/
#ifndef LV_USE_SPINBOX
#define LV_USE_SPINBOX 1
#endif
/*Switch (dependencies: lv_slider)*/
#ifndef LV_USE_SW
#define LV_USE_SW 1
#endif
/*Text area (dependencies: lv_label, lv_page)*/
#ifndef LV_USE_TA
#define LV_USE_TA 1
#endif
#if LV_USE_TA != 0
#ifndef LV_TA_DEF_CURSOR_BLINK_TIME
# define LV_TA_DEF_CURSOR_BLINK_TIME 400 /*ms*/
#endif
#ifndef LV_TA_DEF_PWD_SHOW_TIME
# define LV_TA_DEF_PWD_SHOW_TIME 1500 /*ms*/
#endif
#endif
/*Table (dependencies: lv_label)*/
#ifndef LV_USE_TABLE
#define LV_USE_TABLE 1
#endif
#if LV_USE_TABLE
#ifndef LV_TABLE_COL_MAX
# define LV_TABLE_COL_MAX 12
#endif
#endif
/*Tab (dependencies: lv_page, lv_btnm)*/
#ifndef LV_USE_TABVIEW
#define LV_USE_TABVIEW 1
#endif
# if LV_USE_TABVIEW != 0
/*Time of slide animation [ms] (0: no animation)*/
#ifndef LV_TABVIEW_DEF_ANIM_TIME
# define LV_TABVIEW_DEF_ANIM_TIME 300
#endif
#endif
/*Tileview (dependencies: lv_page) */
#ifndef LV_USE_TILEVIEW
#define LV_USE_TILEVIEW 1
#endif
#if LV_USE_TILEVIEW
/*Time of slide animation [ms] (0: no animation)*/
#ifndef LV_TILEVIEW_DEF_ANIM_TIME
# define LV_TILEVIEW_DEF_ANIM_TIME 300
#endif
#endif
/*Window (dependencies: lv_cont, lv_btn, lv_label, lv_img, lv_page)*/
#ifndef LV_USE_WIN
#define LV_USE_WIN 1
#endif
/*==================
* Non-user section
*==================*/
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) /* Disable warnings for Visual Studio*/
#ifndef _CRT_SECURE_NO_WARNINGS
# define _CRT_SECURE_NO_WARNINGS
#endif
#endif
#endif /*LV_CONF_CHECKER_H*/

11
src/lv_core/lv_core.mk Normal file
View File

@ -0,0 +1,11 @@
CSRCS += lv_group.c
CSRCS += lv_indev.c
CSRCS += lv_disp.c
CSRCS += lv_obj.c
CSRCS += lv_refr.c
CSRCS += lv_style.c
DEPPATH += --dep-path $(LVGL_DIR)/lvgl/src/lv_core
VPATH += :$(LVGL_DIR)/lvgl/src/lv_core
CFLAGS += "-I$(LVGL_DIR)/lvgl/src/lv_core"

Some files were not shown because too many files have changed in this diff Show More