tagging release
[dasher.git] / Src / DasherCore / DasherViewSquare.h
blob24515e2eb04fb97cccdf1e13904ca8bb9e72ea1a
1 // DasherViewSquare.h
2 //
3 // Copyright (c) 2001-2004 David Ward
5 #ifndef __DasherViewSquare_h__
6 #define __DasherViewSquare_h__
7 #include "DasherView.h"
8 #include <deque>
9 #include "Alphabet/GroupInfo.h"
13 using namespace std;
15 namespace Dasher {
16 class CDasherViewSquare;
17 class CDasherView;
18 class CDasherModel;
19 class CDelayedDraw;
20 class CDasherNode;
23 class Dasher::CDasherViewSquare;
24 class Dasher::CDasherModel;
25 class Dasher::CDelayedDraw;
26 class Dasher::CDasherNode;
28 /// \ingroup View
29 /// @{
31 /// An implementation of the DasherView class
32 ///
33 /// This class renders Dasher in the vanilla style,
34 /// but with horizontal and vertical mappings
35 ///
36 /// Horizontal mapping - linear and log
37 /// Vertical mapping - linear with different gradient
38 class Dasher::CDasherViewSquare:public Dasher::CDasherView
40 public:
42 /// Constructor
43 ///
44 /// \param pEventHandler Event handler.
45 /// \param pSettingsStore Settings store.
46 /// \param DasherScreen Pointer to creen to which the view will render.
47 /// \todo Don't cache screen and model locally - screen can be
48 /// passed as parameter to the drawing functions, and data structure
49 /// can be extracted from the model and passed too.
51 CDasherViewSquare(CEventHandler *pEventHandler, CSettingsStore *pSettingsStore, CDasherScreen *DasherScreen);
52 ~CDasherViewSquare();
54 ///
55 /// Event handler
56 ///
58 virtual void HandleEvent(Dasher::CEvent * pEvent);
60 ///
61 /// Supply a new screen to draw to
62 ///
64 void ChangeScreen(CDasherScreen * NewScreen);
66 ///
67 /// @name Coordinate system conversion
68 /// Convert between screen and Dasher coordinates
69 /// @{
71 ///
72 /// Convert a screen co-ordinate to Dasher co-ordinates
73 ///
74 void Screen2Dasher(screenint iInputX, screenint iInputY, myint & iDasherX, myint & iDasherY,bool b1D, bool bNonlinearity);
76 ///
77 /// Convert Dasher co-ordinates to screen co-ordinates
78 ///
79 void Dasher2Screen(myint iDasherX, myint iDasherY, screenint & iScreenX, screenint & iScreenY);
81 ///
82 /// Return true if a node spanning y1 to y2 is entirely enclosed by
83 /// the screen boundary
84 ///
85 bool IsNodeVisible(myint y1, myint y2);
87 ///
88 /// Get the bounding box of the visible region.
89 ///
90 void VisibleRegion( myint &iDasherMinX, myint &iDasherMinY, myint &iDasherMaxX, myint &iDasherMaxY );
92 double xmap(double x) const;
93 double ymap(double x) const {
94 return m_ymap.map( (myint)x );
97 /// @}
100 /// @name High level drawing
101 /// Drawing more complex structures, generally implemented by derived class
102 /// @{
105 /// Draw the game mode pointer
108 void DrawGameModePointer(myint iPosition);
109 /// @}
112 private:
115 /// Render the current state of the model.
118 virtual void RenderNodes(CDasherNode *pRoot, myint iRootMin, myint iRootMax, std::vector<CDasherNode *> &vNodeList, std::vector<CDasherNode *> &vDeleteList, myint *iGamePointer);
122 /// Recursively render all nodes in a tree. Responsible for all the Render_node calls
125 int RecursiveRender(CDasherNode * Render, myint y1, myint y2, int mostleft, std::vector<CDasherNode *> &vNodeList, std::vector<CDasherNode *> &vDeleteList, myint *iGamePointer, bool bDraw,myint parent_width,int parent_color);
127 /// Render a single node
128 /// \param Color The colour to draw it
129 /// \param y1 Upper extent.
130 /// \param y2 Lower extent
131 /// \param mostleft The left most position in which the text (l->r)
132 /// can be displayed in order to avoid overlap. This is updated by
133 /// the function to allow for the new text
134 /// \param sDisplayText Text to display.
135 /// \param bShove Whether the node shoves
136 /// \todo Character and displaytext are redundant. We shouldn't need
137 /// to know about alphabets here, so only use the latterr
138 int RenderNode(const int Color, myint y1, myint y2, int &mostleft, const std::string &sDisplayText, bool bShove);
140 int RenderNodeOutlineFast(const int Color, myint y1, myint y2, int &mostleft, const std::string &sDisplayText, bool bShove);
141 int RenderNodePartFast(const int Color, myint y1, myint y2, int &mostleft, const std::string &sDisplayText, bool bShove, myint iParentWidth);
142 int RenderNodeFatherFast(const int parent_color, myint y1, myint y2, int &mostleft, const std::string &sDisplayText, bool bShove,myint iParentWidth, bool bVisible);
143 #ifdef _WIN32
145 /// FIXME - couldn't find windows version of round(double) so here's one!
146 /// \param number to be rounded
148 double round(double d)
150 if(d - floor(d) < 0.5)
151 return floor(d);
152 else
153 return ceil(d);
156 #endif
158 // Class definitions
160 class Cymap {
161 public:
162 Cymap(myint iScale);
163 Cymap() {}
164 inline myint map(myint y) const;
165 myint unmap(myint y) const;
166 private:
167 myint m_Y1, m_Y2, m_Y3;
170 double xmax(double x, double y) const;
171 double ixmap(double x) const;
172 inline void Crosshair(myint sx);
174 // Called on screen size changes
175 void SetScaleFactor();
178 /// Get the scale factor for conversion between Dasher co-ordinates
179 /// and screen co-ordinates
181 void GetScaleFactor( int eOrientation, myint *iScaleFactorX, myint *iScaleFactorY );
184 // Data
186 bool bInBox; // Whether we're in the mouseposstart box
187 int iBoxStart; // Time that the current box was drawn
188 int iBoxEntered; // Time when the user enttered the current box
190 double m_dXmpa, m_dXmpb, m_dXmpc, m_dXmpd;
191 screenint CanvasX, CanvasY, CanvasBorder;
192 Cymap m_ymap;
194 // Cached values for scaling
195 myint iLRScaleFactorX;
196 myint iLRScaleFactorY;
197 myint iTBScaleFactorX;
198 myint iTBScaleFactorY;
200 // The factor that scale factors are multipled by
201 myint m_iScalingFactor;
203 // Cached extents of visible region
204 myint m_iDasherMinX;
205 myint m_iDasherMaxX;
206 myint m_iDasherMinY;
207 myint m_iDasherMaxY;
209 /// @}
210 #include "DasherViewSquare.inl"
212 #endif /* #ifndef __DasherViewSquare_h__ */