Initial commit of porting @AloyseTech's color picker from lvgl v5 to v6
This commit is contained in:
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)) {
|
||||
|
||||
@@ -136,7 +136,21 @@ void tri_draw_flat(const lv_point_t * points, const lv_area_t * mask, const lv_s
|
||||
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]);
|
||||
/* LVGLv5
|
||||
/*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;
|
||||
|
||||
/*Chech out of mask* /
|
||||
if(tri[0].x < mask->x1 && tri[1].x < mask->x1 && tri[2].x < mask->x1) return; /*Out of the mask on the left* /
|
||||
if(tri[0].x > mask->x2 && tri[1].x > mask->x2 && tri[2].x > mask->x2) return; /*Out of the mask on the right* /
|
||||
if(tri[0].y < mask->y1 && tri[1].y < mask->y1 && tri[2].y < mask->y1) return; /*Out of the mask on the top* /
|
||||
if(tri[0].y > mask->y2 && tri[1].y > mask->y2 && tri[2].y > mask->y2) return; /*Out of the mask on the bottom* /
|
||||
*/
|
||||
/*Draw the triangle*/
|
||||
lv_point_t edge1;
|
||||
lv_coord_t dx1 = LV_MATH_ABS(tri[0].x - tri[1].x);
|
||||
|
||||
@@ -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
|
||||
**********************/
|
||||
|
||||
1907
src/lv_objx/lv_cpicker.c
Normal file
1907
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 {
|
||||
/*New data for this type */
|
||||
uint16_t hue;
|
||||
uint8_t saturation;
|
||||
uint8_t value;
|
||||
struct
|
||||
{
|
||||
lv_style_t * style;
|
||||
uint8_t type;
|
||||
}ind;
|
||||
//LVGLv5 lv_action_t value_changed;
|
||||
uint16_t prev_hue;
|
||||
uint16_t prev_saturation;
|
||||
uint16_t prev_value;
|
||||
uint16_t prev_pos;
|
||||
uint8_t wheel_mode:2;
|
||||
uint8_t wheel_fixed:1;
|
||||
uint8_t type:1;
|
||||
uint32_t last_clic;
|
||||
lv_color_t ring_color;
|
||||
} lv_cpicker_ext_t;
|
||||
|
||||
|
||||
/*Styles*/
|
||||
enum {
|
||||
LV_CPICKER_STYLE_MAIN,
|
||||
LV_CPICKER_STYLE_IND,
|
||||
};
|
||||
typedef uint8_t lv_cpicker_style_t;
|
||||
|
||||
enum {
|
||||
LV_CPICKER_IND_NONE,
|
||||
LV_CPICKER_IND_LINE,
|
||||
LV_CPICKER_IND_CIRCLE,
|
||||
LV_CPICKER_IND_IN
|
||||
};
|
||||
typedef uint8_t lv_cpicker_ind_type_t;
|
||||
|
||||
enum {
|
||||
LV_CPICKER_TYPE_RECT,
|
||||
LV_CPICKER_TYPE_DISC,
|
||||
};
|
||||
typedef uint8_t lv_cpicker_type_t;
|
||||
|
||||
enum {
|
||||
LV_CPICKER_WHEEL_HUE,
|
||||
LV_CPICKER_WHEEL_SAT,
|
||||
LV_CPICKER_WHEEL_VAL
|
||||
};
|
||||
typedef uint8_t lv_cpicker_wheel_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);
|
||||
|
||||
/*======================
|
||||
* Add/remove functions
|
||||
*=====================*/
|
||||
|
||||
|
||||
/*=====================
|
||||
* Setter functions
|
||||
*====================*/
|
||||
|
||||
/**
|
||||
* 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_ind_type(lv_obj_t * cpicker, lv_cpicker_ind_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 ring color of a colorpicker.
|
||||
* @param cpicker pointer to colorpicker object
|
||||
* @param ring_color new ring color
|
||||
*/
|
||||
void lv_cpicker_set_ring_color(lv_obj_t * cpicker, lv_color_t ring_color);
|
||||
|
||||
/**
|
||||
* Set the current saturation of a colorpicker.
|
||||
* @param cpicker pointer to colorpicker object
|
||||
* @param sat current selected saturation
|
||||
*/
|
||||
void lv_cpicker_set_saturation(lv_obj_t * cpicker, uint16_t sat);
|
||||
|
||||
/**
|
||||
* 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, uint16_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 action callback on value change event.
|
||||
* @param cpicker pointer to colorpicker object
|
||||
* @param action callback function
|
||||
*/
|
||||
//LVGLv5 void lv_cpicker_set_action(lv_obj_t * cpicker, lv_action_t action);
|
||||
|
||||
/**
|
||||
* Set the current wheel mode.
|
||||
* @param cpicker pointer to colorpicker object
|
||||
* @param mode wheel mode (hue/sat/val)
|
||||
*/
|
||||
void lv_cpicker_set_wheel_mode(lv_obj_t * cpicker, lv_cpicker_wheel_mode_t mode);
|
||||
|
||||
/**
|
||||
* Set if the wheel mode is changed on long press on center
|
||||
* @param cpicker pointer to colorpicker object
|
||||
* @param fixed_mode mode cannot be changed if set
|
||||
*/
|
||||
void lv_cpicker_set_wheel_fixed(lv_obj_t * cpicker, bool fixed_mode);
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
*====================*/
|
||||
|
||||
/**
|
||||
* 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 ring color of a colorpicker.
|
||||
* @param cpicker pointer to colorpicker object
|
||||
* @return current ring color
|
||||
*/
|
||||
lv_color_t lv_cpicker_get_ring_color(const lv_obj_t * cpicker);
|
||||
|
||||
/**
|
||||
* 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 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);
|
||||
|
||||
/**
|
||||
* Get the action callback called on value change event.
|
||||
* @param cpicker pointer to colorpicker object
|
||||
* @return action callback function
|
||||
*/
|
||||
//LVGLv5 lv_action_t lv_cpicker_get_action(lv_obj_t * cpicker);
|
||||
|
||||
/*=====================
|
||||
* Other functions
|
||||
*====================*/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /*USE_LV_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
|
||||
|
||||
Reference in New Issue
Block a user