… | |
… | |
18 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
18 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
19 | if (exists $widget->{tooltip}) { |
19 | if (exists $widget->{tooltip}) { |
20 | |
20 | |
21 | if ($TOOLTIP->{owner} != $widget) { |
21 | if ($TOOLTIP->{owner} != $widget) { |
22 | $TOOLTIP->{owner} = $widget; |
22 | $TOOLTIP->{owner} = $widget; |
|
|
23 | |
|
|
24 | my $tip = $widget->{tooltip}; |
|
|
25 | |
|
|
26 | $tip = $tip->($widget) if CODE:: eq ref $tip; |
|
|
27 | |
23 | $TOOLTIP->set_text ($widget->{tooltip}); |
28 | $TOOLTIP->set_text ($widget->{tooltip}); |
24 | $TOOLTIP->move ($widget->coord2global ($widget->{w}, 0)); |
29 | $TOOLTIP->move ($widget->coord2global ($widget->{w}, 0)); |
25 | $TOOLTIP->show; |
30 | $TOOLTIP->show; |
26 | } |
31 | } |
27 | |
32 | |
… | |
… | |
1179 | |
1184 | |
1180 | sub set_fontsize { |
1185 | sub set_fontsize { |
1181 | my ($self, $fontsize) = @_; |
1186 | my ($self, $fontsize) = @_; |
1182 | |
1187 | |
1183 | $self->{fontsize} = $fontsize; |
1188 | $self->{fontsize} = $fontsize; |
|
|
1189 | delete $self->{texture}; |
1184 | $self->check_size; |
1190 | $self->check_size; |
|
|
1191 | $self->update; |
1185 | } |
1192 | } |
1186 | |
1193 | |
1187 | sub _draw { |
1194 | sub _draw { |
1188 | my ($self) = @_; |
1195 | my ($self) = @_; |
1189 | |
1196 | |
… | |
… | |
1721 | my $self = $class->SUPER::new ( |
1728 | my $self = $class->SUPER::new ( |
1722 | tooltip => $arg{type}, |
1729 | tooltip => $arg{type}, |
1723 | %arg, |
1730 | %arg, |
1724 | ); |
1731 | ); |
1725 | |
1732 | |
1726 | $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); |
1733 | $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999", can_events => 1, can_hover => 1); |
1727 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1); |
1734 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_events => 1, can_hover => 1); |
1728 | $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999"); |
1735 | $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999", can_events => 1, can_hover => 1); |
1729 | |
1736 | |
1730 | $self |
1737 | $self |
1731 | } |
1738 | } |
1732 | |
1739 | |
1733 | sub set_fontsize { |
1740 | sub set_fontsize { |
… | |
… | |
2129 | $self->emit (changed => $self->{state}); |
2136 | $self->emit (changed => $self->{state}); |
2130 | } |
2137 | } |
2131 | |
2138 | |
2132 | ############################################################################# |
2139 | ############################################################################# |
2133 | |
2140 | |
|
|
2141 | package CFClient::UI::Tooltip; |
|
|
2142 | |
|
|
2143 | our @ISA = CFClient::UI::Bin::; |
|
|
2144 | |
|
|
2145 | use CFClient::OpenGL; |
|
|
2146 | |
|
|
2147 | sub new { |
|
|
2148 | my $class = shift; |
|
|
2149 | |
|
|
2150 | $class->SUPER::new ( |
|
|
2151 | @_, |
|
|
2152 | can_events => 0, |
|
|
2153 | ) |
|
|
2154 | } |
|
|
2155 | |
|
|
2156 | sub set_text { |
|
|
2157 | my ($self, $text) = @_; |
|
|
2158 | |
|
|
2159 | $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0]; |
|
|
2160 | $self->{label}->set_text ($text); |
|
|
2161 | $self->add ($self->{label}); |
|
|
2162 | } |
|
|
2163 | |
|
|
2164 | sub size_request { |
|
|
2165 | my ($self) = @_; |
|
|
2166 | |
|
|
2167 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
|
|
2168 | |
|
|
2169 | $w = List::Util::min $::WIDTH * 0.2, $w; |
|
|
2170 | $h = List::Util::max $::HEIGHT * 0.2, $h; |
|
|
2171 | |
|
|
2172 | ($w + 4, $h + 4) |
|
|
2173 | } |
|
|
2174 | |
|
|
2175 | sub _draw { |
|
|
2176 | my ($self) = @_; |
|
|
2177 | |
|
|
2178 | glPushMatrix; |
|
|
2179 | glTranslate 0.375, 0.375; |
|
|
2180 | |
|
|
2181 | my ($w, $h) = @$self{qw(w h)}; |
|
|
2182 | |
|
|
2183 | glColor 1, 0.8, 0.4; |
|
|
2184 | glBegin GL_QUADS; |
|
|
2185 | glVertex 0 , 0; |
|
|
2186 | glVertex 0 , $h; |
|
|
2187 | glVertex $w, $h; |
|
|
2188 | glVertex $w, 0; |
|
|
2189 | glEnd; |
|
|
2190 | |
|
|
2191 | glColor 0, 0, 0; |
|
|
2192 | glBegin GL_LINE_LOOP; |
|
|
2193 | glVertex 0 , 0; |
|
|
2194 | glVertex 0 , $h; |
|
|
2195 | glVertex $w, $h; |
|
|
2196 | glVertex $w, 0; |
|
|
2197 | glEnd; |
|
|
2198 | |
|
|
2199 | glPopMatrix; |
|
|
2200 | |
|
|
2201 | glTranslate 2, 2; |
|
|
2202 | $self->SUPER::_draw; |
|
|
2203 | } |
|
|
2204 | |
|
|
2205 | ############################################################################# |
|
|
2206 | |
2134 | package CFClient::UI::Root; |
2207 | package CFClient::UI::Root; |
2135 | |
2208 | |
2136 | our @ISA = CFClient::UI::Container::; |
2209 | our @ISA = CFClient::UI::Container::; |
2137 | |
2210 | |
2138 | use CFClient::OpenGL; |
2211 | use CFClient::OpenGL; |
… | |
… | |
2213 | ############################################################################# |
2286 | ############################################################################# |
2214 | |
2287 | |
2215 | package CFClient::UI; |
2288 | package CFClient::UI; |
2216 | |
2289 | |
2217 | $ROOT = new CFClient::UI::Root; |
2290 | $ROOT = new CFClient::UI::Root; |
2218 | $TOOLTIP = new CFClient::UI::Label fontsize => 0.8, can_events => 0; |
2291 | $TOOLTIP = new CFClient::UI::Tooltip; |
2219 | |
2292 | |
2220 | 1 |
2293 | 1 |
2221 | |
2294 | |