mudgangster

Tiny, scriptable MUD client
Log | Files | Refs | README

textbox.h (1223B)


      1 #pragma once
      2 
      3 #include "ui.h"
      4 
      5 constexpr size_t MAX_LINE_LENGTH = 2048;
      6 constexpr size_t SCROLLBACK_SIZE = 1 << 14;
      7 
      8 struct TextBox {
      9 	struct Glyph {
     10 		char ch;
     11 		u8 style;
     12 	};
     13 
     14 	struct Line {
     15 		Glyph glyphs[ MAX_LINE_LENGTH ];
     16 		size_t len;
     17 	};
     18 
     19 	Span< Line > lines;
     20 	size_t head;
     21 	size_t num_lines;
     22 	size_t max_lines;
     23 
     24 	int x, y;
     25 	int w, h;
     26 	size_t scroll_offset;
     27 
     28 	bool selecting;
     29 	bool selecting_and_mouse_moved;
     30 	bool scroll_down_after_selecting;
     31 	int selection_start_col, selection_start_row;
     32 	int selection_end_col, selection_end_row;
     33 
     34 	bool dirty;
     35 };
     36 
     37 void textbox_init( TextBox * tb, size_t scrollback );
     38 
     39 void textbox_add( TextBox * tb, const char * str, size_t len, Colour fg, Colour bg, bool bold );
     40 void textbox_newline( TextBox * tb );
     41 
     42 void textbox_scroll( TextBox * tb, int offset );
     43 void textbox_page_down( TextBox * tb );
     44 void textbox_page_up( TextBox * tb );
     45 
     46 void textbox_mouse_down( TextBox * tb, int x, int y );
     47 void textbox_mouse_move( TextBox * tb, int x, int y );
     48 void textbox_mouse_up( TextBox * tb, int x, int y );
     49 
     50 void textbox_set_pos( TextBox * tb, int x, int y );
     51 void textbox_set_size( TextBox * tb, int w, int h );
     52 
     53 void textbox_draw( TextBox * tb );
     54 
     55 void textbox_destroy( TextBox * tb );