Exemplo n.º 1
0
        protected override void OnBuildToolBar(Gtk.Toolbar tb)
        {
            base.OnBuildToolBar(tb);

            if (font_label == null)
            {
                font_label = new ToolBarLabel(string.Format(" {0}: ", Translations.GetString("Font")));
            }

            tb.AppendItem(font_label);

            if (font_button == null)
            {
                font_button = new (new FontButton()
                {
                    ShowStyle = true, ShowSize = true, UseFont = true
                });
                // Default to Arial if possible.
                font_button.Widget.Font = Settings.GetSetting(FONT_SETTING, "Arial 12");

                font_button.Widget.FontSet += HandleFontChanged;
            }

            tb.AppendItem(font_button);

            tb.AppendItem(new SeparatorToolItem());

            if (bold_btn == null)
            {
                bold_btn          = new ToolBarToggleButton("Toolbar.Bold.png", Translations.GetString("Bold"), Translations.GetString("Bold"));
                bold_btn.Active   = Settings.GetSetting(BOLD_SETTING, false);
                bold_btn.Toggled += HandleBoldButtonToggled;
            }

            tb.AppendItem(bold_btn);

            if (italic_btn == null)
            {
                italic_btn          = new ToolBarToggleButton("Toolbar.Italic.png", Translations.GetString("Italic"), Translations.GetString("Italic"));
                italic_btn.Active   = Settings.GetSetting(ITALIC_SETTING, false);
                italic_btn.Toggled += HandleItalicButtonToggled;
            }

            tb.AppendItem(italic_btn);

            if (underscore_btn == null)
            {
                underscore_btn          = new ToolBarToggleButton("Toolbar.Underline.png", Translations.GetString("Underline"), Translations.GetString("Underline"));
                underscore_btn.Active   = Settings.GetSetting(UNDERLINE_SETTING, false);
                underscore_btn.Toggled += HandleUnderscoreButtonToggled;
            }

            tb.AppendItem(underscore_btn);

            tb.AppendItem(new SeparatorToolItem());

            var alignment = (TextAlignment)Settings.GetSetting(ALIGNMENT_SETTING, (int)TextAlignment.Left);

            if (left_alignment_btn == null)
            {
                left_alignment_btn          = new ToolBarToggleButton("Toolbar.LeftAlignment.png", Translations.GetString("Left Align"), Translations.GetString("Left Align"));
                left_alignment_btn.Active   = alignment == TextAlignment.Left;
                left_alignment_btn.Toggled += HandleLeftAlignmentButtonToggled;
            }

            tb.AppendItem(left_alignment_btn);

            if (center_alignment_btn == null)
            {
                center_alignment_btn          = new ToolBarToggleButton("Toolbar.CenterAlignment.png", Translations.GetString("Center Align"), Translations.GetString("Center Align"));
                center_alignment_btn.Active   = alignment == TextAlignment.Center;
                center_alignment_btn.Toggled += HandleCenterAlignmentButtonToggled;
            }

            tb.AppendItem(center_alignment_btn);

            if (Right_alignment_btn == null)
            {
                Right_alignment_btn          = new ToolBarToggleButton("Toolbar.RightAlignment.png", Translations.GetString("Right Align"), Translations.GetString("Right Align"));
                Right_alignment_btn.Active   = alignment == TextAlignment.Right;
                Right_alignment_btn.Toggled += HandleRightAlignmentButtonToggled;
            }

            tb.AppendItem(Right_alignment_btn);

            if (fill_sep == null)
            {
                fill_sep = new Gtk.SeparatorToolItem();
            }

            tb.AppendItem(fill_sep);

            if (fill_label == null)
            {
                fill_label = new ToolBarLabel(string.Format(" {0}: ", Translations.GetString("Text Style")));
            }

            tb.AppendItem(fill_label);

            if (fill_button == null)
            {
                fill_button = new ToolBarDropDownButton();

                fill_button.AddItem(Translations.GetString("Normal"), Pinta.Resources.Icons.FillStyleFill, 0);
                fill_button.AddItem(Translations.GetString("Normal and Outline"), Pinta.Resources.Icons.FillStyleOutlineFill, 1);
                fill_button.AddItem(Translations.GetString("Outline"), Pinta.Resources.Icons.FillStyleOutline, 2);
                fill_button.AddItem(Translations.GetString("Fill Background"), Pinta.Resources.Icons.FillStyleBackground, 3);

                fill_button.SelectedIndex        = Settings.GetSetting(STYLE_SETTING, 0);
                fill_button.SelectedItemChanged += HandleBoldButtonToggled;
            }

            tb.AppendItem(fill_button);

            if (outline_sep == null)
            {
                outline_sep = new SeparatorToolItem();
            }

            tb.AppendItem(outline_sep);

            if (outline_width_label == null)
            {
                outline_width_label = new ToolBarLabel(string.Format(" {0}: ", Translations.GetString("Outline width")));
            }

            tb.AppendItem(outline_width_label);

            if (outline_width == null)
            {
                outline_width = new (new SpinButton(1, 1e5, 1)
                {
                    Value = Settings.GetSetting(OUTLINE_WIDTH_SETTING, 2)
                });
                outline_width.Widget.ValueChanged += HandleFontChanged;
            }

            tb.AppendItem(outline_width);

            outline_width.Visible = outline_width_label.Visible = outline_sep.Visible = StrokeText;

            UpdateFont();

            if (PintaCore.Workspace.HasOpenDocuments)
            {
                //Make sure the event handler is never added twice.
                PintaCore.Workspace.ActiveDocument.LayerCloned -= FinalizeText;

                //When an ImageSurface is Cloned, finalize the re-editable text (if applicable).
                PintaCore.Workspace.ActiveDocument.LayerCloned += FinalizeText;
            }
        }
Exemplo n.º 2
0
        protected override void OnBuildToolBar(Gtk.Toolbar tb)
        {
            base.OnBuildToolBar(tb);

            if (font_label == null)
            {
                font_label = new ToolBarLabel(string.Format(" {0}: ", Catalog.GetString("Font")));
            }

            tb.AppendItem(font_label);

            if (font_combo == null)
            {
                var fonts = PintaCore.System.Fonts.GetInstalledFonts();
                fonts.Sort();

                // Default to Arial or first in list
                int index = Math.Max(fonts.IndexOf("Arial"), 0);

                font_combo = new ToolBarFontComboBox(150, index, fonts.ToArray());
                font_combo.ComboBox.Changed += HandleFontChanged;
            }

            tb.AppendItem(font_combo);

            if (spacer_label == null)
            {
                spacer_label = new ToolBarLabel(" ");
            }

            tb.AppendItem(spacer_label);

            if (size_combo == null)
            {
                size_combo = new ToolBarComboBox(65, 0, true);

                size_combo.ComboBox.Changed += HandleSizeChanged;
            }

            tb.AppendItem(size_combo);

            tb.AppendItem(new SeparatorToolItem());

            if (bold_btn == null)
            {
                bold_btn          = new ToolBarToggleButton("Toolbar.Bold.png", Catalog.GetString("Bold"), Catalog.GetString("Bold"));
                bold_btn.Toggled += HandleBoldButtonToggled;
            }

            tb.AppendItem(bold_btn);

            if (italic_btn == null)
            {
                italic_btn          = new ToolBarToggleButton("Toolbar.Italic.png", Catalog.GetString("Italic"), Catalog.GetString("Italic"));
                italic_btn.Toggled += HandleItalicButtonToggled;
            }

            tb.AppendItem(italic_btn);

            if (underscore_btn == null)
            {
                underscore_btn          = new ToolBarToggleButton("Toolbar.Underline.png", Catalog.GetString("Underline"), Catalog.GetString("Underline"));
                underscore_btn.Toggled += HandleUnderscoreButtonToggled;
            }

            tb.AppendItem(underscore_btn);

            tb.AppendItem(new SeparatorToolItem());

            if (left_alignment_btn == null)
            {
                left_alignment_btn          = new ToolBarToggleButton("Toolbar.LeftAlignment.png", Catalog.GetString("Left Align"), Catalog.GetString("Left Align"));
                left_alignment_btn.Active   = true;
                left_alignment_btn.Toggled += HandleLeftAlignmentButtonToggled;
            }

            tb.AppendItem(left_alignment_btn);

            if (center_alignment_btn == null)
            {
                center_alignment_btn          = new ToolBarToggleButton("Toolbar.CenterAlignment.png", Catalog.GetString("Center Align"), Catalog.GetString("Center Align"));
                center_alignment_btn.Toggled += HandleCenterAlignmentButtonToggled;
            }

            tb.AppendItem(center_alignment_btn);

            if (Right_alignment_btn == null)
            {
                Right_alignment_btn          = new ToolBarToggleButton("Toolbar.RightAlignment.png", Catalog.GetString("Right Align"), Catalog.GetString("Right Align"));
                Right_alignment_btn.Toggled += HandleRightAlignmentButtonToggled;
            }

            tb.AppendItem(Right_alignment_btn);

            if (fill_sep == null)
            {
                fill_sep = new Gtk.SeparatorToolItem();
            }

            tb.AppendItem(fill_sep);

            if (fill_label == null)
            {
                fill_label = new ToolBarLabel(string.Format(" {0}: ", Catalog.GetString("Text Style")));
            }

            tb.AppendItem(fill_label);

            if (fill_button == null)
            {
                fill_button = new ToolBarDropDownButton();

                fill_button.AddItem(Catalog.GetString("Normal"), "ShapeTool.Fill.png", 0);
                fill_button.AddItem(Catalog.GetString("Normal and Outline"), "ShapeTool.OutlineFill.png", 1);
                fill_button.AddItem(Catalog.GetString("Outline"), "ShapeTool.Outline.png", 2);
                fill_button.AddItem(Catalog.GetString("Fill Background"), "TextTool.FillBackground.png", 3);

                fill_button.SelectedItemChanged += HandleBoldButtonToggled;
            }

            tb.AppendItem(fill_button);

            tb.AppendItem(new SeparatorToolItem());

            if (outline_width_label == null)
            {
                outline_width_label = new ToolBarLabel(string.Format(" {0}: ", Catalog.GetString("Outline width")));
            }

            tb.AppendItem(outline_width_label);

            if (outline_width_minus == null)
            {
                outline_width_minus          = new ToolBarButton("Toolbar.MinusButton.png", "", Catalog.GetString("Decrease outline size"));
                outline_width_minus.Clicked += MinusButtonClickedEvent;
            }

            tb.AppendItem(outline_width_minus);

            if (outline_width == null)
            {
                outline_width = new ToolBarComboBox(65, 1, true, "1", "2", "3", "4", "5", "6", "7", "8", "9",
                                                    "10", "11", "12", "13", "14", "15", "20", "25", "30", "35",
                                                    "40", "45", "50", "55");

                (outline_width.Child as ComboBoxEntry).Changed += HandleSizeChanged;
            }

            tb.AppendItem(outline_width);

            if (outline_width_plus == null)
            {
                outline_width_plus          = new ToolBarButton("Toolbar.PlusButton.png", "", Catalog.GetString("Increase outline size"));
                outline_width_plus.Clicked += PlusButtonClickedEvent;
            }

            tb.AppendItem(outline_width_plus);

            UpdateFontSizes();

            if (PintaCore.Workspace.HasOpenDocuments)
            {
                //Make sure the event handler is never added twice.
                PintaCore.Workspace.ActiveDocument.LayerCloned -= FinalizeText;

                //When an ImageSurface is Cloned, finalize the re-editable text (if applicable).
                PintaCore.Workspace.ActiveDocument.LayerCloned += FinalizeText;
            }
        }