3 // Copyright (c) 2001-2004 David Ward
5 #ifndef __DasherViewSquare_h__
6 #define __DasherViewSquare_h__
7 #include "DasherView.h"
9 #include "Alphabet/GroupInfo.h"
16 class CDasherViewSquare
;
23 class Dasher::CDasherViewSquare
;
24 class Dasher::CDasherModel
;
25 class Dasher::CDelayedDraw
;
26 class Dasher::CDasherNode
;
31 /// An implementation of the DasherView class
33 /// This class renders Dasher in the vanilla style,
34 /// but with horizontal and vertical mappings
36 /// Horizontal mapping - linear and log
37 /// Vertical mapping - linear with different gradient
38 class Dasher::CDasherViewSquare
:public Dasher::CDasherView
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
);
58 virtual void HandleEvent(Dasher::CEvent
* pEvent
);
61 /// Supply a new screen to draw to
64 void ChangeScreen(CDasherScreen
* NewScreen
);
67 /// @name Coordinate system conversion
68 /// Convert between screen and Dasher coordinates
72 /// Convert a screen co-ordinate to Dasher co-ordinates
74 void Screen2Dasher(screenint iInputX
, screenint iInputY
, myint
& iDasherX
, myint
& iDasherY
,bool b1D
, bool bNonlinearity
);
77 /// Convert Dasher co-ordinates to screen co-ordinates
79 void Dasher2Screen(myint iDasherX
, myint iDasherY
, screenint
& iScreenX
, screenint
& iScreenY
);
82 /// Return true if a node spanning y1 to y2 is entirely enclosed by
83 /// the screen boundary
85 bool IsNodeVisible(myint y1
, myint y2
);
88 /// Get the bounding box of the visible region.
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
);
100 /// @name High level drawing
101 /// Drawing more complex structures, generally implemented by derived class
105 /// Draw the game mode pointer
108 void DrawGameModePointer(myint iPosition
);
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
);
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)
164 inline myint
map(myint y
) const;
165 myint
unmap(myint y
) const;
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
);
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
;
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
210 #include "DasherViewSquare.inl"
212 #endif /* #ifndef __DasherViewSquare_h__ */