summaryrefslogtreecommitdiff
path: root/indra/newview/llfloatersnapshot.h
blob: 1f303ea4d6532d34193e8afaf7fce11ca7563628 (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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/** 
 * @file llfloatersnapshot.h
 * @brief Snapshot preview window, allowing saving, e-mailing, etc.
 *
 * $LicenseInfo:firstyear=2004&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2016, 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$
 */

#ifndef LL_LLFLOATERSNAPSHOT_H
#define LL_LLFLOATERSNAPSHOT_H

#include "llagent.h"
#include "llfloater.h"
#include "llpanelsnapshot.h"
#include "llsnapshotmodel.h"

class LLSpinCtrl;
class LLSnapshotLivePreview;

class LLFloaterSnapshotBase : public LLFloater
{
    LOG_CLASS(LLFloaterSnapshotBase);

public:

    LLFloaterSnapshotBase(const LLSD& key);
    virtual ~LLFloaterSnapshotBase();

	/*virtual*/ void draw();
	/*virtual*/ void onClose(bool app_quitting);
	virtual S32 notify(const LLSD& info);

	// TODO: create a snapshot model instead
	virtual void saveTexture() = 0;
	void postSave();
	virtual void postPanelSwitch();
	LLPointer<LLImageFormatted> getImageData();
	LLSnapshotLivePreview* getPreviewView();
	const LLVector3d& getPosTakenGlobal();

	const LLRect& getThumbnailPlaceholderRect() { return mThumbnailPlaceholder->getRect(); }

	void setRefreshLabelVisible(bool value) { mRefreshLabel->setVisible(value); }
	void setSuccessLabelPanelVisible(bool value) { mSucceessLblPanel->setVisible(value); }
	void setFailureLabelPanelVisible(bool value) { mFailureLblPanel->setVisible(value); }
	void inventorySaveFailed();

	class ImplBase;
	friend class ImplBase;
	ImplBase* impl;

protected:
	LLUICtrl* mThumbnailPlaceholder;
	LLUICtrl *mRefreshBtn, *mRefreshLabel;
	LLUICtrl *mSucceessLblPanel, *mFailureLblPanel;
};

class LLFloaterSnapshotBase::ImplBase
{
public:
	typedef enum e_status
	{
		STATUS_READY,
		STATUS_WORKING,
		STATUS_FINISHED
	} EStatus;

	ImplBase(LLFloaterSnapshotBase* floater) : mAvatarPauseHandles(),
		mLastToolset(NULL),
		mAspectRatioCheckOff(false),
		mNeedRefresh(false),
		mStatus(STATUS_READY),
		mFloater(floater)
	{}
	virtual ~ImplBase()
	{
		//unpause avatars
		mAvatarPauseHandles.clear();
	}

	static void onClickNewSnapshot(void* data);
	static void onClickAutoSnap(LLUICtrl *ctrl, void* data);
	static void onClickFilter(LLUICtrl *ctrl, void* data);
	static void onClickUICheck(LLUICtrl *ctrl, void* data);
	static void onClickHUDCheck(LLUICtrl *ctrl, void* data);
	static void onCommitFreezeFrame(LLUICtrl* ctrl, void* data);

	virtual LLPanelSnapshot* getActivePanel(LLFloaterSnapshotBase* floater, bool ok_if_not_found = true) = 0;
	virtual LLSnapshotModel::ESnapshotType getActiveSnapshotType(LLFloaterSnapshotBase* floater);
	virtual LLSnapshotModel::ESnapshotFormat getImageFormat(LLFloaterSnapshotBase* floater) = 0;
	virtual std::string getSnapshotPanelPrefix() = 0;

	LLSnapshotLivePreview* getPreviewView();
	virtual void updateControls(LLFloaterSnapshotBase* floater) = 0;
	virtual void updateLayout(LLFloaterSnapshotBase* floater);
	virtual void updateLivePreview();
	virtual void setStatus(EStatus status, bool ok = true, const std::string& msg = LLStringUtil::null);
	virtual EStatus getStatus() const { return mStatus; }
	virtual void setNeedRefresh(bool need);

	static BOOL updatePreviewList(bool initialized);

	void setAdvanced(bool advanced) { mAdvanced = advanced; }

	virtual LLSnapshotModel::ESnapshotLayerType getLayerType(LLFloaterSnapshotBase* floater) = 0;
	virtual void checkAutoSnapshot(LLSnapshotLivePreview* floater, BOOL update_thumbnail = FALSE);
	void setWorking(bool working);
	virtual void setFinished(bool finished, bool ok = true, const std::string& msg = LLStringUtil::null) = 0;

public:
	LLFloaterSnapshotBase* mFloater;
	std::vector<LLAnimPauseRequest> mAvatarPauseHandles;

	LLToolset*	mLastToolset;
	LLHandle<LLView> mPreviewHandle;
	bool mAspectRatioCheckOff;
	bool mNeedRefresh;
	bool mAdvanced;
	EStatus mStatus;
};

class LLFloaterSnapshot : public LLFloaterSnapshotBase
{
	LOG_CLASS(LLFloaterSnapshot);

public:
	LLFloaterSnapshot(const LLSD& key);
	/*virtual*/ ~LLFloaterSnapshot();
    
	/*virtual*/ BOOL postBuild();
	/*virtual*/ void onOpen(const LLSD& key);
	/*virtual*/ S32 notify(const LLSD& info);
	
	static void update();

	void onExtendFloater();

	static LLFloaterSnapshot* getInstance();
	static LLFloaterSnapshot* findInstance();
	/*virtual*/ void saveTexture();
	BOOL saveLocal();
	static void setAgentEmail(const std::string& email);

	class Impl;
	friend class Impl;
};

///----------------------------------------------------------------------------
/// Class LLFloaterSnapshot::Impl
///----------------------------------------------------------------------------

class LLFloaterSnapshot::Impl : public LLFloaterSnapshotBase::ImplBase
{
	LOG_CLASS(LLFloaterSnapshot::Impl);
public:
	Impl(LLFloaterSnapshotBase* floater)
		: LLFloaterSnapshotBase::ImplBase(floater)
	{}
	~Impl()
	{}

	void applyKeepAspectCheck(LLFloaterSnapshotBase* view, BOOL checked);
	void updateResolution(LLUICtrl* ctrl, void* data, BOOL do_update = TRUE);
	static void onCommitLayerTypes(LLUICtrl* ctrl, void*data);
	void onImageQualityChange(LLFloaterSnapshotBase* view, S32 quality_val);
	void onImageFormatChange(LLFloaterSnapshotBase* view);
	void applyCustomResolution(LLFloaterSnapshotBase* view, S32 w, S32 h);
	static void onSendingPostcardFinished(LLFloaterSnapshotBase* floater, bool status);
	BOOL checkImageSize(LLSnapshotLivePreview* previewp, S32& width, S32& height, BOOL isWidthChanged, S32 max_value);
	void setImageSizeSpinnersValues(LLFloaterSnapshotBase *view, S32 width, S32 height);
	void updateSpinners(LLFloaterSnapshotBase* view, LLSnapshotLivePreview* previewp, S32& width, S32& height, BOOL is_width_changed);
	static void onSnapshotUploadFinished(LLFloaterSnapshotBase* floater, bool status);

	/*virtual*/ LLPanelSnapshot* getActivePanel(LLFloaterSnapshotBase* floater, bool ok_if_not_found = true);
	/*virtual*/ LLSnapshotModel::ESnapshotFormat getImageFormat(LLFloaterSnapshotBase* floater);
	LLSpinCtrl* getWidthSpinner(LLFloaterSnapshotBase* floater);
	LLSpinCtrl* getHeightSpinner(LLFloaterSnapshotBase* floater);
	void enableAspectRatioCheckbox(LLFloaterSnapshotBase* floater, BOOL enable);
	void setAspectRatioCheckboxValue(LLFloaterSnapshotBase* floater, BOOL checked);
	/*virtual*/ std::string getSnapshotPanelPrefix();

	void setResolution(LLFloaterSnapshotBase* floater, const std::string& comboname);
	/*virtual*/ void updateControls(LLFloaterSnapshotBase* floater);

private:
	/*virtual*/ LLSnapshotModel::ESnapshotLayerType getLayerType(LLFloaterSnapshotBase* floater);
	void comboSetCustom(LLFloaterSnapshotBase *floater, const std::string& comboname);
	void checkAspectRatio(LLFloaterSnapshotBase *view, S32 index);
	void setFinished(bool finished, bool ok = true, const std::string& msg = LLStringUtil::null);
};

class LLSnapshotFloaterView : public LLFloaterView
{
public:
	struct Params 
	:	public LLInitParam::Block<Params, LLFloaterView::Params>
	{
	};

protected:
	LLSnapshotFloaterView (const Params& p);
	friend class LLUICtrlFactory;

public:
	virtual ~LLSnapshotFloaterView();

	/*virtual*/	BOOL handleKey(KEY key, MASK mask, BOOL called_from_parent);
	/*virtual*/	BOOL handleMouseDown(S32 x, S32 y, MASK mask);
	/*virtual*/	BOOL handleMouseUp(S32 x, S32 y, MASK mask);
	/*virtual*/	BOOL handleHover(S32 x, S32 y, MASK mask);
};

extern LLSnapshotFloaterView* gSnapshotFloaterView;

#endif // LL_LLFLOATERSNAPSHOT_H