… | |
… | |
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 | |
146 | sub size_request { |
143 | sub size_request { |
… | |
… | |
151 | } |
148 | } |
152 | |
149 | |
153 | sub _draw { |
150 | sub _draw { |
154 | my ($self) = @_; |
151 | my ($self) = @_; |
155 | |
152 | |
|
|
153 | my ($w, $h) = $self->size_request;#TODO# use widht/height of texture |
156 | my $tex = $self->{texture} |
154 | my $tex = $self->{texture} |
157 | or return; |
155 | or return; |
158 | |
156 | |
159 | warn "DRAW TEX: $tex->{width} $tex->{height}\n"; |
|
|
160 | glEnable GL_BLEND; |
157 | glEnable GL_BLEND; |
161 | glEnable GL_TEXTURE_2D; |
158 | glEnable GL_TEXTURE_2D; |
162 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
159 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
163 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
160 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
164 | |
161 | |
165 | glColor 1, 1, 1; |
162 | glColor 1, 1, 1; |
166 | |
163 | |
167 | glBegin GL_QUADS; |
164 | glBegin GL_QUADS; |
168 | glTexCoord 0, 0; glVertex 0 , 0; |
165 | glTexCoord 0, 0; glVertex 0, 0; |
169 | glTexCoord 0, 1; glVertex 0 , $tex->{height}; |
166 | glTexCoord 0, 1; glVertex 0, $h; |
170 | glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height}; |
167 | glTexCoord 1, 1; glVertex $w, $h; |
171 | glTexCoord 1, 0; glVertex $tex->{width}, 0; |
168 | glTexCoord 1, 0; glVertex $w, 0; |
172 | glEnd; |
169 | glEnd; |
173 | |
170 | |
174 | glDisable GL_BLEND; |
171 | glDisable GL_BLEND; |
175 | glDisable GL_TEXTURE_2D; |
172 | glDisable GL_TEXTURE_2D; |
176 | } |
173 | } |
… | |
… | |
203 | glTexCoord 1, 0; glVertex $w + 4 , 0; |
200 | glTexCoord 1, 0; glVertex $w + 4 , 0; |
204 | glEnd; |
201 | glEnd; |
205 | |
202 | |
206 | glPushMatrix; |
203 | glPushMatrix; |
207 | glTranslate (2, 2, 0); |
204 | glTranslate (2, 2, 0); |
208 | $chld->_draw; |
205 | $chld->draw; |
209 | glPopMatrix; |
206 | glPopMatrix; |
210 | } |
207 | } |
211 | |
208 | |
212 | package Crossfire::Client::Widget::Table; |
209 | package Crossfire::Client::Widget::Table; |
213 | |
210 | |
… | |
… | |
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; |
277 | glPushMatrix; |
281 | glTranslate ($x, $y, 0); |
278 | glTranslate ($x, $y, 0);#TODO#there must be no translate here, instead the widget must be moved |
282 | my $c = $self->{childs}->[$yi]->[$xi]; |
279 | my $c = $self->{childs}->[$yi]->[$xi]; |
283 | $c->_draw if $c; |
280 | $c->draw if $c; |
284 | glPopMatrix; |
281 | glPopMatrix; |
285 | |
282 | |
286 | $x += $self->max_col_width ($xi); |
283 | $x += $self->max_col_width ($xi); |
287 | } |
284 | } |
288 | |
285 | |
… | |
… | |
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 | glPushMatrix; |
323 | glTranslate (0, $y, 0); |
320 | glTranslate (0, $y, 0);# see above TODO |
324 | $_->_draw; |
321 | $_->draw; |
325 | glPopMatrix; |
322 | glPopMatrix; |
326 | my ($w, $h) = $_->size_request; |
323 | my ($w, $h) = $_->size_request; |
327 | $y += $h; |
324 | $y += $h; |
328 | } |
325 | } |
329 | } |
326 | } |
… | |
… | |
421 | |
418 | |
422 | sub key_up { |
419 | sub key_up { |
423 | } |
420 | } |
424 | |
421 | |
425 | sub _draw { |
422 | sub _draw { |
|
|
423 | my ($self) = @_; |
|
|
424 | |
426 | glEnable GL_TEXTURE_2D; |
425 | glEnable GL_TEXTURE_2D; |
427 | glEnable GL_BLEND; |
426 | glEnable GL_BLEND; |
428 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
427 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
429 | |
428 | |
430 | my $map = $::CONN->{map}; |
429 | my $map = $::CONN->{map}; |
431 | |
430 | |
432 | for my $x (0 .. $::CONN->{mapw} - 1) { |
431 | for my $x (0 .. int $::WIDTH / 32) { |
433 | for my $y (0 .. $::CONN->{maph} - 1) { |
432 | for my $y (0 .. int $::HEIGHT / 32) { |
434 | |
433 | |
435 | my $cell = $map->[$x][$y] |
434 | my $cell = $map->[$x + $::CONN->{mapx}] |
|
|
435 | [$y + $::CONN->{mapy}] |
436 | or next; |
436 | or next; |
437 | |
437 | |
438 | 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 { |
439 | glColor $darkness, $darkness, $darkness; |
442 | glColor $darkness, $darkness, $darkness; |
|
|
443 | } |
440 | |
444 | |
441 | for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) { |
445 | for my $num (grep $_, @$cell[1,2,3]) { |
442 | my $tex = $::CONN->{face}[$num]{texture} || next; |
446 | my $tex = $::CONN->{face}[$num]{texture} || next; |
443 | |
447 | |
444 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
448 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
445 | |
449 | |
446 | my $w = $tex->{width}; |
450 | my $w = $tex->{width}; |