Esempio n. 1
0
 public void SetForeground(System.Drawing.Color color)
 {
     if (ctx.InvokeRequired)
     {
         ColorDelegate c = new ColorDelegate(SetForeground);
         ctx.Invoke(c, new object[] { color });
         return;
     }
     fg = color;
     output.ForeColor = fg;
     input.ForeColor  = fg;
 }
Esempio n. 2
0
        public static IEnumerator DoFadeColor(ColorDelegate colorDelegate, Color32 fromColor, Color32 toColor, float fadeDuration)
        {
            float currentTime = 0f;

            while (currentTime <= fadeDuration)
            {
                float timeProportion = currentTime / fadeDuration;

                Color32 newColor = Color.Lerp(fromColor, toColor, timeProportion);

                colorDelegate(newColor);
                currentTime += Time.timeScale == 0f ? Time.fixedUnscaledDeltaTime : Time.fixedDeltaTime;

                yield return(null);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Converts source bitmap from 24bppRGB to 1bppIndexed and returns converted Bitmap.
        /// Color conversion algorithm is provided by ColorDelegate.
        /// </summary>
        public static unsafe Bitmap rgbTo1bppIndexed(Bitmap source, ColorDelegate colorDelegate)
        {
            if (source.PixelFormat != PixelFormat.Format24bppRgb)
            {
                throw new ArgumentException("Unsuported Bitmap format! Expected PixelFormat.Format24bppRgb");
            }
            int        width = source.Width, height = source.Height;
            Bitmap     converted             = new Bitmap(width, height, PixelFormat.Format1bppIndexed);
            Rectangle  rectangle             = new Rectangle(0, 0, width, height);
            BitmapData sourceData            = source.LockBits(rectangle, ImageLockMode.ReadOnly, source.PixelFormat);
            BitmapData convertedData         = converted.LockBits(rectangle, ImageLockMode.ReadWrite, converted.PixelFormat);
            byte *     sourcePixelPointer    = (byte *)sourceData.Scan0;
            byte *     convertedPixelPointer = (byte *)convertedData.Scan0;
            int        sourceLine            = -sourceData.Stride;
            int        convertedLine         = -convertedData.Stride;

            for (int y = 0; y < height; ++y)
            {
                sourceLine    += sourceData.Stride;
                convertedLine += convertedData.Stride;
                int sourcePixel = sourceLine - 3;
                for (int x = 0; x < width; ++x)
                {
                    sourcePixel += 3;                                 // index for source pixel (24bbp, rgb format)
                    int   convertedPixels = convertedLine + (x >> 3); // destination byte for pixel (1bpp, ie 8pixels per byte)
                    Color pixelColor      = Color.FromArgb(0, sourcePixelPointer[sourcePixel], sourcePixelPointer[sourcePixel + 1], sourcePixelPointer[sourcePixel + 2]);
                    if (colorDelegate(pixelColor))
                    {
                        convertedPixelPointer[convertedPixels] |= (byte)(0x80 >> (x & 0x7));    // mask out pixel bit in destination byte
                    }
                }
            }
            source.UnlockBits(sourceData);
            converted.UnlockBits(convertedData);
            return(converted);
        }
Esempio n. 4
0
 public static void ColorHandles(Color color, ColorDelegate colorFun)
 {
     UnityEditor.Handles.color = color;
     colorFun();
     ResetColorHandles();
 }
Esempio n. 5
0
 public static void ColorGUI(Color color, ColorDelegate colorFun)
 {
     GUI.color = color;
     colorFun();
     ResetColorGUI();
 }
Esempio n. 6
0
 public static IEnumerator DoFadeOutBlack(ColorDelegate colorDelegate, float fadeDuration)
 {
     yield return(FadeFunc.DoFadeColor(colorDelegate, FadeFunc.blackT, FadeFunc.black, fadeDuration));
 }
Esempio n. 7
0
 public static IEnumerator DoFadeOutWhite(ColorDelegate colorDelegate, float fadeDuration)
 {
     yield return(FadeFunc.DoFadeColor(colorDelegate, FadeFunc.whiteT, FadeFunc.white, fadeDuration));
 }
Esempio n. 8
0
 public TriangularTrail(Entity target, int length, WidthDelegate width, ColorDelegate color, Effect effect = null, bool additive = false, float?tipLength = null) : base(target, length, width, color, effect, additive)
 {
     _tipLength = tipLength ?? -1;
 }