PageRenderTime 99ms CodeModel.GetById 40ms app.highlight 36ms RepoModel.GetById 14ms 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
  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
 29// Precompiled header
 30#include "llviewerprecompiledheaders.h"
 31// associated header
 32#include "llviewerwindowlistener.h"
 33// STL headers
 34#include <map>
 35// std headers
 36// external library headers
 37// other Linden headers
 38#include "llviewerwindow.h"
 39
 40LLViewerWindowListener::LLViewerWindowListener(LLViewerWindow* llviewerwindow):
 41    LLEventAPI("LLViewerWindow",
 42               "LLViewerWindow listener to (e.g.) save a screenshot"),
 43    mViewerWindow(llviewerwindow)
 44{
 45    // add() every method we want to be able to invoke via this event API.
 46    LLSD saveSnapshotArgs;
 47    saveSnapshotArgs["filename"] = LLSD::String();
 48    saveSnapshotArgs["reply"] = LLSD::String();
 49    // The following are optional, so don't build them into required prototype.
 50//  saveSnapshotArgs["width"] = LLSD::Integer();
 51//  saveSnapshotArgs["height"] = LLSD::Integer();
 52//  saveSnapshotArgs["showui"] = LLSD::Boolean();
 53//  saveSnapshotArgs["rebuild"] = LLSD::Boolean();
 54//  saveSnapshotArgs["type"] = LLSD::String();
 55    add("saveSnapshot",
 56        "Save screenshot: [\"filename\"], [\"width\"], [\"height\"], [\"showui\"], [\"rebuild\"], [\"type\"]\n"
 57        "type: \"COLOR\", \"DEPTH\"\n"
 58        "Post on [\"reply\"] an event containing [\"ok\"]",
 59        &LLViewerWindowListener::saveSnapshot,
 60        saveSnapshotArgs);
 61    add("requestReshape",
 62        "Resize the window: [\"w\"], [\"h\"]",
 63        &LLViewerWindowListener::requestReshape);
 64}
 65
 66void LLViewerWindowListener::saveSnapshot(const LLSD& event) const
 67{
 68    typedef std::map<LLSD::String, LLViewerWindow::ESnapshotType> TypeMap;
 69    TypeMap types;
 70#define tp(name) types[#name] = LLViewerWindow::SNAPSHOT_TYPE_##name
 71    tp(COLOR);
 72    tp(DEPTH);
 73#undef  tp
 74    // Our add() call should ensure that the incoming LLSD does in fact
 75    // contain our required arguments. Deal with the optional ones.
 76    S32 width (mViewerWindow->getWindowWidthRaw());
 77    S32 height(mViewerWindow->getWindowHeightRaw());
 78    if (event.has("width"))
 79        width = event["width"].asInteger();
 80    if (event.has("height"))
 81        height = event["height"].asInteger();
 82    // showui defaults to true, requiring special treatment
 83    bool showui = true;
 84    if (event.has("showui"))
 85        showui = event["showui"].asBoolean();
 86    bool rebuild(event["rebuild"]); // defaults to false
 87    LLViewerWindow::ESnapshotType type(LLViewerWindow::SNAPSHOT_TYPE_COLOR);
 88    if (event.has("type"))
 89    {
 90        TypeMap::const_iterator found = types.find(event["type"]);
 91        if (found == types.end())
 92        {
 93            LL_ERRS("LLViewerWindowListener") << "LLViewerWindowListener::saveSnapshot(): "
 94                                              << "unrecognized type " << event["type"] << LL_ENDL;
 95	    return;
 96        }
 97        type = found->second;
 98    }
 99    bool ok = mViewerWindow->saveSnapshot(event["filename"], width, height, showui, rebuild, type);
100    sendReply(LLSDMap("ok", ok), event);
101}
102
103void LLViewerWindowListener::requestReshape(LLSD const & event_data) const
104{
105	if(event_data.has("w") && event_data.has("h"))
106	{
107		mViewerWindow->reshape(event_data["w"].asInteger(), event_data["h"].asInteger());
108	}
109}