@@ -204,6 +204,17 @@ void graphicsToDeviceCoordinates(const JsGraphics *gfx, int *x, int *y) {
204
204
if (gfx -> data .flags & JSGRAPHICSFLAGS_INVERT_Y ) * y = (int )(gfx -> data .height - (* y + 1 ));
205
205
}
206
206
207
+ // If graphics is flipped or rotated then the coordinates need modifying
208
+ void graphicsToDeviceCoordinates16x (const JsGraphics * gfx , int * x , int * y ) {
209
+ if (gfx -> data .flags & JSGRAPHICSFLAGS_SWAP_XY ) {
210
+ int t = * x ;
211
+ * x = * y ;
212
+ * y = t ;
213
+ }
214
+ if (gfx -> data .flags & JSGRAPHICSFLAGS_INVERT_X ) * x = (int )((gfx -> data .width - 1 )* 16 - * x );
215
+ if (gfx -> data .flags & JSGRAPHICSFLAGS_INVERT_Y ) * y = (int )((gfx -> data .height - 1 )* 16 - * y );
216
+ }
217
+
207
218
unsigned short graphicsGetWidth (const JsGraphics * gfx ) {
208
219
return (gfx -> data .flags & JSGRAPHICSFLAGS_SWAP_XY ) ? gfx -> data .height : gfx -> data .width ;
209
220
}
@@ -409,7 +420,7 @@ void graphicsDrawLine(JsGraphics *gfx, int x1, int y1, int x2, int y2) {
409
420
}
410
421
411
422
412
-
423
+ // Fill poly - each member of vertices is 1/16th pixel
413
424
void graphicsFillPoly (JsGraphics * gfx , int points , short * vertices ) {
414
425
typedef struct {
415
426
short x ,y ;
@@ -423,11 +434,11 @@ void graphicsFillPoly(JsGraphics *gfx, int points, short *vertices) {
423
434
// convert into device coordinates...
424
435
int vx = v [i ].x ;
425
436
int vy = v [i ].y ;
426
- graphicsToDeviceCoordinates (gfx , & vx , & vy );
437
+ graphicsToDeviceCoordinates16x (gfx , & vx , & vy );
427
438
v [i ].x = (short )vx ;
428
439
v [i ].y = (short )vy ;
429
440
// work out min and max
430
- short y = v [i ].y ;
441
+ short y = v [i ].y >> 4 ;
431
442
if (y < miny ) miny = y ;
432
443
if (y > maxy ) maxy = y ;
433
444
}
@@ -442,16 +453,15 @@ void graphicsFillPoly(JsGraphics *gfx, int points, short *vertices) {
442
453
const int MAX_CROSSES = 64 ;
443
454
444
455
// for each scanline
445
- for (y = miny ;y <=maxy ;y ++ ) {
456
+ for (y = miny << 4 ;y <=maxy << 4 ;y += 16 ) {
446
457
short cross [MAX_CROSSES ];
447
458
bool slopes [MAX_CROSSES ];
448
459
int crosscnt = 0 ;
449
460
// work out all the times lines cross the scanline
450
461
j = points - 1 ;
451
462
for (i = 0 ;i < points ;i ++ ) {
452
- if ((y == miny && (v [i ].y == y || v [j ].y == y )) || // special-case top line
453
- (v [i ].y < y && v [j ].y >=y ) ||
454
- (v [j ].y < y && v [i ].y >=y )) {
463
+ if ((v [i ].y <=y && v [j ].y >=y ) ||
464
+ (v [j ].y <=y && v [i ].y >=y )) {
455
465
if (crosscnt < MAX_CROSSES ) {
456
466
int l = v [j ].y - v [i ].y ;
457
467
if (l ) { // don't do horiz lines - rely on the ends of the lines that join onto them
@@ -482,7 +492,8 @@ void graphicsFillPoly(JsGraphics *gfx, int points, short *vertices) {
482
492
for (i = 0 ;i < crosscnt ;i ++ ) {
483
493
if (s == 0 ) x = cross [i ];
484
494
if (slopes [i ]) s ++ ; else s -- ;
485
- if (!s || i == crosscnt - 1 ) graphicsFillRectDevice (gfx ,x ,y ,cross [i ],y ,gfx -> data .fgColor );
495
+ if (!s || i == crosscnt - 1 )
496
+ graphicsFillRectDevice (gfx ,x >>4 ,y >>4 ,cross [i ]>>4 ,y >>4 ,gfx -> data .fgColor );
486
497
if (jspIsInterrupted ()) break ;
487
498
}
488
499
}
0 commit comments