SBSPSS/Utils/MapEdit/MapEditView.cpp

183 lines
5.9 KiB
C++
Raw Normal View History

2000-09-22 17:11:29 +02:00
// MapEditView.cpp : implementation of the CMapEditView class
//
2000-09-22 18:56:20 +02:00
#include "stdafx.h"
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glut.h>
#include "GLEnabledView.h"
#include "MapEdit.h"
#include "MapEditDoc.h"
#include "MapEditView.h"
2000-09-25 17:43:52 +02:00
#include "MainFrm.h"
2000-09-22 17:11:29 +02:00
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMapEditView
2000-09-22 18:56:20 +02:00
IMPLEMENT_DYNCREATE(CMapEditView, CGLEnabledView)
2000-09-22 17:11:29 +02:00
2000-09-22 18:56:20 +02:00
BEGIN_MESSAGE_MAP(CMapEditView, CGLEnabledView)
2000-09-22 17:11:29 +02:00
//{{AFX_MSG_MAP(CMapEditView)
ON_WM_SETFOCUS()
2000-09-22 23:19:46 +02:00
ON_WM_LBUTTONUP()
ON_WM_LBUTTONDOWN()
ON_WM_MBUTTONDOWN()
ON_WM_MBUTTONUP()
ON_WM_MOUSEWHEEL()
ON_WM_RBUTTONDOWN()
ON_WM_RBUTTONUP()
2000-09-25 17:43:52 +02:00
ON_WM_MOUSEMOVE()
2000-11-17 00:08:54 +01:00
ON_COMMAND(ID_TOGGLE_TILEVIEW, OnToggleTileview)
ON_COMMAND(ID_TOOLBAR_GRID, OnToggleGrid)
ON_COMMAND(ID_MIRRORX, OnMirrorx)
ON_COMMAND(ID_MIRRORY, OnMirrory)
2000-11-17 22:36:13 +01:00
ON_COMMAND(ID_ACTIVEBRUSH_LEFT, OnActivebrushLeft)
ON_COMMAND(ID_ACTIVEBRUSH_RIGHT, OnActivebrushRight)
2000-11-22 23:08:47 +01:00
ON_COMMAND(ID_MAP_SETSIZE, OnMapSetSize)
2000-12-11 22:52:32 +01:00
ON_COMMAND(ID_2D_3D_TOGGLE, On2d3dToggle)
2000-11-20 17:21:43 +01:00
ON_COMMAND(ID_TOOLBAR_TILEPALETTE, OnToggleTileview)
ON_COMMAND(ID_TOGGLE_GRID, OnToggleGrid)
2000-09-22 17:11:29 +02:00
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMapEditView construction/destruction
CMapEditView::CMapEditView()
{
}
CMapEditView::~CMapEditView()
{
}
/////////////////////////////////////////////////////////////////////////////
2000-09-22 23:19:46 +02:00
void CMapEditView::VideoMode(ColorsNumber & c, ZAccuracy & z, BOOL & dbuf)
2000-09-22 17:11:29 +02:00
{
2000-11-21 22:27:55 +01:00
c=MILLIONS; // ask for 65355 colors...
2000-09-22 23:19:46 +02:00
z=NORMAL; // ...16 bit Z-buffer...
dbuf=TRUE; // ...double-buffering
2000-09-22 17:11:29 +02:00
}
2000-09-22 23:19:46 +02:00
/////////////////////////////////////////////////////////////////////////////
void CMapEditView::OnCreateGL()
2000-09-22 17:11:29 +02:00
{
2000-11-17 22:36:13 +01:00
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Background Color
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
2000-11-28 00:07:07 +01:00
glEnable(GL_BLEND); // Enable Alpha Channel
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Alpha Blend Style
2000-09-22 17:11:29 +02:00
}
2000-11-03 23:40:41 +01:00
2000-10-30 22:16:48 +01:00
/////////////////////////////////////////////////////////////////////////////
2000-11-06 21:24:11 +01:00
2000-09-22 23:19:46 +02:00
void CMapEditView::OnDrawGL()
2000-09-22 17:11:29 +02:00
{
2000-11-06 21:24:11 +01:00
GetDocument()->Render(this);
2000-09-22 17:11:29 +02:00
}
2000-11-03 23:40:41 +01:00
/////////////////////////////////////////////////////////////////////////////
void CMapEditView::OnSizeGL(int cx, int cy)
{
glViewport(0,0,cx,cy);
2000-11-28 00:07:07 +01:00
2000-11-03 23:40:41 +01:00
// update the camera
glPushMatrix();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
SetupPersMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
2000-11-06 21:24:11 +01:00
GetDocument()->UpdateView(this);
2000-11-03 23:40:41 +01:00
}
/////////////////////////////////////////////////////////////////////////////
2000-11-06 21:24:11 +01:00
void CMapEditView::SetupPersMatrix()
2000-11-03 23:40:41 +01:00
{
2000-11-28 00:07:07 +01:00
gluPerspective(40.0,m_dAspectRatio,0.1f, 100.0f);
glTranslatef(0.0f,0.0f,-4.f);
// GLint viewport[4];
// glGetIntegerv( GL_VIEWPORT, viewport );
// glMatrixMode( GL_PROJECTION );
// glLoadIdentity();
// glOrtho( 0.0f, viewport[2]-viewport[0],viewport[3]-viewport[1], 0.0f, 0.1f, 100.0f);
// glOrtho( 0.0f, +30,+20, 0, 0.1f, 100.0f);
// glTranslatef(0.0f,0.0f,-0.f);
// glMatrixMode( GL_MODELVIEW );
// glLoadIdentity();
// glTranslatef( 0.375, 0.375, 0.0 );
2000-11-03 23:40:41 +01:00
}
2000-11-06 21:24:11 +01:00
2000-09-22 17:11:29 +02:00
/////////////////////////////////////////////////////////////////////////////
// CMapEditView diagnostics
#ifdef _DEBUG
void CMapEditView::AssertValid() const
{
2000-09-22 18:56:20 +02:00
CGLEnabledView::AssertValid();
2000-09-22 17:11:29 +02:00
}
void CMapEditView::Dump(CDumpContext& dc) const
{
2000-09-22 18:56:20 +02:00
CGLEnabledView::Dump(dc);
2000-09-22 17:11:29 +02:00
}
CMapEditDoc* CMapEditView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMapEditDoc)));
return (CMapEditDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMapEditView message handlers
void CMapEditView::OnSetFocus(CWnd* pOldWnd)
{
CMapEditDoc *CurDoc=GetDocument();
2000-09-22 18:56:20 +02:00
CGLEnabledView::OnSetFocus(pOldWnd);
2000-09-22 17:11:29 +02:00
theApp.SetCurrent(CurDoc);
2000-11-20 21:33:42 +01:00
CurDoc->UpdateAll(this);
// CurDoc->UpdateAllViews(this);
2000-09-25 17:43:52 +02:00
}
/*********************************************************************************/
/*********************************************************************************/
/*********************************************************************************/
2000-11-06 21:24:11 +01:00
void CMapEditView::OnLButtonDown(UINT nFlags, CPoint point) {GetDocument()->LButtonControl(this,nFlags,point,TRUE);}
void CMapEditView::OnLButtonUp(UINT nFlags, CPoint point) {GetDocument()->LButtonControl(this,nFlags,point,FALSE);}
void CMapEditView::OnMButtonDown(UINT nFlags, CPoint point) {GetDocument()->MButtonControl(this,nFlags,point,TRUE);}
void CMapEditView::OnMButtonUp(UINT nFlags, CPoint point) {GetDocument()->MButtonControl(this,nFlags,point,FALSE);}
BOOL CMapEditView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt) {GetDocument()->MouseWheel(this,nFlags,zDelta,pt) ;return(0);}
void CMapEditView::OnRButtonDown(UINT nFlags, CPoint point) {GetDocument()->RButtonControl(this,nFlags,point,TRUE);}
void CMapEditView::OnRButtonUp(UINT nFlags, CPoint point) {GetDocument()->RButtonControl(this,nFlags,point,FALSE);}
void CMapEditView::OnMouseMove(UINT nFlags, CPoint point) {GetDocument()->MouseMove(this,nFlags, point);}
2000-11-17 00:08:54 +01:00
void CMapEditView::OnToggleTileview() {GetDocument()->ToggleTileView(this);}
void CMapEditView::OnToggleGrid() {GetDocument()->ToggleGrid(this);}
2000-11-20 17:21:43 +01:00
void CMapEditView::OnMirrorx() {GetDocument()->MirrorX(this);}
void CMapEditView::OnMirrory() {GetDocument()->MirrorY(this);}
void CMapEditView::OnActivebrushLeft() {GetDocument()->ActiveBrushLeft(this);}
void CMapEditView::OnActivebrushRight() {GetDocument()->ActiveBrushRight(this);}
2000-11-17 22:36:13 +01:00
2000-11-20 17:21:43 +01:00
void CMapEditView::OnMapSetSize() {GetDocument()->MapSetSize(this);}
2000-11-22 23:08:47 +01:00
void CMapEditView::On2d3dToggle() {GetDocument()->Toggle2d3d(this);}