[Plugin] [REL] Console Colored Text 0.2 (New version)
#21

Just made correct printc and printfc:
pawn Код:
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);\
}
Reply
#22

Quote:
Originally Posted by 0rb
Just made correct printc and printfc:
pawn Код:
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)


//or..
stock printc(colors, string[])
{
  new old_colors = GetConsoleTextColor();
  SetConsoleTextColor(colors);
  print(string);
  SetConsoleTextColor(old_colors);
}
nice ^^
Reply
#23

Bah, you quoted old versions.

Also, colors(background, text); :

edited:
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))
Sorry for partially hijacking this topic but i think it's useful to post this. Maybe modify your .inc with all those things!
Reply
#24

Quote:
Originally Posted by 0rb
Bah, you quoted old versions.

Also, colors(background, text); :

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:background = BLACK, e_console_color:text = WHITE);

colors(e_console_color:background = BLACK, e_console_color:text = WHITE)
  return _:text + (16 * _:background);
Sorry for partially hijacking this topic but i think it's useful to post this. Maybe modify your .inc with all those things!
np. i add all this in the next version and i give credits(of corse )
Reply
#25

Edited my last post: arguments was mixed, and converted as a macro

Edit: some other things, but now i can't think of something else to do with it :P:
pawn Код:
//until you change functions names :)

native GetConsoleColors();
native SetConsoleColors(colors);

#define GetConsoleColors() \
  GetConsoleTextColor()

#define SetConsoleColors(%1) \
  SetConsoleTextColor(%1)
pawn Код:
//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)
Also renamed colors function because that name can be already used for a variable or whatever..and made it using bit operation (more efficient, i think)
pawn Код:
native ConsoleColors(e_console_color:foreground, e_console_color:background);

#define ConsoleColors(%1,%2) \
  (_:%2 << 4 | _:%1)
that's all, i think.


SUGGESTIONS if possible:

GetConsoleBufferWidth : returns the max characters of a line
GetConsoleBufferHeight : returns max lines that can be displayed (without 'overwriting')
Reply
#26

this plugin is cool nice dude!
Reply
#27

Quote:
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')
can you specify the params of these functions?

Reply
#28

Well, no params, only return value, or maybe

GetConsoleBufferSize(&width, &height) //width in 'characters', height in 'lines'

So if you know the width buffer, you can print string of the same length, for making nice tables for example . And height buffer can be useful for clearing the console for example

But that's no more related to console colors. I also wonder if it's possible to move cursor, as originally possible in Pawn, ad get/set the color of only where the cursor is (this join my other suggestion of start/end, which you said is impossible because of logprintf, but i really think it's possible to get and set the color of only 1 'cell' of the console buffer). So we can make colored games like tetris or whatever.
pawn Код:
GetConsoleCursorPos(&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
Reply
#29

this is a preview of the next version :P

Код:
/*
	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)
Reply
#30

I made
pawn Код:
SetConsoleCellData(x, y, character, e_console_color:foreground, e_console_color:background);
pawn Код:
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);


Interested?
Reply
#31

it looks funny but i don't think many people will use so many colors in one line ><
Reply
#32

Quote:
Originally Posted by 0rb
I made
pawn Код:
SetConsoleCellData(x, y, character, e_console_color:foreground, e_console_color:background);
pawn Код:
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);


Interested?
nice !!! if you wanna give me the source of the function i can add in the next version
Reply
#33

Well it's basically something like this:
pawn Код:
//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 make a plugin with <almost> all possible console functions i'll maybe release it once i got buffers system working fine.

Reply
#34

Quote:
Originally Posted by 0rb
Well it's basically something like this:
pawn Код:
//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 make a plugin with <almost> all possible console functions i'll maybe release it once i got buffers system working fine.

i can help you, if you want...
Reply
#35

lol cosmy, this isn't the WHOLE surse , this is a bollshit... post it or you'll be reported
Reply
#36

New download link ?
Reply
#37

Has the new version of PlayOn messed up anyones else's plugins? My old plugins work but when I try to install a new one, I get "You plugin is not compatible with the new version of PlayOn." The weird thing is I am using the same API as all my older plugins that work. Any ideas?
Reply
#38

I remake it because i don't have it anymore. Now just wait a moment...

EDIT:

bin + src: http://www27.zippyshare.com/v/74631330/file.html
Reply
#39

Has the new version of PlayOn messed up anyones else's plugins? My old plugins work but when I try to install a new one, I get "You plugin is not compatible with the new version of PlayOn." The weird thing is I am using the same API as all my older plugins that work. Any ideas?
Reply
#40

really nice plugin,
Код:
stock SendConsoleText(text[], color)
{
      SetConsoleTextColors(color);
      printf("%s", text);
      SetConsoleTextColors(CONSOLE_DEFAULT);
}
Use this if you want
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)