This commit is contained in:
parent
4f2649a592
commit
057cb931bb
19 changed files with 919 additions and 590 deletions
|
@ -1,6 +1,6 @@
|
|||
/*******************/
|
||||
/*** Layer Shade ***/
|
||||
/*******************/
|
||||
/*****************/
|
||||
/*** Layer RGB ***/
|
||||
/*****************/
|
||||
|
||||
|
||||
#include "stdafx.h"
|
||||
|
@ -16,167 +16,173 @@
|
|||
|
||||
#include "Core.h"
|
||||
#include "Layer.h"
|
||||
#include "LayerShade.h"
|
||||
#include "LayerRGB.h"
|
||||
#include "Utils.h"
|
||||
#include "Select.h"
|
||||
#include "Export.h"
|
||||
#include "GUILayerShade.h"
|
||||
#include "GUILayerRGB.h"
|
||||
#include "Elem.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
char *CLayerRGB::RGBModeName[CLayerRGB::GUI_MODE_MAX]={"Paint","Tint","Lighten","Darken"};
|
||||
|
||||
u8 BrushGfx1[]=
|
||||
{
|
||||
1
|
||||
};
|
||||
|
||||
u8 BrushGfx2[]=
|
||||
{
|
||||
1,1,
|
||||
1,1,
|
||||
};
|
||||
u8 BrushGfx3[]=
|
||||
{
|
||||
0,1,0,
|
||||
1,2,1,
|
||||
0,1,0,
|
||||
};
|
||||
u8 BrushGfx4[]=
|
||||
{
|
||||
0,1,1,0,
|
||||
1,2,2,1,
|
||||
1,2,2,1,
|
||||
0,1,1,0,
|
||||
};
|
||||
u8 BrushGfx5[]=
|
||||
{
|
||||
0,0,1,0,0,
|
||||
0,1,2,1,0,
|
||||
1,2,3,2,1,
|
||||
0,1,2,1,0,
|
||||
0,0,1,0,0,
|
||||
};
|
||||
u8 BrushGfx6[]=
|
||||
{
|
||||
0,0,1,1,0,0,
|
||||
0,1,2,2,1,0,
|
||||
1,2,3,3,2,1,
|
||||
1,2,3,3,2,1,
|
||||
0,1,2,2,1,0,
|
||||
0,0,1,1,0,0,
|
||||
};
|
||||
u8 BrushGfx7[]=
|
||||
{
|
||||
0,0,1,1,1,0,0,
|
||||
0,1,2,2,2,1,0,
|
||||
1,2,3,3,3,2,1,
|
||||
1,2,3,4,3,2,1,
|
||||
1,2,3,3,3,2,1,
|
||||
0,1,2,2,2,1,0,
|
||||
0,0,1,1,1,0,0,
|
||||
};
|
||||
u8 BrushGfx8[]=
|
||||
{
|
||||
0,0,1,1,1,1,0,0,
|
||||
0,1,2,2,2,2,1,0,
|
||||
1,2,3,3,3,3,2,1,
|
||||
1,2,3,4,4,3,2,1,
|
||||
1,2,3,4,4,3,2,1,
|
||||
1,2,3,3,3,3,2,1,
|
||||
0,1,2,2,2,2,1,0,
|
||||
0,0,1,1,1,1,0,0,
|
||||
};
|
||||
|
||||
CLayerRGB::sRGBBrush CLayerRGB::RGBBrushTable[CLayerRGB::RGB_BRUSH_MAX]=
|
||||
{
|
||||
{1,0,BrushGfx1},
|
||||
{2,1,BrushGfx2},
|
||||
{3,1,BrushGfx3},
|
||||
{4,2,BrushGfx4},
|
||||
{5,2,BrushGfx5},
|
||||
{6,3,BrushGfx6},
|
||||
{7,3,BrushGfx7},
|
||||
{8,4,BrushGfx8},
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
// New Layer
|
||||
CLayerShade::CLayerShade(sLayerDef &Def)
|
||||
CLayerRGB::CLayerRGB(sLayerDef &Def)
|
||||
{
|
||||
InitLayer(Def);
|
||||
GString ExecPath;
|
||||
GString ScriptName;
|
||||
|
||||
GfxBank=new CElemBank(-1,-1,false,CElem::CentreModeLR | CElem::CentreModeTB);
|
||||
LoadGfx();
|
||||
Cursor.Gfx=-1;
|
||||
Cursor.Ofs[0].x=-2; Cursor.Ofs[0].y=-2;
|
||||
Cursor.Ofs[1].x=+2; Cursor.Ofs[1].y=-2;
|
||||
Cursor.Ofs[2].x=-2; Cursor.Ofs[2].y=+2;
|
||||
Cursor.Ofs[3].x=+2; Cursor.Ofs[3].y=+2;
|
||||
Cursor.TransMode=0;
|
||||
CurrentRGB.R=128;
|
||||
CurrentRGB.G=128;
|
||||
CurrentRGB.B=128;
|
||||
CurrentMode=0;
|
||||
CurrentBrush=0;
|
||||
ShadeFlag=false;
|
||||
LastCursPos.x=-1;
|
||||
LastCursPos.y=-1;
|
||||
|
||||
for(int i=0; i<4; i++)
|
||||
{
|
||||
Cursor.RGB[i].R=Cursor.RGB[i].G=Cursor.RGB[i].B=255;
|
||||
}
|
||||
CurrentGfx=-1;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
CLayerShade::~CLayerShade()
|
||||
CLayerRGB::~CLayerRGB()
|
||||
{
|
||||
GfxBank->CleanUp();
|
||||
delete GfxBank;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CLayerShade::LoadGfx()
|
||||
{
|
||||
GString ExecPath;
|
||||
GString ScriptName;
|
||||
GetExecPath(ExecPath);
|
||||
ScriptName=ExecPath+theApp.GetConfigStr("LayerScript","BackGfxScript");
|
||||
Script.LoadAndImport(ScriptName);
|
||||
|
||||
int i,ListSize=Script.GetGroupCount();
|
||||
BankList.resize(ListSize);
|
||||
|
||||
for (i=0; i<ListSize; i++)
|
||||
{
|
||||
sBackList &ThisGfx=BankList[i];
|
||||
|
||||
char *Name=Script.GetGroupName(i);
|
||||
char *Gfx=Script.GetStr(Name,"gfx");
|
||||
|
||||
ThisGfx.Name=Name;
|
||||
if (Gfx)
|
||||
{
|
||||
char Filename[512];
|
||||
GFName::makeabsolute(ExecPath,Gfx,Filename);
|
||||
ThisGfx.ElemID=GfxBank->AddSet(Filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CLayerShade::InitLayer(sLayerDef &Def)
|
||||
void CLayerRGB::InitLayer(sLayerDef &Def)
|
||||
{
|
||||
CLayer::InitLayer(Def);
|
||||
// LayerDef.Width=TileLayerMinWidth+(Def.Width-TileLayerMinWidth)/GetScaleFactor();
|
||||
// LayerDef.Height=TileLayerMinHeight+(Def.Height-TileLayerMinHeight)/GetScaleFactor();
|
||||
|
||||
ShadeRGB[0].R=255; ShadeRGB[0].G=255; ShadeRGB[0].B=255;
|
||||
ShadeRGB[1].R=255; ShadeRGB[1].G=0; ShadeRGB[1].B=0;
|
||||
ShadeRGB[2].R=0; ShadeRGB[2].G=255; ShadeRGB[2].B=0;
|
||||
ShadeRGB[3].R=0; ShadeRGB[3].G=0; ShadeRGB[3].B=255;
|
||||
|
||||
ShadeCount=2;
|
||||
|
||||
SetSize(Def.Width,Def.Height,true);
|
||||
}
|
||||
/*****************************************************************************/
|
||||
void CLayerShade::Load(CFile *File,int Version)
|
||||
void CLayerRGB::Load(CFile *File,int Version)
|
||||
{
|
||||
int i;
|
||||
InitLayer(LayerDef);
|
||||
|
||||
File->Read(&ShadeCount,sizeof(int));
|
||||
|
||||
if (Version<9)
|
||||
{ // GOD I HATE FILE VERSIONS NOW!!
|
||||
int DummyInt;
|
||||
File->Read(&CurrentRGB,sizeof(sRGBElem));
|
||||
File->Read(&CurrentBrush,sizeof(int));
|
||||
File->Read(&CurrentMode,sizeof(int));
|
||||
File->Read(&ShadeFlag,sizeof(bool));
|
||||
|
||||
for (i=0; i<LAYER_SHADE_RGB_MAX; i++)
|
||||
{
|
||||
RGBQUAD RGB;
|
||||
File->Read(&DummyInt,sizeof(int));
|
||||
File->Read(&RGB,sizeof(RGBQUAD));
|
||||
ShadeRGB[i].R=RGB.rgbRed;
|
||||
ShadeRGB[i].G=RGB.rgbGreen;
|
||||
ShadeRGB[i].B=RGB.rgbBlue;
|
||||
}
|
||||
File->Read(&DummyInt,sizeof(int));
|
||||
File->Read(&DummyInt,sizeof(int));
|
||||
if (Version==8)
|
||||
{
|
||||
File->Read(&DummyInt,sizeof(int));
|
||||
File->Read(&DummyInt,sizeof(int));
|
||||
File->Read(&DummyInt,sizeof(int));
|
||||
File->Read(&DummyInt,sizeof(int));
|
||||
}
|
||||
}
|
||||
else
|
||||
// Read Map
|
||||
File->Read(&MapWidth,sizeof(int));
|
||||
File->Read(&MapHeight,sizeof(int));
|
||||
SetSize(MapWidth,MapHeight,false);
|
||||
for (int Y=0; Y<MapHeight; Y++)
|
||||
{
|
||||
int GfxCount;
|
||||
for (i=0; i<LAYER_SHADE_RGB_MAX; i++)
|
||||
for (int X=0; X<MapWidth; X++)
|
||||
{
|
||||
File->Read(&ShadeRGB[i],sizeof(sRGBCol));
|
||||
}
|
||||
// Load GfxList
|
||||
File->Read(&GfxCount,sizeof(int));
|
||||
GfxList.resize(GfxCount);
|
||||
for (i=0; i<GfxCount; i++)
|
||||
{
|
||||
sLayerShadeGfx &ThisGfx=GfxList[i];
|
||||
File->Read(&ThisGfx,sizeof(sLayerShadeGfx));
|
||||
}
|
||||
if (GfxCount) CurrentGfx=0;
|
||||
sRGBElem &ThisElem=Map[X][Y];
|
||||
|
||||
File->Read(&ThisElem,sizeof(sRGBElem));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CLayerShade::Save(CFile *File)
|
||||
void CLayerRGB::Save(CFile *File)
|
||||
{
|
||||
// Always Save current version
|
||||
File->Write(&ShadeCount,sizeof(int));
|
||||
for (int i=0; i<LAYER_SHADE_RGB_MAX; i++)
|
||||
{
|
||||
File->Write(&ShadeRGB[i],sizeof(sRGBCol));
|
||||
}
|
||||
int GfxCount=GfxList.size();
|
||||
File->Write(&GfxCount,sizeof(int));
|
||||
|
||||
for (i=0; i<GfxCount; i++)
|
||||
{
|
||||
sLayerShadeGfx &ThisGfx=GfxList[i];
|
||||
File->Write(&ThisGfx,sizeof(sLayerShadeGfx));
|
||||
}
|
||||
File->Write(&CurrentRGB,sizeof(sRGBElem));
|
||||
File->Write(&CurrentBrush,sizeof(int));
|
||||
File->Write(&CurrentMode,sizeof(int));
|
||||
File->Write(&ShadeFlag,sizeof(bool));
|
||||
|
||||
// Read Map
|
||||
File->Write(&MapWidth,sizeof(int));
|
||||
File->Write(&MapHeight,sizeof(int));
|
||||
for (int Y=0; Y<MapHeight; Y++)
|
||||
{
|
||||
for (int X=0; X<MapWidth; X++)
|
||||
{
|
||||
sRGBElem &ThisElem=Map[X][Y];
|
||||
|
||||
File->Write(&ThisElem,sizeof(sRGBElem));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
void CLayerShade::Render(CCore *Core,Vector3 &CamPos,bool Is3d)
|
||||
void CLayerRGB::Render(CCore *Core,Vector3 &CamPos,bool Is3d)
|
||||
{
|
||||
Vector3 ThisCam=Core->OffsetCam(CamPos,GetScaleFactor());
|
||||
float ZoomW=Core->GetZoomW();
|
||||
|
@ -184,93 +190,133 @@ float ZoomH=Core->GetZoomH();
|
|||
float ScrOfsX=(ZoomW/2);
|
||||
float ScrOfsY=(ZoomH/2);
|
||||
Vector3 &Scale=Core->GetScaleVector();
|
||||
int ThisCount=ShadeCount-1;
|
||||
float X0=0;
|
||||
float X1=LayerDef.Width;
|
||||
float Y=(0+1);
|
||||
float YInc=(float)LayerDef.Height/(float)ThisCount;
|
||||
int i,ListSize;
|
||||
int StartX=(int)ThisCam.x;
|
||||
int StartY=(int)ThisCam.y;
|
||||
float ShiftX=ThisCam.x - (int)ThisCam.x;
|
||||
float ShiftY=ThisCam.y - (int)ThisCam.y;
|
||||
CLayerTile *ActionLayer=(CLayerTile*)Core->GetActionLayer();
|
||||
|
||||
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
|
||||
if (StartX<0) StartX=0;
|
||||
if (StartY<0) StartY=0;
|
||||
|
||||
glBegin (GL_QUADS);
|
||||
for (i=0; i<ThisCount; i++)
|
||||
{
|
||||
glColor3ub(ShadeRGB[i+0].R,ShadeRGB[i+0].G,ShadeRGB[i+0].B);
|
||||
glVertex3f( X0,Y,0.0f);
|
||||
glVertex3f( X1,Y,0.0f);
|
||||
Y-=YInc;
|
||||
glColor3ub(ShadeRGB[i+1].R,ShadeRGB[i+1].G,ShadeRGB[i+1].B);
|
||||
glVertex3f( X1,Y,0.0f);
|
||||
glVertex3f( X0,Y,0.0f);
|
||||
}
|
||||
glEnd();
|
||||
glPopMatrix();
|
||||
// Render Gfx
|
||||
ListSize=GfxList.size();
|
||||
for (i=0; i<ListSize; i++)
|
||||
int DrawW=ZoomW+8;
|
||||
int DrawH=ZoomH+8;
|
||||
|
||||
if (StartX+DrawW>MapWidth) DrawW=MapWidth-StartX;
|
||||
if (StartY+DrawH>MapHeight) DrawH=MapHeight-StartY;
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glScalef(Scale.x,Scale.y,Scale.z);
|
||||
glTranslatef(-ShiftX,ShiftY,0); // Set scroll offset
|
||||
glTranslatef(-ScrOfsX,ScrOfsY,0); // Bring to top left corner
|
||||
|
||||
for (int YLoop=0; YLoop<DrawH; YLoop++)
|
||||
{
|
||||
sLayerShadeGfx &ThisGfx=GfxList[i];
|
||||
RenderBackGfx(Core,ThisCam,ThisGfx);
|
||||
for (int XLoop=0; XLoop<DrawW; XLoop++)
|
||||
{
|
||||
int XPos=StartX+XLoop;
|
||||
int YPos=StartY+YLoop;
|
||||
|
||||
sRGBElem &ThisElem=Map[XPos][YPos];
|
||||
sMapElem &MapElem=ActionLayer->GetMapElem(XPos,YPos);
|
||||
if (MapElem.Tile)
|
||||
{
|
||||
float fR=(1.0f/255.0f)*ThisElem.R;
|
||||
float fG=(1.0f/255.0f)*ThisElem.G;
|
||||
float fB=(1.0f/255.0f)*ThisElem.B;
|
||||
glLoadName (0);
|
||||
glBegin (GL_QUADS);
|
||||
glColor4f(fR,fG,fB,0.5);
|
||||
BuildGLQuad(0,1,0,1,0);
|
||||
glEnd();
|
||||
}
|
||||
glTranslatef(1.0f,0,0); // Next X
|
||||
}
|
||||
glTranslatef(-DrawW,-1,0); // Next y, rewind to start X
|
||||
}
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
void CLayerShade::RenderCursor(CCore *Core,Vector3 &CamPos,bool Is3d)
|
||||
void CLayerRGB::RenderCursor(CCore *Core,Vector3 &CamPos,bool Is3d)
|
||||
{
|
||||
Vector3 ThisCam=Core->OffsetCam(CamPos,GetScaleFactor());
|
||||
CPoint &CursPos=Core->GetCursorPos();
|
||||
CPoint CursPos=Core->GetCursorPos();
|
||||
|
||||
Cursor.Pos.x=CursPos.x;
|
||||
Cursor.Pos.y=CursPos.y;
|
||||
if (CursPos.x<0 || CursPos.y<0) return;
|
||||
if (Cursor.Gfx==-1) return;
|
||||
RenderBackGfx(Core,ThisCam,Cursor);
|
||||
}
|
||||
if (CursPos.x<0 || CursPos.y<0) return;
|
||||
sRGBBrush &ThisBrush=RGBBrushTable[CurrentBrush];
|
||||
|
||||
CursPos.x-=ThisBrush.XYOfs;
|
||||
CursPos.y-=ThisBrush.XYOfs;
|
||||
CursPos.x-=(int)ThisCam.x;
|
||||
CursPos.y-=(int)ThisCam.y;
|
||||
|
||||
/*****************************************************************************/
|
||||
void CLayerShade::RenderBackGfx(CCore *Core,Vector3 &ThisCam,sLayerShadeGfx &ThisGfx)
|
||||
{
|
||||
float ZoomW=Core->GetZoomW();
|
||||
float ZoomH=Core->GetZoomH();
|
||||
float ScrOfsX=(ZoomW/2);
|
||||
float ScrOfsY=(ZoomH/2);
|
||||
Vector3 &Scale=Core->GetScaleVector();
|
||||
Vector3 ScrOfs(ZoomW/2,ZoomH/2,0);
|
||||
int i;
|
||||
float ShiftX=ThisCam.x - (int)ThisCam.x;
|
||||
float ShiftY=ThisCam.y - (int)ThisCam.y;
|
||||
u8 *Gfx=ThisBrush.Gfx;
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glScalef(Scale.x,Scale.y,Scale.z);
|
||||
glTranslatef(-ShiftX,ShiftY,0); // Set scroll offset
|
||||
glTranslatef(-ScrOfsX,ScrOfsY,0); // Bring to top left corner
|
||||
glTranslatef(CursPos.x,-CursPos.y,0); // Bring to top left corner
|
||||
|
||||
CElem Elem=GfxBank->GetElem(ThisGfx.Gfx,0);
|
||||
for (int YLoop=0; YLoop<ThisBrush.WH; YLoop++)
|
||||
{
|
||||
for (int XLoop=0; XLoop<ThisBrush.WH; XLoop++)
|
||||
{
|
||||
u8 B=*Gfx++;
|
||||
float fR,fG,fB,Bi;
|
||||
Bi=(1.0f/8.0f)*(float)B;
|
||||
|
||||
if (B)
|
||||
{
|
||||
glLoadName (0);
|
||||
glBegin (GL_QUADS);
|
||||
switch(CurrentMode)
|
||||
{
|
||||
case GUI_MODE_PAINT:
|
||||
fR=CurrentRGB.R;
|
||||
fG=CurrentRGB.G;
|
||||
fB=CurrentRGB.B;
|
||||
break;
|
||||
case GUI_MODE_TINT:
|
||||
fR=((1.0f/255.0f)*CurrentRGB.R)+Bi;
|
||||
fG=((1.0f/255.0f)*CurrentRGB.G)+Bi;
|
||||
fB=((1.0f/255.0f)*CurrentRGB.B)+Bi;
|
||||
break;
|
||||
case GUI_MODE_LIGHTEN:
|
||||
case GUI_MODE_DARKEN:
|
||||
fR=1;
|
||||
fG=1;
|
||||
fB=1;
|
||||
break;
|
||||
}
|
||||
glColor4f(fR,fG,fB,0.5);
|
||||
BuildGLQuad(0,1,0,1,0);
|
||||
glEnd();
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
}
|
||||
glTranslatef(1.0f,0,0); // Next X
|
||||
}
|
||||
glTranslatef(-ThisBrush.WH,-1,0); // Next y, rewind to start X
|
||||
}
|
||||
glPopMatrix();
|
||||
|
||||
glScalef(Scale.x,Scale.y,Scale.z);
|
||||
glTranslatef(-ThisCam.x,ThisCam.y,0); // Set scroll offset
|
||||
glTranslatef(-ScrOfs.x,ScrOfs.y,0); // Bring to top left corner
|
||||
|
||||
glTranslatef(ThisGfx.Pos.x,-ThisGfx.Pos.y,0); // Set Pos
|
||||
glColor3ub(255,255,255);
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, Elem.GetTexID());
|
||||
glBegin (GL_QUADS);
|
||||
i=0; glColor3ub(ThisGfx.RGB[i].R,ThisGfx.RGB[i].G,ThisGfx.RGB[i].B); glTexCoord2f(0.0f,1.0f); glVertex3f(ThisGfx.Ofs[i].x ,-ThisGfx.Ofs[i].y,0.0f);
|
||||
i=1; glColor3ub(ThisGfx.RGB[i].R,ThisGfx.RGB[i].G,ThisGfx.RGB[i].B); glTexCoord2f(1.0f,1.0f); glVertex3f(ThisGfx.Ofs[i].x ,-ThisGfx.Ofs[i].y,0.0f);
|
||||
i=3; glColor3ub(ThisGfx.RGB[i].R,ThisGfx.RGB[i].G,ThisGfx.RGB[i].B); glTexCoord2f(1.0f,0.0f); glVertex3f(ThisGfx.Ofs[i].x ,-ThisGfx.Ofs[i].y,0.0f);
|
||||
i=2; glColor3ub(ThisGfx.RGB[i].R,ThisGfx.RGB[i].G,ThisGfx.RGB[i].B); glTexCoord2f(0.0f,0.0f); glVertex3f(ThisGfx.Ofs[i].x ,-ThisGfx.Ofs[i].y,0.0f);
|
||||
glEnd();
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CLayerShade::CheckLayerSize(int Width,int Height)
|
||||
void CLayerRGB::CheckLayerSize(int Width,int Height)
|
||||
{
|
||||
if (Resize(Width,Height))
|
||||
{
|
||||
|
@ -281,262 +327,236 @@ void CLayerShade::CheckLayerSize(int Width,int Height)
|
|||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
bool CLayerShade::Resize(int Width,int Height)
|
||||
void CLayerRGB::SetSize(int Width,int Height,BOOL ClearFlag)
|
||||
{
|
||||
MapWidth=Width;
|
||||
MapHeight=Height;
|
||||
Map.resize(Width);
|
||||
for (int i=0;i<Width;i++)
|
||||
{
|
||||
Map[i].resize(Height);
|
||||
}
|
||||
|
||||
Width=TileLayerMinWidth+(Width-TileLayerMinWidth)/GetScaleFactor();
|
||||
Height=TileLayerMinHeight+(Height-TileLayerMinHeight)/GetScaleFactor();
|
||||
if (LayerDef.Width!=Width || LayerDef.Height!=Height)
|
||||
if (ClearFlag) Clear();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CLayerRGB::Clear()
|
||||
{
|
||||
for (int Y=0;Y<MapHeight;Y++)
|
||||
{
|
||||
LayerDef.Width=Width;
|
||||
LayerDef.Height=Height;
|
||||
for (int X=0;X<MapWidth;X++)
|
||||
{
|
||||
Map[X][Y].R=128;
|
||||
Map[X][Y].G=128;
|
||||
Map[X][Y].B=128;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
bool CLayerRGB::Resize(int Width,int Height)
|
||||
{
|
||||
if (MapWidth!= Width || MapHeight!=Height)
|
||||
{
|
||||
SetSize(Width,Height,true);
|
||||
return(true);
|
||||
}
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*** Gui *********************************************************************/
|
||||
/*****************************************************************************/
|
||||
void CLayerShade::GUIInit(CCore *Core)
|
||||
void CLayerRGB::GUIInit(CCore *Core)
|
||||
{
|
||||
int i,ListSize;
|
||||
|
||||
GUIShade.DisableCallback();
|
||||
Core->GUIAdd(GUIShade,IDD_LAYER_SHADE);
|
||||
int i;
|
||||
|
||||
// Init BankList
|
||||
ListSize=BankList.size();
|
||||
GUIShade.m_GfxBankList.ResetContent();
|
||||
GUIShade.m_DefList.ResetContent();
|
||||
for (i=0; i<ListSize; i++)
|
||||
GUIRGB.DisableCallback();
|
||||
Core->GUIAdd(GUIRGB,IDD_LAYER_RGB);
|
||||
|
||||
// Init ModeList
|
||||
GUIRGB.m_ModeList.ResetContent();
|
||||
for (i=0; i<GUI_MODE_MAX; i++)
|
||||
{
|
||||
GUIShade.m_GfxBankList.AddString(BankList[i].Name);
|
||||
GUIShade.m_DefList.AddString(BankList[i].Name);
|
||||
GUIRGB.m_ModeList.AddString(RGBModeName[i]);
|
||||
}
|
||||
GUIRGB.m_RSpin.SetRange(0,255);
|
||||
GUIRGB.m_GSpin.SetRange(0,255);
|
||||
GUIRGB.m_BSpin.SetRange(0,255);
|
||||
GUIRGB.m_BrushSpin.SetRange(0,RGB_BRUSH_MAX-1);
|
||||
|
||||
GUIShade.m_GfxTransList.ResetContent();
|
||||
GUIShade.m_GfxTransList.AddString("Normal");
|
||||
GUIShade.m_GfxTransList.AddString("50%");
|
||||
GUIShade.m_GfxTransList.AddString("Subtractive");
|
||||
GUIShade.m_GfxTransList.AddString("Another one");
|
||||
|
||||
GUIShade.m_GfxPosXSpin.SetRange(0,32000); GUIShade.m_GfxPosYSpin.SetRange(0,32000);
|
||||
GUIShade.m_GfxSpinx0.SetRange(-32,+32); GUIShade.m_GfxSpiny0.SetRange(-32,+32);
|
||||
GUIShade.m_GfxSpinx1.SetRange(-32,+32); GUIShade.m_GfxSpiny1.SetRange(-32,+32);
|
||||
GUIShade.m_GfxSpinx2.SetRange(-32,+32); GUIShade.m_GfxSpiny2.SetRange(-32,+32);
|
||||
GUIShade.m_GfxSpinx3.SetRange(-32,+32); GUIShade.m_GfxSpiny3.SetRange(-32,+32);
|
||||
GUIShade.EnableCallback();
|
||||
GUIRGB.EnableCallback();
|
||||
Core->RedrawView();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CLayerShade::GUIKill(CCore *Core)
|
||||
void CLayerRGB::GUIKill(CCore *Core)
|
||||
{
|
||||
|
||||
GUIChanged(Core);
|
||||
Core->GUIRemove(GUIShade,IDD_LAYER_SHADE);
|
||||
Core->GUIRemove(GUIRGB,IDD_LAYER_RGB);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CLayerShade::GUIUpdate(CCore *Core)
|
||||
void CLayerRGB::GUIUpdate(CCore *Core)
|
||||
{
|
||||
int i,ListSize;
|
||||
GUIRGB.DisableCallback();
|
||||
|
||||
// Shades
|
||||
GUIShade.DisableCallback();
|
||||
|
||||
for (i=0; i<LAYER_SHADE_MAX; i++)
|
||||
{
|
||||
GUIShade.SetShadeRGB(i,ShadeRGB[i].R,ShadeRGB[i].G,ShadeRGB[i].B);
|
||||
}
|
||||
GUIShade.m_ShadeCountSpin.SetRange(2,4);
|
||||
GUIShade.SetVal(GUIShade.m_ShadeCount,ShadeCount,2,4);
|
||||
|
||||
// Gfx
|
||||
ListSize=GfxList.size();
|
||||
if (!ListSize)
|
||||
{
|
||||
GUIShade.m_GfxCurrent.SetWindowText("");
|
||||
GUIShade.m_GfxCurrentSpin.SetRange(0,0);
|
||||
return;
|
||||
}
|
||||
|
||||
sLayerShadeGfx &ThisGfx=GfxList[CurrentGfx];
|
||||
|
||||
GUIShade.m_GfxCurrentSpin.SetRange(0,ListSize);
|
||||
GUIShade.SetVal(GUIShade.m_GfxCurrent,CurrentGfx,0,ListSize-1);
|
||||
GUIShade.SetVal(GUIShade.m_GfxPosX,ThisGfx.Pos.x);
|
||||
GUIShade.SetVal(GUIShade.m_GfxPosY,ThisGfx.Pos.y);
|
||||
GUIShade.m_GfxBankList.SetCurSel(ThisGfx.Gfx);
|
||||
GUIRGB.m_ModeList.SetCurSel(CurrentMode);
|
||||
GUIRGB.SetRGB(CurrentRGB.R,CurrentRGB.G,CurrentRGB.B);
|
||||
GUIRGB.SetVal(GUIRGB.m_Brush,CurrentBrush);
|
||||
GUIRGB.m_Shade.SetCheck(ShadeFlag);
|
||||
|
||||
for ( i=0;i<4; i++)
|
||||
{
|
||||
GUIShade.SetGfxRGB(i,ThisGfx.RGB[i].R,ThisGfx.RGB[i].G,ThisGfx.RGB[i].B);
|
||||
}
|
||||
|
||||
GUIShade.SetVal(GUIShade.m_Gfxx0,ThisGfx.Ofs[0].x); GUIShade.SetVal(GUIShade.m_Gfxy0,ThisGfx.Ofs[0].y);
|
||||
GUIShade.SetVal(GUIShade.m_Gfxx1,ThisGfx.Ofs[1].x); GUIShade.SetVal(GUIShade.m_Gfxy1,ThisGfx.Ofs[1].y);
|
||||
GUIShade.SetVal(GUIShade.m_Gfxx2,ThisGfx.Ofs[2].x); GUIShade.SetVal(GUIShade.m_Gfxy2,ThisGfx.Ofs[2].y);
|
||||
GUIShade.SetVal(GUIShade.m_Gfxx3,ThisGfx.Ofs[3].x); GUIShade.SetVal(GUIShade.m_Gfxy3,ThisGfx.Ofs[3].y);
|
||||
|
||||
GUIShade.m_GfxTransList.SetCurSel(ThisGfx.TransMode);
|
||||
GUIShade.EnableCallback();
|
||||
GUIRGB.EnableCallback();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CLayerShade::GUIChanged(CCore *Core)
|
||||
void CLayerRGB::GUIChanged(CCore *Core)
|
||||
{
|
||||
int i,ListSize;
|
||||
int LastGfx=CurrentGfx;
|
||||
// Shade
|
||||
for (i=0; i<LAYER_SHADE_MAX; i++)
|
||||
{
|
||||
GUIShade.GetShadeRGB(i,ShadeRGB[i].R,ShadeRGB[i].G,ShadeRGB[i].B);
|
||||
}
|
||||
GUIShade.GetVal(GUIShade.m_ShadeCount,ShadeCount,2,4);
|
||||
// Gfx
|
||||
ListSize=GfxList.size();
|
||||
GUIShade.GetVal(GUIShade.m_GfxCurrent,ListSize,0,ListSize);
|
||||
if (!ListSize || CurrentGfx==-1) return;
|
||||
|
||||
sLayerShadeGfx &ThisGfx=GfxList[CurrentGfx];
|
||||
|
||||
GUIShade.GetVal(GUIShade.m_GfxPosX,ThisGfx.Pos.x);
|
||||
GUIShade.GetVal(GUIShade.m_GfxPosY,ThisGfx.Pos.y);
|
||||
ThisGfx.Gfx=GUIShade.m_GfxBankList.GetCurSel();
|
||||
|
||||
for ( i=0;i<4; i++)
|
||||
{
|
||||
GUIShade.GetGfxRGB(i,ThisGfx.RGB[i].R,ThisGfx.RGB[i].G,ThisGfx.RGB[i].B);
|
||||
}
|
||||
GUIShade.GetVal(GUIShade.m_Gfxx0,ThisGfx.Ofs[0].x); GUIShade.GetVal(GUIShade.m_Gfxy0,ThisGfx.Ofs[0].y);
|
||||
GUIShade.GetVal(GUIShade.m_Gfxx1,ThisGfx.Ofs[1].x); GUIShade.GetVal(GUIShade.m_Gfxy1,ThisGfx.Ofs[1].y);
|
||||
GUIShade.GetVal(GUIShade.m_Gfxx2,ThisGfx.Ofs[2].x); GUIShade.GetVal(GUIShade.m_Gfxy2,ThisGfx.Ofs[2].y);
|
||||
GUIShade.GetVal(GUIShade.m_Gfxx3,ThisGfx.Ofs[3].x); GUIShade.GetVal(GUIShade.m_Gfxy3,ThisGfx.Ofs[3].y);
|
||||
ThisGfx.TransMode=GUIShade.m_GfxTransList.GetCurSel();
|
||||
|
||||
if (CurrentGfx!=LastGfx)
|
||||
{
|
||||
GUIUpdate(Core);
|
||||
}
|
||||
CurrentMode=GUIRGB.m_ModeList.GetCurSel();
|
||||
GUIRGB.GetRGB(CurrentRGB.R,CurrentRGB.G,CurrentRGB.B);
|
||||
GUIRGB.GetVal(GUIRGB.m_Brush,CurrentBrush);
|
||||
ShadeFlag=GUIRGB.m_Shade.GetCheck()!=0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*** Functions ***************************************************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
bool CLayerShade::LButtonControl(CCore *Core,UINT nFlags, CPoint &CursorPos,bool DownFlag)
|
||||
bool CLayerRGB::LButtonControl(CCore *Core,UINT nFlags, CPoint &CursorPos,bool DownFlag)
|
||||
{
|
||||
if (DownFlag) AddGfx(Core);
|
||||
return(true);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
bool CLayerShade::RButtonControl(CCore *Core,UINT nFlags, CPoint &CursorPos,bool DownFlag)
|
||||
{
|
||||
if (DownFlag) Cursor.Gfx=-1;
|
||||
return(true);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
bool CLayerShade::MouseMove(CCore *Core,UINT nFlags, CPoint &CursorPos)
|
||||
{
|
||||
return(true);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
bool CLayerShade::Command(int CmdMsg,CCore *Core,int Param0,int Param1)
|
||||
{
|
||||
bool Ret=false;
|
||||
|
||||
switch(CmdMsg)
|
||||
if (DownFlag)
|
||||
{
|
||||
case CmdMsg_ShadeGfxNew:
|
||||
Cursor.Gfx=Param0;
|
||||
GUIShade.m_DefList.SetCurSel(-1);
|
||||
break;
|
||||
case CmdMsg_ShadeGfxSelect:
|
||||
GUIShade.GetVal(GUIShade.m_GfxCurrent,CurrentGfx);
|
||||
if (CurrentGfx>GfxList.size()-1) CurrentGfx=GfxList.size()-1;
|
||||
GUIUpdate(Core);
|
||||
break;
|
||||
case CmdMsg_ShadeGfxGoto:
|
||||
GotoGfx(Core);
|
||||
break;
|
||||
case CmdMsg_ShadeGfxDelete:
|
||||
DeleteGfx(Core);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
Paint(Core,CursorPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
LastCursPos.x=-1;
|
||||
LastCursPos.y=-1;
|
||||
}
|
||||
return(true);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
bool CLayerRGB::RButtonControl(CCore *Core,UINT nFlags, CPoint &CursorPos,bool DownFlag)
|
||||
{
|
||||
if (DownFlag) Grab(Core,CursorPos);
|
||||
return(true);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
bool CLayerRGB::MouseMove(CCore *Core,UINT nFlags, CPoint &CursorPos)
|
||||
{
|
||||
if (nFlags & MK_LBUTTON)
|
||||
{
|
||||
Paint(Core,CursorPos);
|
||||
}
|
||||
return(true);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CLayerRGB::Paint(CCore *Core,CPoint &CursorPos)
|
||||
{
|
||||
if (CursorPos.x<0 || CursorPos.x>MapWidth) return;
|
||||
if (CursorPos.y<0 || CursorPos.y>MapHeight) return;
|
||||
|
||||
if (CursorPos.x== LastCursPos.x && CursorPos.y==LastCursPos.y) return;
|
||||
LastCursPos=CursorPos;
|
||||
|
||||
sRGBBrush &ThisBrush=RGBBrushTable[CurrentBrush];
|
||||
u8 *Gfx=ThisBrush.Gfx;
|
||||
CPoint CursPos;
|
||||
|
||||
CursPos.x=CursorPos.x-ThisBrush.XYOfs;
|
||||
CursPos.y=CursorPos.y-ThisBrush.XYOfs;
|
||||
|
||||
for (int Y=0; Y<ThisBrush.WH; Y++)
|
||||
{
|
||||
for (int X=0; X<ThisBrush.WH; X++)
|
||||
{
|
||||
CPoint Pos=CursPos;
|
||||
Pos.x+=X;
|
||||
Pos.y+=Y;
|
||||
int Blk=*Gfx++;
|
||||
|
||||
if (Blk)
|
||||
if (Pos.x>=0 && Pos.x<MapWidth &&
|
||||
Pos.y>=0 && Pos.y<MapHeight)
|
||||
{
|
||||
sRGBElem MapElem=GetRGB(Pos.x,Pos.y);
|
||||
int R=CurrentRGB.R;
|
||||
int G=CurrentRGB.G;
|
||||
int B=CurrentRGB.B;
|
||||
int Br=(R/8)*Blk;
|
||||
int Bg=(G/8)*Blk;
|
||||
int Bb=(B/8)*Blk;
|
||||
|
||||
switch(CurrentMode)
|
||||
{
|
||||
case GUI_MODE_PAINT:
|
||||
break;
|
||||
case GUI_MODE_TINT:
|
||||
R=(MapElem.R+Br);
|
||||
G=(MapElem.G+Bg);
|
||||
B=(MapElem.B+Bb);
|
||||
break;
|
||||
case GUI_MODE_LIGHTEN:
|
||||
R=MapElem.R+4;
|
||||
G=MapElem.G+4;
|
||||
B=MapElem.B+4;
|
||||
break;
|
||||
case GUI_MODE_DARKEN:
|
||||
R=MapElem.R-4;
|
||||
G=MapElem.G-4;
|
||||
B=MapElem.B-4;
|
||||
break;
|
||||
}
|
||||
if (R<0) R=0; else if (R>255) R=255;
|
||||
if (G<0) G=0; else if (G>255) G=255;
|
||||
if (B<0) B=0; else if (B>255) B=255;
|
||||
Map[Pos.x][Pos.y].R=R;
|
||||
Map[Pos.x][Pos.y].G=G;
|
||||
Map[Pos.x][Pos.y].B=B;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return(Ret);
|
||||
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CLayerShade::AddGfx(CCore *Core)
|
||||
void CLayerRGB::Grab(CCore *Core,CPoint &CursorPos)
|
||||
{
|
||||
if (Cursor.Gfx==-1) return;
|
||||
if (CursorPos.x<0 || CursorPos.x>MapWidth) return;
|
||||
if (CursorPos.y<0 || CursorPos.y>MapHeight) return;
|
||||
|
||||
CurrentGfx=GfxList.size();
|
||||
GfxList.push_back(Cursor);
|
||||
|
||||
Cursor.Gfx=-1;
|
||||
GUIUpdate(Core);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CLayerShade::GotoGfx(CCore *Core)
|
||||
{
|
||||
if (CurrentGfx==-1) return;
|
||||
sLayerShadeGfx &ThisGfx=GfxList[CurrentGfx];
|
||||
CPoint Pos;
|
||||
Pos.x=ThisGfx.Pos.x;
|
||||
Pos.y=ThisGfx.Pos.y;
|
||||
Core->SetCamPos(Pos);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CLayerShade::DeleteGfx(CCore *Core)
|
||||
{
|
||||
if (!GfxList.size()) return;
|
||||
|
||||
GfxList.erase(CurrentGfx);
|
||||
if (CurrentGfx) CurrentGfx--;
|
||||
CurrentRGB=Map[CursorPos.x][CursorPos.y];
|
||||
GUIUpdate(Core);
|
||||
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CLayerShade::Export(CCore *Core,CExport &Exp)
|
||||
void CLayerRGB::Export(CCore *Core,CExport &Exp)
|
||||
{
|
||||
int i,ListSize;
|
||||
Exp.ExportLayerHeader(LayerDef);//LAYER_TYPE_RGB,LayerDef.SubType,LayerDef.Width,LayerDef.Height);
|
||||
|
||||
Exp.ExportLayerHeader(LayerDef);//LAYER_TYPE_SHADE,LayerDef.SubType,LayerDef.Width,LayerDef.Height);
|
||||
Exp.Write(&ShadeCount,sizeof(int));
|
||||
for (i=0; i<LAYER_SHADE_RGB_MAX; i++)
|
||||
{
|
||||
Exp.Write(&ShadeRGB[i],sizeof(sRGBCol));
|
||||
}
|
||||
int f=ShadeFlag;
|
||||
Exp.Write(&f,sizeof(int));
|
||||
|
||||
// Write Gfx List
|
||||
ListSize=GfxList.size();
|
||||
Exp.Write(&ListSize,sizeof(int));
|
||||
for (int Y=0; Y<MapHeight; Y++)
|
||||
{
|
||||
for (int X=0; X<MapWidth; X++)
|
||||
{
|
||||
sRGBElem &ThisElem=Map[X][Y];
|
||||
sRGBCol RGB;
|
||||
|
||||
for (i=0; i<ListSize; i++)
|
||||
{
|
||||
sLayerShadeGfx &ThisGfx=GfxList[i];
|
||||
Exp.Write(&ThisGfx,sizeof(sLayerShadeGfx));
|
||||
}
|
||||
// Write Gfx Names
|
||||
ListSize=BankList.size();
|
||||
Exp.Write(&ListSize,sizeof(int));
|
||||
for (i=0; i<ListSize; i++)
|
||||
{
|
||||
char Txt[256];
|
||||
sprintf(Txt,BankList[i].Name);
|
||||
Exp.Write(Txt,strlen(Txt)+1);
|
||||
RGB.R=ThisElem.R;
|
||||
RGB.G=ThisElem.G;
|
||||
RGB.B=ThisElem.B;
|
||||
|
||||
Exp.Write(&RGB,sizeof(sRGBCol));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue