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.194 by root, Thu May 11 23:41:47 2006 UTC vs.
Revision 1.196 by root, Fri May 12 00:16:34 2006 UTC

24 24
25 my $tip = $widget->{tooltip}; 25 my $tip = $widget->{tooltip};
26 26
27 $tip = $tip->($widget) if CODE:: eq ref $tip; 27 $tip = $tip->($widget) if CODE:: eq ref $tip;
28 28
29 $TOOLTIP->set_markup ($widget->{tooltip}); 29 $TOOLTIP->set_tooltip_from ($widget);
30
31 $TOOLTIP->show; 30 $TOOLTIP->show;
32 31
33 my ($x, $y) = $widget->coord2global ($widget->{w}, 0); 32 my ($x, $y) = $widget->coord2global ($widget->{w}, 0);
34 33
35 if ($x + $TOOLTIP->{w} > $::WIDTH) { 34 if ($x + $TOOLTIP->{w} > $::WIDTH) {
1672 1671
1673 if ($GRAB == $self) { 1672 if ($GRAB == $self) {
1674 $self->{fg} = $self->{active_fg}; 1673 $self->{fg} = $self->{active_fg};
1675 } 1674 }
1676 1675
1677 glEnable GL_BLEND;
1678 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1679 glEnable GL_TEXTURE_2D; 1676 glEnable GL_TEXTURE_2D;
1680 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1677 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1681 glColor 0, 0, 0, 1; 1678 glColor 0, 0, 0, 1;
1682 1679
1683 $tex[0]->draw_quad (0, 0, $self->{w}, $self->{h}); 1680 $tex[0]->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
1684 1681
1685 glDisable GL_TEXTURE_2D; 1682 glDisable GL_TEXTURE_2D;
1686 glDisable GL_BLEND;
1687 1683
1688 $self->SUPER::_draw; 1684 $self->SUPER::_draw;
1689} 1685}
1690 1686
1691############################################################################# 1687#############################################################################
1738 1734
1739 my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2; 1735 my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2;
1740 1736
1741 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; 1737 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} };
1742 1738
1743 glEnable GL_BLEND;
1744 glEnable GL_TEXTURE_2D; 1739 glEnable GL_TEXTURE_2D;
1745 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1746 1740
1747 my $tex = $self->{state} ? $tex[1] : $tex[0]; 1741 my $tex = $self->{state} ? $tex[1] : $tex[0];
1748 1742
1749 $tex->draw_quad (0, 0, $s, $s); 1743 $tex->draw_quad_alpha (0, 0, $s, $s);
1750 1744
1751 glDisable GL_TEXTURE_2D; 1745 glDisable GL_TEXTURE_2D;
1752 glDisable GL_BLEND;
1753} 1746}
1754 1747
1755############################################################################# 1748#############################################################################
1756 1749
1757package CFClient::UI::Image; 1750package CFClient::UI::Image;
1800 glTranslate 0, -$self->{w}, 0; 1793 glTranslate 0, -$self->{w}, 0;
1801 1794
1802 ($w, $h) = ($h, $w); 1795 ($w, $h) = ($h, $w);
1803 } 1796 }
1804 1797
1805 glEnable GL_BLEND;
1806 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1807 glEnable GL_TEXTURE_2D; 1798 glEnable GL_TEXTURE_2D;
1808 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1799 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1809 1800
1810 $tex->draw_quad (0, 0, $w, $h); 1801 $tex->draw_quad_alpha (0, 0, $w, $h);
1811 1802
1812 glDisable GL_BLEND;
1813 glDisable GL_TEXTURE_2D; 1803 glDisable GL_TEXTURE_2D;
1814} 1804}
1815 1805
1816############################################################################# 1806#############################################################################
1817 1807
2109 $page ||= 2; 2099 $page ||= 2;
2110 2100
2111 my $knob_a = $inner_pad_px + ($value - $page * 0.5); 2101 my $knob_a = $inner_pad_px + ($value - $page * 0.5);
2112 my $knob_b = $inner_pad_px + ($value + $page * 0.5); 2102 my $knob_b = $inner_pad_px + ($value + $page * 0.5);
2113 2103
2114 glEnable GL_BLEND;
2115 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
2116 glEnable GL_TEXTURE_2D; 2104 glEnable GL_TEXTURE_2D;
2117 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2105 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2118 2106
2119 # draw background 2107 # draw background
2120 $tex[1]->draw_quad (0, 0, $w, $h); 2108 $tex[1]->draw_quad_alpha (0, 0, $w, $h);
2121 2109
2122 # draw handle 2110 # draw handle
2123 $tex[0]->draw_quad ($knob_a, 0, $knob_b - $knob_a, $h); 2111 $tex[0]->draw_quad_alpha ($knob_a, 0, $knob_b - $knob_a, $h);
2124 2112
2125 glDisable GL_BLEND;
2126 glDisable GL_TEXTURE_2D; 2113 glDisable GL_TEXTURE_2D;
2127} 2114}
2128 2115
2129############################################################################# 2116#############################################################################
2130 2117
2141 fontsize => 1, 2128 fontsize => 1,
2142 can_events => 0, 2129 can_events => 0,
2143 #font => default_font 2130 #font => default_font
2144 @_, 2131 @_,
2145 2132
2146 layout => (new CFClient::Layout), 2133 layout => (new CFClient::Layout 1),
2147 par => [], 2134 par => [],
2148 height => 0, 2135 height => 0,
2149 children => [ 2136 children => [
2150 (new CFClient::UI::Empty expand => 1), 2137 (new CFClient::UI::Empty expand => 1),
2151 (new CFClient::UI::Slider vertical => 1), 2138 (new CFClient::UI::Slider vertical => 1),
2169 2156
2170 my $layout = $self->{layout}; 2157 my $layout = $self->{layout};
2171 2158
2172 $layout->set_height ($self->{fontsize} * $::FONTSIZE); 2159 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2173 $layout->set_width ($self->{children}[0]{w}); 2160 $layout->set_width ($self->{children}[0]{w});
2174 $layout->set_text ($text); 2161 $layout->set_markup ($text);
2175 2162
2176 ($layout->size)[1] 2163 ($layout->size)[1]
2177} 2164}
2178 2165
2179sub reflow { 2166sub reflow {
2235 2222
2236 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { 2223 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub {
2237 glClearColor 0, 0, 0, 0; 2224 glClearColor 0, 0, 0, 0;
2238 glClear GL_COLOR_BUFFER_BIT; 2225 glClear GL_COLOR_BUFFER_BIT;
2239 2226
2240 glEnable GL_BLEND;
2241 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
2242 glEnable GL_TEXTURE_2D; 2227 glEnable GL_TEXTURE_2D;
2243 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2228 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2244 2229
2245 my $top = int $self->{children}[1]{range}[0]; 2230 my $top = int $self->{children}[1]{range}[0];
2246 2231
2255 2240
2256 for my $par (@{$self->{par}}) { 2241 for my $par (@{$self->{par}}) {
2257 my $h = $par->[0]; 2242 my $h = $par->[0];
2258 2243
2259 if ($y0 < $y + $h && $y < $y1) { 2244 if ($y0 < $y + $h && $y < $y1) {
2245 $layout->set_foreground (@{ $par->[1] });
2260 $layout->set_text ($par->[2]); 2246 $layout->set_markup ($par->[2]);
2261 2247
2262 glColor @{ $par->[1] };
2263 my ($W, $H) = $layout->size; 2248 my ($W, $H) = $layout->size;
2264 CFClient::Texture->new_from_layout ($layout)->draw_quad (0, $y - $y0); 2249 CFClient::Texture->new_from_layout ($layout)->draw_quad_alpha_premultiplied (0, $y - $y0);
2265 } 2250 }
2266 2251
2267 $y += $h; 2252 $y += $h;
2268 } 2253 }
2269 2254
2270 glDisable GL_TEXTURE_2D; 2255 glDisable GL_TEXTURE_2D;
2271 glDisable GL_BLEND;
2272 }; 2256 };
2273 }); 2257 });
2274} 2258}
2275 2259
2276sub _draw { 2260sub _draw {
2277 my ($self) = @_; 2261 my ($self) = @_;
2278 2262
2279 glEnable GL_BLEND;
2280 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2281 glEnable GL_TEXTURE_2D; 2263 glEnable GL_TEXTURE_2D;
2282 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2264 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2283 glColor 1, 1, 1, 1; 2265 glColor 1, 1, 1, 1;
2284 $self->{texture}->draw_quad (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); 2266 $self->{texture}->draw_quad_alpha_premultiplied (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h});
2285 glDisable GL_TEXTURE_2D; 2267 glDisable GL_TEXTURE_2D;
2286 glDisable GL_BLEND;
2287 2268
2288 $self->{children}[1]->draw; 2269 $self->{children}[1]->draw;
2289 2270
2290} 2271}
2291 2272
2385 @_, 2366 @_,
2386 can_events => 0, 2367 can_events => 0,
2387 ) 2368 )
2388} 2369}
2389 2370
2390sub set_markup { 2371sub set_tooltip_from {
2391 my ($self, $text) = @_; 2372 my ($self, $widget) = @_;
2392 2373
2393 $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0]; 2374 $self->{label} = new CFClient::UI::Label
2394 $self->{label}->set_markup ($text); 2375 markup => $widget->{tooltip},
2376 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
2377 fontsize => 0.8,
2378 fg => [0, 0, 0, 1],
2379 font => ($widget->{tooltip_font} || $::FONT_PROP);
2380
2395 $self->add ($self->{label}); 2381 $self->add ($self->{label});
2396} 2382}
2397 2383
2398sub size_request { 2384sub size_request {
2399 my ($self) = @_; 2385 my ($self) = @_;
2400
2401 $self->child->set_max_size ($::WIDTH * 0.3);
2402 2386
2403 my ($w, $h) = @{$self->child}{qw(req_w req_h)}; 2387 my ($w, $h) = @{$self->child}{qw(req_w req_h)};
2404 2388
2405 ($w + 4, $h + 4) 2389 ($w + 4, $h + 4)
2406} 2390}
2468 return unless $::CONN;#d# manage and cache textures differently 2452 return unless $::CONN;#d# manage and cache textures differently
2469 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; 2453 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]];
2470 2454
2471 # TODO animation 2455 # TODO animation
2472 if ($tex) { 2456 if ($tex) {
2473 glEnable GL_BLEND;
2474 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
2475 glEnable GL_TEXTURE_2D; 2457 glEnable GL_TEXTURE_2D;
2476 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2458 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2477 glColor 1, 1, 1, 1; 2459 glColor 1, 1, 1, 1;
2478 $tex->draw_quad (0, 0, $self->{w}, $self->{h}); 2460 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
2479 glDisable GL_TEXTURE_2D; 2461 glDisable GL_TEXTURE_2D;
2480 glDisable GL_BLEND;
2481 } 2462 }
2482} 2463}
2483 2464
2484############################################################################# 2465#############################################################################
2485 2466
2691 my $len = int 30 / $item->{fontsize}; 2672 my $len = int 30 / $item->{fontsize};
2692 substr $_, $len, length, "…" if $len < length; 2673 substr $_, $len, length, "…" if $len < length;
2693 } 2674 }
2694 2675
2695 new CFClient::UI::Label 2676 new CFClient::UI::Label
2696 markup => $short, 2677 markup => $short,
2697 tooltip => delete $item->{tooltip}, 2678 tooltip => delete $item->{tooltip},
2679 tooltip_font => $::FONT_PROP,
2680 tooltip_width => 0.75,
2698 fontsize => delete $item->{fontsize}, 2681 fontsize => delete $item->{fontsize},
2699 color => delete $item->{color}, 2682 color => delete $item->{color},
2700 can_events => 1, 2683 can_events => 1,
2701 can_hover => 1, 2684 can_hover => 1,
2702 }; 2685 };
2703 } 2686 }
2704 2687
2705 $self->clear; 2688 $self->clear;
2706 $self->SUPER::add (@widgets); 2689 $self->SUPER::add (@widgets);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines