This commit is contained in:
Daveo 2001-08-02 12:42:38 +00:00
parent 115da19f78
commit ca1110c6e5
15 changed files with 470 additions and 294 deletions

View File

@ -64,10 +64,14 @@ void PadFile(FILE *File)
{
int Pad=ftell(File) & 3;
if (Pad)
while (ftell(File) &3)
{
fwrite(&Pad,Pad,1,File);
fwrite(&Pad,1,1,File);
}
// if (Pad)
// {
// fwrite(&Pad,Pad,1,File);
// }
}
//***************************************************************************

View File

@ -157,7 +157,8 @@ public:
void FlipY(void);
void Resize(int NewWidth,int NewHeight);
u8 GetPixel(int PixX,int PixY) { return(Buffa[PixX+(PixY*Width)]);}
u8 GetPixel(int PixX,int PixY) { return(Buffa[PixX+(PixY*Width)]);}
void SetPixel(int PixX,int PixY,u8 Col) { Buffa[PixX+(PixY*Width)]=Col;}
protected:
void CopyFrame(Frame const &);

View File

@ -52,6 +52,7 @@ enum CmdMsg
CmdMsg_ShadeGfxDelete, // 34
// Misc
CmdMsg_Report, // 35
CmdMsg_Undo, // 36
};
#endif

View File

@ -30,32 +30,25 @@ void CGUILayerRGB::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CGUILayerRGB)
DDX_Control(pDX, IDC_LAYERSHADE_RATELIST, m_RateList);
DDX_Control(pDX, IDC_LAYERSHADE_BRUSHLIST, m_BrushList);
DDX_Control(pDX, IDC_LAYERSHADE_MODELIST, m_ModeList);
DDX_Control(pDX, IDC_LAYERSHADE_SHADE, m_Shade);
DDX_Control(pDX, IDC_LAYERSHADE_BSPIN, m_BSpin);
DDX_Control(pDX, IDC_LAYERSHADE_B, m_B);
DDX_Control(pDX, IDC_LAYERSHADE_GSPIN, m_GSpin);
DDX_Control(pDX, IDC_LAYERSHADE_G, m_G);
DDX_Control(pDX, IDC_LAYERSHADE_RSPIN, m_RSpin);
DDX_Control(pDX, IDC_LAYERSHADE_R, m_R);
DDX_Control(pDX, IDC_LAYERSHADE_BRUSHSPIN, m_BrushSpin);
DDX_Control(pDX, IDC_LAYERSHADE_BRUSH, m_Brush);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CGUILayerRGB, CDialog)
//{{AFX_MSG_MAP(CGUILayerRGB)
ON_EN_CHANGE(IDC_LAYERSHADE_BRUSH, OnParamChange)
ON_EN_CHANGE(IDC_LAYERSHADE_R, OnParamChange)
ON_EN_CHANGE(IDC_LAYERSHADE_G, OnParamChange)
ON_EN_CHANGE(IDC_LAYERSHADE_B, OnParamChange)
ON_CBN_SELCHANGE(IDC_LAYERSHADE_MODELIST, OnParamChange)
ON_CBN_SELCHANGE(IDC_LAYERSHADE_BRUSHLIST, OnParamChange)
ON_CBN_SELCHANGE(IDC_LAYERSHADE_RATELIST, OnParamChange)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/*
void CGUILayerRGB::SetVal(CEdit &Dlg,int &Val,int Min,int Max)
{
CString Str;
@ -87,6 +80,7 @@ CString Str;
/////////////////////////////////////////////////////////////////////////////
void CGUILayerRGB::SetRGB(u8 &R,u8 &G,u8 &B)
{
int iR,iG,iB;
iR=R;
@ -106,6 +100,7 @@ int iR,iG,iB;
/////////////////////////////////////////////////////////////////////////////
void CGUILayerRGB::GetRGB(u8 &R,u8 &G,u8 &B)
{
int iR,iG,iB;
iR=R;
@ -121,6 +116,6 @@ int iR,iG,iB;
B=iB;
}
*/
/////////////////////////////////////////////////////////////////////////////
void CGUILayerRGB::OnParamChange() {if (CallbackFlag) theApp.GetCurrent()->GUIChanged();}

View File

@ -22,16 +22,10 @@ public:
// Dialog Data
//{{AFX_DATA(CGUILayerRGB)
enum { IDD = IDD_LAYER_RGB };
CComboBox m_RateList;
CComboBox m_BrushList;
CComboBox m_ModeList;
CButton m_Shade;
CSpinButtonCtrl m_BSpin;
CEdit m_B;
CSpinButtonCtrl m_GSpin;
CEdit m_G;
CSpinButtonCtrl m_RSpin;
CEdit m_R;
CSpinButtonCtrl m_BrushSpin;
CEdit m_Brush;
//}}AFX_DATA
@ -47,10 +41,10 @@ public:
void EnableCallback() {CallbackFlag=true;}
void DisableCallback() {CallbackFlag=false;}
void SetVal(CEdit &Dlg,int &Val,int Min=-1,int Max=-1);
void GetVal(CEdit &Dlg,int &Val,int Min=-1,int Max=-1);
void SetRGB(u8 &R,u8 &G,u8 &B);
void GetRGB(u8 &R,u8 &G,u8 &B);
// void SetVal(CEdit &Dlg,int &Val,int Min=-1,int Max=-1);
// void GetVal(CEdit &Dlg,int &Val,int Min=-1,int Max=-1);
// void SetRGB(u8 &R,u8 &G,u8 &B);
// void GetRGB(u8 &R,u8 &G,u8 &B);
protected:
bool CallbackFlag;

View File

@ -8,6 +8,8 @@
#include <gl\gl.h>
#include <gl\glu.h>
#include "GLEnabledView.h"
#include <io.h>
#include <frame.hpp>
#include "MapEdit.h"
#include "MapEditDoc.h"
@ -24,81 +26,11 @@
#include "Elem.h"
/*****************************************************************************/
char *CLayerRGB::RGBModeName[CLayerRGB::GUI_MODE_MAX]={"Paint","Tint","Lighten","Darken"};
char *CLayerRGB::RGBModeName[CLayerRGB::GUI_MODE_MAX]={"Paint","Lighten","Darken"};
float RGBAlpha=0.5f;
int RateInc=5;
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},
};
#define MAX_UNDO 16
/*****************************************************************************/
/*****************************************************************************/
@ -113,10 +45,11 @@ CLayerRGB::CLayerRGB(sLayerDef &Def)
CurrentRGB.B=128;
CurrentMode=0;
CurrentBrush=0;
CurrentRate=0;
ShadeFlag=false;
LastCursPos.x=-1;
LastCursPos.y=-1;
CurrentUndo=0;
}
@ -130,7 +63,9 @@ void CLayerRGB::InitLayer(sLayerDef &Def)
{
CLayer::InitLayer(Def);
SetSize(Def.Width,Def.Height,true);
BuildBrushList();
}
/*****************************************************************************/
void CLayerRGB::Load(CFile *File,int Version)
{
@ -179,6 +114,92 @@ void CLayerRGB::Save(CFile *File)
}
}
/*****************************************************************************/
void CLayerRGB::BuildBrushList()
{
GString Path;
GString Filename;
_finddata_t Find;
long FileHandle;
int Error=0;
BrushList.clear();
GetExecPath(Path);
Path+="\\Brushes\\";
Filename=Path+"*.bmp";
if( (FileHandle= _findfirst( Filename, &Find)) == -1L )
{
ASSERT(!"No Brushes Found :o(\n");
return;
}
while (Error==0)
{
GString ThisFile=Path+Find.name;
LoadBrush(ThisFile);
Error=_findnext( FileHandle, &Find);
}
_findclose( FileHandle);
}
/*****************************************************************************/
void CLayerRGB::LoadBrush(const char *Name)
{
GFName Filename=Name;
int BrushCount=BrushList.size();
BrushList.resize(BrushCount+1);
sRGBBrush &NewBrush=BrushList[BrushCount];
Frame Frm;
int W,H;
NewBrush.Name=Filename.File();
Frm.LoadBMP(Name);
W=Frm.GetWidth();
H=Frm.GetHeight();
NewBrush.W=W;
NewBrush.H=H;
NewBrush.XOfs=W/2;
NewBrush.YOfs=H/2;
NewBrush.Gfx.resize(W*H);
int Ofs=0;
for (int Y=0;Y<H; Y++)
{
for (int X=0;X<W; X++)
{
u8 Col=Frm.GetPixel(X,Y);
Col=Frm.GetPal()[Col].GetR();
NewBrush.Gfx[Ofs++]=Col;
}
}
TRACE1("%s\n",NewBrush.Name);
}
/*****************************************************************************/
bool CLayerRGB::Command(int CmdMsg,CCore *Core,int Param0,int Param1)
{
bool Ret=false;
switch(CmdMsg)
{
case CmdMsg_Undo:
Undo();
break;
default:
break;
}
return(Ret);
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
@ -228,7 +249,7 @@ int DrawH=ZoomH+8;
float fB=(1.0f/255.0f)*ThisElem.B;
glLoadName (0);
glBegin (GL_QUADS);
glColor4f(fR,fG,fB,0.5);
glColor4f(fR,fG,fB,RGBAlpha);
BuildGLQuad(0,1,0,1,0);
glEnd();
}
@ -247,21 +268,24 @@ Vector3 ThisCam=Core->OffsetCam(CamPos,GetScaleFactor());
CPoint CursPos=Core->GetCursorPos();
if (CursPos.x<0 || CursPos.y<0) return;
sRGBBrush &ThisBrush=RGBBrushTable[CurrentBrush];
sRGBBrush &ThisBrush=BrushList[CurrentBrush];
CursPos.x-=ThisBrush.XYOfs;
CursPos.y-=ThisBrush.XYOfs;
CursPos.x-=ThisBrush.XOfs;
CursPos.y-=ThisBrush.YOfs;
CursPos.x-=(int)ThisCam.x;
CursPos.y-=(int)ThisCam.y;
float ZoomW=Core->GetZoomW();
float ZoomH=Core->GetZoomH();
float ScrOfsX=(ZoomW/2);
float ScrOfsY=(ZoomH/2);
Vector3 &Scale=Core->GetScaleVector();
float ShiftX=ThisCam.x - (int)ThisCam.x;
float ShiftY=ThisCam.y - (int)ThisCam.y;
u8 *Gfx=ThisBrush.Gfx;
float ZoomW=Core->GetZoomW();
float ZoomH=Core->GetZoomH();
float ScrOfsX=(ZoomW/2);
float ScrOfsY=(ZoomH/2);
Vector3 &Scale=Core->GetScaleVector();
float ShiftX=ThisCam.x - (int)ThisCam.x;
float ShiftY=ThisCam.y - (int)ThisCam.y;
std::vector<u8> &Gfx=ThisBrush.Gfx;
int Ofs=0;
int Rate=100-(CurrentRate*RateInc);
float fRate=(1.0/100.f)*Rate;
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
@ -271,45 +295,25 @@ u8 *Gfx=ThisBrush.Gfx;
glTranslatef(-ScrOfsX,ScrOfsY,0); // Bring to top left corner
glTranslatef(CursPos.x,-CursPos.y,0); // Bring to top left corner
for (int YLoop=0; YLoop<ThisBrush.WH; YLoop++)
for (int YLoop=0; YLoop<ThisBrush.H; YLoop++)
{
for (int XLoop=0; XLoop<ThisBrush.WH; XLoop++)
for (int XLoop=0; XLoop<ThisBrush.W; XLoop++)
{
u8 B=*Gfx++;
float fR,fG,fB,Bi;
Bi=(1.0f/8.0f)*(float)B;
u8 B=Gfx[Ofs++];
if (B)
{
glLoadName (0);
float fRGB=(1.0f/255.0f)*fRate*B;
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);
glColor4f(fRGB,fRGB,fRGB,RGBAlpha);
BuildGLQuad(0,1,0,1,0);
glEnd();
}
glTranslatef(1.0f,0,0); // Next X
}
glTranslatef(-ThisBrush.WH,-1,0); // Next y, rewind to start X
glTranslatef(-ThisBrush.W,-1,0); // Next y, rewind to start X
}
glPopMatrix();
@ -329,13 +333,27 @@ void CLayerRGB::CheckLayerSize(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);
}
int m,i;
MapWidth=Width;
MapHeight=Height;
Map.resize(Width);
for (i=0;i<Width;i++)
{
Map[i].resize(Height);
}
UndoList.resize(MAX_UNDO);
TRACE1("%i\n",UndoList.size());
for (m=0; m<MAX_UNDO; m++)
{
sRGBUndo &ThisUndo=UndoList[m];
ThisUndo.Valid=false;
ThisUndo.Map.resize(Width);
for (i=0;i<Width;i++)
{
ThisUndo.Map[i].resize(Height);
}
}
if (ClearFlag) Clear();
}
@ -372,21 +390,33 @@ bool CLayerRGB::Resize(int Width,int Height)
void CLayerRGB::GUIInit(CCore *Core)
{
int i;
int ListSize,i;
GUIRGB.DisableCallback();
Core->GUIAdd(GUIRGB,IDD_LAYER_RGB);
// Init BrushList
ListSize=BrushList.size();
GUIRGB.m_BrushList.ResetContent();
for (i=0; i<ListSize; i++)
{
GUIRGB.m_BrushList.AddString(BrushList[i].Name);
}
// Init ModeList
GUIRGB.m_ModeList.ResetContent();
for (i=0; i<GUI_MODE_MAX; i++)
{
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);
// Init RateList
GUIRGB.m_RateList.ResetContent();
for (i=0; i<100/RateInc; i++)
{
char Str[8];
sprintf(Str,"%i%",100-(i*RateInc));
GUIRGB.m_RateList.AddString(Str);
}
GUIRGB.EnableCallback();
Core->RedrawView();
@ -406,11 +436,9 @@ void CLayerRGB::GUIUpdate(CCore *Core)
GUIRGB.DisableCallback();
GUIRGB.m_ModeList.SetCurSel(CurrentMode);
GUIRGB.SetRGB(CurrentRGB.R,CurrentRGB.G,CurrentRGB.B);
GUIRGB.SetVal(GUIRGB.m_Brush,CurrentBrush);
GUIRGB.m_BrushList.SetCurSel(CurrentBrush);
GUIRGB.m_RateList.SetCurSel(CurrentRate);
GUIRGB.m_Shade.SetCheck(ShadeFlag);
GUIRGB.EnableCallback();
}
@ -418,8 +446,8 @@ void CLayerRGB::GUIUpdate(CCore *Core)
void CLayerRGB::GUIChanged(CCore *Core)
{
CurrentMode=GUIRGB.m_ModeList.GetCurSel();
GUIRGB.GetRGB(CurrentRGB.R,CurrentRGB.G,CurrentRGB.B);
GUIRGB.GetVal(GUIRGB.m_Brush,CurrentBrush);
CurrentBrush=GUIRGB.m_BrushList.GetCurSel();
CurrentRate=GUIRGB.m_RateList.GetCurSel();
ShadeFlag=GUIRGB.m_Shade.GetCheck()!=0;
}
@ -431,6 +459,9 @@ bool CLayerRGB::LButtonControl(CCore *Core,UINT nFlags, CPoint &CursorPos,bool D
{
if (DownFlag)
{
if (CursorPos.x<0 || CursorPos.x>MapWidth) return(false);
if (CursorPos.y<0 || CursorPos.y>MapHeight) return(false);
CreateUndo();
Paint(Core,CursorPos);
}
else
@ -458,69 +489,93 @@ bool CLayerRGB::MouseMove(CCore *Core,UINT nFlags, CPoint &CursorPos)
return(true);
}
/*****************************************************************************/
void CLayerRGB::CreateUndo()
{
sRGBUndo &ThisUndo=UndoList[CurrentUndo];
for (int y=0; y<MapHeight; y++)
{
for (int x=0; x<MapWidth; x++)
{
ThisUndo.Map[x][y]=Map[x][y];
}
}
ThisUndo.Valid=true;
CurrentUndo++;
if (CurrentUndo>=MAX_UNDO) CurrentUndo=0;
}
/*****************************************************************************/
void CLayerRGB::Undo()
{
int Idx=CurrentUndo-1;
if (Idx<0) Idx+=MAX_UNDO;
sRGBUndo &ThisUndo=UndoList[Idx];
if (ThisUndo.Valid)
{
CurrentUndo=Idx;
for (int y=0; y<MapHeight; y++)
{
for (int x=0; x<MapWidth; x++)
{
Map[x][y]=ThisUndo.Map[x][y];
}
}
ThisUndo.Valid=false;
}
}
/*****************************************************************************/
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;
sRGBBrush &ThisBrush=BrushList[CurrentBrush];
std::vector<u8> &Gfx=ThisBrush.Gfx;
CPoint CursPos;
int Ofs=0;
CursPos.x=CursorPos.x-ThisBrush.XYOfs;
CursPos.y=CursorPos.y-ThisBrush.XYOfs;
CursPos.x=CursorPos.x-ThisBrush.XOfs;
CursPos.y=CursorPos.y-ThisBrush.YOfs;
for (int Y=0; Y<ThisBrush.WH; Y++)
for (int Y=0; Y<ThisBrush.H; Y++)
{
for (int X=0; X<ThisBrush.WH; X++)
for (int X=0; X<ThisBrush.W; X++)
{
CPoint Pos=CursPos;
Pos.x+=X;
Pos.y+=Y;
int Blk=*Gfx++;
int Blk=Gfx[Ofs++];
if (Blk)
if (Pos.x>=0 && Pos.x<MapWidth &&
Pos.y>=0 && Pos.y<MapHeight)
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;
int RGB;
int Rate=100-(CurrentRate*RateInc);
float fRate=(1.0/100.f)*Rate;
int RGBInc=(int)(fRate*(float)Blk);
switch(CurrentMode)
{
case GUI_MODE_PAINT:
break;
case GUI_MODE_TINT:
R=(MapElem.R+Br);
G=(MapElem.G+Bg);
B=(MapElem.B+Bb);
RGB=RGBInc;
break;
case GUI_MODE_LIGHTEN:
R=MapElem.R+4;
G=MapElem.G+4;
B=MapElem.B+4;
RGB=MapElem.R+RGBInc;
break;
case GUI_MODE_DARKEN:
R=MapElem.R-4;
G=MapElem.G-4;
B=MapElem.B-4;
// RGBInc=255-RGBInc;
RGB=MapElem.R-RGBInc;
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;
if (RGB<0) RGB=0; else if (RGB>255) RGB=255;
Map[Pos.x][Pos.y].R=RGB;
Map[Pos.x][Pos.y].G=RGB;
Map[Pos.x][Pos.y].B=RGB;
}
}
}
@ -530,12 +585,13 @@ CPoint CursPos;
/*****************************************************************************/
void CLayerRGB::Grab(CCore *Core,CPoint &CursorPos)
{
/*
if (CursorPos.x<0 || CursorPos.x>MapWidth) return;
if (CursorPos.y<0 || CursorPos.y>MapHeight) return;
CurrentRGB=Map[CursorPos.x][CursorPos.y];
GUIUpdate(Core);
*/
}
/*****************************************************************************/
void CLayerRGB::Export(CCore *Core,CExport &Exp)

View File

@ -16,6 +16,12 @@ struct sRGBElem
u8 R,G,B;
};
struct sRGBUndo
{
bool Valid;
std::vector< std::vector<sRGBElem> > Map;
};
/*****************************************************************************/
class CCore;
class CLayerRGB : public CLayer
@ -25,22 +31,18 @@ public:
enum
{
GUI_MODE_PAINT=0,
GUI_MODE_TINT,
GUI_MODE_LIGHTEN,
GUI_MODE_DARKEN,
GUI_MODE_MAX
};
enum
{
RGB_BRUSH_MAX=8,
};
struct sRGBBrush
{
int WH;
int XYOfs;
u8 *Gfx;
GString Name;
int W,H;
int XOfs,YOfs;
std::vector<u8> Gfx;
};
@ -78,8 +80,14 @@ virtual void LoadGfx(CCore *Core){}
bool LButtonControl(CCore *Core,UINT nFlags, CPoint &CursorPos,bool DownFlag);
bool RButtonControl(CCore *Core,UINT nFlags, CPoint &CursorPos,bool DownFlag);
bool MouseMove(CCore *Core,UINT nFlags, CPoint &CursorPos);
bool Command(int CmdMsg,CCore *Core,int Param0=0,int Param1=0);
protected:
void BuildBrushList();
void LoadBrush(const char *Name);
void CreateUndo();
void Undo();
void Render(CCore *Core,Vector3 &CamPos,CMap &ThisMap,bool Render3d,float Alpha=1.0f,Vector3 *Ofs=0);
void Paint(CCore *Core,CPoint &CursorPos);
void Grab(CCore *Core,CPoint &CursorPos);
@ -90,15 +98,19 @@ protected:
sRGBElem CurrentRGB;
int CurrentBrush;
int CurrentMode;
int CurrentRate;
bool ShadeFlag;
int CurrentUndo;
int MapWidth,MapHeight;
std::vector< std::vector<sRGBElem> > Map;
std::vector<sRGBBrush> BrushList;
std::vector<sRGBUndo> UndoList;
CPoint LastCursPos;
static char *RGBModeName[GUI_MODE_MAX];
static sRGBBrush RGBBrushTable[CLayerRGB::RGB_BRUSH_MAX];
};

View File

@ -2,7 +2,7 @@
[General Info]
Version=1
LastClass=CGUILayerRGB
LastClass=CMapEditDoc
LastTemplate=CDialog
NewFileInclude1=#include "stdafx.h"
NewFileInclude2=#include "mapedit.h"
@ -37,27 +37,27 @@ Class25=CMapEditDoc
Class26=CMapEditView
ResourceCount=22
Resource1=IDD_LAYER_PLATFORM
Resource2=IDR_TOOLBAR (English (U.S.))
Resource3=IDD_ADDLAYER
Resource4=IDD_LAYER_HAZARD
Resource5=IDD_LAYER_SHADE
Resource6=IDD_ELEMLIST
Resource7=IDD_LAYER_THING_POS
Resource8=IDD_LAYER_ACTOR
Resource9=IDD_LAYER_COLLISION
Resource10=IDR_MAINFRAME (English (U.S.))
Resource11=IDD_MULTIBAR (English (U.S.))
Resource12=IDD_LAYER_THING
Resource13=IDD_TILEBANK
Resource14=IDD_LAYER_FX
Resource15=IDD_NEWMAP
Resource16=IDD_ABOUTBOX (English (U.S.))
Resource1=IDD_ADDLAYER
Resource2=IDD_LAYER_COLLISION
Resource3=IDD_LAYER_FX
Resource4=IDD_LAYER_SHADE
Resource5=IDR_MAINFRAME (English (U.S.))
Resource6=IDD_MULTIBAR (English (U.S.))
Resource7=IDD_NEWMAP
Resource8=IDD_LAYER_LIST
Resource9=IDD_ABOUTBOX (English (U.S.))
Resource10=IDD_ELEMLIST
Resource11=IDD_LAYER_THING
Resource12=IDD_RESIZE
Resource13=IDD_LAYER_HAZARD
Resource14=IDD_TOOLBAR
Resource15=IDD_LAYER_TRIGGER
Resource16=IDD_LAYER_ACTOR
Resource17=IDR_MAPEDITYPE (English (U.S.))
Resource18=IDD_LAYER_TRIGGER
Resource19=IDD_LAYER_LIST
Resource20=IDD_RESIZE
Resource21=IDD_TOOLBAR
Resource18=IDD_TILEBANK
Resource19=IDD_LAYER_THING_POS
Resource20=IDD_LAYER_PLATFORM
Resource21=IDR_TOOLBAR (English (U.S.))
Class27=CGUILayerRGB
Resource22=IDD_LAYER_RGB
@ -207,12 +207,14 @@ Type=0
BaseClass=CMDIFrameWnd
HeaderFile=MainFrm.h
ImplementationFile=MainFrm.cpp
LastObject=CMainFrame
[CLS:CMapEditApp]
Type=0
BaseClass=CWinApp
HeaderFile=MapEdit.h
ImplementationFile=MapEdit.cpp
LastObject=CMapEditApp
[CLS:CAboutDlg]
Type=0
@ -228,7 +230,7 @@ HeaderFile=MapEditDoc.h
ImplementationFile=MapEditDoc.cpp
Filter=N
VirtualFilter=DC
LastObject=ID_REPORT
LastObject=ID_EDIT_UNDO
[CLS:CMapEditView]
Type=0
@ -617,21 +619,13 @@ ControlCount=0
[DLG:IDD_LAYER_RGB]
Type=1
Class=CGUILayerRGB
ControlCount=14
ControlCount=6
Control1=IDC_LAYERSHADE_BRUSHTEXT,static,1342308352
Control2=IDC_LAYERSHADE_BRUSH,edit,1350641792
Control3=IDC_LAYERSHADE_BRUSHSPIN,msctls_updown32,1342177334
Control4=IDC_LAYERSHADE_MODELIST,combobox,1344339971
Control5=IDC_LAYERSHADE_RTEXT,static,1342308352
Control6=IDC_LAYERSHADE_R,edit,1350641792
Control7=IDC_LAYERSHADE_RSPIN,msctls_updown32,1342177334
Control8=IDC_LAYERSHADE_GTEXT,static,1342308352
Control9=IDC_LAYERSHADE_G,edit,1350641792
Control10=IDC_LAYERSHADE_GSPIN,msctls_updown32,1342177334
Control11=IDC_LAYERSHADE_BTEXT,static,1342308352
Control12=IDC_LAYERSHADE_B,edit,1350641792
Control13=IDC_LAYERSHADE_BSPIN,msctls_updown32,1342177334
Control14=IDC_LAYERSHADE_SHADE,button,1342242851
Control2=IDC_LAYERSHADE_MODELIST,combobox,1344339971
Control3=IDC_LAYERSHADE_SHADE,button,1342242851
Control4=IDC_LAYERSHADE_MODETEXT,static,1342308352
Control5=IDC_LAYERSHADE_BRUSHLIST,combobox,1344339971
Control6=IDC_LAYERSHADE_RATELIST,combobox,1344339971
[CLS:CGUILayerRGB]
Type=0
@ -639,6 +633,6 @@ HeaderFile=GUILayerRGB.h
ImplementationFile=GUILayerRGB.cpp
BaseClass=CDialog
Filter=D
LastObject=IDC_LAYERSHADE_MODELIST
LastObject=CGUILayerRGB
VirtualFilter=dWC

View File

@ -884,38 +884,20 @@ BEGIN
UDS_ARROWKEYS,75,70,11,10
END
IDD_LAYER_RGB DIALOG DISCARDABLE 0, 0, 156, 56
IDD_LAYER_RGB DIALOG DISCARDABLE 0, 0, 156, 106
STYLE WS_CHILD
FONT 8, "MS Sans Serif"
BEGIN
LTEXT "Brush",IDC_LAYERSHADE_BRUSHTEXT,10,5,25,10
EDITTEXT IDC_LAYERSHADE_BRUSH,30,5,25,12,ES_AUTOHSCROLL |
ES_READONLY | ES_NUMBER
CONTROL "Spin1",IDC_LAYERSHADE_BRUSHSPIN,"msctls_updown32",
UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY |
UDS_ARROWKEYS,45,0,11,15
COMBOBOX IDC_LAYERSHADE_MODELIST,60,5,90,65,CBS_DROPDOWNLIST |
COMBOBOX IDC_LAYERSHADE_MODELIST,35,20,75,65,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
LTEXT "R",IDC_LAYERSHADE_RTEXT,10,25,15,10
EDITTEXT IDC_LAYERSHADE_R,10,35,30,12,ES_AUTOHSCROLL |
ES_READONLY | ES_NUMBER
CONTROL "Spin1",IDC_LAYERSHADE_RSPIN,"msctls_updown32",
UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY |
UDS_ARROWKEYS,25,30,11,15
LTEXT "G",IDC_LAYERSHADE_GTEXT,45,25,15,10
EDITTEXT IDC_LAYERSHADE_G,45,35,30,12,ES_AUTOHSCROLL |
ES_READONLY | ES_NUMBER
CONTROL "Spin1",IDC_LAYERSHADE_GSPIN,"msctls_updown32",
UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY |
UDS_ARROWKEYS,61,30,11,15
LTEXT "B",IDC_LAYERSHADE_BTEXT,75,25,15,10
EDITTEXT IDC_LAYERSHADE_B,75,35,30,12,ES_AUTOHSCROLL |
ES_READONLY | ES_NUMBER
CONTROL "Spin1",IDC_LAYERSHADE_BSPIN,"msctls_updown32",
UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY |
UDS_ARROWKEYS,91,30,11,15
CONTROL "Shade",IDC_LAYERSHADE_SHADE,"Button",BS_AUTOCHECKBOX |
BS_LEFTTEXT | WS_TABSTOP,105,35,35,10
BS_LEFTTEXT | WS_TABSTOP,5,50,35,10
LTEXT "Mode",IDC_LAYERSHADE_MODETEXT,10,20,20,10
COMBOBOX IDC_LAYERSHADE_BRUSHLIST,35,5,115,65,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
COMBOBOX IDC_LAYERSHADE_RATELIST,110,20,40,65,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
END
@ -1060,7 +1042,7 @@ BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 149
TOPMARGIN, 7
BOTTOMMARGIN, 49
BOTTOMMARGIN, 99
END
END
#endif // APSTUDIO_INVOKED

View File

@ -37,9 +37,10 @@ BEGIN_MESSAGE_MAP(CMapEditDoc, CDocument)
ON_COMMAND(ID_RESET_VIEW, OnResetView)
ON_COMMAND(ID_RENDER_TO_TGA, OnRenderToTga)
ON_COMMAND(ID_ROTATE, OnRotate)
ON_COMMAND(ID_REPORT, OnReport)
ON_COMMAND(ID_TOOLBAR_TILEPALETTE, OnToggleSubView)
ON_COMMAND(ID_TOGGLE_GRID, OnToggleGrid)
ON_COMMAND(ID_REPORT, OnReport)
ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
@ -200,6 +201,8 @@ void CMapEditDoc::OnEditPaste() {Command(CmdMsg_Paste);}
void CMapEditDoc::OnActivebrushLeft() {Command(CmdMsg_ActiveBrushLeft);}
void CMapEditDoc::OnActivebrushRight() {Command(CmdMsg_ActiveBrushRight);}
void CMapEditDoc::OnEditUndo() {Command(CmdMsg_Undo);}
void CMapEditDoc::Command(int CmdMsg,int Param0,int Param1)
{
Core.Command(CmdMsg,Param0,Param1);
@ -305,3 +308,4 @@ void CMapEditDoc::FocusView()

View File

@ -86,6 +86,7 @@ protected:
afx_msg void OnRenderToTga();
afx_msg void OnRotate();
afx_msg void OnReport();
afx_msg void OnEditUndo();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()

View File

@ -213,18 +213,10 @@
#define IDC_LAYERSHADE_GFX_YSPIN 1213
#define IDC_LAYERSHADE_DEF_LIST 1214
#define IDC_LAYERSHADE_BRUSHTEXT 1215
#define IDC_LAYERSHADE_BRUSH 1216
#define IDC_LAYERSHADE_BRUSHSPIN 1217
#define IDC_LAYERSHADE_MODETEXT 1216
#define IDC_LAYERSHADE_MODELIST 1218
#define IDC_LAYERSHADE_RTEXT 1219
#define IDC_LAYERSHADE_R 1220
#define IDC_LAYERSHADE_RSPIN 1221
#define IDC_LAYERSHADE_GTEXT 1222
#define IDC_LAYERSHADE_G 1223
#define IDC_LAYERSHADE_GSPIN 1224
#define IDC_LAYERSHADE_BTEXT 1225
#define IDC_LAYERSHADE_B 1226
#define IDC_LAYERSHADE_BSPIN 1227
#define IDC_LAYERSHADE_BRUSHLIST 1219
#define IDC_LAYERSHADE_RATELIST 1220
#define IDC_LAYERSHADE_SHADE 1229
#define ID_TOOLBAR_TILEPALETTE 32774
#define ID_TOOLBAR_PARAMBAR 32783

View File

@ -530,9 +530,8 @@ sBmp NewBmp;
NewBmp.Psx=0;
CheckAndShrinkFrame(NewBmp,ThisFrame.Filename);
ThisFrame.XOfs=NewBmp.CrossHairX;
ThisFrame.YOfs=NewBmp.CrossHairY;
ThisFrame.XOfs=-80;
ThisFrame.YOfs=-80;
// Check Dups
int Idx=FindDup(NewBmp);
@ -540,21 +539,67 @@ int Idx=FindDup(NewBmp);
{
DupCount++;
ThisFrame.FrameIdx=Idx;
sBmp &DupBmp=BmpList[Idx];
ThisFrame.XOfs=DupBmp.CrossHairX;
ThisFrame.YOfs=DupBmp.CrossHairY;
return;
}
// Adjust HotSpot for aspect
// int NXO=(int)(((float)NewBmp.CrossHairX*Aspect));//+(StepX/2));
// NewBmp.CrossHairX=NXO;
float hx=NewBmp.CrossHairX;
float StepX=Aspect;
hx*=StepX;
// float IncX=(float)NewX;
// IncX/=OldX;
// hx+=IncX/2;
/*
float IncX=(float)NewBmp.Frm.GetWidth()*Aspect;
IncX/=(float)NewBmp.CrossHairX;//.NewBmp.Frm.GetWidth();
hx-=IncX;
printf("%i \n",(int)IncX);
*/
int NX=NewBmp.CrossHairX-(int)hx;
// NewBmp.CrossHairX=(int)hx;
// NewBmp.CrossHairX-=NX/2;
/*
float StepX=(float)NewX;
float StepY=(float)NewY;
StepX/=OldX;
StepY/=OldY;
hx*=StepX;
hy*=StepY;
float IncX=(float)NewX;
IncX/=OldX;
hx+=IncX/2;
float IncY=(float)NewY;
IncY/=OldY;
hy+=IncY/2;
*/
// Its unique, add to list
BmpList.push_back(NewBmp);
MakePsxGfx(BmpList[BmpListSize]);
ThisFrame.FrameIdx=BmpListSize;
// copy XY Info
ThisFrame.XOfs=NewBmp.CrossHairX;
ThisFrame.YOfs=NewBmp.CrossHairY;
#if _DEBUG && defined(OutputTGA)
void WriteTGA(GString Name,Frame Frm);
WriteTGA(Name,NewBmp.Frm);
#endif
ThisFrame.FrameIdx=BmpListSize;
}
//***************************************************************************
void WriteTGA(GString Name,Frame Frm)
{
@ -755,8 +800,18 @@ vector<sSpriteFrameGfx> Hdrs;
int X0=dW/2;
int X1=dW-X0;
Hdrs[i].AspectX0=X0;
Hdrs[i].AspectX1=X1;
int W=ThisBmp.Frm.GetWidth();
int W0=W+ThisBmp.CrossHairX;
int W1=W-W0;
// printf("%i %i %i \n",W,W0,W1);
X0=W0*Aspect;
X1=W1*Aspect;
Hdrs[i].AspectX0=X0-W0;
Hdrs[i].AspectX1=X1-W1;
// printf("%i %i %i\n",Hdrs[i].W,X0,X1);
fwrite(ThisBmp.Pak,1,ThisBmp.PakSize,File);
}

View File

@ -50,6 +50,80 @@ sRGBCol *RGB=(sRGBCol*)iPtr;
/*** Pre-Process *************************************************************/
/*****************************************************************************/
/*****************************************************************************/
#define NUM_OF_PAL_ENTRIES 256
#include <tquant.h>
void CMkLevelLayerRGB::PreProcess(CMkLevel *Core)
{
int Size=Width*Height;
int X,Y,Ofs;
vector<u8> SourcePal;
vector<u8> DestPal;
vector<u8> RemapMap;
SourcePal.resize(Width*Height*3);
RemapMap.resize(Width*Height);
DestPal.resize(NUM_OF_PAL_ENTRIES*3);
Ofs=0;
for (Y=0; Y<Height; Y++)
{
for (X=0; X<Width; X++)
{
sRGBElem &ThisElem=RGBMap.Get(X,Y);
SourcePal[Ofs++]=ThisElem.RGB.R;
SourcePal[Ofs++]=ThisElem.RGB.G;
SourcePal[Ofs++]=ThisElem.RGB.B;
}
}
tquant(&SourcePal[0],&RemapMap[0],&DestPal[0],NUM_OF_PAL_ENTRIES,Width*Height);
// Build Out Map And get max color
int ColorCount=0;
OutMap.SetSize(Width,Height);
Ofs=0;
for (Y=0; Y<Height; Y++)
{
for (X=0; X<Width; X++)
{
sRGBElem &ThisElem=RGBMap.Get(X,Y);
u8 Idx=RemapMap[Ofs++];
OutMap.Set(X,Y,Idx);
if (ColorCount<Idx) ColorCount=Idx;
// if (ThisElem.RGB.R!=DestPal[(Idx*3)+0] || ThisElem.RGB.G!=DestPal[(Idx*3)+1] || ThisElem.RGB.B!=DestPal[(Idx*3)+2]) printf("%3d %3d %3d -> %3d %3d %3d\n",ThisElem.RGB.R,ThisElem.RGB.G,ThisElem.RGB.B,DestPal[(Idx*3)+0],DestPal[(Idx*3)+1],DestPal[(Idx*3)+2]);
}
}
ColorCount++;
printf("RGB remapped to %i colors\n",ColorCount);
// Build Out RGB Table
OutRGBTable.SetSize(ColorCount,16);
int RGBInc=6;
if (ShadeFlag) RGBInc=-6;
for (int c=0;c<ColorCount;c++)
{
int R=DestPal[(c*3)+0];
int G=DestPal[(c*3)+1];
int B=DestPal[(c*3)+2];
for (int s=0; s<16; s++)
{
sRGBCol RGB;
RGB.R=R; RGB.G=G; RGB.B=B;
OutRGBTable.Set(c,s,RGB);
R+=RGBInc;
G+=RGBInc;
B+=RGBInc;
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;
}
}
}
#if 0
void CMkLevelLayerRGB::PreProcess(CMkLevel *Core)
{
int X,Y;
@ -157,8 +231,18 @@ int CVal=0;
for (int i=0; i<256; i++)
{
int ThisVal=(SortRGBList[i].RGB.R*SortRGBList[i].RGB.R)+ (SortRGBList[i].RGB.G*SortRGBList[i].RGB.G)+(SortRGBList[i].RGB.B*SortRGBList[i].RGB.B);
sRGBCol &ListRGB=SortRGBList[i].RGB;
int Dr=abs(ListRGB.R-RGB.R);
int Dg=abs(ListRGB.G-RGB.G);
int Db=abs(ListRGB.B-RGB.B);
/*
int ThisVal=(SortRGBList[i].RGB.R*SortRGBList[i].RGB.R)+
(SortRGBList[i].RGB.G*SortRGBList[i].RGB.G)+
(SortRGBList[i].RGB.B*SortRGBList[i].RGB.B);
*/
int ThisVal=Dr+Dg+Db;
if (CIdx==-1 || ThisVal<CVal)
{
CIdx=i;
@ -169,6 +253,7 @@ int CVal=0;
}
#endif
/*****************************************************************************/
/*****************************************************************************/
/*** Process *****************************************************************/

View File

@ -38,9 +38,9 @@ protected:
int FindClosestRGB(sRGBCol const &RGB);
CList2d<sRGBElem> RGBMap;
CList<sRGBList> InRGBList;
CList<sRGBList> SortRGBList;
CList<int> RemapTable;
// CList<sRGBList> InRGBList;
// CList<sRGBList> SortRGBList;
// CList<int> RemapTable;
int ShadeFlag;
CList2d<u8> OutMap;