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