summaryrefslogtreecommitdiff
path: root/indra/newview/llfloaterprofiletexture.cpp
blob: 4ddd7dfc6b16c1a4e35fa3e18b6729ea96004880 (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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/** 
 * @file llfloaterprofiletexture.cpp
 * @brief LLFloaterProfileTexture class implementation
 *
 * $LicenseInfo:firstyear=2022&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2022, 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 "llfloaterprofiletexture.h"

#include "llbutton.h"
#include "llfloaterreg.h"
#include "llpreview.h" // fors constants
#include "lltrans.h"
#include "llviewercontrol.h"
#include "lltextureview.h"
#include "llviewertexture.h"
#include "llviewertexturelist.h"


const S32 CLIENT_RECT_VPAD = 4;
const F32 PREVIEW_TEXTURE_MAX_ASPECT = 20.f;
const F32 PREVIEW_TEXTURE_MIN_ASPECT = 0.5f;


LLFloaterProfileTexture::LLFloaterProfileTexture(LLView* owner)
    : LLFloater(LLSD())
    , mUpdateDimensions(TRUE)
    , mLastHeight(0)
    , mLastWidth(0)
    , mImage(NULL)
    , mImageOldBoostLevel(LLGLTexture::BOOST_NONE)
    , mOwnerHandle(owner->getHandle())
{
    buildFromFile("floater_profile_texture.xml");
}

LLFloaterProfileTexture::~LLFloaterProfileTexture()
{
    if (mImage.notNull())
    {
        mImage->setBoostLevel(mImageOldBoostLevel);
        mImage = NULL;
    }
}

// virtual
BOOL LLFloaterProfileTexture::postBuild()
{
    pProfileIcon = getChild<LLIconCtrl>("profile_pic");

    getChild<LLButton>("close_btn")->setCommitCallback([this](LLUICtrl*, void*) { closeFloater(); }, nullptr);

	return TRUE;
}

// virtual
void LLFloaterProfileTexture::reshape(S32 width, S32 height, BOOL called_from_parent)
{
	LLFloater::reshape(width, height, called_from_parent);
}

// It takes a while until we get height and width information.
// When we receive it, reshape the window accordingly.
void LLFloaterProfileTexture::updateDimensions()
{
    if (mImage.isNull())
    {
        return;
    }
    if ((mImage->getFullWidth() * mImage->getFullHeight()) == 0)
    {
        return;
    }

    S32 img_width = mImage->getFullWidth();
    S32 img_height = mImage->getFullHeight();

    if (mAssetStatus != LLPreview::PREVIEW_ASSET_LOADED
        || mLastWidth != img_width
        || mLastHeight != img_height)
    {
        mAssetStatus = LLPreview::PREVIEW_ASSET_LOADED;
        // Asset has been fully loaded
        mUpdateDimensions = TRUE;
    }

    mLastHeight = img_height;
    mLastWidth = img_width;

    // Reshape the floater only when required
    if (mUpdateDimensions)
    {
        mUpdateDimensions = FALSE;

        LLRect old_floater_rect = getRect();
        LLRect old_image_rect = pProfileIcon->getRect();
        S32 width = old_floater_rect.getWidth() - old_image_rect.getWidth() + mLastWidth;
        S32 height = old_floater_rect.getHeight() - old_image_rect.getHeight() + mLastHeight;

        //reshape floater
        reshape(width, height);

        gFloaterView->adjustToFitScreen(this, FALSE);
    }
}

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

    LLFloater::draw();
}

void LLFloaterProfileTexture::resetAsset()
{
    pProfileIcon->setValue("Generic_Person_Large");
    mImageID = LLUUID::null;
    if (mImage.notNull())
    {
        mImage->setBoostLevel(mImageOldBoostLevel);
        mImage = NULL;
    }
}
void LLFloaterProfileTexture::loadAsset(const LLUUID &image_id)
{
    if (mImageID != image_id)
    {
        if (mImage.notNull())
        {
            mImage->setBoostLevel(mImageOldBoostLevel);
            mImage = NULL;
        }
    }
    else
    {
        return;
    }

    pProfileIcon->setValue(image_id);
    mImageID = image_id;
    mImage = LLViewerTextureManager::getFetchedTexture(mImageID, FTT_DEFAULT, MIPMAP_TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE);
    mImageOldBoostLevel = mImage->getBoostLevel();

    if ((mImage->getFullWidth() * mImage->getFullHeight()) == 0)
    {
        mImage->setLoadedCallback(LLFloaterProfileTexture::onTextureLoaded,
            0, TRUE, FALSE, new LLHandle<LLFloater>(getHandle()), &mCallbackTextureList);

        mImage->setBoostLevel(LLGLTexture::BOOST_PREVIEW);
        mAssetStatus = LLPreview::PREVIEW_ASSET_LOADING;
    }
    else
    {
        mAssetStatus = LLPreview::PREVIEW_ASSET_LOADED;
    }

    mUpdateDimensions = TRUE;
    updateDimensions();
}

// static
void LLFloaterProfileTexture::onTextureLoaded(
    BOOL success,
    LLViewerFetchedTexture *src_vi,
    LLImageRaw* src,
    LLImageRaw* aux_src,
    S32 discard_level,
    BOOL final,
    void* userdata)
{
    LLHandle<LLFloater>* handle = (LLHandle<LLFloater>*)userdata;

    if (!handle->isDead())
    {
        LLFloaterProfileTexture* floater = static_cast<LLFloaterProfileTexture*>(handle->get());
        if (floater && success)
        {
            floater->mUpdateDimensions = TRUE;
            floater->updateDimensions();
        }
    }

    if (final || !success)
    {
        delete handle;
    }
}