1 Star 0 Fork 1

WindowsEmbedded/字符电脑

forked from HellTractor/字符电脑 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
v1.5.0 13.54 KB
一键复制 编辑 原始数据 按行查看 历史
HellTractor 提交于 2022-01-09 06:32 . rename 最新版v1.5.0 to v1.5.0.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
//v0.1 2021.9.11
//v0.2 2021.9.12 窗口可以移动
//v1.0 2021.9.19 优化输出算法、单个应用可以正常运行
#include<iostream>
#include<windows.h>
#include<conio.h>
#include<unistd.h>
using namespace std;
int HANG=40,LIE=150;
const int MAXN=500;//数组规格
int hdcolor=0;//彩色
string performance="low";//性能
char ctable[MAXN][MAXN]={};
char empty[100][MAXN][MAXN]={};//app[i]的白板
int waop=0;
int maincourse();
int main();
int table();
int open(int n);
int tabbar();
int appbar();
int contbar();
int click(int x,int y);
inline void gotoxy(short x, short y) {
COORD coord = {x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
int nowapp=0;
//顶部状态栏
char tabline[MAXN]={};
void printtab(int lie=LIE){
for(int i=0;i<strlen(tabline);i++){
tabline[i]=' ';
}
string strtab="| TAB | 1.开始";
for(int i=1;i<=lie-60;i++){
strtab=strtab+" ";
}
strtab=strtab+"2.应用 3.控制中心 4.取消 | ESC 返回桌面 |";
for(int i=0;i<strtab.length();i++){
tabline[i]=strtab[i];
}
}
void print(char ch[][MAXN],int m,int n,int x,int y,int fx=0,int fy=0/*输出边界*/){
if(!hdcolor)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),15);
else
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),224);
gotoxy(x,y);
for(int i=fx;i<m+fx;i++){
for(int j=fy;j<n+fy;j++){
if(hdcolor && (ch[i][j]=='-' || ch[i][j]=='|' || ch[i][j]=='+')){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),17);
cout<<" ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),224);
}
else {
cout<<ch[i][j];
}
}
gotoxy(x,++y);
//cout<<endl;
}
}
struct appinfo{//68
bool developed=0;//是否已被开发
bool open=0;//是否已被打开
bool dowloaded=0;//是否被安装
int x=13,y=5;//窗口位置
int x1=0,y1=2;
string schedule="home";//app进度
string appname="ERROR";
int hang=HANG/2,lie=LIE/2;
int hang1=HANG-2,lie1=LIE;
char frame[MAXN][MAXN]={};
int fx=0,fy=0;//输出上边界
bool fullscreen=0;
void screenchange(){
int tx=x,ty=y,thang=hang,tlie=lie;
x=x1,y=y1,hang=hang1,lie=lie1;
x1=tx,y1=ty,hang1=thang,lie1=tlie;
}
};
appinfo apps[100];
appinfo sysapps[100];
inline void printempty(int n=nowapp){
print(empty[n],apps[n].hang-5,apps[n].lie-2,apps[n].x+1,apps[n].y+3,apps[n].fx,apps[n].fy);
}
char readc(){
if(waop!=0){
int x=waop;
waop=0;
open(x);
return ' ';
}
char ch=getch();
if(ch==9){//tab 点击后跳转到系统菜单
tabbar();
}
else if(ch==27){//esc跳转桌面
nowapp=0;
table();
exit(0);
}
return ch;
}
string reads(){
char ch;
string str;
int str_=0;
while(ch!=13){
ch=readc();
if(ch==8){
cout<<"\b \b";
str[--str_]=' ';
}
else{
cout<<ch;
str[str_++]=ch;
}
if(ch==13)break;
}
return str;
}
void addicon(char icon[][MAXN],char obj[][MAXN],int m/*icon行数*/,int x,int y){
for(int i=0;i<m;i++){
for(int j=0;j<strlen(icon[i]);j++){
obj[x][y+j]=icon[i][j];
}
x++;
}
}
void addnum(int icon[][MAXN],int obj[][MAXN],int m,int n,int x,int y){
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
obj[x][y+j]=icon[i][j];
}
x++;
}
}
void addstr(string icon,char obj[][MAXN],int x,int y){
for(int i=0;i<icon.length();i++){
obj[x][y++]=icon[i];
}
}
void paintframe(int nowapp){
int hang=apps[nowapp].hang;int lie=apps[nowapp].lie;
for(int i=0;i<hang;i++){//行
for(int j=0;j<lie;j++){//列
apps[nowapp].frame[i][j]=' ';
if(i==0 || i==hang-1)apps[nowapp].frame[i][j]='-';
if(i==2 || i==hang-1)apps[nowapp].frame[i][j]='-';
if(j==0 || j==lie-1)apps[nowapp].frame[i][j]='|';
if(i==hang-1 && j==lie-1)apps[nowapp].frame[i][j]='+';
if(i==0 && j==lie-1)apps[nowapp].frame[i][j]='+';
if(i==hang-1 && j==0 )apps[nowapp].frame[i][j]='+';
if(i==0 && j==0 )apps[nowapp].frame[i][j]='+';
if(i==2 && j==0 )apps[nowapp].frame[i][j]='+';
if(i==2 && j==lie-1)apps[nowapp].frame[i][j]='+';
}
}
for(int j=0;j<apps[nowapp].appname.length();j++){
apps[nowapp].frame[1][j+2]=apps[nowapp].appname[j];
}
}
inline void printframe(int n=nowapp){
print(apps[n].frame,apps[n].hang,apps[n].lie,apps[n].x,apps[n].y);
}
void stable(){//初始化桌面
int n=LIE,m=HANG;//n 列 m 行
for(int i=0;i<m;i++){//行
for(int j=0;j<n;j++){//列
ctable[i][j]=' ';
if(i==0 || i==m-1)ctable[i][j]='-';
if(i==2 || i==m-1)ctable[i][j]='-';
if(j==0 || j==n-1)ctable[i][j]='|';
if(i==m-1 && j==n-1)ctable[i][j]='+';
if(i==0 && j==n-1)ctable[i][j]='+';
if(i==m-1 && j==0 )ctable[i][j]='+';
if(i==0 && j==0 )ctable[i][j]='+';
if(i==2 && j==0 )ctable[i][j]='+';
if(i==2 && j==n-1)ctable[i][j]='+';
}
}
int X=3,Y=3;
int x=X,y=Y;//软件位置编号
char icon[10][MAXN]={
{"+----+"},
{"| |"},
{"+----+"}
};
for(int i=0;i<100;i++){
if(apps[i].dowloaded){
addicon(icon,ctable,3,x,y); //绘制图标
ctable[x+1][y+2]=(i/10)+'0';//容纳两位数
ctable[x+1][y+3]=(i%10)+'0';
for(int j=0;j<apps[i].appname.length();j++){
ctable[x+3][y+j]=apps[i].appname[j];
}
x+=5;
if(x>=30){
x=X;
y+=10;
}
}
}
addstr(tabline,ctable,1,0);
}
void freashempty(int n=nowapp){
for(int i=0;i<MAXN;i++){
for(int j=0;j<MAXN;j++){
empty[n][i][j]=' ';
}
}
}
void printagain(int showapp=1){
system("cls");
print(ctable,HANG,LIE,0,0);
for(int i=0;i<100;i++){
if(!apps[i].fullscreen &&showapp && apps[i].open){
printframe(i);
printempty(i);
}
}
}
void setting(string schedule=apps[1].schedule){//apps[1];
apps[1].open=1;
int hang=apps[1].hang,lie=apps[1].lie;
int x=apps[1].x,y=apps[1].y;
freashempty();
//gotoxy(apps[1].x,apps[1].y);//这是一条定位示例
if(schedule=="home"){
char homei[4][MAXN]={
{"+-------------+ +-------------+"},
{"| 1> 关于系统 | | 2> 显示 |"},
{"+-------------+ +-------------+"},
};
addicon(homei,empty[1],3,1,1);
printempty();
char ch=readc();
if(ch=='1'){
apps[1].schedule="about";
return;
}
else if(ch=='2'){
apps[1].schedule="show";
return;
}
apps[1].schedule="home";
}
else if(schedule=="about"){
char abouti[10][MAXN]={
{"+--------------------------------------------------+"},
{"| v1.5.0 2021.10.5 支持了全屏 按任意键返回 |"},
{"+--------------------------------------------------+"},
};
addicon(abouti,empty[1],3,1,1);
printempty();
char ch=readc();
apps[1].schedule="home";
return;
}
else if(schedule=="show"){//显示
char showi[4][MAXN]={
{"+------------------+ +--------------+ +--------+"},
{"| 1> 显示质量: | | 2> 颜色 | |3> 返回 |"},
{"+------------------+ +--------------+ +--------+"},
};
addstr(performance,showi,1,14);
addstr(to_string(hdcolor),showi,1,37);
addicon(showi,empty[1],3,1,1);
printempty();
char ch=readc();
if(ch=='1'){
if(performance=="high"){
performance="low";
}
else{
performance="high";
}
}
else if(ch=='2'){
hdcolor=1-hdcolor;
printagain(1);
}
else{
apps[1].schedule="home";
}
return;
}
return;
}
void appst(string schedule=apps[2].schedule){//apps[2];
freashempty();
apps[2].open=1;
int hang=apps[2].hang,lie=apps[2].lie;
if(schedule=="home"){
char icon[40][MAXN]={
{"+点击序号以操作------------+"},
{"| |"},
{"+--------------------------+"},
};
int x=1,y=1;//位置编号
for(int i=0;i<100;i++){
if(apps[i].developed){
addicon(icon,empty[2],3,x,y);
string str=to_string(i)+"> "+apps[i].appname;
addstr(str,empty[2],x+1,y+1);
if(y==1){
y+=35;
}
else{
y=1;x+=4;
}
}
}
printempty();
string str=reads();
int n=stoi(str);
if(apps[n].developed){
apps[n].dowloaded=1-apps[n].dowloaded;
apps[n].open=0;
apps[n].schedule="home";
stable();
printagain();
}
}
return;
}
int start();
tabbar(){
gotoxy(0,1);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),240);
for(int i=0;i<strlen(tabline);i++){
cout<<tabline[i];
if(i%10==0)usleep(1000);
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),15);
char temp=readc();
if(temp=='1'){
start();
}
else if(temp=='2'){
appbar();
}
else if(temp=='3'){
contbar();
}
else if(temp=='4'){
}
else if(temp==32){//对当前应用进行操作
}
else{
}
gotoxy(0,1);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),15);
for(int i=0;i<strlen(tabline);i++){
cout<<tabline[i];
if(i%10==0)usleep(1000);
}
return 0;
}
start(){
int x=5,y=3;
char cb[100][MAXN]={
{"+--------------------+"},
{"| |"},
{"| +----------------+ |"},
{"| | 1> 退出 | |"},
{"| +----------------+ |"},
{"| |"},
{"+--------------------+"},
};
print(cb,7,22,x,y);
char t=readc();
if(t=='1'){
exit(0);
}
}
contbar(){
int x=110,y=3;
char cb[100][MAXN]={
{"+--------------------+"},
{"| |"},
{"| +----------------+ |"},
{"| | 1> 全刷 | |"},
{"| +----------------+ |"},
{"| |"},
{"+--------------------+"},
};
print(cb,7,22,x,y);
char t=readc();
if(t=='1'){
printagain(nowapp);
}
}
appbar(){
if(!(0<nowapp<100)){
return 0;
}
int x=LIE-50,y=3;
char cb[100][MAXN]={
{"+--------------------+"},
{"| |"},
{"| |"},
{"| |"},
{"| |"},
{"| |"},
{"| |"},
{"| |"},
{"| |"},
{"| |"},
{"| |"},
{"| |"},
{"+--------------------+"},
};
print(cb,13,22,x,y);
gotoxy(x+2,y+1);cout<<"当前应用:"<<apps[nowapp].appname;
gotoxy(x+2,y+3);cout<<"a.更改窗口位置";
gotoxy(x+2,y+5);cout<<"b.关闭应用";
gotoxy(x+2,y+7);cout<<"c.翻页";
if(apps[nowapp].fullscreen){
gotoxy(x+2,y+9);cout<<"d.向下还原";
}
else{
gotoxy(x+2,y+9);cout<<"d.全屏";
}
char t=readc();
if(t=='a'){
print(cb,13,22,x,y);
gotoxy(x+2,y+1);cout<<"wasd操控 空格结束";
while(1){
t=readc();
if(t=='a'){
apps[nowapp].x--;
}
if(t=='w'){
apps[nowapp].y--;
}
if(t=='s'){
apps[nowapp].y++;
}
if(t=='d'){
apps[nowapp].x++;
}
if(t==32){
print(ctable,40,150,0,0);
open(nowapp);
maincourse();
exit(0);
}
printframe();
}
}
else if(t=='b'){
apps[nowapp].schedule="home";
apps[nowapp].open=0;
apps[nowapp].fx=0;
apps[nowapp].fy=0;
printagain(1);
return 0;
}
else if(t=='c'){
print(cb,13,22,x,y);
if(nowapp>0 && apps[nowapp].dowloaded){
gotoxy(x+2,y+7);cout<<"ws操控 空格结束";
}
else{
gotoxy(x+2,y+7);cout<<"请先选中一个应用";
return 0;
}
while(1){
t=readc();
if(t==32){
print(ctable,40,150,0,0);
open(nowapp);
maincourse();
exit(0);
}
if(t=='w'){
if(apps[nowapp].fx>0)
apps[nowapp].fx--;
printempty();
}
else if(t=='s'){
apps[nowapp].fx++;
printempty();
}
}
}
else if(t=='d'){
apps[nowapp].fullscreen=1-apps[nowapp].fullscreen;
apps[nowapp].screenchange();
printagain();
open(nowapp);
exit(0);
}
return 0;
}
void registry(){//app注册表
apps[0].appname="system";
apps[1].developed=1;
apps[1].appname="设置";
apps[1].dowloaded=1;
apps[2].developed=1;
apps[2].appname="应用商店";
apps[2].dowloaded=1;
for(int i=3;i<=30;i++){
apps[i].developed=1;
apps[i].appname="体验翻页功能";
}
}
int starter(){
cout<<"配置\n\n分辨率\n";
cout<<"1.默认 2.自定义";
char ch=getch();
if(ch=='1'){
return 0;
}
else{
system("cls");
cout<<"\n行数(默认:"<<HANG<<"):";
cin>>HANG;
cout<<"\n列数(默认:"<<LIE<<"):";
cin>>LIE;
}
return 0;
}
void open(int n){
if(n==0)return 0;
if(apps[n].developed && apps[n].dowloaded){//应用
for(int i=0;i<100;i++){
if(apps[i].open && i!=n && !apps[i].fullscreen){//窗口堆叠
if(apps[i].x==apps[n].x && apps[i].y==apps[n].y)continue;
printframe(i);
printempty(i);
}
}
apps[n].open=1;
while(apps[n].open){
paintframe(n);
printframe(n);
switch (n) {
case 1: setting();break;
case 2: appst();break;
default:
apps[n].open=0;
apps[n].developed=0;
apps[n].dowloaded=0;
stable();
table();
exit(0);
break;
}
}
}
else {//系统函数
if(n==-1){
tabbar();
}
}
}
void table(){
nowapp=0;
print(ctable,HANG,LIE,0,0);
while(1){
int f=1;
for(int i=10;i<100;i++){
if(apps[i].dowloaded){
f=0;break;
}
}
if(!f){
string str=reads();
nowapp=stoi(str);
if(nowapp>100){
continue;
}
open(nowapp);
}
else{
char ch=readc();
nowapp=ch-'0';
open(nowapp);
}
}
}
void maincourse(){
nowapp=0;
printtab();//绘制tabline
registry();//载入注册表
stable();//绘制ctable
table();//桌面程序
}
void main(){
starter();
maincourse();
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/EmbeddedGitee/character-computer.git
git@gitee.com:EmbeddedGitee/character-computer.git
EmbeddedGitee
character-computer
字符电脑
master

搜索帮助