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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines