glbitmapfont.hpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:10k
- /*
- * ===========================================================================
- * PRODUCTION $Log: glbitmapfont.hpp,v $
- * PRODUCTION Revision 1000.3 2004/06/01 19:49:23 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.15
- * PRODUCTION
- * ===========================================================================
- */
- #ifndef GUI_OPENGL___GLBITMAPFONT__HPP
- #define GUI_OPENGL___GLBITMAPFONT__HPP
- /* $Id: glbitmapfont.hpp,v 1000.3 2004/06/01 19:49:23 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 <gui/opengl/glfont.hpp>
- /** @addtogroup GUI_OPENGL
- *
- * @{
- */
- BEGIN_NCBI_SCOPE
- class CGlDisplayList;
- //
- // Stand-in for GLUT fonts. This uses glBitmap directly.
- //
- class NCBI_GUIOPENGL_EXPORT CGlBitmapFont : public IGlFont
- {
- public:
- enum EFontSize {
- eFontSize_6 = 0x01,
- eFontSize_8 = 0x02,
- eFontSize_10 = 0x03,
- eFontSize_12 = 0x04,
- eFontSize_14 = 0x05,
- eFontSize_16 = 0x06,
- eFontSize_18 = 0x07,
- eFontSize_20 = 0x08,
- eFontSize_24 = 0x09
- };
- enum EFontFace {
- eFontFace_Bitmap = 0x0100,
- eFontFace_Helvetica = 0x0200,
- eFontFace_Lucida = 0x0300,
- eFontFace_Courier = 0x0400,
- eFontFace_Clean = 0x0500,
- eFontFace_Fixed = 0x0600,
- eFontFace_TimesRoman = 0x0700
- };
- enum EFont {
- // fixed size fonts
- // here, size doesn't map 1:1
- eBitmap5x7 = eFontFace_Bitmap | eFontSize_8,
- eBitmap8x13 = eFontFace_Bitmap | eFontSize_12,
- eBitmap9x15 = eFontFace_Bitmap | eFontSize_14,
- eBitmap10x20 = eFontFace_Bitmap | eFontSize_18,
- eBitmap12x24 = eFontFace_Bitmap | eFontSize_24,
- // helvetica
- eHelvetica6 = eFontFace_Helvetica | eFontSize_6,
- eHelvetica8 = eFontFace_Helvetica | eFontSize_8,
- eHelvetica10 = eFontFace_Helvetica | eFontSize_10,
- eHelvetica12 = eFontFace_Helvetica | eFontSize_12,
- eHelvetica14 = eFontFace_Helvetica | eFontSize_14,
- eHelvetica18 = eFontFace_Helvetica | eFontSize_18,
- eHelvetica20 = eFontFace_Helvetica | eFontSize_20,
- eHelvetica24 = eFontFace_Helvetica | eFontSize_24,
- // lucida
- eLucida6 = eFontFace_Lucida | eFontSize_6,
- eLucida8 = eFontFace_Lucida | eFontSize_8,
- eLucida10 = eFontFace_Lucida | eFontSize_10,
- eLucida12 = eFontFace_Lucida | eFontSize_12,
- eLucida14 = eFontFace_Lucida | eFontSize_14,
- eLucida18 = eFontFace_Lucida | eFontSize_18,
- eLucida20 = eFontFace_Lucida | eFontSize_20,
- eLucida24 = eFontFace_Lucida | eFontSize_24,
- // courier
- eCourier6 = eFontFace_Courier | eFontSize_6,
- eCourier8 = eFontFace_Courier | eFontSize_8,
- eCourier10 = eFontFace_Courier | eFontSize_10,
- eCourier12 = eFontFace_Courier | eFontSize_12,
- eCourier14 = eFontFace_Courier | eFontSize_14,
- eCourier18 = eFontFace_Courier | eFontSize_18,
- eCourier20 = eFontFace_Courier | eFontSize_20,
- eCourier24 = eFontFace_Courier | eFontSize_24,
- // clean
- eClean6 = eFontFace_Clean | eFontSize_6,
- eClean8 = eFontFace_Clean | eFontSize_8,
- eClean10 = eFontFace_Clean | eFontSize_10,
- eClean12 = eFontFace_Clean | eFontSize_12,
- eClean14 = eFontFace_Clean | eFontSize_14,
- eClean18 = eFontFace_Clean | eFontSize_18,
- eClean20 = eFontFace_Clean | eFontSize_20,
- eClean24 = eFontFace_Clean | eFontSize_24,
- // fixed
- eFixed6 = eFontFace_Fixed | eFontSize_6,
- eFixed8 = eFontFace_Fixed | eFontSize_8,
- eFixed10 = eFontFace_Fixed | eFontSize_10,
- eFixed12 = eFontFace_Fixed | eFontSize_12,
- eFixed14 = eFontFace_Fixed | eFontSize_14,
- eFixed18 = eFontFace_Fixed | eFontSize_18,
- eFixed20 = eFontFace_Fixed | eFontSize_20,
- eFixed24 = eFontFace_Fixed | eFontSize_24,
- // Times Roman
- eTimesRoman6 = eFontFace_TimesRoman | eFontSize_6,
- eTimesRoman8 = eFontFace_TimesRoman | eFontSize_8,
- eTimesRoman10 = eFontFace_TimesRoman | eFontSize_10,
- eTimesRoman12 = eFontFace_TimesRoman | eFontSize_12,
- eTimesRoman14 = eFontFace_TimesRoman | eFontSize_14,
- eTimesRoman18 = eFontFace_TimesRoman | eFontSize_18,
- eTimesRoman20 = eFontFace_TimesRoman | eFontSize_20,
- eTimesRoman24 = eFontFace_TimesRoman | eFontSize_24
- };
- // default constructor. This creates a font for the 8x13 bitmap font
- // face
- CGlBitmapFont(void);
- // create a bitmap font with a particular face in mind
- CGlBitmapFont(EFont font);
- // destructor
- ~CGlBitmapFont();
- // set the font to one of the predefined options
- void SetFont (EFont font);
- void SetFontFace(EFontFace face);
- void SetFontSize(EFontSize size);
- // Dump some text somewhere
- virtual void TextOut(const char* text) const;
- virtual void TextOut(float x, float y, const char* text) const;
- // Output text into a given rectangle using a particular alignment.
- // The alignment is a bitmask of FLTK's Fl_Align enums. The only
- // distinction is that text is *always* inside
- void TextOut(float x, float y, float w, float h, const char* text,
- int align = FL_ALIGN_CENTER,
- ETruncate trunc = eTruncate_Ellipsis) const;
- string Truncate(const char*, float w, ETruncate trunc = eTruncate_Ellipsis) const;
- string Truncate(const string& str, float w, ETruncate trunc = eTruncate_Ellipsis) const;
-
- /// prints array of characters in positions (x + i*dx, y + i*dy) where
- /// "i" is index of a character in the given string
- void ArrayTextOut(float x, float y, float dx, float dy, const char* text,
- float scale_x = 1.0f, float scale_y = 1.0f) const;
- // Determine how much space a piece of text will occupy
- virtual float TextWidth (const char* text) const;
- virtual float TextWidth (const char* text, int n) const;
- virtual float TextHeight(void) const;
- // generic metric retrieval
- virtual float GetMetric(EMetric metric,
- const char* text_start = NULL,
- int len = -1) const;
- private:
- // The font we're rendering
- EFont m_Font;
- // precomputed font height
- float m_FontHeight;
- // a set of display lists, one for each character
- mutable CRef<CGlDisplayList> m_Chars[256];
- // Truncate a string for display. This returns the maximum
- // number of characters that can fit into the given width. If the
- // parameter 'str' is not null, the string will be filled out with
- // the truncated text.
- int x_Truncate(const char* text, float w, ETruncate trunc,
- string* str = NULL) const;
- // prohibit
- CGlBitmapFont(const CGlBitmapFont&);
- CGlBitmapFont& operator= (const CGlBitmapFont&);
- };
- /// temporary placed here, later should be moved to the appropriate location
- class NCBI_GUIOPENGL_EXPORT CTextUtils
- {
- public:
- static string FormatSeparatedNumber(int number, bool b_postfix = false);
-
- /// returns number of characters in symbolic representation of the given
- /// number including non-digit separators ( 1,234 )
- static int GetCharsCount(int number);
- };
- END_NCBI_SCOPE
- /* @} */
- /*
- * ===========================================================================
- * $Log: glbitmapfont.hpp,v $
- * Revision 1000.3 2004/06/01 19:49:23 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.15
- *
- * Revision 1.15 2004/05/21 12:44:37 dicuccio
- * Added new font faces
- *
- * Revision 1.14 2004/05/11 18:54:22 dicuccio
- * Added doxygne modules info
- *
- * Revision 1.13 2004/04/20 14:08:37 rsmith
- * trailing commas at the ends of lists are non-standard and give warnings on some platforms.
- *
- * Revision 1.12 2004/03/12 15:28:49 dicuccio
- * Cleaned up non-uniqueness in enums
- *
- * Revision 1.11 2004/03/11 17:17:26 dicuccio
- * Separated font face from font size
- *
- * Revision 1.10 2004/03/03 15:04:47 yazhuk
- * Fixed comments
- *
- * Revision 1.9 2003/11/17 21:02:36 yazhuk
- * Refactored Truncate(), added ArrayTextOut(),
- * renamed GetDigitsCount() to GetCharsCount()
- *
- * Revision 1.8 2003/10/29 22:26:54 yazhuk
- * Added CTextUtils class
- *
- * Revision 1.7 2003/10/09 17:59:06 lebedev
- * Truncate method made public
- *
- * Revision 1.6 2003/09/29 15:11:48 dicuccio
- * Fleshed out GetMetric() API to include text width
- *
- * Revision 1.5 2003/09/25 17:44:33 dicuccio
- * Added API for checking font metrics (only height is supported)
- *
- * Revision 1.4 2003/09/17 16:18:51 dicuccio
- * Added new API for text placement - aligned / truncated text within a defined
- * rectangle
- *
- * Revision 1.3 2003/08/28 19:28:28 dicuccio
- * Made TextOut() functions const; made display lists in CGlBitmapFont mutable
- *
- * Revision 1.2 2003/08/22 15:55:59 dicuccio
- * Added display lists to font renderer. Altered order of fonts in enum to match
- * use as array index
- *
- * Revision 1.1 2003/08/18 19:25:44 dicuccio
- * initial revision
- *
- * ===========================================================================
- */
- #endif // GUI_OPENGL___GLBITMAPFONT__HPP