• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

MyGUI_RenderOut.cpp

Go to the documentation of this file.
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 StaticTextPtr widget = nullptr;
00067             static StaticTextPtr widget_shadow = nullptr;
00068 
00069             if (widget == nullptr) {
00070                 Gui * gui = Gui::getInstancePtr();
00071                 if (gui == nullptr) return;
00072 
00073                 const IntSize& size = gui->getViewSize();
00074 
00075                 if (!LayerManager::getInstance().isExist(layer)) return;
00076                 if (!SkinManager::getInstance().isExist(skin)) return;
00077 
00078 
00079                 widget_shadow = gui->createWidget<StaticText>(skin, IntCoord(offset + 1, offset + 1, size.width - offset - offset, size.height - offset - offset), Align::Stretch, layer);
00080                 widget_shadow->setNeedMouseFocus(false);
00081                 widget_shadow->setTextAlign(Align::Default);
00082                 widget_shadow->setTextColour(Colour::Black);
00083 
00084                 widget = gui->createWidget<StaticText>(skin, IntCoord(offset, offset, size.width - offset - offset, size.height - offset - offset), Align::Stretch, layer);
00085                 widget->setNeedMouseFocus(false);
00086                 widget->setTextAlign(Align::Default);
00087                 widget->setTextColour(Colour::White);
00088 
00089                 if (FontManager::getInstance().getByName(font) != nullptr)
00090                 {
00091                     widget_shadow->setFontName(font);
00092                     widget->setFontName(font);
00093                 }
00094             }
00095 
00096             if (lines.empty()) { // первый раз просто добавляем
00097                 lines.push_back(info(num++, _value));
00098 
00099             }
00100             else { // не первый раз мы тут
00101                 // сравниваем последнюю строку
00102                 if (lines.back().line == _value) lines.back().count ++;
00103                 else {
00104                     lines.push_back(info(num++, _value));
00105                     // удаляем лишнее
00106                     if (lines.size() > count_lines) lines.pop_front();
00107                 }
00108 
00109             }
00110 
00111             // а вот теперь выводми строки
00112             std::string str_out;
00113             str_out.reserve(2048);
00114 
00115             for (DequeInfo::iterator iter=lines.begin(); iter != lines.end(); ++iter) {
00116                 str_out += utility::toString("[ ", (unsigned int)iter->num, (iter->count > 1) ? (" , " + utility::toString((unsigned int)iter->count)) : "", " ]  ", iter->line, "\n");
00117             }
00118 
00119             // непосредственный вывод
00120             widget_shadow->setCaption(str_out);
00121             widget->setCaption(str_out);
00122         }
00123     }
00124 
00125 } // namespace MyGUI

Generated on Sun Jan 30 2011 for MyGUI by  doxygen 1.7.1