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.150 by elmex, Sun Apr 23 00:08:29 2006 UTC vs.
Revision 1.152 by root, Sun Apr 23 01:05:03 2006 UTC

8use CFClient; 8use CFClient;
9 9
10our ($FOCUS, $HOVER, $GRAB); # various widgets 10our ($FOCUS, $HOVER, $GRAB); # various widgets
11 11
12our $ROOT; 12our $ROOT;
13our $TOOLTIP;
13our $BUTTON_STATE; 14our $BUTTON_STATE;
15
16sub check_tooltip {
17 if (!$GRAB) {
18 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) {
19 if (exists $widget->{tooltip}) {
20
21 if ($TOOLTIP->{owner} != $widget) {
22 $TOOLTIP->{owner} = $widget;
23 $TOOLTIP->set_text ($widget->{tooltip});
24 $TOOLTIP->move ($widget->coord2global ($widget->{w}, 0));
25 $TOOLTIP->show;
26 }
27
28 return;
29 }
30 }
31 }
32
33 $TOOLTIP->hide;
34 delete $TOOLTIP->{owner};
35}
14 36
15# class methods for events 37# class methods for events
16sub feed_sdl_key_down_event { 38sub feed_sdl_key_down_event {
17 $FOCUS->key_down ($_[0]) if $FOCUS; 39 $FOCUS->key_down ($_[0]) if $FOCUS;
18} 40}
28 if (!$BUTTON_STATE) { 50 if (!$BUTTON_STATE) {
29 my $widget = $ROOT->find_widget ($x, $y); 51 my $widget = $ROOT->find_widget ($x, $y);
30 52
31 $GRAB = $widget; 53 $GRAB = $widget;
32 $GRAB->update if $GRAB; 54 $GRAB->update if $GRAB;
55
56 check_tooltip;
33 } 57 }
34 58
35 $BUTTON_STATE |= 1 << ($ev->{button} - 1); 59 $BUTTON_STATE |= 1 << ($ev->{button} - 1);
36 60
37 $GRAB->button_down ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; 61 $GRAB->button_down ($ev, $GRAB->coord2local ($x, $y)) if $GRAB;
49 73
50 if (!$BUTTON_STATE) { 74 if (!$BUTTON_STATE) {
51 my $grab = $GRAB; undef $GRAB; 75 my $grab = $GRAB; undef $GRAB;
52 $grab->update if $grab; 76 $grab->update if $grab;
53 $GRAB->update if $GRAB; 77 $GRAB->update if $GRAB;
78
79 check_tooltip;
54 } 80 }
55} 81}
56 82
57sub feed_sdl_motion_event { 83sub feed_sdl_motion_event {
58 my ($ev) = @_; 84 my ($ev) = @_;
63 if ($widget != $HOVER) { 89 if ($widget != $HOVER) {
64 my $hover = $HOVER; $HOVER = $widget; 90 my $hover = $HOVER; $HOVER = $widget;
65 91
66 $hover->update if $hover && $hover->{can_hover}; 92 $hover->update if $hover && $hover->{can_hover};
67 $HOVER->update if $HOVER && $HOVER->{can_hover}; 93 $HOVER->update if $HOVER && $HOVER->{can_hover};
94
95 check_tooltip;
68 } 96 }
69 97
70 $HOVER->mouse_motion ($ev, $HOVER->coord2local ($x, $y)) if $HOVER; 98 $HOVER->mouse_motion ($ev, $HOVER->coord2local ($x, $y)) if $HOVER;
71} 99}
72 100
433 delete $child->{parent}; 461 delete $child->{parent};
434 462
435 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; 463 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
436 464
437 $self->check_size; 465 $self->check_size;
466 $self->update;
438} 467}
439 468
440sub find_widget { 469sub find_widget {
441 my ($self, $x, $y) = @_; 470 my ($self, $x, $y) = @_;
442 471
1150 1179
1151sub set_fontsize { 1180sub set_fontsize {
1152 my ($self, $fontsize) = @_; 1181 my ($self, $fontsize) = @_;
1153 1182
1154 $self->{fontsize} = $fontsize; 1183 $self->{fontsize} = $fontsize;
1184 delete $self->{texture};
1155 $self->check_size; 1185 $self->check_size;
1186 $self->update;
1156} 1187}
1157 1188
1158sub _draw { 1189sub _draw {
1159 my ($self) = @_; 1190 my ($self) = @_;
1160 1191
1685package CFClient::UI::Gauge; 1716package CFClient::UI::Gauge;
1686 1717
1687our @ISA = CFClient::UI::VBox::; 1718our @ISA = CFClient::UI::VBox::;
1688 1719
1689sub new { 1720sub new {
1690 my ($class, %arg) = shift; 1721 my ($class, %arg) = @_;
1691 1722
1692 my $self = $class->SUPER::new ( 1723 my $self = $class->SUPER::new (
1693 @_, 1724 tooltip => $arg{type},
1725 %arg,
1694 ); 1726 );
1695 1727
1696 $self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999"; 1728 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999");
1697 $self->{max} = new CFClient::UI::Label valign => 1, align => 0, template => "999";
1698 $self->add ($self->{value});
1699 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1); 1729 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1);
1700 $self->add ($self->{max}); 1730 $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999");
1701 1731
1702 $self 1732 $self
1703}
1704
1705sub size_request {
1706 my ($self) = @_;
1707 (($self->{max}->size_request)[0], 0)
1708} 1733}
1709 1734
1710sub set_fontsize { 1735sub set_fontsize {
1711 my ($self, $fsize) = @_; 1736 my ($self, $fsize) = @_;
1712 1737
2190############################################################################# 2215#############################################################################
2191 2216
2192package CFClient::UI; 2217package CFClient::UI;
2193 2218
2194$ROOT = new CFClient::UI::Root; 2219$ROOT = new CFClient::UI::Root;
2220$TOOLTIP = new CFClient::UI::Label fontsize => 0.8, can_events => 0;
2195 2221
21961 22221
2197 2223

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines