rlutil.h | |
Description | This file provides some useful utilities for console mode roguelike game development with C and C++. |
Copyright | © 2010 Tapio Vierros |
Licensing | See License |
Macros | |
RLUTIL_USE_ANSI | Define this to use ANSI escape sequences also on Windows (defaults to using WinAPI instead). |
RLUTIL_STRING_T | Define/typedef this to your preference to override rlutil’s string type. |
Functions | |
getch | Get character without waiting for Return to be pressed. |
kbhit | Determines if keyboard has been hit. |
gotoxy | Same as rlutil.locate. |
rlutil | In C++ all functions except getch, kbhit and gotoxy are arranged under namespace rlutil. |
Macros | |
Internal typedefs and macros | |
Enumerations and Constants | |
Color codes | |
ANSI escape strings | |
Key codes for keyhit() | |
Functions | |
getkey | Reads a key press (blocking) and returns a key code. |
nb_getch | Non-blocking getch(). |
getANSIColor | Return ANSI color escape sequence for specified number 0-15. |
getANSIBackgroundColor | Return ANSI background color escape sequence for specified number 0-15. |
setColor | Change color specified by number (Windows / QBasic colors). |
setBackgroundColor | Change background color specified by number (Windows / QBasic colors). |
saveDefaultColor | Call once to preserve colors for use in resetColor() on Windows without ANSI, no-op otherwise |
resetColor | Reset color to default Requires a call to saveDefaultColor() to set the defaults |
cls | Clears screen, resets all attributes and moves cursor home. |
locate | Sets the cursor position to 1-based x,y. |
setChar | Sets the character at the cursor without advancing the cursor |
hidecursor | Hides the cursor. |
showcursor | Shows the cursor. |
msleep | Waits given number of milliseconds before continuing. |
trows | Get the number of rows in the terminal window or -1 on error. |
tcols | Get the number of columns in the terminal window or -1 on error. |
anykey | Waits until a key is pressed. |
min | Returns the lesser of the two arguments. |
max | Returns the greater of the two arguments. |
CursorHider | RAII OOP wrapper for rlutil.hidecursor. |
See License
RLUTIL_INLINE void gotoxy( int x, int y )
Same as rlutil.locate.
namespace rlutil
In C++ all functions except getch, kbhit and gotoxy are arranged under namespace rlutil. That is because some platforms have them defined outside of rlutil.
Macros | |
Internal typedefs and macros | |
Enumerations and Constants | |
Color codes | |
ANSI escape strings | |
Key codes for keyhit() | |
Functions | |
getkey | Reads a key press (blocking) and returns a key code. |
nb_getch | Non-blocking getch(). |
getANSIColor | Return ANSI color escape sequence for specified number 0-15. |
getANSIBackgroundColor | Return ANSI background color escape sequence for specified number 0-15. |
setColor | Change color specified by number (Windows / QBasic colors). |
setBackgroundColor | Change background color specified by number (Windows / QBasic colors). |
saveDefaultColor | Call once to preserve colors for use in resetColor() on Windows without ANSI, no-op otherwise |
resetColor | Reset color to default Requires a call to saveDefaultColor() to set the defaults |
cls | Clears screen, resets all attributes and moves cursor home. |
locate | Sets the cursor position to 1-based x,y. |
setChar | Sets the character at the cursor without advancing the cursor |
hidecursor | Hides the cursor. |
showcursor | Shows the cursor. |
msleep | Waits given number of milliseconds before continuing. |
trows | Get the number of rows in the terminal window or -1 on error. |
tcols | Get the number of columns in the terminal window or -1 on error. |
anykey | Waits until a key is pressed. |
min | Returns the lesser of the two arguments. |
max | Returns the greater of the two arguments. |
RLUTIL_INLINE RLUTIL_STRING_T getANSIColor( const int c )
Return ANSI color escape sequence for specified number 0-15.
See Color Codes
RLUTIL_INLINE RLUTIL_STRING_T getANSIBackgroundColor( const int c )
Return ANSI background color escape sequence for specified number 0-15.
See Color Codes
RLUTIL_INLINE void setColor( int c )
Change color specified by number (Windows / QBasic colors). Don’t change the background color
See Color Codes
RLUTIL_INLINE void setBackgroundColor( int c )
Change background color specified by number (Windows / QBasic colors). Don’t change the foreground color
See Color Codes
RLUTIL_INLINE int saveDefaultColor()
Call once to preserve colors for use in resetColor() on Windows without ANSI, no-op otherwise
See Color Codes See resetColor
RLUTIL_INLINE void resetColor()
Reset color to default Requires a call to saveDefaultColor() to set the defaults
See Color Codes See setColor See saveDefaultColor
struct CursorHider
RAII OOP wrapper for rlutil.hidecursor. Hides the cursor and shows it again when the object goes out of scope.
Get character without waiting for Return to be pressed.
RLUTIL_INLINE int getch( void )
Determines if keyboard has been hit.
RLUTIL_INLINE int kbhit( void )
Same as rlutil.locate.
RLUTIL_INLINE void gotoxy( int x, int y )
Sets the cursor position to 1-based x,y.
RLUTIL_INLINE void locate( int x, int y )
In C++ all functions except getch, kbhit and gotoxy are arranged under namespace rlutil.
namespace rlutil
Reads a key press (blocking) and returns a key code.
RLUTIL_INLINE int getkey( void )
Non-blocking getch().
RLUTIL_INLINE int nb_getch( void )
Return ANSI color escape sequence for specified number 0-15.
RLUTIL_INLINE RLUTIL_STRING_T getANSIColor( const int c )
Return ANSI background color escape sequence for specified number 0-15.
RLUTIL_INLINE RLUTIL_STRING_T getANSIBackgroundColor( const int c )
Change color specified by number (Windows / QBasic colors).
RLUTIL_INLINE void setColor( int c )
Change background color specified by number (Windows / QBasic colors).
RLUTIL_INLINE void setBackgroundColor( int c )
Call once to preserve colors for use in resetColor() on Windows without ANSI, no-op otherwise
RLUTIL_INLINE int saveDefaultColor()
Reset color to default Requires a call to saveDefaultColor() to set the defaults
RLUTIL_INLINE void resetColor()
Clears screen, resets all attributes and moves cursor home.
RLUTIL_INLINE void cls( void )
Sets the character at the cursor without advancing the cursor
RLUTIL_INLINE void setChar( char ch )
Hides the cursor.
RLUTIL_INLINE void hidecursor( void )
Shows the cursor.
RLUTIL_INLINE void showcursor( void )
Waits given number of milliseconds before continuing.
RLUTIL_INLINE void msleep( unsigned int ms )
Get the number of rows in the terminal window or -1 on error.
RLUTIL_INLINE int trows( void )
Get the number of columns in the terminal window or -1 on error.
RLUTIL_INLINE int tcols( void )
Waits until a key is pressed.
#ifdef __cplusplus RLUTIL_INLINE void anykey()
Returns the lesser of the two arguments.
#ifdef __cplusplus template <class T> const T& min ( const T & a, const T & b )
Returns the greater of the two arguments.
#ifdef __cplusplus template <class T> const T& max ( const T & a, const T & b )
RAII OOP wrapper for rlutil.hidecursor.
struct CursorHider