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.53 by root, Mon Apr 10 11:56:28 2006 UTC vs.
Revision 1.72 by root, Tue Apr 11 18:00:45 2006 UTC

1package Crossfire::Client::Widget; 1package CFClient::Widget;
2 2
3use strict; 3use strict;
4 4
5use Scalar::Util; 5use Scalar::Util;
6 6
7use SDL::OpenGL; 7use SDL::OpenGL;
8use SDL::OpenGL::Constants; 8use SDL::OpenGL::Constants;
9 9
10use Crossfire::Client; 10use CFClient;
11 11
12our ($FOCUS, $HOVER, $GRAB); # various widgets 12our ($FOCUS, $HOVER, $GRAB); # various widgets
13 13
14our $TOPLEVEL; 14our $TOPLEVEL;
15our $BUTTON_STATE; 15our $BUTTON_STATE;
34 $GRAB->update if $GRAB; 34 $GRAB->update if $GRAB;
35 } 35 }
36 36
37 $BUTTON_STATE |= 1 << ($ev->button - 1); 37 $BUTTON_STATE |= 1 << ($ev->button - 1);
38 38
39 $GRAB->button_down ($ev) if $GRAB; 39 $GRAB->button_down ($ev, $GRAB->translate ($x, $y)) if $GRAB;
40} 40}
41 41
42sub feed_sdl_button_up_event { 42sub feed_sdl_button_up_event {
43 my ($ev) = @_; 43 my ($ev) = @_;
44 my ($x, $y) = ($ev->motion_x, $ev->motion_y); 44 my ($x, $y) = ($ev->motion_x, $ev->motion_y);
45 45
46 my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y); 46 my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y);
47 47
48 $BUTTON_STATE &= ~(1 << ($ev->button - 1)); 48 $BUTTON_STATE &= ~(1 << ($ev->button - 1));
49
50 $GRAB->button_down ($ev, $GRAB->translate ($x, $y)) if $GRAB;
49 51
50 if (!$BUTTON_STATE) { 52 if (!$BUTTON_STATE) {
51 my $grab = $GRAB; undef $GRAB; 53 my $grab = $GRAB; undef $GRAB;
52 $grab->update if $grab; 54 $grab->update if $grab;
53 $GRAB->update if $GRAB; 55 $GRAB->update if $GRAB;
65 67
66 $hover->update if $hover; 68 $hover->update if $hover;
67 $HOVER->update if $HOVER; 69 $HOVER->update if $HOVER;
68 } 70 }
69 71
70 $HOVER->mouse_motion ($ev) if $HOVER; 72 $HOVER->mouse_motion ($ev, $HOVER->translate ($x, $y)) if $HOVER;
71} 73}
72 74
73sub new { 75sub new {
74 my $class = shift; 76 my $class = shift;
75 77
76 bless { @_ }, $class 78 bless {
79 x => 0,
80 y => 0,
81 z => 0,
82 @_
83 }, $class
77} 84}
78 85
79sub move { 86sub move {
80 my ($self, $x, $y, $z) = @_; 87 my ($self, $x, $y, $z) = @_;
81 $self->{x} = $x; 88 $self->{x} = $x;
97 104
98 $self->{w} = $w; 105 $self->{w} = $w;
99 $self->{h} = $h; 106 $self->{h} = $h;
100} 107}
101 108
109# translate global koordinates to local coordinate system
110sub translate {
111 my ($self, $x, $y) = @_;
112
113 $self->{parent}->translate ($x - $self->{x}, $y - $self->{y});
114}
115
102sub focus_in { 116sub focus_in {
103 my ($self) = @_; 117 my ($self) = @_;
118
119 return if $FOCUS == $self;
104 120
105 my $focus = $FOCUS; $FOCUS = $self; 121 my $focus = $FOCUS; $FOCUS = $self;
106 $focus->update if $focus; 122 $focus->update if $focus;
107 $FOCUS->update; 123 $FOCUS->update;
108} 124}
116 $focus->update if $focus; #? 132 $focus->update if $focus; #?
117} 133}
118 134
119sub mouse_motion { } 135sub mouse_motion { }
120sub button_up { } 136sub button_up { }
121sub button_down { }
122sub key_down { } 137sub key_down { }
123sub key_up { } 138sub key_up { }
139
140sub button_down {
141 my ($self, $ev, $x, $y) = @_;
142
143 $self->focus_in;
144}
124 145
125sub w { $_[0]{w} = $_[1] if @_ > 1; $_[0]{w} } 146sub w { $_[0]{w} = $_[1] if @_ > 1; $_[0]{w} }
126sub h { $_[0]{h} = $_[1] if @_ > 1; $_[0]{h} } 147sub h { $_[0]{h} = $_[1] if @_ > 1; $_[0]{h} }
127sub x { $_[0]{x} = $_[1] if @_ > 1; $_[0]{x} } 148sub x { $_[0]{x} = $_[1] if @_ > 1; $_[0]{x} }
128sub y { $_[0]{y} = $_[1] if @_ > 1; $_[0]{y} } 149sub y { $_[0]{y} = $_[1] if @_ > 1; $_[0]{y} }
129sub z { $_[0]{z} = $_[1] if @_ > 1; $_[0]{z} } 150sub z { $_[0]{z} = $_[1] if @_ > 1; $_[0]{z} }
130 151
131sub draw { 152sub draw {
132 my ($self) = @_; 153 my ($self) = @_;
133 154
155 return unless $self->{h} && $self->{w};
156
134 glPushMatrix; 157 glPushMatrix;
135 glTranslate $self->{x}, $self->{y}, 0; 158 glTranslate $self->{x}, $self->{y}, 0;
136 $self->_draw; 159 $self->_draw;
160 glPopMatrix;
161
137 if ($self == $HOVER) { 162 if ($self == $HOVER) {
163 my ($x, $y) = @$self->{qw(x y)};
164
138 glColor 1, 1, 1, 0.4; 165 glColor 1, 1, 1, 0.1;
139 glEnable GL_BLEND; 166 glEnable GL_BLEND;
140 glBegin GL_QUADS; 167 glBegin GL_QUADS;
141 glVertex 0 , 0; 168 glVertex $x , $y;
142 glVertex $self->{w}, 0; 169 glVertex $x + $self->{w}, $y;
143 glVertex $self->{w}, $self->{h}; 170 glVertex $x + $self->{w}, $y + $self->{h};
144 glVertex 0 , $self->{h}; 171 glVertex $x , $y + $self->{h};
145 glEnd; 172 glEnd;
146 glDisable GL_BLEND; 173 glDisable GL_BLEND;
147 } 174 }
148 glPopMatrix;
149} 175}
150 176
151sub _draw { 177sub _draw {
152 my ($self) = @_; 178 my ($self) = @_;
153 179
193 219
194 $self->{parent}->update 220 $self->{parent}->update
195 if $self->{parent}; 221 if $self->{parent};
196} 222}
197 223
224sub connect {
225 my ($self, $signal, $cb) = @_;
226
227 push @{ $self->{cb}{$signal} }, $cb;
228}
229
230sub emit {
231 my ($self, $signal, @args) = @_;
232
233 $_->($self, @args)
234 for @{$self->{cb}{$signal} || []};
235}
236
198sub DESTROY { 237sub DESTROY {
199 my ($self) = @_; 238 my ($self) = @_;
200 239
201 #$self->deactivate; 240 #$self->deactivate;
202} 241}
203 242
204############################################################################# 243#############################################################################
205 244
206package Crossfire::Client::Widget::Container; 245package CFClient::Widget::DrawBG;
207 246
208our @ISA = Crossfire::Client::Widget::; 247our @ISA = CFClient::Widget::;
248
249use strict;
250use SDL::OpenGL;
209 251
210sub new { 252sub new {
253 my $class = shift;
254
255 # range [value, low, high, page]
256
257 $class->SUPER::new (
258 bg => [0, 0, 0, 0.4],
259 active_bg => [1, 1, 1],
260 @_
261 )
262}
263
264sub _draw {
265 my ($self) = @_;
266
267 my ($w, $h) = @$self{qw(w h)};
268
269 glColor @{ $FOCUS == $self ? $self->{active_bg} : $self->{bg} };
270 glBegin GL_QUADS;
271 glVertex 0 , 0;
272 glVertex 0 , $h;
273 glVertex $w, $h;
274 glVertex $w, 0;
275 glEnd;
276}
277
278#############################################################################
279
280package CFClient::Widget::Empty;
281
282our @ISA = CFClient::Widget::;
283
284sub size_request {
285 (0, 0)
286}
287
288sub draw { }
289
290#############################################################################
291
292package CFClient::Widget::Container;
293
294our @ISA = CFClient::Widget::;
295
296sub new {
211 my ($class, @widgets) = @_; 297 my ($class, %arg) = @_;
212 298
299 my $children = delete $arg{children} || [];
300
213 my $self = $class->SUPER::new (children => []); 301 my $self = $class->SUPER::new (children => [], %arg);
214 $self->add ($_) for @widgets; 302 $self->add ($_) for @$children;
215 303
216 $self 304 $self
217} 305}
218 306
219sub add { 307sub add {
220 my ($self, $chld, $expand) = @_; 308 my ($self, $chld, $expand) = @_;
221 309
222 $chld->{expand} = $expand; 310 $chld->{expand} = $expand;
223 $chld->set_parent ($self); 311 $chld->set_parent ($self);
224 312
225 @{$self->{children}} = 313 $self->{children} = [
226 sort { $a->{z} <=> $b->{z} } 314 sort { $a->{z} <=> $b->{z} }
227 @{$self->{children}}, $chld; 315 @{$self->{children}}, $chld
316 ];
228 317
229 $self->size_allocate ($self->{w}, $self->{h}) 318 $self->size_allocate ($self->{w}, $self->{h})
230 if $self->{w}; #TODO: check for "realised state" 319 if $self->{w}; #TODO: check for "realised state"
231} 320}
232 321
260 $_->draw for @{$self->{children}}; 349 $_->draw for @{$self->{children}};
261} 350}
262 351
263############################################################################# 352#############################################################################
264 353
265package Crossfire::Client::Widget::Bin; 354package CFClient::Widget::Bin;
266 355
267our @ISA = Crossfire::Client::Widget::Container::; 356our @ISA = CFClient::Widget::Container::;
357
358sub new {
359 my ($class, %arg) = @_;
360
361 my $child = (delete $arg{child}) || new CFClient::Widget::Empty::;
362
363 $class->SUPER::new (children => [$child], %arg)
364}
365
366sub add {
367 my ($self, $widget) = @_;
368
369 $self->{children} = [];
370
371 $self->SUPER::add ($widget);
372}
373
374sub remove {
375 my ($self, $widget) = @_;
376
377 $self->SUPER::remove ($widget);
378
379 $self->{children} = [new CFClient::Widget::Empty]
380 unless @{$self->{children}};
381}
268 382
269sub child { $_[0]->{children}[0] } 383sub child { $_[0]->{children}[0] }
270 384
271sub size_request { 385sub size_request {
272 $_[0]{children}[0]->size_request if $_[0]{children}[0]; 386 $_[0]{children}[0]->size_request
273} 387}
274 388
275sub size_allocate { 389sub size_allocate {
276 my ($self, $w, $h) = @_; 390 my ($self, $w, $h) = @_;
277 391
392 return unless $self->{w} != $w || $self->{h} != $h;
393
278 $self->SUPER::size_allocate ($w, $h); 394 $self->SUPER::size_allocate ($w, $h);
279 $self->{children}[0]->size_allocate ($w, $h) 395 $self->{children}[0]->size_allocate ($w, $h);
280 if $self->{children}[0]
281} 396}
282 397
283############################################################################# 398#############################################################################
284 399
285package Crossfire::Client::Widget::Window; 400package CFClient::Widget::Window;
286 401
287our @ISA = Crossfire::Client::Widget::Bin::; 402our @ISA = CFClient::Widget::Bin::;
288 403
289use SDL::OpenGL; 404use SDL::OpenGL;
290 405
291sub new { 406sub new {
292 my ($class, $x, $y, $z, $w, $h) = @_; 407 my ($class, %arg) = @_;
293 408
294 my $self = $class->SUPER::new; 409 my $self = $class->SUPER::new (%arg);
295
296 @$self{qw(x y z w h)} = ($x, $y, $z, $w, $h);
297} 410}
298 411
299sub update { 412sub update {
300 my ($self) = @_; 413 my ($self) = @_;
301 414
415 # we want to do this delayed...
302 $self->render_chld; 416 $self->render_chld;
303 $self->SUPER::update; 417 $self->SUPER::update;
304} 418}
305 419
306sub render_chld { 420sub render_chld {
307 my ($self) = @_; 421 my ($self) = @_;
308 422
309 $self->{texture} = 423 $self->{texture} =
310 Crossfire::Client::Texture->new_from_opengl ( 424 CFClient::Texture->new_from_opengl (
311 $self->{w}, $self->{h}, sub { $self->child->draw } 425 $self->{w}, $self->{h}, sub { $self->child->draw }
312 ); 426 );
313} 427}
314 428
315sub size_allocate { 429sub size_allocate {
316 my ($self, $w, $h) = @_; 430 my ($self, $w, $h) = @_;
431
432 return unless $self->{w} != $w || $self->{h} != $h;
317 433
318 $self->{w} = $w; 434 $self->{w} = $w;
319 $self->{h} = $h; 435 $self->{h} = $h;
320 436
321 $self->child->size_allocate ($w, $h); 437 $self->child->size_allocate ($w, $h);
332 or return; 448 or return;
333 449
334 glEnable GL_BLEND; 450 glEnable GL_BLEND;
335 glEnable GL_TEXTURE_2D; 451 glEnable GL_TEXTURE_2D;
336 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 452 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
337 glBindTexture GL_TEXTURE_2D, $tex->{name};
338 453
339 glBegin GL_QUADS; 454 $tex->draw_quad (0, 0, $w, $h);
340 glTexCoord 0, 0; glVertex 0, 0;
341 glTexCoord 0, 1; glVertex 0, $h;
342 glTexCoord 1, 1; glVertex $w, $h;
343 glTexCoord 1, 0; glVertex $w, 0;
344 glEnd;
345 455
346 glDisable GL_BLEND; 456 glDisable GL_BLEND;
347 glDisable GL_TEXTURE_2D; 457 glDisable GL_TEXTURE_2D;
348} 458}
349 459
350############################################################################# 460#############################################################################
351 461
352package Crossfire::Client::Widget::Frame; 462package CFClient::Widget::Frame;
353 463
354our @ISA = Crossfire::Client::Widget::Bin::; 464our @ISA = CFClient::Widget::Bin::;
355 465
356use SDL::OpenGL; 466use SDL::OpenGL;
357 467
358sub size_request { 468sub size_request {
359 my ($self) = @_; 469 my ($self) = @_;
366} 476}
367 477
368sub size_allocate { 478sub size_allocate {
369 my ($self, $w, $h) = @_; 479 my ($self, $w, $h) = @_;
370 480
481 return unless $self->{w} != $w || $self->{h} != $h;
482
371 $self->{w} = $w; 483 $self->{w} = $w;
372 $self->{h} = $h; 484 $self->{h} = $h;
373 485
374 $self->child->size_allocate ($w - 4, $h - 4); 486 $self->child->size_allocate ($w - 4, $h - 4);
375 $self->child->move (2, 2); 487 $self->child->move (2, 2);
382 494
383 my ($w, $h) = $chld->size_request; 495 my ($w, $h) = $chld->size_request;
384 496
385 glBegin GL_QUADS; 497 glBegin GL_QUADS;
386 glColor 0, 0, 0; 498 glColor 0, 0, 0;
387 glTexCoord 0, 0; glVertex 0 , 0; 499 glVertex 0 , 0;
388 glTexCoord 0, 1; glVertex 0 , $h + 4; 500 glVertex 0 , $h + 4;
389 glTexCoord 1, 1; glVertex $w + 4 , $h + 4; 501 glVertex $w + 4 , $h + 4;
390 glTexCoord 1, 0; glVertex $w + 4 , 0; 502 glVertex $w + 4 , 0;
391 glEnd; 503 glEnd;
392 504
393 $chld->draw; 505 $chld->draw;
394} 506}
395 507
396############################################################################# 508#############################################################################
397 509
398package Crossfire::Client::Widget::FancyFrame; 510package CFClient::Widget::FancyFrame;
399 511
400our @ISA = Crossfire::Client::Widget::Bin::; 512our @ISA = CFClient::Widget::Bin::;
401 513
402use SDL::OpenGL; 514use SDL::OpenGL;
403 515
404my @tex = 516my @tex =
405 map { new_from_file Crossfire::Client::Texture Crossfire::Client::find_rcfile $_ } 517 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
406 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); 518 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
407 519
408sub size_request { 520sub size_request {
409 my ($self) = @_; 521 my ($self) = @_;
410 522
411 my ($w, $h) = $self->SUPER::size_request; 523 my ($w, $h) = $self->SUPER::size_request;
412 524
413 $h += $tex[1]->{height}; 525 $h += $tex[1]->{h};
414 $h += $tex[4]->{height}; 526 $h += $tex[4]->{h};
415 $w += $tex[2]->{width}; 527 $w += $tex[2]->{w};
416 $w += $tex[3]->{width}; 528 $w += $tex[3]->{w};
417 529
418 ($w, $h) 530 ($w, $h)
419} 531}
420 532
421sub size_allocate { 533sub size_allocate {
422 my ($self, $w, $h) = @_; 534 my ($self, $w, $h) = @_;
423 535
536 return unless $self->{w} != $w || $self->{h} != $h;
537
424 $self->SUPER::size_allocate ($w, $h); 538 $self->SUPER::size_allocate ($w, $h);
425 539
426 $h -= $tex[1]->{height}; 540 $h -= $tex[1]->{h};
427 $h -= $tex[4]->{height}; 541 $h -= $tex[4]->{h};
428 $w -= $tex[2]->{width}; 542 $w -= $tex[2]->{w};
429 $w -= $tex[3]->{width}; 543 $w -= $tex[3]->{w};
430 544
431 $h = $h < 0 ? 0 : $h; 545 $h = $h < 0 ? 0 : $h;
432 $w = $w < 0 ? 0 : $w; 546 $w = $w < 0 ? 0 : $w;
433 547
548 my $child = $self->child;
549
434 $self->child->size_allocate ($w, $h); 550 $child->size_allocate ($w, $h);
435 $self->child->move ($tex[3]->{width}, $tex[1]->{height}); 551 $child->move ($tex[3]->{w}, $tex[1]->{h});
436} 552}
437 553
438sub _draw { 554sub _draw {
439 my ($self) = @_; 555 my ($self) = @_;
440 556
445 glEnable GL_TEXTURE_2D; 561 glEnable GL_TEXTURE_2D;
446 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 562 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
447 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 563 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
448 564
449 my $top = $tex[1]; 565 my $top = $tex[1];
450 glBindTexture GL_TEXTURE_2D, $top->{name}; 566 $top->draw_quad (0, 0, $w, $top->{h});
451
452 glBegin GL_QUADS;
453 glTexCoord 0, 0; glVertex 0 , 0;
454 glTexCoord 0, 1; glVertex 0 , $top->{height};
455 glTexCoord 1, 1; glVertex $w , $top->{height};
456 glTexCoord 1, 0; glVertex $w , 0;
457 glEnd;
458 567
459 my $left = $tex[3]; 568 my $left = $tex[3];
460 glBindTexture GL_TEXTURE_2D, $left->{name}; 569 $left->draw_quad (0, $top->{h}, $left->{w}, $ch);
461
462 glBegin GL_QUADS;
463 glTexCoord 0, 0; glVertex 0 , $top->{height};
464 glTexCoord 0, 1; glVertex 0 , $top->{height} + $ch;
465 glTexCoord 1, 1; glVertex $left->{width}, $top->{height} + $ch;
466 glTexCoord 1, 0; glVertex $left->{width}, $top->{height};
467 glEnd;
468 570
469 my $right = $tex[2]; 571 my $right = $tex[2];
470 glBindTexture GL_TEXTURE_2D, $right->{name}; 572 $right->draw_quad ($w - $right->{w}, $top->{h}, $right->{w}, $ch);
471
472 glBegin GL_QUADS;
473 glTexCoord 0, 0; glVertex $w - $right->{width}, $top->{height};
474 glTexCoord 0, 1; glVertex $w - $right->{width}, $top->{height} + $ch;
475 glTexCoord 1, 1; glVertex $w , $top->{height} + $ch;
476 glTexCoord 1, 0; glVertex $w , $top->{height};
477 glEnd;
478 573
479 my $bottom = $tex[4]; 574 my $bottom = $tex[4];
480 glBindTexture GL_TEXTURE_2D, $bottom->{name}; 575 $bottom->draw_quad (0, $h - $bottom->{h}, $w, $bottom->{h});
481
482 glBegin GL_QUADS;
483 glTexCoord 0, 0; glVertex 0 , $h - $bottom->{height};
484 glTexCoord 0, 1; glVertex 0 , $h;
485 glTexCoord 1, 1; glVertex $w , $h;
486 glTexCoord 1, 0; glVertex $w , $h - $bottom->{height};
487 glEnd;
488 576
489 my $bg = $tex[0]; 577 my $bg = $tex[0];
490 glBindTexture GL_TEXTURE_2D, $bg->{name}; 578 glBindTexture GL_TEXTURE_2D, $bg->{name};
491 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 579 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
492 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; 580 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT;
493 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; 581 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT;
494 582
495 my $rep_x = $cw / $bg->{width}; 583 my $rep_x = $cw / $bg->{w};
496 my $rep_y = $ch / $bg->{height}; 584 my $rep_y = $ch / $bg->{h};
497 585
498 glBegin GL_QUADS; 586 $bg->draw_quad ($left->{w}, $top->{h}, $cw, $ch);
499 glTexCoord 0, 0; glVertex $left->{width}, $top->{height};
500 glTexCoord 0, $rep_y; glVertex $left->{width}, $top->{height} + $ch;
501 glTexCoord $rep_x, $rep_y; glVertex $left->{width} + $cw , $top->{height} + $ch;
502 glTexCoord $rep_x, 0; glVertex $left->{width} + $cw , $top->{height};
503 glEnd;
504 587
505 glDisable GL_BLEND; 588 glDisable GL_BLEND;
506 glDisable GL_TEXTURE_2D; 589 glDisable GL_TEXTURE_2D;
507 590
508 $self->child->draw; 591 $self->child->draw;
509 592
510} 593}
511 594
512############################################################################# 595#############################################################################
513 596
514package Crossfire::Client::Widget::Table; 597package CFClient::Widget::Table;
515 598
516our @ISA = Crossfire::Client::Widget::Bin::; 599our @ISA = CFClient::Widget::;
517 600
518use SDL::OpenGL; 601use SDL::OpenGL;
519 602
520sub add { 603sub add {
521 my ($self, $x, $y, $chld) = @_; 604 my ($self, $x, $y, $chld) = @_;
596 } 679 }
597} 680}
598 681
599############################################################################# 682#############################################################################
600 683
601package Crossfire::Client::Widget::VBox; 684package CFClient::Widget::VBox;
602 685
603our @ISA = Crossfire::Client::Widget::Container::; 686our @ISA = CFClient::Widget::Container::;
604 687
605use SDL::OpenGL; 688use SDL::OpenGL;
606 689
607sub size_request { 690sub size_request {
608 my ($self) = @_; 691 my ($self) = @_;
616} 699}
617 700
618sub size_allocate { 701sub size_allocate {
619 my ($self, $w, $h) = @_; 702 my ($self, $w, $h) = @_;
620 703
704 return unless $self->{w} != $w || $self->{h} != $h;
705
621 $self->w ($w); 706 $self->{w} = $w;
622 $self->h ($h); 707 $self->{h} = $h;
623 708
624 my $exp; 709 return unless $self->{h};
625 my @oth; 710
626 # find expand widget 711 my $children = $self->{children};
627 for (@{$self->{children}}) { 712
628 if ($_->{expand}) { 713 my @h = map +($_->size_request)[1], @$children;
629 $exp = $_; 714
630 last; 715 my $req_h = List::Util::sum @h;
716
717 if ($req_h > $h) {
718 # ah well, not enough space
719 $_ = $h[$_] * $h / $req_h for @h;
720 } else {
721 my @exp = grep $_->{expand}, @$children;
722 @exp = @$children unless @exp;
723
724 my %exp = map +($_ => 1), @exp;
725
726 for (0 .. $#$children) {
727 my $child = $children->[$_];
728
729 my $alloc_h = $h[$_];
730 $alloc_h += ($h - $req_h) / @exp if $exp{$child};
731 $h[$_] = $alloc_h;
631 } 732 }
632 push @oth, $_;
633 }
634
635 my ($ow, $oh);
636
637 # get sizes of other widgets
638 for (@oth) {
639 my ($w, $h) = $_->size_request;
640 $oh += $h;
641 if ($ow < $w) { $ow = $w }
642 } 733 }
643 734
644 my $y = 0; 735 my $y = 0;
645 for (@{$self->{children}}) { 736 for (0 .. $#$children) {
737 my $child = $children->[$_];
738 my $h = $h[$_];
646 $_->move (0, $y); 739 $child->move (0, $y);
647
648 if ($_ == $exp) {
649 $_->size_allocate ($w, $h - $oh);
650 $y += $h - $oh;
651 } else {
652 my ($cw, $h) = $_->size_request;
653 $_->size_allocate ($w, $h); 740 $child->size_allocate ($w, $h);
741
654 $y += $h; 742 $y += $h;
655 }
656 } 743 }
657} 744}
658 745
659############################################################################# 746#############################################################################
660 747
661package Crossfire::Client::Widget::Label; 748package CFClient::Widget::Label;
662 749
663our @ISA = Crossfire::Client::Widget::; 750our @ISA = CFClient::Widget::;
664 751
665use SDL::OpenGL; 752use SDL::OpenGL;
666 753
667sub new { 754sub new {
668 my ($class, $x, $y, $z, $height, $text) = @_; 755 my ($class, %arg) = @_;
669 756
757 my $self = $class->SUPER::new (
758 fg => [1, 1, 1],
670 $height ||= $::FONTSIZE; 759 height => $::FONTSIZE,
760 text => "",
761 align => -1,
762 layout => new CFClient::Layout,
763 %arg
764 );
671 765
672 # TODO: color, and make height, xyz etc. optional
673 my $self = $class->SUPER::new (x => $x, y => $y, z => $z, height => $height);
674
675 $self->set_text ($text); 766 $self->set_text ($self->{text});
676 767
677 $self 768 $self
769}
770
771sub escape_text {
772 local $_ = $_[1];
773
774 s/&/&amp;/g;
775 s/>/&gt;/g;
776 s/</&lt;/g;
777
778 $_[1]
678} 779}
679 780
680sub set_text { 781sub set_text {
681 my ($self, $text) = @_; 782 my ($self, $text) = @_;
682 783
683 $self->{text} = $text; 784 $self->{text} = $text;
684 $self->{texture} = new_from_text Crossfire::Client::Texture $text, $self->{height}; 785 $self->{layout}->set_markup ($text);
685 786
787 delete $self->{texture};
686 $self->update; 788 $self->update;
687} 789}
688 790
689sub get_text { 791sub get_text {
690 my ($self, $text) = @_; 792 my ($self, $text) = @_;
693} 795}
694 796
695sub size_request { 797sub size_request {
696 my ($self) = @_; 798 my ($self) = @_;
697 799
800 $self->{layout}->set_width;
801 $self->{layout}->set_height ($self->{height});
802 $self->{layout}->size
698 if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack 803# if ($self->{texture}{w} > 1 && $self->{texture}{height} > 1) { #TODO: hack
699 ( 804# (
700 $self->{texture}{width}, 805# $self->{texture}{w},
701 $self->{texture}{height}, 806# $self->{texture}{h},
702 ) 807# )
703 } else { 808# } else {
704 my ($w, $h, $data) = Crossfire::Client::font_render "Yy", $self->{height}; 809# my ($w, $h, $data) = CFClient::font_render "Yy", $self->{h};
705 810#
706 ($w, $h) 811# ($w, $h)
707 } 812# }
813}
708 814
815sub size_allocate {
816 my ($self, $w, $h) = @_;
817
818 return unless $self->{w} != $w || $self->{h} != $h;
819
820 $self->SUPER::size_allocate ($w, $h);
821 delete $self->{texture};
822}
823
824sub update {
825 my ($self) = @_;
826
827 delete $self->{texture};
828 $self->SUPER::update;
709} 829}
710 830
711sub _draw { 831sub _draw {
712 my ($self) = @_; 832 my ($self) = @_;
713 833
714 my $tex = $self->{texture}; 834 my $tex = $self->{texture} ||= do {
835 $self->{layout}->set_width ($self->{w});
836 new_from_layout CFClient::Texture $self->{layout};
837 };
715 838
716 glEnable GL_BLEND; 839 glEnable GL_BLEND;
717 glEnable GL_TEXTURE_2D; 840 glEnable GL_TEXTURE_2D;
718 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 841 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
719 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 842 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
720 glBindTexture GL_TEXTURE_2D, $tex->{name};
721 843
722 glColor 1, 0, 0, 1; # TODO color 844 glColor @{$self->{fg}};
723 845
724 glBegin GL_QUADS; 846 my $x =
725 glTexCoord 0, 0; glVertex 0 , 0; 847 $self->{align} < 0 ? 0
726 glTexCoord 0, 1; glVertex 0 , $tex->{height}; 848 : $self->{align} > 0 ? $self->{w} - $self->{texture}{w}
727 glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height}; 849 : ($self->{w} + $self->{texture}{w}) * 0.5;
728 glTexCoord 1, 0; glVertex $tex->{width}, 0; 850
729 glEnd; 851 $tex->draw_quad ($x, 0);
730 852
731 glDisable GL_BLEND; 853 glDisable GL_BLEND;
732 glDisable GL_TEXTURE_2D; 854 glDisable GL_TEXTURE_2D;
733} 855}
734 856
735############################################################################# 857#############################################################################
736 858
737package Crossfire::Client::Widget::Entry; 859package CFClient::Widget::Entry;
738 860
739our @ISA = Crossfire::Client::Widget::Label::; 861our @ISA = CFClient::Widget::Label::;
740 862
741use SDL; 863use SDL;
742use SDL::OpenGL; 864use SDL::OpenGL;
743 865
866sub new {
867 my $class = shift;
868
869 $class->SUPER::new (
870 fg => [1, 1, 1],
871 bg => [0, 0, 0, 0.4],
872 active_bg => [1, 1, 1],
873 active_fg => [0, 0, 0],
874 @_
875 )
876}
877
878sub _set_text {
879 my ($self, $text) = @_;
880
881 $self->{last_activity} = $::NOW;
882
883 $self->{text} = $text;
884 $self->{layout}->set_width ($self->{w});
885
886 $text =~ s/./*/g if $self->{hidden};
887
888
889 $self->{layout}->set_markup ($self->escape_text ($text));
890
891 $text = substr $text, 0, $self->{cursor};
892 utf8::encode $text;
893
894 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text);
895}
896
897sub size_request {
898 my ($self) = @_;
899
900 my ($w, $h) = $self->SUPER::size_request;
901
902 ($w + 1, $h) # add 1 for cursor
903}
904
905sub size_allocate {
906 my ($self, $w, $h) = @_;
907
908 return unless $self->{w} != $w || $self->{h} != $h;
909
910 $self->SUPER::size_allocate ($w, $h);
911
912 $self->_set_text ($self->{text});
913}
914
915sub set_text {
916 my ($self, $text) = @_;
917
918 $self->{cursor} = length $text;
919 $self->_set_text ($text);
920 $self->update;
921}
922
744sub key_down { 923sub key_down {
745 my ($self, $ev) = @_; 924 my ($self, $ev) = @_;
746 925
747 my $mod = $ev->key_mod; 926 my $mod = $ev->key_mod;
748 my $sym = $ev->key_sym; 927 my $sym = $ev->key_sym;
750 my $uni = $ev->key_unicode; 929 my $uni = $ev->key_unicode;
751 930
752 my $text = $self->get_text; 931 my $text = $self->get_text;
753 932
754 if ($sym == SDLK_BACKSPACE) { 933 if ($sym == SDLK_BACKSPACE) {
755 substr $text, -1, 1, ''; 934 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
935 } elsif ($sym == SDLK_DELETE) {
936 substr $text, $self->{cursor}, 1, "";
937 } elsif ($sym == SDLK_LEFT) {
938 --$self->{cursor} if $self->{cursor};
939 } elsif ($sym == SDLK_RIGHT) {
940 ++$self->{cursor} if $self->{cursor} < length $self->{text};
756 } elsif ($uni) { 941 } elsif ($uni) {
757 $text .= chr $uni; 942 substr $text, $self->{cursor}++, 0, chr $uni;
758 print "$uni <$text>\n";#d#
759 } 943 }
760 944
761 $self->set_text ($text); 945 $self->_set_text ($text);
946 $self->update;
947}
948
949sub focus_in {
950 my ($self) = @_;
951
952 $self->{last_activity} = $::NOW;
953
954 $self->SUPER::focus_in;
762} 955}
763 956
764sub button_down { 957sub button_down {
765 my ($self, $ev) = @_; 958 my ($self, $ev, $x, $y) = @_;
766 959
767 $self->focus_in; 960 $self->SUPER::button_down ($ev, $x, $y);
961
962 my $idx = $self->{layout}->xy_to_index ($x, $y);
963
964 # byte-index to char-index
965 my $text = $self->{layout};
966 utf8::encode $text;
967 $self->{cursor} = length substr $text, 0, $idx;
968
969 $self->_set_text ($self->{text});
970 $self->update;
971}
972
973sub mouse_motion {
974 my ($self, $ev, $x, $y) = @_;
975# printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d#
768} 976}
769 977
770sub _draw { 978sub _draw {
771 my ($self) = @_; 979 my ($self) = @_;
772 980
981 local $self->{fg} = $self->{fg};
982
773 if ($FOCUS == $self) { 983 if ($FOCUS == $self) {
774 glColor 1, 1, 1; 984 glColor @{$self->{active_bg}};
985 $self->{fg} = $self->{active_fg};
775 } else { 986 } else {
776 glColor 0.7, 0.7, 0.7; 987 glColor @{$self->{bg}};
777 } 988 }
778 989
779 glBegin GL_QUADS; 990 glBegin GL_QUADS;
780 glVertex 0 , 0; 991 glVertex 0 , 0;
781 glVertex 0 , $self->{h} - 1; 992 glVertex 0 , $self->{h};
782 glVertex $self->{w} - 1, $self->{h} - 1; 993 glVertex $self->{w}, $self->{h};
783 glVertex $self->{w} - 1, 0; 994 glVertex $self->{w}, 0;
784 glEnd; 995 glEnd;
785 996
786 $self->SUPER::_draw; 997 $self->SUPER::_draw;
787}
788 998
789############################################################################# 999 #TODO: force update every cursor change :(
1000 if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) {
1001 glColor @{$self->{fg}};
1002 glBegin GL_LINES;
1003 glVertex $self->{cur_x}, $self->{cur_y};
1004 glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h};
1005 glEnd;
1006 }
1007}
790 1008
1009#############################################################################
1010
1011package CFClient::Widget::Slider;
1012
1013use strict;
1014
1015use SDL::OpenGL;
1016use SDL::OpenGL::Constants;
1017
1018our @ISA = CFClient::Widget::DrawBG::;
1019
1020sub size_request {
1021 my ($self) = @_;
1022
1023 my $w = 50;
1024 my $h = 10;
1025
1026 $self->{vertical} ? ($h, $w) : ($w, $h)
1027}
1028
1029sub new {
1030 my $class = shift;
1031
1032 # range [value, low, high, page]
1033
1034 $class->SUPER::new (
1035 fg => [1, 1, 1],
1036 active_fg => [0, 0, 0],
1037 range => [0, 0, 100, 10],
1038 vertical => 1,
1039 @_
1040 )
1041}
1042
1043sub button_down {
1044 my ($self, $ev, $x, $y) = @_;
1045
1046 $self->SUPER::button_down ($ev, $x, $y);
1047 $self->mouse_motion ($ev, $x, $y);
1048}
1049
1050sub mouse_motion {
1051 my ($self, $ev, $x, $y) = @_;
1052
1053 if ($GRAB == $self) {
1054 my ($value, $lo, $hi, $page) = @{$self->{range}};
1055
1056 my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w});
1057
1058 $x = $x * ($hi - $lo) / $w + $lo;
1059 $x = $lo if $x < $lo;
1060 $x = $hi - $page if $x > $hi - $page;
1061 $self->{range}[0] = $x;
1062
1063 $self->emit (changed => $x);
1064 $self->update;
1065 }
1066}
1067
1068sub _draw {
1069 my ($self) = @_;
1070
1071 $self->SUPER::_draw ();
1072
1073 my ($w, $h) = @$self{qw(w h)};
1074
1075 if ($self->{vertical}) {
1076 # draw a vertical slider like a rotated horizontal slider
1077
1078 glRotate 90, 0, 0, 1;
1079 glTranslate 0, -$self->{w}, 0;
1080
1081 ($w, $h) = ($h, $w);
1082 }
1083
1084 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg};
1085 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg};
1086
1087 my ($value, $lo, $hi, $page) = @{$self->{range}};
1088
1089 $page = int $page * $w / ($hi - $lo);
1090 $value = int +($value - $lo) * $w / ($hi - $lo);
1091
1092 $w -= $page;
1093 $page &= ~1;
1094 glTranslate $page * 0.5, 0, 0;
1095
1096 glColor @$fg;
1097 glBegin GL_LINES;
1098 glVertex 0, 0; glVertex 0, $h;
1099 glVertex $w - 1, 0; glVertex $w - 1, $h;
1100 glVertex 0, $h * 0.5; glVertex $w, $h * 0.5;
1101 glEnd;
1102
1103 my $knob_a = $value - $page * 0.5;
1104 my $knob_b = $value + $page * 0.5;
1105
1106 glBegin GL_QUADS;
1107 glColor @$fg;
1108 glVertex $knob_a, 0;
1109 glVertex $knob_a, $h;
1110 glVertex $knob_b, $h;
1111 glVertex $knob_b, 0;
1112
1113 if ($knob_a < $knob_b - 2) {
1114 glColor @$bg;
1115 glVertex $knob_a + 1, 1;
1116 glVertex $knob_a + 1, $h - 1;
1117 glVertex $knob_b - 1, $h - 1;
1118 glVertex $knob_b - 1, 1;
1119 }
1120 glEnd;
1121}
1122
1123#############################################################################
1124
791package Crossfire::Client::Widget::MapWidget; 1125package CFClient::Widget::MapWidget;
792 1126
793use strict; 1127use strict;
794 1128
795use List::Util qw(min max); 1129use List::Util qw(min max);
796 1130
797use SDL; 1131use SDL;
798use SDL::OpenGL; 1132use SDL::OpenGL;
799use SDL::OpenGL::Constants; 1133use SDL::OpenGL::Constants;
800 1134
801our @ISA = Crossfire::Client::Widget::; 1135our @ISA = CFClient::Widget::;
1136
1137sub new {
1138 my $class = shift;
1139
1140 $class->SUPER::new (
1141 z => -1,
1142 list => (glGenLists 1),
1143 @_
1144 )
1145}
802 1146
803sub key_down { 1147sub key_down {
804 print "MAPKEYDOWN\n"; 1148 print "MAPKEYDOWN\n";
805} 1149}
806 1150
812 1 + int $::WIDTH / 32, 1156 1 + int $::WIDTH / 32,
813 1 + int $::HEIGHT / 32, 1157 1 + int $::HEIGHT / 32,
814 ) 1158 )
815} 1159}
816 1160
1161sub update {
1162 my ($self) = @_;
1163
1164 $self->{need_update} = 1;
1165}
1166
817sub _draw { 1167sub _draw {
818 my ($self) = @_; 1168 my ($self) = @_;
819 1169
1170 if (delete $self->{need_update}) {
1171 glNewList $self->{list}, GL_COMPILE;
1172
820 my $mx = $::CONN->{mapx}; 1173 my $mx = $::CONN->{mapx};
821 my $my = $::CONN->{mapy}; 1174 my $my = $::CONN->{mapy};
822 1175
823 my $map = $::CONN->{map}; 1176 my $map = $::CONN->{map};
824 1177
825 my ($xofs, $yofs); 1178 my ($xofs, $yofs);
826 1179
827 my $sw = 1 + int $::WIDTH / 32; 1180 my $sw = 1 + int $::WIDTH / 32;
828 my $sh = 1 + int $::HEIGHT / 32; 1181 my $sh = 1 + int $::HEIGHT / 32;
829 1182
830 if ($::CONN->{mapw} > $sw) { 1183 if ($::CONN->{mapw} > $sw) {
831 $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5; 1184 $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5;
832 } else { 1185 } else {
833 $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs}; 1186 $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs};
834 } 1187 }
835 1188
836 if ($::CONN->{maph} > $sh) { 1189 if ($::CONN->{maph} > $sh) {
837 $yofs = $my + ($::CONN->{maph} - $sh) * 0.5; 1190 $yofs = $my + ($::CONN->{maph} - $sh) * 0.5;
838 } else { 1191 } else {
839 $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs}; 1192 $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs};
840 } 1193 }
841 1194
842 glEnable GL_TEXTURE_2D; 1195 glEnable GL_TEXTURE_2D;
843 glEnable GL_BLEND; 1196 glEnable GL_BLEND;
844 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1197 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
845 1198
846 my $sw4 = ($sw + 3) & ~3; 1199 my $sw4 = ($sw + 3) & ~3;
847 my $lighting = "\x00" x ($sw4 * $sh); 1200 my $darkness = "\x00" x ($sw4 * $sh);
848 1201
849 for my $x (0 .. $sw - 1) { 1202 for my $x (0 .. $sw - 1) {
1203 my $row = $map->[$x + $xofs];
850 for my $y (0 .. $sh - 1) { 1204 for my $y (0 .. $sh - 1) {
851 1205
852 my $cell = $map->[$x + $xofs][$y + $yofs] 1206 my $cell = $row->[$y + $yofs]
853 or next; 1207 or next;
854 1208
855 my $darkness = $cell->[0] * (1 / 255); 1209 my $dark = $cell->[0];
856 if ($darkness < 0) { 1210 if ($dark < 0) {
857 $darkness = $cell->[1] ? 0.2 : 0; 1211 substr $darkness, $y * $sw4 + $x, 1, chr 224;
1212 } else {
1213 substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark;
858 } 1214 }
859 substr $lighting, $y * $sw4 + $x, 1, chr 255 - $darkness * 255;
860 1215
861 for my $num (grep $_, @$cell[1,2,3]) { 1216 for my $num (grep $_, @$cell[1,2,3]) {
862 my $tex = $::CONN->{face}[$num]{texture} || next; 1217 my $tex = $::CONN->{face}[$num]{texture} || next;
1218
1219 my ($w, $h) = @$tex{qw(w h)};
863 1220
864 glBindTexture GL_TEXTURE_2D, $tex->{name}; 1221 $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h);
865
866 my $w = $tex->{width};
867 my $h = $tex->{height};
868
869 my $px = ($x + 1) * 32 - $w;
870 my $py = ($y + 1) * 32 - $h;
871
872 glBegin GL_QUADS;
873 glTexCoord 0, 0; glVertex $px , $py;
874 glTexCoord 0, 1; glVertex $px , $py + $h;
875 glTexCoord 1, 1; glVertex $px + $w, $py + $h;
876 glTexCoord 1, 0; glVertex $px + $w, $py;
877 glEnd; 1222 }
878 } 1223 }
879 } 1224 }
880 }
881 1225
882# if (1) { # higher quality darkness 1226# if (1) { # higher quality darkness
883# $lighting =~ s/(.)/$1$1$1/gs; 1227# $lighting =~ s/(.)/$1$1$1/gs;
884# my $pb = new_from_data Gtk2::Gdk::Pixbuf $lighting, "rgb", 0, 8, $sw4, $sh, $sw4 * 3; 1228# my $pb = new_from_data Gtk2::Gdk::Pixbuf $lighting, "rgb", 0, 8, $sw4, $sh, $sw4 * 3;
885# 1229#
887# 1231#
888# $lighting = $pb->get_pixels; 1232# $lighting = $pb->get_pixels;
889# $lighting =~ s/(.)../$1/gs; 1233# $lighting =~ s/(.)../$1/gs;
890# } 1234# }
891 1235
892 $lighting = new Crossfire::Client::Texture
893 width => $sw4,
894 height => $sh,
895 data => $lighting,
896 internalformat => GL_ALPHA,
897 format => GL_ALPHA;
898
899 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1236 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
900 glColor 0.5, 0.5, 0.5, 1;
901 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1237 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
902 glBindTexture GL_TEXTURE_2D, $lighting->{name};
903 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR;
904 glBegin GL_QUADS;
905 glTexCoord 0, 0; glVertex 0 , 0;
906 glTexCoord 0, 1; glVertex 0 , $sh * 32;
907 glTexCoord 1, 1; glVertex $sw4 * 32, $sh * 32;
908 glTexCoord 1, 0; glVertex $sw4 * 32, 0;
909 glEnd;
910 1238
1239 $darkness = new CFClient::Texture
1240 width => $sw4,
1241 height => $sh,
1242 data => $darkness,
1243 internalformat => GL_ALPHA,
1244 format => GL_ALPHA;
1245
1246 glColor 0.45, 0.45, 0.45, 1;
1247 $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32);
1248
911 glDisable GL_TEXTURE_2D; 1249 glDisable GL_TEXTURE_2D;
912 glDisable GL_BLEND; 1250 glDisable GL_BLEND;
1251
1252 glEndList;
1253 }
1254
1255 glCallList $self->{list};
913} 1256}
914 1257
915my %DIR = ( 1258my %DIR = (
916 SDLK_KP8, [1, "north"], 1259 SDLK_KP8, [1, "north"],
917 SDLK_KP9, [2, "northeast"], 1260 SDLK_KP9, [2, "northeast"],
963 } 1306 }
964} 1307}
965 1308
966############################################################################# 1309#############################################################################
967 1310
968package Crossfire::Client::Widget::Animator; 1311package CFClient::Widget::Animator;
969 1312
970use SDL::OpenGL; 1313use SDL::OpenGL;
971 1314
972our @ISA = Crossfire::Client::Widget::Bin::; 1315our @ISA = CFClient::Widget::Bin::;
973 1316
974sub moveto { 1317sub moveto {
975 my ($self, $x, $y) = @_; 1318 my ($self, $x, $y) = @_;
976 1319
977 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 1320 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
978 $self->{speed} = 2; 1321 $self->{speed} = 0.001;
979 $self->{time} = 1; 1322 $self->{time} = 1;
980 1323
981 ::animation_start $self; 1324 ::animation_start $self;
982} 1325}
983 1326
1005 glPopMatrix; 1348 glPopMatrix;
1006} 1349}
1007 1350
1008############################################################################# 1351#############################################################################
1009 1352
1010package Crossfire::Client::Widget::Toplevel; 1353package CFClient::Widget::Toplevel;
1011 1354
1012our @ISA = Crossfire::Client::Widget::Container::; 1355our @ISA = CFClient::Widget::Container::;
1013 1356
1014sub size_request { 1357sub size_request {
1015 ($::WIDTH, $::HEIGHT) 1358 ($::WIDTH, $::HEIGHT)
1016} 1359}
1017 1360
1022 1365
1023 $_->size_allocate ($_->size_request) 1366 $_->size_allocate ($_->size_request)
1024 for @{$self->{children}}; 1367 for @{$self->{children}};
1025} 1368}
1026 1369
1370sub translate {
1371 my ($self, $x, $y) = @_;
1372
1373 ($x, $y)
1374}
1375
1027sub update { 1376sub update {
1028 my ($self) = @_; 1377 my ($self) = @_;
1029 1378
1030 $self->size_allocate ($self->size_request); 1379 $self->size_allocate ($self->size_request);
1031 ::refresh (); 1380 ::refresh ();
1045 $self->_draw; 1394 $self->_draw;
1046} 1395}
1047 1396
1048############################################################################# 1397#############################################################################
1049 1398
1050package Crossfire::Client::Widget; 1399package CFClient::Widget;
1051 1400
1052$TOPLEVEL = new Crossfire::Client::Widget::Toplevel; 1401$TOPLEVEL = new CFClient::Widget::Toplevel;
1053 1402
10541 14031
1055 1404

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines