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.470 by root, Fri Sep 19 02:24:32 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines