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 Simple Windowing Interface Manager (SWIM)
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.h"
embeddedartists 0:5e5e9ec91fc8 33 #include "lpc_fonts.h"
embeddedartists 0:5e5e9ec91fc8 34 #include "lpc_helvr10.h"
embeddedartists 0:5e5e9ec91fc8 35
embeddedartists 0:5e5e9ec91fc8 36 /*****************************************************************************
embeddedartists 0:5e5e9ec91fc8 37 * Private types/enumerations/variables
embeddedartists 0:5e5e9ec91fc8 38 ****************************************************************************/
embeddedartists 0:5e5e9ec91fc8 39
embeddedartists 0:5e5e9ec91fc8 40 static const FONT_T* defaultFont = (FONT_T*)&font_helvr10;
embeddedartists 0:5e5e9ec91fc8 41
embeddedartists 0:5e5e9ec91fc8 42 /*****************************************************************************
embeddedartists 0:5e5e9ec91fc8 43 * Public types/enumerations/variables
embeddedartists 0:5e5e9ec91fc8 44 ****************************************************************************/
embeddedartists 0:5e5e9ec91fc8 45
embeddedartists 0:5e5e9ec91fc8 46 /*****************************************************************************
embeddedartists 0:5e5e9ec91fc8 47 * Private functions
embeddedartists 0:5e5e9ec91fc8 48 ****************************************************************************/
embeddedartists 0:5e5e9ec91fc8 49
embeddedartists 0:5e5e9ec91fc8 50 /* Absolute value function */
embeddedartists 0:5e5e9ec91fc8 51 static int32_t swim_abs(int32_t v1)
embeddedartists 0:5e5e9ec91fc8 52 {
embeddedartists 0:5e5e9ec91fc8 53 if (v1 > 0) {
embeddedartists 0:5e5e9ec91fc8 54 return v1;
embeddedartists 0:5e5e9ec91fc8 55 }
embeddedartists 0:5e5e9ec91fc8 56
embeddedartists 0:5e5e9ec91fc8 57 return -v1;
embeddedartists 0:5e5e9ec91fc8 58 }
embeddedartists 0:5e5e9ec91fc8 59
embeddedartists 0:5e5e9ec91fc8 60 /* Draw a line on the physical display */
embeddedartists 0:5e5e9ec91fc8 61 static void swim_put_line_raw(SWIM_WINDOW_T *win,
embeddedartists 0:5e5e9ec91fc8 62 int32_t x1,
embeddedartists 0:5e5e9ec91fc8 63 int32_t y1,
embeddedartists 0:5e5e9ec91fc8 64 int32_t x2,
embeddedartists 0:5e5e9ec91fc8 65 int32_t y2)
embeddedartists 0:5e5e9ec91fc8 66 {
embeddedartists 0:5e5e9ec91fc8 67 int32_t e2, sx, sy, dx, dy, err;
embeddedartists 0:5e5e9ec91fc8 68
embeddedartists 0:5e5e9ec91fc8 69 /* calculate delta_x and delta_y */
embeddedartists 0:5e5e9ec91fc8 70 dx = swim_abs(x2 - x1);
embeddedartists 0:5e5e9ec91fc8 71 dy = swim_abs(y2 - y1);
embeddedartists 0:5e5e9ec91fc8 72
embeddedartists 0:5e5e9ec91fc8 73 /* set the direction for the step for both x and y, and
embeddedartists 0:5e5e9ec91fc8 74 initialize the error */
embeddedartists 0:5e5e9ec91fc8 75 if (x1 < x2) {
embeddedartists 0:5e5e9ec91fc8 76 sx = 1;
embeddedartists 0:5e5e9ec91fc8 77 }
embeddedartists 0:5e5e9ec91fc8 78 else {
embeddedartists 0:5e5e9ec91fc8 79 sx = -1;
embeddedartists 0:5e5e9ec91fc8 80 }
embeddedartists 0:5e5e9ec91fc8 81
embeddedartists 0:5e5e9ec91fc8 82 if (y1 < y2) {
embeddedartists 0:5e5e9ec91fc8 83 sy = 1;
embeddedartists 0:5e5e9ec91fc8 84 }
embeddedartists 0:5e5e9ec91fc8 85 else {
embeddedartists 0:5e5e9ec91fc8 86 sy = -1;
embeddedartists 0:5e5e9ec91fc8 87 }
embeddedartists 0:5e5e9ec91fc8 88
embeddedartists 0:5e5e9ec91fc8 89 err = dx - dy;
embeddedartists 0:5e5e9ec91fc8 90
embeddedartists 0:5e5e9ec91fc8 91 while (1) {
embeddedartists 0:5e5e9ec91fc8 92 if ((x1 >= 0) && (x1 <= win->xpsize) &&
embeddedartists 0:5e5e9ec91fc8 93 (y1 >= 0) && (y1 <= win->ypsize)) {
embeddedartists 0:5e5e9ec91fc8 94 swim_put_pixel_physical(win, x1, y1, win->pen);
embeddedartists 0:5e5e9ec91fc8 95 }
embeddedartists 0:5e5e9ec91fc8 96
embeddedartists 0:5e5e9ec91fc8 97 if ((x1 == x2) && (y1 == y2)) {
embeddedartists 0:5e5e9ec91fc8 98 return;
embeddedartists 0:5e5e9ec91fc8 99 }
embeddedartists 0:5e5e9ec91fc8 100
embeddedartists 0:5e5e9ec91fc8 101 e2 = 2 * err;
embeddedartists 0:5e5e9ec91fc8 102 if (e2 > -dy) {
embeddedartists 0:5e5e9ec91fc8 103 err -= dy;
embeddedartists 0:5e5e9ec91fc8 104 x1 += sx;
embeddedartists 0:5e5e9ec91fc8 105 }
embeddedartists 0:5e5e9ec91fc8 106 if (e2 < dx) {
embeddedartists 0:5e5e9ec91fc8 107 err += dx;
embeddedartists 0:5e5e9ec91fc8 108 y1 += sy;
embeddedartists 0:5e5e9ec91fc8 109 }
embeddedartists 0:5e5e9ec91fc8 110 }
embeddedartists 0:5e5e9ec91fc8 111 }
embeddedartists 0:5e5e9ec91fc8 112
embeddedartists 0:5e5e9ec91fc8 113 /* Initializes a window and the default values for the window */
embeddedartists 0:5e5e9ec91fc8 114 static BOOL_32 swim_window_open_p(SWIM_WINDOW_T *win,
embeddedartists 0:5e5e9ec91fc8 115 int32_t xsize,
embeddedartists 0:5e5e9ec91fc8 116 int32_t ysize,
embeddedartists 0:5e5e9ec91fc8 117 COLOR_T *fbaddr,
embeddedartists 0:5e5e9ec91fc8 118 int32_t xwin_min,
embeddedartists 0:5e5e9ec91fc8 119 int32_t ywin_min,
embeddedartists 0:5e5e9ec91fc8 120 int32_t xwin_max,
embeddedartists 0:5e5e9ec91fc8 121 int32_t ywin_max,
embeddedartists 0:5e5e9ec91fc8 122 int32_t border_width,
embeddedartists 0:5e5e9ec91fc8 123 COLOR_T pcolor,
embeddedartists 0:5e5e9ec91fc8 124 COLOR_T bkcolor,
embeddedartists 0:5e5e9ec91fc8 125 COLOR_T fcolor,
embeddedartists 0:5e5e9ec91fc8 126 BOOL_32 clear)
embeddedartists 0:5e5e9ec91fc8 127 {
embeddedartists 0:5e5e9ec91fc8 128 int32_t i;
embeddedartists 0:5e5e9ec91fc8 129 BOOL_32 init = false;
embeddedartists 0:5e5e9ec91fc8 130
embeddedartists 0:5e5e9ec91fc8 131 /* Before continuing, check to see that the window size is
embeddedartists 0:5e5e9ec91fc8 132 in the physical dimensions of the display */
embeddedartists 0:5e5e9ec91fc8 133 if ((xwin_min >= 0) && (ywin_min >= 0) &&
embeddedartists 0:5e5e9ec91fc8 134 (xwin_max < xsize) && (ywin_max < ysize)) {
embeddedartists 0:5e5e9ec91fc8 135 init = true;
embeddedartists 0:5e5e9ec91fc8 136 }
embeddedartists 0:5e5e9ec91fc8 137 else {
embeddedartists 0:5e5e9ec91fc8 138 /* Window size is out of the physical display size, so it
embeddedartists 0:5e5e9ec91fc8 139 should be invalidated */
embeddedartists 0:5e5e9ec91fc8 140 win->winused = 0x0;
embeddedartists 0:5e5e9ec91fc8 141 }
embeddedartists 0:5e5e9ec91fc8 142
embeddedartists 0:5e5e9ec91fc8 143 if (init == true) {
embeddedartists 0:5e5e9ec91fc8 144 /* Save physical display dimensions */
embeddedartists 0:5e5e9ec91fc8 145 win->xpsize = xsize;
embeddedartists 0:5e5e9ec91fc8 146 win->ypsize = ysize;
embeddedartists 0:5e5e9ec91fc8 147
embeddedartists 0:5e5e9ec91fc8 148 /* Save frame buffer address */
embeddedartists 0:5e5e9ec91fc8 149 win->fb = fbaddr;
embeddedartists 0:5e5e9ec91fc8 150
embeddedartists 0:5e5e9ec91fc8 151 /* Save physical window dimensions and default colors */
embeddedartists 0:5e5e9ec91fc8 152 win->xpmin = xwin_min;
embeddedartists 0:5e5e9ec91fc8 153 win->ypmin = ywin_min;
embeddedartists 0:5e5e9ec91fc8 154 win->xpmax = xwin_max;
embeddedartists 0:5e5e9ec91fc8 155 win->ypmax = ywin_max;
embeddedartists 0:5e5e9ec91fc8 156 win->pen = pcolor;
embeddedartists 0:5e5e9ec91fc8 157 win->bkg = bkcolor;
embeddedartists 0:5e5e9ec91fc8 158 win->fill = fcolor;
embeddedartists 0:5e5e9ec91fc8 159
embeddedartists 0:5e5e9ec91fc8 160 /* Compute physical window dimensions of draw area only */
embeddedartists 0:5e5e9ec91fc8 161 win->xpvmin = xwin_min + border_width;
embeddedartists 0:5e5e9ec91fc8 162 win->ypvmin = ywin_min + border_width;
embeddedartists 0:5e5e9ec91fc8 163 win->xpvmax = xwin_max - border_width;
embeddedartists 0:5e5e9ec91fc8 164 win->ypvmax = ywin_max - border_width;
embeddedartists 0:5e5e9ec91fc8 165
embeddedartists 0:5e5e9ec91fc8 166 /* Compute virtual window size of draw area */
embeddedartists 0:5e5e9ec91fc8 167 win->xvsize = xwin_max - xwin_min - 2 * border_width;
embeddedartists 0:5e5e9ec91fc8 168 win->yvsize = ywin_max - ywin_min - 2 * border_width;
embeddedartists 0:5e5e9ec91fc8 169
embeddedartists 0:5e5e9ec91fc8 170 /* Fill in any unused border padding between draw area and border
embeddedartists 0:5e5e9ec91fc8 171 will fill color */
embeddedartists 0:5e5e9ec91fc8 172 for (i = 0; i < border_width; i++) {
embeddedartists 0:5e5e9ec91fc8 173 swim_put_line_raw(win, (xwin_min + i),
embeddedartists 0:5e5e9ec91fc8 174 (ywin_min + i), (xwin_max - i), (ywin_min + i));
embeddedartists 0:5e5e9ec91fc8 175 swim_put_line_raw(win, (xwin_max - i),
embeddedartists 0:5e5e9ec91fc8 176 (ywin_min + i), (xwin_max - i), (ywin_max - i));
embeddedartists 0:5e5e9ec91fc8 177 swim_put_line_raw(win, (xwin_max - i),
embeddedartists 0:5e5e9ec91fc8 178 (ywin_max - i), (xwin_min + i), (ywin_max - i));
embeddedartists 0:5e5e9ec91fc8 179 swim_put_line_raw(win, (xwin_min + i),
embeddedartists 0:5e5e9ec91fc8 180 (ywin_max - i), (xwin_min + i), (ywin_min + i));
embeddedartists 0:5e5e9ec91fc8 181 }
embeddedartists 0:5e5e9ec91fc8 182
embeddedartists 0:5e5e9ec91fc8 183 /* Clear draw area with background color */
embeddedartists 0:5e5e9ec91fc8 184 if (clear == true) {
embeddedartists 0:5e5e9ec91fc8 185 swim_clear_screen(win, bkcolor);
embeddedartists 0:5e5e9ec91fc8 186 }
embeddedartists 0:5e5e9ec91fc8 187
embeddedartists 0:5e5e9ec91fc8 188 /* Use the default font and make background transparent */
embeddedartists 0:5e5e9ec91fc8 189 win->font = (FONT_T*)defaultFont;
embeddedartists 0:5e5e9ec91fc8 190
embeddedartists 0:5e5e9ec91fc8 191 /* Set starting text position in upper left of window */
embeddedartists 0:5e5e9ec91fc8 192 win->xvpos = win->xpvmin;
embeddedartists 0:5e5e9ec91fc8 193 win->yvpos = win->ypvmin;
embeddedartists 0:5e5e9ec91fc8 194 }
embeddedartists 0:5e5e9ec91fc8 195
embeddedartists 0:5e5e9ec91fc8 196 return init;
embeddedartists 0:5e5e9ec91fc8 197 }
embeddedartists 0:5e5e9ec91fc8 198
embeddedartists 0:5e5e9ec91fc8 199 /* Circle support function */
embeddedartists 0:5e5e9ec91fc8 200 static void swim_plot4points(SWIM_WINDOW_T *win, int32_t cx, int32_t cy, int32_t x, int32_t y, int32_t Filled)
embeddedartists 0:5e5e9ec91fc8 201 {
embeddedartists 0:5e5e9ec91fc8 202 int16_t x0, x1, y0, y1;
embeddedartists 0:5e5e9ec91fc8 203
embeddedartists 0:5e5e9ec91fc8 204 y0 = cy + y;
embeddedartists 0:5e5e9ec91fc8 205 y1 = cy - y;
embeddedartists 0:5e5e9ec91fc8 206 if ( Filled ) {
embeddedartists 0:5e5e9ec91fc8 207 for ( x0 = cx - x; x0 <= cx + x; x0++ ) {
embeddedartists 0:5e5e9ec91fc8 208 swim_put_pixel_physical(win, x0, y0, win->pen);
embeddedartists 0:5e5e9ec91fc8 209 swim_put_pixel_physical(win, x0, y1, win->pen);
embeddedartists 0:5e5e9ec91fc8 210 }
embeddedartists 0:5e5e9ec91fc8 211 }
embeddedartists 0:5e5e9ec91fc8 212 else {
embeddedartists 0:5e5e9ec91fc8 213 x0 = cx + x;
embeddedartists 0:5e5e9ec91fc8 214 x1 = cx - x;
embeddedartists 0:5e5e9ec91fc8 215 swim_put_pixel_physical(win, x0, y0, win->pen);
embeddedartists 0:5e5e9ec91fc8 216 if (x != 0) {
embeddedartists 0:5e5e9ec91fc8 217 swim_put_pixel_physical(win, x1, y0, win->pen);
embeddedartists 0:5e5e9ec91fc8 218 }
embeddedartists 0:5e5e9ec91fc8 219 if (y != 0) {
embeddedartists 0:5e5e9ec91fc8 220 swim_put_pixel_physical(win, x0, y1, win->pen);
embeddedartists 0:5e5e9ec91fc8 221 }
embeddedartists 0:5e5e9ec91fc8 222 if (( x != 0) && ( y != 0) ) {
embeddedartists 0:5e5e9ec91fc8 223 swim_put_pixel_physical(win, x1, y1, win->pen);
embeddedartists 0:5e5e9ec91fc8 224 }
embeddedartists 0:5e5e9ec91fc8 225 }
embeddedartists 0:5e5e9ec91fc8 226 }
embeddedartists 0:5e5e9ec91fc8 227
embeddedartists 0:5e5e9ec91fc8 228 /* Circle support function */
embeddedartists 0:5e5e9ec91fc8 229 static void swim_plot8points(SWIM_WINDOW_T *win, int32_t cx, int32_t cy, int32_t x, int32_t y, int32_t Filled)
embeddedartists 0:5e5e9ec91fc8 230 {
embeddedartists 0:5e5e9ec91fc8 231 swim_plot4points(win, cx, cy, x, y, Filled);
embeddedartists 0:5e5e9ec91fc8 232 if (x != y) {
embeddedartists 0:5e5e9ec91fc8 233 swim_plot4points(win, cx, cy, y, x, Filled);
embeddedartists 0:5e5e9ec91fc8 234 }
embeddedartists 0:5e5e9ec91fc8 235 }
embeddedartists 0:5e5e9ec91fc8 236
embeddedartists 0:5e5e9ec91fc8 237 /***********************************************************************
embeddedartists 0:5e5e9ec91fc8 238 * Public functions
embeddedartists 0:5e5e9ec91fc8 239 **********************************************************************/
embeddedartists 0:5e5e9ec91fc8 240
embeddedartists 0:5e5e9ec91fc8 241 /* Puts a pixel at the virtual X, Y coordinate in the window */
embeddedartists 0:5e5e9ec91fc8 242 void swim_put_pixel(SWIM_WINDOW_T *win,
embeddedartists 0:5e5e9ec91fc8 243 int32_t x1,
embeddedartists 0:5e5e9ec91fc8 244 int32_t y1)
embeddedartists 0:5e5e9ec91fc8 245 {
embeddedartists 0:5e5e9ec91fc8 246 int16_t realx, realy;
embeddedartists 0:5e5e9ec91fc8 247
embeddedartists 0:5e5e9ec91fc8 248 /* Convert virtual coordinate to physical coordinate taking into
embeddedartists 0:5e5e9ec91fc8 249 consideration the border size of the window */
embeddedartists 0:5e5e9ec91fc8 250 realx = win->xpvmin + x1;
embeddedartists 0:5e5e9ec91fc8 251 realy = win->ypvmin + y1;
embeddedartists 0:5e5e9ec91fc8 252
embeddedartists 0:5e5e9ec91fc8 253 /* Only put the pixel in the window if it fits in the window */
embeddedartists 0:5e5e9ec91fc8 254 if ((realx <= win->xpvmax) &&
embeddedartists 0:5e5e9ec91fc8 255 (realy <= win->ypvmax)) {
embeddedartists 0:5e5e9ec91fc8 256 swim_put_pixel_physical(win, realx, realy, win->pen);
embeddedartists 0:5e5e9ec91fc8 257 }
embeddedartists 0:5e5e9ec91fc8 258 }
embeddedartists 0:5e5e9ec91fc8 259
embeddedartists 0:5e5e9ec91fc8 260 /* Draw a line in the virtual window with clipping */
embeddedartists 0:5e5e9ec91fc8 261 void swim_put_line(SWIM_WINDOW_T *win,
embeddedartists 0:5e5e9ec91fc8 262 int32_t x1,
embeddedartists 0:5e5e9ec91fc8 263 int32_t y1,
embeddedartists 0:5e5e9ec91fc8 264 int32_t x2,
embeddedartists 0:5e5e9ec91fc8 265 int32_t y2)
embeddedartists 0:5e5e9ec91fc8 266 {
embeddedartists 0:5e5e9ec91fc8 267 int32_t e2, sx, sy, dx, dy, err;
embeddedartists 0:5e5e9ec91fc8 268
embeddedartists 0:5e5e9ec91fc8 269 /* Convert virtual coordinates to physical coordinates */
embeddedartists 0:5e5e9ec91fc8 270 x1 = x1 + win->xpvmin;
embeddedartists 0:5e5e9ec91fc8 271 x2 = x2 + win->xpvmin;
embeddedartists 0:5e5e9ec91fc8 272 y1 = y1 + win->ypvmin;
embeddedartists 0:5e5e9ec91fc8 273 y2 = y2 + win->ypvmin;
embeddedartists 0:5e5e9ec91fc8 274
embeddedartists 0:5e5e9ec91fc8 275 /* calculate delta_x and delta_y */
embeddedartists 0:5e5e9ec91fc8 276 dx = swim_abs(x2 - x1);
embeddedartists 0:5e5e9ec91fc8 277 dy = swim_abs(y2 - y1);
embeddedartists 0:5e5e9ec91fc8 278
embeddedartists 0:5e5e9ec91fc8 279 /* set the direction for the step for both x and y, and
embeddedartists 0:5e5e9ec91fc8 280 initialize the error */
embeddedartists 0:5e5e9ec91fc8 281 if (x1 < x2) {
embeddedartists 0:5e5e9ec91fc8 282 sx = 1;
embeddedartists 0:5e5e9ec91fc8 283 }
embeddedartists 0:5e5e9ec91fc8 284 else {
embeddedartists 0:5e5e9ec91fc8 285 sx = -1;
embeddedartists 0:5e5e9ec91fc8 286 }
embeddedartists 0:5e5e9ec91fc8 287
embeddedartists 0:5e5e9ec91fc8 288 if (y1 < y2) {
embeddedartists 0:5e5e9ec91fc8 289 sy = 1;
embeddedartists 0:5e5e9ec91fc8 290 }
embeddedartists 0:5e5e9ec91fc8 291 else {
embeddedartists 0:5e5e9ec91fc8 292 sy = -1;
embeddedartists 0:5e5e9ec91fc8 293 }
embeddedartists 0:5e5e9ec91fc8 294
embeddedartists 0:5e5e9ec91fc8 295 err = dx - dy;
embeddedartists 0:5e5e9ec91fc8 296
embeddedartists 0:5e5e9ec91fc8 297 while (1) {
embeddedartists 0:5e5e9ec91fc8 298 if ((x1 >= win->xpvmin) && (x1 <= win->xpvmax) &&
embeddedartists 0:5e5e9ec91fc8 299 (y1 >= win->ypvmin) && (y1 <= win->ypvmax)) {
embeddedartists 0:5e5e9ec91fc8 300 swim_put_pixel_physical(win, x1, y1, win->pen);
embeddedartists 0:5e5e9ec91fc8 301 }
embeddedartists 0:5e5e9ec91fc8 302
embeddedartists 0:5e5e9ec91fc8 303 if ((x1 == x2) && (y1 == y2)) {
embeddedartists 0:5e5e9ec91fc8 304 return;
embeddedartists 0:5e5e9ec91fc8 305 }
embeddedartists 0:5e5e9ec91fc8 306
embeddedartists 0:5e5e9ec91fc8 307 e2 = 2 * err;
embeddedartists 0:5e5e9ec91fc8 308 if (e2 > -dy) {
embeddedartists 0:5e5e9ec91fc8 309 err -= dy;
embeddedartists 0:5e5e9ec91fc8 310 x1 += sx;
embeddedartists 0:5e5e9ec91fc8 311 }
embeddedartists 0:5e5e9ec91fc8 312 if (e2 < dx) {
embeddedartists 0:5e5e9ec91fc8 313 err += dx;
embeddedartists 0:5e5e9ec91fc8 314 y1 += sy;
embeddedartists 0:5e5e9ec91fc8 315 }
embeddedartists 0:5e5e9ec91fc8 316 }
embeddedartists 0:5e5e9ec91fc8 317 }
embeddedartists 0:5e5e9ec91fc8 318
embeddedartists 0:5e5e9ec91fc8 319 /* Draw a diamond in the virtual window */
embeddedartists 0:5e5e9ec91fc8 320 void swim_put_diamond(SWIM_WINDOW_T *win,
embeddedartists 0:5e5e9ec91fc8 321 int32_t x,
embeddedartists 0:5e5e9ec91fc8 322 int32_t y,
embeddedartists 0:5e5e9ec91fc8 323 int32_t rx,
embeddedartists 0:5e5e9ec91fc8 324 int32_t ry)
embeddedartists 0:5e5e9ec91fc8 325 {
embeddedartists 0:5e5e9ec91fc8 326 int32_t xleft, xright, xleft1, xleft2, xright1, idy, ypmid;
embeddedartists 0:5e5e9ec91fc8 327 int32_t ypmin, ypmax, dlta, err, e2;
embeddedartists 0:5e5e9ec91fc8 328
embeddedartists 0:5e5e9ec91fc8 329 /* Use line draw functions to draw border in pen color in virtual
embeddedartists 0:5e5e9ec91fc8 330 coordinates */
embeddedartists 0:5e5e9ec91fc8 331 swim_put_line(win, x - rx, y, x, y - ry);
embeddedartists 0:5e5e9ec91fc8 332 swim_put_line(win, x + rx, y, x, y - ry);
embeddedartists 0:5e5e9ec91fc8 333 swim_put_line(win, x - rx, y, x, y + ry);
embeddedartists 0:5e5e9ec91fc8 334 swim_put_line(win, x + rx, y, x, y + ry);
embeddedartists 0:5e5e9ec91fc8 335
embeddedartists 0:5e5e9ec91fc8 336 /* Adjust rx and rx for interior fill region minus border */
embeddedartists 0:5e5e9ec91fc8 337 rx--;
embeddedartists 0:5e5e9ec91fc8 338 ry--;
embeddedartists 0:5e5e9ec91fc8 339 if ((rx <= 0) || (ry <= 0)) {
embeddedartists 0:5e5e9ec91fc8 340 return;
embeddedartists 0:5e5e9ec91fc8 341 }
embeddedartists 0:5e5e9ec91fc8 342
embeddedartists 0:5e5e9ec91fc8 343 /* Y limits in physical coordinates minus border line */
embeddedartists 0:5e5e9ec91fc8 344 ypmin = y - ry + win->ypvmin;
embeddedartists 0:5e5e9ec91fc8 345 ypmid = y + win->ypvmin;
embeddedartists 0:5e5e9ec91fc8 346 ypmax = y + ry + win->ypvmin;
embeddedartists 0:5e5e9ec91fc8 347
embeddedartists 0:5e5e9ec91fc8 348 /* X starts draw from center line */
embeddedartists 0:5e5e9ec91fc8 349 xleft = xright = x + win->xpvmin;
embeddedartists 0:5e5e9ec91fc8 350
embeddedartists 0:5e5e9ec91fc8 351 err = rx - ry;
embeddedartists 0:5e5e9ec91fc8 352 dlta = 1 + rx / ry;
embeddedartists 0:5e5e9ec91fc8 353
embeddedartists 0:5e5e9ec91fc8 354 for (idy = ypmin; idy <= ypmid; idy++) {
embeddedartists 0:5e5e9ec91fc8 355 xleft1 = xleft2 = xleft;
embeddedartists 0:5e5e9ec91fc8 356 xright1 = xright;
embeddedartists 0:5e5e9ec91fc8 357
embeddedartists 0:5e5e9ec91fc8 358 /* Clip left and right to virtual window size */
embeddedartists 0:5e5e9ec91fc8 359 if (xleft1 < win->xpvmin) {
embeddedartists 0:5e5e9ec91fc8 360 xleft2 = xleft1 = win->xpvmin;
embeddedartists 0:5e5e9ec91fc8 361 }
embeddedartists 0:5e5e9ec91fc8 362 if (xright1 > win->xpvmax) {
embeddedartists 0:5e5e9ec91fc8 363 xright1 = win->xpvmax;
embeddedartists 0:5e5e9ec91fc8 364 }
embeddedartists 0:5e5e9ec91fc8 365
embeddedartists 0:5e5e9ec91fc8 366 /* Is top half visible? */
embeddedartists 0:5e5e9ec91fc8 367 if ((idy >= win->ypvmin) && (idy <= win->ypvmax)) {
embeddedartists 0:5e5e9ec91fc8 368 while (xleft1 <= xright1) {
embeddedartists 0:5e5e9ec91fc8 369 swim_put_pixel_physical(win, xleft1, idy, win->fill);
embeddedartists 0:5e5e9ec91fc8 370 xleft1++;
embeddedartists 0:5e5e9ec91fc8 371 }
embeddedartists 0:5e5e9ec91fc8 372 }
embeddedartists 0:5e5e9ec91fc8 373
embeddedartists 0:5e5e9ec91fc8 374 /* Draw bottom half if visible */
embeddedartists 0:5e5e9ec91fc8 375 if ((ypmax >= ypmid) && (ypmax <= win->ypvmax)) {
embeddedartists 0:5e5e9ec91fc8 376 /* Mirror bottom */
embeddedartists 0:5e5e9ec91fc8 377 while (xleft2 <= xright1) {
embeddedartists 0:5e5e9ec91fc8 378 swim_put_pixel_physical(win, xleft2, ypmax, win->fill);
embeddedartists 0:5e5e9ec91fc8 379 xleft2++;
embeddedartists 0:5e5e9ec91fc8 380 }
embeddedartists 0:5e5e9ec91fc8 381 }
embeddedartists 0:5e5e9ec91fc8 382 ypmax--;
embeddedartists 0:5e5e9ec91fc8 383
embeddedartists 0:5e5e9ec91fc8 384 e2 = 2 * err;
embeddedartists 0:5e5e9ec91fc8 385 if (e2 > -ry) {
embeddedartists 0:5e5e9ec91fc8 386 err -= ry;
embeddedartists 0:5e5e9ec91fc8 387 xleft -= dlta;
embeddedartists 0:5e5e9ec91fc8 388 xright += dlta;
embeddedartists 0:5e5e9ec91fc8 389 }
embeddedartists 0:5e5e9ec91fc8 390 if (e2 < rx) {
embeddedartists 0:5e5e9ec91fc8 391 err += rx;
embeddedartists 0:5e5e9ec91fc8 392 }
embeddedartists 0:5e5e9ec91fc8 393 }
embeddedartists 0:5e5e9ec91fc8 394 }
embeddedartists 0:5e5e9ec91fc8 395
embeddedartists 0:5e5e9ec91fc8 396 /* Draws a circle in the virtual window */
embeddedartists 0:5e5e9ec91fc8 397 void swim_put_circle(SWIM_WINDOW_T *win, int32_t cx, int32_t cy, int32_t radius, int32_t Filled)
embeddedartists 0:5e5e9ec91fc8 398 {
embeddedartists 0:5e5e9ec91fc8 399 int32_t Error = -radius;
embeddedartists 0:5e5e9ec91fc8 400 int16_t x = radius;
embeddedartists 0:5e5e9ec91fc8 401 int16_t y = 0;
embeddedartists 0:5e5e9ec91fc8 402
embeddedartists 0:5e5e9ec91fc8 403 /* Convert virtual coordinates to physical coordinates */
embeddedartists 0:5e5e9ec91fc8 404 cx += win->xpvmin;
embeddedartists 0:5e5e9ec91fc8 405 cy += win->ypvmin;
embeddedartists 0:5e5e9ec91fc8 406
embeddedartists 0:5e5e9ec91fc8 407 while ( x >= y ) {
embeddedartists 0:5e5e9ec91fc8 408 swim_plot8points(win, cx, cy, x, y, Filled);
embeddedartists 0:5e5e9ec91fc8 409
embeddedartists 0:5e5e9ec91fc8 410 Error += y;
embeddedartists 0:5e5e9ec91fc8 411 ++y;
embeddedartists 0:5e5e9ec91fc8 412 Error += y;
embeddedartists 0:5e5e9ec91fc8 413
embeddedartists 0:5e5e9ec91fc8 414 if ( Error >= 0 ) {
embeddedartists 0:5e5e9ec91fc8 415 --x;
embeddedartists 0:5e5e9ec91fc8 416 Error -= x;
embeddedartists 0:5e5e9ec91fc8 417 Error -= x;
embeddedartists 0:5e5e9ec91fc8 418 }
embeddedartists 0:5e5e9ec91fc8 419 }
embeddedartists 0:5e5e9ec91fc8 420 }
embeddedartists 0:5e5e9ec91fc8 421
embeddedartists 0:5e5e9ec91fc8 422 /* Fills the draw area of the display with the selected color */
embeddedartists 0:5e5e9ec91fc8 423 void swim_clear_screen(SWIM_WINDOW_T *win,
embeddedartists 0:5e5e9ec91fc8 424 COLOR_T colr)
embeddedartists 0:5e5e9ec91fc8 425 {
embeddedartists 0:5e5e9ec91fc8 426 int32_t x, y;
embeddedartists 0:5e5e9ec91fc8 427
embeddedartists 0:5e5e9ec91fc8 428 for (y = win->ypvmin; y <= win->ypvmax; y++) {
embeddedartists 0:5e5e9ec91fc8 429 for (x = win->xpvmin; x <= win->xpvmax; x++) {
embeddedartists 0:5e5e9ec91fc8 430 swim_put_pixel_physical(win, x, y, colr);
embeddedartists 0:5e5e9ec91fc8 431 }
embeddedartists 0:5e5e9ec91fc8 432 }
embeddedartists 0:5e5e9ec91fc8 433 }
embeddedartists 0:5e5e9ec91fc8 434
embeddedartists 0:5e5e9ec91fc8 435 /* Place a box with corners (X1, Y1) and (X2, Y2) */
embeddedartists 0:5e5e9ec91fc8 436 void swim_put_box(SWIM_WINDOW_T *win,
embeddedartists 0:5e5e9ec91fc8 437 int32_t x1,
embeddedartists 0:5e5e9ec91fc8 438 int32_t y1,
embeddedartists 0:5e5e9ec91fc8 439 int32_t x2,
embeddedartists 0:5e5e9ec91fc8 440 int32_t y2)
embeddedartists 0:5e5e9ec91fc8 441 {
embeddedartists 0:5e5e9ec91fc8 442 int32_t xinc, yinc;
embeddedartists 0:5e5e9ec91fc8 443 int32_t ysave;
embeddedartists 0:5e5e9ec91fc8 444
embeddedartists 0:5e5e9ec91fc8 445 if (x1 > x2) {
embeddedartists 0:5e5e9ec91fc8 446 xinc = x1;
embeddedartists 0:5e5e9ec91fc8 447 x1 = x2;
embeddedartists 0:5e5e9ec91fc8 448 x2 = xinc;
embeddedartists 0:5e5e9ec91fc8 449 }
embeddedartists 0:5e5e9ec91fc8 450
embeddedartists 0:5e5e9ec91fc8 451 /* Swap y1 and y2 if y1 is larger than y2 */
embeddedartists 0:5e5e9ec91fc8 452 if (y1 > y2) {
embeddedartists 0:5e5e9ec91fc8 453 yinc = y1;
embeddedartists 0:5e5e9ec91fc8 454 y1 = y2;
embeddedartists 0:5e5e9ec91fc8 455 y2 = yinc;
embeddedartists 0:5e5e9ec91fc8 456 }
embeddedartists 0:5e5e9ec91fc8 457
embeddedartists 0:5e5e9ec91fc8 458 /* Convert virtual coordinates to physical coordinates */
embeddedartists 0:5e5e9ec91fc8 459 x1 = x1 + win->xpvmin;
embeddedartists 0:5e5e9ec91fc8 460 x2 = x2 + win->xpvmin;
embeddedartists 0:5e5e9ec91fc8 461 y1 = y1 + win->ypvmin;
embeddedartists 0:5e5e9ec91fc8 462 y2 = y2 + win->ypvmin;
embeddedartists 0:5e5e9ec91fc8 463
embeddedartists 0:5e5e9ec91fc8 464 /* Clip boxes to window sizes */
embeddedartists 0:5e5e9ec91fc8 465 if (x1 < win->xpvmin) {
embeddedartists 0:5e5e9ec91fc8 466 x1 = win->xpvmin;
embeddedartists 0:5e5e9ec91fc8 467 }
embeddedartists 0:5e5e9ec91fc8 468 if (y1 < win->ypvmin) {
embeddedartists 0:5e5e9ec91fc8 469 y1 = win->ypvmin;
embeddedartists 0:5e5e9ec91fc8 470 }
embeddedartists 0:5e5e9ec91fc8 471 if (x2 > win->xpvmax) {
embeddedartists 0:5e5e9ec91fc8 472 x2 = win->xpvmax;
embeddedartists 0:5e5e9ec91fc8 473 }
embeddedartists 0:5e5e9ec91fc8 474 if (y2 > win->ypvmax) {
embeddedartists 0:5e5e9ec91fc8 475 y2 = win->ypvmax;
embeddedartists 0:5e5e9ec91fc8 476 }
embeddedartists 0:5e5e9ec91fc8 477
embeddedartists 0:5e5e9ec91fc8 478 /* Get X and Y differences */
embeddedartists 0:5e5e9ec91fc8 479 xinc = x2 - x1;
embeddedartists 0:5e5e9ec91fc8 480 yinc = y2 - y1;
embeddedartists 0:5e5e9ec91fc8 481
embeddedartists 0:5e5e9ec91fc8 482 /* Make outer edge of box in pen color */
embeddedartists 0:5e5e9ec91fc8 483 swim_put_line_raw(win, x1, y1, x2, y1);
embeddedartists 0:5e5e9ec91fc8 484 swim_put_line_raw(win, x2, y1, x2, y2);
embeddedartists 0:5e5e9ec91fc8 485 swim_put_line_raw(win, x2, y2, x1, y2);
embeddedartists 0:5e5e9ec91fc8 486 swim_put_line_raw(win, x1, y2, x1, y1);
embeddedartists 0:5e5e9ec91fc8 487
embeddedartists 0:5e5e9ec91fc8 488 /* Increment X, Y values so they won't overwrite the edge */
embeddedartists 0:5e5e9ec91fc8 489 x1++;
embeddedartists 0:5e5e9ec91fc8 490 y1++;
embeddedartists 0:5e5e9ec91fc8 491
embeddedartists 0:5e5e9ec91fc8 492 /* Draw the box inside with the fill color */
embeddedartists 0:5e5e9ec91fc8 493 ysave = y1;
embeddedartists 0:5e5e9ec91fc8 494 while (x1 < x2) {
embeddedartists 0:5e5e9ec91fc8 495 y1 = ysave;
embeddedartists 0:5e5e9ec91fc8 496 while (y1 < y2) {
embeddedartists 0:5e5e9ec91fc8 497 swim_put_pixel_physical(win, x1, y1, win->fill);
embeddedartists 0:5e5e9ec91fc8 498 y1++;
embeddedartists 0:5e5e9ec91fc8 499 }
embeddedartists 0:5e5e9ec91fc8 500
embeddedartists 0:5e5e9ec91fc8 501 x1++;
embeddedartists 0:5e5e9ec91fc8 502 }
embeddedartists 0:5e5e9ec91fc8 503 }
embeddedartists 0:5e5e9ec91fc8 504
embeddedartists 0:5e5e9ec91fc8 505 /* Initializes a window and the default values for the window */
embeddedartists 0:5e5e9ec91fc8 506 BOOL_32 swim_window_open(SWIM_WINDOW_T *win,
embeddedartists 0:5e5e9ec91fc8 507 int32_t xsize,
embeddedartists 0:5e5e9ec91fc8 508 int32_t ysize,
embeddedartists 0:5e5e9ec91fc8 509 COLOR_T *fbaddr,
embeddedartists 0:5e5e9ec91fc8 510 int32_t xwin_min,
embeddedartists 0:5e5e9ec91fc8 511 int32_t ywin_min,
embeddedartists 0:5e5e9ec91fc8 512 int32_t xwin_max,
embeddedartists 0:5e5e9ec91fc8 513 int32_t ywin_max,
embeddedartists 0:5e5e9ec91fc8 514 int32_t border_width,
embeddedartists 0:5e5e9ec91fc8 515 COLOR_T pcolor,
embeddedartists 0:5e5e9ec91fc8 516 COLOR_T bkcolor,
embeddedartists 0:5e5e9ec91fc8 517 COLOR_T fcolor)
embeddedartists 0:5e5e9ec91fc8 518 {
embeddedartists 0:5e5e9ec91fc8 519 BOOL_32 init;
embeddedartists 0:5e5e9ec91fc8 520
embeddedartists 0:5e5e9ec91fc8 521 init = swim_window_open_p(win, xsize, ysize, fbaddr, xwin_min,
embeddedartists 0:5e5e9ec91fc8 522 ywin_min, xwin_max, ywin_max, border_width, pcolor, bkcolor,
embeddedartists 0:5e5e9ec91fc8 523 fcolor, true);
embeddedartists 0:5e5e9ec91fc8 524
embeddedartists 0:5e5e9ec91fc8 525 /* Default font background is not transparent */
embeddedartists 0:5e5e9ec91fc8 526 win->tfont = 1;
embeddedartists 0:5e5e9ec91fc8 527
embeddedartists 0:5e5e9ec91fc8 528 return init;
embeddedartists 0:5e5e9ec91fc8 529 }
embeddedartists 0:5e5e9ec91fc8 530
embeddedartists 0:5e5e9ec91fc8 531 /* Initializes a window without clearing it */
embeddedartists 0:5e5e9ec91fc8 532 BOOL_32 swim_window_open_noclear(SWIM_WINDOW_T *win,
embeddedartists 0:5e5e9ec91fc8 533 int32_t xsize,
embeddedartists 0:5e5e9ec91fc8 534 int32_t ysize,
embeddedartists 0:5e5e9ec91fc8 535 COLOR_T *fbaddr,
embeddedartists 0:5e5e9ec91fc8 536 int32_t xwin_min,
embeddedartists 0:5e5e9ec91fc8 537 int32_t ywin_min,
embeddedartists 0:5e5e9ec91fc8 538 int32_t xwin_max,
embeddedartists 0:5e5e9ec91fc8 539 int32_t ywin_max,
embeddedartists 0:5e5e9ec91fc8 540 int32_t border_width,
embeddedartists 0:5e5e9ec91fc8 541 COLOR_T pcolor,
embeddedartists 0:5e5e9ec91fc8 542 COLOR_T bkcolor,
embeddedartists 0:5e5e9ec91fc8 543 COLOR_T fcolor)
embeddedartists 0:5e5e9ec91fc8 544 {
embeddedartists 0:5e5e9ec91fc8 545 BOOL_32 init;
embeddedartists 0:5e5e9ec91fc8 546
embeddedartists 0:5e5e9ec91fc8 547 init = swim_window_open_p(win, xsize, ysize, fbaddr, xwin_min,
embeddedartists 0:5e5e9ec91fc8 548 ywin_min, xwin_max, ywin_max, border_width, pcolor, bkcolor,
embeddedartists 0:5e5e9ec91fc8 549 fcolor, false);
embeddedartists 0:5e5e9ec91fc8 550
embeddedartists 0:5e5e9ec91fc8 551 /* Default font background is transparent */
embeddedartists 0:5e5e9ec91fc8 552 win->tfont = 0;
embeddedartists 0:5e5e9ec91fc8 553
embeddedartists 0:5e5e9ec91fc8 554 return init;
embeddedartists 0:5e5e9ec91fc8 555 }
embeddedartists 0:5e5e9ec91fc8 556
embeddedartists 0:5e5e9ec91fc8 557 /* Deallocates a window */
embeddedartists 0:5e5e9ec91fc8 558 void swim_window_close(SWIM_WINDOW_T *win)
embeddedartists 0:5e5e9ec91fc8 559 {
embeddedartists 0:5e5e9ec91fc8 560 win->winused = 0x0;
embeddedartists 0:5e5e9ec91fc8 561 }
embeddedartists 0:5e5e9ec91fc8 562
embeddedartists 0:5e5e9ec91fc8 563 /* Sets the pen color */
embeddedartists 0:5e5e9ec91fc8 564 void swim_set_pen_color(SWIM_WINDOW_T *win,
embeddedartists 0:5e5e9ec91fc8 565 COLOR_T pen_color)
embeddedartists 0:5e5e9ec91fc8 566 {
embeddedartists 0:5e5e9ec91fc8 567 win->pen = pen_color;
embeddedartists 0:5e5e9ec91fc8 568 }
embeddedartists 0:5e5e9ec91fc8 569
embeddedartists 0:5e5e9ec91fc8 570 /* Sets the fill color */
embeddedartists 0:5e5e9ec91fc8 571 void swim_set_fill_color(SWIM_WINDOW_T *win,
embeddedartists 0:5e5e9ec91fc8 572 COLOR_T fill_color)
embeddedartists 0:5e5e9ec91fc8 573 {
embeddedartists 0:5e5e9ec91fc8 574 win->fill = fill_color;
embeddedartists 0:5e5e9ec91fc8 575 }
embeddedartists 0:5e5e9ec91fc8 576
embeddedartists 0:5e5e9ec91fc8 577 /* Sets the color used for backgrounds */
embeddedartists 0:5e5e9ec91fc8 578 void swim_set_bkg_color(SWIM_WINDOW_T *win,
embeddedartists 0:5e5e9ec91fc8 579 COLOR_T bkg_color)
embeddedartists 0:5e5e9ec91fc8 580 {
embeddedartists 0:5e5e9ec91fc8 581 win->bkg = bkg_color;
embeddedartists 0:5e5e9ec91fc8 582 }
embeddedartists 0:5e5e9ec91fc8 583
embeddedartists 0:5e5e9ec91fc8 584 /* Sets the font to be used for all new windows */
embeddedartists 0:5e5e9ec91fc8 585 void swim_set_default_font(const FONT_T* def_font)
embeddedartists 0:5e5e9ec91fc8 586 {
embeddedartists 0:5e5e9ec91fc8 587 defaultFont = def_font;
embeddedartists 0:5e5e9ec91fc8 588 }
embeddedartists 0:5e5e9ec91fc8 589
embeddedartists 0:5e5e9ec91fc8 590 /* Get the virtual window horizontal size */
embeddedartists 0:5e5e9ec91fc8 591 int32_t swim_get_horizontal_size(SWIM_WINDOW_T *win)
embeddedartists 0:5e5e9ec91fc8 592 {
embeddedartists 0:5e5e9ec91fc8 593 return win->xvsize;
embeddedartists 0:5e5e9ec91fc8 594 }
embeddedartists 0:5e5e9ec91fc8 595
embeddedartists 0:5e5e9ec91fc8 596 /* Get the virtual window vertical size */
embeddedartists 0:5e5e9ec91fc8 597 int32_t swim_get_vertical_size(SWIM_WINDOW_T *win)
embeddedartists 0:5e5e9ec91fc8 598 {
embeddedartists 0:5e5e9ec91fc8 599 return win->yvsize;
embeddedartists 0:5e5e9ec91fc8 600 }
embeddedartists 0:5e5e9ec91fc8 601