Color Console For AGK2.0 
Alex 'Jack' Schmidt 2018
==== online-arts.de ====

Version 1.3

Easy Lib with some commands in order to control the console.
Beware, if you loose focus, (because you clicked on the console) you won't get input commands anymore.
This plugin is free and can be used for any work without charge.



Changelog:

1.0
x32 Support
Basic interface created

1.1
New commands added

1.2
x64 Support added

1.3
int = Console.GetHandle() command added
Console.SetHandle(int handle) command added - to get the window handle of the console and redirect other app output to them (one console, multiple apps)
Greatly reduced most static variable calls by buffering them, the performance should be better, but not notably.
Most of the Part is converted to unicode, but as AGK chars are Multibyte and somehow not convertable, there will be no unicode chars right now


The command set:

Console.Init(int MaxLines,CloseableFlag) - initialize the console in agk - Maxlines: maxial lines in the console to be shown
Console.SetTitle(String$) - set a title for the console
Console.SetColor(int color) - set text color (0-255)
Console.Clear() - similar to cls, can also apply the background color, when setColor is used
Console.SetString(int px, int py,String$) - set a specific text on a specific position in the console
Console.PrintCon(String$) - writes a string to the console
Console.SetSize(x,y) - Sets the console window size, as far as windows lets you
Console.SetVisible(state) - toggles console visibility
Console.Version() - prints the version of this plugin to console
Console.SetPosition(x,y) - Sets the console window position
Console.SetBufferSize(x,y) - Sets the console buffer size
Console.Close() - closes the console
Console.SetHandle(int handle) - set console handle target
int = Console.GetHandle() - get console handle target


You can use the handle commands in order to obtain a console handle and pass it to another application, that can write to the first console, if handle set correctly!
Playing around with the size will be a fun, as restrictive Microsoft is restrictive.



Example AGK2 Code:

// Project: ConsolePlugin 
// Created: 21.10.2018

#import_plugin Console  // load console plugin


// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "ConsolePlugin" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 60, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts

// dumb count system
line as integer
tick as integer
maxtick=800

// console commands:
Console.Init(20,0) // maximal 100 lines, no window close option
Console.SetTitle("Console")
Console.SetColor(46) // sets bg to green and text to yellow
Console.Clear() // clear sreen and apply color sheme
Console.SetString(0,1,"====================================================================") // some static text
Console.SetString(1,4,"Soon the color text routine starts, be prepared") // some static text
Console.Version() // print console Version to console
Console.SetSize(80,20) // set custom console size, as far as you can push it, limits are very strict
Console.SetBufferSize(80,18) // set custom console buffer size

do



	if GetRawKeyPressed(32) // Press SPACE to toggle console visibility
		s=1-s
		Console.SetVisible(s)
	endif
	
	if line<1 // initial 'static console'

		if GetRawKeyState(27) // Press ESC Key to toggle display text 
			Console.SetString(1,3,"[ESC] Yes. Now its pressed          ") // overwrite previous used chars by using space key
		else
			Console.SetString(1,3,"[ESC] key pressed? No, not yet   ")
		endif

		Console.SetString(57,4,str(tick)+" / "+str(maxtick)) // continous update
		
		Console.SetString(57,3,"FPS: "+str(ScreenFPS(),3))   // continous update

	endif
	

	if GetRawKeyPressed(13) then Console.Clear() // clear console by pressing ENTER

	inc tick
	if tick>maxtick
		maxtick=60
		inc line
		color = mod(line,255)
		Console.SetColor(color)
		Console.PrintCon("")	
		Console.PrintCon("Multi color Console Output in AGK for Windows x32")
		Console.PrintCon("Made by Jack - alex04.schmidt@gmail.com        Line: "+str(line*4-1) + "    color: "+str(color))
		Console.PrintCon("")
		tick = 0
	endif


    Print( ScreenFPS() )
    Sync()
loop

quit:
	Console.Close() // closes a console, frees allocation
	end
return
