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.366 by root, Mon Apr 23 19:17:41 2007 UTC vs.
Revision 1.371 by root, Sun Jul 15 22:07:48 2007 UTC

268 $self->hide; 268 $self->hide;
269 $self->emit ("destroy"); 269 $self->emit ("destroy");
270 %$self = (); 270 %$self = ();
271} 271}
272 272
273sub TO_JSON {
274 { __widget_ref__ => $_[0]{s_id} }
275}
276
273sub show { 277sub show {
274 my ($self) = @_; 278 my ($self) = @_;
275 279
276 return if $self->{parent}; 280 return if $self->{parent};
277 281
316sub set_visibility { 320sub set_visibility {
317 my ($self, $visible) = @_; 321 my ($self, $visible) = @_;
318 322
319 return if $self->{visible} == $visible; 323 return if $self->{visible} == $visible;
320 324
321 $visible ? $self->hide 325 $visible ? $self->show
322 : $self->show; 326 : $self->hide;
323} 327}
324 328
325sub toggle_visibility { 329sub toggle_visibility {
326 my ($self) = @_; 330 my ($self) = @_;
327 331
1029 1033
1030############################################################################# 1034#############################################################################
1031 1035
1032package CFPlus::UI::ScrolledWindow; 1036package CFPlus::UI::ScrolledWindow;
1033 1037
1034our @ISA = CFPlus::UI::HBox::; 1038our @ISA = CFPlus::UI::Table::;
1035 1039
1036sub new { 1040sub new {
1037 my ($class, %arg) = @_; 1041 my ($class, %arg) = @_;
1038 1042
1039 my $child = delete $arg{child}; 1043 my $child = delete $arg{child};
1040 1044
1041 my $self; 1045 my $self;
1042 1046
1043 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
1044 vertical => 1, 1057 vertical => 1,
1045 range => [0, 0, 1, 0.01], # HACK fix 1058 range => [0, 0, 1, 0.01], # HACK fix
1046 on_changed => sub { 1059 on_changed => sub {
1047 $self->{vp}->set_offset (0, $_[1]); 1060 $self->{vpos} = $_[1];
1061 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos});
1048 }, 1062 },
1049 ; 1063 ;
1050 1064
1051 $self = $class->SUPER::new ( 1065 $self = $class->SUPER::new (
1052 vp => (new CFPlus::UI::ViewPort expand => 1), 1066 vp => (new CFPlus::UI::ViewPort expand => 1),
1053 can_events => 1, 1067 can_events => 1,
1054 slider => $slider, 1068 hslider => $hslider,
1069 vslider => $vslider,
1070 col_expand => [1, 0],
1071 row_expand => [1, 0],
1055 %arg, 1072 %arg,
1056 ); 1073 );
1057 1074
1075 $self->SUPER::add (0, 0, $self->{vp});
1058 $self->SUPER::add ($self->{vp}, $self->{slider}); 1076 $self->SUPER::add (1, 0, $self->{vslider});
1077 $self->SUPER::add (0, 1, $self->{hslider});
1078
1059 $self->add ($child) if $child; 1079 $self->add ($child) if $child;
1060 1080
1061 $self 1081 $self
1062} 1082}
1063 1083
1072sub invoke_mouse_wheel { 1092sub invoke_mouse_wheel {
1073 my ($self, $ev) = @_; 1093 my ($self, $ev) = @_;
1074 1094
1075 return 0 unless $ev->{dy}; # only vertical movements 1095 return 0 unless $ev->{dy}; # only vertical movements
1076 1096
1077 $self->{slider}->emit (mouse_wheel => $ev); 1097 $self->{vslider}->emit (mouse_wheel => $ev);
1078 1098
1079 1 1099 1
1080} 1100}
1081 1101
1082sub update_slider { 1102sub update_slider {
1083 my ($self) = @_; 1103 my ($self) = @_;
1084 1104
1105 my $child = ($self->{vp} or return)->child;
1106
1107 my ($w1, $w2) = ($child->{w}, $self->{vp}{w});
1085 $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $self->{vp}->child->{h}, $self->{vp}{h}, 1]); 1108 $self->{hslider}->set_range ([$self->{hslider}{range}[0], 0, $w1, $w2, 1]);
1109 #$self->{hslider}->set_visibility ($w1 != $w2);
1110
1111 my ($h1, $h2) = ($child->{h}, $self->{vp}{h});
1112 $self->{vslider}->set_range ([$self->{vslider}{range}[0], 0, $h1, $h2, 1]);
1113 #$self->{vslider}->set_visibility ($h1 != $h2);
1086} 1114}
1087 1115
1088sub update { 1116sub update {
1089 my ($self) = @_; 1117 my ($self) = @_;
1090 1118
1091 $self->SUPER::update; 1119 $self->SUPER::update;
1092
1093 $self->update_slider; 1120 $self->update_slider;
1094} 1121}
1095 1122
1096sub invoke_size_allocate { 1123sub invoke_size_allocate {
1097 my ($self, $w, $h) = @_; 1124 my ($self, $w, $h) = @_;
1098 1125
1099 $self->update_slider; 1126 $self->update_slider;
1100
1101 $self->SUPER::invoke_size_allocate ($w, $h) 1127 $self->SUPER::invoke_size_allocate ($w, $h)
1102} 1128}
1103 1129
1104############################################################################# 1130#############################################################################
1105 1131
1477sub new { 1503sub new {
1478 my $class = shift; 1504 my $class = shift;
1479 1505
1480 $class->SUPER::new ( 1506 $class->SUPER::new (
1481 col_expand => [], 1507 col_expand => [],
1508 row_expand => [],
1482 @_, 1509 @_,
1483 ) 1510 )
1484} 1511}
1485 1512
1486sub children { 1513sub children {
1561 my ($ws, $hs) = $self->get_wh; 1588 my ($ws, $hs) = $self->get_wh;
1562 1589
1563 my $req_w = (sum @$ws) || 1; 1590 my $req_w = (sum @$ws) || 1;
1564 my $req_h = (sum @$hs) || 1; 1591 my $req_h = (sum @$hs) || 1;
1565 1592
1566 # TODO: nicer code && do row_expand 1593 # TODO: nicer code
1567 my @col_expand = @{$self->{col_expand}}; 1594 my @col_expand = @{$self->{col_expand}};
1568 @col_expand = (1) x @$ws unless @col_expand; 1595 @col_expand = (1) x @$ws unless @col_expand;
1569 my $col_expand = (sum @col_expand) || 1; 1596 my $col_expand = (sum @col_expand) || 1;
1570 1597
1571 # linearly scale sizes
1572 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; 1598 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws;
1573 $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs;
1574 1599
1575 CFPlus::UI::harmonize $ws; 1600 CFPlus::UI::harmonize $ws;
1601
1602 my @row_expand = @{$self->{row_expand}};
1603 @row_expand = (1) x @$ws unless @row_expand;
1604 my $row_expand = (sum @row_expand) || 1;
1605
1606 $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs;
1607
1576 CFPlus::UI::harmonize $hs; 1608 CFPlus::UI::harmonize $hs;
1577 1609
1578 my $y; 1610 my $y;
1579 1611
1580 for my $r (0 .. $#{$self->{children}}) { 1612 for my $r (0 .. $#{$self->{children}}) {
1969 my $mod = $ev->{mod}; 2001 my $mod = $ev->{mod};
1970 my $sym = $ev->{sym}; 2002 my $sym = $ev->{sym};
1971 my $uni = $ev->{unicode}; 2003 my $uni = $ev->{unicode};
1972 2004
1973 my $text = $self->get_text; 2005 my $text = $self->get_text;
2006
2007 $self->{cursor} = List::Util::max 0, List::Util::min $self->{cursor}, length $text;
1974 2008
1975 if ($uni == 8) { 2009 if ($uni == 8) {
1976 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 2010 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
1977 } elsif ($uni == 127) { 2011 } elsif ($uni == 127) {
1978 substr $text, $self->{cursor}, 1, ""; 2012 substr $text, $self->{cursor}, 1, "";
3300 $self->{timer} = Event->timer ( 3334 $self->{timer} = Event->timer (
3301 at => $self->{animspeed} * int $::NOW / $self->{animspeed}, 3335 at => $self->{animspeed} * int $::NOW / $self->{animspeed},
3302 hard => 1, 3336 hard => 1,
3303 interval => $self->{animspeed}, 3337 interval => $self->{animspeed},
3304 cb => sub { 3338 cb => sub {
3339 delete $self->{wait_face};
3305 ++$widget->{frame}; 3340 ++$widget->{frame};
3306 $widget->update; 3341 $widget->update;
3307 }, 3342 },
3308 ); 3343 );
3309 } 3344 }
3336 my $anim = $::CONN->{anim}[$self->{anim}]; 3371 my $anim = $::CONN->{anim}[$self->{anim}];
3337 3372
3338 $face = $anim->[ $self->{frame} % @$anim ] 3373 $face = $anim->[ $self->{frame} % @$anim ]
3339 if $anim && @$anim; 3374 if $anim && @$anim;
3340 } 3375 }
3376
3377 my $faceid = $::CONN->{faceid}[$face || $self->{face}]
3378 or return;
3341 3379
3342 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]]; 3380 my $tex = $::CONN->{texture}[$faceid];
3343 3381
3344 if ($tex) { 3382 if ($tex) {
3345 glEnable GL_TEXTURE_2D; 3383 glEnable GL_TEXTURE_2D;
3346 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 3384 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
3347 glColor 0, 0, 0, 1; 3385 glColor 0, 0, 0, 1;
3348 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); 3386 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
3349 glDisable GL_TEXTURE_2D; 3387 glDisable GL_TEXTURE_2D;
3388 } else {
3389 $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub {
3390 $self->update;
3391 });
3350 } 3392 }
3351} 3393}
3352 3394
3353sub destroy { 3395sub destroy {
3354 my ($self) = @_; 3396 my ($self) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines