]> icculus.org git repositories - btb/d2x.git/blob - include/console.h
merge console init functions
[btb/d2x.git] / include / console.h
1 /* Console, based on an old version of SDL_Console */
2
3 #ifndef _CONSOLE_H_
4 #define _CONSOLE_H_ 1
5
6 /*! \mainpage
7
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.
12
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.
16
17  Have Fun!
18
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)
23  */
24
25
26 #include "cmd.h"
27 #include "cvar.h"
28 #include "gr.h"
29 #include "key.h"
30
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
53
54 enum {
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
59 };
60
61 /*! This is a struct for the console's 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 #if 0
86         unsigned char ConsoleAlpha;     //! The consoles alpha level
87 #endif
88         int CommandScrollBack;          //! How much the users scrolled back in the command lines
89 }
90 ConsoleInformation;
91
92 /*! Takes keys from the keyboard and inputs them to the console if the console isVisible().
93         If the event was not handled (i.e. WM events or unknown ctrl- or alt-sequences)
94         the function returns the event for further processing. */
95 int CON_Events(int event);
96 /*! Makes the console visible */
97 void CON_Show(void);
98 /*! Hides the console */
99 void CON_Hide(void);
100 /*! Returns 1 if the console is visible, 0 else */
101 int CON_isVisible(void);
102 /*! Draws the console to the screen if it isVisible()*/
103 void CON_DrawConsole(void);
104 /*! Initializes the console */
105 void CON_Init(void);
106 /*! Initializes the graphical console */
107 void CON_InitGFX(int w, int h);
108 /*! printf for the console */
109 void CON_Out(const char *str, ...);
110 /*! Changes the size of the console */
111 int CON_Resize(int x, int y, int w, int h);
112
113
114 /* Priority levels */
115 #define CON_CRITICAL -2
116 #define CON_URGENT   -1
117 #define CON_NORMAL    0
118 #define CON_VERBOSE   1
119 #define CON_DEBUG     2
120
121 void con_printf(int level, char *fmt, ...);
122
123 /* Console CVars */
124 /* How discriminating we are about which messages are displayed */
125 extern cvar_t con_threshold;
126
127
128 #endif /* _CONSOLE_H_ */