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.418 by elmex, Tue Jul 24 18:39:39 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#############################################################################
3622 children => [ 3685 children => [
3623 (new CFPlus::UI::Label markup => $left, expand => 1), 3686 (new CFPlus::UI::Label markup => $left, expand => 1),
3624 (new CFPlus::UI::Label markup => $right, align => +1), 3687 (new CFPlus::UI::Label markup => $right, align => +1),
3625 ], 3688 ],
3626 ; 3689 ;
3627 3690
3628 } else { 3691 } else {
3629 $widget = new CFPlus::UI::Label 3692 $widget = new CFPlus::UI::Label
3630 can_hover => 1, 3693 can_hover => 1,
3631 can_events => 1, 3694 can_events => 1,
3632 markup => $widget, 3695 markup => $widget,
3768 buttonbar => (new CFPlus::UI::Buttonbar), 3831 buttonbar => (new CFPlus::UI::Buttonbar),
3769 multiplexer => (new CFPlus::UI::Multiplexer expand => 1), 3832 multiplexer => (new CFPlus::UI::Multiplexer expand => 1),
3770 # filter => # will be put between multiplexer and $self 3833 # filter => # will be put between multiplexer and $self
3771 @_, 3834 @_,
3772 ); 3835 );
3773 3836
3774 $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; 3837 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
3775 $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); 3838 $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer});
3776 3839
3777 { 3840 {
3778 Scalar::Util::weaken (my $wself = $self); 3841 Scalar::Util::weaken (my $wself = $self);
3819 3882
3820sub remove { 3883sub remove {
3821 my ($self, @widgets) = @_; 3884 my ($self, @widgets) = @_;
3822 3885
3823 $self->{multiplexer}->remove (@widgets) 3886 $self->{multiplexer}->remove (@widgets)
3887}
3888
3889sub pages {
3890 my ($self) = @_;
3891 $self->{multiplexer}->children
3824} 3892}
3825 3893
3826sub add_tab { 3894sub add_tab {
3827 my ($self, $title, $widget, $tooltip) = @_; 3895 my ($self, $title, $widget, $tooltip) = @_;
3828 3896

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines