Commit ca24660
select character set
Changed files (4)
modifiedlibbirdfont/DefaultCharactersSet.valamodifiedlibbirdfont/LanguageSelectionTab.valamodifiedlibbirdfont/MenuTab.valamodifiedlibbirdfont/TabBar.vala
Diff
@@ -27,7 +27,7 @@ public class DefaultCharacterSet { add_language (_("Chinese"), "zh", ""); add_language (_("English"), "en", "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z");- add_language (_("Japanese"), "jp", "");+ add_language (_("Japanese"), "ja", ""); add_language (_("Javanese"), "jv", "ꦀ ꦁ ꦂ ꦃ ꦄ ꦅ ꦆ ꦇ ꦈ ꦉ ꦊ ꦋ ꦌ ꦍ ꦎ ꦏ ꦐ ꦑ ꦒ ꦓ ꦔ ꦕ ꦖ ꦗ ꦘ ꦙ ꦚ ꦛ ꦜ ꦝ ꦞ ꦟ ꦠ ꦡ ꦢ ꦣ ꦤ ꦥ ꦦ ꦧ ꦨ ꦩ ꦪ ꦫ ꦬ ꦭ ꦮ ꦯ ꦰ ꦱ ꦲ ꦳ ꦴ ꦵ ꦶ ꦷ ꦸ ꦹ ꦺ ꦻ ꦼ ꦽ ꦾ ꦿ ꧀ ꧁ ꧂ ꧃ ꧄ ꧅ ꧆ ꧇ ꧈ ꧉ ꧊ ꧋ ꧌ ꧍ ꧏ ꧐ ꧑ ꧒ ꧓ ꧔ ꧕ ꧖ ꧗ ꧘ ꧙ ꧞ ꧟ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z"); add_language (_("Russian"), "ro", "А Б В Г Д Е Ё Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Ъ Ы Ь Э Ю Я а б в г д е ё ж з и й к л м н о п р с т у ф х ц ч ш щ ъ ы ь э ю я"); add_language (_("Swedish"), "sv", "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z Å Ä Ö a b c d e f g h i j k l m n o p q r s t u v w x y z å ä ö");@@ -11,71 +11,145 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. */+using Cairo;+using Math; namespace BirdFont { public class LanguageSelectionTab : FontDisplay { - public LanguageSelectionTab () { - add_html_callback ("select_language", (val) => {- TabBar tb = MainWindow.get_tab_bar ();- set_prefered_character_set (val);- tb.close_display (this);- Toolbox.select_tool_by_name ("custom_character_set"); - });+ int scroll = 0;+ int visible_rows = 0;+ WidgetAllocation allocation = new WidgetAllocation ();+ + public LanguageSelectionTab () {+ }++ void select_language (int row) {+ string iso_code;+ TabBar tb = MainWindow.get_tab_bar ();+ + return_if_fail (0 <= row < DefaultLanguages.codes.length ());+ + iso_code = DefaultLanguages.codes.nth (row).data;+ Preferences.set ("language", iso_code);+ tb.close_display (this);+ Toolbox.select_tool_by_name ("custom_character_set"); } - /** @param iso_code language iso code. */- public static void set_prefered_character_set (string iso_code) {- Preferences.set ("language", iso_code); + public override void button_release (int button, double ex, double ey) {+ int r = (int) rint ((ey - 17) / 18.0);+ if (button == 1 && 0 <= r < DefaultLanguages.codes.length ()) {+ select_language (r + scroll);+ }+ }+ + public override void draw (WidgetAllocation allocation, Context cr) {+ int y = 20;+ int s = 0;+ bool color = (scroll % 2) == 0;+ + this.allocation = allocation;+ + visible_rows = (int) (allocation.height / 18.0);+ + cr.save ();+ cr.set_source_rgba (1, 1, 1, 1);+ cr.rectangle (0, 0, allocation.width, allocation.height);+ cr.fill ();+ cr.restore ();+ + cr.save ();+ cr.set_source_rgba (0.3, 0.3, 0.3, 1);+ cr.set_font_size (12);+ + foreach (string language in DefaultLanguages.names) {+ if (s++ >= scroll) {+ draw_row (allocation, cr, language, color, y);+ y += 18;+ color = !color;+ }+ }+ cr.restore ();+ } ++ private static void draw_row (WidgetAllocation allocation, Context cr, string language, bool color, double y) {++ if (color) {+ cr.save ();+ cr.set_source_rgba (224/255.0, 224/255.0, 224/255.0, 1);+ cr.rectangle (0, y - 14, allocation.width, 18);+ cr.fill ();+ cr.restore ();+ }+ + cr.move_to (30, y);+ cr.show_text (language); } public override string get_name () {- return _("Character set");+ _("Character set");+ return "Character set"; } - public override bool is_html_canvas () {+ public override bool has_scrollbar () { return true; } - public override string get_html () {- string headline = _("Select default character set");- StringBuilder c = new StringBuilder ();+ public override void scroll_wheel_down (double x, double y) {+ uint rows = DefaultLanguages.names.length ();+ scroll += 3; - c.append ("""-<html>-<head>- <script type="text/javascript" src="supplement.js"></script>- <style type="text/css">@import url("style.css");</style>-</head>-<body>- - <div style="width:350px; margin: 50px auto 0 auto;">- <div class="heading"><h2>""" + headline + """</h2></div>+ if (scroll + visible_rows > rows) {+ scroll = (int) (rows - visible_rows);+ } - <form>- """);+ if (scroll < 0) {+ scroll = 0;+ } - int i = 0;- string language_code;- foreach (string language in DefaultLanguages.names) {- language_code = DefaultLanguages.codes.nth (i).data;- c.append ("""- <input class="button" type="button" value=""" + "\"" + language + "\"" - + """ onclick="call ('select_language:""" + language_code + """');"/>- <br />- """);- i++;+ update_scrollbar ();+ redraw_area (0, 0, allocation.width, allocation.height);+ }+ + public override void scroll_wheel_up (double x, double y) {+ scroll -= 3;+ + if (scroll < 0) {+ scroll = 0; } - c.append ("""- </form>- </div>-</body>-</html>""");+ update_scrollbar ();+ redraw_area (0, 0, allocation.width, allocation.height);+ } - return c.str;- } + public override void selected_canvas () {+ update_scrollbar ();+ redraw_area (0, 0, allocation.width, allocation.height);+ }+ + public void update_scrollbar () {+ uint rows = DefaultLanguages.names.length ();++ if (rows == 0 || visible_rows == 0) {+ MainWindow.set_scrollbar_size (0);+ MainWindow.set_scrollbar_position (0);+ } else {+ MainWindow.set_scrollbar_size ((double) visible_rows / rows);+ MainWindow.set_scrollbar_position ((double) scroll / rows);+ }+ }++ public override void scroll_to (double percent) {+ uint rows = DefaultLanguages.names.length ();+ scroll = (int) (percent * rows);+ + if (scroll > rows - visible_rows) {+ scroll = (int) (rows - visible_rows);+ }+ + redraw_area (0, 0, allocation.width, allocation.height);+ } } }@@ -517,7 +517,7 @@ c.append (""" /** Display the language selection tab. */ public static void select_language () {- MainWindow.get_tab_bar ().add_unique_tab (new LanguageSelectionTab (), 120, false);+ MainWindow.get_tab_bar ().add_unique_tab (new LanguageSelectionTab ()); } public static void use_current_glyph_as_background () {@@ -431,7 +431,7 @@ public class TabBar : GLib.Object { int s = (tabs.length () == 0) ? 0 : selected + 1; if (tab_width < 0) {- tab_width = 9 * display_item.get_name ().char_count ();+ tab_width = 9 * _(display_item.get_name ()).char_count (); tab_width += 30; }