NCBI C++ Toolkit Cross Reference

  C++/src/gui/widgets/seq_graphic/rendering_ctx.cpp


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 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128
/* $Id: rendering_ctx.cpp 27939 2013-04-26 15:54:25Z wuliangs $ * =========================================================================== * * PUBLIC DOMAIN NOTICE * National Center for Biotechnology Information * * This software/database is a "United States Government Work" under the * terms of the United States Copyright Act. It was written as part of * the author's official duties as a United States Government employee and * thus cannot be copyrighted. This software/database is freely available * to the public for use. The National Library of Medicine and the U.S. * Government have not placed any restriction on its use or reproduction. * * Although all reasonable efforts have been taken to ensure the accuracy * and reliability of the software and data, the NLM and the U.S. * Government do not and cannot warrant the performance or results that * may be obtained by using this software or data. The NLM and the U.S. * Government disclaim all warranties, express or implied, including * warranties of performance, merchantability or fitness for any particular * purpose. * * Please cite the author in any work or product based on this material. * * =========================================================================== * * Authors: Liangshou Wu * * File Description: * */ #include <ncbi_pch.hpp> #include <corelib/ncbistd.hpp> #include <serial/iterator.hpp> #include <gui/objutils/utils.hpp> #include <gui/opengl/glpane.hpp> #include <gui/opengl/glutils.hpp> #include <gui/opengl/glrender.hpp> #include <gui/widgets/seq_graphic/rendering_ctx.hpp> #include <math.h> BEGIN_NCBI_SCOPE CRenderingContext::CRenderingContext() : m_Pane(NULL) , m_MinLabelSize(1.0) , m_Offset(0.0) , m_Scale(1.0) , m_ScaleInv(1.0) , m_bHorz(true) , m_bFlipped(false) , m_Font_Helv10(CGlBitmapFont::eHelvetica10) {} CRenderingContext::~CRenderingContext() { m_Pane = NULL; } void CRenderingContext::PrepareContext(CGlPane& pane, bool horz, bool flipped) { m_Pane = &pane; m_bHorz = horz; m_bFlipped = flipped; m_Offset = horz ? pane.GetOffsetX() : pane.GetOffsetY(); m_Scale = fabs(horz ? pane.GetScaleX() : pane.GetScaleY()); m_ScaleInv = 1.0 / m_Scale; TModelRect rcV = pane.GetVisibleRect(); TModelRect rcM = pane.GetModelLimitsRect(); if (horz) { if (flipped) { m_VisRange.Set(rcV.Right(), rcV.Left()); m_LimitRange.Set(rcM.Right(), rcM.Left()); } else { m_VisRange.Set(rcV.Left(), rcV.Right()); m_LimitRange.Set(rcM.Left(), rcM.Right()); } } else { if (flipped) { m_VisRange.Set(rcV.Top(), rcV.Bottom()); m_LimitRange.Set(rcM.Top(), rcM.Bottom()); } else { m_VisRange.Set(rcV.Bottom(), rcV.Top()); m_LimitRange.Set(rcM.Bottom(), rcM.Top()); } } m_VisSeqRange.Set( (TSeqPos)(m_VisRange.GetFrom() + 0.5), (TSeqPos)(m_VisRange.GetTo() + 0.5)); m_MinLabelSize = ScreenToSeq(m_Font_Helv10.TextWidth("AAAAA")); } TModelRange CRenderingContext::IntersectVisible_Y(const TModelRange& r) const { TModelRange vert_range(m_Pane->GetVisibleRect().Top(), m_Pane->GetVisibleRect().Bottom()); return vert_range.IntersectionWith(r); } void CRenderingContext::DrawQuad(TModelUnit x1, TModelUnit y1, TModelUnit x2, TModelUnit y2, bool border) const { // If x1 and x2 are projected onto the same pixel on screen. // We simply draw aline instead of a quad. CGlRender& gl = GetGl(); gl.PolygonMode(GL_FRONT_AND_BACK, GL_FILL); if (fabs(x2-x1) < GetScale()) { TModelUnit mid = (x2+x1)/TModelUnit(2.0); x1 = mid-GetScale()/(TModelUnit)2.0; x2 = mid+GetScale()/(TModelUnit)2.0; } gl.Rectd(x1 - m_Offset, y1, x2 - m_Offset, y2); if (border) { DrawRect(x1, y1, x2, y2); } } void CRenderingContext::DrawShadedQuad(const TModelRect& rcm, const CRgbaColor& c1, const CRgbaColor& c2, bool shade_vert) const { CGlRender& gl = GetGl(); gl.PolygonMode(GL_FRONT_AND_BACK, GL_FILL); gl.ShadeModel(GL_SMOOTH); gl.Begin(GL_QUADS); if (shade_vert) { gl.ColorC(c1); gl.Vertex3d(rcm.Right() - m_Offset + 1, rcm.Top(), 0.0); gl.Vertex3d(rcm.Left() - m_Offset, rcm.Top(), 0.0); gl.ColorC(c2); gl.Vertex3d(rcm.Left() - m_Offset, rcm.Bottom(), 0.0); gl.Vertex3d(rcm.Right() - m_Offset + 1, rcm.Bottom(), 0.0); } else { gl.ColorC(c1); gl.Vertex3d(rcm.Left() - m_Offset, rcm.Top(), 0.0); gl.Vertex3d(rcm.Left() - m_Offset, rcm.Bottom(), 0.0); gl.ColorC(c2); gl.Vertex3d(rcm.Right() - m_Offset + 1, rcm.Bottom(), 0.0); gl.Vertex3d(rcm.Right() - m_Offset + 1, rcm.Top(), 0.0); } gl.End(); gl.ShadeModel(GL_FLAT); } void CRenderingContext::DrawSquare(const TModelPoint& p, TModelUnit size, const CRgbaColor& color, bool neg_strand) const { TModelUnit size_x = ScreenToSeq(size); TModelUnit f = neg_strand ? p.X() - size_x : p.X(); TModelUnit t = neg_strand ? p.X() - 1.0 : p.X() + size_x - 1.0; Draw3DQuad(f, p.Y() - size * 0.5f, t, p.Y() + size * 0.5f, color, true); } void CRenderingContext::DrawDisk(const TModelPoint& p, TModelUnit r, GLint from, GLint to) const { CGlRender& gl = GetGl(); gl.PolygonMode(GL_FRONT_AND_BACK, GL_FILL); const double PI_180 = 3.1415926 / 180.0; TModelUnit f = from * PI_180; TModelUnit t = to * PI_180; TModelUnit r_x = ScreenToSeq(r); gl.Begin(GL_TRIANGLE_FAN); gl.Vertex2d(p.X() - m_Offset, p.Y()); TModelUnit step = (t - f) * 0.02; for (; f < t + step * 0.02; f += step) { gl.Vertex2d(p.X() - m_Offset + r_x * cos(f), p.Y() - r * sin(f)); } gl.End(); } void CRenderingContext::DrawDisk(const TModelPoint& p, TModelUnit radius, const CRgbaColor& color, bool neg_strand) const { CGlRender& gl = GetGl(); TModelUnit add = ScreenToSeq(radius); add = neg_strand ? -add : add; TModelPoint center(p.X() + add*TModelUnit(0.5), p.Y()); CRgbaColor color2 = color; color2.Lighten(0.5f); CRgbaColor color3 = color; color3.SetAlpha(0.3f); radius *= TModelUnit(0.5); // if blend is explicitly enabled, reset it at the end bool blend_enabled = gl.GetState()->IsEnabled(GL_BLEND); // Largest circle (to get darker outside border): gl.Disable(GL_BLEND); gl.ColorC(color); DrawDisk(center, radius - TModelUnit(0.5)); // To anti-alias the edge a little: gl.Enable(GL_BLEND); gl.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); gl.ColorC(color3); DrawDisk(center, radius); // Inner circle (lighter): gl.Disable(GL_BLEND); gl.ColorC(color2); DrawDisk(center, radius - TModelUnit(1.5)); if (blend_enabled) gl.Enable(GL_BLEND); } void CRenderingContext::Draw3DTriangle(const TModelPoint& p, TModelUnit size, const CRgbaColor& color, bool neg_strand, bool need_neck) const { TModelUnit off_x = ScreenToSeq(size); TModelUnit off_y = size; TModelUnit add_x = neg_strand ? off_x : (-off_x); CRgbaColor color2 = color; color2.Lighten(0.5); CGlRender& gl = GetGl(); gl.PolygonMode(GL_FRONT_AND_BACK, GL_FILL); gl.ColorC(color); // draw "neck" if (need_neck) { DrawLine(p.X() + add_x/*+ 1*/, p.Y(), p.X() + add_x * 1.5 /*+1*/, p.Y()); } gl.ShadeModel(GL_SMOOTH); gl.Begin(GL_TRIANGLES); TModelPoint p0(p.X() + add_x, p.Y()); TModelPoint p1(p.X(), p.Y()); TModelPoint p2(p.X() + add_x, p.Y() - off_y); TModelPoint p3(p.X() + add_x, p.Y() + off_y); gl.ColorC(color2); gl.Vertex2d(p0.X() - m_Offset, p0.Y()); gl.Vertex2d(p1.X() - m_Offset, p1.Y()); gl.ColorC(color); gl.Vertex2d(p2.X() - m_Offset, p2.Y()); gl.ColorC(color2); gl.Vertex2d(p0.X() - m_Offset, p0.Y()); gl.Vertex2d(p1.X() - m_Offset, p1.Y()); gl.ColorC(color); gl.Vertex2d(p3.X() - m_Offset, p3.Y()); gl.End(); gl.ShadeModel(GL_FLAT); } void CRenderingContext::Draw3DArrow (const TModelPoint& p, TModelUnit size, bool neg_strand) const { TModelUnit off_x = ScreenToSeq(size); TModelUnit add_x = neg_strand ? off_x : (-off_x); TModelUnit off_y = size; DrawLine(p.X(), p.Y(), p.X() + add_x, p.Y() - off_y); DrawLine(p.X(), p.Y(), p.X() + add_x, p.Y() + off_y); DrawLine(p.X(), p.Y(), p.X() + add_x * 1.5, p.Y()); } void CRenderingContext::DrawArrow(TModelUnit x1, TModelUnit x2, TModelUnit x3, TModelUnit line_center, TModelUnit bar_h, TModelUnit head_h) const { CGlRender& gl = GetGl(); if (x1 != x2) { gl.Begin(GL_QUADS); gl.Vertex2d(x1 - m_Offset, line_center + bar_h); gl.Vertex2d(x2 - m_Offset, line_center + bar_h); gl.Vertex2d(x2 - m_Offset, line_center - bar_h); gl.Vertex2d(x1 - m_Offset, line_center - bar_h); gl.End(); } gl.Begin(GL_TRIANGLES); gl.Vertex2d(x2 - m_Offset, line_center + head_h); gl.Vertex2d(x3 - m_Offset, line_center); gl.Vertex2d(x2 - m_Offset, line_center - head_h); gl.End(); } void CRenderingContext::DrawArrowBoundary(TModelUnit x1, TModelUnit x2, TModelUnit x3, TModelUnit line_center, TModelUnit bar_h, TModelUnit head_h) const { CGlRender& gl = GetGl(); gl.LineJoinStyle(IGlState::eRoundedJoin); gl.Begin(GL_LINE_LOOP); gl.Vertex2d(x1 - m_Offset, line_center + bar_h); gl.Vertex2d(x2 - m_Offset, line_center + bar_h); gl.Vertex2d(x2 - m_Offset, line_center + head_h); gl.Vertex2d(x3 - m_Offset, line_center); gl.Vertex2d(x2 - m_Offset, line_center - head_h); gl.Vertex2d(x2 - m_Offset, line_center - bar_h); gl.Vertex2d(x1 - m_Offset, line_center - bar_h); gl.End(); gl.LineJoinStyle(IGlState::eMiteredJoin); } void CRenderingContext::DrawGreaterLessSign(TModelUnit x, TModelUnit y, TModelUnit bar_h, bool negative) const { TModelUnit size = bar_h * 0.5; if (bar_h >= 8.0) { size -= 1.0; } TModelUnit x_off = ScreenToSeq((negative ? -1.0 : 1.0) * size * 0.5); CGlRender& gl = GetGl(); gl.Begin(GL_LINES); gl.Vertex2d(x - m_Offset - x_off, y + size); gl.Vertex2d(x - m_Offset + x_off, y); gl.Vertex2d(x - m_Offset + x_off, y); gl.Vertex2d(x - m_Offset - x_off, y - size); gl.End(); } void CRenderingContext::Draw3DQuad(TModelUnit x1, TModelUnit y1, TModelUnit x2, TModelUnit y2, const CRgbaColor& color, bool border) const { CGlRender& gl = GetGl(); gl.PolygonMode(GL_FRONT_AND_BACK, GL_FILL); // If x1 and x2 get projected onto the same pixel on screen. // we simply draw a vertical line to represent a quad. if (x2 - x1 + 1.0 < GetScale()) { gl.ColorC(color); CGlAttrGuard AttrGuard(GL_LINE_BIT); gl.Disable(GL_LINE_SMOOTH); // HACK, mesa somehow projects y differently for drawling a line // and drawing a quad. We add an slight y offset to make this work. TModelUnit y_off = 0.0001; DrawLine(x1, y1 + y_off, x1, y2 + y_off); //gl.Enable(GL_LINE_SMOOTH); } else { TModelUnit xx1 = x1 - m_Offset; TModelUnit yy1 = y1; TModelUnit xx2 = x2 - m_Offset; TModelUnit yy2 = y2; TModelUnit mid = y1 + (y2 - y1) * 0.5f; CRgbaColor color2 = color; color2.Lighten(0.5); gl.ShadeModel(GL_SMOOTH); gl.Begin(GL_TRIANGLE_STRIP); gl.ColorC(color); gl.Vertex2d(xx1, yy1); gl.Vertex2d(xx2 + 1, yy1); gl.ColorC(color2); gl.Vertex2d(xx1, mid); gl.Vertex2d(xx2 + 1, mid); gl.ColorC(color); gl.Vertex2d(xx1, yy2); gl.Vertex2d(xx2 + 1, yy2); gl.End(); gl.ShadeModel(GL_FLAT); if (border) { gl.ColorC(color); DrawRect(x1, y1, x2 + 1.0, y2); } } } void CRenderingContext::Draw3DQuad_HorzLines(TModelUnit x1, TModelUnit y1, TModelUnit x2, TModelUnit y2, const CRgbaColor& color, bool border) const { CGlRender& gl = GetGl(); // If x1 and x2 get projected onto the same pixel on screen. // we simply draw a vertical line to represent a quad. if (x2 - x1 + 1.0 < GetScale()) { gl.ColorC(color); CGlAttrGuard AttrGuard(GL_LINE_BIT); gl.Disable(GL_LINE_SMOOTH); // HACK, mesa somehow projects y differently for drawling a line // and drawing a quad. We add an slight y offset to make this work. TModelUnit y_off = 0.0001; DrawLine(x1, y1 + y_off, x1, y2 + y_off); } else { TModelUnit xx1 = x1 - m_Offset; TModelUnit yy1 = y1; TModelUnit xx2 = x2 - m_Offset; TModelUnit yy2 = y2; TModelUnit mid = y1 + (y2 - y1) * 0.5f; CRgbaColor color2 = color; color2.Lighten(0.5); CVect4<float> c1(color.GetRed(), color.GetGreen(), color.GetBlue(), color.GetAlpha()); CVect4<float> c2(color2.GetRed(), color2.GetGreen(), color2.GetBlue(), color2.GetAlpha()); CVect4<float> c3(c1); TModelUnit delta(2.0); int steps = (y2-y1)/delta; TModelUnit ydelta = (y2-y1)/TModelUnit(steps); CVect4<float> color_delta = (c2-c1)/(float)(steps/2); gl.LineWidth(1.0f); gl.Disable(GL_LINE_SMOOTH); gl.Begin(GL_LINES); for (int i=0; i<steps; i++) { gl.Color4f(c1.X(), c1.Y(), c1.Z(), c1.W()); if (i<steps/2) c1 += color_delta; else c1 -= color_delta; double yval = yy1+ydelta*(TModelUnit)i; gl.Vertex3d(xx1, yval, 0.0); gl.Vertex3d(xx2, yval, 0.0); } gl.End(); } if (border) { gl.ColorC(color); DrawRect(x1, y1, x2, y2); } } void CRenderingContext::DrawRoundQuad(const TModelPoint& cnt, TModelUnit w, TModelUnit h, TModelUnit r) const { CGlRender& gl = GetGl(); gl.PolygonMode(GL_FRONT_AND_BACK, GL_FILL); double PI = 3.1415926; double step = PI/16; double angle = 0.0; TModelUnit r_x = ScreenToSeq(r); TModelPoint p(cnt.X() - m_Offset, cnt.Y()); TModelUnit x = p.X() + w - r_x; TModelUnit y = p.Y() - h + r; gl.Begin(GL_TRIANGLE_FAN); gl.Vertex2d(x, y); for (; angle < PI * 0.5; angle += step) { gl.Vertex2d(x + r_x * cos(angle), y - r * sin(angle)); } x = p.X() - w + r_x; for (angle = PI * 0.5; angle < PI; angle += step) { gl.Vertex2d(x + r_x * cos(angle), y - r * sin(angle)); } y = p.Y() + h - r; for (angle = PI; angle < PI * 1.5; angle += step) { gl.Vertex2d(x + r_x * cos(angle), y - r * sin(angle)); } x = p.X() + w - r_x; for (angle = PI * 1.5; angle < PI * 2; angle += step) { gl.Vertex2d(x + r_x * cos(angle), y - r * sin(angle)); } gl.End(); } void CRenderingContext::Draw3DFletch(TModelUnit pos_x, TModelUnit line_y1, TModelUnit line_y2, TModelUnit tail_height, const CRgbaColor& color, bool neg_strand) const { CGlRender& gl = GetGl(); TModelUnit off = ScreenToSeq(tail_height); TModelUnit mid = line_y1 + (line_y2 - line_y1) * 0.5f; TModelUnit add = neg_strand ? -off : off; CRgbaColor color2 = color; color2.Lighten(0.5); gl.ShadeModel(GL_SMOOTH); gl.Begin(GL_TRIANGLES); // p0 is a start point TModelPoint p0(pos_x + add, mid); TModelPoint p1(pos_x + add, line_y1); TModelPoint p2(pos_x , line_y1); TModelPoint p3(pos_x + add, line_y2); TModelPoint p4(pos_x , line_y2); gl.ColorC(color2); gl.Vertex2d(p0.X() - m_Offset, p0.Y()); gl.ColorC(color); gl.Vertex2d(p1.X() - m_Offset, p1.Y()); gl.Vertex2d(p2.X() - m_Offset, p2.Y()); gl.ColorC(color2); gl.Vertex2d(p0.X() - m_Offset, p0.Y()); gl.ColorC(color); gl.Vertex2d(p3.X() - m_Offset, p3.Y()); gl.Vertex2d(p4.X() - m_Offset, p4.Y()); gl.End(); gl.ShadeModel(GL_FLAT); gl.ColorC(color); gl.LineWidth(1.5f); // draw border DrawLine(pos_x, line_y1, pos_x + add, line_y1); DrawLine(pos_x, line_y1, pos_x + add, mid); DrawLine(pos_x, line_y2, pos_x + add, line_y2); DrawLine(pos_x, line_y2, pos_x + add, mid); gl.LineWidth(1.0f); } void CRenderingContext::DrawSelection(TModelUnit x1, TModelUnit y1, TModelUnit x2, TModelUnit y2) const { CGlRender& gl = GetGl(); // expand 1 pix on each side TModelUnit padding_y = 1.0; TModelUnit padding_x = ScreenToSeq(padding_y); gl.ColorC(m_SelColor); gl.LineWidth(1.5f); DrawRect(x1 - padding_x, y1 + padding_y, x2 + padding_x, y2 - padding_y); gl.LineWidth(1.0f); } void CRenderingContext::DrawRect(TModelUnit x1, TModelUnit y1, TModelUnit x2, TModelUnit y2) const { CGlRender& gl = GetGl(); gl.LineJoinStyle(IGlState::eRoundedJoin); gl.Begin(GL_LINE_LOOP); gl.Vertex2d(x1 - m_Offset, y1); gl.Vertex2d(x1 - m_Offset, y2); gl.Vertex2d(x2 - m_Offset, y2); gl.Vertex2d(x2 - m_Offset, y1); gl.End(); gl.LineJoinStyle(IGlState::eMiteredJoin); } void CRenderingContext::DrawBackground(const TModelRect& rcm, TModelUnit border) const { CGlRender& gl = GetGl(); TModelRect rect(rcm); TModelUnit border_x = ScreenToSeq(border); // bottom > top which is the reverse of CGlRect rect.Inflate(border_x, -border); gl.Rectd(rect.Left() - m_Offset, rect.Bottom(), rect.Right() - m_Offset, rect.Top()); } void CRenderingContext::DrawStrandIndicators(const TModelPoint& start, TModelUnit length, TModelUnit apart, TModelUnit size, const CRgbaColor& color, bool neg_strand, bool avoid_center) const { CGlRender& gl = GetGl(); // adjust the start and lenght to ensure only draw indicators // inside the visible range TModelUnit start_x(start.X()); TModelUnit start_y(start.Y()); TModelUnit min_v = m_VisRange.GetFrom(); TModelUnit max_v = m_VisRange.GetTo(); if (start_x < min_v) { start_x = min_v; length -= start_x - start.X(); } if (start_x + length > max_v) { length = max_v - start_x; } int strand_sign = neg_strand ? -1 : 1; TModelUnit w1 = 0.2 * size * m_Scale; TModelUnit w2 = 4.0 * w1; TModelUnit half = 0.4 * size; TModelUnit size_x1 = strand_sign * w1; TModelUnit size_x2 = strand_sign * w2; TModelUnit size_y1 = half; TModelUnit size_y2 = half * 2.0; int num = (int)floor(length / apart - 0.2f) + 1; TModelUnit off = (length - apart * (num - 1)) * 0.5 - strand_sign * w2 * 0.5; TModelUnit off_x = off - m_Offset + start_x; TModelUnit off_y = start_y + 0.1 * size; gl.ShadeModel(GL_FLAT); //gl.Disable(GL_BLEND); gl.PdfShadeStyle(CGlState::eFlat); for (int i = 0; i < num; ++i) { if (avoid_center && num % 2 == 1 && i == (num - 1) / 2) { off_x += apart; continue; } CRgbaColor curr_color(color.GetRed(), color.GetGreen(), color.GetBlue(), color.GetAlpha()); curr_color.Darken(i % 3 * 0.12f); gl.ColorC(curr_color); gl.Begin(GL_TRIANGLE_STRIP); gl.Vertex2d(off_x + 0.0, off_y + size_y2); gl.Vertex2d(off_x + size_x2 , off_y + size_y1); gl.Vertex2d(off_x + size_x1, off_y + size_y1); gl.Vertex2d(off_x, off_y); gl.End(); off_x += apart; } } void CRenderingContext::Draw5Prime(TModelUnit x, TModelUnit y, bool direct, TModelUnit size_h, TModelUnit size_v) const { TModelUnit two_pixel_w = ScreenToSeq(2.0); size_h = ScreenToSeq(size_h); TModelUnit tri_w = (size_h - two_pixel_w) * 0.5; TModelUnit tri_h = (size_v - 2.0) * 0.5; const char* label = "5'"; //CGlBitmapFont font(CGlBitmapFont::eHelvetica8); CGlTextureFont font(CGlTextureFont::eFontFace_Helvetica_Bold, 8); size_v -= 1.0; TModelRect rect; TModelUnit label_x, label_y; if (direct) { rect.SetLeft(x); rect.SetRight(x + size_h); rect.SetTop(y - size_v); rect.SetBottom(y); label_x = x + two_pixel_w; label_y = y - 2.0; } else { rect.SetLeft(x - size_h); rect.SetRight(x); rect.SetTop(y + size_v); rect.SetBottom(y); label_x = x - size_h + tri_w - two_pixel_w * 0.5; label_y = y + size_v - 1.0; } DrawRect(rect); if (direct) { TModelUnit corner_x = x + size_h; DrawTriangle(corner_x, y, corner_x, y - tri_h, corner_x - tri_w, y); TModelUnit corner_y = y - size_v; DrawTriangle(corner_x, corner_y, corner_x - tri_w, corner_y, corner_x, corner_y + tri_h); } else { TModelUnit corner_x = x - size_h; DrawTriangle(corner_x, y, corner_x, y + tri_h, corner_x + tri_w, y); TModelUnit corner_y = y + size_v; DrawTriangle(corner_x, corner_y, corner_x + tri_w, corner_y, corner_x, corner_y - tri_h); } TextOut(&font, label, label_x, label_y, false); } void CRenderingContext::DrawTexture(const TModelRect& rc, const TModelRect& rc_coord) const { CGlRender& gl = GetGl(); CGlAttrGuard AttrGuard(GL_LINE_BIT); gl.Disable(GL_LINE_SMOOTH); gl.Begin(GL_QUADS); gl.TexCoord2d(rc_coord.Left(), rc_coord.Bottom()); gl.Vertex2d(rc.Left() - m_Offset, rc.Bottom()); gl.TexCoord2d(rc_coord.Right(), rc_coord.Bottom()); gl.Vertex2d(rc.Right() - m_Offset, rc.Bottom()); gl.TexCoord2d(rc_coord.Right(), rc_coord.Top()); gl.Vertex2d(rc.Right() - m_Offset, rc.Top()); gl.TexCoord2d(rc_coord.Left(), rc_coord.Top()); gl.Vertex2d(rc.Left() - m_Offset, rc.Top()); gl.End(); gl.Enable(GL_LINE_SMOOTH); } void CRenderingContext::DrawHairLine(int opt, size_t total, const multiset <TSeqPos>& all_pos, TSeqPos pos, TModelUnit line_y, const CRgbaColor& c_light, const CRgbaColor& c_dark) const { // use light color when no intersection, dark otherwise //CRgbaColor c_dark c_light = m_ConfigSettings->GetElementColor( // CSeqGraphicColorConfig::eSelection_HairlineOne); //CRgbaColor c_dark = m_ConfigSettings->GetElementColor( // CSeqGraphicColorConfig::eSelection_HairlineMany); CGlRender& gl = GetGl(); bool need_line = true; CRgbaColor color; switch (opt) { case 1: // 1. Show all hairlines with selections color = all_pos.count(pos) > 1 ? c_dark : c_light; break; case 2: // 2. Show only hairlines that are not shared (i.e., places that are different) color = c_light; need_line = all_pos.count(pos) == 1; break; case 3: // 3. Show only hairlines that are shared by any two of the selections color = c_dark; need_line = all_pos.count(pos) >= 2; break; case 4: // 4. Show hairlines shared by *all* of the selections. color = c_dark; need_line = all_pos.count(pos) == total; break; } TModelRect rcV = m_Pane->GetVisibleRect(); // render "From" if (need_line) { CGlAttrGuard AttrGuard(GL_LINE_BIT); gl.ColorC(color); gl.Disable(GL_LINE_SMOOTH); DrawLine(pos, line_y, pos, m_bHorz ? rcV.Top() : rcV.Right()); gl.Enable(GL_LINE_SMOOTH); } } void CRenderingContext::DrawUnalignedTail(TModelUnit x1, TModelUnit x2, TModelUnit y1, TModelUnit y2, bool is_polya) const { CGlRender& gl = GetGl(); { CGlAttrGuard AttrGuard(GL_LINE_BIT); gl.Disable(GL_LINE_SMOOTH); gl.Begin(GL_LINE_LOOP); gl.Vertex2d(x1 - m_Offset, y1); gl.Vertex2d(x1 - m_Offset, y2); gl.Vertex2d(x2 - m_Offset, y2); gl.Vertex2d(x2 - m_Offset, y1); gl.End(); } gl.Color3f(1.0f, 0.2f, 0.2f); if (is_polya) { //CGlBitmapFont font(CGlBitmapFont::eHelvetica8); CGlTextureFont font(CGlTextureFont::eFontFace_Helvetica_Bold, 8); TextOut(&font, "pA", (x1 + x2) * 0.5, y2 - 2, true); } else { //TModelUnit off_v = (y2 - y1) * 0.2; TModelUnit off_h = (x2 - x1) / 6; //x1 += off_h; //y1 += off_v; //y2 -= off_v; gl.Begin(GL_LINE_STRIP); gl.Vertex2d(x1 - m_Offset, y2); x1 += 2 * off_h; gl.Vertex2d(x1 - m_Offset, y1); x1 += 0.5 * off_h; gl.Vertex2d(x1 - m_Offset, y2); x1 += off_h; gl.Vertex2d(x1 - m_Offset, y1); x1 += 0.5 * off_h; gl.Vertex2d(x1 - m_Offset, y2); x1 += 2 * off_h; gl.Vertex2d(x1 - m_Offset, y1); gl.End(); } } // slant dashed line void CRenderingContext::DrawPseudoBar(TModelUnit x1, TModelUnit y1, TModelUnit x2, TModelUnit y2, const CRgbaColor& light_color, const CRgbaColor& dark_color) const { CGlRender& gl = GetGl(); TModelUnit xoff = 0.0; TModelUnit delta = ScreenToSeq(8.0); bool shaded = true; if (fabs(x2-x1) <= GetScale()) { gl.ColorC(light_color); CGlAttrGuard AttrGuard(GL_LINE_BIT); gl.Disable(GL_LINE_SMOOTH); // HACK, mesa somehow projects y differently for drawling a line // and drawing a quad. We add an slight y offset to make this work. TModelUnit y_off = 0.0001; DrawLine(x1, y1 + y_off, x1, y2 + y_off); return; } // Draw a triangle strip alternating colors for each pair of triangles gl.ShadeModel(GL_FLAT); gl.PdfShadeStyle(IGlState::eFlat); gl.Enable(GL_BLEND); gl.Begin(GL_TRIANGLE_STRIP); gl.ColorC(light_color); gl.Vertex3d(x1 - m_Offset, y1, 0.0); gl.Vertex3d(x1 - m_Offset, y2, 0.0); while (xoff+delta <= x2-x1) { xoff += delta; gl.Vertex3d(x1 + xoff - m_Offset, y1, 0.0); if (shaded) gl.ColorC(dark_color); else gl.ColorC(light_color); gl.Vertex3d(x1 + xoff - m_Offset, y2, 0.0); shaded = !shaded; } // Draw end (should pretty much always be a little more // to draw...) if (x1 + xoff < x2) { gl.Vertex3d(x2 - m_Offset, y1, 0.0); if (shaded) gl.ColorC(dark_color); else gl.ColorC(light_color); gl.Vertex3d(x2 - m_Offset, y2, 0.0); } gl.End(); } // Draw 2 <'s with some anti-aliasing. The previous texture approach // worked just as well (or better), but doesn't work with PDF output void CRenderingContext::DrawPartialBarMark(TModelUnit x1, TModelUnit y1, TModelUnit y2, bool loc, TModelUnit dir) const { CGlRender& gl = GetGl(); TModelUnit mid = (y1 + y2)/2.0; TModelUnit w1 = dir*ScreenToSeq(1.0); TModelUnit w2 = dir*ScreenToSeq(5.0); if (loc) { gl.Color4f(0.3f, 0.1f, 0.1f, 0.7f); } else { gl.Color4f(1.0f, 1.0f, 1.0f, 0.7f); } // darker single-width arrow gl.Begin(GL_TRIANGLES); gl.Vertex3d(x1 + w1 - m_Offset, mid, 0.0); gl.Vertex3d(x1 + w2 - m_Offset, y2, 0.0); gl.Vertex3d(x1 + w2-w1 - m_Offset, y2, 0.0); gl.Vertex3d(x1 + w1 - m_Offset, mid, 0.0); gl.Vertex3d(x1 + w2-w1 - m_Offset, y2, 0.0); gl.Vertex3d(x1 - m_Offset, mid, 0.0); gl.Vertex3d(x1 + w1 - m_Offset, mid, 0.0); gl.Vertex3d(x1 + w2 - m_Offset, y1, 0.0); gl.Vertex3d(x1 + w2-w1 - m_Offset, y1, 0.0); gl.Vertex3d(x1 + w1 - m_Offset, mid, 0.0); gl.Vertex3d(x1 + w2-w1 - m_Offset, y1, 0.0); gl.Vertex3d(x1 - m_Offset, mid, 0.0); gl.End(); if (loc) { gl.Color4f(0.3f, 0.1f, 0.1f, 0.3f); } else { gl.Color4f(1.0f, 1.0f, 1.0f, 0.3f); } // Overlay lighter arrow for antialiasing w1 = dir*ScreenToSeq(3.0); w2 = dir*ScreenToSeq(7.0); x1 -= dir*ScreenToSeq(1.0); gl.Begin(GL_TRIANGLES); gl.Vertex3d(x1 + w1 - m_Offset, mid, 0.0); gl.Vertex3d(x1 + w2 - m_Offset, y2, 0.0); gl.Vertex3d(x1 + w2-w1 - m_Offset, y2, 0.0); gl.Vertex3d(x1 + w1 - m_Offset, mid, 0.0); gl.Vertex3d(x1 + w2-w1 - m_Offset, y2, 0.0); gl.Vertex3d(x1 - m_Offset, mid, 0.0); gl.Vertex3d(x1 + w1 - m_Offset, mid, 0.0); gl.Vertex3d(x1 + w2 - m_Offset, y1, 0.0); gl.Vertex3d(x1 + w2-w1 - m_Offset, y1, 0.0); gl.Vertex3d(x1 + w1 - m_Offset, mid, 0.0); gl.Vertex3d(x1 + w2-w1 - m_Offset, y1, 0.0); gl.Vertex3d(x1 - m_Offset, mid, 0.0); gl.End(); } // symbol '>>' void CRenderingContext::DrawPartialBar(TModelUnit x1, TModelUnit y1, TModelUnit x2, TModelUnit y2, bool p_start, bool p_stop, bool loc) const { CGlRender& gl = GetGl(); TModelUnit tex_len = ScreenToSeq(8); if (x2 - x1 < tex_len) return; if (p_start) { DrawPartialBarMark(x1+ScreenToSeq(1.0), y1, y2, loc); DrawPartialBarMark(x1 + ScreenToSeq(5.0), y1, y2, loc); } if (p_stop && (!p_start || (x2 - x1) > 2.0 * tex_len)) { gl.Disable(GL_CULL_FACE); DrawPartialBarMark(x2-ScreenToSeq(1.0), y1, y2, loc, -1); DrawPartialBarMark(x2-ScreenToSeq(5.0), y1, y2, loc, -1); } } void CRenderingContext::DrawHighlight(const TModelRect& rect) const { CGlRender& gl = GetGl(); TModelUnit band_w = 4.0; TModelUnit band_w_x = ScreenToSeq(band_w); TModelUnit left = rect.Left() - m_Offset; TModelUnit right = rect.Right() - m_Offset; TModelUnit top = rect.Top() - 1.0; TModelUnit bottom = rect.Bottom(); //CRgbaColor color1(0.23f, 0.63f, 0.73f, 1.0f); //CRgbaColor color2(0.23f, 0.63f, 0.73f, 0.1f); CRgbaColor color1(0.4f, 0.4f, 0.4f, 1.0f); CRgbaColor color2(0.5f, 0.5f, 0.5f, 0.1f); gl.ShadeModel(GL_FLAT); gl.ShadeModel(GL_SMOOTH); gl.Begin(GL_QUADS); gl.ColorC(color1); gl.Vertex3d(left, top, 0.0); gl.Vertex3d(right, top, 0.0); gl.ColorC(color2); gl.Vertex3d(right, top - band_w, 0.0); gl.Vertex3d(left, top - band_w, 0.0); gl.ColorC(color1); gl.Vertex3d(right, bottom, 0.0); gl.Vertex3d(left, bottom, 0.0); gl.ColorC(color2); gl.Vertex3d(left, bottom + band_w, 0.0); gl.Vertex3d(right, bottom + band_w, 0.0); gl.ColorC(color1); gl.Vertex3d(left, bottom, 0.0); gl.Vertex3d(left, top, 0.0); gl.ColorC(color2); gl.Vertex3d(left - band_w_x, top, 0.0); gl.Vertex3d(left - band_w_x, bottom, 0.0); gl.ColorC(color1); gl.Vertex3d(right, bottom, 0.0); gl.Vertex3d(right, top, 0.0); gl.ColorC(color2); gl.Vertex3d(right + band_w_x, top, 0.0); gl.Vertex3d(right + band_w_x, bottom, 0.0); gl.ColorC(color1); gl.Vertex3d(left, top, 0.0); gl.ColorC(color2); gl.Vertex3d(left, top - band_w, 0.0); gl.Vertex3d(left - band_w_x, top - band_w, 0.0); gl.Vertex3d(left - band_w_x, top, 0.0); gl.ColorC(color1); gl.Vertex3d(right, top, 0.0); gl.ColorC(color2); gl.Vertex3d(right + band_w_x, top, 0.0); gl.Vertex3d(right + band_w_x, top - band_w, 0.0); gl.Vertex3d(right, top - band_w, 0.0); gl.ColorC(color1); gl.Vertex3d(left, bottom, 0.0); gl.ColorC(color2); gl.Vertex3d(left, bottom + band_w, 0.0); gl.Vertex3d(left - band_w_x, bottom + band_w, 0.0); gl.Vertex3d(left - band_w_x, bottom, 0.0); gl.ColorC(color1); gl.Vertex3d(right, bottom, 0.0); gl.ColorC(color2); gl.Vertex3d(right + band_w_x, bottom, 0.0); gl.Vertex3d(right + band_w_x, bottom + band_w, 0.0); gl.Vertex3d(right, bottom + band_w, 0.0); gl.End(); gl.ShadeModel(GL_FLAT); } void CRenderingContext::TextOut(const CGlTextureFont* font, const char* text, TModelUnit x, TModelUnit y, bool center, bool adjust_flip) const { CGlRender& gl = GetGl(); x -= m_Offset; TModelUnit width = ScreenToSeq(font->TextWidth(text)); if (center) { x += m_bHorz ? -width * 0.5 : width * 0.5; //x = max(x, TModelUnit(0.0)); } if (m_bFlipped && adjust_flip) { x += m_bHorz ? width : -width; } gl.BeginText(font); gl.WriteText(x, y, text); gl.EndText(); } void CRenderingContext::TextOut(const CGlBitmapFont* font, const char* text, TModelUnit x, TModelUnit y, bool center, bool adjust_flip) const { x -= m_Offset; TModelUnit width = ScreenToSeq(font->TextWidth(text)); if (center) { x += m_bHorz ? -width * 0.5 : width * 0.5; //x = max(x, TModelUnit(0.0)); } if (m_bFlipped && adjust_flip) { x += m_bHorz ? width : -width; } font->TextOut(x, y, text); } void CRenderingContext::DrawLine(TModelUnit x1, TModelUnit y1, TModelUnit x2, TModelUnit y2) const { CGlRender& gl = GetGl(); gl.Begin(GL_LINES); gl.Vertex2d(x1 - m_Offset, y1); gl.Vertex2d(x2 - m_Offset, y2); gl.End(); } END_NCBI_SCOPE

source navigation ]   [ diff markup ]   [ identifier search ]   [ freetext search ]   [ file search ]  

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.