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.
ugfx_release_2.6
inmarket 2013-09-25 17:15:50 +10:00
parent f16d80e099
commit c5ceb31e73
2 changed files with 41 additions and 22 deletions

View File

@ -27,7 +27,7 @@
#define GDISP_NEED_ARC FALSE #define GDISP_NEED_ARC FALSE
#define GDISP_NEED_SCROLL FALSE #define GDISP_NEED_SCROLL FALSE
#define GDISP_NEED_PIXELREAD FALSE #define GDISP_NEED_PIXELREAD FALSE
#define GDISP_NEED_CONTROL TRUE #define GDISP_NEED_CONTROL FALSE
#define GDISP_NEED_MULTITHREAD FALSE #define GDISP_NEED_MULTITHREAD FALSE
#define GDISP_NEED_STREAMING TRUE #define GDISP_NEED_STREAMING TRUE

View File

@ -40,35 +40,44 @@
#define WALLCOLOR HTML2COLOR(0x303030) #define WALLCOLOR HTML2COLOR(0x303030)
#define BACKCOLOR HTML2COLOR(0xC0C0C0) #define BACKCOLOR HTML2COLOR(0xC0C0C0)
#define FLOORCOLOR HTML2COLOR(0x606060) #define FLOORCOLOR HTML2COLOR(0x606060)
#define SHADOW (255-255*0.2) #define SHADOWALPHA (255-255*0.2)
int main(void) { 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; color_t colour;
float ii, spin, o, spinspeed, h, f, g; float ii, spin, dy, spinspeed, h, f, g;
gfxInit(); gfxInit();
gdispSetOrientation(GDISP_ROTATE_90); #if GDISP_NEED_CONTROL
gdispSetOrientation(GDISP_ROTATE_90);
#endif
width = gdispGetWidth(); width = gdispGetWidth();
height = gdispGetHeight(); height = gdispGetHeight();
i=height/5+height%2+1; radius=height/5+height%2+1; // The ball radius
ii = 1.0/i; ii = 1.0/radius; // radius as easy math
floor=height/5-1; floor=height/5-1; // floor position
spin=0.0; spin=0.0; // current spin angle on the ball
l=width/2; spinspeed=0.1; // current spin speed of the ball
m=height/4; ballx=width/2; // ball x position (relative to the ball center)
n=.01*width; bally=height/4; // ball y position (relative to the ball center)
o=0.0; dx=.01*width; // motion in the x axis
spinspeed=0.1; 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) { while(1) {
// Draw one frame // Draw one frame
gdispStreamStart(0, 0, width, height); gdispStreamStart(minx, miny, maxx-minx, maxy-miny);
for (y=0; h = (m-y)*ii, y<height; y++) { for (y=miny; h = (bally-y)*ii, y<maxy; y++) {
for (x=0; x < width; x++) { for (x=minx; x < maxx; x++) {
g=(l-x)*ii; g=(ballx-x)*ii;
f=-.3*g+.954*h; f=-.3*g+.954*h;
if (g*g < 1-h*h) { if (g*g < 1-h*h) {
/* The inside of the ball */ /* The inside of the ball */
@ -90,17 +99,27 @@ int main(void) {
// The ball shadow is darker // The ball shadow is darker
if (g*(g+.4)+h*(h+.1) < 1) if (g*(g+.4)+h*(h+.1) < 1)
colour = gdispBlendColor(colour, Black, SHADOW); colour = gdispBlendColor(colour, Black, SHADOWALPHA);
} }
gdispStreamColor(colour); /* pixel to the LCD */ gdispStreamColor(colour); /* pixel to the LCD */
} }
} }
gdispStreamStop(); 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 // Motion
spin += spinspeed; spin += spinspeed;
m += o; ballx += dx; bally += dy;
o = m > height-1.75*floor ? -.04*height : o+.002*height; dx = ballx < radius || ballx > width-radius ? spinspeed=-spinspeed,-dx : dx;
n = (l+=n)<i || l>width-i ? spinspeed=-spinspeed,-n : n; dy = bally > height-1.75*floor ? -.04*height : dy+.002*height;
} }
} }