1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
#include "glui.h"
#define DEFAULT_TITLE "RADIOLA"
#define SCREEN_X 640
#define SCREEN_Y 480
int glui_init( glui_t **t )
{
int ret=-1;
glui_t *tui = NULL;
tui = malloc( sizeof(glui_t) );
if (tui == NULL)
{
return -1;
}
memset(tui, 0, sizeof(glui_t));
if ( SDL_Init(SDL_INIT_VIDEO) != 0)
{
printf("Cannot init sdl\n");
return -1;
}
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;
}
*t = tui;
ret = 0;
return ret;
}
//init waterfall
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;
}
//first draw, draw all buffer
int glui_waterfall_draw( glui_waterfall_t *w )
{
int ret=-1;
return ret;
}
//redraw only changed lines
int glui_waterfall_redraw( glui_waterfall_t *w )
{
int ret=-1;
return ret;
}
//update params of waterfall and then need to draw not redraw
int glui_waterfall_update( glui_t *w )
{
int ret=-1;
return ret;
}
//push one line of data to buffer
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
glui_color_t glui_waterfall_color( uint8_t d )
{
glui_color_t c;
c.r = d;
c.g = d;
c.b = d;
return c;
}
//close terminal ui
int glui_close( glui_t *t )
{
int ret=0;
if ( t->win != NULL )
{
SDL_DestroyWindow( t->win );
}
SDL_Quit();
return ret;
}
|