mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
Merge branch 'color_picker_6' of https://github.com/paulpv/lvgl into paulpv-color_picker_6
This commit is contained in:
commit
6e9f10451d
@ -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;
|
||||
|
1
lvgl.h
1
lvgl.h
@ -45,6 +45,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"
|
||||
|
@ -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,
|
||||
@ -100,7 +99,7 @@ void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, cons
|
||||
uint32_t r_act_sqr = xi * xi + yi * yi;
|
||||
if(r_act_sqr > r_out_sqr) continue;
|
||||
|
||||
deg_base = fast_atan2(xi, yi) - 180;
|
||||
deg_base = lv_atan2(xi, yi) - 180;
|
||||
|
||||
deg = 180 + deg_base;
|
||||
if(deg_test(deg, start_angle, end_angle)) {
|
||||
|
@ -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;
|
||||
|
@ -94,6 +94,110 @@ 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 sqrt of an integer.
|
||||
* @param x
|
||||
* @return the sqrt of x
|
||||
*/
|
||||
uint16_t lv_sqrt(uint32_t x)
|
||||
{
|
||||
uint16_t res=0;
|
||||
uint16_t add= 0x8000;
|
||||
int i;
|
||||
for(i=0;i<16;i++)
|
||||
{
|
||||
uint16_t temp=res | add;
|
||||
uint32_t g2=temp*temp;
|
||||
if (x>=g2)
|
||||
{
|
||||
res=temp;
|
||||
}
|
||||
add>>=1;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
@ -54,6 +54,21 @@ 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 sqrt of an integer.
|
||||
* @param x
|
||||
* @return the sqrt of x
|
||||
*/
|
||||
uint16_t lv_sqrt(uint32_t x);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
1974
src/lv_objx/lv_cpicker.c
Normal file
1974
src/lv_objx/lv_cpicker.c
Normal file
File diff suppressed because it is too large
Load Diff
233
src/lv_objx/lv_cpicker.h
Normal file
233
src/lv_objx/lv_cpicker.h
Normal file
@ -0,0 +1,233 @@
|
||||
/**
|
||||
* @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
|
||||
**********************/
|
||||
/*Data of colorpicker*/
|
||||
typedef struct {
|
||||
uint16_t hue;
|
||||
uint8_t saturation;
|
||||
uint8_t value;
|
||||
struct
|
||||
{
|
||||
lv_style_t * style;
|
||||
uint8_t type;
|
||||
} indicator;
|
||||
uint16_t prev_hue;
|
||||
uint8_t prev_saturation;
|
||||
uint8_t prev_value;
|
||||
uint16_t prev_pos;
|
||||
uint8_t color_mode:2;
|
||||
uint8_t color_mode_fixed:1;
|
||||
uint8_t type:1;
|
||||
uint32_t last_click;
|
||||
lv_area_t rect_preview_area;
|
||||
lv_area_t rect_gradient_area;
|
||||
lv_coord_t rect_gradient_w;
|
||||
lv_coord_t rect_gradient_h;
|
||||
} lv_cpicker_ext_t;
|
||||
|
||||
/*Styles*/
|
||||
enum {
|
||||
LV_CPICKER_STYLE_MAIN,
|
||||
LV_CPICKER_STYLE_INDICATOR,
|
||||
};
|
||||
typedef uint8_t lv_cpicker_style_t;
|
||||
|
||||
enum {
|
||||
LV_CPICKER_INDICATOR_NONE,
|
||||
LV_CPICKER_INDICATOR_LINE,
|
||||
LV_CPICKER_INDICATOR_CIRCLE,
|
||||
LV_CPICKER_INDICATOR_IN
|
||||
};
|
||||
typedef uint8_t lv_cpicker_indicator_type_t;
|
||||
|
||||
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;
|
||||
|
||||
/**********************
|
||||
* 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 * chart, 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 a type of a colorpicker indicator.
|
||||
* @param cpicker pointer to colorpicker object
|
||||
* @param type indicator type
|
||||
*/
|
||||
void lv_cpicker_set_indicator_type(lv_obj_t * cpicker, lv_cpicker_indicator_type_t type);
|
||||
|
||||
/**
|
||||
* Set the current hue of a colorpicker.
|
||||
* @param cpicker pointer to colorpicker object
|
||||
* @param hue current selected hue
|
||||
*/
|
||||
void 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
|
||||
*/
|
||||
void 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
|
||||
*/
|
||||
void lv_cpicker_set_value(lv_obj_t * cpicker, uint8_t val);
|
||||
|
||||
/**
|
||||
* Set the current color of a colorpicker.
|
||||
* @param cpicker pointer to colorpicker object
|
||||
* @param color current selected color
|
||||
*/
|
||||
void 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);
|
||||
|
||||
/*=====================
|
||||
* 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 style pointer to the style
|
||||
*/
|
||||
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 hue 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 color of a colorpicker.
|
||||
* @param cpicker pointer to colorpicker object
|
||||
* @return color current selected color
|
||||
*/
|
||||
lv_color_t lv_cpicker_get_color(lv_obj_t * cpicker);
|
||||
|
||||
/*=====================
|
||||
* Other functions
|
||||
*====================*/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /*LV_USE_CPICKER*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_CPICKER_H*/
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user