… | |
… | |
14 | |
14 | |
15 | my $self = $class->SUPER::new ( |
15 | my $self = $class->SUPER::new ( |
16 | z => -1, |
16 | z => -1, |
17 | can_focus => 1, |
17 | can_focus => 1, |
18 | list => glGenList, |
18 | list => glGenList, |
|
|
19 | |
|
|
20 | smooth_matrix => [ |
|
|
21 | 0.05, 0.13, 0.05, |
|
|
22 | 0.13, 0.30, 0.13, |
|
|
23 | 0.05, 0.13, 0.05, |
|
|
24 | ], |
|
|
25 | |
19 | @_ |
26 | @_ |
20 | ); |
27 | ); |
21 | |
28 | |
22 | $self->{completer} = new CFClient::MapWidget::Command:: |
29 | $self->{completer} = new CFClient::MapWidget::Command:: |
23 | command => $self->{command}, |
30 | command => $self->{command}, |
… | |
… | |
56 | sub button_down { |
63 | sub button_down { |
57 | my ($self, $ev, $x, $y) = @_; |
64 | my ($self, $ev, $x, $y) = @_; |
58 | |
65 | |
59 | $self->focus_in; |
66 | $self->focus_in; |
60 | |
67 | |
61 | if ($ev->{button} == 2) { |
68 | if ($ev->{button} == 1) { |
|
|
69 | my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99; |
|
|
70 | my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99; |
|
|
71 | |
|
|
72 | my $fx = int +($ev->{x} - $::CFG->{map_shift_x}) / (32 * $::CFG->{map_scale}) - 0.5 * $sw + 0.99; |
|
|
73 | my $fy = int +($ev->{y} - $::CFG->{map_shift_y}) / (32 * $::CFG->{map_scale}) - 0.5 * $sh + 0.99; |
|
|
74 | |
|
|
75 | $::CONN->send (sprintf "lookat %d %d", $fx, $fy); |
|
|
76 | |
|
|
77 | } elsif ($ev->{button} == 2) { |
62 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
78 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
63 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
79 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
64 | |
80 | |
65 | $self->{motion} = sub { |
81 | $self->{motion} = sub { |
66 | my ($ev, $x, $y) = @_; |
82 | my ($ev, $x, $y) = @_; |
… | |
… | |
71 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
87 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
72 | |
88 | |
73 | $self->update; |
89 | $self->update; |
74 | }; |
90 | }; |
75 | } |
91 | } |
|
|
92 | |
|
|
93 | 1 |
76 | } |
94 | } |
77 | |
95 | |
78 | sub button_up { |
96 | sub button_up { |
79 | my ($self, $ev, $x, $y) = @_; |
97 | my ($self, $ev, $x, $y) = @_; |
80 | |
98 | |
81 | delete $self->{motion}; |
99 | delete $self->{motion}; |
|
|
100 | |
|
|
101 | 1 |
82 | } |
102 | } |
83 | |
103 | |
84 | sub mouse_motion { |
104 | sub mouse_motion { |
85 | my ($self, $ev, $x, $y) = @_; |
105 | my ($self, $ev, $x, $y) = @_; |
86 | |
106 | |
|
|
107 | if ($self->{motion}) { |
87 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
108 | $self->{motion}->($ev, $x, $y); |
|
|
109 | } else { |
|
|
110 | return 0; |
|
|
111 | } |
|
|
112 | |
|
|
113 | 1 |
88 | } |
114 | } |
89 | |
115 | |
90 | sub size_request { |
116 | sub size_request { |
91 | ( |
117 | ( |
92 | 1 + 32 * int $::WIDTH / 32, |
118 | 1 + 32 * int $::WIDTH / 32, |
… | |
… | |
118 | ); |
144 | ); |
119 | |
145 | |
120 | sub key_down { |
146 | sub key_down { |
121 | my ($self, $ev) = @_; |
147 | my ($self, $ev) = @_; |
122 | |
148 | |
123 | return unless $::CONN; |
149 | return 0 unless $::CONN; |
124 | |
150 | |
125 | my $mod = $ev->{mod}; |
151 | my $mod = $ev->{mod}; |
126 | my $sym = $ev->{sym}; |
152 | my $sym = $ev->{sym}; |
127 | my $uni = $ev->{unicode}; |
153 | my $uni = $ev->{unicode}; |
128 | |
154 | |
… | |
… | |
155 | $self->{ctrl}++; |
181 | $self->{ctrl}++; |
156 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
182 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
157 | } else { |
183 | } else { |
158 | $::CONN->user_send ("$DIR{$sym}[1]"); |
184 | $::CONN->user_send ("$DIR{$sym}[1]"); |
159 | } |
185 | } |
160 | } elsif ($ev->{unicode}) { |
186 | } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) { |
|
|
187 | $::BIND_EDITOR->set_binding (undef, undef, [], |
|
|
188 | sub { |
|
|
189 | my ($mod, $sym, $cmds) = @_; |
|
|
190 | $::CFG->{bindings}->{$mod}->{$sym} = $cmds; |
|
|
191 | }); |
|
|
192 | $::BIND_EDITOR->start; |
|
|
193 | $::BIND_EDITOR->show; |
|
|
194 | } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) { |
|
|
195 | $::BIND_EDITOR->stop; |
|
|
196 | $::BIND_EDITOR->ask_for_bind_and_commit; |
|
|
197 | $::BIND_EDITOR->hide; |
|
|
198 | } elsif (my $bind_cmd = $::CFG->{bindings}->{$mod}->{$sym}) { |
|
|
199 | $::CONN->user_send ($_) for @$bind_cmd; |
|
|
200 | } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { |
161 | $self->{completer}->key_down ($ev); |
201 | $self->{completer}->key_down ($ev); |
162 | $self->{completer}->show; |
202 | $self->{completer}->show; |
|
|
203 | } else { |
|
|
204 | return 0; |
|
|
205 | } |
|
|
206 | |
163 | } |
207 | 1 |
164 | } |
208 | } |
165 | |
209 | |
166 | sub key_up { |
210 | sub key_up { |
167 | my ($self, $ev) = @_; |
211 | my ($self, $ev) = @_; |
168 | |
212 | |
|
|
213 | my $res = 0; |
169 | my $mod = $ev->{mod}; |
214 | my $mod = $ev->{mod}; |
170 | my $sym = $ev->{sym}; |
215 | my $sym = $ev->{sym}; |
171 | |
216 | |
172 | if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { |
217 | if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { |
173 | $::CONN->user_send ("fire_stop"); |
218 | $::CONN->user_send ("fire_stop"); |
|
|
219 | $res = 1; |
174 | } |
220 | } |
|
|
221 | |
175 | if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { |
222 | if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { |
176 | $::CONN->user_send ("run_stop"); |
223 | $::CONN->user_send ("run_stop"); |
|
|
224 | $res = 1; |
177 | } |
225 | } |
|
|
226 | |
|
|
227 | $res |
178 | } |
228 | } |
179 | |
229 | |
180 | sub draw { |
230 | sub draw { |
181 | my ($self) = @_; |
231 | my ($self) = @_; |
182 | |
232 | |
… | |
… | |
209 | glConvolutionFilter2D ( |
259 | glConvolutionFilter2D ( |
210 | GL_CONVOLUTION_2D, |
260 | GL_CONVOLUTION_2D, |
211 | GL_ALPHA, |
261 | GL_ALPHA, |
212 | 3, 3, |
262 | 3, 3, |
213 | GL_ALPHA, GL_FLOAT, |
263 | GL_ALPHA, GL_FLOAT, |
214 | pack "f*", |
264 | (pack "f*", @{ $self->{smooth_matrix} }), |
215 | 0.05, 0.13, 0.05, |
|
|
216 | 0.13, 0.30, 0.13, |
|
|
217 | 0.05, 0.13, 0.05, |
|
|
218 | ); |
265 | ); |
219 | glEnable GL_CONVOLUTION_2D; |
266 | glEnable GL_CONVOLUTION_2D; |
220 | } |
267 | } |
221 | |
268 | |
222 | $self->{fow_texture_name} ||= glGenTexture; |
269 | $self->{fow_texture_name} ||= glGenTexture; |
… | |
… | |
277 | # |
324 | # |
278 | # $label->show; |
325 | # $label->show; |
279 | # $label->update; |
326 | # $label->update; |
280 | # |
327 | # |
281 | # $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub { |
328 | # $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub { |
282 | # $label->move ( |
329 | # $label->move_abs ( |
283 | # ($::WIDTH - $label->{w}) * 0.5, |
330 | # ($::WIDTH - $label->{w}) * 0.5, |
284 | # ($::HEIGHT - $label->{h}) * 0.5, |
331 | # ($::HEIGHT - $label->{h}) * 0.5, |
285 | # ); |
332 | # ); |
286 | # }); |
333 | # }); |
287 | # |
334 | # |
… | |
… | |
456 | |
503 | |
457 | sub size_allocate { |
504 | sub size_allocate { |
458 | my ($self, $w, $h) = @_; |
505 | my ($self, $w, $h) = @_; |
459 | |
506 | |
460 | $self->SUPER::size_allocate ($w, $h); |
507 | $self->SUPER::size_allocate ($w, $h); |
461 | $self->move (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); |
508 | $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); |
462 | } |
509 | } |
463 | |
510 | |
464 | sub show { |
511 | sub show { |
465 | my ($self) = @_; |
512 | my ($self) = @_; |
466 | |
513 | |
… | |
… | |
476 | } |
523 | } |
477 | |
524 | |
478 | sub key_down { |
525 | sub key_down { |
479 | my ($self, $ev) = @_; |
526 | my ($self, $ev) = @_; |
480 | |
527 | |
481 | $self->{entry}->key_down ($ev); |
528 | $self->{entry}->key_down ($ev) |
482 | } |
529 | } |
483 | |
530 | |
484 | sub update_labels { |
531 | sub update_labels { |
485 | my ($self) = @_; |
532 | my ($self) = @_; |
486 | |
533 | |