tests/interactive-ascii: improve padshapes1.c
authorMatthew Mondor <mmondor@pulsar-zone.net>
Thu, 13 Apr 2023 13:20:49 +0000 (13:20 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Thu, 13 Apr 2023 13:20:49 +0000 (13:20 +0000)
- Bugfixes, discovered when testing on ncurses(3) vs curses(3)
- More comments

tests/interactive-ascii/padshapes1.c

index c44ec75..b2a8849 100644 (file)
@@ -160,7 +160,10 @@ main(void)
        /* Convert strings to pads */
        shape_init(COLOR_PAIR(8));
 
-       /* Enable hardware features if available */
+       /*
+        * Enable hardware features if available.
+        * Apparently sometimes beneficial other times not.
+        */
        /*
        if (has_ic())
                idcok(w, TRUE);
@@ -314,6 +317,7 @@ int_min(int a, int b)
        return (a < b ? a : b);
 }
 
+/* 2d text shape blitting routine */
 static void
 shape_draw(int shape, int y, int x)
 {
@@ -327,8 +331,8 @@ shape_draw(int shape, int y, int x)
        yo = ys / 2;
 
        (void)copywin(pad, w, 0, 0, y - yo, x - xo,
-           int_min(y + ys - 1, TERM_LINES - 1),
-           int_min(x + xs - 1, TERM_COLUMNS - 1),
+           int_min((y - yo) + ys - 1, TERM_LINES - 1),
+           int_min((x - xo) + xs - 1, TERM_COLUMNS - 1),
            TRUE);
 }
 
@@ -342,6 +346,7 @@ anim_init(void)
        for (i = 0; i < NOBJECTS; i++) {
                aobject_t *o = &objects[i];
 
+               /* 24 bugs, 20 stars, 10 shapes */
                if (i <= 26) {
                        o->t = AOT_BUG;
                        o->c = 'A' + i;
@@ -371,6 +376,7 @@ anim_redraw(void)
 {
        int i;
 
+       /* Redraw screen with all objects */
        (void)attrset(COLOR_PAIR(0));
        (void)erase();
        for (i = 0; i < NOBJECTS; i++) {
@@ -407,9 +413,10 @@ anim_update(void)
                        else
                                x = TERM_COLUMNS - 1;
                } else {
-                       /* Change direction */
+                       /* Change direction 1/4 of the time */
                        if (d > -1 && d < 4)
                                o->d = d;
+                       /* Move in current direction */
                        switch (o->d) {
                        case 0: /* Up */
                                if (y > 0)