/// <summary> /// Initializes a new instance of the <see cref="Graphics2D"/> class. /// </summary> /// <param name="device">The hardware device which is used for rendering.</param> /// <param name="renderTarget">The render target which is used by this graphics object.</param> /// <param name="screenSize">The size of the screen in device independent pixels.</param> internal Graphics2D(EngineDevice device, D2D.RenderTarget renderTarget, Size2F screenSize) { m_transformSettings = Graphics2DTransformSettings.Default; m_transformStack = new Matrix3x2Stack(); m_device = device; m_renderTarget = renderTarget; m_screenPixelSize = screenSize; m_deviceContext = m_renderTarget as D2D.DeviceContext; }
/// <summary> /// Sets current transform settings on this graphics object. /// (be carefull, the state is changed on device level!) /// </summary> /// <param name="transformSettings">The settings to be set.</param> internal void PushTransformSettings(Graphics2DTransformSettings transformSettings) { m_transformSettings = transformSettings; switch (transformSettings.TransformMode) { // Overtake given scaling matrix case Graphics2DTransformMode.Custom: m_transformStack.Push(transformSettings.CustomTransform); break; // Calculate scaling matrix here case Graphics2DTransformMode.AutoScaleToVirtualScreen: float virtualWidth = m_transformSettings.VirtualScreenSize.Width; float virtualHeight = m_transformSettings.VirtualScreenSize.Height; if (virtualWidth == 0f) { virtualWidth = m_screenPixelSize.Width; } if (virtualHeight == 0f) { virtualHeight = m_screenPixelSize.Height; } float scaleFactorX = m_screenPixelSize.Width / virtualWidth; float scaleFactorY = m_screenPixelSize.Height / virtualHeight; float combinedScaleFactor = Math.Min(scaleFactorX, scaleFactorY); float truePixelWidth = virtualWidth * combinedScaleFactor; float truePixelHeight = virtualHeight * combinedScaleFactor; m_transformStack.Push(); m_transformStack.TransformLocal( Matrix3x2.CreateScale(combinedScaleFactor) * Matrix3x2.CreateTranslation( m_screenPixelSize.Width / 2f - truePixelWidth / 2f, m_screenPixelSize.Height / 2f - truePixelHeight / 2f)); break; default: throw new SeeingSharpGraphicsException($"Unable to handle transform mode {transformSettings.TransformMode}"); } // Apply current transform this.ApplyTransformStack(); }