… | |
… | |
136 | $rem += $_ - $i; |
136 | $rem += $_ - $i; |
137 | $_ = $i; |
137 | $_ = $i; |
138 | } |
138 | } |
139 | } |
139 | } |
140 | |
140 | |
|
|
141 | sub full_refresh { |
|
|
142 | # make a copy, otherwise for complains about freed values. |
|
|
143 | my @widgets = values %WIDGET; |
|
|
144 | |
|
|
145 | $_->update |
|
|
146 | for @widgets; |
|
|
147 | } |
|
|
148 | |
141 | # call when resolution changes etc. |
149 | # call when resolution changes etc. |
142 | sub rescale_widgets { |
150 | sub rescale_widgets { |
143 | my ($sx, $sy) = @_; |
151 | my ($sx, $sy) = @_; |
144 | |
152 | |
|
|
153 | # make a copy, otherwise for complains about freed values. |
145 | for my $widget (values %WIDGET) { |
154 | my @widgets = values %WIDGET; |
|
|
155 | |
|
|
156 | for my $widget (@widgets) { |
146 | if ($widget->{toplevel}) { |
157 | if ($widget->{toplevel}) { |
147 | $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x}; |
158 | $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x}; |
148 | $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; |
159 | $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; |
149 | $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w}; |
160 | $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w}; |
150 | $widget->{user_w} = int 0.5 + $widget->{user_w} * $sx if exists $widget->{user_w}; |
161 | $widget->{user_w} = int 0.5 + $widget->{user_w} * $sx if exists $widget->{user_w}; |
… | |
… | |
195 | %$self = (); |
206 | %$self = (); |
196 | } |
207 | } |
197 | |
208 | |
198 | sub show { |
209 | sub show { |
199 | my ($self) = @_; |
210 | my ($self) = @_; |
200 | |
|
|
201 | return if $self->{parent}; |
211 | return if $self->{parent}; |
202 | |
212 | |
203 | $CFClient::UI::ROOT->add ($self); |
213 | $CFClient::UI::ROOT->add ($self); |
204 | } |
214 | } |
205 | |
215 | |
… | |
… | |
416 | Scalar::Util::weaken ($self->{parent} = $parent); |
426 | Scalar::Util::weaken ($self->{parent} = $parent); |
417 | |
427 | |
418 | # TODO: req_w _does_change after ->reconfigure |
428 | # TODO: req_w _does_change after ->reconfigure |
419 | $self->check_size |
429 | $self->check_size |
420 | unless exists $self->{req_w}; |
430 | unless exists $self->{req_w}; |
|
|
431 | |
|
|
432 | $self->show; |
421 | } |
433 | } |
422 | |
434 | |
423 | sub check_size { |
435 | sub check_size { |
424 | my ($self, $forced) = @_; |
436 | my ($self, $forced) = @_; |
425 | |
437 | |
… | |
… | |
688 | $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
700 | $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
689 | glClearColor 0, 0, 0, 0; |
701 | glClearColor 0, 0, 0, 0; |
690 | glClear GL_COLOR_BUFFER_BIT; |
702 | glClear GL_COLOR_BUFFER_BIT; |
691 | |
703 | |
692 | $self->_render; |
704 | $self->_render; |
693 | # glColorMask 1, 1, 1, 0; |
|
|
694 | # glEnable GL_BLEND; |
|
|
695 | # glBlendFunc GL_SRC_ALPHA, GL_ZERO; |
|
|
696 | # glRasterPos 0, 0; |
|
|
697 | # glCopyPixels 0, 0, $self->{w}, $self->{h}; |
|
|
698 | # glDisable GL_BLEND; |
|
|
699 | # glColorMask 1, 1, 1, 1; |
|
|
700 | }; |
705 | }; |
701 | } |
706 | } |
702 | |
707 | |
703 | sub _draw { |
708 | sub _draw { |
704 | my ($self) = @_; |
709 | my ($self) = @_; |
… | |
… | |
708 | my $tex = $self->{texture} |
713 | my $tex = $self->{texture} |
709 | or return; |
714 | or return; |
710 | |
715 | |
711 | glEnable GL_TEXTURE_2D; |
716 | glEnable GL_TEXTURE_2D; |
712 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
717 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
713 | glColor 0, 0, 0, 1; |
718 | glColor 1, 1, 1, 1; |
714 | |
719 | |
715 | $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); |
720 | $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); |
716 | |
721 | |
717 | glDisable GL_TEXTURE_2D; |
722 | glDisable GL_TEXTURE_2D; |
718 | } |
723 | } |
… | |
… | |
801 | $self->{vp}->set_offset (0, $_[1] * ($self->{vp}{child_h} - $self->{vp}{h})); |
806 | $self->{vp}->set_offset (0, $_[1] * ($self->{vp}{child_h} - $self->{vp}{h})); |
802 | }, |
807 | }, |
803 | ; |
808 | ; |
804 | |
809 | |
805 | $self = $class->SUPER::new ( |
810 | $self = $class->SUPER::new ( |
806 | vp => (new CFClient::UI::ViewPort), |
811 | vp => (new CFClient::UI::ViewPort expand => 1), |
807 | slider => $slider, |
812 | slider => $slider, |
808 | @_, |
813 | @_, |
809 | ); |
814 | ); |
810 | |
815 | |
811 | $self->{vp}->add ($self->{scrolled}); |
816 | $self->{vp}->add ($self->{scrolled}); |
… | |
… | |
1297 | #bg => none |
1302 | #bg => none |
1298 | #active_bg => none |
1303 | #active_bg => none |
1299 | #font => default_font |
1304 | #font => default_font |
1300 | #text => initial text |
1305 | #text => initial text |
1301 | #markup => initial narkup |
1306 | #markup => initial narkup |
|
|
1307 | #max_w => maximum pixel width |
|
|
1308 | ellipsise => 3, # end |
1302 | layout => (new CFClient::Layout), |
1309 | layout => (new CFClient::Layout), |
1303 | fontsize => 1, |
1310 | fontsize => 1, |
1304 | align => -1, |
1311 | align => -1, |
1305 | valign => -1, |
1312 | valign => -1, |
1306 | padding => 2, |
1313 | padding => 2, |
… | |
… | |
1371 | sub size_request { |
1378 | sub size_request { |
1372 | my ($self) = @_; |
1379 | my ($self) = @_; |
1373 | |
1380 | |
1374 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1381 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1375 | $self->{layout}->set_width ($self->{max_w} || -1); |
1382 | $self->{layout}->set_width ($self->{max_w} || -1); |
|
|
1383 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
|
|
1384 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1376 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1385 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1377 | |
1386 | |
1378 | my ($w, $h) = $self->{layout}->size; |
1387 | my ($w, $h) = $self->{layout}->size; |
1379 | |
1388 | |
1380 | if (exists $self->{template}) { |
1389 | if (exists $self->{template}) { |
… | |
… | |
1416 | |
1425 | |
1417 | my $tex = $self->{texture} ||= do { |
1426 | my $tex = $self->{texture} ||= do { |
1418 | $self->{layout}->set_foreground (@{$self->{fg}}); |
1427 | $self->{layout}->set_foreground (@{$self->{fg}}); |
1419 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1428 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1420 | $self->{layout}->set_width ($self->{w}); |
1429 | $self->{layout}->set_width ($self->{w}); |
|
|
1430 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
|
|
1431 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1421 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1432 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1422 | |
1433 | |
1423 | my $tex = new_from_layout CFClient::Texture $self->{layout}; |
1434 | my $tex = new_from_layout CFClient::Texture $self->{layout}; |
1424 | |
1435 | |
1425 | $self->{ox} = int ($self->{align} < 0 ? $self->{padding} |
1436 | $self->{ox} = int ($self->{align} < 0 ? $self->{padding} |
1426 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
1437 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
… | |
… | |
2048 | range => [0, 0, 100, 10], |
2059 | range => [0, 0, 100, 10], |
2049 | req_w => $::WIDTH / 80, |
2060 | req_w => $::WIDTH / 80, |
2050 | req_h => $::WIDTH / 80, |
2061 | req_h => $::WIDTH / 80, |
2051 | vertical => 0, |
2062 | vertical => 0, |
2052 | can_hover => 1, |
2063 | can_hover => 1, |
2053 | inner_pad => .05, |
2064 | inner_pad => 0.02, |
2054 | @_ |
2065 | @_ |
2055 | ); |
2066 | ); |
2056 | |
2067 | |
2057 | $self->set_value ($self->{range}[0]); |
2068 | $self->set_value ($self->{range}[0]); |
2058 | $self->update; |
2069 | $self->update; |
… | |
… | |
2148 | glScale $self->{w}, $self->{h}; |
2159 | glScale $self->{w}, $self->{h}; |
2149 | |
2160 | |
2150 | if ($self->{vertical}) { |
2161 | if ($self->{vertical}) { |
2151 | # draw a vertical slider like a rotated horizontal slider |
2162 | # draw a vertical slider like a rotated horizontal slider |
2152 | |
2163 | |
|
|
2164 | glTranslate 1, 0, 0; |
2153 | glRotate 90, 0, 0, 1; |
2165 | glRotate 90, 0, 0, 1; |
2154 | glTranslate 0, 1, 0; |
|
|
2155 | } |
2166 | } |
2156 | |
2167 | |
2157 | my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; |
2168 | my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; |
2158 | my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; |
2169 | my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; |
2159 | |
2170 | |
… | |
… | |
2205 | |
2216 | |
2206 | $self->{fontsize} = $fontsize; |
2217 | $self->{fontsize} = $fontsize; |
2207 | $self->reflow; |
2218 | $self->reflow; |
2208 | } |
2219 | } |
2209 | |
2220 | |
|
|
2221 | sub size_allocate { |
|
|
2222 | my ($self, $w, $h) = @_; |
|
|
2223 | |
|
|
2224 | $self->SUPER::size_allocate ($w, $h); |
|
|
2225 | |
|
|
2226 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
|
|
2227 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
|
|
2228 | $self->{layout}->set_width ($self->{children}[0]{w}); |
|
|
2229 | |
|
|
2230 | $self->reflow; |
|
|
2231 | } |
|
|
2232 | |
2210 | sub text_height { |
2233 | sub text_height { |
2211 | my ($self, $text) = @_; |
2234 | my ($self, $text, $indent) = @_; |
2212 | |
2235 | |
2213 | my $layout = $self->{layout}; |
2236 | my $layout = $self->{layout}; |
2214 | |
2237 | |
2215 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2238 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2216 | $layout->set_width ($self->{children}[0]{w}); |
2239 | $layout->set_width ($self->{children}[0]{w} - $indent); |
2217 | $layout->set_markup ($text); |
2240 | $layout->set_markup ($text); |
2218 | |
2241 | |
2219 | ($layout->size)[1] |
2242 | ($layout->size)[1] |
2220 | } |
2243 | } |
2221 | |
2244 | |
… | |
… | |
2224 | |
2247 | |
2225 | $self->{need_reflow}++; |
2248 | $self->{need_reflow}++; |
2226 | $self->update; |
2249 | $self->update; |
2227 | } |
2250 | } |
2228 | |
2251 | |
2229 | sub size_allocate { |
|
|
2230 | my ($self, $w, $h) = @_; |
|
|
2231 | |
|
|
2232 | $self->SUPER::size_allocate ($w, $h); |
|
|
2233 | |
|
|
2234 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
|
|
2235 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
|
|
2236 | $self->{layout}->set_width ($self->{children}[0]{w}); |
|
|
2237 | |
|
|
2238 | $self->reflow; |
|
|
2239 | } |
|
|
2240 | |
|
|
2241 | sub add_paragraph { |
2252 | sub add_paragraph { |
2242 | my ($self, $color, $text) = @_; |
2253 | my ($self, $color, $text, $indent) = @_; |
2243 | |
2254 | |
2244 | #TODO: intelligently "reformat" paragraph |
2255 | #TODO: intelligently "reformat" paragraph |
2245 | |
2256 | |
|
|
2257 | for my $line (split /\n/, $text) { |
2246 | my $height = $self->text_height ($text); |
2258 | my $height = $self->text_height ($line); |
2247 | |
|
|
2248 | $self->{height} += $height; |
2259 | $self->{height} += $height; |
2249 | |
|
|
2250 | push @{$self->{par}}, [$height, $color, $text]; |
2260 | push @{$self->{par}}, [$height, $color, $indent, $line]; |
|
|
2261 | } |
2251 | |
2262 | |
2252 | $self->{children}[1]{range} = [$self->{height} - $self->{h}, 0, $self->{height}, $self->{h}]; |
2263 | $self->{children}[1]{range} = [$self->{height} - $self->{h}, 0, $self->{height}, $self->{h}]; |
2253 | $self->{children}[1]->update; |
2264 | $self->{children}[1]->update; |
2254 | } |
2265 | } |
2255 | |
2266 | |
… | |
… | |
2264 | |
2275 | |
2265 | $ROOT->on_post_alloc ($self, sub { |
2276 | $ROOT->on_post_alloc ($self, sub { |
2266 | if (delete $self->{need_reflow}) { |
2277 | if (delete $self->{need_reflow}) { |
2267 | my $height = 0; |
2278 | my $height = 0; |
2268 | |
2279 | |
2269 | $height += $_->[0] = $self->text_height ($_->[2]) |
2280 | $height += $_->[0] = $self->text_height ($_->[3], $_->[2]) |
2270 | for @{$self->{par}}; |
2281 | for @{$self->{par}}; |
2271 | |
2282 | |
2272 | $self->{height} = $height; |
2283 | $self->{height} = $height; |
2273 | |
2284 | |
2274 | $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; |
2285 | $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; |
|
|
2286 | $self->{children}[1]->update; |
2275 | |
2287 | |
2276 | delete $self->{texture}; |
2288 | delete $self->{texture}; |
2277 | } |
2289 | } |
2278 | |
2290 | |
2279 | $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { |
2291 | $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { |
2280 | glClearColor 0, 0, 0, 0; |
2292 | glClearColor 0.5, 0.5, 0.5, 0; |
2281 | glClear GL_COLOR_BUFFER_BIT; |
2293 | glClear GL_COLOR_BUFFER_BIT; |
2282 | |
|
|
2283 | glEnable GL_TEXTURE_2D; |
|
|
2284 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
2285 | |
2294 | |
2286 | my $top = int $self->{children}[1]{range}[0]; |
2295 | my $top = int $self->{children}[1]{range}[0]; |
2287 | |
2296 | |
2288 | my $y0 = $top; |
2297 | my $y0 = $top; |
2289 | my $y1 = $top + $self->{h}; |
2298 | my $y1 = $top + $self->{h}; |
… | |
… | |
2292 | |
2301 | |
2293 | my $layout = $self->{layout}; |
2302 | my $layout = $self->{layout}; |
2294 | |
2303 | |
2295 | $layout->set_font ($self->{font}) if $self->{font}; |
2304 | $layout->set_font ($self->{font}) if $self->{font}; |
2296 | |
2305 | |
|
|
2306 | glEnable GL_BLEND; |
|
|
2307 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2308 | |
2297 | for my $par (@{$self->{par}}) { |
2309 | for my $par (@{$self->{par}}) { |
2298 | my $h = $par->[0]; |
2310 | my $h = $par->[0]; |
2299 | |
2311 | |
2300 | if ($y0 < $y + $h && $y < $y1) { |
2312 | if ($y0 < $y + $h && $y < $y1) { |
2301 | $layout->set_foreground (@{ $par->[1] }); |
2313 | $layout->set_foreground (@{ $par->[1] }); |
|
|
2314 | $layout->set_width ($self->{w} - $par->[2]); |
2302 | $layout->set_markup ($par->[2]); |
2315 | $layout->set_markup ($par->[3]); |
2303 | |
2316 | |
2304 | my ($W, $H) = $layout->size; |
2317 | my ($w, $h, $data, $format, $internalformat) = $layout->render; |
2305 | CFClient::Texture->new_from_layout ($layout)->draw_quad_alpha_premultiplied (0, $y - $y0); |
2318 | |
|
|
2319 | glRasterPos $par->[2], $y - $y0; |
|
|
2320 | glDrawPixels $w, $h, $format, GL_UNSIGNED_BYTE, $data; |
2306 | } |
2321 | } |
2307 | |
2322 | |
2308 | $y += $h; |
2323 | $y += $h; |
2309 | } |
2324 | } |
2310 | |
2325 | |
2311 | glDisable GL_TEXTURE_2D; |
2326 | glDisable GL_BLEND; |
2312 | }; |
2327 | }; |
2313 | }); |
2328 | }); |
2314 | } |
2329 | } |
2315 | |
2330 | |
2316 | sub _draw { |
2331 | sub _draw { |
2317 | my ($self) = @_; |
2332 | my ($self) = @_; |
2318 | |
2333 | |
2319 | glEnable GL_TEXTURE_2D; |
2334 | glEnable GL_TEXTURE_2D; |
2320 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2335 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2321 | glColor 1, 1, 1, 1; |
2336 | glColor 1, 1, 1, 1; |
2322 | $self->{texture}->draw_quad_alpha_premultiplied (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); |
2337 | $self->{texture}->draw_quad_alpha (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); |
2323 | glDisable GL_TEXTURE_2D; |
2338 | glDisable GL_TEXTURE_2D; |
2324 | |
2339 | |
2325 | $self->{children}[1]->draw; |
2340 | $self->{children}[1]->draw; |
2326 | |
2341 | |
2327 | } |
2342 | } |
… | |
… | |
2426 | |
2441 | |
2427 | sub set_tooltip_from { |
2442 | sub set_tooltip_from { |
2428 | my ($self, $widget) = @_; |
2443 | my ($self, $widget) = @_; |
2429 | |
2444 | |
2430 | $self->add (new CFClient::UI::Label |
2445 | $self->add (new CFClient::UI::Label |
2431 | markup => $widget->{tooltip}, |
2446 | markup => $widget->{tooltip}, |
2432 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
2447 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
2433 | fontsize => 0.8, |
2448 | fontsize => 0.8, |
2434 | fg => [0, 0, 0, 1], |
2449 | fg => [0, 0, 0, 1], |
|
|
2450 | ellipsise => 0, |
2435 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
2451 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
2436 | ); |
2452 | ); |
2437 | } |
2453 | } |
2438 | |
2454 | |
2439 | sub size_request { |
2455 | sub size_request { |
2440 | my ($self) = @_; |
2456 | my ($self) = @_; |
… | |
… | |
2486 | use CFClient::OpenGL; |
2502 | use CFClient::OpenGL; |
2487 | |
2503 | |
2488 | sub new { |
2504 | sub new { |
2489 | my $class = shift; |
2505 | my $class = shift; |
2490 | |
2506 | |
2491 | $class->SUPER::new ( |
2507 | my $self = $class->SUPER::new ( |
2492 | aspect => 1, |
2508 | aspect => 1, |
2493 | @_, |
2509 | @_, |
2494 | ) |
2510 | ); |
|
|
2511 | |
|
|
2512 | if ($self->{anim} && $self->{animspeed}) { |
|
|
2513 | Scalar::Util::weaken (my $widget = $self); |
|
|
2514 | |
|
|
2515 | $self->{timer} = Event->timer ( |
|
|
2516 | at => $self->{animspeed} * int $::NOW / $self->{animspeed}, |
|
|
2517 | hard => 1, |
|
|
2518 | interval => $self->{animspeed}, |
|
|
2519 | cb => sub { |
|
|
2520 | ++$widget->{frame}; |
|
|
2521 | $widget->update; |
|
|
2522 | }, |
|
|
2523 | ); |
|
|
2524 | } |
|
|
2525 | |
|
|
2526 | $self |
2495 | } |
2527 | } |
2496 | |
2528 | |
2497 | sub size_request { |
2529 | sub size_request { |
2498 | (32, 8) |
2530 | (32, 8) |
2499 | } |
2531 | } |
2500 | |
2532 | |
|
|
2533 | sub update { |
|
|
2534 | my ($self) = @_; |
|
|
2535 | |
|
|
2536 | return unless $self->{visible}; |
|
|
2537 | |
|
|
2538 | $self->SUPER::update; |
|
|
2539 | } |
|
|
2540 | |
2501 | sub _draw { |
2541 | sub _draw { |
2502 | my ($self) = @_; |
2542 | my ($self) = @_; |
2503 | |
2543 | |
2504 | return unless $::CONN;#d# manage and cache textures differently |
2544 | return unless $::CONN;#d# manage and cache textures differently |
|
|
2545 | |
|
|
2546 | my $face; |
|
|
2547 | |
|
|
2548 | if ($self->{frame}) { |
|
|
2549 | my $anim = $::CONN->{anim}[$self->{anim}]; |
|
|
2550 | |
|
|
2551 | $face = $anim->[ $self->{frame} % @$anim ] |
|
|
2552 | if $anim && @$anim; |
|
|
2553 | } |
|
|
2554 | |
2505 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; |
2555 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]]; |
2506 | |
2556 | |
2507 | # TODO animation |
|
|
2508 | if ($tex) { |
2557 | if ($tex) { |
2509 | glEnable GL_TEXTURE_2D; |
2558 | glEnable GL_TEXTURE_2D; |
2510 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2559 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2511 | glColor 1, 1, 1, 1; |
2560 | glColor 1, 1, 1, 1; |
2512 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2561 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2513 | glDisable GL_TEXTURE_2D; |
2562 | glDisable GL_TEXTURE_2D; |
2514 | } |
2563 | } |
2515 | } |
2564 | } |
2516 | |
2565 | |
|
|
2566 | sub DESTROY { |
|
|
2567 | my ($self) = @_; |
|
|
2568 | |
|
|
2569 | $self->{timer}->cancel |
|
|
2570 | if $self->{timer}; |
|
|
2571 | |
|
|
2572 | $self->SUPER::DESTROY; |
|
|
2573 | } |
|
|
2574 | |
2517 | ############################################################################# |
2575 | ############################################################################# |
2518 | |
2576 | |
2519 | package CFClient::UI::InventoryItem; |
2577 | package CFClient::UI::InventoryItem; |
2520 | |
2578 | |
2521 | our @ISA = CFClient::UI::HBox::; |
2579 | our @ISA = CFClient::UI::HBox::; |
2522 | |
2580 | |
2523 | sub new { |
2581 | sub _item_to_desc { |
2524 | my $class = shift; |
2582 | my ($item) = @_; |
2525 | |
2583 | |
2526 | my %args = @_; |
2584 | my $desc = |
2527 | |
|
|
2528 | my $item = delete $args{item}; |
|
|
2529 | |
|
|
2530 | my $desc = $item->{nrof} < 2 |
2585 | $item->{nrof} < 2 |
2531 | ? $item->{name} |
2586 | ? $item->{name} |
2532 | : "$item->{nrof} $item->{name_pl}"; |
2587 | : "$item->{nrof} × $item->{name_pl}"; |
2533 | |
2588 | |
2534 | $item->{flags} & Crossfire::Protocol::F_OPEN |
2589 | $item->{flags} & Crossfire::Protocol::F_OPEN |
2535 | and $desc .= " (open)"; |
2590 | and $desc .= " (open)"; |
2536 | $item->{flags} & Crossfire::Protocol::F_APPLIED |
2591 | $item->{flags} & Crossfire::Protocol::F_APPLIED |
2537 | and $desc .= " (applied)"; |
2592 | and $desc .= " (applied)"; |
… | |
… | |
2544 | $item->{flags} & Crossfire::Protocol::F_DAMNED |
2599 | $item->{flags} & Crossfire::Protocol::F_DAMNED |
2545 | and $desc .= " (damned)"; |
2600 | and $desc .= " (damned)"; |
2546 | $item->{flags} & Crossfire::Protocol::F_LOCKED |
2601 | $item->{flags} & Crossfire::Protocol::F_LOCKED |
2547 | and $desc .= " *"; |
2602 | and $desc .= " *"; |
2548 | |
2603 | |
|
|
2604 | $desc |
|
|
2605 | } |
|
|
2606 | |
|
|
2607 | sub new { |
|
|
2608 | my $class = shift; |
|
|
2609 | |
|
|
2610 | my %args = @_; |
|
|
2611 | |
|
|
2612 | my $item = delete $args{item}; |
|
|
2613 | |
|
|
2614 | my $desc = _item_to_desc ($item); |
|
|
2615 | |
2549 | my $self = $class->SUPER::new ( |
2616 | my $self = $class->SUPER::new ( |
2550 | can_hover => 1, |
2617 | can_hover => 1, |
2551 | can_events => 1, |
2618 | can_events => 1, |
2552 | tooltip => ((CFClient::UI::Label::escape $desc) |
2619 | tooltip => ((CFClient::UI::Label::escape $desc) |
2553 | . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), |
2620 | . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), |
2554 | connect_button_down => sub { |
2621 | connect_button_down => sub { |
2555 | my ($self, $ev, $x, $y) = @_; |
2622 | my ($self, $ev, $x, $y) = @_; |
2556 | |
2623 | |
2557 | # todo: maybe put examine on 1? but should just be a tooltip :( |
2624 | # todo: maybe put examine on 1? but should just be a tooltip :( |
2558 | if ($ev->{button} == 1) { |
2625 | if ($ev->{button} == 1) { |
|
|
2626 | my $targ = $::CONN->{player}{tag}; |
|
|
2627 | |
|
|
2628 | if ($item->{container} == $::CONN->{player}{tag}) { |
|
|
2629 | $targ = $main::OPENCONT; |
|
|
2630 | } |
|
|
2631 | |
2559 | $::CONN->send ("move $::CONN->{player}{tag} $item->{tag} 0"); |
2632 | $::CONN->send ("move $targ $item->{tag} 0"); |
2560 | } elsif ($ev->{button} == 2) { |
2633 | } elsif ($ev->{button} == 2) { |
2561 | $::CONN->send ("apply $item->{tag}"); |
2634 | $::CONN->send ("apply $item->{tag}"); |
2562 | } elsif ($ev->{button} == 3) { |
2635 | } elsif ($ev->{button} == 3) { |
2563 | my @menu_items = ( |
2636 | my @menu_items = ( |
2564 | ["examine", sub { $::CONN->send ("examine $item->{tag}") }], |
2637 | ["examine", sub { $::CONN->send ("examine $item->{tag}") }], |
2565 | ["mark", sub { $::CONN->send ("mark $item->{tag}") }], |
2638 | ["mark", sub { $::CONN->send ("mark ". pack "N", $item->{tag}) }], |
2566 | ["apply", sub { $::CONN->send ("apply $item->{tag}") }], |
2639 | ["apply", sub { $::CONN->send ("apply $item->{tag}") }], |
|
|
2640 | ( |
|
|
2641 | $item->{flags} & Crossfire::Protocol::F_LOCKED |
|
|
2642 | ? ( |
|
|
2643 | ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $item->{tag}) }], |
|
|
2644 | ) |
|
|
2645 | : ( |
|
|
2646 | ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $item->{tag}) }], |
2567 | ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }], |
2647 | ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }], |
2568 | [ |
2648 | ) |
2569 | $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock", |
|
|
2570 | sub { $::CONN->send ("lock ". () ."$item->{tag}") }, |
|
|
2571 | ], |
2649 | ), |
2572 | ); |
2650 | ); |
2573 | |
2651 | |
2574 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
2652 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
2575 | } |
2653 | } |
2576 | |
2654 | |
2577 | 1 |
2655 | 1 |
2578 | }, |
2656 | }, |
2579 | %args |
2657 | %args |
2580 | ); |
2658 | ); |
|
|
2659 | |
2581 | |
2660 | |
2582 | $self->add (new CFClient::UI::Face |
2661 | $self->add (new CFClient::UI::Face |
2583 | can_events => 0, |
2662 | can_events => 0, |
2584 | face => $item->{face}, |
2663 | face => $item->{face}, |
2585 | anim => $item->{anim}, |
2664 | anim => $item->{anim}, |
2586 | animspeed => $item->{animspeed}, |
2665 | animspeed => $item->{animspeed}, |
2587 | ); |
2666 | ); |
2588 | |
2667 | |
2589 | $self->add (new CFClient::UI::Label |
2668 | $self->add ($self->{name_lbl} = new CFClient::UI::Label can_events => 0); |
2590 | can_events => 0, |
2669 | |
2591 | text => $desc, |
2670 | $self->{item} = $item; |
2592 | ); |
2671 | |
|
|
2672 | $self->update_item; |
2593 | |
2673 | |
2594 | $self |
2674 | $self |
|
|
2675 | } |
|
|
2676 | |
|
|
2677 | sub update_item { |
|
|
2678 | my ($self) = @_; |
|
|
2679 | |
|
|
2680 | my $desc = _item_to_desc ($self->{item}); |
|
|
2681 | |
|
|
2682 | $self->{name_lbl}->set_text ($desc); |
2595 | } |
2683 | } |
2596 | |
2684 | |
2597 | ############################################################################# |
2685 | ############################################################################# |
2598 | |
2686 | |
2599 | package CFClient::UI::Inventory; |
2687 | package CFClient::UI::Inventory; |
… | |
… | |
2623 | } @$items; |
2711 | } @$items; |
2624 | |
2712 | |
2625 | $self->{real_items} = \@items; |
2713 | $self->{real_items} = \@items; |
2626 | |
2714 | |
2627 | for my $item (@items) { |
2715 | for my $item (@items) { |
2628 | my $desc = $item->{nrof} < 2 |
|
|
2629 | ? $item->{name} |
|
|
2630 | : "$item->{nrof} $item->{name_pl}"; |
|
|
2631 | |
|
|
2632 | $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item; |
2716 | $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item; |
|
|
2717 | $item->update_item (); |
2633 | } |
2718 | } |
2634 | |
2719 | |
2635 | $self->{scrolled}->add (@items); |
2720 | $self->{scrolled}->add (@items); |
2636 | |
2721 | |
2637 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
2722 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
… | |
… | |
2718 | |
2803 | |
2719 | package CFClient::UI::Statusbox; |
2804 | package CFClient::UI::Statusbox; |
2720 | |
2805 | |
2721 | our @ISA = CFClient::UI::VBox::; |
2806 | our @ISA = CFClient::UI::VBox::; |
2722 | |
2807 | |
|
|
2808 | sub new { |
|
|
2809 | my $class = shift; |
|
|
2810 | |
|
|
2811 | $class->SUPER::new ( |
|
|
2812 | fontsize => 0.8, |
|
|
2813 | @_, |
|
|
2814 | ) |
|
|
2815 | } |
|
|
2816 | |
2723 | sub reorder { |
2817 | sub reorder { |
2724 | my ($self) = @_; |
2818 | my ($self) = @_; |
2725 | my $NOW = time; |
2819 | my $NOW = time; |
2726 | |
2820 | |
2727 | while (my ($k, $v) = each %{ $self->{item} }) { |
2821 | while (my ($k, $v) = each %{ $self->{item} }) { |
… | |
… | |
2746 | : $item->{text}; |
2840 | : $item->{text}; |
2747 | |
2841 | |
2748 | for ($short) { |
2842 | for ($short) { |
2749 | s/^\s+//; |
2843 | s/^\s+//; |
2750 | s/\s+/ /g; |
2844 | s/\s+/ /g; |
2751 | my $len = int 40 / $item->{fontsize}; |
|
|
2752 | substr $_, $len, length, "…" if $len < length; |
|
|
2753 | } |
2845 | } |
2754 | |
2846 | |
2755 | new CFClient::UI::Label |
2847 | new CFClient::UI::Label |
2756 | markup => $short, |
2848 | markup => $short, |
2757 | tooltip => $item->{tooltip}, |
2849 | tooltip => $item->{tooltip}, |
2758 | tooltip_font => $::FONT_PROP, |
2850 | tooltip_font => $::FONT_PROP, |
2759 | tooltip_width => 0.67, |
2851 | tooltip_width => 0.67, |
2760 | fontsize => $item->{fontsize}, |
2852 | fontsize => $item->{fontsize} || $self->{fontsize}, |
|
|
2853 | max_w => $::WIDTH * 0.44, |
2761 | fg => $item->{fg}, |
2854 | fg => $item->{fg}, |
2762 | can_events => 1, |
2855 | can_events => 1, |
2763 | can_hover => 1 |
2856 | can_hover => 1 |
2764 | }; |
2857 | }; |
2765 | } |
2858 | } |
… | |
… | |
2792 | $self->{item}{$group} = { |
2885 | $self->{item}{$group} = { |
2793 | id => ++$self->{id}, |
2886 | id => ++$self->{id}, |
2794 | text => $text, |
2887 | text => $text, |
2795 | timeout => $timeout, |
2888 | timeout => $timeout, |
2796 | tooltip => $text, |
2889 | tooltip => $text, |
2797 | fontsize => 0.8, |
|
|
2798 | fg => [0.8, 0.8, 0.8, 0.8], |
2890 | fg => [0.8, 0.8, 0.8, 0.8], |
2799 | pri => 0, |
2891 | pri => 0, |
2800 | count => 1, |
2892 | count => 1, |
2801 | %arg, |
2893 | %arg, |
2802 | }; |
2894 | }; |
2803 | } |
2895 | } |
2804 | |
2896 | |
2805 | $self->reorder; |
2897 | $self->reorder; |
2806 | } |
2898 | } |
2807 | |
2899 | |
|
|
2900 | sub reconfigure { |
|
|
2901 | my ($self) = @_; |
|
|
2902 | |
|
|
2903 | delete $_->{label} |
|
|
2904 | for values %{ $self->{item} || {} }; |
|
|
2905 | |
|
|
2906 | $self->reorder; |
|
|
2907 | $self->SUPER::reconfigure; |
|
|
2908 | } |
|
|
2909 | |
2808 | ############################################################################# |
2910 | ############################################################################# |
2809 | |
2911 | |
2810 | package CFClient::UI::Root; |
2912 | package CFClient::UI::Root; |
2811 | |
2913 | |
2812 | our @ISA = CFClient::UI::Container::; |
2914 | our @ISA = CFClient::UI::Container::; |
… | |
… | |
2895 | $child->{x} = int $child->{x}; |
2997 | $child->{x} = int $child->{x}; |
2896 | $child->{y} = int $child->{y}; |
2998 | $child->{y} = int $child->{y}; |
2897 | } |
2999 | } |
2898 | |
3000 | |
2899 | $self->SUPER::add (@children); |
3001 | $self->SUPER::add (@children); |
|
|
3002 | |
|
|
3003 | while (@children) { |
|
|
3004 | my $w = pop @children; |
|
|
3005 | push @children, $w->children; |
|
|
3006 | $w->{visible} = 1; |
|
|
3007 | } |
|
|
3008 | } |
|
|
3009 | |
|
|
3010 | sub remove { |
|
|
3011 | my ($self, @children) = @_; |
|
|
3012 | |
|
|
3013 | $self->SUPER::remove (@children); |
|
|
3014 | |
|
|
3015 | while (@children) { |
|
|
3016 | my $w = pop @children; |
|
|
3017 | push @children, $w->children; |
|
|
3018 | delete $w->{visible}; |
|
|
3019 | } |
2900 | } |
3020 | } |
2901 | |
3021 | |
2902 | sub on_refresh { |
3022 | sub on_refresh { |
2903 | my ($self, $id, $cb) = @_; |
3023 | my ($self, $id, $cb) = @_; |
2904 | |
3024 | |
… | |
… | |
2973 | glClearColor +($::CFG->{fow_intensity}) x 3, 1; |
3093 | glClearColor +($::CFG->{fow_intensity}) x 3, 1; |
2974 | glClear GL_COLOR_BUFFER_BIT; |
3094 | glClear GL_COLOR_BUFFER_BIT; |
2975 | |
3095 | |
2976 | glMatrixMode GL_PROJECTION; |
3096 | glMatrixMode GL_PROJECTION; |
2977 | glLoadIdentity; |
3097 | glLoadIdentity; |
2978 | glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000 , 10000; |
3098 | glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; |
2979 | glMatrixMode GL_MODELVIEW; |
3099 | glMatrixMode GL_MODELVIEW; |
2980 | glLoadIdentity; |
3100 | glLoadIdentity; |
2981 | |
3101 | |
2982 | $self->_draw; |
3102 | $self->_draw; |
2983 | } |
3103 | } |
… | |
… | |
2985 | ############################################################################# |
3105 | ############################################################################# |
2986 | |
3106 | |
2987 | package CFClient::UI; |
3107 | package CFClient::UI; |
2988 | |
3108 | |
2989 | $ROOT = new CFClient::UI::Root; |
3109 | $ROOT = new CFClient::UI::Root; |
2990 | $TOOLTIP = new CFClient::UI::Tooltip; |
3110 | $TOOLTIP = new CFClient::UI::Tooltip z => 900; |
2991 | |
3111 | |
2992 | 1 |
3112 | 1 |
2993 | |
3113 | |