首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

NCurses 庫 Pad(墊子)編程指南:超大虛擬窗口的創建與顯示控制

     編輯:關於C語言

Pad 與 Window 核心差異

核心 API

特性WINDOWPAD
尺寸限制不超過物理屏幕可任意大,不受終端可視區限制
位置綁定固定在屏幕座標無固定位置,需指定顯示區域
子窗口subwin/derwinsubpad
刷新方式wrefresh/wnoutrefreshprefetch/pnoutrefresh
與標準屏關聯直接關聯無直接關聯
函數原型關鍵參數說明
newpadWINDOW* newpad(int lines, int cols)創建指定行列數的 pad,無定位參數
subpadWINDOW* subpad(WINDOW* pad, int lines, int cols, int begin_y, int begin_x)在父 pad 內創建子 pad,座標相對父 pad
prefreshint prefresh(WINDOW* pad, int py, int px, int sy1, int sx1, int sy2, int sx2)核心刷新函數:
py,px:pad 內待顯示區域左上角
sy1,sx1,sy2,sx2:標準屏幕顯示矩形區域

刷新參數幾何關係圖解

Pad 內存座標系                    標準屏幕座標系
+--------------------------+      +--------------------------+
|        (py,px)           |      |        (sy1,sx1)         |
|        ┌───────────┐     |      |        ┌───────────┐     |
|        │  顯示區域   │     | ───> |        │  可視窗口   │     |
|        │  (sy2-sy1+1 │     |      |        │  (sy2-sy1+1 │     |
|        │   行, sx2-sx1+1列)     |      |        │   行, sx2-sx1+1列) |
|        └───────────┘     |      |        └───────────┘     |
+--------------------------+      +--------------------------+

典型使用流程

// 1. 創建 1000x200 的巨大 pad
WINDOW* bigpad = newpad(1000, 200);

// 2. 向 pad 寫入大量數據(可超出屏幕)
for (int i = 0; i < 1000; i++) {
    wprintw(bigpad, "Line %d: Data...\n", i);
}

// 3. 顯示 pad 中第 100-120 行,第 0-79 列到屏幕 (0,0) 到 (20,79)
prefresh(bigpad, 100, 0, 0, 0, 20, 79);

// 4. 實現滾動:循環調用 prefresh 修改 py 參數
//    可配合鍵盤輸入實現類似 less 的翻頁效果

高級用法:雙緩衝刷新

pnoutrefresh(pad1, py1, px1, sy1, sx1, ey1, ex1);
pnoutrefresh(pad2, py2, px2, sy2, sx2, ey2, ex2);
doupdate();  // 統一物理刷新

本文整理自「暗日」博客,原文地址:https://darksun.blog.51cto.com/3874064/1297302

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved