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.413 by root, Mon Jul 23 15:30:45 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
953 $self->{view_x} = $x; 953 $self->{view_x} = $x;
954 $self->{view_y} = $y; 954 $self->{view_y} = $y;
955 955
956 $self->emit (changed => $x, $y); 956 $self->emit (changed => $x, $y);
957 $self->update; 957 $self->update;
958 }
959}
960
961sub set_center {
962 my ($self, $x, $y) = @_;
963
964 $self->set_offset ($x - $self->{w} * .5, $y - $self->{h} * .5);
965}
966
967sub make_visible {
968 my ($self, $x, $y, $border) = @_;
969
970 if ( $x < $self->{view_x} + $self->{w} * $border
971 || $x > $self->{view_x} + $self->{w} * (1 - $border)
972 || $y < $self->{view_y} + $self->{h} * $border
973 || $y > $self->{view_y} + $self->{h} * (1 - $border)
974 ) {
975 $self->set_center ($x, $y);
958 } 976 }
959} 977}
960 978
961# hmm, this does not work for topleft of $self... but we should not ask for that 979# hmm, this does not work for topleft of $self... but we should not ask for that
962sub coord2local { 980sub coord2local {
1074sub add { 1092sub add {
1075 my ($self, $widget) = @_; 1093 my ($self, $widget) = @_;
1076 1094
1077 $self->{vp}->add ($self->{child} = $widget); 1095 $self->{vp}->add ($self->{child} = $widget);
1078} 1096}
1097
1098sub set_offset { shift->{vp}->set_offset (@_) }
1099sub set_center { shift->{vp}->set_center (@_) }
1100sub make_visible { shift->{vp}->make_visible (@_) }
1079 1101
1080sub update_slider { 1102sub update_slider {
1081 my ($self) = @_; 1103 my ($self) = @_;
1082 1104
1083 my $child = ($self->{vp} or return)->child; 1105 my $child = ($self->{vp} or return)->child;
2052 my $class = shift; 2074 my $class = shift;
2053 2075
2054 $class->SUPER::new ( 2076 $class->SUPER::new (
2055 fg => [1, 1, 1], 2077 fg => [1, 1, 1],
2056 bg => [0, 0, 0, 0.2], 2078 bg => [0, 0, 0, 0.2],
2057 active_bg => [1, 1, 1, 0.5], 2079 active_bg => [0, 0, 1, .2],
2058 active_fg => [0, 0, 0], 2080 active_fg => [1, 1, 1],
2081 active_outline => [1, 1, 0],
2059 can_hover => 1, 2082 can_hover => 1,
2060 can_focus => 1, 2083 can_focus => 1,
2061 valign => 0, 2084 valign => 0,
2062 can_events => 1, 2085 can_events => 1,
2063 ellipsise => 0, 2086 ellipsise => 0,
2220 2243
2221 unless (exists $self->{cur_h}) { 2244 unless (exists $self->{cur_h}) {
2222 my $text = substr $self->{text}, 0, $self->{cursor}; 2245 my $text = substr $self->{text}, 0, $self->{cursor};
2223 utf8::encode $text; 2246 utf8::encode $text;
2224 2247
2225 @$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);
2226 } 2249 }
2227 2250
2251 glColor_premultiply @{$self->{active_fg}};
2228 glBegin GL_LINES; 2252 glBegin GL_LINES;
2229 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};
2230 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};
2231 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;
2232 } 2267 }
2233} 2268}
2234 2269
2235############################################################################# 2270#############################################################################
2236 2271
2322 1 2357 1
2323} 2358}
2324 2359
2325############################################################################# 2360#############################################################################
2326 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
2327package CFPlus::UI::Button; 2411package CFPlus::UI::Button;
2328 2412
2329our @ISA = CFPlus::UI::Label::; 2413our @ISA = CFPlus::UI::Label::;
2330 2414
2331use CFPlus::OpenGL; 2415use CFPlus::OpenGL;
2465sub new { 2549sub new {
2466 my $class = shift; 2550 my $class = shift;
2467 2551
2468 my $self = $class->SUPER::new ( 2552 my $self = $class->SUPER::new (
2469 can_events => 0, 2553 can_events => 0,
2554 scale => 1,
2470 @_, 2555 @_,
2471 ); 2556 );
2472 2557
2473 $self->{path} || $self->{tex} 2558 $self->{path} || $self->{tex}
2474 or Carp::croak "'path' or 'tex' attributes required"; 2559 or Carp::croak "'path' or 'tex' attributes required";
2499} 2584}
2500 2585
2501sub size_request { 2586sub size_request {
2502 my ($self) = @_; 2587 my ($self) = @_;
2503 2588
2504 ($self->{tex}{w}, $self->{tex}{h}) 2589 (int $self->{tex}{w} * $self->{scale}, int $self->{tex}{h} * $self->{scale})
2505} 2590}
2506 2591
2507sub _draw { 2592sub _draw {
2508 my ($self) = @_; 2593 my ($self) = @_;
2509 2594
2519 } 2604 }
2520 2605
2521 glEnable GL_TEXTURE_2D; 2606 glEnable GL_TEXTURE_2D;
2522 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2607 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2523 2608
2524 $tex->draw_quad (0, 0, $w, $h); 2609 $tex->draw_quad_alpha (0, 0, $w, $h);
2525 2610
2526 glDisable GL_TEXTURE_2D; 2611 glDisable GL_TEXTURE_2D;
2527} 2612}
2528 2613
2529############################################################################# 2614#############################################################################
3600 children => [ 3685 children => [
3601 (new CFPlus::UI::Label markup => $left, expand => 1), 3686 (new CFPlus::UI::Label markup => $left, expand => 1),
3602 (new CFPlus::UI::Label markup => $right, align => +1), 3687 (new CFPlus::UI::Label markup => $right, align => +1),
3603 ], 3688 ],
3604 ; 3689 ;
3605 3690
3606 } else { 3691 } else {
3607 $widget = new CFPlus::UI::Label 3692 $widget = new CFPlus::UI::Label
3608 can_hover => 1, 3693 can_hover => 1,
3609 can_events => 1, 3694 can_events => 1,
3610 markup => $widget, 3695 markup => $widget,
3746 buttonbar => (new CFPlus::UI::Buttonbar), 3831 buttonbar => (new CFPlus::UI::Buttonbar),
3747 multiplexer => (new CFPlus::UI::Multiplexer expand => 1), 3832 multiplexer => (new CFPlus::UI::Multiplexer expand => 1),
3748 # filter => # will be put between multiplexer and $self 3833 # filter => # will be put between multiplexer and $self
3749 @_, 3834 @_,
3750 ); 3835 );
3751 3836
3752 $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; 3837 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
3753 $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); 3838 $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer});
3754 3839
3755 { 3840 {
3756 Scalar::Util::weaken (my $wself = $self); 3841 Scalar::Util::weaken (my $wself = $self);
3797 3882
3798sub remove { 3883sub remove {
3799 my ($self, @widgets) = @_; 3884 my ($self, @widgets) = @_;
3800 3885
3801 $self->{multiplexer}->remove (@widgets) 3886 $self->{multiplexer}->remove (@widgets)
3887}
3888
3889sub pages {
3890 my ($self) = @_;
3891 $self->{multiplexer}->children
3802} 3892}
3803 3893
3804sub add_tab { 3894sub add_tab {
3805 my ($self, $title, $widget, $tooltip) = @_; 3895 my ($self, $title, $widget, $tooltip) = @_;
3806 3896

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines