Skip to content

Commit

Permalink
second big push. Now there is an editor.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidedc committed Jul 14, 2011
1 parent 8c573f8 commit 70c081a
Show file tree
Hide file tree
Showing 760 changed files with 86,700 additions and 263 deletions.
2 changes: 2 additions & 0 deletions CompiledSketches/.gitignore
@@ -0,0 +1,2 @@

SketchFromP5NitroEditor
115 changes: 115 additions & 0 deletions P5Nitro/Cursor.java
@@ -0,0 +1,115 @@
public class Cursor {

int cursorChar = 0, cursorLine = 0;
public TextArea textArea;
float cursorX = 0;

public Cursor(TextArea textArea){
this.textArea = textArea;
}

public void advanceCursorByWord() {

int currentLineLength = textArea.currentLine().length();

int c = cursorChar;
if(cursorChar == currentLineLength) {
if(changeLine(1)) {
cursorChar = 0;
}
return;
}
if(textArea.currentLine().charAt(c) == ' ') {
c++;
}
while(c < currentLineLength) {
if(textArea.currentLine().charAt(c) == ' ') {
break;
}
c++;
}
cursorChar = c;
}

void resetCursorPosition() {
cursorChar = 0;
cursorLine = 0;
}

public void retreatCursorByChar() {

if(cursorChar > 0) {
cursorChar--;
}
else if(cursorChar == 0) {
if(changeLine(-1)) {
cursorChar = textArea.currentLine().length();
}
}
}

public void retreatCursorByWord() {

int c = cursorChar - 1;
if(cursorChar == 0) {
if(changeLine(-1)) {
cursorChar = textArea.currentLine().length();
}
return;
}
if(textArea.currentLine().charAt(c - 1) == ' ') {
c--;
}
while(c > 0) {
if(textArea.currentLine().charAt(c - 1) == ' ') {
break;
}
c--;
}
cursorChar = c;
}


public boolean changeLine(int byLines) {

if(byLines > 0 && cursorLine + byLines > textArea.nonWrappingLinesArrayList.size() - 1) {
return false;
}
else if(byLines < 0 && cursorLine + byLines < 0) {
return false;
}
cursorLine += byLines;

int currentLineLength = textArea.currentLine().length();

if(cursorChar > currentLineLength) {
cursorChar = currentLineLength;
}
return true;
}

public void advanceCursorByChar() {

int currentLineLength = textArea.currentLine().length();

if(cursorChar < currentLineLength) {
cursorChar++;
}
else if(cursorChar == currentLineLength) {
if(changeLine(1)) {
cursorChar = 0;
}
}
}


public void updateCursorPosition() {
String stringBeforeCaret = (new String((StringBuffer)textArea.nonWrappingLinesArrayList.get(cursorLine))).substring(0,cursorChar);
//cursorX = (float)textArea.p.textWidth(stringBeforeCaret) * textArea.scalingFactor;
cursorX = (float)textArea.p.textWidth(stringBeforeCaret);

// this is faster with monospaced fonts:
// cursorX = (float)p.textWidth("a") * (float)theCursor.cursorChar * scalingFactor;
}

}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 70c081a

Please sign in to comment.