1 /* Console, based on an old version of SDL_Console */
8 \section intro Introduction
9 SDL_Console is a console that can be added to any SDL application. It is similar to Quake and other games consoles.
10 A console is meant to be a very simple way of interacting with a program and executing commands. You can also have
11 more than one console at a time.
13 \section docs Documentation
14 For a detailed description of all functions see \ref CON_console.h. Remark that functions that have the mark "Internal"
15 are only used internally. There's not much use of calling these functions.
19 \author Garett Banuk <mongoose@mongeese.org> (Original Version)
20 \author Clemens Wacha <reflex-2000@gmx.net> (Version 2.x, Documentation)
21 \author Boris Lesner <talanthyr@tuxfamily.org> (Package Maintainer)
22 \author Bradley Bell <btb@icculus.org> (Descent Version)
31 //! Cut the buffer line if it becomes longer than this
32 #define CON_CHARS_PER_LINE 128
33 //! Cursor blink frequency in ms
34 #define CON_BLINK_RATE 500
35 //! Border in pixels from the most left to the first letter
36 #define CON_CHAR_BORDER 4
37 //! Spacing in pixels between lines
38 #define CON_LINE_SPACE 1
39 //! Default prompt used at the commandline
40 #define CON_DEFAULT_PROMPT "]"
41 //! Scroll this many lines at a time (when pressing PGUP or PGDOWN)
42 #define CON_LINE_SCROLL 2
43 //! Indicator showing that you scrolled up the history
44 #define CON_SCROLL_INDICATOR "^"
45 //! Cursor shown if we are in insert mode
46 #define CON_INS_CURSOR "_"
47 //! Cursor shown if we are in overwrite mode
48 #define CON_OVR_CURSOR "|"
49 //! Defines the default hide key (Hide() the console if pressed)
50 #define CON_DEFAULT_HIDEKEY KEY_ESC
51 //! Defines the opening/closing speed
52 #define CON_OPENCLOSE_SPEED 50
55 CON_CLOSED, //! The console is closed (and not shown)
56 CON_CLOSING, //! The console is still open and visible but closing
57 CON_OPENING, //! The console is visible and opening but not yet fully open
58 CON_OPEN //! The console is open and visible
61 /*! This is a struct for each consoles data */
62 typedef struct console_information_td {
63 int Visible; //! enum that tells which visible state we are in CON_HIDE, CON_SHOW, CON_RAISE, CON_LOWER
64 int RaiseOffset; //! Offset used when scrolling in the console
65 int HideKey; //! the key that can hide the console
66 char **ConsoleLines; //! List of all the past lines
67 char **CommandLines; //! List of all the past commands
68 int TotalConsoleLines; //! Total number of lines in the console
69 int ConsoleScrollBack; //! How much the user scrolled back in the console
70 int TotalCommands; //! Number of commands in the Back Commands
71 int LineBuffer; //! The number of visible lines in the console (autocalculated)
72 int VChars; //! The number of visible characters in one console line (autocalculated)
73 char* Prompt; //! Prompt displayed in command line
74 char Command[CON_CHARS_PER_LINE]; //! current command in command line = lcommand + rcommand
75 char RCommand[CON_CHARS_PER_LINE]; //! left hand side of cursor
76 char LCommand[CON_CHARS_PER_LINE]; //! right hand side of cursor
77 char VCommand[CON_CHARS_PER_LINE]; //! current visible command line
78 int CursorPos; //! Current cursor position in CurrentCommand
79 int Offset; //! CommandOffset (first visible char of command) - if command is too long to fit into console
80 int InsMode; //! Insert or Overwrite characters?
81 grs_canvas *ConsoleSurface; //! Canvas of the console
82 grs_screen *OutputScreen; //! This is the screen to draw the console to
83 grs_bitmap *BackgroundImage; //! Background image for the console
84 grs_bitmap *InputBackground; //! Dirty rectangle to draw over behind the users background
85 int DispX, DispY; //! The top left x and y coords of the console on the display screen
87 unsigned char ConsoleAlpha; //! The consoles alpha level
89 int CommandScrollBack; //! How much the users scrolled back in the command lines
93 /*! Takes keys from the keyboard and inputs them to the console if the console isVisible().
94 If the event was not handled (i.e. WM events or unknown ctrl- or alt-sequences)
95 the function returns the event for further processing. */
96 int CON_Events(int event);
97 /*! Makes the console visible */
99 /*! Hides the console */
101 /*! Returns 1 if the console is visible, 0 else */
102 int CON_isVisible(void);
103 /*! Draws the console to the screen if it isVisible()*/
104 void CON_DrawConsole(void);
105 /*! Initializes a new console */
106 ConsoleInformation *CON_Init(grs_font *Font, grs_screen *DisplayScreen, int lines, int x, int y, int w, int h);
107 /*! printf for the console */
108 void CON_Out(const char *str, ...);
109 /*! Changes the size of the console */
110 int CON_Resize(int x, int y, int w, int h);
113 /* Priority levels */
114 #define CON_CRITICAL -2
115 #define CON_URGENT -1
117 #define CON_VERBOSE 1
121 void con_init_gfx(void);
122 void con_resize(void);
123 void con_printf(int level, char *fmt, ...);
126 /* How discriminating we are about which messages are displayed */
127 extern cvar_t con_threshold;
130 #endif /* _CONSOLE_H_ */