phylo_tree_label.cpp

来自「ncbi源码」· C++ 代码 · 共 162 行

CPP
162
字号
/* * =========================================================================== * PRODUCTION $Log: phylo_tree_label.cpp,v $ * PRODUCTION Revision 1000.1  2004/06/02 20:24:31  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.5 * PRODUCTION * =========================================================================== *//*  $Id: phylo_tree_label.cpp,v 1000.1 2004/06/02 20:24:31 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 <gui/widgets/phylo_tree/phylo_tree_label.hpp>BEGIN_NCBI_SCOPE//////////////////////////////////////////////////////////////////////// Construction/Destruction//////////////////////////////////////////////////////////////////////CPhyloTreeLabel::CPhyloTreeLabel(){    x_CreateFonts();}CPhyloTreeLabel::~CPhyloTreeLabel(){    x_DestroyFonts();}// initialization of fontsvoid CPhyloTreeLabel::x_CreateFonts(void){    // m_Fonts.push_back(new CGlBitmapFont(CGlBitmapFont::eHelvetica6));    m_Fonts.push_back(new CGlBitmapFont(CGlBitmapFont::eHelvetica8));    m_Fonts.push_back(new CGlBitmapFont(CGlBitmapFont::eHelvetica10));    m_Fonts.push_back(new CGlBitmapFont(CGlBitmapFont::eHelvetica12));    m_Fonts.push_back(new CGlBitmapFont(CGlBitmapFont::eHelvetica14));    m_Fonts.push_back(new CGlBitmapFont(CGlBitmapFont::eHelvetica18));    m_Fonts.push_back(new CGlBitmapFont(CGlBitmapFont::eHelvetica20));        m_Fonts.push_back(new CGlBitmapFont(CGlBitmapFont::eHelvetica24));    }// deinitialization of fontsvoid CPhyloTreeLabel::x_DestroyFonts(void){    for (vector <CGlBitmapFont*> :: iterator it = m_Fonts.begin(); it!=m_Fonts.end(); it++){        delete *it;    }    m_Fonts.clear();}CGlBitmapFont * CPhyloTreeLabel::x_BestFont(int size){        CGlBitmapFont * bestFont = NULL;        for (vector <CGlBitmapFont*> :: iterator it = m_Fonts.begin(); it!=m_Fonts.end(); it++){       if (size > (*it)->TextHeight()) bestFont = *it;    }    return bestFont ? bestFont : *m_Fonts.begin();}CGlRect<int> CPhyloTreeLabel::GetRect(CGlPane& pane, CGlPoint<int> & pos, string text, bool bLeft){    CGlRect<int>    boundBox;    CGlBitmapFont * bestFont = x_BestFont(pane.ProjectX(pane.GetVisibleRect().Left()+m_NodeSize*2));    Int4 offset = 10;        double text_h = bestFont->GetMetric(CGlBitmapFont::eMetric_CharHeight);    double text_w = bestFont->TextWidth(text.c_str());          boundBox.Init(pane.UnProjectX(pane.ProjectX(pos.X() + ((!bLeft)?offset:-offset)) - text_w),                  pane.UnProjectY(pane.ProjectY(pos.Y()) - text_h/2),                  pane.UnProjectX(pane.ProjectX(pos.X() + ((!bLeft)?offset:-offset)) + text_w),                  pane.UnProjectY(pane.ProjectY(pos.Y()) + text_h/2));                      return boundBox;}void CPhyloTreeLabel::Render(CGlPane& pane, CGlPoint<int> & pos, string text, bool bSelected, bool bLeft){            CGlBitmapFont * bestFont = x_BestFont(pane.ProjectX(pane.GetVisibleRect().Left()+m_NodeSize*2));    glColor4fv((bSelected?m_LabelSelColor:m_LabelColor).GetGlColor());        Int4 offset = 10;        double text_h = bestFont->GetMetric(CGlBitmapFont::eMetric_CharHeight);    double text_w = bestFont->TextWidth(text.c_str());        double out_y  = pane.UnProjectY(pane.ProjectY(pos.Y()) - text_h/2);    double out_x  = pane.UnProjectX(pane.ProjectX(pos.X()) - text_w);              double space_x =   pane.ProjectX(m_RightMargin + pane.GetVisibleRect().Left() - offset - 1);        bestFont->TextOut(((!bLeft)? pos.X() + offset: out_x - offset),                           out_y,                                                     space_x,                          text_h,                          text.c_str(),                          FL_ALIGN_LEFT);                               }END_NCBI_SCOPE/* * =========================================================================== * $Log: phylo_tree_label.cpp,v $ * Revision 1000.1  2004/06/02 20:24:31  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.5 * * Revision 1.5  2004/06/02 16:39:38  tereshko * Added font * * Revision 1.4  2004/05/21 22:27:54  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.3  2004/05/11 20:53:12  tereshko * Work in progress * * Revision 1.2  2004/05/06 19:42:21  tereshko * Rendering improvements * * Revision 1.1  2004/04/20 21:56:18  tereshko * Initial revision * * =========================================================================== */

⌨️ 快捷键说明

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