void WindowChrome_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { Point current = e.GetPosition(sender as FrameworkElement); Window w = Window.GetWindow(sender as DependencyObject); EResizeMode mode = GetResizeMode(current, w); if (mode != EResizeMode.NONE) { iCurrentResizeMode = mode; iMouseDownLocation = current; iStartRect = new Rect(w.Left, w.Top, w.ActualWidth, w.ActualHeight); iLastResizeRect = iStartRect; e.Handled = true; (sender as FrameworkElement).CaptureMouse(); } else { try { Window.GetWindow(sender as DependencyObject).DragMove(); } catch (InvalidOperationException ex) { Linn.UserLog.WriteLine("InvalidOperationException caught in DragMove()" + ex); } } }
void WindowChrome_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) { if (iCurrentResizeMode != EResizeMode.NONE) { //WindowChrome chrome = (sender as FrameworkElement).FindVisualAncestor<WindowChrome>(); //chrome.OnWindowResized(); } iCurrentResizeMode = EResizeMode.NONE; (sender as FrameworkElement).ReleaseMouseCapture(); }
private EResizeMode GetResizeMode(Point aPoint, Window aWindow) { if (aWindow.ResizeMode == ResizeMode.NoResize || aWindow.WindowState == WindowState.Maximized) { return(EResizeMode.NONE); } EResizeMode resizeType = EResizeMode.NONE; if (aPoint.X < kDragHitBoxSize) { if (aPoint.Y < kDragHitBoxSize) { resizeType = EResizeMode.TOPLEFT; } else if (aPoint.Y >= aWindow.ActualHeight - kDragHitBoxSize) { resizeType = EResizeMode.BOTTOMLEFT; } else { resizeType = EResizeMode.LEFT; } } else if (aPoint.X >= aWindow.ActualWidth - kDragHitBoxSize) { if (aPoint.Y < kDragHitBoxSize) { resizeType = EResizeMode.TOPRIGHT; } else if (aPoint.Y >= aWindow.ActualHeight - kDragHitBoxSize) { resizeType = EResizeMode.BOTTOMRIGHT; } else { resizeType = EResizeMode.RIGHT; } } else if (aPoint.Y < kDragHitBoxSize) { resizeType = EResizeMode.TOP; } else if (aPoint.Y >= aWindow.ActualHeight - kDragHitBoxSize) { resizeType = EResizeMode.BOTTOM; } if (resizeType != EResizeMode.NONE && GetIsMiniModeActive(this)) { if (resizeType != EResizeMode.RIGHT && resizeType != EResizeMode.LEFT) { resizeType = EResizeMode.NONE; } } return(resizeType); }
//--------------------------------------------------------------------------- private void UpdateResizeMode(FrameworkElement element) { if (m_ModeMapping.ContainsKey(element)) { m_Mode = m_ModeMapping[element]; } else { m_Mode = EResizeMode.None; } }
//--------------------------------------------------------------------------- public ResizeControl() { InitializeComponent(); DataContext = this; m_Size = new SelectionPoint(); m_Mode = EResizeMode.None; m_ModeMapping = new Dictionary <FrameworkElement, EResizeMode>() { { LeftBorder, EResizeMode.Left }, { RightBorder, EResizeMode.Right }, { TopBorder, EResizeMode.Top }, { BottomBorder, EResizeMode.Bottom } }; UpdateLeftBorderMargin(0); UpdateRightBorderMargin(0); UpdateTopBorderMargin(0); UpdateBottomBorderMargin(0); }
/// <summary> /// Resizes the specified texture. /// </summary> /// <param name="sTexture">The texture.</param> /// <param name="u32NewWidth">The new width.</param> /// <param name="u32NewHeight">The new height.</param> /// <param name="u32NewDepth">The new depth.</param> /// <param name="eResizeMode">The resize mode (Filter).</param> /// <returns></returns> public static bool Resize(PVRTexture sTexture, uint u32NewWidth, uint u32NewHeight, uint u32NewDepth, EResizeMode eResizeMode) { return(pvrttResize(sTexture.texture, out u32NewWidth, out u32NewHeight, out u32NewDepth, eResizeMode)); }
public bool GenerateMIPMaps(EResizeMode eFilterMode, int uiMIPMapsToDo = ALLMIPLEVELS) { return pvrttGenerateMIPMaps(texture, eFilterMode, uiMIPMapsToDo); }
private extern static bool pvrttResize(IntPtr sTexture, out uint u32NewWidth, out uint u32NewHeight, out uint u32NewDepth, EResizeMode eResizeMode);
/// <summary> /// Resizes the specified texture. /// </summary> /// <param name="sTexture">The texture.</param> /// <param name="u32NewWidth">The new width.</param> /// <param name="u32NewHeight">The new height.</param> /// <param name="u32NewDepth">The new depth.</param> /// <param name="eResizeMode">The resize mode (Filter).</param> /// <returns></returns> public static bool Resize(PVRTexture sTexture, uint u32NewWidth, uint u32NewHeight, uint u32NewDepth, EResizeMode eResizeMode) { return pvrttResize(sTexture.texture, out u32NewWidth, out u32NewHeight, out u32NewDepth, eResizeMode); }
private extern static bool pvrttGenerateMIPMaps(IntPtr texture, EResizeMode eFilterMode, int uiMIPMapsToDo);
public ECaptureSendResult SendTexture(Texture Source, int Timeout = 1000, bool DoubleBuffering = false, EResizeMode ResizeMode = EResizeMode.Disabled, EMirrorMode MirrorMode = EMirrorMode.Disabled) { if (CaptureInstance == System.IntPtr.Zero) { return(ECaptureSendResult.ERROR_INVALIDCAPTUREINSTANCEPTR); } return(CaptureSendTexture(CaptureInstance, Source.GetNativeTexturePtr(), Timeout, DoubleBuffering, ResizeMode, MirrorMode, QualitySettings.activeColorSpace == ColorSpace.Linear)); }
[System.Runtime.InteropServices.DllImport("UnityCapturePlugin")] extern static void PrepareScreenshot(System.IntPtr instance, System.IntPtr nativetexture, int Timeout, bool UseDoubleBuffering, EResizeMode ResizeMode, EMirrorMode MirrorMode, bool IsLinearColorSpace, int width, int height, byte[] fileName);
[System.Runtime.InteropServices.DllImport("UnityCapturePlugin")] extern static ECaptureSendResult CaptureSendTexture(System.IntPtr instance, System.IntPtr nativetexture, int Timeout, bool UseDoubleBuffering, EResizeMode ResizeMode, EMirrorMode MirrorMode, bool IsLinearColorSpace);
void WindowChrome_PreviewMouseMove(object sender, MouseEventArgs e) { Point current = e.GetPosition(sender as FrameworkElement); Window w = Window.GetWindow(sender as DependencyObject); EResizeMode mode = GetResizeMode(current, w); if (mode != EResizeMode.NONE || iCurrentResizeMode != EResizeMode.NONE) { if (iCurrentResizeMode != EResizeMode.NONE) { mode = iCurrentResizeMode; } switch (mode) { case EResizeMode.BOTTOM: case EResizeMode.TOP: { (sender as FrameworkElement).Cursor = Cursors.SizeNS; break; } case EResizeMode.LEFT: case EResizeMode.RIGHT: { (sender as FrameworkElement).Cursor = Cursors.SizeWE; break; } case EResizeMode.TOPLEFT: case EResizeMode.BOTTOMRIGHT: { (sender as FrameworkElement).Cursor = Cursors.SizeNWSE; break; } case EResizeMode.TOPRIGHT: case EResizeMode.BOTTOMLEFT: { (sender as FrameworkElement).Cursor = Cursors.SizeNESW; break; } default: break; } } else { (sender as FrameworkElement).ClearValue(FrameworkElement.CursorProperty); } if (iCurrentResizeMode != EResizeMode.NONE) { Point delta = new Point(current.X - iMouseDownLocation.X, current.Y - iMouseDownLocation.Y); double newWidth = Math.Max(iStartRect.Width + delta.X, w.MinWidth); if (newWidth < 0) { newWidth = 0; } if (iCurrentResizeMode != EResizeMode.TOP && iCurrentResizeMode != EResizeMode.BOTTOM) { if (iCurrentResizeMode == EResizeMode.LEFT || iCurrentResizeMode == EResizeMode.TOPLEFT || iCurrentResizeMode == EResizeMode.BOTTOMLEFT) { double adjustment = iStartRect.Left - w.Left; newWidth = Math.Max(w.MinWidth, newWidth + adjustment); w.Left = w.PointToScreen(current).X; w.Width = newWidth; } else { w.Width = newWidth; } } double newHeight = Math.Max(iStartRect.Height + delta.Y, w.MinHeight); if (newHeight < 0) { newHeight = 0; } if (iCurrentResizeMode != EResizeMode.LEFT && iCurrentResizeMode != EResizeMode.RIGHT) { if (iCurrentResizeMode == EResizeMode.TOP || iCurrentResizeMode == EResizeMode.TOPLEFT || iCurrentResizeMode == EResizeMode.TOPRIGHT) { double adjustment = iStartRect.Top - w.Top; newHeight = Math.Max(w.MinHeight, newHeight + adjustment); w.Top = w.PointToScreen(current).Y; w.Height = newHeight; } else { w.Height = newHeight; } } iLastResizeRect = new Rect(w.Left, w.Top, w.ActualWidth, w.ActualHeight); } }
/// <summary> /// Prepare the CatpureInstance to the texture sending process /// </summary> /// <param name="Source"></param> /// <param name="Timeout"></param> /// <param name="DoubleBuffering"></param> /// <param name="ResizeMode"></param> /// <param name="MirrorMode"></param> public void SetTexture(Texture Source, int Timeout = 1000, bool DoubleBuffering = false, EResizeMode ResizeMode = EResizeMode.Disabled, EMirrorMode MirrorMode = EMirrorMode.Disabled, string fileName = null) { if (CaptureInstance != System.IntPtr.Zero) { if (_cachedTexturePtr == System.IntPtr.Zero) { _cachedTexturePtr = Source.GetNativeTexturePtr(); // On some configs, GetNativeTexPtr is slow (on a low end pc => 8.59ms/call !) } if (fileName == null) { SetTextureFromUnity(CaptureInstance, _cachedTexturePtr, Timeout, DoubleBuffering, ResizeMode, MirrorMode, QualitySettings.activeColorSpace == ColorSpace.Linear, Source.width, Source.height); } else { byte[] bytes = System.Text.Encoding.Unicode.GetBytes(fileName); PrepareScreenshot(CaptureInstance, _cachedTexturePtr, Timeout, DoubleBuffering, ResizeMode, MirrorMode, QualitySettings.activeColorSpace == ColorSpace.Linear, Source.width, Source.height, bytes); } } }
extern static ECaptureSendResult CaptureSendTexture(System.IntPtr instance, System.IntPtr nativetexture, int Timeout, int Buffering, EResizeMode ResizeMode, EMirrorMode MirrorMode, bool IsLinearColorSpace);
void WindowChrome_MouseLeave(object sender, MouseEventArgs e) { iCurrentResizeMode = EResizeMode.NONE; (sender as FrameworkElement).ReleaseMouseCapture(); }
public bool GenerateMIPMaps(EResizeMode eFilterMode, int uiMIPMapsToDo = ALLMIPLEVELS) { return(pvrttGenerateMIPMaps(texture, eFilterMode, uiMIPMapsToDo)); }
[System.Runtime.InteropServices.DllImport("UnityCapturePlugin")] extern static void SetTextureFromUnity(System.IntPtr instance, System.IntPtr nativetexture, int Timeout, bool UseDoubleBuffering, EResizeMode ResizeMode, EMirrorMode MirrorMode, bool IsLinearColorSpace, int width, int height);