Debian Codegraph @

garglk/style.cpp

raw symbols SCIP
1 // Copyright (C) 2006-2009 by Tor Andersson.
2 //
3 // This file is part of Gargoyle.
4 //
5 // Gargoyle is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // Gargoyle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Gargoyle; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 #include <stdexcept>
20
21 #include "glk.h"
22 #include "garglk.h"
23
24 void glk_stylehint_set(glui32 wintype, glui32 styl, glui32 hint, glsi32 val)
25 {
26 if (!gli_conf_stylehint) {
27 return;
28 }
29
30 if (wintype == wintype_AllTypes) {
31 glk_stylehint_set(wintype_TextGrid, styl, hint, val);
32 glk_stylehint_set(wintype_TextBuffer, styl, hint, val);
33 return;
34 }
35
36 if (wintype != wintype_TextGrid && wintype != wintype_TextBuffer) {
37 return;
38 }
39
40 try {
41 style_t &style = wintype == wintype_TextGrid ? gli_gstyles.at(styl) :
42 gli_tstyles.at(styl);
43
44 switch (hint) {
45 case stylehint_TextColor:
46 style.fg = Color((val >> 16) & 0xff,
47 (val >> 8) & 0xff,
48 (val) & 0xff);
49 break;
50
51 case stylehint_BackColor:
52 style.bg = Color((val >> 16) & 0xff,
53 (val >> 8) & 0xff,
54 (val) & 0xff);
55 break;
56
57 case stylehint_ReverseColor:
58 style.reverse = (val != 0);
59 break;
60
61 case stylehint_Proportional:
62 if (wintype == wintype_TextBuffer) {
63 style.font.monospace = val == 0;
64 }
65 break;
66
67 case stylehint_Weight:
68 style.font.bold = val != 0;
69 break;
70
71 case stylehint_Oblique:
72 style.font.italic = val != 0;
73 break;
74 }
75
76 if (wintype == wintype_TextBuffer &&
77 styl == style_Normal &&
78 hint == stylehint_BackColor) {
79 gli_window_color = style.bg;
80 }
81
82 if (wintype == wintype_TextBuffer &&
83 styl == style_Normal &&
84 hint == stylehint_TextColor) {
85 gli_more_color = style.fg;
86 gli_caret_color = style.fg;
87 }
88 } catch (const std::out_of_range &) {
89 }
90 }
91
92 void glk_stylehint_clear(glui32 wintype, glui32 styl, glui32 hint)
93 {
94 if (!gli_conf_stylehint) {
95 return;
96 }
97
98 if (wintype == wintype_AllTypes) {
99 glk_stylehint_clear(wintype_TextGrid, styl, hint);
100 glk_stylehint_clear(wintype_TextBuffer, styl, hint);
101 return;
102 }
103
104 if (wintype != wintype_TextGrid && wintype != wintype_TextBuffer) {
105 return;
106 }
107
108 try {
109 style_t &style = wintype == wintype_TextGrid ? gli_gstyles.at(styl) :
110 gli_tstyles.at(styl);
111
112 const style_t &def = wintype == wintype_TextGrid ? gli_gstyles_def.at(styl) :
113 gli_tstyles_def.at(styl);
114
115 switch (hint) {
116 case stylehint_TextColor:
117 style.fg = def.fg;
118 break;
119
120 case stylehint_BackColor:
121 style.bg = def.bg;
122 break;
123
124 case stylehint_ReverseColor:
125 style.reverse = def.reverse;
126 break;
127
128 case stylehint_Proportional:
129 case stylehint_Weight:
130 case stylehint_Oblique:
131 style.font = def.font;
132 break;
133 }
134 } catch (const std::out_of_range &) {
135 }
136 }
137
138 glui32 glk_style_distinguish(winid_t win, glui32 styl1, glui32 styl2)
139 {
140 try {
141 if (win->type == wintype_TextGrid) {
142 window_textgrid_t *dwin = win->wingrid();
143 return dwin->styles.at(styl1) != dwin->styles.at(styl2);
144 }
145 if (win->type == wintype_TextBuffer) {
146 window_textbuffer_t *dwin = win->winbuffer();
147 return dwin->styles.at(styl1) != dwin->styles.at(styl2);
148 }
149 } catch (const std::out_of_range &) {
150 }
151
152 return false;
153 }
154
155 glui32 glk_style_measure(winid_t win, glui32 styl, glui32 hint, glui32 *result)
156 {
157 if (win->type != wintype_TextGrid && win->type != wintype_TextBuffer) {
158 return false;
159 }
160
161 try {
162 const style_t &style = win->type == wintype_TextGrid ? win->wingrid()->styles.at(styl) :
163 win->winbuffer()->styles.at(styl);
164
165 switch (hint) {
166 case stylehint_Indentation:
167 case stylehint_ParaIndentation:
168 *result = 0;
169 return true;
170
171 case stylehint_Justification:
172 *result = stylehint_just_LeftFlush;
173 return true;
174
175 case stylehint_Size:
176 *result = 1;
177 return true;
178
179 case stylehint_Weight:
180 *result = style.font.bold;
181 return true;
182
183 case stylehint_Oblique:
184 *result = style.font.italic;
185 return true;
186
187 case stylehint_Proportional:
188 *result = !style.font.monospace;
189 return true;
190
191 case stylehint_TextColor:
192 *result =
193 (style.fg[0] << 16) |
194 (style.fg[1] << 8) |
195 (style.fg[2]);
196 return true;
197
198 case stylehint_BackColor:
199 *result =
200 (style.bg[0] << 16) |
201 (style.bg[1] << 8) |
202 (style.bg[2]);
203 return true;
204
205 case stylehint_ReverseColor:
206 *result = style.reverse;
207 return true;
208 }
209 } catch (const std::out_of_range &) {
210 }
211
212 return false;
213 }