-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathFl_Trace_Window.h
More file actions
66 lines (59 loc) · 1.9 KB
/
Fl_Trace_Window.h
File metadata and controls
66 lines (59 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#pragma once
#include <FL/Fl.H>
#include <FL/Fl_Text_Display.H>
#include <FL/Fl_Window.H>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <sstream>
class Fl_Trace_Window : public Fl_Window {
public:
Fl_Trace_Window() : Fl_Window {0, 0, "Debug"} {
resizable(this);
auto screen_num = Fl::screen_num(x(), y());
auto screen_x = 0, screen_y = 0, screen_width = 0, screen_height = 0;
Fl::screen_xywh(screen_x, screen_y, screen_width, screen_height);
resize(screen_x, screen_y + (screen_height / 5 * 4), screen_width, screen_height / 5);
text_display.buffer(&text_buffer);
#if defined(TRACE)
show();
#endif
}
void append(const char* value) noexcept {
#if defined(TRACE)
if (need_header) write_header();
text_buffer.append(value);
std::cerr << value;
text_display.scroll(text_buffer.count_lines(0, text_buffer.length()), 0);
#endif
}
void append_line(const char* value) noexcept {
#if defined(TRACE)
if (need_header) write_header();
text_buffer.append(value);
std::cerr << value;
text_buffer.append("\n");
std::cerr << std::endl;
text_display.scroll(text_buffer.count_lines(0, text_buffer.length()), 0);
need_header = true;
#endif
}
void hide() noexcept override {iconize();}
void resize(int x, int y, int width, int height) noexcept override {
Fl_Window::resize(x, y, width, height);
text_display.resize(0, 0, w(), h());
}
private:
void write_header() noexcept {
auto current_time = time(nullptr);
auto current_tm = localtime(¤t_time);
auto ss = std::stringstream {};
ss << std::put_time(current_tm, "%Y-%m-%d %H:%M:%S - ");
text_buffer.append(ss.str().c_str());
std::cerr << ss.str();
need_header = false;
}
bool need_header = true;
Fl_Text_Buffer text_buffer;
Fl_Text_Display text_display {0, 0, 0, 0};
};