Ejemplo n.º 1
0
        private void UpdateSwatchColorFromTextBoxes(object sender, TextChangedEventArgs e)
        {
            if (!commitTextboxChanges)
            {
                return;
            }
            commitTextboxChanges = false;
            for (int i = 0; i < 3; i++)
            {
                swatchTextBoxes[i].TextChanged -= UpdateSwatchColorFromTextBoxes;
            }

            var color16 = ChannelStringsToColor16(swatchTextBoxes.Select(box => box.Text).ToArray());
            var color32 = TileImage.Convert16BitColor(color16);

            color16                 = PaletteRun.FlipColorChannels(color16);
            swatch.Result           = color32.ToString();
            swatchTextBoxes[3].Text = color16.ToString("X4");

            for (int i = 0; i < 3; i++)
            {
                swatchTextBoxes[i].TextChanged += UpdateSwatchColorFromTextBoxes;
            }
            commitTextboxChanges = true;
        }
Ejemplo n.º 2
0
        private void UpdateSwatchColorFromBytesBox(object sender, TextChangedEventArgs e)
        {
            if (!commitTextboxChanges)
            {
                return;
            }
            commitTextboxChanges            = false;
            swatchTextBoxes[3].TextChanged -= UpdateSwatchColorFromBytesBox;

            if (short.TryParse(swatchTextBoxes[3].Text, NumberStyles.HexNumber, CultureInfo.CurrentCulture, out var color16))
            {
                color16 = PaletteRun.FlipColorChannels(color16);
                var color32 = TileImage.Convert16BitColor(color16);
                swatch.Result = color32.ToString();

                var channels = Color16ToChannelStrings(color16);
                for (int i = 0; i < channels.Length; i++)
                {
                    swatchTextBoxes[i].TextChanged -= UpdateSwatchColorFromTextBoxes;
                    swatchTextBoxes[i].Text         = channels[i];
                    swatchTextBoxes[i].TextChanged += UpdateSwatchColorFromTextBoxes;
                }
            }

            swatchTextBoxes[3].TextChanged += UpdateSwatchColorFromBytesBox;
            commitTextboxChanges            = true;
        }
        private void UpdateSwatchColorFromBytesBox(object sender, TextChangedEventArgs e)
        {
            if (!commitTextboxChanges)
            {
                return;
            }
            commitTextboxChanges = false;

            if (short.TryParse(swatchTextBoxes[3].Text, NumberStyles.HexNumber, CultureInfo.CurrentCulture, out var color16))
            {
                color16 = PaletteRun.FlipColorChannels(color16);
                var color32 = TileImage.Convert16BitColor(color16);
                UpdateTextBoxes(color32, ignore16bitColor: true);
            }

            commitTextboxChanges = true;
        }
        private void UpdateTextBoxes(
            Color color32,
            bool ignore5bitChannels = false,
            bool ignore8bitChannels = false,
            bool ignore16bitColor   = false,
            bool ignore32bitColor   = false,
            bool ignoreSwatch       = false
            )
        {
            var color16  = TileImage.Convert16BitColor(color32);
            var channels = Color16ToChannelStrings(color16);

            color16 = PaletteRun.FlipColorChannels(color16);

            if (!ignore5bitChannels)
            {
                for (int i = 0; i < channels.Length; i++)
                {
                    swatchTextBoxes[i].Text = channels[i];
                }
            }

            if (!ignore16bitColor)
            {
                swatchTextBoxes[3].Text = color16.ToString("X4");
            }

            if (!ignore8bitChannels)
            {
                for (int i = 0; i < channels.Length; i++)
                {
                    decompTextBoxes[i].Text = (int.Parse(channels[i]) * 255 / 31).ToString();
                }
            }

            if (!ignore32bitColor)
            {
                decompTextBoxes[3].Text = color32.ToString().Substring(3); // cut off the #FF at the beginning
            }

            if (!ignoreSwatch)
            {
                swatch.Result = color32.ToString();
            }
        }
Ejemplo n.º 5
0
        private void UpdateSwatchTextBoxContentFromSwatch()
        {
            if (!commitTextboxChanges)
            {
                return;
            }
            var color32  = (Color)ColorConverter.ConvertFromString(swatch.Result);
            var color16  = TileImage.Convert16BitColor(color32);
            var channels = Color16ToChannelStrings(color16);

            color16 = PaletteRun.FlipColorChannels(color16);
            for (int i = 0; i < channels.Length; i++)
            {
                swatchTextBoxes[i].TextChanged -= UpdateSwatchColorFromTextBoxes;
                swatchTextBoxes[i].Text         = channels[i];
                swatchTextBoxes[i].TextChanged += UpdateSwatchColorFromTextBoxes;
            }
            swatchTextBoxes[3].TextChanged -= UpdateSwatchColorFromBytesBox;
            swatchTextBoxes[3].Text         = color16.ToString("X4");
            swatchTextBoxes[3].TextChanged += UpdateSwatchColorFromBytesBox;
        }