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.25 by root, Sat Apr 8 22:08:24 2006 UTC vs.
Revision 1.29 by root, Sun Apr 9 00:09:50 2006 UTC

123use SDL::OpenGL; 123use SDL::OpenGL;
124 124
125sub add { 125sub add {
126 my ($self, $chld) = @_; 126 my ($self, $chld) = @_;
127 $self->SUPER::add ($chld); 127 $self->SUPER::add ($chld);
128 $self->render_chld; 128 $self->render_chld; #TODO: Move this to the size_request event propably?
129} 129}
130 130
131sub render_chld { 131sub render_chld {
132 my ($self) = @_; 132 my ($self) = @_;
133 my $chld = $self->get; 133 my $chld = $self->get;
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;
187 188
188sub _draw { 189sub _draw {
189 my ($self) = @_; 190 my ($self) = @_;
190 191
191 my $chld = $self->get; 192 my $chld = $self->get;
193
194 $chld->move (2, 2, 0); #TODO:move to size_request
192 195
193 my ($w, $h) = $chld->size_request; 196 my ($w, $h) = $chld->size_request;
194 197
195 glColor 1, 0, 0; 198 glColor 1, 0, 0;
196 glBegin GL_QUADS; 199 glBegin GL_QUADS;
198 glTexCoord 0, 1; glVertex 0 , $h + 4; 201 glTexCoord 0, 1; glVertex 0 , $h + 4;
199 glTexCoord 1, 1; glVertex $w + 4 , $h + 4; 202 glTexCoord 1, 1; glVertex $w + 4 , $h + 4;
200 glTexCoord 1, 0; glVertex $w + 4 , 0; 203 glTexCoord 1, 0; glVertex $w + 4 , 0;
201 glEnd; 204 glEnd;
202 205
203 glPushMatrix;
204 glTranslate (2, 2, 0);
205 $chld->draw; 206 $chld->draw;
206 glPopMatrix;
207} 207}
208 208
209package Crossfire::Client::Widget::Table; 209package Crossfire::Client::Widget::Table;
210 210
211our @ISA = Crossfire::Client::Widget::Container::; 211our @ISA = Crossfire::Client::Widget::Container::;
272 for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) { 272 for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) {
273 my $x = 0; 273 my $x = 0;
274 274
275 for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) { 275 for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) {
276 276
277 glPushMatrix;
278 glTranslate ($x, $y, 0);#TODO#there must be no translate here, instead the widget must be moved
279 my $c = $self->{childs}->[$yi]->[$xi]; 277 my $c = $self->{childs}->[$yi]->[$xi];
278 if ($c) {
279 $c->move ($x, $y, 0); #TODO: Move to size_request
280 $c->draw if $c; 280 $c->draw if $c;
281 glPopMatrix; 281 }
282 282
283 $x += $self->max_col_width ($xi); 283 $x += $self->max_col_width ($xi);
284 } 284 }
285 285
286 $y += $self->max_row_height ($yi); 286 $y += $self->max_row_height ($yi);
314sub _draw { 314sub _draw {
315 my ($self) = @_; 315 my ($self) = @_;
316 316
317 my ($x, $y); 317 my ($x, $y);
318 for (@{$self->{childs} || []}) { 318 for (@{$self->{childs} || []}) {
319 glPushMatrix; 319 $_->move (0, $y, 0); #TODO: move to size_request
320 glTranslate (0, $y, 0);# see above TODO
321 $_->draw; 320 $_->draw;
322 glPopMatrix;
323 my ($w, $h) = $_->size_request; 321 my ($w, $h) = $_->size_request;
324 $y += $h; 322 $y += $h;
325 } 323 }
326} 324}
327 325
330our @ISA = Crossfire::Client::Widget::; 328our @ISA = Crossfire::Client::Widget::;
331 329
332use SDL::OpenGL; 330use SDL::OpenGL;
333 331
334sub new { 332sub new {
335 my ($class, $x, $y, $z, $ttf, $text) = @_; 333 my ($class, $x, $y, $z, $height, $text) = @_;
336 334
337 my $self = $class->SUPER::new (x => $x, y => $y, z => $z, ttf => $ttf); 335 my $self = $class->SUPER::new (x => $x, y => $y, z => $z, height => $height);
338 336
339 $self->set_text ($text); 337 $self->set_text ($text);
340 338
341 $self 339 $self
342} 340}
343 341
344sub set_text { 342sub set_text {
345 my ($self, $text) = @_; 343 my ($self, $text) = @_;
344
345 $self->{text} = $text;
346
346 $self->{texture} = new_from_ttf Crossfire::Client::Texture $self->{ttf}, $self->{text} = $text; 347 $self->{texture} = new_from_text Crossfire::Client::Texture $text, $self->{height};
347} 348}
348 349
349sub get_text { 350sub get_text {
350 my ($self, $text) = @_; 351 my ($self, $text) = @_;
352
351 $self->{text} 353 $self->{text}
352} 354}
353 355
354sub size_request { 356sub size_request {
355 my ($self) = @_; 357 my ($self) = @_;
368 glEnable GL_BLEND; 370 glEnable GL_BLEND;
369 glEnable GL_TEXTURE_2D; 371 glEnable GL_TEXTURE_2D;
370 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 372 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
371 glBindTexture GL_TEXTURE_2D, $tex->{name}; 373 glBindTexture GL_TEXTURE_2D, $tex->{name};
372 374
373 glColor 1, 1, 1; 375 glColor 1, 1, 1, 0.8;
374 376
375 glBegin GL_QUADS; 377 glBegin GL_QUADS;
376 glTexCoord 0, 0; glVertex 0 , 0; 378 glTexCoord 0, 0; glVertex 0 , 0;
377 glTexCoord 0, 1; glVertex 0 , $tex->{height}; 379 glTexCoord 0, 1; glVertex 0 , $tex->{height};
378 glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height}; 380 glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height};
433 435
434 my $sw = 1 + int $::WIDTH / 32; 436 my $sw = 1 + int $::WIDTH / 32;
435 my $sh = 1 + int $::HEIGHT / 32; 437 my $sh = 1 + int $::HEIGHT / 32;
436 438
437 if ($::CONN->{mapw} > $sw) { 439 if ($::CONN->{mapw} > $sw) {
438 $xofs = ($sw - $::CONN->{mapw}) * 0.5; 440 $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5;
439 } else { 441 } else {
440 $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs}; 442 $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs};
441 } 443 }
442 444
443 if ($::CONN->{maph} > $sh) { 445 if ($::CONN->{maph} > $sh) {
444 $yofs = ($sh - $::CONN->{maph}) * 0.5; 446 $yofs = $my + ($::CONN->{maph} - $sh) * 0.5;
445 } else { 447 } else {
446 $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs}; 448 $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs};
447 } 449 }
448 450
449 glEnable GL_TEXTURE_2D; 451 glEnable GL_TEXTURE_2D;
450 glEnable GL_BLEND; 452 glEnable GL_BLEND;
451 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 453 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
452
453 warn "<$mx,$my> <$xofs,$yofs>\n";#d#
454 454
455 for my $x (0 .. $sw - 1) { 455 for my $x (0 .. $sw - 1) {
456 for my $y (0 .. $sh - 1) { 456 for my $y (0 .. $sh - 1) {
457 457
458 my $cell = $map->[$x + $xofs][$y + $yofs] 458 my $cell = $map->[$x + $xofs][$y + $yofs]

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines