alnmulti_renderer.cpp

来自「ncbi源码」· C++ 代码 · 共 636 行 · 第 1/2 页

CPP
636
字号
/* * =========================================================================== * PRODUCTION $Log: alnmulti_renderer.cpp,v $ * PRODUCTION Revision 1000.1  2004/06/01 21:07:11  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.12 * PRODUCTION * =========================================================================== *//*  $Id: alnmulti_renderer.cpp,v 1000.1 2004/06/01 21:07:11 gouriano Exp $ * =========================================================================== * *                            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:  Andrey Yazhuk * * File Description: * */#include <ncbi_pch.hpp>#include <corelib/ncbistl.hpp>#include <corelib/ncbitime.hpp>#include <gui/widgets/aln_multiple/alnmulti_renderer.hpp>#include <algorithm>BEGIN_NCBI_SCOPEstatic const int kRulerSpace = 4;static const int kMasterRowSpace = 4;CAlnMultiRenderer::CAlnMultiRenderer(const TVPRect& rc): m_pContext(NULL),  m_RulerAreaHeight(0),  m_MasterAreaHeight(0),  m_ListAreaHeight(0),  m_bFocused(true){    m_RulerPane.EnableOffset();    SetBackColor(CGlColor(0.95f, 1.0f, 0.95f)); //light green    m_Ruler.SetHorizontal(true, CRuler::eTop);    m_RulerAreaHeight = m_Ruler.GetPreferredSize().Y() + kRulerSpace;    // setup columns    AddColumn(120, "Description", IAlignRow::eDescr);        AddColumn(40, "Icons", IAlignRow::eIcons);    AddColumn(60, "Start", IAlignRow::eStart);    AddColumn(0,"Alignment", IAlignRow::eAlignment, 1.0); // resizable, takes 100% of free space    AddColumn(60, "End", IAlignRow::eEnd);    AddColumn(60, "SeqEnd", IAlignRow::eSeqEnd);    Resize(rc);}void CAlnMultiRenderer::SetContext(IAlnMultiRendererContext* p_context){    m_pContext = p_context;}void    CAlnMultiRenderer::SetBackColor(const CGlColor Color){    m_BackColor = Color;}const CGlColor&    CAlnMultiRenderer::GetBackColor() const{    return m_BackColor;}CRuler&    CAlnMultiRenderer::GetRuler(){    return m_Ruler;}void    CAlnMultiRenderer::Resize(const TVPRect& rc){    m_rcBounds = rc;        x_LayoutColumns();    x_Layout();}/// Graphics is rendered inthe current OpenGL context in the viewport defined/// by the / following rectangle/// (0, 0, m_rcBounds.Width() - 1, m_rcBounds.Height() - 1)void    CAlnMultiRenderer::Render(){    x_Render(NULL);}void    CAlnMultiRenderer::Render(TAreaVector& areas){    x_Render(&areas);}void    CAlnMultiRenderer::x_Render(TAreaVector* p_areas){    glClearColor(m_BackColor.GetRed(), m_BackColor.GetGreen(),                 m_BackColor.GetBlue(), m_BackColor.GetAlpha());    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    x_RenderRuler(p_areas);    x_ResetRowListMap();    x_RenderMasterRow();    x_RenderItems(p_areas);    x_PurgeRowListMap();}void    CAlnMultiRenderer::Update(){    x_Layout();    m_RowToList.clear();}void    CAlnMultiRenderer::SetRulerHeight(int height){    m_RulerAreaHeight = height;    x_Layout();}/////////////////////////////////////////////////////////////////////////////////// protected membersint     CAlnMultiRenderer::GetListTop() const{    return m_rcBounds.Height() - m_ListAreaHeight;}int     CAlnMultiRenderer::GetColumnIndexByType(EColumnType type) const{    int n_col = GetColumnsCount();    for( int i = 0; i < n_col; i++ )    {        if(m_vColumns[i].m_UserData == type)            return i;    }        return -1;}TVPRect     CAlnMultiRenderer::GetColumnRect(int i_col) const{    const SColumn& Col = GetColumn(i_col);    return  TVPRect(Col.m_Pos, 0,                    Col.m_Pos + Col.m_Width -1, m_rcBounds.Height() - 1);}TVPRect     CAlnMultiRenderer::GetColumnRect(EColumnType Type)   const{    int iCol = GetColumnIndexByType(Type);    return GetColumnRect(iCol);}IAlignRow::EColumnType    CAlnMultiRenderer::GetColumnTypeByIndex(int i_col) const{    _ASSERT(i_col > -1);    int type = (int) GetColumn(i_col).m_UserData;    return (IAlignRow::EColumnType) type;}IAlignRow::EColumnType    CAlnMultiRenderer::GetColumnTypeByX(int x) const{    int i_col = CAlnMultiRenderer::GetColumnIndexByX(x);    if(i_col >= 0)  {        int type = (int) GetColumn(i_col).m_UserData;        return (IAlignRow::EColumnType) type;    } else return IAlignRow::eInvalid;}void    CAlnMultiRenderer::x_Layout(){    m_MasterAreaHeight = kMasterRowSpace * 2;    if(x_GetContext()) {        IAlignRow* pRow = x_GetContext()->GetMasterRow();        if(pRow)            m_MasterAreaHeight += pRow->GetHeightPixels();    }    m_ListAreaHeight = GetVPListTop() + 1;}void    CAlnMultiRenderer::x_RenderRuler(TAreaVector* p_areas){    if(m_RulerAreaHeight > 0)   {        int iAlign = GetColumnIndexByType(IAlignRow::eAlignment);                const SColumn& col = GetColumn(iAlign);        if(col.VisibleWidth())  {            TVPUnit bot_y = m_ListAreaHeight + m_MasterAreaHeight;            TVPUnit top_y = bot_y  + m_RulerAreaHeight - 1;            TVPRect rc_vp(col.m_Pos, bot_y, col.m_Pos + col.m_Width - 1, top_y);            m_RulerPane.SetViewport(rc_vp);            const CGlPane& port = x_GetContext()->GetAlignPort();                TModelRect rcM = port.GetModelLimitsRect();              rcM.SetVert(0, m_RulerAreaHeight - 1);                      m_RulerPane.SetModelLimitsRect(rcM);                  TModelRect rcV = port.GetVisibleRect();                    rcV.SetVert(0, m_RulerAreaHeight - 1);                      m_RulerPane.SetVisibleRect(rcV);                       m_Ruler.Render(m_RulerPane);  // render            if(p_areas) {                CHTMLActiveArea area(CHTMLActiveArea::eLink, rc_vp,                                     "Ruler", "Ruler", "");                p_areas->push_back(area);            }        }    }}void    CAlnMultiRenderer::x_RenderMasterRow(){    CGlPane pane(CGlPane::eNeverUpdate);    pane.EnableOffset();    TVPRect rc(0, m_ListAreaHeight);    rc.SetSize(m_rcBounds.Width(), m_MasterAreaHeight);    pane.SetViewport(rc);    pane.OpenPixels();    glColor3f(0.85f, 1.0f, 0.85f);    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);    glRecti(rc.Left(), rc.Bottom(), rc.Right(), rc.Top());    pane.Close();    int state = x_GetContext()->IsRendererFocused() ?                           IAlignRow::fWidgetFocused  : IAlignRow::fNone;    IAlignRow* p_row = x_GetContext()->GetMasterRow();    if(p_row)    {        int H = p_row->GetHeightPixels();        x_RenderRow(p_row, pane, state, rc.Bottom() + H + kMasterRowSpace, NULL);    }}void    CAlnMultiRenderer::x_RenderItems(TAreaVector* p_areas){    if(x_GetContext()) {        // calculate visible range        const CGlPane& port = x_GetContext()->GetAlignPort();        TModelRect rcM = port.GetVisibleRect();        int iFirst = x_GetContext()->GetLineByModelY((int) rcM.Top());        iFirst = max(iFirst, 0);        int iLast = x_GetContext()->GetLineByModelY((int) rcM.Bottom());        iLast = (iLast == -1) ? x_GetContext()->GetLinesCount()-1 : iLast;        if(iLast >= iFirst) {            x_RenderItemsRange(iFirst, iLast, p_areas);        }    }}void CAlnMultiRenderer::x_RenderItemsRange(int iFirst, int iLast,                                           TAreaVector* p_areas){    if(x_GetContext()) {        const CGlPane& port = x_GetContext()->GetAlignPort();        // create clipping rectangle        TVPRect rc_clip = port.GetViewport();        rc_clip.SetHorz(0, m_rcBounds.Width() - 1);        if(rc_clip.Height()  &&  rc_clip.Width())  {            int y1 = GetVPListTop() + (int) port.GetVisibleRect().Top();            const int base_state = m_bFocused ?                                   IAlignRow::fWidgetFocused  : IAlignRow::fNone;            int i_focused = x_GetContext()->GetFocusedItemIndex();            // create a single CGlPane for rendering all cells in all rows            CGlPane pane(p_areas ? CGlPane::eAlwaysUpdate : CGlPane::eNeverUpdate);            pane.EnableOffset();            pane.SetClipRect(&rc_clip);            for( int i = iFirst ; i <= iLast ; i++) {                IAlignRow* p_row = x_GetContext()->GetRowByLine(i);                int state = base_state;                if(x_GetContext()->IsItemSelected(i))                    state |= IAlignRow::fItemSelected;                if(i_focused == i)                    state |= IAlignRow::fItemFocused;                int y = y1 - x_GetContext()->GetLinePosY(i);                x_RenderRow(p_row, pane, state, y, p_areas);            }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?