… | |
… | |
4 | |
4 | |
5 | use Scalar::Util; |
5 | use Scalar::Util; |
6 | |
6 | |
7 | use SDL::OpenGL; |
7 | use SDL::OpenGL; |
8 | use SDL::OpenGL::Constants; |
8 | use SDL::OpenGL::Constants; |
|
|
9 | |
|
|
10 | use Crossfire::Client; |
9 | |
11 | |
10 | our $FOCUS; # the widget with current focus |
12 | our $FOCUS; # the widget with current focus |
11 | |
13 | |
12 | # class methods for events |
14 | # class methods for events |
13 | sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS } |
15 | sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS } |
… | |
… | |
37 | Carp::confess "size_request is abtract"; |
39 | Carp::confess "size_request is abtract"; |
38 | } |
40 | } |
39 | |
41 | |
40 | sub size_allocate { |
42 | sub size_allocate { |
41 | my ($self, $w, $h) = @_; |
43 | my ($self, $w, $h) = @_; |
|
|
44 | |
42 | $self->w ($w); |
45 | $self->{w} = $w; |
43 | $self->h ($h); |
46 | $self->{h} = $h; |
44 | } |
47 | } |
45 | |
48 | |
46 | sub focus_in { |
49 | sub focus_in { |
47 | my ($widget) = @_; |
50 | my ($widget) = @_; |
48 | $FOCUS = $widget; |
51 | $FOCUS = $widget; |
… | |
… | |
82 | $self->_draw; |
85 | $self->_draw; |
83 | glPopMatrix; |
86 | glPopMatrix; |
84 | } |
87 | } |
85 | |
88 | |
86 | sub _draw { |
89 | sub _draw { |
87 | my ($widget) = @_; |
90 | my ($self) = @_; |
|
|
91 | |
|
|
92 | warn "no draw defined for $self\n"; |
88 | } |
93 | } |
89 | |
94 | |
90 | sub bbox { |
95 | sub bbox { |
91 | my ($self) = @_; |
96 | my ($self) = @_; |
92 | my ($w, $h) = $self->size_request; |
97 | my ($w, $h) = $self->size_request; |
… | |
… | |
96 | $self->{x} = $w, |
101 | $self->{x} = $w, |
97 | $self->{y} = $h |
102 | $self->{y} = $h |
98 | ) |
103 | ) |
99 | } |
104 | } |
100 | |
105 | |
|
|
106 | sub find_widget { |
|
|
107 | my ($self, $x, $y) = @_; |
|
|
108 | |
|
|
109 | return $self |
|
|
110 | if $x >= $self->{x} && $x < $self->{x} + $self->{w} |
|
|
111 | && $y >= $self->{y} && $y < $self->{y} + $self->{h}; |
|
|
112 | |
|
|
113 | () |
|
|
114 | } |
|
|
115 | |
101 | sub del_parent { $_[0]->{parent} = undef } |
116 | sub del_parent { $_[0]->{parent} = undef } |
102 | |
117 | |
103 | sub set_parent { |
118 | sub set_parent { |
104 | my ($self, $par) = @_; |
119 | my ($self, $par) = @_; |
105 | |
120 | |
… | |
… | |
122 | my ($self) = @_; |
137 | my ($self) = @_; |
123 | |
138 | |
124 | #$self->deactivate; |
139 | #$self->deactivate; |
125 | } |
140 | } |
126 | |
141 | |
|
|
142 | ############################################################################# |
|
|
143 | |
|
|
144 | package Crossfire::Client::Widget::Container; |
|
|
145 | |
|
|
146 | our @ISA = Crossfire::Client::Widget::; |
|
|
147 | |
|
|
148 | sub new { |
|
|
149 | my ($class, @widgets) = @_; |
|
|
150 | |
|
|
151 | my $self = $class->SUPER::new (children => []); |
|
|
152 | $self->add ($_) for @widgets; |
|
|
153 | |
|
|
154 | $self |
|
|
155 | } |
|
|
156 | |
|
|
157 | sub add { |
|
|
158 | my ($self, $chld, $expand) = @_; |
|
|
159 | |
|
|
160 | $chld->{expand} = $expand; |
|
|
161 | $chld->set_parent ($self); |
|
|
162 | |
|
|
163 | @{$self->{children}} = |
|
|
164 | sort { $a->{z} <=> $b->{z} } |
|
|
165 | @{$self->{children}}, $chld; |
|
|
166 | |
|
|
167 | $self->size_allocate ($self->{w}, $self->{h}); |
|
|
168 | } |
|
|
169 | |
|
|
170 | sub remove { |
|
|
171 | my ($self, $widget) = @_; |
|
|
172 | |
|
|
173 | $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; |
|
|
174 | |
|
|
175 | $self->size_allocate ($self->{w}, $self->{h}); |
|
|
176 | } |
|
|
177 | |
|
|
178 | sub find_widget { |
|
|
179 | my ($self, $x, $y) = @_; |
|
|
180 | |
|
|
181 | my $res; |
|
|
182 | |
|
|
183 | for (@{ $self->{children} }) { |
|
|
184 | $res = $_->find_widget ($x, $y) |
|
|
185 | and return $res; |
|
|
186 | } |
|
|
187 | |
|
|
188 | () |
|
|
189 | } |
|
|
190 | |
|
|
191 | sub size_request { |
|
|
192 | my ($self) = @_; |
|
|
193 | |
|
|
194 | my ($hs, $ws) = (0, 0); |
|
|
195 | for (@{$self->{children} || []}) { |
|
|
196 | my ($w, $h) = $_->size_request; |
|
|
197 | $hs += $h; |
|
|
198 | if ($ws < $w) { $ws = $w } |
|
|
199 | } |
|
|
200 | |
|
|
201 | return ($ws, $hs); |
|
|
202 | } |
|
|
203 | |
|
|
204 | sub _draw { |
|
|
205 | my ($self) = @_; |
|
|
206 | |
|
|
207 | $_->draw for @{$self->{children}}; |
|
|
208 | } |
|
|
209 | |
|
|
210 | ############################################################################# |
|
|
211 | |
127 | package Crossfire::Client::Widget::Bin; |
212 | package Crossfire::Client::Widget::Bin; |
128 | |
213 | |
129 | our @ISA = Crossfire::Client::Widget::; |
214 | our @ISA = Crossfire::Client::Widget::Container::; |
130 | |
215 | |
131 | sub add { $_[0]->{child} = $_[1]; $_[1]->set_parent ($_[0]); $_[1]->{expand} = $_[2] } |
|
|
132 | sub get { $_[0]->{child} } |
216 | sub child { $_[0]->{children}[0] } |
133 | |
|
|
134 | sub remove { |
|
|
135 | my ($self, $chld) = @_; |
|
|
136 | delete $self->{child} |
|
|
137 | if $self->{child} == $chld; |
|
|
138 | } |
|
|
139 | |
217 | |
140 | sub size_request { |
218 | sub size_request { |
141 | $_[0]->{child}->size_request if $_[0]->{child} |
219 | $_[0]{children}[0]->size_request if $_[0]{children}[0]; |
142 | } |
220 | } |
|
|
221 | |
143 | sub size_allocate { |
222 | sub size_allocate { |
144 | my ($self, $w, $h) = @_; |
223 | my ($self, $w, $h) = @_; |
|
|
224 | |
145 | $self->SUPER::size_allocate ($w, $h); |
225 | $self->SUPER::size_allocate ($w, $h); |
146 | $self->{child}->size_allocate ($w, $h) |
226 | $self->{children}[0]->size_allocate ($w, $h) |
147 | if $self->{child} |
227 | if $self->{children}[0] |
148 | } |
228 | } |
149 | |
229 | |
150 | sub _draw { |
230 | ############################################################################# |
151 | my ($self) = @_; |
|
|
152 | |
|
|
153 | $self->{child}->draw; |
|
|
154 | } |
|
|
155 | |
231 | |
156 | package Crossfire::Client::Widget::Toplevel; |
232 | package Crossfire::Client::Widget::Toplevel; |
157 | |
233 | |
|
|
234 | our @ISA = Crossfire::Client::Widget::Container::; |
|
|
235 | |
|
|
236 | sub update { |
|
|
237 | my ($self) = @_; |
|
|
238 | |
|
|
239 | ::refresh (); |
|
|
240 | } |
|
|
241 | |
|
|
242 | sub add { |
|
|
243 | my ($self, $widget) = @_; |
|
|
244 | |
|
|
245 | $self->SUPER::add ($widget); |
|
|
246 | |
|
|
247 | $widget->size_allocate ($widget->size_request); |
|
|
248 | } |
|
|
249 | |
|
|
250 | ############################################################################# |
|
|
251 | |
|
|
252 | package Crossfire::Client::Widget::Window; |
|
|
253 | |
158 | our @ISA = Crossfire::Client::Widget::; |
254 | our @ISA = Crossfire::Client::Widget::Bin::; |
159 | |
255 | |
160 | use SDL::OpenGL; |
256 | use SDL::OpenGL; |
161 | |
257 | |
162 | sub add { |
258 | sub new { |
163 | my ($self, $chld) = @_; |
259 | my ($class, $x, $y, $z, $w, $h) = @_; |
164 | |
260 | |
165 | push @{$self->{childs}}, $chld; |
261 | my $self = $class->SUPER::new; |
166 | @{$self->{childs}} = |
|
|
167 | sort { $a->{z} <=> $b->{z} } |
|
|
168 | @{$self->{childs}}; |
|
|
169 | |
262 | |
170 | $chld->set_parent ($self); |
263 | @$self{qw(x y z w h)} = ($x, $y, $z, $w, $h); |
171 | $chld->size_allocate ($chld->size_request); |
|
|
172 | } |
|
|
173 | |
|
|
174 | sub remove { |
|
|
175 | my ($self, $chld) = @_; |
|
|
176 | @{$self->{childs}} = |
|
|
177 | sort { $a->{z} <=> $b->{z} } |
|
|
178 | grep { $_ && $_ != $_[0] } |
|
|
179 | @{$self->{childs}} |
|
|
180 | } |
264 | } |
181 | |
265 | |
182 | sub update { |
266 | sub update { |
183 | my ($self) = @_; |
267 | my ($self) = @_; |
184 | ::refresh (); |
|
|
185 | } |
|
|
186 | |
268 | |
187 | sub _draw { |
|
|
188 | my ($self) = @_; |
|
|
189 | |
|
|
190 | $_->draw for @{$self->{childs}}; |
|
|
191 | } |
|
|
192 | |
|
|
193 | package Crossfire::Client::Widget::Window; |
|
|
194 | |
|
|
195 | our @ISA = Crossfire::Client::Widget::Bin::; |
|
|
196 | |
|
|
197 | use SDL::OpenGL; |
|
|
198 | |
|
|
199 | sub add { |
|
|
200 | my ($self, $chld) = @_; |
|
|
201 | warn "ADD $chld\n"; |
|
|
202 | $self->SUPER::add ($chld); |
|
|
203 | $chld->set_parent ($self); |
|
|
204 | } |
|
|
205 | |
|
|
206 | sub remove { |
|
|
207 | my ($self) = @_; |
|
|
208 | # TODO FIXME: removing a child from a window will crash, see render_chld |
|
|
209 | # $self->update; |
|
|
210 | } |
|
|
211 | |
|
|
212 | sub update { |
|
|
213 | my ($self) = @_; |
|
|
214 | $self->render_chld; |
269 | $self->render_chld; |
|
|
270 | $self->SUPER::update; |
215 | } |
271 | } |
216 | |
272 | |
217 | sub render_chld { |
273 | sub render_chld { |
218 | my ($self) = @_; |
274 | my ($self) = @_; |
219 | my $chld = $self->get; |
|
|
220 | my ($w, $h) = $self->size_request; |
|
|
221 | |
275 | |
222 | require Carp; |
|
|
223 | Carp::cluck "RENDERCHI $w $h"; |
|
|
224 | warn "RENDERCHI $w $h\n"; |
|
|
225 | $self->{texture} = |
276 | $self->{texture} = |
226 | Crossfire::Client::Texture->new_from_opengl ( |
277 | Crossfire::Client::Texture->new_from_opengl ( |
227 | $w, $h, sub { $chld->draw } |
278 | $self->{w}, $self->{h}, sub { $self->child->draw } |
228 | ); |
279 | ); |
229 | $self->{texture}->upload; |
|
|
230 | } |
|
|
231 | |
|
|
232 | sub size_request { |
|
|
233 | my ($self) = @_; |
|
|
234 | ($self->w, $self->h) |
|
|
235 | } |
280 | } |
236 | |
281 | |
237 | sub size_allocate { |
282 | sub size_allocate { |
238 | my ($self, $w, $h) = @_; |
283 | my ($self, $w, $h) = @_; |
239 | |
284 | |
240 | $self->w ($w); |
285 | $self->{w} = $w; |
241 | $self->h ($h); |
286 | $self->{h} = $h; |
|
|
287 | |
242 | $self->get->size_allocate ($w, $h); |
288 | $self->child->size_allocate ($w, $h); |
243 | |
289 | |
244 | $self->update; #TODO: Move this to the size_request event propably? |
290 | $self->render_chld; |
245 | } |
291 | } |
246 | |
292 | |
247 | sub _draw { |
293 | sub _draw { |
248 | my ($self) = @_; |
294 | my ($self) = @_; |
249 | |
295 | |
… | |
… | |
266 | |
312 | |
267 | glDisable GL_BLEND; |
313 | glDisable GL_BLEND; |
268 | glDisable GL_TEXTURE_2D; |
314 | glDisable GL_TEXTURE_2D; |
269 | } |
315 | } |
270 | |
316 | |
|
|
317 | ############################################################################# |
|
|
318 | |
271 | package Crossfire::Client::Widget::Frame; |
319 | package Crossfire::Client::Widget::Frame; |
272 | |
320 | |
273 | our @ISA = Crossfire::Client::Widget::Bin::; |
321 | our @ISA = Crossfire::Client::Widget::Bin::; |
274 | |
322 | |
275 | use SDL::OpenGL; |
323 | use SDL::OpenGL; |
276 | |
324 | |
277 | sub size_request { |
325 | sub size_request { |
278 | my ($self) = @_; |
326 | my ($self) = @_; |
279 | my $chld = $self->get |
327 | my $chld = $self->child |
280 | or return (0, 0); |
328 | or return (0, 0); |
281 | |
329 | |
282 | $chld->move (2, 2); |
330 | $chld->move (2, 2); |
283 | |
331 | |
284 | map { $_ + 4 } $chld->size_request; |
332 | map { $_ + 4 } $chld->size_request; |
285 | } |
333 | } |
286 | |
334 | |
287 | sub size_allocate { |
335 | sub size_allocate { |
288 | my ($self, $w, $h) = @_; |
336 | my ($self, $w, $h) = @_; |
289 | |
337 | |
290 | $self->w ($w); |
338 | $self->{w} = $w; |
291 | $self->h ($h); |
339 | $self->{h} = $h; |
292 | |
340 | |
293 | $self->get->size_allocate ($w - 4, $h - 4); |
341 | $self->child->size_allocate ($w - 4, $h - 4); |
294 | $self->get->move (2, 2); |
342 | $self->child->move (2, 2); |
295 | } |
343 | } |
296 | |
344 | |
297 | sub _draw { |
345 | sub _draw { |
298 | my ($self) = @_; |
346 | my ($self) = @_; |
299 | |
347 | |
300 | my $chld = $self->get; |
348 | my $chld = $self->child; |
301 | |
349 | |
302 | my ($w, $h) = $chld->size_request; |
350 | my ($w, $h) = $chld->size_request; |
303 | |
351 | |
304 | glBegin GL_QUADS; |
352 | glBegin GL_QUADS; |
305 | glColor 0, 0, 0; |
353 | glColor 0, 0, 0; |
… | |
… | |
310 | glEnd; |
358 | glEnd; |
311 | |
359 | |
312 | $chld->draw; |
360 | $chld->draw; |
313 | } |
361 | } |
314 | |
362 | |
|
|
363 | ############################################################################# |
|
|
364 | |
315 | package Crossfire::Client::Widget::FancyFrame; |
365 | package Crossfire::Client::Widget::FancyFrame; |
316 | |
366 | |
317 | our @ISA = Crossfire::Client::Widget::Frame::; |
367 | our @ISA = Crossfire::Client::Widget::Bin::; |
318 | |
368 | |
319 | use SDL::OpenGL; |
369 | use SDL::OpenGL; |
320 | |
370 | |
321 | sub new { |
371 | my @tex = |
322 | my ($self, $theme) = @_; |
|
|
323 | $self = $self->SUPER::new; |
|
|
324 | |
|
|
325 | $self->{txts} = [ |
|
|
326 | map { new_from_file Crossfire::Client::Texture Crossfire::Client::find_rcfile $_ } |
372 | map { new_from_file Crossfire::Client::Texture Crossfire::Client::find_rcfile $_ } |
327 | qw/d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png/ |
373 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
328 | ]; |
|
|
329 | $self |
|
|
330 | } |
|
|
331 | |
374 | |
332 | sub size_request { |
375 | sub size_request { |
333 | my ($self) = @_; |
376 | my ($self) = @_; |
|
|
377 | |
334 | my ($w, $h) = $self->get->size_request; |
378 | my ($w, $h) = $self->SUPER::size_request; |
335 | |
379 | |
336 | $h += $self->{txts}->[1]->{height}; |
380 | $h += $tex[1]->{height}; |
337 | $h += $self->{txts}->[4]->{height}; |
381 | $h += $tex[4]->{height}; |
338 | $w += $self->{txts}->[2]->{width}; |
382 | $w += $tex[2]->{width}; |
339 | $w += $self->{txts}->[3]->{width}; |
383 | $w += $tex[3]->{width}; |
340 | |
384 | |
341 | ($w, $h) |
385 | ($w, $h) |
342 | } |
386 | } |
343 | |
387 | |
344 | sub size_allocate { |
388 | sub size_allocate { |
345 | my ($self, $w, $h) = @_; |
389 | my ($self, $w, $h) = @_; |
346 | |
390 | |
347 | $self->w ($w); |
391 | $self->SUPER::size_allocate ($w, $h); |
348 | $self->h ($h); |
392 | |
349 | $h -= $self->{txts}->[1]->{height}; |
393 | $h -= $tex[1]->{height}; |
350 | $h -= $self->{txts}->[4]->{height}; |
394 | $h -= $tex[4]->{height}; |
351 | $w -= $self->{txts}->[2]->{width}; |
395 | $w -= $tex[2]->{width}; |
352 | $w -= $self->{txts}->[3]->{width}; |
396 | $w -= $tex[3]->{width}; |
353 | |
397 | |
354 | $h = $h < 0 ? 0 : $h; |
398 | $h = $h < 0 ? 0 : $h; |
355 | $w = $w < 0 ? 0 : $w; |
399 | $w = $w < 0 ? 0 : $w; |
356 | warn "CHILD:$w $h\n"; |
400 | warn "CHILD:$w $h\n"; |
357 | $self->get->size_allocate ($w, $h); |
401 | $self->child->size_allocate ($w, $h); |
358 | $self->get->move ($self->{txts}->[3]->{width}, $self->{txts}->[1]->{height}); |
402 | $self->child->move ($self->{txts}->[3]->{width}, $self->{txts}->[1]->{height}); |
359 | } |
403 | } |
360 | |
404 | |
361 | sub _draw { |
405 | sub _draw { |
362 | my ($self) = @_; |
406 | my ($self) = @_; |
363 | |
407 | |
364 | my ($w, $h) = ($self->w, $self->h); |
408 | my ($w, $h) = ($self->w, $self->h); |
365 | my ($cw, $ch) = ($self->get->w, $self->get->h); |
409 | my ($cw, $ch) = ($self->child->w, $self->child->h); |
366 | |
410 | |
367 | glEnable GL_BLEND; |
411 | glEnable GL_BLEND; |
368 | glEnable GL_TEXTURE_2D; |
412 | glEnable GL_TEXTURE_2D; |
369 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
413 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
370 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
414 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
371 | |
415 | |
372 | my $top = $self->{txts}->[1]; |
416 | my $top = $tex[1]; |
373 | glBindTexture GL_TEXTURE_2D, $top->{name}; |
417 | glBindTexture GL_TEXTURE_2D, $top->{name}; |
374 | |
418 | |
375 | glBegin GL_QUADS; |
419 | glBegin GL_QUADS; |
376 | glTexCoord 0, 0; glVertex 0 , 0; |
420 | glTexCoord 0, 0; glVertex 0 , 0; |
377 | glTexCoord 0, 1; glVertex 0 , $top->{height}; |
421 | glTexCoord 0, 1; glVertex 0 , $top->{height}; |
378 | glTexCoord 1, 1; glVertex $w , $top->{height}; |
422 | glTexCoord 1, 1; glVertex $w , $top->{height}; |
379 | glTexCoord 1, 0; glVertex $w , 0; |
423 | glTexCoord 1, 0; glVertex $w , 0; |
380 | glEnd; |
424 | glEnd; |
381 | |
425 | |
382 | my $left = $self->{txts}->[3]; |
426 | my $left = $tex[3]; |
383 | glBindTexture GL_TEXTURE_2D, $left->{name}; |
427 | glBindTexture GL_TEXTURE_2D, $left->{name}; |
384 | |
428 | |
385 | glBegin GL_QUADS; |
429 | glBegin GL_QUADS; |
386 | glTexCoord 0, 0; glVertex 0 , $top->{height}; |
430 | glTexCoord 0, 0; glVertex 0 , $top->{height}; |
387 | glTexCoord 0, 1; glVertex 0 , $top->{height} + $ch; |
431 | glTexCoord 0, 1; glVertex 0 , $top->{height} + $ch; |
388 | glTexCoord 1, 1; glVertex $left->{width}, $top->{height} + $ch; |
432 | glTexCoord 1, 1; glVertex $left->{width}, $top->{height} + $ch; |
389 | glTexCoord 1, 0; glVertex $left->{width}, $top->{height}; |
433 | glTexCoord 1, 0; glVertex $left->{width}, $top->{height}; |
390 | glEnd; |
434 | glEnd; |
391 | |
435 | |
392 | my $right = $self->{txts}->[2]; |
436 | my $right = $tex[2]; |
393 | glBindTexture GL_TEXTURE_2D, $right->{name}; |
437 | glBindTexture GL_TEXTURE_2D, $right->{name}; |
394 | |
438 | |
395 | glBegin GL_QUADS; |
439 | glBegin GL_QUADS; |
396 | glTexCoord 0, 0; glVertex $w - $right->{width}, $top->{height}; |
440 | glTexCoord 0, 0; glVertex $w - $right->{width}, $top->{height}; |
397 | glTexCoord 0, 1; glVertex $w - $right->{width}, $top->{height} + $ch; |
441 | glTexCoord 0, 1; glVertex $w - $right->{width}, $top->{height} + $ch; |
398 | glTexCoord 1, 1; glVertex $w , $top->{height} + $ch; |
442 | glTexCoord 1, 1; glVertex $w , $top->{height} + $ch; |
399 | glTexCoord 1, 0; glVertex $w , $top->{height}; |
443 | glTexCoord 1, 0; glVertex $w , $top->{height}; |
400 | glEnd; |
444 | glEnd; |
401 | |
445 | |
402 | my $bottom = $self->{txts}->[4]; |
446 | my $bottom = $tex[4]; |
403 | glBindTexture GL_TEXTURE_2D, $bottom->{name}; |
447 | glBindTexture GL_TEXTURE_2D, $bottom->{name}; |
404 | |
448 | |
405 | glBegin GL_QUADS; |
449 | glBegin GL_QUADS; |
406 | glTexCoord 0, 0; glVertex 0 , $h - $bottom->{height}; |
450 | glTexCoord 0, 0; glVertex 0 , $h - $bottom->{height}; |
407 | glTexCoord 0, 1; glVertex 0 , $h; |
451 | glTexCoord 0, 1; glVertex 0 , $h; |
408 | glTexCoord 1, 1; glVertex $w , $h; |
452 | glTexCoord 1, 1; glVertex $w , $h; |
409 | glTexCoord 1, 0; glVertex $w , $h - $bottom->{height}; |
453 | glTexCoord 1, 0; glVertex $w , $h - $bottom->{height}; |
410 | glEnd; |
454 | glEnd; |
411 | |
455 | |
412 | my $bg = $self->{txts}->[0]; |
456 | my $bg = $tex[0]; |
413 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
457 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
414 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
458 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
415 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; |
459 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; |
416 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; |
460 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; |
417 | |
461 | |
… | |
… | |
426 | glEnd; |
470 | glEnd; |
427 | |
471 | |
428 | glDisable GL_BLEND; |
472 | glDisable GL_BLEND; |
429 | glDisable GL_TEXTURE_2D; |
473 | glDisable GL_TEXTURE_2D; |
430 | |
474 | |
431 | $self->get->draw; |
475 | $self->child->draw; |
432 | |
476 | |
433 | } |
477 | } |
|
|
478 | |
|
|
479 | ############################################################################# |
434 | |
480 | |
435 | package Crossfire::Client::Widget::Table; |
481 | package Crossfire::Client::Widget::Table; |
436 | |
482 | |
437 | our @ISA = Crossfire::Client::Widget::Bin::; |
483 | our @ISA = Crossfire::Client::Widget::Bin::; |
438 | |
484 | |
439 | use SDL::OpenGL; |
485 | use SDL::OpenGL; |
440 | |
486 | |
441 | sub add { |
487 | sub add { |
442 | my ($self, $x, $y, $chld) = @_; |
488 | my ($self, $x, $y, $chld) = @_; |
443 | my $old_chld = $self->{childs}[$y][$x]; |
489 | my $old_chld = $self->{children}[$y][$x]; |
444 | |
490 | |
445 | $self->{childs}[$y][$x] = $chld; |
491 | $self->{children}[$y][$x] = $chld; |
446 | $chld->set_parent ($self); |
492 | $chld->set_parent ($self); |
447 | $self->update; |
493 | $self->update; |
448 | } |
494 | } |
449 | |
495 | |
450 | sub max_row_height { |
496 | sub max_row_height { |
451 | my ($self, $row) = @_; |
497 | my ($self, $row) = @_; |
452 | |
498 | |
453 | my $hs = 0; |
499 | my $hs = 0; |
454 | for (my $xi = 0; $xi <= $#{$self->{childs}->[$row] || []}; $xi++) { |
500 | for (my $xi = 0; $xi <= $#{$self->{children}->[$row] || []}; $xi++) { |
455 | my $c = $self->{childs}->[$row]->[$xi]; |
501 | my $c = $self->{children}->[$row]->[$xi]; |
456 | if ($c) { |
502 | if ($c) { |
457 | my ($w, $h) = $c->size_request; |
503 | my ($w, $h) = $c->size_request; |
458 | if ($hs < $h) { $hs = $h } |
504 | if ($hs < $h) { $hs = $h } |
459 | } |
505 | } |
460 | } |
506 | } |
… | |
… | |
463 | |
509 | |
464 | sub max_col_width { |
510 | sub max_col_width { |
465 | my ($self, $col) = @_; |
511 | my ($self, $col) = @_; |
466 | |
512 | |
467 | my $ws = 0; |
513 | my $ws = 0; |
468 | for (my $yi = 0; $yi <= $#{$self->{childs} || []}; $yi++) { |
514 | for (my $yi = 0; $yi <= $#{$self->{children} || []}; $yi++) { |
469 | my $c = ($self->{childs}->[$yi] || [])->[$col]; |
515 | my $c = ($self->{children}->[$yi] || [])->[$col]; |
470 | if ($c) { |
516 | if ($c) { |
471 | my ($w, $h) = $c->size_request; |
517 | my ($w, $h) = $c->size_request; |
472 | if ($ws < $w) { $ws = $w } |
518 | if ($ws < $w) { $ws = $w } |
473 | } |
519 | } |
474 | } |
520 | } |
… | |
… | |
478 | sub size_request { |
524 | sub size_request { |
479 | my ($self) = @_; |
525 | my ($self) = @_; |
480 | |
526 | |
481 | my ($hs, $ws) = (0, 0); |
527 | my ($hs, $ws) = (0, 0); |
482 | |
528 | |
483 | for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) { |
529 | for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) { |
484 | $hs += $self->max_row_height ($yi); |
530 | $hs += $self->max_row_height ($yi); |
485 | } |
531 | } |
486 | |
532 | |
487 | for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) { |
533 | for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) { |
488 | my $wm = 0; |
534 | my $wm = 0; |
489 | for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) { |
535 | for (my $xi = 0; $xi <= $#{$self->{children}->[$yi]}; $xi++) { |
490 | $wm += $self->max_col_width ($xi) |
536 | $wm += $self->max_col_width ($xi) |
491 | } |
537 | } |
492 | if ($ws < $wm) { $ws = $wm } |
538 | if ($ws < $wm) { $ws = $wm } |
493 | } |
539 | } |
494 | |
540 | |
… | |
… | |
497 | |
543 | |
498 | sub _draw { |
544 | sub _draw { |
499 | my ($self) = @_; |
545 | my ($self) = @_; |
500 | |
546 | |
501 | my $y = 0; |
547 | my $y = 0; |
502 | for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) { |
548 | for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) { |
503 | my $x = 0; |
549 | my $x = 0; |
504 | |
550 | |
505 | for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) { |
551 | for (my $xi = 0; $xi <= $#{$self->{children}->[$yi]}; $xi++) { |
506 | |
552 | |
507 | my $c = $self->{childs}->[$yi]->[$xi]; |
553 | my $c = $self->{children}->[$yi]->[$xi]; |
508 | if ($c) { |
554 | if ($c) { |
509 | $c->move ($x, $y, 0); #TODO: Move to size_request |
555 | $c->move ($x, $y, 0); #TODO: Move to size_request |
510 | $c->draw if $c; |
556 | $c->draw if $c; |
511 | } |
557 | } |
512 | |
558 | |
… | |
… | |
515 | |
561 | |
516 | $y += $self->max_row_height ($yi); |
562 | $y += $self->max_row_height ($yi); |
517 | } |
563 | } |
518 | } |
564 | } |
519 | |
565 | |
|
|
566 | ############################################################################# |
|
|
567 | |
520 | package Crossfire::Client::Widget::VBox; |
568 | package Crossfire::Client::Widget::VBox; |
521 | |
569 | |
522 | our @ISA = Crossfire::Client::Widget::Bin::; |
570 | our @ISA = Crossfire::Client::Widget::Container::; |
523 | |
571 | |
524 | use SDL::OpenGL; |
572 | use SDL::OpenGL; |
525 | |
|
|
526 | sub add { |
|
|
527 | my ($self, $chld, $expand) = @_; |
|
|
528 | push @{$self->{childs}}, $chld; |
|
|
529 | $chld->{expand} = $expand; |
|
|
530 | $chld->set_parent ($self); |
|
|
531 | $self->update; |
|
|
532 | } |
|
|
533 | |
|
|
534 | sub size_request { |
|
|
535 | my ($self) = @_; |
|
|
536 | |
|
|
537 | my ($hs, $ws) = (0, 0); |
|
|
538 | for (@{$self->{childs} || []}) { |
|
|
539 | my ($w, $h) = $_->size_request; |
|
|
540 | $hs += $h; |
|
|
541 | if ($ws < $w) { $ws = $w } |
|
|
542 | } |
|
|
543 | |
|
|
544 | return ($ws, $hs); |
|
|
545 | } |
|
|
546 | |
573 | |
547 | sub size_allocate { |
574 | sub size_allocate { |
548 | my ($self, $w, $h) = @_; |
575 | my ($self, $w, $h) = @_; |
549 | |
576 | |
550 | $self->w ($w); |
577 | $self->w ($w); |
551 | $self->h ($h); |
578 | $self->h ($h); |
552 | |
579 | |
553 | my $exp; |
580 | my $exp; |
554 | my @oth; |
581 | my @oth; |
555 | # find expand widget |
582 | # find expand widget |
556 | for (@{$self->{childs}}) { |
583 | for (@{$self->{children}}) { |
557 | if ($_->{expand}) { |
584 | if ($_->{expand}) { |
558 | $exp = $_; |
585 | $exp = $_; |
559 | last; |
586 | last; |
560 | } |
587 | } |
561 | push @oth, $_; |
588 | push @oth, $_; |
… | |
… | |
569 | $oh += $h; |
596 | $oh += $h; |
570 | if ($ow < $w) { $ow = $w } |
597 | if ($ow < $w) { $ow = $w } |
571 | } |
598 | } |
572 | |
599 | |
573 | my $y = 0; |
600 | my $y = 0; |
574 | for (@{$self->{childs}}) { |
601 | for (@{$self->{children}}) { |
575 | $_->move (0, $y); |
602 | $_->move (0, $y); |
576 | |
603 | |
577 | if ($_ == $exp) { |
604 | if ($_ == $exp) { |
578 | $_->size_allocate ($w, $h - $oh); |
605 | $_->size_allocate ($w, $h - $oh); |
579 | $y += $h - $oh; |
606 | $y += $h - $oh; |
… | |
… | |
587 | |
614 | |
588 | sub _draw { |
615 | sub _draw { |
589 | my ($self) = @_; |
616 | my ($self) = @_; |
590 | |
617 | |
591 | my ($x, $y); |
618 | my ($x, $y); |
592 | for (@{$self->{childs} || []}) { |
619 | for (@{$self->{children} || []}) { |
593 | $_->draw; |
620 | $_->draw; |
594 | $y += $_->h; |
621 | $y += $_->h; |
595 | } |
622 | } |
596 | } |
623 | } |
|
|
624 | |
|
|
625 | ############################################################################# |
597 | |
626 | |
598 | package Crossfire::Client::Widget::Label; |
627 | package Crossfire::Client::Widget::Label; |
599 | |
628 | |
600 | our @ISA = Crossfire::Client::Widget::; |
629 | our @ISA = Crossfire::Client::Widget::; |
601 | |
630 | |
… | |
… | |
658 | |
687 | |
659 | glDisable GL_BLEND; |
688 | glDisable GL_BLEND; |
660 | glDisable GL_TEXTURE_2D; |
689 | glDisable GL_TEXTURE_2D; |
661 | } |
690 | } |
662 | |
691 | |
|
|
692 | ############################################################################# |
|
|
693 | |
663 | package Crossfire::Client::Widget::TextEntry; |
694 | package Crossfire::Client::Widget::TextEntry; |
664 | |
695 | |
665 | our @ISA = Crossfire::Client::Widget::Label::; |
696 | our @ISA = Crossfire::Client::Widget::Label::; |
666 | |
697 | |
667 | use SDL; |
698 | use SDL; |
… | |
… | |
684 | } elsif ($uni) { |
715 | } elsif ($uni) { |
685 | $text .= chr $uni; |
716 | $text .= chr $uni; |
686 | } |
717 | } |
687 | $self->set_text ($text); |
718 | $self->set_text ($text); |
688 | } |
719 | } |
|
|
720 | |
|
|
721 | ############################################################################# |
689 | |
722 | |
690 | package Crossfire::Client::Widget::MapWidget; |
723 | package Crossfire::Client::Widget::MapWidget; |
691 | |
724 | |
692 | use strict; |
725 | use strict; |
693 | |
726 | |
… | |
… | |
860 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
893 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
861 | $::CONN->send ("command run_stop"); |
894 | $::CONN->send ("command run_stop"); |
862 | } |
895 | } |
863 | } |
896 | } |
864 | |
897 | |
|
|
898 | ############################################################################# |
|
|
899 | |
865 | package Crossfire::Client::Widget::Animator; |
900 | package Crossfire::Client::Widget::Animator; |
866 | |
901 | |
867 | use SDL::OpenGL; |
902 | use SDL::OpenGL; |
868 | |
903 | |
869 | our @ISA = Crossfire::Client::Widget::Bin::; |
904 | our @ISA = Crossfire::Client::Widget::Bin::; |
… | |
… | |
896 | sub _draw { |
931 | sub _draw { |
897 | my ($self) = @_; |
932 | my ($self) = @_; |
898 | |
933 | |
899 | glPushMatrix; |
934 | glPushMatrix; |
900 | glRotate $self->{time} * 10000, 0, 1, 0; |
935 | glRotate $self->{time} * 10000, 0, 1, 0; |
901 | $self->{child}->draw; |
936 | $self->{children}[0]->draw; |
902 | glPopMatrix; |
937 | glPopMatrix; |
903 | } |
938 | } |
904 | |
939 | |
905 | 1; |
940 | 1; |
906 | |
941 | |