Ticket #8422: drawLine.diff
File drawLine.diff, 3.8 KB (added by , 19 years ago) |
---|
-
common/util.cpp
diff -ur --exclude=CVS --exclude=Makefile ScummVM/common/util.cpp ScummVM+hack/common/util.cpp
old new 264 264 } 265 265 266 266 267 #pragma mark - 268 269 270 void drawLine(int x0, int y0, int x1, int y1, int color, void (*plotProc)(int, int, int, void *), void *data) { 271 // Bresenham's line algorithm, as described by Wikipedia 272 bool steep = ABS(y1 - y0) > ABS(x1 - x0); 273 274 if (steep) { 275 SWAP(x0, y0); 276 SWAP(x1, y1); 277 } 278 279 int delta_x = ABS(x1 - x0); 280 int delta_y = ABS(y1 - y0); 281 int err = 0; 282 int delta_err = delta_y; 283 int x = x0; 284 int y = y0; 285 286 int x_step = (x0 < x1) ? 1 : -1; 287 int y_step = (y0 < y1) ? 1 : -1; 288 289 if (steep) 290 (*plotProc)(y, x, color, data); 291 else 292 (*plotProc)(x, y, color, data); 293 294 while (x != x1) { 295 x += x_step; 296 err += delta_err; 297 if (2 * err > delta_x) { 298 y += y_step; 299 err -= delta_x; 300 } 301 if (steep) 302 (*plotProc)(y, x, color, data); 303 else 304 (*plotProc)(x, y, color, data); 305 } 306 } 307 267 308 } // End of namespace Common -
common/util.h
diff -ur --exclude=CVS --exclude=Makefile ScummVM/common/util.h ScummVM+hack/common/util.h
old new 185 185 extern const char *getRenderModeCode(RenderMode id); 186 186 extern const char *getRenderModeDescription(RenderMode id); 187 187 188 /** 189 * Draw a line from between two points. 190 * @param x0 Start X coordinate 191 * @param y0 Start Y coordinate 192 * @param x1 End X coordinate 193 * @param y1 End Y coordinate 194 * @param color Line color 195 * @param plotProc Callback function that plots each point 196 * @param data Data passed to the callback function 197 */ 198 extern void drawLine(int x0, int y0, int x1, int y1, int color, void (*plotProc)(int, int, int, void *), void *data); 199 188 200 } // End of namespace Common 189 201 190 202 -
sword2/build_display.h
diff -ur --exclude=CVS --exclude=Makefile ScummVM/sword2/build_display.h ScummVM+hack/sword2/build_display.h
old new 417 417 418 418 void plotPoint(int x, int y, uint8 colour); 419 419 void drawLine(int x0, int y0, int x1, int y1, uint8 colour); 420 void drawLine(int x0, int y0, int x1, int y1, int color, void (*plotProc)(int, int, int, void *), void *data);421 420 422 421 #ifdef BACKEND_8BIT 423 422 void plotYUV(byte *lut, int width, int height, byte *const *dat); -
sword2/driver/render.cpp
diff -ur --exclude=CVS --exclude=Makefile ScummVM/sword2/driver/render.cpp ScummVM+hack/sword2/driver/render.cpp
old new 225 225 */ 226 226 227 227 void Screen::drawLine(int x0, int y0, int x1, int y1, uint8 colour) { 228 drawLine(x0, y0, x1, y1, colour, &plot, this); 229 } 230 231 // TODO: Main line-drawing function. Move this somewhere where other engines 232 // can benefit from it. 233 234 void Screen::drawLine(int x0, int y0, int x1, int y1, int color, void (*plotProc)(int, int, int, void *), void *data) { 235 // Bresenham's line algorithm, as described by Wikipedia 236 bool steep = ABS(y1 - y0) > ABS(x1 - x0); 237 238 if (steep) { 239 SWAP(x0, y0); 240 SWAP(x1, y1); 241 } 242 243 int delta_x = ABS(x1 - x0); 244 int delta_y = ABS(y1 - y0); 245 int err = 0; 246 int delta_err = delta_y; 247 int x = x0; 248 int y = y0; 249 250 int x_step = (x0 < x1) ? 1 : -1; 251 int y_step = (y0 < y1) ? 1 : -1; 252 253 if (steep) 254 (*plotProc)(y, x, color, data); 255 else 256 (*plotProc)(x, y, color, data); 257 258 while (x != x1) { 259 x += x_step; 260 err += delta_err; 261 if (2 * err > delta_x) { 262 y += y_step; 263 err -= delta_x; 264 } 265 if (steep) 266 (*plotProc)(y, x, color, data); 267 else 268 (*plotProc)(x, y, color, data); 269 } 228 Common::drawLine(x0, y0, x1, y1, colour, &plot, this); 270 229 } 271 230 272 231 /**