phylo_tree_label.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:6k
- /*
- * ===========================================================================
- * 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 fonts
- void 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 fonts
- void 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
- *
- * ===========================================================================
- */