Корисник:МартинПетковски/Проекти
Овде е изворниот код на неколку проекти на Мартин Петковски
Библиотека за креирање на анимирани конзолски менија во C++[уреди | уреди извор]
menulib.h
#include<iostream> #include<conio.h> #include<string> #include<windows.h> #include<iomanip> #include"defin.h" using namespace std; bool animation; class menu { private: int color,focus,c,i,j; string _options[50], focus_decoration; int _fields,ws,anim_speed,speed_buffer; void color_text(string red) { HANDLE hConsole; hConsole=GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hConsole, color); cout<<red<<endl; SetConsoleTextAttribute(hConsole, 15); } void _color_text(string red, int color_it) { HANDLE hConsole; hConsole=GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hConsole, color_it); cout<<red<<endl; SetConsoleTextAttribute(hConsole, 15); } public: menu(string options[], int fields, string _focus_decoration="", int _color=WHITE, int _ws=6, bool _animation=false, int _anim_speed=80) { for(i=0;i<fields+1;i++) { _options[i]=options[i]; } color=_color; _fields=fields; focus_decoration=_focus_decoration; ws=_ws; animation=_animation; anim_speed=_anim_speed; speed_buffer=_anim_speed; } void create(string options[], int fields, string _focus_decoration="", int _color=WHITE, int _ws=6, bool _animation=false, int _anim_speed=80) { for(i=0;i<fields+1;i++) { _options[i]=options[i]; } color=_color; _fields=fields; focus_decoration=_focus_decoration; ws=_ws; animation=_animation; anim_speed=_anim_speed; speed_buffer=_anim_speed; } void flush() { anim_speed=speed_buffer; } int draw() { if(anim_speed>100) anim_speed=2; else anim_speed=100-anim_speed; focus=1; if(animation==false) { while(c!=ENTER) { system("cls"); for(i=1;i<=_fields;i++) { if(focus==i) { cout<<focus_decoration<<" "; color_text(_options[i]); } else cout<<_options[i]<<endl; } c=_getch(); if(c==UP) focus--; if(c==DOWN) focus++; if(focus<1) focus=_fields; if(focus>_fields) focus=1; } } else { c=UP; while(c!=ENTER) { j=1; if(c==UP||c==DOWN) { system("cls"); while(j<ws) { system("cls"); for(i=1;i<=_fields;i++) { if(focus==i) { cout<<focus_decoration<<setw(_options[i].length()+j); color_text(_options[i]); } else cout<<_options[i]<<endl; } Sleep(j*anim_speed); j++; } } c=_getch(); if(c==UP) focus--; if(c==DOWN) focus++; if(focus<1) focus=_fields; if(focus>_fields) focus=1; } } system("cls"); return focus; } void transition(int type, int duration, int x=80) { int check_color; if(color==CYAN) check_color=3; else if(color==LIGHTCYAN) check_color=4; else check_color=2; if(type==FADEIN) { for(i=0;i<check_color;i++) { for(j=1;j<_fields+1;j++) { switch(color) { case CYAN: _color_text(_options[j],cyan_fadeblack[i]); break; case LIGHTCYAN: _color_text(_options[j],lightcyan_fadeblack[i]); break; case LIGHTBLUE: _color_text(_options[j],lightblue_fadeblack[i]); break; case LIGHTGREEN: _color_text(_options[j],lightgreen_fadeblack[i]); break; case LIGHTRED: _color_text(_options[j],lightred_fadeblack[i]); break; case LIGHTMAGENTA: _color_text(_options[j],lightmagenta_fadeblack[i]); break; default: cout<<"ONLY LIGHT DEFINED COLORS CAN FADE IN!"<<endl; system("pause"); goto end; break; } } Sleep(duration); system("cls"); } end:; } if(type==FADEOUT) { for(i=check_color;i>0;i--) { for(j=1;j<_fields+1;j++) { switch(color) { case CYAN: _color_text(_options[j],cyan_fadeblack[i]); break; case LIGHTCYAN: _color_text(_options[j],lightcyan_fadeblack[i]); break; case LIGHTBLUE: _color_text(_options[j],lightblue_fadeblack[i]); break; case LIGHTGREEN: _color_text(_options[j],lightgreen_fadeblack[i]); break; case LIGHTRED: _color_text(_options[j],lightred_fadeblack[i]); break; case LIGHTMAGENTA: _color_text(_options[j],lightmagenta_fadeblack[i]); break; default: cout<<"ONLY LIGHT DEFINED COLORS CAN FADE OUT!"<<endl; system("pause"); goto end2; break; } } Sleep(duration); system("cls"); } end2:; } if(type==ROLL_LEFT) { j=x-_options[i].length(); while(j!=0) { for(i=1;i<_fields+1;i++) { cout<<setw(j)<<_options[i]<<endl;; } j--; Sleep(duration); system("cls"); } } if(type==ROLL_RIGHT) { j=0; while(j!=x-_options[i].length()) { for(i=1;i<_fields+1;i++) { cout<<setw(j)<<_options[i]<<endl;; } j++; Sleep(duration); system("cls"); } } } void modify(string _focus_decoration="", int _color=NULL, int _ws=NULL, int _anim_speed=NULL, bool _animation=animation) { if(_color!=NULL) color=_color; if(_focus_decoration!="") focus_decoration=_focus_decoration; if(_ws!=NULL) ws=_ws; if(_anim_speed!=NULL) anim_speed=_anim_speed; if(_anim_speed!=NULL) speed_buffer=_anim_speed; animation=_animation; } };