SBSPSS/Utils/MapEdit/LayerRGB.cpp

757 lines
18 KiB
C++
Raw Normal View History

2001-07-28 18:33:48 +02:00
/*****************/
/*** Layer RGB ***/
/*****************/
2001-07-26 22:16:11 +02:00
#include "stdafx.h"
#include <Vector3.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include "GLEnabledView.h"
2001-08-02 14:42:38 +02:00
#include <io.h>
#include <frame.hpp>
2001-07-26 22:16:11 +02:00
#include "MapEdit.h"
#include "MapEditDoc.h"
#include "MapEditView.h"
#include "MainFrm.h"
#include "Core.h"
#include "Layer.h"
2001-07-28 18:33:48 +02:00
#include "LayerRGB.h"
2001-07-26 22:16:11 +02:00
#include "Utils.h"
#include "Select.h"
#include "Export.h"
2001-07-28 18:33:48 +02:00
#include "GUILayerRGB.h"
2001-07-26 22:16:11 +02:00
#include "Elem.h"
2001-07-28 18:33:48 +02:00
/*****************************************************************************/
2001-08-02 14:42:38 +02:00
char *CLayerRGB::RGBModeName[CLayerRGB::GUI_MODE_MAX]={"Paint","Lighten","Darken"};
float RGBAlpha=0.5f;
int RateInc=5;
2001-07-28 18:33:48 +02:00
2001-08-02 14:42:38 +02:00
#define MAX_UNDO 16
2001-07-26 22:16:11 +02:00
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
// New Layer
2001-07-28 18:33:48 +02:00
CLayerRGB::CLayerRGB(sLayerDef &Def)
2001-07-26 22:16:11 +02:00
{
InitLayer(Def);
2001-08-02 20:45:20 +02:00
ShadeRGB.R=224;
ShadeRGB.G=224;
ShadeRGB.B=224;
2001-07-28 18:33:48 +02:00
CurrentMode=0;
CurrentBrush=0;
2001-08-02 14:42:38 +02:00
CurrentRate=0;
2001-07-28 18:33:48 +02:00
LastCursPos.x=-1;
LastCursPos.y=-1;
2001-08-02 14:42:38 +02:00
CurrentUndo=0;
2001-07-26 22:16:11 +02:00
}
2001-07-28 18:33:48 +02:00
2001-07-26 22:16:11 +02:00
/*****************************************************************************/
2001-07-28 18:33:48 +02:00
CLayerRGB::~CLayerRGB()
2001-07-26 22:16:11 +02:00
{
}
/*****************************************************************************/
2001-07-28 18:33:48 +02:00
void CLayerRGB::InitLayer(sLayerDef &Def)
2001-07-26 22:16:11 +02:00
{
CLayer::InitLayer(Def);
2001-07-28 18:33:48 +02:00
SetSize(Def.Width,Def.Height,true);
2001-08-02 14:42:38 +02:00
BuildBrushList();
2001-07-26 22:16:11 +02:00
}
2001-08-02 14:42:38 +02:00
2001-07-26 22:16:11 +02:00
/*****************************************************************************/
2001-07-28 18:33:48 +02:00
void CLayerRGB::Load(CFile *File,int Version)
2001-07-26 22:16:11 +02:00
{
InitLayer(LayerDef);
2001-08-02 20:45:20 +02:00
File->Read(&ShadeRGB,sizeof(sRGBElem));
2001-07-28 18:33:48 +02:00
File->Read(&CurrentBrush,sizeof(int));
File->Read(&CurrentMode,sizeof(int));
2001-08-02 20:45:20 +02:00
File->Read(&SpareFlag,sizeof(bool));
2001-07-26 22:16:11 +02:00
2001-07-28 18:33:48 +02:00
// Read Map
File->Read(&MapWidth,sizeof(int));
File->Read(&MapHeight,sizeof(int));
SetSize(MapWidth,MapHeight,false);
for (int Y=0; Y<MapHeight; Y++)
2001-07-26 22:16:11 +02:00
{
2001-07-28 18:33:48 +02:00
for (int X=0; X<MapWidth; X++)
2001-07-26 22:16:11 +02:00
{
2001-07-28 18:33:48 +02:00
sRGBElem &ThisElem=Map[X][Y];
2001-07-26 22:16:11 +02:00
2001-07-28 18:33:48 +02:00
File->Read(&ThisElem,sizeof(sRGBElem));
}
2001-07-26 22:16:11 +02:00
}
}
/*****************************************************************************/
2001-07-28 18:33:48 +02:00
void CLayerRGB::Save(CFile *File)
2001-07-26 22:16:11 +02:00
{
// Always Save current version
2001-08-02 20:45:20 +02:00
File->Write(&ShadeRGB,sizeof(sRGBElem));
2001-07-28 18:33:48 +02:00
File->Write(&CurrentBrush,sizeof(int));
File->Write(&CurrentMode,sizeof(int));
2001-08-02 20:45:20 +02:00
File->Write(&SpareFlag,sizeof(bool));
2001-07-28 18:33:48 +02:00
// Read Map
File->Write(&MapWidth,sizeof(int));
File->Write(&MapHeight,sizeof(int));
for (int Y=0; Y<MapHeight; Y++)
2001-07-26 22:16:11 +02:00
{
2001-07-28 18:33:48 +02:00
for (int X=0; X<MapWidth; X++)
{
sRGBElem &ThisElem=Map[X][Y];
2001-07-26 22:16:11 +02:00
2001-07-28 18:33:48 +02:00
File->Write(&ThisElem,sizeof(sRGBElem));
}
}
2001-07-26 22:16:11 +02:00
}
2001-08-02 14:42:38 +02:00
/*****************************************************************************/
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;
2001-08-02 20:45:20 +02:00
case CmdMsg_Filter:
CreateUndo();
if (Param0==0) BiFilter(Core);
if (Param0==1) TriFilter(Core);
if (Param0==2) STriFilter(Core);
break;
2001-08-02 14:42:38 +02:00
default:
break;
}
return(Ret);
}
2001-07-26 22:16:11 +02:00
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
2001-07-28 18:33:48 +02:00
void CLayerRGB::Render(CCore *Core,Vector3 &CamPos,bool Is3d)
2001-07-26 22:16:11 +02:00
{
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-07-28 18:33:48 +02:00
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();
if (StartX<0) StartX=0;
if (StartY<0) StartY=0;
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++)
{
for (int XLoop=0; XLoop<DrawW; XLoop++)
2001-07-26 22:16:11 +02:00
{
2001-07-28 18:33:48 +02:00
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);
2001-08-02 14:42:38 +02:00
glColor4f(fR,fG,fB,RGBAlpha);
2001-07-28 18:33:48 +02:00
BuildGLQuad(0,1,0,1,0);
glEnd();
}
glTranslatef(1.0f,0,0); // Next X
2001-07-26 22:16:11 +02:00
}
2001-07-28 18:33:48 +02:00
glTranslatef(-DrawW,-1,0); // Next y, rewind to start X
2001-07-26 22:16:11 +02:00
}
2001-07-28 18:33:48 +02:00
glPopMatrix();
2001-07-26 22:16:11 +02:00
}
/*****************************************************************************/
2001-07-28 18:33:48 +02:00
void CLayerRGB::RenderCursor(CCore *Core,Vector3 &CamPos,bool Is3d)
2001-07-26 22:16:11 +02:00
{
Vector3 ThisCam=Core->OffsetCam(CamPos,GetScaleFactor());
2001-07-28 18:33:48 +02:00
CPoint CursPos=Core->GetCursorPos();
2001-07-26 22:16:11 +02:00
2001-07-28 18:33:48 +02:00
if (CursPos.x<0 || CursPos.y<0) return;
2001-08-02 14:42:38 +02:00
sRGBBrush &ThisBrush=BrushList[CurrentBrush];
2001-07-28 18:33:48 +02:00
2001-08-02 14:42:38 +02:00
CursPos.x-=ThisBrush.XOfs;
CursPos.y-=ThisBrush.YOfs;
2001-07-28 18:33:48 +02:00
CursPos.x-=(int)ThisCam.x;
CursPos.y-=(int)ThisCam.y;
2001-07-26 22:16:11 +02:00
2001-08-02 14:42:38 +02:00
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;
2001-07-28 18:33:48 +02:00
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
2001-08-02 14:42:38 +02:00
for (int YLoop=0; YLoop<ThisBrush.H; YLoop++)
2001-07-28 18:33:48 +02:00
{
2001-08-02 14:42:38 +02:00
for (int XLoop=0; XLoop<ThisBrush.W; XLoop++)
2001-07-28 18:33:48 +02:00
{
2001-08-02 14:42:38 +02:00
u8 B=Gfx[Ofs++];
2001-07-28 18:33:48 +02:00
if (B)
{
2001-08-02 14:42:38 +02:00
float fRGB=(1.0f/255.0f)*fRate*B;
2001-07-28 18:33:48 +02:00
glBegin (GL_QUADS);
2001-08-02 14:42:38 +02:00
glColor4f(fRGB,fRGB,fRGB,RGBAlpha);
2001-07-28 18:33:48 +02:00
BuildGLQuad(0,1,0,1,0);
glEnd();
}
glTranslatef(1.0f,0,0); // Next X
}
2001-08-02 14:42:38 +02:00
glTranslatef(-ThisBrush.W,-1,0); // Next y, rewind to start X
2001-07-28 18:33:48 +02:00
}
glPopMatrix();
2001-07-26 22:16:11 +02:00
}
/*****************************************************************************/
2001-07-28 18:33:48 +02:00
void CLayerRGB::CheckLayerSize(int Width,int Height)
2001-07-26 22:16:11 +02:00
{
if (Resize(Width,Height))
{
CString mexstr;
mexstr.Format("%s Layer Resized to Correct Size\nPlease re-save\n", GetName());
AfxMessageBox(mexstr,MB_OK | MB_ICONEXCLAMATION);
}
}
/*****************************************************************************/
2001-07-28 18:33:48 +02:00
void CLayerRGB::SetSize(int Width,int Height,BOOL ClearFlag)
2001-07-26 22:16:11 +02:00
{
2001-08-02 14:42:38 +02:00
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);
}
}
2001-07-28 18:33:48 +02:00
if (ClearFlag) Clear();
}
2001-07-26 22:16:11 +02:00
2001-07-28 18:33:48 +02:00
/*****************************************************************************/
void CLayerRGB::Clear()
{
for (int Y=0;Y<MapHeight;Y++)
2001-07-26 22:16:11 +02:00
{
2001-07-28 18:33:48 +02:00
for (int X=0;X<MapWidth;X++)
{
Map[X][Y].R=128;
Map[X][Y].G=128;
Map[X][Y].B=128;
}
2001-07-26 22:16:11 +02:00
}
2001-07-28 18:33:48 +02:00
}
2001-07-26 22:16:11 +02:00
2001-07-28 18:33:48 +02:00
/*****************************************************************************/
bool CLayerRGB::Resize(int Width,int Height)
{
if (MapWidth!= Width || MapHeight!=Height)
{
SetSize(Width,Height,true);
return(true);
}
2001-07-26 22:16:11 +02:00
return(false);
}
/*****************************************************************************/
/*** Gui *********************************************************************/
/*****************************************************************************/
2001-07-28 18:33:48 +02:00
void CLayerRGB::GUIInit(CCore *Core)
2001-07-26 22:16:11 +02:00
{
2001-08-02 14:42:38 +02:00
int ListSize,i;
2001-07-28 18:33:48 +02:00
GUIRGB.DisableCallback();
Core->GUIAdd(GUIRGB,IDD_LAYER_RGB);
2001-07-26 22:16:11 +02:00
2001-08-02 14:42:38 +02:00
// Init BrushList
ListSize=BrushList.size();
GUIRGB.m_BrushList.ResetContent();
for (i=0; i<ListSize; i++)
{
GUIRGB.m_BrushList.AddString(BrushList[i].Name);
}
2001-07-28 18:33:48 +02:00
// Init ModeList
GUIRGB.m_ModeList.ResetContent();
for (i=0; i<GUI_MODE_MAX; i++)
2001-07-26 22:16:11 +02:00
{
2001-07-28 18:33:48 +02:00
GUIRGB.m_ModeList.AddString(RGBModeName[i]);
2001-07-26 22:16:11 +02:00
}
2001-08-02 14:42:38 +02:00
// 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);
}
2001-07-26 22:16:11 +02:00
2001-08-02 20:45:20 +02:00
GUIRGB.m_RSpin.SetRange(0,255);
GUIRGB.m_GSpin.SetRange(0,255);
GUIRGB.m_BSpin.SetRange(0,255);
2001-07-28 18:33:48 +02:00
GUIRGB.EnableCallback();
2001-07-26 22:16:11 +02:00
Core->RedrawView();
}
/*****************************************************************************/
2001-07-28 18:33:48 +02:00
void CLayerRGB::GUIKill(CCore *Core)
2001-07-26 22:16:11 +02:00
{
2001-07-28 18:33:48 +02:00
2001-07-26 22:16:11 +02:00
GUIChanged(Core);
2001-07-28 18:33:48 +02:00
Core->GUIRemove(GUIRGB,IDD_LAYER_RGB);
2001-07-26 22:16:11 +02:00
}
/*****************************************************************************/
2001-07-28 18:33:48 +02:00
void CLayerRGB::GUIUpdate(CCore *Core)
2001-07-26 22:16:11 +02:00
{
2001-07-28 18:33:48 +02:00
GUIRGB.DisableCallback();
2001-07-26 22:16:11 +02:00
2001-07-28 18:33:48 +02:00
GUIRGB.m_ModeList.SetCurSel(CurrentMode);
2001-08-02 14:42:38 +02:00
GUIRGB.m_BrushList.SetCurSel(CurrentBrush);
GUIRGB.m_RateList.SetCurSel(CurrentRate);
2001-08-02 20:45:20 +02:00
GUIRGB.SetRGB(ShadeRGB.R,ShadeRGB.G,ShadeRGB.B);
2001-07-28 18:33:48 +02:00
GUIRGB.EnableCallback();
2001-07-26 22:16:11 +02:00
}
/*****************************************************************************/
2001-07-28 18:33:48 +02:00
void CLayerRGB::GUIChanged(CCore *Core)
2001-07-26 22:16:11 +02:00
{
2001-07-28 18:33:48 +02:00
CurrentMode=GUIRGB.m_ModeList.GetCurSel();
2001-08-02 14:42:38 +02:00
CurrentBrush=GUIRGB.m_BrushList.GetCurSel();
CurrentRate=GUIRGB.m_RateList.GetCurSel();
2001-08-02 20:45:20 +02:00
GUIRGB.GetRGB(ShadeRGB.R,ShadeRGB.G,ShadeRGB.B);
2001-07-26 22:16:11 +02:00
}
/*****************************************************************************/
/*** Functions ***************************************************************/
/*****************************************************************************/
2001-07-28 18:33:48 +02:00
bool CLayerRGB::LButtonControl(CCore *Core,UINT nFlags, CPoint &CursorPos,bool DownFlag)
2001-07-26 22:16:11 +02:00
{
2001-07-28 18:33:48 +02:00
if (DownFlag)
{
2001-08-02 14:42:38 +02:00
if (CursorPos.x<0 || CursorPos.x>MapWidth) return(false);
if (CursorPos.y<0 || CursorPos.y>MapHeight) return(false);
CreateUndo();
2001-07-28 18:33:48 +02:00
Paint(Core,CursorPos);
}
else
{
LastCursPos.x=-1;
LastCursPos.y=-1;
}
2001-07-26 22:16:11 +02:00
return(true);
}
/*****************************************************************************/
2001-07-28 18:33:48 +02:00
bool CLayerRGB::RButtonControl(CCore *Core,UINT nFlags, CPoint &CursorPos,bool DownFlag)
2001-07-26 22:16:11 +02:00
{
2001-07-28 18:33:48 +02:00
if (DownFlag) Grab(Core,CursorPos);
2001-07-26 22:16:11 +02:00
return(true);
}
/*****************************************************************************/
2001-07-28 18:33:48 +02:00
bool CLayerRGB::MouseMove(CCore *Core,UINT nFlags, CPoint &CursorPos)
2001-07-26 22:16:11 +02:00
{
2001-07-28 18:33:48 +02:00
if (nFlags & MK_LBUTTON)
{
Paint(Core,CursorPos);
}
2001-07-26 22:16:11 +02:00
return(true);
}
2001-08-02 14:42:38 +02:00
/*****************************************************************************/
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;
}
}
2001-07-26 22:16:11 +02:00
/*****************************************************************************/
2001-07-28 18:33:48 +02:00
void CLayerRGB::Paint(CCore *Core,CPoint &CursorPos)
2001-07-26 22:16:11 +02:00
{
2001-07-28 18:33:48 +02:00
if (CursorPos.x== LastCursPos.x && CursorPos.y==LastCursPos.y) return;
LastCursPos=CursorPos;
2001-07-26 22:16:11 +02:00
2001-08-02 14:42:38 +02:00
sRGBBrush &ThisBrush=BrushList[CurrentBrush];
std::vector<u8> &Gfx=ThisBrush.Gfx;
2001-07-28 18:33:48 +02:00
CPoint CursPos;
2001-08-02 14:42:38 +02:00
int Ofs=0;
2001-07-26 22:16:11 +02:00
2001-08-02 14:42:38 +02:00
CursPos.x=CursorPos.x-ThisBrush.XOfs;
CursPos.y=CursorPos.y-ThisBrush.YOfs;
2001-07-26 22:16:11 +02:00
2001-08-02 14:42:38 +02:00
for (int Y=0; Y<ThisBrush.H; Y++)
2001-07-28 18:33:48 +02:00
{
2001-08-02 14:42:38 +02:00
for (int X=0; X<ThisBrush.W; X++)
2001-07-28 18:33:48 +02:00
{
CPoint Pos=CursPos;
Pos.x+=X;
Pos.y+=Y;
2001-08-02 14:42:38 +02:00
int Blk=Gfx[Ofs++];
2001-07-28 18:33:48 +02:00
if (Blk)
2001-08-02 14:42:38 +02:00
if (Pos.x>=0 && Pos.x<MapWidth && Pos.y>=0 && Pos.y<MapHeight)
2001-07-28 18:33:48 +02:00
{
sRGBElem MapElem=GetRGB(Pos.x,Pos.y);
2001-08-02 14:42:38 +02:00
int RGB;
int Rate=100-(CurrentRate*RateInc);
float fRate=(1.0/100.f)*Rate;
int RGBInc=(int)(fRate*(float)Blk);
2001-07-28 18:33:48 +02:00
switch(CurrentMode)
{
case GUI_MODE_PAINT:
2001-08-02 14:42:38 +02:00
RGB=RGBInc;
2001-07-28 18:33:48 +02:00
break;
case GUI_MODE_LIGHTEN:
2001-08-02 14:42:38 +02:00
RGB=MapElem.R+RGBInc;
2001-07-28 18:33:48 +02:00
break;
case GUI_MODE_DARKEN:
2001-08-02 14:42:38 +02:00
RGB=MapElem.R-RGBInc;
2001-07-28 18:33:48 +02:00
break;
}
2001-08-02 14:42:38 +02:00
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;
2001-07-28 18:33:48 +02:00
}
}
}
2001-07-26 22:16:11 +02:00
}
/*****************************************************************************/
2001-07-28 18:33:48 +02:00
void CLayerRGB::Grab(CCore *Core,CPoint &CursorPos)
2001-07-26 22:16:11 +02:00
{
2001-08-02 14:42:38 +02:00
/*
2001-07-28 18:33:48 +02:00
if (CursorPos.x<0 || CursorPos.x>MapWidth) return;
if (CursorPos.y<0 || CursorPos.y>MapHeight) return;
2001-07-26 22:16:11 +02:00
2001-07-28 18:33:48 +02:00
CurrentRGB=Map[CursorPos.x][CursorPos.y];
2001-07-26 22:16:11 +02:00
GUIUpdate(Core);
2001-08-02 14:42:38 +02:00
*/
2001-07-26 22:16:11 +02:00
}
2001-08-02 20:45:20 +02:00
/*****************************************************************************/
void CLayerRGB::BiFilter(CCore *Core)
{
for(int Y=0;Y<MapHeight; Y++)
{
for(int X=0; X<MapWidth; X++)
{
int SCol=0,SCount=0;
// *p=(( (*p) + ( ( *(p+1)+*(p-1)+*(p-WIDTH)+*(p+WIDTH) ) >>2 ) )>>1);
GetFilterCol(Core,X-1,Y+0,SCol,SCount);
GetFilterCol(Core,X+1,Y+0,SCol,SCount);
GetFilterCol(Core,X+0,Y-1,SCol,SCount);
GetFilterCol(Core,X+0,Y+1,SCol,SCount);
if (SCount)
{
SCol/=SCount;
SetFilterCol(Core,X,Y,SCol,2);
}
}
}
}
/*****************************************************************************/
void CLayerRGB::TriFilter(CCore *Core)
{
for(int Y=0;Y<MapHeight; Y++)
{
for(int X=0; X<MapWidth; X++)
{
int SCol=0,SCount=0;
// *p=(( (*p) + ( (*(p+1)+*(p-1)+*(p-WIDTH)+*(p+WIDTH)+*(p-WIDTH-1)+*(p-WIDTH+1)+*(p+WIDTH-1)+*(p+WIDTH+1)) >>3 ) )>>1);
GetFilterCol(Core,X-1,Y-1,SCol,SCount);
GetFilterCol(Core,X+0,Y-1,SCol,SCount);
GetFilterCol(Core,X+1,Y-1,SCol,SCount);
GetFilterCol(Core,X-1,Y+0,SCol,SCount);
GetFilterCol(Core,X+1,Y+0,SCol,SCount);
GetFilterCol(Core,X-1,Y+1,SCol,SCount);
GetFilterCol(Core,X+0,Y+1,SCol,SCount);
GetFilterCol(Core,X+1,Y+1,SCol,SCount);
if (SCount)
{
SCol/=SCount;
SetFilterCol(Core,X,Y,SCol,2);
}
}
}
}
/*****************************************************************************/
void CLayerRGB::STriFilter(CCore *Core)
{
for(int Y=0;Y<MapHeight; Y++)
{
for(int X=0; X<MapWidth; X++)
{
int SCol=0,SCount=0;
// c=(( (*p) + ( (*(p+1)+*(p-1)+*(p-WIDTH)+*(p+WIDTH)+*(p-WIDTH-1)+*(p-WIDTH+1)+*(p+WIDTH-1)+*(p+WIDTH+1)) >>3 ) )>>1);
// *(p-WIDTH-1)=c;
// *(p-WIDTH+1)=c;
// *(p+WIDTH-1)=c;
// *(p+WIDTH+1)=c;
GetFilterCol(Core,X-1,Y-1,SCol,SCount);
GetFilterCol(Core,X+0,Y-1,SCol,SCount);
GetFilterCol(Core,X+1,Y-1,SCol,SCount);
GetFilterCol(Core,X-1,Y+0,SCol,SCount);
GetFilterCol(Core,X+1,Y+0,SCol,SCount);
GetFilterCol(Core,X-1,Y+1,SCol,SCount);
GetFilterCol(Core,X+0,Y+1,SCol,SCount);
GetFilterCol(Core,X+1,Y+1,SCol,SCount);
if (SCount)
{
SCol/=SCount;
SetFilterCol(Core,X-1,Y-1,SCol,1);
SetFilterCol(Core,X+1,Y-1,SCol,1);
SetFilterCol(Core,X-1,Y+1,SCol,1);
SetFilterCol(Core,X+1,Y+1,SCol,1);
}
}
}
}
/*****************************************************************************/
void CLayerRGB::GetFilterCol(CCore *Core,int X,int Y,int &SumCol,int &Count)
{
CLayerTile *ActionLayer=(CLayerTile*)Core->GetActionLayer();
if (X>=0 && X<MapWidth && Y>=0 && Y<MapHeight)
{
sMapElem &MapElem=ActionLayer->GetMapElem(X,Y);
if (MapElem.Tile)
{
sRGBElem &C=Map[X][Y];
SumCol+=C.R;
Count++;
}
}
}
/*****************************************************************************/
void CLayerRGB::SetFilterCol(CCore *Core,int X,int Y,int Col,int Div)
{
CLayerTile *ActionLayer=(CLayerTile*)Core->GetActionLayer();
if (X>=0 && X<MapWidth && Y>=0 && Y<MapHeight)
{
sMapElem &MapElem=ActionLayer->GetMapElem(X,Y);
if (MapElem.Tile)
{
sRGBElem &ThisElem=Map[X][Y];
Col+=ThisElem.R;
if (Div) Col/=Div;
ThisElem.R=Col;
ThisElem.G=Col;
ThisElem.B=Col;
}
}
}
2001-07-26 22:16:11 +02:00
/*****************************************************************************/
2001-07-28 18:33:48 +02:00
void CLayerRGB::Export(CCore *Core,CExport &Exp)
2001-07-26 22:16:11 +02:00
{
2001-08-02 20:45:20 +02:00
sRGBCol RGB;
2001-07-28 18:33:48 +02:00
Exp.ExportLayerHeader(LayerDef);//LAYER_TYPE_RGB,LayerDef.SubType,LayerDef.Width,LayerDef.Height);
2001-08-02 20:45:20 +02:00
RGB.R=ShadeRGB.R;
RGB.G=ShadeRGB.G;
RGB.B=ShadeRGB.B;
Exp.Write(&RGB,sizeof(sRGBCol));
2001-07-26 22:16:11 +02:00
2001-07-28 18:33:48 +02:00
for (int Y=0; Y<MapHeight; Y++)
2001-07-26 22:16:11 +02:00
{
2001-07-28 18:33:48 +02:00
for (int X=0; X<MapWidth; X++)
{
sRGBElem &ThisElem=Map[X][Y];
2001-07-26 22:16:11 +02:00
2001-07-28 18:33:48 +02:00
RGB.R=ThisElem.R;
RGB.G=ThisElem.G;
RGB.B=ThisElem.B;
2001-07-26 22:16:11 +02:00
2001-07-28 18:33:48 +02:00
Exp.Write(&RGB,sizeof(sRGBCol));
}
2001-07-26 22:16:11 +02:00
}
}