/**1* @file lv_area.h2*3*/45#ifndef LV_AREA_H6#define LV_AREA_H78#ifdef __cplusplus9extern "C" {10#endif111213/*********************14* INCLUDES15*********************/16#include <string.h>17#include <utils/types.h>1819/*********************20* DEFINES21*********************/22#define LV_COORD_MAX (16383) /*To avoid overflow don't let the max [-32,32k] range */23#define LV_COORD_MIN (-16384)2425/**********************26* TYPEDEFS27**********************/28typedef int16_t lv_coord_t;2930typedef struct31{32lv_coord_t x;33lv_coord_t y;34} lv_point_t;3536typedef struct37{38lv_coord_t x1;39lv_coord_t y1;40lv_coord_t x2;41lv_coord_t y2;42} lv_area_t;4344/**********************45* GLOBAL PROTOTYPES46**********************/4748/**49* Initialize an area50* @param area_p pointer to an area51* @param x1 left coordinate of the area52* @param y1 top coordinate of the area53* @param x2 right coordinate of the area54* @param y2 bottom coordinate of the area55*/56void lv_area_set(lv_area_t * area_p, lv_coord_t x1, lv_coord_t y1, lv_coord_t x2, lv_coord_t y2);5758/**59* Copy an area60* @param dest pointer to the destination area61* @param src pointer to the source area62*/63inline static void lv_area_copy(lv_area_t * dest, const lv_area_t * src)64{65memcpy(dest, src, sizeof(lv_area_t));66}6768/**69* Get the width of an area70* @param area_p pointer to an area71* @return the width of the area (if x1 == x2 -> width = 1)72*/73static inline lv_coord_t lv_area_get_width(const lv_area_t * area_p)74{75return area_p->x2 - area_p->x1 + 1;76}7778/**79* Get the height of an area80* @param area_p pointer to an area81* @return the height of the area (if y1 == y2 -> height = 1)82*/83static inline lv_coord_t lv_area_get_height(const lv_area_t * area_p)84{85return area_p->y2 - area_p->y1 + 1;86}8788/**89* Set the width of an area90* @param area_p pointer to an area91* @param w the new width of the area (w == 1 makes x1 == x2)92*/93void lv_area_set_width(lv_area_t * area_p, lv_coord_t w);9495/**96* Set the height of an area97* @param area_p pointer to an area98* @param h the new height of the area (h == 1 makes y1 == y2)99*/100void lv_area_set_height(lv_area_t * area_p, lv_coord_t h);101102/**103* Set the position of an area (width and height will be kept)104* @param area_p pointer to an area105* @param x the new x coordinate of the area106* @param y the new y coordinate of the area107*/108void lv_area_set_pos(lv_area_t * area_p, lv_coord_t x, lv_coord_t y);109110/**111* Return with area of an area (x * y)112* @param area_p pointer to an area113* @return size of area114*/115uint32_t lv_area_get_size(const lv_area_t * area_p);116117/**118* Get the common parts of two areas119* @param res_p pointer to an area, the result will be stored her120* @param a1_p pointer to the first area121* @param a2_p pointer to the second area122* @return false: the two area has NO common parts, res_p is invalid123*/124bool lv_area_intersect(lv_area_t * res_p, const lv_area_t * a1_p, const lv_area_t * a2_p);125126/**127* Join two areas into a third which involves the other two128* @param res_p pointer to an area, the result will be stored here129* @param a1_p pointer to the first area130* @param a2_p pointer to the second area131*/132void lv_area_join(lv_area_t * a_res_p, const lv_area_t * a1_p, const lv_area_t * a2_p);133134/**135* Check if a point is on an area136* @param a_p pointer to an area137* @param p_p pointer to a point138* @return false:the point is out of the area139*/140bool lv_area_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p);141142/**143* Check if two area has common parts144* @param a1_p pointer to an area.145* @param a2_p pointer to an other area146* @return false: a1_p and a2_p has no common parts147*/148bool lv_area_is_on(const lv_area_t * a1_p, const lv_area_t * a2_p);149150/**151* Check if an area is fully on an other152* @param ain_p pointer to an area which could be on aholder_p153* @param aholder pointer to an area which could involve ain_p154* @return155*/156bool lv_area_is_in(const lv_area_t * ain_p, const lv_area_t * aholder_p);157158/**********************159* MACROS160**********************/161162#ifdef __cplusplus163} /* extern "C" */164#endif165166167#endif168169170