1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <windows.h>
using namespace std;
vector<string> colourOptions = { "0 : Black" ,
"1 : Blue" ,
"2 : Green" ,
"3 : Aqua" ,
"4 : Red" ,
"5 : Purple" ,
"6 : Yellow" ,
"7 : White" ,
"8 : Gray" ,
"9 : Light_Blue" ,
"10: Light_Green" ,
"11: Light_Aqua" ,
"12: Light_Red" ,
"13: Light_Purple",
"14: Light_Yellow",
"15: Bright_White" };
vector<string> mainOptions = { "1. Change text colour",
"2. Change frame colour",
"3. Change frame type" };
vector<string> frameOptions = { "1. No frame",
"2. Single frame",
"3. Double frame" };
HANDLE h = GetStdHandle( STD_OUTPUT_HANDLE );
struct Frame
{
char TL, TR, BL, BR, H, V;
int colour = 7;
};
void colour( int n ) { SetConsoleTextAttribute( h, n ); }
void drawChar ( char c, int col = 7 ) { colour( col ); cout << c; }
void drawString( string s, int col = 7 ) { colour( col ); cout << s; }
void setFrameBlank ( Frame &F ) { F = { ' ', ' ', ' ', ' ', ' ', ' ', F.colour }; }
void setFrameSingle( Frame &F ) { F = { '+', '+', '+', '+', '-', '|', F.colour }; }
void setFrameDouble( Frame &F ) { F = { '╔', '╗', '╚', '╝', '═', '║', F.colour }; }
int drawMenu( const vector<string> &options, const Frame &F, int textColour, int width )
{
drawString( F.TL + string( width, F.H ) + F.TR, F.colour );
cout << '\n';
for ( string s : options )
{
drawChar ( F.V, F.colour );
drawString( ' ' + s + string( width - s.size() - 1, ' '), textColour );
drawChar ( F.V, F.colour );
cout << '\n';
}
drawString( F.BL + string( width, F.H ) + F.BR, F.colour );
cout << '\n';
colour( textColour );
int ans;
cin >> ans;
cout << '\n';
return ans;
}
int main()
{
Frame F; setFrameDouble( F );
int textColour = 7;
int menuWidth = 30;
while( true )
{
int ans = drawMenu( mainOptions, F, textColour, menuWidth );
switch( ans )
{
case 1:
textColour = drawMenu( colourOptions, F, textColour, menuWidth );
break;
case 2:
F.colour = drawMenu( colourOptions, F, textColour, menuWidth );
break;
case 3:
{
int typeFrame = drawMenu( frameOptions, F, textColour, menuWidth );
switch ( typeFrame )
{
case 1: setFrameBlank ( F ); break;
case 2: setFrameSingle( F ); break;
case 3: setFrameDouble( F ); break;
}
break;
}
default:
colour( 7 );
return 0;
}
}
}
|