Commit 3d7d3f1
New file menu
Changed files (6)
modifiedgraphics/tools_and_buttons.svgaddedicons/menu.pngmodifiedlibbirdfont/MainWindow.valaaddedlibbirdfont/Menu.valamodifiedlibbirdfont/TabBar.valamodifiedlibbirdfont/TabContent.vala
Diff
@@ -1524,8 +1524,8 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="4.0000001"- inkscape:cx="324.93909"- inkscape:cy="128.40856"+ inkscape:cx="459.05169"+ inkscape:cy="687.23668" inkscape:current-layer="layer1" inkscape:document-units="px" showgrid="false"@@ -3955,12 +3955,12 @@ inkscape:export-xdpi="320" inkscape:export-ydpi="320" /> <rect- style="opacity:1;color:#000000;fill:#33363b;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:20;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"+ style="color:#000000;fill:#33363b;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:20;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" id="rect4330" width="174.22142"- height="37.342556"+ height="37.098652" x="270.01135"- y="130.7104" />+ y="130.9543" /> <path style="fill:#2c2f33;fill-opacity:1;stroke:#26272b;stroke-width:1.08162749;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1" d="m 369.43527,135.01754 18.88609,0.13751 c 3.96902,0.0969 5.3426,1.35943 5.77448,4.78631 l 0.0259,17.0893 c -0.12039,3.50816 -1.85708,4.92123 -4.96983,4.90512 l -20.94199,0 c -2.02353,-0.10763 -3.91115,-0.89537 -4.00655,-3.65731 l 0,-17.73466 c 0.003,-3.90203 1.49133,-5.42246 5.23184,-5.52627 z"@@ -5765,5 +5765,36 @@ inkscape:export-filename="/home/johan/birdfont/icons/generate_html_document.png" inkscape:export-xdpi="320" inkscape:export-ydpi="320" />+ <g+ id="g3826"+ transform="translate(-19.999999,-59.499998)"+ inkscape:export-filename="/home/johan/birdfont/icons/menu.png"+ inkscape:export-xdpi="320"+ inkscape:export-ydpi="320">+ <path+ inkscape:export-ydpi="319.88824"+ inkscape:export-xdpi="319.88824"+ inkscape:export-filename="/home/johan/birdfont/icons/zoom_out.png"+ style="fill:none;stroke:#656a73;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"+ d="m 429.55443,116.58311 -16.23756,0"+ id="path4868-4-9-2-3"+ inkscape:connector-curvature="0" />+ <path+ inkscape:connector-curvature="0"+ id="path4947-0-3"+ d="m 429.55443,120.41629 -16.23756,0"+ style="fill:none;stroke:#656a73;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"+ inkscape:export-filename="/home/johan/birdfont/icons/zoom_out.png"+ inkscape:export-xdpi="319.88824"+ inkscape:export-ydpi="319.88824" />+ <path+ inkscape:export-ydpi="319.88824"+ inkscape:export-xdpi="319.88824"+ inkscape:export-filename="/home/johan/birdfont/icons/zoom_out.png"+ style="fill:none;stroke:#656a73;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"+ d="m 429.55443,124.53239 -16.23756,0"+ id="path3824"+ inkscape:connector-curvature="0" />+ </g> </g> </svg>new file mode 100644Binary files /dev/null and b/icons/menu.png differ@@ -29,6 +29,7 @@ public class MainWindow : GLib.Object { public static CharDatabase character_database; public static LigatureList ligature_display; public static SpacingClassTab spacing_class_tab; + public static Menu menu; /** Number of pixels per mm */ public static double units = 1; @@ -47,6 +48,11 @@ public class MainWindow : GLib.Object { character_database = new CharDatabase (); ligature_display = new LigatureList (); spacing_class_tab = new SpacingClassTab (); + menu = new Menu (); + } + + public static Menu get_menu () { + return menu; } /** Set the number of picels per millimeter for the current screen. */ new file mode 100644@@ -0,0 +1,218 @@+/*+ Copyright (C) 2014 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 + published by the Free Software Foundation; either version 3 of the + License, or (at your option) any later version.++ This library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details.+*/++using Cairo;++namespace BirdFont {++/** Interface for events from native window to the current tab. */+public class Menu : GLib.Object {++ public bool show_menu {+ get {+ return menu_visibility;+ }+ + set {+ string tab_name;+ + menu_visibility = value;+ current_menu = top_menu;+ + if (menu_visibility) {+ tab_name = MainWindow.get_tab_bar ().get_selected_tab ().get_display ().get_name ();+ if (tab_name == "Description" || tab_name == "Preview") {+ MenuTab.select_overview ();+ }+ }+ }+ }+ + public bool menu_visibility = false;+ public SubMenu top_menu;++ SubMenu current_menu;+ WidgetAllocation allocation;++ double width = 250 * MainWindow.units;+ double height = 25 * MainWindow.units;+ + public Menu () {+ SubMenu menu = new SubMenu ();+ SubMenu file_menu = new SubMenu ();+ + MenuItem file = new MenuItem (t_("File"));+ file.action.connect (() => {+ set_menu (file_menu);+ });+ + menu.items.add (file);++ MenuItem new_file = new MenuItem (t_("New"), "new");+ new_file.action.connect (() => {+ MenuTab.new_file ();+ show_menu = false;+ });+ file_menu.items.add (new_file);+ + MenuItem open = new MenuItem (t_("Open"), "open");+ open.action.connect (() => {+ show_menu = false;+ MenuTab.load ();+ });+ file_menu.items.add (open);++ MenuItem recent_files = new MenuItem (t_("Recent Files"), "recent files");+ recent_files.action.connect (() => {+ show_menu = false;+ MainWindow.open_recent_files_tab ();+ });+ file_menu.items.add (recent_files);+ + MenuItem save = new MenuItem (t_("Save"), "save");+ save.action.connect (() => {+ MenuTab.save ();+ show_menu = false;+ });+ file_menu.items.add (save);++ MenuItem save_as = new MenuItem (t_("Save As"), "save as");+ save_as.action.connect (() => {+ MenuTab.save_as ();+ show_menu = false;+ });+ file_menu.items.add (save_as);++ MenuItem export = new MenuItem (t_("Export"), "export");+ export.action.connect (() => {+ MenuTab.export_fonts_in_background ();+ show_menu = false;+ });+ file_menu.items.add (export);++ MenuItem preview = new MenuItem (t_("Preview"), "preview");+ preview.action.connect (() => {+ MenuTab.preview ();+ show_menu = false;+ });+ file_menu.items.add (preview);++ MenuItem description = new MenuItem (t_("Name and Description"), "name and description");+ description.action.connect (() => {+ MenuTab.show_description ();+ show_menu = false;+ });+ file_menu.items.add (description);++ MenuItem select_character_set = new MenuItem (t_("Select Character Set"), "select character set");+ select_character_set.action.connect (() => {+ MenuTab.select_language ();+ show_menu = false;+ });+ file_menu.items.add (select_character_set);+ + MenuItem settings = new MenuItem (t_("Settings"), "settings");+ settings.action.connect (() => {+ MenuTab.show_settings_tab ();+ show_menu = false;+ });+ file_menu.items.add (settings);++ MenuItem quit = new MenuItem (t_("Quit"), "quit");+ quit.action.connect (() => {+ MenuTab.quit ();+ show_menu = false;+ });+ file_menu.items.add (quit);+ + current_menu = menu;+ top_menu = menu;+ allocation = new WidgetAllocation ();+ }++ public void button_release (int button, double ex, double ey) {+ double y = 0;+ double x = allocation.width - width;+ + foreach (MenuItem item in current_menu.items) {+ if (x <= ex < allocation.width && y <= ey <= y + height) {+ item.action ();+ GlyphCanvas.redraw ();+ return;+ }+ + y += height;+ }+ + menu_visibility = false;+ current_menu = (!) top_menu;+ GlyphCanvas.redraw ();+ }++ public void set_menu (SubMenu m) {+ current_menu = m;+ GlyphCanvas.redraw ();+ }+ + public void draw (WidgetAllocation allocation, Context cr) {+ double y = 0;+ double x = allocation.width - width;+ double label_x;+ double label_y;+ double font_size;+ + this.allocation = allocation;+ + foreach (MenuItem item in current_menu.items) {+ cr.save ();+ cr.set_source_rgba (38 / 255.0, 39 / 255.0, 43 / 255.0, 1);+ cr.rectangle (x, y, width, height);+ cr.fill ();+ cr.restore ();+ + cr.save ();+ cr.set_source_rgba (101 / 255.0, 108 / 255.0, 116 / 255.0, 1);+ label_x = allocation.width - width + 0.7 * height * MainWindow.units;+ font_size = 17 * MainWindow.units;+ label_y = y + font_size - 1 * MainWindow.units;+ item.label.draw (cr, label_x, label_y, font_size);+ + y += height;+ }+ }++ public class SubMenu : GLib.Object { + public Gee.ArrayList<MenuItem> items;+ + public SubMenu () {+ items = new Gee.ArrayList<MenuItem> ();+ }+ }+ + public class MenuItem : GLib.Object {+ + public signal void action ();+ public Text label;+ public string identifier;+ + public MenuItem (string label, string identifier = "") {+ this.label = new Text ();+ this.label.set_text (label);+ this.identifier = identifier;+ }+ + }+}++}@@ -27,6 +27,7 @@ public class TabBar : GLib.Object { static const int NEXT_TAB = -2; static const int PREVIOUS_TAB = -3; static const int PROGRESS_WHEEL = -3;+ static const int SHOW_MENU = -4; int first_tab = 0; int selected = 0;@@ -45,6 +46,7 @@ public class TabBar : GLib.Object { ImageSurface? to_previous_tab; ImageSurface? tab_bar_background = null;+ ImageSurface? menu_icon; double scale = 1; // scale images in 320 dpi @@ -63,6 +65,8 @@ public class TabBar : GLib.Object { progress = Icons.get_icon ("progress_wheel.png"); tab_bar_background = Icons.get_icon ("tab_bar_background.png");+ + menu_icon = Icons.get_icon ("menu.png"); } public void set_background_color (double r, double g, double b) {@@ -72,6 +76,11 @@ public class TabBar : GLib.Object { } public void motion (double x, double y) {+ if (MenuTab.suppress_event) {+ warn_if_test ("Event suppressed");+ return;+ }+ over_close (x, y, out over, out over_close_tab); } @@ -86,7 +95,13 @@ public class TabBar : GLib.Object { return; } - if (has_scroll () && has_progress_wheel ()) {+ if (!has_progress_wheel ()) {+ if (x > width - 25) {+ over_close_tab = NO_TAB;+ over = SHOW_MENU;+ return;+ }+ } else if (has_scroll () && has_progress_wheel ()) { if (x > width - 19) { over_close_tab = NO_TAB; over = PROGRESS_WHEEL;@@ -386,6 +401,12 @@ public class TabBar : GLib.Object { // always close any pending text input if the user switches tab MainWindow.native_window.hide_text_input (); + if (index == SHOW_MENU) {+ MainWindow.get_menu ().show_menu = ! MainWindow.get_menu ().show_menu;+ GlyphCanvas.redraw ();+ return;+ }+ if (index == NEXT_TAB) { selected++; @@ -508,6 +529,8 @@ public class TabBar : GLib.Object { public void select_tab_click (double x, double y, int width, int height) { int over, close; + MainWindow.get_menu ().show_menu = false;+ this.width = width; this.height = height; this.scale = height / 117.0;@@ -634,7 +657,19 @@ public class TabBar : GLib.Object { progress_y = (has_scroll ()) ? h - ((!) progress).get_height () - 5 / scale : (h - ((!) progress).get_height ()) / 2; cr.set_source_surface (c.get_target (), w - 19 / scale, progress_y); cr.paint ();- + } else {+ // menu icon+ if (menu_icon != null) {+ + if (MainWindow.get_menu ().show_menu) {+ cr.set_source_rgba (38 / 255.0, 39 / 255.0, 43 / 255.0, 1);+ cr.rectangle (w - 32 / scale, 0, 32 / scale, h);+ cr.fill ();+ }+ + cr.set_source_surface ((!) menu_icon, w - 25 / scale, h / 2.0 - ((!) menu_icon).get_height () / 2.0);+ cr.paint ();+ } } draw_tabs (cr);@@ -59,6 +59,8 @@ public class TabContent : GLib.Object { } public static void draw (WidgetAllocation allocation, Context cr) {+ Menu menu = MainWindow.get_menu ();+ if (MenuTab.suppress_event) { cr.save (); cr.set_source_rgba (1, 1, 1, 1);@@ -69,6 +71,10 @@ public class TabContent : GLib.Object { GlyphCanvas.set_allocation (allocation); MainWindow.get_current_glyph ().resized (allocation); GlyphCanvas.current_display.draw (allocation, cr);+ + if (menu.show_menu) {+ menu.draw (allocation, cr);+ } } } @@ -111,7 +117,11 @@ public class TabContent : GLib.Object { return; } - GlyphCanvas.current_display.button_release (button, x, y);+ if (MainWindow.get_menu ().show_menu) {+ MainWindow.get_menu ().button_release (button, x, y);+ } else {+ GlyphCanvas.current_display.button_release (button, x, y);+ } } public static void button_press (uint button, double x, double y) {@@ -119,7 +129,9 @@ public class TabContent : GLib.Object { return; } - GlyphCanvas.current_display.button_press (button, x, y);+ if (!MainWindow.get_menu ().show_menu) {+ GlyphCanvas.current_display.button_press (button, x, y);+ } } public static void double_click (uint button, double ex, double ey) {@@ -127,7 +139,9 @@ public class TabContent : GLib.Object { return; } - GlyphCanvas.current_display.double_click (button, ex, ey);+ if (!MainWindow.get_menu ().show_menu) {+ GlyphCanvas.current_display.double_click (button, ex, ey);+ } } public static void scroll_wheel_up (double x, double y) {@@ -135,7 +149,9 @@ public class TabContent : GLib.Object { return; } - GlyphCanvas.current_display.scroll_wheel_up (x, y);+ if (!MainWindow.get_menu ().show_menu) {+ GlyphCanvas.current_display.scroll_wheel_up (x, y);+ } } public static void scroll_wheel_down (double x, double y) {@@ -143,7 +159,9 @@ public class TabContent : GLib.Object { return; } - GlyphCanvas.current_display.scroll_wheel_down (x, y);+ if (!MainWindow.get_menu ().show_menu) {+ GlyphCanvas.current_display.scroll_wheel_down (x, y);+ } } public static void tap_down (int finger, int x, int y) {@@ -151,7 +169,9 @@ public class TabContent : GLib.Object { return; } - GlyphCanvas.current_display.tap_down (finger, x, y);+ if (!MainWindow.get_menu ().show_menu) {+ GlyphCanvas.current_display.tap_down (finger, x, y);+ } } public static void tap_up (int finger, int x, int y) {@@ -159,7 +179,9 @@ public class TabContent : GLib.Object { return; } - GlyphCanvas.current_display.tap_up (finger, x, y);+ if (!MainWindow.get_menu ().show_menu) {+ GlyphCanvas.current_display.tap_up (finger, x, y);+ } } public static void tap_move (int finger, int x, int y) {@@ -167,7 +189,9 @@ public class TabContent : GLib.Object { return; } - GlyphCanvas.current_display.tap_move (finger, x, y);+ if (!MainWindow.get_menu ().show_menu) {+ GlyphCanvas.current_display.tap_move (finger, x, y);+ } } public static void undo () {