aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llui/llui.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llui/llui.cpp')
-rw-r--r--linden/indra/llui/llui.cpp461
1 files changed, 297 insertions, 164 deletions
diff --git a/linden/indra/llui/llui.cpp b/linden/indra/llui/llui.cpp
index 96f293e..f6ce985 100644
--- a/linden/indra/llui/llui.cpp
+++ b/linden/indra/llui/llui.cpp
@@ -12,12 +12,12 @@
12 * ("GPL"), unless you have obtained a separate licensing agreement 12 * ("GPL"), unless you have obtained a separate licensing agreement
13 * ("Other License"), formally executed by you and Linden Lab. Terms of 13 * ("Other License"), formally executed by you and Linden Lab. Terms of
14 * the GPL can be found in doc/GPL-license.txt in this distribution, or 14 * the GPL can be found in doc/GPL-license.txt in this distribution, or
15 * online at http://secondlife.com/developers/opensource/gplv2 15 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
16 * 16 *
17 * There are special exceptions to the terms and conditions of the GPL as 17 * There are special exceptions to the terms and conditions of the GPL as
18 * it is applied to this Source Code. View the full text of the exception 18 * it is applied to this Source Code. View the full text of the exception
19 * in the file doc/FLOSS-exception.txt in this software distribution, or 19 * in the file doc/FLOSS-exception.txt in this software distribution, or
20 * online at http://secondlife.com/developers/opensource/flossexception 20 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
21 * 21 *
22 * By copying, modifying or distributing this software, you acknowledge 22 * By copying, modifying or distributing this software, you acknowledge
23 * that you have read and understood your obligations described above, 23 * that you have read and understood your obligations described above,
@@ -79,7 +79,7 @@ LLVector2 LLUI::sGLScaleFactor(1.f, 1.f);
79LLWindow* LLUI::sWindow = NULL; 79LLWindow* LLUI::sWindow = NULL;
80LLHtmlHelp* LLUI::sHtmlHelp = NULL; 80LLHtmlHelp* LLUI::sHtmlHelp = NULL;
81BOOL LLUI::sShowXUINames = FALSE; 81BOOL LLUI::sShowXUINames = FALSE;
82std::stack<LLRect> LLUI::sClipRectStack; 82std::stack<LLRect> LLScreenClipRect::sClipRectStack;
83 83
84// 84//
85// Functions 85// Functions
@@ -410,39 +410,76 @@ void gl_corners_2d(S32 left, S32 top, S32 right, S32 bottom, S32 length, F32 max
410} 410}
411 411
412 412
413void gl_draw_image( S32 x, S32 y, LLImageGL* image, const LLColor4& color ) 413void gl_draw_image( S32 x, S32 y, LLImageGL* image, const LLColor4& color, const LLRectf& uv_rect )
414{ 414{
415 gl_draw_scaled_rotated_image( x, y, image->getWidth(0), image->getHeight(0), 0.f, image, color ); 415 if (NULL == image)
416 {
417 llwarns << "image == NULL; aborting function" << llendl;
418 return;
419 }
420 gl_draw_scaled_rotated_image( x, y, image->getWidth(0), image->getHeight(0), 0.f, image, color, uv_rect );
416} 421}
417 422
418void gl_draw_scaled_image(S32 x, S32 y, S32 width, S32 height, LLImageGL* image, const LLColor4& color) 423void gl_draw_scaled_image(S32 x, S32 y, S32 width, S32 height, LLImageGL* image, const LLColor4& color, const LLRectf& uv_rect)
419{ 424{
420 gl_draw_scaled_rotated_image( x, y, width, height, 0.f, image, color ); 425 if (NULL == image)
426 {
427 llwarns << "image == NULL; aborting function" << llendl;
428 return;
429 }
430 gl_draw_scaled_rotated_image( x, y, width, height, 0.f, image, color, uv_rect );
421} 431}
422 432
423void gl_draw_scaled_image_with_border(S32 x, S32 y, S32 border_width, S32 border_height, S32 width, S32 height, LLImageGL* image, const LLColor4& color, BOOL solid_color) 433void gl_draw_scaled_image_with_border(S32 x, S32 y, S32 border_width, S32 border_height, S32 width, S32 height, LLImageGL* image, const LLColor4& color, BOOL solid_color, const LLRectf& uv_rect)
424{ 434{
425 stop_glerror();
426 F32 border_scale = 1.f;
427
428 if (NULL == image) 435 if (NULL == image)
429 { 436 {
430 llwarns << "image == NULL; aborting function" << llendl; 437 llwarns << "image == NULL; aborting function" << llendl;
431 return; 438 return;
432 } 439 }
433 440
434 if (border_height * 2 > height) 441 // scale screen size of borders down
435 { 442 F32 border_width_fraction = (F32)border_width / (F32)image->getWidth(0);
436 border_scale = (F32)height / ((F32)border_height * 2.f); 443 F32 border_height_fraction = (F32)border_height / (F32)image->getHeight(0);
437 } 444
438 if (border_width * 2 > width) 445 LLRectf scale_rect(border_width_fraction, 1.f - border_height_fraction, 1.f - border_width_fraction, border_height_fraction);
446 gl_draw_scaled_image_with_border(x, y, width, height, image, color, solid_color, uv_rect, scale_rect);
447}
448
449void gl_draw_scaled_image_with_border(S32 x, S32 y, S32 width, S32 height, LLImageGL* image, const LLColor4& color, BOOL solid_color, const LLRectf& uv_rect, const LLRectf& scale_rect)
450{
451 stop_glerror();
452
453 if (NULL == image)
439 { 454 {
440 border_scale = llmin(border_scale, (F32)width / ((F32)border_width * 2.f)); 455 llwarns << "image == NULL; aborting function" << llendl;
456 return;
441 } 457 }
442 458
443 // scale screen size of borders down 459 // scale screen size of borders down
444 S32 scaled_border_width = llfloor(border_scale * (F32)border_width); 460 LLRectf clipped_scale_rect = uv_rect;
445 S32 scaled_border_height = llfloor(border_scale * (F32)border_height); 461 clipped_scale_rect.intersectWith(scale_rect);
462
463 LLRect draw_rect(0, height, width, 0);
464 LLRect draw_scale_rect(llround((F32)image->getWidth() * scale_rect.mLeft),
465 llround((F32)image->getHeight() * scale_rect.mTop),
466 llround((F32)image->getWidth() * scale_rect.mRight),
467 llround((F32)image->getHeight() * scale_rect.mBottom));
468 // scale fixed region of image up with drawn region
469 draw_scale_rect.mRight += width - image->getWidth();
470 draw_scale_rect.mTop += height - image->getHeight();
471
472 S32 border_shrink_width = llmax(0, draw_scale_rect.mLeft - draw_scale_rect.mRight);
473 S32 border_shrink_height = llmax(0, draw_scale_rect.mBottom - draw_scale_rect.mTop);
474
475 F32 shrink_width_ratio = scale_rect.getWidth() == 1.f ? 0.f : border_shrink_width / ((F32)image->getWidth() * (1.f - scale_rect.getWidth()));
476 F32 shrink_height_ratio = scale_rect.getHeight() == 1.f ? 0.f : border_shrink_height / ((F32)image->getHeight() * (1.f - scale_rect.getHeight()));
477
478 F32 shrink_scale = 1.f - llmax(shrink_width_ratio, shrink_height_ratio);
479 draw_scale_rect.mLeft = llround((F32)draw_scale_rect.mLeft * shrink_scale);
480 draw_scale_rect.mTop = llround(lerp((F32)height, (F32)draw_scale_rect.mTop, shrink_scale));
481 draw_scale_rect.mRight = llround(lerp((F32)width, (F32)draw_scale_rect.mRight, shrink_scale));
482 draw_scale_rect.mBottom = llround((F32)draw_scale_rect.mBottom * shrink_scale);
446 483
447 LLGLSUIDefault gls_ui; 484 LLGLSUIDefault gls_ui;
448 485
@@ -470,127 +507,124 @@ void gl_draw_scaled_image_with_border(S32 x, S32 y, S32 border_width, S32 border
470 507
471 glColor4fv(color.mV); 508 glColor4fv(color.mV);
472 509
473 F32 border_width_fraction = (F32)border_width / (F32)image->getWidth(0);
474 F32 border_height_fraction = (F32)border_height / (F32)image->getHeight(0);
475
476 glBegin(GL_QUADS); 510 glBegin(GL_QUADS);
477 { 511 {
478 // draw bottom left 512 // draw bottom left
479 glTexCoord2f(0.f, 0.f); 513 glTexCoord2d(uv_rect.mLeft, uv_rect.mBottom);
480 glVertex2i(0, 0); 514 glVertex2i(0, 0);
481 515
482 glTexCoord2f(border_width_fraction, 0.f); 516 glTexCoord2f(clipped_scale_rect.mLeft, uv_rect.mBottom);
483 glVertex2i(scaled_border_width, 0); 517 glVertex2i(draw_scale_rect.mLeft, 0);
484 518
485 glTexCoord2f(border_width_fraction, border_height_fraction); 519 glTexCoord2f(clipped_scale_rect.mLeft, clipped_scale_rect.mBottom);
486 glVertex2i(scaled_border_width, scaled_border_height); 520 glVertex2i(draw_scale_rect.mLeft, draw_scale_rect.mBottom);
487 521
488 glTexCoord2f(0.f, border_height_fraction); 522 glTexCoord2d(uv_rect.mLeft, clipped_scale_rect.mBottom);
489 glVertex2i(0, scaled_border_height); 523 glVertex2i(0, draw_scale_rect.mBottom);
490 524
491 // draw bottom middle 525 // draw bottom middle
492 glTexCoord2f(border_width_fraction, 0.f); 526 glTexCoord2f(clipped_scale_rect.mLeft, uv_rect.mBottom);
493 glVertex2i(scaled_border_width, 0); 527 glVertex2i(draw_scale_rect.mLeft, 0);
494 528
495 glTexCoord2f(1.f - border_width_fraction, 0.f); 529 glTexCoord2d(clipped_scale_rect.mRight, uv_rect.mBottom);
496 glVertex2i(width - scaled_border_width, 0); 530 glVertex2i(draw_scale_rect.mRight, 0);
497 531
498 glTexCoord2f(1.f - border_width_fraction, border_height_fraction); 532 glTexCoord2d(clipped_scale_rect.mRight, clipped_scale_rect.mBottom);
499 glVertex2i(width - scaled_border_width, scaled_border_height); 533 glVertex2i(draw_scale_rect.mRight, draw_scale_rect.mBottom);
500 534
501 glTexCoord2f(border_width_fraction, border_height_fraction); 535 glTexCoord2f(clipped_scale_rect.mLeft, clipped_scale_rect.mBottom);
502 glVertex2i(scaled_border_width, scaled_border_height); 536 glVertex2i(draw_scale_rect.mLeft, draw_scale_rect.mBottom);
503 537
504 // draw bottom right 538 // draw bottom right
505 glTexCoord2f(1.f - border_width_fraction, 0.f); 539 glTexCoord2d(clipped_scale_rect.mRight, uv_rect.mBottom);
506 glVertex2i(width - scaled_border_width, 0); 540 glVertex2i(draw_scale_rect.mRight, 0);
507 541
508 glTexCoord2f(1.f, 0.f); 542 glTexCoord2d(uv_rect.mRight, uv_rect.mBottom);
509 glVertex2i(width, 0); 543 glVertex2i(width, 0);
510 544
511 glTexCoord2f(1.f, border_height_fraction); 545 glTexCoord2d(uv_rect.mRight, clipped_scale_rect.mBottom);
512 glVertex2i(width, scaled_border_height); 546 glVertex2i(width, draw_scale_rect.mBottom);
513 547
514 glTexCoord2f(1.f - border_width_fraction, border_height_fraction); 548 glTexCoord2d(clipped_scale_rect.mRight, clipped_scale_rect.mBottom);
515 glVertex2i(width - scaled_border_width, scaled_border_height); 549 glVertex2i(draw_scale_rect.mRight, draw_scale_rect.mBottom);
516 550
517 // draw left 551 // draw left
518 glTexCoord2f(0.f, border_height_fraction); 552 glTexCoord2d(uv_rect.mLeft, clipped_scale_rect.mBottom);
519 glVertex2i(0, scaled_border_height); 553 glVertex2i(0, draw_scale_rect.mBottom);
520 554
521 glTexCoord2f(border_width_fraction, border_height_fraction); 555 glTexCoord2f(clipped_scale_rect.mLeft, clipped_scale_rect.mBottom);
522 glVertex2i(scaled_border_width, scaled_border_height); 556 glVertex2i(draw_scale_rect.mLeft, draw_scale_rect.mBottom);
523 557
524 glTexCoord2f(border_width_fraction, 1.f - border_height_fraction); 558 glTexCoord2f(clipped_scale_rect.mLeft, clipped_scale_rect.mTop);
525 glVertex2i(scaled_border_width, height - scaled_border_height); 559 glVertex2i(draw_scale_rect.mLeft, draw_scale_rect.mTop);
526 560
527 glTexCoord2f(0.f, 1.f - border_height_fraction); 561 glTexCoord2d(uv_rect.mLeft, clipped_scale_rect.mTop);
528 glVertex2i(0, height - scaled_border_height); 562 glVertex2i(0, draw_scale_rect.mTop);
529 563
530 // draw middle 564 // draw middle
531 glTexCoord2f(border_width_fraction, border_height_fraction); 565 glTexCoord2f(clipped_scale_rect.mLeft, clipped_scale_rect.mBottom);
532 glVertex2i(scaled_border_width, scaled_border_height); 566 glVertex2i(draw_scale_rect.mLeft, draw_scale_rect.mBottom);
533 567
534 glTexCoord2f(1.f - border_width_fraction, border_height_fraction); 568 glTexCoord2d(clipped_scale_rect.mRight, clipped_scale_rect.mBottom);
535 glVertex2i(width - scaled_border_width, scaled_border_height); 569 glVertex2i(draw_scale_rect.mRight, draw_scale_rect.mBottom);
536 570
537 glTexCoord2f(1.f - border_width_fraction, 1.f - border_height_fraction); 571 glTexCoord2d(clipped_scale_rect.mRight, clipped_scale_rect.mTop);
538 glVertex2i(width - scaled_border_width, height - scaled_border_height); 572 glVertex2i(draw_scale_rect.mRight, draw_scale_rect.mTop);
539 573
540 glTexCoord2f(border_width_fraction, 1.f - border_height_fraction); 574 glTexCoord2f(clipped_scale_rect.mLeft, clipped_scale_rect.mTop);
541 glVertex2i(scaled_border_width, height - scaled_border_height); 575 glVertex2i(draw_scale_rect.mLeft, draw_scale_rect.mTop);
542 576
543 // draw right 577 // draw right
544 glTexCoord2f(1.f - border_width_fraction, border_height_fraction); 578 glTexCoord2d(clipped_scale_rect.mRight, clipped_scale_rect.mBottom);
545 glVertex2i(width - scaled_border_width, scaled_border_height); 579 glVertex2i(draw_scale_rect.mRight, draw_scale_rect.mBottom);
546 580
547 glTexCoord2f(1.f, border_height_fraction); 581 glTexCoord2d(uv_rect.mRight, clipped_scale_rect.mBottom);
548 glVertex2i(width, scaled_border_height); 582 glVertex2i(width, draw_scale_rect.mBottom);
549 583
550 glTexCoord2f(1.f, 1.f - border_height_fraction); 584 glTexCoord2d(uv_rect.mRight, clipped_scale_rect.mTop);
551 glVertex2i(width, height - scaled_border_height); 585 glVertex2i(width, draw_scale_rect.mTop);
552 586
553 glTexCoord2f(1.f - border_width_fraction, 1.f - border_height_fraction); 587 glTexCoord2d(clipped_scale_rect.mRight, clipped_scale_rect.mTop);
554 glVertex2i(width - scaled_border_width, height - scaled_border_height); 588 glVertex2i(draw_scale_rect.mRight, draw_scale_rect.mTop);
555 589
556 // draw top left 590 // draw top left
557 glTexCoord2f(0.f, 1.f - border_height_fraction); 591 glTexCoord2d(uv_rect.mLeft, clipped_scale_rect.mTop);
558 glVertex2i(0, height - scaled_border_height); 592 glVertex2i(0, draw_scale_rect.mTop);
559 593
560 glTexCoord2f(border_width_fraction, 1.f - border_height_fraction); 594 glTexCoord2f(clipped_scale_rect.mLeft, clipped_scale_rect.mTop);
561 glVertex2i(scaled_border_width, height - scaled_border_height); 595 glVertex2i(draw_scale_rect.mLeft, draw_scale_rect.mTop);
562 596
563 glTexCoord2f(border_width_fraction, 1.f); 597 glTexCoord2f(clipped_scale_rect.mLeft, uv_rect.mTop);
564 glVertex2i(scaled_border_width, height); 598 glVertex2i(draw_scale_rect.mLeft, height);
565 599
566 glTexCoord2f(0.f, 1.f); 600 glTexCoord2d(uv_rect.mLeft, uv_rect.mTop);
567 glVertex2i(0, height); 601 glVertex2i(0, height);
568 602
569 // draw top middle 603 // draw top middle
570 glTexCoord2f(border_width_fraction, 1.f - border_height_fraction); 604 glTexCoord2f(clipped_scale_rect.mLeft, clipped_scale_rect.mTop);
571 glVertex2i(scaled_border_width, height - scaled_border_height); 605 glVertex2i(draw_scale_rect.mLeft, draw_scale_rect.mTop);
572 606
573 glTexCoord2f(1.f - border_width_fraction, 1.f - border_height_fraction); 607 glTexCoord2d(clipped_scale_rect.mRight, clipped_scale_rect.mTop);
574 glVertex2i(width - scaled_border_width, height - scaled_border_height); 608 glVertex2i(draw_scale_rect.mRight, draw_scale_rect.mTop);
575 609
576 glTexCoord2f(1.f - border_width_fraction, 1.f); 610 glTexCoord2d(clipped_scale_rect.mRight, uv_rect.mTop);
577 glVertex2i(width - scaled_border_width, height); 611 glVertex2i(draw_scale_rect.mRight, height);
578 612
579 glTexCoord2f(border_width_fraction, 1.f); 613 glTexCoord2f(clipped_scale_rect.mLeft, uv_rect.mTop);
580 glVertex2i(scaled_border_width, height); 614 glVertex2i(draw_scale_rect.mLeft, height);
581 615
582 // draw top right 616 // draw top right
583 glTexCoord2f(1.f - border_width_fraction, 1.f - border_height_fraction); 617 glTexCoord2d(clipped_scale_rect.mRight, clipped_scale_rect.mTop);
584 glVertex2i(width - scaled_border_width, height - scaled_border_height); 618 glVertex2i(draw_scale_rect.mRight, draw_scale_rect.mTop);
585 619
586 glTexCoord2f(1.f, 1.f - border_height_fraction); 620 glTexCoord2d(uv_rect.mRight, clipped_scale_rect.mTop);
587 glVertex2i(width, height - scaled_border_height); 621 glVertex2i(width, draw_scale_rect.mTop);
588 622
589 glTexCoord2f(1.f, 1.f); 623 glTexCoord2d(uv_rect.mRight, uv_rect.mTop);
590 glVertex2i(width, height); 624 glVertex2i(width, height);
591 625
592 glTexCoord2f(1.f - border_width_fraction, 1.f); 626 glTexCoord2d(clipped_scale_rect.mRight, uv_rect.mTop);
593 glVertex2i(width - scaled_border_width, height); 627 glVertex2i(draw_scale_rect.mRight, height);
594 } 628 }
595 glEnd(); 629 glEnd();
596 } 630 }
@@ -602,12 +636,12 @@ void gl_draw_scaled_image_with_border(S32 x, S32 y, S32 border_width, S32 border
602 } 636 }
603} 637}
604 638
605void gl_draw_rotated_image(S32 x, S32 y, F32 degrees, LLImageGL* image, const LLColor4& color) 639void gl_draw_rotated_image(S32 x, S32 y, F32 degrees, LLImageGL* image, const LLColor4& color, const LLRectf& uv_rect)
606{ 640{
607 gl_draw_scaled_rotated_image( x, y, image->getWidth(0), image->getHeight(0), degrees, image, color ); 641 gl_draw_scaled_rotated_image( x, y, image->getWidth(0), image->getHeight(0), degrees, image, color, uv_rect );
608} 642}
609 643
610void gl_draw_scaled_rotated_image(S32 x, S32 y, S32 width, S32 height, F32 degrees, LLImageGL* image, const LLColor4& color) 644void gl_draw_scaled_rotated_image(S32 x, S32 y, S32 width, S32 height, F32 degrees, LLImageGL* image, const LLColor4& color, const LLRectf& uv_rect)
611{ 645{
612 if (NULL == image) 646 if (NULL == image)
613 { 647 {
@@ -635,16 +669,16 @@ void gl_draw_scaled_rotated_image(S32 x, S32 y, S32 width, S32 height, F32 degre
635 669
636 glBegin(GL_QUADS); 670 glBegin(GL_QUADS);
637 { 671 {
638 glTexCoord2f(1.f, 1.f); 672 glTexCoord2f(uv_rect.mRight, uv_rect.mTop);
639 glVertex2i(width, height ); 673 glVertex2i(width, height );
640 674
641 glTexCoord2f(0.f, 1.f); 675 glTexCoord2f(uv_rect.mLeft, uv_rect.mTop);
642 glVertex2i(0, height ); 676 glVertex2i(0, height );
643 677
644 glTexCoord2f(0.f, 0.f); 678 glTexCoord2f(uv_rect.mLeft, uv_rect.mBottom);
645 glVertex2i(0, 0); 679 glVertex2i(0, 0);
646 680
647 glTexCoord2f(1.f, 0.f); 681 glTexCoord2f(uv_rect.mRight, uv_rect.mBottom);
648 glVertex2i(width, 0); 682 glVertex2i(width, 0);
649 } 683 }
650 glEnd(); 684 glEnd();
@@ -653,7 +687,7 @@ void gl_draw_scaled_rotated_image(S32 x, S32 y, S32 width, S32 height, F32 degre
653} 687}
654 688
655 689
656void gl_draw_scaled_image_inverted(S32 x, S32 y, S32 width, S32 height, LLImageGL* image, const LLColor4& color) 690void gl_draw_scaled_image_inverted(S32 x, S32 y, S32 width, S32 height, LLImageGL* image, const LLColor4& color, const LLRectf& uv_rect)
657{ 691{
658 if (NULL == image) 692 if (NULL == image)
659 { 693 {
@@ -673,16 +707,16 @@ void gl_draw_scaled_image_inverted(S32 x, S32 y, S32 width, S32 height, LLImageG
673 707
674 glBegin(GL_QUADS); 708 glBegin(GL_QUADS);
675 { 709 {
676 glTexCoord2f(1.f, 0.f); 710 glTexCoord2f(uv_rect.mRight, uv_rect.mBottom);
677 glVertex2i(width, height ); 711 glVertex2i(width, height );
678 712
679 glTexCoord2f(0.f, 0.f); 713 glTexCoord2f(uv_rect.mLeft, uv_rect.mBottom);
680 glVertex2i(0, height ); 714 glVertex2i(0, height );
681 715
682 glTexCoord2f(0.f, 1.f); 716 glTexCoord2f(uv_rect.mLeft, uv_rect.mTop);
683 glVertex2i(0, 0); 717 glVertex2i(0, 0);
684 718
685 glTexCoord2f(1.f, 1.f); 719 glTexCoord2f(uv_rect.mRight, uv_rect.mTop);
686 glVertex2i(width, 0); 720 glVertex2i(width, 0);
687 } 721 }
688 glEnd(); 722 glEnd();
@@ -1584,40 +1618,6 @@ void LLUI::loadIdentity()
1584 LLFontGL::sCurOrigin.mZ = 0; 1618 LLFontGL::sCurOrigin.mZ = 0;
1585} 1619}
1586 1620
1587//static
1588void LLUI::setScissorRegionScreen(const LLRect& rect)
1589{
1590 stop_glerror();
1591 S32 x,y,w,h;
1592 x = llround(rect.mLeft * LLUI::sGLScaleFactor.mV[VX]);
1593 y = llround(rect.mBottom * LLUI::sGLScaleFactor.mV[VY]);
1594 w = llround(rect.getWidth() * LLUI::sGLScaleFactor.mV[VX]);
1595 h = llround(rect.getHeight() * LLUI::sGLScaleFactor.mV[VY]);
1596 glScissor( x,y,w,h );
1597 stop_glerror();
1598}
1599
1600//static
1601void LLUI::setScissorRegionLocal(const LLRect& rect)
1602{
1603 stop_glerror();
1604 S32 screen_left = LLFontGL::sCurOrigin.mX + rect.mLeft;
1605 S32 screen_bottom = LLFontGL::sCurOrigin.mY + rect.mBottom;
1606
1607 S32 x,y,w,h;
1608
1609 x = llround((F32)screen_left * LLUI::sGLScaleFactor.mV[VX]);
1610 y = llround((F32)screen_bottom * LLUI::sGLScaleFactor.mV[VY]);
1611 w = llround((F32)rect.getWidth() * LLUI::sGLScaleFactor.mV[VX]);
1612 h = llround((F32)rect.getHeight() * LLUI::sGLScaleFactor.mV[VY]);
1613
1614 w = llmax(0,w);
1615 h = llmax(0,h);
1616
1617 glScissor(x,y,w,h);
1618 stop_glerror();
1619}
1620
1621//static 1621//static
1622void LLUI::setScaleFactor(const LLVector2 &scale_factor) 1622void LLUI::setScaleFactor(const LLVector2 &scale_factor)
1623{ 1623{
@@ -1696,6 +1696,34 @@ LLVector2 LLUI::getWindowSize()
1696} 1696}
1697 1697
1698//static 1698//static
1699void LLUI::screenPointToGL(S32 screen_x, S32 screen_y, S32 *gl_x, S32 *gl_y)
1700{
1701 *gl_x = llround((F32)screen_x * sGLScaleFactor.mV[VX]);
1702 *gl_y = llround((F32)screen_y * sGLScaleFactor.mV[VY]);
1703}
1704
1705//static
1706void LLUI::glPointToScreen(S32 gl_x, S32 gl_y, S32 *screen_x, S32 *screen_y)
1707{
1708 *screen_x = llround((F32)gl_x / sGLScaleFactor.mV[VX]);
1709 *screen_y = llround((F32)gl_y / sGLScaleFactor.mV[VY]);
1710}
1711
1712//static
1713void LLUI::screenRectToGL(const LLRect& screen, LLRect *gl)
1714{
1715 screenPointToGL(screen.mLeft, screen.mTop, &gl->mLeft, &gl->mTop);
1716 screenPointToGL(screen.mRight, screen.mBottom, &gl->mRight, &gl->mBottom);
1717}
1718
1719//static
1720void LLUI::glRectToScreen(const LLRect& gl, LLRect *screen)
1721{
1722 glPointToScreen(gl.mLeft, gl.mTop, &screen->mLeft, &screen->mTop);
1723 glPointToScreen(gl.mRight, gl.mBottom, &screen->mRight, &screen->mBottom);
1724}
1725
1726//static
1699LLUUID LLUI::findAssetUUIDByName(const LLString &asset_name) 1727LLUUID LLUI::findAssetUUIDByName(const LLString &asset_name)
1700{ 1728{
1701 if(asset_name == LLString::null) return LLUUID::null; 1729 if(asset_name == LLString::null) return LLUUID::null;
@@ -1710,64 +1738,169 @@ LLUUID LLUI::findAssetUUIDByName(const LLString &asset_name)
1710 return LLUUID( foundValue ); 1738 return LLUUID( foundValue );
1711} 1739}
1712 1740
1741//static
1742LLUIImage* LLUI::getUIImageByName(const LLString& name)
1743{
1744 return sImageProvider->getUIImageByID(findAssetUUIDByName(name));
1745}
1746
1747
1713// static 1748// static
1714void LLUI::setHtmlHelp(LLHtmlHelp* html_help) 1749void LLUI::setHtmlHelp(LLHtmlHelp* html_help)
1715{ 1750{
1716 LLUI::sHtmlHelp = html_help; 1751 LLUI::sHtmlHelp = html_help;
1717} 1752}
1718 1753
1754LLScreenClipRect::LLScreenClipRect(const LLRect& rect, BOOL enabled) : mScissorState(GL_SCISSOR_TEST), mEnabled(enabled)
1755{
1756 if (mEnabled)
1757 {
1758 pushClipRect(rect);
1759 }
1760 mScissorState.setEnabled(!sClipRectStack.empty());
1761 updateScissorRegion();
1762}
1763
1764LLScreenClipRect::~LLScreenClipRect()
1765{
1766 if (mEnabled)
1767 {
1768 popClipRect();
1769 }
1770 updateScissorRegion();
1771}
1772
1719//static 1773//static
1720void LLUI::pushClipRect(const LLRect& rect) 1774void LLScreenClipRect::pushClipRect(const LLRect& rect)
1721{ 1775{
1722 LLRect combined_clip_rect = rect; 1776 LLRect combined_clip_rect = rect;
1723 if (!sClipRectStack.empty()) 1777 if (!sClipRectStack.empty())
1724 { 1778 {
1725 combined_clip_rect.intersectWith(sClipRectStack.top()); 1779 LLRect top = sClipRectStack.top();
1780 combined_clip_rect.intersectWith(top);
1726 } 1781 }
1727 sClipRectStack.push(combined_clip_rect); 1782 sClipRectStack.push(combined_clip_rect);
1728 setScissorRegionScreen(combined_clip_rect);
1729} 1783}
1730 1784
1731//static 1785//static
1732void LLUI::popClipRect() 1786void LLScreenClipRect::popClipRect()
1733{ 1787{
1734 sClipRectStack.pop(); 1788 sClipRectStack.pop();
1735 if (!sClipRectStack.empty())
1736 {
1737 setScissorRegionScreen(sClipRectStack.top());
1738 }
1739} 1789}
1740 1790
1741LLClipRect::LLClipRect(const LLRect& rect, BOOL enabled) : mScissorState(GL_SCISSOR_TEST, enabled), mEnabled(enabled) 1791//static
1792void LLScreenClipRect::updateScissorRegion()
1742{ 1793{
1743 if (mEnabled) 1794 if (sClipRectStack.empty()) return;
1744 { 1795
1745 LLUI::pushClipRect(rect); 1796 LLRect rect = sClipRectStack.top();
1746 } 1797 stop_glerror();
1798 S32 x,y,w,h;
1799 x = llfloor(rect.mLeft * LLUI::sGLScaleFactor.mV[VX]);
1800 y = llfloor(rect.mBottom * LLUI::sGLScaleFactor.mV[VY]);
1801 w = llmax(0, llceil(rect.getWidth() * LLUI::sGLScaleFactor.mV[VX])) + 1;
1802 h = llmax(0, llceil(rect.getHeight() * LLUI::sGLScaleFactor.mV[VY])) + 1;
1803 glScissor( x,y,w,h );
1804 stop_glerror();
1747} 1805}
1748 1806
1749LLClipRect::~LLClipRect() 1807
1808LLLocalClipRect::LLLocalClipRect(const LLRect &rect, BOOL enabled)
1809: LLScreenClipRect(LLRect(rect.mLeft + LLFontGL::sCurOrigin.mX,
1810 rect.mTop + LLFontGL::sCurOrigin.mY,
1811 rect.mRight + LLFontGL::sCurOrigin.mX,
1812 rect.mBottom + LLFontGL::sCurOrigin.mY),
1813 enabled)
1750{ 1814{
1751 if (mEnabled)
1752 {
1753 LLUI::popClipRect();
1754 }
1755} 1815}
1756 1816
1757LLLocalClipRect::LLLocalClipRect(const LLRect &rect, BOOL enabled) : mScissorState(GL_SCISSOR_TEST, enabled), mEnabled(enabled) 1817
1818//
1819// LLUIImage
1820//
1821
1822LLUIImage::LLUIImage(LLPointer<LLImageGL> image) :
1823 mImage(image),
1824 mScaleRegion(0.f, 1.f, 1.f, 0.f),
1825 mClipRegion(0.f, 1.f, 1.f, 0.f),
1826 mUniformScaling(TRUE),
1827 mNoClip(TRUE)
1758{ 1828{
1759 if (mEnabled)
1760 {
1761 LLRect scissor_rect = rect;
1762 scissor_rect.translate(LLFontGL::sCurOrigin.mX, LLFontGL::sCurOrigin.mY);
1763 LLUI::pushClipRect(scissor_rect);
1764 }
1765} 1829}
1766 1830
1767LLLocalClipRect::~LLLocalClipRect() 1831void LLUIImage::setClipRegion(const LLRectf& region)
1832{
1833 mClipRegion = region;
1834 mNoClip = mClipRegion.mLeft == 0.f
1835 && mClipRegion.mRight == 1.f
1836 && mClipRegion.mBottom == 0.f
1837 && mClipRegion.mTop == 1.f;
1838}
1839
1840void LLUIImage::setScaleRegion(const LLRectf& region)
1841{
1842 mScaleRegion = region;
1843 mUniformScaling = mScaleRegion.mLeft == 0.f
1844 && mScaleRegion.mRight == 1.f
1845 && mScaleRegion.mBottom == 0.f
1846 && mScaleRegion.mTop == 1.f;
1847}
1848
1849//TODO: move drawing implementation inside class
1850void LLUIImage::draw(S32 x, S32 y, const LLColor4& color)
1768{ 1851{
1769 if (mEnabled) 1852 gl_draw_image(x, y, mImage, color, mClipRegion);
1853}
1854
1855void LLUIImage::draw(S32 x, S32 y, S32 width, S32 height, const LLColor4& color)
1856{
1857 if (mUniformScaling)
1858 {
1859 gl_draw_scaled_image(x, y, width, height, mImage, color, mClipRegion);
1860 }
1861 else
1770 { 1862 {
1771 LLUI::popClipRect(); 1863 gl_draw_scaled_image_with_border(
1864 x, y,
1865 width, height,
1866 mImage,
1867 color,
1868 FALSE,
1869 mClipRegion,
1870 mScaleRegion);
1772 } 1871 }
1773} 1872}
1873
1874void LLUIImage::drawSolid(S32 x, S32 y, S32 width, S32 height, const LLColor4& color)
1875{
1876 gl_draw_scaled_image_with_border(
1877 x, y,
1878 width, height,
1879 mImage,
1880 color,
1881 TRUE,
1882 mClipRegion,
1883 mScaleRegion);
1884}
1885
1886void LLUIImage::drawSolid(S32 x, S32 y, const LLColor4& color)
1887{
1888 gl_draw_scaled_image_with_border(
1889 x, y,
1890 getWidth(), getHeight(),
1891 mImage,
1892 color,
1893 TRUE,
1894 mClipRegion,
1895 mScaleRegion);
1896}
1897
1898S32 LLUIImage::getWidth()
1899{
1900 return mImage->getWidth(0);
1901}
1902
1903S32 LLUIImage::getHeight()
1904{
1905 return mImage->getHeight(0);
1906}