예제 #1
0
        private static GridLabel GetPreviousSelectionAccordingTo(GridLabel target, List <GridLabel> searchTarget)
        {
            var selection =
                searchTarget.FirstOrDefault(label => label.X == target.X && label.Y == target.Y);

            return(selection);
        }
예제 #2
0
        private void SelectLabel(GridLabel selection)
        {
            ResetLabel(_previousHexSelection);
            ResetLabel(_previousCharSelection);

            SetBackgroundColor(selection, BackgroundTheme.Black);
            switch (selection.GridType)
            {
            case GridType.Hex:
                _previousHexSelection = selection;
                var charSelection = GetPreviousSelectionAccordingTo(selection, _charLabels);
                if (charSelection != null)
                {
                    _previousCharSelection = charSelection;
                    SetBackgroundColor(charSelection, BackgroundTheme.Black);
                }
                break;

            case GridType.Char:
                _previousCharSelection = selection;
                var hexSelection = GetPreviousSelectionAccordingTo(selection, _hexLabels);
                if (hexSelection != null)
                {
                    _previousHexSelection = hexSelection;
                    SetBackgroundColor(hexSelection, BackgroundTheme.Black);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
예제 #3
0
 private static void ResetLabel(GridLabel selection)
 {
     if (selection != null)
     {
         SetBackgroundColor(selection, BackgroundTheme.White);
     }
 }
예제 #4
0
        private static void SetBackgroundColor(GridLabel target, BackgroundTheme theme)
        {
            switch (theme)
            {
            case BackgroundTheme.Black:
                target.Background = Brushes.Black;
                target.Foreground = Brushes.White;
                break;

            case BackgroundTheme.White:
                target.Background = Brushes.White;
                target.Foreground = Brushes.Black;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(theme), theme, null);
            }
        }
예제 #5
0
        private GridLabel BuildGridLabel(int index, string text, GridType gridType)
        {
            var label = new GridLabel(index % RowLength, index / RowLength, gridType)
            {
                Content             = text,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                Margin     = new Thickness(index % RowLength * TextWidth + Offest, index / RowLength * TextHeight, 0, 0),
                Width      = TextWidth + 5,
                Height     = TextHeight + 5,
                FontFamily = new FontFamily("monospace"),
                FontSize   = 24
            };

            label.MouseDown += (s, e) =>
            {
                SelectLabel((GridLabel)s);
            };
            label.ToolTip = new ToolTip()
            {
                Content = $"0x{Convert.ToString(index, 16)}"
            };
            return(label);
        }