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.17 by elmex, Sat Apr 8 13:34:19 2006 UTC vs.
Revision 1.19 by root, Sat Apr 8 14:04:14 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; 11our @ACTIVE_WIDGETS;
19 bless { @_ }, $class 22 bless { @_ }, $class
20} 23}
21 24
22sub activate { 25sub activate {
23 push @ACTIVE_WIDGETS, $_[0]; 26 push @ACTIVE_WIDGETS, $_[0];
27 Scalar::Util::weaken $ACTIVE_WIDGETS[-1];
24} 28}
25 29
26sub deactivate { 30sub 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;
31} 42}
32 43
33sub size_request { 44sub size_request {
34 die "size_request is abtract"; 45 die "size_request is abtract";
35} 46}
78 my ($widget) = @_; 89 my ($widget) = @_;
79} 90}
80 91
81sub bbox { 92sub bbox {
82 my ($widget) = @_; 93 my ($widget) = @_;
94}
95
96sub DESTROY {
97 my ($self) = @_;
98
99 $self->deactivate;
83} 100}
84 101
85package Crossfire::Client::Widget::Container; 102package Crossfire::Client::Widget::Container;
86 103
87our @ISA = Crossfire::Client::Widget::; 104our @ISA = Crossfire::Client::Widget::;
286sub _draw { 303sub _draw {
287 my ($self) = @_; 304 my ($self) = @_;
288 305
289 my $tex = $self->{texture}; 306 my $tex = $self->{texture};
290 307
291 $self->{x}--;
292
293 glEnable GL_BLEND; 308 glEnable GL_BLEND;
294 glEnable GL_TEXTURE_2D; 309 glEnable GL_TEXTURE_2D;
295 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 310 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
296 glBindTexture GL_TEXTURE_2D, $tex->{name}; 311 glBindTexture GL_TEXTURE_2D, $tex->{name};
297 312
363 for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) { 378 for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) {
364 my $tex = $::CONN->{face}[$num]{texture} || next; 379 my $tex = $::CONN->{face}[$num]{texture} || next;
365 380
366 glBindTexture GL_TEXTURE_2D, $tex->{name}; 381 glBindTexture GL_TEXTURE_2D, $tex->{name};
367 382
383 my $w = $tex->{width};
384 my $h = $tex->{height};
385
386 my $px = ($x + 1) * 32 - $w;
387 my $py = ($y + 1) * 32 - $h;
388
368 glBegin GL_QUADS; 389 glBegin GL_QUADS;
369 glTexCoord 0, 0; glVertex $x * 32 , $y * 32; 390 glTexCoord 0, 0; glVertex $px , $py;
370 glTexCoord 0, 1; glVertex $x * 32 , $y * 32 + 32; 391 glTexCoord 0, 1; glVertex $px , $py + $h;
371 glTexCoord 1, 1; glVertex $x * 32 + 32, $y * 32 + 32; 392 glTexCoord 1, 1; glVertex $px + $w, $py + $h;
372 glTexCoord 1, 0; glVertex $x * 32 + 32, $y * 32; 393 glTexCoord 1, 0; glVertex $px + $w, $py;
373 glEnd; 394 glEnd;
374 } 395 }
375 } 396 }
376 } 397 }
377 398
379 glDisable GL_BLEND; 400 glDisable GL_BLEND;
380} 401}
381 402
382my %DIR = ( 403my %DIR = (
383 SDLK_KP8, [1, "north"], 404 SDLK_KP8, [1, "north"],
384 SDLK_KP9, [2, "northest"], 405 SDLK_KP9, [2, "northeast"],
385 SDLK_KP6, [3, "east"], 406 SDLK_KP6, [3, "east"],
386 SDLK_KP3, [4, "southeast"], 407 SDLK_KP3, [4, "southeast"],
387 SDLK_KP2, [5, "south"], 408 SDLK_KP2, [5, "south"],
388 SDLK_KP1, [6, "southwest"], 409 SDLK_KP1, [6, "southwest"],
389 SDLK_KP4, [7, "west"], 410 SDLK_KP4, [7, "west"],
390 SDLK_KP7, [8, "northwest"], 411 SDLK_KP7, [8, "northwest"],
412
413 SDLK_UP, [1, "north"],
414 SDLK_RIGHT, [3, "east"],
415 SDLK_DOWN, [5, "south"],
416 SDLK_LEFT, [7, "west"],
391); 417);
392 418
393sub key_down { 419sub key_down {
394 my ($self, $ev) = @_; 420 my ($self, $ev) = @_;
395 421
398 424
399 if ($sym == SDLK_KP5) { 425 if ($sym == SDLK_KP5) {
400 $::CONN->send ("command stay fire"); 426 $::CONN->send ("command stay fire");
401 } elsif (exists $DIR{$sym}) { 427 } elsif (exists $DIR{$sym}) {
402 if ($mod & KMOD_SHIFT) { 428 if ($mod & KMOD_SHIFT) {
429 $self->{shft}++;
403 $::CONN->send ("command fire $DIR{$sym}[0]"); 430 $::CONN->send ("command fire $DIR{$sym}[0]");
404 } elsif ($mod & KMOD_CTRL) { 431 } elsif ($mod & KMOD_CTRL) {
432 $self->{ctrl}++;
405 $::CONN->send ("command run $DIR{$sym}[0]"); 433 $::CONN->send ("command run $DIR{$sym}[0]");
406 } else { 434 } else {
435 $::CONN->send ("command $DIR{$sym}[1]");
407 } 436 }
408 } 437 }
409} 438}
410 439
411sub key_up { 440sub key_up {
412 my ($self, $ev) = @_; 441 my ($self, $ev) = @_;
413 442
414 my $mod = $ev->key_mod; 443 my $mod = $ev->key_mod;
415 my $sym = $ev->key_sym; 444 my $sym = $ev->key_sym;
416 445
417 if (exists $DIR{$sym}) { 446 if (!($mod & KMOD_SHIFT) && delete $self->{shft}) {
418 if ($mod & KMOD_SHIFT) {
419 $::CONN->send ("command fire_stop"); 447 $::CONN->send ("command fire_stop");
420 } else { 448 }
449 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) {
421 $::CONN->send ("command run_stop"); 450 $::CONN->send ("command run_stop");
422 }
423 } 451 }
424} 452}
425 453
4261; 4541;
427 455

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines