Пример #1
0
 private void IterateIcons(object state)
 {
     // creating a new icon block should be on UI thread ;-)
     Application.Current?.Dispatcher?.Invoke(() =>
     {
         var icon  = IconHelper.Icons[_currentIcon];
         IconBlock = null;
         GC.Collect();
         IconBlock = new IconBlock {
             Icon = icon, Height = 32, FontSize = 24
         };
         OnPropertyChanged(nameof(IconBlock));
         _currentIcon = (_currentIcon + 1) % IconHelper.Icons.Length;
     });
 }
Пример #2
0
 private void OnIconBlockChange(object state)
 {
     // creating a new icon block should be on UI thread ;)
     Application.Current.Dispatcher.Invoke(() =>
     {
         var values  = Enum.GetValues(typeof(IconChar));
         var rndIcon = (IconChar)values.GetValue(_random.Next(values.Length));
         IconBlock   = null;
         GC.Collect();
         IconBlock = new IconBlock {
             Icon = rndIcon, Height = 80, FontSize = 72
         };
         OnPropertyChanged(nameof(IconBlock));
     });
 }
Пример #3
0
        public static MenuItem CreateMenuItem(string header, IconChar?icon = null, Action?callback = null)
        {
            MenuItem item = new MenuItem();

            item.Style  = Application.Current.FindResource("AnaMenuItem") as Style;
            item.Click += (s, e) => callback?.Invoke();

            TextBlock textBlock = new TextBlock();

            ////textBlock.Key = headerKey;
            textBlock.Text = header;
            item.Header    = textBlock;

            if (icon != null)
            {
                IconBlock iconBlock = new IconBlock();
                iconBlock.Icon = (IconChar)icon;
                item.Icon      = iconBlock;
            }

            return(item);
        }
Пример #4
0
        // [JsonIgnore]
        // public Project Project { get { return Engine.Engine.project; } }

        internal static Panel GetActionHeader(GUIAction guiAction, bool enableable, bool toggleable, bool deleteable)
        {
            var action = guiAction.action;
            var grid   = new Grid {
                Background = new SolidColorBrush(System.Windows.Media.Color.FromRgb(0x50, 0x50, 0x50)),
                Margin     = new Thickness(0, 0, 0, action.Collapsed ? 0 : 5)
            };
            var c1 = new ColumnDefinition();
            var c2 = new ColumnDefinition {
                Width = GridLength.Auto
            };

            grid.ColumnDefinitions.Add(c1);
            grid.ColumnDefinitions.Add(c2);

            var stackPanel = new StackPanel {
                Orientation = Orientation.Horizontal
            };

            // Define the icons
            var openIcon = new IconBlock {
                Icon = IconChar.CaretDown, FontSize = 12, Width = 12
            };
            var collapseIcon = new IconBlock {
                Icon = IconChar.CaretRight, FontSize = 12, Width = 12
            };
            var checkedIcon = new IconBlock {
                Icon = IconChar.CheckSquare, FontSize = 12, Width = 12
            };
            var uncheckedIcon = new IconBlock {
                Icon = IconChar.Square, FontSize = 12, Width = 12
            };
            var deleteIcon = new IconBlock {
                Icon = IconChar.TrashAlt, FontSize = 12, Width = 12
            };

            // Define the buttons
            var expandCollapseToggle = new Button {
                Content    = action.Collapsed ? collapseIcon : openIcon,
                Margin     = new Thickness(2, 0, 2, 0),
                Background = Brushes.Transparent,
                IsTabStop  = false
            };
            var enableDisableToggle = new Button {
                Content    = action.Enabled ? checkedIcon : uncheckedIcon,
                Margin     = new Thickness(2, 0, 2, 0),
                Background = Brushes.Transparent,
                IsTabStop  = false
            };
            var deleteAction = new Button {
                Content             = deleteIcon,
                Margin              = new Thickness(2, 0, 5, 0),
                Background          = Brushes.Transparent,
                HorizontalAlignment = HorizontalAlignment.Right,
                IsTabStop           = false
            };

            // Define the button events
            expandCollapseToggle.Click += (sender, e) => {
                action.Collapsed = !action.Collapsed;
                OnActionsUpdated(sender);
            };
            enableDisableToggle.Click += (sender, e) => {
                action.Enabled = !action.Enabled;
                guiAction.Layer.ApplyActions();
                OnActionsUpdated(sender);
                EventBus.OnLayerActionChanged(sender);
            };
            deleteAction.Click += (sender, e) => {
                guiAction.Layer.actions.Remove(action);
                guiAction.Layer.ApplyActions();
                OnActionsUpdated(sender);
                EventBus.OnLayerActionRemoved(sender);
            };

            // Define the Header
            var title = new TextBlock {
                Text       = action.Name,
                FontWeight = FontWeights.Bold,
                Margin     = new Thickness(5)
            };

            // Add the items to the stack panel
            if (guiAction.panels.Count > 0 && toggleable)
            {
                stackPanel.Children.Add(expandCollapseToggle);
            }
            else
            {
                enableDisableToggle.Margin = new Thickness(20, 0, 2, 0);
            }

            if (enableable)
            {
                stackPanel.Children.Add(enableDisableToggle);
            }
            stackPanel.Children.Add(title);

            // Define the grid columns
            Grid.SetColumn(stackPanel, 0);
            Grid.SetColumn(deleteAction, 1);

            // Add the items to the grid
            grid.Children.Add(stackPanel);
            if (deleteable)
            {
                grid.Children.Add(deleteAction);
            }

            return(grid);
        }
