2017-08-30 18:31:27 -04:00
|
|
|
#pragma once
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "DrawCommand.h"
|
|
|
|
|
|
|
|
class DrawLineCommand : public DrawCommand
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
int _x, _y, _x2, _y2, _color;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void InternalDraw()
|
|
|
|
{
|
2017-10-03 19:39:02 -04:00
|
|
|
int x = _x;
|
|
|
|
int y = _y;
|
|
|
|
int dx = abs(_x2 - x), sx = x < _x2 ? 1 : -1;
|
|
|
|
int dy = abs(_y2 - y), sy = y < _y2 ? 1 : -1;
|
|
|
|
int err = (dx > dy ? dx : -dy) / 2, e2;
|
|
|
|
|
|
|
|
while(true) {
|
|
|
|
DrawPixel(x, y, _color);
|
|
|
|
if(x == _x2 && y == _y2) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
e2 = err;
|
|
|
|
if(e2 > -dx) {
|
|
|
|
err -= dy; x += sx;
|
2017-08-30 18:31:27 -04:00
|
|
|
}
|
2017-10-03 19:39:02 -04:00
|
|
|
if(e2 < dy) {
|
|
|
|
err += dx; y += sy;
|
2017-08-30 18:31:27 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
DrawLineCommand(int x, int y, int x2, int y2, int color, int frameCount) :
|
2017-08-30 19:36:20 -04:00
|
|
|
DrawCommand(frameCount), _x(x), _y(y), _x2(x2), _y2(y2), _color(color)
|
2017-08-30 18:31:27 -04:00
|
|
|
{
|
2017-09-02 10:36:57 -04:00
|
|
|
//Invert alpha byte - 0 = opaque, 255 = transparent (this way, no need to specifiy alpha channel all the time)
|
|
|
|
_color = (~color & 0xFF000000) | (color & 0xFFFFFF);
|
2017-08-30 18:31:27 -04:00
|
|
|
}
|
|
|
|
};
|