llui_libtest.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:7k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llui_libtest.cpp
  3.  * @brief Integration test for the LLUI library
  4.  *
  5.  * $LicenseInfo:firstyear=2009&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2009-2010, Linden Research, Inc.
  8.  * 
  9.  * Second Life Viewer Source Code
  10.  * The source code in this file ("Source Code") is provided by Linden Lab
  11.  * to you under the terms of the GNU General Public License, version 2.0
  12.  * ("GPL"), unless you have obtained a separate licensing agreement
  13.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  14.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16.  * 
  17.  * There are special exceptions to the terms and conditions of the GPL as
  18.  * it is applied to this Source Code. View the full text of the exception
  19.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  20.  * online at
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. #include "linden_common.h"
  33. #include "llui_libtest.h"
  34. // project includes
  35. #include "llwidgetreg.h"
  36. // linden library includes
  37. #include "llcontrol.h" // LLControlGroup
  38. #include "lldir.h"
  39. #include "llerrorcontrol.h"
  40. #include "llfloater.h"
  41. #include "llfontfreetype.h"
  42. #include "llfontgl.h"
  43. #include "lltransutil.h"
  44. #include "llui.h"
  45. #include "lluictrlfactory.h"
  46. #include <iostream>
  47. // *TODO: switch to using TUT
  48. // *TODO: teach Parabuild about this program, run automatically after full builds
  49. // I believe these must be globals, not stack variables.  JC
  50. LLControlGroup gSavedSettings("Global"); // saved at end of session
  51. LLControlGroup gSavedPerAccountSettings("PerAccount"); // saved at end of session
  52. LLControlGroup gWarningSettings("Warnings"); // persists ignored dialogs/warnings
  53. // We can't create LLImageGL objects because we have no window or rendering 
  54. // context.  Provide enough of an LLUIImage to test the LLUI library without
  55. // an underlying image.
  56. class TestUIImage : public LLUIImage
  57. {
  58. public:
  59. TestUIImage()
  60. : LLUIImage( std::string(), NULL ) // NULL ImageGL, don't deref!
  61. { }
  62. /*virtual*/ S32 getWidth() const
  63. {
  64. return 16;
  65. }
  66. /*virtual*/ S32 getHeight() const
  67. {
  68. return 16;
  69. }
  70. };
  71. class LLTexture ;
  72. // We need to supply dummy images
  73. class TestImageProvider : public LLImageProviderInterface
  74. {
  75. public:
  76. /*virtual*/ LLPointer<LLUIImage> getUIImage(const std::string& name, S32 priority)
  77. {
  78. return makeImage();
  79. }
  80. /*virtual*/ LLPointer<LLUIImage> getUIImageByID(const LLUUID& id, S32 priority)
  81. {
  82. return makeImage();
  83. }
  84. /*virtual*/ void cleanUp()
  85. {
  86. }
  87. LLPointer<LLUIImage> makeImage()
  88. {
  89. LLPointer<LLTexture> image_gl;
  90. LLPointer<LLUIImage> image = new TestUIImage(); //LLUIImage( std::string(), image_gl);
  91. mImageList.push_back(image);
  92. return image;
  93. }
  94. public:
  95. // Unclear if we need this, hold on to one copy of each image we make
  96. std::vector<LLPointer<LLUIImage> > mImageList;
  97. };
  98. TestImageProvider gTestImageProvider;
  99. static std::string get_xui_dir()
  100. {
  101. std::string delim = gDirUtilp->getDirDelimiter();
  102. return gDirUtilp->getSkinBaseDir() + delim + "default" + delim + "xui" + delim;
  103. }
  104. void init_llui()
  105. {
  106. // Font lookup needs directory support
  107. #if LL_DARWIN
  108. const char* newview_path = "../../../../newview";
  109. #else
  110. const char* newview_path = "../../../newview";
  111. #endif
  112. gDirUtilp->initAppDirs("SecondLife", newview_path);
  113. gDirUtilp->setSkinFolder("default");
  114. // colors are no longer stored in a LLControlGroup file
  115. LLUIColorTable::instance().loadFromSettings();
  116. std::string config_filename = gDirUtilp->getExpandedFilename(
  117.  LL_PATH_APP_SETTINGS, "settings.xml");
  118. gSavedSettings.loadFromFile(config_filename);
  119. // See LLAppViewer::init()
  120. LLUI::settings_map_t settings;
  121. settings["config"] = &gSavedSettings;
  122. settings["ignores"] = &gWarningSettings;
  123. settings["floater"] = &gSavedSettings;
  124. settings["account"] = &gSavedPerAccountSettings;
  125. // Don't use real images as we don't have a GL context
  126. LLUI::initClass(settings, &gTestImageProvider);
  127. const bool no_register_widgets = false;
  128. LLWidgetReg::initClass( no_register_widgets );
  129. // Unclear if this is needed
  130. LLUI::setupPaths();
  131. // Otherwise we get translation warnings when setting up floaters
  132. // (tooltips for buttons)
  133. std::set<std::string> default_args;
  134. LLTransUtil::parseStrings("strings.xml", default_args);
  135. LLTransUtil::parseLanguageStrings("language_settings.xml");
  136. LLFontManager::initClass();
  137. // Creating widgets apparently requires fonts to be initialized,
  138. // otherwise it crashes.
  139. LLFontGL::initClass(96.f, 1.f, 1.f,
  140. gDirUtilp->getAppRODataDir(),
  141. LLUI::getXUIPaths(),
  142. false ); // don't create gl textures
  143. LLFloaterView::Params fvparams;
  144. fvparams.name("Floater View");
  145. fvparams.rect( LLRect(0,480,640,0) );
  146. fvparams.mouse_opaque(false);
  147. fvparams.follows.flags(FOLLOWS_ALL);
  148. fvparams.tab_stop(false);
  149. gFloaterView = LLUICtrlFactory::create<LLFloaterView> (fvparams);
  150. }
  151. void export_test_floaters()
  152. {
  153. // Convert all test floaters to new XML format
  154. std::string delim = gDirUtilp->getDirDelimiter();
  155. std::string xui_dir = get_xui_dir() + "en" + delim;
  156. std::string filename;
  157. while (gDirUtilp->getNextFileInDir(xui_dir, "floater_test_*.xml", filename, false))
  158. {
  159. if (filename.find("_new.xml") != std::string::npos)
  160. {
  161. // don't re-export other test floaters
  162. continue;
  163. }
  164. llinfos << "Converting " << filename << llendl;
  165. // Build a floater and output new attributes
  166. LLXMLNodePtr output_node = new LLXMLNode();
  167. LLFloater* floater = new LLFloater(LLSD());
  168. LLUICtrlFactory::getInstance()->buildFloater(floater,
  169.  filename,
  170. //  FALSE, // don't open floater
  171.  output_node);
  172. std::string out_filename = xui_dir + filename;
  173. std::string::size_type extension_pos = out_filename.rfind(".xml");
  174. out_filename.resize(extension_pos);
  175. out_filename += "_new.xml";
  176. llinfos << "Output: " << out_filename << llendl;
  177. LLFILE* floater_file = LLFile::fopen(out_filename.c_str(), "w");
  178. LLXMLNode::writeHeaderToFile(floater_file);
  179. output_node->writeToFile(floater_file);
  180. fclose(floater_file);
  181. }
  182. }
  183. int main(int argc, char** argv)
  184. {
  185. // Must init LLError for llerrs to actually cause errors.
  186. LLError::initForApplication(".");
  187. init_llui();
  188. export_test_floaters();
  189. return 0;
  190. }