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.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;
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 width/height of texture
154
156 my $tex = $self->{texture} 155 my $tex = $self->{texture}
157 or return; 156 or return;
158 157
159 warn "DRAW TEX: $tex->{width} $tex->{height}\n";
160 glEnable GL_BLEND; 158 glEnable GL_BLEND;
161 glEnable GL_TEXTURE_2D; 159 glEnable GL_TEXTURE_2D;
162 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 160 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
163 glBindTexture GL_TEXTURE_2D, $tex->{name}; 161 glBindTexture GL_TEXTURE_2D, $tex->{name};
164 162
165 glColor 1, 1, 1; 163 glColor 1, 1, 1;
166 164
167 glBegin GL_QUADS; 165 glBegin GL_QUADS;
168 glTexCoord 0, 0; glVertex 0 , 0; 166 glTexCoord 0, 0; glVertex 0, 0;
169 glTexCoord 0, 1; glVertex 0 , $tex->{height}; 167 glTexCoord 0, 1; glVertex 0, $h;
170 glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height}; 168 glTexCoord 1, 1; glVertex $w, $h;
171 glTexCoord 1, 0; glVertex $tex->{width}, 0; 169 glTexCoord 1, 0; glVertex $w, 0;
172 glEnd; 170 glEnd;
173 171
174 glDisable GL_BLEND; 172 glDisable GL_BLEND;
175 glDisable GL_TEXTURE_2D; 173 glDisable GL_TEXTURE_2D;
176} 174}
190 188
191sub _draw { 189sub _draw {
192 my ($self) = @_; 190 my ($self) = @_;
193 191
194 my $chld = $self->get; 192 my $chld = $self->get;
193
194 $chld->move (2, 2, 0); #TODO:move to size_request
195 195
196 my ($w, $h) = $chld->size_request; 196 my ($w, $h) = $chld->size_request;
197 197
198 glColor 1, 0, 0; 198 glColor 1, 0, 0;
199 glBegin GL_QUADS; 199 glBegin GL_QUADS;
201 glTexCoord 0, 1; glVertex 0 , $h + 4; 201 glTexCoord 0, 1; glVertex 0 , $h + 4;
202 glTexCoord 1, 1; glVertex $w + 4 , $h + 4; 202 glTexCoord 1, 1; glVertex $w + 4 , $h + 4;
203 glTexCoord 1, 0; glVertex $w + 4 , 0; 203 glTexCoord 1, 0; glVertex $w + 4 , 0;
204 glEnd; 204 glEnd;
205 205
206 glPushMatrix;
207 glTranslate (2, 2, 0);
208 $chld->_draw; 206 $chld->draw;
209 glPopMatrix;
210} 207}
211 208
212package Crossfire::Client::Widget::Table; 209package Crossfire::Client::Widget::Table;
213 210
214our @ISA = Crossfire::Client::Widget::Container::; 211our @ISA = Crossfire::Client::Widget::Container::;
275 for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) { 272 for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) {
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;
281 glTranslate ($x, $y, 0);
282 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
283 $c->_draw if $c; 280 $c->draw if $c;
284 glPopMatrix; 281 }
285 282
286 $x += $self->max_col_width ($xi); 283 $x += $self->max_col_width ($xi);
287 } 284 }
288 285
289 $y += $self->max_row_height ($yi); 286 $y += $self->max_row_height ($yi);
317sub _draw { 314sub _draw {
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 $_->move (0, $y, 0); #TODO: move to size_request
323 glTranslate (0, $y, 0);
324 $_->_draw; 320 $_->draw;
325 glPopMatrix;
326 my ($w, $h) = $_->size_request; 321 my ($w, $h) = $_->size_request;
327 $y += $h; 322 $y += $h;
328 } 323 }
329} 324}
330 325
333our @ISA = Crossfire::Client::Widget::; 328our @ISA = Crossfire::Client::Widget::;
334 329
335use SDL::OpenGL; 330use SDL::OpenGL;
336 331
337sub new { 332sub new {
338 my ($class, $x, $y, $z, $ttf, $text) = @_; 333 my ($class, $x, $y, $z, $height, $text) = @_;
339 334
340 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);
341 336
342 $self->set_text ($text); 337 $self->set_text ($text);
343 338
344 $self 339 $self
345} 340}
346 341
347sub set_text { 342sub set_text {
348 my ($self, $text) = @_; 343 my ($self, $text) = @_;
344
345 $self->{text} = $text;
346
349 $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};
350} 348}
351 349
352sub get_text { 350sub get_text {
353 my ($self, $text) = @_; 351 my ($self, $text) = @_;
352
354 $self->{text} 353 $self->{text}
355} 354}
356 355
357sub size_request { 356sub size_request {
358 my ($self) = @_; 357 my ($self) = @_;
371 glEnable GL_BLEND; 370 glEnable GL_BLEND;
372 glEnable GL_TEXTURE_2D; 371 glEnable GL_TEXTURE_2D;
373 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 372 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
374 glBindTexture GL_TEXTURE_2D, $tex->{name}; 373 glBindTexture GL_TEXTURE_2D, $tex->{name};
375 374
376 glColor 1, 1, 1; 375 glColor 1, 1, 1, 0.8;
377 376
378 glBegin GL_QUADS; 377 glBegin GL_QUADS;
379 glTexCoord 0, 0; glVertex 0 , 0; 378 glTexCoord 0, 0; glVertex 0 , 0;
380 glTexCoord 0, 1; glVertex 0 , $tex->{height}; 379 glTexCoord 0, 1; glVertex 0 , $tex->{height};
381 glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height}; 380 glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height};
407 406
408package Crossfire::Client::Widget::MapWidget; 407package Crossfire::Client::Widget::MapWidget;
409 408
410use strict; 409use strict;
411 410
412our @ISA = qw/Crossfire::Client::Widget/; 411use List::Util qw(min max);
413 412
414use SDL; 413use SDL;
415use SDL::OpenGL; 414use SDL::OpenGL;
416use SDL::OpenGL::Constants; 415use SDL::OpenGL::Constants;
416
417our @ISA = Crossfire::Client::Widget::;
417 418
418sub key_down { 419sub key_down {
419 print "MAPKEYDOWN\n"; 420 print "MAPKEYDOWN\n";
420} 421}
421 422
422sub key_up { 423sub key_up {
423} 424}
424 425
425sub _draw { 426sub _draw {
426 my ($self) = @_; 427 my ($self) = @_;
428
429 my $mx = $::CONN->{mapx};
430 my $my = $::CONN->{mapy};
431
432 my $map = $::CONN->{map};
433
434 my ($xofs, $yofs);
435
436 my $sw = 1 + int $::WIDTH / 32;
437 my $sh = 1 + int $::HEIGHT / 32;
438
439 if ($::CONN->{mapw} > $sw) {
440 $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5;
441 } else {
442 $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs};
443 }
444
445 if ($::CONN->{maph} > $sh) {
446 $yofs = $my + ($::CONN->{maph} - $sh) * 0.5;
447 } else {
448 $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs};
449 }
427 450
428 glEnable GL_TEXTURE_2D; 451 glEnable GL_TEXTURE_2D;
429 glEnable GL_BLEND; 452 glEnable GL_BLEND;
430 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 453 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
431 454
432 my $map = $::CONN->{map}; 455 for my $x (0 .. $sw - 1) {
456 for my $y (0 .. $sh - 1) {
433 457
434 for my $x (0 .. int $::WIDTH / 32) { 458 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; 459 or next;
440 460
441 my $darkness = $cell->[0] * (1 / 255); 461 my $darkness = $cell->[0] * (1 / 255);
442 if ($darkness < 0) { 462 if ($darkness < 0) {
443 $darkness = 0.5; 463 glColor 0.3, 0.3, 0.3;
464 } else {
465 glColor $darkness, $darkness, $darkness;
444 } 466 }
445 glColor $darkness, $darkness, $darkness;
446 467
447 for my $num (grep $_, @$cell[1,2,3]) { 468 for my $num (grep $_, @$cell[1,2,3]) {
448 my $tex = $::CONN->{face}[$num]{texture} || next; 469 my $tex = $::CONN->{face}[$num]{texture} || next;
449 470
450 glBindTexture GL_TEXTURE_2D, $tex->{name}; 471 glBindTexture GL_TEXTURE_2D, $tex->{name};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines