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.414 by root, Mon Jul 23 17:54:14 2007 UTC vs.
Revision 1.419 by root, Tue Jul 24 19:32:21 2007 UTC

273 $self->emit ("destroy"); 273 $self->emit ("destroy");
274 %$self = (); 274 %$self = ();
275} 275}
276 276
277sub TO_JSON { 277sub TO_JSON {
278 { __widget_ref__ => $_[0]{s_id} } 278 { __w_ => $_[0]{s_id} }
279} 279}
280 280
281sub show { 281sub show {
282 my ($self) = @_; 282 my ($self) = @_;
283 283
2074 my $class = shift; 2074 my $class = shift;
2075 2075
2076 $class->SUPER::new ( 2076 $class->SUPER::new (
2077 fg => [1, 1, 1], 2077 fg => [1, 1, 1],
2078 bg => [0, 0, 0, 0.2], 2078 bg => [0, 0, 0, 0.2],
2079 active_bg => [1, 1, 1, 0.5], 2079 active_bg => [0, 0, 1, .2],
2080 active_fg => [0, 0, 0], 2080 active_fg => [1, 1, 1],
2081 active_outline => [1, 1, 0],
2081 can_hover => 1, 2082 can_hover => 1,
2082 can_focus => 1, 2083 can_focus => 1,
2083 valign => 0, 2084 valign => 0,
2084 can_events => 1, 2085 can_events => 1,
2085 ellipsise => 0, 2086 ellipsise => 0,
2242 2243
2243 unless (exists $self->{cur_h}) { 2244 unless (exists $self->{cur_h}) {
2244 my $text = substr $self->{text}, 0, $self->{cursor}; 2245 my $text = substr $self->{text}, 0, $self->{cursor};
2245 utf8::encode $text; 2246 utf8::encode $text;
2246 2247
2247 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text) 2248 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text);
2248 } 2249 }
2249 2250
2251 glColor_premultiply @{$self->{active_fg}};
2250 glBegin GL_LINES; 2252 glBegin GL_LINES;
2251 glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; 2253 glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy};
2252 glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; 2254 glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h};
2253 glEnd; 2255 glEnd;
2256
2257 glLineWidth 3;
2258 glColor @{$self->{active_outline}};
2259 glTranslate -.375, -.375;
2260 glBegin GL_LINE_LOOP;
2261 glVertex 0, 0;
2262 glVertex $self->{w}, 0;
2263 glVertex $self->{w}, $self->{h};
2264 glVertex 0, $self->{h};
2265 glEnd;
2266 glLineWidth 1;
2254 } 2267 }
2255} 2268}
2256 2269
2257############################################################################# 2270#############################################################################
2258 2271
2344 1 2357 1
2345} 2358}
2346 2359
2347############################################################################# 2360#############################################################################
2348 2361
2362package CFPlus::UI::ButtonBin;
2363
2364our @ISA = CFPlus::UI::Bin::;
2365
2366use CFPlus::OpenGL;
2367
2368my @tex =
2369 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2370 qw(b1_button_inactive.png b1_button_active.png);
2371
2372sub new {
2373 my $class = shift;
2374
2375 $class->SUPER::new (
2376 can_hover => 1,
2377 align => 0,
2378 valign => 0,
2379 can_events => 1,
2380 @_
2381 )
2382}
2383
2384sub invoke_button_up {
2385 my ($self, $ev, $x, $y) = @_;
2386
2387 $self->emit ("activate")
2388 if $x >= 0 && $x < $self->{w}
2389 && $y >= 0 && $y < $self->{h};
2390
2391 1
2392}
2393
2394sub _draw {
2395 my ($self) = @_;
2396
2397 glEnable GL_TEXTURE_2D;
2398 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2399 glColor 0, 0, 0, 1;
2400
2401 my $tex = $tex[$GRAB == $self];
2402 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
2403
2404 glDisable GL_TEXTURE_2D;
2405
2406 $self->SUPER::_draw;
2407}
2408
2409#############################################################################
2410
2349package CFPlus::UI::Button; 2411package CFPlus::UI::Button;
2350 2412
2351our @ISA = CFPlus::UI::Label::; 2413our @ISA = CFPlus::UI::Label::;
2352 2414
2353use CFPlus::OpenGL; 2415use CFPlus::OpenGL;
2487sub new { 2549sub new {
2488 my $class = shift; 2550 my $class = shift;
2489 2551
2490 my $self = $class->SUPER::new ( 2552 my $self = $class->SUPER::new (
2491 can_events => 0, 2553 can_events => 0,
2554 scale => 1,
2492 @_, 2555 @_,
2493 ); 2556 );
2494 2557
2495 $self->{path} || $self->{tex} 2558 $self->{path} || $self->{tex}
2496 or Carp::croak "'path' or 'tex' attributes required"; 2559 or Carp::croak "'path' or 'tex' attributes required";
2521} 2584}
2522 2585
2523sub size_request { 2586sub size_request {
2524 my ($self) = @_; 2587 my ($self) = @_;
2525 2588
2526 ($self->{tex}{w}, $self->{tex}{h}) 2589 (int $self->{tex}{w} * $self->{scale}, int $self->{tex}{h} * $self->{scale})
2527} 2590}
2528 2591
2529sub _draw { 2592sub _draw {
2530 my ($self) = @_; 2593 my ($self) = @_;
2531 2594
2541 } 2604 }
2542 2605
2543 glEnable GL_TEXTURE_2D; 2606 glEnable GL_TEXTURE_2D;
2544 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2607 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2545 2608
2546 $tex->draw_quad (0, 0, $w, $h); 2609 $tex->draw_quad_alpha (0, 0, $w, $h);
2547 2610
2548 glDisable GL_TEXTURE_2D; 2611 glDisable GL_TEXTURE_2D;
2549} 2612}
2550 2613
2551############################################################################# 2614#############################################################################
3425 glTranslate 0.375, 0.375; 3488 glTranslate 0.375, 0.375;
3426 3489
3427 my ($w, $h) = @$self{qw(w h)}; 3490 my ($w, $h) = @$self{qw(w h)};
3428 3491
3429 glColor 1, 0.8, 0.4; 3492 glColor 1, 0.8, 0.4;
3430 glBegin GL_QUADS; 3493 glRect 0, 0, $w, $h;
3431 glVertex 0 , 0;
3432 glVertex 0 , $h;
3433 glVertex $w, $h;
3434 glVertex $w, 0;
3435 glEnd;
3436 3494
3437 glColor 0, 0, 0; 3495 glColor 0, 0, 0;
3438 glBegin GL_LINE_LOOP; 3496 glBegin GL_LINE_LOOP;
3439 glVertex 0 , 0; 3497 glVertex 0 , 0;
3440 glVertex 0 , $h; 3498 glVertex 0 , $h;
3622 children => [ 3680 children => [
3623 (new CFPlus::UI::Label markup => $left, expand => 1), 3681 (new CFPlus::UI::Label markup => $left, expand => 1),
3624 (new CFPlus::UI::Label markup => $right, align => +1), 3682 (new CFPlus::UI::Label markup => $right, align => +1),
3625 ], 3683 ],
3626 ; 3684 ;
3627 3685
3628 } else { 3686 } else {
3629 $widget = new CFPlus::UI::Label 3687 $widget = new CFPlus::UI::Label
3630 can_hover => 1, 3688 can_hover => 1,
3631 can_events => 1, 3689 can_events => 1,
3632 markup => $widget, 3690 markup => $widget,
3768 buttonbar => (new CFPlus::UI::Buttonbar), 3826 buttonbar => (new CFPlus::UI::Buttonbar),
3769 multiplexer => (new CFPlus::UI::Multiplexer expand => 1), 3827 multiplexer => (new CFPlus::UI::Multiplexer expand => 1),
3770 # filter => # will be put between multiplexer and $self 3828 # filter => # will be put between multiplexer and $self
3771 @_, 3829 @_,
3772 ); 3830 );
3773 3831
3774 $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; 3832 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
3775 $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); 3833 $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer});
3776 3834
3777 { 3835 {
3778 Scalar::Util::weaken (my $wself = $self); 3836 Scalar::Util::weaken (my $wself = $self);
3819 3877
3820sub remove { 3878sub remove {
3821 my ($self, @widgets) = @_; 3879 my ($self, @widgets) = @_;
3822 3880
3823 $self->{multiplexer}->remove (@widgets) 3881 $self->{multiplexer}->remove (@widgets)
3882}
3883
3884sub pages {
3885 my ($self) = @_;
3886 $self->{multiplexer}->children
3824} 3887}
3825 3888
3826sub add_tab { 3889sub add_tab {
3827 my ($self, $title, $widget, $tooltip) = @_; 3890 my ($self, $title, $widget, $tooltip) = @_;
3828 3891

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines