summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2015-04-05 09:37:18 -0600
committerGregory Nutt <gnutt@nuttx.org>2015-04-05 09:37:18 -0600
commitf582bded7f9ed649a228891bb2f4cfa2cbda89cd (patch)
tree67c61d349225c40852f7ea4f404c14f0f5ecdc88
parent0aa9b220495236e5ce855a2fd7565e3ccd94114a (diff)
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
-rw-r--r--nuttx/libnx/nx/nx_drawline.c35
-rw-r--r--nuttx/libnx/nx/nx_fillcircle.c3
-rw-r--r--nuttx/libnx/nxtk/nxtk_drawlinetoolbar.c35
-rw-r--r--nuttx/libnx/nxtk/nxtk_drawlinewindow.c37
-rw-r--r--nuttx/libnx/nxtk/nxtk_fillcircletoolbar.c3
-rw-r--r--nuttx/libnx/nxtk/nxtk_fillcirclewindow.c3
6 files changed, 109 insertions, 7 deletions
diff --git a/nuttx/libnx/nx/nx_drawline.c b/nuttx/libnx/nx/nx_drawline.c
index f29c3b6097..162dd15388 100644
--- a/nuttx/libnx/nx/nx_drawline.c
+++ b/nuttx/libnx/nx/nx_drawline.c
@@ -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;
}
diff --git a/nuttx/libnx/nx/nx_fillcircle.c b/nuttx/libnx/nx/nx_fillcircle.c
index aba0fd649a..7bfa1551f5 100644
--- a/nuttx/libnx/nx/nx_fillcircle.c
+++ b/nuttx/libnx/nx/nx_fillcircle.c
@@ -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;
}
diff --git a/nuttx/libnx/nxtk/nxtk_drawlinetoolbar.c b/nuttx/libnx/nxtk/nxtk_drawlinetoolbar.c
index 8c2810ce38..61cef31d3b 100644
--- a/nuttx/libnx/nxtk/nxtk_drawlinetoolbar.c
+++ b/nuttx/libnx/nxtk/nxtk_drawlinetoolbar.c
@@ -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;
}
diff --git a/nuttx/libnx/nxtk/nxtk_drawlinewindow.c b/nuttx/libnx/nxtk/nxtk_drawlinewindow.c
index 8183bf79de..584ff457cb 100644
--- a/nuttx/libnx/nxtk/nxtk_drawlinewindow.c
+++ b/nuttx/libnx/nxtk/nxtk_drawlinewindow.c
@@ -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;
}
diff --git a/nuttx/libnx/nxtk/nxtk_fillcircletoolbar.c b/nuttx/libnx/nxtk/nxtk_fillcircletoolbar.c
index b4ec94edd8..af502c7660 100644
--- a/nuttx/libnx/nxtk/nxtk_fillcircletoolbar.c
+++ b/nuttx/libnx/nxtk/nxtk_fillcircletoolbar.c
@@ -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;
}
diff --git a/nuttx/libnx/nxtk/nxtk_fillcirclewindow.c b/nuttx/libnx/nxtk/nxtk_fillcirclewindow.c
index ee59ace1e0..b155e85ff9 100644
--- a/nuttx/libnx/nxtk/nxtk_fillcirclewindow.c
+++ b/nuttx/libnx/nxtk/nxtk_fillcirclewindow.c
@@ -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;
}