xywnd.cpp

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

CPP
2,569
字号
            face.planepts[2][2] = Betwixt(g_Clip1.m_ptClip[2], g_Clip2.m_ptClip[2]);
            face.planepts[2][0] = selected_brushes.next->maxs[0];
          }
          else
          {
            face.planepts[0][1] = selected_brushes.next->mins[1];
            face.planepts[1][1] = selected_brushes.next->mins[1];
            face.planepts[2][0] = Betwixt(g_Clip1.m_ptClip[0], g_Clip2.m_ptClip[0]);
            face.planepts[2][2] = Betwixt(g_Clip1.m_ptClip[2], g_Clip2.m_ptClip[2]);
            face.planepts[2][1] = selected_brushes.next->maxs[1];
          }
        }

        Brush_SplitBrushByFace (selected_brushes.next, &face, pFront, pBack);
      }

    }
  }
}

void CleanList(brush_t* pList)
{
  brush_t* pBrush = pList->next; 
  while (pBrush != NULL && pBrush != pList)
  {
    brush_t* pNext = pBrush->next;
    Brush_Free(pBrush);
    pBrush = pNext;
  }
}

void CXYWnd::ProduceSplitLists()
{
  if (AnyPatchesSelected())
  {
    Sys_Printf("Deslecting patches for clip operation.\n");
    brush_t *next;
	  for (brush_t *pb = selected_brushes.next ; pb != &selected_brushes ; pb = next)
	  {
      next = pb->next;
      if (pb->patchBrush)
      {
		    Brush_RemoveFromList (pb);
		    Brush_AddToList (pb, &active_brushes);
        UpdatePatchInspector();
      }
    }
  }

  CleanList(&g_brFrontSplits);
  CleanList(&g_brBackSplits);
  g_brFrontSplits.next = &g_brFrontSplits;
  g_brBackSplits.next = &g_brBackSplits;
  brush_t* pBrush;
	for (pBrush = selected_brushes.next ; pBrush != NULL && pBrush != &selected_brushes ; pBrush=pBrush->next)
  {
    brush_t* pFront = NULL;
    brush_t* pBack = NULL;
    if (ClipMode())
    {
      if (g_Clip1.Set() && g_Clip2.Set())
      {
        face_t face;
        VectorCopy(g_Clip1.m_ptClip,face.planepts[0]);
        VectorCopy(g_Clip2.m_ptClip,face.planepts[1]);
        VectorCopy(g_Clip3.m_ptClip,face.planepts[2]);
        if (g_Clip3.Set() == false)
        {
          if (g_pParentWnd->ActiveXY()->GetViewType() == XY)
          {
            face.planepts[0][2] = pBrush->mins[2];
            face.planepts[1][2] = pBrush->mins[2];
            face.planepts[2][0] = Betwixt(g_Clip1.m_ptClip[0], g_Clip2.m_ptClip[0]);
            face.planepts[2][1] = Betwixt(g_Clip1.m_ptClip[1], g_Clip2.m_ptClip[1]);
            face.planepts[2][2] = pBrush->maxs[2];
          }
          else if (g_pParentWnd->ActiveXY()->GetViewType() == YZ)
          {
            face.planepts[0][0] = pBrush->mins[0];
            face.planepts[1][0] = pBrush->mins[0];
            face.planepts[2][1] = Betwixt(g_Clip1.m_ptClip[1], g_Clip2.m_ptClip[1]);
            face.planepts[2][2] = Betwixt(g_Clip1.m_ptClip[2], g_Clip2.m_ptClip[2]);
            face.planepts[2][0] = pBrush->maxs[0];
          }
          else
          {
            face.planepts[0][1] = pBrush->mins[1];
            face.planepts[1][1] = pBrush->mins[1];
            face.planepts[2][0] = Betwixt(g_Clip1.m_ptClip[0], g_Clip2.m_ptClip[0]);
            face.planepts[2][2] = Betwixt(g_Clip1.m_ptClip[2], g_Clip2.m_ptClip[2]);
            face.planepts[2][1] = pBrush->maxs[1];
          }
        }
        Brush_SplitBrushByFace (pBrush, &face, &pFront, &pBack);
        if (pBack)
          Brush_AddToList(pBack, &g_brBackSplits);
        if (pFront)
          Brush_AddToList(pFront, &g_brFrontSplits);
      }
    }
  }
}

void Brush_CopyList (brush_t* pFrom, brush_t* pTo)
{
	brush_t* pBrush = pFrom->next; 
	while (pBrush != NULL && pBrush != pFrom)
	{
		brush_t* pNext = pBrush->next;
		Brush_RemoveFromList(pBrush);
		Brush_AddToList(pBrush, pTo);
		pBrush = pNext;
	}
}

void CXYWnd::OnRButtonDown(UINT nFlags, CPoint point) 
{
  g_pParentWnd->SetActiveXY(this);
  m_ptDown = point;
  m_bRButtonDown = true;

  if (g_PrefsDlg.m_nMouseButtons == 3) // 3 button mouse 
  {
    if ((GetKeyState(VK_CONTROL) & 0x8000))
    {
      if (ClipMode()) // already there?
        DropClipPoint(nFlags, point);
      else
      {
        SetClipMode(true);
        g_bRogueClipMode = true;
        DropClipPoint(nFlags, point);
      }
      return;
    }
  }
  OriginalButtonDown(nFlags, point);
}

void CXYWnd::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// plugin entities
	if (DispatchOnLButtonUp(nFlags, point.x, point.y ))
		return;

	if (ClipMode())
  {
    if (g_pMovingClip)
    {
      ReleaseCapture();
      g_pMovingClip = NULL;
    }
  }
  OriginalButtonUp(nFlags, point);
}

void CXYWnd::OnMButtonUp(UINT nFlags, CPoint point) 
{
  OriginalButtonUp(nFlags, point);
}

void CXYWnd::OnRButtonUp(UINT nFlags, CPoint point) 
{
  m_bRButtonDown = false;
  if (point == m_ptDown)    // mouse didn't move
  {
    bool bGo = true;
    if ((GetKeyState(VK_MENU) & 0x8000))
      bGo = false;
    if ((GetKeyState(VK_CONTROL) & 0x8000))
      bGo = false;
    if ((GetKeyState(VK_SHIFT) & 0x8000))
      bGo = false;
    if (bGo)
      HandleDrop();
  }
  OriginalButtonUp(nFlags, point);
}

void CXYWnd::OriginalButtonDown(UINT nFlags, CPoint point)
{
  CRect rctZ;
  GetClientRect(rctZ);
  SetWindowPos(&wndTop, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
  if (::GetTopWindow( g_qeglobals.d_hwndMain ) != GetSafeHwnd())
    ::BringWindowToTop(GetSafeHwnd());
	SetFocus();
	SetCapture();
	XY_MouseDown (point.x, rctZ.Height() - 1 - point.y , nFlags);
  m_nScrollFlags = nFlags;
}          

void CXYWnd::OriginalButtonUp(UINT nFlags, CPoint point)
{
  CRect rctZ;
  GetClientRect(rctZ);
  XY_MouseUp (point.x, rctZ.Height() - 1 - point.y , nFlags);
	if (! (nFlags & (MK_LBUTTON|MK_RBUTTON|MK_MBUTTON)))
		ReleaseCapture ();
}


float fDiff(float f1, float f2)
{
  if (f1 > f2)
    return f1 - f2;
  else
    return f2 - f1;
}


vec3_t tdp;
void CXYWnd::OnMouseMove(UINT nFlags, CPoint point) 
{
	// plugin entities
	//++timo TODO: handle return code
	DispatchOnMouseMove( nFlags, point.x, point.y );

  m_ptDown.x = 0;
  m_ptDown.y = 0;

  if ( g_PrefsDlg.m_bChaseMouse == TRUE &&
       (point.x < 0 || point.y < 0 || 
       point.x > m_nWidth || point.y > m_nHeight) &&
       GetCapture() == this)
  {
    float fAdjustment = (g_qeglobals.d_gridsize / 8 * 64) / m_fScale;
    //m_ptDrag = point;
    m_ptDragAdj.x = 0;
    m_ptDragAdj.y = 0;
    if (point.x < 0)
    {
      m_ptDragAdj.x = -fAdjustment;
    }
    else 
    if (point.x > m_nWidth)
    {
      m_ptDragAdj.x = fAdjustment;
    }
    if (point.y < 0)
    {
      m_ptDragAdj.y = -fAdjustment;
    }
    else
    if (point.y > m_nHeight)
    {
      m_ptDragAdj.y = fAdjustment;
    }
    if (m_nTimerID == -1)
    {
      m_nTimerID = SetTimer(100, 50, NULL);
      m_ptDrag = point;
      m_ptDragTotal = 0;
    }
    return;
  }
  //else if (m_nTimerID != -1)
  if (m_nTimerID != -1)
  {
    KillTimer(m_nTimerID);
    pressx -= m_ptDragTotal.x;
    pressy += m_ptDragTotal.y;
    m_nTimerID = -1;
    //return;
  }

  bool bCrossHair = false;
  if (!m_bRButtonDown)
  {
    tdp[0] = tdp[1] = tdp[2] = 0.0;
    SnapToPoint (point.x, m_nHeight - 1 - point.y , tdp);

    g_strStatus.Format("x:: %.1f  y:: %.1f  z:: %.1f", tdp[0], tdp[1], tdp[2]);
    g_pParentWnd->SetStatusText(1, g_strStatus);

    // i need to generalize the point code.. having 3 flavors pretty much sucks.. 
    // once the new curve stuff looks like it is going to stick i will 
    // rationalize this down to a single interface.. 
    if (PointMode())
    {
      if (g_pMovingPoint && GetCapture() == this)
      {
        bCrossHair = true;
        SnapToPoint (point.x, m_nHeight - 1 - point.y , g_pMovingPoint->m_ptClip);
        g_pMovingPoint->UpdatePointPtr();
        Sys_UpdateWindows(XY | W_CAMERA_IFON);
      }
      else
      {
        g_pMovingPoint = NULL;
        int nDim1 = (m_nViewType == YZ) ? 1 : 0;
        int nDim2 = (m_nViewType == XY) ? 1 : 2;
        for (int n = 0; n < g_nPointCount; n++)
        {
          if ( fDiff(g_PointPoints[n].m_ptClip[nDim1], tdp[nDim1]) < 3 &&
               fDiff(g_PointPoints[n].m_ptClip[nDim2], tdp[nDim2]) < 3 )
          {
            bCrossHair = true;
            g_pMovingPoint = &g_PointPoints[n];
          }
        }
      }
    }
    else if (ClipMode())
    {
      if (g_pMovingClip && GetCapture() == this)
      {
        bCrossHair = true;
        SnapToPoint (point.x, m_nHeight - 1 - point.y , g_pMovingClip->m_ptClip);
        Sys_UpdateWindows(XY | W_CAMERA_IFON);
      }
      else
      {
        g_pMovingClip = NULL;
        int nDim1 = (m_nViewType == YZ) ? 1 : 0;
        int nDim2 = (m_nViewType == XY) ? 1 : 2;
        if (g_Clip1.Set())
        {
          if ( fDiff(g_Clip1.m_ptClip[nDim1], tdp[nDim1]) < 3 &&
               fDiff(g_Clip1.m_ptClip[nDim2], tdp[nDim2]) < 3 )
          {
            bCrossHair = true;
            g_pMovingClip = &g_Clip1;
          }
        }
        if (g_Clip2.Set())
        {
          if ( fDiff(g_Clip2.m_ptClip[nDim1], tdp[nDim1]) < 3 &&
               fDiff(g_Clip2.m_ptClip[nDim2], tdp[nDim2]) < 3 )
          {
            bCrossHair = true;
            g_pMovingClip = &g_Clip2;
          }
        }
        if (g_Clip3.Set())
        {
          if ( fDiff(g_Clip3.m_ptClip[nDim1], tdp[nDim1]) < 3 &&
               fDiff(g_Clip3.m_ptClip[nDim2], tdp[nDim2]) < 3 )
          {
            bCrossHair = true;
            g_pMovingClip = &g_Clip3;
          }
        }
      }
      if (bCrossHair == false)
        XY_MouseMoved (point.x, m_nHeight - 1 - point.y , nFlags);
    }
    else if (PathMode())
    {
      if (g_pMovingPath && GetCapture() == this)
      {
        bCrossHair = true;
        SnapToPoint (point.x, m_nHeight - 1 - point.y , g_pMovingPath->m_ptClip);
        Sys_UpdateWindows(XY | W_CAMERA_IFON);
      }
      else
      {
        g_pMovingPath = NULL;
        int nDim1 = (m_nViewType == YZ) ? 1 : 0;
        int nDim2 = (m_nViewType == XY) ? 1 : 2;
        for (int n = 0; n < g_nPathCount; n++)
        {
          if ( fDiff(g_PathPoints[n].m_ptClip[nDim1], tdp[nDim1]) < 3 &&
               fDiff(g_PathPoints[n].m_ptClip[nDim2], tdp[nDim2]) < 3 )
          {
            bCrossHair = true;
            g_pMovingPath = &g_PathPoints[n];
          }
        }
      }
    }
    else
    {
      XY_MouseMoved (point.x, m_nHeight - 1 - point.y , nFlags);
    }
  }
  else 
  {
    XY_MouseMoved (point.x, m_nHeight - 1 - point.y , nFlags);
  }
  if (bCrossHair)
    SetCursor(::LoadCursor(NULL, IDC_CROSS));
  else
    SetCursor(::LoadCursor(NULL, IDC_ARROW));
}

void CXYWnd::RetainClipMode(bool bMode)
{
  bool bSave = g_bRogueClipMode;
  SetClipMode(bMode);
  if (bMode == true)
    g_bRogueClipMode = bSave;
  else
    g_bRogueClipMode = false;
}

void CXYWnd::SetClipMode(bool bMode)
{
  g_bClipMode = bMode;
  g_bRogueClipMode = false;
  if (bMode)
  {
    g_Clip1.Reset();
    g_Clip2.Reset();
    g_Clip3.Reset();
    CleanList(&g_brFrontSplits);
    CleanList(&g_brBackSplits);
    g_brFrontSplits.next = &g_brFrontSplits;
    g_brBackSplits.next = &g_brBackSplits;
  }
  else
  {
    if (g_pMovingClip)
    {
      ReleaseCapture();
      g_pMovingClip = NULL;
    }
    CleanList(&g_brFrontSplits);
    CleanList(&g_brBackSplits);
    g_brFrontSplits.next = &g_brFrontSplits;
    g_brBackSplits.next = &g_brBackSplits;
    Sys_UpdateWindows(XY | W_CAMERA_IFON);
  }
}

bool CXYWnd::ClipMode()
{
  return g_bClipMode;
}

bool CXYWnd::RogueClipMode()
{
  return g_bRogueClipMode;
}

bool CXYWnd::PathMode()
{
  return g_bPathMode;
}


bool CXYWnd::PointMode()
{
  return g_bPointMode;
}

void CXYWnd::SetPointMode(bool b)
{
  g_bPointMode = b;
  if (!b)
    g_nPointCount = 0;
}


void CXYWnd::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
  bool bPaint = true;
  if (!qwglMakeCurrent(dc.m_hDC, s_hglrcXY))
  {
    Sys_Printf("ERROR: wglMakeCurrent failed.. Error:%i\n",qglGetError());
    Sys_Printf("Please restart Q3Radiant if the Map view is not working\n");
    bPaint = false;
  }
  if (bPaint)
  {
    QE_CheckOpenGLForErrors();
		XY_Draw ();
    QE_CheckOpenGLForErrors();

    if (m_nViewType != XY)
    {
      qglPushMatrix();
      if (m_nViewType == YZ)
        qglRotatef (-90,  0, 1, 0);	    // put Z going up
      qglRotatef (-90,  1, 0, 0);	    // put Z going up
    }
 
    if (g_bCrossHairs)
    {
	    qglColor4f(0.2, 0.9, 0.2, 0.8);
		  qglBegin (GL_LINES);
      if (m_nViewType == XY)
      {
        qglVertex2f(-16384, tdp[1]);
        qglVertex2f(16384, tdp[1]);
        qglVertex2f(tdp[0], -16384);
        qglVertex2f(tdp[0], 16384);
      }
      else if (m_nViewType == YZ)
      {
        qglVertex3f(tdp[0], -16384, tdp[2]);
        qglVertex3f(tdp[0], 16384, tdp[2]);
        qglVertex3f(tdp[0], tdp[1], -16384);
        qglVertex3f(tdp[0], tdp[1], 16384);
      }
      else
      {
        qglVertex3f(-16384, tdp[1], tdp[2]);
        qglVertex3f( 16384, tdp[1], tdp[2]);
        qglVertex3f(tdp[0], tdp[1], -16384);
        qglVertex3f(tdp[0], tdp[1], 16384);
      }
		  qglEnd();
    }

    if (ClipMode())
    {
      qglPointSize (4);
		  qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_CLIPPER]);
		  qglBegin (GL_POINTS);
      if (g_Clip1.Set())
			  qglVertex3fv (g_Clip1);
      if (g_Clip2.Set())

⌨️ 快捷键说明

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