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.363 by root, Sun Dec 10 00:06:49 2006 UTC vs.
Revision 1.372 by root, Sun Jul 15 22:13:43 2007 UTC

22our $TOOLTIP_WATCHER = Event->idle (min => 1/60, cb => sub { 22our $TOOLTIP_WATCHER = Event->idle (min => 1/60, cb => sub {
23 if (!$GRAB) { 23 if (!$GRAB) {
24 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { 24 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) {
25 if (length $widget->{tooltip}) { 25 if (length $widget->{tooltip}) {
26 if ($TOOLTIP->{owner} != $widget) { 26 if ($TOOLTIP->{owner} != $widget) {
27 $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner};
27 $TOOLTIP->hide; 28 $TOOLTIP->hide;
28 29
29 $TOOLTIP->{owner} = $widget; 30 $TOOLTIP->{owner} = $widget;
31 $TOOLTIP->{owner}->emit ("tooltip_show") if $TOOLTIP->{owner};
30 32
31 return if $ENV{CFPLUS_DEBUG} & 8; 33 return if $ENV{CFPLUS_DEBUG} & 8;
32 34
33 my $tip = $widget->{tooltip}; 35 my $tip = $widget->{tooltip};
34 36
42 } 44 }
43 } 45 }
44 } 46 }
45 47
46 $TOOLTIP->hide; 48 $TOOLTIP->hide;
49 $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner};
47 delete $TOOLTIP->{owner}; 50 delete $TOOLTIP->{owner};
48}); 51});
49 52
50sub get_layout { 53sub get_layout {
51 my $layout; 54 my $layout;
265 $self->hide; 268 $self->hide;
266 $self->emit ("destroy"); 269 $self->emit ("destroy");
267 %$self = (); 270 %$self = ();
268} 271}
269 272
273sub TO_JSON {
274 { __widget_ref__ => $_[0]{s_id} }
275}
276
270sub show { 277sub show {
271 my ($self) = @_; 278 my ($self) = @_;
272 279
273 return if $self->{parent}; 280 return if $self->{parent};
274 281
313sub set_visibility { 320sub set_visibility {
314 my ($self, $visible) = @_; 321 my ($self, $visible) = @_;
315 322
316 return if $self->{visible} == $visible; 323 return if $self->{visible} == $visible;
317 324
318 $visible ? $self->hide 325 $visible ? $self->show
319 : $self->show; 326 : $self->hide;
320} 327}
321 328
322sub toggle_visibility { 329sub toggle_visibility {
323 my ($self) = @_; 330 my ($self) = @_;
324 331
1026 1033
1027############################################################################# 1034#############################################################################
1028 1035
1029package CFPlus::UI::ScrolledWindow; 1036package CFPlus::UI::ScrolledWindow;
1030 1037
1031our @ISA = CFPlus::UI::HBox::; 1038our @ISA = CFPlus::UI::Table::;
1032 1039
1033sub new { 1040sub new {
1034 my ($class, %arg) = @_; 1041 my ($class, %arg) = @_;
1035 1042
1036 my $child = delete $arg{child}; 1043 my $child = delete $arg{child};
1037 1044
1038 my $self; 1045 my $self;
1039 1046
1040 my $slider = new CFPlus::UI::Slider 1047 my $hslider = new CFPlus::UI::Slider
1048 vertical => 0,
1049 range => [0, 0, 1, 0.01], # HACK fix
1050 on_changed => sub {
1051 $self->{hpos} = $_[1];
1052 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos});
1053 },
1054 ;
1055
1056 my $vslider = new CFPlus::UI::Slider
1041 vertical => 1, 1057 vertical => 1,
1042 range => [0, 0, 1, 0.01], # HACK fix 1058 range => [0, 0, 1, 0.01], # HACK fix
1043 on_changed => sub { 1059 on_changed => sub {
1044 $self->{vp}->set_offset (0, $_[1]); 1060 $self->{vpos} = $_[1];
1061 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos});
1045 }, 1062 },
1046 ; 1063 ;
1047 1064
1048 $self = $class->SUPER::new ( 1065 $self = $class->SUPER::new (
1049 vp => (new CFPlus::UI::ViewPort expand => 1), 1066 scroll_x => 0,
1067 scroll_y => 1,
1050 can_events => 1, 1068 can_events => 1,
1051 slider => $slider, 1069 hslider => $hslider,
1070 vslider => $vslider,
1071 col_expand => [1, 0],
1072 row_expand => [1, 0],
1052 %arg, 1073 %arg,
1053 ); 1074 );
1054 1075
1076 $self->{vp} = new CFPlus::UI::ViewPort
1077 expand => 1,
1078 scroll_x => $self->{scroll_x},
1079 scroll_y => $self->{scroll_y},
1080 ;
1081
1082 $self->SUPER::add (0, 0, $self->{vp});
1055 $self->SUPER::add ($self->{vp}, $self->{slider}); 1083 $self->SUPER::add (1, 0, $self->{vslider}) if $self->{scroll_y};
1084 $self->SUPER::add (0, 1, $self->{hslider}) if $self->{scroll_x};
1085
1056 $self->add ($child) if $child; 1086 $self->add ($child) if $child;
1057 1087
1058 $self 1088 $self
1059} 1089}
1060 1090
1069sub invoke_mouse_wheel { 1099sub invoke_mouse_wheel {
1070 my ($self, $ev) = @_; 1100 my ($self, $ev) = @_;
1071 1101
1072 return 0 unless $ev->{dy}; # only vertical movements 1102 return 0 unless $ev->{dy}; # only vertical movements
1073 1103
1074 $self->{slider}->emit (mouse_wheel => $ev); 1104 $self->{vslider}->emit (mouse_wheel => $ev);
1075 1105
1076 1 1106 1
1077} 1107}
1078 1108
1079sub update_slider { 1109sub update_slider {
1080 my ($self) = @_; 1110 my ($self) = @_;
1081 1111
1112 my $child = ($self->{vp} or return)->child;
1113
1114 my ($w1, $w2) = ($child->{w}, $self->{vp}{w});
1082 $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $self->{vp}->child->{h}, $self->{vp}{h}, 1]); 1115 $self->{hslider}->set_range ([$self->{hslider}{range}[0], 0, $w1, $w2, 1]);
1116 #$self->{hslider}->set_visibility ($w1 != $w2);
1117
1118 my ($h1, $h2) = ($child->{h}, $self->{vp}{h});
1119 $self->{vslider}->set_range ([$self->{vslider}{range}[0], 0, $h1, $h2, 1]);
1120 #$self->{vslider}->set_visibility ($h1 != $h2);
1083} 1121}
1084 1122
1085sub update { 1123sub update {
1086 my ($self) = @_; 1124 my ($self) = @_;
1087 1125
1088 $self->SUPER::update; 1126 $self->SUPER::update;
1089
1090 $self->update_slider; 1127 $self->update_slider;
1091} 1128}
1092 1129
1093sub invoke_size_allocate { 1130sub invoke_size_allocate {
1094 my ($self, $w, $h) = @_; 1131 my ($self, $w, $h) = @_;
1095 1132
1096 $self->update_slider; 1133 $self->update_slider;
1097
1098 $self->SUPER::invoke_size_allocate ($w, $h) 1134 $self->SUPER::invoke_size_allocate ($w, $h)
1099} 1135}
1100 1136
1101############################################################################# 1137#############################################################################
1102 1138
1474sub new { 1510sub new {
1475 my $class = shift; 1511 my $class = shift;
1476 1512
1477 $class->SUPER::new ( 1513 $class->SUPER::new (
1478 col_expand => [], 1514 col_expand => [],
1515 row_expand => [],
1479 @_, 1516 @_,
1480 ) 1517 )
1481} 1518}
1482 1519
1483sub children { 1520sub children {
1558 my ($ws, $hs) = $self->get_wh; 1595 my ($ws, $hs) = $self->get_wh;
1559 1596
1560 my $req_w = (sum @$ws) || 1; 1597 my $req_w = (sum @$ws) || 1;
1561 my $req_h = (sum @$hs) || 1; 1598 my $req_h = (sum @$hs) || 1;
1562 1599
1563 # TODO: nicer code && do row_expand 1600 # TODO: nicer code
1564 my @col_expand = @{$self->{col_expand}}; 1601 my @col_expand = @{$self->{col_expand}};
1565 @col_expand = (1) x @$ws unless @col_expand; 1602 @col_expand = (1) x @$ws unless @col_expand;
1566 my $col_expand = (sum @col_expand) || 1; 1603 my $col_expand = (sum @col_expand) || 1;
1567 1604
1568 # linearly scale sizes
1569 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; 1605 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws;
1570 $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs;
1571 1606
1572 CFPlus::UI::harmonize $ws; 1607 CFPlus::UI::harmonize $ws;
1608
1609 my @row_expand = @{$self->{row_expand}};
1610 @row_expand = (1) x @$ws unless @row_expand;
1611 my $row_expand = (sum @row_expand) || 1;
1612
1613 $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs;
1614
1573 CFPlus::UI::harmonize $hs; 1615 CFPlus::UI::harmonize $hs;
1574 1616
1575 my $y; 1617 my $y;
1576 1618
1577 for my $r (0 .. $#{$self->{children}}) { 1619 for my $r (0 .. $#{$self->{children}}) {
1966 my $mod = $ev->{mod}; 2008 my $mod = $ev->{mod};
1967 my $sym = $ev->{sym}; 2009 my $sym = $ev->{sym};
1968 my $uni = $ev->{unicode}; 2010 my $uni = $ev->{unicode};
1969 2011
1970 my $text = $self->get_text; 2012 my $text = $self->get_text;
2013
2014 $self->{cursor} = List::Util::max 0, List::Util::min $self->{cursor}, length $text;
1971 2015
1972 if ($uni == 8) { 2016 if ($uni == 8) {
1973 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 2017 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
1974 } elsif ($uni == 127) { 2018 } elsif ($uni == 127) {
1975 substr $text, $self->{cursor}, 1, ""; 2019 substr $text, $self->{cursor}, 1, "";
2708sub invoke_mouse_wheel { 2752sub invoke_mouse_wheel {
2709 my ($self, $ev) = @_; 2753 my ($self, $ev) = @_;
2710 2754
2711 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; 2755 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx};
2712 2756
2757 my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2;
2758
2713 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * 0.2); 2759 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart);
2714 2760
2715 ! ! $delta 2761 ! ! $delta
2716} 2762}
2717 2763
2718sub update { 2764sub update {
2828 #font => default_font 2874 #font => default_font
2829 @_, 2875 @_,
2830 2876
2831 layout => (new CFPlus::Layout), 2877 layout => (new CFPlus::Layout),
2832 par => [], 2878 par => [],
2879 max_par => 0,
2833 height => 0, 2880 height => 0,
2834 children => [ 2881 children => [
2835 (new CFPlus::UI::Empty expand => 1), 2882 (new CFPlus::UI::Empty expand => 1),
2836 (new CFPlus::UI::Slider vertical => 1), 2883 (new CFPlus::UI::Slider vertical => 1),
2837 ], 2884 ],
2960 wrapped => 1, 3007 wrapped => 1,
2961 }; 3008 };
2962 3009
2963 $self->add (@{ $para->{widget} }) if @{ $para->{widget} }; 3010 $self->add (@{ $para->{widget} }) if @{ $para->{widget} };
2964 push @{$self->{par}}, $para; 3011 push @{$self->{par}}, $para;
3012 }
3013
3014 if (my $max = $self->{max_par}) {
3015 shift @{$self->{par}} while @{$self->{par}} > $max;
2965 } 3016 }
2966 3017
2967 $self->{need_reflow}++; 3018 $self->{need_reflow}++;
2968 $self->update; 3019 $self->update;
2969} 3020}
3290 $self->{timer} = Event->timer ( 3341 $self->{timer} = Event->timer (
3291 at => $self->{animspeed} * int $::NOW / $self->{animspeed}, 3342 at => $self->{animspeed} * int $::NOW / $self->{animspeed},
3292 hard => 1, 3343 hard => 1,
3293 interval => $self->{animspeed}, 3344 interval => $self->{animspeed},
3294 cb => sub { 3345 cb => sub {
3346 delete $self->{wait_face};
3295 ++$widget->{frame}; 3347 ++$widget->{frame};
3296 $widget->update; 3348 $widget->update;
3297 }, 3349 },
3298 ); 3350 );
3299 } 3351 }
3326 my $anim = $::CONN->{anim}[$self->{anim}]; 3378 my $anim = $::CONN->{anim}[$self->{anim}];
3327 3379
3328 $face = $anim->[ $self->{frame} % @$anim ] 3380 $face = $anim->[ $self->{frame} % @$anim ]
3329 if $anim && @$anim; 3381 if $anim && @$anim;
3330 } 3382 }
3383
3384 my $faceid = $::CONN->{faceid}[$face || $self->{face}]
3385 or return;
3331 3386
3332 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]]; 3387 my $tex = $::CONN->{texture}[$faceid];
3333 3388
3334 if ($tex) { 3389 if ($tex) {
3335 glEnable GL_TEXTURE_2D; 3390 glEnable GL_TEXTURE_2D;
3336 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 3391 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
3337 glColor 0, 0, 0, 1; 3392 glColor 0, 0, 0, 1;
3338 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); 3393 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
3339 glDisable GL_TEXTURE_2D; 3394 glDisable GL_TEXTURE_2D;
3395 } else {
3396 $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub {
3397 $self->update;
3398 });
3340 } 3399 }
3341} 3400}
3342 3401
3343sub destroy { 3402sub destroy {
3344 my ($self) = @_; 3403 my ($self) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines