… | |
… | |
268 | $self->hide; |
268 | $self->hide; |
269 | $self->emit ("destroy"); |
269 | $self->emit ("destroy"); |
270 | %$self = (); |
270 | %$self = (); |
271 | } |
271 | } |
272 | |
272 | |
|
|
273 | sub TO_JSON { |
|
|
274 | { __widget_ref__ => $_[0]{s_id} } |
|
|
275 | } |
|
|
276 | |
273 | sub show { |
277 | sub show { |
274 | my ($self) = @_; |
278 | my ($self) = @_; |
275 | |
279 | |
276 | return if $self->{parent}; |
280 | return if $self->{parent}; |
277 | |
281 | |
… | |
… | |
316 | sub set_visibility { |
320 | sub 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 | |
325 | sub toggle_visibility { |
329 | sub toggle_visibility { |
326 | my ($self) = @_; |
330 | my ($self) = @_; |
327 | |
331 | |
… | |
… | |
1029 | |
1033 | |
1030 | ############################################################################# |
1034 | ############################################################################# |
1031 | |
1035 | |
1032 | package CFPlus::UI::ScrolledWindow; |
1036 | package CFPlus::UI::ScrolledWindow; |
1033 | |
1037 | |
1034 | our @ISA = CFPlus::UI::HBox::; |
1038 | our @ISA = CFPlus::UI::Table::; |
1035 | |
1039 | |
1036 | sub new { |
1040 | sub 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 | |
… | |
… | |
1072 | sub invoke_mouse_wheel { |
1099 | sub 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 | |
1082 | sub update_slider { |
1109 | sub 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 | |
1088 | sub update { |
1123 | sub 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 | |
1096 | sub invoke_size_allocate { |
1130 | sub 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 | |
… | |
… | |
1477 | sub new { |
1510 | sub 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 | |
1486 | sub children { |
1520 | sub 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, ""; |
… | |
… | |
3300 | $self->{timer} = Event->timer ( |
3341 | $self->{timer} = Event->timer ( |
3301 | at => $self->{animspeed} * int $::NOW / $self->{animspeed}, |
3342 | at => $self->{animspeed} * int $::NOW / $self->{animspeed}, |
3302 | hard => 1, |
3343 | hard => 1, |
3303 | interval => $self->{animspeed}, |
3344 | interval => $self->{animspeed}, |
3304 | cb => sub { |
3345 | cb => sub { |
|
|
3346 | delete $self->{wait_face}; |
3305 | ++$widget->{frame}; |
3347 | ++$widget->{frame}; |
3306 | $widget->update; |
3348 | $widget->update; |
3307 | }, |
3349 | }, |
3308 | ); |
3350 | ); |
3309 | } |
3351 | } |
… | |
… | |
3336 | my $anim = $::CONN->{anim}[$self->{anim}]; |
3378 | my $anim = $::CONN->{anim}[$self->{anim}]; |
3337 | |
3379 | |
3338 | $face = $anim->[ $self->{frame} % @$anim ] |
3380 | $face = $anim->[ $self->{frame} % @$anim ] |
3339 | if $anim && @$anim; |
3381 | if $anim && @$anim; |
3340 | } |
3382 | } |
|
|
3383 | |
|
|
3384 | my $faceid = $::CONN->{faceid}[$face || $self->{face}] |
|
|
3385 | or return; |
3341 | |
3386 | |
3342 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]]; |
3387 | my $tex = $::CONN->{texture}[$faceid]; |
3343 | |
3388 | |
3344 | if ($tex) { |
3389 | if ($tex) { |
3345 | glEnable GL_TEXTURE_2D; |
3390 | glEnable GL_TEXTURE_2D; |
3346 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
3391 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
3347 | glColor 0, 0, 0, 1; |
3392 | glColor 0, 0, 0, 1; |
3348 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
3393 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
3349 | 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 | }); |
3350 | } |
3399 | } |
3351 | } |
3400 | } |
3352 | |
3401 | |
3353 | sub destroy { |
3402 | sub destroy { |
3354 | my ($self) = @_; |
3403 | my ($self) = @_; |