+++ /dev/null
-/*
- * Sixth 3D engine. Author: Svjatoslav Agejenko.
- * This project is released under Creative Commons Zero (CC0) license.
- */
-package eu.svjatoslav.sixth.e3d.gui.textEditorComponent;
-
-import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
-
-public class ColorConfig {
-
- public Color normalText = new Color(255, 255, 255);
- public Color normalBack = new Color(20, 20, 20, 255);
-
- public Color tabulatorBack = new Color(25, 25, 25, 255);
-
- public Color cursorText = new Color(255, 255, 255);
- public Color cursorBack = new Color(255, 0, 0);
-
- public Color selectedText = new Color(255, 255, 255);
- public Color selectedBack = new Color(0, 80, 80);
-
- public Color pageEnd = new Color(70, 70, 0);
-
-}
--- /dev/null
+/*
+ * Sixth 3D engine. Author: Svjatoslav Agejenko.
+ * This project is released under Creative Commons Zero (CC0) license.
+ */
+package eu.svjatoslav.sixth.e3d.gui.textEditorComponent;
+
+import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
+
+public class LookAndFeel {
+
+ public Color foreground = new Color(255, 255, 255);
+ public Color background = new Color(20, 20, 20, 255);
+
+ public Color tabStopBackground = new Color(25, 25, 25, 255);
+
+ public Color cursorForeground = new Color(255, 255, 255);
+ public Color cursorBackground = new Color(255, 0, 0);
+
+ public Color selectionForeground = new Color(255, 255, 255);
+ public Color selectionBackground = new Color(0, 80, 80);
+
+}
public class Page {
- public List<TextLine> lines = new ArrayList<>();
+ public List<TextLine> rows = new ArrayList<>();
public void ensureMaxTextLine(final int row) {
- while (lines.size() <= row)
- lines.add(new TextLine());
+ while (rows.size() <= row)
+ rows.add(new TextLine());
}
public char getChar(final int row, final int column) {
- if (lines.size() <= row)
+ if (rows.size() <= row)
return ' ';
- return lines.get(row).getCharForLocation(column);
+ return rows.get(row).getCharForLocation(column);
}
public TextLine getLine(final int row) {
ensureMaxTextLine(row);
- return lines.get(row);
+ return rows.get(row);
}
public int getLineLength(final int row) {
- if (lines.size() <= row)
+ if (rows.size() <= row)
return 0;
- return lines.get(row).getLength();
+ return rows.get(row).getLength();
}
public int getLinesCount() {
pack();
- return lines.size();
+ return rows.size();
}
public String getText() {
pack();
final StringBuilder result = new StringBuilder();
- for (final TextLine textLine : lines) {
+ for (final TextLine textLine : rows) {
if (result.length() > 0)
result.append("\n");
result.append(textLine.toString());
}
public void insertLine(final int row, final TextLine textLine) {
- lines.add(row, textLine);
+ rows.add(row, textLine);
}
private void pack() {
int newLength = 0;
- for (int i = lines.size() - 1; i >= 0; i--)
- if (!lines.get(i).isEmpty()) {
+ for (int i = rows.size() - 1; i >= 0; i--)
+ if (!rows.get(i).isEmpty()) {
newLength = i + 1;
break;
}
- if (newLength == lines.size())
+ if (newLength == rows.size())
return;
- lines = lines.subList(0, newLength);
+ rows = rows.subList(0, newLength);
}
public void removeCharacter(final int row, final int col) {
- if (lines.size() <= row)
+ if (rows.size() <= row)
return;
getLine(row).removeCharacter(col);
}
public void removeLine(final int row) {
- if (lines.size() <= row)
+ if (rows.size() <= row)
return;
- lines.remove(row);
+ rows.remove(row);
}
}
import eu.svjatoslav.sixth.e3d.gui.ViewPanel;
import eu.svjatoslav.sixth.e3d.gui.humaninput.KeyboardHelper;
import eu.svjatoslav.sixth.e3d.math.Transform;
-import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.textcanvas.TextCanvas;
import java.awt.*;
public TextPointer selectionEnd = new TextPointer(0, 0);
public TextPointer cursorLocation = new TextPointer(0, 0);
Page page = new Page();
- ColorConfig colorConfig = new ColorConfig();
+ LookAndFeel lookAndFeel;
boolean repaintPage = false;
public TextEditComponent(final Transform transform,
- final ViewPanel viewPanel, final Point2D sizeInWorldCoordinates) {
+ final ViewPanel viewPanel,
+ final Point2D sizeInWorldCoordinates,
+ LookAndFeel lookAndFeel) {
super(transform, viewPanel, sizeInWorldCoordinates.to3D());
- // initialize visual panel
-
+ this.lookAndFeel = lookAndFeel;
final int columns = (int) (sizeInWorldCoordinates.x / TextCanvas.FONT_CHAR_WIDTH);
final int rows = (int) (sizeInWorldCoordinates.y / TextCanvas.FONT_CHAR_HEIGHT);
- textCanvas = new TextCanvas(new Transform(), new TextPointer(rows,
- columns), Color.WHITE, colorConfig.normalBack);
+ textCanvas = new TextCanvas(
+ new Transform(),
+ new TextPointer(rows, columns),
+ lookAndFeel.foreground, lookAndFeel.background);
textCanvas.setMouseInteractionController(this);
identSelection:
{
- // check that identation is possible
+ // check that indentation is possible
for (int y = selectionStart.row; y < selectionEnd.row; y++) {
final TextLine textLine = page.getLine(y);
public void repaintPage() {
- final int chXe = textCanvas.getSize().column + 2;
- final int chYe = textCanvas.getSize().row + 2;
+ final int columnCount = textCanvas.getSize().column + 2;
+ final int rowCount = textCanvas.getSize().row + 2;
- for (int cy = 0; cy < chYe; cy++)
- for (int cx = 0; cx < chXe; cx++) {
- final boolean isTabMargin = ((cx + scrolledCharacters) % 4) == 0;
+ for (int row = 0; row < rowCount; row++)
+ for (int column = 0; column < columnCount; column++) {
+ final boolean isTabMargin = ((column + scrolledCharacters) % 4) == 0;
- if ((cx == (cursorLocation.column - scrolledCharacters))
- & (cy == (cursorLocation.row - scrolledLines))) {
+ if ((column == (cursorLocation.column - scrolledCharacters))
+ & (row == (cursorLocation.row - scrolledLines))) {
// cursor
- textCanvas.setBackgroundColor(colorConfig.cursorBack);
- textCanvas.setForegroundColor(colorConfig.cursorText);
- } else if (new TextPointer(cy + scrolledLines, cx).isBetween(
+ textCanvas.setBackgroundColor(lookAndFeel.cursorBackground);
+ textCanvas.setForegroundColor(lookAndFeel.cursorForeground);
+ } else if (new TextPointer(row + scrolledLines, column).isBetween(
selectionStart, selectionEnd)) {
// selected text
- textCanvas.setBackgroundColor(colorConfig.selectedBack);
- textCanvas.setForegroundColor(colorConfig.selectedText);
+ textCanvas.setBackgroundColor(lookAndFeel.selectionBackground);
+ textCanvas.setForegroundColor(lookAndFeel.selectionForeground);
} else {
// normal text
- textCanvas.setBackgroundColor(colorConfig.normalBack);
- textCanvas.setForegroundColor(colorConfig.normalText);
+ textCanvas.setBackgroundColor(lookAndFeel.background);
+ textCanvas.setForegroundColor(lookAndFeel.foreground);
if (isTabMargin)
textCanvas
- .setBackgroundColor(colorConfig.tabulatorBack);
+ .setBackgroundColor(lookAndFeel.tabStopBackground);
}
- final char charUnderCursor = page.getChar(cy + scrolledLines,
- cx + scrolledCharacters);
+ final char charUnderCursor = page.getChar(row + scrolledLines,
+ column + scrolledCharacters);
- textCanvas.putChar(cy, cx, charUnderCursor);
+ textCanvas.putChar(row, column, charUnderCursor);
}
}
public void repaintRow(final int rowNumber) {
- // TODO: fix this
+ // TODO: Optimize this. No need to repaint entire page.
repaintPage();
}