26 #include "simplegfx.h"
32 int ComputeOutCode(
int x,
int y,
int w,
int h) {
35 if (
x < 0) code |= 0b0001;
36 else if (
x >= w) code |= 0b0010;
37 if (y < 0) code |= 0b1000;
38 else if (y >= h) code |= 0b0100;
43 void drawLine(
screen_t *dev,
int x0,
int y0,
int x1,
int y1,
int c) {
49 x0 = dev->
width - x0 - 1;
50 x1 = dev->
width - x1 - 1;
56 x0 = dev->
width - x0 - 1;
58 x1 = dev->
width - x1 - 1;
75 int outcode0 = ComputeOutCode(x0, y0, dev->
width, dev->
height);
76 int outcode1 = ComputeOutCode(x1, y1, dev->
width, dev->
height);
80 if (!(outcode0 | outcode1)) {
83 }
else if (outcode0 & outcode1) {
91 int outcodeOut = outcode0 ? outcode0 : outcode1;
95 if (outcodeOut & 0b1000) {
96 x = x0 + (x1 - x0) * (0 - y0) / (y1 - y0);
98 }
else if (outcodeOut & 0b0100) {
99 x = x0 + (x1 - x0) * (dev->
height - y0 - 1) / (y1 - y0);
101 }
else if (outcodeOut & 0b0010) {
102 y = y0 + (y1 - y0) * (dev->
width - x0 - 1) / (x1 - x0);
104 }
else if (outcodeOut & 0b0001) {
105 y = y0 + (y1 - y0) * (0 - x0) / (x1 - x0);
111 if (outcodeOut == outcode0) {
114 outcode0 = ComputeOutCode(x0, y0, dev->
width, dev->
height);
118 outcode1 = ComputeOutCode(x1, y1, dev->
width, dev->
height);
125 signed char ix = (dx > 0) - (dx < 0);
129 signed char iy = (dy > 0) - (dy < 0);
135 int err = dy - (dx >> 1);
137 if( (err >= 0) && (err || (ix > 0)) ) {
147 int err = dx - (dy >> 1);
149 if( (err >= 0) && (err || (iy > 0)) ) {
164 void drawFastHLine(
screen_t *dev,
int x,
int y,
int w,
int color) {
165 if((y >= 0) && (y < getDisplayHeight(dev))) {
170 if((
x + w) > getDisplayWidth(dev)) {
171 w = (getDisplayWidth(dev) -
x);
199 void drawFastVLine(
screen_t *dev,
int x,
int y,
int h,
int color) {
201 if((
x >= 0) && (
x < getDisplayWidth(dev))) {
208 if((y + h) > getDisplayHeight(dev)) {
209 h = (getDisplayHeight(dev) - y);