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.29 by root, Sun Apr 9 00:09:50 2006 UTC vs.
Revision 1.31 by elmex, Sun Apr 9 00:43:11 2006 UTC

158 glEnable GL_BLEND; 158 glEnable GL_BLEND;
159 glEnable GL_TEXTURE_2D; 159 glEnable GL_TEXTURE_2D;
160 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 160 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
161 glBindTexture GL_TEXTURE_2D, $tex->{name}; 161 glBindTexture GL_TEXTURE_2D, $tex->{name};
162 162
163 glColor 1, 1, 1; 163 glColor 1, 0, 1;
164 164
165 glBegin GL_QUADS; 165 glBegin GL_QUADS;
166 glTexCoord 0, 0; glVertex 0, 0; 166 glTexCoord 0, 0; glVertex 0, 0;
167 glTexCoord 0, 1; glVertex 0, $h; 167 glTexCoord 0, 1; glVertex 0, $h;
168 glTexCoord 1, 1; glVertex $w, $h; 168 glTexCoord 1, 1; glVertex $w, $h;
181 181
182sub size_request { 182sub size_request {
183 my ($self) = @_; 183 my ($self) = @_;
184 my $chld = $self->get 184 my $chld = $self->get
185 or return (0, 0); 185 or return (0, 0);
186
187 $chld->move (2, 2);
188
186 map { $_ + 4 } $chld->size_request; 189 map { $_ + 4 } $chld->size_request;
187} 190}
188 191
189sub _draw { 192sub _draw {
190 my ($self) = @_; 193 my ($self) = @_;
191 194
192 my $chld = $self->get; 195 my $chld = $self->get;
193 196
194 $chld->move (2, 2, 0); #TODO:move to size_request
195
196 my ($w, $h) = $chld->size_request; 197 my ($w, $h) = $chld->size_request;
197 198
198 glColor 1, 0, 0;
199 glBegin GL_QUADS; 199 glBegin GL_QUADS;
200 glColor 0, 0, 0;
200 glTexCoord 0, 0; glVertex 0 , 0; 201 glTexCoord 0, 0; glVertex 0 , 0;
201 glTexCoord 0, 1; glVertex 0 , $h + 4; 202 glTexCoord 0, 1; glVertex 0 , $h + 4;
202 glTexCoord 1, 1; glVertex $w + 4 , $h + 4; 203 glTexCoord 1, 1; glVertex $w + 4 , $h + 4;
203 glTexCoord 1, 0; glVertex $w + 4 , 0; 204 glTexCoord 1, 0; glVertex $w + 4 , 0;
204 glEnd; 205 glEnd;
205 206
206 $chld->draw; 207 $chld->draw;
207} 208}
209
210package Crossfire::Client::Widget::FancyFrame;
211
212our @ISA = Crossfire::Client::Widget::Frame::;
213
214use SDL::OpenGL;
215
216#TODO: implement themed frame
208 217
209package Crossfire::Client::Widget::Table; 218package Crossfire::Client::Widget::Table;
210 219
211our @ISA = Crossfire::Client::Widget::Container::; 220our @ISA = Crossfire::Client::Widget::Container::;
212 221
367 376
368 my $tex = $self->{texture}; 377 my $tex = $self->{texture};
369 378
370 glEnable GL_BLEND; 379 glEnable GL_BLEND;
371 glEnable GL_TEXTURE_2D; 380 glEnable GL_TEXTURE_2D;
381 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
372 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 382 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
373 glBindTexture GL_TEXTURE_2D, $tex->{name}; 383 glBindTexture GL_TEXTURE_2D, $tex->{name};
374 384
375 glColor 1, 1, 1, 0.8; 385 glColor 1, 1, 1, 0.8;
376 386
383 393
384 glDisable GL_BLEND; 394 glDisable GL_BLEND;
385 glDisable GL_TEXTURE_2D; 395 glDisable GL_TEXTURE_2D;
386} 396}
387 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
388package Crossfire::Client::Widget::TextView; 427package Crossfire::Client::Widget::TextView;
389 428
390use strict; 429use strict;
391 430
392our @ISA = qw/Crossfire::Client::Widget/; 431our @ISA = qw/Crossfire::Client::Widget/;
393 432
394use SDL::OpenGL; 433use SDL::OpenGL;
395use 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#}
396 459
397sub add_line { 460sub add_line {
398 my ($self, $line) = @_; 461 my ($self, $line) = @_;
399 push @{$self->{lines}}, $line; 462 push @{$self->{lines}}, $line;
400}
401 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
402sub _draw { 482sub draw_line {
403 my ($self) = @_; 483 my ($self, $tex, $y) = @_;
404 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;
405} 512}
406 513
407package Crossfire::Client::Widget::MapWidget; 514package Crossfire::Client::Widget::MapWidget;
408 515
409use strict; 516use strict;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines