Apply the new ground_level method.
[crawl.git] / crawl-ref / source / format.h
bloba490e14762651403c7f6a4d5875f75a3d99d6a6d
1 /*
2 * File: format.h
3 * Created by: haranp on Sat Feb 17 13:35:54 2007 UTC
4 */
6 #ifndef __FORMAT_H__
7 #define __FORMAT_H__
9 #include <string>
10 #include <vector>
12 #include "externs.h"
14 // Definitions for formatted_string
16 enum fs_op_type
18 FSOP_COLOUR,
19 FSOP_TEXT,
22 class formatted_string
24 public:
25 formatted_string(int init_colour = 0);
26 explicit formatted_string(const std::string &s, int init_colour = 0);
28 operator std::string() const;
29 void display(int start = 0, int end = -1) const;
30 std::string tostring(int start = 0, int end = -1) const;
31 std::string to_colour_string() const;
33 void cprintf(const char *s, ...);
34 void cprintf(const std::string &s);
35 void add_glyph(glyph g);
36 void textcolor(int color);
37 formatted_string substr(size_t index, size_t length=std::string::npos) const;
38 void all_caps();
40 void clear();
41 bool empty();
43 void swap(formatted_string& other);
45 std::string::size_type length() const;
46 std::string html_dump() const;
48 bool operator < (const formatted_string &other) const;
49 const formatted_string &operator += (const formatted_string &other);
50 char &operator [] (size_t idx);
52 public:
53 static formatted_string parse_string(
54 const std::string &s,
55 bool eot_ends_format = true,
56 bool (*process_tag)(const std::string &tag) = NULL,
57 int main_colour = LIGHTGREY);
59 static void parse_string_to_multiple(
60 const std::string &s,
61 std::vector<formatted_string> &out);
63 static int get_colour(const std::string &tag);
65 private:
66 int find_last_colour() const;
68 static void parse_string1(
69 const std::string &s,
70 formatted_string &fs,
71 std::vector<int> &colour_stack,
72 bool (*process_tag)(const std::string &tag));
74 public:
75 struct fs_op
77 fs_op_type type;
78 int x, y;
79 bool relative;
80 std::string text;
82 fs_op(int color)
83 : type(FSOP_COLOUR), x(color), y(-1), relative(false), text()
87 fs_op(const std::string &s)
88 : type(FSOP_TEXT), x(-1), y(-1), relative(false), text(s)
92 operator fs_op_type () const
94 return type;
96 void display() const;
99 typedef std::vector<fs_op> oplist;
100 oplist ops;
103 int count_linebreaks(const formatted_string& fs);
105 int tagged_string_tag_length(const std::string& s);
106 int tagged_string_printable_length(const std::string& s);
107 std::string tagged_string_substr(const std::string& s, int start, int end);
108 void display_tagged_block(const std::string& s);
110 #endif