Update of /cvsroot/ggi/ggi-core/libggi/programs/demos
In directory sc8-pr-cvs1:/tmp/cvs-serv2090
Modified Files:
Makefile.am pageflip.c
Log Message:
Added animation to test all primitives in multi-frame environment.
Index: Makefile.am
===================================================================
RCS file: /cvsroot/ggi/ggi-core/libggi/programs/demos/Makefile.am,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Makefile.am 21 Dec 2002 18:37:53 -0000 1.5
+++ Makefile.am 23 Jan 2003 03:05:55 -0000 1.6
@@ -13,7 +13,7 @@
# -lgg is needed for ggUSleep() and ggCurTime()
demo_LDADD = ${top_builddir}/ggi/libggi.la -lgg
flying_ggis_LDADD = ${top_builddir}/ggi/libggi.la -lgg -lm
-pageflip_LDADD = ${top_builddir}/ggi/libggi.la -lgg
+pageflip_LDADD = ${top_builddir}/ggi/libggi.la -lgg -lm
saver_LDADD = ${top_builddir}/ggi/libggi.la -lgg -lm
slimy_LDADD = ${top_builddir}/ggi/libggi.la -lm
stars_LDADD = ${top_builddir}/ggi/libggi.la -lgg -lm
Index: pageflip.c
===================================================================
RCS file: /cvsroot/ggi/ggi-core/libggi/programs/demos/pageflip.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- pageflip.c 17 Jun 2001 09:08:28 -0000 1.2
+++ pageflip.c 23 Jan 2003 03:05:55 -0000 1.3
@@ -36,12 +36,79 @@
#include <stdlib.h>
#include <time.h>
#include <ggi/ggi.h>
+#include <math.h>
ggi_color black = { 0x0000, 0x0000, 0x0000 };
ggi_color white = { 0xffff, 0xffff, 0xffff };
ggi_color blue = { 0x0000, 0x0000, 0xffff };
ggi_color yellow = { 0xffff, 0xffff, 0x0000 };
+void animate_one_frame(ggi_visual_t vis, int x, int y, int w, int h,
+ ggi_pixel *buf, int x2) {
+
+ ggiDrawHLine(vis, x, y, w);
+ ggiDrawHLine(vis, x, y + h - 1, w);
+ ggiDrawVLine(vis, x, y, h);
+ ggiDrawVLine(vis, x + w - 1, y, h);
+ ggiDrawBox(vis, x + 2, y + 2, w - 4, h - 4);
+ ggiGetBox(vis, x + 5, y + 5, w - 10, h/2 - 7, buf);
+ ggiPutBox(vis, x + 5, y + 5, w - 10, h/2 - 7, buf);
+ ggiCopyBox(vis, x+5, y + h/2, w - 10, h/2 - 5, x+5, y + h/2);
+ ggiPuts(vis, x + 7, y + 7, "Get/Put");
+ ggiPuts(vis, x + 7, y + h/2 + 2, "Copy");
+
+ ggiDrawBox(vis, x2, y, 5, 5);
+
+}
+
+void animate(ggi_visual_t vis, ggi_mode *mode, int j) {
+ int f, w, h;
+ ggi_pixel *buf;
+ ggi_color c1, c2;
+
+ c1.r = ((sin((double)j / 100) + 1) * 32768);
+ c1.g = ((sin(2.094394 + (double)j / 100) + 1) * 32768);
+ c1.b = ((sin(4.188789 + (double)j / 100) + 1) * 32768);
+ c1.a = 0;
+
+ c2.r = ((sin(3.141592 + (double)j / 100) + 1) * 32768);
+ c2.g = ((sin(5.235986 + (double)j / 100) + 1) * 32768);
+ c2.b = ((sin(7.330381 + (double)j / 100) + 1) * 32768);
+ c2.a = 0;
+
+ ggiSetGCForeground(vis, ggiMapColor(vis, &c1));
+ ggiSetGCBackground(vis, ggiMapColor(vis, &c2));
+
+ w = mode->virt.x / mode->frames;
+ h = mode->virt.y / 5;
+
+ buf = malloc(w * h * GT_SIZE(mode->graphtype));
+ if (buf == NULL) return;
+
+ ggiSetOrigin(vis, j % (mode->virt.x - mode->visible.x + 1),
+ j % (mode->virt.y - mode->visible.y + 1));
+
+ for (f = 0; f < mode->frames; f++) {
+ int x, y, yspan;
+
+ x = f * w;
+ yspan = mode->virt.y - h;
+ y = (j + (yspan * 2 * (f/mode->frames))) % (2 * yspan);
+ y += yspan * 2 * f/mode->frames;
+ y %= yspan * 2;
+ if (y >= yspan) y = yspan * 2 - y;
+ x += (sin(3.14159264 * 4 * y / yspan) + 1) * (w * 1 / 10);
+ ggiSetWriteFrame(vis, f);
+ ggiSetReadFrame(vis, (f+1) % mode->frames);
+ animate_one_frame(vis, x, y, w * 4/5, h, buf,
+ (x + w * (mode->frames - 1) + w/2) %
+ mode->virt.x);
+ }
+
+ free(buf);
+}
+
+
int main(int argc, char *argv[])
{
@@ -102,17 +169,30 @@
return 1;
}
+ ggiSetGCBackground(vis, ggiMapColor(vis, &white));
+ ggiSetGCForeground(vis, ggiMapColor(vis, &white));
+ ggiFillscreen(vis);
+ }
+
+ /* Clip a small border so that clipping can be verified. */
+ ggiSetGCClipping(vis, 5, 5, mode.virt.x - 5, mode.virt.y - 5);
+
+ /* Write something into each frame */
+ for(i = 0; i < mode.frames; i++) {
+
+ ggiSetWriteFrame(vis, i);
+
ggiSetGCBackground(vis, ggiMapColor(vis, &black));
ggiSetGCForeground(vis, ggiMapColor(vis, &black));
ggiFillscreen(vis);
sprintf(buf, "Hello World #%d!", i);
- for (j=0; j < mode.visible.y; j += cy) {
+ for (j=0; j < mode.virt.y; j += cy) {
ggi_color col;
- int x = random() % mode.visible.x;
+ int x = random() % mode.virt.x;
int h = (random() & 0x7fff) + 0x8000;
int l = (random() & 0x7fff);
@@ -131,6 +211,7 @@
/* Cycle through frames */
i = 0;
+ j = 0;
do {
if(ggiSetDisplayFrame(vis, i)) {
ggiPanic("Cannot set display frame!\n");
@@ -139,8 +220,16 @@
ggiFlush(vis);
/* Wait */
+ c = GIIK_VOID;
do {
- c = ggiGetc(vis);
+ struct timeval tv={0,0};
+ int key;
+
+ key = ggiEventPoll(vis,emKeyPress,&tv);
+ if (key & emKeyPress) c = ggiGetc(vis);
+ ggUSleep(50000);
+ animate(vis, &mode, j);
+ j++;
} while (c==GIIK_VOID || GII_KTYP(c)==GII_KT_MOD);
i = (i+1) % mode.frames;
|