diff options
| -rw-r--r-- | engines/sci/gfx/gfx_driver.cpp | 9 | ||||
| -rw-r--r-- | engines/sci/gfx/gfx_support.cpp | 48 | ||||
| -rw-r--r-- | engines/sci/gfx/gfx_tools.h | 3 | 
3 files changed, 45 insertions, 15 deletions
diff --git a/engines/sci/gfx/gfx_driver.cpp b/engines/sci/gfx/gfx_driver.cpp index 1d8eb6f01f..0010983779 100644 --- a/engines/sci/gfx/gfx_driver.cpp +++ b/engines/sci/gfx/gfx_driver.cpp @@ -59,13 +59,6 @@ static void drawProc(int x, int y, int c, void *data) {  	memcpy(p + (y * drv->_screen->_width * drv->getMode()->scaleFactor + x), &col, 1);  } -static void drawProcPriority(int x, int y, int c, void *data) { -	GfxDriver *drv = (GfxDriver *)data; -	byte *p = drv->_screen->_priorityScreen; -	uint8 col = c; -	memcpy(p + (y * drv->_screen->_width + x), &col, 1); -} -  void GfxDriver::drawLine(Common::Point start, Common::Point end, gfx_color_t color,  						gfx_line_mode_t line_mode, gfx_line_style_t line_style) {  	uint32 scolor = color.visual.getParentIndex(); @@ -87,7 +80,7 @@ void GfxDriver::drawLine(Common::Point start, Common::Point end, gfx_color_t col  				Graphics::drawLine(nstart.x, nstart.y, nend.x, nend.y, scolor, drawProc, this);  				if (color.mask & GFX_MASK_PRIORITY) { -					Graphics::drawLine(nstart.x, nstart.y, nend.x, nend.y, color.priority, drawProcPriority, this); +					gfx_draw_line_buffer(_screen->_priorityScreen, 1, 1, nstart, nend, color.priority);  				}  			}  		} diff --git a/engines/sci/gfx/gfx_support.cpp b/engines/sci/gfx/gfx_support.cpp index 2529fde35b..22de7055c2 100644 --- a/engines/sci/gfx/gfx_support.cpp +++ b/engines/sci/gfx/gfx_support.cpp @@ -34,15 +34,49 @@  namespace Sci { -static void drawProc(int x, int y, int c, void *data) { -	gfx_pixmap_t *pxm = (gfx_pixmap_t *)data; -	byte *p = pxm->index_data; -	uint8 col = c; -	memcpy(p + (y * pxm->index_width + x), &col, 1); -} +#define LINEMACRO(startx, starty, deltalinear, deltanonlinear, linearvar, nonlinearvar, \ +                  linearend, nonlinearstart, linearmod, nonlinearmod) \ +	incrNE = ((deltalinear) > 0) ? (deltalinear) : -(deltalinear); \ +	incrNE <<= 1; \ +	deltanonlinear <<= 1; \ +	incrE = ((deltanonlinear) > 0) ? -(deltanonlinear) : (deltanonlinear);  \ +	d = nonlinearstart - 1;  \ +	while (linearvar != (linearend)) { \ +		memcpy(buffer + linewidth * (starty) + (startx), &color, pixelwidth); \ +		linearvar += linearmod; \ +		if ((d += incrE) < 0) { \ +			d += incrNE; \ +			nonlinearvar += nonlinearmod; \ +		}; \ +	}; \ +	memcpy(buffer + linewidth * (starty) + (startx), &color, pixelwidth); + + +// Sierra's Bresenham line drawing +// WARNING: Do not just blindly replace this with Graphics::drawLine(), as it seems to create issues with flood fill +void gfx_draw_line_buffer(byte *buffer, int linewidth, int pixelwidth, Common::Point start, Common::Point end, unsigned int color) { +	int incrE, incrNE, d; +	int dx = ABS(end.x - start.x); +	int dy = ABS(end.y - start.y); +#ifdef SCUMM_BIG_ENDIAN +	color = SWAP_BYTES_32(color); +#endif + +	if (dx > dy) { +		int sign1 = (end.x < start.x) ? -1 : 1; +		int sign2 = (end.y < start.y) ? -1 : 1; +		LINEMACRO(start.x, start.y, dx, dy, start.x, start.y, end.x, dx, sign1 * pixelwidth, sign2); +	} else { // dx <= dy +		int sign1 = (end.y < start.y) ? -1 : 1; +		int sign2 = (end.x < start.x) ? -1 : 1; +		LINEMACRO(start.x, start.y, dy, dx, start.y, start.x, end.y, dy, sign1, sign2 * pixelwidth); +	} + } +  +#undef LINEMACRO  void gfx_draw_line_pixmap_i(gfx_pixmap_t *pxm, Common::Point start, Common::Point end, int color) { -	Graphics::drawLine(start.x, start.y, end.x, end.y, color, drawProc, pxm); +	gfx_draw_line_buffer(pxm->index_data, pxm->index_width, 1, start, end, color);  }  void gfx_draw_box_buffer(byte *buffer, int linewidth, rect_t zone, int color) { diff --git a/engines/sci/gfx/gfx_tools.h b/engines/sci/gfx/gfx_tools.h index 6de6b81afc..99f338cf06 100644 --- a/engines/sci/gfx/gfx_tools.h +++ b/engines/sci/gfx/gfx_tools.h @@ -144,6 +144,9 @@ void gfx_free_pixmap(gfx_pixmap_t *pxm);  void gfx_draw_line_pixmap_i(gfx_pixmap_t *pxm, Common::Point start,  	Common::Point end, int color); +void gfx_draw_line_buffer(byte *buffer, int linewidth, int pixelwidth,  +	Common::Point start, Common::Point end, unsigned int color); +  /**   * Draws a filled rectangular area to a pixmap's index buffer   *  | 
