summaryrefslogtreecommitdiff
path: root/hammer/mapview2dbase.h
blob: 8ae645ac089488851e0cab1248050358216a3d91 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//===========================================================================//

#ifndef MAPVIEW2DBASE_H
#define MAPVIEW2DBASE_H
#ifdef _WIN32
#pragma once
#endif


#include "Axes2.h"
#include "MapView.h"
#include "MapClass.h"		// For CMapObjectList
#include "utlvector.h"
#include "VGuiWnd.h"
#include "color.h"

class CTitleWnd;
class CMapDoc;
class Tool3D;

class CMapView2DBase : public CView, public CMapView, public Axes2, public CVGuiWnd
{
// Operations
public:
	LRESULT WindowProc( UINT message, WPARAM wParam, LPARAM lParam );

	void SetViewOrigin( float flHorz, float flVert, bool bRelative = false );
			
	void SetZoom(float flNewZoom);
	float GetZoom( void );

	void CenterView(Vector *pt3 = NULL);
	void UpdateClientView();
	void ToolScrollToPoint(const Vector2D &ptClient);
	void UpdateStatusBar();
	int  ObjectsAt( const Vector2D &vPoint, HitInfo_t *pObjects, int nMaxObjects, unsigned int nFlags = 0 );
	int  ObjectsAt( CMapWorld *pWorld, const Vector2D &vPoint, HitInfo_t *pObjects, int nMaxObjects, unsigned int nFlags = 0 );
	void GetCenterPoint(Vector& pt);
	void OnContextMenu(UINT nFlags, const Vector2D &vPoint);
	
	void EnsureVisible(Vector &vecPos, float flMargin);
	void UpdateTitleWindowPos();
	
	virtual void Render() {}

	void ZoomIn(BOOL bAllViews = FALSE);
	void ZoomOut(BOOL bAllViews = FALSE);

	//
	// Coordinate transformation functions.
	//
	void ProcessInput() {}
	void RenderView();
	void ActivateView(bool bActivate);
	void UpdateView(int nFlags);
	CView *GetViewWnd() { return (CView*)this; }
	CMapDoc *GetMapDoc() { return (CMapDoc*)m_pDocument; }

	void WorldToClient(Vector2D &vecClient, const Vector &vecWorld);
	void ClientToWorld(Vector &vecWorld, const Vector2D &ptClient);
	void BuildRay( const Vector2D &ptClient, Vector& vStart, Vector& vEnd );
	void GetBestTransformPlane( Vector &horzAxis, Vector &vertAxis, Vector &thirdAxis);
			
	const Vector &GetViewAxis();
	bool IsInClientView( const Vector &vecMin, const Vector &vecMax );
	bool IsInClientView( const Vector2D &vecMin, const Vector2D &vecMax );

	bool CheckDistance(const Vector2D &vecCheck, const Vector2D &vecRef, int nDist);
	bool IsBoxFullyVisible(const Vector &vecMins, const Vector &vecMaxs);
	bool CanBoxFitInView(const Vector &minsWorld, const Vector &maxsWorld);
	bool PointInClientRect( const Vector2D &point );
	bool HitTest( const Vector2D &vPoint, const Vector& mins, const Vector& maxs );
	
// Implementation
protected:
	CMapView2DBase();           // protected constructor used by dynamic creation
	virtual ~CMapView2DBase();
	DECLARE_DYNCREATE(CMapView2DBase)

	// Derived classes must implement these
	virtual bool IsLogical() { return false; }
	virtual void OnRenderListDirty() {}

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CMapView2DBase)
	protected:
	virtual void OnInitialUpdate();     // first time after construct
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
	virtual BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint point);
	virtual void OnDraw(CDC *) {};
	//}}AFX_VIRTUAL

#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

	void DrawGridLogical( CRender2D *pRender );
	void DrawGrid( CRender2D *pRender, int xAxis, int yAxis, float depth, bool bNoSmallGrid = false );
	CRender2D *GetRender();
	CTitleWnd *GetTitleWnd();
	bool HasTitleWnd() const;

	// Create a title window.
	void CreateTitleWindow(void);

protected:
	// timer IDs:
	enum 
	{ 
		TIMER_SCROLLVIEW = 1, 
	};

	void DrawPointFile( CRender2D *pRender );
	bool HighlightGridLine( CRender2D *pRender, int nGridLine );

	POINT m_ptLDownClient;		// client pos at which lbutton was pressed, for dragging the view

	// TODO zoom  & forward are all camera properties, remove here

	CRender2D *m_pRender;		// Performs the 3D rendering in our window.

	float	m_flMinZoom;		// Minimum legal zoom factor (should be sufficient to display entire map in the view)

	// these vars are used often, so keep values. they just mirror Camera values
	Vector  m_vViewOrigin;
	float	m_fZoom;			// zoom factor (* map units)
	float	m_fClientWidthHalf;	
	float	m_fClientHeightHalf;
	Vector  m_vViewAxis;		// view axis, normal

	Vector	m_ViewMin;			// client view in world coordinates, same as 3D view frustum
	Vector	m_ViewMax;

	int		m_ClientWidth;
	int		m_ClientHeight;
	
	int		m_xScroll, m_yScroll;	// amount to scroll on timer
	
	bool	m_bToolShown;			// is tool currently visible?
	CTitleWnd *m_pwndTitle;			// title window

	Color	m_clrGrid;				// standard grid color
	Color	m_clrGrid1024;			// 1024 unit line color
	Color	m_clrGridCustom;		// custom unit color
	Color	m_clrGridDot;			// grid dot color
	Color	m_clrAxis;				// grid axis color 

	//
	// Color scheme functions.
	//
	void AdjustColorIntensity(Color &color, int nIntensity);
	void SetColorMode(bool bBlackOnWhite);

	
	// mouse drag (space + leftbutton):
	bool	m_bMouseDrag;	// status indicator

	// Generated message map functions
	//{{AFX_MSG(CMapView2DBase)
	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnEditProperties();
	afx_msg void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnUpdateEditFunction(CCmdUI *pCmdUI);
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()
};


//-----------------------------------------------------------------------------
// Inline methods
//-----------------------------------------------------------------------------
inline bool CMapView2DBase::PointInClientRect( const Vector2D &point )
{
	return ( point.x >= 0 && point.y >= 0 && point.x < m_ClientWidth && point.y < m_ClientHeight );
}

inline float CMapView2DBase::GetZoom() 
{ 
	return m_fZoom; 
}

inline CRender2D *CMapView2DBase::GetRender()
{
	return m_pRender;
}

inline CTitleWnd* CMapView2DBase::GetTitleWnd()
{
	return m_pwndTitle;
}

inline bool CMapView2DBase::HasTitleWnd() const
{
	return m_pwndTitle != NULL;
}


#endif // MAPVIEW2DBASE_H