rendering some text

This commit is contained in:
Dani The Skunk 2022-10-21 05:25:51 +00:00
parent 021270985f
commit ceda613fec
1 changed files with 87 additions and 1 deletions

View File

@ -2,13 +2,99 @@ package com.danitheskunk.skunkwrite;
import com.danitheskunk.skunkworks.BaseGame; import com.danitheskunk.skunkworks.BaseGame;
import com.danitheskunk.skunkworks.Vec2i; import com.danitheskunk.skunkworks.Vec2i;
import com.danitheskunk.skunkworks.gfx.Color;
import com.danitheskunk.skunkworks.gfx.IRenderContext;
import com.danitheskunk.skunkworks.gfx.vt.Terminal;
import java.util.ArrayList;
import java.util.List;
public class Skunkwrite extends BaseGame { public class Skunkwrite extends BaseGame {
final private Terminal term;
final private List<String> lines;
public Skunkwrite() { public Skunkwrite() {
super(new Vec2i(2560, 1440), "Skunk Write v0.0"); super(new Vec2i(1280, 720), "Skunk Write v0.0");
lines = new ArrayList<>();
lines.add("Bacon ipsum dolor amet boudin leberkas jowl, short ribs " +
"t-bone ribeye ham pig. Meatball pastrami boudin swine " +
"frankfurter, buffalo ribeye short loin turkey jerky drumstick " +
"leberkas tenderloin prosciutto pancetta. Ground round tri-tip " +
"pastrami drumstick, strip steak doner chuck brisket t-bone " +
"meatball sirloin spare ribs shank. Prosciutto short ribs jowl " +
"andouille.");
lines.add("Sirloin prosciutto sausage buffalo turkey beef " +
"frankfurter" +
" spare ribs shank boudin bresaola shankle. Doner ham boudin " +
"bresaola kielbasa salami buffalo tongue cow. Salami pig bacon " +
"swine. Porchetta venison boudin, pig tongue turducken sausage " +
"corned beef salami leberkas ham pork shoulder strip steak " +
"kielbasa.");
lines.add("Meatloaf cow jerky, prosciutto ball tip tongue hamburger " +
"turducken leberkas pancetta andouille flank. Bresaola corned beef" +
" pork belly, turducken flank chislic venison shankle. Tongue " +
"capicola cupim pork loin. Alcatra ribeye boudin kevin frankfurter" +
" turkey salami. Prosciutto jerky biltong turkey ham hock " +
"burgdoggen salami andouille rump.");
lines.add("Pork belly hamburger strip steak rump. Doner ground round " +
"buffalo venison tenderloin shoulder beef ribs chuck ham drumstick. Bacon ham hock boudin corned beef shank jowl ribeye. Sausage brisket tenderloin venison. Filet mignon beef chuck, ribeye ground round pork loin cow tongue brisket shank kevin.");
lines.add("Meatloaf turducken leberkas beef ribs drumstick fatback " +
"landjaeger ribeye ham hamburger. Boudin ground round beef ribs cow strip steak alcatra. Jerky tenderloin chuck biltong prosciutto, chislic kielbasa. Ham kielbasa cupim cow boudin pork jerky fatback chicken shoulder landjaeger tail strip steak. Cupim tail meatball sausage, shank biltong ham corned beef chuck pancetta boudin pork alcatra bresaola ribeye. Pancetta ball tip buffalo bacon picanha, frankfurter pastrami pork loin ham hock.");
term = new Terminal(
new Vec2i(160, 51),
window.loadFontTileset("fonts/ega-8x14.png")
);
//term.drawHalfString(new Vec2i(0, 0), "Meow", Color.GREEN);
drawEditor();
} }
public static void main(String[] args) { public static void main(String[] args) {
new Skunkwrite().run(); new Skunkwrite().run();
} }
private int findSplitPoint(String str, int lineLength) {
var pos = lineLength - 1;
while(pos > 0) {
if(str.charAt(pos) == ' ') {
return pos;
}
--pos;
}
return lineLength - 1;
}
private List<String> splitIntoLines(String str, int lineLength) {
var lines = new ArrayList<String>();
while(str.length() > lineLength) {
int len = findSplitPoint(str, lineLength);
if(len == -1) {
lines.add(str);
break;
}
lines.add(str.substring(0, len));
str = str.substring(len+1);
}
lines.add(str);
return lines;
}
private void drawEditor() {
int lineLength = 60;
int x = (term.getSize().getX() - lineLength)/2;
int y = 0;
for(int i = 0; i < lines.size(); ++i) {
var l = splitIntoLines(lines.get(i), lineLength);
for(int j = 0; j < l.size(); ++j) {
term.drawString(new Vec2i(x, y), l.get(j), Color.GREEN);
++y;
}
++y;
}
}
@Override
protected void render(IRenderContext rc) {
rc.drawTerminal(term);
}
} }