MyGUI
3.0.3
|
00001 00007 /* 00008 This file is part of MyGUI. 00009 00010 MyGUI is free software: you can redistribute it and/or modify 00011 it under the terms of the GNU Lesser General Public License as published by 00012 the Free Software Foundation, either version 3 of the License, or 00013 (at your option) any later version. 00014 00015 MyGUI is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU Lesser General Public License for more details. 00019 00020 You should have received a copy of the GNU Lesser General Public License 00021 along with MyGUI. If not, see <http://www.gnu.org/licenses/>. 00022 */ 00023 00024 #include "MyGUI_Precompiled.h" 00025 #include "MyGUI_RenderOut.h" 00026 #include "MyGUI_Utility.h" 00027 00028 #include "MyGUI_Gui.h" 00029 #include "MyGUI_FontManager.h" 00030 #include "MyGUI_LayerManager.h" 00031 #include "MyGUI_SkinManager.h" 00032 #include "MyGUI_StaticText.h" 00033 00034 namespace MyGUI 00035 { 00036 namespace implement 00037 { 00038 00039 // структура информации об одной строке 00040 struct info 00041 { 00042 info() : num(0), count(1) { } 00043 info(size_t _num, const std::string& _line) : num(_num), count(1), line(_line) { } 00044 00045 size_t num; 00046 size_t count; 00047 std::string line; 00048 }; 00049 00050 void render_out(const std::string& _value) 00051 { 00052 // очередь 00053 typedef std::deque<info> DequeInfo; 00054 00055 // текущая строка 00056 static size_t num = 0; 00057 // очередь всех наших строк 00058 static DequeInfo lines; 00059 00060 const int offset = 10; 00061 const size_t count_lines = 20; 00062 static const std::string font = "DejaVuSans.14"; 00063 static const std::string layer = "Statistic"; 00064 static const std::string skin = "StaticText"; 00065 00066 static StaticText* widget = nullptr; 00067 static StaticText* widget_shadow = nullptr; 00068 00069 if (widget == nullptr) 00070 { 00071 Gui * gui = Gui::getInstancePtr(); 00072 if (gui == nullptr) return; 00073 00074 const IntSize& size = gui->getViewSize(); 00075 00076 if (!LayerManager::getInstance().isExist(layer)) return; 00077 if (!SkinManager::getInstance().isExist(skin)) return; 00078 00079 00080 widget_shadow = gui->createWidget<StaticText>(skin, IntCoord(offset + 1, offset + 1, size.width - offset - offset, size.height - offset - offset), Align::Stretch, layer); 00081 widget_shadow->setNeedMouseFocus(false); 00082 widget_shadow->setTextAlign(Align::Default); 00083 widget_shadow->setTextColour(Colour::Black); 00084 00085 widget = gui->createWidget<StaticText>(skin, IntCoord(offset, offset, size.width - offset - offset, size.height - offset - offset), Align::Stretch, layer); 00086 widget->setNeedMouseFocus(false); 00087 widget->setTextAlign(Align::Default); 00088 widget->setTextColour(Colour::White); 00089 00090 if (FontManager::getInstance().getByName(font) != nullptr) 00091 { 00092 widget_shadow->setFontName(font); 00093 widget->setFontName(font); 00094 } 00095 } 00096 00097 // первый раз просто добавляем 00098 if (lines.empty()) 00099 { 00100 lines.push_back(info(num++, _value)); 00101 00102 } 00103 // не первый раз мы тут 00104 else 00105 { 00106 // сравниваем последнюю строку 00107 if (lines.back().line == _value) lines.back().count ++; 00108 else 00109 { 00110 lines.push_back(info(num++, _value)); 00111 // удаляем лишнее 00112 if (lines.size() > count_lines) lines.pop_front(); 00113 } 00114 00115 } 00116 00117 // а вот теперь выводми строки 00118 std::string str_out; 00119 str_out.reserve(2048); 00120 00121 for (DequeInfo::iterator iter=lines.begin(); iter != lines.end(); ++iter) 00122 { 00123 str_out += utility::toString("[ ", (unsigned int)iter->num, (iter->count > 1) ? (" , " + utility::toString((unsigned int)iter->count)) : "", " ] ", iter->line, "\n"); 00124 } 00125 00126 // непосредственный вывод 00127 widget_shadow->setCaption(str_out); 00128 widget->setCaption(str_out); 00129 } 00130 } 00131 00132 } // namespace MyGUI