… | |
… | |
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 | if $self->{w}; #TODO: check for "realised state" |
|
|
169 | } |
|
|
170 | |
|
|
171 | sub remove { |
|
|
172 | my ($self, $widget) = @_; |
|
|
173 | |
|
|
174 | $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; |
|
|
175 | |
|
|
176 | $self->size_allocate ($self->{w}, $self->{h}); |
|
|
177 | } |
|
|
178 | |
|
|
179 | sub find_widget { |
|
|
180 | my ($self, $x, $y) = @_; |
|
|
181 | |
|
|
182 | my $res; |
|
|
183 | |
|
|
184 | for (@{ $self->{children} }) { |
|
|
185 | $res = $_->find_widget ($x, $y) |
|
|
186 | and return $res; |
|
|
187 | } |
|
|
188 | |
|
|
189 | () |
|
|
190 | } |
|
|
191 | |
|
|
192 | sub _draw { |
|
|
193 | my ($self) = @_; |
|
|
194 | |
|
|
195 | $_->draw for @{$self->{children}}; |
|
|
196 | } |
|
|
197 | |
|
|
198 | ############################################################################# |
|
|
199 | |
127 | package Crossfire::Client::Widget::Bin; |
200 | package Crossfire::Client::Widget::Bin; |
128 | |
201 | |
129 | our @ISA = Crossfire::Client::Widget::; |
202 | our @ISA = Crossfire::Client::Widget::Container::; |
130 | |
203 | |
131 | sub add { $_[0]->{child} = $_[1]; $_[1]->set_parent ($_[0]); $_[1]->{expand} = $_[2] } |
|
|
132 | sub get { $_[0]->{child} } |
204 | sub child { $_[0]->{children}[0] } |
133 | |
|
|
134 | sub remove { |
|
|
135 | my ($self, $chld) = @_; |
|
|
136 | delete $self->{child} |
|
|
137 | if $self->{child} == $chld; |
|
|
138 | } |
|
|
139 | |
205 | |
140 | sub size_request { |
206 | sub size_request { |
141 | $_[0]->{child}->size_request if $_[0]->{child} |
207 | $_[0]{children}[0]->size_request if $_[0]{children}[0]; |
142 | } |
208 | } |
|
|
209 | |
143 | sub size_allocate { |
210 | sub size_allocate { |
144 | my ($self, $w, $h) = @_; |
211 | my ($self, $w, $h) = @_; |
|
|
212 | |
145 | $self->SUPER::size_allocate ($w, $h); |
213 | $self->SUPER::size_allocate ($w, $h); |
146 | $self->{child}->size_allocate ($w, $h) |
214 | $self->{children}[0]->size_allocate ($w, $h) |
147 | if $self->{child} |
215 | if $self->{children}[0] |
148 | } |
216 | } |
149 | |
217 | |
150 | sub _draw { |
218 | ############################################################################# |
151 | my ($self) = @_; |
|
|
152 | |
|
|
153 | $self->{child}->draw; |
|
|
154 | } |
|
|
155 | |
219 | |
156 | package Crossfire::Client::Widget::Toplevel; |
220 | package Crossfire::Client::Widget::Toplevel; |
157 | |
221 | |
|
|
222 | our @ISA = Crossfire::Client::Widget::Container::; |
|
|
223 | |
|
|
224 | sub update { |
|
|
225 | my ($self) = @_; |
|
|
226 | |
|
|
227 | ::refresh (); |
|
|
228 | } |
|
|
229 | |
|
|
230 | sub add { |
|
|
231 | my ($self, $widget) = @_; |
|
|
232 | |
|
|
233 | $self->SUPER::add ($widget); |
|
|
234 | |
|
|
235 | $widget->size_allocate ($widget->size_request); |
|
|
236 | } |
|
|
237 | |
|
|
238 | ############################################################################# |
|
|
239 | |
|
|
240 | package Crossfire::Client::Widget::Window; |
|
|
241 | |
158 | our @ISA = Crossfire::Client::Widget::; |
242 | our @ISA = Crossfire::Client::Widget::Bin::; |
159 | |
243 | |
160 | use SDL::OpenGL; |
244 | use SDL::OpenGL; |
161 | |
245 | |
162 | sub add { |
246 | sub new { |
163 | my ($self, $chld) = @_; |
247 | my ($class, $x, $y, $z, $w, $h) = @_; |
164 | |
248 | |
165 | push @{$self->{childs}}, $chld; |
249 | my $self = $class->SUPER::new; |
166 | @{$self->{childs}} = |
|
|
167 | sort { $a->{z} <=> $b->{z} } |
|
|
168 | @{$self->{childs}}; |
|
|
169 | |
250 | |
170 | $chld->set_parent ($self); |
251 | @$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 | } |
252 | } |
181 | |
253 | |
182 | sub update { |
254 | sub update { |
183 | my ($self) = @_; |
255 | my ($self) = @_; |
184 | ::refresh (); |
|
|
185 | } |
|
|
186 | |
256 | |
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; |
257 | $self->render_chld; |
|
|
258 | $self->SUPER::update; |
215 | } |
259 | } |
216 | |
260 | |
217 | sub render_chld { |
261 | sub render_chld { |
218 | my ($self) = @_; |
262 | my ($self) = @_; |
219 | my $chld = $self->get; |
|
|
220 | my ($w, $h) = $self->size_request; |
|
|
221 | |
263 | |
222 | require Carp; |
|
|
223 | Carp::cluck "RENDERCHI $w $h"; |
|
|
224 | warn "RENDERCHI $w $h\n"; |
|
|
225 | $self->{texture} = |
264 | $self->{texture} = |
226 | Crossfire::Client::Texture->new_from_opengl ( |
265 | Crossfire::Client::Texture->new_from_opengl ( |
227 | $w, $h, sub { $chld->draw } |
266 | $self->{w}, $self->{h}, sub { $self->child->draw } |
228 | ); |
267 | ); |
229 | $self->{texture}->upload; |
|
|
230 | } |
|
|
231 | |
|
|
232 | sub size_request { |
|
|
233 | my ($self) = @_; |
|
|
234 | ($self->w, $self->h) |
|
|
235 | } |
268 | } |
236 | |
269 | |
237 | sub size_allocate { |
270 | sub size_allocate { |
238 | my ($self, $w, $h) = @_; |
271 | my ($self, $w, $h) = @_; |
239 | |
272 | |
240 | $self->w ($w); |
273 | $self->{w} = $w; |
241 | $self->h ($h); |
274 | $self->{h} = $h; |
|
|
275 | |
242 | $self->get->size_allocate ($w, $h); |
276 | $self->child->size_allocate ($w, $h); |
243 | |
277 | |
244 | $self->update; #TODO: Move this to the size_request event propably? |
278 | $self->render_chld; |
245 | } |
279 | } |
246 | |
280 | |
247 | sub _draw { |
281 | sub _draw { |
248 | my ($self) = @_; |
282 | my ($self) = @_; |
249 | |
283 | |
… | |
… | |
266 | |
300 | |
267 | glDisable GL_BLEND; |
301 | glDisable GL_BLEND; |
268 | glDisable GL_TEXTURE_2D; |
302 | glDisable GL_TEXTURE_2D; |
269 | } |
303 | } |
270 | |
304 | |
|
|
305 | ############################################################################# |
|
|
306 | |
271 | package Crossfire::Client::Widget::Frame; |
307 | package Crossfire::Client::Widget::Frame; |
272 | |
308 | |
273 | our @ISA = Crossfire::Client::Widget::Bin::; |
309 | our @ISA = Crossfire::Client::Widget::Bin::; |
274 | |
310 | |
275 | use SDL::OpenGL; |
311 | use SDL::OpenGL; |
276 | |
312 | |
277 | sub size_request { |
313 | sub size_request { |
278 | my ($self) = @_; |
314 | my ($self) = @_; |
279 | my $chld = $self->get |
315 | my $chld = $self->child |
280 | or return (0, 0); |
316 | or return (0, 0); |
281 | |
317 | |
282 | $chld->move (2, 2); |
318 | $chld->move (2, 2); |
283 | |
319 | |
284 | map { $_ + 4 } $chld->size_request; |
320 | map { $_ + 4 } $chld->size_request; |
285 | } |
321 | } |
286 | |
322 | |
287 | sub size_allocate { |
323 | sub size_allocate { |
288 | my ($self, $w, $h) = @_; |
324 | my ($self, $w, $h) = @_; |
289 | |
325 | |
290 | $self->w ($w); |
326 | $self->{w} = $w; |
291 | $self->h ($h); |
327 | $self->{h} = $h; |
292 | |
328 | |
293 | $self->get->size_allocate ($w - 4, $h - 4); |
329 | $self->child->size_allocate ($w - 4, $h - 4); |
294 | $self->get->move (2, 2); |
330 | $self->child->move (2, 2); |
295 | } |
331 | } |
296 | |
332 | |
297 | sub _draw { |
333 | sub _draw { |
298 | my ($self) = @_; |
334 | my ($self) = @_; |
299 | |
335 | |
300 | my $chld = $self->get; |
336 | my $chld = $self->child; |
301 | |
337 | |
302 | my ($w, $h) = $chld->size_request; |
338 | my ($w, $h) = $chld->size_request; |
303 | |
339 | |
304 | glBegin GL_QUADS; |
340 | glBegin GL_QUADS; |
305 | glColor 0, 0, 0; |
341 | glColor 0, 0, 0; |
… | |
… | |
310 | glEnd; |
346 | glEnd; |
311 | |
347 | |
312 | $chld->draw; |
348 | $chld->draw; |
313 | } |
349 | } |
314 | |
350 | |
|
|
351 | ############################################################################# |
|
|
352 | |
315 | package Crossfire::Client::Widget::FancyFrame; |
353 | package Crossfire::Client::Widget::FancyFrame; |
316 | |
354 | |
317 | our @ISA = Crossfire::Client::Widget::Frame::; |
355 | our @ISA = Crossfire::Client::Widget::Bin::; |
318 | |
356 | |
319 | use SDL::OpenGL; |
357 | use SDL::OpenGL; |
320 | |
358 | |
321 | sub new { |
359 | 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 $_ } |
360 | 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/ |
361 | 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 | |
362 | |
332 | sub size_request { |
363 | sub size_request { |
333 | my ($self) = @_; |
364 | my ($self) = @_; |
|
|
365 | |
334 | my ($w, $h) = $self->get->size_request; |
366 | my ($w, $h) = $self->SUPER::size_request; |
335 | |
367 | |
336 | $h += $self->{txts}->[1]->{height}; |
368 | $h += $tex[1]->{height}; |
337 | $h += $self->{txts}->[4]->{height}; |
369 | $h += $tex[4]->{height}; |
338 | $w += $self->{txts}->[2]->{width}; |
370 | $w += $tex[2]->{width}; |
339 | $w += $self->{txts}->[3]->{width}; |
371 | $w += $tex[3]->{width}; |
340 | |
372 | |
341 | ($w, $h) |
373 | ($w, $h) |
342 | } |
374 | } |
343 | |
375 | |
344 | sub size_allocate { |
376 | sub size_allocate { |
345 | my ($self, $w, $h) = @_; |
377 | my ($self, $w, $h) = @_; |
346 | |
378 | |
347 | $self->w ($w); |
379 | $self->SUPER::size_allocate ($w, $h); |
348 | $self->h ($h); |
380 | |
349 | $h -= $self->{txts}->[1]->{height}; |
381 | $h -= $tex[1]->{height}; |
350 | $h -= $self->{txts}->[4]->{height}; |
382 | $h -= $tex[4]->{height}; |
351 | $w -= $self->{txts}->[2]->{width}; |
383 | $w -= $tex[2]->{width}; |
352 | $w -= $self->{txts}->[3]->{width}; |
384 | $w -= $tex[3]->{width}; |
353 | |
385 | |
354 | $h = $h < 0 ? 0 : $h; |
386 | $h = $h < 0 ? 0 : $h; |
355 | $w = $w < 0 ? 0 : $w; |
387 | $w = $w < 0 ? 0 : $w; |
356 | warn "CHILD:$w $h\n"; |
388 | |
357 | $self->get->size_allocate ($w, $h); |
389 | $self->child->size_allocate ($w, $h); |
358 | $self->get->move ($self->{txts}->[3]->{width}, $self->{txts}->[1]->{height}); |
390 | $self->child->move ($tex[3]->{width}, $tex[1]->{height}); |
359 | } |
391 | } |
360 | |
392 | |
361 | sub _draw { |
393 | sub _draw { |
362 | my ($self) = @_; |
394 | my ($self) = @_; |
363 | |
395 | |
364 | my ($w, $h) = ($self->w, $self->h); |
396 | my ($w, $h) = ($self->{w}, $self->{h}); |
365 | my ($cw, $ch) = ($self->get->w, $self->get->h); |
397 | my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); |
366 | |
398 | |
367 | glEnable GL_BLEND; |
399 | glEnable GL_BLEND; |
368 | glEnable GL_TEXTURE_2D; |
400 | glEnable GL_TEXTURE_2D; |
369 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
401 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
370 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
402 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
371 | |
403 | |
372 | my $top = $self->{txts}->[1]; |
404 | my $top = $tex[1]; |
373 | glBindTexture GL_TEXTURE_2D, $top->{name}; |
405 | glBindTexture GL_TEXTURE_2D, $top->{name}; |
374 | |
406 | |
375 | glBegin GL_QUADS; |
407 | glBegin GL_QUADS; |
376 | glTexCoord 0, 0; glVertex 0 , 0; |
408 | glTexCoord 0, 0; glVertex 0 , 0; |
377 | glTexCoord 0, 1; glVertex 0 , $top->{height}; |
409 | glTexCoord 0, 1; glVertex 0 , $top->{height}; |
378 | glTexCoord 1, 1; glVertex $w , $top->{height}; |
410 | glTexCoord 1, 1; glVertex $w , $top->{height}; |
379 | glTexCoord 1, 0; glVertex $w , 0; |
411 | glTexCoord 1, 0; glVertex $w , 0; |
380 | glEnd; |
412 | glEnd; |
381 | |
413 | |
382 | my $left = $self->{txts}->[3]; |
414 | my $left = $tex[3]; |
383 | glBindTexture GL_TEXTURE_2D, $left->{name}; |
415 | glBindTexture GL_TEXTURE_2D, $left->{name}; |
384 | |
416 | |
385 | glBegin GL_QUADS; |
417 | glBegin GL_QUADS; |
386 | glTexCoord 0, 0; glVertex 0 , $top->{height}; |
418 | glTexCoord 0, 0; glVertex 0 , $top->{height}; |
387 | glTexCoord 0, 1; glVertex 0 , $top->{height} + $ch; |
419 | glTexCoord 0, 1; glVertex 0 , $top->{height} + $ch; |
388 | glTexCoord 1, 1; glVertex $left->{width}, $top->{height} + $ch; |
420 | glTexCoord 1, 1; glVertex $left->{width}, $top->{height} + $ch; |
389 | glTexCoord 1, 0; glVertex $left->{width}, $top->{height}; |
421 | glTexCoord 1, 0; glVertex $left->{width}, $top->{height}; |
390 | glEnd; |
422 | glEnd; |
391 | |
423 | |
392 | my $right = $self->{txts}->[2]; |
424 | my $right = $tex[2]; |
393 | glBindTexture GL_TEXTURE_2D, $right->{name}; |
425 | glBindTexture GL_TEXTURE_2D, $right->{name}; |
394 | |
426 | |
395 | glBegin GL_QUADS; |
427 | glBegin GL_QUADS; |
396 | glTexCoord 0, 0; glVertex $w - $right->{width}, $top->{height}; |
428 | glTexCoord 0, 0; glVertex $w - $right->{width}, $top->{height}; |
397 | glTexCoord 0, 1; glVertex $w - $right->{width}, $top->{height} + $ch; |
429 | glTexCoord 0, 1; glVertex $w - $right->{width}, $top->{height} + $ch; |
398 | glTexCoord 1, 1; glVertex $w , $top->{height} + $ch; |
430 | glTexCoord 1, 1; glVertex $w , $top->{height} + $ch; |
399 | glTexCoord 1, 0; glVertex $w , $top->{height}; |
431 | glTexCoord 1, 0; glVertex $w , $top->{height}; |
400 | glEnd; |
432 | glEnd; |
401 | |
433 | |
402 | my $bottom = $self->{txts}->[4]; |
434 | my $bottom = $tex[4]; |
403 | glBindTexture GL_TEXTURE_2D, $bottom->{name}; |
435 | glBindTexture GL_TEXTURE_2D, $bottom->{name}; |
404 | |
436 | |
405 | glBegin GL_QUADS; |
437 | glBegin GL_QUADS; |
406 | glTexCoord 0, 0; glVertex 0 , $h - $bottom->{height}; |
438 | glTexCoord 0, 0; glVertex 0 , $h - $bottom->{height}; |
407 | glTexCoord 0, 1; glVertex 0 , $h; |
439 | glTexCoord 0, 1; glVertex 0 , $h; |
408 | glTexCoord 1, 1; glVertex $w , $h; |
440 | glTexCoord 1, 1; glVertex $w , $h; |
409 | glTexCoord 1, 0; glVertex $w , $h - $bottom->{height}; |
441 | glTexCoord 1, 0; glVertex $w , $h - $bottom->{height}; |
410 | glEnd; |
442 | glEnd; |
411 | |
443 | |
412 | my $bg = $self->{txts}->[0]; |
444 | my $bg = $tex[0]; |
413 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
445 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
414 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
446 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
415 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; |
447 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; |
416 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; |
448 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; |
417 | |
449 | |
… | |
… | |
426 | glEnd; |
458 | glEnd; |
427 | |
459 | |
428 | glDisable GL_BLEND; |
460 | glDisable GL_BLEND; |
429 | glDisable GL_TEXTURE_2D; |
461 | glDisable GL_TEXTURE_2D; |
430 | |
462 | |
431 | $self->get->draw; |
463 | $self->child->draw; |
432 | |
464 | |
433 | } |
465 | } |
|
|
466 | |
|
|
467 | ############################################################################# |
434 | |
468 | |
435 | package Crossfire::Client::Widget::Table; |
469 | package Crossfire::Client::Widget::Table; |
436 | |
470 | |
437 | our @ISA = Crossfire::Client::Widget::Bin::; |
471 | our @ISA = Crossfire::Client::Widget::Bin::; |
438 | |
472 | |
439 | use SDL::OpenGL; |
473 | use SDL::OpenGL; |
440 | |
474 | |
441 | sub add { |
475 | sub add { |
442 | my ($self, $x, $y, $chld) = @_; |
476 | my ($self, $x, $y, $chld) = @_; |
443 | my $old_chld = $self->{childs}[$y][$x]; |
477 | my $old_chld = $self->{children}[$y][$x]; |
444 | |
478 | |
445 | $self->{childs}[$y][$x] = $chld; |
479 | $self->{children}[$y][$x] = $chld; |
446 | $chld->set_parent ($self); |
480 | $chld->set_parent ($self); |
447 | $self->update; |
481 | $self->update; |
448 | } |
482 | } |
449 | |
483 | |
450 | sub max_row_height { |
484 | sub max_row_height { |
451 | my ($self, $row) = @_; |
485 | my ($self, $row) = @_; |
452 | |
486 | |
453 | my $hs = 0; |
487 | my $hs = 0; |
454 | for (my $xi = 0; $xi <= $#{$self->{childs}->[$row] || []}; $xi++) { |
488 | for (my $xi = 0; $xi <= $#{$self->{children}->[$row] || []}; $xi++) { |
455 | my $c = $self->{childs}->[$row]->[$xi]; |
489 | my $c = $self->{children}->[$row]->[$xi]; |
456 | if ($c) { |
490 | if ($c) { |
457 | my ($w, $h) = $c->size_request; |
491 | my ($w, $h) = $c->size_request; |
458 | if ($hs < $h) { $hs = $h } |
492 | if ($hs < $h) { $hs = $h } |
459 | } |
493 | } |
460 | } |
494 | } |
… | |
… | |
463 | |
497 | |
464 | sub max_col_width { |
498 | sub max_col_width { |
465 | my ($self, $col) = @_; |
499 | my ($self, $col) = @_; |
466 | |
500 | |
467 | my $ws = 0; |
501 | my $ws = 0; |
468 | for (my $yi = 0; $yi <= $#{$self->{childs} || []}; $yi++) { |
502 | for (my $yi = 0; $yi <= $#{$self->{children} || []}; $yi++) { |
469 | my $c = ($self->{childs}->[$yi] || [])->[$col]; |
503 | my $c = ($self->{children}->[$yi] || [])->[$col]; |
470 | if ($c) { |
504 | if ($c) { |
471 | my ($w, $h) = $c->size_request; |
505 | my ($w, $h) = $c->size_request; |
472 | if ($ws < $w) { $ws = $w } |
506 | if ($ws < $w) { $ws = $w } |
473 | } |
507 | } |
474 | } |
508 | } |
… | |
… | |
478 | sub size_request { |
512 | sub size_request { |
479 | my ($self) = @_; |
513 | my ($self) = @_; |
480 | |
514 | |
481 | my ($hs, $ws) = (0, 0); |
515 | my ($hs, $ws) = (0, 0); |
482 | |
516 | |
483 | for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) { |
517 | for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) { |
484 | $hs += $self->max_row_height ($yi); |
518 | $hs += $self->max_row_height ($yi); |
485 | } |
519 | } |
486 | |
520 | |
487 | for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) { |
521 | for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) { |
488 | my $wm = 0; |
522 | my $wm = 0; |
489 | for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) { |
523 | for (my $xi = 0; $xi <= $#{$self->{children}->[$yi]}; $xi++) { |
490 | $wm += $self->max_col_width ($xi) |
524 | $wm += $self->max_col_width ($xi) |
491 | } |
525 | } |
492 | if ($ws < $wm) { $ws = $wm } |
526 | if ($ws < $wm) { $ws = $wm } |
493 | } |
527 | } |
494 | |
528 | |
… | |
… | |
497 | |
531 | |
498 | sub _draw { |
532 | sub _draw { |
499 | my ($self) = @_; |
533 | my ($self) = @_; |
500 | |
534 | |
501 | my $y = 0; |
535 | my $y = 0; |
502 | for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) { |
536 | for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) { |
503 | my $x = 0; |
537 | my $x = 0; |
504 | |
538 | |
505 | for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) { |
539 | for (my $xi = 0; $xi <= $#{$self->{children}->[$yi]}; $xi++) { |
506 | |
540 | |
507 | my $c = $self->{childs}->[$yi]->[$xi]; |
541 | my $c = $self->{children}->[$yi]->[$xi]; |
508 | if ($c) { |
542 | if ($c) { |
509 | $c->move ($x, $y, 0); #TODO: Move to size_request |
543 | $c->move ($x, $y, 0); #TODO: Move to size_request |
510 | $c->draw if $c; |
544 | $c->draw if $c; |
511 | } |
545 | } |
512 | |
546 | |
… | |
… | |
515 | |
549 | |
516 | $y += $self->max_row_height ($yi); |
550 | $y += $self->max_row_height ($yi); |
517 | } |
551 | } |
518 | } |
552 | } |
519 | |
553 | |
|
|
554 | ############################################################################# |
|
|
555 | |
520 | package Crossfire::Client::Widget::VBox; |
556 | package Crossfire::Client::Widget::VBox; |
521 | |
557 | |
522 | our @ISA = Crossfire::Client::Widget::Bin::; |
558 | our @ISA = Crossfire::Client::Widget::Container::; |
523 | |
559 | |
524 | use SDL::OpenGL; |
560 | use SDL::OpenGL; |
525 | |
561 | |
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 { |
562 | sub size_request { |
535 | my ($self) = @_; |
563 | my ($self) = @_; |
536 | |
564 | |
537 | my ($hs, $ws) = (0, 0); |
565 | my @alloc = map [$_->size_request], @{$self->{children}}; |
538 | for (@{$self->{childs} || []}) { |
566 | |
539 | my ($w, $h) = $_->size_request; |
|
|
540 | $hs += $h; |
|
|
541 | if ($ws < $w) { $ws = $w } |
|
|
542 | } |
567 | ( |
543 | |
568 | (List::Util::max map $_->[0], @alloc), |
544 | return ($ws, $hs); |
569 | (List::Util::sum map $_->[1], @alloc), |
|
|
570 | ) |
545 | } |
571 | } |
546 | |
572 | |
547 | sub size_allocate { |
573 | sub size_allocate { |
548 | my ($self, $w, $h) = @_; |
574 | my ($self, $w, $h) = @_; |
549 | |
575 | |
… | |
… | |
551 | $self->h ($h); |
577 | $self->h ($h); |
552 | |
578 | |
553 | my $exp; |
579 | my $exp; |
554 | my @oth; |
580 | my @oth; |
555 | # find expand widget |
581 | # find expand widget |
556 | for (@{$self->{childs}}) { |
582 | for (@{$self->{children}}) { |
557 | if ($_->{expand}) { |
583 | if ($_->{expand}) { |
558 | $exp = $_; |
584 | $exp = $_; |
559 | last; |
585 | last; |
560 | } |
586 | } |
561 | push @oth, $_; |
587 | push @oth, $_; |
… | |
… | |
569 | $oh += $h; |
595 | $oh += $h; |
570 | if ($ow < $w) { $ow = $w } |
596 | if ($ow < $w) { $ow = $w } |
571 | } |
597 | } |
572 | |
598 | |
573 | my $y = 0; |
599 | my $y = 0; |
574 | for (@{$self->{childs}}) { |
600 | for (@{$self->{children}}) { |
575 | $_->move (0, $y); |
601 | $_->move (0, $y); |
576 | |
602 | |
577 | if ($_ == $exp) { |
603 | if ($_ == $exp) { |
578 | $_->size_allocate ($w, $h - $oh); |
604 | $_->size_allocate ($w, $h - $oh); |
579 | $y += $h - $oh; |
605 | $y += $h - $oh; |
… | |
… | |
583 | $y += $h; |
609 | $y += $h; |
584 | } |
610 | } |
585 | } |
611 | } |
586 | } |
612 | } |
587 | |
613 | |
588 | sub _draw { |
614 | ############################################################################# |
589 | my ($self) = @_; |
|
|
590 | |
|
|
591 | my ($x, $y); |
|
|
592 | for (@{$self->{childs} || []}) { |
|
|
593 | $_->draw; |
|
|
594 | $y += $_->h; |
|
|
595 | } |
|
|
596 | } |
|
|
597 | |
615 | |
598 | package Crossfire::Client::Widget::Label; |
616 | package Crossfire::Client::Widget::Label; |
599 | |
617 | |
600 | our @ISA = Crossfire::Client::Widget::; |
618 | our @ISA = Crossfire::Client::Widget::; |
601 | |
619 | |
… | |
… | |
658 | |
676 | |
659 | glDisable GL_BLEND; |
677 | glDisable GL_BLEND; |
660 | glDisable GL_TEXTURE_2D; |
678 | glDisable GL_TEXTURE_2D; |
661 | } |
679 | } |
662 | |
680 | |
|
|
681 | ############################################################################# |
|
|
682 | |
663 | package Crossfire::Client::Widget::TextEntry; |
683 | package Crossfire::Client::Widget::TextEntry; |
664 | |
684 | |
665 | our @ISA = Crossfire::Client::Widget::Label::; |
685 | our @ISA = Crossfire::Client::Widget::Label::; |
666 | |
686 | |
667 | use SDL; |
687 | use SDL; |
… | |
… | |
684 | } elsif ($uni) { |
704 | } elsif ($uni) { |
685 | $text .= chr $uni; |
705 | $text .= chr $uni; |
686 | } |
706 | } |
687 | $self->set_text ($text); |
707 | $self->set_text ($text); |
688 | } |
708 | } |
|
|
709 | |
|
|
710 | ############################################################################# |
689 | |
711 | |
690 | package Crossfire::Client::Widget::MapWidget; |
712 | package Crossfire::Client::Widget::MapWidget; |
691 | |
713 | |
692 | use strict; |
714 | use strict; |
693 | |
715 | |
… | |
… | |
860 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
882 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
861 | $::CONN->send ("command run_stop"); |
883 | $::CONN->send ("command run_stop"); |
862 | } |
884 | } |
863 | } |
885 | } |
864 | |
886 | |
|
|
887 | ############################################################################# |
|
|
888 | |
865 | package Crossfire::Client::Widget::Animator; |
889 | package Crossfire::Client::Widget::Animator; |
866 | |
890 | |
867 | use SDL::OpenGL; |
891 | use SDL::OpenGL; |
868 | |
892 | |
869 | our @ISA = Crossfire::Client::Widget::Bin::; |
893 | our @ISA = Crossfire::Client::Widget::Bin::; |
… | |
… | |
896 | sub _draw { |
920 | sub _draw { |
897 | my ($self) = @_; |
921 | my ($self) = @_; |
898 | |
922 | |
899 | glPushMatrix; |
923 | glPushMatrix; |
900 | glRotate $self->{time} * 10000, 0, 1, 0; |
924 | glRotate $self->{time} * 10000, 0, 1, 0; |
901 | $self->{child}->draw; |
925 | $self->{children}[0]->draw; |
902 | glPopMatrix; |
926 | glPopMatrix; |
903 | } |
927 | } |
904 | |
928 | |
905 | 1; |
929 | 1; |
906 | |
930 | |