surfacedlg.cpp

来自「quake3工具源码。包括生成bsp文件」· C++ 代码 · 共 963 行 · 第 1/2 页

CPP
963
字号
			{
				if (bUp)
					pt->rotate += 45;
				else
					pt->rotate -= 45;
				if (pt->rotate < 0)
					pt->rotate += 360;
				if (pt->rotate >= 360)
					pt->rotate -= 360;
			}
		}
		else if (nID == IDC_SPIN_HSCALE)
		{
			if (g_qeglobals.m_bBrushPrimitMode)
			{
				if (bUp)
					m_scale[0] += 0.1;
				else
					m_scale[0] -= 0.1;
			}
			else
			{
				if (bUp)
					pt->scale[0] += 0.1;
				else
					pt->scale[0] -= 0.1;
			}
		}
		else if (nID == IDC_SPIN_VSCALE)
		{
			if (g_qeglobals.m_bBrushPrimitMode)
			{
				if (bUp)
					m_scale[1] += 0.1;
				else
					m_scale[1] -= 0.1;
			}
			else
			{
				if (bUp)
					pt->scale[1] += 0.1;
				else
					pt->scale[1] -= 0.1;
			}
		}
		else if (nID == IDC_SPIN_HSHIFT)
		{
			if (g_qeglobals.m_bBrushPrimitMode)
			{
				if (bUp)
					m_shift[0] += 8;
				else
					m_shift[0] -= 8;
			}
			else
			{
				if (bUp)
					pt->shift[0] += 8;
				else
					pt->shift[0] -= 8;
			}
		}
		else if (nID == IDC_SPIN_VSHIFT)
		{
			if (g_qeglobals.m_bBrushPrimitMode)
			{
				if (bUp)
					m_shift[1] += 8;
				else
					m_shift[1] -= 8;
			}
			else
			{
				if (bUp)
					pt->shift[1] += 8;
				else
					pt->shift[1] -= 8;
			}
		}
	}
	// a local copy of the texture matrix, given for a qtexture_t with width=2 height=2
	brushprimit_texdef_t	local_bp;
	brushprimit_texdef_t	*bpt;
	if (g_qeglobals.m_bBrushPrimitMode)
	{
    face_t *selFace = NULL;
		if (g_bNewFace && g_ptrSelectedFaces.GetSize() > 0)
    {
      selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(0));
			bpt = &selFace->brushprimit_texdef;
    }
		else
    {
			bpt = &g_qeglobals.d_texturewin.brushprimit_texdef;
    }
		// compute texture matrix
		// the matrix returned must be understood as a qtexture_t with width=2 height=2
		FakeTexCoordsToTexMat( m_shift, m_rotate, m_scale, local_bp.coords );
		// copy the texture matrix in the global struct
		// fit the qtexture if we have a face selected, otherwise g_qeglobals.d_texturewin.brushprimit_texdef uses the basic qtexture_t with width=2 height=2
		ConvertTexMatWithQTexture( &local_bp, NULL, bpt, ( ( g_bNewFace && selFace ) ? selFace->d_texture : NULL ) );
	}
	// brush primit : will update the widgets after reading back texture matrix and computing fake shift scale rot
	SetTexMods();
	g_changed_surface = true;
	Select_SetTexture(pt,&local_bp);
}

void CSurfaceDlg::UpdateSpinners(int nScrollCode, int nPos, CScrollBar* pBar)
{
	texdef_t *pt;

	GetTexMods ();
  if (g_bNewFace && g_ptrSelectedFaces.GetSize() > 0)
  {
    face_t *selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(0));
		pt = &selFace->texdef;
  }
  else
  {
	  pt = &g_qeglobals.d_texturewin.texdef;
  }

	if ((nScrollCode != SB_LINEUP) && (nScrollCode != SB_LINEDOWN))
		return;
	
  if (pBar->GetSafeHwnd() == ::GetDlgItem(GetSafeHwnd(), IDC_ROTATEA))
	{
		if (nScrollCode == SB_LINEUP)
			pt->rotate += 45;
		else
			pt->rotate -= 45;

		if (pt->rotate < 0)
			pt->rotate += 360;

		if (pt->rotate >= 360)
			pt->rotate -= 360;
	}

  else if (pBar->GetSafeHwnd() == ::GetDlgItem(GetSafeHwnd(), IDC_HSCALEA))
	{
		if (nScrollCode == SB_LINEDOWN)
			pt->scale[0] -= 0.1;
		else
			pt->scale[0] += 0.1;
	}
	
  else if (pBar->GetSafeHwnd() == ::GetDlgItem(GetSafeHwnd(), IDC_VSCALEA))
	{
		if (nScrollCode == SB_LINEUP)
			pt->scale[1] += 0.1;
		else
			pt->scale[1] -= 0.1;
	} 
	
  else if (pBar->GetSafeHwnd() == ::GetDlgItem(GetSafeHwnd(), IDC_HSHIFTA))
	{
		if (nScrollCode == SB_LINEDOWN)
			pt->shift[0] -= 8;
		else
			pt->shift[0] += 8;
	}
	
  else if (pBar->GetSafeHwnd() == ::GetDlgItem(GetSafeHwnd(), IDC_VSHIFTA))
	{
		if (nScrollCode == SB_LINEUP)
			pt->shift[1] += 8;
		else
			pt->shift[1] -= 8;
	}

	SetTexMods();
	g_changed_surface = true;
	//++timo if !g_qeglobals.m_bBrushPrimitMode send a NULL brushprimit_texdef
	if (!g_qeglobals.m_bBrushPrimitMode)
	{
		Sys_Printf("Warning : non brush primitive mode call to CSurfaceDlg::GetTexMods broken\n");
		Sys_Printf("          ( Select_SetTexture not called )\n");
	}
