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

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.16 by root, Fri Apr 7 23:16:29 2006 UTC vs.
Revision 1.33 by root, Sun Apr 9 01:37:58 2006 UTC

1package Crossfire::Client::Widget; 1package Crossfire::Client::Widget;
2 2
3use strict; 3use strict;
4
5use Scalar::Util;
6
4use SDL::OpenGL; 7use SDL::OpenGL;
5use SDL::OpenGL::Constants; 8use SDL::OpenGL::Constants;
6 9
7our $FOCUS; # the widget with current focus 10our $FOCUS; # the widget with current focus
8our @ACTIVE_WIDGETS; 11#our @ACTIVE_WIDGETS;
9 12
10# class methods for events 13# class methods for events
11sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS } 14sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS }
12sub feed_sdl_key_up_event { $FOCUS->key_up ($_[0]) if $FOCUS } 15sub feed_sdl_key_up_event { $FOCUS->key_up ($_[0]) if $FOCUS }
13sub feed_sdl_button_down_event { $FOCUS->button_down ($_[0]) if $FOCUS } 16sub feed_sdl_button_down_event { }
14sub feed_sdl_button_up_event { $FOCUS->button_up ($_[0]) if $FOCUS } 17sub feed_sdl_button_up_event { }
15 18
16sub new { 19sub new {
17 my $class = shift; 20 my $class = shift;
18 21
19 bless { @_ }, $class 22 bless { @_ }, $class
20} 23}
21 24
22sub activate { 25#sub activate {
23 push @ACTIVE_WIDGETS, $_[0]; 26# push @ACTIVE_WIDGETS, $_[0];
24} 27# Scalar::Util::weaken $ACTIVE_WIDGETS[-1];
28#}
25 29
26sub deactivate { 30#sub deactivate {
27 @ACTIVE_WIDGETS = 31# @ACTIVE_WIDGETS =
28 sort { $a->{z} <=> $b->{z} } 32# sort { $a->{z} <=> $b->{z} }
29 grep { $_ != $_[0] } 33# grep { $_ && $_ != $_[0] }
30 @ACTIVE_WIDGETS; 34# @ACTIVE_WIDGETS;
35#}
36
37sub move {
38 my ($self, $x, $y, $z) = @_;
39 $self->{x} = $x;
40 $self->{y} = $y;
41 $self->{z} = $z if defined $z;
42}
43
44sub needs_redraw {
45 0
31} 46}
32 47
33sub size_request { 48sub size_request {
34 die "size_request is abtract"; 49 die "size_request is abtract";
35} 50}
77sub _draw { 92sub _draw {
78 my ($widget) = @_; 93 my ($widget) = @_;
79} 94}
80 95
81sub bbox { 96sub bbox {
82 my ($widget) = @_; 97 my ($self) = @_;
98 my ($w, $h) = $self->size_request;
99 (
100 $self->{x},
101 $self->{y},
102 $self->{x} = $w,
103 $self->{y} = $h
104 )
105}
106
107sub del_parent { $_[0]->{parent} = undef }
108
109sub set_parent {
110 my ($self, $par) = @_;
111
112 $self->{parent} = $par;
113 Scalar::Util::weaken $self->{parent};
114}
115
116sub get_parent {
117 $_[0]->{parent}
118}
119
120sub update {
121 my ($self) = @_;
122
123 $self->{parent}->update
124 if $self->{parent};
125}
126
127sub DESTROY {
128 my ($self) = @_;
129
130 #$self->deactivate;
83} 131}
84 132
85package Crossfire::Client::Widget::Container; 133package Crossfire::Client::Widget::Container;
86 134
87our @ISA = Crossfire::Client::Widget::; 135our @ISA = Crossfire::Client::Widget::;
88 136
89use SDL::OpenGL; 137use SDL::OpenGL;
90 138
91sub add { $_[0]->{child} = $_[1] } 139sub add { $_[0]->{child} = $_[1]; $_[1]->set_parent ($_[0]); $_[1]->update }
92sub get { $_[0]->{child} } 140sub get { $_[0]->{child} }
141sub remove {
142 my ($self, $chld) = @_;
143 delete $self->{child}
144 if $self->{child} == $chld;
145}
93 146
94sub size_request { $_[0]->{child}->size_request if $_[0]->{child} } 147sub size_request { $_[0]->{child}->size_request if $_[0]->{child} }
95 148
96sub _draw { die "Containers can't be drawn!" } 149sub _draw { die "Containers can't be drawn!" }
97 150
98package Crossfire::Client::Widget::Frame; 151package Crossfire::Client::Widget::Toplevel;
152
153our @ISA = Crossfire::Client::Widget::;
154
155use SDL::OpenGL;
156
157sub add {
158 my ($self, $chld) = @_;
159
160 push @{$self->{childs}}, $chld;
161 @{$self->{childs}} =
162 sort { $a->{z} <=> $b->{z} }
163 @{$self->{childs}};
164
165 $chld->set_parent ($self);
166}
167
168sub remove {
169 my ($self, $chld) = @_;
170 @{$self->{childs}} =
171 sort { $a->{z} <=> $b->{z} }
172 grep { $_ && $_ != $_[0] }
173 @{$self->{childs}}
174}
175
176sub update {
177 my ($self) = @_;
178 ::refresh ();
179}
180
181sub _draw {
182 my ($self) = @_;
183
184 $_->draw for @{$self->{childs}};
185}
186
187package Crossfire::Client::Widget::Window;
99 188
100our @ISA = Crossfire::Client::Widget::Container::; 189our @ISA = Crossfire::Client::Widget::Container::;
101 190
102use SDL::OpenGL; 191use SDL::OpenGL;
192
193sub add {
194 my ($self, $chld) = @_;
195 $self->SUPER::add ($chld);
196 $chld->set_parent ($self);
197 $self->update; #TODO: Move this to the size_request event propably?
198}
199
200sub remove {
201 my ($self) = @_;
202 # TODO FIXME: removing a child from a window will crash, see render_chld
203 $self->update;
204}
205
206sub update {
207 my ($self) = @_;
208 $self->render_chld;
209}
210
211sub render_chld {
212 my ($self) = @_;
213 my $chld = $self->get;
214 my ($w, $h) = $self->size_request;
215
216 $self->{texture} =
217 Crossfire::Client::Texture->new_from_opengl (
218 $w, $h, sub { $chld->draw }
219 );
220 $self->{texture}->upload;
221}
103 222
104sub size_request { 223sub size_request {
105 my ($self) = @_; 224 my ($self) = @_;
106 my $chld = $self->get 225 my $chld = $self->get
107 or return (0, 0); 226 or return (0, 0);
227 $chld->size_request
228}
229
230sub _draw {
231 my ($self) = @_;
232
233 my ($w, $h) = $self->size_request;#TODO# use width/height of texture
234
235 my $tex = $self->{texture}
236 or return;
237
238 glEnable GL_BLEND;
239 glEnable GL_TEXTURE_2D;
240 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
241 glBindTexture GL_TEXTURE_2D, $tex->{name};
242
243 glColor 1, 0, 1;
244
245 glBegin GL_QUADS;
246 glTexCoord 0, 0; glVertex 0, 0;
247 glTexCoord 0, 1; glVertex 0, $h;
248 glTexCoord 1, 1; glVertex $w, $h;
249 glTexCoord 1, 0; glVertex $w, 0;
250 glEnd;
251
252 glDisable GL_BLEND;
253 glDisable GL_TEXTURE_2D;
254}
255
256package Crossfire::Client::Widget::Frame;
257
258our @ISA = Crossfire::Client::Widget::Container::;
259
260use SDL::OpenGL;
261
262sub size_request {
263 my ($self) = @_;
264 my $chld = $self->get
265 or return (0, 0);
266
267 $chld->move (2, 2);
268
108 map { $_ + 4 } $chld->size_request; 269 map { $_ + 4 } $chld->size_request;
109} 270}
110 271
111sub _draw { 272sub _draw {
112 my ($self) = @_; 273 my ($self) = @_;
113 274
114 my $chld = $self->get; 275 my $chld = $self->get;
115 276
116 my ($w, $h) = $chld->size_request; 277 my ($w, $h) = $chld->size_request;
117 278
118 glColor 1, 0, 0;
119 glBegin GL_QUADS; 279 glBegin GL_QUADS;
280 glColor 0, 0, 0;
120 glTexCoord 0, 0; glVertex 0 , 0; 281 glTexCoord 0, 0; glVertex 0 , 0;
121 glTexCoord 0, 1; glVertex 0 , $h + 4; 282 glTexCoord 0, 1; glVertex 0 , $h + 4;
122 glTexCoord 1, 1; glVertex $w + 4 , $h + 4; 283 glTexCoord 1, 1; glVertex $w + 4 , $h + 4;
123 glTexCoord 1, 0; glVertex $w + 4 , 0; 284 glTexCoord 1, 0; glVertex $w + 4 , 0;
124 glEnd; 285 glEnd;
125 286
126 glPushMatrix;
127 glTranslate (2, 2, 0);
128 $chld->_draw; 287 $chld->draw;
129 glPopMatrix;
130} 288}
289
290package Crossfire::Client::Widget::FancyFrame;
291
292our @ISA = Crossfire::Client::Widget::Frame::;
293
294use SDL::OpenGL;
295
296#TODO: implement themed frame
131 297
132package Crossfire::Client::Widget::Table; 298package Crossfire::Client::Widget::Table;
133 299
134our @ISA = Crossfire::Client::Widget::Container::; 300our @ISA = Crossfire::Client::Widget::Container::;
135 301
136use SDL::OpenGL; 302use SDL::OpenGL;
137 303
138sub add { 304sub add {
139 my ($self, $x, $y, $chld) = @_; 305 my ($self, $x, $y, $chld) = @_;
306 my $old_chld = $self->{childs}[$y][$x];
307
140 $self->{childs}[$y][$x] = $chld; 308 $self->{childs}[$y][$x] = $chld;
309 $chld->set_parent ($self);
310 $self->update;
141} 311}
142 312
143sub max_row_height { 313sub max_row_height {
144 my ($self, $row) = @_; 314 my ($self, $row) = @_;
145 315
146 my $hs = 0; 316 my $hs = 0;
147 for (my $xi = 0; $xi <= $#{$self->{childs}->[$row] || []}; $xi++) { 317 for (my $xi = 0; $xi <= $#{$self->{childs}->[$row] || []}; $xi++) {
148 my $c = $self->{childs}->[$row]->[$xi]; 318 my $c = $self->{childs}->[$row]->[$xi];
319 if ($c) {
149 my ($w, $h) = $c->size_request if $c; 320 my ($w, $h) = $c->size_request;
150 if ($hs < $h) { $hs = $h } 321 if ($hs < $h) { $hs = $h }
322 }
151 } 323 }
152 return $hs; 324 return $hs;
153} 325}
154 326
155sub max_col_width { 327sub max_col_width {
156 my ($self, $col) = @_; 328 my ($self, $col) = @_;
157 329
158 my $ws = 0; 330 my $ws = 0;
159 for (my $yi = 0; $yi <= $#{$self->{childs} || []}; $yi++) { 331 for (my $yi = 0; $yi <= $#{$self->{childs} || []}; $yi++) {
160 my $c = ($self->{childs}->[$yi] || [])->[$col]; 332 my $c = ($self->{childs}->[$yi] || [])->[$col];
333 if ($c) {
161 my ($w, $h) = $c->size_request if $c; 334 my ($w, $h) = $c->size_request;
162 if ($ws < $w) { $ws = $w } 335 if ($ws < $w) { $ws = $w }
336 }
163 } 337 }
164 return $ws; 338 return $ws;
165} 339}
166 340
167sub size_request { 341sub size_request {
191 for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) { 365 for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) {
192 my $x = 0; 366 my $x = 0;
193 367
194 for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) { 368 for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) {
195 369
196 glPushMatrix;
197 glTranslate ($x, $y, 0);
198 my $c = $self->{childs}->[$yi]->[$xi]; 370 my $c = $self->{childs}->[$yi]->[$xi];
371 if ($c) {
372 $c->move ($x, $y, 0); #TODO: Move to size_request
199 $c->_draw if $c; 373 $c->draw if $c;
200 glPopMatrix; 374 }
201 375
202 $x += $self->max_col_width ($xi); 376 $x += $self->max_col_width ($xi);
203 } 377 }
204 378
205 $y += $self->max_row_height ($yi); 379 $y += $self->max_row_height ($yi);
213use SDL::OpenGL; 387use SDL::OpenGL;
214 388
215sub add { 389sub add {
216 my ($self, $chld) = @_; 390 my ($self, $chld) = @_;
217 push @{$self->{childs}}, $chld; 391 push @{$self->{childs}}, $chld;
392 $chld->set_parent ($self);
393 $self->update;
218} 394}
219 395
220sub size_request { 396sub size_request {
221 my ($self) = @_; 397 my ($self) = @_;
222 398
233sub _draw { 409sub _draw {
234 my ($self) = @_; 410 my ($self) = @_;
235 411
236 my ($x, $y); 412 my ($x, $y);
237 for (@{$self->{childs} || []}) { 413 for (@{$self->{childs} || []}) {
238 glPushMatrix; 414 $_->move (0, $y, 0); #TODO: move to size_request
239 glTranslate (0, $y, 0);
240 $_->_draw; 415 $_->draw;
241 glPopMatrix;
242 my ($w, $h) = $_->size_request; 416 my ($w, $h) = $_->size_request;
243 $y += $h; 417 $y += $h;
244 } 418 }
245} 419}
246 420
249our @ISA = Crossfire::Client::Widget::; 423our @ISA = Crossfire::Client::Widget::;
250 424
251use SDL::OpenGL; 425use SDL::OpenGL;
252 426
253sub new { 427sub new {
254 my ($class, $x, $y, $z, $ttf, $text) = @_; 428 my ($class, $x, $y, $z, $height, $text) = @_;
255 429
430 # TODO: color, and make height, xyz etc. optional
256 my $self = $class->SUPER::new (x => $x, y => $y, z => $z, ttf => $ttf); 431 my $self = $class->SUPER::new (x => $x, y => $y, z => $z, height => $height);
257 432
258 $self->set_text ($text); 433 $self->set_text ($text);
259 434
260 $self 435 $self
261} 436}
262 437
263sub set_text { 438sub set_text {
264 my ($self, $text) = @_; 439 my ($self, $text) = @_;
440
441 $self->{text} = $text;
265 $self->{texture} = new_from_ttf Crossfire::Client::Texture $self->{ttf}, $self->{text} = $text; 442 $self->{texture} = new_from_text Crossfire::Client::Texture $text, $self->{height};
443
444 $self->update;
266} 445}
267 446
268sub get_text { 447sub get_text {
269 my ($self, $text) = @_; 448 my ($self, $text) = @_;
449
270 $self->{text} 450 $self->{text}
271} 451}
272 452
273sub size_request { 453sub size_request {
274 my ($self) = @_; 454 my ($self) = @_;
282sub _draw { 462sub _draw {
283 my ($self) = @_; 463 my ($self) = @_;
284 464
285 my $tex = $self->{texture}; 465 my $tex = $self->{texture};
286 466
287 $self->{x}--;
288
289 glEnable GL_BLEND; 467 glEnable GL_BLEND;
290 glEnable GL_TEXTURE_2D; 468 glEnable GL_TEXTURE_2D;
469 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
291 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 470 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
292 glBindTexture GL_TEXTURE_2D, $tex->{name}; 471 glBindTexture GL_TEXTURE_2D, $tex->{name};
293 472
294 glColor 1, 1, 1; 473 glColor 1, 1, 1, 0.6; # TODO color
295 474
296 glBegin GL_QUADS; 475 glBegin GL_QUADS;
297 glTexCoord 0, 0; glVertex 0 , 0; 476 glTexCoord 0, 0; glVertex 0 , 0;
298 glTexCoord 0, 1; glVertex 0 , $tex->{height}; 477 glTexCoord 0, 1; glVertex 0 , $tex->{height};
299 glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height}; 478 glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height};
302 481
303 glDisable GL_BLEND; 482 glDisable GL_BLEND;
304 glDisable GL_TEXTURE_2D; 483 glDisable GL_TEXTURE_2D;
305} 484}
306 485
486package Crossfire::Client::Widget::TextEntry;
487
488our @ISA = Crossfire::Client::Widget::Label::;
489
490use SDL;
491use SDL::OpenGL;
492
493sub key_down {
494 my ($self, $ev) = @_;
495
496 my $mod = $ev->key_mod;
497 my $sym = $ev->key_sym;
498
499 $ev->set_unicode (1);
500 my $uni = $ev->key_unicode;
501
502 my $text = $self->get_text;
503
504 if ($sym == SDLK_BACKSPACE) {
505 substr $text, -1, 1, '';
506
507 } elsif ($uni) {
508 $text .= chr $uni;
509 }
510 $self->set_text ($text);
511}
512
513
514# XXX: TextView isn't neccessary with pango multiline text rendering
307package Crossfire::Client::Widget::TextView; 515package Crossfire::Client::Widget::TextView;
308 516
309use strict; 517use strict;
310 518
311our @ISA = qw/Crossfire::Client::Widget/; 519our @ISA = qw/Crossfire::Client::Widget/;
312 520
313use SDL::OpenGL; 521use SDL::OpenGL;
314use SDL::OpenGL::Constants; 522use SDL::OpenGL::Constants;
523
524sub new {
525 my ($class, $text, $h) = @_;
526 my $self = $class->SUPER::new ();
527
528 $self->{txt_height} = $h;
529 @{$self->{lines}} = split /\r?\n/, $text;
530
531 for (split /\r?\n/, $text) {
532 $self->add_line ($_);
533 }
534 $self
535}
536
537#sub render_lines {
538# my ($self) = @_;
539#
540# $self->{txt_lines} = [];
541#
542# for (@{$self->{lines}}) {
543# push @{$self->{txt_lines}},
544# new_from_ttf Crossfire::Client::Texture $self->{ttf}, $_;
545# }
546#}
315 547
316sub add_line { 548sub add_line {
317 my ($self, $line) = @_; 549 my ($self, $line) = @_;
318 push @{$self->{lines}}, $line; 550 push @{$self->{lines}}, $line;
319}
320 551
552 push @{$self->{txt_lines}},
553 new_from_text Crossfire::Client::Texture $line, $self->{txt_height};
554}
555
556sub size_request {
557 my ($self) = @_;
558
559 my $w = 0;
560 my $h = 0;
561
562 for (@{$self->{txt_lines}}) {
563 if ($w < $_->{width}) { $w = $_->{width} }
564 $h += $_->{height};
565 }
566
567 return ($w, $h);
568}
569
321sub _draw { 570sub draw_line {
322 my ($self) = @_; 571 my ($self, $tex, $y) = @_;
323 572
573 glBindTexture GL_TEXTURE_2D, $tex->{name};
574
575 glColor 1, 0, 1;
576
577 glBegin GL_QUADS;
578 glTexCoord 0, 0; glVertex 0 , $y;
579 glTexCoord 0, 1; glVertex 0 , $y + $tex->{height};
580 glTexCoord 1, 1; glVertex $tex->{width}, $y + $tex->{height};
581 glTexCoord 1, 0; glVertex $tex->{width}, $y;
582 glEnd;
583}
584
585sub _draw {
586 my ($self) = @_;
587
588 glEnable GL_BLEND;
589 glEnable GL_TEXTURE_2D;
590 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;#DECAL;
591
592 my $l = 0;
593 for (@{$self->{txt_lines}}) {
594 $self->draw_line ($_, $l);
595 $l += $_->{height};
596 }
597
598 glDisable GL_BLEND;
599 glDisable GL_TEXTURE_2D;
324} 600}
325 601
326package Crossfire::Client::Widget::MapWidget; 602package Crossfire::Client::Widget::MapWidget;
327 603
328use strict; 604use strict;
329 605
330our @ISA = qw/Crossfire::Client::Widget/; 606use List::Util qw(min max);
331 607
332use SDL; 608use SDL;
333use SDL::OpenGL; 609use SDL::OpenGL;
334use SDL::OpenGL::Constants; 610use SDL::OpenGL::Constants;
611
612our @ISA = Crossfire::Client::Widget::;
335 613
336sub key_down { 614sub key_down {
337 print "MAPKEYDOWN\n"; 615 print "MAPKEYDOWN\n";
338} 616}
339 617
340sub key_up { 618sub key_up {
341} 619}
342 620
343sub _draw { 621sub _draw {
622 my ($self) = @_;
623
624 my $mx = $::CONN->{mapx};
625 my $my = $::CONN->{mapy};
626
627 my $map = $::CONN->{map};
628
629 my ($xofs, $yofs);
630
631 my $sw = 1 + int $::WIDTH / 32;
632 my $sh = 1 + int $::HEIGHT / 32;
633
634 if ($::CONN->{mapw} > $sw) {
635 $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5;
636 } else {
637 $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs};
638 }
639
640 if ($::CONN->{maph} > $sh) {
641 $yofs = $my + ($::CONN->{maph} - $sh) * 0.5;
642 } else {
643 $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs};
644 }
645
344 glEnable GL_TEXTURE_2D; 646 glEnable GL_TEXTURE_2D;
345 glEnable GL_BLEND; 647 glEnable GL_BLEND;
346 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 648 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
347 649
348 my $map = $::CONN->{map}; 650 for my $x (0 .. $sw - 1) {
349
350 for my $x (0 .. $::CONN->{mapw} - 1) {
351 for my $y (0 .. $::CONN->{maph} - 1) { 651 for my $y (0 .. $sh - 1) {
352 652
353 my $cell = $map->[$x][$y] 653 my $cell = $map->[$x + $xofs][$y + $yofs]
354 or next; 654 or next;
355 655
356 my $darkness = $cell->[3] * (1 / 255); 656 my $darkness = $cell->[0] * (1 / 255);
657 if ($darkness < 0) {
658 glColor 0.3, 0.3, 0.3;
659 } else {
357 glColor $darkness, $darkness, $darkness; 660 glColor $darkness, $darkness, $darkness;
661 }
358 662
359 for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) { 663 for my $num (grep $_, @$cell[1,2,3]) {
360 my $tex = $::CONN->{face}[$num]{texture} || next; 664 my $tex = $::CONN->{face}[$num]{texture} || next;
361 665
362 glBindTexture GL_TEXTURE_2D, $tex->{name}; 666 glBindTexture GL_TEXTURE_2D, $tex->{name};
363 667
668 my $w = $tex->{width};
669 my $h = $tex->{height};
670
671 my $px = ($x + 1) * 32 - $w;
672 my $py = ($y + 1) * 32 - $h;
673
364 glBegin GL_QUADS; 674 glBegin GL_QUADS;
365 glTexCoord 0, 0; glVertex $x * 32 , $y * 32; 675 glTexCoord 0, 0; glVertex $px , $py;
366 glTexCoord 0, 1; glVertex $x * 32 , $y * 32 + 32; 676 glTexCoord 0, 1; glVertex $px , $py + $h;
367 glTexCoord 1, 1; glVertex $x * 32 + 32, $y * 32 + 32; 677 glTexCoord 1, 1; glVertex $px + $w, $py + $h;
368 glTexCoord 1, 0; glVertex $x * 32 + 32, $y * 32; 678 glTexCoord 1, 0; glVertex $px + $w, $py;
369 glEnd; 679 glEnd;
370 } 680 }
371 } 681 }
372 } 682 }
373 683
375 glDisable GL_BLEND; 685 glDisable GL_BLEND;
376} 686}
377 687
378my %DIR = ( 688my %DIR = (
379 SDLK_KP8, [1, "north"], 689 SDLK_KP8, [1, "north"],
380 SDLK_KP9, [2, "northest"], 690 SDLK_KP9, [2, "northeast"],
381 SDLK_KP6, [3, "east"], 691 SDLK_KP6, [3, "east"],
382 SDLK_KP3, [4, "southeast"], 692 SDLK_KP3, [4, "southeast"],
383 SDLK_KP2, [5, "south"], 693 SDLK_KP2, [5, "south"],
384 SDLK_KP1, [6, "southwest"], 694 SDLK_KP1, [6, "southwest"],
385 SDLK_KP4, [7, "west"], 695 SDLK_KP4, [7, "west"],
386 SDLK_KP7, [8, "northwest"], 696 SDLK_KP7, [8, "northwest"],
697
698 SDLK_UP, [1, "north"],
699 SDLK_RIGHT, [3, "east"],
700 SDLK_DOWN, [5, "south"],
701 SDLK_LEFT, [7, "west"],
387); 702);
388 703
389sub key_down { 704sub key_down {
390 my ($self, $ev) = @_; 705 my ($self, $ev) = @_;
391 706
394 709
395 if ($sym == SDLK_KP5) { 710 if ($sym == SDLK_KP5) {
396 $::CONN->send ("command stay fire"); 711 $::CONN->send ("command stay fire");
397 } elsif (exists $DIR{$sym}) { 712 } elsif (exists $DIR{$sym}) {
398 if ($mod & KMOD_SHIFT) { 713 if ($mod & KMOD_SHIFT) {
714 $self->{shft}++;
399 $::CONN->send ("command fire $DIR{$sym}[0]"); 715 $::CONN->send ("command fire $DIR{$sym}[0]");
400 } elsif ($mod & KMOD_CTRL) { 716 } elsif ($mod & KMOD_CTRL) {
717 $self->{ctrl}++;
401 $::CONN->send ("command run $DIR{$sym}[0]"); 718 $::CONN->send ("command run $DIR{$sym}[0]");
402 } else { 719 } else {
720 $::CONN->send ("command $DIR{$sym}[1]");
403 } 721 }
404 } 722 }
405} 723}
406 724
407sub key_up { 725sub key_up {
408 my ($self, $ev) = @_; 726 my ($self, $ev) = @_;
409 727
410 my $mod = $ev->key_mod; 728 my $mod = $ev->key_mod;
411 my $sym = $ev->key_sym; 729 my $sym = $ev->key_sym;
412 730
413 if (exists $DIR{$sym}) { 731 if (!($mod & KMOD_SHIFT) && delete $self->{shft}) {
414 if ($mod & KMOD_SHIFT) {
415 $::CONN->send ("command fire_stop"); 732 $::CONN->send ("command fire_stop");
416 } else { 733 }
734 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) {
417 $::CONN->send ("command run_stop"); 735 $::CONN->send ("command run_stop");
418 }
419 } 736 }
420} 737}
421 738
4221; 7391;
423 740

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines