… | |
… | |
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 | |
… | |
… | |
204 | } |
209 | } |
205 | } |
210 | } |
206 | |
211 | |
207 | sub size_allocate { |
212 | sub size_allocate { |
208 | # nothing to be done |
213 | # nothing to be done |
|
|
214 | } |
|
|
215 | |
|
|
216 | sub set_max_size { |
|
|
217 | my ($self, $w, $h) = @_; |
|
|
218 | |
|
|
219 | delete $self->{max_w}; $self->{max_w} = $w if $w; |
|
|
220 | delete $self->{max_h}; $self->{max_h} = $h if $h; |
209 | } |
221 | } |
210 | |
222 | |
211 | # return top left coordinates |
223 | # return top left coordinates |
212 | sub _topleft { |
224 | sub _topleft { |
213 | my ($self, $x, $y) = @_; |
225 | my ($self, $x, $y) = @_; |
… | |
… | |
1094 | sub new { |
1106 | sub new { |
1095 | my ($class, %arg) = @_; |
1107 | my ($class, %arg) = @_; |
1096 | |
1108 | |
1097 | my $self = $class->SUPER::new ( |
1109 | my $self = $class->SUPER::new ( |
1098 | fg => [1, 1, 1], |
1110 | fg => [1, 1, 1], |
|
|
1111 | #font => default_font |
1099 | fontsize => 1, |
1112 | fontsize => 1, |
1100 | text => "", |
1113 | text => "", |
1101 | align => -1, |
1114 | align => -1, |
1102 | valign => -1, |
1115 | valign => -1, |
1103 | padding => 2, |
1116 | padding => 2, |
… | |
… | |
1149 | } |
1162 | } |
1150 | |
1163 | |
1151 | sub size_request { |
1164 | sub size_request { |
1152 | my ($self) = @_; |
1165 | my ($self) = @_; |
1153 | |
1166 | |
1154 | $self->{layout}->set_width; |
1167 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
|
|
1168 | $self->{layout}->set_width ($self->{max_w} || -1); |
1155 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1169 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1156 | |
1170 | |
1157 | my ($w, $h) = $self->{layout}->size; |
1171 | my ($w, $h) = $self->{layout}->size; |
1158 | |
1172 | |
1159 | if (exists $self->{template}) { |
1173 | if (exists $self->{template}) { |
|
|
1174 | $self->{template}->set_font ($self->{font}) if $self->{font}; |
1160 | $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); |
1175 | $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); |
1161 | |
1176 | |
1162 | my ($w2, $h2) = $self->{template}->size; |
1177 | my ($w2, $h2) = $self->{template}->size; |
1163 | |
1178 | |
1164 | $w = List::Util::max $w, $w2; |
1179 | $w = List::Util::max $w, $w2; |
… | |
… | |
1188 | |
1203 | |
1189 | sub _draw { |
1204 | sub _draw { |
1190 | my ($self) = @_; |
1205 | my ($self) = @_; |
1191 | |
1206 | |
1192 | my $tex = $self->{texture} ||= do { |
1207 | my $tex = $self->{texture} ||= do { |
|
|
1208 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1193 | $self->{layout}->set_width ($self->{w}); |
1209 | $self->{layout}->set_width ($self->{w}); |
1194 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1210 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1195 | new_from_layout CFClient::Texture $self->{layout} |
1211 | new_from_layout CFClient::Texture $self->{layout} |
1196 | }; |
1212 | }; |
1197 | |
1213 | |
… | |
… | |
1723 | my $self = $class->SUPER::new ( |
1739 | my $self = $class->SUPER::new ( |
1724 | tooltip => $arg{type}, |
1740 | tooltip => $arg{type}, |
1725 | %arg, |
1741 | %arg, |
1726 | ); |
1742 | ); |
1727 | |
1743 | |
1728 | $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); |
1744 | $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999", can_events => 1, can_hover => 1); |
1729 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1); |
1745 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_events => 1, can_hover => 1); |
1730 | $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999"); |
1746 | $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999", can_events => 1, can_hover => 1); |
1731 | |
1747 | |
1732 | $self |
1748 | $self |
1733 | } |
1749 | } |
1734 | |
1750 | |
1735 | sub set_fontsize { |
1751 | sub set_fontsize { |
… | |
… | |
1902 | sub new { |
1918 | sub new { |
1903 | my $class = shift; |
1919 | my $class = shift; |
1904 | |
1920 | |
1905 | my $self = $class->SUPER::new ( |
1921 | my $self = $class->SUPER::new ( |
1906 | fontsize => 1, |
1922 | fontsize => 1, |
|
|
1923 | #font => default_font |
1907 | @_, |
1924 | @_, |
1908 | |
1925 | |
1909 | layout => (new CFClient::Layout), |
1926 | layout => (new CFClient::Layout), |
1910 | par => [], |
1927 | par => [], |
1911 | height => 0, |
1928 | height => 0, |
… | |
… | |
1951 | sub size_allocate { |
1968 | sub size_allocate { |
1952 | my ($self, $w, $h) = @_; |
1969 | my ($self, $w, $h) = @_; |
1953 | |
1970 | |
1954 | $self->SUPER::size_allocate ($w, $h); |
1971 | $self->SUPER::size_allocate ($w, $h); |
1955 | |
1972 | |
|
|
1973 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1956 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1974 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1957 | $self->{layout}->set_width ($self->{children}[0]{w}); |
1975 | $self->{layout}->set_width ($self->{children}[0]{w}); |
1958 | |
1976 | |
1959 | $self->reflow; |
1977 | $self->reflow; |
1960 | } |
1978 | } |
… | |
… | |
2012 | my $y1 = $top + $self->{h}; |
2030 | my $y1 = $top + $self->{h}; |
2013 | |
2031 | |
2014 | my $y = 0; |
2032 | my $y = 0; |
2015 | |
2033 | |
2016 | my $layout = $self->{layout}; |
2034 | my $layout = $self->{layout}; |
|
|
2035 | |
|
|
2036 | $layout->set_font ($self->{font}) if $self->{font}; |
2017 | |
2037 | |
2018 | for my $par (@{$self->{par}}) { |
2038 | for my $par (@{$self->{par}}) { |
2019 | my $h = $par->[0]; |
2039 | my $h = $par->[0]; |
2020 | |
2040 | |
2021 | if ($y0 < $y + $h && $y < $y1) { |
2041 | if ($y0 < $y + $h && $y < $y1) { |
… | |
… | |
2149 | } |
2169 | } |
2150 | |
2170 | |
2151 | sub set_text { |
2171 | sub set_text { |
2152 | my ($self, $text) = @_; |
2172 | my ($self, $text) = @_; |
2153 | |
2173 | |
2154 | $self->{label} ||= new CFClient::UI::Label fontsize => 0.8; |
2174 | $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0]; |
2155 | $self->{label}->set_text ($text); |
2175 | $self->{label}->set_text ($text); |
2156 | $self->add ($self->{label}); |
2176 | $self->add ($self->{label}); |
2157 | } |
2177 | } |
2158 | |
2178 | |
2159 | sub size_request { |
2179 | sub size_request { |
2160 | my ($self) = @_; |
2180 | my ($self) = @_; |
2161 | |
2181 | |
|
|
2182 | $self->child->set_max_size ($::WIDTH * 0.2); |
|
|
2183 | |
2162 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
2184 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
2163 | |
2185 | |
2164 | $w = List::Util::min $::WIDTH * 0.2, $w; |
2186 | ($w + 4, $h + 4) |
|
|
2187 | } |
2165 | |
2188 | |
2166 | ($w, $h) |
2189 | sub _draw { |
|
|
2190 | my ($self) = @_; |
|
|
2191 | |
|
|
2192 | glPushMatrix; |
|
|
2193 | glTranslate 0.375, 0.375; |
|
|
2194 | |
|
|
2195 | my ($w, $h) = @$self{qw(w h)}; |
|
|
2196 | |
|
|
2197 | glColor 1, 0.8, 0.4; |
|
|
2198 | glBegin GL_QUADS; |
|
|
2199 | glVertex 0 , 0; |
|
|
2200 | glVertex 0 , $h; |
|
|
2201 | glVertex $w, $h; |
|
|
2202 | glVertex $w, 0; |
|
|
2203 | glEnd; |
|
|
2204 | |
|
|
2205 | glColor 0, 0, 0; |
|
|
2206 | glBegin GL_LINE_LOOP; |
|
|
2207 | glVertex 0 , 0; |
|
|
2208 | glVertex 0 , $h; |
|
|
2209 | glVertex $w, $h; |
|
|
2210 | glVertex $w, 0; |
|
|
2211 | glEnd; |
|
|
2212 | |
|
|
2213 | glPopMatrix; |
|
|
2214 | |
|
|
2215 | glTranslate 2, 2; |
|
|
2216 | $self->SUPER::_draw; |
2167 | } |
2217 | } |
2168 | |
2218 | |
2169 | ############################################################################# |
2219 | ############################################################################# |
2170 | |
2220 | |
2171 | package CFClient::UI::Root; |
2221 | package CFClient::UI::Root; |