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

Merge branch 'feat-cpicker' into dev-6.1

This commit is contained in:
Gabor Kiss-Vamosi 2019-11-06 05:27:52 +01:00
commit a76e65db88
13 changed files with 1445 additions and 6 deletions

View File

@ -188,8 +188,8 @@ Styles can be assigned to the objects to changed their appearance. A style descr
You can create a new style like this:
```c
static lv_style_t style1; /*Declare a new style. Should be `static`*/
lv_style_copy(&style1, &lv_style_plain); /*Copy a buil-in style*/
static lv_style_t style1; /*Declare a new style. Should be `static`*/
lv_style_copy(&style1, &lv_style_plain); /*Copy a built-in style*/
style1.body.main_color = LV_COLOR_RED; /*Main color*/
style1.body.grad_color = lv_color_hex(0xffd83c) /*Gradient color (orange)*/
style1.body.radius = 3;

View File

@ -425,6 +425,9 @@ typedef void * lv_obj_user_data_t;
/*Container (dependencies: -*/
#define LV_USE_CONT 1
/*Color picker (dependencies: -*/
#define LV_USE_CPICKER 1
/*Drop down list (dependencies: lv_page, lv_label, lv_symbol_def.h)*/
#define LV_USE_DDLIST 1
#if LV_USE_DDLIST != 0

1
lvgl.h
View File

@ -46,6 +46,7 @@ extern "C" {
#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_cpicker.h"
#include "src/lv_objx/lv_bar.h"
#include "src/lv_objx/lv_slider.h"
#include "src/lv_objx/lv_led.h"

View File

@ -595,6 +595,11 @@
#define LV_USE_CONT 1
#endif
/*Color picker (dependencies: -*/
#ifndef LV_USE_CPICKER
#define LV_USE_CPICKER 1
#endif
/*Drop down list (dependencies: lv_page, lv_label, lv_symbol_def.h)*/
#ifndef LV_USE_DDLIST
#define LV_USE_DDLIST 1

View File

@ -20,7 +20,6 @@
/**********************
* STATIC PROTOTYPES
**********************/
static uint16_t fast_atan2(int x, int y);
static void ver_line(lv_coord_t x, lv_coord_t y, const lv_area_t * mask, lv_coord_t len, lv_color_t color,
lv_opa_t opa);
static void hor_line(lv_coord_t x, lv_coord_t y, const lv_area_t * mask, lv_coord_t len, lv_color_t color,
@ -121,7 +120,7 @@ void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, cons
if(r_act_sqr > r_out_sqr) continue;
#endif
deg_base = fast_atan2(xi, yi) - 180;
deg_base = lv_atan2(xi, yi) - 180;
#if LV_ANTIALIAS
int opa = -1;

View File

@ -45,8 +45,7 @@ static void point_swap(lv_point_t * p1, lv_point_t * p2);
*/
void lv_draw_triangle(const lv_point_t * points, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale)
{
/*Return is the triangle is degenerated*/
/*Return if the triangle is degenerated*/
if(points[0].x == points[1].x && points[0].y == points[1].y) return;
if(points[1].x == points[2].x && points[1].y == points[2].y) return;
if(points[0].x == points[2].x && points[0].y == points[2].y) return;

View File

@ -192,6 +192,19 @@ bool lv_area_is_in(const lv_area_t * ain_p, const lv_area_t * aholder_p)
return is_in;
}
/**
* Increment or decrement an area's size by a single amount
* @param a_p pointer to an area to grow
* @param amount amount to increment the area, or negative to decrement
*/
void lv_area_increment(lv_area_t * a_p, const lv_coord_t amount)
{
a_p->x1 -= amount;
a_p->y1 -= amount;
a_p->x2 += amount;
a_p->y2 += amount;
}
/**********************
* STATIC FUNCTIONS
**********************/

View File

@ -168,6 +168,13 @@ bool lv_area_is_on(const lv_area_t * a1_p, const lv_area_t * a2_p);
*/
bool lv_area_is_in(const lv_area_t * ain_p, const lv_area_t * aholder_p);
/**
* Increment or decrement an area's size by a single amount
* @param a_p pointer to an area to grow
* @param amount amount to increment the area, or negative to decrement
*/
void lv_area_increment(lv_area_t * a_p, const lv_coord_t amount);
/**********************
* MACROS
**********************/

View File

@ -94,6 +94,87 @@ int32_t lv_bezier3(uint32_t t, int32_t u0, int32_t u1, int32_t u2, int32_t u3)
return v1 + v2 + v3 + v4;
}
/**
* Calculate the atan2 of a vector.
* @param x
* @param y
* @return the angle in degree calculated from the given parameters in range of [0..360]
*/
uint16_t lv_atan2(int x, int y)
{
// Fast XY vector to integer degree algorithm - Jan 2011 www.RomanBlack.com
// Converts any XY values including 0 to a degree value that should be
// within +/- 1 degree of the accurate value without needing
// large slow trig functions like ArcTan() or ArcCos().
// NOTE! at least one of the X or Y values must be non-zero!
// This is the full version, for all 4 quadrants and will generate
// the angle in integer degrees from 0-360.
// Any values of X and Y are usable including negative values provided
// they are between -1456 and 1456 so the 16bit multiply does not overflow.
unsigned char negflag;
unsigned char tempdegree;
unsigned char comp;
unsigned int degree; // this will hold the result
//signed int x; // these hold the XY vector at the start
//signed int y; // (and they will be destroyed)
unsigned int ux;
unsigned int uy;
// Save the sign flags then remove signs and get XY as unsigned ints
negflag = 0;
if(x < 0) {
negflag += 0x01; // x flag bit
x = (0 - x); // is now +
}
ux = x; // copy to unsigned var before multiply
if(y < 0) {
negflag += 0x02; // y flag bit
y = (0 - y); // is now +
}
uy = y; // copy to unsigned var before multiply
// 1. Calc the scaled "degrees"
if(ux > uy) {
degree = (uy * 45) / ux; // degree result will be 0-45 range
negflag += 0x10; // octant flag bit
} else {
degree = (ux * 45) / uy; // degree result will be 0-45 range
}
// 2. Compensate for the 4 degree error curve
comp = 0;
tempdegree = degree; // use an unsigned char for speed!
if(tempdegree > 22) { // if top half of range
if(tempdegree <= 44) comp++;
if(tempdegree <= 41) comp++;
if(tempdegree <= 37) comp++;
if(tempdegree <= 32) comp++; // max is 4 degrees compensated
} else { // else is lower half of range
if(tempdegree >= 2) comp++;
if(tempdegree >= 6) comp++;
if(tempdegree >= 10) comp++;
if(tempdegree >= 15) comp++; // max is 4 degrees compensated
}
degree += comp; // degree is now accurate to +/- 1 degree!
// Invert degree if it was X>Y octant, makes 0-45 into 90-45
if(negflag & 0x10) degree = (90 - degree);
// 3. Degree is now 0-90 range for this quadrant,
// need to invert it for whichever quadrant it was in
if(negflag & 0x02) { // if -Y
if(negflag & 0x01) // if -Y -X
degree = (180 + degree);
else // else is -Y +X
degree = (180 - degree);
} else { // else is +Y
if(negflag & 0x01) // if +Y -X
degree = (360 - degree);
}
return degree;
}
/**
* Calculate the integer square root of a number.
* @param num

View File

@ -54,6 +54,14 @@ int16_t lv_trigo_sin(int16_t angle);
*/
int32_t lv_bezier3(uint32_t t, int32_t u0, int32_t u1, int32_t u2, int32_t u3);
/**
* Calculate the atan2 of a vector.
* @param x
* @param y
* @return the angle in degree calculated from the given parameters in range of [0..360]
*/
uint16_t lv_atan2(int x, int y);
/**
* Calculate the integer square root of a number.
* @param num

1059
src/lv_objx/lv_cpicker.c Normal file

File diff suppressed because it is too large Load Diff

263
src/lv_objx/lv_cpicker.h Normal file
View File

@ -0,0 +1,263 @@
/**
* @file lv_cpicker.h
*
*/
#ifndef LV_CPICKER_H
#define LV_CPICKER_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_conf.h"
#else
#include "../../../lv_conf.h"
#endif
#if LV_USE_CPICKER != 0
#include "../lv_core/lv_obj.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
enum {
LV_CPICKER_TYPE_RECT,
LV_CPICKER_TYPE_DISC,
};
typedef uint8_t lv_cpicker_type_t;
enum {
LV_CPICKER_COLOR_MODE_HUE,
LV_CPICKER_COLOR_MODE_SATURATION,
LV_CPICKER_COLOR_MODE_VALUE
};
typedef uint8_t lv_cpicker_color_mode_t;
/*Data of colorpicker*/
typedef struct {
lv_color_hsv_t hsv;
struct {
lv_style_t * style;
lv_point_t pos;
uint8_t colored :1;
} indic;
uint32_t last_click_time;
uint32_t last_change_time;
lv_point_t last_press_point;
lv_cpicker_color_mode_t color_mode :2;
uint8_t color_mode_fixed :1;
lv_cpicker_type_t type :1;
uint8_t preview :1;
} lv_cpicker_ext_t;
/*Styles*/
enum {
LV_CPICKER_STYLE_MAIN,
LV_CPICKER_STYLE_INDICATOR,
};
typedef uint8_t lv_cpicker_style_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Create a colorpicker objects
* @param par pointer to an object, it will be the parent of the new colorpicker
* @param copy pointer to a colorpicker object, if not NULL then the new object will be copied from it
* @return pointer to the created colorpicker
*/
lv_obj_t * lv_cpicker_create(lv_obj_t * par, const lv_obj_t * copy);
/*=====================
* Setter functions
*====================*/
/**
* Set a new type for a colorpicker
* @param cpicker pointer to a colorpicker object
* @param type new type of the colorpicker (from 'lv_cpicker_type_t' enum)
*/
void lv_cpicker_set_type(lv_obj_t * cpicker, lv_cpicker_type_t type);
/**
* Set a style of a colorpicker.
* @param cpicker pointer to colorpicker object
* @param type which style should be set
* @param style pointer to a style
*/
void lv_cpicker_set_style(lv_obj_t * cpicker, lv_cpicker_style_t type, lv_style_t *style);
/**
* Set the current hue of a colorpicker.
* @param cpicker pointer to colorpicker object
* @param hue current selected hue [0..360]
* @return true if changed, otherwise false
*/
bool lv_cpicker_set_hue(lv_obj_t * cpicker, uint16_t hue);
/**
* Set the current saturation of a colorpicker.
* @param cpicker pointer to colorpicker object
* @param saturation current selected saturation [0..100]
* @return true if changed, otherwise false
*/
bool lv_cpicker_set_saturation(lv_obj_t * cpicker, uint8_t saturation);
/**
* Set the current value of a colorpicker.
* @param cpicker pointer to colorpicker object
* @param val current selected value [0..100]
* @return true if changed, otherwise false
*/
bool lv_cpicker_set_value(lv_obj_t * cpicker, uint8_t val);
/**
* Set the current hsv of a colorpicker.
* @param cpicker pointer to colorpicker object
* @param hsv current selected hsv
* @return true if changed, otherwise false
*/
bool lv_cpicker_set_hsv(lv_obj_t * cpicker, lv_color_hsv_t hsv);
/**
* Set the current color of a colorpicker.
* @param cpicker pointer to colorpicker object
* @param color current selected color
* @return true if changed, otherwise false
*/
bool lv_cpicker_set_color(lv_obj_t * cpicker, lv_color_t color);
/**
* Set the current color mode.
* @param cpicker pointer to colorpicker object
* @param mode color mode (hue/sat/val)
*/
void lv_cpicker_set_color_mode(lv_obj_t * cpicker, lv_cpicker_color_mode_t mode);
/**
* Set if the color mode is changed on long press on center
* @param cpicker pointer to colorpicker object
* @param fixed color mode cannot be changed on long press
*/
void lv_cpicker_set_color_mode_fixed(lv_obj_t * cpicker, bool fixed);
/**
* Make the indicator to be colored to the current color
* @param cpicker pointer to colorpicker object
* @param en true: color the indicator; false: not color the indicator
*/
void lv_cpicker_set_indic_colored(lv_obj_t * cpicker, bool en);
/**
* Add a color preview in the middle of the DISC type color picker
* @param cpicker pointer to colorpicker object
* @param en true: enable preview; false: disable preview
*/
void lv_cpicker_set_preview(lv_obj_t * cpicker, bool en);
/*=====================
* Getter functions
*====================*/
/**
* Get the current color mode.
* @param cpicker pointer to colorpicker object
* @return color mode (hue/sat/val)
*/
lv_cpicker_color_mode_t lv_cpicker_get_color_mode(lv_obj_t * cpicker);
/**
* Get if the color mode is changed on long press on center
* @param cpicker pointer to colorpicker object
* @return mode cannot be changed on long press
*/
bool lv_cpicker_get_color_mode_fixed(lv_obj_t * cpicker);
/**
* Get style of a colorpicker.
* @param cpicker pointer to colorpicker object
* @param type which style should be get
* @return pointer to the style
*/
const lv_style_t * lv_cpicker_get_style(const lv_obj_t * cpicker, lv_cpicker_style_t type);
/**
* Get the current hue of a colorpicker.
* @param cpicker pointer to colorpicker object
* @return current selected hue
*/
uint16_t lv_cpicker_get_hue(lv_obj_t * cpicker);
/**
* Get the current saturation of a colorpicker.
* @param cpicker pointer to colorpicker object
* @return current selected saturation
*/
uint8_t lv_cpicker_get_saturation(lv_obj_t * cpicker);
/**
* Get the current hue of a colorpicker.
* @param cpicker pointer to colorpicker object
* @return current selected value
*/
uint8_t lv_cpicker_get_value(lv_obj_t * cpicker);
/**
* Get the current selected hsv of a colorpicker.
* @param cpicker pointer to colorpicker object
* @return current selected hsv
*/
lv_color_hsv_t lv_cpicker_get_hsv(lv_obj_t * cpicker);
/**
* Get the current selected color of a colorpicker.
* @param cpicker pointer to colorpicker object
* @return current selected color
*/
lv_color_t lv_cpicker_get_color(lv_obj_t * cpicker);
/**
* Whether the indicator is colored to the current color or not
* @param cpicker pointer to colorpicker object
* @return true: color the indicator; false: not color the indicator
*/
bool lv_cpicker_get_indic_colored(lv_obj_t * cpicker);
/**
* Whether the preview is enabled or not
* @param cpicker pointer to colorpicker object
* @return en true: preview is enabled; false: preview is disabled
*/
bool lv_cpicker_get_preview(lv_obj_t * cpicker);
/*=====================
* Other functions
*====================*/
/**********************
* MACROS
**********************/
#endif /*LV_USE_CPICKER*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_CPICKER_H*/

View File

@ -1,6 +1,7 @@
CSRCS += lv_arc.c
CSRCS += lv_bar.c
CSRCS += lv_cb.c
CSRCS += lv_cpicker.c
CSRCS += lv_ddlist.c
CSRCS += lv_kb.c
CSRCS += lv_line.c