--- nono/lib/textscreen.cpp 2026/04/29 17:04:57 1.1.1.8 +++ nono/lib/textscreen.cpp 2026/04/29 17:05:22 1.1.1.10 @@ -4,12 +4,12 @@ // Licensed under nono-license.txt // -#include "textscreen.h" - // // テキストスクリーン // +#include "textscreen.h" + // コンストラクタ TextScreen::TextScreen() { @@ -186,3 +186,27 @@ TextScreen::SetAttr(TA attr) auto& ch = textbuf[(Y * col) + X]; ch = (ch & 0xff) | (uint)attr; } + +// src の src_y 行目から rows 行をこのスクリーンの dst_y 行目以降にコピーする。 +// 双方のカーソルは移動しない。 +// もし row がどちらかではみ出た場合はコピーをそこで終了する。 +// src と dst (この screen) の桁数が違うと assert する。 +void +TextScreen::CopyRowsFrom(int dst_y, int rows, const TextScreen& src, int src_y) +{ + assert(GetCol() == src.GetCol()); + + const auto& srcbuf = src.GetBuf(); + + // rows を小さいほうに揃える。 + if (rows > GetRow() - dst_y) { + rows = GetRow() - dst_y; + } + if (rows > src.GetRow() - src_y) { + rows = src.GetRow() - src_y; + } + + // 内部構造を知っているので一気にコピー。 + memcpy(&textbuf[dst_y * col], &srcbuf[src_y * col], + sizeof(textbuf[0]) * col * rows); +}