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.121 by root, Mon Apr 17 19:21:00 2006 UTC vs.
Revision 1.125 by root, Mon Apr 17 20:52:15 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;
260 my ($self, $parent) = @_; 260 my ($self, $parent) = @_;
261 261
262 Scalar::Util::weaken ($self->{parent} = $parent); 262 Scalar::Util::weaken ($self->{parent} = $parent);
263} 263}
264 264
265sub check_size {
266 my ($self) = @_;
267
268 my ($w, $h) = $self->size_request;
269
270 if ($w != $self->{req_w} || $h != $self->{req_h}) {
271 $self->{req_w} = $w;
272 $self->{req_h} = $h;
273
274 $self->{parent}->check_size
275 if $self->{parent};
276 }
277}
278
265sub update { 279sub update {
266 my ($self) = @_; 280 my ($self) = @_;
267 281
268 $self->{parent}->update 282 $self->{parent}->update
269 if $self->{parent}; 283 if $self->{parent};
376sub remove { 390sub remove {
377 my ($self, $widget) = @_; 391 my ($self, $widget) = @_;
378 392
379 $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; 393 $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ];
380 394
381 $self->size_allocate (0, 0, $self->{w}, $self->{h}); 395 $self->check_size;
382} 396}
383 397
384sub find_widget { 398sub find_widget {
385 my ($self, $x, $y) = @_; 399 my ($self, $x, $y) = @_;
386 400
506 $tex->draw_quad (0, 0, $w, $h); 520 $tex->draw_quad (0, 0, $w, $h);
507 521
508 glDisable GL_BLEND; 522 glDisable GL_BLEND;
509 glDisable GL_TEXTURE_2D; 523 glDisable GL_TEXTURE_2D;
510} 524}
525
526#############################################################################
527
528package CFClient::UI::ViewPort;
529
530our @ISA = CFClient::UI::Window::;
531
532sub new { die }
533
534sub size_request {
535 my ($self) = @_;
536
537 @$self{qw(child_w child_h)} = $self->child->size_request;
538 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)});
539
540 @$self{qw(child_w child_h)}
541}
542
543sub size_allocate {
544 my ($self, $x, $y, $w, $h) = @_;
545
546 $self->_size_allocate ($x, $y, $w, $h) or return;
547}
548
549sub _draw {
550 my ($self) = @_;
551
552 $self->{children}[1]->draw;
553}
554
511 555
512############################################################################# 556#############################################################################
513 557
514package CFClient::UI::Frame; 558package CFClient::UI::Frame;
515 559
846} 890}
847 891
848sub size_allocate { 892sub size_allocate {
849 my ($self, $x, $y, $w, $h) = @_; 893 my ($self, $x, $y, $w, $h) = @_;
850 894
851 $self->_size_allocate ($x, $y, $w, $h); 895 $self->_size_allocate ($x, $y, $w, $h) or return;
852 896
853 ($h, $w) = ($w, $h); 897 ($h, $w) = ($w, $h);
854 898
855 my $children = $self->{children}; 899 my $children = $self->{children};
856 900
882 my $h = $h[$_]; 926 my $h = $h[$_];
883 $child->size_allocate ($y, 0, $h, $w); 927 $child->size_allocate ($y, 0, $h, $w);
884 928
885 $y += $h; 929 $y += $h;
886 } 930 }
931
932 1
887} 933}
888 934
889############################################################################# 935#############################################################################
890 936
891package CFClient::UI::VBox; 937package CFClient::UI::VBox;
906} 952}
907 953
908sub size_allocate { 954sub size_allocate {
909 my ($self, $x, $y, $w, $h) = @_; 955 my ($self, $x, $y, $w, $h) = @_;
910 956
911 $self->_size_allocate ($x, $y, $w, $h); 957 $self->_size_allocate ($x, $y, $w, $h) or return;
912 958
913 my $children = $self->{children}; 959 my $children = $self->{children};
914 960
915 my @h = map +($_->size_request)[1], @$children; 961 my @h = map +($_->size_request)[1], @$children;
916 962
938 my $h = $h[$_]; 984 my $h = $h[$_];
939 $child->size_allocate (0, $y, $w, $h); 985 $child->size_allocate (0, $y, $w, $h);
940 986
941 $y += $h; 987 $y += $h;
942 } 988 }
989
990 1
943} 991}
944 992
945############################################################################# 993#############################################################################
946 994
947package CFClient::UI::Label; 995package CFClient::UI::Label;
1043 glEnable GL_TEXTURE_2D; 1091 glEnable GL_TEXTURE_2D;
1044 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1092 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1045 1093
1046 glColor @{$self->{fg}}; 1094 glColor @{$self->{fg}};
1047 1095
1048 my $x = 1096 $self->{ox} = int (
1049 $self->{align} < 0 ? $self->{padding} 1097 $self->{align} < 0 ? $self->{padding}
1050 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 1098 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
1051 : ($self->{w} - $tex->{w}) * 0.5; 1099 : ($self->{w} - $tex->{w}) * 0.5
1100 );
1052 1101
1053 my $y = 1102 $self->{oy} = int (
1054 $self->{valign} < 0 ? $self->{padding} 1103 $self->{valign} < 0 ? $self->{padding}
1055 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} 1104 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding}
1056 : ($self->{h} - $tex->{h}) * 0.5; 1105 : ($self->{h} - $tex->{h}) * 0.5
1106 );
1057 1107
1058 $tex->draw_quad (int $x, int $y); 1108 $tex->draw_quad ($self->{ox}, $self->{oy});
1059 1109
1060 glDisable GL_TEXTURE_2D; 1110 glDisable GL_TEXTURE_2D;
1061 glDisable GL_BLEND; 1111 glDisable GL_BLEND;
1062} 1112}
1063 1113
1114} 1164}
1115 1165
1116sub size_allocate { 1166sub size_allocate {
1117 my ($self, $x, $y, $w, $h) = @_; 1167 my ($self, $x, $y, $w, $h) = @_;
1118 1168
1119 $self->SUPER::size_allocate ($x, $y, $w, $h); 1169 $self->SUPER::size_allocate ($x, $y, $w, $h) or return;
1120 1170
1121 $self->_set_text ($self->{text}); 1171 $self->_set_text ($self->{text});
1122} 1172}
1123 1173
1124sub set_text { 1174sub set_text {
1224 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text) 1274 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text)
1225 } 1275 }
1226 1276
1227 glColor @{$self->{fg}}; 1277 glColor @{$self->{fg}};
1228 glBegin GL_LINES; 1278 glBegin GL_LINES;
1229 glVertex $self->{cur_x}, $self->{cur_y};
1230 glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h}; 1279 glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy};
1280 glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h};
1231 glEnd; 1281 glEnd;
1232 } 1282 }
1233} 1283}
1234 1284
1235package CFClient::UI::Entry; 1285package CFClient::UI::Entry;
1272 1322
1273 $class->SUPER::new ( 1323 $class->SUPER::new (
1274 padding => 4, 1324 padding => 4,
1275 fg => [1, 1, 1], 1325 fg => [1, 1, 1],
1276 bg => [1, 1, 1, 0.2], 1326 bg => [1, 1, 1, 0.2],
1277 active_fg => [1, 1, 0], 1327 active_fg => [0, 0, 1],
1278 can_hover => 1, 1328 can_hover => 1,
1279 @_ 1329 @_
1280 ) 1330 )
1281} 1331}
1282 1332
1345} 1395}
1346 1396
1347sub size_allocate { 1397sub size_allocate {
1348 my ($self, $x, $y, $w, $h) = @_; 1398 my ($self, $x, $y, $w, $h) = @_;
1349 1399
1350 $self->_size_allocate ($x, $y, $w, $h); 1400 $self->_size_allocate ($x, $y, $w, $h) or return;
1351} 1401}
1352 1402
1353sub button_down { 1403sub button_down {
1354 my ($self, $ev, $x, $y) = @_; 1404 my ($self, $ev, $x, $y) = @_;
1355 1405
1379 1429
1380 $tex->draw_quad (0, 0, $s, $s); 1430 $tex->draw_quad (0, 0, $s, $s);
1381 1431
1382 glDisable GL_TEXTURE_2D; 1432 glDisable GL_TEXTURE_2D;
1383 glDisable GL_BLEND; 1433 glDisable GL_BLEND;
1434}
1435
1436#############################################################################
1437
1438package CFClient::UI::VGauge;
1439
1440our @ISA = CFClient::UI::Base::;
1441
1442use SDL::OpenGL;
1443
1444my %tex = (
1445 food => [
1446 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1447 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1448 ],
1449 grace => [
1450 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1451 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/
1452 ],
1453 hp => [
1454 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1455 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1456 ],
1457 mana => [
1458 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1459 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/
1460 ],
1461);
1462
1463# eg. VGauge->new (gauge => 'food'), default gauge: food
1464sub new {
1465 my $class = shift;
1466
1467 my $self = $class->SUPER::new (gauge => 'food', @_);
1468
1469 $self
1470}
1471
1472sub size_request {
1473 my ($self) = @_;
1474
1475 ($self->{w}, $self->{h})
1476}
1477
1478sub set_max {
1479 my ($self, $max) = @_;
1480 $self->{max_val} = $max;
1481}
1482
1483sub set_value {
1484 my ($self, $val, $max) = @_;
1485
1486 $self->set_max ($max)
1487 if defined $max;
1488
1489 $max = $self->{max_val};
1490 $self->{val} = $val;
1491
1492 $self->update;
1493}
1494
1495sub _draw {
1496 my ($self) = @_;
1497
1498 my $tex = $tex{$self->{gauge}};
1499
1500 my ($w, $h) = ($self->{w}, $self->{h});
1501
1502 my $ycut = $self->{val} / ($self->{max_val} || 1);
1503 $ycut = 1 if $self->{val} > $self->{max_val};
1504
1505 my $t1 = $tex->[0];
1506 my $t2 = $tex->[1];
1507
1508 glEnable GL_BLEND;
1509 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1510 glEnable GL_TEXTURE_2D;
1511 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1512
1513 my $h1 = $self->{h} - $ycut * $self->{h};
1514 my $h2 = $ycut * $self->{h};
1515
1516 my $yp = 0;
1517
1518 glBindTexture (GL_TEXTURE_2D, $t1->{name});
1519 glBegin (GL_QUADS);
1520 glTexCoord (0, 0); glVertex (0 , $yp);
1521 glTexCoord (0, (1 - $ycut)); glVertex (0 , $yp + $h1);
1522 glTexCoord (1, (1 - $ycut)); glVertex (0 + $w, $yp + $h1);
1523 glTexCoord (1, 0); glVertex (0 + $w, $yp);
1524 glEnd ();
1525
1526 $yp += $h1;
1527
1528 glBindTexture (GL_TEXTURE_2D, $t2->{name});
1529 glBegin (GL_QUADS);
1530 glTexCoord (0, (1 - $ycut)); glVertex (0 , $yp);
1531 glTexCoord (0, 1); glVertex (0 , $yp + $h2);
1532 glTexCoord (1, 1); glVertex (0 + $w, $yp + $h2);
1533 glTexCoord (1, (1 - $ycut)); glVertex (0 + $w, $yp);
1534 glEnd ();
1535
1536 glDisable GL_BLEND;
1537 glDisable GL_TEXTURE_2D;
1384} 1538}
1385 1539
1386############################################################################# 1540#############################################################################
1387 1541
1388package CFClient::UI::Slider; 1542package CFClient::UI::Slider;
1584} 1738}
1585 1739
1586sub size_allocate { 1740sub size_allocate {
1587 my ($self, $x, $y, $w, $h) = @_; 1741 my ($self, $x, $y, $w, $h) = @_;
1588 1742
1589 $self->SUPER::size_allocate ($x, $y, $w, $h); 1743 $self->SUPER::size_allocate ($x, $y, $w, $h) or return;
1590 1744
1591 $self->{layout}->set_height ($self->{fontsize}); 1745 $self->{layout}->set_height ($self->{fontsize});
1592 $self->{layout}->set_width ($self->{w}); 1746 $self->{layout}->set_width ($self->{w});
1593 1747
1594 $self->reflow; 1748 $self->reflow;
1749 $self->update;
1595} 1750}
1596 1751
1597sub add_paragraph { 1752sub add_paragraph {
1598 my ($self, $color, $text) = @_; 1753 my ($self, $color, $text) = @_;
1599 1754
1884 2039
1885 my $mod = $ev->key_mod; 2040 my $mod = $ev->key_mod;
1886 my $sym = $ev->key_sym; 2041 my $sym = $ev->key_sym;
1887 2042
1888 if ($sym == SDLK_KP5) { 2043 if ($sym == SDLK_KP5) {
1889 $::CONN->user_send ("command stay fire"); 2044 $::CONN->user_send ("stay fire");
1890 } elsif ($sym == SDLK_a) { 2045 } elsif ($sym == SDLK_a) {
1891 $::CONN->user_send ("command apply"); 2046 $::CONN->user_send ("apply");
1892 } elsif ($sym == SDLK_QUOTE) { 2047 } elsif ($sym == SDLK_QUOTE) {
1893 $self->emit ('activate_console'); 2048 $self->emit ('activate_console');
1894 } elsif ($sym == SDLK_SLASH) { 2049 } elsif ($sym == SDLK_SLASH) {
1895 $self->emit ('activate_console' => '/'); 2050 $self->emit ('activate_console' => '/');
1896 } elsif (exists $DIR{$sym}) { 2051 } elsif (exists $DIR{$sym}) {
1897 if ($mod & KMOD_SHIFT) { 2052 if ($mod & KMOD_SHIFT) {
1898 $self->{shft}++; 2053 $self->{shft}++;
1899 $::CONN->user_send ("command fire $DIR{$sym}[0]"); 2054 $::CONN->user_send ("fire $DIR{$sym}[0]");
1900 } elsif ($mod & KMOD_CTRL) { 2055 } elsif ($mod & KMOD_CTRL) {
1901 $self->{ctrl}++; 2056 $self->{ctrl}++;
1902 $::CONN->user_send ("command run $DIR{$sym}[0]"); 2057 $::CONN->user_send ("run $DIR{$sym}[0]");
1903 } else { 2058 } else {
1904 $::CONN->user_send ("command $DIR{$sym}[1]"); 2059 $::CONN->user_send ("$DIR{$sym}[1]");
1905 } 2060 }
1906 } 2061 }
1907} 2062}
1908 2063
1909sub key_up { 2064sub key_up {
1911 2066
1912 my $mod = $ev->key_mod; 2067 my $mod = $ev->key_mod;
1913 my $sym = $ev->key_sym; 2068 my $sym = $ev->key_sym;
1914 2069
1915 if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { 2070 if (!($mod & KMOD_SHIFT) && delete $self->{shft}) {
1916 $::CONN->user_send ("command fire_stop"); 2071 $::CONN->user_send ("fire_stop");
1917 } 2072 }
1918 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { 2073 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) {
1919 $::CONN->user_send ("command run_stop"); 2074 $::CONN->user_send ("run_stop");
1920 } 2075 }
1921} 2076}
1922 2077
1923############################################################################# 2078#############################################################################
1924 2079
2007 2162
2008our @ISA = CFClient::UI::Container::; 2163our @ISA = CFClient::UI::Container::;
2009 2164
2010use SDL::OpenGL; 2165use SDL::OpenGL;
2011 2166
2167sub check_size {
2168 my ($self) = @_;
2169
2170 $self->size_allocate (0, 0, $::WITH, $::HEIGHT);
2171}
2172
2012sub size_request { 2173sub size_request {
2013 ($::WIDTH, $::HEIGHT) 2174 ($::WIDTH, $::HEIGHT)
2014} 2175}
2015 2176
2016sub size_allocate { 2177sub size_allocate {
2029} 2190}
2030 2191
2031sub update { 2192sub update {
2032 my ($self) = @_; 2193 my ($self) = @_;
2033 2194
2034 $self->size_allocate (0, 0, $::WIDTH, $::HEIGHT); 2195 $self->check_size;
2035 ::refresh (); 2196 ::refresh ();
2036} 2197}
2037 2198
2038sub add { 2199sub add {
2039 my ($self, $widget) = @_; 2200 my ($self, $widget) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines