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.55 by root, Mon Apr 10 19:34:04 2006 UTC vs.
Revision 1.74 by root, Tue Apr 11 19:31:18 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines