2001-02-09 22:17:01 +01:00
|
|
|
/*******************/
|
|
|
|
/*** Layer Shade ***/
|
|
|
|
/*******************/
|
|
|
|
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include <Vector3.h>
|
|
|
|
#include <gl\gl.h>
|
|
|
|
#include <gl\glu.h>
|
|
|
|
#include "GLEnabledView.h"
|
|
|
|
|
|
|
|
#include "MapEdit.h"
|
|
|
|
#include "MapEditDoc.h"
|
|
|
|
#include "MapEditView.h"
|
|
|
|
#include "MainFrm.h"
|
|
|
|
|
|
|
|
#include "Core.h"
|
|
|
|
#include "Layer.h"
|
|
|
|
#include "LayerShade.h"
|
|
|
|
#include "Utils.h"
|
|
|
|
#include "Select.h"
|
|
|
|
#include "Export.h"
|
|
|
|
#include "LayerShadeGUI.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
// New Layer
|
|
|
|
CLayerShade::CLayerShade(int _SubType,int _Width,int _Height)
|
|
|
|
{
|
|
|
|
SubType=_SubType;
|
|
|
|
|
|
|
|
SetDefaultParams();
|
|
|
|
|
|
|
|
Width=TileLayerMinWidth+(_Width-TileLayerMinWidth)/ScaleFactor;
|
|
|
|
Height=TileLayerMinHeight+(_Height-TileLayerMinHeight)/ScaleFactor;
|
|
|
|
|
2001-02-20 16:57:03 +01:00
|
|
|
RGB[0].rgbRed=255; RGB[0].rgbGreen=255; RGB[0].rgbBlue=255;
|
|
|
|
RGB[1].rgbRed=255; RGB[1].rgbGreen=0; RGB[1].rgbBlue=0;
|
|
|
|
RGB[2].rgbRed=0; RGB[2].rgbGreen=255; RGB[2].rgbBlue=0;
|
|
|
|
RGB[3].rgbRed=0; RGB[3].rgbGreen=0; RGB[3].rgbBlue=255;
|
|
|
|
Count=2;
|
2001-02-09 22:17:01 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
// Load Layer
|
|
|
|
CLayerShade::CLayerShade(CFile *File,int Version)
|
|
|
|
{
|
|
|
|
Load(File,Version);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
CLayerShade::~CLayerShade()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CLayerShade::Load(CFile *File,int Version)
|
|
|
|
{
|
|
|
|
File->Read(&Render3dFlag,sizeof(BOOL));
|
|
|
|
File->Read(&ScaleFactor,sizeof(float));
|
|
|
|
File->Read(&ResizeFlag,sizeof(BOOL));
|
|
|
|
File->Read(&VisibleFlag,sizeof(BOOL));
|
|
|
|
File->Read(&SubType,sizeof(int));
|
|
|
|
File->Read(&Width,sizeof(int));
|
|
|
|
File->Read(&Height,sizeof(int));
|
|
|
|
|
2001-02-20 16:57:03 +01:00
|
|
|
if (Version==2)
|
|
|
|
{
|
|
|
|
File->Read(&RGB[0],sizeof(RGBQUAD));
|
|
|
|
File->Read(&RGB[1],sizeof(RGBQUAD));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
File->Read(&Count,sizeof(int));
|
|
|
|
for (int i=0; i<LAYER_SHADE_RGB_MAX; i++)
|
|
|
|
{
|
|
|
|
File->Read(&Pos[i],sizeof(int));
|
|
|
|
File->Read(&RGB[i],sizeof(RGBQUAD));
|
|
|
|
}
|
|
|
|
}
|
2001-02-09 22:17:01 +01:00
|
|
|
|
|
|
|
TRACE1("%s\t",GetName());
|
|
|
|
TRACE1("Scl:%g\t",ScaleFactor);
|
|
|
|
TRACE1("%i\n",VisibleFlag);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CLayerShade::Save(CFile *File)
|
|
|
|
{
|
|
|
|
// Always Save current version
|
|
|
|
|
|
|
|
File->Write(&Render3dFlag,sizeof(BOOL));
|
|
|
|
File->Write(&ScaleFactor,sizeof(float));
|
|
|
|
File->Write(&ResizeFlag,sizeof(BOOL));
|
|
|
|
File->Write(&VisibleFlag,sizeof(BOOL));
|
|
|
|
File->Write(&SubType,sizeof(SubType));
|
|
|
|
File->Write(&Width,sizeof(int));
|
|
|
|
File->Write(&Height,sizeof(int));
|
|
|
|
|
2001-02-20 16:57:03 +01:00
|
|
|
File->Write(&Count,sizeof(int));
|
|
|
|
for (int i=0; i<LAYER_SHADE_RGB_MAX; i++)
|
|
|
|
{
|
|
|
|
File->Write(&Pos[i],sizeof(int));
|
|
|
|
File->Write(&RGB[i],sizeof(RGBQUAD));
|
|
|
|
}
|
|
|
|
|
2001-02-09 22:17:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CLayerShade::Render(CCore *Core,Vector3 &CamPos,BOOL Is3d)
|
|
|
|
{
|
|
|
|
Vector3 ThisCam=Core->OffsetCam(CamPos,GetScaleFactor());
|
|
|
|
float ZoomW=Core->GetZoomW();
|
|
|
|
float ZoomH=Core->GetZoomH();
|
|
|
|
float ScrOfsX=(ZoomW/2);
|
|
|
|
float ScrOfsY=(ZoomH/2);
|
|
|
|
Vector3 &Scale=Core->GetScaleVector();
|
2001-02-20 16:57:03 +01:00
|
|
|
int ThisCount=Count-1;
|
|
|
|
float X0=0;
|
|
|
|
float X1=Width;
|
|
|
|
float Y=(0+1);
|
2001-02-09 22:17:01 +01:00
|
|
|
|
2001-02-20 16:57:03 +01:00
|
|
|
float YInc=(float)Height/(float)ThisCount;
|
2001-02-09 22:17:01 +01:00
|
|
|
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glPushMatrix();
|
|
|
|
glLoadIdentity();
|
|
|
|
glScalef(Scale.x,Scale.y,Scale.z);
|
|
|
|
glTranslatef(-ThisCam.x,ThisCam.y,0); // Set scroll offset
|
|
|
|
glTranslatef(-ScrOfsX,ScrOfsY,0); // Bring to top left corner
|
|
|
|
|
|
|
|
glBegin (GL_QUADS);
|
2001-02-20 16:57:03 +01:00
|
|
|
for (int i=0; i<ThisCount; i++)
|
|
|
|
{
|
|
|
|
glColor3ub(RGB[i+0].rgbRed,RGB[i+0].rgbGreen,RGB[i+0].rgbBlue);
|
|
|
|
glVertex3f( X0,Y,0.0f);
|
|
|
|
glVertex3f( X1,Y,0.0f);
|
|
|
|
Y-=YInc;
|
|
|
|
glColor3ub(RGB[i+1].rgbRed,RGB[i+1].rgbGreen,RGB[i+1].rgbBlue);
|
|
|
|
glVertex3f( X1,Y,0.0f);
|
|
|
|
glVertex3f( X0,Y,0.0f);
|
|
|
|
}
|
2001-02-09 22:17:01 +01:00
|
|
|
glEnd();
|
|
|
|
glPopMatrix();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2001-02-14 23:35:47 +01:00
|
|
|
BOOL CLayerShade::Resize(int _Width,int _Height)
|
2001-02-09 22:17:01 +01:00
|
|
|
{
|
2001-02-14 23:35:47 +01:00
|
|
|
Width=TileLayerMinWidth+(_Width-TileLayerMinWidth)/ScaleFactor;
|
|
|
|
Height=TileLayerMinHeight+(_Height-TileLayerMinHeight)/ScaleFactor;
|
2001-02-09 22:17:01 +01:00
|
|
|
|
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*** Gui *********************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CLayerShade::GUIInit(CCore *Core)
|
|
|
|
{
|
|
|
|
Core->GUIAdd(ShadeDlg,IDD_LAYERSHADE_GUI);
|
2001-02-20 16:57:03 +01:00
|
|
|
for (int i=0; i<LAYER_SHADE_MAX; i++)
|
|
|
|
{
|
|
|
|
ShadeDlg.SetRGB(RGB[i],i);
|
|
|
|
}
|
|
|
|
ShadeDlg.SetCount(Count);
|
2001-02-09 22:17:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CLayerShade::GUIKill(CCore *Core)
|
|
|
|
{
|
2001-02-14 23:35:47 +01:00
|
|
|
Core->GUIRemove(ShadeDlg,IDD_LAYERSHADE_GUI);
|
2001-02-09 22:17:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CLayerShade::GUIUpdate(CCore *Core)
|
|
|
|
{
|
2001-02-20 16:57:03 +01:00
|
|
|
ShadeDlg.CheckData();
|
2001-02-09 22:17:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CLayerShade::GUIChanged(CCore *Core)
|
|
|
|
{
|
2001-02-20 16:57:03 +01:00
|
|
|
for (int i=0; i<LAYER_SHADE_MAX; i++)
|
|
|
|
{
|
|
|
|
ShadeDlg.GetRGB(RGB[i],i);
|
|
|
|
}
|
|
|
|
ShadeDlg.GetCount(Count);
|
2001-02-09 22:17:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*** Functions ***************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CLayerShade::Export(CCore *Core,CExport &Exp)
|
|
|
|
{
|
2001-02-16 19:23:01 +01:00
|
|
|
Exp.ExportLayerHeader(LAYER_TYPE_SHADE,SubType,Width,Height);
|
2001-02-20 16:57:03 +01:00
|
|
|
Exp.Write(&Count,sizeof(int));
|
2001-02-16 19:23:01 +01:00
|
|
|
for (int i=0; i<LAYER_SHADE_RGB_MAX; i++)
|
|
|
|
{
|
2001-02-20 16:57:03 +01:00
|
|
|
Exp.Write(&Pos[i],sizeof(int));
|
2001-02-16 19:23:01 +01:00
|
|
|
Exp.Write(&RGB[i],sizeof(RGBQUAD));
|
|
|
|
}
|
2001-02-09 22:17:01 +01:00
|
|
|
}
|
|
|
|
|