//	Select_SetTexture(pt);
}

void UpdateSurfaceDialog()
{
	if (g_qeglobals.bSurfacePropertiesPlugin)
	{
		g_SurfaceTable.m_pfnUpdateSurfaceDialog();
	}
	else
	{
		if (g_surfwin)
			g_dlgSurface.SetTexMods();
	}
	g_pParentWnd->UpdateTextureBar();
}

bool ByeByeSurfaceDialog();

void DoSurface (void)
{
	// surface properties plugin ?
	if (g_qeglobals.bSurfacePropertiesPlugin)
	{
		g_SurfaceTable.m_pfnDoSurface();
		return;
	}

  g_bNewFace = g_PrefsDlg.m_bFace;
  g_bNewApplyHandling = g_PrefsDlg.m_bNewApplyHandling;
  g_bGatewayhack = g_PrefsDlg.m_bGatewayHack;
	// save current state for cancel
	g_old_texdef = g_qeglobals.d_texturewin.texdef;
	g_changed_surface = false;

  if (g_surfwin == NULL && g_dlgSurface.GetSafeHwnd() == NULL)
  {
    g_patch_texdef.scale[0] = 0.05;
    g_patch_texdef.scale[1] = 0.05;
    g_patch_texdef.shift[0] = 0.05;
    g_patch_texdef.shift[1] = 0.05;
	// use rotation increment from preferences
    g_patch_texdef.rotate = g_PrefsDlg.m_nRotation;

    g_dlgSurface.Create(IDD_SURFACE);
    CRect rct;
	  LONG lSize = sizeof(rct);
	  if (LoadRegistryInfo("Radiant::SurfaceWindow", &rct, &lSize))
      g_dlgSurface.SetWindowPos(NULL, rct.left, rct.top, 0,0, SWP_NOSIZE | SWP_SHOWWINDOW);

    Sys_UpdateWindows(W_ALL);
  }
  else
  {
    g_surfwin = g_dlgSurface.GetSafeHwnd();
	  g_dlgSurface.SetTexMods ();
    g_dlgSurface.ShowWindow(SW_SHOW);
  }
}		

bool ByeByeSurfaceDialog()
{
	// surface properties plugin ?
	if (g_qeglobals.bSurfacePropertiesPlugin)
	{
		return g_SurfaceTable.m_pfnByeByeSurfaceDialog();
	}

  if (g_surfwin)
  {
    if (g_bGatewayhack)
      PostMessage(g_surfwin, WM_COMMAND, IDAPPLY, 0);
    else
      PostMessage(g_surfwin, WM_COMMAND, IDCANCEL, 0);
    return true;
  }
  else return false;
}

BOOL CSurfaceDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
  g_surfwin = GetSafeHwnd();
	SetTexMods ();

#ifdef QUAKE3
  GetDlgItem(IDC_CHECK32)->SetWindowText("Curve");
  GetDlgItem(IDC_CHECK64)->SetWindowText("Inverted");
#endif

  m_wndHScale.SetRange(0, 1000);
  m_wndVScale.SetRange(0, 1000);
  m_wndHShift.SetRange(0, 1000);
  m_wndVShift.SetRange(0, 1000);
  m_wndRotate.SetRange(0, 1000);
  m_wndWidth.SetRange(1, 32);
  m_wndHeight.SetRange(1, 32);

  LPVOID lpv = g_pParentWnd->GetPlugInMgr().GetSurfaceFlags();
  if (lpv != NULL)
  {
    int i = 0;
    char* p = reinterpret_cast<char*>(lpv);
    char* pBuff = new char[strlen(p)+1];
    strcpy(pBuff, p);
    char* pToken = strtok(pBuff, ";\0");
    while (pToken != NULL)
    {
      GetDlgItem(g_checkboxes[i++])->SetWindowText(pToken);
      pToken = strtok(NULL, ";\0");
    }
  }

  if (strstr(g_PrefsDlg.m_strWhatGame, "Quake3") != NULL) {
    for (int i=0 ; i < 64 ; i++) {
      ::EnableWindow(GetDlgItem(g_checkboxes[i])->GetSafeHwnd(), FALSE);
    }

  }

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CSurfaceDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
	UpdateSpinners(nSBCode, nPos, pScrollBar);
  Sys_UpdateWindows(W_CAMERA);
}

void CSurfaceDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	
	CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}

void CSurfaceDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
	UpdateSpinners(nSBCode, nPos, pScrollBar);
	Sys_UpdateWindows(W_CAMERA);
}

void CSurfaceDlg::OnApply() 
{
	GetTexMods ();
  Sys_UpdateWindows(W_CAMERA);
  if (g_bNewApplyHandling)
    OnOK();
}

void CSurfaceDlg::OnOK() 
{
	GetTexMods();
  g_surfwin = NULL;
	CDialog::OnOK();
  Sys_UpdateWindows(W_ALL);
}

void CSurfaceDlg::OnClose() 
{
  g_surfwin = NULL;
	CDialog::OnClose();
}

void CSurfaceDlg::OnCancel() 
{
  if (g_bGatewayhack)
    OnOK();
  else
    OnBtnCancel();
}

void CSurfaceDlg::OnDestroy() 
{
  if (GetSafeHwnd())
  {
    CRect rct;
    GetWindowRect(rct);
	  SaveRegistryInfo("Radiant::SurfaceWindow", &rct, sizeof(rct));
  }
	CDialog::OnDestroy();
  g_surfwin = NULL;
  Sys_UpdateWindows(W_ALL);
}

void CSurfaceDlg::OnBtnCancel() 
{
	g_qeglobals.d_texturewin.texdef = g_old_texdef;
	if (g_changed_surface)
	{
		//++timo if !g_qeglobals.m_bBrushPrimitMode send a NULL brushprimit_texdef
		if (!g_qeglobals.m_bBrushPrimitMode)
		{
			Sys_Printf("Warning : non brush primitive mode call to CSurfaceDlg::GetTexMods broken\n");
			Sys_Printf("          ( Select_SetTexture not called )\n");
		}
//		Select_SetTexture(&g_qeglobals.d_texturewin.texdef);
	}
  g_surfwin = NULL;
  DestroyWindow();
}

void CSurfaceDlg::OnBtnColor() 
{
}

HBRUSH CSurfaceDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	return hbr;
}

int CSurfaceDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CDialog::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	return 0;
}

BOOL CSurfaceDlg::PreCreateWindow(CREATESTRUCT& cs) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	return CDialog::PreCreateWindow(cs);
}


void CSurfaceDlg::OnDeltaPosSpin(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
  UpdateSpinners((pNMUpDown->iDelta > 0), pNMUpDown->hdr.idFrom);
	*pResult = 0;
}

void CSurfaceDlg::OnBtnPatchdetails() 
{
  Patch_NaturalizeSelected(true);
  Sys_UpdateWindows(W_ALL);
}

void CSurfaceDlg::OnBtnPatchnatural() 
{
  Patch_NaturalizeSelected();
  Sys_UpdateWindows(W_ALL);
}

void CSurfaceDlg::OnBtnPatchreset() 
{
  CTextureLayout dlg;
  if (dlg.DoModal() == IDOK)
  {
    Patch_ResetTexturing(dlg.m_fX, dlg.m_fY);
  }
  Sys_UpdateWindows(W_ALL);
}

void CSurfaceDlg::OnBtnPatchfit() 
{
  Patch_FitTexturing();
  Sys_UpdateWindows(W_ALL);
}

void CSurfaceDlg::OnBtnAxial() 
{
  Select_SetTexture (&g_qeglobals.d_texturewin.texdef, &g_qeglobals.d_texturewin.brushprimit_texdef, true);
	g_changed_surface = true;
  SetTexMods();
  Sys_UpdateWindows(W_ALL);
}

void CSurfaceDlg::OnBtnBrushfit() 
{
	// TODO: Add your control notification handler code here
	
}

void CSurfaceDlg::OnBtnFacefit() 
{
  UpdateData(TRUE);
  if (g_ptrSelectedFaces.GetSize() == 0)
  {
    brush_t *b;
		for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
    {
      for (face_t* pFace = b->brush_faces; pFace; pFace = pFace->next)
      {
        g_ptrSelectedFaces.Add(pFace);
        g_ptrSelectedFaceBrushes.Add(b);
      }
    }
  }
  Select_FitTexture(m_nHeight, m_nWidth);
  SetTexMods();
	g_changed_surface = true;
  Sys_UpdateWindows(W_ALL);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?