The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

ZoomTool.vala in libbirdfont

This file is a part of the Birdfont project.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git

Revisions

View the latest version of libbirdfont/ZoomTool.vala.
Suppress zoom when canvas is moving
1 /* 2 Copyright (C) 2012 Johan Mattsson 3 4 This library is free software; you can redistribute it and/or modify 5 it under the terms of the GNU Lesser General Public License as 6 published by the Free Software Foundation; either version 3 of the 7 License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, but 10 WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 */ 14 15 namespace BirdFont { 16 17 public class ZoomTool : Tool { 18 19 int zoom_area_begin_x = -1; 20 int zoom_area_begin_y = -1; 21 22 int view_index = 0; 23 Gee.ArrayList<Tab> views; 24 25 public ZoomTool (string n) { 26 base (n, "Zoom"); 27 28 views = new Gee.ArrayList<Tab> (); 29 30 select_action.connect((self) => { 31 }); 32 33 select_action.connect((self) => { 34 }); 35 36 press_action.connect((self, b, x, y) => { 37 if (b == 1 && KeyBindings.modifier != CTRL) { 38 zoom_area_begin_x = x; 39 zoom_area_begin_y = y; 40 } 41 }); 42 43 move_action.connect((self, x, y) => { 44 Glyph g; 45 46 if (zoom_area_begin_x > 0) { 47 g = MainWindow.get_current_glyph (); 48 g.show_zoom_area (zoom_area_begin_x, zoom_area_begin_y, x, y); 49 } 50 }); 51 52 release_action.connect((self, b, x, y) => { 53 Glyph g; 54 55 if (b == 1 && KeyBindings.modifier != CTRL) { 56 store_current_view (); 57 58 g = MainWindow.get_current_glyph (); 59 60 if (zoom_area_begin_x == x && zoom_area_begin_y == y) { // zero width center this point but don't zoom in 61 g.set_center (x, y); 62 } else { 63 g.set_zoom_from_area (); 64 } 65 66 zoom_area_begin_x = -1; 67 zoom_area_begin_y = -1; 68 } 69 }); 70 } 71 72 public static void zoom_full_background_image () { 73 BackgroundImage bg; 74 Glyph g = MainWindow.get_current_glyph (); 75 int x, y; 76 77 g.reset_zoom (); 78 79 if (g.get_background_image () == null) { 80 return; 81 } 82 83 bg = (!) g.get_background_image (); 84 85 x = (int) (bg.img_offset_x); 86 y = (int) (bg.img_offset_y); 87 88 g.set_zoom_area (x, y, (int) (x + bg.size_margin * bg.img_scale_x), (int) (y + bg.size_margin * bg.img_scale_y)); 89 g.set_zoom_from_area (); 90 } 91 92 public void zoom_full_glyph () { 93 store_current_view (); 94 95 MainWindow.get_current_display ().zoom_min (); 96 } 97 98 /** Add an item to zoom view list. */ 99 public void store_current_view () { 100 if (views.size - 1 > view_index) { 101 int i = view_index + 1; 102 while (i != views.size - 1) { 103 views.remove_at (i); 104 } 105 } 106 107 views.add (MainWindow.get_current_tab ()); 108 view_index = (int) views.size - 1; 109 MainWindow.get_current_display ().store_current_view (); 110 } 111 112 /** Redo last zoom.*/ 113 public void next_view () { 114 if (view_index + 1 >= (int) views.size) { 115 return; 116 } 117 118 view_index++; 119 120 MainWindow.get_current_display ().next_view (); 121 GlyphCanvas.redraw (); 122 } 123 124 /** Undo last zoom. */ 125 public void previous_view () { 126 if (view_index == 0) { 127 return; 128 } 129 130 view_index--; 131 132 MainWindow.get_current_display ().restore_last_view (); 133 GlyphCanvas.redraw (); 134 } 135 } 136 137 } 138