Branch data Line data Source code
1 : : #ifndef bqtCellHH
2 : : #define bqtCellHH
3 : : /** @file rendering/cell.hh
4 : : * @brief Defines Cell, the structure that represents a character on screen.
5 : : */
6 : : #include <cstdint>
7 : : #include <cstring>
8 : :
9 : : /** Elements in a screen buffer are called cells.
10 : : * Cell is a structure that can be memcpy'd verbatim.
11 : : * Its properties can be assigned and read directly.
12 : : *
13 : : * It includes:
14 : : *
15 : : * ch The character code (unicode character index)
16 : : * fgcolor The foreground color (RGB)
17 : : * bgcolor The background color (RGB)
18 : : *
19 : : * Attributes, defined as in SGR of ANSI:
20 : : *
21 : : * bold, dim, italic, underline, underline2,
22 : : * overstrike, inverse, framed, encircled,
23 : : * overlined, fraktur, conceal, proportional,
24 : : * ideo_underline, ideo_underline2, ideo_overline,
25 : : * ideo_stress
26 : : * render_size: 0=normal,1=doublewidth,2=doublewidth+topline,3=doublewidth+bottomline
27 : : * blink: 0=none, 1=blink, 2=faster blink, 3=undefined
28 : : * scriptsize: 0=normal, 1=superscript, 2=subscript
29 : : * protect (protected-flag as in ANSI)
30 : : *
31 : : * And a dirty-flag, used by screen renderer.
32 : : *
33 : : * Attributes and flags are defined as bit fields
34 : : * with attention to alignment and total size of structure.
35 : : *
36 : : * Constructor and comparison operators are inlined for performance.
37 : : */
38 : : struct Cell
39 : : {
40 : : // 24-bit color foreground,background = 48 bits total
41 : : // 32-bit character
42 : : std::uint_least32_t fgcolor; ///< foreground color
43 : : std::uint_least32_t bgcolor; ///< background color
44 : : char32_t ch; ///< the character symbol (unicode codepoint)
45 : : bool bold: 1; ///< bit 0
46 : : bool dim: 1; ///< bit 1
47 : : bool italic: 1; ///< bit 2
48 : : bool underline: 1; ///< bit 3
49 : : bool underline2: 1; ///< bit 4
50 : : bool overstrike: 1; ///< bit 5
51 : : bool inverse: 1; ///< bit 6
52 : : bool framed: 1; ///< bit 7
53 : : bool encircled: 1; ///< bit 8
54 : : bool overlined: 1; ///< bit 9
55 : : bool fraktur: 1; ///< bit 10
56 : : bool conceal: 1; ///< bit 11
57 : : unsigned char render_size: 2; ///< bit 12-13 0=normal,1=doublewidth,2=doublewidth+topline,3=doublewidth+bottomline
58 : : unsigned char blink: 2; ///< bit 14-15
59 : :
60 : : unsigned char scriptsize: 2; ///< bit 16-17: 0=normal,1=superscript,2=subscript
61 : : bool proportional: 1; ///< bit 18
62 : : bool ideo_underline: 1; ///< bit 19
63 : : bool ideo_underline2: 1; ///< bit 20
64 : : bool ideo_overline: 1; ///< bit 21
65 : : bool ideo_overline2: 1; ///< bit 22
66 : : bool ideo_stress: 1; ///< bit 23
67 : : unsigned padding: 6; ///< bit 24,25,26, 27,28,29
68 : :
69 : : bool protect: 1; ///< bit 30
70 : : bool dirty: 1; ///< bit 31 (placed last for efficient access)
71 : :
72 : : /* Total size: 4 * 32 bits = 128 bits (16 bytes) */
73 : :
74 : : /* Constructor: Initializes the object with default attributes.
75 : : * Sets the character as a space, color as light-gray on black, and the dirty flag.
76 : : */
77 : 1319118 : Cell()
78 : 1319118 : {
79 : 1319118 : std::memset(this, 0, sizeof(Cell));
80 : 1319118 : fgcolor = 0xCCCCCC;
81 : 1319118 : bgcolor = 0x000000;
82 : 1319118 : ch = U' ';
83 : 1319118 : dirty = true;
84 : 1319118 : }
85 : :
86 : : /** operator==: Equality comparison
87 : : * Compares everything except dirty and protect.
88 : : * @param b The other cell to compare against.
89 : : * @returns True if the cells are equivalent.
90 : : */
91 : 781690 : bool operator== (const Cell& b) const
92 : : {
93 : 781690 : Cell tmp1 = *this;
94 : 781690 : Cell tmp2 = b;
95 : 781690 : tmp1.dirty = false; tmp1.protect = false;
96 : 781690 : tmp2.dirty = false; tmp2.protect = false;
97 : 781690 : return std::memcmp(&tmp1, &tmp2, sizeof(Cell)) == 0;
98 : : /*
99 : : return std::tuple(fgcolor,bgcolor,ch,bold,dim,italic,
100 : : underline,underline2,overstrike,inverse,blink,
101 : : framed,encircled,fraktur,conceal,overlined,
102 : : scriptsize,proportional,
103 : : ideo_underline,ideo_underline2,ideo_overline,ideo_overline2,ideo_stress,
104 : : render_size)
105 : : == std::tuple(b.fgcolor,b.bgcolor,b.ch,b.bold,b.dim,b.italic,
106 : : b.underline,b.underline2,b.overstrike,b.inverse,b.blink,
107 : : b.framed,b.encircled,b.fraktur,b.conceal,b.overlined,
108 : : b.scriptsize,b.proportional,
109 : : b.ideo_underline,b.ideo_underline2,b.ideo_overline,b.ideo_overline2,b.ideo_stress,
110 : : b.render_size);
111 : : */
112 : : }
113 : :
114 : : /** operator!=. Simply inverses operator==.
115 : : * @param b The other cell to compare against.
116 : : * @returns True if the cells are not equivalent.
117 : : */
118 : 765379 : bool operator!= (const Cell& b) const
119 : : {
120 [ + + - + : 765379 : return !operator==(b);
+ + ]
121 : : }
122 : : };
123 : :
124 : : #endif
|