Graphical demo for the LPC4088 Experiment Base Board with one of the Display Expansion Kits. This program displays how to write text in different fonts.

Dependencies:   EALib mbed

Committer:
embeddedartists
Date:
Thu Jun 25 10:30:15 2015 +0000
Revision:
0:5e5e9ec91fc8
First version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
embeddedartists 0:5e5e9ec91fc8 1 /*
embeddedartists 0:5e5e9ec91fc8 2 * @brief SWIM font management
embeddedartists 0:5e5e9ec91fc8 3 *
embeddedartists 0:5e5e9ec91fc8 4 * @note
embeddedartists 0:5e5e9ec91fc8 5 * Copyright(C) NXP Semiconductors, 2012
embeddedartists 0:5e5e9ec91fc8 6 * All rights reserved.
embeddedartists 0:5e5e9ec91fc8 7 *
embeddedartists 0:5e5e9ec91fc8 8 * @par
embeddedartists 0:5e5e9ec91fc8 9 * Software that is described herein is for illustrative purposes only
embeddedartists 0:5e5e9ec91fc8 10 * which provides customers with programming information regarding the
embeddedartists 0:5e5e9ec91fc8 11 * LPC products. This software is supplied "AS IS" without any warranties of
embeddedartists 0:5e5e9ec91fc8 12 * any kind, and NXP Semiconductors and its licensor disclaim any and
embeddedartists 0:5e5e9ec91fc8 13 * all warranties, express or implied, including all implied warranties of
embeddedartists 0:5e5e9ec91fc8 14 * merchantability, fitness for a particular purpose and non-infringement of
embeddedartists 0:5e5e9ec91fc8 15 * intellectual property rights. NXP Semiconductors assumes no responsibility
embeddedartists 0:5e5e9ec91fc8 16 * or liability for the use of the software, conveys no license or rights under any
embeddedartists 0:5e5e9ec91fc8 17 * patent, copyright, mask work right, or any other intellectual property rights in
embeddedartists 0:5e5e9ec91fc8 18 * or to any products. NXP Semiconductors reserves the right to make changes
embeddedartists 0:5e5e9ec91fc8 19 * in the software without notification. NXP Semiconductors also makes no
embeddedartists 0:5e5e9ec91fc8 20 * representation or warranty that such application will be suitable for the
embeddedartists 0:5e5e9ec91fc8 21 * specified use without further testing or modification.
embeddedartists 0:5e5e9ec91fc8 22 *
embeddedartists 0:5e5e9ec91fc8 23 * @par
embeddedartists 0:5e5e9ec91fc8 24 * Permission to use, copy, modify, and distribute this software and its
embeddedartists 0:5e5e9ec91fc8 25 * documentation is hereby granted, under NXP Semiconductors' and its
embeddedartists 0:5e5e9ec91fc8 26 * licensor's relevant copyrights in the software, without fee, provided that it
embeddedartists 0:5e5e9ec91fc8 27 * is used in conjunction with NXP Semiconductors microcontrollers. This
embeddedartists 0:5e5e9ec91fc8 28 * copyright, permission, and disclaimer notice must appear in all copies of
embeddedartists 0:5e5e9ec91fc8 29 * this code.
embeddedartists 0:5e5e9ec91fc8 30 */
embeddedartists 0:5e5e9ec91fc8 31
embeddedartists 0:5e5e9ec91fc8 32 #include "lpc_swim_font.h"
embeddedartists 0:5e5e9ec91fc8 33
embeddedartists 0:5e5e9ec91fc8 34 /*****************************************************************************
embeddedartists 0:5e5e9ec91fc8 35 * Private types/enumerations/variables
embeddedartists 0:5e5e9ec91fc8 36 ****************************************************************************/
embeddedartists 0:5e5e9ec91fc8 37
embeddedartists 0:5e5e9ec91fc8 38 /*****************************************************************************
embeddedartists 0:5e5e9ec91fc8 39 * Public types/enumerations/variables
embeddedartists 0:5e5e9ec91fc8 40 ****************************************************************************/
embeddedartists 0:5e5e9ec91fc8 41
embeddedartists 0:5e5e9ec91fc8 42 /*****************************************************************************
embeddedartists 0:5e5e9ec91fc8 43 * Private functions
embeddedartists 0:5e5e9ec91fc8 44 ****************************************************************************/
embeddedartists 0:5e5e9ec91fc8 45
embeddedartists 0:5e5e9ec91fc8 46 /* Determines the length of the word (in pixels) up to the first
embeddedartists 0:5e5e9ec91fc8 47 whitespace character */
embeddedartists 0:5e5e9ec91fc8 48 static int16_t swim_get_word_len(SWIM_WINDOW_T *win,
embeddedartists 0:5e5e9ec91fc8 49 const CHAR *text)
embeddedartists 0:5e5e9ec91fc8 50 {
embeddedartists 0:5e5e9ec91fc8 51 int32_t i;
embeddedartists 0:5e5e9ec91fc8 52 int16_t wlen = 0;
embeddedartists 0:5e5e9ec91fc8 53
embeddedartists 0:5e5e9ec91fc8 54 /* Find the length in pixels of the next word (separated by
embeddedartists 0:5e5e9ec91fc8 55 whitespace) */
embeddedartists 0:5e5e9ec91fc8 56 i = 0;
embeddedartists 0:5e5e9ec91fc8 57 while (((uint8_t) text[i] > ' ') && ((uint8_t) text[i] <= 0x7E)) {
embeddedartists 0:5e5e9ec91fc8 58 wlen = wlen + win->font->font_width_table
embeddedartists 0:5e5e9ec91fc8 59 [(uint8_t) text[i] - win->font->first_char];
embeddedartists 0:5e5e9ec91fc8 60 i++;
embeddedartists 0:5e5e9ec91fc8 61 }
embeddedartists 0:5e5e9ec91fc8 62
embeddedartists 0:5e5e9ec91fc8 63 return wlen;
embeddedartists 0:5e5e9ec91fc8 64 }
embeddedartists 0:5e5e9ec91fc8 65
embeddedartists 0:5e5e9ec91fc8 66 /* Puts a word in the window, but adds a newline to keep the
embeddedartists 0:5e5e9ec91fc8 67 word contiguous (without an edge break) if necessary */
embeddedartists 0:5e5e9ec91fc8 68 static int32_t swim_put_word(SWIM_WINDOW_T *win,
embeddedartists 0:5e5e9ec91fc8 69 const CHAR *text)
embeddedartists 0:5e5e9ec91fc8 70 {
embeddedartists 0:5e5e9ec91fc8 71 int32_t i;
embeddedartists 0:5e5e9ec91fc8 72
embeddedartists 0:5e5e9ec91fc8 73 /* Will the length of the next word exceed the window margin? */
embeddedartists 0:5e5e9ec91fc8 74 if ((swim_get_word_len(win, text) + win->xvpos) > win->xpvmax) {
embeddedartists 0:5e5e9ec91fc8 75 /* Do a newline */
embeddedartists 0:5e5e9ec91fc8 76 swim_put_newline(win);
embeddedartists 0:5e5e9ec91fc8 77 }
embeddedartists 0:5e5e9ec91fc8 78
embeddedartists 0:5e5e9ec91fc8 79 /* Put just the word characters on the display up to the next
embeddedartists 0:5e5e9ec91fc8 80 non-whitespace character or the end of the string */
embeddedartists 0:5e5e9ec91fc8 81 i = 0;
embeddedartists 0:5e5e9ec91fc8 82 while (((uint8_t) text[i] > ' ') && ((uint8_t) text[i] <= 0x7E)) {
embeddedartists 0:5e5e9ec91fc8 83 swim_put_char(win, text[i]);
embeddedartists 0:5e5e9ec91fc8 84 i++;
embeddedartists 0:5e5e9ec91fc8 85 }
embeddedartists 0:5e5e9ec91fc8 86
embeddedartists 0:5e5e9ec91fc8 87 return i;
embeddedartists 0:5e5e9ec91fc8 88 }
embeddedartists 0:5e5e9ec91fc8 89
embeddedartists 0:5e5e9ec91fc8 90 /***********************************************************************
embeddedartists 0:5e5e9ec91fc8 91 * Public functions
embeddedartists 0:5e5e9ec91fc8 92 **********************************************************************/
embeddedartists 0:5e5e9ec91fc8 93
embeddedartists 0:5e5e9ec91fc8 94 /* Put text at x, y (char) position on screen */
embeddedartists 0:5e5e9ec91fc8 95 void swim_put_text_centered_win(SWIM_WINDOW_T *win,
embeddedartists 0:5e5e9ec91fc8 96 const CHAR *text,
embeddedartists 0:5e5e9ec91fc8 97 int32_t y)
embeddedartists 0:5e5e9ec91fc8 98 {
embeddedartists 0:5e5e9ec91fc8 99 swim_put_text_centered(win, text, 0, win->xvsize-1, y);
embeddedartists 0:5e5e9ec91fc8 100 }
embeddedartists 0:5e5e9ec91fc8 101
embeddedartists 0:5e5e9ec91fc8 102 /* Put text at x, y (char) position on screen */
embeddedartists 0:5e5e9ec91fc8 103 void swim_put_text_centered(SWIM_WINDOW_T *win,
embeddedartists 0:5e5e9ec91fc8 104 const CHAR *text,
embeddedartists 0:5e5e9ec91fc8 105 int32_t x0,
embeddedartists 0:5e5e9ec91fc8 106 int32_t x1,
embeddedartists 0:5e5e9ec91fc8 107 int32_t y)
embeddedartists 0:5e5e9ec91fc8 108 {
embeddedartists 0:5e5e9ec91fc8 109 int w, h;
embeddedartists 0:5e5e9ec91fc8 110 if (x0 > x1) {
embeddedartists 0:5e5e9ec91fc8 111 w = x0;
embeddedartists 0:5e5e9ec91fc8 112 x0 = x1;
embeddedartists 0:5e5e9ec91fc8 113 x1 = w;
embeddedartists 0:5e5e9ec91fc8 114 }
embeddedartists 0:5e5e9ec91fc8 115 swim_get_string_bounds(win, text, &w, &h);
embeddedartists 0:5e5e9ec91fc8 116 swim_put_text_xy(win, text, x0 + (x1-x0-w)/2, y);
embeddedartists 0:5e5e9ec91fc8 117 }
embeddedartists 0:5e5e9ec91fc8 118
embeddedartists 0:5e5e9ec91fc8 119 /* Put text at x, y (char) position on screen */
embeddedartists 0:5e5e9ec91fc8 120 void swim_put_text_xy(SWIM_WINDOW_T *win,
embeddedartists 0:5e5e9ec91fc8 121 const CHAR *text,
embeddedartists 0:5e5e9ec91fc8 122 int32_t x,
embeddedartists 0:5e5e9ec91fc8 123 int32_t y)
embeddedartists 0:5e5e9ec91fc8 124 {
embeddedartists 0:5e5e9ec91fc8 125 /* Convert virtual x, y positon to physical position */
embeddedartists 0:5e5e9ec91fc8 126 swim_set_xy(win, x, y);
embeddedartists 0:5e5e9ec91fc8 127
embeddedartists 0:5e5e9ec91fc8 128 /* Display text string */
embeddedartists 0:5e5e9ec91fc8 129 swim_put_text(win, text);
embeddedartists 0:5e5e9ec91fc8 130 }
embeddedartists 0:5e5e9ec91fc8 131
embeddedartists 0:5e5e9ec91fc8 132 /* Sets the X, Y pixel coordinates for the next text operation */
embeddedartists 0:5e5e9ec91fc8 133 void swim_set_xy(SWIM_WINDOW_T *win,
embeddedartists 0:5e5e9ec91fc8 134 int32_t x,
embeddedartists 0:5e5e9ec91fc8 135 int32_t y)
embeddedartists 0:5e5e9ec91fc8 136 {
embeddedartists 0:5e5e9ec91fc8 137 win->xvpos = x + win->xpvmin;
embeddedartists 0:5e5e9ec91fc8 138 win->yvpos = y + win->ypvmin;
embeddedartists 0:5e5e9ec91fc8 139
embeddedartists 0:5e5e9ec91fc8 140 /* Limit to window dimensions */
embeddedartists 0:5e5e9ec91fc8 141 if (win->xvpos < win->xpvmin) {
embeddedartists 0:5e5e9ec91fc8 142 win->xvpos = win->xpvmin;
embeddedartists 0:5e5e9ec91fc8 143 }
embeddedartists 0:5e5e9ec91fc8 144 else if (win->xvpos > win->xpvmax) {
embeddedartists 0:5e5e9ec91fc8 145 win->xvpos = win->xpvmax;
embeddedartists 0:5e5e9ec91fc8 146 }
embeddedartists 0:5e5e9ec91fc8 147
embeddedartists 0:5e5e9ec91fc8 148 if (win->yvpos < win->ypvmin) {
embeddedartists 0:5e5e9ec91fc8 149 win->yvpos = win->ypvmin;
embeddedartists 0:5e5e9ec91fc8 150 }
embeddedartists 0:5e5e9ec91fc8 151 else if (win->yvpos > win->ypvmax) {
embeddedartists 0:5e5e9ec91fc8 152 win->yvpos = win->ypvmax;
embeddedartists 0:5e5e9ec91fc8 153 }
embeddedartists 0:5e5e9ec91fc8 154 }
embeddedartists 0:5e5e9ec91fc8 155
embeddedartists 0:5e5e9ec91fc8 156 /* Returns the X, Y pixel coordinates for the next text operation */
embeddedartists 0:5e5e9ec91fc8 157 void swim_get_xy(SWIM_WINDOW_T *win,
embeddedartists 0:5e5e9ec91fc8 158 int32_t *x,
embeddedartists 0:5e5e9ec91fc8 159 int32_t *y)
embeddedartists 0:5e5e9ec91fc8 160 {
embeddedartists 0:5e5e9ec91fc8 161 *x = win->xvpos - win->xpvmin;
embeddedartists 0:5e5e9ec91fc8 162 *y = win->yvpos - win->ypvmin;
embeddedartists 0:5e5e9ec91fc8 163 }
embeddedartists 0:5e5e9ec91fc8 164
embeddedartists 0:5e5e9ec91fc8 165 /* Puts a string of text in a window */
embeddedartists 0:5e5e9ec91fc8 166 void swim_put_text(SWIM_WINDOW_T *win,
embeddedartists 0:5e5e9ec91fc8 167 const CHAR *text)
embeddedartists 0:5e5e9ec91fc8 168 {
embeddedartists 0:5e5e9ec91fc8 169 int32_t i = 0;
embeddedartists 0:5e5e9ec91fc8 170
embeddedartists 0:5e5e9ec91fc8 171 /* Continue until the entire string is output */
embeddedartists 0:5e5e9ec91fc8 172 while (text[i] != '\0') {
embeddedartists 0:5e5e9ec91fc8 173 if (text[i] == '\n') {
embeddedartists 0:5e5e9ec91fc8 174 swim_put_newline(win);
embeddedartists 0:5e5e9ec91fc8 175 }
embeddedartists 0:5e5e9ec91fc8 176 else if (((uint8_t) text[i] >= win->font->first_char)
embeddedartists 0:5e5e9ec91fc8 177 && ((uint8_t) text[i] <= win->font->last_char)) {
embeddedartists 0:5e5e9ec91fc8 178 /* Put character on screen */
embeddedartists 0:5e5e9ec91fc8 179 swim_put_char(win, text[i]);
embeddedartists 0:5e5e9ec91fc8 180 }
embeddedartists 0:5e5e9ec91fc8 181
embeddedartists 0:5e5e9ec91fc8 182 i++;
embeddedartists 0:5e5e9ec91fc8 183 }
embeddedartists 0:5e5e9ec91fc8 184 }
embeddedartists 0:5e5e9ec91fc8 185
embeddedartists 0:5e5e9ec91fc8 186 /* Puts a string of text in a window with breaks */
embeddedartists 0:5e5e9ec91fc8 187 void swim_put_ltext(SWIM_WINDOW_T *win,
embeddedartists 0:5e5e9ec91fc8 188 const CHAR *text)
embeddedartists 0:5e5e9ec91fc8 189 {
embeddedartists 0:5e5e9ec91fc8 190 int32_t i = 0;
embeddedartists 0:5e5e9ec91fc8 191
embeddedartists 0:5e5e9ec91fc8 192 /* Continue until the entire string is output */
embeddedartists 0:5e5e9ec91fc8 193 while (text[i] != '\0') {
embeddedartists 0:5e5e9ec91fc8 194 if (text[i] == '\n') {
embeddedartists 0:5e5e9ec91fc8 195 swim_put_newline(win);
embeddedartists 0:5e5e9ec91fc8 196 i++;
embeddedartists 0:5e5e9ec91fc8 197 }
embeddedartists 0:5e5e9ec91fc8 198 else if (((uint8_t) text[i] >= win->font->first_char)
embeddedartists 0:5e5e9ec91fc8 199 && ((uint8_t) text[i] <= win->font->last_char)) {
embeddedartists 0:5e5e9ec91fc8 200 /* Check for entire words first */
embeddedartists 0:5e5e9ec91fc8 201 if (((uint8_t) text[i] > ' ') && ((uint8_t) text[i] <= 0x7E)) {
embeddedartists 0:5e5e9ec91fc8 202 /* Put entire word on screen */
embeddedartists 0:5e5e9ec91fc8 203 i = i + swim_put_word(win, &text[i]);
embeddedartists 0:5e5e9ec91fc8 204 }
embeddedartists 0:5e5e9ec91fc8 205 else {
embeddedartists 0:5e5e9ec91fc8 206 swim_put_char(win, text[i]);
embeddedartists 0:5e5e9ec91fc8 207 i++;
embeddedartists 0:5e5e9ec91fc8 208 }
embeddedartists 0:5e5e9ec91fc8 209 }
embeddedartists 0:5e5e9ec91fc8 210 else {
embeddedartists 0:5e5e9ec91fc8 211 /* Put a space out */
embeddedartists 0:5e5e9ec91fc8 212 swim_put_char(win, ' ');
embeddedartists 0:5e5e9ec91fc8 213 i++;
embeddedartists 0:5e5e9ec91fc8 214 }
embeddedartists 0:5e5e9ec91fc8 215 }
embeddedartists 0:5e5e9ec91fc8 216 }
embeddedartists 0:5e5e9ec91fc8 217
embeddedartists 0:5e5e9ec91fc8 218 /* xx */
embeddedartists 0:5e5e9ec91fc8 219 void swim_window_scroll(SWIM_WINDOW_T *win,
embeddedartists 0:5e5e9ec91fc8 220 int32_t lines)
embeddedartists 0:5e5e9ec91fc8 221 {
embeddedartists 0:5e5e9ec91fc8 222 int32_t yref1 = win->ypvmin;
embeddedartists 0:5e5e9ec91fc8 223 int32_t yref2 = yref1 + lines;
embeddedartists 0:5e5e9ec91fc8 224 int32_t ref;
embeddedartists 0:5e5e9ec91fc8 225
embeddedartists 0:5e5e9ec91fc8 226 while (yref2 <= win->ypvmax) {
embeddedartists 0:5e5e9ec91fc8 227
embeddedartists 0:5e5e9ec91fc8 228 /* Line move addresses */
embeddedartists 0:5e5e9ec91fc8 229 uint32_t ix = win->xpvmin;
embeddedartists 0:5e5e9ec91fc8 230 uint32_t destIy = yref1;
embeddedartists 0:5e5e9ec91fc8 231 uint32_t srcIy = yref2;
embeddedartists 0:5e5e9ec91fc8 232
embeddedartists 0:5e5e9ec91fc8 233 /* Move a single line at a time */
embeddedartists 0:5e5e9ec91fc8 234 ref = win->xpvmax - win->xpvmin + 1;
embeddedartists 0:5e5e9ec91fc8 235 while (ref > 0) {
embeddedartists 0:5e5e9ec91fc8 236 COLOR_T pixel = swim_get_pixel_physical(win, ix, srcIy);
embeddedartists 0:5e5e9ec91fc8 237 swim_put_pixel_physical(win, ix, destIy, pixel);
embeddedartists 0:5e5e9ec91fc8 238 ix++;
embeddedartists 0:5e5e9ec91fc8 239 ref--;
embeddedartists 0:5e5e9ec91fc8 240 }
embeddedartists 0:5e5e9ec91fc8 241
embeddedartists 0:5e5e9ec91fc8 242 /* Next lines */
embeddedartists 0:5e5e9ec91fc8 243 yref1++;
embeddedartists 0:5e5e9ec91fc8 244 yref2++;
embeddedartists 0:5e5e9ec91fc8 245 }
embeddedartists 0:5e5e9ec91fc8 246
embeddedartists 0:5e5e9ec91fc8 247 /* Clear out bottom lines */
embeddedartists 0:5e5e9ec91fc8 248 yref1 = win->yvpos;
embeddedartists 0:5e5e9ec91fc8 249 while (yref1 <= win->ypvmax) {
embeddedartists 0:5e5e9ec91fc8 250
embeddedartists 0:5e5e9ec91fc8 251 /* Line clear address */
embeddedartists 0:5e5e9ec91fc8 252 uint32_t ix = win->xpvmin;
embeddedartists 0:5e5e9ec91fc8 253 uint32_t destIy = yref1;
embeddedartists 0:5e5e9ec91fc8 254
embeddedartists 0:5e5e9ec91fc8 255 /* Clear a single line at a time */
embeddedartists 0:5e5e9ec91fc8 256 ref = win->xpvmax - win->xpvmin + 1;
embeddedartists 0:5e5e9ec91fc8 257 while (ref > 0) {
embeddedartists 0:5e5e9ec91fc8 258 swim_put_pixel_physical(win, ix, destIy, win->bkg);
embeddedartists 0:5e5e9ec91fc8 259 ix++;
embeddedartists 0:5e5e9ec91fc8 260 ref--;
embeddedartists 0:5e5e9ec91fc8 261 }
embeddedartists 0:5e5e9ec91fc8 262
embeddedartists 0:5e5e9ec91fc8 263 yref1++;
embeddedartists 0:5e5e9ec91fc8 264 }
embeddedartists 0:5e5e9ec91fc8 265 }
embeddedartists 0:5e5e9ec91fc8 266
embeddedartists 0:5e5e9ec91fc8 267 /* Puts a single character in the window */
embeddedartists 0:5e5e9ec91fc8 268 void swim_put_char(SWIM_WINDOW_T *win,
embeddedartists 0:5e5e9ec91fc8 269 const CHAR textchar)
embeddedartists 0:5e5e9ec91fc8 270 {
embeddedartists 0:5e5e9ec91fc8 271 int32_t i, j;
embeddedartists 0:5e5e9ec91fc8 272 int32_t charindex;
embeddedartists 0:5e5e9ec91fc8 273 const uint16_t *charfields;
embeddedartists 0:5e5e9ec91fc8 274 uint16_t chardata;
embeddedartists 0:5e5e9ec91fc8 275
embeddedartists 0:5e5e9ec91fc8 276 /* If this is a carriage return, do a newline */
embeddedartists 0:5e5e9ec91fc8 277 if (textchar == '\n') {
embeddedartists 0:5e5e9ec91fc8 278 swim_put_newline(win);
embeddedartists 0:5e5e9ec91fc8 279 }
embeddedartists 0:5e5e9ec91fc8 280 else {
embeddedartists 0:5e5e9ec91fc8 281 /* Determine index to character data */
embeddedartists 0:5e5e9ec91fc8 282 charindex = (int32_t) textchar - (int32_t) win->font->first_char;
embeddedartists 0:5e5e9ec91fc8 283
embeddedartists 0:5e5e9ec91fc8 284 /* Will the character fit on the display? */
embeddedartists 0:5e5e9ec91fc8 285 if ((win->xvpos +
embeddedartists 0:5e5e9ec91fc8 286 (int32_t) win->font->font_width_table[charindex]) >
embeddedartists 0:5e5e9ec91fc8 287 win->xpvmax) {
embeddedartists 0:5e5e9ec91fc8 288 /* Will not fit, do a newline */
embeddedartists 0:5e5e9ec91fc8 289 swim_put_newline(win);
embeddedartists 0:5e5e9ec91fc8 290 }
embeddedartists 0:5e5e9ec91fc8 291
embeddedartists 0:5e5e9ec91fc8 292 /* Determine the start of the bitfields for the character */
embeddedartists 0:5e5e9ec91fc8 293 charfields = win->font->font_table + (charindex *
embeddedartists 0:5e5e9ec91fc8 294 win->font->font_height);
embeddedartists 0:5e5e9ec91fc8 295
embeddedartists 0:5e5e9ec91fc8 296 /* Map character to the window */
embeddedartists 0:5e5e9ec91fc8 297 /* Each iteration of this loop does a row */
embeddedartists 0:5e5e9ec91fc8 298 for (i = 0; i < (int32_t) win->font->font_height; i++) {
embeddedartists 0:5e5e9ec91fc8 299
embeddedartists 0:5e5e9ec91fc8 300 /* Get starting pixel in the line */
embeddedartists 0:5e5e9ec91fc8 301 uint32_t rowIx = win->xvpos;
embeddedartists 0:5e5e9ec91fc8 302 uint32_t rowIy = win->yvpos + i;
embeddedartists 0:5e5e9ec91fc8 303
embeddedartists 0:5e5e9ec91fc8 304 /* Get character line mapping data */
embeddedartists 0:5e5e9ec91fc8 305 chardata = charfields[i];
embeddedartists 0:5e5e9ec91fc8 306
embeddedartists 0:5e5e9ec91fc8 307 /* Convert character line bit data to a pixel line in
embeddedartists 0:5e5e9ec91fc8 308 window */
embeddedartists 0:5e5e9ec91fc8 309 /* Each iteration of this loop does one pixel of the row */
embeddedartists 0:5e5e9ec91fc8 310 for (j =
embeddedartists 0:5e5e9ec91fc8 311 (int32_t) win->font->font_width_table[charindex];
embeddedartists 0:5e5e9ec91fc8 312 j > 0; j--) {
embeddedartists 0:5e5e9ec91fc8 313 if ((chardata & 0x8000) != 0) {
embeddedartists 0:5e5e9ec91fc8 314 swim_put_pixel_physical(win, rowIx, rowIy, win->pen);
embeddedartists 0:5e5e9ec91fc8 315 }
embeddedartists 0:5e5e9ec91fc8 316 else if (win->tfont != 0) {
embeddedartists 0:5e5e9ec91fc8 317 swim_put_pixel_physical(win, rowIx, rowIy, win->bkg);
embeddedartists 0:5e5e9ec91fc8 318 }
embeddedartists 0:5e5e9ec91fc8 319 rowIx++;
embeddedartists 0:5e5e9ec91fc8 320
embeddedartists 0:5e5e9ec91fc8 321 /* Next bit in character line */
embeddedartists 0:5e5e9ec91fc8 322 chardata = chardata << 1;
embeddedartists 0:5e5e9ec91fc8 323 }
embeddedartists 0:5e5e9ec91fc8 324 }
embeddedartists 0:5e5e9ec91fc8 325
embeddedartists 0:5e5e9ec91fc8 326 /* Increment to next text location */
embeddedartists 0:5e5e9ec91fc8 327 win->xvpos = win->xvpos +
embeddedartists 0:5e5e9ec91fc8 328 (int32_t) win->font->font_width_table[charindex];
embeddedartists 0:5e5e9ec91fc8 329 }
embeddedartists 0:5e5e9ec91fc8 330 }
embeddedartists 0:5e5e9ec91fc8 331
embeddedartists 0:5e5e9ec91fc8 332 /* Puts a newline in the window */
embeddedartists 0:5e5e9ec91fc8 333 void swim_put_newline(SWIM_WINDOW_T *win)
embeddedartists 0:5e5e9ec91fc8 334 {
embeddedartists 0:5e5e9ec91fc8 335 int32_t diff;
embeddedartists 0:5e5e9ec91fc8 336
embeddedartists 0:5e5e9ec91fc8 337 /* Set text pointer to start of next line */
embeddedartists 0:5e5e9ec91fc8 338 win->xvpos = win->xpvmin;
embeddedartists 0:5e5e9ec91fc8 339 win->yvpos = win->yvpos + (int32_t) win->font->font_height;
embeddedartists 0:5e5e9ec91fc8 340
embeddedartists 0:5e5e9ec91fc8 341 /* Next character is below bottom of window, scroll the window
embeddedartists 0:5e5e9ec91fc8 342 up */
embeddedartists 0:5e5e9ec91fc8 343 while ((win->yvpos +
embeddedartists 0:5e5e9ec91fc8 344 (int32_t) win->font->font_height) > win->ypvmax) {
embeddedartists 0:5e5e9ec91fc8 345 /* Scroll just enough for the next line */
embeddedartists 0:5e5e9ec91fc8 346 diff = (int32_t) win->font->font_height -
embeddedartists 0:5e5e9ec91fc8 347 (win->ypvmax - win->yvpos);
embeddedartists 0:5e5e9ec91fc8 348 win->yvpos = win->yvpos - diff;
embeddedartists 0:5e5e9ec91fc8 349 swim_window_scroll(win, diff);
embeddedartists 0:5e5e9ec91fc8 350 }
embeddedartists 0:5e5e9ec91fc8 351 }
embeddedartists 0:5e5e9ec91fc8 352
embeddedartists 0:5e5e9ec91fc8 353 /* Sets the active font */
embeddedartists 0:5e5e9ec91fc8 354 void swim_set_font(SWIM_WINDOW_T *win,
embeddedartists 0:5e5e9ec91fc8 355 FONT_T *font)
embeddedartists 0:5e5e9ec91fc8 356 {
embeddedartists 0:5e5e9ec91fc8 357 int32_t diff;
embeddedartists 0:5e5e9ec91fc8 358
embeddedartists 0:5e5e9ec91fc8 359 win->font = font;
embeddedartists 0:5e5e9ec91fc8 360
embeddedartists 0:5e5e9ec91fc8 361 /* After changing to the new font, determine if there is enough
embeddedartists 0:5e5e9ec91fc8 362 room for the font height on the existing line in the window */
embeddedartists 0:5e5e9ec91fc8 363 if ((win->yvpos + win->font->font_height) > win->ypvmax) {
embeddedartists 0:5e5e9ec91fc8 364 diff = (int32_t) win->font->font_height -
embeddedartists 0:5e5e9ec91fc8 365 (win->ypvmax - win->yvpos);
embeddedartists 0:5e5e9ec91fc8 366 win->yvpos = win->yvpos - diff;
embeddedartists 0:5e5e9ec91fc8 367 swim_window_scroll(win, diff);
embeddedartists 0:5e5e9ec91fc8 368 }
embeddedartists 0:5e5e9ec91fc8 369 }
embeddedartists 0:5e5e9ec91fc8 370
embeddedartists 0:5e5e9ec91fc8 371 /* Returns the active font's height in pixels */
embeddedartists 0:5e5e9ec91fc8 372 int16_t swim_get_font_height(SWIM_WINDOW_T *win)
embeddedartists 0:5e5e9ec91fc8 373 {
embeddedartists 0:5e5e9ec91fc8 374 return win->font->font_height;
embeddedartists 0:5e5e9ec91fc8 375 }
embeddedartists 0:5e5e9ec91fc8 376
embeddedartists 0:5e5e9ec91fc8 377 void swim_get_string_bounds(SWIM_WINDOW_T *win, const CHAR * text, int* width, int* height)
embeddedartists 0:5e5e9ec91fc8 378 {
embeddedartists 0:5e5e9ec91fc8 379 int32_t i = 0;
embeddedartists 0:5e5e9ec91fc8 380 int w = 0;
embeddedartists 0:5e5e9ec91fc8 381 *width = 0;
embeddedartists 0:5e5e9ec91fc8 382 *height = win->font->font_height;
embeddedartists 0:5e5e9ec91fc8 383
embeddedartists 0:5e5e9ec91fc8 384 /* Continue until the entire string is output */
embeddedartists 0:5e5e9ec91fc8 385 while (text[i] != '\0') {
embeddedartists 0:5e5e9ec91fc8 386 if (text[i] == '\n') {
embeddedartists 0:5e5e9ec91fc8 387 *width = MAX(w, *width);
embeddedartists 0:5e5e9ec91fc8 388 w = 0;
embeddedartists 0:5e5e9ec91fc8 389 *height += win->font->font_height;
embeddedartists 0:5e5e9ec91fc8 390 }
embeddedartists 0:5e5e9ec91fc8 391 else if (((uint8_t) text[i] >= win->font->first_char)
embeddedartists 0:5e5e9ec91fc8 392 && ((uint8_t) text[i] <= win->font->last_char)) {
embeddedartists 0:5e5e9ec91fc8 393
embeddedartists 0:5e5e9ec91fc8 394 /* Determine index to character data */
embeddedartists 0:5e5e9ec91fc8 395 int charindex = (int) text[i] - (int) win->font->first_char;
embeddedartists 0:5e5e9ec91fc8 396
embeddedartists 0:5e5e9ec91fc8 397 w += win->font->font_width_table[charindex];
embeddedartists 0:5e5e9ec91fc8 398 }
embeddedartists 0:5e5e9ec91fc8 399
embeddedartists 0:5e5e9ec91fc8 400 i++;
embeddedartists 0:5e5e9ec91fc8 401 }
embeddedartists 0:5e5e9ec91fc8 402
embeddedartists 0:5e5e9ec91fc8 403 *width = MAX(w, *width);
embeddedartists 0:5e5e9ec91fc8 404 }
embeddedartists 0:5e5e9ec91fc8 405
embeddedartists 0:5e5e9ec91fc8 406
embeddedartists 0:5e5e9ec91fc8 407 /* Creates a title bar for the window */
embeddedartists 0:5e5e9ec91fc8 408 void swim_set_title(SWIM_WINDOW_T *win,
embeddedartists 0:5e5e9ec91fc8 409 const CHAR *title,
embeddedartists 0:5e5e9ec91fc8 410 COLOR_T ttlbkcolor)
embeddedartists 0:5e5e9ec91fc8 411 {
embeddedartists 0:5e5e9ec91fc8 412 COLOR_T savedf, savedp, savedb;
embeddedartists 0:5e5e9ec91fc8 413 int32_t savedt;
embeddedartists 0:5e5e9ec91fc8 414
embeddedartists 0:5e5e9ec91fc8 415 /* Is present font height larger than window client height? */
embeddedartists 0:5e5e9ec91fc8 416 if ((swim_get_font_height(win) < (4 + win->yvsize)) &&
embeddedartists 0:5e5e9ec91fc8 417 (title != (CHAR *) 0)) {
embeddedartists 0:5e5e9ec91fc8 418 /* There is enough room for title bar, so continue */
embeddedartists 0:5e5e9ec91fc8 419
embeddedartists 0:5e5e9ec91fc8 420 /* Save original colors and font transparentcy flag */
embeddedartists 0:5e5e9ec91fc8 421 savedf = win->fill;
embeddedartists 0:5e5e9ec91fc8 422 savedp = win->pen;
embeddedartists 0:5e5e9ec91fc8 423 savedb = win->bkg;
embeddedartists 0:5e5e9ec91fc8 424 savedt = win->tfont;
embeddedartists 0:5e5e9ec91fc8 425
embeddedartists 0:5e5e9ec91fc8 426 /* Set fill color to background color (temporarily)
embeddedartists 0:5e5e9ec91fc8 427 used with box function */
embeddedartists 0:5e5e9ec91fc8 428 win->fill = ttlbkcolor;
embeddedartists 0:5e5e9ec91fc8 429 win->bkg = ttlbkcolor;
embeddedartists 0:5e5e9ec91fc8 430 win->pen = win->bkg;
embeddedartists 0:5e5e9ec91fc8 431
embeddedartists 0:5e5e9ec91fc8 432 /* Draw the background for the title bar */
embeddedartists 0:5e5e9ec91fc8 433 swim_put_box(win, 0, 0, win->xvsize,
embeddedartists 0:5e5e9ec91fc8 434 (4 + swim_get_font_height(win) - 2));
embeddedartists 0:5e5e9ec91fc8 435
embeddedartists 0:5e5e9ec91fc8 436 /* Reset text starting position for title string */
embeddedartists 0:5e5e9ec91fc8 437 win->xvpos = win->xpvmin + 2;
embeddedartists 0:5e5e9ec91fc8 438 win->yvpos = win->ypvmin + 1;
embeddedartists 0:5e5e9ec91fc8 439
embeddedartists 0:5e5e9ec91fc8 440 /* Restore original pen color (used for text color) */
embeddedartists 0:5e5e9ec91fc8 441 win->pen = savedp;
embeddedartists 0:5e5e9ec91fc8 442
embeddedartists 0:5e5e9ec91fc8 443 /* Restore the original colors */
embeddedartists 0:5e5e9ec91fc8 444 win->fill = savedf;
embeddedartists 0:5e5e9ec91fc8 445 win->bkg = savedb;
embeddedartists 0:5e5e9ec91fc8 446
embeddedartists 0:5e5e9ec91fc8 447 /* Put string in title bar area (with transparent background) */
embeddedartists 0:5e5e9ec91fc8 448 win->tfont = 0;
embeddedartists 0:5e5e9ec91fc8 449 swim_put_text(win, title);
embeddedartists 0:5e5e9ec91fc8 450 win->tfont = savedt;
embeddedartists 0:5e5e9ec91fc8 451
embeddedartists 0:5e5e9ec91fc8 452 /* Draw a line under the title bar, but before the
embeddedartists 0:5e5e9ec91fc8 453 (new) client area */
embeddedartists 0:5e5e9ec91fc8 454 swim_put_line(win, 0,
embeddedartists 0:5e5e9ec91fc8 455 (4 + swim_get_font_height(win) - 1),
embeddedartists 0:5e5e9ec91fc8 456 win->xpvmax, (4 + swim_get_font_height(win) - 1));
embeddedartists 0:5e5e9ec91fc8 457
embeddedartists 0:5e5e9ec91fc8 458 /* Adjust client height of window (virtual and physcal) */
embeddedartists 0:5e5e9ec91fc8 459 win->ypmin = win->ypmin + swim_get_font_height(win) + 4;
embeddedartists 0:5e5e9ec91fc8 460 win->ypvmin = win->ypvmin + swim_get_font_height(win) + 4;
embeddedartists 0:5e5e9ec91fc8 461
embeddedartists 0:5e5e9ec91fc8 462 /* Resize y dimension */
embeddedartists 0:5e5e9ec91fc8 463 win->yvsize = win->yvsize - swim_get_font_height(win) + 4;
embeddedartists 0:5e5e9ec91fc8 464
embeddedartists 0:5e5e9ec91fc8 465 /* Reset text starting position to new client area */
embeddedartists 0:5e5e9ec91fc8 466 win->xvpos = win->xpvmin;
embeddedartists 0:5e5e9ec91fc8 467 win->yvpos = win->ypvmin;
embeddedartists 0:5e5e9ec91fc8 468 }
embeddedartists 0:5e5e9ec91fc8 469 }
embeddedartists 0:5e5e9ec91fc8 470
embeddedartists 0:5e5e9ec91fc8 471 /* Enables and disables font backgrounds */
embeddedartists 0:5e5e9ec91fc8 472 void swim_set_font_transparency(SWIM_WINDOW_T *win,
embeddedartists 0:5e5e9ec91fc8 473 int32_t trans)
embeddedartists 0:5e5e9ec91fc8 474 {
embeddedartists 0:5e5e9ec91fc8 475 win->tfont = trans;
embeddedartists 0:5e5e9ec91fc8 476 }
embeddedartists 0:5e5e9ec91fc8 477