//----------------------------------------------------------------------------- // Purpose: Renders this region as a wireframe box. // Input : pRender - 3D Renderer. //----------------------------------------------------------------------------- void Box3D::RenderTool3D(CRender3D *pRender) { if ( IsTranslating() ) { VMatrix matrix = GetTransformMatrix(); pRender->BeginLocalTransfrom( matrix ); } else if (IsEmpty()) { return; } pRender->PushRenderMode( RENDER_MODE_FLAT ); pRender->SetDrawColor( GetRValue(m_clrBox), GetGValue(m_clrBox), GetBValue(m_clrBox) ); pRender->DrawBox( bmins, bmaxs ); pRender->PopRenderMode(); if ( IsTranslating() ) { pRender->EndLocalTransfrom(); if ( m_TranslateMode == modeMove || m_TranslateMode == modeRotate ) { Vector vec = m_vTranslationFixPoint; if ( m_TranslateMode == modeMove ) { TranslatePoint( vec ); } // draw 'X' pRender->PushRenderMode( RENDER_MODE_FLAT_NOZ ); pRender->SetHandleStyle( 7, CRender::HANDLE_CROSS ); pRender->SetHandleColor( GetRValue(Options.colors.clrToolDrag), GetGValue(Options.colors.clrToolDrag), GetBValue(Options.colors.clrToolDrag) ); pRender->DrawHandle( vec ); pRender->PopRenderMode(); } } else if ( m_bEnableHandles ) { RenderHandles3D( pRender, bmins, bmaxs ); }; }
//----------------------------------------------------------------------------- // Purpose: Renders a selection gizmo at our bounds center. // Input : pRender - Rendering interface. //----------------------------------------------------------------------------- void Marker3D::RenderTool3D(CRender3D *pRender) { if (!IsActiveTool()) { return; } Vector *pPos; if (IsTranslating()) { pPos = &m_vecTranslatePos; } else { if (IsEmpty()) { return; } pPos = &m_vecPos; } // // Setup the renderer. // pRender->SetRenderMode(RENDER_MODE_WIREFRAME); CMeshBuilder meshBuilder; IMesh* pMesh = MaterialSystemInterface()->GetDynamicMesh(); meshBuilder.Begin(pMesh, MATERIAL_LINES, 3); meshBuilder.Position3f(g_MIN_MAP_COORD, (*pPos)[1], (*pPos)[2]); meshBuilder.Color3ub(255, 0, 0); meshBuilder.AdvanceVertex(); meshBuilder.Position3f(g_MAX_MAP_COORD, (*pPos)[1], (*pPos)[2]); meshBuilder.Color3ub(255, 0, 0); meshBuilder.AdvanceVertex(); meshBuilder.Position3f((*pPos)[0], g_MIN_MAP_COORD, (*pPos)[2]); meshBuilder.Color3ub(0, 255, 0); meshBuilder.AdvanceVertex(); meshBuilder.Position3f((*pPos)[0], g_MAX_MAP_COORD, (*pPos)[2]); meshBuilder.Color3ub(0, 255, 0); meshBuilder.AdvanceVertex(); meshBuilder.Position3f((*pPos)[0], (*pPos)[1], g_MIN_MAP_COORD); meshBuilder.Color3ub(0, 0, 255); meshBuilder.AdvanceVertex(); meshBuilder.Position3f((*pPos)[0], (*pPos)[1], g_MAX_MAP_COORD); meshBuilder.Color3ub(0, 0, 255); meshBuilder.AdvanceVertex(); meshBuilder.End(); pMesh->Draw(); pRender->SetRenderMode(RENDER_MODE_DEFAULT); }
//----------------------------------------------------------------------------- // Purpose: Handles the escape key in the 2D or 3D views. //----------------------------------------------------------------------------- void Cordon3D::OnEscape(void) { if ( IsTranslating() ) { FinishTranslation( false ); } else { m_pDocument->GetTools()->SetTool(TOOL_POINTER); } }
//----------------------------------------------------------------------------- // Purpose: Handles left mouse button up events in the 2D view. // Input : Per CWnd::OnLButtonUp. // Output : Returns true if the message was handled, false if not. //----------------------------------------------------------------------------- bool Cordon3D::OnLMouseUp2D(CMapView2D *pView, UINT nFlags, const Vector2D &vPoint) { Tool3D::OnLMouseUp2D(pView, nFlags, vPoint) ; if ( IsTranslating() ) { FinishTranslation( true ); m_pDocument->SetCordon( bmins, bmaxs ); } m_pDocument->UpdateStatusbar(); return true; }
//----------------------------------------------------------------------------- // Purpose: Handles left mouse button up events in the 2D view. // Input : Per CWnd::OnLButtonUp. // Output : Returns true if the message was handled, false if not. //----------------------------------------------------------------------------- bool Clipper3D::OnLMouseUp2D(CMapView2D *pView, UINT nFlags, CPoint point) { ReleaseCapture(); if (IsTranslating()) { m_bLButtonDown = false; FinishTranslation(TRUE); m_pDocument->ToolUpdateViews(CMapView2D::updTool); } m_pDocument->UpdateStatusbar(); return true; }
//----------------------------------------------------------------------------- // Purpose: // Input : pRender - //----------------------------------------------------------------------------- void Marker3D::RenderTool2D(CRender2D *pRender) { if (!IsActiveTool()) { return; } Vector vecPos; CRect rect; CPoint pt; if (IsTranslating()) { vecPos = m_vecTranslatePos; } else { if (IsEmpty()) { return; } vecPos = m_vecPos; } pt.x = vecPos[axHorz]; pt.y = vecPos[axVert]; PointToScreen(pt); pRender->SetLineType(CRender2D::LINE_SOLID, CRender2D::LINE_THIN, 35, 255, 75); // // Draw center rect. // rect.SetRect(pt, pt); rect.InflateRect(6, 6); pRender->Rectangle(rect, false); // // Draw crosshairs. // pRender->MoveTo(g_MIN_MAP_COORD, pt.y); pRender->LineTo(g_MAX_MAP_COORD, pt.y); pRender->MoveTo(pt.x, g_MIN_MAP_COORD); pRender->LineTo(pt.x, g_MAX_MAP_COORD); }
//----------------------------------------------------------------------------- // Purpose: Handles mouse move events in the 2D view. // Input : Per CWnd::OnMouseMove. // Output : Returns true if the message was handled, false if not. //----------------------------------------------------------------------------- bool Cordon3D::OnMouseMove2D(CMapView2D *pView, UINT nFlags, const Vector2D &vPoint) { vgui::HCursor hCursor = vgui::dc_arrow; Tool3D::OnMouseMove2D(pView, nFlags, vPoint) ; unsigned int uConstraints = GetConstraints( nFlags ); // Convert to world coords. Vector vecWorld; pView->ClientToWorld(vecWorld, vPoint); // Update status bar position display. // char szBuf[128]; m_pDocument->Snap(vecWorld,uConstraints); sprintf(szBuf, " @%.0f, %.0f ", vecWorld[pView->axHorz], vecWorld[pView->axVert]); SetStatusText(SBI_COORDS, szBuf); if ( IsTranslating() ) { // cursor is cross here Tool3D::UpdateTranslation( pView, vPoint, uConstraints ); hCursor = vgui::dc_none; } else if ( HitTest(pView, vPoint, true) ) { hCursor = UpdateCursor( pView, m_LastHitTestHandle, m_TranslateMode ); } if ( hCursor != vgui::dc_none ) pView->SetCursor( hCursor ); return true; }
//----------------------------------------------------------------------------- // Purpose: // Input : *pDC - // bounds - //----------------------------------------------------------------------------- void Box3D::RenderTool2D(CRender2D *pRender) { Vector mins = bmins; Vector maxs = bmaxs; CMapView2D *pView = (CMapView2D*)pRender->GetView(); Assert( pRender ); if ( IsTranslating() ) { TranslateBox( mins, maxs ); } else if ( IsEmpty() ) { return; } if ( m_dwDrawFlags & boundstext) { DrawBoundsText(pRender, mins, maxs, DBT_TOP | DBT_LEFT); } if ( IsTranslating() ) { pRender->PushRenderMode( RENDER_MODE_DOTTED ); pRender->SetDrawColor( GetRValue(Options.colors.clrToolDrag), GetGValue(Options.colors.clrToolDrag), GetBValue(Options.colors.clrToolDrag) ); } else if (!(m_dwDrawFlags & thicklines)) { pRender->PushRenderMode( RENDER_MODE_DOTTED ); pRender->SetDrawColor( GetRValue(m_clrBox), GetGValue(m_clrBox), GetBValue(m_clrBox) ); } else { pRender->PushRenderMode( RENDER_MODE_FLAT_NOZ ); pRender->SetDrawColor( GetRValue(m_clrBox), GetGValue(m_clrBox), GetBValue(m_clrBox) ); } // render bounds if ( !IsTranslating() || m_TranslateMode == modeScale || m_TranslateMode == modeMove ) { // draw simple rectangle pRender->DrawRectangle( mins, maxs, false, 0 ); } else { // during rotation or shearing, draw transformed bounding box Vector v[4]; // init all points to center v[0] = v[1] = v[2] = v[3] = (bmins+bmaxs) / 2; int axis = pView->axHorz; v[0][axis] = v[1][axis] = bmins[axis]; v[2][axis] = v[3][axis] = bmaxs[axis]; axis = pView->axVert; v[1][axis] = v[2][axis] = bmins[axis]; v[0][axis] = v[3][axis] = bmaxs[axis]; for ( int i=0; i<4; i++) { TranslatePoint( v[i] ); } pRender->DrawLine( v[0], v[1] ); pRender->DrawLine( v[1], v[2] ); pRender->DrawLine( v[2], v[3] ); pRender->DrawLine( v[3], v[0] ); } pRender->PopRenderMode(); // draw a cross for translation origin in move or rotation mode if ( IsTranslating() ) { if ( m_TranslateMode == modeMove || m_TranslateMode == modeRotate ) { Vector vec = m_vTranslationFixPoint; if ( m_TranslateMode == modeMove ) { TranslatePoint( vec ); } // draw 'X' pRender->SetHandleStyle( 7, CRender::HANDLE_CROSS ); pRender->SetHandleColor( GetRValue(Options.colors.clrToolDrag), GetGValue(Options.colors.clrToolDrag), GetBValue(Options.colors.clrToolDrag) ); pRender->DrawHandle( vec ); } } else if ( m_bEnableHandles ) { RenderHandles2D( pRender, mins, maxs ); } }
//----------------------------------------------------------------------------- // Purpose: // Input : pszBuf - //----------------------------------------------------------------------------- void Box3D::GetStatusString(char *pszBuf) { *pszBuf = '\0'; Vector mins(0,0,0); Vector maxs(0,0,0); if ( IsValidBox() ) { mins = bmins; maxs = bmaxs; } if ( IsTranslating() ) { TranslateBox( mins, maxs ); } Vector size = maxs - mins; Vector center = ( maxs + mins ) * 0.5f; if ( !IsTranslating() || m_TranslateMode == modeScale || m_TranslateMode == modeMove ) { if (!IsEmpty()) { if ( IsTranslating() && m_TranslateMode == modeMove ) { center = m_vTranslationFixPoint; TranslatePoint( center ); } switch (m_eWorldUnits) { case Units_None: { sprintf(pszBuf, " %dw %dl %dh @(%.0f %.0f %.0f)", (int)fabs(size.x), (int)fabs(size.y), (int)fabs(size.z), center.x,center.y,center.z ); break; } case Units_Inches: { sprintf(pszBuf, " %d\"w %d\"l %d\"h", (int)fabs(size.x), (int)fabs(size.y), (int)fabs(size.z)); break; } case Units_Feet_Inches: { int nFeetWide = (int)fabs(size.x) / 12; int nInchesWide = (int)fabs(size.x) % 12; int nFeetLong = (int)fabs(size.y) / 12; int nInchesLong = (int)fabs(size.y) % 12; int nFeetHigh = (int)fabs(size.z) / 12; int nInchesHigh = (int)fabs(size.z) % 12; sprintf(pszBuf, " %d' %d\"w %d' %d\"l %d' %d\"h", nFeetWide, nInchesWide, nFeetLong, nInchesLong, nFeetHigh, nInchesHigh); break; } } } } else if ( m_TranslateMode == modeShear ) { sprintf(pszBuf, " shear: %d %d %d ", (int)m_vTranslation.x, (int)m_vTranslation.y, (int)m_vTranslation.z ); } else if ( m_TranslateMode == modeRotate ) { int rotAxis = GetTransformationAxis(); if ( rotAxis != -1 ) { sprintf(pszBuf, " %.2f%c", m_vTranslation[abs(rotAxis+2)%3], 0xF8); } else { sprintf(pszBuf, " %.2f %.2f %.2f%c", m_vTranslation.x, m_vTranslation.y, m_vTranslation.z, 0xF8); } } else { Assert( 0 ); } }
//----------------------------------------------------------------------------- // Purpose: Handles mouse move events in the 2D view. // Input : Per CWnd::OnMouseMove. // Output : Returns true if the message was handled, false if not. //----------------------------------------------------------------------------- bool Clipper3D::OnMouseMove2D(CMapView2D *pView, UINT nFlags, CPoint point) { CMapDoc *pDoc = pView->GetDocument(); if (!pDoc) { return false; } bool bCursorSet = false; BOOL bDisableSnap = (GetAsyncKeyState(VK_MENU) & 0x8000) ? TRUE : FALSE; // // Make sure the point is visible. // if (m_bLButtonDown) { pView->ToolScrollToPoint(point); } // // Convert to some odd coordinate space that the base tools code uses. // CPoint ptScreen = point; ptScreen.x += pView->GetScrollPos(SB_HORZ); ptScreen.y += pView->GetScrollPos(SB_VERT); // // Convert to world coords. // Vector vecWorld; pView->ClientToWorld(vecWorld, point); point.x = vecWorld[axHorz]; point.y = vecWorld[axVert]; // // Update status bar position display. // char szBuf[128]; m_pDocument->Snap(vecWorld); sprintf(szBuf, " @%.0f, %.0f ", vecWorld[axHorz], vecWorld[axVert]); SetStatusText(SBI_COORDS, szBuf); if (IsTranslating()) { // cursor is cross here bCursorSet = true; UINT uConstraints = 0; if (bDisableSnap) { uConstraints |= Tool3D::constrainNosnap; } if(nFlags & MK_CONTROL) { uConstraints |= Clipper3D::constrainMoveBoth; } if (UpdateTranslation(point, uConstraints, CSize(0,0))) { pDoc->ToolUpdateViews(CMapView2D::updTool); pDoc->Update3DViews(); } } else if (!IsEmpty()) { // // If the cursor is on a handle, set it to a cross. // if (HitTest(ptScreen, TRUE) != -1) { SetCursor(AfxGetApp()->LoadStandardCursor(IDC_CROSS)); bCursorSet = true; } } if (!bCursorSet) { SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW)); } return true; }
//----------------------------------------------------------------------------- // Purpose: // Input : pView - // nFlags - // point - // Output : Returns true on success, false on failure. //----------------------------------------------------------------------------- bool Marker3D::OnMouseMove2D(CMapView2D *pView, UINT nFlags, CPoint point) { CMapDoc *pDoc = pView->GetDocument(); if (!pDoc) { return false; } bool bCursorSet = false; unsigned int uConstraints = 0; if ((GetAsyncKeyState(VK_MENU) & 0x8000)) { uConstraints |= Tool3D::constrainNosnap; } // // Make sure the point is visible. // if (m_bLButtonDown) { pView->ToolScrollToPoint(point); } // // Convert to some odd coordinate space that the base tools code uses. // CPoint ptHitTest = point; ptHitTest.x += pView->GetScrollPos(SB_HORZ); ptHitTest.y += pView->GetScrollPos(SB_VERT); // // Convert to world coords. // Vector vecWorld; pView->ClientToWorld(vecWorld, point); point.x = vecWorld[axHorz]; point.y = vecWorld[axVert]; // // Update status bar position display. // char szBuf[128]; m_pDocument->Snap(vecWorld); sprintf(szBuf, " @%.0f, %.0f ", vecWorld[axHorz], vecWorld[axVert]); SetStatusText(SBI_COORDS, szBuf); // // If we are currently dragging the marker, update that operation based on // the current cursor position and keyboard state. // if (IsTranslating()) { if (UpdateTranslation(point, uConstraints, CSize(0,0))) { pDoc->ToolUpdateViews(CMapView2D::updTool); pDoc->Update3DViews(); } // Don't change the cursor while dragging - it should remain a cross. bCursorSet = true; SetCursor(AfxGetApp()->LoadStandardCursor(IDC_CROSS)); } else if (!IsEmpty()) { // Don't change the cursor while dragging - it should remain a cross. bCursorSet = true; SetCursor(AfxGetApp()->LoadStandardCursor(IDC_CROSS)); } if (!bCursorSet) { SetCursor(s_hcurEntity); } return true; }