| 1 | #cxx . . $ `<file>/src/draw.cpp`/include <SDL.h> |
| 2 | #include <SDL/SDL.h> |
| 3 | #include <SDL/SDL_image.h> |
| 4 | #include "SDL/SDL_image.h" |
| 5 | #include <SDL/SDL_thread.h> |
| 6 | #include <math.h> |
| 7 | #include "draw.h"cxx . . $ `<file>/src/draw.h`/ |
| 8 | |
| 9 | |
| 10 | void DrawPixelcxx . . $ DrawPixel(6f3c846de5417090).(SDL_Surface *screen, int x, int y, Uint32cxx . . $ Uint32# color){ |
| 11 | //this only works for 16bpp screens |
| 12 | //are we outside the screen????? |
| 13 | //If we are bail out now before it's too late! |
| 14 | |
| 15 | if (x > 1023 || x < 0 || y > 759 || y < 0) { |
| 16 | return; |
| 17 | } |
| 18 | |
| 19 | //place the pixel on the screen |
| 20 | Uint16cxx . . $ Uint16# *pixel_location; |
| 21 | pixel_location = (Uint16cxx . . $ Uint16# *)screen->pixels + y*screen->pitch/2 + x; |
| 22 | *pixel_location = color; |
| 23 | } |
| 24 | |
| 25 | void DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(SDL_Surface *screen, int X1, int Y1, int X2, int Y2, Uint32cxx . . $ Uint32# Color){ |
| 26 | |
| 27 | //don't even ask me about this stuff All I know is it works |
| 28 | //and thats ALL I care about... |
| 29 | |
| 30 | int dx,dy,sdx,sdy,py,px,x,y; |
| 31 | dx = X2 - X1; |
| 32 | dy = Y2 - Y1; |
| 33 | if (dx < 0) sdx = -1; |
| 34 | else sdx = 1; |
| 35 | if (dy < 0) sdy = -1; |
| 36 | else sdy = 1; |
| 37 | dx = sdx * dx + 1; |
| 38 | dy = sdy * dy + 1; |
| 39 | x = 0; |
| 40 | y = 0; |
| 41 | px = X1; |
| 42 | py = Y1; |
| 43 | if (dx >= dy){ |
| 44 | for (int x = 0; x < dx; x++){ |
| 45 | DrawPixelcxx . . $ DrawPixel(6f3c846de5417090).(screen, px, py, Color); |
| 46 | y = y + dy; |
| 47 | if (y >= dx){ |
| 48 | y = y - dx; |
| 49 | py = py + sdy; |
| 50 | } |
| 51 | px = px + sdx; |
| 52 | } |
| 53 | }else{ |
| 54 | for (int y = 0; y < dy; y++){ |
| 55 | DrawPixelcxx . . $ DrawPixel(6f3c846de5417090).(screen, px, py, Color); |
| 56 | x = x + dx; |
| 57 | if (x >= dy){ |
| 58 | x = x - dy; |
| 59 | px = px + sdx; |
| 60 | } |
| 61 | py = py + sdy; |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | |
| 67 | void DrawArccxx . . $ DrawArc(ff1e8d23fb3fb7e5).(SDL_Surface *screen, int X1, int Y1, int Radius, int Theta1, int Theta2, Uint32cxx . . $ Uint32# Color){ |
| 68 | |
| 69 | //Draw an arc at (X1,Y1) of a given radius from theta1 to theta2 using specified Color. |
| 70 | int x, y, xc, yc, radius; |
| 71 | int theta, theta1, theta2; |
| 72 | xc = X1; |
| 73 | yc = Y1; |
| 74 | radius = Radius; |
| 75 | theta1 = Theta1; |
| 76 | theta2 = Theta2; |
| 77 | |
| 78 | for(theta=theta1;theta<=theta2;theta+=5) { |
| 79 | x = xc + int(radius*coscxx . . $ cos(fee4f1d22bc8e617).(theta*3.14/180.0)); |
| 80 | y = yc - int(radius*sincxx . . $ sin(fee4f1d22bc8e617).(theta*3.14/180.0)); |
| 81 | DrawPixelcxx . . $ DrawPixel(6f3c846de5417090).(screen, x, y, Color); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | void DrawCirclecxx . . $ DrawCircle(23d17e51af626352).(SDL_Surface *screen, int X1, int Y1, int Radius, Uint32cxx . . $ Uint32# Color){ |
| 86 | |
| 87 | //Draw a circle at (X1,Y1) of a given radius using specified Color. |
| 88 | /* |
| 89 | int xc, yc, radius; |
| 90 | xc = X1; |
| 91 | yc = Y1; |
| 92 | radius = Radius; |
| 93 | */ |
| 94 | DrawArccxx . . $ DrawArc(ff1e8d23fb3fb7e5).(screen, X1, Y1, Radius, 0, 360, Color); |
| 95 | } |
| 96 | |
| 97 | |
| 98 | void FillCirclecxx . . $ FillCircle(23d17e51af626352).(SDL_Surface *screen, int X1, int Y1, int Radius, Uint32cxx . . $ Uint32# Color) |
| 99 | { |
| 100 | int my_radius; |
| 101 | my_radius = Radius; |
| 102 | while (my_radius > 1) |
| 103 | { |
| 104 | DrawCirclecxx . . $ DrawCircle(23d17e51af626352).(screen, X1, Y1, my_radius, Color); |
| 105 | my_radius--; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | void DrawDiamondcxx . . $ DrawDiamond(9b0c43a30c43b495).(SDL_Surface *screen, int X1, int Y1, int Size, char Direction, Uint32cxx . . $ Uint32# Color){ |
| 110 | |
| 111 | //Draw a diamond at (X1,Y1) of Size using specified Color. |
| 112 | // Direction: T = Top, B = Bottom, F = Full |
| 113 | int xc, yc; |
| 114 | int size; |
| 115 | xc = X1; |
| 116 | yc = Y1; |
| 117 | size = Size; |
| 118 | |
| 119 | switch(Direction){ |
| 120 | |
| 121 | case 'B': |
| 122 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc-size, yc, xc, yc+size, Color); //bottomleft |
| 123 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc+size, yc, xc, yc+size, Color); //bottomright |
| 124 | break; |
| 125 | |
| 126 | case 'T': |
| 127 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc, yc-size, xc-size, yc, Color); //topleft |
| 128 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc, yc-size, xc+size, yc, Color); //topright |
| 129 | break; |
| 130 | |
| 131 | default: |
| 132 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc-size, yc, xc, yc+size, Color); //bottomleft |
| 133 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc+size, yc, xc, yc+size, Color); //bottomright |
| 134 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc, yc-size, xc-size, yc, Color); //topleft |
| 135 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc, yc-size, xc+size, yc, Color); //topright |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | void DrawBoxcxx . . $ DrawBox(9b0c43a30c43b495).(SDL_Surface *screen, int X1, int Y1, int Size, char Direction, Uint32cxx . . $ Uint32# Color){ |
| 140 | |
| 141 | //Draw a Box at (X1,Y1) of Size using specified Color. |
| 142 | // Direction: T = Top, B = Bottom, F = Full |
| 143 | int xc, yc; |
| 144 | int size; |
| 145 | char direction; |
| 146 | xc = X1; |
| 147 | yc = Y1; |
| 148 | size = Size; |
| 149 | direction = Direction; |
| 150 | |
| 151 | switch(direction){ |
| 152 | |
| 153 | case 'T': |
| 154 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc-size, yc-size, xc-size, yc, Color); |
| 155 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc-size, yc-size, xc+size, yc-size, Color); |
| 156 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc+size, yc-size, xc+size, yc, Color); |
| 157 | break; |
| 158 | |
| 159 | case 'B': |
| 160 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc-size, yc, xc-size, yc+size, Color); |
| 161 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc-size, yc+size, xc+size, yc+size, Color); |
| 162 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc+size, yc, xc+size, yc+size, Color); |
| 163 | break; |
| 164 | |
| 165 | default: |
| 166 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc-size, yc-size, xc+size, yc-size, Color); |
| 167 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc+size, yc-size, xc+size, yc+size, Color); |
| 168 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc-size, yc-size, xc-size, yc+size, Color); |
| 169 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc-size, yc+size, xc+size, yc+size, Color); |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | |
| 174 | void DrawRectanglecxx . . $ DrawRectangle(1738f3ac1892ed0c).(SDL_Surface *screen, int x1, int y1, int x2, int y2, Uint32cxx . . $ Uint32# color) |
| 175 | { |
| 176 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, x1, y1, x1, y2, color); |
| 177 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, x1, y1, x2, y1, color); |
| 178 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, x1, y2, x2, y2, color); |
| 179 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, x2, y1, x2, y2, color); |
| 180 | } |
| 181 | |
| 182 | |
| 183 | void FillRectanglecxx . . $ FillRectangle(1738f3ac1892ed0c).(SDL_Surface *screen, int x1, int y1, int x2, int y2, Uint32cxx . . $ Uint32# color) |
| 184 | { |
| 185 | int x, y; |
| 186 | |
| 187 | for (y = y1; y <= y2; y++) |
| 188 | { |
| 189 | for (x = x1; x <= x2; x++) |
| 190 | { |
| 191 | DrawPixelcxx . . $ DrawPixel(6f3c846de5417090).(screen, x, y, color); |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | |
| 197 | |
| 198 | void DrawCrosscxx . . $ DrawCross(9b0c43a30c43b495).(SDL_Surface *screen, int X1, int Y1, int Size, char Direction, Uint32cxx . . $ Uint32# Color){ |
| 199 | |
| 200 | //Draw a Cross at (X1,Y1) of Size using specified Color. |
| 201 | // Direction: T = Top, B = Bottom, F = Full |
| 202 | int xc, yc; |
| 203 | int size; |
| 204 | char direction; |
| 205 | xc = X1; |
| 206 | yc = Y1; |
| 207 | size = Size; |
| 208 | direction = Direction; |
| 209 | |
| 210 | switch(direction){ |
| 211 | |
| 212 | case 'T': |
| 213 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc-size, yc-size/2, xc-size, yc, Color); |
| 214 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc+size, yc-size/2, xc+size, yc, Color); |
| 215 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc-size/2, yc-size, xc+size/2, yc-size, Color); |
| 216 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc-size/2, yc-size, xc-size/2, yc-size/2, Color); |
| 217 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc+size/2, yc-size, xc+size/2, yc-size/2, Color); |
| 218 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc+size/2, yc-size/2, xc+size, yc-size/2, Color); |
| 219 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc-size, yc-size/2, xc-size/2, yc-size/2, Color); |
| 220 | break; |
| 221 | |
| 222 | case 'B': |
| 223 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc-size, yc, xc-size, yc+size/2, Color); |
| 224 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc+size, yc, xc+size, yc+size/2, Color); |
| 225 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc-size/2, yc+size, xc+size/2, yc+size, Color); |
| 226 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc-size/2, yc+size/2, xc-size/2, yc+size, Color); |
| 227 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc+size/2, yc+size/2, xc+size/2, yc+size, Color); |
| 228 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc-size, yc+size/2, xc-size/2, yc+size/2, Color); |
| 229 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc+size/2, yc+size/2, xc+size, yc+size/2, Color); |
| 230 | break; |
| 231 | |
| 232 | default: |
| 233 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc-size, yc-size/2, xc-size, yc+size/2, Color); |
| 234 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc+size, yc-size/2, xc+size, yc+size/2, Color); |
| 235 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc-size/2, yc-size, xc+size/2, yc-size, Color); |
| 236 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc-size/2, yc+size, xc+size/2, yc+size, Color); |
| 237 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc-size/2, yc-size, xc-size/2, yc-size/2, Color); |
| 238 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc-size/2, yc+size/2, xc-size/2, yc+size, Color); |
| 239 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc+size/2, yc-size, xc+size/2, yc-size/2, Color); |
| 240 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc+size/2, yc+size/2, xc+size/2, yc+size, Color); |
| 241 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc-size, yc+size/2, xc-size/2, yc+size/2, Color); |
| 242 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc+size/2, yc-size/2, xc+size, yc-size/2, Color); |
| 243 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc-size, yc-size/2, xc-size/2, yc-size/2, Color); |
| 244 | DrawLinecxx . . $ DrawLine(1738f3ac1892ed0c).(screen, xc+size/2, yc+size/2, xc+size, yc+size/2, Color); |
| 245 | } |
| 246 | } |