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.20 by elmex, Sat Apr 8 17:21:01 2006 UTC vs.
Revision 1.25 by root, Sat Apr 8 22:08:24 2006 UTC

133 my $chld = $self->get; 133 my $chld = $self->get;
134 my ($w, $h) = $self->size_request; 134 my ($w, $h) = $self->size_request;
135 135
136 $self->{texture} = 136 $self->{texture} =
137 Crossfire::Client::Texture->new_from_opengl ( 137 Crossfire::Client::Texture->new_from_opengl (
138 $w, $h, sub { 138 $w, $h, sub { $chld->draw }
139 my ($txt, $w, $h) = @_;
140 $chld->_draw;
141 }
142 ); 139 );
143 $self->{texture}->upload; 140 $self->{texture}->upload;
144} 141}
145 142
146sub size_request { 143sub size_request {
151} 148}
152 149
153sub _draw { 150sub _draw {
154 my ($self) = @_; 151 my ($self) = @_;
155 152
153 my ($w, $h) = $self->size_request;#TODO# use widht/height of texture
156 my $tex = $self->{texture} 154 my $tex = $self->{texture}
157 or return; 155 or return;
158 156
159 warn "DRAW TEX: $tex->{width} $tex->{height}\n";
160 glEnable GL_BLEND; 157 glEnable GL_BLEND;
161 glEnable GL_TEXTURE_2D; 158 glEnable GL_TEXTURE_2D;
162 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 159 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
163 glBindTexture GL_TEXTURE_2D, $tex->{name}; 160 glBindTexture GL_TEXTURE_2D, $tex->{name};
164 161
165 glColor 1, 1, 1; 162 glColor 1, 1, 1;
166 163
167 glBegin GL_QUADS; 164 glBegin GL_QUADS;
168 glTexCoord 0, 0; glVertex 0 , 0; 165 glTexCoord 0, 0; glVertex 0, 0;
169 glTexCoord 0, 1; glVertex 0 , $tex->{height}; 166 glTexCoord 0, 1; glVertex 0, $h;
170 glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height}; 167 glTexCoord 1, 1; glVertex $w, $h;
171 glTexCoord 1, 0; glVertex $tex->{width}, 0; 168 glTexCoord 1, 0; glVertex $w, 0;
172 glEnd; 169 glEnd;
173 170
174 glDisable GL_BLEND; 171 glDisable GL_BLEND;
175 glDisable GL_TEXTURE_2D; 172 glDisable GL_TEXTURE_2D;
176} 173}
203 glTexCoord 1, 0; glVertex $w + 4 , 0; 200 glTexCoord 1, 0; glVertex $w + 4 , 0;
204 glEnd; 201 glEnd;
205 202
206 glPushMatrix; 203 glPushMatrix;
207 glTranslate (2, 2, 0); 204 glTranslate (2, 2, 0);
208 $chld->_draw; 205 $chld->draw;
209 glPopMatrix; 206 glPopMatrix;
210} 207}
211 208
212package Crossfire::Client::Widget::Table; 209package Crossfire::Client::Widget::Table;
213 210
276 my $x = 0; 273 my $x = 0;
277 274
278 for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) { 275 for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) {
279 276
280 glPushMatrix; 277 glPushMatrix;
281 glTranslate ($x, $y, 0); 278 glTranslate ($x, $y, 0);#TODO#there must be no translate here, instead the widget must be moved
282 my $c = $self->{childs}->[$yi]->[$xi]; 279 my $c = $self->{childs}->[$yi]->[$xi];
283 $c->_draw if $c; 280 $c->draw if $c;
284 glPopMatrix; 281 glPopMatrix;
285 282
286 $x += $self->max_col_width ($xi); 283 $x += $self->max_col_width ($xi);
287 } 284 }
288 285
318 my ($self) = @_; 315 my ($self) = @_;
319 316
320 my ($x, $y); 317 my ($x, $y);
321 for (@{$self->{childs} || []}) { 318 for (@{$self->{childs} || []}) {
322 glPushMatrix; 319 glPushMatrix;
323 glTranslate (0, $y, 0); 320 glTranslate (0, $y, 0);# see above TODO
324 $_->_draw; 321 $_->draw;
325 glPopMatrix; 322 glPopMatrix;
326 my ($w, $h) = $_->size_request; 323 my ($w, $h) = $_->size_request;
327 $y += $h; 324 $y += $h;
328 } 325 }
329} 326}
407 404
408package Crossfire::Client::Widget::MapWidget; 405package Crossfire::Client::Widget::MapWidget;
409 406
410use strict; 407use strict;
411 408
412our @ISA = qw/Crossfire::Client::Widget/; 409use List::Util qw(min max);
413 410
414use SDL; 411use SDL;
415use SDL::OpenGL; 412use SDL::OpenGL;
416use SDL::OpenGL::Constants; 413use SDL::OpenGL::Constants;
414
415our @ISA = Crossfire::Client::Widget::;
417 416
418sub key_down { 417sub key_down {
419 print "MAPKEYDOWN\n"; 418 print "MAPKEYDOWN\n";
420} 419}
421 420
422sub key_up { 421sub key_up {
423} 422}
424 423
425sub _draw { 424sub _draw {
425 my ($self) = @_;
426
427 my $mx = $::CONN->{mapx};
428 my $my = $::CONN->{mapy};
429
430 my $map = $::CONN->{map};
431
432 my ($xofs, $yofs);
433
434 my $sw = 1 + int $::WIDTH / 32;
435 my $sh = 1 + int $::HEIGHT / 32;
436
437 if ($::CONN->{mapw} > $sw) {
438 $xofs = ($sw - $::CONN->{mapw}) * 0.5;
439 } else {
440 $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs};
441 }
442
443 if ($::CONN->{maph} > $sh) {
444 $yofs = ($sh - $::CONN->{maph}) * 0.5;
445 } else {
446 $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs};
447 }
448
426 glEnable GL_TEXTURE_2D; 449 glEnable GL_TEXTURE_2D;
427 glEnable GL_BLEND; 450 glEnable GL_BLEND;
428 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 451 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
429 452
430 my $map = $::CONN->{map}; 453 warn "<$mx,$my> <$xofs,$yofs>\n";#d#
431 454
432 for my $x (0 .. $::CONN->{mapw} - 1) { 455 for my $x (0 .. $sw - 1) {
433 for my $y (0 .. $::CONN->{maph} - 1) { 456 for my $y (0 .. $sh - 1) {
434 457
435 my $cell = $map->[$x][$y] 458 my $cell = $map->[$x + $xofs][$y + $yofs]
436 or next; 459 or next;
437 460
438 my $darkness = $cell->[3] * (1 / 255); 461 my $darkness = $cell->[0] * (1 / 255);
462 if ($darkness < 0) {
463 glColor 0.3, 0.3, 0.3;
464 } else {
439 glColor $darkness, $darkness, $darkness; 465 glColor $darkness, $darkness, $darkness;
466 }
440 467
441 for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) { 468 for my $num (grep $_, @$cell[1,2,3]) {
442 my $tex = $::CONN->{face}[$num]{texture} || next; 469 my $tex = $::CONN->{face}[$num]{texture} || next;
443 470
444 glBindTexture GL_TEXTURE_2D, $tex->{name}; 471 glBindTexture GL_TEXTURE_2D, $tex->{name};
445 472
446 my $w = $tex->{width}; 473 my $w = $tex->{width};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines