Ejemplo n.º 1
0
        private void FillOverlays()
        {
            AddTab(OverlayFactory.GetOverlaysNotInTypes(new[] { typeof(OverlayRepeater), typeof(OverlayPath) })
                   .Where(t => t != typeof(OverlayFlag) && t != typeof(OverlayImage))
                   .Select(o => OverlayFactory.GetInstance(o, _defaultMaximumX, _defaultMaximumY)), strings.Shapes);

            var emblems    = OverlayFactory.GetOverlaysByType(typeof(OverlayPath)).Select(o => OverlayFactory.GetInstance(o, _defaultMaximumX, _defaultMaximumY));
            var custom     = OverlayFactory.CustomTypes.Select(o => o.Value);
            var allEmblems = emblems.Union(custom).OrderBy(o => o.DisplayName);

            AddTab(allEmblems, strings.Emblems);

            AddTab(OverlayFactory.GetOverlaysByType(typeof(OverlayRepeater))
                   .Select(o => OverlayFactory.GetInstance(o, _defaultMaximumX, _defaultMaximumY))
                   .Union(new Overlay[]
            {
                new OverlayFlag(_defaultMaximumY, _defaultMaximumY),
                new OverlayImage(string.Empty, string.Empty, _defaultMaximumX, _defaultMaximumX)
            }), strings.Special);
        }
Ejemplo n.º 2
0
        private void AddTab(IEnumerable <Overlay> overlays, string tabName)
        {
            var style     = (Style)FindResource("GraphicButton");
            var wrapPanel = new WrapPanel();

            foreach (var button in overlays.Select(overlay => new Button
            {
                ToolTip = overlay.DisplayName,
                Content = overlay.CanvasThumbnail(),
                Tag = overlay.Name,
                Padding = new Thickness(2),
                Style = style
            }))
            {
                button.Click += (s, e) =>
                {
                    var tag = (string)((Button)s).Tag;

                    switch (tag)
                    {
                    case "flag":
                        string path = Flag.GetFlagPath();

                        Flag flag;
                        try
                        {
                            flag = Flag.LoadFromFile(path);
                        }
                        catch (OperationCanceledException)
                        {
                            return;
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(string.Format("{0}\n{1} \"{2}\"", strings.CouldNotOpenFileError, strings.ErrorAtLine, ex.Message), "FlagMaker", MessageBoxButton.OK, MessageBoxImage.Warning);
                            return;
                        }

                        SelectedOverlay = new OverlayFlag(flag, path, _defaultMaximumX, _defaultMaximumY);
                        break;

                    case "image":
                        var dlg = new OpenFileDialog
                        {
                            DefaultExt  = ".png",
                            Filter      = "Images (*.png;*.jpg)|*.png;*.jpg",
                            Multiselect = false
                        };

                        if (!(dlg.ShowDialog() ?? false))
                        {
                            return;
                        }
                        SelectedOverlay = new OverlayImage(dlg.FileName, string.Empty, _defaultMaximumX, _defaultMaximumY);
                        break;

                    default:
                        SelectedOverlay = OverlayFactory.GetInstance(tag, _defaultMaximumX, _defaultMaximumY);
                        break;
                    }
                };

                wrapPanel.Children.Add(button);
            }

            var scrollViewer = new ScrollViewer
            {
                Content = wrapPanel,
                VerticalScrollBarVisibility = ScrollBarVisibility.Auto
            };

            var tabItem = new TabItem {
                Header = tabName, Content = scrollViewer
            };

            _tabs.Items.Add(tabItem);
        }