.
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 magnify (double magnification) {
78 }
79
80 public virtual void tap_down (int finger, int x, int y) {
81 if (finger == 0) {
82 if ((GLib.get_real_time () - last_tap_time) / 1000000.0 < 0.4) {
83 double_click (1, x, y);
84 } else {
85 button_press (1, x, y);
86 }
87
88 last_tap_time = GLib.get_real_time ();
89 }
90
91 last_tap_y = -1;
92 }
93
94 public virtual void tap_up (int finger, int x, int y) {
95 if (finger == 0) {
96 button_release (1, x, y);
97 }
98
99 last_tap_y = -1;
100 }
101
102 public virtual void tap_move (int finger, int x, int y) {
103 double d;
104 if (finger == 0) {
105 motion_notify (x, y);
106
107 d = y - last_tap_y;
108 if (last_tap_y > -1 && fabs (d) > 15) { // FIXME: pixels, other units are better
109 if (d > 0) {
110 scroll_wheel (x, y, 15, 0);
111 } else {
112 scroll_wheel (x, y, 15, 0);
113 }
114 }
115
116 last_tap_y = y;
117 }
118 }
119
120 public virtual void zoom_in () {
121 }
122
123 public virtual void zoom_out () {
124 }
125
126 public virtual void zoom_max () {
127 }
128
129 public virtual void zoom_min () {
130 }
131
132 public virtual void move_view (double x, double y) {
133 }
134
135 public virtual void reset_zoom () {
136 }
137
138 public virtual void store_current_view () {
139 }
140
141 public virtual void restore_last_view () {
142 }
143
144 public virtual void next_view () {
145 }
146
147 public virtual void scroll_wheel (double x, double y,
148 double pixeldelta_x, double pixeldelta_y) {
149 }
150
151 public virtual void undo () {
152 }
153
154 public virtual void redo () {
155 }
156
157 public static File find_file (string? dir, string name) {
158 return SearchPaths.find_file (dir, name);
159 }
160
161 /** returns false if bindings to a single key works in the display. */
162 public virtual bool needs_modifier () {
163 return false;
164 }
165 }
166
167 }
168