vrheights

view src/console.h @ 16:7f6d68d95c22

updated to new version of goatvr
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 30 Oct 2015 06:34:31 +0200
parents
children
line source
1 #ifndef CONSOLE_H_
2 #define CONSOLE_H_
4 #include <vector>
5 #include <list>
6 #include <string>
7 #include <functional>
8 #include <drawtext.h>
10 #define INPUTQ_SIZE 64
12 class Console {
13 public:
14 enum Anchor {TOP_LEFT, BOTTOM_LEFT, CENTER};
16 private:
17 bool visible;
18 int nlines, ncolumns;
19 int pos_x, pos_y;
20 Anchor anchor;
22 int inpq_front, inpq_back;
23 int keybuf[INPUTQ_SIZE];
25 std::string prompt;
26 std::string input; // current input line
27 int cursor;
28 int input_win; // first character to show in the input "window"
30 // input history
31 int max_hist_lines;
32 std::list<std::string> hist;
33 bool hist_iter_valid;
34 std::list<std::string>::const_reverse_iterator hist_iter;
36 // console output
37 int max_output_lines;
38 std::vector<std::string> output;
39 bool echo;
41 std::function<void (const char*)> cmd_handler;
43 int font_size;
44 dtx_font *font;
46 void set_cursor(int x);
47 int get_cursor() const;
49 public:
50 enum {
51 KEY_LEFT = 256,
52 KEY_RIGHT,
53 KEY_UP, KEY_DOWN,
54 KEY_INS,
55 KEY_DEL,
56 KEY_HOME,
57 KEY_END,
58 KEY_PGUP,
59 KEY_PGDOWN
60 };
62 Console();
64 void set_font(dtx_font *font, int sz);
65 void set_history_size(int hsz);
66 void set_output_buffer_size(int sz);
67 void set_command_func(std::function<void (const char*)> func);
69 void set_echo(bool echo);
70 bool get_echo() const;
72 void show() { set_visible(true); }
73 void hide() { set_visible(false); }
74 void set_visible(bool v);
75 bool is_visible() const;
77 void set_size(int lines, int columns = 80);
78 int get_size_lines() const;
79 int get_size_columns() const;
81 void set_position(int x, int y, Anchor anchor = TOP_LEFT);
83 // update returns true if what it did makes a redraw necessary
84 bool update();
85 void draw() const;
87 void input_key(int key); // send a keystroke to the console
89 void putchar(char c);
90 void puts(const char *str);
91 void printf(const char *fmt, ...);
93 void debug();
94 };
96 #endif // CONSOLE_H_