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.78 by root, Tue Apr 11 22:49:13 2006 UTC vs.
Revision 1.81 by root, Wed Apr 12 00:40:45 2006 UTC

79use SDL::OpenGL; 79use SDL::OpenGL;
80 80
81sub new { 81sub new {
82 my $class = shift; 82 my $class = shift;
83 83
84 bless { 84 my $self = bless {
85 x => 0, 85 x => 0,
86 y => 0, 86 y => 0,
87 z => 0, 87 z => 0,
88 w => -1, 88 w => -1,
89 h => -1, 89 h => -1,
90 @_ 90 @_
91 }, $class 91 }, $class;
92
93 for (keys %$self) {
94 if (/^connect_(.*)$/) {
95 $self->connect ($1 => delete $self->{$_});
96 }
97 }
98
99 $self
92} 100}
93 101
94sub move { 102sub move {
95 my ($self, $x, $y, $z) = @_; 103 my ($self, $x, $y, $z) = @_;
96 $self->{x} = $x; 104 $self->{x} = $x;
263 271
264 # range [value, low, high, page] 272 # range [value, low, high, page]
265 273
266 $class->SUPER::new ( 274 $class->SUPER::new (
267 bg => [0, 0, 0, 0.2], 275 bg => [0, 0, 0, 0.2],
268 active_bg => [1, 1, 1], 276 active_bg => [1, 1, 1, 0.5],
269 @_ 277 @_
270 ) 278 )
271} 279}
272 280
273sub _draw { 281sub _draw {
933 941
934 $self->{text} = $text; 942 $self->{text} = $text;
935 $self->{layout}->set_markup ($text); 943 $self->{layout}->set_markup ($text);
936 944
937 delete $self->{texture}; 945 delete $self->{texture};
946# $self->{w} = $self->{h} = -1;
938 $self->update; 947 $self->update;
939} 948}
940 949
941sub get_text { 950sub get_text {
942 my ($self, $text) = @_; 951 my ($self, $text) = @_;
975sub _draw { 984sub _draw {
976 my ($self) = @_; 985 my ($self) = @_;
977 986
978 my $tex = $self->{texture} ||= do { 987 my $tex = $self->{texture} ||= do {
979 $self->{layout}->set_width ($self->{w}); 988 $self->{layout}->set_width ($self->{w});
980 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{height}); 989 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{height});
981 new_from_layout CFClient::Texture $self->{layout} 990 new_from_layout CFClient::Texture $self->{layout}
982 }; 991 };
983 992
984 glEnable GL_BLEND; 993 glEnable GL_BLEND;
985 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 994 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1012 my $class = shift; 1021 my $class = shift;
1013 1022
1014 $class->SUPER::new ( 1023 $class->SUPER::new (
1015 fg => [1, 1, 1], 1024 fg => [1, 1, 1],
1016 bg => [0, 0, 0, 0.2], 1025 bg => [0, 0, 0, 0.2],
1017 active_bg => [1, 1, 1], 1026 active_bg => [1, 1, 1, 0.5],
1018 active_fg => [0, 0, 0], 1027 active_fg => [0, 0, 0],
1019 @_ 1028 @_
1020 ) 1029 )
1021} 1030}
1022 1031
1155 } 1164 }
1156} 1165}
1157 1166
1158############################################################################# 1167#############################################################################
1159 1168
1169package CFClient::UI::Button;
1170
1171our @ISA = CFClient::UI::Label::;
1172
1173use SDL;
1174use SDL::OpenGL;
1175
1176sub new {
1177 my $class = shift;
1178
1179 $class->SUPER::new (
1180 padding => 4,
1181 fg => [1, 1, 1],
1182 bg => [1, 1, 1, 0.2],
1183 active_bg => [0, 0, 0, 0.5],
1184 active_fg => [1, 1, 0],
1185 border_fg => [1, 1, 0],
1186 @_
1187 )
1188}
1189
1190sub button_up {
1191 my ($self, $ev, $x, $y) = @_;
1192
1193 if ($x >= 0 && $x < $self->{w}
1194 && $y >= 0 && $y < $self->{h}) {
1195 $self->emit ("activate");
1196 }
1197}
1198
1199sub _draw {
1200 my ($self) = @_;
1201
1202 local $self->{fg} = $self->{fg};
1203
1204 glEnable GL_BLEND;
1205 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1206
1207 glTranslate 0.375, 0.375, 0; # make line and polyogon coordinates behave similarly
1208
1209 glBegin GL_LINE_LOOP;
1210 glColor @{$self->{border_fg}};
1211 glVertex 1 , 1;
1212 glVertex 1 , $self->{h} - 2;
1213 glVertex $self->{w} - 2, $self->{h} - 2;
1214 glVertex $self->{w} - 2, 1;
1215 glEnd;
1216
1217 if ($GRAB == $self) {
1218 glColor @{$self->{active_bg}};
1219 $self->{fg} = $self->{active_fg};
1220 } else {
1221 glColor @{$self->{bg}};
1222 }
1223
1224 glBegin GL_QUADS;
1225 glVertex 2 , 2;
1226 glVertex 2 , $self->{h} - 2;
1227 glVertex $self->{w} - 2, $self->{h} - 2;
1228 glVertex $self->{w} - 2, 2;
1229 glEnd;
1230 glDisable GL_BLEND;
1231
1232 $self->SUPER::_draw;
1233}
1234
1235#############################################################################
1236
1160package CFClient::UI::Slider; 1237package CFClient::UI::Slider;
1161 1238
1162use strict; 1239use strict;
1163 1240
1164use SDL::OpenGL; 1241use SDL::OpenGL;
1242 $value = int +($value - $lo) * $w / ($hi - $lo); 1319 $value = int +($value - $lo) * $w / ($hi - $lo);
1243 1320
1244 $w -= $page; 1321 $w -= $page;
1245 $page &= ~1; 1322 $page &= ~1;
1246 glTranslate $page * 0.5, 0, 0; 1323 glTranslate $page * 0.5, 0, 0;
1324 $page ||= 2;
1247 1325
1248 glColor @$fg; 1326 glColor @$fg;
1249 glBegin GL_LINES; 1327 glBegin GL_LINES;
1250 glVertex 0, 0; glVertex 0, $h; 1328 glVertex 0, 0; glVertex 0, $h;
1251 glVertex $w - 1, 0; glVertex $w - 1, $h; 1329 glVertex $w - 1, 0; glVertex $w - 1, $h;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines