main.c (13264B)
1 /* 2 Copyright (c) 2012, Broadcom Europe Ltd 3 All rights reserved. 4 5 Redistribution and use in source and binary forms, with or without 6 modification, are permitted provided that the following conditions are met: 7 * Redistributions of source code must retain the above copyright 8 notice, this list of conditions and the following disclaimer. 9 * Redistributions in binary form must reproduce the above copyright 10 notice, this list of conditions and the following disclaimer in the 11 documentation and/or other materials provided with the distribution. 12 * Neither the name of the copyright holder nor the 13 names of its contributors may be used to endorse or promote products 14 derived from this software without specific prior written permission. 15 16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 // Test app for VG font library. 29 30 #include <stdio.h> 31 #include <stdlib.h> 32 #include <string.h> 33 #include <assert.h> 34 #include <unistd.h> 35 36 #include "bcm_host.h" 37 #include "vgfont.h" 38 39 int32_t render_subtitle(GRAPHICS_RESOURCE_HANDLE img, const char *text, const uint32_t text_size, const uint32_t text_size_selected, const uint32_t x_offset, const uint32_t y_offset, uint32_t fontcolor) 40 { 41 uint32_t height=0; 42 uint32_t img_w, img_h; 43 44 graphics_get_resource_size(img, &img_w, &img_h); 45 46 // split now points to last line of text. split-text = length of initial text. text_length-(split-text) is length of last line 47 if (fontcolor == 7) { 48 graphics_resource_render_text_ext(img, x_offset, y_offset-height, 49 GRAPHICS_RESOURCE_WIDTH, 50 GRAPHICS_RESOURCE_HEIGHT, 51 GRAPHICS_RGBA32(255,255,255,100), /* fg */ 52 GRAPHICS_RGBA32(20,20,20,200), /* bg */ 53 text, 90, text_size); 54 } 55 if (fontcolor == 6) { 56 graphics_resource_render_text_ext(img, x_offset, y_offset-height, 57 GRAPHICS_RESOURCE_WIDTH, 58 GRAPHICS_RESOURCE_HEIGHT, 59 GRAPHICS_RGBA32(225,255,255,0), /* fg */ 60 GRAPHICS_RGBA32(0,0,0,0), /* bg */ 61 text, 90, text_size); 62 } 63 if (fontcolor == 5) { 64 graphics_resource_render_text_ext(img, x_offset, y_offset-height, 65 GRAPHICS_RESOURCE_WIDTH, 66 GRAPHICS_RESOURCE_HEIGHT, 67 GRAPHICS_RGBA32(255,255,255,0xff), /* fg */ 68 GRAPHICS_RGBA32(0,0,0,150), /* bg */ 69 text, 90, text_size); 70 } 71 if (fontcolor == 4) { 72 graphics_resource_render_text_ext(img, x_offset, y_offset-height, 73 GRAPHICS_RESOURCE_WIDTH, 74 GRAPHICS_RESOURCE_HEIGHT, 75 GRAPHICS_RGBA32(30,255,255,0xff), /* fg */ 76 GRAPHICS_RGBA32(0,0,0,0), /* bg */ 77 text, 90, text_size); 78 } 79 if (fontcolor == 3) { 80 graphics_resource_render_text_ext(img, x_offset, y_offset-height, 81 GRAPHICS_RESOURCE_WIDTH, 82 GRAPHICS_RESOURCE_HEIGHT, 83 GRAPHICS_RGBA32(30,30,255,0xff), /* fg */ 84 GRAPHICS_RGBA32(0,0,0,0), /* bg */ 85 text, 90, text_size); 86 } 87 if (fontcolor == 2) { 88 graphics_resource_render_text_ext(img, x_offset, y_offset-height, 89 GRAPHICS_RESOURCE_WIDTH, 90 GRAPHICS_RESOURCE_HEIGHT, 91 GRAPHICS_RGBA32(30,255,30,0xff), /* fg */ 92 GRAPHICS_RGBA32(0,0,0,0), /* bg */ 93 text, 90, text_size); 94 } 95 if (fontcolor == 1) { 96 graphics_resource_render_text_ext(img, x_offset, y_offset-height, 97 GRAPHICS_RESOURCE_WIDTH, 98 GRAPHICS_RESOURCE_HEIGHT, 99 GRAPHICS_RGBA32(0,0,0,0xff), /* fg */ 100 GRAPHICS_RGBA32(30,255,255,0xff), /* bg */ 101 text, 90, text_size_selected); 102 } 103 return 0; 104 } 105 106 int main(void) 107 { 108 GRAPHICS_RESOURCE_HANDLE img; 109 uint32_t width, height; 110 int LAYER=10; 111 bcm_host_init(); 112 int s; 113 114 s = gx_graphics_init("."); 115 assert(s == 0); 116 117 s = graphics_get_display_size(0, &width, &height); 118 assert(s == 0); 119 120 s = gx_create_window(0, width, height, GRAPHICS_RESOURCE_RGBA32, &img); 121 assert(s == 0); 122 123 // transparent before display to avoid screen flash 124 graphics_resource_fill(img, 0, 0, width, height, GRAPHICS_RGBA32(0,0,0,0x00)); 125 126 graphics_display_resource(img, 0, LAYER, 0, 0, GRAPHICS_RESOURCE_WIDTH, GRAPHICS_RESOURCE_HEIGHT, VC_DISPMAN_ROT0, 1); 127 128 FILE * fp; 129 FILE * fp2; 130 FILE * fp3; 131 char * line = 0; 132 //char * b = NULL; 133 size_t len = 0; 134 ssize_t read = 0; 135 int linenr = 0; 136 int selected; 137 int showmenu; 138 int header; 139 int menuadd = 1; 140 char newread[500]; 141 char oldread[500]; 142 char vumeter[130]; 143 uint32_t y_offset2 = 0; 144 uint32_t y_offset3 = 21; 145 uint32_t y_offset4 = 42; 146 uint32_t y_offset5 = 421; 147 uint32_t y_offset6 = 442; 148 uint32_t y_offset = 466; 149 uint32_t text_size = 15; 150 uint32_t text_size_selected = 16; 151 int space = 10; 152 int morespace = 12; 153 int rectime = 700; 154 int color = 3; 155 int row1 = 0; 156 int row2 = 0; 157 int row3 = 0; 158 int row4 = 0; 159 int row5 = 0; 160 int moverow = 0; 161 if (width == 1920){ 162 y_offset2 = 5; 163 y_offset3 = 45; 164 y_offset4 = 85; 165 y_offset5 = 960; 166 y_offset6 = 1000; 167 y_offset = 1040; 168 rectime = 1600; 169 text_size = 30; 170 text_size_selected = 32; 171 space = 23; 172 morespace = 27; 173 } 174 if (width < 799){ 175 y_offset2 = 16; 176 y_offset3 = 30; 177 y_offset4 = 43; 178 y_offset5 = 433; 179 y_offset6 = 445; 180 y_offset = 457; 181 rectime = 600; 182 text_size = 11; 183 text_size_selected = 11; 184 space = 7; 185 morespace = 10; 186 moverow = 20; 187 } 188 while (1) { 189 // char ch; 190 linenr = 0; 191 fp = fopen("/dev/shm/interface","r"); 192 if (fp != NULL){ 193 fread(newread, sizeof(char), 500, fp); 194 fclose(fp); 195 } 196 fp3 = fopen("/dev/shm/vumeter","r"); 197 while(fgets(vumeter, 130, fp3) != NULL); 198 fclose(fp3); 199 // check if something has changed 200 if (strcmp(newread, oldread) != 0) { 201 strcpy(oldread, newread); 202 //const char *text = "Never give up on your dreams"; 203 color = 3; 204 row1 = 0+moverow; 205 row2 = 0+moverow; 206 row3 = 0+moverow; 207 row4 = 0+moverow; 208 row5 = 0+moverow; 209 graphics_resource_fill(img, 0, 0, width, height, GRAPHICS_RGBA32(0,0,0,0x00)); 210 // blue, at the top (y=40) 211 // selected 0 1 2 3 4 5 6 7 8 212 213 // draw the text if updated 214 fp2 = fopen("/dev/shm/interface", "r"); 215 if (fp2 != NULL){ 216 while ((read = getline(&line, &len, fp2)) != -1) { 217 //line = b; 218 read = read - 1; //don't count the selected line 219 line[read] = '\0'; //remove return char 220 //strcat(line, " "); 221 //printf("%s",line); 222 if (linenr == 0) 223 selected = atoi(line); 224 if (linenr == 1) 225 showmenu = atoi(line); 226 if (linenr == selected + 2 + menuadd) 227 color = 1; //selected color 228 else { 229 if (showmenu == 1) 230 color = 5; //unselected; 231 if (showmenu == 2) 232 color = 7; 233 if (showmenu == 0) 234 color = 6; 235 }; 236 if ((linenr == 2) && (read == 0)) 237 header = 0; 238 if ((linenr == 2) && (read > 0)) 239 header = 1; 240 if (selected == 420){ 241 if (linenr == 1) 242 render_subtitle(img, line, text_size, text_size_selected, moverow, y_offset2, 5); 243 if (linenr > 1) { 244 render_subtitle(img, line, text_size, text_size_selected, row1, y_offset3, 5); 245 row1 += read * space + morespace; 246 } 247 } 248 if (header == 0){ //check if normal menu or header menu 249 if (selected < 420){ 250 if ((linenr == 6+menuadd) && (read > 0)){ //show recording time if there is any 251 render_subtitle(img, line, text_size, text_size_selected, rectime, y_offset2, 3); 252 } 253 if (linenr >= 2+menuadd && linenr <= 5+menuadd){ 254 if (color == 6) 255 color = 5; 256 render_subtitle(img, line, text_size, text_size_selected, row1, y_offset2, color); 257 row1 += read * space + morespace; 258 } 259 if (linenr >= 7+menuadd && linenr <= 12+menuadd){ 260 render_subtitle(img, line, text_size, text_size_selected, row2, y_offset3, color); 261 row2 += read * space + morespace; 262 } 263 if (linenr >= 13+menuadd && linenr <= 20+menuadd){ 264 render_subtitle(img, line, text_size, text_size_selected, row3, y_offset4, color); 265 row3 += read * space + morespace; 266 } 267 if (linenr >= 21+menuadd && linenr <= 27+menuadd){ 268 render_subtitle(img, line, text_size, text_size_selected, row4, y_offset5, color); 269 row4 += read * space + morespace; 270 } 271 if (linenr >= 28+menuadd && linenr <= 40+menuadd){ 272 render_subtitle(img, line, text_size, text_size_selected, row5, y_offset6, color); 273 row5 += read * space + morespace; 274 } 275 } 276 } 277 else { // header menu 278 if (linenr == 1+menuadd) 279 render_subtitle(img, line, text_size, text_size_selected, moverow, y_offset2, 5); 280 if (linenr > 1+menuadd){ 281 render_subtitle(img, line, text_size, text_size_selected, row1, y_offset3, color); 282 row1 += read * space + morespace; 283 } 284 } 285 linenr += 1; 286 free(line); 287 line = NULL; 288 } 289 free(line); 290 line = NULL; 291 fclose(fp2); 292 } 293 //graphics_update_displayed_resource(img, 0, 0, 0, 0); 294 } 295 char s_vol1 = vumeter[85]; 296 char s_vol2 = vumeter[86]; 297 char s_vol[1]; 298 s_vol[0] = s_vol1; 299 s_vol[1] = s_vol2; 300 int vol = atoi(s_vol); 301 int vucolor = 6; 302 //printf("%s", s_vol); 303 if (vol >= 0 && vol < 35) 304 vucolor = 4; 305 if (vol >= 35 && vol < 99) 306 vucolor = 2; 307 if (vol >= 99) 308 vucolor = 3; 309 render_subtitle(img, vumeter, text_size, text_size_selected , moverow, y_offset, vucolor); 310 graphics_update_displayed_resource(img, 0, 0, 0, 0); 311 usleep(20000); 312 } 313 graphics_display_resource(img, 0, LAYER, 0, 0, GRAPHICS_RESOURCE_WIDTH, GRAPHICS_RESOURCE_HEIGHT, VC_DISPMAN_ROT0, 0); 314 graphics_delete_resource(img); 315 return 0; 316 } 317