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:
parent
ae03d56700
commit
0eebd78a9b
@ -47,7 +47,7 @@
|
||||
#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
|
||||
|
||||
/* Split the line into trapezoids */
|
||||
|
||||
ret = nxgl_splitline(vector, trap, &rect, width);
|
||||
switch (ret)
|
||||
{
|
||||
/* 0: Line successfully broken up into three trapezoids. Values in
|
||||
* traps[0], traps[1], and traps[2] are valid.
|
||||
*/
|
||||
|
||||
case 0:
|
||||
ret = nx_filltrapezoid(hwnd, NULL, &trap[0], color);
|
||||
if (ret == OK)
|
||||
@ -122,18 +128,45 @@ int nx_drawline(NXWINDOW hwnd, FAR struct nxgl_vector_s *vector,
|
||||
}
|
||||
break;
|
||||
|
||||
/* 1: Line successfully represented by one trapezoid. Value in traps[1]
|
||||
* is valid.
|
||||
*/
|
||||
|
||||
case 1:
|
||||
ret = nx_filltrapezoid(hwnd, NULL, &trap[1], color);
|
||||
break;
|
||||
|
||||
/* 2: Line successfully represented by one rectangle. Value in rect is
|
||||
* valid
|
||||
*/
|
||||
|
||||
case 2:
|
||||
ret = nx_fill(hwnd, &rect, color);
|
||||
break;
|
||||
|
||||
/* <0: On errors, a negated errno value is returned. */
|
||||
|
||||
default:
|
||||
set_errno(-ret);
|
||||
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;
|
||||
}
|
||||
|
@ -47,7 +47,7 @@
|
||||
#include <nuttx/nx/nx.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define NCIRCLE_TRAPS 8
|
||||
@ -110,5 +110,6 @@ int nx_fillcircle(NXWINDOW hwnd, FAR const struct nxgl_point_s *center,
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
@ -48,7 +48,7 @@
|
||||
#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
|
||||
|
||||
/* Split the line into trapezoids */
|
||||
|
||||
ret = nxgl_splitline(vector, trap, &rect, width);
|
||||
switch (ret)
|
||||
{
|
||||
/* 0: Line successfully broken up into three trapezoids. Values in
|
||||
* traps[0], traps[1], and traps[2] are valid.
|
||||
*/
|
||||
|
||||
case 0:
|
||||
ret = nxtk_filltraptoolbar(hfwnd, &trap[0], color);
|
||||
if (ret == OK)
|
||||
@ -125,18 +131,45 @@ int nxtk_drawlinetoolbar(NXTKWINDOW hfwnd, FAR struct nxgl_vector_s *vector,
|
||||
}
|
||||
break;
|
||||
|
||||
/* 1: Line successfully represented by one trapezoid. Value in traps[1]
|
||||
* is valid.
|
||||
*/
|
||||
|
||||
case 1:
|
||||
ret = nxtk_filltraptoolbar(hfwnd, &trap[1], color);
|
||||
break;
|
||||
|
||||
/* 2: Line successfully represented by one rectangle. Value in rect is
|
||||
* valid
|
||||
*/
|
||||
|
||||
case 2:
|
||||
ret = nxtk_filltoolbar(hfwnd, &rect, color);
|
||||
break;
|
||||
|
||||
/* <0: On errors, a negated errno value is returned. */
|
||||
|
||||
default:
|
||||
set_errno(EINVAL);
|
||||
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;
|
||||
}
|
||||
|
@ -48,7 +48,7 @@
|
||||
#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
|
||||
|
||||
/* Split the line into trapezoids */
|
||||
|
||||
ret = nxgl_splitline(vector, trap, &rect, width);
|
||||
switch (ret)
|
||||
{
|
||||
/* 0: Line successfully broken up into three trapezoids. Values in
|
||||
* traps[0], traps[1], and traps[2] are valid.
|
||||
*/
|
||||
|
||||
case 0:
|
||||
ret = nxtk_filltrapwindow(hfwnd, &trap[0], color);
|
||||
if (ret == OK)
|
||||
@ -124,18 +130,45 @@ int nxtk_drawlinewindow(NXTKWINDOW hfwnd, FAR struct nxgl_vector_s *vector,
|
||||
}
|
||||
break;
|
||||
|
||||
/* 1: Line successfully represented by one trapezoid. Value in traps[1]
|
||||
* is valid.
|
||||
*/
|
||||
|
||||
case 1:
|
||||
ret = nxtk_filltrapwindow(hfwnd, &trap[1], color);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
/* 2: Line successfully represented by one rectangle. Value in rect is
|
||||
* valid
|
||||
*/
|
||||
|
||||
case 2:
|
||||
ret = nxtk_fillwindow(hfwnd, &rect, color);
|
||||
break;
|
||||
|
||||
/* <0: On errors, a negated errno value is returned. */
|
||||
|
||||
default:
|
||||
set_errno(EINVAL);
|
||||
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;
|
||||
}
|
||||
|
@ -47,7 +47,7 @@
|
||||
#include <nuttx/nx/nxtk.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define NCIRCLE_TRAPS 8
|
||||
@ -111,5 +111,6 @@ int nxtk_fillcircletoolbar(NXWINDOW hfwnd, FAR const struct nxgl_point_s *center
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
@ -47,7 +47,7 @@
|
||||
#include <nuttx/nx/nxtk.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define NCIRCLE_TRAPS 8
|
||||
@ -111,5 +111,6 @@ int nxtk_fillcirclewindow(NXWINDOW hfwnd, FAR const struct nxgl_point_s *center,
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user