aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Hannam <andrewh@inmarket.com.au>2012-12-06 22:24:28 +1000
committerAndrew Hannam <andrewh@inmarket.com.au>2012-12-06 22:24:28 +1000
commitec89b8e82d890066f60c48349da062add76db6cd (patch)
tree2cf66747b0fb82e4fc45cdc141456f79ab36e86c
parent07f34835358ef65de310934ae726b66c7ca46f68 (diff)
downloaduGFX-ec89b8e82d890066f60c48349da062add76db6cd.tar.gz
uGFX-ec89b8e82d890066f60c48349da062add76db6cd.tar.bz2
uGFX-ec89b8e82d890066f60c48349da062add76db6cd.zip
Fixes to GWIN graph and demo
-rw-r--r--demos/modules/graph/main.c25
-rw-r--r--src/gwin/graph.c3
2 files changed, 20 insertions, 8 deletions
diff --git a/demos/modules/graph/main.c b/demos/modules/graph/main.c
index bd2da2f6..40267522 100644
--- a/demos/modules/graph/main.c
+++ b/demos/modules/graph/main.c
@@ -13,9 +13,19 @@ int data[5][2] = {
GGraphObject g;
+GGraphStyle GraphStyle1 = {
+ { GGRAPH_POINT_DOT, 0, Blue }, // point
+ { GGRAPH_LINE_NONE, 2, Gray }, // line
+ { GGRAPH_LINE_SOLID, 0, White }, // x axis
+ { GGRAPH_LINE_SOLID, 0, White }, // y axis
+ { GGRAPH_LINE_NONE, 0, White, 0 }, // x grid
+ { GGRAPH_LINE_NONE, 0, White, 0 }, // y grid
+ GWIN_GRAPH_STYLE_XAXIS_ARROWS|GWIN_GRAPH_STYLE_YAXIS_ARROWS // flags
+};
+
GGraphStyle GraphStyle2 = {
{ GGRAPH_POINT_DOT, 0, Green }, // point
- { GGRAPH_LINE_DOT, 2, Gray }, // line
+ { GGRAPH_LINE_NONE, 2, Gray }, // line
{ GGRAPH_LINE_SOLID, 0, White }, // x axis
{ GGRAPH_LINE_SOLID, 0, White }, // y axis
{ GGRAPH_LINE_NONE, 0, White, 0 }, // x grid
@@ -33,19 +43,20 @@ int main(void) {
gdispInit();
gdispClear(Black);
- gh = gwinCreateGraph(0, 0, gdispGetWidth(), gdispGetHeight());
+ gh = gwinCreateGraph(&g, 0, 0, gdispGetWidth(), gdispGetHeight());
- gwinGraphSetOrigin(gh, 150, 150);
+ gwinGraphSetOrigin(gh, gwinGetWidth(gh)/2, gwinGetHeight(gh)/2);
+ gwinGraphSetStyle(gh, &GraphStyle1);
gwinGraphDrawAxis(gh);
- for(i = 0; i < 2500; i++)
- gwinGraphDrawPoint(gh, i-170, 80*sin(2*0.2*M_PI*i/180));
+ for(i = 0; i < gwinGetWidth(gh); i++)
+ gwinGraphDrawPoint(gh, i-gwinGetWidth(gh)/2, 80*sin(2*0.2*M_PI*i/180));
gwinGraphStartSet(gh);
gwinGraphSetStyle(gh, &GraphStyle2);
- for(i = 0; i < 2500; i++)
- gwinGraphDrawPoint(gh, i/5-150, 95*sin(2*0.2*M_PI*i/180));
+ for(i = 0; i < gwinGetWidth(gh)*5; i++)
+ gwinGraphDrawPoint(gh, i/5-gwinGetWidth(gh)/2, 95*sin(2*0.2*M_PI*i/180));
while(TRUE) {
chThdSleepMilliseconds(100);
diff --git a/src/gwin/graph.c b/src/gwin/graph.c
index e950f623..581001ad 100644
--- a/src/gwin/graph.c
+++ b/src/gwin/graph.c
@@ -88,7 +88,7 @@ static void lineto(GGraphObject *gg, coord_t x0, coord_t y0, coord_t x1, coord_t
x0 += gg->gwin.x + gg->xorigin;
y0 = gg->gwin.y + gg->gwin.height - 1 - gg->yorigin - y0;
x1 += gg->gwin.x + gg->xorigin;
- y1 += gg->gwin.y + gg->gwin.height - 1 - gg->yorigin - y1;
+ y1 = gg->gwin.y + gg->gwin.height - 1 - gg->yorigin - y1;
if (style->size <= 0) {
// Use the driver to draw a solid line
@@ -235,6 +235,7 @@ void gwinGraphSetStyle(GHandle gh, const GGraphStyle *pstyle) {
gg->style.ygrid.size = pstyle->ygrid.size;
gg->style.ygrid.color = pstyle->ygrid.color;
gg->style.ygrid.spacing = pstyle->ygrid.spacing;
+ gg->style.flags = pstyle->flags;
#undef gg
}