// Copyright 2026, University of Freiburg,
// Chair of Algorithms and Data Structures.
// Author: Johannes Kalmbach <kalmbach@cs.uni-freiburg.de>.
// Author: Christoph Ullinger <ullingec@cs.uni-freiburg.de>.
#include "./TerminalManager.h"
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <ncurses.h>
// ____________________________________________________________________________
bool UserInput::isEscape() { return keycode_ == 27; }
bool UserInput::isKeyLeft() { return keycode_ == KEY_LEFT; }
bool UserInput::isKeyRight() { return keycode_ == KEY_RIGHT; }
bool UserInput::isKeyUp() { return keycode_ == KEY_UP; }
bool UserInput::isKeyDown() { return keycode_ == KEY_DOWN; }
bool UserInput::isMouseclick() { return mouseRow_ != -1; }
// ____________________________________________________________________________
void TerminalManager::drawLine(int row1, int col1, int row2, int col2,
int color) {
int dominantCol = std::abs(col2 - col1);
int dominantRow = std::abs(row2 - row1);
int stepCol = (col1 < col2) ? 1 : -1;
int stepRow = (row1 < row2) ? 1 : -1;
int error = dominantCol - dominantRow;
while (true) {
drawPixel(row1, col1, color);
if (col1 == col2 && row1 == row2) {
break;
}
int error2 = 2 * error;
if (error2 > -dominantRow) {
error -= dominantRow;
col1 += stepCol;
}
if (error2 < dominantCol) {
error += dominantCol;
row1 += stepRow;
}
}
}