1 #pragma once
2 #ifndef CATA_SRC_CURSESPORT_H
3 #define CATA_SRC_CURSESPORT_H
4 
5 #include <utility>
6 #if defined(TILES) || defined(_WIN32)
7 
8 #include <array>
9 #include <string>
10 #include <vector>
11 
12 #include "point.h"
13 
14 namespace catacurses
15 {
16 class window;
17 
18 enum base_color : short;
19 } // namespace catacurses
20 
21 /**
22  * Contains our own curses implementation.
23  * Don't use it in the game itself, use only function of @ref catacurses.
24  * Functions declared here are *not* defined in ncurses builds.
25  */
26 namespace cata_cursesport
27 {
28 using base_color = catacurses::base_color;
29 
30 //a pair of colors[] indexes, foreground and background
31 struct pairs {
32     base_color FG;
33     base_color BG;
34 };
35 
36 //Individual lines, so that we can track changed lines
37 struct cursecell {
38     std::string ch;
39     base_color FG = static_cast<base_color>( 0 );
40     base_color BG = static_cast<base_color>( 0 );
41 
cursecellcursecell42     explicit cursecell( std::string ch ) : ch( std::move( ch ) ) { }
cursecellcursecell43     cursecell() : cursecell( std::string( 1, ' ' ) ) { }
44 
45     bool operator==( const cursecell &b ) const {
46         return FG == b.FG && BG == b.BG && ch == b.ch;
47     }
48 };
49 
50 struct curseline {
51     bool touched;
52     std::vector<cursecell> chars;
53 };
54 
55 // The curses window struct
56 struct WINDOW {
57     // Top-left corner of window
58     point pos;
59     int width;
60     int height;
61     // Current foreground color from attron
62     base_color FG;
63     // Current background color from attron
64     base_color BG;
65     // Does this window actually exist?
66     bool inuse;
67     // Tracks if the window text has been changed
68     bool draw;
69     point cursor;
70     std::vector<curseline> line;
71 };
72 
73 extern std::array<pairs, 100> colorpairs;
74 void curses_drawwindow( const catacurses::window &win );
75 
76 // Allow extra logic for framebuffer clears
77 extern void handle_additional_window_clear( WINDOW *win );
78 
79 } // namespace cata_cursesport
80 
81 // TODO: move into cata_cursesport
82 // Used only in SDL mode for clearing windows using rendering
83 void clear_window_area( const catacurses::window &win );
84 int projected_window_width();
85 int projected_window_height();
86 bool handle_resize( int w, int h );
87 void resize_term( int cell_w, int cell_h );
88 int get_scaling_factor();
89 
90 #endif
91 #endif // CATA_SRC_CURSESPORT_H
92 
93