font_window.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:6k
- /*
- * ===========================================================================
- * PRODUCTION $Log: font_window.cpp,v $
- * PRODUCTION Revision 1000.1 2004/06/01 20:52:14 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.3
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: font_window.cpp,v 1000.1 2004/06/01 20:52:14 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: Mike DiCuccio
- *
- * File Description:
- *
- */
- #include <ncbi_pch.hpp>
- #include "font_window.hpp"
- BEGIN_NCBI_SCOPE
- CFontWindow::CFontWindow(int x, int y, int w, int h, const char* label)
- : CGlCanvas2d(x, y, w, h)
- {
- m_Camera.SetLayout(CGlCamera::eOrtho);
- m_Camera.SetLeftPlane (0);
- m_Camera.SetRightPlane (w);
- m_Camera.SetTopPlane (h);
- m_Camera.SetBottomPlane(0);
- m_Camera.SetNearPlane( 1.0f);
- m_Camera.SetFarPlane (-1.0f);
- }
- void CFontWindow::resize(int x, int y, int w, int h)
- {
- CGlCanvas2d::resize(x, y, w, h);
- m_Camera.SetRightPlane(w);
- m_Camera.SetTopPlane (h);
- }
- void CFontWindow::draw()
- {
- x_DrawBackground(1.0f, 1.0f, 1.0f);
- x_SetupView();
- if ( !m_Font ) {
- SetFont(CGlBitmapFont::eHelvetica10);
- }
- glColor3f(0.0f, 0.0f, 0.0f);
- int panel_x = 10;
- int panel_y = 10;
- int panel_wid = w() - 20;
- int panel_ht = (h() - 20) / 4;
- int text_ht = m_Font->TextHeight();
- string str;
- //
- // panel 1: centered
- //
- str = "Centered text in (";
- str += NStr::IntToString(panel_x) + ", ";
- str += NStr::IntToString(panel_y) + ", ";
- str += NStr::IntToString(panel_x + panel_wid) + ", ";
- str += NStr::IntToString(panel_y + panel_ht ) + ")";
- str += " text height = " + NStr::IntToString(text_ht);
- str += " (and a tag to make it long)";
- m_Font->TextOut(panel_x, panel_y, panel_wid, panel_ht,
- str.c_str(), FL_ALIGN_CENTER);
- glBegin(GL_LINE_LOOP);
- glVertex2f(panel_x, panel_y);
- glVertex2f(panel_x + panel_wid, panel_y);
- glVertex2f(panel_x + panel_wid, panel_y + panel_ht);
- glVertex2f(panel_x, panel_y + panel_ht);
- glEnd();
- //
- // panel 2: right justified
- //
- panel_y += panel_ht;
- str = "Right justified text in (";
- str += NStr::IntToString(panel_x) + ", ";
- str += NStr::IntToString(panel_y) + ", ";
- str += NStr::IntToString(panel_x + panel_wid) + ", ";
- str += NStr::IntToString(panel_y + panel_ht ) + ")";
- str += " (and a tag to make it long)";
- m_Font->TextOut(panel_x, panel_y, panel_wid, panel_ht,
- str.c_str(), FL_ALIGN_RIGHT);
- glBegin(GL_LINE_LOOP);
- glVertex2f(panel_x, panel_y);
- glVertex2f(panel_x + panel_wid, panel_y);
- glVertex2f(panel_x + panel_wid, panel_y + panel_ht);
- glVertex2f(panel_x, panel_y + panel_ht);
- glEnd();
- //
- // panel 3: top-left justified
- //
- panel_y += panel_ht;
- str = "Top-Left justified text in (";
- str += NStr::IntToString(panel_x) + ", ";
- str += NStr::IntToString(panel_y) + ", ";
- str += NStr::IntToString(panel_x + panel_wid) + ", ";
- str += NStr::IntToString(panel_y + panel_ht ) + ")";
- str += " (and blunt-end truncation)";
- m_Font->TextOut(panel_x, panel_y, panel_wid, panel_ht,
- str.c_str(), FL_ALIGN_TOP | FL_ALIGN_LEFT,
- CGlBitmapFont::eTruncate_Empty);
- glBegin(GL_LINE_LOOP);
- glVertex2f(panel_x, panel_y);
- glVertex2f(panel_x + panel_wid, panel_y);
- glVertex2f(panel_x + panel_wid, panel_y + panel_ht);
- glVertex2f(panel_x, panel_y + panel_ht);
- glEnd();
- //
- // panel 4: bottom-right justified
- //
- panel_y += panel_ht;
- str = "Bottom-Right justified text in (";
- str += NStr::IntToString(panel_x) + ", ";
- str += NStr::IntToString(panel_y) + ", ";
- str += NStr::IntToString(panel_x + panel_wid) + ", ";
- str += NStr::IntToString(panel_y + panel_ht ) + ")";
- str += " (and a tag to make it long)";
- m_Font->TextOut(panel_x, panel_y, panel_wid, panel_ht,
- str.c_str(), FL_ALIGN_BOTTOM | FL_ALIGN_RIGHT);
- glBegin(GL_LINE_LOOP);
- glVertex2f(panel_x, panel_y);
- glVertex2f(panel_x + panel_wid, panel_y);
- glVertex2f(panel_x + panel_wid, panel_y + panel_ht);
- glVertex2f(panel_x, panel_y + panel_ht);
- glEnd();
- }
- void CFontWindow::SetFont(CGlBitmapFont::EFont font)
- {
- make_current();
- m_Font.Reset(new CGlBitmapFont(font));
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: font_window.cpp,v $
- * Revision 1000.1 2004/06/01 20:52:14 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.3
- *
- * Revision 1.3 2004/05/21 22:27:45 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.2 2003/09/29 15:44:15 dicuccio
- * Inverted Y axis coordinate (made OpenGL normal)
- *
- * Revision 1.1 2003/09/17 16:22:03 dicuccio
- * Initial revision
- *
- * ===========================================================================
- */