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.333 by root, Sun Jul 23 11:09:58 2006 UTC vs.
Revision 1.337 by root, Mon Jul 24 04:24:43 2006 UTC

367 my ($self, $x, $y, $w, $h) = @_; 367 my ($self, $x, $y, $w, $h) = @_;
368 368
369 if ($self->{aspect}) { 369 if ($self->{aspect}) {
370 my ($ow, $oh) = ($w, $h); 370 my ($ow, $oh) = ($w, $h);
371 371
372 $w = List::Util::min $w, int $h * $self->{aspect}; 372 $w = List::Util::min $w, CFClient::ceil $h * $self->{aspect};
373 $h = List::Util::min $h, int $w / $self->{aspect}; 373 $h = List::Util::min $h, CFClient::ceil $w / $self->{aspect};
374 374
375 # use alignment to adjust x, y 375 # use alignment to adjust x, y
376 376
377 $x += int 0.5 * ($ow - $w); 377 $x += int 0.5 * ($ow - $w);
378 $y += int 0.5 * ($oh - $h); 378 $y += int 0.5 * ($oh - $h);
1635 } 1635 }
1636 1636
1637 $self 1637 $self
1638} 1638}
1639 1639
1640sub escape($) {
1641 local $_ = $_[0];
1642
1643 s/&/&/g;
1644 s/>/>/g;
1645 s/</&lt;/g;
1646
1647 $_
1648}
1649
1650sub update { 1640sub update {
1651 my ($self) = @_; 1641 my ($self) = @_;
1652 1642
1653 delete $self->{texture}; 1643 delete $self->{texture};
1654 $self->SUPER::update; 1644 $self->SUPER::update;
2063 $self->SUPER::_draw; 2053 $self->SUPER::_draw;
2064} 2054}
2065 2055
2066############################################################################# 2056#############################################################################
2067 2057
2058package CFClient::UI::CheckBox;
2059
2060our @ISA = CFClient::UI::DrawBG::;
2061
2062my @tex =
2063 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
2064 qw(c1_checkbox_bg.png c1_checkbox_active.png);
2065
2066use CFClient::OpenGL;
2067
2068sub new {
2069 my $class = shift;
2070
2071 $class->SUPER::new (
2072 padding_x => 2,
2073 padding_y => 2,
2074 fg => [1, 1, 1],
2075 active_fg => [1, 1, 0],
2076 bg => [0, 0, 0, 0.2],
2077 active_bg => [1, 1, 1, 0.5],
2078 state => 0,
2079 can_hover => 1,
2080 @_
2081 )
2082}
2083
2084sub size_request {
2085 my ($self) = @_;
2086
2087 (6) x 2
2088}
2089
2090sub toggle {
2091 my ($self) = @_;
2092
2093 $self->{state} = !$self->{state};
2094 $self->emit (changed => $self->{state});
2095 $self->update;
2096}
2097
2098sub invoke_button_down {
2099 my ($self, $ev, $x, $y) = @_;
2100
2101 if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x}
2102 && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) {
2103 $self->toggle;
2104 } else {
2105 return 0
2106 }
2107
2108 1
2109}
2110
2111sub _draw {
2112 my ($self) = @_;
2113
2114 $self->SUPER::_draw;
2115
2116 glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0;
2117
2118 my ($w, $h) = @$self{qw(w h)};
2119
2120 my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2;
2121
2122 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} };
2123
2124 my $tex = $self->{state} ? $tex[1] : $tex[0];
2125
2126 glEnable GL_TEXTURE_2D;
2127 $tex->draw_quad_alpha (0, 0, $s, $s);
2128 glDisable GL_TEXTURE_2D;
2129}
2130
2131#############################################################################
2132
2133package CFClient::UI::Image;
2134
2135our @ISA = CFClient::UI::Base::;
2136
2137use CFClient::OpenGL;
2138
2139our %texture_cache;
2140
2141sub new {
2142 my $class = shift;
2143
2144 my $self = $class->SUPER::new (
2145 can_events => 0,
2146 @_,
2147 );
2148
2149 $self->{path} || $self->{tex}
2150 or Carp::croak "'path' or 'tex' attributes required";
2151
2152 $self->{tex} ||= $texture_cache{$self->{path}} ||=
2153 new_from_file CFClient::Texture CFClient::find_rcfile $self->{path}, mipmap => 1;
2154
2155 Scalar::Util::weaken $texture_cache{$self->{path}};
2156
2157 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2158
2159 $self
2160}
2161
2162sub STORABLE_freeze {
2163 my ($self, $cloning) = @_;
2164
2165 $self->{path}
2166 or die "cannot serialise CFClient::UI::Image on non-loadable images\n";
2167
2168 $self->{path}
2169}
2170
2171sub STORABLE_attach {
2172 my ($self, $cloning, $path) = @_;
2173
2174 $self->new (path => $path)
2175}
2176
2177sub size_request {
2178 my ($self) = @_;
2179
2180 ($self->{tex}{w}, $self->{tex}{h})
2181}
2182
2183sub _draw {
2184 my ($self) = @_;
2185
2186 my $tex = $self->{tex};
2187
2188 my ($w, $h) = ($self->{w}, $self->{h});
2189
2190 if ($self->{rot90}) {
2191 glRotate 90, 0, 0, 1;
2192 glTranslate 0, -$self->{w}, 0;
2193
2194 ($w, $h) = ($h, $w);
2195 }
2196
2197 glEnable GL_TEXTURE_2D;
2198 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2199
2200 $tex->draw_quad (0, 0, $w, $h);
2201
2202 glDisable GL_TEXTURE_2D;
2203}
2204
2205#############################################################################
2206
2068package CFClient::UI::ImageButton; 2207package CFClient::UI::ImageButton;
2069 2208
2070our @ISA = CFClient::UI::Image::; 2209our @ISA = CFClient::UI::Image::;
2071 2210
2072use CFClient::OpenGL; 2211use CFClient::OpenGL;
2095 $self->emit ("activate") 2234 $self->emit ("activate")
2096 if $x >= 0 && $x < $self->{w} 2235 if $x >= 0 && $x < $self->{w}
2097 && $y >= 0 && $y < $self->{h}; 2236 && $y >= 0 && $y < $self->{h};
2098 2237
2099 1 2238 1
2100}
2101
2102#############################################################################
2103
2104package CFClient::UI::CheckBox;
2105
2106our @ISA = CFClient::UI::DrawBG::;
2107
2108my @tex =
2109 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
2110 qw(c1_checkbox_bg.png c1_checkbox_active.png);
2111
2112use CFClient::OpenGL;
2113
2114sub new {
2115 my $class = shift;
2116
2117 $class->SUPER::new (
2118 padding_x => 2,
2119 padding_y => 2,
2120 fg => [1, 1, 1],
2121 active_fg => [1, 1, 0],
2122 bg => [0, 0, 0, 0.2],
2123 active_bg => [1, 1, 1, 0.5],
2124 state => 0,
2125 can_hover => 1,
2126 @_
2127 )
2128}
2129
2130sub size_request {
2131 my ($self) = @_;
2132
2133 (6) x 2
2134}
2135
2136sub toggle {
2137 my ($self) = @_;
2138
2139 $self->{state} = !$self->{state};
2140 $self->emit (changed => $self->{state});
2141 $self->update;
2142}
2143
2144sub invoke_button_down {
2145 my ($self, $ev, $x, $y) = @_;
2146
2147 if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x}
2148 && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) {
2149 $self->toggle;
2150 } else {
2151 return 0
2152 }
2153
2154 1
2155}
2156
2157sub _draw {
2158 my ($self) = @_;
2159
2160 $self->SUPER::_draw;
2161
2162 glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0;
2163
2164 my ($w, $h) = @$self{qw(w h)};
2165
2166 my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2;
2167
2168 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} };
2169
2170 my $tex = $self->{state} ? $tex[1] : $tex[0];
2171
2172 glEnable GL_TEXTURE_2D;
2173 $tex->draw_quad_alpha (0, 0, $s, $s);
2174 glDisable GL_TEXTURE_2D;
2175}
2176
2177#############################################################################
2178
2179package CFClient::UI::Image;
2180
2181our @ISA = CFClient::UI::Base::;
2182
2183use CFClient::OpenGL;
2184
2185our %texture_cache;
2186
2187sub new {
2188 my $class = shift;
2189
2190 my $self = $class->SUPER::new (
2191 can_events => 0,
2192 @_,
2193 );
2194
2195 $self->{path} || $self->{tex}
2196 or Carp::croak "'path' or 'tex' attributes required";
2197
2198 $self->{tex} ||= $texture_cache{$self->{path}} ||=
2199 new_from_file CFClient::Texture CFClient::find_rcfile $self->{path}, mipmap => 1;
2200
2201 Scalar::Util::weaken $texture_cache{$self->{path}};
2202
2203 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2204
2205 $self
2206}
2207
2208sub size_request {
2209 my ($self) = @_;
2210
2211 ($self->{tex}{w}, $self->{tex}{h})
2212}
2213
2214sub _draw {
2215 my ($self) = @_;
2216
2217 my $tex = $self->{tex};
2218
2219 my ($w, $h) = ($self->{w}, $self->{h});
2220
2221 if ($self->{rot90}) {
2222 glRotate 90, 0, 0, 1;
2223 glTranslate 0, -$self->{w}, 0;
2224
2225 ($w, $h) = ($h, $w);
2226 }
2227
2228 glEnable GL_TEXTURE_2D;
2229 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2230
2231 $tex->draw_quad_alpha (0, 0, $w, $h);
2232
2233 glDisable GL_TEXTURE_2D;
2234} 2239}
2235 2240
2236############################################################################# 2241#############################################################################
2237 2242
2238package CFClient::UI::VGauge; 2243package CFClient::UI::VGauge;
3053 3058
3054############################################################################# 3059#############################################################################
3055 3060
3056package CFClient::UI::Face; 3061package CFClient::UI::Face;
3057 3062
3058our @ISA = CFClient::UI::Base::; 3063our @ISA = CFClient::UI::DrawBG::;
3059 3064
3060use CFClient::OpenGL; 3065use CFClient::OpenGL;
3061 3066
3062sub new { 3067sub new {
3063 my $class = shift; 3068 my $class = shift;
3099 3104
3100sub _draw { 3105sub _draw {
3101 my ($self) = @_; 3106 my ($self) = @_;
3102 3107
3103 return unless $::CONN; 3108 return unless $::CONN;
3109
3110 $self->SUPER::_draw;
3104 3111
3105 my $face; 3112 my $face;
3106 3113
3107 if ($self->{frame}) { 3114 if ($self->{frame}) {
3108 my $anim = $::CONN->{anim}[$self->{anim}]; 3115 my $anim = $::CONN->{anim}[$self->{anim}];
3355 $self->emit (page_changed => $self->{multiplexer}{current}); 3362 $self->emit (page_changed => $self->{multiplexer}{current});
3356} 3363}
3357 3364
3358############################################################################# 3365#############################################################################
3359 3366
3360package CFClient::UI::Combobox; 3367package CFClient::UI::Selector;
3361 3368
3362use utf8; 3369use utf8;
3363 3370
3364our @ISA = CFClient::UI::Button::; 3371our @ISA = CFClient::UI::Button::;
3365 3372
3935 $h = 0 if $h < 0; 3942 $h = 0 if $h < 0;
3936 3943
3937 $w = max $widget->{min_w}, $w; 3944 $w = max $widget->{min_w}, $w;
3938 $h = max $widget->{min_h}, $h; 3945 $h = max $widget->{min_h}, $h;
3939 3946
3947# $w = min $self->{w} - $widget->{x}, $w if $self->{w};
3948# $h = min $self->{h} - $widget->{y}, $h if $self->{h};
3949
3940 $w = min $widget->{max_w}, $w if exists $widget->{max_w}; 3950 $w = min $widget->{max_w}, $w if exists $widget->{max_w};
3941 $h = min $widget->{max_h}, $h if exists $widget->{max_h}; 3951 $h = min $widget->{max_h}, $h if exists $widget->{max_h};
3942 3952
3943 $w = int $w + 0.5; 3953 $w = int $w + 0.5;
3944 $h = int $h + 0.5; 3954 $h = int $h + 0.5;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines