Ticket #8422: drawLine2.diff

File drawLine2.diff, 6.1 KB (added by eriktorbjorn, 19 years ago)

Patch against an April 23 CVS snapshot

  • graphics/module.mk

    Files ScummVM/gob/debug.o and ScummVM+hack/gob/debug.o differ
    Files ScummVM/gob/resource.o and ScummVM+hack/gob/resource.o differ
    diff -urN --exclude=CVS --exclude=Makefile ScummVM/graphics/module.mk ScummVM+hack/graphics/module.mk
    old new  
    77        graphics/fontman.o \
    88        graphics/newfont.o \
    99        graphics/newfont_big.o \
     10        graphics/primitives.o \
    1011        graphics/scummfont.o \
    1112        graphics/surface.o
    1213
  • graphics/primitives.cpp

    diff -urN --exclude=CVS --exclude=Makefile ScummVM/graphics/primitives.cpp ScummVM+hack/graphics/primitives.cpp
    old new  
     1/* ScummVM - Scumm Interpreter
     2 * Copyright (C) 2002-2005 The ScummVM project
     3 *
     4 * This program is free software; you can redistribute it and/or
     5 * modify it under the terms of the GNU General Public License
     6 * as published by the Free Software Foundation; either version 2
     7 * of the License, or (at your option) any later version.
     8 *
     9 * This program is distributed in the hope that it will be useful,
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12 * GNU General Public License for more details.
     13 *
     14 * You should have received a copy of the GNU General Public License
     15 * along with this program; if not, write to the Free Software
     16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
     17 *
     18 * $Header$
     19 */
     20
     21#include "common/stdafx.h"
     22#include "common/util.h"
     23
     24namespace Graphics {
     25
     26void drawLine(int x0, int y0, int x1, int y1, int color, void (*plotProc)(int, int, int, void *), void *data) {
     27        // Bresenham's line algorithm, as described by Wikipedia
     28        bool steep = ABS(y1 - y0) > ABS(x1 - x0);
     29
     30        if (steep) {
     31                SWAP(x0, y0);
     32                SWAP(x1, y1);
     33        }
     34
     35        int delta_x = ABS(x1 - x0);
     36        int delta_y = ABS(y1 - y0);
     37        int err = 0;
     38        int delta_err = delta_y;
     39        int x = x0;
     40        int y = y0;
     41
     42        int x_step = (x0 < x1) ? 1 : -1;
     43        int y_step = (y0 < y1) ? 1 : -1;
     44
     45        if (steep)
     46                (*plotProc)(y, x, color, data);
     47        else
     48                (*plotProc)(x, y, color, data);
     49
     50        while (x != x1) {
     51                x += x_step;
     52                err += delta_err;
     53                if (2 * err > delta_x) {
     54                        y += y_step;
     55                        err -= delta_x;
     56                }
     57                if (steep)
     58                        (*plotProc)(y, x, color, data);
     59                else
     60                        (*plotProc)(x, y, color, data);
     61        }
     62}
     63
     64}       // End of namespace Graphics
  • graphics/primitives.h

    diff -urN --exclude=CVS --exclude=Makefile ScummVM/graphics/primitives.h ScummVM+hack/graphics/primitives.h
    old new  
     1/* ScummVM - Scumm Interpreter
     2 * Copyright (C) 2002-2005 The ScummVM project
     3 *
     4 * This program is free software; you can redistribute it and/or
     5 * modify it under the terms of the GNU General Public License
     6 * as published by the Free Software Foundation; either version 2
     7 * of the License, or (at your option) any later version.
     8 *
     9 * This program is distributed in the hope that it will be useful,
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12 * GNU General Public License for more details.
     13 *
     14 * You should have received a copy of the GNU General Public License
     15 * along with this program; if not, write to the Free Software
     16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
     17 *
     18 * $Header$
     19 */
     20
     21#ifndef GRAPHICS_PRIMITIVES_H
     22#define GRAPHICS_PRIMITIVES_H
     23
     24namespace Graphics {
     25
     26extern void drawLine(int x0, int y0, int x1, int y1, int color, void (*plotProc)(int, int, int, void *), void *data);
     27
     28}       // End of namespace Graphics
     29
     30#endif
  • sword2/build_display.h

    diff -urN --exclude=CVS --exclude=Makefile ScummVM/sword2/build_display.h ScummVM+hack/sword2/build_display.h
    old new  
    417417
    418418        void plotPoint(int x, int y, uint8 colour);
    419419        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);
    421420
    422421#ifdef BACKEND_8BIT
    423422        void plotYUV(byte *lut, int width, int height, byte *const *dat);
  • sword2/driver/render.cpp

    diff -urN --exclude=CVS --exclude=Makefile ScummVM/sword2/driver/render.cpp ScummVM+hack/sword2/driver/render.cpp
    old new  
    2121#include "common/stdafx.h"
    2222#include "common/system.h"
    2323
     24#include "graphics/primitives.h"
     25
    2426#include "sword2/sword2.h"
    2527#include "sword2/defs.h"
    2628#include "sword2/build_display.h"
     
    225227 */
    226228
    227229void 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         }
     230        Graphics::drawLine(x0, y0, x1, y1, colour, &plot, this);
    270231}
    271232
    272233/**