没有合适的资源?快使用搜索试试~ 我知道了~
对ncurses 的封装,方便学习
4星 · 超过85%的资源 需积分: 9 14 下载量 43 浏览量
2012-04-06
11:13:22
上传
评论 2
收藏 109KB DOC 举报
温馨提示
试读
18页
采用c++封装的ncurses 如果想了解ncurses的同学可以进来看看哦, 如果不懂那么也可以直接使用
资源推荐
资源详情
资源评论
/***********************************************
对 ncurses 的一个 c++封装
直接贴出源代码 如果要源文件的请联系本人
作者:hmy
**********************************************/
本实例是对 ncurses 的一个封装
下面是把 win 窗口集合到一
#include <ncurses.h>
#ifndef STRING
#define STRING
#include <vector>
#include <string.h>
using namespace std;
#endif
//窗口结构体
//字体结构体
void inttochars(int n,char *p);//整形转字符
int charToint(char *p);//字符转整形
class WINDOWS
{
public :
int count;
};
class TEXT
{
public:
WINDOW *win;
TEXT(){};
TEXT(int x,int y,int b,int f,int len,int length);
int x,y,b,f,length,len,ci;//len 输入个数 length 文本框长度
void set_text(int x,int y,int b,int f,int len,int length);//设置文本框
void setXY(int x,int y){this->x=x;this->y=y;} //设置 xy
int getX(){return x;}
int getY(){return y;}
void setColor(int b,int f);//设置颜色
int getBcolor(){return b;}
int getFcolor(){return f;}
char* getName(){ return text; }//得到收入的内容
char* getChar(int n,char *p){ inttochars(n,p); return p;}
int getInt(){return charToint(text);} //把输入的东西转换为整形
void setLen(int len); //重新设置字体长度
char name[100];
char text[100];
};
class FONT:public WINDOWS
{
public:
FONT(){count++; ct=0;}
FONT(int x,int y,int b,int f, char *name);
void setXY(int x,int y)
{
ox=this->x;
oy=this->y;
this->x=x;
this->y=y;
}
void setOXY(int x,int y)
{
ox=x;
oy=y;
}
void setOXY()
{
ox=x;
oy=y;
}
void setName(char *name) //重新初始化字符串
{
this->name=name;
int i=0;
while(name[i]!='\0')
{
space[i++]=' ';
}
space[i]='\0';
}
void setfont(int x,int y,int b,int f, char *name);
void setColor(int b,int f);
int getX(){return x;}
int getY(){return y;}
WINDOW *win;
int x,y,b,f,ci,ox,oy;
volatile int direction;
bool isShow;
char *name;
char space[100];
static int count;
int col;
int ct;
};
class BTN :public WINDOWS
{
public:
WINDOW *win,*fream;
int x,y,b,f,w,h,num,cio,cin,nb,nf,ci,click;// num 编号
bool isShow;
FONT *name;
BTN(){isShow=false; name=new FONT();click=0;}
BTN(int x,int y,int w,int h,char *name,int b,int f,int nb,int nf,int fb,int ff);//按钮设置
~BTN(){delwin(win);}
void setShow(bool bl){isShow=bl;} //设置是否显示
void setColor(int b,int f,int nb,int nf,int fb,int ff);//设置按钮颜色
void setBtn(int x,int y,int w,int h,char *name);//设置按钮基本设置
void btnfresh(); //按钮刷新
void clickbtn(); //点击事件反映
void addBox(int ch,int ch1){ box(win,ch,ch1); };
};
class NWIN:public WINDOWS
{
public:
typedef vector<FONT *> SubWin;
NWIN();
~NWIN();
SubWin sub;
WINDOW *win,*fawin;//win:自己的窗体 ,fawin:母窗体
int x,y,width,height,bk_color,f_color,ci;//bk_color:背景颜色 f_color:字体颜色 ci=颜色编号
int len;
void (addwin) (NWIN *win); //新建窗体
void (del) (NWIN *win);//删除窗体
void (setColor)(NWIN *win,int b,int f);//设置颜色
void (fresh) (NWIN *win);//刷新
void (addBox) (NWIN *win,int ch,int ch1);//加边框
void (addsub) (NWIN win,NWIN*subwins);//加子窗口
void (addfont) (NWIN *win,FONT &fonts);//加字体
void (addtext) (NWIN *win,TEXT *txt);//增加文本框
void (addbtn) (NWIN *win,BTN **); //增加按钮
int (txtput) (NWIN *win,TEXT *txt,char flg);//输入文本字体
void over(NWIN &subwin , NWIN &win){ overwrite(subwin.win,win.win);};//覆盖
void clearTrail(NWIN *win,FONT & fonts);//清除痕迹
int btnclics(BTN &btn_ok,BTN &btn_no);//增加点击事件
};
NWIN::NWIN()
{
len=0;
}
NWIN::~NWIN()
{
sub.clear();
}
typedef struct u_use
{
int len;
int wlen;
}U_S;
void _ninit();
void _nclose();
void init_win(NWIN *,int ,int ,int ,int);
//int txtput(NWIN *win,TEXT *txt,char flg);//输入字体 0 为默认输出
int input(NWIN subwin,TEXT *txt,char flg);//输入文本框函数 返回最后输入的字符
//void btnfresh(BTN btn);//刷新按钮
void clickbtn(BTN btn);
static int colori=1;
//初始化位置和函数
void init_win(NWIN *win,int x,int y,int w,int h)
{
win->x=x;
win->y=y;
win->height=h;
win->width=w;
win->win=NULL;
win->fawin=NULL;
}
//设置按钮
void BTN::setBtn(int x,int y,int w,int h,char *name)
{
this->x=x;
this->y=y;
剩余17页未读,继续阅读
资源评论
- yijunlai2013-01-18看起来有点乱,不是很好理解
- wgzh16152012-12-25很好的资源,对我这初学者帮助很大
- qwe1681922013-06-01写的非常的乱码,不适合阅读
源来猿往
- 粉丝: 363
- 资源: 19
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功