NAME
Games::Console - provide a 2D quake style in-game console
SYNOPSIS
use Games::Console;
my $console = Games::Console->new(
font => $font_object,
background_color => [ 1,1,0],
background_alpha => 0.4,
text_color => [ 1,1,1 ],
text_alpha => 1,
speed => 50, # in percent per second
height => 50, # fully opened, in percent of screen
width => 100, # fully opened, in percent of screen
backbuffer_size => 100, # keep so many messages
prompt => ' >',
cursor => '_',
);
$console->screen_width($width);
$console->screen_height($height);
$console->toggle($current_time);
$console->message('Hello there!');
$console->input('a');
EXPORTS
Exports nothing on default.
DESCRIPTION
This package provides you with a quake-style console for your games. The console gathers messages and let's you scroll trough them. It also can display a command line.
This package is just a base class setting up everything, but doesn't actually render anything.
See Games::Console::SDL and Games::Console::OpenGL for subclasses that implement the actual rendering to the screen via SDL and OpenGL, respectively.
METHODS
- new()
-
my $console = Games::Console->new( $args );
Create a new console. Typically, you have only one.
$args
is a hash ref containing the following keys:logfile where to log messages loglevel the log level (e.g. what to log) text_color color of output text as array ref [r,g,b] text_alpha blend font over background for semitransparent background_color color of background as array ref [r,g,b] background_alpha blend console background over screen background
- message()
-
$console->message($message);
Append a message to the console's buffer.
- render()
-
$console->render ( $current_time );
If the console is currently visible, render it.
- add_input()
-
$console->add_input('a');
Add the text to the current input line (e.g. what is displayed after the prompt). See also input().
- input()
-
$current_input = $console->input(); $console->input('foo');
Get or set the contents of the current input line (e.g. what is displayed after the prompt). See also input().
Example usage after user pressed enter:
$console->message( $console->input() ); $console->input('');
- backspace()
-
$console->backspace();
Erases the last charcter from the current input buffer, unless the buffer is empty. Returns the current input buffer after the operation.
- text_color()
-
$rgb = $console->text_color(); # [$r,$g, $b ] $console->color(1,0.1,0.8); # set RGB
Sets the color of the text output.
- background_color()
-
$rgb = $console->background_color(); # [$r,$g, $b ] $console->background_color(1,0.1,0.8); # set RGB
Sets the color of the background output. See also background_alpha().
- text_alpha()
-
$a = $console->text_alpha(); # $a $console->alpha(0.8); # set A $console->alpha(undef); # set's it to 1.0 (seems an OpenGL # specific set because # glColor($r,$g,$b) also sets $a == 1
Sets the alpha value of the rendered text output.
- background_alpha()
-
$a = $console->background_alpha(); # $a $console->background_alpha(0.8); # set A
Sets the alpha value of the background (e.g. make it semi-transparent or opaque).
- speed()
-
$s = $console->speed(); # in percent $console->color(20); # set new speed (means 5 seconds time)
Gets/sets the opening/closing speed in percent per second, e.g. 25 means 100/25 = 4 seconds time.
- cursor()
-
$s = $console->cursor(); # get cursor string $console->cursor('_'); # set new cursor
Get/sets the string used as cursor.
- prompt()
-
$s = $console->prompt(); # get prompt string $console->prompt('_'); # set new prompt string
Get/sets the string used as prompt.
- backbuffer_size()
-
$s = $console->backbuffer_size(); # so many lines $console->backbuffer_size(20); # keep 20
Sets the number of lines in the backbuffer, e.g. how many of the last message lines are kept by the console.
- close()
-
$console->close();
- open()
-
$console->open();
- toggle()
-
$console->toggle($current_time);
- visible()
-
$console->visible(); $console->visible(1);
Makes the console immidiately visible or invisible, unlike open(), close() or toggle(), which gradually move the console in or out.
- scroll()
-
$console->scroll(-1); $console->scroll(1); $console->scroll(+2);
Scroll the console'soutput by so many lines up or down (to access the backbuffer via SHIFT+CURSOR_UP, for instance). See also offset().
- offset()
-
my $offset = $console->offset();
Return the current offset. See scroll().
- messages()
-
my $msgs = $console->messages();
Return number of message-lines in backbuffer.
- clear()
-
$console->clear();
Erase all message-lines in the backbuffer, e.g. clear it.
KNOWN BUGS
None yet.
AUTHORS
(c) 2003,2006 Tels <http://bloodgate.com/>
SEE ALSO
Games::3D, SDL:App::FPS, and SDL::OpenGL.