Debian Codegraph @

src/common/gui_printf.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2004 CreepLord ([email protected])
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 #ifdef WIN32_GUI
20
21 #include "common/setup_before.h"
22 #include "gui_printf.h"
23
24 #include <cstdarg>
25 #include <cwchar>
26
27 #include <windows.h>
28 #include <richedit.h>
29
30 #include "common/eventlog.h"
31 #include <common/format.h>
32 #include "common/setup_after.h"
33
34 namespace pvpgn
35 {
36
37 HWND ghwndConsole;
38
39 static void guiAddText(const char *str, COLORREF clr)
40 {
41 int text_length = SendMessageW(ghwndConsole, WM_GETTEXTLENGTH, 0, 0);
42
43 if (text_length > 30000)
44 {
45 CHARRANGE ds = {};
46 ds.cpMin = 0;
47 ds.cpMax = text_length - 30000;
48 SendMessageW(ghwndConsole, EM_EXSETSEL, 0, (LPARAM)&ds);
49 SendMessageW(ghwndConsole, EM_REPLACESEL, FALSE, 0);
50 }
51
52 CHARRANGE cr = {};
53 cr.cpMin = text_length;
54 cr.cpMax = text_length;
55 SendMessageW(ghwndConsole, EM_EXSETSEL, 0, (LPARAM)&cr);
56
57 CHARFORMATW fmt = {};
58 fmt.cbSize = sizeof(CHARFORMATW);
59 fmt.dwMask = CFM_COLOR | CFM_FACE | CFM_SIZE | CFM_BOLD | CFM_ITALIC | CFM_STRIKEOUT | CFM_UNDERLINE;
60 fmt.yHeight = 160;
61 fmt.dwEffects = 0;
62 fmt.crTextColor = clr;
63 std::swprintf(fmt.szFaceName, sizeof fmt.szFaceName / sizeof *fmt.szFaceName, L"%ls", L"Courier New");
64
65 SendMessageW(ghwndConsole, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&fmt);
66 SendMessageA(ghwndConsole, EM_REPLACESEL, FALSE, (LPARAM)str);
67 }
68
69 //template <typename... Args>
70 //void gui_lvprintf(t_eventlog_level l, const char* format, const Args& ... args)
71 void gui_lvprintf(t_eventlog_level l, const char* format, fmt::ArgList args)
72 {
73 COLORREF clr;
74
75 switch (l)
76 {
77 case eventlog_level_none:
78 clr = RGB(0, 0, 0);
79 break;
80 case eventlog_level_trace:
81 clr = RGB(255, 0, 255);
82 break;
83 case eventlog_level_debug:
84 clr = RGB(0, 0, 255);
85 break;
86 case eventlog_level_info:
87 clr = RGB(0, 0, 0);
88 break;
89 case eventlog_level_warn:
90 clr = RGB(255, 128, 64);
91 break;
92 case eventlog_level_error:
93 clr = RGB(255, 0, 0);
94 break;
95 case eventlog_level_fatal:
96 clr = RGB(255, 0, 0);
97 break;
98 default:
99 clr = RGB(0, 0, 0);
100 }
101
102 guiAddText(fmt::format(format, args).c_str(), clr);
103 }
104 }
105 #endif