NCBI C++ ToolKit
ruler.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef GUI_WIDGETS_GL___RULER__HPP
2 #define GUI_WIDGETS_GL___RULER__HPP
3 
4 /* $Id: ruler.hpp 35505 2016-05-16 15:18:00Z shkeda $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Andrey Yazhuk
30  *
31  * File Description:
32  *
33  */
34 
36 #include <gui/opengl/glpane.hpp>
38 
39 #include <util/align_range.hpp>
41 
42 
44 
45 ////////////////////////////////////////////////////////////////////////////////
46 /// CRuler is a renderable object drawing a scale with position labels.
47 
49 {
50 public:
51  enum EColorType {
55  };
56 
57  /// Ticks and labels placement.
58  /// The geometry names and their relative positions are:
59  ///
60  /// Label(top)
61  /// | <-- opposite label ticks
62  /// | | <-- opposite major ticks
63  /// | | | | | | | | | | | | | | <-- oppsite minor ticks
64  ///------------------------------------------------------------------
65  /// | | | | | | | | | | | | | | <-- minor ticks
66  /// | | <-- major ticks
67  /// | <-- label ticks
68  ///
69  /// Here are the rules:
70  /// 1. Major/minor ticks are are always on the opposite side of labels,
71  /// so the Opposite Major/Minor ticks will be on the same side
72  /// with labels.
73  /// 2. Label position is configurable. If label placement is top,
74  /// then the major/minor ticks will face down, and the opposite
75  /// major/minor ticks will face up.
76  /// 3. The tick sizes can also be modified to create different tick
77  /// orientations. E.g. setting major/minor ticks to zero will
78  /// create a ruler with tick facing label side always.
79  /// 4. Major/Opp tick sizes >= Minor/Opp tick sizes
80  /// 5. Label/Opp tick sizes >= Major/Opp tick sizes
81 
85  eLabelTickHeight, ///< tick size at label position
86  eOppMinorTickHeight, ///< minor tick on the opposite side
87  eOppMajorTickHeight, ///< major tick on the opposite side
88  eOppLabelTickHeight ///< tick size at label position (opposite)
89  };
90 
96  eDefault
97  };
98 
99  /// How labels align around ticks.
100  enum ELabelAlign {
102  eAln_Left, ///< valid for horizontal mode only (mapped to eAln_Bottom for vertical mode)
103  eAln_Right, ///< valid for horizontal mode only (mapped to eAln_Top for vertical mode)
104  eAln_Top, ///< valid for vertical mode only (mapped to eAln_Right for horizontal mode)
105  eAln_Bottom ///< valid for vertical mode only (mapped to eAln_Left for horizontal mode)
106  };
107 
109  fHideLabels = 0x01, // do not render labels along the scale
110  fShowOrigin = 0x02, // draw "Origin" label
111  fShowMetric = 0x04, // draw "Metric"
112  fShowTextLabel = 0x08, // draw text label
113  fFillBackground = 0x10, //
114  fHideNegative = 0x20, // hide negative coordinate
115  fHideFirstLabel = 0x40, // hide the first scale label
116  fHideLastLabel = 0x80, // hide the last scale label
117  fFirstLabelHasText = 0x100, // draw text label next to fisrt label
118  fDefaultDisplayOptions = fFillBackground
119  };
120 
125 
126  /// Origin specifies the position in the model space that is represented as "1"
127  /// in the Ruler's display space. It can be thought of as the offset of the
128  /// local coordinate system associated with Ruler relative to the global coordinate system.
129 
130  CRuler(bool horz = true);
131  virtual ~CRuler();
132 
133  void SetHorizontal(bool b_horz, ELabelPlacement place = eDefault,
134  ELabelAlign aln = eAln_Center);
135  void SetColor(EColorType type, const CRgbaColor& color);
136  void SetFont(CGlTextureFont::EFontFace font_type,
137  unsigned int font_size=12);
138  void SetLabelOrientation(CGlTextureFont::EFontRotateFlags rotate,
139  int rotate_degrees);
140  void SetGeometryParam(EGeometryParam geom, int value);
141 
142  // takes a combination of EDisplayOptions flags
143  void SetDisplayOptions(int options);
144 
145  /// SetAutoRange() activates automatic mode; in this mode ruler's range is equal to
146  /// the provided model limits range (obtained via CGlPane::GetModelLimitsRect()).
147  void SetAutoRange();
148 
149  /// SetRange() activates "manual" mode; in this mode ruler's range in
150  /// model space is explicitly limited to [Start, End], SeqStart specifies the
151  /// number corresponding to the first position in the range;
152  /// if b_reverse == "true" then SeqStart will correspond to End and
153  /// displayed numbers will increase from the right to the left.
154  void SetRange(int start, int end, int seq_start, bool reverse);
155 
156  void SetMapping(const TAlignColl& coll);
157  void SetBaseWidth(int value);
158 
159  void SetTextLabel(const string& label);
160 
161  TVPPoint GetPreferredSize(int max_num = 0) const;
162 
163  /// Get the distance between two tick labels.
164  int GetLabelStep() const;
165 
166  void Update(CGlPane& pane);
167 
168  /// @name IRenderable implementation
169  /// @{
170  virtual void Render(CGlPane& pane);
171 
172  virtual TVPRect GetVPRect() const;
173  virtual void SetVPRect(const TVPRect& rect);
174 
175  virtual TModelRect GetModelRect() const;
176  virtual void SetModelRect(const TModelRect& rc);
177 
178  virtual TVPPoint PreferredSize();
179 
180  virtual bool IsVisible();
181  virtual void SetVisible(bool set);
182 
183  virtual bool NeedTooltip(CGlPane& pane, int vp_x, int vp_y);
184  virtual string GetTooltip();
185  virtual void SetOrder(int order);
186  virtual int GetOrder() const;
187 
188  /// @}
189 
190 protected:
191  bool x_TextAlongAxis() const;
192 
193  int x_ToDisplay(const TAlignRange& range, int model) const;
194  TModelUnit x_ToModel(const TAlignRange& range, int display) const;
195  void x_CalcStartStopOffsets(const TAlignRange& range, TModelUnit& from_offset, TModelUnit& to_offset);
196 
197  void x_CalculatePosLabelsStep(CGlPane& Pane);
198  void x_ChooseTickSpace(double scale);
199 
200  void x_UpdateMappingByPane(CGlPane& pane);
201  void x_UpdatePosLabelsStep(CGlPane& pane);
202 
203  void x_RenderRange(CGlPane& pane, const TAlignRange& range, const TRange& clip_r);
204  void x_RenderBackground(CGlPane& pane, const TModelRect& rc, const TRange& clip_r);
205  void x_RenderScale(CGlPane& pane, const TAlignRange& range, const TRange& clip_r);
206  void x_RenderAllPosLabels(CGlPane& pane, const TAlignRange& range, const TRange& clip_r);
207  void x_RenderOriginAndMetric(CGlPane& pane, const TRange& clip_r);
208 
209  string x_GetPositionLabel(const TAlignRange& range, int iElem);
210  void x_GenerateLabelPositions(const TAlignRange& range,
211  int first_elem, int last_elem, vector<TModelUnit>& vElemPos);
212 
213  void x_RenderPosLabel(CGlPane& pane, double pos_u,
214  double label_offset_u, const string& text,
215  bool draw_tick = true);
216  void x_RenderHorzPosLabel(CGlPane& pane, double pos_u,
217  double label_offset_u, const string& text,
218  bool draw_tick = true);
219  void x_RenderVertPosLabel(CGlPane& pane, double pos_u,
220  double label_offset_u, const string& text,
221  bool draw_tick = true);
222 
223  int x_GetMaxNum();
224 
225  int x_GetTicksLabelsSizeV(int max_num) const;
226  int x_GetOriginMetricSizeV() const;
227 
228  TModelPoint x_GetLabelSize(CGlPane& pane, const string& label);
229  TModelPoint x_GetLabelSizeUnscaled(CGlPane& pane, const string& label);
230 
231 
232 protected:
233  bool m_Visible;
234  bool m_Horz;
237 
238  /// Font rotation flags (rotate around base or cap)
240  /// Use degrees as int for safe comparison to 0, 90, 180 etc.
242 
243 
245 
247  //int m_Start, m_End; /// range in model space represented by the ruler
248  //int m_Offset; /// added to m_Start to produce displayed numbers, so that
249  /// range displayed is [m_Start + m_Offset, m_End + m_Offset]
250 
251  // this is a collection that defines mapping from the Ruler's model space
252  // (as defined by a given CGlPane) to the "display" space
253  // labels and ticks will be rendered only for intervals existing in the
254  // collection.
256 
259 
260  string m_TextLabel;
261 
262  //bool m_ReverseDisplay;
263 
265 
267 
271 
272  /// @name tick sizes
273  /// @{
280  /// @}
281 
282  bool m_Dirty; /// "true" if parameters affecting layout have been changed
283 
285  double m_ScaleX, m_ScaleY;
286 
287  double m_MaxLabelW;
288  double m_MaxLabelH;
289 
290  int m_BaseStep; // has form 10^X, m_PosLabelsStep = K * m_BaseStep;
291  int m_PosLabelsStep; // distance between two labels (in model coords)
292  int m_TickSpace; // distance beween two minor ticks (in model coords)
293 };
294 
295 
296 ////////////////////////////////////////////////////////////////////////////////
297 /// CRuler inline methods
298 inline
300 { return m_PosLabelsStep; }
301 
302 inline
304 { x_UpdatePosLabelsStep(pane); }
305 
306 
307 inline
309 {
310  _ASSERT(value > 0);
311  m_BaseWidth = value > 0 ? value : 1;
313 
314 }
315 inline
316 void CRuler::SetOrder(int order)
317 {
318 }
319 inline
320 int CRuler::GetOrder() const
321 {
322  return 0;
323 }
324 
326 
327 #endif // GUI_WIDGETS_GL___RULER__HPP
CAlignRange Represents an element of pairwise alignment of two sequences.
Definition: align_range.hpp:63
class CGlPane
Definition: glpane.hpp:62
class CRgbaColor provides a simple abstraction for managing colors.
Definition: rgba_color.hpp:58
CRuler is a renderable object drawing a scale with position labels.
Definition: ruler.hpp:49
CAlignRange< TPos > TAlignRange
Definition: ruler.hpp:122
float m_BaseOffset
Definition: ruler.hpp:258
ELabelAlign m_LabelAln
Definition: ruler.hpp:236
int GetLabelStep() const
Get the distance between two tick labels.
Definition: ruler.hpp:299
CGlTextureFont m_Font
Definition: ruler.hpp:266
EDisplayOptions
Definition: ruler.hpp:108
string m_TextLabel
Definition: ruler.hpp:260
EColorType
Definition: ruler.hpp:51
@ eRuler
Definition: ruler.hpp:52
@ eText
Definition: ruler.hpp:53
CRgbaColor m_TextColor
Definition: ruler.hpp:268
TSignedSeqPos TPos
Definition: ruler.hpp:121
TModelRect m_rcLimits
"true" if parameters affecting layout have been changed
Definition: ruler.hpp:284
double m_MaxLabelW
Definition: ruler.hpp:287
int m_BaseStep
Definition: ruler.hpp:290
bool m_Dirty
Definition: ruler.hpp:282
int m_DisplayOptions
Definition: ruler.hpp:264
CGlTextureFont::EFontRotateFlags m_FontRotate
Font rotation flags (rotate around base or cap)
Definition: ruler.hpp:239
virtual void SetOrder(int order)
Definition: ruler.hpp:316
CAlignRangeCollection< TAlignRange > TAlignColl
Definition: ruler.hpp:124
CRgbaColor m_BackColor
Definition: ruler.hpp:270
double m_ScaleY
Definition: ruler.hpp:285
int m_FontRotateDegrees
Use degrees as int for safe comparison to 0, 90, 180 etc.
Definition: ruler.hpp:241
void SetBaseWidth(int value)
Definition: ruler.hpp:308
ELabelPlacement
Definition: ruler.hpp:91
@ eBottom
Definition: ruler.hpp:92
@ eTop
Definition: ruler.hpp:93
@ eLeft
Definition: ruler.hpp:94
@ eRight
Definition: ruler.hpp:95
CRgbaColor m_RulerColor
Definition: ruler.hpp:269
CRange< TPos > TRange
Definition: ruler.hpp:123
int m_BaseWidth
Definition: ruler.hpp:257
int m_MinorTickSize
Definition: ruler.hpp:275
EGeometryParam
Ticks and labels placement.
Definition: ruler.hpp:82
@ eOppMajorTickHeight
major tick on the opposite side
Definition: ruler.hpp:87
@ eMajorTickHeight
Definition: ruler.hpp:84
@ eMinorTickHeight
Definition: ruler.hpp:83
@ eOppMinorTickHeight
minor tick on the opposite side
Definition: ruler.hpp:86
@ eLabelTickHeight
tick size at label position
Definition: ruler.hpp:85
int m_PosLabelsStep
Definition: ruler.hpp:291
bool m_Visible
Definition: ruler.hpp:233
int m_OppMinorTickSize
Definition: ruler.hpp:278
virtual int GetOrder() const
Definition: ruler.hpp:320
int m_MajorTickSize
Definition: ruler.hpp:274
ELabelPlacement m_LabelPlace
Definition: ruler.hpp:235
int m_LabelTickSize
Definition: ruler.hpp:276
void x_UpdatePosLabelsStep(CGlPane &pane)
Definition: ruler.cpp:547
TVPRect m_rcBounds
Definition: ruler.hpp:244
ELabelAlign
How labels align around ticks.
Definition: ruler.hpp:100
@ eAln_Top
valid for vertical mode only (mapped to eAln_Right for horizontal mode)
Definition: ruler.hpp:104
@ eAln_Right
valid for horizontal mode only (mapped to eAln_Top for vertical mode)
Definition: ruler.hpp:103
@ eAln_Left
valid for horizontal mode only (mapped to eAln_Bottom for vertical mode)
Definition: ruler.hpp:102
@ eAln_Center
Definition: ruler.hpp:101
int m_TickSpace
Definition: ruler.hpp:292
bool m_Horz
Definition: ruler.hpp:234
int m_OppLabelTickSize
Definition: ruler.hpp:279
void Update(CGlPane &pane)
Definition: ruler.hpp:303
double m_MaxLabelH
Definition: ruler.hpp:288
bool m_AutoRange
Definition: ruler.hpp:246
int m_OppMajorTickSize
Definition: ruler.hpp:277
TAlignColl m_Mapping
range displayed is [m_Start + m_Offset, m_End + m_Offset]
Definition: ruler.hpp:255
IRenderable class IRenderable defines an abstract interface required for rendering graphical panels i...
Definition: irenderable.hpp:50
virtual void SetModelRect(const TModelRect &rc)=0
virtual int GetOrder() const =0
virtual void SetVisible(bool set)=0
virtual void SetOrder(int order)=0
virtual void SetVPRect(const TVPRect &rc)=0
virtual bool NeedTooltip(CGlPane &pane, TVPUnit vp_x, TVPUnit vp_y)=0
virtual void Render(CGlPane &pane)=0
virtual TModelRect GetModelRect() const =0
virtual TVPPoint PreferredSize()=0
virtual bool IsVisible()=0
virtual TVPRect GetVPRect() const =0
virtual string GetTooltip()=0
Definition: set.hpp:45
int TSignedSeqPos
Type for signed sequence position.
Definition: ncbimisc.hpp:887
GLdouble TModelUnit
Definition: gltypes.hpp:48
EFontRotateFlags
Font rotate options.
EFontFace
Set of pre-defined fonts for which we know we have valid font files.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_GUIWIDGETS_GL_EXPORT
Definition: gui_export.h:529
static const char label[]
n background color
@ eBackground
Definition: map_control.hpp:49
static void text(MDB_val *v)
Definition: mdb_dump.c:62
range(_Ty, _Ty) -> range< _Ty >
constexpr auto rotate(list< Ts... >) -> decltype((list<>{}+...+rotate_item< Ts >{}))
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
Definition: type.c:6
#define _ASSERT
Modified on Wed May 22 11:30:28 2024 by modify_doxy.py rev. 669887