aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Editors/ElementsEditor.xaml
blob: 3d1bedc465b121532feb5c629fd97974599d3887 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<core:HybridControl x:Class="Tango.Editors.ElementsEditor"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:Tango.Editors"
             xmlns:converters="clr-namespace:Tango.Editors.Converters"
             xmlns:core="clr-namespace:Tango.Editors"
             mc:Ignorable="d" 
              x:Name="editor" FontSize="8" FocusVisualStyle="{x:Null}">

    <UserControl.Resources>

        <!--Converters-->
        <converters:HorizontalOffsetToMarginConverter x:Key="HorizontalOffsetToMarginConverter"></converters:HorizontalOffsetToMarginConverter>

        <!--Styles and Templates-->
        <Style TargetType="{x:Type ListBoxItem}" x:Key="basicListBoxItem">
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="IsSelected" Value="{Binding IsSelected,Mode=TwoWay}"></Setter>
            <Setter Property="BorderThickness" Value="0"></Setter>
            <Setter Property="FocusVisualStyle" Value="{x:Null}"></Setter>
            <Setter Property="Padding" Value="0"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListBoxItem}">
                        <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0" Background="{TemplateBinding Background}" Padding="0" SnapsToDevicePixels="true">
                            <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsSelected" Value="true">
                                <Setter Property="Background" TargetName="Bd" Value="Transparent"/>
                            </Trigger>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="IsSelected" Value="true"/>
                                    <Condition Property="Selector.IsSelectionActive" Value="false"/>
                                </MultiTrigger.Conditions>
                                <Setter Property="Background" TargetName="Bd" Value="Transparent"/>
                            </MultiTrigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style TargetType="ListBox" x:Key="basicList">
            <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
            <Setter Property="Background" Value="Transparent"></Setter>
            <Setter Property="BorderThickness" Value="0"></Setter>
            <Setter Property="Margin" Value="0"></Setter>
            <Setter Property="Padding" Value="0"></Setter>
            <Setter Property="FocusVisualStyle" Value="{x:Null}"></Setter>
            <Setter Property="ItemContainerStyle">
                <Setter.Value>
                    <Style TargetType="ListBoxItem" BasedOn="{StaticResource basicListBoxItem}">
                        <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
                        <Setter Property="Margin" Value="0"></Setter>
                        <Setter Property="Padding" Value="0"></Setter>
                        <Setter Property="BorderThickness" Value="0"></Setter>
                        <Style.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Background" Value="Transparent"></Setter>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </Setter.Value>
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListBox}">
                        <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0" Background="{TemplateBinding Background}" Padding="0" SnapsToDevicePixels="True">
                            <ScrollViewer Focusable="False" Padding="0">
                                <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                            </ScrollViewer>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
                            </Trigger>
                            <Trigger Property="IsGrouping" Value="True">
                                <Setter Property="ScrollViewer.CanContentScroll" Value="False"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <!--Themes-->
        <SolidColorBrush x:Key="RulerBackground" Color="#151515"></SolidColorBrush>
        <SolidColorBrush x:Key="EditorBackground" Color="#202020"></SolidColorBrush>
        <SolidColorBrush x:Key="SelectionFillBrush" Color="#80FFFFFF"></SolidColorBrush>
        <SolidColorBrush x:Key="SelectionStrokeBrush" Color="Gainsboro"></SolidColorBrush>

    </UserControl.Resources>

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition>
                <ColumnDefinition.Style>
                    <Style TargetType="ColumnDefinition">
                        <Setter Property="Width" Value="{Binding ElementName=editor,Path=RulerHeight,FallbackValue=30,TargetNullValue=30}"></Setter>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding ElementName=editor,Path=EditorMode}" Value="AdvancedCanvas">
                                <Setter Property="Width" Value="0"></Setter>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ColumnDefinition.Style>
            </ColumnDefinition>
            <ColumnDefinition Width="1*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition>
                <RowDefinition.Style>
                    <Style TargetType="RowDefinition">
                        <Setter Property="Height" Value="{Binding ElementName=editor,Path=RulerHeight,FallbackValue=30,TargetNullValue=30}"></Setter>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding ElementName=editor,Path=EditorMode}" Value="AdvancedCanvas">
                                <Setter Property="Height" Value="0"></Setter>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </RowDefinition.Style>
            </RowDefinition>
            <RowDefinition Height="1*"/>
        </Grid.RowDefinitions>

        <Grid Background="{Binding ElementName=editor,Path=EditorBackground}">
            <Border BorderBrush="{Binding ElementName=editor,Path=Foreground}" BorderThickness="0 0 1 1" Background="Transparent" PreviewMouseUp="OnResetScaleFactor" Cursor="Hand" ToolTip="Reset">
                <Viewbox Margin="5">
                    <Path Fill="{Binding ElementName=editor,Path=Foreground}" Data="M533.333 0v216.667L450 133.333l-100 100l-50-50l100-100L316.667 0H533.333z M233.333 350l-100 100l83.333 83.333H0   V316.667L83.333 400l100-100L233.333 350z"></Path>
                </Viewbox>
            </Border>
        </Grid>

        <Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Column="1" ClipToBounds="True" Background="{Binding ElementName=editor,Path=RulerBackground}" BorderThickness="0 0 0 1" BorderBrush="{Binding ElementName=editor,Path=Foreground}">
            <local:PixelRuler HorizontalAlignment="Left" Width="{Binding ElementName=gridInnerScrollViewer,Path=ActualWidth}" MinWidth="{Binding ElementName=scrollViewer,Path=ViewportWidth}" AutoSize="True" Marks="Down" Foreground="{Binding RelativeSource={RelativeSource AncestorType=local:ElementsEditor},Path=Foreground}" 
                              Zoom="{Binding RelativeSource={RelativeSource AncestorType=local:ElementsEditor},Path=ScaleFactor}"
                              Margin="{Binding ElementName=scrollViewer,Path=HorizontalOffset,Converter={StaticResource HorizontalOffsetToMarginConverter},ConverterParameter='left'}">
            </local:PixelRuler>
        </Border>
        <Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="1" ClipToBounds="True" Background="{Binding ElementName=editor,Path=RulerBackground}" BorderThickness="0 0 1 0" BorderBrush="{Binding ElementName=editor,Path=Foreground}">
            <local:PixelRuler VerticalAlignment="Top" Width="{Binding ElementName=gridInnerScrollViewer,Path=ActualHeight}" MinWidth="{Binding ElementName=scrollViewer,Path=ViewportHeight}" AutoSize="True" Orientation="Horizontal" Foreground="{Binding ElementName=editor,Path=Foreground}" 
                              Zoom="{Binding RelativeSource={RelativeSource AncestorType=local:ElementsEditor},Path=ScaleFactor}"
                              Margin="{Binding ElementName=scrollViewer,Path=VerticalOffset,Converter={StaticResource HorizontalOffsetToMarginConverter},ConverterParameter='top'}">
                <local:PixelRuler.LayoutTransform>
                    <TransformGroup>
                        <RotateTransform Angle="90"></RotateTransform>
                    </TransformGroup>
                </local:PixelRuler.LayoutTransform>
            </local:PixelRuler>
        </Border>

        <local:CustomScrollViewer x:Name="scrollViewer" FocusVisualStyle="{x:Null}" MouseZooming="OnMouseWheelZooming" Grid.Column="1" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
            <local:CustomScrollViewer.Resources>
                <Style TargetType="{x:Type local:CustomScrollViewer}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type ScrollViewer}">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition/>
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition/>
                                        <RowDefinition Height="Auto"/>
                                    </Grid.RowDefinitions>
                                    <ScrollContentPresenter Grid.Column="0" />
                                    <ScrollBar x:Name="PART_VerticalScrollBar" Grid.Row="0" Grid.Column="1" Value="{TemplateBinding VerticalOffset}" Maximum="{TemplateBinding ScrollableHeight}" ViewportSize="{TemplateBinding ViewportHeight}" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>
                                    <ScrollBar x:Name="PART_HorizontalScrollBar" Orientation="Horizontal" Grid.Row="1" Grid.Column="0" Value="{TemplateBinding HorizontalOffset}" Maximum="{TemplateBinding ScrollableWidth}" ViewportSize="{TemplateBinding ViewportWidth}" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>
                                    <!--<Rectangle Grid.Row="1" Grid.Column="1" Fill="Red"/>-->
                                </Grid>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </local:CustomScrollViewer.Resources>
            <Grid x:Name="gridInnerScrollViewer">
                <Grid x:Name="gridCanvas" HorizontalAlignment="Left" VerticalAlignment="Top" Background="{Binding ElementName=editor,Path=EditorBackground}">
                    <Grid.Style>
                        <Style TargetType="Grid">
                            <Setter Property="Width" Value="{Binding RelativeSource={RelativeSource AncestorType=local:ElementsEditor},Path=EditorWidth,FallbackValue=1280}"></Setter>
                            <Setter Property="Height" Value="{Binding RelativeSource={RelativeSource AncestorType=local:ElementsEditor},Path=EditorHeight,FallbackValue=720}"></Setter>
                            
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding ElementName=editor,Path=EditorMode}" Value="AdvancedCanvas">
                                    <Setter Property="Width" Value="{Binding ElementName=gridInnerScrollViewer,Path=ActualWidth}"></Setter>
                                    <Setter Property="Height" Value="{Binding ElementName=gridInnerScrollViewer,Path=ActualHeight}"></Setter>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Grid.Style>

                    <Grid.LayoutTransform>
                        <ScaleTransform 
                    ScaleX="{Binding RelativeSource={RelativeSource AncestorType=local:ElementsEditor},Path=ScaleFactor}" 
                    ScaleY="{Binding RelativeSource={RelativeSource AncestorType=local:ElementsEditor},Path=ScaleFactor}">
                        </ScaleTransform>
                    </Grid.LayoutTransform>

                    <Image IsHitTestVisible="False" Stretch="Fill" Width="{Binding ElementName=canvas,Path=ActualWidth}" Height="{Binding ElementName=canvas,Path=ActualHeight}" HorizontalAlignment="Left" VerticalAlignment="Top" Source="{Binding RelativeSource={RelativeSource AncestorType=local:ElementsEditor},Path=PreviewImage,Mode=OneWay,IsAsync=True,BindsDirectlyToSource=True}" Opacity="{Binding RelativeSource={RelativeSource AncestorType=local:ElementsEditor},Path=PreviewVisualSourceOpacity}"></Image>

                    <Grid MouseDown="OnCanvasMouseDown" MouseUp="OnCanvasMouseUp" MouseMove="OnCanvasMouseMove" Background="Transparent">
                        <Canvas x:Name="canvas" ClipToBounds="True">

                        </Canvas>
                    </Grid>

                    <Canvas x:Name="selectionCanvas" IsHitTestVisible="False" ClipToBounds="False" Visibility="Hidden">
                        <Rectangle x:Name="selectionRec" Stroke="{Binding ElementName=editor,Path=SelectionStrokeBrush,FallbackValue={StaticResource SelectionStrokeBrush},TargetNullValue={StaticResource SelectionStrokeBrush}}" Fill="{Binding ElementName=editor,Path=SelectionFillBrush,FallbackValue={StaticResource SelectionFillBrush},TargetNullValue={StaticResource SelectionFillBrush}}" IsHitTestVisible="False"></Rectangle>
                    </Canvas>
                </Grid>
            </Grid>
        </local:CustomScrollViewer>
    </Grid>
</core:HybridControl>