texwnd.cpp
来自「quake3工具源码。包括生成bsp文件」· C++ 代码 · 共 2,647 行 · 第 1/5 页
CPP
2,647 行
return hwndEdit;
}
void Delay(float fSeconds)
{
DWORD dw = ::GetTickCount();
DWORD dwTil = dw + (fSeconds * 1000);
while (::GetTickCount() < dwTil)
{
MSG msg;
if (::PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
void ViewShader(const char *pFile, const char *pName)
{
CString str;
char* pBuff = NULL;
int nSize = LoadFile(pFile, reinterpret_cast<void**>(&pBuff));
if (nSize == -1)
{
nSize = PakLoadAnyFile(pFile, reinterpret_cast<void**>(&pBuff));
}
if (nSize > 0)
{
str = pBuff;
}
int nStart = 0;
if (str.GetLength() > 0)
{
CString strFind = pName;
CString strLook = str;
strLook.MakeLower();
strFind.MakeLower();
int n = strLook.Find(strFind);
if (n >= 0)
{
nStart = n;
}
}
CString s= "editpad ";
s += pFile;
WinExec(s, SW_SHOWNORMAL);
Delay(1.5);
HWND hwndEdit = FindEditWindow();
if (hwndEdit != NULL)
{
PostMessage(hwndEdit, EM_SETSEL, nStart, nStart);
}
else
{
Sys_Printf("Unable to load shader editor.\n");
}
}
/*
==============
SelectTexture
By mouse click
==============
*/
void SelectTexture (int mx, int my, bool bShift, bool bFitScale)
{
int x, y;
qtexture_t *q;
texdef_t tex;
brushprimit_texdef_t brushprimit_tex;
my += g_qeglobals.d_texturewin.originy-g_qeglobals.d_texturewin.height;
Texture_StartPos ();
while (1)
{
q = Texture_NextPos (&x, &y);
if (!q)
break;
int nWidth = (g_PrefsDlg.m_bHiColorTextures == TRUE) ? q->width * ((float)g_PrefsDlg.m_nTextureScale / 100) : q->width;
int nHeight = (g_PrefsDlg.m_bHiColorTextures == TRUE) ? q->height * ((float)g_PrefsDlg.m_nTextureScale / 100) : q->height;
if (mx > x && mx - x < nWidth
&& my < y && y - my < nHeight + FONT_HEIGHT)
{
if (bShift)
{
if (g_PrefsDlg.m_bHiColorTextures && q->shadername[0] != 0)
{
//CString s = "notepad ";
//s += q->shadername;
//WinExec(s, SW_SHOWNORMAL);
ViewShader(q->shadername, q->name);
}
}
memset (&tex, 0, sizeof(tex));
memset (&brushprimit_tex, 0, sizeof(brushprimit_tex));
if (g_qeglobals.m_bBrushPrimitMode)
{
// brushprimit fitted to a 2x2 texture
brushprimit_tex.coords[0][0] = 1.0f;
brushprimit_tex.coords[1][1] = 1.0f;
}
else
{
tex.scale[0] = (g_PrefsDlg.m_bHiColorTextures) ? 0.5 : 1;
tex.scale[1] = (g_PrefsDlg.m_bHiColorTextures) ? 0.5 : 1;
}
tex.flags = q->flags;
tex.value = q->value;
tex.contents = q->contents;
//strcpy (tex.name, q->name);
tex.SetName(q->name);
Texture_SetTexture ( &tex, &brushprimit_tex, bFitScale, GETPLUGINTEXDEF(q));
CString strTex;
CString strName = q->name;
//int nPos = strName.Find('\\');
//if (nPos == -1)
// nPos = strName.Find('/');
//if (nPos >= 0)
// strName = strName.Right(strName.GetLength() - nPos - 1);
strTex.Format("%s W: %i H: %i", strName.GetBuffer(0), q->width, q->height);
g_pParentWnd->SetStatusText(3, strTex);
return;
}
}
Sys_Status("Did not select a texture\n", 0);
}
/*
==============
Texture_MouseDown
==============
*/
void Texture_MouseDown (int x, int y, int buttons)
{
Sys_GetCursorPos (&textures_cursorx, &textures_cursory);
// lbutton = select texture
if (buttons == MK_LBUTTON || buttons == (MK_LBUTTON | MK_SHIFT) || buttons == (MK_LBUTTON | MK_CONTROL))
{
SelectTexture (x, g_qeglobals.d_texturewin.height - 1 - y, buttons & MK_SHIFT, buttons & MK_CONTROL);
UpdateSurfaceDialog();
UpdatePatchInspector();
}
}
/*
==============
Texture_MouseUp
==============
*/
void Texture_MouseUp (int x, int y, int buttons)
{
}
/*
==============
Texture_MouseMoved
==============
*/
void Texture_MouseMoved (int x, int y, int buttons)
{
int scale = 1;
if ( buttons & MK_SHIFT )
scale = 4;
// rbutton = drag texture origin
if (buttons & MK_RBUTTON)
{
Sys_GetCursorPos (&x, &y);
if ( y != textures_cursory)
{
g_qeglobals.d_texturewin.originy += ( y-textures_cursory) * scale;
if (g_qeglobals.d_texturewin.originy > 0)
g_qeglobals.d_texturewin.originy = 0;
Sys_SetCursorPos (textures_cursorx, textures_cursory);
CWnd *pWnd = CWnd::FromHandle(g_qeglobals.d_hwndTexture);
if (g_PrefsDlg.m_bTextureScrollbar && pWnd != NULL)
{
pWnd->SetScrollPos(SB_VERT, abs(g_qeglobals.d_texturewin.originy));
}
InvalidateRect(g_qeglobals.d_hwndTexture, NULL, false);
UpdateWindow (g_qeglobals.d_hwndTexture);
}
return;
}
}
/*
============================================================================
DRAWING
============================================================================
*/
int imax(int iFloor, int i) { if (i>iFloor) return iFloor; return i; }
HFONT ghFont = NULL;
/*
============
Texture_Draw2
============
*/
void Texture_Draw2 (int width, int height)
{
qtexture_t *q;
int x, y;
char *name;
qglClearColor (
g_qeglobals.d_savedinfo.colors[COLOR_TEXTUREBACK][0],
g_qeglobals.d_savedinfo.colors[COLOR_TEXTUREBACK][1],
g_qeglobals.d_savedinfo.colors[COLOR_TEXTUREBACK][2],
0);
qglViewport (0,0,width,height);
qglMatrixMode(GL_PROJECTION);
qglLoadIdentity ();
qglClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
qglDisable (GL_DEPTH_TEST);
qglDisable(GL_BLEND);
qglOrtho (0, width, g_qeglobals.d_texturewin.originy-height, g_qeglobals.d_texturewin.originy, -100, 100);
qglEnable (GL_TEXTURE_2D);
qglPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
g_qeglobals.d_texturewin.width = width;
g_qeglobals.d_texturewin.height = height;
Texture_StartPos ();
while (1)
{
q = Texture_NextPos (&x, &y);
if (!q)
break;
int nWidth = (g_PrefsDlg.m_bHiColorTextures == TRUE) ? q->width * ((float)g_PrefsDlg.m_nTextureScale / 100) : q->width;
int nHeight = (g_PrefsDlg.m_bHiColorTextures == TRUE) ? q->height * ((float)g_PrefsDlg.m_nTextureScale / 100) : q->height;
// Is this texture visible?
if ( (y-nHeight-FONT_HEIGHT < g_qeglobals.d_texturewin.originy)
&& (y > g_qeglobals.d_texturewin.originy - height) )
{
// if in use, draw a background
if ((q->inuse && !texture_showinuse) || q->bFromShader)
{
qglLineWidth (1);
if (q->bFromShader)
{
qglColor3f (1,1,1);
}
else
{
qglColor3f (0.5,1,0.5);
}
qglDisable (GL_TEXTURE_2D);
qglBegin (GL_LINE_LOOP);
qglVertex2f (x-1,y+1-FONT_HEIGHT);
qglVertex2f (x-1,y-nHeight-1-FONT_HEIGHT);
qglVertex2f (x+1+nWidth,y-nHeight-1-FONT_HEIGHT);
qglVertex2f (x+1+nWidth,y+1-FONT_HEIGHT);
qglEnd ();
qglEnable (GL_TEXTURE_2D);
}
// Draw the texture
float fScale = (g_PrefsDlg.m_bHiColorTextures == TRUE) ? ((float)g_PrefsDlg.m_nTextureScale / 100) : 1.0;
qglBindTexture( GL_TEXTURE_2D, q->texture_number );
QE_CheckOpenGLForErrors();
qglColor3f (1,1,1);
qglBegin (GL_QUADS);
qglTexCoord2f (0,0);
qglVertex2f (x,y-FONT_HEIGHT);
qglTexCoord2f (1,0);
qglVertex2f (x+nWidth,y-FONT_HEIGHT);
qglTexCoord2f (1,1);
qglVertex2f (x+nWidth,y-FONT_HEIGHT-nHeight);
qglTexCoord2f (0,1);
qglVertex2f (x,y-FONT_HEIGHT-nHeight);
qglEnd ();
// draw the selection border
if (!strcmpi(g_qeglobals.d_texturewin.texdef.name, q->name))
{
qglLineWidth (3);
qglColor3f (1,0,0);
qglDisable (GL_TEXTURE_2D);
qglBegin (GL_LINE_LOOP);
qglVertex2f (x-4,y-FONT_HEIGHT+4);
qglVertex2f (x-4,y-FONT_HEIGHT-nHeight-4);
qglVertex2f (x+4+nWidth,y-FONT_HEIGHT-nHeight-4);
qglVertex2f (x+4+nWidth,y-FONT_HEIGHT+4);
qglEnd ();
qglEnable (GL_TEXTURE_2D);
qglLineWidth (1);
}
// draw the texture name
qglColor3f (0,0,0);
qglRasterPos2f (x, y-FONT_HEIGHT+2);
// don't draw the directory name
for (name = q->name ; *name && *name != '/' && *name != '\\' ; name++)
;
if (!*name)
name = q->name;
else
name++;
if (g_PrefsDlg.m_bHiColorTextures && q->shadername[0] != 0)
{
// slow as shit
CString s = "[";
s += name;
s += "]";
qglCallLists (s.GetLength(), GL_UNSIGNED_BYTE, s.GetBuffer(0));
}
else
{
qglCallLists (strlen(name), GL_UNSIGNED_BYTE, name);
}
}
}
g_qeglobals.d_texturewin.m_nTotalHeight = abs(y) + 100;
// reset the current texture
qglBindTexture( GL_TEXTURE_2D, 0 );
qglFinish();
}
void Texture_Init (bool bHardInit)
{
char name[1024];
byte *pal = NULL;
if (g_PrefsDlg.m_bHiColorTextures == FALSE)
{
// load the palette
sprintf (name, "%s/pics/colormap.pcx", ValueForKey (g_qeglobals.d_project_entity, "basepath"));
Load256Image (name, NULL, &pal, NULL, NULL);
if (!pal)
{
// before dropping out, try to load it from the QERadiant directory
CString strFile = g_strAppPath;
AddSlash(strFile);
strFile += "colormap.pcx";
Load256Image (strFile.GetBuffer(0), NULL, &pal, NULL, NULL);
if (!pal)
Sys_Printf ("Couldn't load %s or %s", name, strFile);
}
else
{
Texture_InitPalette (pal);
free (pal);
}
}
// create the fallback texture
if (bHardInit)
{
Texture_MakeNotexture();
g_qeglobals.d_qtextures = NULL;
}
LoadShaders();
}
void Texture_FlushUnused()
{
CWaitCursor cursor;
Texture_ShowInuse();
if (g_qeglobals.d_qtextures)
{
qtexture_t* pTex = g_qeglobals.d_qtextures->next;
qtexture_t *pPrev = g_qeglobals.d_qtextures;
while (pTex != NULL && pTex != g_qeglobals.d_qtextures)
{
qtexture_t* pNextTex = pTex->next;
if (g_qeglobals.bSurfacePropertiesPlugin)
{
// Timo
// Surface properties plugin
#ifdef _DEBUG
if ( !pTex->pData )
Sys_Printf("WARNING: found a qtexture_t* with no IPluginQTexture\n");
#endif
if ( pTex->pData && pTex->inuse )
GETPLUGINTEXDEF(pTex)->DecRef();
}
if (!pTex->inuse)
{
unsigned int nTexture = pTex->texture_number;
qglDeleteTextures(1, &nTexture);
pPrev->next = pNextTex;
free(pTex);
}
else
{
pPrev = pTex;
}
pTex = pNextTex;
}
}
}
void Texture_Cleanup(CStringList *pList)
{
if (g_qeglobals.d_qtextures)
{
qtexture_t* pTex = g_qeglobals.d_qtextures->next;
while (pTex != NULL && pTex != g_qeglobals.d_qtextures)
{
qtexture_t* pNextTex = pTex->next;
if (pList)
{
if (pTex->name[0] != '(')
{
pList->AddTail(pTex->name);
}
}
if (g_qeglobals.bSurfacePropertiesPlugin)
{
// Timo
// Surface properties plugin
#ifdef _DEBUG
if ( !pTex->pData )
Sys_Printf("WARNING: found a qtexture_t* with no IPluginQTexture\n");
#endif
if ( pTex->pData )
GETPLUGINTEXDEF(pTex)->DecRef();
}
free(pTex);
pTex = pNextTex;
}
}
int nSize = g_lstSkinCache.GetSize();
for (int i = 0; i < nSize; i++)
{
SkinInfo *pInfo = reinterpret_cast<SkinInfo*>(g_lstSkinCache.GetAt(i));
delete pInfo;
}
}
/*
==================
Texture_Flush
==================
*/
void Texture_Flush (bool bReload)
{
if (!ConfirmModified())
return;
Map_New ();
CWaitCursor cursor;
CStringList strList;
Texture_Init(false);
Texture_Cleanup(&strList);
GLuint* pGln = new GLuint[texture_extension_number-1];
qglGenTextures(texture_extension_number-1, pGln);
QE_CheckOpenGLForErrors();
qglDeleteTextures(texture_extension_number-1, pGln);
QE_CheckOpenGLForErrors();
delete []pGln;
texture_extension_number = 1;
g_qeglobals.d_qtextures = NULL;
if (bReload)
{
POSITION pos = strList.GetHeadPosition();
while (pos)
{
CString strTex = strList.GetNext(pos);
Texture_ForName (strTex.GetBuffer(0));
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CTexWnd
IMPLEMENT_DYNCREATE(CTexWnd, CWnd);
CTexWnd::CTexWnd()
{
m_bNeedRange = true;
}
CTexWnd::~CTexWnd()
{
}
BEGIN_MESSAGE_MAP(CTexWnd, CWnd)
//{{AFX_MSG_MAP(CT
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?