MyGUI  3.0.1
MyGUI_RenderOut.cpp
Go to the documentation of this file.
1 
7 /*
8  This file is part of MyGUI.
9 
10  MyGUI is free software: you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  MyGUI is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
22 */
23 
24 #include "MyGUI_Precompiled.h"
25 #include "MyGUI_RenderOut.h"
26 #include "MyGUI_Utility.h"
27 
28 #include "MyGUI_Gui.h"
29 #include "MyGUI_FontManager.h"
30 #include "MyGUI_LayerManager.h"
31 #include "MyGUI_SkinManager.h"
32 #include "MyGUI_StaticText.h"
33 
34 namespace MyGUI
35 {
36  namespace implement
37  {
38 
39  // структура информации об одной строке
40  struct info
41  {
42  info() : num(0), count(1) { }
43  info(size_t _num, const std::string& _line) : num(_num), count(1), line(_line) { }
44 
45  size_t num;
46  size_t count;
47  std::string line;
48  };
49 
50  void render_out(const std::string& _value)
51  {
52  // очередь
53  typedef std::deque<info> DequeInfo;
54 
55  // текущая строка
56  static size_t num = 0;
57  // очередь всех наших строк
58  static DequeInfo lines;
59 
60  const int offset = 10;
61  const size_t count_lines = 20;
62  static const std::string font = "DejaVuSans.14";
63  static const std::string layer = "Statistic";
64  static const std::string skin = "StaticText";
65 
66  static StaticText* widget = nullptr;
67  static StaticText* widget_shadow = nullptr;
68 
69  if (widget == nullptr)
70  {
71  Gui * gui = Gui::getInstancePtr();
72  if (gui == nullptr) return;
73 
74  const IntSize& size = gui->getViewSize();
75 
76  if (!LayerManager::getInstance().isExist(layer)) return;
77  if (!SkinManager::getInstance().isExist(skin)) return;
78 
79 
80  widget_shadow = gui->createWidget<StaticText>(skin, IntCoord(offset + 1, offset + 1, size.width - offset - offset, size.height - offset - offset), Align::Stretch, layer);
81  widget_shadow->setNeedMouseFocus(false);
82  widget_shadow->setTextAlign(Align::Default);
83  widget_shadow->setTextColour(Colour::Black);
84 
85  widget = gui->createWidget<StaticText>(skin, IntCoord(offset, offset, size.width - offset - offset, size.height - offset - offset), Align::Stretch, layer);
86  widget->setNeedMouseFocus(false);
89 
90  if (FontManager::getInstance().getByName(font) != nullptr)
91  {
92  widget_shadow->setFontName(font);
93  widget->setFontName(font);
94  }
95  }
96 
97  // первый раз просто добавляем
98  if (lines.empty())
99  {
100  lines.push_back(info(num++, _value));
101 
102  }
103  // не первый раз мы тут
104  else
105  {
106  // сравниваем последнюю строку
107  if (lines.back().line == _value) lines.back().count ++;
108  else
109  {
110  lines.push_back(info(num++, _value));
111  // удаляем лишнее
112  if (lines.size() > count_lines) lines.pop_front();
113  }
114 
115  }
116 
117  // а вот теперь выводми строки
118  std::string str_out;
119  str_out.reserve(2048);
120 
121  for (DequeInfo::iterator iter=lines.begin(); iter != lines.end(); ++iter)
122  {
123  str_out += utility::toString("[ ", (unsigned int)iter->num, (iter->count > 1) ? (" , " + utility::toString((unsigned int)iter->count)) : "", " ] ", iter->line, "\n");
124  }
125 
126  // непосредственный вывод
127  widget_shadow->setCaption(str_out);
128  widget->setCaption(str_out);
129  }
130  }
131 
132 } // namespace MyGUI