everything depends on t.cur.y/x for memory purposes and on t.cur.r_x/y t.cur.off_x/y for render purposes
This commit is contained in:
parent
140b9a6752
commit
8efd7c3fbd
168
ste.c
168
ste.c
@ -19,12 +19,13 @@ struct term {
|
|||||||
struct {
|
struct {
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
unsigned int off_x;
|
int off_x;
|
||||||
unsigned int off_y;
|
int off_y;
|
||||||
int r_x;
|
int r_x;
|
||||||
int d_x;
|
int r_y;
|
||||||
|
//int d_x;
|
||||||
//int xx;
|
//int xx;
|
||||||
int yy;
|
//int yy;
|
||||||
} cur;
|
} cur;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
@ -43,7 +44,7 @@ struct term {
|
|||||||
typedef struct row {
|
typedef struct row {
|
||||||
int size;
|
int size;
|
||||||
char *chars;
|
char *chars;
|
||||||
unsigned int r_size;
|
int r_size;
|
||||||
char *render;
|
char *render;
|
||||||
} row;
|
} row;
|
||||||
|
|
||||||
@ -60,11 +61,11 @@ static void drawBar (char *s);
|
|||||||
static void drawScreen ();
|
static void drawScreen ();
|
||||||
static void drawLines (void);
|
static void drawLines (void);
|
||||||
static void updateRender (row *rw);
|
static void updateRender (row *rw);
|
||||||
static void updateOffset (void);
|
static void curUpdateRender (void);
|
||||||
static void cursorMove(int a);
|
static void cursorMove(int a);
|
||||||
static int decimalSize (int n);
|
static int decimalSize (int n);
|
||||||
static inline void lnMove (int y, int x);
|
static inline void lnMove (int y, int x);
|
||||||
static int curRealToRender (row *rw, int c_x);
|
//static int curRealToRender (row *rw, int c_x);
|
||||||
|
|
||||||
/* Row operations */
|
/* Row operations */
|
||||||
static inline void rowInit (void);
|
static inline void rowInit (void);
|
||||||
@ -142,22 +143,24 @@ int main (int argc, char *argv[])
|
|||||||
case (KEY_ENTER):
|
case (KEY_ENTER):
|
||||||
case (10):
|
case (10):
|
||||||
case ('\r'):
|
case ('\r'):
|
||||||
rowAddRow(t.cur.yy);
|
//rowAddRow(t.cur.yy);
|
||||||
|
|
||||||
|
//t.cur.off_x = 0;
|
||||||
|
rowAddRow(t.cur.y);
|
||||||
t.cur.y++;
|
t.cur.y++;
|
||||||
t.cur.x = 0;
|
t.cur.x = 0;
|
||||||
t.cur.off_x = 0;
|
|
||||||
break;
|
break;
|
||||||
case (KEY_END):
|
case (KEY_END):
|
||||||
t.cur.y = rows.rownum;
|
t.cur.y = rows.rownum - 1;
|
||||||
t.cur.off_y = 0;
|
//t.cur.off_y = 0;
|
||||||
break;
|
break;
|
||||||
case (KEY_HOME):
|
case (KEY_HOME):
|
||||||
t.cur.y = 0;
|
t.cur.y = 0;
|
||||||
t.cur.off_y = 0;
|
//t.cur.off_y = 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (c == KEY_STAB) c = '\t';
|
if (c == KEY_STAB) c = '\t';
|
||||||
rowAddChar(&rows.rw[t.cur.yy], c, t.cur.x);
|
rowAddChar(&rows.rw[t.cur.y], c, t.cur.x);
|
||||||
}
|
}
|
||||||
if (decimalSize(rows.rownum) - irow) updateInfo();
|
if (decimalSize(rows.rownum) - irow) updateInfo();
|
||||||
}
|
}
|
||||||
@ -239,13 +242,13 @@ void drawScreen ()
|
|||||||
/* Clear the screen */
|
/* Clear the screen */
|
||||||
erase();
|
erase();
|
||||||
/* Update Scroll */
|
/* Update Scroll */
|
||||||
updateOffset();
|
curUpdateRender();
|
||||||
/* draw the lines */
|
/* draw the lines */
|
||||||
drawLines();
|
drawLines();
|
||||||
/* draw the bar */
|
/* draw the bar */
|
||||||
drawBar(t.statusbar);
|
drawBar(t.statusbar);
|
||||||
/* move back to the cursor position */
|
/* move back to the cursor position */
|
||||||
lnMove(t.cur.y, t.cur.r_x);
|
lnMove(t.cur.r_y, t.cur.r_x);
|
||||||
/* refresh the screen */
|
/* refresh the screen */
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
@ -256,7 +259,7 @@ void drawLines (void)
|
|||||||
static int ln, i;
|
static int ln, i;
|
||||||
/* move to the beginning of the screen */
|
/* move to the beginning of the screen */
|
||||||
|
|
||||||
for (i = 0, ln = 0; i < t.dim.y; i++) {
|
for (i = 0, ln = 0; i < t.dim.y + t.cur.off_y; i++) {
|
||||||
ln = i + t.cur.off_y;
|
ln = i + t.cur.off_y;
|
||||||
if (ln >= rows.rownum) break;
|
if (ln >= rows.rownum) break;
|
||||||
|
|
||||||
@ -293,11 +296,12 @@ void drawBar (char *s)
|
|||||||
/* Print the message */
|
/* Print the message */
|
||||||
mvprintw(t.dim.y, 0, s);
|
mvprintw(t.dim.y, 0, s);
|
||||||
/* Fill everything else with spaces */
|
/* Fill everything else with spaces */
|
||||||
for (int i = len; i <= t.dim.x + t.pad; i++)
|
static int i;
|
||||||
|
for (i = len; i <= t.dim.x + t.pad; i++)
|
||||||
mvaddch(t.dim.y, i, ' ');
|
mvaddch(t.dim.y, i, ' ');
|
||||||
|
|
||||||
static char m[40];
|
static char m[40];
|
||||||
sprintf(m, "x: %d y: %d Zoom: %c", t.cur.x, t.cur.yy, whatsThat());
|
sprintf(m, "x: %d y: %d Zoom: %c", t.cur.x, t.cur.y, whatsThat());
|
||||||
mvaddstr(t.dim.y, t.dim.x + t.pad - strlen(m), m);
|
mvaddstr(t.dim.y, t.dim.x + t.pad - strlen(m), m);
|
||||||
|
|
||||||
/* Return to normal contrast mode */
|
/* Return to normal contrast mode */
|
||||||
@ -554,7 +558,7 @@ void rowDeleteRow (int pos)
|
|||||||
/* ----------------------------- row operations --------------------------- */
|
/* ----------------------------- row operations --------------------------- */
|
||||||
|
|
||||||
/* take care of the cursor movement */
|
/* take care of the cursor movement */
|
||||||
void cursorMove (int a)
|
/*void cursorMove (int a)
|
||||||
{
|
{
|
||||||
switch (a) {
|
switch (a) {
|
||||||
case (KEY_LEFT):
|
case (KEY_LEFT):
|
||||||
@ -604,11 +608,12 @@ void cursorMove (int a)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
void updateOffset (void)
|
|
||||||
|
/*void curUpdateRender (void)
|
||||||
{
|
{
|
||||||
/* Set y offset */
|
//Set y offset
|
||||||
if (t.cur.y >= t.dim.y) {
|
if (t.cur.y >= t.dim.y) {
|
||||||
if (t.cur.y == t.dim.y) t.cur.off_y++;
|
if (t.cur.y == t.dim.y) t.cur.off_y++;
|
||||||
else t.cur.off_y += t.cur.y - t.dim.y;
|
else t.cur.off_y += t.cur.y - t.dim.y;
|
||||||
@ -620,18 +625,10 @@ void updateOffset (void)
|
|||||||
t.cur.y = 0;
|
t.cur.y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set x offeset */
|
//Old curRealToRender()
|
||||||
/*if (t.cur.x >= t.dim.x) {
|
|
||||||
if (t.cur.x == t.dim.x - 1) t.cur.off_x++;
|
|
||||||
else t.cur.off_x += t.cur.x - t.dim.x;
|
|
||||||
|
|
||||||
t.cur.x = t.dim.x;
|
|
||||||
|
|
||||||
} else if (t.cur.x < 0 && t.cur.off_x > 0) {
|
|
||||||
t.cur.off_x--;
|
|
||||||
t.cur.x = 0;
|
|
||||||
}*/
|
|
||||||
t.cur.r_x = curRealToRender(&rows.rw[t.cur.yy], t.cur.x);
|
t.cur.r_x = curRealToRender(&rows.rw[t.cur.yy], t.cur.x);
|
||||||
|
|
||||||
|
|
||||||
if (t.cur.r_x >= t.dim.x) {
|
if (t.cur.r_x >= t.dim.x) {
|
||||||
t.cur.off_x += (t.cur.r_x > t.dim.x ) ? (t.cur.r_x - t.dim.x) : 1;
|
t.cur.off_x += (t.cur.r_x > t.dim.x ) ? (t.cur.r_x - t.dim.x) : 1;
|
||||||
t.cur.r_x = t.dim.x - 1;
|
t.cur.r_x = t.dim.x - 1;
|
||||||
@ -639,14 +636,15 @@ void updateOffset (void)
|
|||||||
t.cur.off_x -= (t.cur.off_x > 0) ? 0 : t.cur.off_x;
|
t.cur.off_x -= (t.cur.off_x > 0) ? 0 : t.cur.off_x;
|
||||||
t.cur.r_x = 0;
|
t.cur.r_x = 0;
|
||||||
}
|
}
|
||||||
/* convert the cursor from real to render
|
//convert the cursor from real to render
|
||||||
* and update other cursor info */
|
// and update other cursor info
|
||||||
t.cur.yy = t.cur.y + t.cur.off_y;
|
t.cur.yy = t.cur.y + t.cur.off_y;
|
||||||
//t.cur.xx = t.cur.x + t.cur.off_x;
|
//t.cur.xx = t.cur.x + t.cur.off_x;
|
||||||
//t.cur.d_x = t.cur.r_x - t.cur.x;
|
//t.cur.d_x = t.cur.r_x - t.cur.x;
|
||||||
}
|
} */
|
||||||
|
|
||||||
/* convert the cursor matchoing the memory to the drawn one */
|
/* convert the cursor matchoing the memory to the drawn one */
|
||||||
|
/*
|
||||||
int curRealToRender (row *rw, int c_x)
|
int curRealToRender (row *rw, int c_x)
|
||||||
{
|
{
|
||||||
static int r_x = 0, i;
|
static int r_x = 0, i;
|
||||||
@ -655,13 +653,13 @@ int curRealToRender (row *rw, int c_x)
|
|||||||
r_x++;
|
r_x++;
|
||||||
}
|
}
|
||||||
return r_x;
|
return r_x;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
/*---------------------------------- scroll ------------------------------------*/
|
/*---------------------------------- scroll ------------------------------------*/
|
||||||
|
|
||||||
/* See whats under the cursor (memory) */
|
/* See whats under the cursor (memory) */
|
||||||
int whatsThat (void) {
|
int whatsThat (void) {
|
||||||
int c = rows.rw[t.cur.yy].chars[t.cur.x];
|
int c = rows.rw[t.cur.y].chars[t.cur.x];
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case ('\t'):
|
case ('\t'):
|
||||||
return '^';
|
return '^';
|
||||||
@ -683,20 +681,20 @@ int whatsThat (void) {
|
|||||||
void handleDel (int select)
|
void handleDel (int select)
|
||||||
{
|
{
|
||||||
if (!select) {
|
if (!select) {
|
||||||
if (t.cur.x <= 0 && t.cur.yy > 0) {
|
if (t.cur.x <= 0 && t.cur.y > 0) {
|
||||||
t.cur.x = rows.rw[t.cur.yy - 1].size;
|
t.cur.x = rows.rw[t.cur.y - 1].size;
|
||||||
rowAddString(&rows.rw[t.cur.yy - 1], rows.rw[t.cur.yy].chars, rows.rw[t.cur.yy].size, -1);
|
rowAddString(&rows.rw[t.cur.y - 1], rows.rw[t.cur.y].chars, rows.rw[t.cur.y].size, -1);
|
||||||
rowDeleteRow(t.cur.yy);
|
rowDeleteRow(t.cur.y);
|
||||||
t.cur.y--;
|
t.cur.y--;
|
||||||
} else {
|
} else {
|
||||||
rowDeleteChar(&rows.rw[t.cur.yy], 0, t.cur.x);
|
rowDeleteChar(&rows.rw[t.cur.y], 0, t.cur.x);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (t.cur.x >= rows.rw[t.cur.yy].size) {
|
if (t.cur.x >= rows.rw[t.cur.y].size) {
|
||||||
rowAddString(&rows.rw[t.cur.yy], rows.rw[t.cur.yy + 1].chars, rows.rw[t.cur.yy + 1].size, -1);
|
rowAddString(&rows.rw[t.cur.y], rows.rw[t.cur.y + 1].chars, rows.rw[t.cur.y + 1].size, -1);
|
||||||
rowDeleteRow(t.cur.yy + 1);
|
rowDeleteRow(t.cur.y + 1);
|
||||||
} else {
|
} else {
|
||||||
rowDeleteChar(&rows.rw[t.cur.yy], 1, t.cur.x);
|
rowDeleteChar(&rows.rw[t.cur.y], 1, t.cur.x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -711,4 +709,80 @@ void updateInfo (void)
|
|||||||
t.dim.x -= t.pad + 1;
|
t.dim.x -= t.pad + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* take care of the cursor movement */
|
||||||
|
void cursorMove (int a)
|
||||||
|
{
|
||||||
|
switch (a) {
|
||||||
|
case (KEY_LEFT):
|
||||||
|
if (t.cur.x <= 0) {
|
||||||
|
if (t.cur.y) {
|
||||||
|
t.cur.y--;
|
||||||
|
t.cur.x = rows.rw[t.cur.y].size;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
t.cur.x--;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case (KEY_RIGHT):
|
||||||
|
if (t.cur.x >= rows.rw[t.cur.y].size) {
|
||||||
|
if (t.cur.y < rows.rownum - 1) {
|
||||||
|
t.cur.y++;
|
||||||
|
t.cur.x = 0;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
t.cur.x++;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case (KEY_UP):
|
||||||
|
if (t.cur.y) {
|
||||||
|
t.cur.y--;
|
||||||
|
if (t.cur.x > rows.rw[t.cur.y].size)
|
||||||
|
t.cur.x = rows.rw[t.cur.y].size;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case (KEY_DOWN):
|
||||||
|
if (t.cur.y < rows.rownum - 1) {
|
||||||
|
t.cur.y++;
|
||||||
|
if (t.cur.x > rows.rw[t.cur.y].size)
|
||||||
|
t.cur.x = rows.rw[t.cur.y].size;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void curUpdateRender ()
|
||||||
|
{
|
||||||
|
// y
|
||||||
|
if (t.cur.y >= t.cur.off_y && t.cur.y < t.cur.off_y + t.dim.y) {
|
||||||
|
t.cur.r_y = t.cur.y - t.cur.off_y;
|
||||||
|
|
||||||
|
} else if (t.cur.y >= t.cur.off_y + t.dim.y) {
|
||||||
|
if (t.cur.y == t.cur.off_y + t.dim.y) t.cur.off_y++;
|
||||||
|
else t.cur.off_y += t.cur.y - (t.cur.off_y + t.dim.y);
|
||||||
|
t.cur.r_y = t.dim.y - 1;
|
||||||
|
|
||||||
|
} else if (t.cur.y < t.cur.off_y) {
|
||||||
|
t.cur.off_y -= t.cur.off_y - t.cur.y;
|
||||||
|
t.cur.r_y = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// x
|
||||||
|
static int i;
|
||||||
|
for (i = 0, t.cur.r_x = 0; i < t.cur.x; i++) {
|
||||||
|
if (rows.rw[t.cur.y].chars[i] == '\t') t.cur.r_x += (TABSIZE - 1) - (t.cur.r_x % TABSIZE);
|
||||||
|
t.cur.r_x++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (t.cur.r_x >= t.cur.off_x && t.cur.r_x < t.dim.x) {
|
||||||
|
//ok
|
||||||
|
} else if (t.cur.r_x < t.cur.off_x) {
|
||||||
|
t.cur.off_x -= t.cur.off_x - t.cur.r_x;
|
||||||
|
t.cur.r_x = 0;
|
||||||
|
|
||||||
|
} else if (t.cur.r_x >= t.cur.off_x + t.dim.x) {
|
||||||
|
t.cur.off_x += t.cur.r_x - t.cur.off_x - t.dim.x;
|
||||||
|
t.cur.r_x = t.dim.x - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
/*--------------------------------- testing ------------------------------------*/
|
/*--------------------------------- testing ------------------------------------*/
|
||||||
|
Loading…
Reference in New Issue
Block a user