linear_sel_handler.cpp

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

CPP
566
字号
    m_pHost->SHH_Redraw();    }void    CLinearSelHandler::x_OnResetAll(){    bool b_update = ! m_Selection.empty();    m_Selection.clear();    m_ExtState = eNoExt;    m_OpType = eNoOp;    if(b_update)        m_pHost->SHH_Redraw();}void    CLinearSelHandler::x_OnOpChange(CGUIEvent& event){   if(m_ExtState != eNoExt)   {        EOpType NewType = x_GetOpTypeByEvent(event);                if(NewType != m_OpType) {            m_OpType = NewType;            x_OnSelectCursor();            m_pHost->SHH_Redraw();        }    } }void    CLinearSelHandler::x_OnSelectCursor(){    switch(m_OpType)    {    case eNoOp:   {        TSeqRange HitR;        bool b_hit_start = false;        x_HitTest(HitR, b_hit_start);            m_bResizeCursor = HitR.NotEmpty();    }; break;    case eAdd:     case eRemove:    case eChange:   m_bResizeCursor = true; break;    }       x_SetCursor();}void    CLinearSelHandler::x_SetCursor(){    Fl_Cursor Cur = FL_CURSOR_DEFAULT;    if(m_bResizeCursor) {        Cur = (m_Orientation == eHorz) ? FL_CURSOR_WE : FL_CURSOR_NS;     }     fl_cursor(Cur, FL_BLACK, FL_WHITE);}/////////////////////////////////////////////////////////////////////////////////// helper functions// translate modificators to operation typeCLinearSelHandler::EOpType CLinearSelHandler::x_GetOpTypeByEvent(CGUIEvent& event)    const{    switch(event.GetGUIState())    {    case CGUIEvent::eSelectState: return eAdd;    case CGUIEvent::eSelectAltState:    return eRemove;    default:    return eNoOp;    }}TModelUnit CLinearSelHandler::x_MouseToSeqPos(){    _ASSERT(m_pPane);    int z = (m_Orientation == eHorz) ? Fl::event_x() : Fl::event_y();    return m_pHost->SHH_GetModelByWindow(z, m_Orientation) + 0.5;}void    CLinearSelHandler::x_HitTest(TSeqRange& range, bool& b_hit_start){    _ASSERT(m_pPane);    int z = (m_Orientation == eHorz) ? Fl::event_x() : Fl::event_y();        int min_D = -1;    bool b_min_start = false;    const TSeqRange* p_min_range = 0;    const TRangeColl& C = m_Selection;    ITERATE(TRangeColl, it, C)  {        const TSeqRange& R = *it;        int from_Z = m_pHost->SHH_GetWindowByModel(R.GetFrom(), m_Orientation);        int to_Z = m_pHost->SHH_GetWindowByModel(R.GetToOpen(), m_Orientation);        int D = abs(z - from_Z);        if(min_D < 0 || min_D > D)    {            min_D = D;            b_min_start = true;            p_min_range = &R;        }        D = abs(z - to_Z);        if(min_D > D)    {            min_D = D;            b_min_start = false;            p_min_range = &R;        }            }    if(min_D > -1  && min_D <= kDragThreshold) {        b_hit_start = b_min_start;        _ASSERT(p_min_range);        range  = *p_min_range;    } else range.SetLength(0);}TSeqPos CLinearSelHandler::x_ClipPosByRange(TSeqPos pos){    bool b_horz = (m_Orientation == eHorz);    TModelRect rc_lim = m_pPane->GetModelLimitsRect();    pos = max(pos, (TSeqPos) (b_horz ? rc_lim.Left() : rc_lim.Bottom()));    pos = min(pos, (TSeqPos) (b_horz ? rc_lim.Right() : rc_lim.Top()));        return pos;}void    CLinearSelHandler::x_AddToSelection(const TSeqRange& range){    m_Selection.CombineWith(range);}void    CLinearSelHandler::x_RemoveFromSelection(const TSeqRange& range){    m_Selection.Subtract(range);}void    CLinearSelHandler::Render(CGlPane& pane, ERenderingOption option){    TModelRect rc_vis = pane.GetVisibleRect();        if(! rc_vis.IsEmpty()) {            pane.OpenOrtho();                TModelUnit offset_x = pane.GetOffsetX();        TModelUnit offset_y = pane.GetOffsetY();        bool b_horz = (m_Orientation == eHorz);        // draw exisiting selection        glColorC( (option == eActiveState) ? m_SelColor : m_PassiveSelColor);        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);                const TRangeColl& C = m_Selection;        ITERATE(TRangeColl, it, C)  { // for every segment            const TSeqRange& r = *it;            switch(m_Orientation)   {            case eHorz: glRectd(r.GetFrom() - offset_x, rc_vis.Bottom() - offset_y,                                 r.GetToOpen() - offset_x, rc_vis.Top() - offset_y); break;            case eVert: glRectd(rc_vis.Left() - offset_x, r.GetFrom() - offset_y,                                 rc_vis.Right() - offset_x, r.GetToOpen() - offset_y); break;            }        }                if(m_OpType != eNoOp)   { // draw current range            TModelRect rc_curr(rc_vis);            if(b_horz)  {                rc_curr.SetLeft( max(rc_vis.Left(), (TModelUnit) m_CurrRange.GetFrom()) );                rc_curr.SetRight( min(rc_vis.Right(), (TModelUnit) m_CurrRange.GetToOpen()) );            } else {                rc_curr.SetBottom( max(rc_vis.Bottom(), (TModelUnit) m_CurrRange.GetFrom()) );                rc_curr.SetTop( min(rc_vis.Top(), (TModelUnit) m_CurrRange.GetToOpen()) );            }            glRectd(rc_curr.Left() - offset_x, rc_curr.Top() - offset_y,                     rc_curr.Right() - offset_x, rc_curr.Bottom() - offset_y);                    if(option == eActiveState)  {                glColorC(m_SymbolColor);                 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);                glRectd(rc_curr.Left() - offset_x, rc_curr.Bottom() - offset_y,                         rc_curr.Right() - offset_x, rc_curr.Top() - offset_y);                                // drwaing Operation symbol                const char* s = 0;                switch(m_OpType)    {                case eAdd: s = "+"; break;                case eRemove: s = "-"; break;                case eChange: s = "<->"; break;                case eNoOp: break;                }                                        float w = m_Font.TextWidth(s) * pane.GetScaleX();                float kY = pane.GetScaleY() < 0 ? -1.0f : 1.0f;                float h = kY * m_Font.TextHeight() * pane.GetScaleY(); // make it positive                            // if there is enougth space - draw operation symbol                if(w < rc_curr.Width()  &&  h < fabs(rc_curr.Height()))   {                     float x = (rc_curr.Left() + rc_curr.Right() - w) / 2 - offset_x;                    float y = (rc_curr.Bottom() + rc_curr.Top() - h) / 2 - offset_y;                    m_Font.TextOut(x, y, s);                }            }        }        pane.Close();    }}END_NCBI_SCOPE/* * =========================================================================== * $Log: linear_sel_handler.cpp,v $ * Revision 1000.2  2004/06/01 21:10:38  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.11 * * Revision 1.11  2004/05/21 22:27:54  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.10  2004/04/06 16:07:58  yazhuk * Clean-up * * Revision 1.9  2004/03/23 14:07:37  dicuccio * Fixed compiler warnings * * Revision 1.8  2004/03/11 17:52:33  dicuccio * Use TSeqRange instead of TRange * * Revision 1.7  2004/02/12 21:00:47  yazhuk * Support of CGlPane "offset" mode * * Revision 1.6  2004/02/09 14:36:54  lebedev * Restore glPolygonMode to default state after rendering * * Revision 1.5  2004/02/09 13:49:14  lebedev * Added  methods for customizing selection colors * * Revision 1.4  2004/01/08 19:46:01  yazhuk * Clean-up * * Revision 1.3  2003/12/05 17:51:04  yazhuk * Fixed cursor selection for vertical orientation. * * Revision 1.2  2003/12/01 20:52:36  ucko * Use fabs, not abs, for floating-point numbers. * * Revision 1.1  2003/12/01 16:33:19  yazhuk * Former alnmulti_sel_handler.cpp moved to gui/widgets/gl * * Revision 1.12  2003/10/29 23:28:34  yazhuk * Changed includes * * Revision 1.11  2003/10/20 15:51:58  yazhuk * Changed keyboard events handling policy. * * Revision 1.10  2003/10/15 21:25:03  yazhuk * Fixed "selection last position" bug. Eliminated excessive updates. * * Revision 1.9  2003/10/10 19:07:36  yazhuk * Replaced glColor3fv with glColorC * * Revision 1.8  2003/10/08 14:17:25  dicuccio * use glColor3fv instead of glColorC * * Revision 1.7  2003/09/29 17:00:09  dicuccio * fl.H -> Fl.H * * Revision 1.6  2003/09/29 15:53:42  dicuccio * Reordered #include statements * * Revision 1.5  2003/09/23 21:11:21  yazhuk * Removed x_ModifiersOk() and x_ClipPosByRange() definitions * * Revision 1.4  2003/09/14 14:03:44  ucko * #include <math.h> (needed with GCC) * * Revision 1.3  2003/09/10 20:44:21  yazhuk * Improved drawing of the current range * * Revision 1.2  2003/09/08 20:49:42  yazhuk * Added functions for manipulating with Selection * * Revision 1.1  2003/09/08 16:31:49  yazhuk * Initial revision * * =========================================================================== */

⌨️ 快捷键说明

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