BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lvgl
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
lvgl
Commits
04a0bcaa
Commit
04a0bcaa
authored
Jan 09, 2017
by
Kiss-Vamosi Gabor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lv_rect: bugfix in design cover check when radious is LV_RECT_CIRCLE
parent
b2aa49a5
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
392 additions
and
4 deletions
+392
-4
lv_gauge.c
lv_objx/lv_gauge.c
+306
-0
lv_gauge.h
lv_objx/lv_gauge.h
+78
-0
lv_objx_templ.c
lv_objx/lv_objx_templ.c
+3
-3
lv_rect.c
lv_objx/lv_rect.c
+5
-1
No files found.
lv_objx/lv_gauge.c
0 → 100644
View file @
04a0bcaa
/**
* @file lv_gauge.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_conf.h"
#if USE_LV_GAUGE != 0
#include "lv_gauge.h"
#include <stdio.h>
#include "../lv_draw/lv_draw.h"
#include "../lv_misc/text.h"
#include "misc/math/trigo.h"
/*********************
* DEFINES
*********************/
#define LV_GAUGE_DEF_WIDTH (150 * LV_DOWNSCALE)
#define LV_GAUGE_DEF_HEIGHT (150 * LV_DOWNSCALE)
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static
bool
lv_gauge_design
(
lv_obj_t
*
gauge
,
const
area_t
*
mask
,
lv_design_mode_t
mode
);
static
void
lv_gauges_init
(
void
);
/**********************
* STATIC VARIABLES
**********************/
static
lv_gauges_t
lv_gauges_def
;
/*Default gauge style*/
static
lv_design_f_t
ancestor_design_f
=
NULL
;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/*-----------------
* Create function
*-----------------*/
/**
* Create a gauge objects
* @param par pointer to an object, it will be the parent of the new gauge
* @param copy pointer to a gauge object, if not NULL then the new object will be copied from it
* @return pointer to the created gauge
*/
lv_obj_t
*
lv_gauge_create
(
lv_obj_t
*
par
,
lv_obj_t
*
copy
)
{
/*Create the ancestor gauge*/
lv_obj_t
*
new_gauge
=
lv_rect_create
(
par
,
copy
);
dm_assert
(
new_gauge
);
/*Allocate the gauge type specific extended data*/
lv_gauge_ext_t
*
ext
=
lv_obj_alloc_ext
(
new_gauge
,
sizeof
(
lv_gauge_ext_t
));
dm_assert
(
ext
);
/*Initialize the allocated 'ext' */
ext
->
min
=
0
;
ext
->
max
=
100
;
ext
->
value
=
90
;
if
(
ancestor_design_f
==
NULL
)
ancestor_design_f
=
lv_obj_get_design_f
(
new_gauge
);
/*The signal and design functions are not copied so set them here*/
lv_obj_set_signal_f
(
new_gauge
,
lv_gauge_signal
);
lv_obj_set_design_f
(
new_gauge
,
lv_gauge_design
);
/*Init the new gauge gauge*/
if
(
copy
==
NULL
)
{
lv_obj_set_size
(
new_gauge
,
LV_GAUGE_DEF_WIDTH
,
LV_GAUGE_DEF_HEIGHT
);
lv_obj_set_style
(
new_gauge
,
lv_gauges_get
(
LV_GAUGES_DEF
,
NULL
));
}
/*Copy an existing gauge*/
else
{
lv_gauge_ext_t
*
copy_ext
=
lv_obj_get_ext
(
copy
);
/*Refresh the style with new signal function*/
lv_obj_refr_style
(
new_gauge
);
}
return
new_gauge
;
}
/**
* Signal function of the gauge
* @param gauge pointer to a gauge object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return true: the object is still valid (not deleted), false: the object become invalid
*/
bool
lv_gauge_signal
(
lv_obj_t
*
gauge
,
lv_signal_t
sign
,
void
*
param
)
{
bool
valid
;
/* Include the ancient signal function */
valid
=
lv_rect_signal
(
gauge
,
sign
,
param
);
/* The object can be deleted so check its validity and then
* make the object specific signal handling */
if
(
valid
!=
false
)
{
switch
(
sign
)
{
case
LV_SIGNAL_CLEANUP
:
/*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
break
;
default:
break
;
}
}
return
valid
;
}
/*=====================
* Setter functions
*====================*/
void
lv_gauge_set_value
(
lv_obj_t
*
gauge
,
int16_t
value
)
{
lv_gauge_ext_t
*
ext
=
lv_obj_get_ext
(
gauge
);
if
(
value
>
ext
->
max
)
value
=
ext
->
max
;
if
(
value
<
ext
->
min
)
value
=
ext
->
min
;
ext
->
value
=
value
;
lv_obj_inv
(
gauge
);
}
/*=====================
* Getter functions
*====================*/
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_gauges_builtin_t enum
* @param copy copy the style to this variable. (NULL if unused)
* @return pointer to an lv_gauges_t style
*/
lv_gauges_t
*
lv_gauges_get
(
lv_gauges_builtin_t
style
,
lv_gauges_t
*
copy
)
{
static
bool
style_inited
=
false
;
/*Make the style initialization if it is not done yet*/
if
(
style_inited
==
false
)
{
lv_gauges_init
();
style_inited
=
true
;
}
lv_gauges_t
*
style_p
;
switch
(
style
)
{
case
LV_GAUGES_DEF
:
style_p
=
&
lv_gauges_def
;
break
;
default:
style_p
=
&
lv_gauges_def
;
}
if
(
copy
!=
NULL
)
{
if
(
style_p
!=
NULL
)
memcpy
(
copy
,
style_p
,
sizeof
(
lv_gauges_t
));
else
memcpy
(
copy
,
&
lv_gauges_def
,
sizeof
(
lv_gauges_t
));
}
return
style_p
;
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Handle the drawing related tasks of the gauges
* @param gauge 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_gauge_design
(
lv_obj_t
*
gauge
,
const
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
ancestor_design_f
(
gauge
,
mask
,
mode
);
}
/*Draw the object*/
else
if
(
mode
==
LV_DESIGN_DRAW_MAIN
)
{
lv_gauges_t
*
style
=
lv_obj_get_style
(
gauge
);
lv_gauge_ext_t
*
ext
=
lv_obj_get_ext
(
gauge
);
ancestor_design_f
(
gauge
,
mask
,
mode
);
char
scale_txt
[
16
];
area_t
label_cord
;
point_t
label_size
;
uint8_t
i
;
cord_t
r
=
lv_obj_get_width
(
gauge
)
/
2
-
style
->
label_pad
;
cord_t
x
;
cord_t
y
;
cord_t
x_ofs
=
lv_obj_get_width
(
gauge
)
/
2
+
gauge
->
cords
.
x1
;
cord_t
y_ofs
=
lv_obj_get_height
(
gauge
)
/
2
+
gauge
->
cords
.
y1
;
int16_t
angle
;
int16_t
angle_ofs
=
90
+
(
360
-
style
->
angle
)
/
2
;
int16_t
scale_act
;
for
(
i
=
0
;
i
<
style
->
label_num
;
i
++
)
{
angle
=
(
i
*
style
->
angle
)
/
(
style
->
label_num
-
1
)
+
angle_ofs
;
y
=
(
int32_t
)((
int32_t
)
trigo_sin
(
angle
)
*
r
)
/
TRIGO_SIN_MAX
;
y
+=
y_ofs
;
x
=
(
int32_t
)((
int32_t
)
trigo_sin
(
angle
+
90
)
*
r
)
/
TRIGO_SIN_MAX
;
x
+=
x_ofs
;
scale_act
=
(
int32_t
)((
int32_t
)(
ext
->
max
-
ext
->
min
)
*
i
)
/
(
style
->
label_num
-
1
);
scale_act
+=
ext
->
min
;
sprintf
(
scale_txt
,
"%d"
,
scale_act
);
txt_get_size
(
&
label_size
,
scale_txt
,
font_get
(
style
->
scale_labels
.
font
),
style
->
scale_labels
.
letter_space
,
style
->
scale_labels
.
line_space
,
LV_CORD_MAX
);
label_cord
.
x1
=
x
-
label_size
.
x
/
2
;
label_cord
.
y1
=
y
-
label_size
.
y
/
2
;
label_cord
.
x2
=
label_cord
.
x1
+
label_size
.
x
;
label_cord
.
y2
=
label_cord
.
y1
+
label_size
.
y
;
lv_draw_label
(
&
label_cord
,
mask
,
&
style
->
scale_labels
,
OPA_COVER
,
scale_txt
);
}
point_t
p_mid
;
point_t
p_end
;
int16_t
needle_angle
=
ext
->
value
*
220
/
(
ext
->
max
-
ext
->
min
)
+
angle_ofs
;
int16_t
needle_y
=
(
trigo_sin
(
needle_angle
)
*
r
)
/
TRIGO_SIN_MAX
;
int16_t
needle_x
=
(
trigo_sin
(
needle_angle
+
90
)
*
r
)
/
TRIGO_SIN_MAX
;
p_mid
.
x
=
x_ofs
;
p_mid
.
y
=
y_ofs
;
p_end
.
x
=
needle_x
+
x_ofs
;
p_end
.
y
=
needle_y
+
y_ofs
;
lv_draw_line
(
&
p_mid
,
&
p_end
,
mask
,
&
style
->
needle_lines
,
OPA_50
);
lv_rects_t
nm
;
area_t
nm_cord
;
lv_rects_get
(
LV_RECTS_DEF
,
&
nm
);
nm
.
bwidth
=
0
;
nm
.
round
=
LV_RECT_CIRCLE
;
nm
.
objs
.
color
=
COLOR_GRAY
;
//style->needle_lines.objs.color;
nm
.
gcolor
=
COLOR_GRAY
;
//style->needle_lines.objs.color;
nm_cord
.
x1
=
x_ofs
-
5
*
LV_DOWNSCALE
;
nm_cord
.
y1
=
y_ofs
-
5
*
LV_DOWNSCALE
;
nm_cord
.
x2
=
x_ofs
+
5
*
LV_DOWNSCALE
;
nm_cord
.
y2
=
y_ofs
+
5
*
LV_DOWNSCALE
;
lv_draw_rect
(
&
nm_cord
,
mask
,
&
nm
,
OPA_100
);
}
/*Post draw when the children are drawn*/
else
if
(
mode
==
LV_DESIGN_DRAW_POST
)
{
ancestor_design_f
(
gauge
,
mask
,
mode
);
}
return
true
;
}
/**
* Initialize the built-in gauge styles
*/
static
void
lv_gauges_init
(
void
)
{
/*Default style*/
lv_rects_get
(
LV_RECTS_DEF
,
&
lv_gauges_def
.
rects
);
lv_gauges_def
.
rects
.
round
=
LV_RECT_CIRCLE
;
lv_gauges_def
.
rects
.
bwidth
=
6
*
LV_DOWNSCALE
;
lv_gauges_def
.
rects
.
gcolor
=
COLOR_RED
;
lv_labels_get
(
LV_RECTS_DEF
,
&
lv_gauges_def
.
scale_labels
);
lv_lines_get
(
LV_LINES_DEF
,
&
lv_gauges_def
.
needle_lines
);
lv_gauges_def
.
needle_lines
.
objs
.
color
=
COLOR_WHITE
;
lv_gauges_def
.
needle_lines
.
width
=
3
*
LV_DOWNSCALE
;
lv_gauges_def
.
label_pad
=
20
*
LV_DOWNSCALE
;
lv_gauges_def
.
label_num
=
5
;
lv_gauges_def
.
angle
=
220
;
}
#endif
lv_objx/lv_gauge.h
0 → 100644
View file @
04a0bcaa
/**
* @file lv_gauge.h
*
*/
/*Search an replace: gauge -> object normal name with lower case (e.g. button, label etc.)
* gauge -> object short name with lower case(e.g. btn, label etc)
* GAUGE -> object short name with upper case (e.g. BTN, LABEL etc.)
*
*/
#ifndef LV_GAUGE_H
#define LV_GAUGE_H
/*********************
* INCLUDES
*********************/
#include "lv_conf.h"
#if USE_LV_GAUGE != 0
#include "../lv_obj/lv_obj.h"
#include "lv_rect.h"
#include "lv_label.h"
#include "lv_line.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/*Style of gauge*/
typedef
struct
{
lv_rects_t
rects
;
/*Style of ancestor*/
/*New style element for this type */
lv_labels_t
scale_labels
;
lv_lines_t
needle_lines
;
cord_t
label_pad
;
uint16_t
angle
;
uint8_t
label_num
;
}
lv_gauges_t
;
/*Built-in styles of gauge*/
typedef
enum
{
LV_GAUGES_DEF
,
}
lv_gauges_builtin_t
;
/*Data of gauge*/
typedef
struct
{
lv_rect_ext_t
rect
;
/*Ext. of ancestor*/
/*New data for this type */
int16_t
min
;
int16_t
max
;
int16_t
value
;
}
lv_gauge_ext_t
;
/**********************
* GLOBAL PROTOTYPES
**********************/
lv_obj_t
*
lv_gauge_create
(
lv_obj_t
*
par
,
lv_obj_t
*
copy
);
bool
lv_gauge_signal
(
lv_obj_t
*
gauge
,
lv_signal_t
sign
,
void
*
param
);
lv_gauges_t
*
lv_gauges_get
(
lv_gauges_builtin_t
style
,
lv_gauges_t
*
copy
);
void
lv_gauge_set_value
(
lv_obj_t
*
gauge
,
int16_t
value
);
/**********************
* MACROS
**********************/
#endif
#endif
lv_objx/lv_objx_templ.c
View file @
04a0bcaa
...
...
@@ -29,7 +29,7 @@
* STATIC PROTOTYPES
**********************/
static
bool
lv_templ_design
(
lv_obj_t
*
templ
,
const
area_t
*
mask
,
lv_design_mode_t
mode
);
static
void
lv_temps_init
(
void
);
static
void
lv_temp
l
s_init
(
void
);
/**********************
* STATIC VARIABLES
...
...
@@ -138,7 +138,7 @@ lv_templs_t * lv_templs_get(lv_templs_builtin_t style, lv_templs_t * copy)
/*Make the style initialization if it is not done yet*/
if
(
style_inited
==
false
)
{
lv_temps_init
();
lv_temp
l
s_init
();
style_inited
=
true
;
}
...
...
@@ -197,7 +197,7 @@ static bool lv_templ_design(lv_obj_t * templ, const area_t * mask, lv_design_mod
/**
* Initialize the built-in template styles
*/
static
void
lv_temps_init
(
void
)
static
void
lv_temp
l
s_init
(
void
)
{
/*Default style*/
}
...
...
lv_objx/lv_rect.c
View file @
04a0bcaa
...
...
@@ -284,11 +284,15 @@ lv_rects_t * lv_rects_get(lv_rects_builtin_t style, lv_rects_t * copy)
*/
static
bool
lv_rect_design
(
lv_obj_t
*
rect
,
const
area_t
*
mask
,
lv_design_mode_t
mode
)
{
/* Because of the radius it is not sure the area is covered*/
if
(
mode
==
LV_DESIGN_COVER_CHK
)
{
/* Because of the radius it is not sure the area is covered
* Check the areas where there is no radius*/
if
(
LV_SA
(
rect
,
lv_rects_t
)
->
empty
!=
0
)
return
false
;
uint16_t
r
=
LV_SA
(
rect
,
lv_rects_t
)
->
round
;
if
(
r
==
LV_RECT_CIRCLE
)
return
false
;
area_t
area_tmp
;
/*Check horizontally without radius*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment