1 /* ScummVM - Graphic Adventure Engine
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include "common/util.h"
29 void drawLine(int x0
, int y0
, int x1
, int y1
, int color
, void (*plotProc
)(int, int, int, void *), void *data
) {
30 // Bresenham's line algorithm, as described by Wikipedia
31 const bool steep
= ABS(y1
- y0
) > ABS(x1
- x0
);
38 const int delta_x
= ABS(x1
- x0
);
39 const int delta_y
= ABS(y1
- y0
);
40 const int delta_err
= delta_y
;
45 const int x_step
= (x0
< x1
) ? 1 : -1;
46 const int y_step
= (y0
< y1
) ? 1 : -1;
49 (*plotProc
)(y
, x
, color
, data
);
51 (*plotProc
)(x
, y
, color
, data
);
56 if (2 * err
> delta_x
) {
61 (*plotProc
)(y
, x
, color
, data
);
63 (*plotProc
)(x
, y
, color
, data
);
68 // FIXME: This is a limited version of thick line drawing
69 // it draws striped lines at some angles. Better algorithm could
72 // http://homepages.enterprise.net/murphy/thickline/index.html
74 // Feel free to replace it with better implementation
75 void drawThickLine(int x0
, int y0
, int x1
, int y1
, int thickness
, int color
, void (*plotProc
)(int, int, int, void *), void *data
) {
76 const bool steep
= ABS(y1
- y0
) > ABS(x1
- x0
);
85 float d
= (float)sqrt(dx
* dx
+ dy
* dy
);
90 int thickX
= (int)((float)thickness
* dy
/ d
/ 2);
91 int thickY
= (int)((float)thickness
* dx
/ d
/ 2);
93 const int delta_x
= ABS(x1
- x0
);
94 const int delta_y
= ABS(y1
- y0
);
95 const int delta_err
= delta_y
;
100 const int x_step
= (x0
< x1
) ? 1 : -1;
101 const int y_step
= (y0
< y1
) ? 1 : -1;
104 drawLine(y
- thickY
, x
+ thickX
, y
+ thickY
, x
- thickX
, color
, plotProc
, data
);
106 drawLine(x
- thickX
, y
+ thickY
, x
+ thickX
, y
- thickY
, color
, plotProc
, data
);
111 if (2 * err
> delta_x
) {
116 drawLine(y
- thickY
, x
+ thickX
, y
+ thickY
, x
- thickX
, color
, plotProc
, data
);
118 drawLine(x
- thickX
, y
+ thickY
, x
+ thickX
, y
- thickY
, color
, plotProc
, data
);
122 } // End of namespace Graphics