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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines