예제 #1
0
        private void DrawInternal(DeviceContext pContext, BitmapResource pBitmap, Vector2 pPosition, Size pSize)
        {
            _effects[0].SetInput(0, pBitmap.DirectXBitmap, false);

            float widthFactor;
            float heightFactor;

            if (_useTiledScaling)
            {
                widthFactor  = Game.ActiveCamera.Zoom;
                heightFactor = Game.ActiveCamera.Zoom;
            }
            else
            {
                widthFactor  = pSize.Width / pBitmap.Width;
                heightFactor = pSize.Height / pBitmap.Height;
            }

            var scale = new SharpDX.Direct2D1.Effect(_context, Scale);

            scale.SetValue(0, new RawVector2(widthFactor, heightFactor));
            scale.SetInput(0, _effects[_effects.Count - 1].Output, false);

            if (pBitmap.Source.HasValue)
            {
                var r      = pBitmap.Source.Value;
                var source = new RawRectangleF(r.Left, r.Top, r.Left + pSize.Width, r.Top + pSize.Height);
                pContext.DrawImage(scale.Output, pPosition, source, InterpolationMode.Linear, CompositeMode.SourceOver);
            }
            else
            {
                pContext.DrawImage(_effects[_effects.Count - 1].Output, pPosition);
            }
        }
예제 #2
0
        /// <summary>
        /// Gets the input object for an effect.
        /// </summary>
        /// <param name="device">The device for which to get the input.</param>
        IDisposable IImageInternal.GetImageObject(EngineDevice device)
        {
            if (device.IsUsingFallbackMethodFor2D)
            {
                return(null);
            }

            D2D.Effect effect = m_loadedEffects[device.DeviceIndex];
            if (effect == null)
            {
                // Create the effect
                effect = BuildEffect(device);

                // Set input values
                for (int loop = 0; loop < m_effectInputs.Length; loop++)
                {
                    using (D2D.Image actInput = m_effectInputs[loop].GetImageObject(device) as D2D.Image)
                    {
                        effect.SetInput(loop, actInput, new SharpDX.Mathematics.Interop.RawBool(false));
                    }
                }

                // Store loaded effect
                m_loadedEffects[device.DeviceIndex] = effect;
            }

            return(effect.Output);
        }
예제 #3
0
        protected SharpDX.Direct2D1.Image Output(DeviceContext rDc)
        {
            D2DBitmap ntdx = null;

            try
            {
                ntdx = D2DBitmap.FromWicBitmap(rDc, _Pelete);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
            Image result1;

            var blEf = new SharpDX.Direct2D1.Effect(rDc, Effect.Opacity);

            blEf.SetInput(0, ntdx, new RawBool());
            blEf.SetValue(0, Opacity);

            result1 = blEf.Output;
            blEf.Dispose();
            if (size_changed)
            {
                var tfEf = new SharpDX.Direct2D1.Effects.AffineTransform2D(rDc);
                tfEf.SetInput(0, result1, new RawBool());

                result1.Dispose();
                var x_rate = _Size.Width / (double)_Pelete.Size.Width;
                var y_rate = _Size.Height / (double)_Pelete.Size.Height;
                tfEf.TransformMatrix = new RawMatrix3x2((float)x_rate, 0f, 0f, (float)y_rate, 0f, 0f);
                result1 = tfEf.Output;
                tfEf.Dispose();
            }
            if (Orientation != 1.0f)
            {
                var tfEf1 = new SharpDX.Direct2D1.Effects.AffineTransform2D(rDc);
                tfEf1.SetInput(0, result1, new RawBool());

                result1.Dispose();
                var mr32 = Matrix3x2.CreateRotation((float)Orientation, new Vector2(RotationPoint.X, RotationPoint.Y));
                tfEf1.TransformMatrix = new RawMatrix3x2(mr32.M11, mr32.M12, mr32.M21, mr32.M22, mr32.M31, mr32.M32);
                result1 = tfEf1.Output;
                tfEf1.Dispose();
            }
            if (this.Saturation != 1f)
            {
                var stEf = new SharpDX.Direct2D1.Effects.Saturation(rDc);
                stEf.SetInput(0, result1, new RawBool());

                result1.Dispose();
                stEf.Value = Saturation;
                result1    = stEf.Output;
                stEf.Dispose();
            }
            if (this.Brightness != 0.5f)
            {
                var btEf = new SharpDX.Direct2D1.Effects.Brightness(rDc);
                btEf.SetInput(0, result1, new RawBool());

                result1.Dispose();
                btEf.BlackPoint = new RawVector2(1.0f - Brightness, Brightness);
                //  btEf.WhitePoint =;
                result1 = btEf.Output;
                btEf.Dispose();
            }
            ntdx.Dispose();
            return(result1);
        }