added lots of line drawing functions to virtual terminal
This commit is contained in:
parent
ab90320e9c
commit
b90784f744
|
@ -42,6 +42,7 @@ public class Test {
|
|||
term.setChar(new Vec2i(9, 9), 0xC9, Color.GREEN);
|
||||
term.setChar(new Vec2i(10, 10), 0xC9, Color.GREEN);
|
||||
term.drawHalfString(new Vec2i(11, 11), "AHello world. This is a test.", Color.GREEN);
|
||||
term.drawBoxDouble(new Recti(11, 12, 4, 4), Color.GREEN, Color.DARK_GRAY, true);
|
||||
|
||||
while(!window.shouldClose()) {
|
||||
window.tick();
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package com.danitheskunk.skunkworks.gfx.vt;
|
||||
|
||||
import com.danitheskunk.skunkworks.Recti;
|
||||
import com.danitheskunk.skunkworks.Vec2i;
|
||||
import com.danitheskunk.skunkworks.gfx.Color;
|
||||
import com.danitheskunk.skunkworks.gfx.font.Cp437;
|
||||
import com.danitheskunk.skunkworks.gfx.font.IFont;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
@ -110,7 +112,7 @@ public class Terminal {
|
|||
|
||||
public void setBackgroundColor(Vec2i pos, Color color) {
|
||||
var cell = cells.get(vecToPos(pos));
|
||||
cell.fgColor = color;
|
||||
cell.bgColor = color;
|
||||
}
|
||||
|
||||
public int getChar(Vec2i pos) {
|
||||
|
@ -221,6 +223,205 @@ public class Terminal {
|
|||
}
|
||||
}
|
||||
|
||||
public void drawHorizontalSingleLine(Vec2i pos, int len) {
|
||||
var x = pos.getX();
|
||||
var y = pos.getY();
|
||||
for(int i = 0; i < len; ++i) {
|
||||
setChar(new Vec2i(x + i, y), Cp437.BOX_SINGLE_HORIZONTAL);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawHorizontalSingleLine(Vec2i pos, int len, Color foregroundColor) {
|
||||
var x = pos.getX();
|
||||
var y = pos.getY();
|
||||
for(int i = 0; i < len; ++i) {
|
||||
setChar(new Vec2i(x + i, y), Cp437.BOX_SINGLE_HORIZONTAL, foregroundColor);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawHorizontalSingleLine(Vec2i pos, int len, Color foregroundColor, Color backgroundColor) {
|
||||
var x = pos.getX();
|
||||
var y = pos.getY();
|
||||
for(int i = 0; i < len; ++i) {
|
||||
setChar(new Vec2i(x + i, y), Cp437.BOX_SINGLE_HORIZONTAL, foregroundColor, backgroundColor);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawHorizontalDoubleLine(Vec2i pos, int len) {
|
||||
var x = pos.getX();
|
||||
var y = pos.getY();
|
||||
for(int i = 0; i < len; ++i) {
|
||||
setChar(new Vec2i(x + i, y), Cp437.BOX_DOUBLE_HORIZONTAL);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawHorizontalDoubleLine(Vec2i pos, int len, Color foregroundColor) {
|
||||
var x = pos.getX();
|
||||
var y = pos.getY();
|
||||
for(int i = 0; i < len; ++i) {
|
||||
setChar(new Vec2i(x + i, y), Cp437.BOX_DOUBLE_HORIZONTAL, foregroundColor);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawHorizontalDoubleLine(Vec2i pos, int len, Color foregroundColor, Color backgroundColor) {
|
||||
var x = pos.getX();
|
||||
var y = pos.getY();
|
||||
for(int i = 0; i < len; ++i) {
|
||||
setChar(new Vec2i(x + i, y), Cp437.BOX_DOUBLE_HORIZONTAL, foregroundColor, backgroundColor);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawVerticalSingleLine(Vec2i pos, int len) {
|
||||
var x = pos.getX();
|
||||
var y = pos.getY();
|
||||
for(int i = 0; i < len; ++i) {
|
||||
setChar(new Vec2i(x, y + i), Cp437.BOX_SINGLE_VERTICAL);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawVerticalSingleLine(Vec2i pos, int len, Color foregroundColor) {
|
||||
var x = pos.getX();
|
||||
var y = pos.getY();
|
||||
for(int i = 0; i < len; ++i) {
|
||||
setChar(new Vec2i(x, y + i), Cp437.BOX_SINGLE_VERTICAL, foregroundColor);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawVerticalSingleLine(Vec2i pos, int len, Color foregroundColor, Color backgroundColor) {
|
||||
var x = pos.getX();
|
||||
var y = pos.getY();
|
||||
for(int i = 0; i < len; ++i) {
|
||||
setChar(new Vec2i(x, y + i), Cp437.BOX_SINGLE_VERTICAL, foregroundColor, backgroundColor);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawVerticalDoubleLine(Vec2i pos, int len) {
|
||||
var x = pos.getX();
|
||||
var y = pos.getY();
|
||||
for(int i = 0; i < len; ++i) {
|
||||
setChar(new Vec2i(x, y + i), Cp437.BOX_DOUBLE_VERTICAL);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawVerticalDoubleLine(Vec2i pos, int len, Color foregroundColor) {
|
||||
var x = pos.getX();
|
||||
var y = pos.getY();
|
||||
for(int i = 0; i < len; ++i) {
|
||||
setChar(new Vec2i(x, y + i), Cp437.BOX_DOUBLE_VERTICAL, foregroundColor);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawVerticalDoubleLine(Vec2i pos, int len, Color foregroundColor, Color backgroundColor) {
|
||||
var x = pos.getX();
|
||||
var y = pos.getY();
|
||||
for(int i = 0; i < len; ++i) {
|
||||
setChar(new Vec2i(x, y + i), Cp437.BOX_DOUBLE_VERTICAL, foregroundColor, backgroundColor);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawBoxSingle(Recti rect) {
|
||||
var pos = rect.getPos();
|
||||
setChar(pos, Cp437.BOX_SINGLE_RIGHT_BOTTOM);
|
||||
setChar(Vec2i.add(pos, new Vec2i(rect.getWidth() - 1, 0)), Cp437.BOX_SINGLE_BOTTOM_LEFT);
|
||||
setChar(Vec2i.add(pos, new Vec2i(0, rect.getHeight() - 1)), Cp437.BOX_SINGLE_TOP_RIGHT);
|
||||
setChar(Vec2i.add(pos, new Vec2i(rect.getWidth() - 1, rect.getHeight() - 1)), Cp437.BOX_SINGLE_TOP_LEFT);
|
||||
drawHorizontalSingleLine(Vec2i.add(pos, new Vec2i(1, 0)), rect.getWidth() - 2);
|
||||
drawHorizontalSingleLine(Vec2i.add(pos, new Vec2i(1, rect.getHeight() - 1)), rect.getWidth() - 2);
|
||||
drawVerticalSingleLine(Vec2i.add(pos, new Vec2i(0, 1)), rect.getHeight() - 2);
|
||||
drawVerticalSingleLine(Vec2i.add(pos, new Vec2i(rect.getWidth() - 1, 1)), rect.getHeight() - 2);
|
||||
}
|
||||
|
||||
public void drawBoxSingle(Recti rect, Color foregroundColor) {
|
||||
var pos = rect.getPos();
|
||||
setChar(pos, Cp437.BOX_SINGLE_RIGHT_BOTTOM, foregroundColor);
|
||||
setChar(Vec2i.add(pos, new Vec2i(rect.getWidth() - 1, 0)), Cp437.BOX_SINGLE_BOTTOM_LEFT, foregroundColor);
|
||||
setChar(Vec2i.add(pos, new Vec2i(0, rect.getHeight() - 1)), Cp437.BOX_SINGLE_TOP_RIGHT, foregroundColor);
|
||||
setChar(Vec2i.add(pos, new Vec2i(rect.getWidth() - 1, rect.getHeight() - 1)), Cp437.BOX_SINGLE_TOP_LEFT, foregroundColor);
|
||||
drawHorizontalSingleLine(Vec2i.add(pos, new Vec2i(1, 0)), rect.getWidth() - 2, foregroundColor);
|
||||
drawHorizontalSingleLine(Vec2i.add(pos, new Vec2i(1, rect.getHeight() - 1)), rect.getWidth() - 2, foregroundColor);
|
||||
drawVerticalSingleLine(Vec2i.add(pos, new Vec2i(0, 1)), rect.getHeight() - 2, foregroundColor);
|
||||
drawVerticalSingleLine(Vec2i.add(pos, new Vec2i(rect.getWidth() - 1, 1)), rect.getHeight() - 2, foregroundColor);
|
||||
}
|
||||
|
||||
public void drawBoxSingle(Recti rect, Color foregroundColor, Color backgroundColor) {
|
||||
drawBoxSingle(rect, foregroundColor, backgroundColor, true);
|
||||
}
|
||||
|
||||
public void drawBoxSingle(Recti rect, Color foregroundColor, Color backgroundColor, boolean fill) {
|
||||
var pos = rect.getPos();
|
||||
setChar(pos, Cp437.BOX_SINGLE_RIGHT_BOTTOM, foregroundColor, backgroundColor);
|
||||
setChar(Vec2i.add(pos, new Vec2i(rect.getWidth() - 1, 0)), Cp437.BOX_SINGLE_BOTTOM_LEFT, foregroundColor, backgroundColor);
|
||||
setChar(Vec2i.add(pos, new Vec2i(0, rect.getHeight() - 1)), Cp437.BOX_SINGLE_TOP_RIGHT, foregroundColor, backgroundColor);
|
||||
setChar(Vec2i.add(pos, new Vec2i(rect.getWidth() - 1, rect.getHeight() - 1)), Cp437.BOX_SINGLE_TOP_LEFT, foregroundColor, backgroundColor);
|
||||
drawHorizontalSingleLine(Vec2i.add(pos, new Vec2i(1, 0)), rect.getWidth() - 2, foregroundColor, backgroundColor);
|
||||
drawHorizontalSingleLine(Vec2i.add(pos, new Vec2i(1, rect.getHeight() - 1)), rect.getWidth() - 2, foregroundColor, backgroundColor);
|
||||
drawVerticalSingleLine(Vec2i.add(pos, new Vec2i(0, 1)), rect.getHeight() - 2, foregroundColor, backgroundColor);
|
||||
drawVerticalSingleLine(Vec2i.add(pos, new Vec2i(rect.getWidth() - 1, 1)), rect.getHeight() - 2, foregroundColor, backgroundColor);
|
||||
|
||||
if(fill) {
|
||||
//todo: use draw rect
|
||||
var x = rect.getX() + 1;
|
||||
var y = rect.getY() + 1;
|
||||
for(int iy = 0; iy < rect.getWidth() - 2; ++iy) {
|
||||
for(int ix = 0; ix < rect.getWidth() - 2; ++ix) {
|
||||
setBackgroundColor(new Vec2i(x + ix, y + iy), backgroundColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void drawBoxDouble(Recti rect) {
|
||||
var pos = rect.getPos();
|
||||
setChar(pos, Cp437.BOX_DOUBLE_RIGHT_BOTTOM);
|
||||
setChar(Vec2i.add(pos, new Vec2i(rect.getWidth() - 1, 0)), Cp437.BOX_DOUBLE_BOTTOM_LEFT);
|
||||
setChar(Vec2i.add(pos, new Vec2i(0, rect.getHeight() - 1)), Cp437.BOX_DOUBLE_TOP_RIGHT);
|
||||
setChar(Vec2i.add(pos, new Vec2i(rect.getWidth() - 1, rect.getHeight() - 1)), Cp437.BOX_DOUBLE_TOP_LEFT);
|
||||
drawHorizontalDoubleLine(Vec2i.add(pos, new Vec2i(1, 0)), rect.getWidth() - 2);
|
||||
drawHorizontalDoubleLine(Vec2i.add(pos, new Vec2i(1, rect.getHeight() - 1)), rect.getWidth() - 2);
|
||||
drawVerticalDoubleLine(Vec2i.add(pos, new Vec2i(0, 1)), rect.getHeight() - 2);
|
||||
drawVerticalDoubleLine(Vec2i.add(pos, new Vec2i(rect.getWidth() - 1, 1)), rect.getHeight() - 2);
|
||||
}
|
||||
|
||||
public void drawBoxDouble(Recti rect, Color foregroundColor) {
|
||||
var pos = rect.getPos();
|
||||
setChar(pos, Cp437.BOX_DOUBLE_RIGHT_BOTTOM, foregroundColor);
|
||||
setChar(Vec2i.add(pos, new Vec2i(rect.getWidth() - 1, 0)), Cp437.BOX_DOUBLE_BOTTOM_LEFT, foregroundColor);
|
||||
setChar(Vec2i.add(pos, new Vec2i(0, rect.getHeight() - 1)), Cp437.BOX_DOUBLE_TOP_RIGHT, foregroundColor);
|
||||
setChar(Vec2i.add(pos, new Vec2i(rect.getWidth() - 1, rect.getHeight() - 1)), Cp437.BOX_DOUBLE_TOP_LEFT, foregroundColor);
|
||||
drawHorizontalDoubleLine(Vec2i.add(pos, new Vec2i(1, 0)), rect.getWidth() - 2, foregroundColor);
|
||||
drawHorizontalDoubleLine(Vec2i.add(pos, new Vec2i(1, rect.getHeight() - 1)), rect.getWidth() - 2, foregroundColor);
|
||||
drawVerticalDoubleLine(Vec2i.add(pos, new Vec2i(0, 1)), rect.getHeight() - 2, foregroundColor);
|
||||
drawVerticalDoubleLine(Vec2i.add(pos, new Vec2i(rect.getWidth() - 1, 1)), rect.getHeight() - 2, foregroundColor);
|
||||
}
|
||||
|
||||
public void drawBoxDouble(Recti rect, Color foregroundColor, Color backgroundColor) {
|
||||
drawBoxDouble(rect, foregroundColor, backgroundColor, true);
|
||||
}
|
||||
|
||||
public void drawBoxDouble(Recti rect, Color foregroundColor, Color backgroundColor, boolean fill) {
|
||||
var pos = rect.getPos();
|
||||
setChar(pos, Cp437.BOX_DOUBLE_RIGHT_BOTTOM, foregroundColor, backgroundColor);
|
||||
setChar(Vec2i.add(pos, new Vec2i(rect.getWidth() - 1, 0)), Cp437.BOX_DOUBLE_BOTTOM_LEFT, foregroundColor, backgroundColor);
|
||||
setChar(Vec2i.add(pos, new Vec2i(0, rect.getHeight() - 1)), Cp437.BOX_DOUBLE_TOP_RIGHT, foregroundColor, backgroundColor);
|
||||
setChar(Vec2i.add(pos, new Vec2i(rect.getWidth() - 1, rect.getHeight() - 1)), Cp437.BOX_DOUBLE_TOP_LEFT, foregroundColor, backgroundColor);
|
||||
drawHorizontalDoubleLine(Vec2i.add(pos, new Vec2i(1, 0)), rect.getWidth() - 2, foregroundColor, backgroundColor);
|
||||
drawHorizontalDoubleLine(Vec2i.add(pos, new Vec2i(1, rect.getHeight() - 1)), rect.getWidth() - 2, foregroundColor, backgroundColor);
|
||||
drawVerticalDoubleLine(Vec2i.add(pos, new Vec2i(0, 1)), rect.getHeight() - 2, foregroundColor, backgroundColor);
|
||||
drawVerticalDoubleLine(Vec2i.add(pos, new Vec2i(rect.getWidth() - 1, 1)), rect.getHeight() - 2, foregroundColor, backgroundColor);
|
||||
|
||||
if(fill) {
|
||||
//todo: use draw rect
|
||||
var x = rect.getX() + 1;
|
||||
var y = rect.getY() + 1;
|
||||
for(int iy = 0; iy < rect.getWidth() - 2; ++iy) {
|
||||
for(int ix = 0; ix < rect.getWidth() - 2; ++ix) {
|
||||
setBackgroundColor(new Vec2i(x + ix, y + iy), backgroundColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class Cell {
|
||||
int fullChar;
|
||||
int secondChar;
|
||||
|
|
Loading…
Reference in New Issue