aboutsummaryrefslogtreecommitdiffstats
path: root/demos
diff options
context:
space:
mode:
authorinmarket <andrewh@inmarket.com.au>2013-09-25 17:15:50 +1000
committerinmarket <andrewh@inmarket.com.au>2013-09-25 17:15:50 +1000
commitc5ceb31e730b31f003b3b61c1172670e6e549994 (patch)
tree4219a1eafdd29d45efe048aff3a303120f7f3988 /demos
parentf16d80e099fd7e7fad241d8d08525920235893e5 (diff)
downloaduGFX-c5ceb31e730b31f003b3b61c1172670e6e549994.tar.gz
uGFX-c5ceb31e730b31f003b3b61c1172670e6e549994.tar.bz2
uGFX-c5ceb31e730b31f003b3b61c1172670e6e549994.zip
Update to streaming demo program to only update the needed area (results in much faster display on slow devices)
Also now demonstrates streaming to a non-full screen area.
Diffstat (limited to 'demos')
-rw-r--r--demos/modules/gdisp/gdisp_streaming/gfxconf.h2
-rw-r--r--demos/modules/gdisp/gdisp_streaming/main.c61
2 files changed, 41 insertions, 22 deletions
diff --git a/demos/modules/gdisp/gdisp_streaming/gfxconf.h b/demos/modules/gdisp/gdisp_streaming/gfxconf.h
index 0b5701ba..72bb0618 100644
--- a/demos/modules/gdisp/gdisp_streaming/gfxconf.h
+++ b/demos/modules/gdisp/gdisp_streaming/gfxconf.h
@@ -27,7 +27,7 @@
#define GDISP_NEED_ARC FALSE
#define GDISP_NEED_SCROLL FALSE
#define GDISP_NEED_PIXELREAD FALSE
-#define GDISP_NEED_CONTROL TRUE
+#define GDISP_NEED_CONTROL FALSE
#define GDISP_NEED_MULTITHREAD FALSE
#define GDISP_NEED_STREAMING TRUE
diff --git a/demos/modules/gdisp/gdisp_streaming/main.c b/demos/modules/gdisp/gdisp_streaming/main.c
index cc5eb8b3..41b900c3 100644
--- a/demos/modules/gdisp/gdisp_streaming/main.c
+++ b/demos/modules/gdisp/gdisp_streaming/main.c
@@ -40,35 +40,44 @@
#define WALLCOLOR HTML2COLOR(0x303030)
#define BACKCOLOR HTML2COLOR(0xC0C0C0)
#define FLOORCOLOR HTML2COLOR(0x606060)
-#define SHADOW (255-255*0.2)
+#define SHADOWALPHA (255-255*0.2)
int main(void) {
- coord_t width, height, x, y, i, l, m, n, floor;
+ coord_t width, height, x, y, radius, ballx, bally, dx, floor;
+ coord_t minx, miny, maxx, maxy;
+ coord_t ballcx, ballcy;
color_t colour;
- float ii, spin, o, spinspeed, h, f, g;
+ float ii, spin, dy, spinspeed, h, f, g;
gfxInit();
- gdispSetOrientation(GDISP_ROTATE_90);
+ #if GDISP_NEED_CONTROL
+ gdispSetOrientation(GDISP_ROTATE_90);
+ #endif
width = gdispGetWidth();
height = gdispGetHeight();
- i=height/5+height%2+1;
- ii = 1.0/i;
- floor=height/5-1;
- spin=0.0;
- l=width/2;
- m=height/4;
- n=.01*width;
- o=0.0;
- spinspeed=0.1;
+ radius=height/5+height%2+1; // The ball radius
+ ii = 1.0/radius; // radius as easy math
+ floor=height/5-1; // floor position
+ spin=0.0; // current spin angle on the ball
+ spinspeed=0.1; // current spin speed of the ball
+ ballx=width/2; // ball x position (relative to the ball center)
+ bally=height/4; // ball y position (relative to the ball center)
+ dx=.01*width; // motion in the x axis
+ dy=0.0; // motion in the y axis
+ ballcx = 12*radius/5; // ball x diameter including the shadow
+ ballcy = 21*radius/10; // ball y diameter including the shadow
+
+
+ minx = miny = 0; maxx = width; maxy = height; // The clipping window for this frame.
while(1) {
// Draw one frame
- gdispStreamStart(0, 0, width, height);
- for (y=0; h = (m-y)*ii, y<height; y++) {
- for (x=0; x < width; x++) {
- g=(l-x)*ii;
+ gdispStreamStart(minx, miny, maxx-minx, maxy-miny);
+ for (y=miny; h = (bally-y)*ii, y<maxy; y++) {
+ for (x=minx; x < maxx; x++) {
+ g=(ballx-x)*ii;
f=-.3*g+.954*h;
if (g*g < 1-h*h) {
/* The inside of the ball */
@@ -90,17 +99,27 @@ int main(void) {
// The ball shadow is darker
if (g*(g+.4)+h*(h+.1) < 1)
- colour = gdispBlendColor(colour, Black, SHADOW);
+ colour = gdispBlendColor(colour, Black, SHADOWALPHA);
}
gdispStreamColor(colour); /* pixel to the LCD */
}
}
gdispStreamStop();
+ // Calculate the new frame size (note this is a drawing optimisation only)
+ minx = ballx - radius; miny = bally - radius;
+ maxx = minx + ballcx; maxy = miny + ballcy;
+ if (dx > 0) maxx += dx; else minx += dx;
+ if (dy > 0) maxy += dy; else miny += dy;
+ if (minx < 0) minx = 0;
+ if (maxx > width) maxx = width;
+ if (miny < 0) miny = 0;
+ if (maxy > height) maxy = height;
+
// Motion
spin += spinspeed;
- m += o;
- o = m > height-1.75*floor ? -.04*height : o+.002*height;
- n = (l+=n)<i || l>width-i ? spinspeed=-spinspeed,-n : n;
+ ballx += dx; bally += dy;
+ dx = ballx < radius || ballx > width-radius ? spinspeed=-spinspeed,-dx : dx;
+ dy = bally > height-1.75*floor ? -.04*height : dy+.002*height;
}
}