Port of the LPC4088 QSB EA LCD Sphere Demo to the LPC4088 DM using the DMSupport lib. Dropping the QSB EALib
Dependencies: DMBasicGUI DMSupport
Fork of lpc4088_displaymodule_hello_world by
Graphics.cpp
00001 00002 #include "mbed.h" 00003 #include "Graphics.h" 00004 00005 00006 Graphics::Graphics(uint16_t *pFrmBuf, uint16_t dispWidth, uint16_t dispHeight) 00007 { 00008 this->windowX = dispWidth; 00009 this->windowY = dispHeight; 00010 this->pFrmBuf = pFrmBuf; 00011 } 00012 00013 void Graphics::setFrameBuffer( uint16_t *pFrmBuf ) 00014 { 00015 this->pFrmBuf = pFrmBuf; 00016 } 00017 00018 int32_t Graphics::abs(int32_t v1) const 00019 { 00020 if (v1 > 0) 00021 return v1; 00022 00023 return -v1; 00024 } 00025 00026 /*********************************************************************** 00027 * 00028 * Function: swim_put_line_raw 00029 * 00030 * Purpose: Draw a line on the physical display 00031 * 00032 * Processing: 00033 * See function. 00034 * 00035 * Parameters: 00036 * win : Window identifier 00037 * x1 : Physical X position of X line start 00038 * y1 : Physical Y position of Y line start 00039 * x2 : Physical X position of X line end 00040 * y2 : Physical Y position of Y line end 00041 * 00042 * Outputs: None 00043 * 00044 * Returns: Nothing 00045 * 00046 * Notes: None 00047 * 00048 **********************************************************************/ 00049 void Graphics::put_line(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int16_t color) 00050 { 00051 int32_t e2, sx, sy, dx, dy, err; 00052 00053 /* calculate delta_x and delta_y */ 00054 dx = abs(x2 - x1); 00055 dy = abs(y2 - y1); 00056 00057 /* set the direction for the step for both x and y, and 00058 initialize the error */ 00059 if (x1 < x2) 00060 sx = 1; 00061 else 00062 sx = -1; 00063 00064 if (y1 < y2) 00065 sy = 1; 00066 else 00067 sy = -1; 00068 00069 err = dx - dy; 00070 00071 while (1) 00072 { 00073 if ((x1 >= 0) && (x1 < this->windowX) && 00074 (y1 >= 0) && (y1 < this->windowY)) 00075 this->pFrmBuf[x1 + (this->windowX*y1)] = color; 00076 00077 if ((x1 == x2) && (y1 == y2)) 00078 return; 00079 00080 e2 = 2 * err; 00081 if (e2 > -dy) 00082 { 00083 err -= dy; 00084 x1 += sx; 00085 } 00086 if (e2 < dx) 00087 { 00088 err += dx; 00089 y1 += sy; 00090 } 00091 } 00092 } 00093 00094 /*********************************************************************** 00095 * 00096 * Function: plot4points 00097 * 00098 * Purpose: 00099 * 00100 * Processing: 00101 * See function. 00102 * 00103 * Parameters: 00104 * win : Window identifier 00105 * cx : 00106 * cy : 00107 * x : 00108 * y : 00109 * Filled : 00110 * 00111 * Outputs: None 00112 * 00113 * Returns: Nothing 00114 * 00115 * Notes: None 00116 * 00117 **********************************************************************/ 00118 void Graphics::plot4points( int32_t cx, int32_t cy, int32_t x, int32_t y, int16_t color, int32_t Filled ) 00119 { 00120 int16_t x0, x1, y0, y1; 00121 00122 y0 = cy + y; 00123 y1 = cy - y; 00124 if( Filled ) 00125 { 00126 for( x0=cx - x; x0<=cx + x; x0++ ) 00127 { 00128 if ((x0>=0) && (x0<this->windowX) && (y0>=0) && (y0<this->windowY)) 00129 this->pFrmBuf[x0 + (this->windowX*y0)] = color; 00130 if ((x0>=0) && (x0<this->windowX) && (y1>=0) && (y1<this->windowY)) 00131 this->pFrmBuf[x0 + (this->windowX*y1)] = color; 00132 } 00133 } 00134 else 00135 { 00136 x0 = cx + x; 00137 x1 = cx - x; 00138 if ((x0>=0) && (x0<this->windowX) && (y0>=0) && (y0<this->windowY)) 00139 this->pFrmBuf[x0 + (this->windowX*y0)] = color; 00140 if ((x != 0) && 00141 (x1>=0) && (x1<this->windowX) && (y0>=0) && (y0<this->windowY)) 00142 this->pFrmBuf[x1 + (this->windowX*y0)] = color; 00143 if ((y != 0) && 00144 (x0>=0) && (x0<this->windowX) && (y1>=0) && (y1<this->windowY)) 00145 this->pFrmBuf[x0 + (this->windowX*y1)] = color; 00146 if ((x != 0 && y != 0) && 00147 (x1>=0) && (x1<this->windowX) && (y1>=0) && (y1<this->windowY)) 00148 this->pFrmBuf[x1 + (this->windowX*y1)] = color; 00149 } 00150 } 00151 00152 /*********************************************************************** 00153 * 00154 * Function: plot8points 00155 * 00156 * Purpose: 00157 * 00158 * Processing: 00159 * See function. 00160 * 00161 * Parameters: 00162 * win : Window identifier 00163 * cx : 00164 * cy : 00165 * x : 00166 * y : 00167 * Filled : 00168 * 00169 * Outputs: None 00170 * 00171 * Returns: Nothing 00172 * 00173 * Notes: None 00174 * 00175 **********************************************************************/ 00176 void Graphics::plot8points( int32_t cx, int32_t cy, int32_t x, int32_t y, int16_t color, int32_t Filled ) 00177 { 00178 plot4points( cx, cy, x, y, color, Filled ); 00179 if (x != y) 00180 plot4points( cx, cy, y, x, color, Filled ); 00181 } 00182 00183 /*********************************************************************** 00184 * 00185 * Function: swim_put_circle 00186 * 00187 * Purpose: 00188 * 00189 * Processing: 00190 * See function. 00191 * 00192 * Parameters: 00193 * win : Window identifier 00194 * cx : 00195 * cy : 00196 * radius : 00197 * Filled : 00198 * 00199 * Outputs: None 00200 * 00201 * Returns: Nothing 00202 * 00203 * Notes: None 00204 * 00205 **********************************************************************/ 00206 void Graphics::put_circle( int32_t cx, int32_t cy, int16_t color, int32_t radius, int32_t Filled ) 00207 { 00208 int32_t Error = -radius; 00209 int16_t x = radius; 00210 int16_t y = 0; 00211 00212 while( x >= y ) 00213 { 00214 plot8points( cx, cy, x, y, color, Filled ); 00215 00216 Error += y; 00217 ++y; 00218 Error += y; 00219 00220 if( Error >= 0 ) 00221 { 00222 --x; 00223 Error -= x; 00224 Error -= x; 00225 } 00226 } 00227 } 00228 00229 00230
Generated on Fri Jul 15 2022 16:25:52 by 1.7.2