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.26 by elmex, Sat Apr 8 22:23:57 2006 UTC vs.
Revision 1.31 by elmex, Sun Apr 9 00:43:11 2006 UTC

148} 148}
149 149
150sub _draw { 150sub _draw {
151 my ($self) = @_; 151 my ($self) = @_;
152 152
153 my ($w, $h) = $self->size_request;#TODO# use widht/height of texture 153 my ($w, $h) = $self->size_request;#TODO# use width/height of texture
154
154 my $tex = $self->{texture} 155 my $tex = $self->{texture}
155 or return; 156 or return;
156 157
157 glEnable GL_BLEND; 158 glEnable GL_BLEND;
158 glEnable GL_TEXTURE_2D; 159 glEnable GL_TEXTURE_2D;
159 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 160 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
160 glBindTexture GL_TEXTURE_2D, $tex->{name}; 161 glBindTexture GL_TEXTURE_2D, $tex->{name};
161 162
162 glColor 1, 1, 1; 163 glColor 1, 0, 1;
163 164
164 glBegin GL_QUADS; 165 glBegin GL_QUADS;
165 glTexCoord 0, 0; glVertex 0, 0; 166 glTexCoord 0, 0; glVertex 0, 0;
166 glTexCoord 0, 1; glVertex 0, $h; 167 glTexCoord 0, 1; glVertex 0, $h;
167 glTexCoord 1, 1; glVertex $w, $h; 168 glTexCoord 1, 1; glVertex $w, $h;
180 181
181sub size_request { 182sub size_request {
182 my ($self) = @_; 183 my ($self) = @_;
183 my $chld = $self->get 184 my $chld = $self->get
184 or return (0, 0); 185 or return (0, 0);
186
187 $chld->move (2, 2);
188
185 map { $_ + 4 } $chld->size_request; 189 map { $_ + 4 } $chld->size_request;
186} 190}
187 191
188sub _draw { 192sub _draw {
189 my ($self) = @_; 193 my ($self) = @_;
190 194
191 my $chld = $self->get; 195 my $chld = $self->get;
192 196
193 $chld->move (2, 2, 0); #TODO:move to size_request
194
195 my ($w, $h) = $chld->size_request; 197 my ($w, $h) = $chld->size_request;
196 198
197 glColor 1, 0, 0;
198 glBegin GL_QUADS; 199 glBegin GL_QUADS;
200 glColor 0, 0, 0;
199 glTexCoord 0, 0; glVertex 0 , 0; 201 glTexCoord 0, 0; glVertex 0 , 0;
200 glTexCoord 0, 1; glVertex 0 , $h + 4; 202 glTexCoord 0, 1; glVertex 0 , $h + 4;
201 glTexCoord 1, 1; glVertex $w + 4 , $h + 4; 203 glTexCoord 1, 1; glVertex $w + 4 , $h + 4;
202 glTexCoord 1, 0; glVertex $w + 4 , 0; 204 glTexCoord 1, 0; glVertex $w + 4 , 0;
203 glEnd; 205 glEnd;
204 206
205 $chld->draw; 207 $chld->draw;
206} 208}
209
210package Crossfire::Client::Widget::FancyFrame;
211
212our @ISA = Crossfire::Client::Widget::Frame::;
213
214use SDL::OpenGL;
215
216#TODO: implement themed frame
207 217
208package Crossfire::Client::Widget::Table; 218package Crossfire::Client::Widget::Table;
209 219
210our @ISA = Crossfire::Client::Widget::Container::; 220our @ISA = Crossfire::Client::Widget::Container::;
211 221
327our @ISA = Crossfire::Client::Widget::; 337our @ISA = Crossfire::Client::Widget::;
328 338
329use SDL::OpenGL; 339use SDL::OpenGL;
330 340
331sub new { 341sub new {
332 my ($class, $x, $y, $z, $ttf, $text) = @_; 342 my ($class, $x, $y, $z, $height, $text) = @_;
333 343
334 my $self = $class->SUPER::new (x => $x, y => $y, z => $z, ttf => $ttf); 344 my $self = $class->SUPER::new (x => $x, y => $y, z => $z, height => $height);
335 345
336 $self->set_text ($text); 346 $self->set_text ($text);
337 347
338 $self 348 $self
339} 349}
340 350
341sub set_text { 351sub set_text {
342 my ($self, $text) = @_; 352 my ($self, $text) = @_;
353
354 $self->{text} = $text;
355
343 $self->{texture} = new_from_ttf Crossfire::Client::Texture $self->{ttf}, $self->{text} = $text; 356 $self->{texture} = new_from_text Crossfire::Client::Texture $text, $self->{height};
344} 357}
345 358
346sub get_text { 359sub get_text {
347 my ($self, $text) = @_; 360 my ($self, $text) = @_;
361
348 $self->{text} 362 $self->{text}
349} 363}
350 364
351sub size_request { 365sub size_request {
352 my ($self) = @_; 366 my ($self) = @_;
362 376
363 my $tex = $self->{texture}; 377 my $tex = $self->{texture};
364 378
365 glEnable GL_BLEND; 379 glEnable GL_BLEND;
366 glEnable GL_TEXTURE_2D; 380 glEnable GL_TEXTURE_2D;
381 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
367 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;#DECAL; 382 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
368 glBindTexture GL_TEXTURE_2D, $tex->{name}; 383 glBindTexture GL_TEXTURE_2D, $tex->{name};
369 384
370 glColor 1, 0, 1; 385 glColor 1, 1, 1, 0.8;
371 386
372 glBegin GL_QUADS; 387 glBegin GL_QUADS;
373 glTexCoord 0, 0; glVertex 0 , 0; 388 glTexCoord 0, 0; glVertex 0 , 0;
374 glTexCoord 0, 1; glVertex 0 , $tex->{height}; 389 glTexCoord 0, 1; glVertex 0 , $tex->{height};
375 glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height}; 390 glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height};
378 393
379 glDisable GL_BLEND; 394 glDisable GL_BLEND;
380 glDisable GL_TEXTURE_2D; 395 glDisable GL_TEXTURE_2D;
381} 396}
382 397
398package Crossfire::Client::Widget::TextEntry;
399
400our @ISA = Crossfire::Client::Widget::Label::;
401
402use SDL;
403use SDL::OpenGL;
404
405sub key_down {
406 my ($self, $ev) = @_;
407
408 my $mod = $ev->key_mod;
409 my $sym = $ev->key_sym;
410
411 $ev->set_unicode (1);
412 my $uni = $ev->key_unicode;
413
414 my $text = $self->get_text;
415
416 if ($sym == SDLK_BACKSPACE) {
417 substr $text, -1, 1, '';
418
419 } elsif ($uni) {
420 $text .= chr $uni;
421 }
422 $self->set_text ($text);
423}
424
425
426# XXX: TextView isn't neccessary with pango multiline text rendering
383package Crossfire::Client::Widget::TextView; 427package Crossfire::Client::Widget::TextView;
384 428
385use strict; 429use strict;
386 430
387our @ISA = qw/Crossfire::Client::Widget/; 431our @ISA = qw/Crossfire::Client::Widget/;
388 432
389use SDL::OpenGL; 433use SDL::OpenGL;
390use SDL::OpenGL::Constants; 434use SDL::OpenGL::Constants;
435
436sub new {
437 my ($class, $text, $h) = @_;
438 my $self = $class->SUPER::new ();
439
440 $self->{txt_height} = $h;
441 @{$self->{lines}} = split /\r?\n/, $text;
442
443 for (split /\r?\n/, $text) {
444 $self->add_line ($_);
445 }
446 $self
447}
448
449#sub render_lines {
450# my ($self) = @_;
451#
452# $self->{txt_lines} = [];
453#
454# for (@{$self->{lines}}) {
455# push @{$self->{txt_lines}},
456# new_from_ttf Crossfire::Client::Texture $self->{ttf}, $_;
457# }
458#}
391 459
392sub add_line { 460sub add_line {
393 my ($self, $line) = @_; 461 my ($self, $line) = @_;
394 push @{$self->{lines}}, $line; 462 push @{$self->{lines}}, $line;
395}
396 463
464 push @{$self->{txt_lines}},
465 new_from_text Crossfire::Client::Texture $line, $self->{txt_height};
466}
467
468sub size_request {
469 my ($self) = @_;
470
471 my $w = 0;
472 my $h = 0;
473
474 for (@{$self->{txt_lines}}) {
475 if ($w < $_->{width}) { $w = $_->{width} }
476 $h += $_->{height};
477 }
478
479 return ($w, $h);
480}
481
397sub _draw { 482sub draw_line {
398 my ($self) = @_; 483 my ($self, $tex, $y) = @_;
399 484
485 glBindTexture GL_TEXTURE_2D, $tex->{name};
486
487 glColor 1, 0, 1;
488
489 glBegin GL_QUADS;
490 glTexCoord 0, 0; glVertex 0 , $y;
491 glTexCoord 0, 1; glVertex 0 , $y + $tex->{height};
492 glTexCoord 1, 1; glVertex $tex->{width}, $y + $tex->{height};
493 glTexCoord 1, 0; glVertex $tex->{width}, $y;
494 glEnd;
495}
496
497sub _draw {
498 my ($self) = @_;
499
500 glEnable GL_BLEND;
501 glEnable GL_TEXTURE_2D;
502 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;#DECAL;
503
504 my $l = 0;
505 for (@{$self->{txt_lines}}) {
506 $self->draw_line ($_, $l);
507 $l += $_->{height};
508 }
509
510 glDisable GL_BLEND;
511 glDisable GL_TEXTURE_2D;
400} 512}
401 513
402package Crossfire::Client::Widget::MapWidget; 514package Crossfire::Client::Widget::MapWidget;
403 515
404use strict; 516use strict;
430 542
431 my $sw = 1 + int $::WIDTH / 32; 543 my $sw = 1 + int $::WIDTH / 32;
432 my $sh = 1 + int $::HEIGHT / 32; 544 my $sh = 1 + int $::HEIGHT / 32;
433 545
434 if ($::CONN->{mapw} > $sw) { 546 if ($::CONN->{mapw} > $sw) {
435 $xofs = ($sw - $::CONN->{mapw}) * 0.5; 547 $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5;
436 } else { 548 } else {
437 $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs}; 549 $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs};
438 } 550 }
439 551
440 if ($::CONN->{maph} > $sh) { 552 if ($::CONN->{maph} > $sh) {
441 $yofs = ($sh - $::CONN->{maph}) * 0.5; 553 $yofs = $my + ($::CONN->{maph} - $sh) * 0.5;
442 } else { 554 } else {
443 $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs}; 555 $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs};
444 } 556 }
445 557
446 glEnable GL_TEXTURE_2D; 558 glEnable GL_TEXTURE_2D;
447 glEnable GL_BLEND; 559 glEnable GL_BLEND;
448 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 560 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
449
450 warn "<$mx,$my> <$xofs,$yofs>\n";#d#
451 561
452 for my $x (0 .. $sw - 1) { 562 for my $x (0 .. $sw - 1) {
453 for my $y (0 .. $sh - 1) { 563 for my $y (0 .. $sh - 1) {
454 564
455 my $cell = $map->[$x + $xofs][$y + $yofs] 565 my $cell = $map->[$x + $xofs][$y + $yofs]

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines