amiga_imgv
annotate src/main.c @ 5:0d3d7b020e6a
progress...
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 27 Oct 2017 12:32:24 +0300 |
parents | a4788c959918 |
children | 4c36d0f44aa6 |
rev | line source |
---|---|
nuclear@0 | 1 #include <stdio.h> |
nuclear@0 | 2 #include <stdlib.h> |
nuclear@0 | 3 #include <string.h> |
nuclear@0 | 4 #include <assert.h> |
nuclear@0 | 5 #include "gfx.h" |
nuclear@0 | 6 #include "image.h" |
nuclear@0 | 7 #include "logger.h" |
nuclear@0 | 8 |
nuclear@0 | 9 |
nuclear@0 | 10 static int proc_event(union gfx_event *ev); |
nuclear@0 | 11 |
nuclear@0 | 12 int main(int argc, char **argv) |
nuclear@0 | 13 { |
nuclear@0 | 14 struct ham_image *img; |
nuclear@0 | 15 |
nuclear@0 | 16 if(argv[1]) { |
nuclear@0 | 17 if(!(img = load_ham_image(argv[1]))) { |
nuclear@0 | 18 fprintf(stderr, "failed to load image: %s\n", argv[1]); |
nuclear@0 | 19 return 1; |
nuclear@0 | 20 } |
nuclear@0 | 21 } else { |
nuclear@0 | 22 printf("generating test image ...\n"); |
nuclear@0 | 23 if(!(img = gen_ham_image(320, 256, 6))) { |
nuclear@0 | 24 fprintf(stderr, "failed to generate image\n"); |
nuclear@0 | 25 return 1; |
nuclear@0 | 26 } |
nuclear@0 | 27 } |
nuclear@0 | 28 |
nuclear@0 | 29 if(gfx_init(6, GFX_HAM) == -1) { |
nuclear@0 | 30 return 1; |
nuclear@0 | 31 } |
nuclear@0 | 32 gfx_wait_vblank(); |
nuclear@3 | 33 gfx_show_image(img); |
nuclear@0 | 34 |
nuclear@0 | 35 for(;;) { |
nuclear@0 | 36 union gfx_event ev; |
nuclear@0 | 37 if(gfx_next_event(&ev, GFX_EVLOOP_BLOCK)) { |
nuclear@0 | 38 if(proc_event(&ev) == -1) { |
nuclear@0 | 39 break; |
nuclear@0 | 40 } |
nuclear@0 | 41 } |
nuclear@0 | 42 } |
nuclear@0 | 43 |
nuclear@0 | 44 gfx_shutdown(); |
nuclear@0 | 45 return 0; |
nuclear@0 | 46 } |
nuclear@0 | 47 |
nuclear@0 | 48 static int proc_event(union gfx_event *ev) |
nuclear@0 | 49 { |
nuclear@0 | 50 switch(ev->type) { |
nuclear@0 | 51 case GFX_EV_QUIT: |
nuclear@0 | 52 return -1; |
nuclear@0 | 53 |
nuclear@0 | 54 case GFX_EV_KEY: |
nuclear@0 | 55 switch(ev->key.key) { |
nuclear@0 | 56 case 27: |
nuclear@0 | 57 return -1; |
nuclear@0 | 58 default: |
nuclear@0 | 59 break; |
nuclear@0 | 60 } |
nuclear@0 | 61 break; |
nuclear@0 | 62 |
nuclear@0 | 63 default: |
nuclear@0 | 64 break; |
nuclear@0 | 65 } |
nuclear@0 | 66 return 0; |
nuclear@0 | 67 } |