Commit 7e2fa4e
Merge branch 'master' of github.com:johanmattssonm/birdfont
Changed files (10)
modifiedlibbirdfont/Button.valamodifiedlibbirdfont/CheckBox.valamodifiedlibbirdfont/DescriptionDisplay.valamodifiedlibbirdfont/Dialog.valamodifiedlibbirdfont/Expander.valamodifiedlibbirdfont/KeyBindings.valamodifiedlibbirdfont/MoveTool.valamodifiedlibbirdfont/Renderer/TextArea.valamodifiedlibbirdfont/Toolbox.valamodifiedlibbirdfont/Widget.vala
Diff
@@ -58,7 +58,7 @@ public class Button : Widget { return label.get_width () + 2 * padding; } - public void button_press (uint button, double x, double y) {+ public override void button_press (uint button, double x, double y) { if (is_over (x, y)) { action (); }@@ -26,6 +26,8 @@ public class CheckBox : Widget { public double w = 12 * MainWindow.units; public double h = 12 * MainWindow.units; + bool has_focus = false;+ public Text label; public CheckBox (string text = "", double font_size = -1) {@@ -61,7 +63,13 @@ public class CheckBox : Widget { cr.save (); cr.set_line_width (1);- Theme.color (cr, "Foreground 1");+ + if (has_focus) {+ Theme.color (cr, "Highlighted 1");+ } else {+ Theme.color (cr, "Foreground 1");+ }+ draw_rounded_rectangle (cr, widget_x, widget_y + center_y, w, h - padding, padding); cr.stroke (); cr.restore ();@@ -88,6 +96,18 @@ public class CheckBox : Widget { label.draw (cr); } + public override void key_press (uint keyval) {+ unichar c = (unichar) keyval;++ if (c == ' ') {+ checked = !checked;+ }+ }++ public override void focus (bool focus) {+ has_focus = focus;+ }+ } }@@ -1,5 +1,5 @@ /*- Copyright (C) 2014 Johan Mattsson+ Copyright (C) 2014 2015 Johan Mattsson This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as @@ -22,8 +22,10 @@ public class DescriptionDisplay : FontDisplay { double scroll = 0; double content_height = 1; WidgetAllocation allocation;+ Gee.ArrayList<Widget> focus_ring = new Gee.ArrayList<Widget> ();+ int focus_index = 0; - TextArea? keyboard_focus = null;+ Widget? keyboard_focus = null; TextArea postscript_name; TextArea name;@@ -74,6 +76,7 @@ public class DescriptionDisplay : FontDisplay { font.touch (); }); widgets.add (postscript_name);+ focus_ring.add (postscript_name); widgets.add (new Text (t_("Name"), label_size, label_margin)); name.margin_bottom = margin;@@ -83,7 +86,8 @@ public class DescriptionDisplay : FontDisplay { font.touch (); }); widgets.add (name);- + focus_ring.add (name);+ widgets.add (new Text (t_("Style"), label_size, label_margin)); style.margin_bottom = 1.5 * margin; style.set_text (font.subfamily);@@ -92,6 +96,7 @@ public class DescriptionDisplay : FontDisplay { font.touch (); }); widgets.add (style);+ focus_ring.add (style); bold = new CheckBox (t_("Bold"), label_size); bold.updated.connect ((c) => {@@ -100,6 +105,7 @@ public class DescriptionDisplay : FontDisplay { }); bold.checked = font.bold; widgets.add (bold);+ focus_ring.add (bold); italic = new CheckBox (t_("Italic"), label_size); italic.updated.connect ((c) => {@@ -109,6 +115,7 @@ public class DescriptionDisplay : FontDisplay { italic.checked = font.italic; italic.margin_bottom = margin; widgets.add (italic);+ focus_ring.add (italic); widgets.add (new Text (t_("Weight"), label_size, label_margin)); weight.margin_bottom = margin;@@ -118,6 +125,7 @@ public class DescriptionDisplay : FontDisplay { font.touch (); }); widgets.add (weight);+ focus_ring.add (weight); widgets.add (new Text (t_("Full Name (Name and Style)"), label_size, label_margin)); full_name.margin_bottom = margin;@@ -127,6 +135,7 @@ public class DescriptionDisplay : FontDisplay { font.touch (); }); widgets.add (full_name);+ focus_ring.add (full_name); widgets.add (new Text (t_("Unique Identifier"), label_size, label_margin)); unique_id.margin_bottom = margin;@@ -136,6 +145,7 @@ public class DescriptionDisplay : FontDisplay { font.touch (); }); widgets.add (unique_id);+ focus_ring.add (unique_id); widgets.add (new Text (t_("Version"), label_size, label_margin)); version.margin_bottom = margin;@@ -145,6 +155,7 @@ public class DescriptionDisplay : FontDisplay { font.touch (); }); widgets.add (version);+ focus_ring.add (version); widgets.add (new Text (t_("Description"), label_size, label_margin)); description.margin_bottom = margin;@@ -155,6 +166,7 @@ public class DescriptionDisplay : FontDisplay { font.touch (); }); widgets.add (description);+ focus_ring.add (description); widgets.add (new Text (t_("Copyright"), label_size, label_margin)); copyright.margin_bottom = margin;@@ -166,6 +178,9 @@ public class DescriptionDisplay : FontDisplay { }); copyright.set_editable (!disable_copyright); widgets.add (copyright);+ focus_ring.add (copyright);+ + set_focus (postscript_name); } public static void set_copyright_editable (bool t) {@@ -228,19 +243,43 @@ public class DescriptionDisplay : FontDisplay { } public override void key_press (uint keyval) {- TextArea focus;+ Widget focus;++ if (keyval == Key.SHIFT_TAB) {+ focus_previous ();+ } else if (keyval == Key.TAB) {+ focus_next ();+ } else if (keyboard_focus != null) {+ focus = (!) keyboard_focus;+ focus.key_press (keyval);+ }+ + GlyphCanvas.redraw ();+ }+ + void focus_previous () {+ focus_index--; - if (keyboard_focus == null) {- return;+ if (focus_index < 0) {+ focus_index = 0; } - focus = (!) keyboard_focus;- focus.key_press (keyval);+ set_focus (focus_ring.get (focus_index));+ }+ + void focus_next () {+ focus_index++;+ + if (focus_index >= focus_ring.size) {+ focus_index = focus_ring.size - 1;+ }+ + set_focus (focus_ring.get (focus_index)); } public override void button_press (uint button, double x, double y) {- TextArea t;- TextArea old;+ Widget t;+ Widget old; CheckBox c; foreach (Widget w in widgets) {@@ -249,12 +288,11 @@ public class DescriptionDisplay : FontDisplay { t = (TextArea) w; if (keyboard_focus != null && (!) keyboard_focus != t) { old = (!) keyboard_focus;- old.draw_carret = false;+ old.focus (false); } - t.draw_carret = true;+ set_focus (t); t.button_press (button, x, y);- keyboard_focus = t; } else if (w is CheckBox) { c = (CheckBox) w; c.set_checked (!c.checked);@@ -265,11 +303,47 @@ public class DescriptionDisplay : FontDisplay { GlyphCanvas.redraw (); } + public void set_focus (Widget w) {+ Widget old;+ + if (keyboard_focus != null && (!) keyboard_focus != w) {+ old = (!) keyboard_focus;+ old.focus (false);+ }+ + keyboard_focus = w;+ w.focus (true);+ + focus_index = focus_ring.index_of (w);++ if (!(0 <= focus_index < focus_ring.size)) {+ focus_index = 0;+ }+ + if (w.widget_y < 0) {+ scroll -= allocation.height;++ if (scroll < 0) {+ scroll = 0;+ } + } else if (w.widget_y > allocation.height - 30 * MainWindow.units) {+ scroll += allocation.height;+ + if (scroll + allocation.height >= content_height) {+ scroll = content_height - allocation.height;+ } + } ++ update_scrollbar ();+ GlyphCanvas.redraw ();+ }+ public override void button_release (int button, double x, double y) {- TextArea t;+ Widget t; if (keyboard_focus != null) { t = (!) keyboard_focus;+ set_focus (t); t.button_release (button, x, y); } @@ -277,7 +351,7 @@ public class DescriptionDisplay : FontDisplay { } public override void motion_notify (double x, double y) {- TextArea t;+ Widget t; if (keyboard_focus != null) { t = (!) keyboard_focus;@@ -35,9 +35,6 @@ public class Dialog : Widget { return 0; } - public virtual void button_press (uint button, double x, double y) {- }- } }@@ -135,18 +135,18 @@ public class Expander : GLib.Object { first_row = true; foreach (Tool t in tool) { if (t.tool_is_visible ()) {- new_row = xt + t.w > Toolbox.allocation_width - margin_small;+ new_row = xt + t.w > Toolbox.allocation_width - 7 * scale; if (new_row && !first_row) { content_height += previous.h + margin_small; xt = x;- yt += previous.h + margin_small;+ yt += previous.h + 7 * scale; } t.x = xt; t.y = yt; - xt += t.w + margin_small;+ xt += t.w + 7 * scale; previous = t; first_row = false;@@ -36,6 +36,7 @@ public enum Key { LOGO_RIGHT = 65516, CONTEXT_MENU = 65383, TAB = 65289,+ SHIFT_TAB = 65056, DEL = 65535, NUM_PLUS = 65451, NUM_MINUS = 65453,@@ -61,7 +61,7 @@ public class MoveTool : Tool { }); key_press_action.connect ((self, keyval) => {- key_press (keyval);+ key_down (keyval); }); draw_action.connect ((self, cr, glyph) => {@@ -75,7 +75,7 @@ public class MoveTool : Tool { } } - public void key_press (uint32 keyval) {+ public void key_down (uint32 keyval) { Glyph g = MainWindow.get_current_glyph (); // delete selected paths@@ -72,6 +72,10 @@ public class TextArea : Widget { editable = true; } + public override void focus (bool focus) {+ draw_carret = focus;+ }+ public override double get_height () { return height + 2 * padding; }@@ -114,7 +118,7 @@ public class TextArea : Widget { } } - public void key_press (uint keyval) {+ public override void key_press (uint keyval) { unichar c; TextUndoItem ui; @@ -528,6 +532,22 @@ public class TextArea : Widget { } public void move_carret_next () {+ unichar c;+ + move_carret_one_character ();+ + if (KeyBindings.has_ctrl ()) {+ while (true) {+ c = move_carret_one_character ();+ + if (c == '\0' || c == ' ') {+ break;+ }+ }+ }+ }+ + unichar move_carret_one_character () { Paragraph paragraph; int index; unichar c;@@ -536,17 +556,37 @@ public class TextArea : Widget { paragraph = paragraphs.get (carret.paragraph); index = carret.character_index;+ paragraph.text.get_next_char (ref index, out c); if (index >= paragraph.text_length && carret.paragraph + 1 < paragraphs.size) { carret.paragraph++; carret.character_index = 0;+ c = ' '; } else { carret.character_index = index; }+ + return c; } public void move_carret_previous () {+ unichar c;+ + move_carret_back_one_character ();+ + if (KeyBindings.has_ctrl ()) {+ while (true) {+ c = move_carret_back_one_character ();+ + if (c == '\0' || c == ' ') {+ break;+ }+ }+ }+ }+ + unichar move_carret_back_one_character () { Paragraph paragraph; int index, last_index; unichar c;@@ -571,11 +611,18 @@ public class TextArea : Widget { if (paragraph.text.has_suffix ("\n")) { carret.character_index -= "\n".length; }+ + c = ' ';+ } else if (last_index > 0) {+ carret.character_index = last_index; } else {- carret.character_index = (last_index) > 0 ? last_index : 0;+ carret.character_index = 0;+ c = ' '; } return_if_fail (0 <= carret.paragraph < paragraphs.size);+ + return c; } public void move_carret_next_row () {@@ -951,7 +998,7 @@ public class TextArea : Widget { } } - public void button_press (uint button, double x, double y) {+ public override void button_press (uint button, double x, double y) { if (is_over (x, y)) { carret = get_carret_at (x, y); selection_end = carret.copy ();@@ -959,12 +1006,12 @@ public class TextArea : Widget { } } - public void button_release (uint button, double x, double y) {+ public override void button_release (uint button, double x, double y) { update_selection = false; show_selection = selection_is_visible (); } - public bool motion (double x, double y) {+ public override bool motion (double x, double y) { if (update_selection) { selection_end = get_carret_at (x, y); show_selection = selection_is_visible ();@@ -992,7 +1039,7 @@ public class TextArea : Widget { cr.save (); cr.set_line_width (1); Theme.color (cr, "Text Area Background");- draw_rounded_rectangle (cr, x, y, this.width, this.height, padding);+ draw_rounded_rectangle (cr, x, y, this.width, this.height - padding, padding); cr.fill (); cr.restore (); @@ -1000,7 +1047,7 @@ public class TextArea : Widget { cr.save (); cr.set_line_width (1); Theme.color (cr, "Foreground 1");- draw_rounded_rectangle (cr, x, y, this.width, this.height, padding);+ draw_rounded_rectangle (cr, x, y, this.width, this.height - padding, padding); cr.stroke (); cr.restore (); }@@ -507,11 +507,13 @@ public class Toolbox : GLib.Object { } public void show_tooltip (string tool_tip, double x, double y) {- this.tool_tip = tool_tip;- this.tool_tip_x = x;- this.tool_tip_y = y;- - redraw_tool_box ();+ if (tool_tip != "") {+ this.tool_tip = tool_tip;+ this.tool_tip_x = x;+ this.tool_tip_y = y;+ + redraw_tool_box ();+ } } public class EmptySet : ToolCollection {@@ -53,6 +53,22 @@ public abstract class Widget : GLib.Object { || (widget_y <= allocation.height <= widget_y + get_height ()) || (0 <= widget_y <= allocation.height); }++ public virtual void key_press (uint keyval) { + }++ public virtual void focus (bool enter) { + }++ public virtual void button_press (uint button, double x, double y) {+ }++ public virtual void button_release (uint button, double x, double y) {+ }+ + public virtual bool motion (double x, double y) {+ return false;+ } } }