B15F Board 15 Famulus Edition

view_info.cpp
1 #include "view_info.h"
2
3 ViewInfo::ViewInfo()
4 {
5 calls.push_back(nullptr);
6 }
7
8 void ViewInfo::setText(std::string text)
9 {
10 this->text = text;
11 }
12
13 void ViewInfo::setLabelClose(std::string label)
14 {
15 this->label_close = label;
16 }
17
18 void ViewInfo::setCall(call_t call)
19 {
20 calls[0] = call;
21 }
22
23 void ViewInfo::draw()
24 {
25 int li = 0;
26 for(std::string line : str_split(text, "\n"))
27 mvwprintw(win, text_offset_y + li++, text_offset_x, "%s", line.c_str());
28
29 close_offset_x = (width - label_close.length()) / 2;
30 close_offset_y = height - 2;
31
32 wattron(win, A_REVERSE);
33 mvwprintw(win, close_offset_y, close_offset_x, "%s", label_close.c_str());
34 wattroff(win, A_REVERSE);
35 }
36
37 call_t ViewInfo::keypress(int& key)
38 {
39 switch(key)
40 {
41
42 case KEY_MOUSE:
43 {
44 // http://pronix.linuxdelta.de/C/Linuxprogrammierung/Linuxsystemprogrammieren_C_Kurs_Kapitel10b.shtml
45 MEVENT event;
46 if(getmouse(&event) == OK && event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED))
47 {
48 size_t column = start_x + close_offset_x;
49 size_t row = start_y + close_offset_y;
50 size_t mouse_x = event.x, mouse_y = event.y;
51 if(mouse_y == row && mouse_x >= column && mouse_x < column + label_close.length())
52 key = -1; // do return from view
53 }
54 break;
55 }
56 case KEY_ENT:
57 key = -1; // do return from view
58 break;
59 default:
60 break;
61 }
62 return calls[0];
63 }