change parts with number keys
authorJohn Tsiombikas <nuclear@member.fsf.org>
Tue, 30 Aug 2016 20:36:01 +0000 (23:36 +0300)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Tue, 30 Aug 2016 20:36:01 +0000 (23:36 +0300)
src/demo.c
src/screen.c
src/screen.h
src/tunnel.c

index 9954cb5..7d22dc4 100644 (file)
@@ -16,10 +16,12 @@ int mouse_x, mouse_y;
 unsigned int mouse_bmask;
 
 static unsigned long nframes;
 unsigned int mouse_bmask;
 
 static unsigned long nframes;
-static const char *start_scr_name = "tunnel";
+static const char *start_scr_name;
 
 int demo_init(int argc, char **argv)
 {
 
 int demo_init(int argc, char **argv)
 {
+       struct screen *scr;
+
        if(argv[1]) {
                start_scr_name = argv[1];
        }
        if(argv[1]) {
                start_scr_name = argv[1];
        }
@@ -27,8 +29,14 @@ int demo_init(int argc, char **argv)
        if(scr_init() == -1) {
                return -1;
        }
        if(scr_init() == -1) {
                return -1;
        }
-       if(scr_change(scr_lookup(start_scr_name), 4000) == -1) {
-               fprintf(stderr, "screen %s not found\n", start_scr_name);
+       if(start_scr_name) {
+               scr = scr_lookup(start_scr_name);
+       } else {
+               scr = scr_screen(0);
+       }
+
+       if(!scr || scr_change(scr, 4000) == -1) {
+               fprintf(stderr, "screen %s not found\n", start_scr_name ? start_scr_name : "0");
                return -1;
        }
 
                return -1;
        }
 
@@ -64,6 +72,11 @@ void demo_keyboard(int key, int state)
                        break;
 
                default:
                        break;
 
                default:
+                       if(key >= '1' && key <= '1' + scr_num_screens()) {
+                               int idx = key - '1';
+                               printf("change screen %d\n", idx);
+                               scr_change(scr_screen(idx), 4000);
+                       }
                        break;
                }
        }
                        break;
                }
        }
index a949fc4..2387d52 100644 (file)
@@ -1,6 +1,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <assert.h>
 #include "screen.h"
 #include "demo.h"
 
 #include "screen.h"
 #include "demo.h"
 
@@ -9,6 +10,7 @@ struct screen *fract_screen(void);
 
 #define NUM_SCR        32
 static struct screen *scr[NUM_SCR];
 
 #define NUM_SCR        32
 static struct screen *scr[NUM_SCR];
+static int num_screens;
 
 static struct screen *cur, *prev, *next;
 static long trans_start, trans_dur;
 
 static struct screen *cur, *prev, *next;
 static long trans_start, trans_dur;
@@ -23,9 +25,12 @@ int scr_init(void)
        if(!(scr[idx++] = fract_screen())) {
                return -1;
        }
        if(!(scr[idx++] = fract_screen())) {
                return -1;
        }
+       num_screens = idx;
 
 
-       for(i=0; i<NUM_SCR; i++) {
-               if(scr[i] && scr[i]->init() == -1) {
+       assert(num_screens <= NUM_SCR);
+
+       for(i=0; i<num_screens; i++) {
+               if(scr[i]->init() == -1) {
                        return -1;
                }
        }
                        return -1;
                }
        }
@@ -35,8 +40,7 @@ int scr_init(void)
 void scr_shutdown(void)
 {
        int i;
 void scr_shutdown(void)
 {
        int i;
-       for(i=0; i<NUM_SCR; i++) {
-               if(!scr[i]) break;
+       for(i=0; i<num_screens; i++) {
                scr[i]->shutdown();
        }
 }
                scr[i]->shutdown();
        }
 }
@@ -64,8 +68,7 @@ void scr_draw(void)
 struct screen *scr_lookup(const char *name)
 {
        int i;
 struct screen *scr_lookup(const char *name)
 {
        int i;
-       for(i=0; i<NUM_SCR; i++) {
-               if(!scr[i]) break;
+       for(i=0; i<num_screens; i++) {
                if(strcmp(scr[i]->name, name) == 0) {
                        return scr[i];
                }
                if(strcmp(scr[i]->name, name) == 0) {
                        return scr[i];
                }
@@ -73,6 +76,16 @@ struct screen *scr_lookup(const char *name)
        return 0;
 }
 
        return 0;
 }
 
+struct screen *scr_screen(int idx)
+{
+       return scr[idx];
+}
+
+int scr_num_screens(void)
+{
+       return num_screens;
+}
+
 int scr_change(struct screen *s, long trans_time)
 {
        if(!s) return -1;
 int scr_change(struct screen *s, long trans_time)
 {
        if(!s) return -1;
index 9a449e8..efb43f7 100644 (file)
@@ -20,6 +20,8 @@ void scr_update(void);
 void scr_draw(void);
 
 struct screen *scr_lookup(const char *name);
 void scr_draw(void);
 
 struct screen *scr_lookup(const char *name);
+struct screen *scr_screen(int idx);
+int scr_num_screens(void);
 int scr_change(struct screen *s, long trans_time);
 
 #endif /* SCREEN_H_ */
 int scr_change(struct screen *s, long trans_time);
 
 #endif /* SCREEN_H_ */
index 55eaefa..4fbc16b 100644 (file)
@@ -181,7 +181,12 @@ static void draw(void)
 
        for(i=0; i<NUM_WORK_ITEMS; i++) {
                int starty = i * num_lines;
 
        for(i=0; i<NUM_WORK_ITEMS; i++) {
                int starty = i * num_lines;
+               int resty = starty + draw_lines;
+               int rest_lines = num_lines - draw_lines;
                draw_tunnel_range((unsigned short*)fb_pixels, xoffs, yoffs, starty, draw_lines, time_msec);
                draw_tunnel_range((unsigned short*)fb_pixels, xoffs, yoffs, starty, draw_lines, time_msec);
+               if(rest_lines) {
+                       memset((unsigned short*)fb_pixels + resty * fb_width, 0, rest_lines * fb_width * 2);
+               }
        }
 }
 
        }
 }