mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 23:40:19 +08:00
Implement line caps by drawing a file circle at the each endpoint of a line with a radius equal to half of the width of the line
This commit is contained in:
+34
-1
@@ -47,7 +47,7 @@
|
|||||||
#include <nuttx/nx/nx.h>
|
#include <nuttx/nx/nx.h>
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-Processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -107,9 +107,15 @@ int nx_drawline(NXWINDOW hwnd, FAR struct nxgl_vector_s *vector,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Split the line into trapezoids */
|
||||||
|
|
||||||
ret = nxgl_splitline(vector, trap, &rect, width);
|
ret = nxgl_splitline(vector, trap, &rect, width);
|
||||||
switch (ret)
|
switch (ret)
|
||||||
{
|
{
|
||||||
|
/* 0: Line successfully broken up into three trapezoids. Values in
|
||||||
|
* traps[0], traps[1], and traps[2] are valid.
|
||||||
|
*/
|
||||||
|
|
||||||
case 0:
|
case 0:
|
||||||
ret = nx_filltrapezoid(hwnd, NULL, &trap[0], color);
|
ret = nx_filltrapezoid(hwnd, NULL, &trap[0], color);
|
||||||
if (ret == OK)
|
if (ret == OK)
|
||||||
@@ -122,18 +128,45 @@ int nx_drawline(NXWINDOW hwnd, FAR struct nxgl_vector_s *vector,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/* 1: Line successfully represented by one trapezoid. Value in traps[1]
|
||||||
|
* is valid.
|
||||||
|
*/
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
ret = nx_filltrapezoid(hwnd, NULL, &trap[1], color);
|
ret = nx_filltrapezoid(hwnd, NULL, &trap[1], color);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/* 2: Line successfully represented by one rectangle. Value in rect is
|
||||||
|
* valid
|
||||||
|
*/
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
ret = nx_fill(hwnd, &rect, color);
|
ret = nx_fill(hwnd, &rect, color);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/* <0: On errors, a negated errno value is returned. */
|
||||||
|
|
||||||
default:
|
default:
|
||||||
set_errno(-ret);
|
set_errno(-ret);
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Draw circular caps at each end of the line to support better line joins */
|
||||||
|
|
||||||
|
if (capped && width >= 3)
|
||||||
|
{
|
||||||
|
nxgl_coord_t radius = width >> 1;
|
||||||
|
|
||||||
|
/* Draw a circle at pt1 */
|
||||||
|
|
||||||
|
ret = nx_fillcircle(hwnd, &vector->pt1, radius, color);
|
||||||
|
if (ret == OK)
|
||||||
|
{
|
||||||
|
/* Draw a circle at pt2 */
|
||||||
|
|
||||||
|
ret = nx_fillcircle(hwnd, &vector->pt2, radius, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@
|
|||||||
#include <nuttx/nx/nx.h>
|
#include <nuttx/nx/nx.h>
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-Processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#define NCIRCLE_TRAPS 8
|
#define NCIRCLE_TRAPS 8
|
||||||
@@ -110,5 +110,6 @@ int nx_fillcircle(NXWINDOW hwnd, FAR const struct nxgl_point_s *center,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@
|
|||||||
#include <nuttx/nx/nxtk.h>
|
#include <nuttx/nx/nxtk.h>
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-Processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -110,9 +110,15 @@ int nxtk_drawlinetoolbar(NXTKWINDOW hfwnd, FAR struct nxgl_vector_s *vector,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Split the line into trapezoids */
|
||||||
|
|
||||||
ret = nxgl_splitline(vector, trap, &rect, width);
|
ret = nxgl_splitline(vector, trap, &rect, width);
|
||||||
switch (ret)
|
switch (ret)
|
||||||
{
|
{
|
||||||
|
/* 0: Line successfully broken up into three trapezoids. Values in
|
||||||
|
* traps[0], traps[1], and traps[2] are valid.
|
||||||
|
*/
|
||||||
|
|
||||||
case 0:
|
case 0:
|
||||||
ret = nxtk_filltraptoolbar(hfwnd, &trap[0], color);
|
ret = nxtk_filltraptoolbar(hfwnd, &trap[0], color);
|
||||||
if (ret == OK)
|
if (ret == OK)
|
||||||
@@ -125,18 +131,45 @@ int nxtk_drawlinetoolbar(NXTKWINDOW hfwnd, FAR struct nxgl_vector_s *vector,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/* 1: Line successfully represented by one trapezoid. Value in traps[1]
|
||||||
|
* is valid.
|
||||||
|
*/
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
ret = nxtk_filltraptoolbar(hfwnd, &trap[1], color);
|
ret = nxtk_filltraptoolbar(hfwnd, &trap[1], color);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/* 2: Line successfully represented by one rectangle. Value in rect is
|
||||||
|
* valid
|
||||||
|
*/
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
ret = nxtk_filltoolbar(hfwnd, &rect, color);
|
ret = nxtk_filltoolbar(hfwnd, &rect, color);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/* <0: On errors, a negated errno value is returned. */
|
||||||
|
|
||||||
default:
|
default:
|
||||||
set_errno(EINVAL);
|
set_errno(EINVAL);
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Draw circular caps at each end of the line to support better line joins */
|
||||||
|
|
||||||
|
if (capped && width >= 3)
|
||||||
|
{
|
||||||
|
nxgl_coord_t radius = width >> 1;
|
||||||
|
|
||||||
|
/* Draw a circle at pt1 */
|
||||||
|
|
||||||
|
ret = nxtk_fillcircletoolbar(hfwnd, &vector->pt1, radius, color);
|
||||||
|
if (ret == OK)
|
||||||
|
{
|
||||||
|
/* Draw a circle at pt2 */
|
||||||
|
|
||||||
|
ret = nxtk_fillcircletoolbar(hfwnd, &vector->pt2, radius, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@
|
|||||||
#include <nuttx/nx/nxtk.h>
|
#include <nuttx/nx/nxtk.h>
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-Processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -109,9 +109,15 @@ int nxtk_drawlinewindow(NXTKWINDOW hfwnd, FAR struct nxgl_vector_s *vector,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Split the line into trapezoids */
|
||||||
|
|
||||||
ret = nxgl_splitline(vector, trap, &rect, width);
|
ret = nxgl_splitline(vector, trap, &rect, width);
|
||||||
switch (ret)
|
switch (ret)
|
||||||
{
|
{
|
||||||
|
/* 0: Line successfully broken up into three trapezoids. Values in
|
||||||
|
* traps[0], traps[1], and traps[2] are valid.
|
||||||
|
*/
|
||||||
|
|
||||||
case 0:
|
case 0:
|
||||||
ret = nxtk_filltrapwindow(hfwnd, &trap[0], color);
|
ret = nxtk_filltrapwindow(hfwnd, &trap[0], color);
|
||||||
if (ret == OK)
|
if (ret == OK)
|
||||||
@@ -124,18 +130,45 @@ int nxtk_drawlinewindow(NXTKWINDOW hfwnd, FAR struct nxgl_vector_s *vector,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/* 1: Line successfully represented by one trapezoid. Value in traps[1]
|
||||||
|
* is valid.
|
||||||
|
*/
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
ret = nxtk_filltrapwindow(hfwnd, &trap[1], color);
|
ret = nxtk_filltrapwindow(hfwnd, &trap[1], color);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/* 2: Line successfully represented by one rectangle. Value in rect is
|
||||||
|
* valid
|
||||||
|
*/
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
ret = nxtk_fillwindow(hfwnd, &rect, color);
|
ret = nxtk_fillwindow(hfwnd, &rect, color);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/* <0: On errors, a negated errno value is returned. */
|
||||||
|
|
||||||
default:
|
default:
|
||||||
set_errno(EINVAL);
|
set_errno(EINVAL);
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Draw circular caps at each end of the line to support better line joins */
|
||||||
|
|
||||||
|
if (capped && width >= 3)
|
||||||
|
{
|
||||||
|
nxgl_coord_t radius = width >> 1;
|
||||||
|
|
||||||
|
/* Draw a circle at pt1 */
|
||||||
|
|
||||||
|
ret = nxtk_fillcirclewindow(hfwnd, &vector->pt1, radius, color);
|
||||||
|
if (ret == OK)
|
||||||
|
{
|
||||||
|
/* Draw a circle at pt2 */
|
||||||
|
|
||||||
|
ret = nxtk_fillcirclewindow(hfwnd, &vector->pt2, radius, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@
|
|||||||
#include <nuttx/nx/nxtk.h>
|
#include <nuttx/nx/nxtk.h>
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-Processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#define NCIRCLE_TRAPS 8
|
#define NCIRCLE_TRAPS 8
|
||||||
@@ -111,5 +111,6 @@ int nxtk_fillcircletoolbar(NXWINDOW hfwnd, FAR const struct nxgl_point_s *center
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@
|
|||||||
#include <nuttx/nx/nxtk.h>
|
#include <nuttx/nx/nxtk.h>
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-Processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#define NCIRCLE_TRAPS 8
|
#define NCIRCLE_TRAPS 8
|
||||||
@@ -111,5 +111,6 @@ int nxtk_fillcirclewindow(NXWINDOW hfwnd, FAR const struct nxgl_point_s *center,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user