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.15 by elmex, Fri Apr 7 23:05:21 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::;
144 my ($self, $row) = @_; 161 my ($self, $row) = @_;
145 162
146 my $hs = 0; 163 my $hs = 0;
147 for (my $xi = 0; $xi <= $#{$self->{childs}->[$row] || []}; $xi++) { 164 for (my $xi = 0; $xi <= $#{$self->{childs}->[$row] || []}; $xi++) {
148 my $c = $self->{childs}->[$row]->[$xi]; 165 my $c = $self->{childs}->[$row]->[$xi];
166 if ($c) {
149 my ($w, $h) = $c->size_request if $c; 167 my ($w, $h) = $c->size_request;
150 if ($hs < $h) { $hs = $h } 168 if ($hs < $h) { $hs = $h }
169 }
151 } 170 }
152 return $hs; 171 return $hs;
153} 172}
154 173
155sub max_col_width { 174sub max_col_width {
156 my ($self, $col) = @_; 175 my ($self, $col) = @_;
157 176
158 my $ws = 0; 177 my $ws = 0;
159 for (my $yi = 0; $yi <= $#{$self->{childs} || []}; $yi++) { 178 for (my $yi = 0; $yi <= $#{$self->{childs} || []}; $yi++) {
160 my $c = ($self->{childs}->[$yi] || [])->[$col]; 179 my $c = ($self->{childs}->[$yi] || [])->[$col];
180 if ($c) {
161 my ($w, $h) = $c->size_request if $c; 181 my ($w, $h) = $c->size_request;
162 if ($ws < $w) { $ws = $w } 182 if ($ws < $w) { $ws = $w }
183 }
163 } 184 }
164 return $ws; 185 return $ws;
165} 186}
166 187
167sub size_request { 188sub size_request {
282sub _draw { 303sub _draw {
283 my ($self) = @_; 304 my ($self) = @_;
284 305
285 my $tex = $self->{texture}; 306 my $tex = $self->{texture};
286 307
287 $self->{x}--;
288
289 glEnable GL_BLEND; 308 glEnable GL_BLEND;
290 glEnable GL_TEXTURE_2D; 309 glEnable GL_TEXTURE_2D;
291 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 310 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
292 glBindTexture GL_TEXTURE_2D, $tex->{name}; 311 glBindTexture GL_TEXTURE_2D, $tex->{name};
293 312
327 346
328use strict; 347use strict;
329 348
330our @ISA = qw/Crossfire::Client::Widget/; 349our @ISA = qw/Crossfire::Client::Widget/;
331 350
351use SDL;
332use SDL::OpenGL; 352use SDL::OpenGL;
333use SDL::OpenGL::Constants; 353use SDL::OpenGL::Constants;
334 354
335sub key_down { 355sub key_down {
336 print "MAPKEYDOWN\n"; 356 print "MAPKEYDOWN\n";
358 for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) { 378 for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) {
359 my $tex = $::CONN->{face}[$num]{texture} || next; 379 my $tex = $::CONN->{face}[$num]{texture} || next;
360 380
361 glBindTexture GL_TEXTURE_2D, $tex->{name}; 381 glBindTexture GL_TEXTURE_2D, $tex->{name};
362 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
363 glBegin GL_QUADS; 389 glBegin GL_QUADS;
364 glTexCoord 0, 0; glVertex $x * 32 , $y * 32; 390 glTexCoord 0, 0; glVertex $px , $py;
365 glTexCoord 0, 1; glVertex $x * 32 , $y * 32 + 32; 391 glTexCoord 0, 1; glVertex $px , $py + $h;
366 glTexCoord 1, 1; glVertex $x * 32 + 32, $y * 32 + 32; 392 glTexCoord 1, 1; glVertex $px + $w, $py + $h;
367 glTexCoord 1, 0; glVertex $x * 32 + 32, $y * 32; 393 glTexCoord 1, 0; glVertex $px + $w, $py;
368 glEnd; 394 glEnd;
369 } 395 }
370 } 396 }
371 } 397 }
372 398
373 glDisable GL_TEXTURE_2D; 399 glDisable GL_TEXTURE_2D;
374 glDisable GL_BLEND; 400 glDisable GL_BLEND;
375} 401}
376 402
403my %DIR = (
404 SDLK_KP8, [1, "north"],
405 SDLK_KP9, [2, "northeast"],
406 SDLK_KP6, [3, "east"],
407 SDLK_KP3, [4, "southeast"],
408 SDLK_KP2, [5, "south"],
409 SDLK_KP1, [6, "southwest"],
410 SDLK_KP4, [7, "west"],
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"],
417);
418
419sub key_down {
420 my ($self, $ev) = @_;
421
422 my $mod = $ev->key_mod;
423 my $sym = $ev->key_sym;
424
425 if ($sym == SDLK_KP5) {
426 $::CONN->send ("command stay fire");
427 } elsif (exists $DIR{$sym}) {
428 if ($mod & KMOD_SHIFT) {
429 $self->{shft}++;
430 $::CONN->send ("command fire $DIR{$sym}[0]");
431 } elsif ($mod & KMOD_CTRL) {
432 $self->{ctrl}++;
433 $::CONN->send ("command run $DIR{$sym}[0]");
434 } else {
435 $::CONN->send ("command $DIR{$sym}[1]");
436 }
437 }
438}
439
440sub key_up {
441 my ($self, $ev) = @_;
442
443 my $mod = $ev->key_mod;
444 my $sym = $ev->key_sym;
445
446 if (!($mod & KMOD_SHIFT) && delete $self->{shft}) {
447 $::CONN->send ("command fire_stop");
448 }
449 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) {
450 $::CONN->send ("command run_stop");
451 }
452}
453
3771; 4541;
378 455

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines