main.c (12200B)
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 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, 16); 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 uint32_t text_size = 15; 129 FILE * fp; 130 FILE * fp2; 131 FILE * fp3; 132 char * line = 0; 133 //char * b = NULL; 134 size_t len = 0; 135 ssize_t read = 0; 136 int linenr = 0; 137 int selected; 138 int showmenu; 139 int header; 140 int menuadd = 1; 141 char newread[500]; 142 char oldread[500]; 143 char vumeter[130]; 144 while (1) { 145 // char ch; 146 linenr = 0; 147 fp = fopen("/dev/shm/interface","r"); 148 if (fp != NULL){ 149 fread(newread, sizeof(char), 500, fp); 150 fclose(fp); 151 } 152 fp3 = fopen("/dev/shm/vumeter","r"); 153 while(fgets(vumeter, 130, fp3) != NULL); 154 fclose(fp3); 155 // check if something has changed 156 if (strcmp(newread, oldread) != 0) { 157 strcpy(oldread, newread); 158 //const char *text = "Never give up on your dreams"; 159 uint32_t y_offset2 = 0; 160 uint32_t y_offset3 = 21; 161 uint32_t y_offset4 = 42; 162 uint32_t y_offset5 = 421; 163 uint32_t y_offset6 = 442; 164 graphics_resource_fill(img, 0, 0, width, height, GRAPHICS_RGBA32(0,0,0,0x00)); 165 // blue, at the top (y=40) 166 // selected 0 1 2 3 4 5 6 7 8 167 int space = 10; 168 int morespace = 12; 169 int color = 3; 170 int row1 = 0; 171 int row2 = 0; 172 int row3 = 0; 173 int row4 = 0; 174 int row5 = 0; 175 // draw the text if updated 176 fp2 = fopen("/dev/shm/interface", "r"); 177 if (fp2 != NULL){ 178 while ((read = getline(&line, &len, fp2)) != -1) { 179 //line = b; 180 read = read - 1; //don't count the selected line 181 line[read] = '\0'; //remove return char 182 //strcat(line, " "); 183 //printf("%s",line); 184 if (linenr == 0) 185 selected = atoi(line); 186 if (linenr == 1) 187 showmenu = atoi(line); 188 if (linenr == selected + 2 + menuadd) 189 color = 1; //selected color 190 else { 191 if (showmenu == 1) 192 color = 5; //unselected; 193 if (showmenu == 2) 194 color = 7; 195 if (showmenu == 0) 196 color = 6; 197 }; 198 if ((linenr == 2) && (read == 0)) 199 header = 0; 200 if ((linenr == 2) && (read > 0)) 201 header = 1; 202 if (selected == 420){ 203 if (linenr == 1) 204 render_subtitle(img, line, text_size, 0, y_offset2, 5); 205 if (linenr > 1) { 206 render_subtitle(img, line, text_size, row1, y_offset3, 5); 207 row1 += read * space + morespace; 208 } 209 } 210 if (header == 0){ //check if normal menu or header menu 211 if (selected < 420){ 212 if ((linenr == 6+menuadd) && (read > 0)){ //show recording time if there is any 213 render_subtitle(img, line, text_size, 700, y_offset2, 3); 214 } 215 if (linenr >= 2+menuadd && linenr <= 5+menuadd){ 216 if (color == 6) 217 color = 5; 218 render_subtitle(img, line, text_size, row1, y_offset2, color); 219 row1 += read * space + morespace; 220 } 221 if (linenr >= 7+menuadd && linenr <= 12+menuadd){ 222 render_subtitle(img, line, text_size, row2, y_offset3, color); 223 row2 += read * space + morespace; 224 } 225 if (linenr >= 13+menuadd && linenr <= 20+menuadd){ 226 render_subtitle(img, line, text_size, row3, y_offset4, color); 227 row3 += read * space + morespace; 228 } 229 if (linenr >= 21+menuadd && linenr <= 27+menuadd){ 230 render_subtitle(img, line, text_size, row4, y_offset5, color); 231 row4 += read * space + morespace; 232 } 233 if (linenr >= 28+menuadd && linenr <= 40+menuadd){ 234 render_subtitle(img, line, text_size, row5, y_offset6, color); 235 row5 += read * space + morespace; 236 } 237 } 238 } 239 else { // header menu 240 if (linenr == 1+menuadd) 241 render_subtitle(img, line, text_size, 0, y_offset2, 5); 242 if (linenr > 1+menuadd){ 243 render_subtitle(img, line, text_size, row1, y_offset3, color); 244 row1 += read * space + morespace; 245 } 246 } 247 linenr += 1; 248 free(line); 249 line = NULL; 250 } 251 free(line); 252 line = NULL; 253 fclose(fp2); 254 } 255 //graphics_update_displayed_resource(img, 0, 0, 0, 0); 256 } 257 uint32_t y_offset = 466; 258 char s_vol1 = vumeter[85]; 259 char s_vol2 = vumeter[86]; 260 char s_vol[1]; 261 s_vol[0] = s_vol1; 262 s_vol[1] = s_vol2; 263 int vol = atoi(s_vol); 264 int vucolor = 6; 265 //printf("%s", s_vol); 266 if (vol >= 0 && vol < 35) 267 vucolor = 4; 268 if (vol >= 35 && vol < 99) 269 vucolor = 2; 270 if (vol >= 99) 271 vucolor = 3; 272 render_subtitle(img, vumeter, text_size, 0, y_offset, vucolor); 273 graphics_update_displayed_resource(img, 0, 0, 0, 0); 274 usleep(20000); 275 } 276 graphics_display_resource(img, 0, LAYER, 0, 0, GRAPHICS_RESOURCE_WIDTH, GRAPHICS_RESOURCE_HEIGHT, VC_DISPMAN_ROT0, 0); 277 graphics_delete_resource(img); 278 return 0; 279 } 280