Пример #5
0
        public static ColorIcon[] GetColorIcons(Stream resourceStream, int colorIc, bool bigEndian, Encoding encoding)
        {
            byte[] buffer;

            if (colorIc == -1 || colorIc >= resourceStream.Length)
            {
                return(null);
            }

            resourceStream.Position = colorIc;

            int cicons = 0;

            while (true)
            {
                buffer = new byte[4];
                resourceStream.Read(buffer, 0, buffer.Length);

                if (BitConverter.ToInt32(buffer, 0) == -1)
                {
                    break;
                }

                cicons++;
            }

            ColorIcon[] colorIcons = new ColorIcon[cicons];

            for (int i = 0; i < cicons; i++)
            {
                buffer = new byte[Marshal.SizeOf(typeof(IconBlock))];
                resourceStream.Read(buffer, 0, buffer.Length);
                IconBlock iconBlock = BigEndianMarshal.ByteArrayToStructureBigEndian <IconBlock>(buffer);
                int       isize     = iconBlock.ib_wicon * iconBlock.ib_hicon / 8;

                buffer = new byte[4];
                resourceStream.Position -= 2;
                resourceStream.Read(buffer, 0, buffer.Length);
                int numRez = BitConverter.ToInt32(buffer.Reverse().ToArray(), 0);

                colorIcons[i] = new ColorIcon
                {
                    Color      = new ColorIconPlane[numRez],
                    Monochrome = new Icon
                    {
                        Width           = iconBlock.ib_wicon,
                        Height          = iconBlock.ib_hicon,
                        X               = iconBlock.ib_xicon,
                        Y               = iconBlock.ib_yicon,
                        ForegroundColor = (ObjectColors)((iconBlock.ib_char >> 12) & 0x000F),
                        BackgroundColor = (ObjectColors)((iconBlock.ib_char >> 8) & 0x000F),
                        Character       = encoding.GetString(new[] { (byte)(iconBlock.ib_char & 0xFF) })[0],
                        CharX           = iconBlock.ib_xchar,
                        CharY           = iconBlock.ib_ychar,
                        TextX           = iconBlock.ib_xtext,
                        TextY           = iconBlock.ib_ytext,
                        TextWidth       = iconBlock.ib_wtext,
                        TextHeight      = iconBlock.ib_htext,
                        Data            = new byte[isize],
                        Mask            = new byte[isize]
                    }
                };

                resourceStream.Read(colorIcons[i].Monochrome.Data, 0, isize);

                // Because the image is stored as words, they get reversed on PC GEM (Little-endian)
                if (!bigEndian)
                {
                    byte[] data = new byte[colorIcons[i].Monochrome.Data.Length];
                    for (int d = 0; d < data.Length; d += 2)
                    {
                        data[d]     = colorIcons[d].Monochrome.Data[d + 1];
                        data[d + 1] = colorIcons[d].Monochrome.Data[d];
                    }

                    colorIcons[i].Monochrome.Data = data;
                }

                resourceStream.Read(colorIcons[i].Monochrome.Mask, 0, isize);

                // Because the mask is stored as words, they get reversed on PC GEM (Little-endian)
                if (!bigEndian)
                {
                    byte[] mask = new byte[colorIcons[i].Monochrome.Mask.Length];
                    for (int m = 0; m < mask.Length; m += 2)
                    {
                        mask[m]     = colorIcons[m].Monochrome.Mask[m + 1];
                        mask[m + 1] = colorIcons[m].Monochrome.Mask[m];
                    }

                    colorIcons[i].Monochrome.Mask = mask;
                }

                if (iconBlock.ib_ptext > 0 && iconBlock.ib_ptext < resourceStream.Length)
                {
                    long oldPosition = resourceStream.Position;
                    resourceStream.Position = iconBlock.ib_ptext;
                    List <byte> chars = new List <byte>();
                    while (true)
                    {
                        int character = resourceStream.ReadByte();

                        if (character <= 0)
                        {
                            break;
                        }

                        chars.Add((byte)character);
                    }

                    colorIcons[i].Monochrome.Text = StringHandlers.CToString(chars.ToArray(), encoding);
                    resourceStream.Position       = oldPosition + 12;
                }
                else
                {
                    byte[] ptext = new byte[12];
                    resourceStream.Read(ptext, 0, 12);
                    colorIcons[i].Monochrome.Text = StringHandlers.CToString(ptext, encoding);
                }

                colorIcons[i].Color = new ColorIconPlane[numRez];

                for (int r = 0; r < numRez; r++)
                {
                    byte[] data;
                    byte[] mask;

                    buffer = new byte[Marshal.SizeOf(typeof(ColorIconBlock))];
                    resourceStream.Read(buffer, 0, buffer.Length);
                    ColorIconBlock cib = BigEndianMarshal.ByteArrayToStructureBigEndian <ColorIconBlock>(buffer);

                    colorIcons[i].Color[r] = new ColorIconPlane
                    {
                        Planes = cib.num_planes,
                        Data   = new byte[isize * cib.num_planes],
                        Mask   = new byte[isize]
                    };

                    resourceStream.Read(colorIcons[i].Color[r].Data, 0, isize * cib.num_planes);

                    // Because the image is stored as words, they get reversed on PC GEM (Little-endian)
                    if (!bigEndian)
                    {
                        data = new byte[colorIcons[i].Color[r].Data.Length];
                        for (int d = 0; d < data.Length; d += 2)
                        {
                            data[d]     = colorIcons[d].Color[r].Data[d + 1];
                            data[d + 1] = colorIcons[d].Color[r].Data[d];
                        }

                        colorIcons[i].Color[r].Data = data;
                    }

                    resourceStream.Read(colorIcons[i].Color[r].Mask, 0, isize);

                    // Because the mask is stored as words, they get reversed on PC GEM (Little-endian)
                    if (!bigEndian)
                    {
                        mask = new byte[colorIcons[i].Color[r].Mask.Length];
                        for (int m = 0; m < mask.Length; m += 2)
                        {
                            mask[m]     = colorIcons[m].Color[r].Mask[m + 1];
                            mask[m + 1] = colorIcons[m].Color[r].Mask[m];
                        }

                        colorIcons[i].Color[r].Mask = mask;
                    }

                    if (cib.sel_data == 0)
                    {
                        continue;
                    }

                    colorIcons[i].Color[r].SelectedData = new byte[isize * cib.num_planes];
                    colorIcons[i].Color[r].SelectedMask = new byte[isize];

                    resourceStream.Read(colorIcons[i].Color[r].SelectedData, 0, isize * cib.num_planes);

                    // Because the image is stored as words, they get reversed on PC GEM (Little-endian)
                    if (!bigEndian)
                    {
                        data = new byte[colorIcons[i].Color[r].SelectedData.Length];
                        for (int d = 0; d < data.Length; d += 2)
                        {
                            data[d]     = colorIcons[d].Color[r].SelectedData[d + 1];
                            data[d + 1] =
                                colorIcons[d].Color[r].SelectedData[d];
                        }

                        colorIcons[i].Color[r].SelectedData = data;
                    }

                    resourceStream.Read(colorIcons[i].Color[r].SelectedMask, 0, isize);

                    // Because the mask is stored as words, they get reversed on PC GEM (Little-endian)
                    if (bigEndian)
                    {
                        continue;
                    }

                    mask = new byte[colorIcons[i].Color[r].SelectedMask.Length];
                    for (int m = 0; m < mask.Length; m += 2)
                    {
                        mask[m]     = colorIcons[m].Color[r].SelectedMask[m + 1];
                        mask[m + 1] = colorIcons[m].Color[r].SelectedMask[m];
                    }

                    colorIcons[i].Color[r].SelectedMask = mask;
                }
            }

            return(colorIcons);
        }
Пример #6
0
        static Icon GetIconBlock(Stream resourceStream, byte[] buffer, bool bigEndian, Encoding encoding)
        {
            long oldPosition = resourceStream.Position;

            IconBlock iconBlock = bigEndian
                                      ? BigEndianMarshal.ByteArrayToStructureBigEndian <IconBlock>(buffer)
                                      : BigEndianMarshal.ByteArrayToStructureLittleEndian <IconBlock>(buffer);

            Icon icon = new Icon
            {
                Width           = iconBlock.ib_wicon,
                Height          = iconBlock.ib_hicon,
                X               = iconBlock.ib_xicon,
                Y               = iconBlock.ib_yicon,
                ForegroundColor = (ObjectColors)((iconBlock.ib_char >> 12) & 0x000F),
                BackgroundColor = (ObjectColors)((iconBlock.ib_char >> 8) & 0x000F),
                Character       = encoding.GetString(new[] { (byte)(iconBlock.ib_char & 0xFF) })[0],
                CharX           = iconBlock.ib_xchar,
                CharY           = iconBlock.ib_ychar,
                TextX           = iconBlock.ib_xtext,
                TextY           = iconBlock.ib_ytext,
                TextWidth       = iconBlock.ib_wtext,
                TextHeight      = iconBlock.ib_htext
            };

            if (iconBlock.ib_ptext > 0 && iconBlock.ib_ptext < resourceStream.Length)
            {
                resourceStream.Position = iconBlock.ib_ptext;
                List <byte> chars = new List <byte>();
                while (true)
                {
                    int character = resourceStream.ReadByte();

                    if (character <= 0)
                    {
                        break;
                    }

                    chars.Add((byte)character);
                }

                icon.Text = StringHandlers.CToString(chars.ToArray(), encoding);
            }

            if (iconBlock.ib_pdata > 0 && iconBlock.ib_pdata < resourceStream.Length)
            {
                resourceStream.Position = iconBlock.ib_pdata;
                icon.Data = new byte[icon.Width * icon.Height / 8];
                resourceStream.Read(icon.Data, 0, icon.Data.Length);

                // Because the image is stored as words, they get reversed on PC GEM (Little-endian)
                if (!bigEndian)
                {
                    byte[] data = new byte[icon.Data.Length];
                    for (int i = 0; i < data.Length; i += 2)
                    {
                        data[i]     = icon.Data[i + 1];
                        data[i + 1] = icon.Data[i];
                    }

                    icon.Data = data;
                }
            }

            if (iconBlock.ib_pmask > 0 && iconBlock.ib_pmask < resourceStream.Length)
            {
                resourceStream.Position = iconBlock.ib_pmask;
                icon.Mask = new byte[icon.Width * icon.Height / 8];
                resourceStream.Read(icon.Mask, 0, icon.Mask.Length);

                // Because the mask is stored as words, they get reversed on PC GEM (Little-endian)
                if (!bigEndian)
                {
                    byte[] mask = new byte[icon.Mask.Length];
                    for (int i = 0; i < mask.Length; i += 2)
                    {
                        mask[i]     = icon.Mask[i + 1];
                        mask[i + 1] = icon.Mask[i];
                    }

                    icon.Mask = mask;
                }
            }

            resourceStream.Position = oldPosition;
            return(icon);
        }