From b3850bbc6986729d12bec63a54b9933979719937 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 10 Mar 2020 19:23:51 +0900 Subject: [PATCH] [qwaq] Implement blitting from draw buffer to text Sending the data out to curses. --- ruamoko/qwaq/qwaq-draw.h | 4 ++++ ruamoko/qwaq/qwaq-draw.r | 10 ++++++++++ ruamoko/qwaq/qwaq-textcontext.h | 17 +++++++++++++++++ ruamoko/qwaq/qwaq-textcontext.r | 34 +++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+) diff --git a/ruamoko/qwaq/qwaq-draw.h b/ruamoko/qwaq/qwaq-draw.h index 50475fa3d..931ea6d12 100644 --- a/ruamoko/qwaq/qwaq-draw.h +++ b/ruamoko/qwaq/qwaq-draw.h @@ -13,6 +13,10 @@ } + (DrawBuffer *) buffer: (Extent) size; - initWithSize: (Extent) size; + +- (Extent) size; +- (int *) buffer; + - blitFromBuffer: (DrawBuffer *) srcBuffer to: (Point) pos from: (Rect) rect; - (void) printf: (string) fmt, ...; diff --git a/ruamoko/qwaq/qwaq-draw.r b/ruamoko/qwaq/qwaq-draw.r index 8ee7ad029..333d737e4 100644 --- a/ruamoko/qwaq/qwaq-draw.r +++ b/ruamoko/qwaq/qwaq-draw.r @@ -18,6 +18,16 @@ return self; } +- (Extent) size +{ + return size; +} + +- (int *) buffer +{ + return buffer; +} + - blitFromBuffer: (DrawBuffer *) srcBuffer to: (Point) pos from: (Rect) rect { Extent srcSize = srcBuffer.size; diff --git a/ruamoko/qwaq/qwaq-textcontext.h b/ruamoko/qwaq/qwaq-textcontext.h index 4a47b16ca..765f90572 100644 --- a/ruamoko/qwaq/qwaq-textcontext.h +++ b/ruamoko/qwaq/qwaq-textcontext.h @@ -6,9 +6,24 @@ #include "qwaq-curses.h" #include "qwaq-rect.h" +@class DrawBuffer; + @interface TextContext : Object { window_t window; + union { + Rect rect; + struct { + Point offset; + Extent size; + }; + struct { + int xpos; + int ypos; + int xlen; + int ylen; + }; + }; } + (int) max_colors; + (int) max_color_pairs; @@ -25,6 +40,8 @@ -(window_t) window; +- blitFromBuffer: (DrawBuffer *) srcBuffer to: (Point) pos from: (Rect) rect; + - (void) printf: (string) fmt, ...; - (void) vprintf: (string) mft, @va_list args; - (void) addch: (int) ch; diff --git a/ruamoko/qwaq/qwaq-textcontext.r b/ruamoko/qwaq/qwaq-textcontext.r index 1797bde48..726872ccf 100644 --- a/ruamoko/qwaq/qwaq-textcontext.r +++ b/ruamoko/qwaq/qwaq-textcontext.r @@ -1,3 +1,4 @@ +#include "qwaq-draw.h" #include "qwaq-textcontext.h" @implementation TextContext @@ -59,6 +60,39 @@ static TextContext *screen; return window; } +- blitFromBuffer: (DrawBuffer *) srcBuffer to: (Point) pos from: (Rect) rect +{ + Extent srcSize = [srcBuffer size]; + Rect r = { {}, srcSize }; + Rect t = { pos, rect.extent }; + + t = clipRect (r, t); + if (t.extent.width < 0 || t.extent.height < 0) { + return self; + } + + rect.offset.x += t.offset.x - pos.x; + rect.offset.y += t.offset.y - pos.y; + rect.extent = t.extent; + pos = t.offset; + + r.offset = nil; + r.extent = size; + + rect = clipRect (r, rect); + if (rect.extent.width < 0 || rect.extent.height < 0) { + return self; + } + + int *src = [srcBuffer buffer] + + rect.offset.y * srcSize.width + rect.offset.x; + for (int y = 0; y < rect.extent.height; y++) { + mvwblit_line (window, pos.x, y + pos.y, src, rect.extent.width); + src += srcSize.width; + } + return self; +} + - (void) mvprintf: (Point) pos, string fmt, ... = #0; - (void) printf: (string) fmt, ... = #0; - (void) vprintf: (string) mft, @va_list args = #0;