private void Draw(SurfaceState state, SurfaceDrawInstance inst) { float destX = inst.DestLocation.X; float destY = inst.DestLocation.Y; Rectangle srcRect = inst.GetSourceRect(SurfaceSize); SizeF displaySize = state.GetDisplaySize(srcRect.Size); PointF rotationCenter = state.GetRotationCenter(displaySize); bool alphaBlend = true; float mRotationCos = (float)Math.Cos(state.RotationAngle); float mRotationSin = (float)Math.Sin(state.RotationAngle); srcRect.X += mSrcRect.Left; srcRect.Y += mSrcRect.Top; if (displaySize.Width < 0) { destX -= displaySize.Width; rotationCenter.X += displaySize.Width; } if (displaySize.Height < 0) { destY -= displaySize.Height; rotationCenter.Y += displaySize.Height; } mDevice.Interpolation = InterpolationHint; SetVertsTextureCoordinates(mVerts, 0, srcRect); SetVertsColor(state.ColorGradient, mVerts, 0, 4); SetVertsPosition(mVerts, 0, new RectangleF(destX, destY, srcRect.Width * (float)state.ScaleWidth, srcRect.Height * (float)state.ScaleHeight), rotationCenter.X, rotationCenter.Y, state.DisplayAlignment, mRotationCos, mRotationSin); mDevice.DrawBuffer.CacheDrawIndexedTriangles(mVerts, mIndices, mTexture.Value, alphaBlend); }
private void Draw(SurfaceState s, SurfaceDrawInstance inst) { mDisplay.CheckInFrame("Surface.Draw"); System.Diagnostics.Debug.Assert(mImage != null); Geometry.SizeF displaySize = s.GetDisplaySize(SurfaceSize); Geometry.PointF rotationCenter = s.GetRotationCenter(displaySize); Drawing_Display disp = Display.Impl as Drawing_Display; Graphics g = disp.FrameGraphics; GraphicsState state = g.Save(); Geometry.PointF translatePoint = Origin.CalcF(s.DisplayAlignment, displaySize); if (displaySize.Width < 0) { translatePoint.X += displaySize.Width; rotationCenter.X += displaySize.Width; } if (displaySize.Height < 0) { translatePoint.Y += displaySize.Height; rotationCenter.Y += displaySize.Height; } if (s.RotationAngle != 0) { // translate to rotation point, rotate, and translate back. // System.Drawing rotates Clockwise! So we must reverse the // rotation angle. g.TranslateTransform(-rotationCenter.X, -rotationCenter.Y, MatrixOrder.Append); g.RotateTransform(-(float)s.RotationAngleDegrees, MatrixOrder.Append); g.TranslateTransform(rotationCenter.X, rotationCenter.Y, MatrixOrder.Append); } g.TranslateTransform(inst.DestLocation.X - translatePoint.X, inst.DestLocation.Y - translatePoint.Y, MatrixOrder.Append); SetInterpolation(g); Geometry.Rectangle srcRect = inst.GetSourceRect(SurfaceSize); if (s.Color != Geometry.Color.White) { ImageAttributes imageAttributes = new ImageAttributes(); ColorMatrix colorMatrix = new ColorMatrix(new float[][] { new float[] { s.Color.R / 255.0f, 0.0f, 0.0f, 0.0f, 0.0f }, new float[] { 0.0f, s.Color.G / 255.0f, 0.0f, 0.0f, 0.0f }, new float[] { 0.0f, 0.0f, s.Color.B / 255.0f, 0.0f, 0.0f }, new float[] { 0.0f, 0.0f, 0.0f, (float)s.Alpha, 0.0f }, new float[] { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f } }); imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); g.DrawImage(mImage, Interop.Convert(DestRect(0, 0, srcRect, s.ScaleWidth, s.ScaleHeight)), srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, GraphicsUnit.Pixel, imageAttributes); } else { g.DrawImage(mImage, Interop.Convert(DestRect(0, 0, srcRect, s.ScaleWidth, s.ScaleHeight)), srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, GraphicsUnit.Pixel); } g.Restore(state); }