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