Skip to content

Commit

Permalink
"Look, ma, I can write!"
Browse files Browse the repository at this point in the history
  • Loading branch information
NotFound committed Dec 12, 2011
1 parent ab55756 commit 3b722a4
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions examples/pokedit.winxed
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,34 @@ class TextWindow : ChildWindow
self.drawall();
}
break;
default:
key = self.LookupString(event);
string line = text[curline];
switch (key) {
case "\r":
string newline = substr(line, curpos);
line = substr(line, 0, curpos);
for (int i = elements(text); i > curline; --i)
text[i] = text[i - 1];
text[curline] = line;
text[curline + 1] = newline;
self.curpos =: 0;
if (! self.movedown())
self.drawlines(curline, 0);
break;
case "\t":
// Cheap trick
l = 8 - (curpos % 8);
key = " " * l;
default:
if (key == null || length(key) == 0 || ord(key) < ord(" "))
break;
line = substr(line, 0, curpos) + key + substr(line, curpos);
curpos += length(key);
text[curline] = line;
self.curpos =: curpos;
self.drawline(curline);
}
}
self.cursor();
}
Expand All @@ -293,8 +321,12 @@ class TextWindow : ChildWindow
--curline;
self.curline =: curline;
int headline = self.headline;
if (headline > curline)
if (headline > curline) {
self.scrollup();
return true;
}
else
return false;
}
function movedown()
{
Expand All @@ -305,8 +337,12 @@ class TextWindow : ChildWindow
int lineheight = self.lineheight;
int headline = self.headline;
int maxline = headline + (height - MARGINSUP) / lineheight;
if (curline >= maxline)
if (curline >= maxline) {
self.scrolldown();
return true;
}
else
return false;
}
function scrollup()
{
Expand Down Expand Up @@ -347,6 +383,15 @@ class TextWindow : ChildWindow
for (int line = headline; line < headline + maxlines; ++line)
self.drawline(line);
}
function drawlines(int from, int to)
{
int headline = self.headline;
int maxlines = self.maxlines;
if (to == 0)
to = headline + maxlines - 1;
for (int line = from; line <= to; ++line)
self.drawline(line);
}
function drawline(int nline)
{
var text = self.text;
Expand Down

0 comments on commit 3b722a4

Please sign in to comment.