jcs
/textview
/amendments
/32
Don't draw lines out of view, only CopyBits if canvas is dirty
jcs made amendment 32 over 2 years ago
--- textview.c Mon Oct 21 22:53:52 2024
+++ textview.c Mon Oct 21 23:23:07 2024
@@ -162,7 +162,7 @@ TVAppend(TVHandle tvh, struct TVStyle *style, char *te
struct TVStyle *cur_style;
struct TVLine *fromline, *toline;
RgnHandle vacated;
- BigRect visible;
+ BigRect redraw;
unsigned long avail, wastop;
short width, prev_style_idx;
char *text_slab_data;
@@ -248,6 +248,7 @@ TVAppend(TVHandle tvh, struct TVStyle *style, char *te
ScrollRect(&tv->canvas->portRect, 0, tv->scrolled.top - wastop,
vacated);
DisposeRgn(vacated);
+ tv->canvas_dirty = true;
}
if (fromline && fromline->nline == tv->nlines)
@@ -255,13 +256,16 @@ TVAppend(TVHandle tvh, struct TVStyle *style, char *te
else
toline = TVGetLine(tv, tv->nlines);
- visible.top = fromline ? fromline->rect.top : tv->padding.top;
- visible.bottom = toline->rect.bottom;
- visible.left = 0;
- visible.right = tv->view.right - tv->view.left;
- TVFindInRect(tv, &visible, fromline ? fromline->nline : 1, TVDrawMatch,
- NULL);
-
+ redraw.top = fromline ? fromline->rect.top : tv->padding.top;
+ redraw.bottom = toline->rect.bottom;
+ redraw.left = 0;
+ redraw.right = tv->view.right - tv->view.left;
+
+ if (tv->scrolled.top + redraw.bottom > 0L &&
+ tv->scrolled.top + redraw.top < tv->view_height)
+ TVFindInRect(tv, &redraw, fromline ? fromline->nline : 1,
+ TVDrawMatch, NULL);
+
TVRevealCanvas(tv);
ret = true;
@@ -610,6 +614,7 @@ TVClear(TVHandle tvh)
TVUseCanvas(tv);
EraseRect(&tv->canvas->portRect);
+ tv->canvas_dirty = true;
TVRevealCanvas(tv);
TVUnlock(tv);
}
@@ -624,6 +629,8 @@ TVUpdate(TVHandle tvh)
TVUseCanvas(tv);
EraseRect(&tv->canvas->portRect);
+ tv->canvas_dirty = true;
+
visible.top = -(tv->scrolled.top);
visible.left = -(tv->scrolled.left);
visible.bottom = visible.top + tv->view_height;
@@ -1108,6 +1115,7 @@ TVDrawMatch(struct TVRec *tv, struct TVFindInRectMatch
match->line->baseline);
DrawText(match->text_slab_data + (match->text_start -
match->text_slab->base), 0, match->text_end - match->text_start);
+ tv->canvas_dirty = true;
return true;
}
@@ -1245,6 +1253,7 @@ TVScrollUnlocked(struct TVRec *tv, short horiz, short
if ((top < 0 ? -top : top) > tv->view_height) {
EraseRect(&tv->canvas->portRect);
+ tv->canvas_dirty = true;
visible.top = -(tv->scrolled.top);
visible.left = -(tv->scrolled.left);
visible.bottom = visible.top + tv->view_height;
@@ -1256,6 +1265,7 @@ TVScrollUnlocked(struct TVRec *tv, short horiz, short
vacated = NewRgn();
ScrollRect(&tv->canvas->portRect, left, top, vacated);
+ tv->canvas_dirty = true;
HLock(vacated);
visible.left = (**vacated).rgnBBox.left - tv->scrolled.left;
visible.top = (**vacated).rgnBBox.top - tv->scrolled.top;
@@ -1307,12 +1317,14 @@ TVRevealCanvas(struct TVRec *tv)
SetPort(tv->canvas_old_port);
- CopyBits(&tv->canvas->portBits, &tv->canvas_old_port->portBits,
- &tv->canvas->portRect, &tv->view, srcCopy, NULL);
+ if (tv->canvas_dirty)
+ CopyBits(&tv->canvas->portBits, &tv->canvas_old_port->portBits,
+ &tv->canvas->portRect, &tv->view, srcCopy, NULL);
ValidRect(&tv->view);
tv->canvas_old_port = NULL;
+ tv->canvas_dirty = false;
HUnlock(tv->canvas_baseaddr);
}
--- textview.h Mon Oct 21 22:32:54 2024
+++ textview.h Mon Oct 21 23:00:37 2024
@@ -85,10 +85,13 @@ struct TVRec {
/* bounds of where we live in window's port */
Rect view;
long view_height;
+
/* full size of all text, bottom grows as more text is added */
BigRect bounds;
+
/* padding into bounds where we should start text */
Rect padding;
+
/* off-screen canvas where we draw text that is visible */
GrafPtr canvas;
Handle canvas_baseaddr;
@@ -96,6 +99,8 @@ struct TVRec {
size_t canvas_size;
/* while drawing on canvas, this stores old thePort */
GrafPtr canvas_old_port;
+ Boolean canvas_dirty;
+
/* bounds as it is scrolled */
BigRect scrolled;