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

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines