ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/MapWidget.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/MapWidget.pm (file contents):
Revision 1.59 by root, Wed Jun 14 16:20:22 2006 UTC vs.
Revision 1.74 by root, Sun Jul 16 23:30:08 2006 UTC

6use List::Util qw(min max); 6use List::Util qw(min max);
7 7
8use CFClient::OpenGL; 8use CFClient::OpenGL;
9 9
10our @ISA = CFClient::UI::Base::; 10our @ISA = CFClient::UI::Base::;
11
12my $magicmap_tex =
13 new_from_file CFClient::Texture CFClient::find_rcfile "magicmap.png",
14 mipmap => 1, wrap => 0, internalformat => GL_ALPHA;
11 15
12sub new { 16sub new {
13 my $class = shift; 17 my $class = shift;
14 18
15 my $self = $class->SUPER::new ( 19 my $self = $class->SUPER::new (
34 . "To enter a verbatim command to send to the server, just type the command, " 38 . "To enter a verbatim command to send to the server, just type the command, "
35 . "followed by a space, and press return. " 39 . "followed by a space, and press return. "
36 . "Typing the initial letters of words (or just any letters) displays guesses " 40 . "Typing the initial letters of words (or just any letters) displays guesses "
37 . "for commands you might want to use.\n" 41 . "for commands you might want to use.\n"
38 . "You can use the cursor-up and cursor-down keys to select between those guesses.\n" 42 . "You can use the cursor-up and cursor-down keys to select between those guesses.\n"
39 . "<b>Right-Click</b> opens a menu where you cna select further options, sich as redefining keybindings.", 43 . "<b>Right-Click</b> opens a menu where you cna select further options, sich as redefining key bindings.",
40 ; 44 ;
41 45
42 $self 46 $self
43} 47}
44 48
58 my ($self) = @_; 62 my ($self) = @_;
59 63
60 %{$self->{completer}{command}} = (); 64 %{$self->{completer}{command}} = ();
61} 65}
62 66
63sub button_down { 67sub invoke_button_down {
64 my ($self, $ev, $x, $y) = @_; 68 my ($self, $ev, $x, $y) = @_;
65 69
66 return unless $::CONN;
67
68 $self->focus_in;
69
70 if ($ev->{button} == 1) { 70 if ($ev->{button} == 1) {
71 my $x = int +($ev->{x} - $::CFG->{map_shift_x}) / (32 * $::CFG->{map_scale}); 71 $self->grab_focus;
72 my $y = int +($ev->{y} - $::CFG->{map_shift_y}) / (32 * $::CFG->{map_scale}); 72 return unless $::CONN;
73
74 $x += int 0.5 * ($::MAP->w - $self->{sw} - 1);
75 $y += int 0.5 * ($::MAP->h - $self->{sh} - 1);
76 73
74 my $x = 1 + CFClient::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx};
75 my $y = 1 + CFClient::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy};
76
77 $x -= int 0.5 * $::MAP->w; 77 $x -= int 0.5 * $self->{sw};
78 $y -= int 0.5 * $::MAP->h; 78 $y -= int 0.5 * $self->{sh};
79
80 $x += 1;
81 $y += 1;
82 79
83 $::CONN->lookat ($x, $y) 80 $::CONN->lookat ($x, $y)
84 if $::CONN; 81 if $::CONN;
85 82
86 } elsif ($ev->{button} == 2) { 83 } elsif ($ev->{button} == 2) {
84 $self->grab_focus;
85 return unless $::CONN;
86
87 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 87 my ($ox, $oy) = ($ev->{x}, $ev->{y});
88 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); 88 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
89 89
90 $self->{motion} = sub { 90 $self->{motion} = sub {
91 my ($ev, $x, $y) = @_; 91 my ($ev, $x, $y) = @_;
95 $::CFG->{map_shift_x} = $bw + $x - $ox; 95 $::CFG->{map_shift_x} = $bw + $x - $ox;
96 $::CFG->{map_shift_y} = $bh + $y - $oy; 96 $::CFG->{map_shift_y} = $bh + $y - $oy;
97 97
98 $self->update; 98 $self->update;
99 }; 99 };
100 } elsif ($ev->{button} == 3) {
101 (new CFClient::UI::Menu
102 items => [
103 ["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }],
104 ["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }],
105 ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }],
106 ["Inventory…\tF4", sub { ::toggle_player_page ($::INVENTORY_PAGE) }],
107 ["Spells…\tF5", sub { ::toggle_player_page ($::SPELL_PAGE) }],
108 ["Setup… \tF9", sub { $::SETUP_DIALOG->toggle_visibility }],
109 ["Server Messages…", sub { $::MESSAGE_WINDOW->toggle_visibility }],
110 [
111 $::PICKUP_ENABLE->{state}
112 ? "Disable automatic pickup"
113 : "Enable automatic pickup",
114 sub { $::PICKUP_ENABLE->toggle }
115 ],
116 ],
117 )->popup ($ev);
100 } 118 }
101 119
102 1 120 1
103} 121}
104 122
105sub button_up { 123sub invoke_button_up {
106 my ($self, $ev, $x, $y) = @_; 124 my ($self, $ev, $x, $y) = @_;
107 125
108 delete $self->{motion}; 126 delete $self->{motion};
109 127
110 1 128 1
111} 129}
112 130
113sub mouse_motion { 131sub invoke_mouse_motion {
114 my ($self, $ev, $x, $y) = @_; 132 my ($self, $ev, $x, $y) = @_;
115 133
116 if ($self->{motion}) { 134 if ($self->{motion}) {
117 $self->{motion}->($ev, $x, $y); 135 $self->{motion}->($ev, $x, $y);
118 } else { 136 } else {
122 1 140 1
123} 141}
124 142
125sub size_request { 143sub size_request {
126 ( 144 (
127 1 + 32 * int $::WIDTH / 32, 145 32 * CFClient::ceil $::WIDTH / 32,
128 1 + 32 * int $::HEIGHT / 32, 146 32 * CFClient::ceil $::HEIGHT / 32,
129 ) 147 )
130} 148}
131 149
132sub update { 150sub update {
133 my ($self) = @_; 151 my ($self) = @_;
150 CFClient::SDLK_RIGHT, [3, "east"], 168 CFClient::SDLK_RIGHT, [3, "east"],
151 CFClient::SDLK_DOWN, [5, "south"], 169 CFClient::SDLK_DOWN, [5, "south"],
152 CFClient::SDLK_LEFT, [7, "west"], 170 CFClient::SDLK_LEFT, [7, "west"],
153); 171);
154 172
155sub key_down { 173sub invoke_key_down {
156 my ($self, $ev) = @_; 174 my ($self, $ev) = @_;
157
158 return 0 unless $::CONN;
159 175
160 my $mod = $ev->{mod}; 176 my $mod = $ev->{mod};
161 my $sym = $ev->{sym}; 177 my $sym = $ev->{sym};
162 my $uni = $ev->{unicode}; 178 my $uni = $ev->{unicode};
163 179
180 $mod &= CFClient::KMOD_CTRL | CFClient::KMOD_ALT | CFClient::KMOD_SHIFT;
181
182 if ($uni == ord "\t") {
183 $::PL_WINDOW->toggle_visibility;
184 } elsif ($sym == CFClient::SDLK_F1 && !$mod) {
185 $::HELP_WINDOW->toggle_visibility;
186 } elsif ($sym == CFClient::SDLK_F2 && !$mod) {
187 ::toggle_player_page ($::STATS_PAGE);
188 } elsif ($sym == CFClient::SDLK_F3 && !$mod) {
189 ::toggle_player_page ($::SKILL_PAGE);
190 } elsif ($sym == CFClient::SDLK_F4 && !$mod) {
191 ::toggle_player_page ($::INVENTORY_PAGE);
192 } elsif ($sym == CFClient::SDLK_F5 && !$mod) {
193 ::toggle_player_page ($::SPELL_PAGE);
194 } elsif ($sym == CFClient::SDLK_F9 && !$mod) {
195 $::SETUP_DIALOG->toggle_visibility;
196 } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) {
197 $::BIND_EDITOR->set_binding (undef, undef, [],
198 sub {
199 my ($mod, $sym, $cmds) = @_;
200 $::BIND_EDITOR->cfg_bind ($mod, $sym, $cmds);
201 });
202 $::BIND_EDITOR->start;
203 $::BIND_EDITOR->show;
204 } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) {
205 $::BIND_EDITOR->stop;
206 $::BIND_EDITOR->ask_for_bind_and_commit;
207 $::BIND_EDITOR->hide;
208 } elsif (!$::CONN) {
209 return 0; # bindings further down need a valid connection
210
164 if ($sym == CFClient::SDLK_KP5) { 211 } elsif ($sym == CFClient::SDLK_KP5 && !$mod) {
165 $::CONN->user_send ("stay fire"); 212 $::CONN->user_send ("stay fire");
166 } elsif ($uni == ord ",") { 213 } elsif ($uni == ord ",") {
167 $::CONN->user_send ("take"); 214 $::CONN->user_send ("take");
168 } elsif ($uni == ord " ") { 215 } elsif ($uni == ord " ") {
169 $::CONN->user_send ("apply"); 216 $::CONN->user_send ("apply");
170 } elsif ($uni == ord ".") { 217 } elsif ($uni == ord ".") {
171 $::CONN->user_send ($self->{completer}{last_command}) 218 $::CONN->user_send ($self->{completer}{last_command})
172 if exists $self->{completer}{last_command}; 219 if exists $self->{completer}{last_command};
173 } elsif ($uni == ord "\t") { 220 } elsif (my $bind_cmd = $::CFG->{profile}{default}{bindings}{$mod}{$sym}) {
174 $::INV_WINDOW->toggle_visibility; 221 $::CONN->user_send ($_) for @$bind_cmd;
175 } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { 222 } elsif (($sym == CFClient::SDLK_KP_PLUS && !$mod) || $uni == ord "+") {
176 $::CONN->user_send ("rotateshoottype +"); 223 $::CONN->user_send ("rotateshoottype +");
177 } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { 224 } elsif (($sym == CFClient::SDLK_KP_MINUS && !$mod) || $uni == ord "-") {
178 $::CONN->user_send ("rotateshoottype -"); 225 $::CONN->user_send ("rotateshoottype -");
179 } elsif ($uni == ord '"') { 226 } elsif ($uni == ord '"') {
180 $self->{completer}->set_prefix ("$::CFG->{say_command} "); 227 $self->{completer}->set_prefix ("$::CFG->{say_command} ");
181 $self->{completer}->show; 228 $self->{completer}->show;
182 } elsif ($uni == ord "'") { 229 } elsif ($uni == ord "'") {
193 $self->{ctrl}++; 240 $self->{ctrl}++;
194 $::CONN->user_send ("run $DIR{$sym}[0]"); 241 $::CONN->user_send ("run $DIR{$sym}[0]");
195 } else { 242 } else {
196 $::CONN->user_send ("$DIR{$sym}[1]"); 243 $::CONN->user_send ("$DIR{$sym}[1]");
197 } 244 }
198 } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) {
199 $::BIND_EDITOR->set_binding (undef, undef, [],
200 sub {
201 my ($mod, $sym, $cmds) = @_;
202 $::CFG->{bindings}->{$mod}->{$sym} = $cmds;
203 });
204 $::BIND_EDITOR->start;
205 $::BIND_EDITOR->show;
206 } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) {
207 $::BIND_EDITOR->stop;
208 $::BIND_EDITOR->ask_for_bind_and_commit;
209 $::BIND_EDITOR->hide;
210 } elsif (my $bind_cmd = $::CFG->{bindings}->{$mod}->{$sym}) {
211 $::CONN->user_send ($_) for @$bind_cmd;
212 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { 245 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) {
213 $self->{completer}->key_down ($ev); 246 $self->{completer}->invoke_key_down ($ev);
214 $self->{completer}->show; 247 $self->{completer}->show;
215 } else { 248 } else {
216 return 0; 249 return 0;
217 } 250 }
218 251
219 1 252 1
220} 253}
221 254
222sub key_up { 255sub invoke_key_up {
223 my ($self, $ev) = @_; 256 my ($self, $ev) = @_;
224 257
225 my $res = 0; 258 my $res = 0;
226 my $mod = $ev->{mod}; 259 my $mod = $ev->{mod};
227 my $sym = $ev->{sym}; 260 my $sym = $ev->{sym};
250 } 283 }
251 284
252 $res 285 $res
253} 286}
254 287
288sub set_magicmap {
289 my ($self, $w, $h, $x, $y, $data) = @_;
290
291 $x -= $::MAP->ox + int 0.5 * $::MAP->w;
292 $y -= $::MAP->oy + int 0.5 * $::MAP->h;
293
294 $self->{magicmap} = [$x, $y, $w, $h, $data];
295
296 $self->update;
297}
298
255sub draw { 299sub draw {
256 my ($self) = @_; 300 my ($self) = @_;
301
302 return unless $::MAP;
257 303
258 my $focused = $CFClient::UI::FOCUS == $self 304 my $focused = $CFClient::UI::FOCUS == $self
259 || $CFClient::UI::FOCUS == $self->{completer}{entry}; 305 || $CFClient::UI::FOCUS == $self->{completer}{entry};
260 306
261 return 307 return
262 unless $::CONN && ($focused || !$::FAST); 308 unless $focused || !$::FAST;
263 309
264 if (delete $self->{need_update}) { 310 if (delete $self->{need_update}) {
311 my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale};
312
313 my $sx = $self->{sx} = CFClient::ceil $::CFG->{map_shift_x} / $tilesize;
314 my $sy = $self->{sy} = CFClient::ceil $::CFG->{map_shift_y} / $tilesize;
315
316 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize;
317 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize;
318
319 my $sw = $self->{sw} = 1 + CFClient::ceil $self->{w} / $tilesize;
320 my $sh = $self->{sh} = 1 + CFClient::ceil $self->{h} / $tilesize;
321
322 if ($::CFG->{fow_enable}) {
323 my ($w, $h, $data) = $::MAP->fow_texture ($sx, $sy, 0, 0, $sw, $sh);
324
325 if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war
326 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
327 glConvolutionFilter2D (
328 GL_CONVOLUTION_2D,
329 GL_ALPHA,
330 3, 3,
331 GL_ALPHA, GL_FLOAT,
332 (pack "f*", @{ $self->{smooth_matrix} }),
333 );
334 glEnable GL_CONVOLUTION_2D;
335 }
336
265 $self->{fow_texture} ||= glGenTexture; 337 $self->{fow_texture} = new CFClient::Texture
338 w => $w,
339 h => $h,
340 data => $data,
341 internalformat => GL_ALPHA,
342 format => GL_ALPHA;
343
344 glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth};
345 } else {
346 delete $self->{fow_texture};
347 }
266 348
267 glNewList $self->{list}; 349 glNewList $self->{list};
268 350
269 if ($::MAP) {
270 my $sw = $self->{sw} = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99;
271 my $sh = $self->{sh} = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99;
272
273 my $sx = $::CFG->{map_shift_x} / $::CFG->{map_scale};
274 my $sy = $::CFG->{map_shift_y} / $::CFG->{map_scale};
275 my $sx0 = $self->{sx0} = ($sx & 31) - 32; $sx = $self->{sx} = ($sx - $sx0) / 32;
276 my $sy0 = $self->{sy0} = ($sy & 31) - 32; $sy = $self->{sy} = ($sy - $sy0) / 32;
277
278 glPushMatrix; 351 glPushMatrix;
352 glTranslate $sx0, $sy0;
279 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 353 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
280 354
281 glTranslate $sx0, $sy0; 355 $::MAP->draw ($sx, $sy, 0, 0, $sw, $sh);
282 356
283 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); 357 glScale 32, 32;
284 358
285 if ($::CFG->{fow_enable}) { 359 if (my $tex = $self->{fow_texture}) {
286 if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war
287 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
288 glConvolutionFilter2D (
289 GL_CONVOLUTION_2D,
290 GL_ALPHA,
291 3, 3,
292 GL_ALPHA, GL_FLOAT,
293 (pack "f*", @{ $self->{smooth_matrix} }),
294 );
295 glEnable GL_CONVOLUTION_2D;
296 }
297
298 $self->{fow_texture_name} ||= glGenTexture;
299 # try to re-use the texture name: TODO improve texture class instead
300
301 $self->{fow_texture} = new CFClient::Texture
302 w => $w,
303 h => $h,
304 data => $data,
305 name => $self->{fow_texture_name},
306 internalformat => GL_ALPHA,
307 format => GL_ALPHA;
308
309 glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth};
310
311 glEnable GL_TEXTURE_2D; 360 glEnable GL_TEXTURE_2D;
312 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 361 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
313 362
314 glColor +($::CFG->{fow_intensity}) x 3, 0.8; 363 glColor +($::CFG->{fow_intensity}) x 3, 0.9;
315 $self->{fow_texture}->draw_quad_alpha (0, 0, $w * 32, $h * 32); 364 $self->{fow_texture}->draw_quad_alpha (0, 0);
316 365
317 glDisable GL_TEXTURE_2D; 366 glDisable GL_TEXTURE_2D;
318 } 367 }
319 368
369 if ($self->{magicmap}) {
370 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} };
371
372 $x += $::MAP->ox - $sx + int 0.5 * ($::MAP->w - $sw + 1);
373 $y += $::MAP->oy - $sy + int 0.5 * ($::MAP->h - $sh + 1);
374
375 glTranslate - $x - 1, - $y - 1;
376 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name};
377 $::MAP->draw_magicmap ($x, $y, $w, $h, $data);
378 }
379
320 glPopMatrix; 380 glPopMatrix;
321 }
322
323 glEndList; 381 glEndList;
324 } 382 }
325 383
326 glPushMatrix;
327 glCallList $self->{list}; 384 glCallList $self->{list};
328 glPopMatrix;
329 385
330 # TNT2 emulates logops in software (or worse :) 386 # TNT2 emulates logops in software (or worse :)
331 if ($focused) { 387 unless ($focused) {
332 (delete $self->{out_of_focus})->destroy
333 if $self->{out_of_focus};
334 } else {
335 glColor 0.4, 0.2, 0.2, 0.6; 388 glColor 0.4, 0.2, 0.2, 0.6;
336 glEnable GL_BLEND; 389 glEnable GL_BLEND;
337 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 390 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
338 glBegin GL_QUADS; 391 glBegin GL_QUADS;
339 glVertex 0, 0; 392 glVertex 0, 0;
340 glVertex 0, $::HEIGHT; 393 glVertex 0, $::HEIGHT;
341 glVertex $::WIDTH, $::HEIGHT; 394 glVertex $::WIDTH, $::HEIGHT;
342 glVertex $::WIDTH, 0; 395 glVertex $::WIDTH, 0;
343 glEnd; 396 glEnd;
344 glDisable GL_BLEND; 397 glDisable GL_BLEND;
345
346# $self->{out_of_focus} ||= do {
347# my $label = new CFClient::UI::Label
348# x => 0,
349# y => 0,
350# z => 1,
351# ellipsise => 0,
352# text => "map out of focus (click map to play)";
353#
354# $label->show;
355# $label->update;
356#
357# $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub {
358# $label->move_abs (
359# ($::WIDTH - $label->{w}) * 0.5,
360# ($::HEIGHT - $label->{h}) * 0.5,
361# );
362# });
363#
364# $label
365# };
366 } 398 }
367} 399}
368 400
369sub DESTROY { 401sub DESTROY {
370 my $self = shift; 402 my $self = shift;
383 415
384sub size_request { 416sub size_request {
385 ($::HEIGHT * 0.25, $::HEIGHT * 0.25) 417 ($::HEIGHT * 0.25, $::HEIGHT * 0.25)
386} 418}
387 419
388sub size_allocate { 420sub invoke_size_allocate {
389 my ($self, $w, $h) = @_; 421 my ($self, $w, $h) = @_;
390 422
391 $self->SUPER::size_allocate ($w, $h);
392 $self->update; 423 $self->update;
424
425 1
393} 426}
394 427
395sub update { 428sub update {
396 my ($self) = @_; 429 my ($self) = @_;
397 430
482 ]; 515 ];
483 516
484 $self->{entry} = new CFClient::UI::Entry 517 $self->{entry} = new CFClient::UI::Entry
485 on_changed => sub { 518 on_changed => sub {
486 $self->update_labels; 519 $self->update_labels;
520 0
487 }, 521 },
488 on_button_down => sub { 522 on_button_down => sub {
489 my ($entry, $ev, $x, $y) = @_; 523 my ($entry, $ev, $x, $y) = @_;
490 524
491 if ($ev->{button} == 3) { 525 if ($ev->{button} == 3) {
492 (new CFClient::UI::Menu 526 (new CFClient::UI::Menu
493 items => [ 527 items => [
528 ["bind <i>" . (CFClient::UI::Label::escape $self->{select}) . "</i> to a key"
494 ["bind to a key" => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->focus_in }) }] 529 => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->grab_focus }) }]
495 ], 530 ],
496 )->popup ($ev); 531 )->popup ($ev);
497 return 1; 532 return 1;
498 } 533 }
499 0 534 0
506 if ($ev->{sym} == 13) { 541 if ($ev->{sym} == 13) {
507 if (exists $self->{select}) { 542 if (exists $self->{select}) {
508 $self->{last_command} = $self->{select}; 543 $self->{last_command} = $self->{select};
509 $::CONN->user_send ($self->{select}); 544 $::CONN->user_send ($self->{select});
510 545
511 unshift @{$self->{history}}, $self->{select}; 546 unshift @{$self->{history}}, $self->{entry}->get_text;
512 $self->{hist_ptr} = 0; 547 $self->{hist_ptr} = 0;
513 548
514 $self->hide; 549 $self->hide;
515 } 550 }
516 } elsif ($ev->{sym} == 27) { 551 } elsif ($ev->{sym} == 27) {
517 $self->{hist_ptr} = 0; 552 $self->{hist_ptr} = 0;
518 $self->hide; 553 $self->hide;
519 return;
520 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { 554 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) {
521 if ($self->{hist_ptr} > 1) { 555 if ($self->{hist_ptr} > 1) {
522 $self->{hist_ptr}--; 556 $self->{hist_ptr}--;
523 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]); 557 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]);
524 } elsif ($self->{hist_ptr} > 0) { 558 } elsif ($self->{hist_ptr} > 0) {
564 598
565 $self->{entry}->set_text ($prefix); 599 $self->{entry}->set_text ($prefix);
566 $self->show; 600 $self->show;
567} 601}
568 602
569sub size_allocate { 603sub invoke_size_allocate {
570 my ($self, $w, $h) = @_; 604 my ($self, $w, $h) = @_;
571 605
572 $self->SUPER::size_allocate ($w, $h);
573 $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); 606 $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10);
607
608 $self->SUPER::invoke_size_allocate ($w, $h)
574} 609}
575 610
576sub show { 611sub show {
577 my ($self) = @_; 612 my ($self) = @_;
578 613
579 $self->SUPER::show; 614 $self->SUPER::show;
580 $self->{entry}->focus_in; 615 $self->{entry}->grab_focus;
581} 616}
582 617
583sub hide { 618sub hide {
584 my ($self) = @_; 619 my ($self) = @_;
585 620
586 $self->SUPER::hide; 621 $self->SUPER::hide;
587 $self->{entry}->set_text (""); 622 $self->{entry}->set_text ("");
588} 623}
589 624
590sub key_down { 625sub invoke_key_down {
591 my ($self, $ev) = @_; 626 my ($self, $ev) = @_;
592 627
593 $self->{entry}->key_down ($ev) 628 $self->{entry}->emit (key_down => $ev)
594} 629}
595 630
596sub update_labels { 631sub update_labels {
597 my ($self) = @_; 632 my ($self) = @_;
598 633
685 $label->set_text (""); 720 $label->set_text ("");
686 $label->set_tooltip (""); 721 $label->set_tooltip ("");
687 } 722 }
688 723
689 $self->update; 724 $self->update;
690 ###
691} 725}
692 726
693sub _draw { 727sub _draw {
694 my ($self) = @_; 728 my ($self) = @_;
695 729

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines