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.373 by root, Sun Jul 15 22:39:30 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 scroll_x => 0,
1067 scroll_y => 1,
1053 can_events => 1, 1068 can_events => 1,
1054 slider => $slider, 1069 hslider => $hslider,
1070 vslider => $vslider,
1071 col_expand => [1, 0],
1072 row_expand => [1, 0],
1055 %arg, 1073 %arg,
1056 ); 1074 );
1057 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});
1058 $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
1059 $self->add ($child) if $child; 1086 $self->add ($child) if $child;
1060 1087
1061 $self 1088 $self
1062} 1089}
1063 1090
1072sub invoke_mouse_wheel { 1099sub invoke_mouse_wheel {
1073 my ($self, $ev) = @_; 1100 my ($self, $ev) = @_;
1074 1101
1075 return 0 unless $ev->{dy}; # only vertical movements 1102 return 0 unless $ev->{dy}; # only vertical movements
1076 1103
1077 $self->{slider}->emit (mouse_wheel => $ev); 1104 $self->{vslider}->emit (mouse_wheel => $ev);
1078 1105
1079 1 1106 1
1080} 1107}
1081 1108
1082sub update_slider { 1109sub update_slider {
1083 my ($self) = @_; 1110 my ($self) = @_;
1084 1111
1112 my $child = ($self->{vp} or return)->child;
1113
1114 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]); 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);
1086} 1121}
1087 1122
1088sub update { 1123sub update {
1089 my ($self) = @_; 1124 my ($self) = @_;
1090 1125
1091 $self->SUPER::update; 1126 $self->SUPER::update;
1092
1093 $self->update_slider; 1127 $self->update_slider;
1094} 1128}
1095 1129
1096sub invoke_size_allocate { 1130sub invoke_size_allocate {
1097 my ($self, $w, $h) = @_; 1131 my ($self, $w, $h) = @_;
1098 1132
1099 $self->update_slider; 1133 $self->update_slider;
1100
1101 $self->SUPER::invoke_size_allocate ($w, $h) 1134 $self->SUPER::invoke_size_allocate ($w, $h)
1102} 1135}
1103 1136
1104############################################################################# 1137#############################################################################
1105 1138
1477sub new { 1510sub new {
1478 my $class = shift; 1511 my $class = shift;
1479 1512
1480 $class->SUPER::new ( 1513 $class->SUPER::new (
1481 col_expand => [], 1514 col_expand => [],
1515 row_expand => [],
1482 @_, 1516 @_,
1483 ) 1517 )
1484} 1518}
1485 1519
1486sub children { 1520sub children {
1561 my ($ws, $hs) = $self->get_wh; 1595 my ($ws, $hs) = $self->get_wh;
1562 1596
1563 my $req_w = (sum @$ws) || 1; 1597 my $req_w = (sum @$ws) || 1;
1564 my $req_h = (sum @$hs) || 1; 1598 my $req_h = (sum @$hs) || 1;
1565 1599
1566 # TODO: nicer code && do row_expand 1600 # TODO: nicer code
1567 my @col_expand = @{$self->{col_expand}}; 1601 my @col_expand = @{$self->{col_expand}};
1568 @col_expand = (1) x @$ws unless @col_expand; 1602 @col_expand = (1) x @$ws unless @col_expand;
1569 my $col_expand = (sum @col_expand) || 1; 1603 my $col_expand = (sum @col_expand) || 1;
1570 1604
1571 # linearly scale sizes
1572 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; 1605 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws;
1573 $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs;
1574 1606
1575 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
1576 CFPlus::UI::harmonize $hs; 1615 CFPlus::UI::harmonize $hs;
1577 1616
1578 my $y; 1617 my $y;
1579 1618
1580 for my $r (0 .. $#{$self->{children}}) { 1619 for my $r (0 .. $#{$self->{children}}) {
1969 my $mod = $ev->{mod}; 2008 my $mod = $ev->{mod};
1970 my $sym = $ev->{sym}; 2009 my $sym = $ev->{sym};
1971 my $uni = $ev->{unicode}; 2010 my $uni = $ev->{unicode};
1972 2011
1973 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;
1974 2015
1975 if ($uni == 8) { 2016 if ($uni == 8) {
1976 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 2017 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
1977 } elsif ($uni == 127) { 2018 } elsif ($uni == 127) {
1978 substr $text, $self->{cursor}, 1, ""; 2019 substr $text, $self->{cursor}, 1, "";
3287 3328
3288sub new { 3329sub new {
3289 my $class = shift; 3330 my $class = shift;
3290 3331
3291 my $self = $class->SUPER::new ( 3332 my $self = $class->SUPER::new (
3333 size_w => 32,
3334 size_h => 8,
3292 aspect => 1, 3335 aspect => 1,
3293 can_events => 0, 3336 can_events => 0,
3294 @_, 3337 @_,
3295 ); 3338 );
3296 3339
3300 $self->{timer} = Event->timer ( 3343 $self->{timer} = Event->timer (
3301 at => $self->{animspeed} * int $::NOW / $self->{animspeed}, 3344 at => $self->{animspeed} * int $::NOW / $self->{animspeed},
3302 hard => 1, 3345 hard => 1,
3303 interval => $self->{animspeed}, 3346 interval => $self->{animspeed},
3304 cb => sub { 3347 cb => sub {
3348 return unless $::CONN;
3349
3305 ++$widget->{frame}; 3350 ++$widget->{frame};
3351 $self->update_face;
3306 $widget->update; 3352 $self->update;
3307 }, 3353 },
3308 ); 3354 );
3355
3356 $self->update_face;
3309 } 3357 }
3310 3358
3311 $self 3359 $self
3312} 3360}
3313 3361
3362sub update_face {
3363 my ($self) = @_;
3364
3365 return unless $::CONN;
3366
3367 if (my $anim = $::CONN->{anim}[$self->{anim}]) {
3368 if ($anim && @$anim) {
3369 delete $self->{wait_face};
3370 $self->{face} = $anim->[ $self->{frame} % @$anim ];
3371 }
3372 }
3373}
3374
3314sub size_request { 3375sub size_request {
3315 (32, 8) 3376 my ($self) = @_;
3377
3378 if ($::CONN) {
3379 if (my $faceid = $::CONN->{faceid}[$self->{face}]) {
3380 if (my $tex = $::CONN->{texture}[$faceid]) {
3381 return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h});
3382 } else {
3383 $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub {
3384 $self->realloc;
3385 });
3386 }
3387 }
3388 }
3389
3390 ($self->{size_w} || 8, $self->{size_h} || 8)
3316} 3391}
3317 3392
3318sub update { 3393sub update {
3319 my ($self) = @_; 3394 my ($self) = @_;
3320 3395
3328 3403
3329 return unless $::CONN; 3404 return unless $::CONN;
3330 3405
3331 $self->SUPER::_draw; 3406 $self->SUPER::_draw;
3332 3407
3333 my $face;
3334
3335 if ($self->{frame}) {
3336 my $anim = $::CONN->{anim}[$self->{anim}]; 3408 my $faceid = $::CONN->{faceid}[$self->{face}]
3337 3409 or return;
3338 $face = $anim->[ $self->{frame} % @$anim ]
3339 if $anim && @$anim;
3340 }
3341 3410
3342 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]]; 3411 my $tex = $::CONN->{texture}[$faceid];
3343 3412
3344 if ($tex) { 3413 if ($tex) {
3345 glEnable GL_TEXTURE_2D; 3414 glEnable GL_TEXTURE_2D;
3346 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 3415 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
3347 glColor 0, 0, 0, 1; 3416 glColor 0, 0, 0, 1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines