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 EmbeddedArtists AB

Committer:
embeddedartists
Date:
Thu Dec 11 11:03:57 2014 +0000
Revision:
0:4977187e90c7
Child:
17:6e2abf107800
First version

Who changed what in which revision?

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