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.41 by root, Sun Apr 9 21:50:21 2006 UTC vs.
Revision 1.50 by root, Sun Apr 9 22:27:24 2006 UTC

7use SDL::OpenGL; 7use SDL::OpenGL;
8use SDL::OpenGL::Constants; 8use SDL::OpenGL::Constants;
9 9
10use Crossfire::Client; 10use Crossfire::Client;
11 11
12our $FOCUS; # the widget with current focus
13
14# class methods for events 12# class methods for events
15sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS } 13sub feed_sdl_key_down_event { $::FOCUS->key_down ($_[0]) if $::FOCUS }
16sub feed_sdl_key_up_event { $FOCUS->key_up ($_[0]) if $FOCUS } 14sub feed_sdl_key_up_event { $::FOCUS->key_up ($_[0]) if $::FOCUS }
17sub feed_sdl_button_down_event { } 15sub feed_sdl_button_down_event { }
18sub feed_sdl_button_up_event { } 16sub feed_sdl_button_up_event { }
19 17
20sub new { 18sub new {
21 my $class = shift; 19 my $class = shift;
46 $self->{h} = $h; 44 $self->{h} = $h;
47} 45}
48 46
49sub focus_in { 47sub focus_in {
50 my ($widget) = @_; 48 my ($widget) = @_;
51 $FOCUS = $widget; 49 $::FOCUS = $widget;
52} 50}
53 51
54sub focus_out { 52sub focus_out {
55 my ($widget) = @_; 53 my ($widget) = @_;
56} 54}
81 my ($self) = @_; 79 my ($self) = @_;
82 80
83 glPushMatrix; 81 glPushMatrix;
84 glTranslate $self->{x}, $self->{y}, 0; 82 glTranslate $self->{x}, $self->{y}, 0;
85 $self->_draw; 83 $self->_draw;
84 if ($self == $::HOVER) {
85 glColor 1, 1, 1, 0.4;
86 glEnable GL_BLEND;
87 glBegin GL_QUADS;
88 glVertex 0, 0;
89 glVertex $self->{w} - 1, 0;
90 glVertex $self->{w} - 1, $self->{h} - 1;
91 glVertex 0, $self->{h} - 1;
92 glEnd;
93 glDisable GL_BLEND;
94 }
86 glPopMatrix; 95 glPopMatrix;
87} 96}
88 97
89sub _draw { 98sub _draw {
90 my ($self) = @_; 99 my ($self) = @_;
162 171
163 @{$self->{children}} = 172 @{$self->{children}} =
164 sort { $a->{z} <=> $b->{z} } 173 sort { $a->{z} <=> $b->{z} }
165 @{$self->{children}}, $chld; 174 @{$self->{children}}, $chld;
166 175
167 $self->size_allocate ($self->{w}, $self->{h}); 176 $self->size_allocate ($self->{w}, $self->{h})
177 if $self->{w}; #TODO: check for "realised state"
168} 178}
169 179
170sub remove { 180sub remove {
171 my ($self, $widget) = @_; 181 my ($self, $widget) = @_;
172 182
176} 186}
177 187
178sub find_widget { 188sub find_widget {
179 my ($self, $x, $y) = @_; 189 my ($self, $x, $y) = @_;
180 190
191 $x -= $self->{x};
192 $y -= $self->{y};
193
181 my $res; 194 my $res;
182 195
183 for (@{ $self->{children} }) { 196 for (reverse @{ $self->{children} }) {
184 $res = $_->find_widget ($x, $y) 197 $res = $_->find_widget ($x, $y)
185 and return $res; 198 and return $res;
186 } 199 }
187 200
188 () 201 $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y})
189}
190
191sub 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} 202}
203 203
204sub _draw { 204sub _draw {
205 my ($self) = @_; 205 my ($self) = @_;
206 206
219 $_[0]{children}[0]->size_request if $_[0]{children}[0]; 219 $_[0]{children}[0]->size_request if $_[0]{children}[0];
220} 220}
221 221
222sub size_allocate { 222sub size_allocate {
223 my ($self, $w, $h) = @_; 223 my ($self, $w, $h) = @_;
224
224 $self->SUPER::size_allocate ($w, $h); 225 $self->SUPER::size_allocate ($w, $h);
225 $self->{children}[0]->size_allocate ($w, $h) 226 $self->{children}[0]->size_allocate ($w, $h)
226 if $self->{children}[0] 227 if $self->{children}[0]
227} 228}
228 229
236 my ($self) = @_; 237 my ($self) = @_;
237 238
238 ::refresh (); 239 ::refresh ();
239} 240}
240 241
242sub add {
243 my ($self, $widget) = @_;
244
245 $self->SUPER::add ($widget);
246
247 $widget->size_allocate ($widget->size_request);
248}
249
241############################################################################# 250#############################################################################
242 251
243package Crossfire::Client::Widget::Window; 252package Crossfire::Client::Widget::Window;
244 253
245our @ISA = Crossfire::Client::Widget::Bin::; 254our @ISA = Crossfire::Client::Widget::Bin::;
246 255
247use SDL::OpenGL; 256use SDL::OpenGL;
248 257
249sub add { 258sub new {
250 my ($self, $chld) = @_; 259 my ($class, $x, $y, $z, $w, $h) = @_;
251 warn "ADD $chld\n";
252 $self->SUPER::add ($chld);
253 $chld->set_parent ($self);
254}
255 260
256sub remove { 261 my $self = $class->SUPER::new;
257 my ($self) = @_; 262
258 # TODO FIXME: removing a child from a window will crash, see render_chld 263 @$self{qw(x y z w h)} = ($x, $y, $z, $w, $h);
259 # $self->update;
260} 264}
261 265
262sub update { 266sub update {
263 my ($self) = @_; 267 my ($self) = @_;
268
264 $self->render_chld; 269 $self->render_chld;
270 $self->SUPER::update;
265} 271}
266 272
267sub render_chld { 273sub render_chld {
268 my ($self) = @_; 274 my ($self) = @_;
269 my $chld = $self->get;
270 my ($w, $h) = $self->size_request;
271 275
272 require Carp;
273 Carp::cluck "RENDERCHI $w $h";
274 warn "RENDERCHI $w $h\n";
275 $self->{texture} = 276 $self->{texture} =
276 Crossfire::Client::Texture->new_from_opengl ( 277 Crossfire::Client::Texture->new_from_opengl (
277 $w, $h, sub { $chld->draw } 278 $self->{w}, $self->{h}, sub { $self->child->draw }
278 ); 279 );
279 $self->{texture}->upload;
280}
281
282sub size_request {
283 my ($self) = @_;
284 ($self->w, $self->h)
285} 280}
286 281
287sub size_allocate { 282sub size_allocate {
288 my ($self, $w, $h) = @_; 283 my ($self, $w, $h) = @_;
289 284
290 $self->w ($w); 285 $self->{w} = $w;
291 $self->h ($h); 286 $self->{h} = $h;
287
292 $self->get->size_allocate ($w, $h); 288 $self->child->size_allocate ($w, $h);
293 289
294 $self->update; #TODO: Move this to the size_request event propably? 290 $self->render_chld;
295} 291}
296 292
297sub _draw { 293sub _draw {
298 my ($self) = @_; 294 my ($self) = @_;
299 295
336 map { $_ + 4 } $chld->size_request; 332 map { $_ + 4 } $chld->size_request;
337} 333}
338 334
339sub size_allocate { 335sub size_allocate {
340 my ($self, $w, $h) = @_; 336 my ($self, $w, $h) = @_;
341 337
342 $self->SUPER::size_allocate ($w, $h); 338 $self->{w} = $w;
339 $self->{h} = $h;
343 340
344 $self->child->size_allocate ($w - 4, $h - 4); 341 $self->child->size_allocate ($w - 4, $h - 4);
345 $self->child->move (2, 2); 342 $self->child->move (2, 2);
346} 343}
347 344
398 $w -= $tex[2]->{width}; 395 $w -= $tex[2]->{width};
399 $w -= $tex[3]->{width}; 396 $w -= $tex[3]->{width};
400 397
401 $h = $h < 0 ? 0 : $h; 398 $h = $h < 0 ? 0 : $h;
402 $w = $w < 0 ? 0 : $w; 399 $w = $w < 0 ? 0 : $w;
403 warn "CHILD:$w $h\n"; 400
404 $self->child->size_allocate ($w, $h); 401 $self->child->size_allocate ($w, $h);
405 $self->child->move ($self->{txts}->[3]->{width}, $self->{txts}->[1]->{height}); 402 $self->child->move ($tex[3]->{width}, $tex[1]->{height});
406} 403}
407 404
408sub _draw { 405sub _draw {
409 my ($self) = @_; 406 my ($self) = @_;
410 407
411 my ($w, $h) = ($self->w, $self->h); 408 my ($w, $h) = ($self->{w}, $self->{h});
412 my ($cw, $ch) = ($self->child->w, $self->child->h); 409 my ($cw, $ch) = ($self->child->{w}, $self->child->{h});
413 410
414 glEnable GL_BLEND; 411 glEnable GL_BLEND;
415 glEnable GL_TEXTURE_2D; 412 glEnable GL_TEXTURE_2D;
416 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 413 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
417 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 414 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
571package Crossfire::Client::Widget::VBox; 568package Crossfire::Client::Widget::VBox;
572 569
573our @ISA = Crossfire::Client::Widget::Container::; 570our @ISA = Crossfire::Client::Widget::Container::;
574 571
575use SDL::OpenGL; 572use SDL::OpenGL;
573
574sub size_request {
575 my ($self) = @_;
576
577 my @alloc = map [$_->size_request], @{$self->{children}};
578
579 (
580 (List::Util::max map $_->[0], @alloc),
581 (List::Util::sum map $_->[1], @alloc),
582 )
583}
576 584
577sub size_allocate { 585sub size_allocate {
578 my ($self, $w, $h) = @_; 586 my ($self, $w, $h) = @_;
579 587
580 $self->w ($w); 588 $self->w ($w);
610 } else { 618 } else {
611 my ($cw, $h) = $_->size_request; 619 my ($cw, $h) = $_->size_request;
612 $_->size_allocate ($w, $h); 620 $_->size_allocate ($w, $h);
613 $y += $h; 621 $y += $h;
614 } 622 }
615 }
616}
617
618sub _draw {
619 my ($self) = @_;
620
621 my ($x, $y);
622 for (@{$self->{children} || []}) {
623 $_->draw;
624 $y += $_->h;
625 } 623 }
626} 624}
627 625
628############################################################################# 626#############################################################################
629 627

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines