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.39 by root, Sun Apr 9 21:39:08 2006 UTC vs.
Revision 1.55 by root, Mon Apr 10 19:34:04 2006 UTC

5use Scalar::Util; 5use Scalar::Util;
6 6
7use SDL::OpenGL; 7use SDL::OpenGL;
8use SDL::OpenGL::Constants; 8use SDL::OpenGL::Constants;
9 9
10our $FOCUS; # the widget with current focus 10use Crossfire::Client;
11
12our ($FOCUS, $HOVER, $GRAB); # various widgets
13
14our $TOPLEVEL;
15our $BUTTON_STATE;
11 16
12# class methods for events 17# class methods for events
13sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS } 18sub feed_sdl_key_down_event {
14sub feed_sdl_key_up_event { $FOCUS->key_up ($_[0]) if $FOCUS } 19 $FOCUS->key_down ($_[0]) if $FOCUS;
20}
21
22sub feed_sdl_key_up_event {
23 $FOCUS->key_up ($_[0]) if $FOCUS;
24}
25
15sub feed_sdl_button_down_event { } 26sub feed_sdl_button_down_event {
27 my ($ev) = @_;
28 my ($x, $y) = ($ev->motion_x, $ev->motion_y);
29
30 if (!$BUTTON_STATE) {
31 my $widget = $TOPLEVEL->find_widget ($x, $y);
32
33 $GRAB = $widget;
34 $GRAB->update if $GRAB;
35 }
36
37 $BUTTON_STATE |= 1 << ($ev->button - 1);
38
39 $GRAB->button_down ($ev) if $GRAB;
40}
41
16sub feed_sdl_button_up_event { } 42sub feed_sdl_button_up_event {
43 my ($ev) = @_;
44 my ($x, $y) = ($ev->motion_x, $ev->motion_y);
45
46 my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y);
47
48 $BUTTON_STATE &= ~(1 << ($ev->button - 1));
49
50 if (!$BUTTON_STATE) {
51 my $grab = $GRAB; undef $GRAB;
52 $grab->update if $grab;
53 $GRAB->update if $GRAB;
54 }
55}
56
57sub feed_sdl_motion_event {
58 my ($ev) = @_;
59 my ($x, $y) = ($ev->motion_x, $ev->motion_y);
60
61 my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y);
62
63 if ($widget != $HOVER) {
64 my $hover = $HOVER; $HOVER = $widget;
65
66 $hover->update if $hover;
67 $HOVER->update if $HOVER;
68 }
69
70 $HOVER->mouse_motion ($ev) if $HOVER;
71}
17 72
18sub new { 73sub new {
19 my $class = shift; 74 my $class = shift;
20 75
21 bless { @_ }, $class 76 bless { @_ }, $class
37 Carp::confess "size_request is abtract"; 92 Carp::confess "size_request is abtract";
38} 93}
39 94
40sub size_allocate { 95sub size_allocate {
41 my ($self, $w, $h) = @_; 96 my ($self, $w, $h) = @_;
97
42 $self->w ($w); 98 $self->{w} = $w;
43 $self->h ($h); 99 $self->{h} = $h;
44} 100}
45 101
46sub focus_in { 102sub focus_in {
47 my ($widget) = @_; 103 my ($self) = @_;
48 $FOCUS = $widget; 104
105 my $focus = $FOCUS; $FOCUS = $self;
106 $focus->update if $focus;
107 $FOCUS->update;
49} 108}
50 109
51sub focus_out { 110sub focus_out {
52 my ($widget) = @_; 111 my ($self) = @_;
53}
54 112
55sub key_down { 113 return unless $FOCUS == $self;
56 my ($widget, $sdlev) = @_;
57}
58 114
59sub key_up { 115 my $focus = $FOCUS; undef $FOCUS;
60 my ($widget, $sdlev) = @_; 116 $focus->update if $focus; #?
61} 117}
62 118
119sub mouse_motion { }
120sub button_up { }
63sub button_down { 121sub button_down { }
64 my ($widget, $sdlev) = @_; 122sub key_down { }
65} 123sub key_up { }
66 124
67sub button_up {
68 my ($widget, $sdlev) = @_;
69}
70
71sub w { $_[0]->{w} = $_[1] if $_[1]; $_[0]->{w} } 125sub w { $_[0]{w} = $_[1] if @_ > 1; $_[0]{w} }
72sub h { $_[0]->{h} = $_[1] if $_[1]; $_[0]->{h} } 126sub h { $_[0]{h} = $_[1] if @_ > 1; $_[0]{h} }
73sub x { $_[0]->{x} = $_[1] if $_[1]; $_[0]->{x} } 127sub x { $_[0]{x} = $_[1] if @_ > 1; $_[0]{x} }
74sub y { $_[0]->{y} = $_[1] if $_[1]; $_[0]->{y} } 128sub y { $_[0]{y} = $_[1] if @_ > 1; $_[0]{y} }
75sub z { $_[0]->{z} = $_[1] if $_[1]; $_[0]->{z} } 129sub z { $_[0]{z} = $_[1] if @_ > 1; $_[0]{z} }
76 130
77sub draw { 131sub draw {
78 my ($self) = @_; 132 my ($self) = @_;
79 133
80 glPushMatrix; 134 glPushMatrix;
81 glTranslate $self->{x}, $self->{y}, 0; 135 glTranslate $self->{x}, $self->{y}, 0;
82 $self->_draw; 136 $self->_draw;
137 if ($self == $HOVER) {
138 glColor 1, 1, 1, 0.4;
139 glEnable GL_BLEND;
140 glBegin GL_QUADS;
141 glVertex 0 , 0;
142 glVertex $self->{w}, 0;
143 glVertex $self->{w}, $self->{h};
144 glVertex 0 , $self->{h};
145 glEnd;
146 glDisable GL_BLEND;
147 }
83 glPopMatrix; 148 glPopMatrix;
84} 149}
85 150
86sub _draw { 151sub _draw {
87 my ($self) = @_; 152 my ($self) = @_;
159 224
160 @{$self->{children}} = 225 @{$self->{children}} =
161 sort { $a->{z} <=> $b->{z} } 226 sort { $a->{z} <=> $b->{z} }
162 @{$self->{children}}, $chld; 227 @{$self->{children}}, $chld;
163 228
164 $self->size_allocate ($self->{w}, $self->{h}); 229 $self->size_allocate ($self->{w}, $self->{h})
230 if $self->{w}; #TODO: check for "realised state"
165} 231}
166 232
167sub remove { 233sub remove {
168 my ($self, $widget) = @_; 234 my ($self, $widget) = @_;
169 235
173} 239}
174 240
175sub find_widget { 241sub find_widget {
176 my ($self, $x, $y) = @_; 242 my ($self, $x, $y) = @_;
177 243
244 $x -= $self->{x};
245 $y -= $self->{y};
246
178 my $res; 247 my $res;
179 248
180 for (@{ $self->{children} }) { 249 for (reverse @{ $self->{children} }) {
181 $res = $_->find_widget ($x, $y) 250 $res = $_->find_widget ($x, $y)
182 and return $res; 251 and return $res;
183 } 252 }
184 253
185 () 254 $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y})
186}
187
188sub size_request {
189 my ($self) = @_;
190
191 my ($hs, $ws) = (0, 0);
192 for (@{$self->{children} || []}) {
193 my ($w, $h) = $_->size_request;
194 $hs += $h;
195 if ($ws < $w) { $ws = $w }
196 }
197
198 return ($ws, $hs);
199} 255}
200 256
201sub _draw { 257sub _draw {
202 my ($self) = @_; 258 my ($self) = @_;
203 259
216 $_[0]{children}[0]->size_request if $_[0]{children}[0]; 272 $_[0]{children}[0]->size_request if $_[0]{children}[0];
217} 273}
218 274
219sub size_allocate { 275sub size_allocate {
220 my ($self, $w, $h) = @_; 276 my ($self, $w, $h) = @_;
277
221 $self->SUPER::size_allocate ($w, $h); 278 $self->SUPER::size_allocate ($w, $h);
222 $self->{children}[0]->size_allocate ($w, $h) 279 $self->{children}[0]->size_allocate ($w, $h)
223 if $self->{children}[0] 280 if $self->{children}[0]
224} 281}
225 282
226############################################################################# 283#############################################################################
227 284
228package Crossfire::Client::Widget::Toplevel; 285package Crossfire::Client::Widget::Window;
229 286
230our @ISA = Crossfire::Client::Widget::Container::; 287our @ISA = Crossfire::Client::Widget::Bin::;
288
289use SDL::OpenGL;
290
291sub new {
292 my ($class, $x, $y, $z, $w, $h) = @_;
293
294 my $self = $class->SUPER::new;
295
296 @$self{qw(x y z w h)} = ($x, $y, $z, $w, $h);
297}
231 298
232sub update { 299sub update {
233 my ($self) = @_; 300 my ($self) = @_;
234 301
235 ::refresh ();
236}
237
238#############################################################################
239
240package Crossfire::Client::Widget::Window;
241
242our @ISA = Crossfire::Client::Widget::Bin::;
243
244use SDL::OpenGL;
245
246sub add {
247 my ($self, $chld) = @_;
248 warn "ADD $chld\n";
249 $self->SUPER::add ($chld);
250 $chld->set_parent ($self);
251}
252
253sub remove {
254 my ($self) = @_;
255 # TODO FIXME: removing a child from a window will crash, see render_chld
256 # $self->update;
257}
258
259sub update {
260 my ($self) = @_;
261 $self->render_chld; 302 $self->render_chld;
303 $self->SUPER::update;
262} 304}
263 305
264sub render_chld { 306sub render_chld {
265 my ($self) = @_; 307 my ($self) = @_;
266 my $chld = $self->get;
267 my ($w, $h) = $self->size_request;
268 308
269 require Carp;
270 Carp::cluck "RENDERCHI $w $h";
271 warn "RENDERCHI $w $h\n";
272 $self->{texture} = 309 $self->{texture} =
273 Crossfire::Client::Texture->new_from_opengl ( 310 Crossfire::Client::Texture->new_from_opengl (
274 $w, $h, sub { $chld->draw } 311 $self->{w}, $self->{h}, sub { $self->child->draw }
275 ); 312 );
276 $self->{texture}->upload;
277}
278
279sub size_request {
280 my ($self) = @_;
281 ($self->w, $self->h)
282} 313}
283 314
284sub size_allocate { 315sub size_allocate {
285 my ($self, $w, $h) = @_; 316 my ($self, $w, $h) = @_;
286 317
287 $self->w ($w); 318 $self->{w} = $w;
288 $self->h ($h); 319 $self->{h} = $h;
320
289 $self->get->size_allocate ($w, $h); 321 $self->child->size_allocate ($w, $h);
290 322
291 $self->update; #TODO: Move this to the size_request event propably? 323 $self->render_chld;
292} 324}
293 325
294sub _draw { 326sub _draw {
295 my ($self) = @_; 327 my ($self) = @_;
296 328
333 map { $_ + 4 } $chld->size_request; 365 map { $_ + 4 } $chld->size_request;
334} 366}
335 367
336sub size_allocate { 368sub size_allocate {
337 my ($self, $w, $h) = @_; 369 my ($self, $w, $h) = @_;
338 370
339 $self->w ($w); 371 $self->{w} = $w;
340 $self->h ($h); 372 $self->{h} = $h;
341 373
342 $self->child->size_allocate ($w - 4, $h - 4); 374 $self->child->size_allocate ($w - 4, $h - 4);
343 $self->child->move (2, 2); 375 $self->child->move (2, 2);
344} 376}
345 377
363 395
364############################################################################# 396#############################################################################
365 397
366package Crossfire::Client::Widget::FancyFrame; 398package Crossfire::Client::Widget::FancyFrame;
367 399
368our @ISA = Crossfire::Client::Widget::Frame::; 400our @ISA = Crossfire::Client::Widget::Bin::;
369 401
370use SDL::OpenGL; 402use SDL::OpenGL;
371 403
372sub new { 404my @tex =
373 my ($self, $theme) = @_;
374 $self = $self->SUPER::new;
375
376 $self->{txts} = [
377 map { new_from_file Crossfire::Client::Texture Crossfire::Client::find_rcfile $_ } 405 map { new_from_file Crossfire::Client::Texture Crossfire::Client::find_rcfile $_ }
378 qw/d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png/ 406 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
379 ];
380 $self
381}
382 407
383sub size_request { 408sub size_request {
384 my ($self) = @_; 409 my ($self) = @_;
385 410
386 my ($w, $h) = $self->SUPER::size_request; 411 my ($w, $h) = $self->SUPER::size_request;
387 412
388 $h += $self->{txts}->[1]->{height}; 413 $h += $tex[1]->{height};
389 $h += $self->{txts}->[4]->{height}; 414 $h += $tex[4]->{height};
390 $w += $self->{txts}->[2]->{width}; 415 $w += $tex[2]->{width};
391 $w += $self->{txts}->[3]->{width}; 416 $w += $tex[3]->{width};
392 417
393 ($w, $h) 418 ($w, $h)
394} 419}
395 420
396sub size_allocate { 421sub size_allocate {
397 my ($self, $w, $h) = @_; 422 my ($self, $w, $h) = @_;
398 423
399 $self->w ($w); 424 $self->SUPER::size_allocate ($w, $h);
400 $self->h ($h); 425
401 $h -= $self->{txts}->[1]->{height}; 426 $h -= $tex[1]->{height};
402 $h -= $self->{txts}->[4]->{height}; 427 $h -= $tex[4]->{height};
403 $w -= $self->{txts}->[2]->{width}; 428 $w -= $tex[2]->{width};
404 $w -= $self->{txts}->[3]->{width}; 429 $w -= $tex[3]->{width};
405 430
406 $h = $h < 0 ? 0 : $h; 431 $h = $h < 0 ? 0 : $h;
407 $w = $w < 0 ? 0 : $w; 432 $w = $w < 0 ? 0 : $w;
408 warn "CHILD:$w $h\n"; 433
409 $self->child->size_allocate ($w, $h); 434 $self->child->size_allocate ($w, $h);
410 $self->child->move ($self->{txts}->[3]->{width}, $self->{txts}->[1]->{height}); 435 $self->child->move ($tex[3]->{width}, $tex[1]->{height});
411} 436}
412 437
413sub _draw { 438sub _draw {
414 my ($self) = @_; 439 my ($self) = @_;
415 440
416 my ($w, $h) = ($self->w, $self->h); 441 my ($w, $h) = ($self->{w}, $self->{h});
417 my ($cw, $ch) = ($self->child->w, $self->child->h); 442 my ($cw, $ch) = ($self->child->{w}, $self->child->{h});
418 443
419 glEnable GL_BLEND; 444 glEnable GL_BLEND;
420 glEnable GL_TEXTURE_2D; 445 glEnable GL_TEXTURE_2D;
421 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 446 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
422 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 447 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
423 448
424 my $top = $self->{txts}->[1]; 449 my $top = $tex[1];
425 glBindTexture GL_TEXTURE_2D, $top->{name}; 450 glBindTexture GL_TEXTURE_2D, $top->{name};
426 451
427 glBegin GL_QUADS; 452 glBegin GL_QUADS;
428 glTexCoord 0, 0; glVertex 0 , 0; 453 glTexCoord 0, 0; glVertex 0 , 0;
429 glTexCoord 0, 1; glVertex 0 , $top->{height}; 454 glTexCoord 0, 1; glVertex 0 , $top->{height};
430 glTexCoord 1, 1; glVertex $w , $top->{height}; 455 glTexCoord 1, 1; glVertex $w , $top->{height};
431 glTexCoord 1, 0; glVertex $w , 0; 456 glTexCoord 1, 0; glVertex $w , 0;
432 glEnd; 457 glEnd;
433 458
434 my $left = $self->{txts}->[3]; 459 my $left = $tex[3];
435 glBindTexture GL_TEXTURE_2D, $left->{name}; 460 glBindTexture GL_TEXTURE_2D, $left->{name};
436 461
437 glBegin GL_QUADS; 462 glBegin GL_QUADS;
438 glTexCoord 0, 0; glVertex 0 , $top->{height}; 463 glTexCoord 0, 0; glVertex 0 , $top->{height};
439 glTexCoord 0, 1; glVertex 0 , $top->{height} + $ch; 464 glTexCoord 0, 1; glVertex 0 , $top->{height} + $ch;
440 glTexCoord 1, 1; glVertex $left->{width}, $top->{height} + $ch; 465 glTexCoord 1, 1; glVertex $left->{width}, $top->{height} + $ch;
441 glTexCoord 1, 0; glVertex $left->{width}, $top->{height}; 466 glTexCoord 1, 0; glVertex $left->{width}, $top->{height};
442 glEnd; 467 glEnd;
443 468
444 my $right = $self->{txts}->[2]; 469 my $right = $tex[2];
445 glBindTexture GL_TEXTURE_2D, $right->{name}; 470 glBindTexture GL_TEXTURE_2D, $right->{name};
446 471
447 glBegin GL_QUADS; 472 glBegin GL_QUADS;
448 glTexCoord 0, 0; glVertex $w - $right->{width}, $top->{height}; 473 glTexCoord 0, 0; glVertex $w - $right->{width}, $top->{height};
449 glTexCoord 0, 1; glVertex $w - $right->{width}, $top->{height} + $ch; 474 glTexCoord 0, 1; glVertex $w - $right->{width}, $top->{height} + $ch;
450 glTexCoord 1, 1; glVertex $w , $top->{height} + $ch; 475 glTexCoord 1, 1; glVertex $w , $top->{height} + $ch;
451 glTexCoord 1, 0; glVertex $w , $top->{height}; 476 glTexCoord 1, 0; glVertex $w , $top->{height};
452 glEnd; 477 glEnd;
453 478
454 my $bottom = $self->{txts}->[4]; 479 my $bottom = $tex[4];
455 glBindTexture GL_TEXTURE_2D, $bottom->{name}; 480 glBindTexture GL_TEXTURE_2D, $bottom->{name};
456 481
457 glBegin GL_QUADS; 482 glBegin GL_QUADS;
458 glTexCoord 0, 0; glVertex 0 , $h - $bottom->{height}; 483 glTexCoord 0, 0; glVertex 0 , $h - $bottom->{height};
459 glTexCoord 0, 1; glVertex 0 , $h; 484 glTexCoord 0, 1; glVertex 0 , $h;
460 glTexCoord 1, 1; glVertex $w , $h; 485 glTexCoord 1, 1; glVertex $w , $h;
461 glTexCoord 1, 0; glVertex $w , $h - $bottom->{height}; 486 glTexCoord 1, 0; glVertex $w , $h - $bottom->{height};
462 glEnd; 487 glEnd;
463 488
464 my $bg = $self->{txts}->[0]; 489 my $bg = $tex[0];
465 glBindTexture GL_TEXTURE_2D, $bg->{name}; 490 glBindTexture GL_TEXTURE_2D, $bg->{name};
466 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 491 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
467 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; 492 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT;
468 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; 493 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT;
469 494
576package Crossfire::Client::Widget::VBox; 601package Crossfire::Client::Widget::VBox;
577 602
578our @ISA = Crossfire::Client::Widget::Container::; 603our @ISA = Crossfire::Client::Widget::Container::;
579 604
580use SDL::OpenGL; 605use SDL::OpenGL;
606
607sub size_request {
608 my ($self) = @_;
609
610 my @alloc = map [$_->size_request], @{$self->{children}};
611
612 (
613 (List::Util::max map $_->[0], @alloc),
614 (List::Util::sum map $_->[1], @alloc),
615 )
616}
581 617
582sub size_allocate { 618sub size_allocate {
583 my ($self, $w, $h) = @_; 619 my ($self, $w, $h) = @_;
584 620
585 $self->w ($w); 621 $self->w ($w);
618 $y += $h; 654 $y += $h;
619 } 655 }
620 } 656 }
621} 657}
622 658
623sub _draw {
624 my ($self) = @_;
625
626 my ($x, $y);
627 for (@{$self->{children} || []}) {
628 $_->draw;
629 $y += $_->h;
630 }
631}
632
633############################################################################# 659#############################################################################
634 660
635package Crossfire::Client::Widget::Label; 661package Crossfire::Client::Widget::Label;
636 662
637our @ISA = Crossfire::Client::Widget::; 663our @ISA = Crossfire::Client::Widget::;
639use SDL::OpenGL; 665use SDL::OpenGL;
640 666
641sub new { 667sub new {
642 my ($class, $x, $y, $z, $height, $text) = @_; 668 my ($class, $x, $y, $z, $height, $text) = @_;
643 669
670 $height ||= $::FONTSIZE;
671
644 # TODO: color, and make height, xyz etc. optional 672 # TODO: color, and make height, xyz etc. optional
645 my $self = $class->SUPER::new (x => $x, y => $y, z => $z, height => $height); 673 my $self = $class->SUPER::new (x => $x, y => $y, z => $z, height => $height);
646 674
647 $self->set_text ($text); 675 $self->set_text ($text);
648 676
665} 693}
666 694
667sub size_request { 695sub size_request {
668 my ($self) = @_; 696 my ($self) = @_;
669 697
670 ( 698 if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack
699 (
671 $self->{texture}{width}, 700 $self->{texture}{width},
672 $self->{texture}{height}, 701 $self->{texture}{height},
702 )
703 } else {
704 my ($w, $h, $data) = Crossfire::Client::font_render "Yy", $self->{height};
705
706 ($w, $h)
673 ) 707 }
708
674} 709}
675 710
676sub _draw { 711sub _draw {
677 my ($self) = @_; 712 my ($self) = @_;
678 713
697 glDisable GL_TEXTURE_2D; 732 glDisable GL_TEXTURE_2D;
698} 733}
699 734
700############################################################################# 735#############################################################################
701 736
702package Crossfire::Client::Widget::TextEntry; 737package Crossfire::Client::Widget::Entry;
703 738
704our @ISA = Crossfire::Client::Widget::Label::; 739our @ISA = Crossfire::Client::Widget::Label::;
705 740
706use SDL; 741use SDL;
707use SDL::OpenGL; 742use SDL::OpenGL;
710 my ($self, $ev) = @_; 745 my ($self, $ev) = @_;
711 746
712 my $mod = $ev->key_mod; 747 my $mod = $ev->key_mod;
713 my $sym = $ev->key_sym; 748 my $sym = $ev->key_sym;
714 749
715 $ev->set_unicode (1);
716 my $uni = $ev->key_unicode; 750 my $uni = $ev->key_unicode;
717 751
718 my $text = $self->get_text; 752 my $text = $self->get_text;
719 753
720 if ($sym == SDLK_BACKSPACE) { 754 if ($sym == SDLK_BACKSPACE) {
721 substr $text, -1, 1, ''; 755 substr $text, -1, 1, '';
722
723 } elsif ($uni) { 756 } elsif ($uni) {
724 $text .= chr $uni; 757 $text .= chr $uni;
758 print "$uni <$text>\n";#d#
725 } 759 }
760
726 $self->set_text ($text); 761 $self->set_text ($text);
762}
763
764sub button_down {
765 my ($self, $ev) = @_;
766
767 $self->focus_in;
768}
769
770sub _draw {
771 my ($self) = @_;
772
773 if ($FOCUS == $self) {
774 glColor 1, 1, 1;
775 } else {
776 glColor 0.7, 0.7, 0.7;
777 }
778
779 glBegin GL_QUADS;
780 glVertex 0 , 0;
781 glVertex 0 , $self->{h} - 1;
782 glVertex $self->{w} - 1, $self->{h} - 1;
783 glVertex $self->{w} - 1, 0;
784 glEnd;
785
786 $self->SUPER::_draw;
727} 787}
728 788
729############################################################################# 789#############################################################################
730 790
731package Crossfire::Client::Widget::MapWidget; 791package Crossfire::Client::Widget::MapWidget;
746 806
747sub key_up { 807sub key_up {
748} 808}
749 809
750sub size_request { 810sub size_request {
751 811 (
752} 812 1 + int $::WIDTH / 32,
753 813 1 + int $::HEIGHT / 32,
754sub size_allocate { 814 )
755} 815}
756 816
757sub _draw { 817sub _draw {
758 my ($self) = @_; 818 my ($self) = @_;
759 819
792 my $cell = $map->[$x + $xofs][$y + $yofs] 852 my $cell = $map->[$x + $xofs][$y + $yofs]
793 or next; 853 or next;
794 854
795 my $darkness = $cell->[0] * (1 / 255); 855 my $darkness = $cell->[0] * (1 / 255);
796 if ($darkness < 0) { 856 if ($darkness < 0) {
797 $darkness = 0.15; 857 $darkness = $cell->[1] ? 0.1 : 0;
798 } 858 }
799 substr $lighting, $y * $sw4 + $x, 1, chr 255 - $darkness * 255; 859 substr $lighting, $y * $sw4 + $x, 1, chr 255 - $darkness * 255;
800 860
801 for my $num (grep $_, @$cell[1,2,3]) { 861 for my $num (grep $_, @$cell[1,2,3]) {
802 my $tex = $::CONN->{face}[$num]{texture} || next; 862 my $tex = $::CONN->{face}[$num]{texture} || next;
831 891
832 $lighting = new Crossfire::Client::Texture 892 $lighting = new Crossfire::Client::Texture
833 width => $sw4, 893 width => $sw4,
834 height => $sh, 894 height => $sh,
835 data => $lighting, 895 data => $lighting,
836 internalformat => GL_ALPHA4, 896 internalformat => GL_ALPHA,
837 format => GL_ALPHA; 897 format => GL_ALPHA;
838 898
839 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 899 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
840 glColor 0, 0, 0, 0.75; 900 glColor 0.45, 0.45, 0.45, 1;
841 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 901 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
842 glBindTexture GL_TEXTURE_2D, $lighting->{name}; 902 glBindTexture GL_TEXTURE_2D, $lighting->{name};
843 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; 903 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR;
844 glBegin GL_QUADS; 904 glBegin GL_QUADS;
845 glTexCoord 0, 0; glVertex 0 , 0; 905 glTexCoord 0, 0; glVertex 0 , 0;
913 973
914sub moveto { 974sub moveto {
915 my ($self, $x, $y) = @_; 975 my ($self, $x, $y) = @_;
916 976
917 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 977 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
918 $self->{speed} = 0.2; 978 $self->{speed} = 2;
919 $self->{time} = 1; 979 $self->{time} = 1;
920 980
921 ::animation_start $self; 981 ::animation_start $self;
922} 982}
923 983
938 998
939sub _draw { 999sub _draw {
940 my ($self) = @_; 1000 my ($self) = @_;
941 1001
942 glPushMatrix; 1002 glPushMatrix;
943 glRotate $self->{time} * 10000, 0, 1, 0; 1003 glRotate $self->{time} * 1000, 0, 1, 0;
944 $self->{children}[0]->draw; 1004 $self->{children}[0]->draw;
945 glPopMatrix; 1005 glPopMatrix;
946} 1006}
947 1007
9481; 1008#############################################################################
949 1009
1010package Crossfire::Client::Widget::Toplevel;
1011
1012our @ISA = Crossfire::Client::Widget::Container::;
1013
1014sub size_request {
1015 ($::WIDTH, $::HEIGHT)
1016}
1017
1018sub size_allocate {
1019 my ($self, $w, $h) = @_;
1020
1021 $self->SUPER::size_allocate ($w, $h);
1022
1023 $_->size_allocate ($_->size_request)
1024 for @{$self->{children}};
1025}
1026
1027sub update {
1028 my ($self) = @_;
1029
1030 $self->size_allocate ($self->size_request);
1031 ::refresh ();
1032}
1033
1034sub add {
1035 my ($self, $widget) = @_;
1036
1037 $self->SUPER::add ($widget);
1038
1039 $widget->size_allocate ($widget->size_request);
1040}
1041
1042sub draw {
1043 my ($self) = @_;
1044
1045 $self->_draw;
1046}
1047
1048#############################################################################
1049
1050package Crossfire::Client::Widget;
1051
1052$TOPLEVEL = new Crossfire::Client::Widget::Toplevel;
1053
10541
1055

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines