summaryrefslogtreecommitdiff
path: root/indra/newview/lltrackpicker.cpp
blob: bef314f9641103bcb8e7ec8fedf1f1d54db6537d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/**
* @author AndreyK Productengine
* @brief LLTrackPicker class header file including related functions
*
* $LicenseInfo:firstyear=2018&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2018, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
* $/LicenseInfo$
*/

#include "llviewerprecompiledheaders.h"

#include "lltrackpicker.h"

#include "llradiogroup.h"
#include "llviewercontrol.h"


//=========================================================================
namespace
{
    const std::string FLOATER_DEFINITION_XML("floater_pick_track.xml");

    const std::string BTN_SELECT("btn_select");
    const std::string BTN_CANCEL("btn_cancel");
    const std::string RDO_TRACK_SELECTION("track_selection");
    const std::string RDO_TRACK_PREFIX("radio_sky");
}
//=========================================================================

LLFloaterTrackPicker::LLFloaterTrackPicker(LLView * owner, const LLSD &params) :
    LLFloater(params),
    mContextConeOpacity(0.0f),
    mOwnerHandle()
{
    mOwnerHandle = owner->getHandle();
    buildFromFile(FLOATER_DEFINITION_XML);
}

LLFloaterTrackPicker::~LLFloaterTrackPicker()
{
}

bool LLFloaterTrackPicker::postBuild()
{
    childSetAction(BTN_CANCEL, [this](LLUICtrl*, const LLSD& param){ onButtonCancel(); });
    childSetAction(BTN_SELECT, [this](LLUICtrl*, const LLSD& param){ onButtonSelect(); });
    return true;
}

void LLFloaterTrackPicker::onClose(bool app_quitting)
{
    if (app_quitting)
        return;

    LLView *owner = mOwnerHandle.get();
    if (owner)
    {
        owner->setFocus(true);
    }
}

void LLFloaterTrackPicker::showPicker(const LLSD &args)
{
    LLSD::array_const_iterator iter;
    LLSD::array_const_iterator end = args.endArray();

    bool select_item = true;
    for (iter = args.beginArray(); iter != end; ++iter)
    {
        S32 track_id = (*iter)["id"].asInteger();
        bool can_enable = (*iter)["enabled"].asBoolean();
        LLCheckBoxCtrl *view = getChild<LLCheckBoxCtrl>(RDO_TRACK_PREFIX + llformat("%d", track_id), true);
        view->setEnabled(can_enable);
        view->setLabelArg("[ALT]", (*iter).has("altitude") ? ((*iter)["altitude"].asString() + "m") : " ");

        // Mark first avaliable item as selected
        if (can_enable && select_item)
        {
            select_item = false;
            getChild<LLRadioGroup>(RDO_TRACK_SELECTION, true)->setSelectedByValue(LLSD(track_id), true);
        }
    }

    openFloater(getKey());
    setFocus(true);
}

void LLFloaterTrackPicker::draw()
{
    LLView *owner = mOwnerHandle.get();
    static LLCachedControl<F32> max_opacity(gSavedSettings, "PickerContextOpacity", 0.4f);
    drawConeToOwner(mContextConeOpacity, max_opacity, owner);

    LLFloater::draw();
}

void LLFloaterTrackPicker::onButtonCancel()
{
    closeFloater();
}

void LLFloaterTrackPicker::onButtonSelect()
{
    if (mCommitSignal)
    {
        (*mCommitSignal)(this, getChild<LLRadioGroup>(RDO_TRACK_SELECTION, true)->getSelectedValue());
    }
    closeFloater();
}

void LLFloaterTrackPicker::onFocusLost()
{
    if (isInVisibleChain())
    {
        closeFloater();
    }
}