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.18 by root, Sat Apr 8 13:36:26 2006 UTC vs.
Revision 1.24 by root, Sat Apr 8 20:25:26 2006 UTC

39 $self->{x} = $x; 39 $self->{x} = $x;
40 $self->{y} = $y; 40 $self->{y} = $y;
41 $self->{z} = $z if defined $z; 41 $self->{z} = $z if defined $z;
42} 42}
43 43
44sub needs_redraw {
45 0
46}
47
44sub size_request { 48sub size_request {
45 die "size_request is abtract"; 49 die "size_request is abtract";
46} 50}
47 51
48sub focus_in { 52sub focus_in {
109sub get { $_[0]->{child} } 113sub get { $_[0]->{child} }
110 114
111sub size_request { $_[0]->{child}->size_request if $_[0]->{child} } 115sub size_request { $_[0]->{child}->size_request if $_[0]->{child} }
112 116
113sub _draw { die "Containers can't be drawn!" } 117sub _draw { die "Containers can't be drawn!" }
118
119package Crossfire::Client::Widget::Window;
120
121our @ISA = Crossfire::Client::Widget::Container::;
122
123use SDL::OpenGL;
124
125sub add {
126 my ($self, $chld) = @_;
127 $self->SUPER::add ($chld);
128 $self->render_chld;
129}
130
131sub render_chld {
132 my ($self) = @_;
133 my $chld = $self->get;
134 my ($w, $h) = $self->size_request;
135
136 $self->{texture} =
137 Crossfire::Client::Texture->new_from_opengl (
138 $w, $h, sub { $chld->draw }
139 );
140 $self->{texture}->upload;
141}
142
143sub size_request {
144 my ($self) = @_;
145 my $chld = $self->get
146 or return (0, 0);
147 $chld->size_request
148}
149
150sub _draw {
151 my ($self) = @_;
152
153 my ($w, $h) = $self->size_request;#TODO# use widht/height of texture
154 my $tex = $self->{texture}
155 or return;
156
157 glEnable GL_BLEND;
158 glEnable GL_TEXTURE_2D;
159 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
160 glBindTexture GL_TEXTURE_2D, $tex->{name};
161
162 glColor 1, 1, 1;
163
164 glBegin GL_QUADS;
165 glTexCoord 0, 0; glVertex 0, 0;
166 glTexCoord 0, 1; glVertex 0, $h;
167 glTexCoord 1, 1; glVertex $w, $h;
168 glTexCoord 1, 0; glVertex $w, 0;
169 glEnd;
170
171 glDisable GL_BLEND;
172 glDisable GL_TEXTURE_2D;
173}
114 174
115package Crossfire::Client::Widget::Frame; 175package Crossfire::Client::Widget::Frame;
116 176
117our @ISA = Crossfire::Client::Widget::Container::; 177our @ISA = Crossfire::Client::Widget::Container::;
118 178
140 glTexCoord 1, 0; glVertex $w + 4 , 0; 200 glTexCoord 1, 0; glVertex $w + 4 , 0;
141 glEnd; 201 glEnd;
142 202
143 glPushMatrix; 203 glPushMatrix;
144 glTranslate (2, 2, 0); 204 glTranslate (2, 2, 0);
145 $chld->_draw; 205 $chld->draw;
146 glPopMatrix; 206 glPopMatrix;
147} 207}
148 208
149package Crossfire::Client::Widget::Table; 209package Crossfire::Client::Widget::Table;
150 210
213 my $x = 0; 273 my $x = 0;
214 274
215 for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) { 275 for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) {
216 276
217 glPushMatrix; 277 glPushMatrix;
218 glTranslate ($x, $y, 0); 278 glTranslate ($x, $y, 0);#TODO#there must be no translate here, instead the widget must be moved
219 my $c = $self->{childs}->[$yi]->[$xi]; 279 my $c = $self->{childs}->[$yi]->[$xi];
220 $c->_draw if $c; 280 $c->draw if $c;
221 glPopMatrix; 281 glPopMatrix;
222 282
223 $x += $self->max_col_width ($xi); 283 $x += $self->max_col_width ($xi);
224 } 284 }
225 285
255 my ($self) = @_; 315 my ($self) = @_;
256 316
257 my ($x, $y); 317 my ($x, $y);
258 for (@{$self->{childs} || []}) { 318 for (@{$self->{childs} || []}) {
259 glPushMatrix; 319 glPushMatrix;
260 glTranslate (0, $y, 0); 320 glTranslate (0, $y, 0);# see above TODO
261 $_->_draw; 321 $_->draw;
262 glPopMatrix; 322 glPopMatrix;
263 my ($w, $h) = $_->size_request; 323 my ($w, $h) = $_->size_request;
264 $y += $h; 324 $y += $h;
265 } 325 }
266} 326}
358 418
359sub key_up { 419sub key_up {
360} 420}
361 421
362sub _draw { 422sub _draw {
423 my ($self) = @_;
424
363 glEnable GL_TEXTURE_2D; 425 glEnable GL_TEXTURE_2D;
364 glEnable GL_BLEND; 426 glEnable GL_BLEND;
365 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 427 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
366 428
367 my $map = $::CONN->{map}; 429 my $map = $::CONN->{map};
368 430
369 for my $x (0 .. $::CONN->{mapw} - 1) { 431 for my $x (0 .. int $::WIDTH / 32) {
370 for my $y (0 .. $::CONN->{maph} - 1) { 432 for my $y (0 .. int $::HEIGHT / 32) {
371 433
372 my $cell = $map->[$x][$y] 434 my $cell = $map->[$x + $::CONN->{mapx}]
435 [$y + $::CONN->{mapy}]
373 or next; 436 or next;
374 437
375 my $darkness = $cell->[3] * (1 / 255); 438 my $darkness = $cell->[0] * (1 / 255);
439 if ($darkness < 0) {
440 glColor 0.3, 0.3, 0.3;
441 } else {
376 glColor $darkness, $darkness, $darkness; 442 glColor $darkness, $darkness, $darkness;
443 }
377 444
378 for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) { 445 for my $num (grep $_, @$cell[1,2,3]) {
379 my $tex = $::CONN->{face}[$num]{texture} || next; 446 my $tex = $::CONN->{face}[$num]{texture} || next;
380 447
381 glBindTexture GL_TEXTURE_2D, $tex->{name}; 448 glBindTexture GL_TEXTURE_2D, $tex->{name};
382 449
450 my $w = $tex->{width};
451 my $h = $tex->{height};
452
453 my $px = ($x + 1) * 32 - $w;
454 my $py = ($y + 1) * 32 - $h;
455
383 glBegin GL_QUADS; 456 glBegin GL_QUADS;
384 glTexCoord 0, 0; glVertex $x * 32 , $y * 32; 457 glTexCoord 0, 0; glVertex $px , $py;
385 glTexCoord 0, 1; glVertex $x * 32 , $y * 32 + 32; 458 glTexCoord 0, 1; glVertex $px , $py + $h;
386 glTexCoord 1, 1; glVertex $x * 32 + 32, $y * 32 + 32; 459 glTexCoord 1, 1; glVertex $px + $w, $py + $h;
387 glTexCoord 1, 0; glVertex $x * 32 + 32, $y * 32; 460 glTexCoord 1, 0; glVertex $px + $w, $py;
388 glEnd; 461 glEnd;
389 } 462 }
390 } 463 }
391 } 464 }
392 465

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines