… | |
… | |
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) = @_; |
145 | $self->SUPER::size_allocate ($w, $h); |
224 | $self->SUPER::size_allocate ($w, $h); |
146 | $self->{child}->size_allocate ($w, $h) |
225 | $self->{children}[0]->size_allocate ($w, $h) |
147 | if $self->{child} |
226 | if $self->{children}[0] |
148 | } |
227 | } |
149 | |
228 | |
150 | sub _draw { |
229 | ############################################################################# |
151 | my ($self) = @_; |
|
|
152 | |
|
|
153 | $self->{child}->draw; |
|
|
154 | } |
|
|
155 | |
230 | |
156 | package Crossfire::Client::Widget::Toplevel; |
231 | package Crossfire::Client::Widget::Toplevel; |
157 | |
232 | |
158 | our @ISA = Crossfire::Client::Widget::; |
233 | our @ISA = Crossfire::Client::Widget::Container::; |
159 | |
|
|
160 | use SDL::OpenGL; |
|
|
161 | |
|
|
162 | sub add { |
|
|
163 | my ($self, $chld) = @_; |
|
|
164 | |
|
|
165 | push @{$self->{childs}}, $chld; |
|
|
166 | @{$self->{childs}} = |
|
|
167 | sort { $a->{z} <=> $b->{z} } |
|
|
168 | @{$self->{childs}}; |
|
|
169 | |
|
|
170 | $chld->set_parent ($self); |
|
|
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 | } |
|
|
181 | |
234 | |
182 | sub update { |
235 | sub update { |
183 | my ($self) = @_; |
236 | my ($self) = @_; |
|
|
237 | |
184 | ::refresh (); |
238 | ::refresh (); |
185 | } |
239 | } |
186 | |
240 | |
187 | sub _draw { |
241 | ############################################################################# |
188 | my ($self) = @_; |
|
|
189 | |
|
|
190 | $_->draw for @{$self->{childs}}; |
|
|
191 | } |
|
|
192 | |
242 | |
193 | package Crossfire::Client::Widget::Window; |
243 | package Crossfire::Client::Widget::Window; |
194 | |
244 | |
195 | our @ISA = Crossfire::Client::Widget::Bin::; |
245 | our @ISA = Crossfire::Client::Widget::Bin::; |
196 | |
246 | |
… | |
… | |
266 | |
316 | |
267 | glDisable GL_BLEND; |
317 | glDisable GL_BLEND; |
268 | glDisable GL_TEXTURE_2D; |
318 | glDisable GL_TEXTURE_2D; |
269 | } |
319 | } |
270 | |
320 | |
|
|
321 | ############################################################################# |
|
|
322 | |
271 | package Crossfire::Client::Widget::Frame; |
323 | package Crossfire::Client::Widget::Frame; |
272 | |
324 | |
273 | our @ISA = Crossfire::Client::Widget::Bin::; |
325 | our @ISA = Crossfire::Client::Widget::Bin::; |
274 | |
326 | |
275 | use SDL::OpenGL; |
327 | use SDL::OpenGL; |
276 | |
328 | |
277 | sub size_request { |
329 | sub size_request { |
278 | my ($self) = @_; |
330 | my ($self) = @_; |
279 | my $chld = $self->get |
331 | my $chld = $self->child |
280 | or return (0, 0); |
332 | or return (0, 0); |
281 | |
333 | |
282 | $chld->move (2, 2); |
334 | $chld->move (2, 2); |
283 | |
335 | |
284 | map { $_ + 4 } $chld->size_request; |
336 | map { $_ + 4 } $chld->size_request; |
285 | } |
337 | } |
286 | |
338 | |
287 | sub size_allocate { |
339 | sub size_allocate { |
288 | my ($self, $w, $h) = @_; |
340 | my ($self, $w, $h) = @_; |
289 | |
341 | |
290 | $self->w ($w); |
342 | $self->SUPER::size_allocate ($w, $h); |
291 | $self->h ($h); |
|
|
292 | |
343 | |
293 | $self->get->size_allocate ($w - 4, $h - 4); |
344 | $self->child->size_allocate ($w - 4, $h - 4); |
294 | $self->get->move (2, 2); |
345 | $self->child->move (2, 2); |
295 | } |
346 | } |
296 | |
347 | |
297 | sub _draw { |
348 | sub _draw { |
298 | my ($self) = @_; |
349 | my ($self) = @_; |
299 | |
350 | |
300 | my $chld = $self->get; |
351 | my $chld = $self->child; |
301 | |
352 | |
302 | my ($w, $h) = $chld->size_request; |
353 | my ($w, $h) = $chld->size_request; |
303 | |
354 | |
304 | glBegin GL_QUADS; |
355 | glBegin GL_QUADS; |
305 | glColor 0, 0, 0; |
356 | glColor 0, 0, 0; |
… | |
… | |
310 | glEnd; |
361 | glEnd; |
311 | |
362 | |
312 | $chld->draw; |
363 | $chld->draw; |
313 | } |
364 | } |
314 | |
365 | |
|
|
366 | ############################################################################# |
|
|
367 | |
315 | package Crossfire::Client::Widget::FancyFrame; |
368 | package Crossfire::Client::Widget::FancyFrame; |
316 | |
369 | |
317 | our @ISA = Crossfire::Client::Widget::Frame::; |
370 | our @ISA = Crossfire::Client::Widget::Bin::; |
318 | |
371 | |
319 | use SDL::OpenGL; |
372 | use SDL::OpenGL; |
320 | |
373 | |
321 | sub new { |
374 | 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 $_ } |
375 | 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/ |
376 | 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 | |
377 | |
332 | sub size_request { |
378 | sub size_request { |
333 | my ($self) = @_; |
379 | my ($self) = @_; |
|
|
380 | |
334 | my ($w, $h) = $self->get->size_request; |
381 | my ($w, $h) = $self->SUPER::size_request; |
335 | |
382 | |
336 | $h += $self->{txts}->[1]->{height}; |
383 | $h += $tex[1]->{height}; |
337 | $h += $self->{txts}->[4]->{height}; |
384 | $h += $tex[4]->{height}; |
338 | $w += $self->{txts}->[2]->{width}; |
385 | $w += $tex[2]->{width}; |
339 | $w += $self->{txts}->[3]->{width}; |
386 | $w += $tex[3]->{width}; |
340 | |
387 | |
341 | ($w, $h) |
388 | ($w, $h) |
342 | } |
389 | } |
343 | |
390 | |
344 | sub size_allocate { |
391 | sub size_allocate { |
345 | my ($self, $w, $h) = @_; |
392 | my ($self, $w, $h) = @_; |
346 | |
393 | |
347 | $self->w ($w); |
394 | $self->SUPER::size_allocate ($w, $h); |
348 | $self->h ($h); |
395 | |
349 | $h -= $self->{txts}->[1]->{height}; |
396 | $h -= $tex[1]->{height}; |
350 | $h -= $self->{txts}->[4]->{height}; |
397 | $h -= $tex[4]->{height}; |
351 | $w -= $self->{txts}->[2]->{width}; |
398 | $w -= $tex[2]->{width}; |
352 | $w -= $self->{txts}->[3]->{width}; |
399 | $w -= $tex[3]->{width}; |
353 | |
400 | |
354 | $h = $h < 0 ? 0 : $h; |
401 | $h = $h < 0 ? 0 : $h; |
355 | $w = $w < 0 ? 0 : $w; |
402 | $w = $w < 0 ? 0 : $w; |
356 | warn "CHILD:$w $h\n"; |
403 | warn "CHILD:$w $h\n"; |
357 | $self->get->size_allocate ($w, $h); |
404 | $self->child->size_allocate ($w, $h); |
358 | $self->get->move ($self->{txts}->[3]->{width}, $self->{txts}->[1]->{height}); |
405 | $self->child->move ($self->{txts}->[3]->{width}, $self->{txts}->[1]->{height}); |
359 | } |
406 | } |
360 | |
407 | |
361 | sub _draw { |
408 | sub _draw { |
362 | my ($self) = @_; |
409 | my ($self) = @_; |
363 | |
410 | |
364 | my ($w, $h) = ($self->w, $self->h); |
411 | my ($w, $h) = ($self->w, $self->h); |
365 | my ($cw, $ch) = ($self->get->w, $self->get->h); |
412 | my ($cw, $ch) = ($self->child->w, $self->child->h); |
366 | |
413 | |
367 | glEnable GL_BLEND; |
414 | glEnable GL_BLEND; |
368 | glEnable GL_TEXTURE_2D; |
415 | glEnable GL_TEXTURE_2D; |
369 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
416 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
370 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
417 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
371 | |
418 | |
372 | my $top = $self->{txts}->[1]; |
419 | my $top = $tex[1]; |
373 | glBindTexture GL_TEXTURE_2D, $top->{name}; |
420 | glBindTexture GL_TEXTURE_2D, $top->{name}; |
374 | |
421 | |
375 | glBegin GL_QUADS; |
422 | glBegin GL_QUADS; |
376 | glTexCoord 0, 0; glVertex 0 , 0; |
423 | glTexCoord 0, 0; glVertex 0 , 0; |
377 | glTexCoord 0, 1; glVertex 0 , $top->{height}; |
424 | glTexCoord 0, 1; glVertex 0 , $top->{height}; |
378 | glTexCoord 1, 1; glVertex $w , $top->{height}; |
425 | glTexCoord 1, 1; glVertex $w , $top->{height}; |
379 | glTexCoord 1, 0; glVertex $w , 0; |
426 | glTexCoord 1, 0; glVertex $w , 0; |
380 | glEnd; |
427 | glEnd; |
381 | |
428 | |
382 | my $left = $self->{txts}->[3]; |
429 | my $left = $tex[3]; |
383 | glBindTexture GL_TEXTURE_2D, $left->{name}; |
430 | glBindTexture GL_TEXTURE_2D, $left->{name}; |
384 | |
431 | |
385 | glBegin GL_QUADS; |
432 | glBegin GL_QUADS; |
386 | glTexCoord 0, 0; glVertex 0 , $top->{height}; |
433 | glTexCoord 0, 0; glVertex 0 , $top->{height}; |
387 | glTexCoord 0, 1; glVertex 0 , $top->{height} + $ch; |
434 | glTexCoord 0, 1; glVertex 0 , $top->{height} + $ch; |
388 | glTexCoord 1, 1; glVertex $left->{width}, $top->{height} + $ch; |
435 | glTexCoord 1, 1; glVertex $left->{width}, $top->{height} + $ch; |
389 | glTexCoord 1, 0; glVertex $left->{width}, $top->{height}; |
436 | glTexCoord 1, 0; glVertex $left->{width}, $top->{height}; |
390 | glEnd; |
437 | glEnd; |
391 | |
438 | |
392 | my $right = $self->{txts}->[2]; |
439 | my $right = $tex[2]; |
393 | glBindTexture GL_TEXTURE_2D, $right->{name}; |
440 | glBindTexture GL_TEXTURE_2D, $right->{name}; |
394 | |
441 | |
395 | glBegin GL_QUADS; |
442 | glBegin GL_QUADS; |
396 | glTexCoord 0, 0; glVertex $w - $right->{width}, $top->{height}; |
443 | glTexCoord 0, 0; glVertex $w - $right->{width}, $top->{height}; |
397 | glTexCoord 0, 1; glVertex $w - $right->{width}, $top->{height} + $ch; |
444 | glTexCoord 0, 1; glVertex $w - $right->{width}, $top->{height} + $ch; |
398 | glTexCoord 1, 1; glVertex $w , $top->{height} + $ch; |
445 | glTexCoord 1, 1; glVertex $w , $top->{height} + $ch; |
399 | glTexCoord 1, 0; glVertex $w , $top->{height}; |
446 | glTexCoord 1, 0; glVertex $w , $top->{height}; |
400 | glEnd; |
447 | glEnd; |
401 | |
448 | |
402 | my $bottom = $self->{txts}->[4]; |
449 | my $bottom = $tex[4]; |
403 | glBindTexture GL_TEXTURE_2D, $bottom->{name}; |
450 | glBindTexture GL_TEXTURE_2D, $bottom->{name}; |
404 | |
451 | |
405 | glBegin GL_QUADS; |
452 | glBegin GL_QUADS; |
406 | glTexCoord 0, 0; glVertex 0 , $h - $bottom->{height}; |
453 | glTexCoord 0, 0; glVertex 0 , $h - $bottom->{height}; |
407 | glTexCoord 0, 1; glVertex 0 , $h; |
454 | glTexCoord 0, 1; glVertex 0 , $h; |
408 | glTexCoord 1, 1; glVertex $w , $h; |
455 | glTexCoord 1, 1; glVertex $w , $h; |
409 | glTexCoord 1, 0; glVertex $w , $h - $bottom->{height}; |
456 | glTexCoord 1, 0; glVertex $w , $h - $bottom->{height}; |
410 | glEnd; |
457 | glEnd; |
411 | |
458 | |
412 | my $bg = $self->{txts}->[0]; |
459 | my $bg = $tex[0]; |
413 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
460 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
414 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
461 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
415 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; |
462 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; |
416 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; |
463 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; |
417 | |
464 | |
… | |
… | |
426 | glEnd; |
473 | glEnd; |
427 | |
474 | |
428 | glDisable GL_BLEND; |
475 | glDisable GL_BLEND; |
429 | glDisable GL_TEXTURE_2D; |
476 | glDisable GL_TEXTURE_2D; |
430 | |
477 | |
431 | $self->get->draw; |
478 | $self->child->draw; |
432 | |
479 | |
433 | } |
480 | } |
|
|
481 | |
|
|
482 | ############################################################################# |
434 | |
483 | |
435 | package Crossfire::Client::Widget::Table; |
484 | package Crossfire::Client::Widget::Table; |
436 | |
485 | |
437 | our @ISA = Crossfire::Client::Widget::Bin::; |
486 | our @ISA = Crossfire::Client::Widget::Bin::; |
438 | |
487 | |
439 | use SDL::OpenGL; |
488 | use SDL::OpenGL; |
440 | |
489 | |
441 | sub add { |
490 | sub add { |
442 | my ($self, $x, $y, $chld) = @_; |
491 | my ($self, $x, $y, $chld) = @_; |
443 | my $old_chld = $self->{childs}[$y][$x]; |
492 | my $old_chld = $self->{children}[$y][$x]; |
444 | |
493 | |
445 | $self->{childs}[$y][$x] = $chld; |
494 | $self->{children}[$y][$x] = $chld; |
446 | $chld->set_parent ($self); |
495 | $chld->set_parent ($self); |
447 | $self->update; |
496 | $self->update; |
448 | } |
497 | } |
449 | |
498 | |
450 | sub max_row_height { |
499 | sub max_row_height { |
451 | my ($self, $row) = @_; |
500 | my ($self, $row) = @_; |
452 | |
501 | |
453 | my $hs = 0; |
502 | my $hs = 0; |
454 | for (my $xi = 0; $xi <= $#{$self->{childs}->[$row] || []}; $xi++) { |
503 | for (my $xi = 0; $xi <= $#{$self->{children}->[$row] || []}; $xi++) { |
455 | my $c = $self->{childs}->[$row]->[$xi]; |
504 | my $c = $self->{children}->[$row]->[$xi]; |
456 | if ($c) { |
505 | if ($c) { |
457 | my ($w, $h) = $c->size_request; |
506 | my ($w, $h) = $c->size_request; |
458 | if ($hs < $h) { $hs = $h } |
507 | if ($hs < $h) { $hs = $h } |
459 | } |
508 | } |
460 | } |
509 | } |
… | |
… | |
463 | |
512 | |
464 | sub max_col_width { |
513 | sub max_col_width { |
465 | my ($self, $col) = @_; |
514 | my ($self, $col) = @_; |
466 | |
515 | |
467 | my $ws = 0; |
516 | my $ws = 0; |
468 | for (my $yi = 0; $yi <= $#{$self->{childs} || []}; $yi++) { |
517 | for (my $yi = 0; $yi <= $#{$self->{children} || []}; $yi++) { |
469 | my $c = ($self->{childs}->[$yi] || [])->[$col]; |
518 | my $c = ($self->{children}->[$yi] || [])->[$col]; |
470 | if ($c) { |
519 | if ($c) { |
471 | my ($w, $h) = $c->size_request; |
520 | my ($w, $h) = $c->size_request; |
472 | if ($ws < $w) { $ws = $w } |
521 | if ($ws < $w) { $ws = $w } |
473 | } |
522 | } |
474 | } |
523 | } |
… | |
… | |
478 | sub size_request { |
527 | sub size_request { |
479 | my ($self) = @_; |
528 | my ($self) = @_; |
480 | |
529 | |
481 | my ($hs, $ws) = (0, 0); |
530 | my ($hs, $ws) = (0, 0); |
482 | |
531 | |
483 | for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) { |
532 | for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) { |
484 | $hs += $self->max_row_height ($yi); |
533 | $hs += $self->max_row_height ($yi); |
485 | } |
534 | } |
486 | |
535 | |
487 | for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) { |
536 | for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) { |
488 | my $wm = 0; |
537 | my $wm = 0; |
489 | for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) { |
538 | for (my $xi = 0; $xi <= $#{$self->{children}->[$yi]}; $xi++) { |
490 | $wm += $self->max_col_width ($xi) |
539 | $wm += $self->max_col_width ($xi) |
491 | } |
540 | } |
492 | if ($ws < $wm) { $ws = $wm } |
541 | if ($ws < $wm) { $ws = $wm } |
493 | } |
542 | } |
494 | |
543 | |
… | |
… | |
497 | |
546 | |
498 | sub _draw { |
547 | sub _draw { |
499 | my ($self) = @_; |
548 | my ($self) = @_; |
500 | |
549 | |
501 | my $y = 0; |
550 | my $y = 0; |
502 | for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) { |
551 | for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) { |
503 | my $x = 0; |
552 | my $x = 0; |
504 | |
553 | |
505 | for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) { |
554 | for (my $xi = 0; $xi <= $#{$self->{children}->[$yi]}; $xi++) { |
506 | |
555 | |
507 | my $c = $self->{childs}->[$yi]->[$xi]; |
556 | my $c = $self->{children}->[$yi]->[$xi]; |
508 | if ($c) { |
557 | if ($c) { |
509 | $c->move ($x, $y, 0); #TODO: Move to size_request |
558 | $c->move ($x, $y, 0); #TODO: Move to size_request |
510 | $c->draw if $c; |
559 | $c->draw if $c; |
511 | } |
560 | } |
512 | |
561 | |
… | |
… | |
515 | |
564 | |
516 | $y += $self->max_row_height ($yi); |
565 | $y += $self->max_row_height ($yi); |
517 | } |
566 | } |
518 | } |
567 | } |
519 | |
568 | |
|
|
569 | ############################################################################# |
|
|
570 | |
520 | package Crossfire::Client::Widget::VBox; |
571 | package Crossfire::Client::Widget::VBox; |
521 | |
572 | |
522 | our @ISA = Crossfire::Client::Widget::Bin::; |
573 | our @ISA = Crossfire::Client::Widget::Container::; |
523 | |
574 | |
524 | use SDL::OpenGL; |
575 | 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 | |
576 | |
547 | sub size_allocate { |
577 | sub size_allocate { |
548 | my ($self, $w, $h) = @_; |
578 | my ($self, $w, $h) = @_; |
549 | |
579 | |
550 | $self->w ($w); |
580 | $self->w ($w); |
551 | $self->h ($h); |
581 | $self->h ($h); |
552 | |
582 | |
553 | my $exp; |
583 | my $exp; |
554 | my @oth; |
584 | my @oth; |
555 | # find expand widget |
585 | # find expand widget |
556 | for (@{$self->{childs}}) { |
586 | for (@{$self->{children}}) { |
557 | if ($_->{expand}) { |
587 | if ($_->{expand}) { |
558 | $exp = $_; |
588 | $exp = $_; |
559 | last; |
589 | last; |
560 | } |
590 | } |
561 | push @oth, $_; |
591 | push @oth, $_; |
… | |
… | |
569 | $oh += $h; |
599 | $oh += $h; |
570 | if ($ow < $w) { $ow = $w } |
600 | if ($ow < $w) { $ow = $w } |
571 | } |
601 | } |
572 | |
602 | |
573 | my $y = 0; |
603 | my $y = 0; |
574 | for (@{$self->{childs}}) { |
604 | for (@{$self->{children}}) { |
575 | $_->move (0, $y); |
605 | $_->move (0, $y); |
576 | |
606 | |
577 | if ($_ == $exp) { |
607 | if ($_ == $exp) { |
578 | $_->size_allocate ($w, $h - $oh); |
608 | $_->size_allocate ($w, $h - $oh); |
579 | $y += $h - $oh; |
609 | $y += $h - $oh; |
… | |
… | |
587 | |
617 | |
588 | sub _draw { |
618 | sub _draw { |
589 | my ($self) = @_; |
619 | my ($self) = @_; |
590 | |
620 | |
591 | my ($x, $y); |
621 | my ($x, $y); |
592 | for (@{$self->{childs} || []}) { |
622 | for (@{$self->{children} || []}) { |
593 | $_->draw; |
623 | $_->draw; |
594 | $y += $_->h; |
624 | $y += $_->h; |
595 | } |
625 | } |
596 | } |
626 | } |
|
|
627 | |
|
|
628 | ############################################################################# |
597 | |
629 | |
598 | package Crossfire::Client::Widget::Label; |
630 | package Crossfire::Client::Widget::Label; |
599 | |
631 | |
600 | our @ISA = Crossfire::Client::Widget::; |
632 | our @ISA = Crossfire::Client::Widget::; |
601 | |
633 | |
… | |
… | |
658 | |
690 | |
659 | glDisable GL_BLEND; |
691 | glDisable GL_BLEND; |
660 | glDisable GL_TEXTURE_2D; |
692 | glDisable GL_TEXTURE_2D; |
661 | } |
693 | } |
662 | |
694 | |
|
|
695 | ############################################################################# |
|
|
696 | |
663 | package Crossfire::Client::Widget::TextEntry; |
697 | package Crossfire::Client::Widget::TextEntry; |
664 | |
698 | |
665 | our @ISA = Crossfire::Client::Widget::Label::; |
699 | our @ISA = Crossfire::Client::Widget::Label::; |
666 | |
700 | |
667 | use SDL; |
701 | use SDL; |
… | |
… | |
684 | } elsif ($uni) { |
718 | } elsif ($uni) { |
685 | $text .= chr $uni; |
719 | $text .= chr $uni; |
686 | } |
720 | } |
687 | $self->set_text ($text); |
721 | $self->set_text ($text); |
688 | } |
722 | } |
|
|
723 | |
|
|
724 | ############################################################################# |
689 | |
725 | |
690 | package Crossfire::Client::Widget::MapWidget; |
726 | package Crossfire::Client::Widget::MapWidget; |
691 | |
727 | |
692 | use strict; |
728 | use strict; |
693 | |
729 | |
… | |
… | |
860 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
896 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
861 | $::CONN->send ("command run_stop"); |
897 | $::CONN->send ("command run_stop"); |
862 | } |
898 | } |
863 | } |
899 | } |
864 | |
900 | |
|
|
901 | ############################################################################# |
|
|
902 | |
865 | package Crossfire::Client::Widget::Animator; |
903 | package Crossfire::Client::Widget::Animator; |
866 | |
904 | |
867 | use SDL::OpenGL; |
905 | use SDL::OpenGL; |
868 | |
906 | |
869 | our @ISA = Crossfire::Client::Widget::Bin::; |
907 | our @ISA = Crossfire::Client::Widget::Bin::; |
… | |
… | |
896 | sub _draw { |
934 | sub _draw { |
897 | my ($self) = @_; |
935 | my ($self) = @_; |
898 | |
936 | |
899 | glPushMatrix; |
937 | glPushMatrix; |
900 | glRotate $self->{time} * 10000, 0, 1, 0; |
938 | glRotate $self->{time} * 10000, 0, 1, 0; |
901 | $self->{child}->draw; |
939 | $self->{children}[0]->draw; |
902 | glPopMatrix; |
940 | glPopMatrix; |
903 | } |
941 | } |
904 | |
942 | |
905 | 1; |
943 | 1; |
906 | |
944 | |