referencing an Enum in a class

In my VS Toolbox I keep a ready-to-use screen control class that I can easily insert into any console program, to give me a quick (translate: lazy) way to change cursor position, text color, window size.
The syntax for the "Screen" control is:
 
screen.scr(CursorX, CursorY, text_color);

Inside the class is an Enum, which lets me simply type text_color as a word, so I down't have to bother looking up or memorizing the color codes.
The Enum:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
enum Hues
	{
		BLACK = 0,
		BLUE = 1,
		GREEN = 2,
		CYAN = 3,
		RED = 4,
		PURPLE = 5,
		DARK_YELLOW = 6,
		DEFAULT = 7,
		GREY = 8,
		BRIGHT_BLUE = 9,
		BRIGHT_GREEN = 10,
		BRIGHT_CYAN = 11,
		BRIGHT_RED = 12,
		MAGENTA = 13,
		YELLOW = 14,
		BRIGHT_WHITE = 15
	};

In the long run, all I have to do is create a "Screen" object at the first entry in MAIN() and set a pointer for it ,which is defined as:
1
2
Screen screen{window_height, window_width};
Screen *scr{&screen};

The above sets the console dimensions (in characters) and sets up an easy-to-type pointer (just call me a lazy typer!!)
This allows me to set cursor position and color anywhere in my code with the syntax:
 
scr->Cset(50,30,scr->BRIGHT_RED);

So, here's my question. Is there some way that I can set up the enum in the Screen class so that there's no need for the second "scr->" in the statement (without putting the Enum outside the class)?
I.e., so that the previous statement becomes merely,
 
scr->Cset(50,50,BRIGHT_RED);

Thanks in advance! Here's the full Screen class code:
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
class Screen
{
public:
	HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
	COORD coord;
	SMALL_RECT Rect;
	int screen_width;
	int screen_height;
	enum Hues
	{
		BLACK = 0,
		BLUE = 1,
		GREEN = 2,
		CYAN = 3,
		RED = 4,
		PURPLE = 5,
		DARK_YELLOW = 6,
		DEFAULT = 7,
		GREY = 8,
		BRIGHT_BLUE = 9,
		BRIGHT_GREEN = 10,
		BRIGHT_CYAN = 11,
		BRIGHT_RED = 12,
		MAGENTA = 13,
		YELLOW = 14,
		BRIGHT_WHITE = 15
	};
	Screen(int w = 60, int h = 50) : screen_width{ w }, screen_height{ h }
	{		
		SetWindow();
	}
	void SetWindow()
	{
		coord.X = screen_width, coord.Y = screen_height;
		Rect.Top = 0, Rect.Left = 0;
		Rect.Bottom = screen_height - 1; Rect.Right = screen_width - 1;
		SetConsoleScreenBufferSize(hConsole, coord);
		SetConsoleWindowInfo(hConsole, TRUE, &Rect);
	}
	void Cset(int x, int y, int c)
	{
		coord.X = x;
		coord.Y = y;
		SetConsoleCursorPosition(hConsole, coord);
		SetConsoleTextAttribute(hConsole, c);
	}
	void SetColor(int c)
	{
		SetConsoleTextAttribute(hConsole, c);
	}
	void SetCursor(int x, int y)
	{
		coord.X = x;
		coord.Y = y;
		SetConsoleCursorPosition(hConsole, coord);
	}
};


Cheers!
Instead of the enum you could have:

 
map<string, int> Hues {("BLACK", 0), ..., ("BRIGHT_WHITE", 15)}


And then:
1
2
3
4
5
void Cset (int x, int y, string str){
...
int c = Hues.find(str)->second;//with usual error-checking; 
SetConsoleTextAttribute(hConsole, c);
}

Last edited on
Topic archived. No new replies allowed.