Exemple #1
0
        static Bitmap GemImageToEto(libexeinfo.GEM.TreeObjectNode node)
        {
            Color color = GemColor.GemToEtoColor(node.BitBlock.Color);
            Color background;

            background = GemColor.GemToEtoColor(node.BitBlock.Color == libexeinfo.GEM.ObjectColors.White
                                                    ? libexeinfo.GEM.ObjectColors.Black
                                                    : libexeinfo.GEM.ObjectColors.White);

            List <Color> pixels = new List <Color>();

            byte[] data = new byte[node.BitBlock.Data.Length];
            int    pos  = 0;
            int    w    = (int)(node.BitBlock.Width / 8);

            // This flips the image.
            while (pos < data.Length)
            {
                for (int i = 0; i < w; i++)
                {
                    byte b = node.BitBlock.Data[pos + i];
                    data[pos + i]  = (byte)(b >> 7);
                    data[pos + i] += (byte)((b >> 5) & 0x02);
                    data[pos + i] += (byte)((b >> 3) & 0x04);
                    data[pos + i] += (byte)((b >> 1) & 0x08);
                    data[pos + i] += (byte)((b << 1) & 0x10);
                    data[pos + i] += (byte)((b << 3) & 0x20);
                    data[pos + i] += (byte)((b << 5) & 0x40);
                    data[pos + i] += (byte)(b << 7);
                }

                pos += w;
            }

            foreach (byte b in data)
            {
                for (int i = 0; i < 8; i++)
                {
                    pixels.Add((b & (1 << i)) != 0 ? color : background);
                }
            }

            return(new Bitmap((int)node.BitBlock.Width, (int)node.BitBlock.Height, PixelFormat.Format32bppRgb, pixels));
        }
        public void Update(libexeinfo.GEM.TreeObjectNode node)
        {
            txtFlags.Text         = node.flags == 0 ? "None" : node.flags.ToString();
            txtState.Text         = node.state == 0 ? "Normal" : node.state.ToString();
            txtCoordinates.Text   = $"{node.x},{node.y}";
            txtSize.Text          = $"{node.width}x{node.height} pixels";
            txtBorderColor.Text   = $"{node.TedInfo.BorderColor}";
            txtFill.Text          = $"{node.TedInfo.Fill}";
            txtFont.Text          = $"{node.TedInfo.Font}";
            txtInsideColor.Text   = $"{node.TedInfo.InsideColor}";
            txtJustification.Text = $"{node.TedInfo.Justification}";
            txtTemplate.Text      = node.TedInfo.Template;
            txtText.Text          = node.TedInfo.Text;
            txtTextColor.Text     = $"{node.TedInfo.TextColor}";
            txtTransparency.Text  =
                node.TedInfo.Transparency ? "Transparent mode" : "Replace mode";
            txtValidation.Text = node.TedInfo.Validation;
            if (node.TedInfo.Thickness < 0)
            {
                txtThickness.Text = $"{node.TedInfo.Thickness * -1} pixels outward";
            }
            else if (node.TedInfo.Thickness < 0)
            {
                txtThickness.Text = $"{node.TedInfo.Thickness} pixels inward";
            }
            else
            {
                txtThickness.Text = "None";
            }

            if (string.IsNullOrWhiteSpace(node.TedInfo.Template))
            {
                txtTemplate.Visible = false;
                lblTemplate.Visible = false;
            }
            else
            {
                txtTemplate.Visible = true;
                lblTemplate.Visible = true;
            }

            if (string.IsNullOrWhiteSpace(node.TedInfo.Text))
            {
                txtText.Visible = false;
                lblText.Visible = false;
            }
            else
            {
                txtText.Visible = true;
                lblText.Visible = true;
            }

            if (string.IsNullOrWhiteSpace(node.TedInfo.Validation))
            {
                txtValidation.Visible = false;
                lblValidation.Visible = false;
            }
            else
            {
                txtValidation.Visible = true;
                lblValidation.Visible = true;
            }

            if (!string.IsNullOrEmpty(node.TedInfo.Template))
            {
                if (string.IsNullOrEmpty(node.TedInfo.Text))
                {
                    txtPreview.Text = node.TedInfo.Template;
                }
                else
                {
                    char[] preview  = node.TedInfo.Template.ToCharArray();
                    char[] template = node.TedInfo.Text.ToCharArray();
                    if (template[0] == '@')
                    {
                        for (int i = 0; i < template.Length; i++)
                        {
                            template[i] = ' ';
                        }
                    }

                    int templatePos = 0;

                    for (int i = 0; i < preview.Length; i++)
                    {
                        if (preview[i] != '_')
                        {
                            continue;
                        }

                        if (templatePos >= template.Length)
                        {
                            continue;
                        }

                        preview[i] = template[templatePos];
                        templatePos++;
                    }

                    txtPreview.Text = new string(preview);
                }
            }
            else
            {
                txtPreview.Text = txtText.Text;
            }

            txtPreview.BackgroundColor = GemColor.GemToEtoColor(node.TedInfo.InsideColor);
            txtPreview.TextColor       = GemColor.GemToEtoColor(node.TedInfo.TextColor);
        }