native printc(colors, const string[]);
native printfc(colors, const format[], {Float,_}:...);
new g_console_colors;
#define printfc(%1,%2); \
{\
g_console_colors = GetConsoleTextColor();\
SetConsoleTextColor(%1);\
printf(%2);\
SetConsoleTextColor(g_console_colors);\
}
#define printc(%1,%2); \
{\
g_console_colors = GetConsoleTextColor();\
SetConsoleTextColor(%1);\
print(%2);\
SetConsoleTextColor(g_console_colors);\
}
|
Originally Posted by 0rb
Just made correct printc and printfc:
pawn Код:
|
enum e_console_color
{
BLACK,
BLUE,
GREEN,
AQUA,
RED,
PURPLE,
YELLOW,
WHITE,
GRAY,
LIGHTBLUE,
LIGHTGREEN,
LIGHTAQUA,
LIGHTRED,
LIGHTPURLE,
LIGHTYELLOW,
BRIGHTWHITE
}
native colors(e_console_color:text, e_console_color:background);
#define colors(%1,%2) \
(_:%1 + (16 * _:%2))
but i think it's useful to post this. Maybe modify your .inc with all those things!
|
Originally Posted by 0rb
Bah, you quoted old versions.
Also, colors(background, text); : pawn Код:
but i think it's useful to post this. Maybe modify your .inc with all those things! |
)
//until you change functions names :)
native GetConsoleColors();
native SetConsoleColors(colors);
#define GetConsoleColors() \
GetConsoleTextColor()
#define SetConsoleColors(%1) \
SetConsoleTextColor(%1)
//and then, MAYBE also replace all *Foreground* by *Text*
native GetConsoleForegroundColor();
native GetConsoleBackgroundColor();
native SetConsoleForegroundColor(e_console_color:color);
native SetConsoleBackgroundColor(e_console_color:color);
native SetConsoleColorsEx(e_console_color:foreground, e_console_color:background);
#define GetConsoleForegroundColor() \
(GetConsoleColors() & 0xF)
#define GetConsoleBackgroundColor() \
(GetConsoleColors() >> 4 & 0xF)
#define SetConsoleForegroundColor(%1) \
SetConsoleColors(GetConsoleBackgroundColor() << 4 | _:%1)
#define SetConsoleBackgroundColor(%1) \
SetConsoleColors(_:%1 << 4 | GetConsoleForegroundColor())
#define SetConsoleColorsEx(%1,%2) \
SetConsoleColors(_:%2 << 4 | _:%1)
native ConsoleColors(e_console_color:foreground, e_console_color:background);
#define ConsoleColors(%1,%2) \
(_:%2 << 4 | _:%1)
nice dude!
|
Originally Posted by 0rb
SUGGESTIONS if possible:
GetConsoleBufferWidth : returns the max characters of a line GetConsoleBufferHeight : returns max lines that can be displayed (without 'overwriting') |

. And height buffer can be useful for clearing the console for exampleGetConsoleCursorPos(&x, &y);
SetConsoleCursorPos(x, y);
GetConsoleCell(x, y, &character, &foreground, &background);
SetConsoleCell(x, y, character, e_console_color:foreground, e_console_color:background);
GetConsoleBuffer(startx, starty, endx, endy, bufferdata[], size = sizeof bufferdata); //not sure for those..
SetConsoleBuffer(startx, starty, endx, endy, bufferdata[], size = sizeof bufferdata); //but can be scripted in Pawn
/*
Console Colored Text 0.3
Author(s):
- Cosmy
- 0rb
Version log:
0.3
- Now SetConsoleTextColor() and GetConsoleTextColor() are called SetConsoleTextColors() and GetConsoleTextColors().
- Added an enum with all possible colors (i think).
- Added printc() and printfc() functions.
- Added GetConsoleForegroundColor(), GetConsoleBackgroundColor(), SetConsoleForegroundColor(), SetConsoleBackgroundColor() and SetConsoleColors().
- Deleted all old defines.
0.2
- Added GetConsoleTextColor() function.
0.1
- First release.
*/
#pragma unused g_console_colors
native SetConsoleTextColors(Attributes);
native GetConsoleTextColors();
new g_console_colors;
enum e_console_color
{
BLACK,
BLUE,
GREEN,
AQUA,
RED,
PURPLE,
YELLOW,
WHITE,
GRAY,
LIGHTBLUE,
LIGHTGREEN,
LIGHTAQUA,
LIGHTRED,
LIGHTPURLE,
LIGHTYELLOW,
BRIGHTWHITE
}
/* printc(colors, const string[]) */
#define printc(%1,%2); \
{\
g_console_colors = GetConsoleTextColors();\
SetConsoleTextColors(%1);\
print(%2);\
SetConsoleTextColors(g_console_colors);\
}
/* printfc(colors, const format[], {Float,_}:...) */
#define printfc(%1,%2); \
{\
g_console_colors = GetConsoleTextColors();\
SetConsoleTextColors(%1);\
printf(%2);\
SetConsoleTextColors(g_console_colors);\
}
/* GetConsoleForegroundColor() */
#define GetConsoleForegroundColor() \
(GetConsoleTextColors() & 0xF)
/* GetConsoleBackgroundColor() */
#define GetConsoleBackgroundColor() \
(GetConsoleTextColors() >> 4 & 0xF)
/* SetConsoleForegroundColor(e_console_color:color) */
#define SetConsoleForegroundColor(%1) \
SetConsoleTextColors(GetConsoleBackgroundColor() << 4 | _:%1)
/* SetConsoleBackgroundColor(e_console_color:color) */
#define SetConsoleBackgroundColor(%1) \
SetConsoleTextColors(_:%1 << 4 | GetConsoleForegroundColor())
/* SetConsoleColors(e_console_color:foreground, e_console_color:background) */
#define SetConsoleColors(%1,%2) \
SetConsoleTextColors(_:%2 << 4 | _:%1)
SetConsoleCellData(x, y, character, e_console_color:foreground, e_console_color:background);
new str[] = "Random colored string out of nowhere :)";
for (new i; i < sizeof str - 1; i++)
SetConsoleCellData(10 + i, 20, str[i], e_console_color:(random(15)+1), e_console_color:BLACK);

|
Originally Posted by 0rb
I made
pawn Код:
pawn Код:
![]() Interested? ![]() |
//SetConsoleCellsData(x, y, length, character, foreground_color, background_color);
//#define SetConsoleCellData(%1,%2,%3,%4,%5) SetConsoleCellsData(%1,%2,1,%3,%4,%5)
static cell AMX_NATIVE_CALL n_SetConsoleCellsData(AMX *amx, cell *params)
{
HANDLE Console = GetStdHandle(STD_OUTPUT_HANDLE);
COORD Coords = {(SHORT)params[1], (SHORT)params[2]};
DWORD Length = (DWORD)params[3];
WCHAR Character = (WCHAR)params[4];
WORD Colors = ((WORD)params[6] << 4 | (WORD)params[5]);
FillConsoleOutputCharacter(Console, Character, Length, Coords, NULL);
FillConsoleOutputAttribute(Console, Colors, Length, Coords, NULL);
return 1;
}
i'll maybe release it once i got buffers system working fine.|
Originally Posted by 0rb
Well it's basically something like this:
pawn Код:
i'll maybe release it once i got buffers system working fine. |
stock SendConsoleText(text[], color)
{
SetConsoleTextColors(color);
printf("%s", text);
SetConsoleTextColors(CONSOLE_DEFAULT);
}