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.151 by root, Sun Apr 23 00:57:39 2006 UTC vs.
Revision 1.157 by root, Sun Apr 23 21:47:32 2006 UTC

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
207sub size_allocate { 212sub size_allocate {
208 # nothing to be done 213 # nothing to be done
214}
215
216sub 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
212sub _topleft { 224sub _topleft {
213 my ($self, $x, $y) = @_; 225 my ($self, $x, $y) = @_;
1094sub new { 1106sub 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
1151sub size_request { 1164sub 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;
1179 1194
1180sub set_fontsize { 1195sub set_fontsize {
1181 my ($self, $fontsize) = @_; 1196 my ($self, $fontsize) = @_;
1182 1197
1183 $self->{fontsize} = $fontsize; 1198 $self->{fontsize} = $fontsize;
1199 delete $self->{texture};
1184 $self->check_size; 1200 $self->check_size;
1201 $self->update;
1185} 1202}
1186 1203
1187sub _draw { 1204sub _draw {
1188 my ($self) = @_; 1205 my ($self) = @_;
1189 1206
1190 my $tex = $self->{texture} ||= do { 1207 my $tex = $self->{texture} ||= do {
1208 $self->{layout}->set_font ($self->{font}) if $self->{font};
1191 $self->{layout}->set_width ($self->{w}); 1209 $self->{layout}->set_width ($self->{w});
1192 $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);
1193 new_from_layout CFClient::Texture $self->{layout} 1211 new_from_layout CFClient::Texture $self->{layout}
1194 }; 1212 };
1195 1213
1721 my $self = $class->SUPER::new ( 1739 my $self = $class->SUPER::new (
1722 tooltip => $arg{type}, 1740 tooltip => $arg{type},
1723 %arg, 1741 %arg,
1724 ); 1742 );
1725 1743
1726 $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);
1727 $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);
1728 $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);
1729 1747
1730 $self 1748 $self
1731} 1749}
1732 1750
1733sub set_fontsize { 1751sub set_fontsize {
1900sub new { 1918sub new {
1901 my $class = shift; 1919 my $class = shift;
1902 1920
1903 my $self = $class->SUPER::new ( 1921 my $self = $class->SUPER::new (
1904 fontsize => 1, 1922 fontsize => 1,
1923 #font => default_font
1905 @_, 1924 @_,
1906 1925
1907 layout => (new CFClient::Layout), 1926 layout => (new CFClient::Layout),
1908 par => [], 1927 par => [],
1909 height => 0, 1928 height => 0,
1949sub size_allocate { 1968sub size_allocate {
1950 my ($self, $w, $h) = @_; 1969 my ($self, $w, $h) = @_;
1951 1970
1952 $self->SUPER::size_allocate ($w, $h); 1971 $self->SUPER::size_allocate ($w, $h);
1953 1972
1973 $self->{layout}->set_font ($self->{font}) if $self->{font};
1954 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1974 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1955 $self->{layout}->set_width ($self->{children}[0]{w}); 1975 $self->{layout}->set_width ($self->{children}[0]{w});
1956 1976
1957 $self->reflow; 1977 $self->reflow;
1958} 1978}
2010 my $y1 = $top + $self->{h}; 2030 my $y1 = $top + $self->{h};
2011 2031
2012 my $y = 0; 2032 my $y = 0;
2013 2033
2014 my $layout = $self->{layout}; 2034 my $layout = $self->{layout};
2035
2036 $layout->set_font ($self->{font}) if $self->{font};
2015 2037
2016 for my $par (@{$self->{par}}) { 2038 for my $par (@{$self->{par}}) {
2017 my $h = $par->[0]; 2039 my $h = $par->[0];
2018 2040
2019 if ($y0 < $y + $h && $y < $y1) { 2041 if ($y0 < $y + $h && $y < $y1) {
2129 $self->emit (changed => $self->{state}); 2151 $self->emit (changed => $self->{state});
2130} 2152}
2131 2153
2132############################################################################# 2154#############################################################################
2133 2155
2156package CFClient::UI::Tooltip;
2157
2158our @ISA = CFClient::UI::Bin::;
2159
2160use CFClient::OpenGL;
2161
2162sub new {
2163 my $class = shift;
2164
2165 $class->SUPER::new (
2166 @_,
2167 can_events => 0,
2168 )
2169}
2170
2171sub set_text {
2172 my ($self, $text) = @_;
2173
2174 $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0];
2175 $self->{label}->set_text ($text);
2176 $self->add ($self->{label});
2177}
2178
2179sub size_request {
2180 my ($self) = @_;
2181
2182 $self->child->set_max_size ($::WIDTH * 0.2);
2183
2184 my ($w, $h) = @{$self->child}{qw(req_w req_h)};
2185
2186 ($w + 4, $h + 4)
2187}
2188
2189sub _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;
2217}
2218
2219#############################################################################
2220
2134package CFClient::UI::Root; 2221package CFClient::UI::Root;
2135 2222
2136our @ISA = CFClient::UI::Container::; 2223our @ISA = CFClient::UI::Container::;
2137 2224
2138use CFClient::OpenGL; 2225use CFClient::OpenGL;
2213############################################################################# 2300#############################################################################
2214 2301
2215package CFClient::UI; 2302package CFClient::UI;
2216 2303
2217$ROOT = new CFClient::UI::Root; 2304$ROOT = new CFClient::UI::Root;
2218$TOOLTIP = new CFClient::UI::Label fontsize => 0.8, can_events => 0; 2305$TOOLTIP = new CFClient::UI::Tooltip;
2219 2306
22201 23071
2221 2308

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines