Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Picaso_4DGL-32PTU_graphics.cpp@3:dcfbceb81fef, 2016-09-09 (annotated)
- Committer:
- CaptainR
- Date:
- Fri Sep 09 10:19:54 2016 +0000
- Revision:
- 3:dcfbceb81fef
- Parent:
- 2:81eaaa491a02
- Child:
- 4:50511ed54ab4
Added a couple graphics functions;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
CaptainR | 1:e2337e2653e1 | 1 | // |
CaptainR | 2:81eaaa491a02 | 2 | // Picaso_4DGL-32PTU is a class to drive 4D Systems TFT touch screens with PICASO processor |
CaptainR | 2:81eaaa491a02 | 3 | // Tested with NUCLEO L152RE development board |
CaptainR | 2:81eaaa491a02 | 4 | // Copyright (C) <2016> Rihards Balass <rihards.balass@gmail.com> |
CaptainR | 1:e2337e2653e1 | 5 | // |
CaptainR | 2:81eaaa491a02 | 6 | // Picaso_4DGL-32PTU is free software: you can redistribute it and/or modify |
CaptainR | 2:81eaaa491a02 | 7 | // it under the terms of the GNU General Public License as published by |
CaptainR | 2:81eaaa491a02 | 8 | // the Free Software Foundation, either version 3 of the License, or |
CaptainR | 2:81eaaa491a02 | 9 | // (at your option) any later version. |
CaptainR | 2:81eaaa491a02 | 10 | // |
CaptainR | 2:81eaaa491a02 | 11 | // Picaso_4DGL-32PTU is distributed in the hope that it will be useful, |
CaptainR | 2:81eaaa491a02 | 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
CaptainR | 2:81eaaa491a02 | 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
CaptainR | 2:81eaaa491a02 | 14 | // GNU General Public License for more details. |
CaptainR | 2:81eaaa491a02 | 15 | // |
CaptainR | 2:81eaaa491a02 | 16 | // You can see GNU General Public License at <http://www.gnu.org/licenses/>. |
CaptainR | 1:e2337e2653e1 | 17 | // |
CaptainR | 0:a5ef6bc3c2e8 | 18 | |
CaptainR | 0:a5ef6bc3c2e8 | 19 | #include "mbed.h" |
CaptainR | 0:a5ef6bc3c2e8 | 20 | #include "Picaso_4DGL-32PTU.h" |
CaptainR | 0:a5ef6bc3c2e8 | 21 | |
CaptainR | 0:a5ef6bc3c2e8 | 22 | //************************************************************************** |
CaptainR | 3:dcfbceb81fef | 23 | // The Clear Screen command clears the screen using the current background color. |
CaptainR | 0:a5ef6bc3c2e8 | 24 | // This command brings some of the settings back to default; such as, |
CaptainR | 0:a5ef6bc3c2e8 | 25 | // Transparency turned OFF |
CaptainR | 3:dcfbceb81fef | 26 | // Outline color set to BLACK |
CaptainR | 0:a5ef6bc3c2e8 | 27 | // Opacity set to OPAQUE |
CaptainR | 0:a5ef6bc3c2e8 | 28 | // Pen set to OUTLINE |
CaptainR | 0:a5ef6bc3c2e8 | 29 | // Line patterns set to OFF |
CaptainR | 0:a5ef6bc3c2e8 | 30 | // Right text margin set to full width |
CaptainR | 0:a5ef6bc3c2e8 | 31 | // Text magnifications set to 1 |
CaptainR | 0:a5ef6bc3c2e8 | 32 | // All origins set to 0:0 |
CaptainR | 0:a5ef6bc3c2e8 | 33 | // The alternative to maintain settings and clear screen is |
CaptainR | 3:dcfbceb81fef | 34 | // to draw a filled rectangle with the required background color. |
CaptainR | 0:a5ef6bc3c2e8 | 35 | //************************************************************************** |
CaptainR | 3:dcfbceb81fef | 36 | void PICASO_4DGL :: cls() { // clear screen |
CaptainR | 0:a5ef6bc3c2e8 | 37 | |
CaptainR | 0:a5ef6bc3c2e8 | 38 | char command[2] = ""; |
CaptainR | 0:a5ef6bc3c2e8 | 39 | |
CaptainR | 2:81eaaa491a02 | 40 | command[0] = (CLS >> (8*1)) & 0xff; |
CaptainR | 2:81eaaa491a02 | 41 | command[1] = (CLS >> (8*0)) & 0xff; |
CaptainR | 0:a5ef6bc3c2e8 | 42 | |
CaptainR | 0:a5ef6bc3c2e8 | 43 | writeCOMMAND(command, 2); |
CaptainR | 0:a5ef6bc3c2e8 | 44 | } |
CaptainR | 0:a5ef6bc3c2e8 | 45 | |
CaptainR | 0:a5ef6bc3c2e8 | 46 | //************************************************************************** |
CaptainR | 3:dcfbceb81fef | 47 | // The Change Color command changes all oldColor pixels to newColor |
CaptainR | 0:a5ef6bc3c2e8 | 48 | // within the clipping window area. |
CaptainR | 0:a5ef6bc3c2e8 | 49 | //************************************************************************** |
CaptainR | 3:dcfbceb81fef | 50 | void PICASO_4DGL :: changeColor(short oldColor, short newColor) { |
CaptainR | 0:a5ef6bc3c2e8 | 51 | |
CaptainR | 0:a5ef6bc3c2e8 | 52 | char command[6] = ""; |
CaptainR | 0:a5ef6bc3c2e8 | 53 | |
CaptainR | 2:81eaaa491a02 | 54 | command[0] = (CHANGE_COLOR >> (8*1)) & 0xff; |
CaptainR | 2:81eaaa491a02 | 55 | command[1] = (CHANGE_COLOR >> (8*0)) & 0xff; |
CaptainR | 2:81eaaa491a02 | 56 | command[2] = (oldColor >> (8*1)) & 0xff; |
CaptainR | 2:81eaaa491a02 | 57 | command[3] = (oldColor >> (8*0)) & 0xff; |
CaptainR | 2:81eaaa491a02 | 58 | command[4] = (newColor >> (8*1)) & 0xff; |
CaptainR | 2:81eaaa491a02 | 59 | command[5] = (newColor >> (8*0)) & 0xff; |
CaptainR | 0:a5ef6bc3c2e8 | 60 | |
CaptainR | 0:a5ef6bc3c2e8 | 61 | writeCOMMAND(command, 6); |
CaptainR | 0:a5ef6bc3c2e8 | 62 | } |
CaptainR | 0:a5ef6bc3c2e8 | 63 | |
CaptainR | 0:a5ef6bc3c2e8 | 64 | //************************************************************************** |
CaptainR | 0:a5ef6bc3c2e8 | 65 | // The Draw Circle command draws a circle with centre point x, y |
CaptainR | 3:dcfbceb81fef | 66 | // with radius r using the specified color. |
CaptainR | 0:a5ef6bc3c2e8 | 67 | //************************************************************************** |
CaptainR | 3:dcfbceb81fef | 68 | void PICASO_4DGL :: drawCircle(short x, short y, short r, short color) { |
CaptainR | 0:a5ef6bc3c2e8 | 69 | |
CaptainR | 0:a5ef6bc3c2e8 | 70 | char command[10] = ""; |
CaptainR | 0:a5ef6bc3c2e8 | 71 | |
CaptainR | 2:81eaaa491a02 | 72 | command[0] = (DRAW_CIRCLE >> (8*1)) & 0xff; |
CaptainR | 2:81eaaa491a02 | 73 | command[1] = (DRAW_CIRCLE >> (8*0)) & 0xff; |
CaptainR | 0:a5ef6bc3c2e8 | 74 | command[2] = (x >> (8*1)) & 0xff; |
CaptainR | 0:a5ef6bc3c2e8 | 75 | command[3] = (x >> (8*0)) & 0xff; |
CaptainR | 0:a5ef6bc3c2e8 | 76 | command[4] = (y >> (8*1)) & 0xff; |
CaptainR | 0:a5ef6bc3c2e8 | 77 | command[5] = (y >> (8*0)) & 0xff; |
CaptainR | 0:a5ef6bc3c2e8 | 78 | command[6] = (r >> (8*1)) & 0xff; |
CaptainR | 0:a5ef6bc3c2e8 | 79 | command[7] = (r >> (8*0)) & 0xff; |
CaptainR | 2:81eaaa491a02 | 80 | command[8] = (color >> (8*1)) & 0xff; |
CaptainR | 2:81eaaa491a02 | 81 | command[9] = (color >> (8*0)) & 0xff; |
CaptainR | 0:a5ef6bc3c2e8 | 82 | |
CaptainR | 0:a5ef6bc3c2e8 | 83 | writeCOMMAND(command, 10); |
CaptainR | 0:a5ef6bc3c2e8 | 84 | } |
CaptainR | 0:a5ef6bc3c2e8 | 85 | |
CaptainR | 3:dcfbceb81fef | 86 | //************************************************************************** |
CaptainR | 3:dcfbceb81fef | 87 | // The Draw Circle command draws a solid circle with centre point x1, y1 |
CaptainR | 3:dcfbceb81fef | 88 | // with radius r using the specified color. |
CaptainR | 3:dcfbceb81fef | 89 | // The outline color can be specified with the “Outline Color” command. |
CaptainR | 3:dcfbceb81fef | 90 | // If “Outline Color” is set to 0, no outline is drawn. |
CaptainR | 3:dcfbceb81fef | 91 | //************************************************************************** |
CaptainR | 3:dcfbceb81fef | 92 | void PICASO_4DGL :: drawFilledCircle(short x, short y, short r, short color) { |
CaptainR | 3:dcfbceb81fef | 93 | |
CaptainR | 3:dcfbceb81fef | 94 | char command[10] = ""; |
CaptainR | 3:dcfbceb81fef | 95 | |
CaptainR | 3:dcfbceb81fef | 96 | command[0] = (CIRCLE_FILLED >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 97 | command[1] = (CIRCLE_FILLED >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 98 | command[2] = (x >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 99 | command[3] = (x >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 100 | command[4] = (y >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 101 | command[5] = (y >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 102 | command[6] = (r >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 103 | command[7] = (r >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 104 | command[8] = (color >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 105 | command[9] = (color >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 106 | |
CaptainR | 3:dcfbceb81fef | 107 | writeCOMMAND(command, 10); |
CaptainR | 3:dcfbceb81fef | 108 | } |
CaptainR | 0:a5ef6bc3c2e8 | 109 | |
CaptainR | 3:dcfbceb81fef | 110 | //************************************************************************** |
CaptainR | 3:dcfbceb81fef | 111 | // The Draw Line command draws a line from x1, y1 to x2, y2 |
CaptainR | 3:dcfbceb81fef | 112 | // using the specified color. |
CaptainR | 3:dcfbceb81fef | 113 | //************************************************************************** |
CaptainR | 3:dcfbceb81fef | 114 | void PICASO_4DGL :: drawLine(short x1, short y1, short x2, short y2, short color) { |
CaptainR | 3:dcfbceb81fef | 115 | |
CaptainR | 3:dcfbceb81fef | 116 | char command[12] = ""; |
CaptainR | 3:dcfbceb81fef | 117 | |
CaptainR | 3:dcfbceb81fef | 118 | command[0] = (DRAW_LINE >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 119 | command[1] = (DRAW_LINE >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 120 | command[2] = (x1 >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 121 | command[3] = (x1 >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 122 | command[4] = (y1 >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 123 | command[5] = (y1 >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 124 | command[6] = (x2 >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 125 | command[7] = (x2 >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 126 | command[8] = (y2 >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 127 | command[9] = (y2 >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 128 | command[10] = (color >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 129 | command[11] = (color >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 130 | |
CaptainR | 3:dcfbceb81fef | 131 | writeCOMMAND(command, 12); |
CaptainR | 3:dcfbceb81fef | 132 | } |
CaptainR | 0:a5ef6bc3c2e8 | 133 | |
CaptainR | 3:dcfbceb81fef | 134 | //************************************************************************** |
CaptainR | 3:dcfbceb81fef | 135 | // The Draw Rectangle command draws a rectangle from x1, y1 to x2, y2 |
CaptainR | 3:dcfbceb81fef | 136 | // using the specified color. |
CaptainR | 3:dcfbceb81fef | 137 | // The line may be tessellated with the “Line Pattern” command. |
CaptainR | 3:dcfbceb81fef | 138 | //************************************************************************** |
CaptainR | 3:dcfbceb81fef | 139 | void PICASO_4DGL :: drawRectangle(short x1, short y1, short x2, short y2, short color) { |
CaptainR | 3:dcfbceb81fef | 140 | |
CaptainR | 3:dcfbceb81fef | 141 | char command[12] = ""; |
CaptainR | 3:dcfbceb81fef | 142 | |
CaptainR | 3:dcfbceb81fef | 143 | command[0] = (DRAW_RECTANGLE >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 144 | command[1] = (DRAW_RECTANGLE >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 145 | command[2] = (x1 >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 146 | command[3] = (x1 >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 147 | command[4] = (y1 >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 148 | command[5] = (y1 >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 149 | command[6] = (x2 >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 150 | command[7] = (x2 >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 151 | command[8] = (y2 >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 152 | command[9] = (y2 >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 153 | command[10] = (color >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 154 | command[11] = (color >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 155 | |
CaptainR | 3:dcfbceb81fef | 156 | writeCOMMAND(command, 12); |
CaptainR | 3:dcfbceb81fef | 157 | } |
CaptainR | 0:a5ef6bc3c2e8 | 158 | |
CaptainR | 3:dcfbceb81fef | 159 | //************************************************************************** |
CaptainR | 3:dcfbceb81fef | 160 | // The Draw Filled Rectangle command draws a solid rectangle from x1, y1 to x2, y2 |
CaptainR | 3:dcfbceb81fef | 161 | // using the specified color. |
CaptainR | 3:dcfbceb81fef | 162 | // The line may be tessellated with the “Line Pattern” command. |
CaptainR | 3:dcfbceb81fef | 163 | // The outline color can be specified with the “Outline Color” command. |
CaptainR | 3:dcfbceb81fef | 164 | // If “Outline Color” is set to 0, no outline is drawn. |
CaptainR | 3:dcfbceb81fef | 165 | //************************************************************************** |
CaptainR | 3:dcfbceb81fef | 166 | void PICASO_4DGL :: drawFilledRectangle(short x1, short y1, short x2, short y2, short color) { |
CaptainR | 3:dcfbceb81fef | 167 | |
CaptainR | 3:dcfbceb81fef | 168 | char command[12] = ""; |
CaptainR | 3:dcfbceb81fef | 169 | |
CaptainR | 3:dcfbceb81fef | 170 | command[0] = (RECTANGLE_FILLED >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 171 | command[1] = (RECTANGLE_FILLED >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 172 | command[2] = (x1 >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 173 | command[3] = (x1 >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 174 | command[4] = (y1 >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 175 | command[5] = (y1 >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 176 | command[6] = (x2 >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 177 | command[7] = (x2 >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 178 | command[8] = (y2 >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 179 | command[9] = (y2 >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 180 | command[10] = (color >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 181 | command[11] = (color >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 182 | |
CaptainR | 3:dcfbceb81fef | 183 | writeCOMMAND(command, 12); |
CaptainR | 3:dcfbceb81fef | 184 | } |
CaptainR | 0:a5ef6bc3c2e8 | 185 | |
CaptainR | 0:a5ef6bc3c2e8 | 186 | |
CaptainR | 3:dcfbceb81fef | 187 | //************************************************************************** |
CaptainR | 3:dcfbceb81fef | 188 | // The Draw Polyline command plots lines between points specified by a pair of arrays |
CaptainR | 3:dcfbceb81fef | 189 | // using the specified color. |
CaptainR | 3:dcfbceb81fef | 190 | // The lines may be tessellated with the “Line Pattern” command. |
CaptainR | 3:dcfbceb81fef | 191 | // The “Draw Polyline” command can be used to create complex raster graphics |
CaptainR | 3:dcfbceb81fef | 192 | // by loading the arrays from serial input or from MEDIA with very little code requirement. |
CaptainR | 3:dcfbceb81fef | 193 | // |
CaptainR | 3:dcfbceb81fef | 194 | // n - Specifies the number of elements in the x and y arrays specifying the vertices for the polyline. |
CaptainR | 3:dcfbceb81fef | 195 | // vx, vy - Specifies the array of elements for the x/y coordinates of the vertices. |
CaptainR | 3:dcfbceb81fef | 196 | // Vx1, vx2, …, vxN, vy1, vy2, …, vyN |
CaptainR | 3:dcfbceb81fef | 197 | //************************************************************************** |
CaptainR | 3:dcfbceb81fef | 198 | void PICASO_4DGL :: drawPolyline(short n, short *vx, short *vy, short color) { |
CaptainR | 3:dcfbceb81fef | 199 | |
CaptainR | 3:dcfbceb81fef | 200 | int size = 6 + (n*4); |
CaptainR | 3:dcfbceb81fef | 201 | int i, j = 4; |
CaptainR | 3:dcfbceb81fef | 202 | char command[size]; |
CaptainR | 3:dcfbceb81fef | 203 | for(i = 0; i < size; i++) command[i] = 0; |
CaptainR | 3:dcfbceb81fef | 204 | |
CaptainR | 3:dcfbceb81fef | 205 | command[0] = (DRAW_POLYLINE >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 206 | command[1] = (DRAW_POLYLINE >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 207 | command[2] = (n >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 208 | command[3] = (n >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 209 | for (i = 0; i < n; i++) { |
CaptainR | 3:dcfbceb81fef | 210 | command[j] = (vx[i] >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 211 | j++; |
CaptainR | 3:dcfbceb81fef | 212 | command[j] = (vx[i] >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 213 | j++; |
CaptainR | 3:dcfbceb81fef | 214 | } |
CaptainR | 3:dcfbceb81fef | 215 | for (i = 0; i < n; i++) { |
CaptainR | 3:dcfbceb81fef | 216 | command[j] = (vy[i] >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 217 | j++; |
CaptainR | 3:dcfbceb81fef | 218 | command[j] = (vy[i] >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 219 | j++; |
CaptainR | 3:dcfbceb81fef | 220 | } |
CaptainR | 3:dcfbceb81fef | 221 | command[j] = (color >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 222 | command[j+1] = (color >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 223 | |
CaptainR | 3:dcfbceb81fef | 224 | writeCOMMAND(command, size); |
CaptainR | 3:dcfbceb81fef | 225 | } |
CaptainR | 0:a5ef6bc3c2e8 | 226 | |
CaptainR | 3:dcfbceb81fef | 227 | //************************************************************************** |
CaptainR | 3:dcfbceb81fef | 228 | // The Draw Polygon command plots lines between points specified by a pair of arrays |
CaptainR | 3:dcfbceb81fef | 229 | // using the specified color. |
CaptainR | 3:dcfbceb81fef | 230 | // The last point is drawn back to the first point, completing the polygon. |
CaptainR | 3:dcfbceb81fef | 231 | // The lines may be tessellated with the “Line Pattern” command. |
CaptainR | 3:dcfbceb81fef | 232 | // The Draw Polygon command can be used to create complex raster graphics |
CaptainR | 3:dcfbceb81fef | 233 | // by loading the arrays from serial input or from MEDIA with very little code requirement. |
CaptainR | 3:dcfbceb81fef | 234 | // |
CaptainR | 3:dcfbceb81fef | 235 | // n - Specifies the number of elements in the x and y arrays specifying the vertices for the polygon. |
CaptainR | 3:dcfbceb81fef | 236 | // vx, vy - Specifies the array of elements for the x/y coordinates of the vertices. |
CaptainR | 3:dcfbceb81fef | 237 | // Vx1, vx2, …, vxN, vy1, vy2, …, vyN |
CaptainR | 3:dcfbceb81fef | 238 | //************************************************************************** |
CaptainR | 3:dcfbceb81fef | 239 | void PICASO_4DGL :: drawPolygon(short n, short *vx, short *vy, short color) { |
CaptainR | 3:dcfbceb81fef | 240 | |
CaptainR | 3:dcfbceb81fef | 241 | int size = 6 + (n*4); |
CaptainR | 3:dcfbceb81fef | 242 | int i, j = 4; |
CaptainR | 3:dcfbceb81fef | 243 | char command[size]; |
CaptainR | 3:dcfbceb81fef | 244 | for(i = 0; i < size; i++) command[i] = 0; |
CaptainR | 3:dcfbceb81fef | 245 | |
CaptainR | 3:dcfbceb81fef | 246 | command[0] = (DRAW_POLYGON >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 247 | command[1] = (DRAW_POLYGON >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 248 | command[2] = (n >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 249 | command[3] = (n >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 250 | for (i = 0; i < n; i++) { |
CaptainR | 3:dcfbceb81fef | 251 | command[j] = (vx[i] >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 252 | j++; |
CaptainR | 3:dcfbceb81fef | 253 | command[j] = (vx[i] >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 254 | j++; |
CaptainR | 3:dcfbceb81fef | 255 | } |
CaptainR | 3:dcfbceb81fef | 256 | for (i = 0; i < n; i++) { |
CaptainR | 3:dcfbceb81fef | 257 | command[j] = (vy[i] >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 258 | j++; |
CaptainR | 3:dcfbceb81fef | 259 | command[j] = (vy[i] >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 260 | j++; |
CaptainR | 3:dcfbceb81fef | 261 | } |
CaptainR | 3:dcfbceb81fef | 262 | command[j] = (color >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 263 | command[j+1] = (color >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 264 | |
CaptainR | 3:dcfbceb81fef | 265 | writeCOMMAND(command, size); |
CaptainR | 3:dcfbceb81fef | 266 | } |
CaptainR | 0:a5ef6bc3c2e8 | 267 | |
CaptainR | 3:dcfbceb81fef | 268 | //************************************************************************** |
CaptainR | 3:dcfbceb81fef | 269 | // The Draw Filled Polygon command draws a solid Polygon between specified vertices: |
CaptainR | 3:dcfbceb81fef | 270 | // x1, y1 x2, y2, .... , xn, yn using the specified color. |
CaptainR | 3:dcfbceb81fef | 271 | // The last point is drawn back to the first point, completing the polygon. |
CaptainR | 3:dcfbceb81fef | 272 | // Vertices must be a minimum of 3 and can be specified in any fashion. |
CaptainR | 3:dcfbceb81fef | 273 | // |
CaptainR | 3:dcfbceb81fef | 274 | // n - Specifies the number of elements in the x and y arrays specifying the vertices for the polygon. |
CaptainR | 3:dcfbceb81fef | 275 | // vx, vy - Specifies the array of elements for the x/y coordinates of the vertices. |
CaptainR | 3:dcfbceb81fef | 276 | // Vx1, vx2, …, vxN, vy1, vy2, …, vyN |
CaptainR | 3:dcfbceb81fef | 277 | //************************************************************************** |
CaptainR | 3:dcfbceb81fef | 278 | void PICASO_4DGL :: drawFilledPolygon(short n, short *vx, short *vy, short color) { |
CaptainR | 3:dcfbceb81fef | 279 | |
CaptainR | 3:dcfbceb81fef | 280 | if (n >= 3) { |
CaptainR | 3:dcfbceb81fef | 281 | int size = 6 + (n*4); |
CaptainR | 3:dcfbceb81fef | 282 | int i, j = 4; |
CaptainR | 3:dcfbceb81fef | 283 | char command[size]; |
CaptainR | 3:dcfbceb81fef | 284 | for(i = 0; i < size; i++) command[i] = 0; |
CaptainR | 3:dcfbceb81fef | 285 | |
CaptainR | 3:dcfbceb81fef | 286 | command[0] = (POLYGON_FILLED >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 287 | command[1] = (POLYGON_FILLED >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 288 | command[2] = (n >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 289 | command[3] = (n >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 290 | for (i = 0; i < n; i++) { |
CaptainR | 3:dcfbceb81fef | 291 | command[j] = (vx[i] >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 292 | j++; |
CaptainR | 3:dcfbceb81fef | 293 | command[j] = (vx[i] >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 294 | j++; |
CaptainR | 3:dcfbceb81fef | 295 | } |
CaptainR | 3:dcfbceb81fef | 296 | for (i = 0; i < n; i++) { |
CaptainR | 3:dcfbceb81fef | 297 | command[j] = (vy[i] >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 298 | j++; |
CaptainR | 3:dcfbceb81fef | 299 | command[j] = (vy[i] >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 300 | j++; |
CaptainR | 3:dcfbceb81fef | 301 | } |
CaptainR | 3:dcfbceb81fef | 302 | command[j] = (color >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 303 | command[j+1] = (color >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 304 | |
CaptainR | 3:dcfbceb81fef | 305 | writeCOMMAND(command, size); |
CaptainR | 3:dcfbceb81fef | 306 | } |
CaptainR | 3:dcfbceb81fef | 307 | } |
CaptainR | 3:dcfbceb81fef | 308 | |
CaptainR | 3:dcfbceb81fef | 309 | //************************************************************************** |
CaptainR | 3:dcfbceb81fef | 310 | // The Draw Triangle command draws a triangle outline between vertices |
CaptainR | 3:dcfbceb81fef | 311 | // x1,y1 , x2,y2 and x3,y3 using the specified color. |
CaptainR | 3:dcfbceb81fef | 312 | // The line may be tessellated with the “Line Pattern” command. |
CaptainR | 3:dcfbceb81fef | 313 | //************************************************************************** |
CaptainR | 3:dcfbceb81fef | 314 | void PICASO_4DGL :: drawTriangle(short x1, short y1, short x2, short y2, short x3, short y3, short color) { |
CaptainR | 3:dcfbceb81fef | 315 | |
CaptainR | 3:dcfbceb81fef | 316 | char command[16] = ""; |
CaptainR | 3:dcfbceb81fef | 317 | |
CaptainR | 3:dcfbceb81fef | 318 | command[0] = (DRAW_TRIANGLE >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 319 | command[1] = (DRAW_TRIANGLE >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 320 | command[2] = (x1 >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 321 | command[3] = (x1 >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 322 | command[4] = (y1 >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 323 | command[5] = (y1 >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 324 | command[6] = (x2 >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 325 | command[7] = (x2 >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 326 | command[8] = (y2 >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 327 | command[9] = (y2 >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 328 | command[10] = (x3 >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 329 | command[11] = (x3 >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 330 | command[12] = (y3 >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 331 | command[13] = (y3 >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 332 | command[14] = (color >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 333 | command[15] = (color >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 334 | |
CaptainR | 3:dcfbceb81fef | 335 | writeCOMMAND(command, 16); |
CaptainR | 3:dcfbceb81fef | 336 | } |
CaptainR | 3:dcfbceb81fef | 337 | |
CaptainR | 3:dcfbceb81fef | 338 | //************************************************************************** |
CaptainR | 3:dcfbceb81fef | 339 | // The Draw Filled Triangle command draws a solid triangle between vertices |
CaptainR | 3:dcfbceb81fef | 340 | // x1, y1, x2, y2 and x3, y3 using the specified color. |
CaptainR | 3:dcfbceb81fef | 341 | //************************************************************************** |
CaptainR | 3:dcfbceb81fef | 342 | void PICASO_4DGL :: drawFilledTriangle(short x1, short y1, short x2, short y2, short x3, short y3, short color) { |
CaptainR | 3:dcfbceb81fef | 343 | |
CaptainR | 3:dcfbceb81fef | 344 | char command[16] = ""; |
CaptainR | 3:dcfbceb81fef | 345 | |
CaptainR | 3:dcfbceb81fef | 346 | command[0] = (TRIANGLE_FILLED >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 347 | command[1] = (TRIANGLE_FILLED >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 348 | command[2] = (x1 >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 349 | command[3] = (x1 >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 350 | command[4] = (y1 >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 351 | command[5] = (y1 >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 352 | command[6] = (x2 >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 353 | command[7] = (x2 >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 354 | command[8] = (y2 >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 355 | command[9] = (y2 >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 356 | command[10] = (x3 >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 357 | command[11] = (x3 >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 358 | command[12] = (y3 >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 359 | command[13] = (y3 >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 360 | command[14] = (color >> (8*1)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 361 | command[15] = (color >> (8*0)) & 0xff; |
CaptainR | 3:dcfbceb81fef | 362 | |
CaptainR | 3:dcfbceb81fef | 363 | writeCOMMAND(command, 16); |
CaptainR | 3:dcfbceb81fef | 364 | } |
CaptainR | 0:a5ef6bc3c2e8 | 365 | |
CaptainR | 0:a5ef6bc3c2e8 | 366 |