c++ - ncurses库我想知道为什么不能绘制颜色
问题描述
[我是使用谷歌翻译的日本人]
演示代码是void Renderer ();
函数部分,为什么我不能绘制颜色?我不知道原因。
此外,该addch ();
功能可以正常绘制颜色。
操作系统: Ubuntu
参考站点A: https ://www.linuxjournal.com/content/programming-color-ncurses
参考站点B: https ://www.linuxjournal.com/content/about-ncurses-colors-0
屏幕.cpp
#include "../header/Screen.hpp"
#include "../header/Character.hpp"
#include "../header/Color.hpp"
#include "../header/Vector.hpp"
#include "../header/Screen.hpp"
// ######################## コンストラクタ ########################
Screen::Screen()
{
//ウインドウ初期化
getmaxyx(stdscr,windowSize.y,windowSize.x);
window = newpad(windowSize.y,windowSize.x);
start_color(); //カラーを有効化
prefresh(window,0,0,0,0,windowSize.y,windowSize.x);
size.x = windowSize.x;
size.y = windowSize.y;
maxSize = size.x * size.y;
stage = std::make_unique<std::vector<Character>>(size.x * size.y);
for(std::vector<Character>::iterator itr = stage->begin(); itr != stage->end(); itr++)
{
itr->chr = ' ';
itr->color = Color::NONE;
itr->type = 0;
}
}
// ######################## 画面サイズ更新 ########################
void Screen::UpdateScreen()
{
//画面サイズを取得
getmaxyx(stdscr,windowSize.y,windowSize.x);
//前のウインドウサイズをより大きければ要素を代入
if((windowSize.x * windowSize.y) > maxSize)
{
maxSize = windowSize.x * windowSize.y;
size.x = windowSize.x;
size.y = windowSize.y;
for(int i = 0; i< (windowSize.x * windowSize.y); i++)
{
stage->emplace_back(Character{Color::NONE,' ',0});
}
}
}
// ######################## Update ########################
void Screen::Update()
{
UpdateScreen(); //画面サイズを更新
}
// ######################## 文字設定 ########################
void Screen::Input(int x,int y,Character c)
{
stage->at((y * size.x) + x) = c;
}
// ######################## 文字削除 ########################
void Screen::Delete(int x,int y)
{
stage->at((y * size.x) + x).chr = ' ';
stage->at((y * size.x) + x).color = Color::NONE;
stage->at((y * size.x) + x).type = 0;
}
// ######################## Renderer ########################
void Screen::Renderer()const
{
for(int y = 0; y < size.y; y++)
{
for(int x = 0; x < size.x; x++)
{
// attron(COLOR_PAIR(stage->at((y * size.x) + x).color));
attron(COLOR_PAIR(16));
mvwaddch(window,y,x,stage->at((y * size.x) + x).chr);
//addch(stage->at((y * size.x) + x).chr);
//attrset(COLOR_PAIR(16));
//attroff(stage->at((y * size.x) + x).type);
// attroff(COLOR_PAIR(stage->at((y * size.x) + x).color));
}
}
prefresh(window,0,0,0,0,windowSize.y,windowSize.x);
}
// ######################## デストラクタ ########################
Screen::~Screen()
{
}
解决方案
wattron(window,COLOR_PAIR(stage->at((y * size.x) +
wattroff(window,COLOR_PAIR(stage->at((y * size.x) +
在使用 windows 时,必须使用wattron()
andwattroff()
函数而不是attron()
andattroff()
函数。
对于for语句,疑问句的注释部分内的代码需要进行如下修改。
for(int y = 0; y < size.y; y++)
{
for(int x = 0; x < size.x; x++)
{
wattron(window,COLOR_PAIR(stage->at((y * size.x) + x).color));
mvwaddch(window,y,x,stage->at((y * size.x) + x).chr);
wattroff(window,COLOR_PAIR(stage->at((y * size.x) + x).color));
}
}
推荐阅读
- sql - 如何根据显示收入和销售数据的库存数据库编写 sql 语句?
- wordpress - .htaccess rewriterule 不工作(wordpress)
- ms-access - 具有输入掩码的访问表编号字段在查询中返回不一致的值
- javascript - 如何在 iphone 6s 和 5s 的键盘上方隐藏图标和文本密码
- multithreading - 为什么我可以将静态 &str “移动”到 Rust 中的多个线程中?
- sql - SQL Server:来自内部视图的带有表值参数的表值 UDF
- java - Java中n个素数的总和
- php - php 一个变量中的两行
- c++ - 智能指针二维数组作为参数
- java - 如何使用 Spring data jdbc 插入具有自定义 id 的记录?