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.73 by root, Tue Apr 11 18:06:53 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines