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.468 by root, Wed Sep 3 10:36:25 2008 UTC vs.
Revision 1.473 by root, Sun Jan 11 03:19:47 2009 UTC

189# call when resolution changes etc. 189# call when resolution changes etc.
190sub rescale_widgets { 190sub rescale_widgets {
191 my ($sx, $sy) = @_; 191 my ($sx, $sy) = @_;
192 192
193 for my $widget (values %WIDGET) { 193 for my $widget (values %WIDGET) {
194 if ($widget->{is_toplevel}) { 194 if ($widget->{is_toplevel} || $widget->{c_rescale}) {
195 $widget->{x} += int $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; 195 $widget->{x} += int $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/;
196 $widget->{y} += int $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; 196 $widget->{y} += int $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/;
197 197
198 $widget->{x} = int 0.5 + $widget->{x} * $sx if $widget->{x} =~ /^[0-9.]+$/; 198 $widget->{x} = int 0.5 + $widget->{x} * $sx if $widget->{x} =~ /^[0-9.]+$/;
199 $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; 199 $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w};
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
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 => 1, 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 );
1540 glEnable GL_TEXTURE_2D; 1543 glEnable GL_TEXTURE_2D;
1541 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1544 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1542 1545
1543 my $border = $self->border; 1546 my $border = $self->border;
1544 1547
1548 if ($border) {
1545 glColor @{ $self->{border_bg} }; 1549 glColor @{ $self->{border_bg} };
1546 $border[0]->draw_quad_alpha ( 0, 0, $w, $border); 1550 $border[0]->draw_quad_alpha ( 0, 0, $w, $border);
1547 $border[1]->draw_quad_alpha ( 0, $border, $border, $ch); 1551 $border[1]->draw_quad_alpha ( 0, $border, $border, $ch);
1548 $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); 1552 $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch);
1549 $border[3]->draw_quad_alpha ( 0, $h - $border, $w, $border); 1553 $border[3]->draw_quad_alpha ( 0, $h - $border, $w, $border);
1550 1554
1551 # move 1555 # move
1552 my $w2 = ($w - $border) * .5; 1556 my $w2 = ($w - $border) * .5;
1553 my $h2 = ($h - $border) * .5; 1557 my $h2 = ($h - $border) * .5;
1554 $icon[0]->draw_quad_alpha ( 0, $h2, $border, $border); 1558 $icon[0]->draw_quad_alpha ( 0, $h2, $border, $border);
1555 $icon[0]->draw_quad_alpha ($w - $border, $h2, $border, $border); 1559 $icon[0]->draw_quad_alpha ($w - $border, $h2, $border, $border);
1556 $icon[0]->draw_quad_alpha ($w2 , $h - $border, $border, $border); 1560 $icon[0]->draw_quad_alpha ($w2 , $h - $border, $border, $border);
1557 1561
1558 # resize 1562 # resize
1559 $icon[1]->draw_quad_alpha ( 0, 0, $border, $border); 1563 $icon[1]->draw_quad_alpha ( 0, 0, $border, $border);
1560 $icon[1]->draw_quad_alpha ($w - $border, 0, $border, $border) 1564 $icon[1]->draw_quad_alpha ($w - $border, 0, $border, $border)
1561 unless $self->{has_close_button}; 1565 unless $self->{has_close_button};
1562 $icon[1]->draw_quad_alpha ( 0, $h - $border, $border, $border); 1566 $icon[1]->draw_quad_alpha ( 0, $h - $border, $border, $border);
1563 $icon[1]->draw_quad_alpha ($w - $border, $h - $border, $border, $border); 1567 $icon[1]->draw_quad_alpha ($w - $border, $h - $border, $border, $border);
1568 }
1564 1569
1565 if (@{$self->{bg}} < 4 || $self->{bg}[3]) { 1570 if (@{$self->{bg}} < 4 || $self->{bg}[3]) {
1566 glColor @{ $self->{bg} }; 1571 glColor @{ $self->{bg} };
1567 1572
1568 # TODO: repeat texture not scale 1573 # TODO: repeat texture not scale
2839 2844
2840sub new { 2845sub new {
2841 my ($class, %arg) = @_; 2846 my ($class, %arg) = @_;
2842 2847
2843 my $self = $class->SUPER::new ( 2848 my $self = $class->SUPER::new (
2849 padding_x => 2,
2850 padding_y => 2,
2844 fg => [1, 1, 1], 2851 fg => [1, 1, 1],
2845 bg => [0, 0, 1, 0.2], 2852 bg => [0, 0, 1, 0.2],
2846 bar => [0.7, 0.5, 0.1, 0.8], 2853 bar => [0.7, 0.5, 0.1, 0.8],
2847 outline => [0.4, 0.3, 0], 2854 outline => [0.4, 0.3, 0],
2848 fontsize => 0.9, 2855 fontsize => 0.9,
2888 my ($self) = @_; 2895 my ($self) = @_;
2889 2896
2890 glEnable GL_BLEND; 2897 glEnable GL_BLEND;
2891 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; 2898 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2892 2899
2900 my $px = $self->{padding_x};
2901 my $py = $self->{padding_y};
2902
2893 if ($self->{value} >= 0) { 2903 if ($self->{value} >= 0) {
2894 my $s = int 2 + ($self->{w} - 4) * $self->{value}; 2904 my $s = int $px + ($self->{w} - $px * 2) * $self->{value};
2895 2905
2896 glColor_premultiply @{$self->{bar}}; 2906 glColor_premultiply @{$self->{bar}};
2897 glRect 2, 2, $s, $self->{h} - 2; 2907 glRect $px, $py, $s, $self->{h} - $py;
2898 glColor_premultiply @{$self->{bg}}; 2908 glColor_premultiply @{$self->{bg}};
2899 glRect $s, 2, $self->{w} - 2, $self->{h} - 2; 2909 glRect $s , $py, $self->{w} - $px, $self->{h} - $py;
2900 } 2910 }
2901 2911
2902 glColor_premultiply @{$self->{outline}}; 2912 glColor_premultiply @{$self->{outline}};
2913
2914 $px -= .5;
2915 $py -= .5;
2916
2903 glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5; 2917 glRect_lineloop $px, $py, $self->{w} - $px, $self->{h} - $py;
2904 2918
2905 glDisable GL_BLEND; 2919 glDisable GL_BLEND;
2906 2920
2907 { 2921 {
2908 local $self->{bg}; # do not draw background 2922 local $self->{bg}; # do not draw background
2917our @ISA = DC::UI::Progress::; 2931our @ISA = DC::UI::Progress::;
2918 2932
2919sub new { 2933sub new {
2920 my ($class, %arg) = @_; 2934 my ($class, %arg) = @_;
2921 2935
2936 my $tt = exists $arg{tooltip} ? "$arg{tooltip}\n\n" : "";
2937
2922 my $self = $class->SUPER::new ( 2938 my $self = $class->SUPER::new (
2939 %arg,
2923 tooltip => sub { 2940 tooltip => sub {
2924 my ($self) = @_; 2941 my ($self) = @_;
2925 2942
2926 sprintf "level %d\n%s points\n%s next level\n%s to go", 2943 sprintf "%slevel %d\n%s points\n%s next level\n%s to go",
2944 $tt,
2927 $self->{lvl}, 2945 $self->{lvl},
2928 ::formsep ($self->{exp}), 2946 ::formsep ($self->{exp}),
2929 ::formsep ($self->{nxt}), 2947 ::formsep ($self->{nxt}),
2930 ::formsep ($self->{nxt} - $self->{exp}), 2948 ::formsep ($self->{nxt} - $self->{exp}),
2931 }, 2949 },
2932 %arg
2933 ); 2950 );
2934 2951
2935 $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) } 2952 $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) }
2936 if $::CONN; 2953 if $::CONN;
2937 2954
3892 $GRAB = $self; 3909 $GRAB = $self;
3893 $self->{button} = $ev->{button}; 3910 $self->{button} = $ev->{button};
3894 3911
3895 $self->show; 3912 $self->show;
3896 $self->move_abs ($ev->{x} - $self->{w} * 0.5, $ev->{y} - $self->{h} * 0.5); 3913 $self->move_abs ($ev->{x} - $self->{w} * 0.5, $ev->{y} - $self->{h} * 0.5);
3914
3915 1 # so it can be used inside event handlers
3897} 3916}
3898 3917
3899sub invoke_mouse_motion { 3918sub invoke_mouse_motion {
3900 my ($self, $ev, $x, $y) = @_; 3919 my ($self, $ev, $x, $y) = @_;
3901 3920
3933 3952
3934 my $self = $class->SUPER::new ( 3953 my $self = $class->SUPER::new (
3935 @_, 3954 @_,
3936 ); 3955 );
3937 3956
3938 $self->{current} = $self->{children}[0] 3957 $self->set_current_page (0);
3939 if @{ $self->{children} };
3940 3958
3941 $self 3959 $self
3942} 3960}
3943 3961
3944sub add { 3962sub add {
3945 my ($self, @widgets) = @_; 3963 my ($self, @widgets) = @_;
3946 3964
3947 $self->SUPER::add (@widgets); 3965 $self->SUPER::add (@widgets);
3948 3966
3949 $self->{current} = $self->{children}[0] 3967 $self->set_current_page (0)
3950 if @{ $self->{children} }; 3968 if @widgets == @{ $self->{children} };
3951} 3969}
3952 3970
3953sub get_current_page { 3971sub get_current_page {
3954 my ($self) = @_; 3972 my ($self) = @_;
3955 3973
3961 3979
3962 my $widget = ref $page_or_widget 3980 my $widget = ref $page_or_widget
3963 ? $page_or_widget 3981 ? $page_or_widget
3964 : $self->{children}[$page_or_widget]; 3982 : $self->{children}[$page_or_widget];
3965 3983
3984 $self->{current}->set_invisible if $self->{current} && $self->{visible};
3985
3966 $self->{current} = $widget; 3986 if (($self->{current} = $widget)) {
3987 $self->{current}->set_visible if $self->{current} && $self->{visible};
3967 $self->{current}->configure (0, 0, $self->{w}, $self->{h}); 3988 $self->{current}->configure (0, 0, $self->{w}, $self->{h});
3968 3989
3969 $self->emit (page_changed => $self->{current}); 3990 $self->emit (page_changed => $self->{current});
3991 }
3970 3992
3971 $self->realloc; 3993 $self->realloc;
3972} 3994}
3973 3995
3974sub visible_children { 3996sub visible_children {
3975 $_[0]{current} 3997 $_[0]{current} || ()
3976} 3998}
3977 3999
3978sub size_request { 4000sub size_request {
3979 my ($self) = @_; 4001 my ($self) = @_;
3980 4002
4003 $self->{current}
3981 $self->{current}->size_request 4004 ? $self->{current}->size_request
4005 : (0, 0)
3982} 4006}
3983 4007
3984sub invoke_size_allocate { 4008sub invoke_size_allocate {
3985 my ($self, $w, $h) = @_; 4009 my ($self, $w, $h) = @_;
3986 4010
3987 $self->{current}->configure (0, 0, $w, $h); 4011 $self->{current}->configure (0, 0, $w, $h)
4012 if $self->{current};
3988 4013
3989 1 4014 1
3990} 4015}
3991 4016
3992sub _draw { 4017sub _draw {
3993 my ($self) = @_; 4018 my ($self) = @_;
3994 4019
3995 $self->{current}->draw; 4020 $self->{current}->draw
4021 if $self->{current};
3996} 4022}
3997 4023
3998############################################################################# 4024#############################################################################
3999 4025
4000package DC::UI::Notebook; 4026package DC::UI::Notebook;
4210 $self 4236 $self
4211} 4237}
4212 4238
4213sub reorder { 4239sub reorder {
4214 my ($self) = @_; 4240 my ($self) = @_;
4215 my $NOW = Time::HiRes::time; 4241 my $NOW = EV::time;
4216 4242
4217 # freeze display when hovering over any label 4243 # freeze display when hovering over any label
4218 return if $DC::UI::TOOLTIP->{owner} 4244 return if $DC::UI::TOOLTIP->{owner}
4219 && grep $DC::UI::TOOLTIP->{owner} == $_->{label}, 4245 && grep $DC::UI::TOOLTIP->{owner} == $_->{label},
4220 values %{ $self->{item} }; 4246 values %{ $self->{item} };
4270 $label->{fg}[3] = $item->{fg}[3] || 1; 4296 $label->{fg}[3] = $item->{fg}[3] || 1;
4271 } 4297 }
4272 4298
4273 push @widgets, $label; 4299 push @widgets, $label;
4274 } 4300 }
4301
4302 my $hash = join ",", @widgets;
4303 return if $hash eq $self->{last_widget_hash};
4304 $self->{last_widget_hash} = $hash;
4275 4305
4276 $self->clear; 4306 $self->clear;
4277 $self->SUPER::add (reverse @widgets); 4307 $self->SUPER::add (reverse @widgets);
4278} 4308}
4279 4309
4584 4614
4585$ROOT = new DC::UI::Root; 4615$ROOT = new DC::UI::Root;
4586$TOOLTIP = new DC::UI::Tooltip z => 900; 4616$TOOLTIP = new DC::UI::Tooltip z => 900;
4587 4617
45881 46181
4589

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines