Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Text Tool #558

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions data/schemas/com.github.akiraux.akira.gschema.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,21 @@
<summary>Default Border Color.</summary>
<description>The default color of the border for a newly created shape.</description>
</key>
<key name="text-color" type="s">
<default>'#000'</default>
<summary>Default CanvasText Font Color.</summary>
<description>The default color of the CanvasText font for a newly created shape.</description>
</key>
<key name="text-size" type="i">
<default>18</default>
<summary>Default CanvasText Text Size</summary>
<description>The default font size of the CanvasText for a newly created shape.</description>
</key>
<key name="text-font" type="s">
<default>'OpenSans'</default>
<summary>Default CanvasText Font.</summary>
<description>The default font for the CanvasText.</description>
</key>

<key name="open-quick" type="b">
<default>false</default>
Expand Down
44 changes: 44 additions & 0 deletions src/Dialogs/SettingsDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public class Akira.Dialogs.SettingsDialog : Gtk.Dialog {
private Gtk.ColorButton fill_color;
private Gtk.ColorButton border_color;
private Gtk.SpinButton border_size;
private Gtk.ColorButton text_fill_color;
private Partials.InputField text_size;
private Gtk.ComboBoxText font_name;

public string [] fonts = Utils.Font.get_fonts ();

public SettingsDialog (Akira.Window _window) {
Object (
Expand Down Expand Up @@ -223,6 +228,9 @@ public class Akira.Dialogs.SettingsDialog : Gtk.Dialog {
var border_rgba = Gdk.RGBA ();
border_rgba.parse (settings.border_color);

var text_fill_rgba = Gdk.RGBA ();
text_fill_rgba.parse (settings.text_color);

grid.attach (new SettingsHeader (_("Default Colors")), 0, 0, 2, 1);

var description = new Gtk.Label (_("Define the default style used when creating a new shape."));
Expand All @@ -232,6 +240,8 @@ public class Akira.Dialogs.SettingsDialog : Gtk.Dialog {

grid.attach (new SettingsLabel (_("Fill Color:")), 0, 2, 1, 1);
fill_color = new Gtk.ColorButton.with_rgba (fill_rgba);
text_fill_color = new Gtk.ColorButton.with_rgba (text_fill_rgba);
text_fill_color.halign = Gtk.Align.START;
fill_color.halign = Gtk.Align.START;
grid.attach (fill_color, 1, 2, 1, 1);

Expand All @@ -251,6 +261,22 @@ public class Akira.Dialogs.SettingsDialog : Gtk.Dialog {
settings.fill_color = rgba_str;
});

text_fill_color.color_set.connect (() => {
var rgba = text_fill_color.get_rgba ();

// Gdk.RGBA uses rgb() if alpha is 1.
string rgba_str = "rgba(%d,%d,%d,%d)".printf (
(int) (rgba.red * 255),
(int) (rgba.green * 255),
(int) (rgba.blue * 255),
(int) (rgba.alpha)
);

debug ("setting color: %s", rgba_str);

settings.text_color = rgba_str;
});

grid.attach (new SettingsLabel (_("Enable Border Style:")), 0, 3, 1, 1);
border_switch = new SettingsSwitch ("set-border");
grid.attach (border_switch, 1, 3, 1, 1);
Expand Down Expand Up @@ -284,8 +310,26 @@ public class Akira.Dialogs.SettingsDialog : Gtk.Dialog {
border_size.secondary_icon_sensitive = false;
border_size.secondary_icon_activatable = false;
grid.attach (border_size, 1, 5, 1, 1);
grid.attach (new SettingsLabel (_("Text Tool Fill:")), 0, 6, 1, 1);
grid.attach (text_fill_color, 1, 6, 1, 1);
text_size = new Akira.Partials.InputField (Akira.Partials.InputField.Unit.PIXEL, 6, true, true);
text_size.halign = Gtk.Align.START;
text_size.entry.hexpand = false;
text_size.entry.sensitive = true;
text_size.set_range (1, 5000);
grid.attach (new SettingsLabel (_("Text Tool Font Size:")), 0, 7, 1, 1);
grid.attach (text_size, 1, 7, 1, 1);
font_name = new Gtk.ComboBoxText.with_entry ();
font_name.halign = Gtk.Align.START;
foreach (string font in fonts) {
font_name.append (font, font);
}
grid.attach (new SettingsLabel (_("Text Tool Font Name:")), 0, 8, 1, 1);
grid.attach (font_name, 1, 8, 1, 1);

settings.bind ("border-size", border_size, "value", SettingsBindFlags.DEFAULT);
settings.bind ("text-size", text_size.entry, "value", SettingsBindFlags.DEFAULT);
settings.bind ("text-font", font_name, "active_id", SettingsBindFlags.DEFAULT);

border_switch.bind_property ("active", border_color, "sensitive", BindingFlags.SYNC_CREATE);
border_switch.bind_property ("active", border_size, "sensitive", BindingFlags.SYNC_CREATE);
Expand Down
2 changes: 2 additions & 0 deletions src/Layouts/LeftSideBar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class Akira.Layouts.LeftSideBar : Gtk.Grid {
var align_items_panel = new Akira.Layouts.Partials.AlignItemsPanel (window);
transform_panel = new Akira.Layouts.Partials.TransformPanel (window);
var border_radius_panel = new Akira.Layouts.Partials.BorderRadiusPanel (window);
var text_options_panel = new Akira.Layouts.Partials.TextOptionsPanel (window);
fills_panel = new Akira.Layouts.Partials.FillsPanel (window);
borders_panel = new Akira.Layouts.Partials.BordersPanel (window);

Expand All @@ -61,6 +62,7 @@ public class Akira.Layouts.LeftSideBar : Gtk.Grid {
scrolled_grid.expand = true;
scrolled_grid.attach (transform_panel, 0, 0, 1, 1);
scrolled_grid.attach (border_radius_panel, 0, 1, 1, 1);
scrolled_grid.attach (text_options_panel, 0, 4, 1, 1);
scrolled_grid.attach (fills_panel, 0, 2, 1, 1);
scrolled_grid.attach (borders_panel, 0, 3, 1, 1);
scrolled_window.add (scrolled_grid);
Expand Down
Loading