PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llviewerwindowlistener.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 109 lines | 62 code | 4 blank | 43 comment | 8 complexity | 22d1ac3b01a51ef2aa1f5259be94c2b2 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llviewerwindowlistener.cpp
  3. * @author Nat Goodspeed
  4. * @date 2009-06-30
  5. * @brief Implementation for llviewerwindowlistener.
  6. *
  7. * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  8. * Second Life Viewer Source Code
  9. * Copyright (C) 2010, Linden Research, Inc.
  10. *
  11. * This library is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation;
  14. * version 2.1 of the License only.
  15. *
  16. * This library is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public
  22. * License along with this library; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. *
  25. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  26. * $/LicenseInfo$
  27. */
  28. // Precompiled header
  29. #include "llviewerprecompiledheaders.h"
  30. // associated header
  31. #include "llviewerwindowlistener.h"
  32. // STL headers
  33. #include <map>
  34. // std headers
  35. // external library headers
  36. // other Linden headers
  37. #include "llviewerwindow.h"
  38. LLViewerWindowListener::LLViewerWindowListener(LLViewerWindow* llviewerwindow):
  39. LLEventAPI("LLViewerWindow",
  40. "LLViewerWindow listener to (e.g.) save a screenshot"),
  41. mViewerWindow(llviewerwindow)
  42. {
  43. // add() every method we want to be able to invoke via this event API.
  44. LLSD saveSnapshotArgs;
  45. saveSnapshotArgs["filename"] = LLSD::String();
  46. saveSnapshotArgs["reply"] = LLSD::String();
  47. // The following are optional, so don't build them into required prototype.
  48. // saveSnapshotArgs["width"] = LLSD::Integer();
  49. // saveSnapshotArgs["height"] = LLSD::Integer();
  50. // saveSnapshotArgs["showui"] = LLSD::Boolean();
  51. // saveSnapshotArgs["rebuild"] = LLSD::Boolean();
  52. // saveSnapshotArgs["type"] = LLSD::String();
  53. add("saveSnapshot",
  54. "Save screenshot: [\"filename\"], [\"width\"], [\"height\"], [\"showui\"], [\"rebuild\"], [\"type\"]\n"
  55. "type: \"COLOR\", \"DEPTH\"\n"
  56. "Post on [\"reply\"] an event containing [\"ok\"]",
  57. &LLViewerWindowListener::saveSnapshot,
  58. saveSnapshotArgs);
  59. add("requestReshape",
  60. "Resize the window: [\"w\"], [\"h\"]",
  61. &LLViewerWindowListener::requestReshape);
  62. }
  63. void LLViewerWindowListener::saveSnapshot(const LLSD& event) const
  64. {
  65. typedef std::map<LLSD::String, LLViewerWindow::ESnapshotType> TypeMap;
  66. TypeMap types;
  67. #define tp(name) types[#name] = LLViewerWindow::SNAPSHOT_TYPE_##name
  68. tp(COLOR);
  69. tp(DEPTH);
  70. #undef tp
  71. // Our add() call should ensure that the incoming LLSD does in fact
  72. // contain our required arguments. Deal with the optional ones.
  73. S32 width (mViewerWindow->getWindowWidthRaw());
  74. S32 height(mViewerWindow->getWindowHeightRaw());
  75. if (event.has("width"))
  76. width = event["width"].asInteger();
  77. if (event.has("height"))
  78. height = event["height"].asInteger();
  79. // showui defaults to true, requiring special treatment
  80. bool showui = true;
  81. if (event.has("showui"))
  82. showui = event["showui"].asBoolean();
  83. bool rebuild(event["rebuild"]); // defaults to false
  84. LLViewerWindow::ESnapshotType type(LLViewerWindow::SNAPSHOT_TYPE_COLOR);
  85. if (event.has("type"))
  86. {
  87. TypeMap::const_iterator found = types.find(event["type"]);
  88. if (found == types.end())
  89. {
  90. LL_ERRS("LLViewerWindowListener") << "LLViewerWindowListener::saveSnapshot(): "
  91. << "unrecognized type " << event["type"] << LL_ENDL;
  92. return;
  93. }
  94. type = found->second;
  95. }
  96. bool ok = mViewerWindow->saveSnapshot(event["filename"], width, height, showui, rebuild, type);
  97. sendReply(LLSDMap("ok", ok), event);
  98. }
  99. void LLViewerWindowListener::requestReshape(LLSD const & event_data) const
  100. {
  101. if(event_data.has("w") && event_data.has("h"))
  102. {
  103. mViewerWindow->reshape(event_data["w"].asInteger(), event_data["h"].asInteger());
  104. }
  105. }