Commit 9d584558 authored by Robert Siemborski's avatar Robert Siemborski
Browse files

lots of commenting for display functions, so hopefully future people

will have an easier time understanding it than I first did ;)

Also, a removal of a redundant call to mvwaddnstr.


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@86 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
No related merge requests found
Showing with 55 additions and 22 deletions
+55 -22
...@@ -521,6 +521,10 @@ void set_modified(void) ...@@ -521,6 +521,10 @@ void set_modified(void)
} }
} }
/* And so start the display update routines */
/* Given a column, this returns the "page" it is on */
/* "page" in the case of the display columns, means which set of 80 */
/* characters is viewable (ie: page 1 shows from 1 to COLS) */
inline int get_page_from_virtual(int virtual) inline int get_page_from_virtual(int virtual)
{ {
int page = 2; int page = 2;
...@@ -537,6 +541,7 @@ inline int get_page_from_virtual(int virtual) ...@@ -537,6 +541,7 @@ inline int get_page_from_virtual(int virtual)
return page; return page;
} }
/* The inverse of the above function */
inline int get_page_start_virtual(int page) inline int get_page_start_virtual(int page)
{ {
int virtual; int virtual;
...@@ -552,16 +557,25 @@ inline int get_page_end_virtual(int page) ...@@ -552,16 +557,25 @@ inline int get_page_end_virtual(int page)
} }
#ifndef NANO_SMALL #ifndef NANO_SMALL
/* Called only from edit_add, and therefore expects a /* This takes care of the case where there is a mark that covers only */
* converted-to-only-spaces line */ /* the current line. */
/* It expects a line with no tab characers (ie: the type that edit_add
/* deals with */
void add_marked_sameline(int begin, int end, filestruct * fileptr, int y, void add_marked_sameline(int begin, int end, filestruct * fileptr, int y,
int virt_cur_x, int this_page) int virt_cur_x, int this_page)
{ {
/*
* The general idea is to break the line up into 3 sections: before
* the mark, the mark, and after the mark. We then paint each in
* turn (for those that are currently visible, of course
*
* 3 start points: 0 -> begin, begin->end, end->strlen(data)
* in data : pre sel post
*/
int this_page_start = get_page_start_virtual(this_page), int this_page_start = get_page_start_virtual(this_page),
this_page_end = get_page_end_virtual(this_page); this_page_end = get_page_end_virtual(this_page);
/* 3 start points: 0 -> begin, begin->end, end->strlen(data) */
/* in data : pre sel post */
/* likewise, 3 data lengths */ /* likewise, 3 data lengths */
int pre_data_len = begin, sel_data_len = end - begin, post_data_len = 0; /* Determined from the other two */ int pre_data_len = begin, sel_data_len = end - begin, post_data_len = 0; /* Determined from the other two */
...@@ -578,17 +592,17 @@ void add_marked_sameline(int begin, int end, filestruct * fileptr, int y, ...@@ -578,17 +592,17 @@ void add_marked_sameline(int begin, int end, filestruct * fileptr, int y,
if (end < this_page_start) if (end < this_page_start)
end = this_page_start; end = this_page_start;
/* we don't care about end, because it will just get cropped
* due to length */
if (begin > this_page_end) if (begin > this_page_end)
begin = this_page_end; begin = this_page_end;
if (end > this_page_end) if (end > this_page_end)
end = this_page_end; end = this_page_end;
/* Now calculate the lengths */
sel_data_len = end - begin; sel_data_len = end - begin;
post_data_len = this_page_end - end; post_data_len = this_page_end - end;
/* Paint this line! */
mvwaddnstr(edit, y, 0, &fileptr->data[this_page_start], pre_data_len); mvwaddnstr(edit, y, 0, &fileptr->data[this_page_start], pre_data_len);
wattron(edit, A_REVERSE); wattron(edit, A_REVERSE);
mvwaddnstr(edit, y, begin - this_page_start, mvwaddnstr(edit, y, begin - this_page_start,
...@@ -599,39 +613,57 @@ void add_marked_sameline(int begin, int end, filestruct * fileptr, int y, ...@@ -599,39 +613,57 @@ void add_marked_sameline(int begin, int end, filestruct * fileptr, int y,
} }
#endif #endif
/* Called only from update_line. Expects a converted-to-not-have-tabs /* edit_add takes care of the job of actually painting a line into the
* edit window.
*
* Called only from update_line. Expects a converted-to-not-have-tabs
* line */ * line */
void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x, void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
int virt_mark_beginx, int this_page) int virt_mark_beginx, int this_page)
{ {
#ifndef NANO_SMALL #ifndef NANO_SMALL
if (ISSET(MARK_ISSET)) { /* There are quite a few cases that could take place, we'll deal
if ((fileptr->lineno > mark_beginbuf->lineno * with them each in turn */
if (ISSET(MARK_ISSET)
&& !((fileptr->lineno > mark_beginbuf->lineno
&& fileptr->lineno > current->lineno) && fileptr->lineno > current->lineno)
|| (fileptr->lineno < mark_beginbuf->lineno || (fileptr->lineno < mark_beginbuf->lineno
&& fileptr->lineno < current->lineno)) { && fileptr->lineno < current->lineno)))
{
/* We're on a normal, unselected line */ /* If we get here we are on a line that is atleast
mvwaddnstr(edit, yval, 0, fileptr->data, COLS); * partially selected. The lineno checks above determined
} else { * that */
if (fileptr != mark_beginbuf && fileptr != current) { if (fileptr != mark_beginbuf && fileptr != current) {
/* We're on selected text */ /* We are on a completely marked line, paint it all
* inverse */
wattron(edit, A_REVERSE); wattron(edit, A_REVERSE);
mvwaddnstr(edit, yval, 0, fileptr->data, COLS); mvwaddnstr(edit, yval, 0, fileptr->data, COLS);
wattroff(edit, A_REVERSE); wattroff(edit, A_REVERSE);
} else if (fileptr == mark_beginbuf && fileptr == current) { } else if (fileptr == mark_beginbuf && fileptr == current) {
/* Special case, we're still on the same line we started /* Special case, we're still on the same line we started
* marking */ * marking -- so we call our helper function */
if (virt_cur_x < virt_mark_beginx) if (virt_cur_x < virt_mark_beginx) {
/* To the right of us is marked */
add_marked_sameline(virt_cur_x, virt_mark_beginx, add_marked_sameline(virt_cur_x, virt_mark_beginx,
fileptr, yval, virt_cur_x, fileptr, yval, virt_cur_x,
this_page); this_page);
else } else {
/* To the left of us is marked */
add_marked_sameline(virt_mark_beginx, virt_cur_x, add_marked_sameline(virt_mark_beginx, virt_cur_x,
fileptr, yval, virt_cur_x, fileptr, yval, virt_cur_x,
this_page); this_page);
}
} else if (fileptr == mark_beginbuf) { } else if (fileptr == mark_beginbuf) {
/* we're updating the line that was first marked */ /*
* we're updating the line that was first marked
* but we're not currently on it. So we want to
* figur out which half to invert based on our
* relative line numbers.
*
* i.e. If we're above the "beginbuf" line, we want to
* mark the left side. Otherwise we're below, so we
* mark the right
*/
int target; int target;
if (mark_beginbuf->lineno > current->lineno) if (mark_beginbuf->lineno > current->lineno)
...@@ -660,7 +692,7 @@ void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x, ...@@ -660,7 +692,7 @@ void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
} else if (fileptr == current) { } else if (fileptr == current) {
/* we're on the cursors line, but it's not the first /* we're on the cursors line, but it's not the first
* one we marked... */ * one we marked. Similar to the previous logic. */
int this_page_start = get_page_start_virtual(this_page), int this_page_start = get_page_start_virtual(this_page),
this_page_end = get_page_end_virtual(this_page); this_page_end = get_page_end_virtual(this_page);
...@@ -691,17 +723,18 @@ void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x, ...@@ -691,17 +723,18 @@ void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
if (mark_beginbuf->lineno > current->lineno) if (mark_beginbuf->lineno > current->lineno)
wattroff(edit, A_REVERSE); wattroff(edit, A_REVERSE);
}
} }
} else } else
#endif #endif
/* Just paint the string (no mark on this line) */
mvwaddnstr(edit, yval, 0, &fileptr->data[start], mvwaddnstr(edit, yval, 0, &fileptr->data[start],
get_page_end_virtual(this_page) - start); get_page_end_virtual(this_page) - start);
} }
/* /*
* Just update one line in the edit buffer * Just update one line in the edit buffer. Basically a wrapper for
* edit_add
* *
* index gives is a place in the string to update starting from. * index gives is a place in the string to update starting from.
* Likely args are current_x or 0. * Likely args are current_x or 0.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment