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.462 by root, Thu Mar 20 22:28:33 2008 UTC vs.
Revision 1.472 by root, Wed Dec 24 04:09:27 2008 UTC

286sub set_visible { 286sub set_visible {
287 my ($self) = @_; 287 my ($self) = @_;
288 288
289 return if $self->{visible}; 289 return if $self->{visible};
290 290
291 $self->{parent} && $self->{parent}{root}#d#
292 or return ::clienterror ("set_visible called without parent ($self->{parent}) or root\n" => 1);
293
291 $self->{root} = $self->{parent}{root}; 294 $self->{root} = $self->{parent}{root};
292 $self->{visible} = $self->{parent}{visible} + 1; 295 $self->{visible} = $self->{parent}{visible} + 1;
293 296
294 $self->emit (visibility_change => 1); 297 $self->emit (visibility_change => 1);
295 298
296 $self->realloc if !exists $self->{req_w}; 299 $self->realloc if !exists $self->{req_w};
297 300
298 $_->set_visible for $self->children; 301 $_->set_visible for $self->visible_children;
299} 302}
300 303
301sub set_invisible { 304sub set_invisible {
302 my ($self) = @_; 305 my ($self) = @_;
303 306
1256 fontsize => ($arg{border} || 0.8) * 0.75; 1259 fontsize => ($arg{border} || 0.8) * 0.75;
1257 } 1260 }
1258 1261
1259 my $self = $class->SUPER::new ( 1262 my $self = $class->SUPER::new (
1260 # label => "", 1263 # label => "",
1261 fg => [0.6, 0.3, 0.1], 1264 fg => undef,
1262 border => 0.8, 1265 border => 0.8,
1263 style => 'single', 1266 style => 'single',
1264 %arg, 1267 %arg,
1265 ); 1268 );
1266 1269
1319 my $border = $self->border; 1322 my $border = $self->border;
1320 my ($w, $h) = ($self->{w}, $self->{h}); 1323 my ($w, $h) = ($self->{w}, $self->{h});
1321 1324
1322 $child->draw; 1325 $child->draw;
1323 1326
1324 glColor @{$self->{fg}}; 1327 glColor @{$self->{fg} || $DC::THEME{fancyframe}};
1325 glBegin GL_LINE_STRIP; 1328 glBegin GL_LINE_STRIP;
1326 glVertex $border * 1.5 , $border * 0.5 + 0.5; 1329 glVertex $border * 1.5 , $border * 0.5 + 0.5;
1327 glVertex $border * 0.5 + 0.5, $border * 0.5 + 0.5; 1330 glVertex $border * 0.5 + 0.5, $border * 0.5 + 0.5;
1328 glVertex $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5; 1331 glVertex $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5;
1329 glVertex $w - $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5; 1332 glVertex $w - $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5;
1344our @ISA = DC::UI::Bin::; 1347our @ISA = DC::UI::Bin::;
1345 1348
1346use DC::OpenGL; 1349use DC::OpenGL;
1347 1350
1348my $bg = 1351my $bg =
1349 new_from_file DC::Texture DC::find_rcfile "d1_bg.png", 1352 new_from_resource DC::Texture "d1_bg.png",
1350 mipmap => 1, wrap => 1; 1353 mipmap => 1, wrap => 1;
1351 1354
1352my @border = 1355my @border =
1353 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 1356 map { new_from_resource DC::Texture $_, mipmap => 1 }
1354 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); 1357 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
1355 1358
1356my @icon = 1359my @icon =
1357 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 1360 map { new_from_resource DC::Texture $_, mipmap => 1 }
1358 qw(x1_move.png x1_resize.png); 1361 qw(x1_move.png x1_resize.png);
1359 1362
1360sub new { 1363sub new {
1361 my ($class, %arg) = @_; 1364 my ($class, %arg) = @_;
1362 1365
1363 my $self = $class->SUPER::new ( 1366 my $self = $class->SUPER::new (
1364 bg => [1, 1, 1, 1], 1367 bg => [1, 1, 1, 1],
1365 border_bg => [1, 1, 1, 1], 1368 border_bg => [1, 1, 1, 1],
1366 border => 0.6, 1369 border => 0.8,
1367 can_events => 1, 1370 can_events => 1,
1368 min_w => 64, 1371 min_w => 64,
1369 min_h => 32, 1372 min_h => 32,
1370 %arg, 1373 %arg,
1371 ); 1374 );
2090 my $class = shift; 2093 my $class = shift;
2091 2094
2092 $class->SUPER::new ( 2095 $class->SUPER::new (
2093 fg => [1, 1, 1], 2096 fg => [1, 1, 1],
2094 bg => [0, 0, 0, 0.2], 2097 bg => [0, 0, 0, 0.2],
2095 outline => [0.6, 0.3, 0.1], 2098 outline => undef,
2096 active_bg => [0, 0, 1, .2], 2099 active_bg => [0, 0, 1, .2],
2097 active_fg => [1, 1, 1], 2100 active_fg => [1, 1, 1],
2098 active_outline => [1, 1, 0], 2101 active_outline => [1, 1, 0],
2099 can_hover => 1, 2102 can_hover => 1,
2100 can_focus => 1, 2103 can_focus => 1,
2158 2161
2159 my $text = $self->get_text; 2162 my $text = $self->get_text;
2160 2163
2161 $self->{cursor} = List::Util::max 0, List::Util::min $self->{cursor}, length $text; 2164 $self->{cursor} = List::Util::max 0, List::Util::min $self->{cursor}, length $text;
2162 2165
2163 if ($uni == 8) { 2166 if ($sym == DC::SDLK_BACKSPACE) {
2164 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 2167 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
2165 } elsif ($uni == 127) { 2168 } elsif ($sym == DC::SDLK_DELETE) {
2166 substr $text, $self->{cursor}, 1, ""; 2169 substr $text, $self->{cursor}, 1, "";
2167 } elsif ($sym == DC::SDLK_LEFT) { 2170 } elsif ($sym == DC::SDLK_LEFT) {
2168 --$self->{cursor} if $self->{cursor}; 2171 --$self->{cursor} if $self->{cursor};
2169 } elsif ($sym == DC::SDLK_RIGHT) { 2172 } elsif ($sym == DC::SDLK_RIGHT) {
2170 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 2173 ++$self->{cursor} if $self->{cursor} < length $self->{text};
2273 glColor @{$self->{active_outline}}; 2276 glColor @{$self->{active_outline}};
2274 glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5; 2277 glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5;
2275 glLineWidth 1; 2278 glLineWidth 1;
2276 2279
2277 } else { 2280 } else {
2278 glColor @{$self->{outline}}; 2281 glColor @{$self->{outline} || $DC::THEME{entry_outline}};
2279 glBegin GL_LINE_STRIP; 2282 glBegin GL_LINE_STRIP;
2280 glVertex .5, $self->{h} * .5; 2283 glVertex .5, $self->{h} * .5;
2281 glVertex .5, $self->{h} - 2.5; 2284 glVertex .5, $self->{h} - 2.5;
2282 glVertex $self->{w} - .5, $self->{h} - 2.5; 2285 glVertex $self->{w} - .5, $self->{h} - 2.5;
2283 glVertex $self->{w} - .5, $self->{h} * .5; 2286 glVertex $self->{w} - .5, $self->{h} * .5;
2405our @ISA = DC::UI::Bin::; 2408our @ISA = DC::UI::Bin::;
2406 2409
2407use DC::OpenGL; 2410use DC::OpenGL;
2408 2411
2409my @tex = 2412my @tex =
2410 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 2413 map { new_from_resource DC::Texture $_, mipmap => 1 }
2411 qw(b1_button_inactive.png b1_button_active.png); 2414 qw(b1_button_inactive.png b1_button_active.png);
2412 2415
2413sub new { 2416sub new {
2414 my $class = shift; 2417 my $class = shift;
2415 2418
2454our @ISA = DC::UI::Label::; 2457our @ISA = DC::UI::Label::;
2455 2458
2456use DC::OpenGL; 2459use DC::OpenGL;
2457 2460
2458my @tex = 2461my @tex =
2459 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 2462 map { new_from_resource DC::Texture $_, mipmap => 1 }
2460 qw(b1_button_inactive.png b1_button_active.png); 2463 qw(b1_button_inactive.png b1_button_active.png);
2461 2464
2462sub new { 2465sub new {
2463 my $class = shift; 2466 my $class = shift;
2464 2467
2507package DC::UI::CheckBox; 2510package DC::UI::CheckBox;
2508 2511
2509our @ISA = DC::UI::DrawBG::; 2512our @ISA = DC::UI::DrawBG::;
2510 2513
2511my @tex = 2514my @tex =
2512 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 2515 map { new_from_resource DC::Texture $_, mipmap => 1 }
2513 qw(c1_checkbox_bg.png c1_checkbox_active.png); 2516 qw(c1_checkbox_bg.png c1_checkbox_active.png);
2514 2517
2515use DC::OpenGL; 2518use DC::OpenGL;
2516 2519
2517sub new { 2520sub new {
2598 2601
2599 $self->{path} || $self->{tex} 2602 $self->{path} || $self->{tex}
2600 or Carp::croak "'path' or 'tex' attributes required"; 2603 or Carp::croak "'path' or 'tex' attributes required";
2601 2604
2602 $self->{tex} ||= $texture_cache{$self->{path}} ||= 2605 $self->{tex} ||= $texture_cache{$self->{path}} ||=
2603 new_from_file DC::Texture DC::find_rcfile $self->{path}, mipmap => 1; 2606 new_from_resource DC::Texture $self->{path}, mipmap => 1;
2604 2607
2605 DC::weaken $texture_cache{$self->{path}}; 2608 DC::weaken $texture_cache{$self->{path}};
2606 2609
2607 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; 2610 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2608 2611
2704 2707
2705use DC::OpenGL; 2708use DC::OpenGL;
2706 2709
2707my %tex = ( 2710my %tex = (
2708 food => [ 2711 food => [
2709 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 2712 map { new_from_resource DC::Texture $_, mipmap => 1 }
2710 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 2713 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
2711 ], 2714 ],
2712 grace => [ 2715 grace => [
2713 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 2716 map { new_from_resource DC::Texture $_, mipmap => 1 }
2714 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/ 2717 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/
2715 ], 2718 ],
2716 hp => [ 2719 hp => [
2717 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 2720 map { new_from_resource DC::Texture $_, mipmap => 1 }
2718 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 2721 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
2719 ], 2722 ],
2720 mana => [ 2723 mana => [
2721 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 2724 map { new_from_resource DC::Texture $_, mipmap => 1 }
2722 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/ 2725 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/
2723 ], 2726 ],
2724); 2727);
2725 2728
2726# eg. VGauge->new (gauge => 'food'), default gauge: food 2729# eg. VGauge->new (gauge => 'food'), default gauge: food
3023use DC::OpenGL; 3026use DC::OpenGL;
3024 3027
3025our @ISA = DC::UI::DrawBG::; 3028our @ISA = DC::UI::DrawBG::;
3026 3029
3027my @tex = 3030my @tex =
3028 map { new_from_file DC::Texture DC::find_rcfile $_ } 3031 map { new_from_resource DC::Texture $_ }
3029 qw(s1_slider.png s1_slider_bg.png); 3032 qw(s1_slider.png s1_slider_bg.png);
3030 3033
3031sub new { 3034sub new {
3032 my $class = shift; 3035 my $class = shift;
3033 3036
3070sub set_value { 3073sub set_value {
3071 my ($self, $value) = @_; 3074 my ($self, $value) = @_;
3072 3075
3073 my ($old_value, $lo, $hi, $page, $unit) = @{$self->{range}}; 3076 my ($old_value, $lo, $hi, $page, $unit) = @{$self->{range}};
3074 3077
3075 $hi = $lo + 1 if $hi <= $lo; 3078 $hi = $lo if $hi < $lo;
3076 3079
3077 $page = $hi - $lo if $page > $hi - $lo; 3080 $value = $hi - $page if $value > $hi - $page;
3078
3079 $value = $lo if $value < $lo; 3081 $value = $lo if $value < $lo;
3080 $value = $hi - $page if $value > $hi - $page;
3081 3082
3082 $value = $lo + $unit * int +($value - $lo + $unit * 0.5) / $unit 3083 $value = $lo + $unit * int +($value - $lo + $unit * 0.5) / $unit
3083 if $unit; 3084 if $unit;
3084 3085
3085 @{$self->{range}} = ($value, $lo, $hi, $page, $unit); 3086 @{$self->{range}} = ($value, $lo, $hi, $page, $unit);
3149 my ($self) = @_; 3150 my ($self) = @_;
3150 3151
3151 unless ($self->{knob_w}) { 3152 unless ($self->{knob_w}) {
3152 $self->set_value ($self->{range}[0]); 3153 $self->set_value ($self->{range}[0]);
3153 3154
3154 my ($value, $lo, $hi, $page) = @{$self->{range}}; 3155 my ($value, $lo, $hi, $page, $unit) = @{$self->{range}};
3155 my $range = ($hi - $page - $lo) || 1e-100; 3156 my $range = ($hi - $page - $lo) || 1e-10;
3156 3157
3157 my $knob_w = List::Util::min 1, $page / ($hi - $lo) || 0.1; 3158 my $knob_w = List::Util::min 1, $page / (($hi - $lo) || 1e-10) || 24 / $self->{w};
3158 3159
3159 $self->{offset} = List::Util::max $self->{inner_pad}, $knob_w * 0.5; 3160 $self->{offset} = List::Util::max $self->{inner_pad}, $knob_w * 0.5;
3160 $self->{scale} = 1 - 2 * $self->{offset} || 1e-100; 3161 $self->{scale} = 1 - 2 * $self->{offset} || 1e-100;
3161 3162
3162 $value = ($value - $lo) / $range; 3163 $value = ($value - $lo) / $range;
3622 3623
3623 $tip =~ s/^\n+//; 3624 $tip =~ s/^\n+//;
3624 $tip =~ s/\n+$//; 3625 $tip =~ s/\n+$//;
3625 3626
3626 $self->add (new DC::UI::Label 3627 $self->add (new DC::UI::Label
3628 fg => $DC::THEME{tooltip_fg},
3627 markup => $tip, 3629 markup => $tip,
3628 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 3630 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
3629 align => 0, 3631 align => 0,
3630 fontsize => 0.8, 3632 fontsize => 0.8,
3631 style => 1, # FLAG_INVERSE 3633 style => $DC::THEME{tooltip_style}, # FLAG_INVERSE
3632 ellipsise => 0, 3634 ellipsise => 0,
3633 font => ($widget->{tooltip_font} || $::FONT_PROP), 3635 font => ($widget->{tooltip_font} || $::FONT_PROP),
3634 ); 3636 );
3635} 3637}
3636 3638
3673sub _draw { 3675sub _draw {
3674 my ($self) = @_; 3676 my ($self) = @_;
3675 3677
3676 my ($w, $h) = @$self{qw(w h)}; 3678 my ($w, $h) = @$self{qw(w h)};
3677 3679
3678 glColor 1, 0.8, 0.4; 3680 glColor @{ $DC::THEME{tooltip_bg} };
3679 glRect 0, 0, $w, $h; 3681 glRect 0, 0, $w, $h;
3680 3682
3681 glColor 0, 0, 0; 3683 glColor @{ $DC::THEME{tooltip_border} };
3682 glRect_lineloop .5, .5, $w + .5, $h + .5; 3684 glRect_lineloop .5, .5, $w + .5, $h + .5;
3683 3685
3684 glTranslate 2, 2; 3686 glTranslate 2, 2;
3685 3687
3686 $self->SUPER::_draw; 3688 $self->SUPER::_draw;
3858 $widget = new DC::UI::HBox 3860 $widget = new DC::UI::HBox
3859 can_hover => 1, 3861 can_hover => 1,
3860 can_events => 1, 3862 can_events => 1,
3861 tooltip => $tooltip, 3863 tooltip => $tooltip,
3862 children => [ 3864 children => [
3863 (new DC::UI::Label markup => $left, expand => 1), 3865 (new DC::UI::Label markup => $left , align => 0, expand => 1),
3864 (new DC::UI::Label markup => $right, align => 1), 3866 (new DC::UI::Label markup => $right, align => 1),
3865 ], 3867 ],
3866 ; 3868 ;
3867 3869
3868 } else { 3870 } else {
3934 3936
3935 my $self = $class->SUPER::new ( 3937 my $self = $class->SUPER::new (
3936 @_, 3938 @_,
3937 ); 3939 );
3938 3940
3939 $self->{current} = $self->{children}[0] 3941 $self->set_current_page (0);
3940 if @{ $self->{children} };
3941 3942
3942 $self 3943 $self
3943} 3944}
3944 3945
3945sub add { 3946sub add {
3946 my ($self, @widgets) = @_; 3947 my ($self, @widgets) = @_;
3947 3948
3948 $self->SUPER::add (@widgets); 3949 $self->SUPER::add (@widgets);
3949 3950
3950 $self->{current} = $self->{children}[0] 3951 $self->set_current_page (0)
3951 if @{ $self->{children} }; 3952 if @widgets == @{ $self->{children} };
3952} 3953}
3953 3954
3954sub get_current_page { 3955sub get_current_page {
3955 my ($self) = @_; 3956 my ($self) = @_;
3956 3957
3962 3963
3963 my $widget = ref $page_or_widget 3964 my $widget = ref $page_or_widget
3964 ? $page_or_widget 3965 ? $page_or_widget
3965 : $self->{children}[$page_or_widget]; 3966 : $self->{children}[$page_or_widget];
3966 3967
3968 $self->{current}->set_invisible if $self->{current} && $self->{visible};
3969
3967 $self->{current} = $widget; 3970 if (($self->{current} = $widget)) {
3971 $self->{current}->set_visible if $self->{current} && $self->{visible};
3968 $self->{current}->configure (0, 0, $self->{w}, $self->{h}); 3972 $self->{current}->configure (0, 0, $self->{w}, $self->{h});
3969 3973
3970 $self->emit (page_changed => $self->{current}); 3974 $self->emit (page_changed => $self->{current});
3975 }
3971 3976
3972 $self->realloc; 3977 $self->realloc;
3973} 3978}
3974 3979
3975sub visible_children { 3980sub visible_children {
3976 $_[0]{current} 3981 $_[0]{current} || ()
3977} 3982}
3978 3983
3979sub size_request { 3984sub size_request {
3980 my ($self) = @_; 3985 my ($self) = @_;
3981 3986
3987 $self->{current}
3982 $self->{current}->size_request 3988 ? $self->{current}->size_request
3989 : (0, 0)
3983} 3990}
3984 3991
3985sub invoke_size_allocate { 3992sub invoke_size_allocate {
3986 my ($self, $w, $h) = @_; 3993 my ($self, $w, $h) = @_;
3987 3994
3988 $self->{current}->configure (0, 0, $w, $h); 3995 $self->{current}->configure (0, 0, $w, $h)
3996 if $self->{current};
3989 3997
3990 1 3998 1
3991} 3999}
3992 4000
3993sub _draw { 4001sub _draw {
3994 my ($self) = @_; 4002 my ($self) = @_;
3995 4003
3996 $self->{current}->draw; 4004 $self->{current}->draw
4005 if $self->{current};
3997} 4006}
3998 4007
3999############################################################################# 4008#############################################################################
4000 4009
4001package DC::UI::Notebook; 4010package DC::UI::Notebook;
4211 $self 4220 $self
4212} 4221}
4213 4222
4214sub reorder { 4223sub reorder {
4215 my ($self) = @_; 4224 my ($self) = @_;
4216 my $NOW = Time::HiRes::time; 4225 my $NOW = EV::time;
4217 4226
4218 # freeze display when hovering over any label 4227 # freeze display when hovering over any label
4219 return if $DC::UI::TOOLTIP->{owner} 4228 return if $DC::UI::TOOLTIP->{owner}
4220 && grep $DC::UI::TOOLTIP->{owner} == $_->{label}, 4229 && grep $DC::UI::TOOLTIP->{owner} == $_->{label},
4221 values %{ $self->{item} }; 4230 values %{ $self->{item} };
4271 $label->{fg}[3] = $item->{fg}[3] || 1; 4280 $label->{fg}[3] = $item->{fg}[3] || 1;
4272 } 4281 }
4273 4282
4274 push @widgets, $label; 4283 push @widgets, $label;
4275 } 4284 }
4285
4286 my $hash = join ",", @widgets;
4287 return if $hash eq $self->{last_widget_hash};
4288 $self->{last_widget_hash} = $hash;
4276 4289
4277 $self->clear; 4290 $self->clear;
4278 $self->SUPER::add (reverse @widgets); 4291 $self->SUPER::add (reverse @widgets);
4279} 4292}
4280 4293

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines