SDL Window Engine  20200905
swe_cunicode_color.h
1 /***************************************************************************
2  * Copyright (C) 2017 by SWE team <sdl.window.engine@gmail.com> *
3  * *
4  * Part of the SWE: SDL Window Engine: *
5  * https://github.com/AndreyBarmaley/sdl-window-engine *
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program; if not, write to the *
19  * Free Software Foundation, Inc., *
20  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  ***************************************************************************/
22 
23 #ifndef _SWE_UNICODE_COLOR_
24 #define _SWE_UNICODE_COLOR_
25 
26 #include <utility>
27 
28 #include "swe_colors.h"
29 #include "swe_cunicode.h"
30 
32 namespace SWE
33 {
35  class UnicodeColor : std::pair<FBColors, u16> /* bg col 8 bit, fg col 8 bit, sym 16 bit */
36  {
37  public:
38  UnicodeColor();
39  UnicodeColor(int sym, const Color & cl);
40  UnicodeColor(int sym, const FBColors & fbc);
41 
42  bool operator< (const UnicodeColor &) const;
43  bool operator> (const UnicodeColor &) const;
44  bool operator== (const UnicodeColor &) const;
45  bool operator!= (const UnicodeColor &) const;
46 
47  bool isUnicode(int uc) const;
48  int unicode(void) const;
49  const FBColors & colors(void) const;
50  int value(void) const;
51 
52  ColorIndex fgindex(void) const;
53  ColorIndex bgindex(void) const;
54  Color fgcolor(void) const;
55  Color bgcolor(void) const;
56 
57  void unicode(int sym);
58  void colors(const FBColors &);
59  void fgindex(const ColorIndex &);
60  void bgindex(const ColorIndex &);
61  };
62 
63  class UCStringList;
64  class FontRender;
65 
67  class UCString : protected std::vector<UnicodeColor>
68  {
69  FBColors defcols;
70 
71  protected:
72  UCString(const_iterator it1, const_iterator it2);
73 
74  public:
75  UCString(const FBColors & fbc = FBColors(Color::Black));
76  UCString(const UnicodeString &, const FBColors & fbc = FBColors(Color::Black));
77  UCString(const UnicodeString &, const ColorIndex &);
78  UCString(const std::vector<UnicodeColor> & v);
79  UCString(const UCString & v);
80  UCString(UCString && v) noexcept;
81 
82  UCString & operator= (const UCString & v);
83  UCString & operator= (UCString && v) noexcept;
84 
85  UCString & operator<< (const FBColors &);
86  UCString & operator<< (const ColorIndex &);
87  UCString & operator<< (const UnicodeString &);
88  UCString & operator<< (const UnicodeColor &);
89  UCString & operator<< (const UCString &);
90 
91  void assign(const UnicodeString &, const FBColors &);
92  UCString & append(const UCString &);
93  UCStringList split(int sep) const;
94  UCStringList splitWidth(const FontRender &, int width) const;
95  UCStringList wrap(int) const;
96 
97  int index(int) const;
98  UCString substr(size_t pos, int len = -1) const;
99  UnicodeString toUnicodeString(void) const;
100  std::string toString(void) const;
101 
102  static UCString parseUnicode(const UnicodeString &, FBColors def = FBColors());
103 
104  UnicodeColor at(size_t) const;
105  size_t length(void) const;
106  size_t size(void) const;
107  };
108 
110  class UCStringList : public std::list<UCString>
111  {
112  public:
113  UCStringList();
114  UCStringList(const UnicodeList & ul, const FBColors & fbc);
115  UCStringList(const UnicodeList & ul, const ColorIndex & col);
116  UCStringList(const std::list<UCString> & v);
117  UCStringList(const UCStringList & v);
118  UCStringList(UCStringList && v) noexcept;
119 
120  UCStringList & operator= (const UCStringList & v);
121  UCStringList & operator= (UCStringList && v) noexcept;
122 
123  size_t maxStringWidth(void) const;
124  size_t totalStringsWidth(void) const;
125 
126  UCString join(void) const;
127  UCString join(const UCString &) const;
128 
129  UCStringList & append(const UCString &);
130  UCStringList & append(const UnicodeList &, const FBColors &);
131  UCStringList & append(const UnicodeList &, const ColorIndex &);
132  UCStringList & append(const UCStringList &);
133 
134  UCStringList & operator<< (const UCString &);
135  UCStringList & operator<< (const UCStringList &);
136  };
137 
138 } // SWE
139 #endif
класс пары двух цветов (foreground, background)
Definition: swe_colors.h:136
пространство SWE.
Definition: swe_binarybuf.cpp:30
класс цветной unicode строки
Definition: swe_cunicode_color.h:67
класс списка unicode строк
Definition: swe_cunicode.h:109
класс цвета
Definition: swe_colors.h:65
базовый класс шрифта
Definition: swe_fontset.h:151
класс индекса цвета
Definition: swe_colors.h:113
класс список цветных unicode строк
Definition: swe_cunicode_color.h:110
класс цветного unicode символа
Definition: swe_cunicode_color.h:35
класс unicode строки
Definition: swe_cunicode.h:41