ruler.hpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:7k
- /*
- * ===========================================================================
- * PRODUCTION $Log: ruler.hpp,v $
- * PRODUCTION Revision 1000.4 2004/04/12 18:16:37 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [CATCHUP_003] Dev-tree R1.7
- * PRODUCTION
- * ===========================================================================
- */
- #ifndef GUI_WIDGETS_GL___RULER__HPP
- #define GUI_WIDGETS_GL___RULER__HPP
- /* $Id: ruler.hpp,v 1000.4 2004/04/12 18:16:37 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: Andrey Yazhuk
- *
- * File Description:
- *
- */
- #include <gui/opengl/glbitmapfont.hpp>
- #include <gui/opengl/glpane.hpp>
- #include <gui/widgets/gl/irenderable.hpp>
- BEGIN_NCBI_SCOPE
- ////////////////////////////////////////////////////////////////////////////////
- /// CRuler is a renderable object drawing a scale with position labels.
- class NCBI_GUIWIDGETS_GL_EXPORT CRuler : public IRenderable
- {
- public:
- enum EColorType {
- eRuller,
- eText,
- eBackground
- };
- enum EGeometryParam {
- eRegularTickHeight,
- eMajorTickHeight
- };
- enum ELabelPlacement {
- eBottom,
- eTop,
- eLeft,
- eRight,
- eDefault
- };
- enum EDisplayOptions {
- fHideLabels = 0x1, // do not render labels along the scale
- fShowOrigin = 0x2, // draw "Origin" label
- fShowMetric = 0x4 // draw "Metric"
- };
-
- /// Origin specifies position in the model space that is represented as "1"
- /// by the Ruler. It can be thought of as offset of the local coordinate
- /// system associated with Ruler relative to the global coordinate system.
-
- CRuler(bool b_horz = true);
- virtual ~CRuler();
- void SetHorizontal(bool b_horz, ELabelPlacement place = eDefault);
- void SetColor(EColorType type, const CGlColor& color);
- void SetFont(CGlBitmapFont::EFont font_type);
- void SetGeometryParam(EGeometryParam geom, int value);
-
- // takes a combination of EDisplayOptions flags
- void SetDisplayOptions(int options);
-
- /// SetAutoRange() activates automatic mode in which ruler's range is equal to
- /// the provided model limits range (obtained by CGlPane::GetModelLimitsRect()).
- void SetAutoRange();
-
- /// SetRange() activates "custom" or "manual" mode in which rulers's range in
- /// model space is explicitly limited to [Start, End], SeqStart specifies number
- /// corresponding to the first position in the range; if b_reverse == "true"
- /// then labels SeqStart will correspond to End and displayed numbers will
- /// increase from right to the left.
- void SetRange(int Start, int End, int SeqStart, bool b_reverse);
-
- TVPPoint GetPreferredSize() const;
- virtual void Render(CGlPane& pane);
- virtual TVPRect GetVPRect();
- virtual TModelRect GetModelRect();
- protected:
- int x_ToDisplay(int model) const;
- int x_ToModel(int display) const;
- void x_CalculatePosLabelsStep(CGlPane& Pane);
- void x_RenderScale(CGlPane& pane, int first_elem, int last_elem);
- void x_RenderAllPosLabels(CGlPane& pane, int first_elem, int last_elem);
- void x_RenderOriginAndMetric(CGlPane& pane);
-
- string x_GetPositionLabel(int iElem);
- void x_GenerateLabelPositions(int first_elem, int last_elem,
- vector<int>& vElemPos);
- void x_RenderPosLabel(CGlPane& pane, double pos_u,
- double label_offset_u, const string& Text);
-
- int x_GetBaseHeight() const;
- protected:
- bool m_bHorz;
- //bool m_bReverse;
- ELabelPlacement m_LabelPlace;
- TVPRect m_rcBounds;
- bool m_bAutoRange;
- int m_Start, m_End; /// range in model space represented by ruller
- int m_Offset; /// added to m_Start to produce displayed numbers, so that
- /// range displayed is [m_Start + m_Offset, m_End + m_Offset]
-
- bool m_bReverseDisplay;
-
- int m_DisplayOptions;
- CGlBitmapFont m_Font;
- CGlColor m_TextColor;
- CGlColor m_RullerColor;
- CGlColor m_BackColor;
-
- // Layout params
- int m_MajorTickSize;
- int m_RegTickSize;
- bool m_bDirty; /// "true" if parameters affecting layout have been changed
- TModelRect m_rcLimits;
- double m_ScaleX, m_ScaleY;
- double m_MaxLabelW;
- double m_MaxLabelH;
-
- int m_BaseStep; // has form 10^X, m_PosLabelsStep = K * m_BaseStep;
- int m_PosLabelsStep; // distance between two labels (in model coords)
- int m_TickSpace; // distance beween two regular ticks (in model coords)
- };
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: ruler.hpp,v $
- * Revision 1000.4 2004/04/12 18:16:37 gouriano
- * PRODUCTION: UPGRADED [CATCHUP_003] Dev-tree R1.7
- *
- * Revision 1.7 2004/03/04 19:32:44 yazhuk
- * Added comments
- *
- * Revision 1.6 2004/03/02 21:53:38 yazhuk
- * Added rendering of origin and metric
- *
- * Revision 1.5 2003/12/10 16:55:25 yazhuk
- * Implemented control over displayed range, offset and direction.
- *
- * Revision 1.4 2003/12/01 16:34:08 yazhuk
- * Added m_BaseStep data member
- *
- * Revision 1.3 2003/11/18 17:55:31 yazhuk
- * Fixed GCC warnings
- *
- * Revision 1.2 2003/11/18 00:52:18 yazhuk
- * Restored IRenderable implementation
- *
- * Revision 1.1 2003/11/17 20:22:53 yazhuk
- * Renamed from ruller.hpp
- *
- * Revision 1.2 2003/10/31 14:05:53 dicuccio
- * Fixed spelling error: CRuller -> CRuler
- *
- * Revision 1.1 2003/10/29 23:18:45 yazhuk
- * Initial revision
- *
- * ===========================================================================
- */
- #endif // GUI_WIDGETS_GL___RULER__HPP