.
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 using Cairo;
16 using Math;
17
18 namespace BirdFont {
19
20 public abstract class FontDisplay : GLib.Object {
21
22 private static double last_tap_y = -1;
23 private static double last_tap_time = 0;
24
25 public static bool dirty_scrollbar = true;
26
27 /** Queue redraw area */
28 public signal void redraw_area (double x, double y, double w, double h);
29
30 public virtual string get_name () {
31 warning ("No name.");
32 return "";
33 }
34
35 public virtual string get_label () {
36 warning ("No label.");
37 return "";
38 }
39
40 public virtual void close () {
41 }
42
43 public virtual bool has_scrollbar () {
44 return false;
45 }
46
47 public virtual void update_scrollbar () {
48 }
49
50 public virtual void scroll_to (double percent) {
51 }
52
53 public virtual void draw (WidgetAllocation allocation, Context cr) {
54 }
55
56 public virtual void selected_canvas () {
57 }
58
59 public virtual void key_press (uint keyval) {
60 }
61
62 public virtual void key_release (uint keyval) {
63 }
64
65 public virtual void motion_notify (double x, double y) {
66 }
67
68 public virtual void button_release (int button, double x, double y) {
69 }
70
71 public virtual void button_press (uint button, double x, double y) {
72 }
73
74 public virtual void double_click (uint button, double ex, double ey) {
75 }
76
77 public virtual void tap_down (int finger, int x, int y) {
78 if (finger == 0) {
79 if ((GLib.get_real_time () - last_tap_time) / 1000000.0 < 0.4) {
80 double_click (1, x, y);
81 } else {
82 button_press (1, x, y);
83 }
84
85 last_tap_time = GLib.get_real_time ();
86 }
87
88 last_tap_y = -1;
89 }
90
91 public virtual void tap_up (int finger, int x, int y) {
92 if (finger == 0) {
93 button_release (1, x, y);
94 }
95
96 last_tap_y = -1;
97 }
98
99 public virtual void tap_move (int finger, int x, int y) {
100 double d;
101 if (finger == 0) {
102 motion_notify (x, y);
103
104 d = y - last_tap_y;
105 if (last_tap_y > -1 && fabs (d) > 15) { // FIXME: pixels, other units are better
106 if (d > 0) {
107 scroll_wheel_up (x, y);
108 } else {
109 scroll_wheel_down (x, y);
110 }
111 }
112
113 last_tap_y = y;
114 }
115 }
116
117 public virtual void zoom_in () {
118 }
119
120 public virtual void zoom_out () {
121 }
122
123 public virtual void zoom_max () {
124 }
125
126 public virtual void zoom_min () {
127 }
128
129 public virtual void move_view (double x, double y) {
130 }
131
132 public virtual void reset_zoom () {
133 }
134
135 public virtual void store_current_view () {
136 }
137
138 public virtual void restore_last_view () {
139 }
140
141 public virtual void next_view () {
142 }
143
144 public virtual void scroll_wheel_up (double x, double y) {
145 }
146
147 public virtual void scroll_wheel_down (double x, double y) {
148 }
149
150 public virtual void undo () {
151 }
152
153 public virtual void redo () {
154 }
155
156 public static File find_file (string? dir, string name) {
157 return SearchPaths.find_file (dir, name);
158 }
159
160 /** returns false if bindings to a single key works in the display. */
161 public virtual bool needs_modifier () {
162 return false;
163 }
164 }
165
166 }
167