aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llpreviewtexture.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--linden/indra/newview/llpreviewtexture.cpp204
1 files changed, 96 insertions, 108 deletions
diff --git a/linden/indra/newview/llpreviewtexture.cpp b/linden/indra/newview/llpreviewtexture.cpp
index 9f401f4..fe94fa4 100644
--- a/linden/indra/newview/llpreviewtexture.cpp
+++ b/linden/indra/newview/llpreviewtexture.cpp
@@ -45,7 +45,7 @@
45#include "llui.h" 45#include "llui.h"
46#include "llviewerimage.h" 46#include "llviewerimage.h"
47#include "llviewerimagelist.h" 47#include "llviewerimagelist.h"
48#include "llvieweruictrlfactory.h" 48#include "lluictrlfactory.h"
49#include "llviewerwindow.h" 49#include "llviewerwindow.h"
50#include "lllineeditor.h" 50#include "lllineeditor.h"
51 51
@@ -159,14 +159,14 @@ void LLPreviewTexture::init()
159 159
160 if (mCopyToInv) 160 if (mCopyToInv)
161 { 161 {
162 gUICtrlFactory->buildFloater(this,"floater_preview_embedded_texture.xml"); 162 LLUICtrlFactory::getInstance()->buildFloater(this,"floater_preview_embedded_texture.xml");
163 163
164 childSetAction("Copy To Inventory",LLPreview::onBtnCopyToInv,this); 164 childSetAction("Copy To Inventory",LLPreview::onBtnCopyToInv,this);
165 } 165 }
166 166
167 else if (mShowKeepDiscard) 167 else if (mShowKeepDiscard)
168 { 168 {
169 gUICtrlFactory->buildFloater(this,"floater_preview_texture_keep_discard.xml"); 169 LLUICtrlFactory::getInstance()->buildFloater(this,"floater_preview_texture_keep_discard.xml");
170 170
171 childSetAction("Keep",onKeepBtn,this); 171 childSetAction("Keep",onKeepBtn,this);
172 childSetAction("Discard",onDiscardBtn,this); 172 childSetAction("Discard",onDiscardBtn,this);
@@ -174,7 +174,7 @@ void LLPreviewTexture::init()
174 174
175 else 175 else
176 { 176 {
177 gUICtrlFactory->buildFloater(this,"floater_preview_texture.xml"); 177 LLUICtrlFactory::getInstance()->buildFloater(this,"floater_preview_texture.xml");
178 } 178 }
179 179
180 180
@@ -193,100 +193,97 @@ void LLPreviewTexture::init()
193 193
194void LLPreviewTexture::draw() 194void LLPreviewTexture::draw()
195{ 195{
196 if( getVisible() ) 196 updateDimensions();
197
198 LLPreview::draw();
199
200 if (!isMinimized())
197 { 201 {
198 updateAspectRatio(); 202 LLGLSUIDefault gls_ui;
203 LLGLSNoTexture gls_notex;
204
205 const LLRect& border = mClientRect;
206 LLRect interior = mClientRect;
207 interior.stretch( -PREVIEW_BORDER_WIDTH );
199 208
200 LLPreview::draw(); 209 // ...border
210 gl_rect_2d( border, LLColor4(0.f, 0.f, 0.f, 1.f));
211 gl_rect_2d_checkerboard( interior );
201 212
202 if (!isMinimized()) 213 if ( mImage.notNull() )
203 { 214 {
204 LLGLSUIDefault gls_ui; 215 // Draw the texture
205 LLGLSNoTexture gls_notex; 216 glColor3f( 1.f, 1.f, 1.f );
206 217 gl_draw_scaled_image(interior.mLeft,
207 const LLRect& border = mClientRect; 218 interior.mBottom,
208 LLRect interior = mClientRect; 219 interior.getWidth(),
209 interior.stretch( -PREVIEW_BORDER_WIDTH ); 220 interior.getHeight(),
210 221 mImage);
211 // ...border 222
212 gl_rect_2d( border, LLColor4(0.f, 0.f, 0.f, 1.f)); 223 // Pump the texture priority
213 gl_rect_2d_checkerboard( interior ); 224 F32 pixel_area = mLoadingFullImage ? (F32)MAX_IMAGE_AREA : (F32)(interior.getWidth() * interior.getHeight() );
214 225 mImage->addTextureStats( pixel_area );
215 if ( mImage.notNull() ) 226
227 // Don't bother decoding more than we can display, unless
228 // we're loading the full image.
229 if (!mLoadingFullImage)
216 { 230 {
217 // Draw the texture 231 S32 int_width = interior.getWidth();
218 glColor3f( 1.f, 1.f, 1.f ); 232 S32 int_height = interior.getHeight();
219 gl_draw_scaled_image(interior.mLeft, 233 mImage->setKnownDrawSize(int_width, int_height);
220 interior.mBottom, 234 }
221 interior.getWidth(), 235 else
222 interior.getHeight(), 236 {
223 mImage); 237 // Don't use this feature
224 238 mImage->setKnownDrawSize(0, 0);
225 // Pump the texture priority 239 }
226 F32 pixel_area = mLoadingFullImage ? (F32)MAX_IMAGE_AREA : (F32)(interior.getWidth() * interior.getHeight() );
227 mImage->addTextureStats( pixel_area );
228
229 // Don't bother decoding more than we can display, unless
230 // we're loading the full image.
231 if (!mLoadingFullImage)
232 {
233 S32 int_width = interior.getWidth();
234 S32 int_height = interior.getHeight();
235 mImage->setKnownDrawSize(int_width, int_height);
236 }
237 else
238 {
239 // Don't use this feature
240 mImage->setKnownDrawSize(0, 0);
241 }
242 240
243 if( mLoadingFullImage ) 241 if( mLoadingFullImage )
242 {
243 LLFontGL::sSansSerif->renderUTF8("Receiving:", 0,
244 interior.mLeft + 4,
245 interior.mBottom + 4,
246 LLColor4::white, LLFontGL::LEFT, LLFontGL::BOTTOM,
247 LLFontGL::DROP_SHADOW);
248
249 F32 data_progress = mImage->mDownloadProgress;
250
251 // Draw the progress bar.
252 const S32 BAR_HEIGHT = 12;
253 const S32 BAR_LEFT_PAD = 80;
254 S32 left = interior.mLeft + 4 + BAR_LEFT_PAD;
255 S32 bar_width = getRect().getWidth() - left - RESIZE_HANDLE_WIDTH - 2;
256 S32 top = interior.mBottom + 4 + BAR_HEIGHT;
257 S32 right = left + bar_width;
258 S32 bottom = top - BAR_HEIGHT;
259
260 LLColor4 background_color(0.f, 0.f, 0.f, 0.75f);
261 LLColor4 decoded_color(0.f, 1.f, 0.f, 1.0f);
262 LLColor4 downloaded_color(0.f, 0.5f, 0.f, 1.0f);
263
264 gl_rect_2d(left, top, right, bottom, background_color);
265
266 if (data_progress > 0.0f)
244 { 267 {
245 LLFontGL::sSansSerif->renderUTF8("Receiving:", 0, 268 // Downloaded bytes
246 interior.mLeft + 4, 269 right = left + llfloor(data_progress * (F32)bar_width);
247 interior.mBottom + 4, 270 if (right > left)
248 LLColor4::white, LLFontGL::LEFT, LLFontGL::BOTTOM,
249 LLFontGL::DROP_SHADOW);
250
251 F32 data_progress = mImage->mDownloadProgress;
252
253 // Draw the progress bar.
254 const S32 BAR_HEIGHT = 12;
255 const S32 BAR_LEFT_PAD = 80;
256 S32 left = interior.mLeft + 4 + BAR_LEFT_PAD;
257 S32 bar_width = getRect().getWidth() - left - RESIZE_HANDLE_WIDTH - 2;
258 S32 top = interior.mBottom + 4 + BAR_HEIGHT;
259 S32 right = left + bar_width;
260 S32 bottom = top - BAR_HEIGHT;
261
262 LLColor4 background_color(0.f, 0.f, 0.f, 0.75f);
263 LLColor4 decoded_color(0.f, 1.f, 0.f, 1.0f);
264 LLColor4 downloaded_color(0.f, 0.5f, 0.f, 1.0f);
265
266 gl_rect_2d(left, top, right, bottom, background_color);
267
268 if (data_progress > 0.0f)
269 { 271 {
270 // Downloaded bytes 272 gl_rect_2d(left, top, right, bottom, downloaded_color);
271 right = left + llfloor(data_progress * (F32)bar_width);
272 if (right > left)
273 {
274 gl_rect_2d(left, top, right, bottom, downloaded_color);
275 }
276 } 273 }
277 } 274 }
278 else
279 if( !mSavedFileTimer.hasExpired() )
280 {
281 LLFontGL::sSansSerif->renderUTF8("File Saved", 0,
282 interior.mLeft + 4,
283 interior.mBottom + 4,
284 LLColor4::white, LLFontGL::LEFT, LLFontGL::BOTTOM,
285 LLFontGL::DROP_SHADOW);
286 }
287 } 275 }
288 } 276 else
289 } 277 if( !mSavedFileTimer.hasExpired() )
278 {
279 LLFontGL::sSansSerif->renderUTF8("File Saved", 0,
280 interior.mLeft + 4,
281 interior.mBottom + 4,
282 LLColor4::white, LLFontGL::LEFT, LLFontGL::BOTTOM,
283 LLFontGL::DROP_SHADOW);
284 }
285 }
286 }
290} 287}
291 288
292 289
@@ -380,7 +377,7 @@ void LLPreviewTexture::onFileLoadedForSave(BOOL success,
380 377
381// It takes a while until we get height and width information. 378// It takes a while until we get height and width information.
382// When we receive it, reshape the window accordingly. 379// When we receive it, reshape the window accordingly.
383void LLPreviewTexture::updateAspectRatio() 380void LLPreviewTexture::updateDimensions()
384{ 381{
385 if (!mImage) return; 382 if (!mImage) return;
386 383
@@ -389,24 +386,21 @@ void LLPreviewTexture::updateAspectRatio()
389 // Attempt to make the image 1:1 on screen. 386 // Attempt to make the image 1:1 on screen.
390 // If that fails, cut width by half. 387 // If that fails, cut width by half.
391 S32 client_width = image_width; 388 S32 client_width = image_width;
389 S32 client_height = image_height;
392 S32 horiz_pad = 2 * (LLPANEL_BORDER_WIDTH + PREVIEW_PAD) + PREVIEW_RESIZE_HANDLE_SIZE; 390 S32 horiz_pad = 2 * (LLPANEL_BORDER_WIDTH + PREVIEW_PAD) + PREVIEW_RESIZE_HANDLE_SIZE;
393 S32 vert_pad = PREVIEW_HEADER_SIZE + 2 * CLIENT_RECT_VPAD + LLPANEL_BORDER_WIDTH; 391 S32 vert_pad = PREVIEW_HEADER_SIZE + 2 * CLIENT_RECT_VPAD + LLPANEL_BORDER_WIDTH;
394 S32 screen_width = gViewerWindow->getWindowWidth(); 392 S32 max_client_width = gViewerWindow->getWindowWidth() - horiz_pad;
395 S32 max_client_width = screen_width - horiz_pad;
396 S32 max_client_height = gViewerWindow->getWindowHeight() - vert_pad; 393 S32 max_client_height = gViewerWindow->getWindowHeight() - vert_pad;
397 F32 inv_aspect_ratio = (F32) image_height / (F32) image_width;
398 394
399 while ((client_width > max_client_width) || ( llround(client_width * inv_aspect_ratio) > max_client_height ) ) 395 while ((client_width > max_client_width) ||
396 (client_height > max_client_height ) )
400 { 397 {
401 client_width /= 2; 398 client_width /= 2;
399 client_height /= 2;
402 } 400 }
403 401
404 S32 view_width = client_width + horiz_pad; 402 S32 view_width = client_width + horiz_pad;
405
406 // Adjust the height based on the width computed above.
407 S32 client_height = llround(client_width * inv_aspect_ratio);
408 S32 view_height = client_height + vert_pad; 403 S32 view_height = client_height + vert_pad;
409
410 404
411 // set text on dimensions display (should be moved out of here and into a callback of some sort) 405 // set text on dimensions display (should be moved out of here and into a callback of some sort)
412 childSetTextArg("dimensions", "[WIDTH]", llformat("%d", mImage->mFullWidth)); 406 childSetTextArg("dimensions", "[WIDTH]", llformat("%d", mImage->mFullWidth));
@@ -465,26 +459,20 @@ void LLPreviewTexture::updateAspectRatio()
465 else 459 else
466 { 460 {
467 client_width = getRect().getWidth() - horiz_pad; 461 client_width = getRect().getWidth() - horiz_pad;
468 client_height = llround(client_width * inv_aspect_ratio); 462 client_height = getRect().getHeight() - vert_pad;
469 } 463 }
470 464
465 S32 max_height = getRect().getHeight() - PREVIEW_BORDER - button_height
466 - CLIENT_RECT_VPAD - info_height - CLIENT_RECT_VPAD - PREVIEW_HEADER_SIZE;
467 S32 max_width = getRect().getWidth() - horiz_pad;
471 468
472 S32 max_height = getRect().getHeight() - PREVIEW_BORDER - button_height 469 client_height = llclamp(client_height, 1, max_height);
473 - CLIENT_RECT_VPAD - info_height - CLIENT_RECT_VPAD - PREVIEW_HEADER_SIZE; 470 client_width = llclamp(client_width, 1, max_width);
474 max_height = llmax(max_height, 1);
475
476 if (client_height > max_height)
477 {
478 F32 aspect_ratio = (F32) image_width / (F32) image_height;
479 client_height = max_height;
480 client_width = llround(client_height * aspect_ratio);
481 }
482 471
483 LLRect window_rect(0, getRect().getHeight(), getRect().getWidth(), 0); 472 LLRect window_rect(0, getRect().getHeight(), getRect().getWidth(), 0);
484 window_rect.mTop -= (PREVIEW_HEADER_SIZE + CLIENT_RECT_VPAD); 473 window_rect.mTop -= (PREVIEW_HEADER_SIZE + CLIENT_RECT_VPAD);
485 window_rect.mBottom += PREVIEW_BORDER + button_height + CLIENT_RECT_VPAD + info_height + CLIENT_RECT_VPAD; 474 window_rect.mBottom += PREVIEW_BORDER + button_height + CLIENT_RECT_VPAD + info_height + CLIENT_RECT_VPAD;
486 475
487 // try to keep aspect ratio when hosted, as hosting view can resize without user input
488 mClientRect.setLeftTopAndSize(window_rect.getCenterX() - (client_width / 2), window_rect.mTop, client_width, client_height); 476 mClientRect.setLeftTopAndSize(window_rect.getCenterX() - (client_width / 2), window_rect.mTop, client_width, client_height);
489} 477}
490 478