📄 texditor.cpp
字号:
// texditor.cpp : Defines the entry point for the application.
//
#include "stdio.h"
#include "stdlib.h"
#include <string.h>
#include <stdarg.h>
#include <math.h>
#include <windows.h>
#include <conio.h>
#include <gl\gl.h> // Header File For The OPenGL32 Library
#include <gl\glu.h> // Header File For The GLu32 Library
#include <gl\glaux.h> // Header File For The GLu32 Library
#include "..\SYSTEMIO.h"
#include "..\MainNeHe.h" // Header File For The NeHeGL Basecode
#include <stdio.h>
#include "stdafx.h"
#include <stdarg.h>
#include "resource.h"
#include "TexturGenerator.h"
#include <windows.h>
#include "FillFilter.h"
#include "FillFilterGUI.h"
#include "PapFilter.h"
#include "PapFilterGUI.h"
#include "MainGUI.h"
#include "TexCommander.h"
#include <commctrl.h>
HDC hDC;
GLuint ScreenTex;
GL_Window MyGLWindow;
/*
#pragma comment( lib, "opengl32.lib" ) // Search For OpenGL32.lib While Linking
#pragma comment( lib, "glu32.lib" ) // Search For GLu32.lib While Linking
#pragma comment( lib, "winmm.lib" ) // Search For WinMM Library While Linking
*/
void SaveLayer(FILE *F,tLayer *Layer)
{
tTC_TEXT *TP;
long M;
if(Layer==NULL) return;
if(Layer->Command!=NULL)
{
fwrite(&Layer->Command->Type,sizeof(char),1,F);
if(Layer->Command->Type==TCID_TEXT)
{
TP=(tTC_TEXT*)Layer->Command->Params;
fwrite(TP,7,1,F);
fwrite(&TP->DaText,TP->Len,1,F);
} else {
M=GetTypeSize(Layer->Command->Type);
fwrite(Layer->Command->Params,M,1,F);
}
}
SaveLayer(F,Layer->Next);
}
void CreateNewLayer()
{
tLayer *Temp;
Temp=CreateLayer();
AktLayer=Temp;
AttachLayer(Layer,Temp);
Temp->Image=CopyImage(GetFatherImage(Layer,Temp));
}
void InsertLayer()
{
tLayer *Temp,*Father;
Temp=CreateLayer();
if(AktLayer==Layer)
{
Temp->Next=Layer;
Layer=Temp;
} else {
Father=Layer;
while(Father->Next!=AktLayer) { Father=Father->Next;}
Temp->Next=Father->Next;
Father->Next=Temp;
}
AktLayer=Temp;
Temp->Image=CopyImage(GetFatherImage(Layer,Temp));
}
void UpDateMainWindow(HWND hWnd)
{
long ComNr;
char Text[220];
ComNr=GetLayerNr(Layer,AktLayer)+1;
sprintf(Text,"%d/%d",ComNr,CountLayers(Layer));
SetDlgItemText(hWnd,IDC_COMMANDNR,Text);
if(AktLayer->Command==NULL)
{
sprintf(Text,"<Empty>");
} else {
switch(AktLayer->Command->Type)
{
case TCID_XORMAP:sprintf(Text,"Create XOR Map");break;
case TCID_BLUR:sprintf(Text,"Blur");break;
case TCID_MOVEMID:sprintf(Text,"MoveMid");break;
case TCID_TWIST:sprintf(Text,"Twist");break;
case TCID_TEXT:sprintf(Text,"Text");break;
case TCID_FILLGEN:sprintf(Text,"FillGen");break;
case TCID_FILLFILTER02:sprintf(Text,"Matrix");break;
case TCID_MIXPICS:sprintf(Text,"Mix Pictures");break;
case TCID_MAKETILEABLE:sprintf(Text,"Make TileAble");break;
case TCID_TWIRL:sprintf(Text,"Twirl");break;
case TCID_TILE:sprintf(Text,"Tile");break;
case TCID_COLOR:sprintf(Text,"Color");break;
case TCID_RANGECOLORS:sprintf(Text,"Range Colors");break;
case TCID_SOLIDFILL:sprintf(Text,"Solid Fill");break;
case TCID_SPHERE:sprintf(Text,"Sphere");break;
}
}
SetDlgItemText(hWnd,IDC_COMMANDANZEIGE,Text);
SendDlgItemMessage(hWnd,IDC_COMMANDSLIDER,TBM_SETRANGE,true,MAKELONG(1,CountLayers(Layer)));
SendDlgItemMessage(hWnd,IDC_COMMANDSLIDER,TBM_SETPOS,true,ComNr);
if(AktLayer->Image!=NULL)
{
DestroyImage(Image);
Image=CopyImage(AktLayer->Image);
}
ReFreshPic(hWnd,Image);
}
void InitFunctionCall(long Type,void *OldParams)
{
long M;
Image=CopyImage(GetFatherImage(Layer,AktLayer));
if(AktLayer->Command!=NULL)
{
if(AktLayer->Command->Type==Type)
{
M=GetTypeSize(Type);
if(M!=0)
{
memcpy(OldParams,AktLayer->Command->Params,M);
}
}
}
}
void StoreCommand(long Type,void *Params)
{
tLayer *Temp,*Old;
if(AktLayer->Command!=NULL)
{
DestroyTexCommand(AktLayer->Command);
}
AktLayer->Command=CreateTexCommand(Type,Params);
DestroyImage(AktLayer->Image);
AktLayer->Image=CopyImage(Image);
Temp=AktLayer->Next;
Old=AktLayer;
while(Temp!=NULL)
{
DestroyImage(Temp->Image);
Temp->Image=CopyImage(GetFatherImage(Layer,Temp));
ReCalcLayer(Temp);
Temp=Temp->Next;
}
if(AktLayer->Next==NULL) CreateNewLayer();
}
void SaveFunction(HWND LB_Parent_Hwnd) // Saved n Model
{
OPENFILENAME ofn; /* common dialog box structure */
char szDirName[MAX_PATH]; /* directory string */
char szFile[4096]; /* filename string */
char szFileTitle[4096]; /* filename string */
long M;
/*
hinst = (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE);
*/
/*
Obtain the system directory name and store it in szDirName.
*/
GetSystemDirectory(szDirName, sizeof(szDirName));
/*
Place the terminating null character in the szFile.
*/
szFile[0] = '\0';
/*
Set the members of the OPENFILENAME structure.
*/
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = LB_Parent_Hwnd;
ofn.lpstrTitle = "Save Texture\0";
ofn.lpstrFilter = "TEXditor Files (*.tcm)\0*.tcm\0All files (*.*)\0*.*\0\0";
ofn.lpstrCustomFilter = NULL;
ofn.nFilterIndex = 1;
ofn.lpstrFile = szFile;
ofn.nMaxFile = 2048;
ofn.lpstrFileTitle = szFileTitle;
ofn.nMaxFileTitle = 2048;
ofn.lpstrInitialDir = ".\0";
ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST /*| OFN_ALLOWMULTISELECT*/;
/*
Display the Open dialog box.
*/
if (GetSaveFileName(&ofn))
{
char *path = ofn.lpstrFile;
char *fname = ofn.lpstrFile;
char *outp;
FILE *F;
tLayer *TempL;
if(strchr(fname,'.')==NULL)
strcat(fname,".tcm");
F=fopen(fname,"wb");
M=CountLayers(Layer);
// Layer ohne Commands rausschmeissen
TempL=Layer;
while(TempL!=NULL)
{
if(TempL->Command==NULL) M--;
TempL=TempL->Next;
}
fwrite(&M,sizeof(long),1,F);
SaveLayer(F,Layer);
fclose(F);
};
}
void LoadFunction(HWND LB_Parent_Hwnd) // L鋎t ne .dat
{
OPENFILENAME ofn; /* common dialog box structure */
char szDirName[MAX_PATH]; /* directory string */
char szFile[4096]; /* filename string */
char szFileTitle[4096]; /* filename string */
long I,K,M;
tLayer *Temp;
/*
hinst = (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE);
*/
/*
Obtain the system directory name and store it in szDirName.
*/
GetSystemDirectory(szDirName, sizeof(szDirName));
/*
Place the terminating null character in the szFile.
*/
szFile[0] = '\0';
/*
Set the members of the OPENFILENAME structure.
*/
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = LB_Parent_Hwnd;
ofn.lpstrTitle = "Load Texture \0";
ofn.lpstrFilter = "TEXditor Files (*.tcm)\0*.tcm\0All files (*.*)\0*.*\0\0";
ofn.lpstrCustomFilter = NULL;
ofn.nFilterIndex = 1;
ofn.lpstrFile = szFile;
ofn.nMaxFile = 2048;
ofn.lpstrFileTitle = szFileTitle;
ofn.nMaxFileTitle = 2048;
ofn.lpstrInitialDir = ".\0";
ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
/*
Display the Open dialog box.
*/
if (GetOpenFileName(&ofn))
{
char *path = ofn.lpstrFile;
char *fname = ofn.lpstrFileTitle;
char *outp;
t_File_Handle *F;
/*
if(strchr(fname,'.')==NULL)
strcat(fname,".tcm");
*/
DestroyLayer(Layer,true);
Layer=LoadLayerFile(fname);
AktLayer=Layer;
// LoadDaAnimation(fname);
};
}
// Process Window Message Callbacks
BOOL CALLBACK MyWindowProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
long Nr;
MainWindow=hWnd;
switch(uMsg)
{
case WM_INITDIALOG:
switch(ShowChannel) {
case 0: CheckDlgButton(hWnd,IDC_RADIO1,BST_CHECKED); break;
case 1: CheckDlgButton(hWnd,IDC_RADIO2,BST_CHECKED); break;
case 2: CheckDlgButton(hWnd,IDC_RADIO3,BST_CHECKED); break;
case 3: CheckDlgButton(hWnd,IDC_RADIO4,BST_CHECKED); break;
case 4: CheckDlgButton(hWnd,IDC_RADIO5,BST_CHECKED); break;
case 5: CheckDlgButton(hWnd,IDC_RADIO6,BST_CHECKED); break;
}
UpDateMainWindow(hWnd);
return(true);
break;
case WM_HSCROLL:
Nr=SendDlgItemMessage(hWnd,IDC_COMMANDSLIDER,TBM_GETPOS,0,0);
AktLayer=GetLayerAddr(Layer,Nr-1);
UpDateMainWindow(hWnd);
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
EndDialog(hWnd,0);
break;
case IDC_GENERATE:
UpDateMainWindow(hWnd);
break;
case IDC_SHOWTILED:
ReFreshPicTiled(hWnd);
break;
case IDC_NEWLAYER:
CreateNewLayer();
UpDateMainWindow(hWnd);
break;
case IDC_INSERTLAYER:
InsertLayer();
UpDateMainWindow(hWnd);
break;
case IDC_XORMAP:
InitFunctionCall(TCID_XORMAP,&C1);
if(DialogBox(NULL,MAKEINTRESOURCE(IDD_XORMAPDLG),hWnd,XORMAPProc))
StoreCommand(TCID_XORMAP,&C1);
UpDateMainWindow(hWnd);
break;
case IDC_BLUR:
InitFunctionCall(TCID_BLUR,NULL);
Blur(Image);
StoreCommand(TCID_BLUR,NULL);
UpDateMainWindow(hWnd);
break;
case IDC_MOVEMID:
InitFunctionCall(TCID_MOVEMID,NULL);
MoveMid(Image);
StoreCommand(TCID_MOVEMID,NULL);
UpDateMainWindow(hWnd);
break;
case IDC_FILLGENERATOR:
InitFunctionCall(TCID_FILLGEN,&C3);
if(DialogBox(NULL,MAKEINTRESOURCE(IDD_FILLFILTER01DIALOG),hWnd,FillFilter01DialogProc))
StoreCommand(TCID_FILLGEN,&C3);
UpDateMainWindow(hWnd);
break;
case IDC_MATRIX:
InitFunctionCall(TCID_FILLFILTER02,&C4);
if(DialogBox(NULL,MAKEINTRESOURCE(IDD_FILLFILTER02DIALOG),hWnd,FillFilter02DialogProc))
StoreCommand(TCID_FILLFILTER02,&C4);
UpDateMainWindow(hWnd);
break;
case IDC_TWIST:
InitFunctionCall(TCID_TWIST,&C2);
if(DialogBox(NULL,MAKEINTRESOURCE(IDD_TWIST),hWnd,TwistProc))
StoreCommand(TCID_TWIST,&C2);
UpDateMainWindow(hWnd);
break;
case IDC_TEXT:
InitFunctionCall(TCID_TEXT,&CT);
if(DialogBox(NULL,MAKEINTRESOURCE(IDD_TEXT),hWnd,TextProc))
StoreCommand(TCID_TEXT,&CT);
UpDateMainWindow(hWnd);
break;
case IDC_MIXPICS:
InitFunctionCall(TCID_MIXPICS,&CMix);
if(DialogBox(NULL,MAKEINTRESOURCE(IDD_MIXPICS),hWnd,MixPicProc))
StoreCommand(TCID_MIXPICS,&CMix);
UpDateMainWindow(hWnd);
break;
case IDC_MAKETILEABLE:
InitFunctionCall(TCID_MAKETILEABLE,&MT);
if(DialogBox(NULL,MAKEINTRESOURCE(IDD_MAKETILEABLE),hWnd,MakeTileAbleProc))
StoreCommand(TCID_MAKETILEABLE,&MT);
UpDateMainWindow(hWnd);
break;
case IDC_TWIRL:
InitFunctionCall(TCID_TWIRL,&CTW);
if(DialogBox(NULL,MAKEINTRESOURCE(IDD_TWIRL),hWnd,TwirlProc))
StoreCommand(TCID_TWIRL,&CTW);
UpDateMainWindow(hWnd);
break;
case IDC_TILE:
InitFunctionCall(TCID_TILE,NULL);
Tile(Image);
StoreCommand(TCID_TILE,NULL);
UpDateMainWindow(hWnd);
break;
case IDC_COLOR:
InitFunctionCall(TCID_COLOR,&CCol);
if(DialogBox(NULL,MAKEINTRESOURCE(IDD_COLORDLG),hWnd,ColorProc))
StoreCommand(TCID_COLOR,&CCol);
UpDateMainWindow(hWnd);
break;
case IDC_RANGECOLORS:
InitFunctionCall(TCID_RANGECOLORS,&CRC);
if(DialogBox(NULL,MAKEINTRESOURCE(IDD_RANGECOLORSDLG),hWnd,RangeColorsProc))
StoreCommand(TCID_RANGECOLORS,&CRC);
UpDateMainWindow(hWnd);
break;
case IDC_SOLIDFILL:
InitFunctionCall(TCID_SOLIDFILL,&CSF);
if(DialogBox(NULL,MAKEINTRESOURCE(IDD_SOLIDFILLDLG),hWnd,SolidFillProc))
StoreCommand(TCID_SOLIDFILL,&CSF);
UpDateMainWindow(hWnd);
break;
case IDC_SPHERE:
InitFunctionCall(TCID_SPHERE,&CS);
if(DialogBox(NULL,MAKEINTRESOURCE(IDD_SPHEREDLG),hWnd,SphereProc))
StoreCommand(TCID_SPHERE,&CS);
UpDateMainWindow(hWnd);
break;
case IDC_SAVE:
SaveFunction(hWnd);
UpDateMainWindow(hWnd);
break;
case IDC_LOAD:
LoadFunction(hWnd);
UpDateMainWindow(hWnd);
break;
case IDC_RADIO1:ShowChannel=0;UpDateMainWindow(hWnd);break;
case IDC_RADIO2:ShowChannel=1;UpDateMainWindow(hWnd);break;
case IDC_RADIO3:ShowChannel=2;UpDateMainWindow(hWnd);break;
case IDC_RADIO4:ShowChannel=3;UpDateMainWindow(hWnd);break;
case IDC_RADIO5:ShowChannel=4;UpDateMainWindow(hWnd);break;
case IDC_RADIO6:ShowChannel=5;UpDateMainWindow(hWnd);break;
}
break;
}
return(false);
}
void LoadFont()
{
long I;
t_File_Handle *F;
F=Load_File("FONTOUTPUT.DAT");
for(I=0;I<96;I++)
{
FileRead(F,&FontItem[I].X,4);
FileRead(F,&FontItem[I].Y,4);
FontItem[I].Data=(char*)malloc(30*30*4);
FileRead(F,FontItem[I].Data,30*30*4);
}
Close_File(F);
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
tImage *Temp;
long I;
MainInstance=hInstance;
// TODO: Place code here.
Image=CreateImage(256,256);
BlankImage=CreateImage(256,256);
memset(BlankImage->Data,0,BlankImage->XSize*BlankImage->YSize*4);
InitATanList();
LoadFont();
C1.A=255;
C1.R=255;
C1.B=255;
C1.G=255;
C2.Wink=0.03;
CTW.Wink=0.03;
C3.AusdehnungX=1;
C3.AusdehnungY=1;
C3.Change=10;
C3.Channel=4;
C3.RandomStart=124;
C3.StartPartikel=1;
C3.StartValue=128;
CMix.FName[0]=0;
CMix.A=128;
CMix.R=128;
CMix.G=128;
CMix.B=128;
CCol.A=255;
CCol.R=255;
CCol.G=128;
CCol.B=64;
CCol.Channel=4;
CCol.Gamma=128;
CRC.Channel=4;
CRC.MinValue=92;
CRC.MaxValue=255;
CRC.MidValue=128;
CSF.Channel=4;
CSF.Value=128;
CS.Channel=4;
CS.MaxValue=255;
CS.MinValue=0;
CS.Type=0;
CT.X=0;
CT.Y=0;
CT.R=255;
CT.G=255;
CT.B=255;
CT.Trans=255;
strcpy(CT.DaText,"Ficken");
CT.Len=6;
MT.Amount=64;
ShowChannel=5;
Layer=CreateLayer();
Layer->Image=CreateImage(256,256);
AktLayer=Layer;
Temp=CopyImage(BlankImage);
for(I=0;I<3;I++)
{
// SolidFill(Temp,&CSF);
// Color(Temp,&CCol);
// Blur(Temp);
// Twirl(Temp,&CTW);
// Twist(Temp,&C2);
// MakeTileAble(Temp,&MT);
// Tile(Temp);
// RangeColors(Temp,&CRC);
// FillbertFilter01(Temp,&C3);
}
DestroyImage(Temp);
InitCommonControls();
DialogBox(hInstance,MAKEINTRESOURCE(IDD_MAINWINDOW),NULL,MyWindowProc);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -