jcs
/textview
/amendments
/18
Combine both rewrites and use a list of shallow lines
Quickly recalculate line numbers and rects, then redraw the ones that
need drawing in the canvas.
jcs made amendment 18 over 2 years ago
--- textview.c Fri Oct 11 20:29:16 2024
+++ textview.c Mon Oct 14 21:32:16 2024
@@ -21,6 +21,8 @@
#define TEXT_SLAB_SIZE (16 * 1024)
#define CHUNK_SLAB_SIZE (sizeof(struct TVChunk) * 50)
+#define LINE_GROUP_NLINES 1000
+#define LINE_GROUP_SIZE (sizeof(struct TVLine) * LINE_GROUP_NLINES)
#define ARE_STYLES_EQUAL(one, two) ((one)->font == (two)->font && \
(one)->style == (two)->style && (one)->size == (two)->size)
@@ -37,17 +39,18 @@ struct TVRec * TVLock(TVHandle tvh);
void TVUnlock(struct TVRec *);
struct TVSlab * TVAllocateTextSlab(struct TVRec *tv);
struct TVSlab * TVAllocateChunkSlab(struct TVRec *tv);
+Handle TVAllocateLineGroup(struct TVRec *tv, short groupn);
struct TVChunk * TVGetChunk(struct TVRec *tv, TVChunkPtr ptr);
struct TVChunk * TVCreateChunk(struct TVRec *tv);
-struct TVChunk * TVSplitChunk(struct TVRec *tv, struct TVChunk *chunk,
- unsigned long length);
+struct TVLine * TVGetLine(struct TVRec *tv, unsigned long line);
+bool TVCalcLines(struct TVRec *tv, unsigned long start);
void TVApplyStyle(struct TVStyle *style);
struct TVStyle * TVFindStyle(struct TVRec *tv, struct TVStyle *style);
-void TVGrowBoundsToFit(struct TVRec *tv, struct TVChunk *chunk);
+void TVGrowBoundsToFit(struct TVRec *tv);
void TVScrollUnlocked(struct TVRec *tv, short horiz, short vert);
-bool TVDrawChunk(struct TVRec *tv, struct TVChunk *chunk);
-void TVDrawOnCanvas(struct TVRec *tv);
-void TVShowCanvas(struct TVRec *tv);
+bool TVDrawVisibleChunks(struct TVRec *tv);
+void TVUseCanvas(struct TVRec *tv);
+void TVRevealCanvas(struct TVRec *tv);
TVHandle
TVNew(Rect *view, Rect *padding)
@@ -122,13 +125,21 @@ TVNew(Rect *view, Rect *padding)
return NULL;
}
+ if (TVAllocateLineGroup(tv, 0) == NULL) {
+ DisposHandle(tv->chunk_slabs[0].data);
+ DisposHandle(tv->text_slabs[0].data);
+ DisposHandle(tv->canvas_baseaddr);
+ DisposHandle(tvh);
+ return NULL;
+ }
+
tv->cur_style = NO_STYLE;
#ifdef DEBUG_DRAWING
- TVDrawOnCanvas(tv);
+ TVUseCanvas(tv);
EraseRect(&tv->canvas.portRect);
FrameRect(&tv->canvas.portRect);
- TVShowCanvas(tv);
+ TVRevealCanvas(tv);
#endif
HUnlock(tvh);
@@ -149,7 +160,6 @@ TVAppend(TVHandle tvh, struct TVStyle *style, char *te
bool new_chunk = false, ret = true;
tv = TVLock(tvh);
- TVDrawOnCanvas(tv);
/* setup style */
prev_style_idx = tv->cur_style;
@@ -158,7 +168,6 @@ TVAppend(TVHandle tvh, struct TVStyle *style, char *te
return false;
if (tv->cur_style != prev_style_idx)
new_chunk = true;
- TVApplyStyle(cur_style);
/* setup text slab */
text_slab = &tv->text_slabs[tv->last_text_slab];
@@ -173,16 +182,16 @@ TVAppend(TVHandle tvh, struct TVStyle *style, char *te
prev_chunk = chunk;
chunk = TVCreateChunk(tv);
if (chunk == NULL) {
- TVShowCanvas(tv);
+ TVRevealCanvas(tv);
TVUnlock(tv);
return false;
}
+#if 0
if (prev_chunk) {
prev_style = TVFindStyle(tv, &tv->styles[prev_chunk->style]);
/* keep us on the same line as the previous chunk */
- chunk->rect.top = prev_chunk->rect.bottom -
- prev_style->height;
+ chunk->top = prev_chunk->rect.bottom - prev_style->height;
chunk->rect.bottom = chunk->rect.top + cur_style->height;
chunk->rect.left = prev_chunk->rect_end_right;
chunk->rect.right = prev_chunk->rect_end_right;
@@ -190,6 +199,7 @@ TVAppend(TVHandle tvh, struct TVStyle *style, char *te
chunk->rect_end_right = prev_chunk->rect_end_right;
prev_chunk->next_chunk = chunk->ptr;
chunk->prev_chunk = prev_chunk->ptr;
+ chunk->start_line = chunk->end_line = prev_chunk->end_line;
} else {
chunk->rect.top = tv->padding.top;
chunk->rect.left = tv->padding.left;
@@ -197,7 +207,9 @@ TVAppend(TVHandle tvh, struct TVStyle *style, char *te
chunk->rect.right = chunk->rect.left;
chunk->rect_start_left = chunk->rect.left;
chunk->rect_end_right = chunk->rect_start_left;
+ chunk->start_line = chunk->end_line = 1;
}
+#endif
chunk->slab = tv->last_text_slab;
chunk->start = text_slab->pos;
@@ -208,10 +220,6 @@ TVAppend(TVHandle tvh, struct TVStyle *style, char *te
if (avail == 0) {
/* new text slab, new chunk */
chunk->end = text_slab->pos;
- if (!TVDrawChunk(tv, chunk)) {
- ret = false;
- break;
- }
if ((text_slab = TVAllocateTextSlab(tv)) == NULL) {
ret = false;
@@ -230,18 +238,16 @@ TVAppend(TVHandle tvh, struct TVStyle *style, char *te
text += avail;
text_slab->pos += avail;
length -= avail;
- chunk->text_length += avail;
tv->text_length += avail;
- }
-
- if (chunk) {
chunk->end = text_slab->pos;
-
- if (!TVDrawChunk(tv, chunk))
- ret = false;
+ chunk->dirty = 1;
}
+
+ if (TVCalcLines(tv, 0))
+ TVDrawVisibleChunks(tv);
+ else
+ ret = false;
- TVShowCanvas(tv);
TVUnlock(tv);
return ret;
}
@@ -451,7 +457,6 @@ TVClear(TVHandle tvh)
n++) {
if (tv->chunk_slabs[n].data == NULL)
continue;
-
DisposHandle(tv->chunk_slabs[n].data);
tv->chunk_slabs[n].data = NULL;
tv->chunk_slabs[n].size = 0;
@@ -462,13 +467,14 @@ TVClear(TVHandle tvh)
memset((char *)*(tv->chunk_slabs[0].data), 0, tv->chunk_slabs[0].size);
HUnlock(tv->chunk_slabs[0].data);
tv->last_chunk_slab = 0;
+ tv->first_chunk = 0;
+ tv->last_chunk = 0;
/* free text slabs except first one */
for (n = 1; n < sizeof(tv->text_slabs) / sizeof(tv->text_slabs[0]);
n++) {
if (tv->text_slabs[n].data == NULL)
continue;
-
DisposHandle(tv->text_slabs[n].data);
tv->text_slabs[n].data = NULL;
tv->text_slabs[n].size = 0;
@@ -479,21 +485,28 @@ TVClear(TVHandle tvh)
memset((char *)*(tv->text_slabs[0].data), 0, tv->text_slabs[0].size);
HUnlock(tv->text_slabs[0].data);
tv->last_text_slab = 0;
-
- tv->first_chunk = 0;
- tv->last_chunk = 0;
-
tv->text_length = 0;
+ /* clear line groups except first one */
+ for (n = 1; n < sizeof(tv->lines) / sizeof(tv->lines[0]); n++) {
+ if (tv->lines[n] == NULL)
+ continue;
+ DisposHandle(tv->lines[n]);
+ tv->lines[n] = NULL;
+ }
+ HLock(tv->lines[0]);
+ memset((char *)*(tv->lines[0]), 0, LINE_GROUP_SIZE);
+ HUnlock(tv->lines[0]);
+
tv->bounds.bottom = tv->padding.top + tv->padding.bottom;
tv->scrolled = tv->bounds;
memset(&tv->styles, 0, sizeof(tv->styles));
tv->cur_style = NO_STYLE;
- TVDrawOnCanvas(tv);
+ TVUseCanvas(tv);
EraseRect(&tv->canvas.portRect);
- TVShowCanvas(tv);
+ TVRevealCanvas(tv);
TVUnlock(tv);
}
@@ -504,7 +517,7 @@ TVUpdate(TVHandle tvh)
struct TVChunk *chunk;
#if 0
tv = TVLock(tvh);
- TVDrawOnCanvas(tv);
+ TVUseCanvas(tv);
for (chunk = TVGetChunk(tv, tv->first_visible_chunk); chunk != NULL;
chunk = TVGetChunk(tv, chunk->next_chunk)) {
@@ -515,7 +528,7 @@ TVUpdate(TVHandle tvh)
TVDrawText(tv, chunk, 0);
}
- TVShowCanvas(tv);
+ TVRevealCanvas(tv);
TVUnlock(tv);
#endif
}
@@ -523,20 +536,20 @@ TVUpdate(TVHandle tvh)
void
TVDispose(TVHandle tvh)
{
-#if 0
struct TVRec *tv;
- /* this will free all but the first slab */
+ /* this will free all but the first slabs */
TVClear(tvh);
tv = TVLock(tvh);
- DisposeHandle(tv->chunk_slabs[0]);
+ DisposeHandle(tv->chunk_slabs[0].data);
+ DisposeHandle(tv->text_slabs[0].data);
+ DisposeHandle(tv->lines[0]);
ClosePort(&tv->canvas);
DisposeHandle(tv->canvas_baseaddr);
DisposeHandle(tvh);
-#endif
}
/*
@@ -577,6 +590,10 @@ TVUnlock(struct TVRec *tv)
for (n = 0; n < sizeof(tv->chunk_slabs) / sizeof(tv->chunk_slabs[0]); n++)
if (tv->chunk_slabs[n].data)
HUnlock(tv->chunk_slabs[n].data);
+ for (n = 0; n < sizeof(tv->lines) / sizeof(tv->lines[0]); n++) {
+ if (tv->lines[n])
+ HUnlock(tv->lines[n]);
+ }
HUnlock(tv->canvas_baseaddr);
HUnlock(RecoverHandle(tv));
@@ -647,6 +664,24 @@ TVAllocateChunkSlab(struct TVRec *tv)
return &tv->chunk_slabs[slot];
}
+Handle
+TVAllocateLineGroup(struct TVRec *tv, short groupn)
+{
+ short n;
+
+ if (groupn > sizeof(tv->lines) / sizeof(tv->lines[0]))
+ return NULL;
+
+ if (tv->lines[groupn] == NULL) {
+ tv->lines[groupn] = NewHandleClear(LINE_GROUP_SIZE);
+
+ if (tv->lines[groupn] == NULL)
+ Debugger();
+ }
+
+ return tv->lines[groupn];
+}
+
struct TVChunk *
TVGetChunk(struct TVRec *tv, TVChunkPtr ptr)
{
@@ -705,6 +740,29 @@ TVCreateChunk(struct TVRec *tv)
return chunk;
}
+struct TVLine *
+TVGetLine(struct TVRec *tv, unsigned long line)
+{
+ Handle group;
+ unsigned short groupn, idx;
+
+ groupn = (line - 1) / LINE_GROUP_NLINES;
+ if (groupn >= (sizeof(tv->lines) / sizeof(tv->lines[0])))
+ return NULL;
+
+ idx = line - 1 - (groupn * LINE_GROUP_NLINES);
+
+ group = tv->lines[groupn];
+ if (group == NULL) {
+ if ((group = TVAllocateLineGroup(tv, groupn)) == NULL)
+ return NULL;
+ }
+ HLock(group);
+
+ /* keep group locked */
+ return (struct TVLine *)(*group + (sizeof(struct TVLine) * idx));
+}
+
void
TVApplyStyle(struct TVStyle *style)
{
@@ -739,10 +797,9 @@ TVFindStyle(struct TVRec *tv, struct TVStyle *style)
tv->styles[n].size = style->size;
cur_style = &tv->styles[n];
GetFontInfo(&cur_style->font_info);
- cur_style->height = //cur_style->font_info.leading +
- cur_style->font_info.ascent + cur_style->font_info.descent;
- cur_style->baseline = cur_style->font_info.leading +
- cur_style->font_info.ascent;
+ cur_style->height = cur_style->font_info.ascent +
+ cur_style->font_info.descent;
+ cur_style->baseline = cur_style->font_info.ascent;
tv->cur_style = n;
return cur_style;
}
@@ -754,10 +811,14 @@ TVFindStyle(struct TVRec *tv, struct TVStyle *style)
}
void
-TVGrowBoundsToFit(struct TVRec *tv, struct TVChunk *chunk)
+TVGrowBoundsToFit(struct TVRec *tv)
{
- if (chunk->rect.bottom > tv->bounds.bottom - tv->padding.bottom) {
- tv->bounds.bottom = chunk->rect.bottom + tv->padding.bottom;
+ struct TVChunk *chunk;
+
+ chunk = TVGetChunk(tv, tv->last_chunk);
+
+ if (chunk && chunk->bottom > tv->bounds.bottom - tv->padding.bottom) {
+ tv->bounds.bottom = chunk->bottom + tv->padding.bottom;
tv->scrolled.bottom = tv->scrolled.top + tv->bounds.bottom;
}
@@ -766,117 +827,90 @@ TVGrowBoundsToFit(struct TVRec *tv, struct TVChunk *ch
}
bool
-TVDrawChunk(struct TVRec *tv, struct TVChunk *chunk)
+TVDrawVisibleChunks(struct TVRec *tv)
{
struct TVSlab *text_slab;
- struct TVChunk *prev_chunk, *tchunk;
+ struct TVChunk *chunk;
struct TVStyle *style;
+ struct TVLine *line, *next_line;
Rect r;
- Point pen;
- unsigned long avail, start_pos;
- long pos, j, n, back_width, back_n;
- short width, prev_style;
- char c, tc, *text_slab_data;
- bool new_line;
+ char c, *text_slab_data;
+ unsigned long bottom, left, datan, chunkn, chunklen, linen;
+ unsigned short chars;
- /* setup style */
- style = &tv->styles[chunk->style];
- if (style == NULL)
- return false;
- TVApplyStyle(style);
+ TVUseCanvas(tv);
+ EraseRect(&tv->canvas.portRect);
- TVDrawOnCanvas(tv);
+ datan = 0;
- /* setup text slab */
- text_slab = &tv->text_slabs[chunk->slab];
- text_slab_data = *(text_slab->data);
+ for (chunk = TVGetChunk(tv, tv->first_chunk); chunk != NULL;
+ chunk = TVGetChunk(tv, chunk->next_chunk)) {
+ /* setup style */
+ style = &tv->styles[chunk->style];
+ if (style == NULL)
+ return false;
+ TVApplyStyle(style);
- /* continue where the previous chunk left off */
- MoveTo(tv->scrolled.left + chunk->rect_end_right,
- tv->scrolled.top + chunk->rect.bottom -
- (style->height - style->baseline));
-
- new_line = false;
- for (n = chunk->last_drawn; n < chunk->end; n++) {
- c = text_slab_data[n];
-
- if (c == '\r') {
- new_line = true;
- width = 0;
- } else {
- if (!(width = style->width_cache[c]))
- width = style->width_cache[c] = CharWidth(c);
+ /* setup text slab */
+ text_slab = &tv->text_slabs[chunk->slab];
+ text_slab_data = *(text_slab->data);
+
+ chunklen = CHUNKPTR_OFFSET(chunk->end) -
+ CHUNKPTR_OFFSET(chunk->start);
- if (c != ' ' && chunk->rect_end_right + width >=
- tv->bounds.right - tv->padding.right) {
- new_line = true;
-
- /* need to wrap this word, walk backwards until we break */
- GetPen(&pen);
- back_width = 0;
- for (back_n = 1; back_n < chunk->end - chunk->start;
- back_n++) {
- tc = text_slab_data[n - back_n];
- if (tc != ' ') {
- back_width += style->width_cache[tc];
- continue;
- }
- r.bottom = pen.v + (style->height - style->baseline) +
- style->font_info.descent;
- r.top = r.bottom - style->height;
- r.right = pen.h;
- r.left = r.right - back_width;
-#ifdef DEBUG_DRAWING
- FrameRect(&r);
-#else
- EraseRect(&r);
-#endif
- /* put the genie back in the bottle */
- n -= back_n - 1;
- avail += back_n - 1;
- chunk->rect_end_right -= back_width;
- c = text_slab_data[n];
- width = style->width_cache[c];
- break; /* and continue below with new c */
- }
- }
+ if ((long)chunk->bottom < tv->scrolled.top) {
+ datan += chunklen;
+ continue;
}
+ if ((long)chunk->top > tv->scrolled.bottom)
+ break;
- if (new_line) {
- new_line = false;
- chunk->rect.left = tv->padding.left;
- chunk->end_line++;
-
- if (n == chunk->start) {
- /* we didn't put any text on previous line, start over */
- chunk->rect.top += style->height;
- chunk->rect.bottom = chunk->rect.top + style->height;
- chunk->rect.right = chunk->rect.left;
- chunk->rect_start_left = chunk->rect.left;
- chunk->rect_end_right = chunk->rect.left;
- chunk->start_line++;
- } else {
- chunk->rect.bottom += style->height;
- if (chunk->rect_end_right > chunk->rect.right)
- chunk->rect.right = chunk->rect_end_right;
- chunk->rect_end_right = chunk->rect.left;
+ linen = chunk->start_line;
+ line = TVGetLine(tv, linen);
+
+ chunkn = 0;
+ while (datan < tv->text_length && chunkn < chunklen &&
+ line != NULL) {
+ if (linen < chunk->end_line &&
+ (next_line = TVGetLine(tv, linen + 1)))
+ chars = next_line->start - line->start;
+ else {
+ next_line = NULL;
+ chars = tv->text_length - line->start;
}
- TVGrowBoundsToFit(tv, chunk);
- MoveTo(tv->scrolled.left + chunk->rect_end_right,
- tv->scrolled.top + chunk->rect.bottom -
- (style->height - style->baseline));
+ if (chars > chunklen)
+ chars = chunklen;
+
+ if (!(chars == 1 && *(text_slab_data + line->start) == '\r')
+#if 0
+ &&
+ tv->scrolled.top + line->rect.bottom >= 0 &&
+ tv->scrolled.top + line->rect.top <= tv->view_height
+#endif
+ ) {
+ if (linen == chunk->start_line)
+ left = chunk->start_left;
+ else
+ left = tv->padding.left;
+
+ MoveTo(left, tv->scrolled.top + line->rect.top +
+ style->baseline);
+ DrawText(text_slab_data + line->start, 0, chars);
+ }
+
+ datan += chars;
+ chunkn += chars;
+
+ if (chunkn == chunklen)
+ break;
+
+ linen++;
+ line = next_line;
}
-
- chunk->rect_end_right += width;
-
- DrawChar(c);
}
- chunk->last_drawn = chunk->end;
- TVGrowBoundsToFit(tv, chunk);
-
- TVShowCanvas(tv);
+ TVRevealCanvas(tv);
return true;
}
@@ -892,7 +926,7 @@ TVScrollUnlocked(struct TVRec *tv, short horiz, short
if (!horiz && !vert)
return;
- TVDrawOnCanvas(tv);
+ TVUseCanvas(tv);
BigRectToRect(tv->scrolled, was);
@@ -922,6 +956,7 @@ TVScrollUnlocked(struct TVRec *tv, short horiz, short
rvacated.top = tv->scrolled.bottom;
rvacated.bottom = rvacated.top - top;
+#if 0
for (chunk = TVGetChunk(tv, tv->first_chunk); chunk != NULL;
chunk = TVGetChunk(tv, chunk->next_chunk)) {
if (chunk->rect.bottom < rvacated.top)
@@ -930,13 +965,152 @@ TVScrollUnlocked(struct TVRec *tv, short horiz, short
break;
//TVDrawChunk(tv, chunk);
}
+#endif
DisposeRgn(vacated);
- TVShowCanvas(tv);
+ TVRevealCanvas(tv);
}
+bool
+TVCalcLines(struct TVRec *tv, unsigned long start)
+{
+ struct TVSlab *text_slab;
+ struct TVChunk *chunk, *prev_chunk;
+ struct TVStyle *style, *prev_style;
+ struct TVLine *line, *next_line;
+ Rect r;
+ unsigned long avail, start_pos, linen, last_space, max_right;
+ long pos, j, n, back_width, back_n;
+ short width, space_width, height;
+ char c, tc, *text_slab_data;
+ bool new_line;
+
+ for (n = 0; n < sizeof(tv->lines) / sizeof(tv->lines[0]); n++) {
+ if (tv->lines[n]) {
+ HLock(tv->lines[n]);
+ memset((char *)*(tv->lines[n]), 0, LINE_GROUP_SIZE);
+ }
+ }
+
+ linen = 1;
+ line = TVGetLine(tv, linen);
+ line->start = 0;
+ line->rect.top = tv->padding.top;
+ line->rect.left = tv->padding.left;
+ line->rect.right = line->rect.left;
+ line->rect.bottom = line->rect.top;
+
+ prev_chunk = NULL;
+ max_right = tv->bounds.right - tv->padding.right;
+
+ for (chunk = TVGetChunk(tv, tv->first_chunk); chunk != NULL;
+ chunk = TVGetChunk(tv, chunk->next_chunk)) {
+ style = &tv->styles[chunk->style];
+ if (style == NULL)
+ return false;
+ TVApplyStyle(style);
+
+ if (prev_chunk) {
+ /* compare style heights, use bigger and possbly change end of
+ * previous chunk */
+ chunk->top = prev_chunk->bottom - prev_style->height;
+ chunk->bottom = chunk->top + style->height;
+ chunk->start_left = prev_chunk->end_right;
+ chunk->start_line = prev_chunk->end_line;
+ } else {
+ chunk->top = tv->padding.top;
+ chunk->bottom = chunk->top + style->height;
+ chunk->start_left = tv->padding.left;
+ chunk->start_line = 1;
+ }
+ chunk->end_line = chunk->start_line;
+ chunk->end_right = chunk->start_left;
+
+ /* setup text slab */
+ text_slab = &tv->text_slabs[chunk->slab];
+ text_slab_data = *(text_slab->data);
+
+ new_line = false;
+ last_space = 0;
+
+ for (n = chunk->start; n < chunk->end; n++) {
+ c = text_slab_data[n];
+
+ if (c == '\r') {
+ new_line = true;
+ width = 0;
+ } else {
+ if (!(width = style->width_cache[c]))
+ width = style->width_cache[c] = CharWidth(c);
+
+ if (c == ' ') {
+ last_space = n;
+ space_width = 0;
+ } else if (chunk->end_right + width >= max_right) {
+ new_line = true;
+ if (last_space) {
+ n = last_space + 1;
+ chunk->end_right -= space_width;
+ c = text_slab_data[n];
+ }
+ }
+ }
+
+ if (new_line) {
+ new_line = false;
+ space_width = 0;
+ linen++;
+
+ line->rect.bottom = line->rect.top + style->height;
+ line->rect.right = chunk->end_right;
+
+ next_line = TVGetLine(tv, linen);
+ next_line->start = n;
+ next_line->rect.top = line->rect.bottom - 1;
+ next_line->rect.left = tv->padding.left;
+ next_line->rect.right = chunk->end_right;
+ next_line->rect.bottom = next_line->rect.top;
+
+ if (n == chunk->start) {
+ /* we didn't put any text on previous line, start over */
+ chunk->top = chunk->bottom;
+ chunk->bottom = chunk->top + style->height;
+ chunk->start_left = tv->padding.left;
+ chunk->end_right = chunk->start_left;
+ chunk->start_line++;
+ } else {
+ chunk->bottom += style->height;
+ chunk->end_right = tv->padding.left;
+ }
+
+ chunk->end_line++;
+ line = next_line;
+ }
+
+ chunk->end_right += width;
+ }
+
+ prev_chunk = chunk;
+ prev_style = style;
+ }
+
+ tv->nlines = linen;
+
+ if (prev_chunk->bottom > tv->bounds.bottom - tv->padding.bottom) {
+ tv->bounds.bottom = prev_chunk->bottom + tv->padding.bottom;
+ tv->scrolled.bottom = tv->scrolled.top + tv->bounds.bottom;
+ }
+
+ if (tv->autoscroll && (tv->scrolled.bottom > tv->view_height)) {
+ tv->scrolled.bottom = tv->view_height;
+ tv->scrolled.top = tv->scrolled.bottom - tv->bounds.bottom;
+ }
+
+ return true;
+}
+
void
-TVDrawOnCanvas(struct TVRec *tv)
+TVUseCanvas(struct TVRec *tv)
{
if (++tv->canvas_refcnt != 1)
return;
@@ -954,7 +1128,7 @@ TVDrawOnCanvas(struct TVRec *tv)
}
void
-TVShowCanvas(struct TVRec *tv)
+TVRevealCanvas(struct TVRec *tv)
{
if (tv->canvas_refcnt <= 0)
Debugger();
--- textview.h Fri Oct 11 20:25:58 2024
+++ textview.h Mon Oct 14 21:33:57 2024
@@ -18,18 +18,6 @@
#include <limits.h>
#include "stdint.h"
-struct TVStyle {
- unsigned char font;
- unsigned char style;
- unsigned char size;
-
- /* these are private and ignored when fed into TVAppend() */
- struct FontInfo font_info;
- unsigned char height;
- unsigned char baseline;
- unsigned char width_cache[256];
-};
-
struct BigRect {
long top;
long right;
@@ -44,32 +32,49 @@ typedef struct BigRect BigRect;
(br).right = (r).right; \
(br).bottom = (r).bottom; )
+struct TVStyle {
+ unsigned char font;
+ unsigned char style;
+ unsigned char size;
+
+ /* these are private and ignored when fed into TVAppend() */
+ struct FontInfo font_info;
+ unsigned char height;
+ unsigned char baseline;
+ unsigned char width_cache[256];
+};
+
typedef unsigned long TVChunkPtr;
-#define EMPTY_CHUNKPTR 0xffffffffL;
-/* high 4 are slab index, low are byte offset */
-#define CHUNKPTR_SLAB(x) (((x) >> 16) & 0xffff)
-#define CHUNKPTR_OFFSET(x) ((x) & 0xffff)
+/* high 2 are slab index, low 6 byte offset */
+#define CHUNKPTR_SLAB(x) (((x) >> 24) & 0xff)
+#define CHUNKPTR_OFFSET(x) ((x) & 0xffffff)
#define SET_CHUNKPTR_SLAB(ptr, x) \
- { (ptr) = ((unsigned long)(x) << 16) | (ptr) & 0xffff; }
+ { (ptr) = ((unsigned long)(x) << 24) | (ptr) & 0xff; }
#define SET_CHUNKPTR_OFFSET(ptr, x) \
- { (ptr) = (ptr) & 0xffff0000 | (x) & 0xffff; }
+ { (ptr) = (ptr) & 0xff000000 | (x) & 0xff; }
struct TVChunk {
TVChunkPtr ptr;
TVChunkPtr prev_chunk;
TVChunkPtr next_chunk;
- unsigned char style;
- unsigned char slab;
- unsigned short start;
- unsigned short end;
unsigned long start_line;
unsigned long end_line;
- unsigned long text_length;
- unsigned short rect_start_left;
- unsigned short rect_end_right;
- unsigned short last_drawn;
+ unsigned short start;
+ unsigned short end;
+ unsigned char style;
+ unsigned char slab;
+ bool dirty;
+ unsigned char _pad;
+ unsigned long top;
+ unsigned long bottom;
+ unsigned short start_left;
+ unsigned short end_right;
+};
+
+struct TVLine {
+ unsigned long start;
BigRect rect;
};
@@ -82,7 +87,7 @@ struct TVSlab {
struct TVRec {
/* bounds of where we live in window's port */
Rect view;
- long view_height;
+ unsigned 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 */
@@ -98,18 +103,21 @@ struct TVRec {
BigRect scrolled;
struct TVStyle styles[32];
+ unsigned char cur_style;
struct TVSlab text_slabs[32];
- struct TVSlab chunk_slabs[64];
+ unsigned char last_text_slab;
+ unsigned long text_length;
+ struct TVSlab chunk_slabs[64];
+ unsigned char last_chunk_slab;
TVChunkPtr first_chunk;
TVChunkPtr last_chunk;
- unsigned long text_length;
+ /* each lines item holds 1000 TVLine records */
+ Handle lines[16];
+ unsigned short nlines;
- unsigned char cur_style;
- unsigned char last_text_slab;
- unsigned char last_chunk_slab;
char unlock_refcnt;
bool autoscroll;
};