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.120 by elmex, Sun Apr 16 17:43:17 2006 UTC vs.
Revision 1.124 by elmex, Mon Apr 17 20:29:37 2006 UTC

225 glPopMatrix; 225 glPopMatrix;
226 226
227 if ($self == $HOVER && $self->{can_hover}) { 227 if ($self == $HOVER && $self->{can_hover}) {
228 my ($x, $y) = @$self{qw(x y)}; 228 my ($x, $y) = @$self{qw(x y)};
229 229
230 glColor 0, 0, 1, 0.2; 230 glColor 1, 0.8, 0.5, 0.2;
231 glEnable GL_BLEND; 231 glEnable GL_BLEND;
232 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 232 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
233 glBegin GL_QUADS; 233 glBegin GL_QUADS;
234 glVertex $x , $y; 234 glVertex $x , $y;
235 glVertex $x + $self->{w}, $y; 235 glVertex $x + $self->{w}, $y;
962 padding => 2, 962 padding => 2,
963 layout => new CFClient::Layout, 963 layout => new CFClient::Layout,
964 %arg 964 %arg
965 ); 965 );
966 966
967 $self->set_text ($self->{text}); 967 $self->{xxx}++ if $self->{text} eq "Client Setup" && $self->{align};#d#
968
969 $self->set_text (delete $self->{text}) if exists $self->{text};
970 $self->set_markup (delete $self->{markup}) if exists $self->{markup};
968 971
969 $self 972 $self
970} 973}
971 974
972sub escape_text { 975sub escape_text {
980} 983}
981 984
982sub set_text { 985sub set_text {
983 my ($self, $text) = @_; 986 my ($self, $text) = @_;
984 987
985 $self->{text} = $text;
986 $self->{layout}->set_markup ($text); 988 $self->{layout}->set_text ($text);
987 989
988 delete $self->{texture}; 990 delete $self->{texture};
989# $self->{w} = $self->{h} = -1;
990 $self->update; 991 $self->update;
991} 992}
992 993
993sub get_text { 994sub set_markup {
994 my ($self, $text) = @_; 995 my ($self, $markup) = @_;
995 996
996 $self->{text} 997 $self->{layout}->set_markup ($markup);
998
999 delete $self->{texture};
1000 $self->update;
997} 1001}
998 1002
999sub size_request { 1003sub size_request {
1000 my ($self) = @_; 1004 my ($self) = @_;
1001 1005
1002 $self->{layout}->set_width; 1006 $self->{layout}->set_width;
1003 $self->{layout}->set_height ($self->{fontsize}); 1007 $self->{layout}->set_height ($self->{fontsize});
1008
1004 my ($w, $h) = $self->{layout}->size; 1009 my ($w, $h) = $self->{layout}->size;
1005 1010
1006 ( 1011 (
1007 $w + $self->{padding} * 2, 1012 $w + $self->{padding} * 2,
1008 $h + $self->{padding} * 2, 1013 $h + $self->{padding} * 2,
1027sub _draw { 1032sub _draw {
1028 my ($self) = @_; 1033 my ($self) = @_;
1029 1034
1030 my $tex = $self->{texture} ||= do { 1035 my $tex = $self->{texture} ||= do {
1031 $self->{layout}->set_width ($self->{w}); 1036 $self->{layout}->set_width ($self->{w});
1032 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize}); 1037 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize});
1033 new_from_layout CFClient::Texture $self->{layout} 1038 new_from_layout CFClient::Texture $self->{layout}
1034 }; 1039 };
1035 1040
1036 glEnable GL_BLEND; 1041 glEnable GL_BLEND;
1037 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1042 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1038 glEnable GL_TEXTURE_2D; 1043 glEnable GL_TEXTURE_2D;
1039 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1044 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1040 1045
1041 glColor @{$self->{fg}}; 1046 glColor @{$self->{fg}};
1042 1047
1043 my $x = 1048 $self->{ox} = int (
1044 $self->{align} < 0 ? $self->{padding} 1049 $self->{align} < 0 ? $self->{padding}
1045 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 1050 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
1046 : ($self->{w} - $tex->{w}) * 0.5; 1051 : ($self->{w} - $tex->{w}) * 0.5
1052 );
1047 1053
1048 my $y = 1054 $self->{oy} = int (
1049 $self->{valign} < 0 ? $self->{padding} 1055 $self->{valign} < 0 ? $self->{padding}
1050 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} 1056 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding}
1051 : ($self->{h} - $tex->{h}) * 0.5; 1057 : ($self->{h} - $tex->{h}) * 0.5
1058 );
1052 1059
1053 $tex->draw_quad (int $x, int $y); 1060 $tex->draw_quad ($self->{ox}, $self->{oy});
1054 1061
1055 glDisable GL_TEXTURE_2D; 1062 glDisable GL_TEXTURE_2D;
1056 glDisable GL_BLEND; 1063 glDisable GL_BLEND;
1057} 1064}
1058 1065
1059############################################################################# 1066#############################################################################
1060 1067
1061package CFClient::UI::Entry; 1068package CFClient::UI::EntryBase;
1062 1069
1063our @ISA = CFClient::UI::Label::; 1070our @ISA = CFClient::UI::Label::;
1064 1071
1065use SDL; 1072use SDL;
1066use SDL::OpenGL; 1073use SDL::OpenGL;
1081} 1088}
1082 1089
1083sub _set_text { 1090sub _set_text {
1084 my ($self, $text) = @_; 1091 my ($self, $text) = @_;
1085 1092
1086 my $old_text = $self->{text}; 1093 delete $self->{cur_h};
1094
1095 return if $self->{text} eq $text;
1087 1096
1088 $self->{last_activity} = $::NOW; 1097 $self->{last_activity} = $::NOW;
1089
1090 $self->{text} = $text; 1098 $self->{text} = $text;
1091 $self->{layout}->set_width ($self->{w});
1092 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize});
1093 1099
1094 $text =~ s/./*/g if $self->{hidden}; 1100 $text =~ s/./*/g if $self->{hidden};
1101 $self->{layout}->set_text ("$text ");
1095 1102
1096 $self->{layout}->set_markup ($self->escape_text ($text) . " "); 1103 $self->emit (changed => $self->{text});
1104}
1097 1105
1098 $text = substr $text, 0, $self->{cursor}; 1106sub get_text {
1099 utf8::encode $text; 1107 $_[0]{text}
1100
1101 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text);
1102
1103 $self->emit (changed => $self->{text}) # XXX: is this the right place to do this?
1104 if $old_text ne $self->{text};
1105} 1108}
1106 1109
1107sub size_request { 1110sub size_request {
1108 my ($self) = @_; 1111 my ($self) = @_;
1109 1112
1213 1216
1214 $self->SUPER::_draw; 1217 $self->SUPER::_draw;
1215 1218
1216 #TODO: force update every cursor change :( 1219 #TODO: force update every cursor change :(
1217 if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) { 1220 if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) {
1221
1222 unless (exists $self->{cur_h}) {
1223 my $text = substr $self->{text}, 0, $self->{cursor};
1224 utf8::encode $text;
1225
1226 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text)
1227 }
1228
1218 glColor @{$self->{fg}}; 1229 glColor @{$self->{fg}};
1219 glBegin GL_LINES; 1230 glBegin GL_LINES;
1220 glVertex $self->{cur_x}, $self->{cur_y};
1221 glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h}; 1231 glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy};
1232 glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h};
1222 glEnd; 1233 glEnd;
1223 } 1234 }
1224} 1235}
1225 1236
1226package CFClient::UI::LineEntry; 1237package CFClient::UI::Entry;
1227 1238
1228our @ISA = CFClient::UI::Entry::; 1239our @ISA = CFClient::UI::EntryBase::;
1229 1240
1230use SDL; 1241use SDL;
1231use SDL::OpenGL; 1242use SDL::OpenGL;
1232 1243
1233sub key_down { 1244sub key_down {
1263 1274
1264 $class->SUPER::new ( 1275 $class->SUPER::new (
1265 padding => 4, 1276 padding => 4,
1266 fg => [1, 1, 1], 1277 fg => [1, 1, 1],
1267 bg => [1, 1, 1, 0.2], 1278 bg => [1, 1, 1, 0.2],
1268 active_fg => [1, 1, 0], 1279 active_fg => [0, 0, 1],
1269 can_hover => 1, 1280 can_hover => 1,
1270 @_ 1281 @_
1271 ) 1282 )
1272} 1283}
1273 1284
1370 1381
1371 $tex->draw_quad (0, 0, $s, $s); 1382 $tex->draw_quad (0, 0, $s, $s);
1372 1383
1373 glDisable GL_TEXTURE_2D; 1384 glDisable GL_TEXTURE_2D;
1374 glDisable GL_BLEND; 1385 glDisable GL_BLEND;
1386}
1387
1388#############################################################################
1389
1390package CFClient::UI::VGauge;
1391
1392our @ISA = CFClient::UI::Base::;
1393
1394use SDL::OpenGL;
1395
1396my %tex = (
1397 food => [
1398 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1399 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1400 ],
1401 grace => [
1402 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1403 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/
1404 ],
1405 hp => [
1406 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1407 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1408 ],
1409 mana => [
1410 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1411 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/
1412 ],
1413);
1414
1415# eg. VGauge->new (gauge => 'food'), default gauge: food
1416sub new {
1417 my $class = shift;
1418
1419 my $self = $class->SUPER::new (gauge => 'food', @_);
1420
1421 $self
1422}
1423
1424sub size_request {
1425 my ($self) = @_;
1426
1427 ($self->{w}, $self->{h})
1428}
1429
1430sub set_max {
1431 my ($self, $max) = @_;
1432 $self->{max_val} = $max;
1433}
1434
1435sub set_value {
1436 my ($self, $val, $max) = @_;
1437
1438 $self->set_max ($max)
1439 if defined $max;
1440
1441 $max = $self->{max_val};
1442 $self->{val} = $val;
1443
1444 $self->update;
1445}
1446
1447sub _draw {
1448 my ($self) = @_;
1449
1450 my $tex = $tex{$self->{gauge}};
1451
1452 my ($w, $h) = ($self->{w}, $self->{h});
1453
1454 my $ycut = $self->{val} / ($self->{max_val} || 1);
1455 $ycut = 1 if $self->{val} > $self->{max_val};
1456
1457 my $t1 = $tex->[0];
1458 my $t2 = $tex->[1];
1459
1460 glEnable GL_BLEND;
1461 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1462 glEnable GL_TEXTURE_2D;
1463 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1464
1465 my $h1 = $self->{h} - $ycut * $self->{h};
1466 my $h2 = $ycut * $self->{h};
1467
1468 my $yp = 0;
1469
1470 glBindTexture (GL_TEXTURE_2D, $t1->{name});
1471 glBegin (GL_QUADS);
1472 glTexCoord (0, 0); glVertex (0 , $yp);
1473 glTexCoord (0, (1 - $ycut)); glVertex (0 , $yp + $h1);
1474 glTexCoord (1, (1 - $ycut)); glVertex (0 + $w, $yp + $h1);
1475 glTexCoord (1, 0); glVertex (0 + $w, $yp);
1476 glEnd ();
1477
1478 $yp += $h1;
1479
1480 glBindTexture (GL_TEXTURE_2D, $t2->{name});
1481 glBegin (GL_QUADS);
1482 glTexCoord (0, (1 - $ycut)); glVertex (0 , $yp);
1483 glTexCoord (0, 1); glVertex (0 , $yp + $h2);
1484 glTexCoord (1, 1); glVertex (0 + $w, $yp + $h2);
1485 glTexCoord (1, (1 - $ycut)); glVertex (0 + $w, $yp);
1486 glEnd ();
1487
1488 glDisable GL_BLEND;
1489 glDisable GL_TEXTURE_2D;
1375} 1490}
1376 1491
1377############################################################################# 1492#############################################################################
1378 1493
1379package CFClient::UI::Slider; 1494package CFClient::UI::Slider;
1875 1990
1876 my $mod = $ev->key_mod; 1991 my $mod = $ev->key_mod;
1877 my $sym = $ev->key_sym; 1992 my $sym = $ev->key_sym;
1878 1993
1879 if ($sym == SDLK_KP5) { 1994 if ($sym == SDLK_KP5) {
1880 $::CONN->user_send ("command stay fire"); 1995 $::CONN->user_send ("stay fire");
1881 } elsif ($sym == SDLK_a) { 1996 } elsif ($sym == SDLK_a) {
1882 $::CONN->user_send ("command apply"); 1997 $::CONN->user_send ("apply");
1883 } elsif ($sym == SDLK_QUOTE) { 1998 } elsif ($sym == SDLK_QUOTE) {
1884 $self->emit ('activate_console'); 1999 $self->emit ('activate_console');
1885 } elsif ($sym == SDLK_SLASH) { 2000 } elsif ($sym == SDLK_SLASH) {
1886 $self->emit ('activate_console' => '/'); 2001 $self->emit ('activate_console' => '/');
1887 } elsif (exists $DIR{$sym}) { 2002 } elsif (exists $DIR{$sym}) {
1888 if ($mod & KMOD_SHIFT) { 2003 if ($mod & KMOD_SHIFT) {
1889 $self->{shft}++; 2004 $self->{shft}++;
1890 $::CONN->user_send ("command fire $DIR{$sym}[0]"); 2005 $::CONN->user_send ("fire $DIR{$sym}[0]");
1891 } elsif ($mod & KMOD_CTRL) { 2006 } elsif ($mod & KMOD_CTRL) {
1892 $self->{ctrl}++; 2007 $self->{ctrl}++;
1893 $::CONN->user_send ("command run $DIR{$sym}[0]"); 2008 $::CONN->user_send ("run $DIR{$sym}[0]");
1894 } else { 2009 } else {
1895 $::CONN->user_send ("command $DIR{$sym}[1]"); 2010 $::CONN->user_send ("$DIR{$sym}[1]");
1896 } 2011 }
1897 } 2012 }
1898} 2013}
1899 2014
1900sub key_up { 2015sub key_up {
1902 2017
1903 my $mod = $ev->key_mod; 2018 my $mod = $ev->key_mod;
1904 my $sym = $ev->key_sym; 2019 my $sym = $ev->key_sym;
1905 2020
1906 if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { 2021 if (!($mod & KMOD_SHIFT) && delete $self->{shft}) {
1907 $::CONN->user_send ("command fire_stop"); 2022 $::CONN->user_send ("fire_stop");
1908 } 2023 }
1909 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { 2024 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) {
1910 $::CONN->user_send ("command run_stop"); 2025 $::CONN->user_send ("run_stop");
1911 } 2026 }
1912} 2027}
1913 2028
1914############################################################################# 2029#############################################################################
1915 2030

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines