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.25 by root, Sat Apr 8 22:08:24 2006 UTC vs.
Revision 1.30 by root, Sun Apr 9 00:18:45 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;
148} 148}
149 149
150sub _draw { 150sub _draw {
151 my ($self) = @_; 151 my ($self) = @_;
152 152
153 my ($w, $h) = $self->size_request;#TODO# use widht/height of texture 153 my ($w, $h) = $self->size_request;#TODO# use width/height of texture
154
154 my $tex = $self->{texture} 155 my $tex = $self->{texture}
155 or return; 156 or return;
156 157
157 glEnable GL_BLEND; 158 glEnable GL_BLEND;
158 glEnable GL_TEXTURE_2D; 159 glEnable GL_TEXTURE_2D;
180 181
181sub size_request { 182sub size_request {
182 my ($self) = @_; 183 my ($self) = @_;
183 my $chld = $self->get 184 my $chld = $self->get
184 or return (0, 0); 185 or return (0, 0);
186
187 $chld->move (2, 2);
188
185 map { $_ + 4 } $chld->size_request; 189 map { $_ + 4 } $chld->size_request;
186} 190}
187 191
188sub _draw { 192sub _draw {
189 my ($self) = @_; 193 my ($self) = @_;
190 194
191 my $chld = $self->get; 195 my $chld = $self->get;
192 196
193 my ($w, $h) = $chld->size_request; 197 my ($w, $h) = $chld->size_request;
194 198
195 glColor 1, 0, 0;
196 glBegin GL_QUADS; 199 glBegin GL_QUADS;
200 glColor 0, 0, 0;
197 glTexCoord 0, 0; glVertex 0 , 0; 201 glTexCoord 0, 0; glVertex 0 , 0;
198 glTexCoord 0, 1; glVertex 0 , $h + 4; 202 glTexCoord 0, 1; glVertex 0 , $h + 4;
199 glTexCoord 1, 1; glVertex $w + 4 , $h + 4; 203 glTexCoord 1, 1; glVertex $w + 4 , $h + 4;
200 glTexCoord 1, 0; glVertex $w + 4 , 0; 204 glTexCoord 1, 0; glVertex $w + 4 , 0;
201 glEnd; 205 glEnd;
202 206
203 glPushMatrix;
204 glTranslate (2, 2, 0);
205 $chld->draw; 207 $chld->draw;
206 glPopMatrix;
207} 208}
208 209
209package Crossfire::Client::Widget::Table; 210package Crossfire::Client::Widget::Table;
210 211
211our @ISA = Crossfire::Client::Widget::Container::; 212our @ISA = Crossfire::Client::Widget::Container::;
272 for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) { 273 for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) {
273 my $x = 0; 274 my $x = 0;
274 275
275 for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) { 276 for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) {
276 277
277 glPushMatrix;
278 glTranslate ($x, $y, 0);#TODO#there must be no translate here, instead the widget must be moved
279 my $c = $self->{childs}->[$yi]->[$xi]; 278 my $c = $self->{childs}->[$yi]->[$xi];
279 if ($c) {
280 $c->move ($x, $y, 0); #TODO: Move to size_request
280 $c->draw if $c; 281 $c->draw if $c;
281 glPopMatrix; 282 }
282 283
283 $x += $self->max_col_width ($xi); 284 $x += $self->max_col_width ($xi);
284 } 285 }
285 286
286 $y += $self->max_row_height ($yi); 287 $y += $self->max_row_height ($yi);
314sub _draw { 315sub _draw {
315 my ($self) = @_; 316 my ($self) = @_;
316 317
317 my ($x, $y); 318 my ($x, $y);
318 for (@{$self->{childs} || []}) { 319 for (@{$self->{childs} || []}) {
319 glPushMatrix; 320 $_->move (0, $y, 0); #TODO: move to size_request
320 glTranslate (0, $y, 0);# see above TODO
321 $_->draw; 321 $_->draw;
322 glPopMatrix;
323 my ($w, $h) = $_->size_request; 322 my ($w, $h) = $_->size_request;
324 $y += $h; 323 $y += $h;
325 } 324 }
326} 325}
327 326
330our @ISA = Crossfire::Client::Widget::; 329our @ISA = Crossfire::Client::Widget::;
331 330
332use SDL::OpenGL; 331use SDL::OpenGL;
333 332
334sub new { 333sub new {
335 my ($class, $x, $y, $z, $ttf, $text) = @_; 334 my ($class, $x, $y, $z, $height, $text) = @_;
336 335
337 my $self = $class->SUPER::new (x => $x, y => $y, z => $z, ttf => $ttf); 336 my $self = $class->SUPER::new (x => $x, y => $y, z => $z, height => $height);
338 337
339 $self->set_text ($text); 338 $self->set_text ($text);
340 339
341 $self 340 $self
342} 341}
343 342
344sub set_text { 343sub set_text {
345 my ($self, $text) = @_; 344 my ($self, $text) = @_;
345
346 $self->{text} = $text;
347
346 $self->{texture} = new_from_ttf Crossfire::Client::Texture $self->{ttf}, $self->{text} = $text; 348 $self->{texture} = new_from_text Crossfire::Client::Texture $text, $self->{height};
347} 349}
348 350
349sub get_text { 351sub get_text {
350 my ($self, $text) = @_; 352 my ($self, $text) = @_;
353
351 $self->{text} 354 $self->{text}
352} 355}
353 356
354sub size_request { 357sub size_request {
355 my ($self) = @_; 358 my ($self) = @_;
365 368
366 my $tex = $self->{texture}; 369 my $tex = $self->{texture};
367 370
368 glEnable GL_BLEND; 371 glEnable GL_BLEND;
369 glEnable GL_TEXTURE_2D; 372 glEnable GL_TEXTURE_2D;
373 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
370 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 374 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
371 glBindTexture GL_TEXTURE_2D, $tex->{name}; 375 glBindTexture GL_TEXTURE_2D, $tex->{name};
372 376
373 glColor 1, 1, 1; 377 glColor 1, 1, 1, 0.8;
374 378
375 glBegin GL_QUADS; 379 glBegin GL_QUADS;
376 glTexCoord 0, 0; glVertex 0 , 0; 380 glTexCoord 0, 0; glVertex 0 , 0;
377 glTexCoord 0, 1; glVertex 0 , $tex->{height}; 381 glTexCoord 0, 1; glVertex 0 , $tex->{height};
378 glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height}; 382 glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height};
433 437
434 my $sw = 1 + int $::WIDTH / 32; 438 my $sw = 1 + int $::WIDTH / 32;
435 my $sh = 1 + int $::HEIGHT / 32; 439 my $sh = 1 + int $::HEIGHT / 32;
436 440
437 if ($::CONN->{mapw} > $sw) { 441 if ($::CONN->{mapw} > $sw) {
438 $xofs = ($sw - $::CONN->{mapw}) * 0.5; 442 $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5;
439 } else { 443 } else {
440 $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs}; 444 $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs};
441 } 445 }
442 446
443 if ($::CONN->{maph} > $sh) { 447 if ($::CONN->{maph} > $sh) {
444 $yofs = ($sh - $::CONN->{maph}) * 0.5; 448 $yofs = $my + ($::CONN->{maph} - $sh) * 0.5;
445 } else { 449 } else {
446 $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs}; 450 $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs};
447 } 451 }
448 452
449 glEnable GL_TEXTURE_2D; 453 glEnable GL_TEXTURE_2D;
450 glEnable GL_BLEND; 454 glEnable GL_BLEND;
451 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 455 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
452
453 warn "<$mx,$my> <$xofs,$yofs>\n";#d#
454 456
455 for my $x (0 .. $sw - 1) { 457 for my $x (0 .. $sw - 1) {
456 for my $y (0 .. $sh - 1) { 458 for my $y (0 .. $sh - 1) {
457 459
458 my $cell = $map->[$x + $xofs][$y + $yofs] 460 my $cell = $map->[$x + $xofs][$y + $yofs]

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines