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.365 by root, Thu Apr 12 07:53:31 2007 UTC vs.
Revision 1.373 by root, Sun Jul 15 22:39:30 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, "";
3284 3328
3285sub new { 3329sub new {
3286 my $class = shift; 3330 my $class = shift;
3287 3331
3288 my $self = $class->SUPER::new ( 3332 my $self = $class->SUPER::new (
3333 size_w => 32,
3334 size_h => 8,
3289 aspect => 1, 3335 aspect => 1,
3290 can_events => 0, 3336 can_events => 0,
3291 @_, 3337 @_,
3292 ); 3338 );
3293 3339
3297 $self->{timer} = Event->timer ( 3343 $self->{timer} = Event->timer (
3298 at => $self->{animspeed} * int $::NOW / $self->{animspeed}, 3344 at => $self->{animspeed} * int $::NOW / $self->{animspeed},
3299 hard => 1, 3345 hard => 1,
3300 interval => $self->{animspeed}, 3346 interval => $self->{animspeed},
3301 cb => sub { 3347 cb => sub {
3348 return unless $::CONN;
3349
3302 ++$widget->{frame}; 3350 ++$widget->{frame};
3351 $self->update_face;
3303 $widget->update; 3352 $self->update;
3304 }, 3353 },
3305 ); 3354 );
3355
3356 $self->update_face;
3306 } 3357 }
3307 3358
3308 $self 3359 $self
3309} 3360}
3310 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
3311sub size_request { 3375sub size_request {
3312 (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)
3313} 3391}
3314 3392
3315sub update { 3393sub update {
3316 my ($self) = @_; 3394 my ($self) = @_;
3317 3395
3325 3403
3326 return unless $::CONN; 3404 return unless $::CONN;
3327 3405
3328 $self->SUPER::_draw; 3406 $self->SUPER::_draw;
3329 3407
3330 my $face;
3331
3332 if ($self->{frame}) {
3333 my $anim = $::CONN->{anim}[$self->{anim}]; 3408 my $faceid = $::CONN->{faceid}[$self->{face}]
3334 3409 or return;
3335 $face = $anim->[ $self->{frame} % @$anim ]
3336 if $anim && @$anim;
3337 }
3338 3410
3339 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]]; 3411 my $tex = $::CONN->{texture}[$faceid];
3340 3412
3341 if ($tex) { 3413 if ($tex) {
3342 glEnable GL_TEXTURE_2D; 3414 glEnable GL_TEXTURE_2D;
3343 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 3415 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
3344 glColor 0, 0, 0, 1; 3416 glColor 0, 0, 0, 1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines