Debian Codegraph @

src/action.c

raw symbols SCIP
1 /* Copyright © 2016 Bill Allombert
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2 of the License, or
6 (at your option) any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 Check the License for details. You should have received a copy of it, along
14 with the package; see the file 'COPYING'. If not, write to the Free Software
15 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18 #include "consolation.h"
19
20 static double xx=1, yy=1, x0=-1, y0=-1, x1=-1, y1=-1;
21 static int mode = 0;
22 static enum current_button button = BUTTON_RELEASED;
23
24 void
25 set_pointer(double x, double y)
26 {
27 xx = x+1; yy = y+1;
28 if (xx < 1) xx = 1; else if (xx > screen_width) xx = screen_width;
29 if (yy < 1) yy = 1; else if (yy > screen_height) yy = screen_height;
30 if (mouse_reporting != MOUSE_REPORTING_OFF)
31 {
32 x0 = -1; y0 = -1;
33 mode = 0;
34 }
35 if (x0 >= 0 && y0 >= 0)
36 select_region((int)xx,(int)yy,(int)x0,(int)y0);
37 else
38 draw_pointer((int)xx,(int)yy);
39 }
40
41 static void
42 select_mode(int mode, int xx, int yy, int x0, int y0)
43 {
44 switch(mode)
45 {
46 case 0:
47 select_region(xx, yy, x0, y0);
48 break;
49 case 1:
50 select_words(xx, yy, x0, y0);
51 break;
52 case 2:
53 select_lines(xx, yy, x0, y0);
54 break;
55 }
56 }
57
58 void
59 move_pointer(double x, double y)
60 {
61 xx += x/20; yy += y/20;
62 if (xx < 1) xx = 1; else if (xx > screen_width) xx = screen_width;
63 if (yy < 1) yy = 1; else if (yy > screen_height) yy = screen_height;
64 if (mouse_reporting != MOUSE_REPORTING_OFF)
65 {
66 x0 = -1; y0 = -1;
67 mode = 0;
68 }
69 if (x0 >= 0 && y0 >= 0)
70 select_mode(mode,(int)xx,(int)yy,(int)x0,(int)y0);
71 else
72 draw_pointer((int)xx,(int)yy);
73 }
74
75 void
76 press_left_button(void)
77 {
78 if (mouse_reporting != MOUSE_REPORTING_OFF)
79 {
80 button = BUTTON_LEFT;
81 report_pointer((int)xx,(int)yy,button);
82 }
83 else
84 {
85 if ((int)x1==(int)xx && (int)y1==(int)yy)
86 {
87 mode = (mode+1)%3;
88 select_mode(mode,(int)xx,(int)yy,(int)xx,(int)yy);
89 }
90 else
91 {
92 mode = 0;
93 select_region((int)xx,(int)yy,(int)xx,(int)yy);
94 }
95 x0=xx; y0=yy; x1=x0; y1=y0;
96 }
97 }
98
99 void
100 release_left_button(void)
101 {
102 if (mouse_reporting == MOUSE_REPORTING_X11)
103 {
104 button = BUTTON_RELEASED;
105 report_pointer((int)xx,(int)yy,button);
106 }
107 x0=-1; y0=-1;
108 }
109
110 void
111 press_middle_button(void)
112 {
113 if (mouse_reporting != MOUSE_REPORTING_OFF)
114 {
115 button = BUTTON_MIDDLE;
116 report_pointer((int)xx,(int)yy,button);
117 }
118 else
119 paste();
120 }
121
122 void
123 release_middle_button(void)
124 {
125 if (mouse_reporting == MOUSE_REPORTING_X11)
126 {
127 button = BUTTON_RELEASED;
128 report_pointer((int)xx,(int)yy,button);
129 }
130 }
131
132 void
133 press_right_button(void)
134 {
135 if (mouse_reporting != MOUSE_REPORTING_OFF)
136 {
137 button = BUTTON_RIGHT;
138 report_pointer((int)xx,(int)yy,button);
139 }
140 else
141 {
142 if (x1>=0 && y1>=0)
143 select_region((int)xx,(int)yy,(int)x1,(int)y1);
144 }
145 }
146
147 void
148 release_right_button(void)
149 {
150 if (mouse_reporting == MOUSE_REPORTING_X11)
151 {
152 button = BUTTON_RELEASED;
153 report_pointer((int)xx,(int)yy,button);
154 }
155 }
156
157 void
158 vertical_axis(double v)
159 {
160 if (v)
161 scroll(v > 0 ? 2 : -2);
162 }