<!--
Copyright 2019 faddenSoft

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<Window x:Class="SourceGen.Tools.WpfGui.InstructionChart"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:system="clr-namespace:System;assembly=mscorlib"
        xmlns:local="clr-namespace:SourceGen.Tools.WpfGui"
        mc:Ignorable="d"
        Title="Instruction Chart"
        Width="800" Height="563" MinWidth="400" MinHeight="180" ResizeMode="CanResizeWithGrip"
        ShowInTaskbar="True"
        Loaded="Window_Loaded"
        PreviewKeyDown="Window_KeyEventHandler">

    <Window.Resources>
        <system:String x:Key="str_6502">MOS 6502</system:String>
        <system:String x:Key="str_65C02">WDC W65C02S</system:String>
        <system:String x:Key="str_65816">WDC W65C816S</system:String>
    </Window.Resources>

    <DockPanel Margin="8">
        <StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" Margin="0,4,0,0">
            <TextBlock Margin="0,3,0,0">CPU:</TextBlock>
            <ComboBox Name="cpuSelectionComboBox" Width="200" Margin="4,0,0,0"
                      HorizontalAlignment="Left"
                      ItemsSource="{Binding CpuItems}" DisplayMemberPath="Name"
                      SelectionChanged="CpuSelectionComboBox_SelectionChanged"/>

            <CheckBox Margin="32,4,0,0" Content="Show undocumented instructions"
                      IsChecked="{Binding ShowUndocumented}"/>
        </StackPanel>

        <DataGrid DockPanel.Dock="Top" Name="instructionGrid"
                  IsReadOnly="True"
                  ItemsSource="{Binding InstructionItems}"
                  FontFamily="{StaticResource GeneralMonoFont}"
                  SnapsToDevicePixels="True"
                  GridLinesVisibility="All"
                  VerticalGridLinesBrush="#FF7F7F7F"
                  HorizontalGridLinesBrush="#FFE2E2E2"
                  AutoGenerateColumns="False"
                  HeadersVisibility="Column"
                  CanUserReorderColumns="False"
                  SelectionMode="Extended"
                  VerticalScrollBarVisibility="Visible">
            <DataGrid.Resources>
                <Style x:Key="cellStyle" TargetType="{x:Type DataGridCell}">
                    <Style.Triggers>
                        <!-- show undocumented opcodes differently -->
                        <DataTrigger Binding="{Binding Path=IsUndocumented}" Value="True">
                            <Setter Property="FontStyle" Value="Italic"/>
                            <Setter Property="Foreground"
                                    Value="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </DataGrid.Resources>
            <DataGrid.Columns>
                <DataGridTextColumn Header="Opc" Binding="{Binding Opcode}"/>
                <DataGridTextColumn Header="Instruction" Binding="{Binding Sample}"
                                    CellStyle="{StaticResource cellStyle}"/>
                <DataGridTextColumn Header="Flags" Binding="{Binding Flags}"/>
                <DataGridTextColumn Header="Cyc" Binding="{Binding Cycles}"/>
                <DataGridTextColumn Header="Description" Binding="{Binding ShortDesc}"
                                    FontFamily="Segoe UI"/>
                <DataGridTextColumn Header="Address Mode" Binding="{Binding AddressMode}"
                                    FontFamily="Segoe UI"/>
            </DataGrid.Columns>
        </DataGrid>
    </DockPanel>
</Window>
