diff options
author | FreeArtMan <dos21h@gmail.com> | 2015-10-02 21:25:53 +0100 |
---|---|---|
committer | FreeArtMan <dos21h@gmail.com> | 2015-10-02 21:25:53 +0100 |
commit | 992bed5fbbbe47917e862ef6a4aee3921bdf4abb (patch) | |
tree | fda00d50423c3c4ea785e96820e9545c0487f178 /draw | |
parent | 240c02c5d64ee02659d0bcbbc61ef3680cbf8ea2 (diff) | |
download | radiola-992bed5fbbbe47917e862ef6a4aee3921bdf4abb.tar.gz radiola-992bed5fbbbe47917e862ef6a4aee3921bdf4abb.zip |
graphical waterfall drawing
Diffstat (limited to 'draw')
-rw-r--r-- | draw/glui.c | 71 | ||||
-rw-r--r-- | draw/glui.h | 19 |
2 files changed, 76 insertions, 14 deletions
diff --git a/draw/glui.c b/draw/glui.c index 3e85646..fd27693 100644 --- a/draw/glui.c +++ b/draw/glui.c @@ -24,16 +24,17 @@ int glui_init( glui_t **t ) return -1; } - tui->win = SDL_CreateWindow("Hello World!", 100, 100, SCREEN_X, SCREEN_Y, SDL_WINDOW_SHOWN); + tui->h = SCREEN_Y; + tui->w = SCREEN_X; + tui->win = SDL_CreateWindow("Hello World!", tui->w, tui->h, SCREEN_X, SCREEN_Y, SDL_WINDOW_SHOWN); if (tui->win == NULL) { printf("Couldnt create SDL window\n"); return -1; } - tui->rend = SDL_CreateRenderer( tui->win, -1, SDL_RENDERER_ACCELERATED); - - + *t = tui; + ret = 0; return ret; } @@ -44,6 +45,33 @@ int glui_waterfall( glui_t **t, glui_waterfall_t **w ) { int ret=-1; + glui_waterfall_t *wtf = NULL; + + wtf = malloc( sizeof(glui_waterfall_t) ); + if ( wtf == NULL ) + { + printf("Cannot alloc waterfall\n"); + return -1; + } + + memset( wtf, 0, sizeof(glui_waterfall_t) ); + + wtf->h = (*t)->h; + wtf->w = (*t)->w; + wtf->cur_h = 5; + + + wtf->rend = SDL_CreateRenderer( (*t)->win, -1, SDL_RENDERER_ACCELERATED); + if ( wtf->rend == NULL ) + { + printf("Canno create SDL Rendered\n"); + return -1; + } + + (*w) = wtf; + (*t)->wf = wtf; + + ret = 0; return ret; } @@ -55,6 +83,7 @@ int glui_waterfall_draw( glui_waterfall_t *w ) int ret=-1; + return ret; } @@ -80,20 +109,44 @@ int glui_waterfall_update( glui_t *w ) //push one line of data to buffer -int glui_waterfall_data( glui_t *w, int len, uint8_t *buf ) +int glui_waterfall_data( glui_t *t, int len, uint8_t *buf ) { int ret=-1; + int i; + int y; + glui_color_t c = glui_waterfall_color(0); + SDL_Point *pt = NULL; + + SDL_SetRenderDrawColor( t->wf->rend, c.r, c.g, c.b, c.a ); + y = t->wf->cur_h; + t->wf->cur_h += 1; + pt = malloc( sizeof(SDL_Point) ); + for ( i=0; i<len; i++ ) + { + c = glui_waterfall_color(buf[i]); + SDL_SetRenderDrawColor( t->wf->rend, c.r, c.g, c.b, c.a ); + pt[0].x = i; + pt[0].y = y; + SDL_RenderDrawPoints( t->wf->rend, pt, 1 ); + } + + + SDL_RenderPresent( t->wf->rend ); + ret = 0; return ret; } //return color -uint8_t glui_waterfall_color( uint8_t d ) +glui_color_t glui_waterfall_color( uint8_t d ) { - uint8_t c; + glui_color_t c; + c.r = d; + c.g = d; + c.b = d; return c; } @@ -104,10 +157,6 @@ int glui_close( glui_t *t ) { int ret=0; - if ( t->rend ) - { - SDL_DestroyRenderer( t->rend ); - } if ( t->win != NULL ) { diff --git a/draw/glui.h b/draw/glui.h index f9f9bdf..0b9f6f3 100644 --- a/draw/glui.h +++ b/draw/glui.h @@ -17,16 +17,29 @@ typedef struct glui_waterfall_t int h,w; uint8_t *buf; size_t buf_len; + int cur_h; + + SDL_Renderer *rend; } glui_waterfall_t; typedef struct glui_t { - SDL_Window *win; - SDL_Renderer *rend; + int h, w; + + SDL_Window *win; + glui_waterfall_t *wf; } glui_t; +typedef struct glui_color_t +{ + uint8_t r; + uint8_t g; + uint8_t b; + uint8_t a; +} glui_color_t; + //prepare terminal ui int glui_init( glui_t **t ); //init waterfall @@ -40,7 +53,7 @@ int glui_waterfall_update( glui_t *w ); //push one line of data to buffer int glui_waterfall_data( glui_t *w, int len, uint8_t *buf ); //return color -uint8_t glui_waterfall_color( uint8_t d ); +glui_color_t glui_waterfall_color( uint8_t d ); //close terminal ui int glui_close( glui_t *t ); |