Skip to content

Commit

Permalink
horizontal scrolling, rep speed
Browse files Browse the repository at this point in the history
  • Loading branch information
dzaima committed Sep 27, 2019
1 parent ee5d270 commit 114ab86
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 34 deletions.
9 changes: 6 additions & 3 deletions AndroidIDE/Highlight.pde
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,18 @@ static class SyntaxHighlight {
g.textSize(sz);
int sel = sel(poi);
float chw = g.textWidth('H');
float ty = y + (MOBILE? sz*.333 : 0);
for(int ln = max(0, floor((sy-y)/sz)); ln < min(lns.length, floor((ey-y)/sz+1)); ln++) {
float cx = x;
String cln = lns[ln];
for (int i = 0; i < cln.length(); i++) {
char cc = cln.charAt(i);
int pos = i + lnstarts[ln];
g.fill(cs[pos]);
g.text(cc, cx, ty + ln*sz);
g.text(cc, cx, y + ln*sz);
int markcol = mark[pos];
if (markcol != 0) {
g.fill(markcol);
g.text("_", cx, ty + ln*sz);
g.text("_", cx, y + ln*sz);
}
if (sel == pos) {
g.stroke(th.pair);
Expand Down Expand Up @@ -194,3 +193,7 @@ class Theme {
int[] dfn = {#AA77BB, #EEBB44, #CC7799, #CCDD00, #B63CDA};

}

static float textY(float y, float sz) {
return y + (MOBILE? sz*.333 : 0);
}
9 changes: 5 additions & 4 deletions AndroidIDE/Keyboard.pde
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ class Keyboard extends Drawable {
Action a = findAction();
if (a != null) {
a.k.redraw(a);
if (millis() - mouseStart > 200) {
if (a.rep && frameCount%2==1) a.call();
int time = millis() - mouseStart;
if (time > 200) {
if (a.rep!=-1 && frameCount%a.rep == 0) a.call();
}
}
}
Expand Down Expand Up @@ -180,7 +181,7 @@ class Key extends Drawable {

class Action {
final String chr, spec, type, gotof;
final boolean rep;
final int rep;
final Keyboard b;
final Key k;
Action (JSONObject o, Keyboard b, Key k) {
Expand All @@ -191,7 +192,7 @@ class Action {

spec = o.getString("spec");
gotof = o.getString("goto");
rep = o.hasKey("rep")? o.getBoolean("rep") : false;
rep = o.hasKey("rep")? o.getInt("rep") : -1;
this.b = b;
this.k = k;
}
Expand Down
26 changes: 20 additions & 6 deletions AndroidIDE/ROText.pde
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
class ROText extends Drawable {
float tsz;
float tsz, chw;
ROText(int x, int y, int w, int h) {
super(x, y, w, h);
s = new ArrayList();
tsz = min(width, height)/20;
setSize(min(width, height)/20);
}
int yoff = 0; // scroll
int xoff = 0; // scroll
int yoff = 0;
int border = 10;
boolean redraw;
void redraw() {
Expand All @@ -23,18 +24,27 @@ class ROText extends Drawable {
int dy = -s.size();
clip(x+border, y+3, w-border*2, h-6);
for (String s : s) {
text(s, x+border, y + dy*tsz + yoff);
text(s, x+border + xoff, y + dy*tsz + yoff);
dy++;
}
noClip();
redraw = false;
}
void tick() {
if (!visible) return;
if (mousePressed && smouseIn()) {
yoff+= mouseY-pmouseY;
if (mousePressed && smouseIn() && (mouseY!=pmouseY || mouseX!=pmouseX)) {
redraw = true;
yoff+= mouseY-pmouseY;
if (yoff < h-border) yoff = h-border;


xoff+= mouseX-pmouseX;
int max = 0;
for (String s : s) max = max(max, s.length());
float maxx = (max - 2)*chw;
if (xoff < -maxx) xoff = (int) -maxx;
if (w > (max + 5)*chw) xoff = 0;
if (xoff > 0) xoff = 0;
}

if (redraw) redraw();
Expand All @@ -44,15 +54,19 @@ class ROText extends Drawable {
void append(String a) { // append a line
s.add(a);
yoff = h-border;
xoff = 0;
redraw = true;
}
void set(ArrayList<String> a) {
s = a;
yoff = h-border;
xoff = 0;
redraw = true;
}
void setSize(int sz) {
tsz = sz;
textSize(tsz);
chw = g.textWidth('H');
redraw = true;
}
void end() {
Expand Down
4 changes: 2 additions & 2 deletions AndroidIDE/Textarea.pde
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ class APLTextarea extends Drawable implements TextReciever {
super(x, y, w, h);
lines = new ArrayList();
lines.add("");
setsz(min(width, height)/20);
}
int tt = 0; // caret flicker timer
int xoff = 0; // scroll
int yoff = 0;

void redraw() {
setsz(min(width, height)/20);
}
boolean saveUndo = true;
boolean modified = false;
Expand Down Expand Up @@ -91,7 +91,7 @@ class APLTextarea extends Drawable implements TextReciever {
// //text(s, x, y + dy*tsz + yoff);
// dy++;
//}
hl.draw(x + xoff, y + yoff, y, y+h, tsz, fullPos());
hl.draw(x + xoff, textY(y + yoff, tsz), y, y+h, tsz, fullPos());

tt--;
if (tt < 0) tt = 60;
Expand Down
28 changes: 22 additions & 6 deletions AndroidIDE/Textfield.pde
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
class APLField extends Drawable implements TextReciever {
float tsz;
float tsz, chw;
SyntaxHighlight hl;
Theme th = new Theme();

float extraH = 1.2;
float xoff = 0;

APLField(int x, int y, int w, int h) {
this(x, y, w, h, "");
Expand All @@ -18,6 +19,8 @@ class APLField extends Drawable implements TextReciever {

void redraw() {
tsz = h/extraH;
textSize(tsz);
chw = textWidth("H");
}
boolean saveUndo = true;
boolean modified = false;
Expand All @@ -29,6 +32,13 @@ class APLField extends Drawable implements TextReciever {
if (mousePressed && !pmousePressed && smouseIn()) {
textInput = this;
}
if (mousePressed && smouseIn()) {
xoff+= mouseX-pmouseX;
}
float maxx = w*.8/chw > line.length()? 0 : (line.length() - 2)*chw;
if (xoff < -maxx) xoff = (int) -maxx;
if (xoff > 0) xoff = 0;

if (modified || saveUndo) {
modified();
hl = new SyntaxHighlight(line, th, g);
Expand All @@ -43,7 +53,7 @@ class APLField extends Drawable implements TextReciever {
clip(x, y, w, h);
if (pmousePressed && !mousePressed && smouseIn() && dist(mouseX, mouseY, smouseX, smouseY) < 10) {
textSize(tsz);
sx = constrain(round((mouseX-x)/textWidth("H")), 0, line.length());
sx = constrain(round((mouseX-x-xoff)/textWidth("H")), 0, line.length());
ex = sx;
tt = 0;
}
Expand All @@ -52,18 +62,18 @@ class APLField extends Drawable implements TextReciever {
rectMode(CORNER);
rect(x, y, w, h);
//text(line, x, y + dy*tsz + h*.1);
if (apl()) hl.draw(x, y, tsz, sx); //SyntaxHighlight.apltext(line, x, y + dy*tsz + h*.1, tsz, new Theme(), g);
if (apl()) hl.draw(x + xoff, textY(y, tsz), tsz, sx); //SyntaxHighlight.apltext(line, x, y + dy*tsz + h*.1, tsz, new Theme(), g);
else {
fill(#D2D2D2);
g.textAlign(LEFT, TOP);
textSize(tsz);
text(line, x, y);
text(line, x + xoff, textY(y, tsz));
}
tt--;
if (tt < 0) tt = 60;

float spx = x + max(textWidth(line.substring(0, sx)), 3);
float epx = x + max(textWidth(line.substring(0, ex)), 3);
float spx = x + max(textWidth(line.substring(0, sx)), 3) + xoff;
float epx = x + max(textWidth(line.substring(0, ex)), 3) + xoff;
float sy = y + h*.1;
float ey = y + h*.9;
if (tt > 30 || this != textInput) {
Expand Down Expand Up @@ -104,6 +114,8 @@ class APLField extends Drawable implements TextReciever {
if (!one()) line = line.substring(0, min) + line.substring(max);
ex = min;
sx = min;
modified = true;
saveUndo = true;
}
void append(String str) {
deleteSel();
Expand Down Expand Up @@ -195,6 +207,10 @@ class APLField extends Drawable implements TextReciever {
else if (s.equals("paste")) {
paste(this);
}
else if (s.equals("match")) {
int sel = hl.sel(sx);
if (sel != -1) sx = ex = sel;
}
else extraSpecial(s);
}
void pasted(String s) {
Expand Down
2 changes: 1 addition & 1 deletion AndroidIDE/data/L.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion AndroidIDE/data/P.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions AndroidIDE/data/kbs.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
MOD ↶ spec=undo
MOD ↷ spec=redo
MOD « rep spec=left
MOD » rep spec=right
MOD ↶ rep=6 spec=undo
MOD ↷ rep=6 spec=redo
MOD « rep=2 spec=left
MOD » rep=2 spec=right
MOD ⇧ spec=shift
MOD ⌫ rep spec=del
MOD ⌫ rep=3 spec=del
MOD C spec=clear
MOD ▲ rep spec=up
MOD ▼ rep spec=down
MOD ▲ rep=6 spec=up
MOD ▼ rep=6 spec=down
MOD # spec=none goto=CODE
MOD A spec=none goto=ABC3
MOD ⏎ spec=enter
Expand All @@ -17,7 +17,7 @@ MOD O spec=openPar chr=()
MOD P spec=wrapPar chr=..)
MOD č spec=copy chr=^C
MOD V spec=paste chr=^V
MOD ⌦ spec=rdel
MOD ⌦ rep=3 spec=rdel
MOD X spec=close
MOD M spec=match

Expand Down
9 changes: 6 additions & 3 deletions AndroidIDE/data/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ function parse(chr, mods) {
if (mods[chr]) {
for (let mod of mods[chr]) {
if (mod === 'sd') o.sd = true;
else if (mod === 'rep') o.rep = true;
else {
let [key, val] = mod.split(/(?<!=)=/);
if (key === 'spec') o.spec = val;
if (key === 'rep') {
o.rep = parseInt(val);
if (o.rep != val) throw new Error("couldn't parse number "+val);
}
else if (key === 'spec') o.spec = val;
else if (key === 'goto') o.goto = val;
else if (key === 'chr') o.chr = val;
else if (key === 'type') o.type = val;
else throw "unknown mod "+mod;
else throw new Error("unknown mod "+mod);
}
}
}
Expand Down

0 comments on commit 114ab86

Please sign in to comment.