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.21 by root, Sat Apr 8 18:15:59 2006 UTC vs.
Revision 1.27 by root, Sat Apr 8 22:25:37 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;
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}
190 187
191sub _draw { 188sub _draw {
192 my ($self) = @_; 189 my ($self) = @_;
193 190
194 my $chld = $self->get; 191 my $chld = $self->get;
192
193 $chld->move (2, 2, 0); #TODO:move to size_request
195 194
196 my ($w, $h) = $chld->size_request; 195 my ($w, $h) = $chld->size_request;
197 196
198 glColor 1, 0, 0; 197 glColor 1, 0, 0;
199 glBegin GL_QUADS; 198 glBegin GL_QUADS;
201 glTexCoord 0, 1; glVertex 0 , $h + 4; 200 glTexCoord 0, 1; glVertex 0 , $h + 4;
202 glTexCoord 1, 1; glVertex $w + 4 , $h + 4; 201 glTexCoord 1, 1; glVertex $w + 4 , $h + 4;
203 glTexCoord 1, 0; glVertex $w + 4 , 0; 202 glTexCoord 1, 0; glVertex $w + 4 , 0;
204 glEnd; 203 glEnd;
205 204
206 glPushMatrix;
207 glTranslate (2, 2, 0);
208 $chld->_draw; 205 $chld->draw;
209 glPopMatrix;
210} 206}
211 207
212package Crossfire::Client::Widget::Table; 208package Crossfire::Client::Widget::Table;
213 209
214our @ISA = Crossfire::Client::Widget::Container::; 210our @ISA = Crossfire::Client::Widget::Container::;
275 for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) { 271 for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) {
276 my $x = 0; 272 my $x = 0;
277 273
278 for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) { 274 for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) {
279 275
280 glPushMatrix;
281 glTranslate ($x, $y, 0);
282 my $c = $self->{childs}->[$yi]->[$xi]; 276 my $c = $self->{childs}->[$yi]->[$xi];
277 if ($c) {
278 $c->move ($x, $y, 0); #TODO: Move to size_request
283 $c->_draw if $c; 279 $c->draw if $c;
284 glPopMatrix; 280 }
285 281
286 $x += $self->max_col_width ($xi); 282 $x += $self->max_col_width ($xi);
287 } 283 }
288 284
289 $y += $self->max_row_height ($yi); 285 $y += $self->max_row_height ($yi);
317sub _draw { 313sub _draw {
318 my ($self) = @_; 314 my ($self) = @_;
319 315
320 my ($x, $y); 316 my ($x, $y);
321 for (@{$self->{childs} || []}) { 317 for (@{$self->{childs} || []}) {
322 glPushMatrix; 318 $_->move (0, $y, 0); #TODO: move to size_request
323 glTranslate (0, $y, 0);
324 $_->_draw; 319 $_->draw;
325 glPopMatrix;
326 my ($w, $h) = $_->size_request; 320 my ($w, $h) = $_->size_request;
327 $y += $h; 321 $y += $h;
328 } 322 }
329} 323}
330 324
368 362
369 my $tex = $self->{texture}; 363 my $tex = $self->{texture};
370 364
371 glEnable GL_BLEND; 365 glEnable GL_BLEND;
372 glEnable GL_TEXTURE_2D; 366 glEnable GL_TEXTURE_2D;
373 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 367 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;#DECAL;
374 glBindTexture GL_TEXTURE_2D, $tex->{name}; 368 glBindTexture GL_TEXTURE_2D, $tex->{name};
375 369
376 glColor 1, 1, 1; 370 glColor 1, 0, 1;
377 371
378 glBegin GL_QUADS; 372 glBegin GL_QUADS;
379 glTexCoord 0, 0; glVertex 0 , 0; 373 glTexCoord 0, 0; glVertex 0 , 0;
380 glTexCoord 0, 1; glVertex 0 , $tex->{height}; 374 glTexCoord 0, 1; glVertex 0 , $tex->{height};
381 glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height}; 375 glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height};
407 401
408package Crossfire::Client::Widget::MapWidget; 402package Crossfire::Client::Widget::MapWidget;
409 403
410use strict; 404use strict;
411 405
412our @ISA = qw/Crossfire::Client::Widget/; 406use List::Util qw(min max);
413 407
414use SDL; 408use SDL;
415use SDL::OpenGL; 409use SDL::OpenGL;
416use SDL::OpenGL::Constants; 410use SDL::OpenGL::Constants;
411
412our @ISA = Crossfire::Client::Widget::;
417 413
418sub key_down { 414sub key_down {
419 print "MAPKEYDOWN\n"; 415 print "MAPKEYDOWN\n";
420} 416}
421 417
422sub key_up { 418sub key_up {
423} 419}
424 420
425sub _draw { 421sub _draw {
426 my ($self) = @_; 422 my ($self) = @_;
423
424 my $mx = $::CONN->{mapx};
425 my $my = $::CONN->{mapy};
426
427 my $map = $::CONN->{map};
428
429 my ($xofs, $yofs);
430
431 my $sw = 1 + int $::WIDTH / 32;
432 my $sh = 1 + int $::HEIGHT / 32;
433
434 if ($::CONN->{mapw} > $sw) {
435 $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5;
436 } else {
437 $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs};
438 }
439
440 if ($::CONN->{maph} > $sh) {
441 $yofs = $my + ($::CONN->{maph} - $sh) * 0.5;
442 } else {
443 $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs};
444 }
427 445
428 glEnable GL_TEXTURE_2D; 446 glEnable GL_TEXTURE_2D;
429 glEnable GL_BLEND; 447 glEnable GL_BLEND;
430 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 448 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
431 449
432 my $map = $::CONN->{map}; 450 for my $x (0 .. $sw - 1) {
451 for my $y (0 .. $sh - 1) {
433 452
434 for my $x (0 .. int $::WIDTH / 32) { 453 my $cell = $map->[$x + $xofs][$y + $yofs]
435 for my $y (0 .. int $::HEIGHT / 32) {
436
437 my $cell = $map->[$x + $::CONN->{mapx}]
438 [$y + $::CONN->{mapy}]
439 or next; 454 or next;
440 455
441 my $darkness = $cell->[0] * (1 / 255); 456 my $darkness = $cell->[0] * (1 / 255);
442 if ($darkness < 0) { 457 if ($darkness < 0) {
443 $darkness = 0.5; 458 glColor 0.3, 0.3, 0.3;
459 } else {
460 glColor $darkness, $darkness, $darkness;
444 } 461 }
445 glColor $darkness, $darkness, $darkness;
446 462
447 for my $num (grep $_, @$cell[1,2,3]) { 463 for my $num (grep $_, @$cell[1,2,3]) {
448 my $tex = $::CONN->{face}[$num]{texture} || next; 464 my $tex = $::CONN->{face}[$num]{texture} || next;
449 465
450 glBindTexture GL_TEXTURE_2D, $tex->{name}; 466 glBindTexture GL_TEXTURE_2D, $tex->{name};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines