phylo_tree_render.cpp

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

CPP
529
字号
/* * =========================================================================== * PRODUCTION $Log: phylo_tree_render.cpp,v $ * PRODUCTION Revision 1000.2  2004/06/02 20:24:36  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.15 * PRODUCTION * =========================================================================== *//*  $Id: phylo_tree_render.cpp,v 1000.2 2004/06/02 20:24:36 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:  Vladimir Tereshkov * * File Description: * */#include <ncbi_pch.hpp>#include <corelib/ncbistl.hpp>#include <gui/opengl/glhelpers.hpp>#include <gui/graph/igraph_utils.hpp>#include <gui/widgets/phylo_tree/phylo_tree_render.hpp>#include <FL/Fl.H>#include <math.h>BEGIN_NCBI_SCOPEIPhyloTreeRenderer :: IPhyloTreeRenderer(){    m_DS        = NULL;    m_DimX      = GetDimX();    m_DimY      = GetDimY();    m_pLabelFont= NULL;    m_bDistMode = false;    // raster rect is setup to default hardcoded values    // it can be changed by Layout()        m_RasterRect.Init(0, 0, m_DimX, m_DimY);                      }void    IPhyloTreeRenderer::SetHost(IPhyloTreeRendererHost* pHost){    m_pHost = pHost;    }void    IPhyloTreeRenderer::x_RenderSelection(CGlPane& pane){     if(m_State == eSelRect) {        _ASSERT(m_pHost);        CGlAttrGuard AttrGuard(GL_POLYGON_BIT);        pane.OpenPixels();        glLineWidth(1.0f);        glColor3f(0.0f, 0.0f, 0.0f);        glLineStipple(1, 0x0F0F);                   glEnable(GL_LINE_STIPPLE);        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);                glDisable(GL_LINE_SMOOTH);                int x1 = m_StartPoint.X();         int y1 = m_pHost->HMGH_GetVPPosByY(m_StartPoint.Y());        int x2 = m_DragPoint.X();        int y2 = m_pHost->HMGH_GetVPPosByY(m_DragPoint.Y());        if(x2 < x1)            swap(x1, x2);        if(y2 < y1)            swap(y1, y2);        glBegin(GL_LINES);            glVertex2d(x1, y2);            glVertex2d(x2, y2);            glVertex2d(x2, y2);            glVertex2d(x2, y1);            glVertex2d(x1, y2);            glVertex2d(x1, y1);                    glVertex2d(x1, y1);            glVertex2d(x2, y1);        glEnd();        glDisable(GL_LINE_STIPPLE);        pane.Close();    }    }/////////////////////////////////////////////////////////////////////////////////// event handlersint IPhyloTreeRenderer::x_OnMousePush(CGUIEvent& event){        CGUIEvent::EGUIState state = event.GetGUIState();    if((state == CGUIEvent::eSelectState  ||  state == CGUIEvent::eSelectIncState)        && ((event.GetGUISignal() == CGUIEvent::eSelectSignal) ||(event.GetGUISignal() == CGUIEvent::ePopupSignal)))    {        if(Fl::event_clicks() == 0) {                        m_State = eSelPoint;            m_StartPoint.m_X = Fl::event_x();            m_StartPoint.m_Y = Fl::event_y();            m_DragPoint = m_StartPoint;            bool b_inc = event.GetGUIState() == CGUIEvent::eSelectIncState;                        // if not incremental - clear selection            if (!b_inc) {                m_DS->SetSelection(m_DS->GetTree(), false, true);                m_SelectedIDs.clear();            }            bool b_selected = x_SelectByPoint(m_DS->GetTree());                          m_State = b_selected ? eSelPoint : eSelRect;                                    m_pHost->FireCBEvent();            m_pHost->HMGH_Redraw();            x_OnSelectCursor();        }                        return 1;    }    return 0;}int IPhyloTreeRenderer::x_OnMouseDrag(CGUIEvent& event){    CGUIEvent::EGUIState state = event.GetGUIState();    if(m_State == eSelRect  &&  (state == CGUIEvent::eSelectState        || state == CGUIEvent::eSelectIncState) )   {                if(Fl::event_x() != m_DragPoint.X()  ||  Fl::event_y() != m_DragPoint.Y())  {            m_State = eSelRect;            m_DragPoint.m_X = Fl::event_x();            m_DragPoint.m_Y = Fl::event_y();            m_pHost->HMGH_Redraw();            x_OnSelectCursor();                }    }     return 1; // always handle drags}int IPhyloTreeRenderer::x_OnMouseRelease(CGUIEvent& event){       CGUIEvent::EGUIState state = event.GetGUIState();    if(m_State == eSelPoint)    {        return 1;    }    if(m_State == eSelRect  &&  (state == CGUIEvent::eSelectState        || state == CGUIEvent::eSelectIncState)         &&  ((event.GetGUISignal() == CGUIEvent::eRelease)||(event.GetGUISignal() == CGUIEvent::ePopupSignal)))   {                bool b_inc = event.GetGUIState() == CGUIEvent::eSelectIncState;               if (!b_inc) {            m_DS->SetSelection(m_DS->GetTree(), false, true);            m_SelectedIDs.clear();        }                x_SelectByRect(m_DS->GetTree());        m_pHost->FireCBEvent();                m_State = eIdle;        m_pHost->HMGH_Redraw();        x_OnSelectCursor();                return 1;    }        return 0;}int IPhyloTreeRenderer::x_OnMouseMove(void){    return (m_State == eIdle) ? 0 : 1;}int IPhyloTreeRenderer::x_OnKeyDown(void){    return (m_State == eIdle) ? 0 : 1;}int IPhyloTreeRenderer::x_OnKeyUp(void){    return (m_State == eIdle) ? 0 : 1;}void IPhyloTreeRenderer::x_OnSelectCursor(void){    switch(m_State)    {    case eIdle:  m_Cursor = FL_CURSOR_DEFAULT; break;    case eSelPoint: m_Cursor = FL_CURSOR_DEFAULT; break;    case eSelRect: m_Cursor = FL_CURSOR_CROSS; break;    default: break;    }       fl_cursor(m_Cursor, FL_BLACK, FL_WHITE);}void IPhyloTreeRenderer::x_RenderLine(double x1, double y1, double x2, double y2, double width, CGlColor color1, CGlColor color2){    glEnable(GL_BLEND);    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);      // correcting line width in x, y directions to not make things look ugly    double ratio = m_pPane->GetScaleY()/m_pPane->GetScaleX();            // reset line width    glLineWidth(1.0);            glShadeModel(GL_SMOOTH);    glEnable(GL_LINE_SMOOTH);    if (width>0){        // angle        double angle = (y1==y2)?1.57:atan((x2-x1)/(y1-y2));        //dx, dy        double dx = width * cos(angle);        double dy = width * sin(angle) * ratio;                    glBegin(GL_QUADS);            // bottom rectangle        glColor4fv(color1.GetGlColor());    glVertex2d(x1-dx, y1-dy); glVertex2d(x2-dx, y2-dy);         glColor4fv(color2.GetGlColor());    glVertex2d(x2, y2); glVertex2d(x1, y1);             // top rectangle            glColor4fv(color2.GetGlColor());  glVertex2d(x1, y1);    glVertex2d(x2, y2);         glColor4fv(color1.GetGlColor());  glVertex2d(x2+dx, y2+dy); glVertex2d(x1+dx, y1+dy);         glEnd();        // border            glBegin(GL_LINES);                glColor4fv(color1.GetGlColor());            glVertex2d(x1-dx, y1-dy); glVertex2d(x2-dx, y2-dy);     

⌨️ 快捷键说明

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