2 Copyright (c) 2012, Broadcom Europe Ltd
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.
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.
28 // Test app for VG font library.
39 static const char *strnchr(const char *str, size_t len, char c)
41 const char *e = str + len;
50 int32_t render_subtitle(GRAPHICS_RESOURCE_HANDLE img, const char *text, const int skip, const uint32_t text_size, const uint32_t y_offset)
52 uint32_t text_length = strlen(text)-skip;
53 uint32_t width=0, height=0;
54 const char *split = text;
56 int len = 0; // length of pre-subtitle
57 uint32_t img_w, img_h;
59 graphics_get_resource_size(img, &img_w, &img_h);
64 s = graphics_resource_text_dimensions_ext(img, split, text_length-(split-text), &width, &height, text_size);
67 const char *space = strnchr(split, text_length-(split-text), ' ');
79 // split now points to last line of text. split-text = length of initial text. text_length-(split-text) is length of last line
81 s = graphics_resource_render_text_ext(img, (img_w - width)>>1, y_offset-height,
82 GRAPHICS_RESOURCE_WIDTH,
83 GRAPHICS_RESOURCE_HEIGHT,
84 GRAPHICS_RGBA32(0xff,0xff,0xff,0xff), /* fg */
85 GRAPHICS_RGBA32(0,0,0,0x80), /* bg */
86 split, text_length-(split-text), text_size);
89 return render_subtitle(img, text, skip+text_length-len, text_size, y_offset - height);
94 GRAPHICS_RESOURCE_HANDLE img;
95 uint32_t width, height;
100 s = gx_graphics_init(".");
103 s = graphics_get_display_size(0, &width, &height);
106 s = gx_create_window(0, width, height, GRAPHICS_RESOURCE_RGBA32, &img);
109 // transparent before display to avoid screen flash
110 graphics_resource_fill(img, 0, 0, width, height, GRAPHICS_RGBA32(0,0,0,0x00));
112 graphics_display_resource(img, 0, LAYER, 0, 0, GRAPHICS_RESOURCE_WIDTH, GRAPHICS_RESOURCE_HEIGHT, VC_DISPMAN_ROT0, 1);
114 uint32_t text_size = 10;
116 const char *text = "The quick brown fox jumps over the lazy dog";
117 uint32_t y_offset = height-60+text_size/2;
118 graphics_resource_fill(img, 0, 0, width, height, GRAPHICS_RGBA32(0,0,0,0x00));
119 // blue, at the top (y=40)
120 graphics_resource_fill(img, 0, 40, width, 1, GRAPHICS_RGBA32(0,0,0xff,0xff));
122 // green, at the bottom (y=height-40)
123 graphics_resource_fill(img, 0, height-40, width, 1, GRAPHICS_RGBA32(0,0xff,0,0xff));
125 // draw the subtitle text
126 render_subtitle(img, text, 0, text_size, y_offset);
127 graphics_update_displayed_resource(img, 0, 0, 0, 0);
133 graphics_display_resource(img, 0, LAYER, 0, 0, GRAPHICS_RESOURCE_WIDTH, GRAPHICS_RESOURCE_HEIGHT, VC_DISPMAN_ROT0, 0);
134 graphics_delete_resource(img);