diff --git a/Utils/MapEdit/Core.cpp b/Utils/MapEdit/Core.cpp index 76bc55118..09e4379cf 100644 --- a/Utils/MapEdit/Core.cpp +++ b/Utils/MapEdit/Core.cpp @@ -30,7 +30,6 @@ BOOL Test3dFlag=TRUE; /*****************************************************************************/ CCore::CCore() { - MouseMode=MOUSE_MODE_NONE; Layers[LAYER_TYPE_BACK]= new CLayerBack(this); Layers[LAYER_TYPE_MID]= new CLayerMid(this); Layers[LAYER_TYPE_ACTION]= new CLayerAction(this); @@ -51,14 +50,13 @@ int i; void CCore::Init(CMapEditView *Wnd) { ParentWindow=Wnd; - ActiveLayer=0; + ActiveLayer=LAYER_TYPE_ACTION; MapCam=Vec(0,0,0); TileCam=Vec(0,0,0); UpdateView(); - + RenderFlag=TRUE; TileSet.push_back(CTileSet("c:/temp/3/test.gin",this)); - TRACE1("%i\n",TileSet.size()); } /*****************************************************************************/ @@ -68,21 +66,26 @@ void CCore::Render() { Vec &ThisCam=GetCam(); - if (GetTileView()) + if (RenderFlag) { - - } - else - { - for (int i=0;iRender(ThisCam,Test3dFlag); - glDisable(GL_DEPTH_TEST); + } + else + { + for (int i=0;iRender(ThisCam,Test3dFlag); + } + } + Layers[ActiveLayer]->RenderGrid(ThisCam); } +// Calc CursorPos + Layers[ActiveLayer]->FindCursorPos(ThisCam,CurrentMousePos); + } @@ -117,8 +120,7 @@ void CCore::MouseWheel(UINT nFlags, short zDelta, CPoint &pt) void CCore::MouseMove(UINT nFlags, CPoint &point) { Vec Ofs(0,0,0); -//float XOfs=0; -//float YOfs=0; + Vec &ThisCam=GetCam(); // check if active doc if (theApp.GetCurrent()!=ParentWindow->GetDocument()) return; @@ -132,8 +134,8 @@ Vec &ThisCam=GetCam(); RECT ThisRect; ParentWindow->GetWindowRect(&ThisRect); - XS=ThisCam.z*2;//*Layers[ActiveLayer]->GetLayerZPos(); - YS=ThisCam.z*2;//*Layers[ActiveLayer]->GetLayerZPos(); + XS=ThisCam.z*4;//*Layers[ActiveLayer]->GetLayerZPos(); + YS=ThisCam.z*4;//*Layers[ActiveLayer]->GetLayerZPos(); XS/=((ThisRect.right-ThisRect.left)); YS/=((ThisRect.bottom-ThisRect.top)); @@ -144,10 +146,10 @@ Vec &ThisCam=GetCam(); Ofs.x*=XS; Ofs.y*=YS; - TRACE2("Move %i %i \n",point.x,point.y); UpdateView(Ofs); } - +// Mouse has moved, so need to redraw windows, to get CursorPos (And pos render) + ParentWindow->Invalidate(); } @@ -176,7 +178,6 @@ CListBox *Dlg=(CListBox *)LayerBar->GetDlgItem(IDC_LAYERBAR_LIST); ToolBar->GetToolBarCtrl().PressButton(ID_TOOLBAR_LAYERBAR,LayerViewFlag); Frm->ShowControlBar(LayerBar, LayerViewFlag, FALSE); -// UpdateView(); } /*****************************************************************************/ @@ -202,7 +203,6 @@ CToolBar *ToolBar=Frm->GetToolBar(); /*****************************************************************************/ GLint CCore::GetTile(int Bank,int TileNo) { - TRACE1("%i\n",TileSet.size()); return(TileSet[Bank].GetTile(TileNo)); } /*****************************************************************************/ @@ -225,16 +225,21 @@ void CCore::UpdateAll() UpdateTileView(TileViewFlag); } +/*****************************************************************************/ +void CCore::Redraw(BOOL f) +{ + RenderFlag=f; + if (RenderFlag) + ParentWindow->Invalidate(); +} + /*****************************************************************************/ void CCore::UpdateView(Vec Ofs) { Vec &ThisCam=GetCam(); - ThisCam=ThisCam+Ofs; + Ofs.y=-Ofs.y; + ThisCam+=Ofs; if (ThisCam.z>-1) ThisCam.z=-1; - - ParentWindow->Invalidate(); -} - - - + Redraw(); +} diff --git a/Utils/MapEdit/Core.h b/Utils/MapEdit/Core.h index 1aaf6bd20..a615bae7f 100644 --- a/Utils/MapEdit/Core.h +++ b/Utils/MapEdit/Core.h @@ -14,16 +14,6 @@ #include "TileSet.h" -/*****************************************************************************/ -enum MOUSE_MODE -{ - MOUSE_MODE_NONE=0, - MOUSE_MODE_LMB_EDIT, - MOUSE_MODE_MMB_EDIT, - MOUSE_MODE_RMB_EDIT, - -}; - /*****************************************************************************/ class CMapEditView; @@ -67,12 +57,15 @@ public: void UpdateView(Vec Ofs=Vec(0,0,0)); Vec &GetCam(); - + void SetCursorPos(CPoint &Pos) {CursorPos=Pos;} + CPoint &GetCursorPos() {return(CursorPos);} + CMapEditView *GetParentWindow() {return(ParentWindow);} + void Redraw(BOOL f=TRUE); private: CMapEditView *ParentWindow; - MOUSE_MODE MouseMode; CPoint CurrentMousePos,LastMousePos; + CPoint CursorPos,LastCursorPos; Vec MapCam,TileCam; CLayer *Layers[LAYER_TYPE_MAX]; @@ -81,6 +74,7 @@ private: std::vector TileSet; CTexCache TexCache; + BOOL RenderFlag; BOOL TileViewFlag; BOOL LayerViewFlag; diff --git a/Utils/MapEdit/GLEnabledView.cpp b/Utils/MapEdit/GLEnabledView.cpp index 5335cffea..15c7fffdd 100644 --- a/Utils/MapEdit/GLEnabledView.cpp +++ b/Utils/MapEdit/GLEnabledView.cpp @@ -216,7 +216,7 @@ void CGLEnabledView::OnDraw(CDC* pDC) wglMakeCurrent(m_pCDC->GetSafeHdc(), m_hRC); // clear background - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); +// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // call the virtual drawing procedure (to be overridden by user) OnDrawGL(); diff --git a/Utils/MapEdit/Layer.cpp b/Utils/MapEdit/Layer.cpp index 954bd4e3a..3e77ab582 100644 --- a/Utils/MapEdit/Layer.cpp +++ b/Utils/MapEdit/Layer.cpp @@ -8,10 +8,10 @@ #include #include #include -//#include "GLEnabledView.h" +#include "GLEnabledView.h" -//#include "MapEditDoc.h" -//#include "MapEditView.h" +#include "MapEditDoc.h" +#include "MapEditView.h" #include "Core.h" #include "Layer.h" @@ -43,9 +43,6 @@ int Height=Map.GetHeight(); /*****************************************************************************/ void CLayer::Render(Vec &MapPos,BOOL Is3d) { - if (Is3d && CanRender3d()) - Render3d(MapPos); - else Render2d(MapPos); } @@ -62,7 +59,6 @@ int Height=Map.GetHeight(); glTranslatef(MapPos.x/XYDiv,MapPos.y/XYDiv,MapPos.z); glBegin(GL_QUADS); - SetTestColor(); BuildGLQuad(-1,Width+1,-1,0,0); // Bottom BuildGLQuad(-1,Width+1,Height+1,Height,0); // Top BuildGLQuad(-1,0,Height,0,0); // Left @@ -73,37 +69,133 @@ int Height=Map.GetHeight(); } /*****************************************************************************/ -float asd=0; void CLayer::Render3d(Vec &MapPos) { float XYDiv=GetLayerZPosDiv(); -float X,Y; -int XX=0; -int YY=0; +int MapW=Map.GetWidth(); +int MapH=Map.GetHeight(); +float StartX=MapPos.x/XYDiv; +float StartY=MapPos.y/XYDiv; glMatrixMode(GL_MODELVIEW); - Y=MapPos.y; - - for (YY=0; YY<3; YY++) + for (int YLoop=0; YLoopGetTile(0,2)); - glCallList(Core->GetTile(0,XX+(YY*3))); - - X+=1.0f; + sMapElem &ThisTile=Map.GetTile(XLoop,YLoop); + + glLoadIdentity(); // Slow way, but good to go for the mo + glTranslatef(StartX+XLoop,StartY-YLoop,MapPos.z); + glCallList(Core->GetTile(ThisTile.Bank,ThisTile.Tile)); } - Y+=1.0f; } } +/*****************************************************************************/ +void CLayer::RenderGrid(Vec &MapPos) +{ +float XYDiv=GetLayerZPosDiv(); +int MapW=Map.GetWidth(); +int MapH=Map.GetHeight(); +float StartX=MapPos.x/XYDiv; +float StartY=MapPos.y/XYDiv; +float OverVal=0.5; + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(StartX,StartY,MapPos.z); + glDisable(GL_TEXTURE_2D); + + glBegin(GL_LINES); + glNormal3f( 1,1,1); + glColor3ub(255,255,255); + + for (int YLoop=0; YLoopGetCursorPos(); + +float XYDiv=GetLayerZPosDiv(); +int MapW=Map.GetWidth(); +int MapH=Map.GetHeight(); +float StartX=MapPos.x/XYDiv; +float StartY=MapPos.y/XYDiv; + + glGetIntegerv(GL_VIEWPORT, Viewport); + glSelectBuffer (SELECT_BUFFER_SIZE, SelectBuffer ); + glRenderMode (GL_SELECT); + + glInitNames(); + glPushName(-1); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + gluPickMatrix( MousePos.x ,(Viewport[3]-MousePos.y),5.0,5.0,Viewport); + Core->GetParentWindow()->SetupPersMatrix(); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(StartX,StartY,MapPos.z); + + + for (int YLoop=0; YLoop > Map; -// sMapElem *Map; CMap Map; }; diff --git a/Utils/MapEdit/MainFrm.cpp b/Utils/MapEdit/MainFrm.cpp index 1b1d41a02..1ecb2cfa6 100644 --- a/Utils/MapEdit/MainFrm.cpp +++ b/Utils/MapEdit/MainFrm.cpp @@ -14,6 +14,11 @@ static char THIS_FILE[] = __FILE__; ///////////////////////////////////////////////////////////////////////////// // CMainFrame +static UINT indicators[] = +{ + ID_SEPARATOR, // status line indicator + ID_INDICATOR_CURSORXY, +}; IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd) @@ -21,15 +26,9 @@ BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ON_WM_CREATE() //}}AFX_MSG_MAP -END_MESSAGE_MAP() + -static UINT indicators[] = -{ - ID_SEPARATOR, // status line indicator - ID_INDICATOR_CAPS, - ID_INDICATOR_NUM, - ID_INDICATOR_SCRL, -}; +END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMainFrame construction/destruction @@ -125,3 +124,5 @@ void CMainFrame::Dump(CDumpContext& dc) const // CMainFrame message handlers + + diff --git a/Utils/MapEdit/MainFrm.h b/Utils/MapEdit/MainFrm.h index 8b1b8d0a4..6767c16f6 100644 --- a/Utils/MapEdit/MainFrm.h +++ b/Utils/MapEdit/MainFrm.h @@ -21,6 +21,7 @@ public: CToolBar *GetToolBar() {return(&m_wndToolBar);} CDialogBar *GetLayerBar() {return(&m_wndLayerBar);} CDialogBar *GetTileBar() {return(&m_wndTileBar);} + CStatusBar *GetStatusBar() {return(&m_wndStatusBar);} // Operations public: @@ -52,6 +53,13 @@ protected: DECLARE_MESSAGE_MAP() }; +enum STATUS_BAR_ENUM +{ +STATUS_BAR_SEP=0, +STATUS_BAR_XPOS, +STATUS_BAR_YPOS, +}; + ///////////////////////////////////////////////////////////////////////////// //{{AFX_INSERT_LOCATION}} diff --git a/Utils/MapEdit/Map.cpp b/Utils/MapEdit/Map.cpp index 1bcde0af7..aa49b63a5 100644 --- a/Utils/MapEdit/Map.cpp +++ b/Utils/MapEdit/Map.cpp @@ -4,6 +4,11 @@ #include "stdafx.h" +#include "gl3d.h" +#include +#include +#include + #include "Map.h" @@ -31,7 +36,6 @@ void CMap::SetSize(int Width,int Height) for (int Y=0;Y > Map; diff --git a/Utils/MapEdit/MapEdit.clw b/Utils/MapEdit/MapEdit.clw index 6752d0fbe..7e5df1f62 100644 --- a/Utils/MapEdit/MapEdit.clw +++ b/Utils/MapEdit/MapEdit.clw @@ -20,10 +20,10 @@ Class8=CMapEditView ResourceCount=6 Resource1=IDR_MAPEDITYPE (English (U.S.)) -Resource2=IDR_MAINFRAME (English (U.S.)) +Resource2=IDD_LAYERBAR (English (U.S.)) Resource3=IDD_LAYERBAR1 (English (U.S.)) -Resource4=IDD_LAYERBAR (English (U.S.)) -Resource5=IDD_ABOUTBOX (English (U.S.)) +Resource4=IDD_ABOUTBOX (English (U.S.)) +Resource5=IDR_MAINFRAME (English (U.S.)) Class9=CTileWindow Resource6=IDD_TILEBAR (English (U.S.)) diff --git a/Utils/MapEdit/MapEdit.rc b/Utils/MapEdit/MapEdit.rc index 30f37a9dc..4bc980dc4 100644 --- a/Utils/MapEdit/MapEdit.rc +++ b/Utils/MapEdit/MapEdit.rc @@ -319,6 +319,7 @@ BEGIN ID_INDICATOR_SCRL "SCRL" ID_INDICATOR_OVR "OVR" ID_INDICATOR_REC "REC" + ID_INDICATOR_CURSORXY "CursorXY" END STRINGTABLE DISCARDABLE diff --git a/Utils/MapEdit/MapEditView.cpp b/Utils/MapEdit/MapEditView.cpp index 046af76f4..5dcaf19a0 100644 --- a/Utils/MapEdit/MapEditView.cpp +++ b/Utils/MapEdit/MapEditView.cpp @@ -37,6 +37,7 @@ BEGIN_MESSAGE_MAP(CMapEditView, CGLEnabledView) ON_WM_MOUSEMOVE() ON_COMMAND(ID_TOOLBAR_LAYERBAR, OnToolbarLayerbar) ON_COMMAND(ID_TOOLBAR_TILEPALETTE, OnToolbarTilepalette) + ON_UPDATE_COMMAND_UI(ID_INDICATOR_CURSORXY, OnStatusCursorXY) //}}AFX_MSG_MAP END_MESSAGE_MAP() @@ -80,12 +81,35 @@ void CMapEditView::OnCreateGL() } + ///////////////////////////////////////////////////////////////////////////// void CMapEditView::OnDrawGL() { Core.Render(); } +///////////////////////////////////////////////////////////////////////////// +void CMapEditView::OnSizeGL(int cx, int cy) +{ + glViewport(0,0,cx,cy); +// update the camera + glPushMatrix(); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + SetupPersMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + Core.Redraw(); +} + +///////////////////////////////////////////////////////////////////////////// +void CMapEditView::SetupPersMatrix() +{ + gluPerspective(40.0,m_dAspectRatio,0.1f, 100.0f); + glTranslatef(0.0f,0.0f,-4.f); + +} + ///////////////////////////////////////////////////////////////////////////// // CMapEditView diagnostics @@ -126,6 +150,17 @@ void CMapEditView::UpdateAll() Core.UpdateAll(); } +/*********************************************************************************/ +void CMapEditView::OnStatusCursorXY(CCmdUI *pCmdUI) +{ +CPoint &XY=Core.GetCursorPos(); +CString XYStr; + pCmdUI->Enable(); + if (XY.x!=-1 && XY.y!=-1) + XYStr.Format( "%d\t%d", XY.x,XY.y); + pCmdUI->SetText(XYStr); +} + /*********************************************************************************/ /*********************************************************************************/ /*********************************************************************************/ @@ -140,3 +175,5 @@ void CMapEditView::OnMouseMove(UINT nFlags, CPoint point) {Core.MouseMove(nFl void CMapEditView::OnToolbarLayerbar() {Core.ToggleLayerView();} void CMapEditView::OnToolbarTilepalette() {Core.ToggleTileView();} + + diff --git a/Utils/MapEdit/MapEditView.h b/Utils/MapEdit/MapEditView.h index a2eb6ca73..6cc2788b4 100644 --- a/Utils/MapEdit/MapEditView.h +++ b/Utils/MapEdit/MapEditView.h @@ -21,6 +21,8 @@ public: CMapEditDoc* GetDocument(); void OnCreateGL(); void OnDrawGL(); + void OnSizeGL(int cx, int cy); + void SetupPersMatrix(); // Operations public: @@ -57,6 +59,7 @@ protected: afx_msg void OnMouseMove(UINT nFlags, CPoint point); afx_msg void OnToolbarLayerbar(); afx_msg void OnToolbarTilepalette(); + afx_msg void OnStatusCursorXY(CCmdUI *pCmdUI); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; diff --git a/Utils/MapEdit/TileSet.cpp b/Utils/MapEdit/TileSet.cpp index 600d77dae..d9d64ef11 100644 --- a/Utils/MapEdit/TileSet.cpp +++ b/Utils/MapEdit/TileSet.cpp @@ -55,17 +55,8 @@ int ChildCount=ThisNode.GetPruneChildCount(); CTile NewTile; NewTile.Load(Core,this,Scene,ThisNode.PruneChildList[Child]); Tile.push_back(NewTile); -// AddTileToSet(Scene,ThisNode.PruneChildList[Child]); } -/* -std::vector const &Tex=Scene.GetTexNames(); - - for (i=0;i