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.207 by elmex, Mon May 15 18:23:33 2006 UTC vs.
Revision 1.209 by root, Wed May 17 00:26:55 2006 UTC

280sub set_max_size { 280sub set_max_size {
281 my ($self, $w, $h) = @_; 281 my ($self, $w, $h) = @_;
282 282
283 delete $self->{max_w}; $self->{max_w} = $w if $w; 283 delete $self->{max_w}; $self->{max_w} = $w if $w;
284 delete $self->{max_h}; $self->{max_h} = $h if $h; 284 delete $self->{max_h}; $self->{max_h} = $h if $h;
285}
286
287sub set_tooltip {
288 my ($self, $tooltip) = @_;
289
290 $self->{tooltip} = $tooltip;
291
292 if ($CFClient::UI::TOOLTIP->{owner} == $self) {
293 delete $CFClient::UI::TOOLTIP->{owner};
294 CFClient::UI::check_tooltip;
295 }
285} 296}
286 297
287# translate global coordinates to local coordinate system 298# translate global coordinates to local coordinate system
288sub coord2local { 299sub coord2local {
289 my ($self, $x, $y) = @_; 300 my ($self, $x, $y) = @_;
455 my $class = shift; 466 my $class = shift;
456 467
457 # range [value, low, high, page] 468 # range [value, low, high, page]
458 469
459 $class->SUPER::new ( 470 $class->SUPER::new (
460 bg => [0, 0, 0, 0.2], 471 #bg => [0, 0, 0, 0.2],
461 active_bg => [1, 1, 1, 0.5], 472 #active_bg => [1, 1, 1, 0.5],
462 @_ 473 @_
463 ) 474 )
464} 475}
465 476
466sub _draw { 477sub _draw {
467 my ($self) = @_; 478 my ($self) = @_;
468 479
480 my $color = $FOCUS == $self && $self->{active_bg}
481 ? $self->{active_bg}
482 : $self->{bg};
483
484 if ($color && (@$color < 4 || $color->[3])) {
469 my ($w, $h) = @$self{qw(w h)}; 485 my ($w, $h) = @$self{qw(w h)};
470 486
471 glEnable GL_BLEND; 487 glEnable GL_BLEND;
472 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 488 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
473 glColor @{ $FOCUS == $self ? $self->{active_bg} : $self->{bg} }; 489 glColor @$color;
474 490
475 glBegin GL_QUADS; 491 glBegin GL_QUADS;
476 glVertex 0 , 0; 492 glVertex 0 , 0;
477 glVertex 0 , $h; 493 glVertex 0 , $h;
478 glVertex $w, $h; 494 glVertex $w, $h;
479 glVertex $w, 0; 495 glVertex $w, 0;
480 glEnd; 496 glEnd;
481 497
482 glDisable GL_BLEND; 498 glDisable GL_BLEND;
499 }
483} 500}
484 501
485############################################################################# 502#############################################################################
486 503
487package CFClient::UI::Empty; 504package CFClient::UI::Empty;
895 my ($self, $w, $h) = @_; 912 my ($self, $w, $h) = @_;
896 913
897 $h -= List::Util::max 0, $self->border * 2; 914 $h -= List::Util::max 0, $self->border * 2;
898 $w -= List::Util::max 0, $self->border * 2; 915 $w -= List::Util::max 0, $self->border * 2;
899 916
900 $self->{title}->configure ($self->border, $self->border - $::FONTSIZE * 2, $w, $::FONTSIZE * 2) 917 $self->{title}->configure ($self->border, int $self->border - $::FONTSIZE * 2, $w, int $::FONTSIZE * 2)
901 if $self->{title}; 918 if $self->{title};
902 919
903 $self->child->configure ($self->border, $self->border, $w, $h); 920 $self->child->configure ($self->border, $self->border, $w, $h);
904} 921}
905 922
1266 1283
1267############################################################################# 1284#############################################################################
1268 1285
1269package CFClient::UI::Label; 1286package CFClient::UI::Label;
1270 1287
1271our @ISA = CFClient::UI::Base::; 1288our @ISA = CFClient::UI::DrawBG::;
1272 1289
1273use CFClient::OpenGL; 1290use CFClient::OpenGL;
1274 1291
1275sub new { 1292sub new {
1276 my ($class, %arg) = @_; 1293 my ($class, %arg) = @_;
1277 1294
1278 my $self = $class->SUPER::new ( 1295 my $self = $class->SUPER::new (
1279 fg => [1, 1, 1], 1296 fg => [1, 1, 1],
1297 #bg => none
1298 #active_bg => none
1280 #font => default_font 1299 #font => default_font
1281 #text => initial text 1300 #text => initial text
1282 #markup => initial narkup 1301 #markup => initial narkup
1283 layout => (new CFClient::Layout), 1302 layout => (new CFClient::Layout),
1284 fontsize => 1, 1303 fontsize => 1,
1302 } 1321 }
1303 1322
1304 $self 1323 $self
1305} 1324}
1306 1325
1307sub escape { 1326sub escape($) {
1308 local $_ = $_[1]; 1327 local $_ = $_[0];
1309 1328
1310 s/&/&amp;/g; 1329 s/&/&amp;/g;
1311 s/>/&gt;/g; 1330 s/>/&gt;/g;
1312 s/</&lt;/g; 1331 s/</&lt;/g;
1313 1332
1314 $_[1] 1333 $_
1315} 1334}
1316 1335
1317sub update { 1336sub update {
1318 my ($self) = @_; 1337 my ($self) = @_;
1319 1338
1390 $self->check_size; 1409 $self->check_size;
1391} 1410}
1392 1411
1393sub _draw { 1412sub _draw {
1394 my ($self) = @_; 1413 my ($self) = @_;
1414
1415 $self->SUPER::_draw; # draw background, if applicable
1395 1416
1396 my $tex = $self->{texture} ||= do { 1417 my $tex = $self->{texture} ||= do {
1397 $self->{layout}->set_foreground (@{$self->{fg}}); 1418 $self->{layout}->set_foreground (@{$self->{fg}});
1398 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1419 $self->{layout}->set_font ($self->{font}) if $self->{font};
1399 $self->{layout}->set_width ($self->{w}); 1420 $self->{layout}->set_width ($self->{w});
1400 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); 1421 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE);
1401 1422
1402 my $tex = new_from_layout CFClient::Texture $self->{layout}; 1423 my $tex = new_from_layout CFClient::Texture $self->{layout};
1403 1424
1404 $self->{ox} = int $self->{align} < 0 ? $self->{padding} 1425 $self->{ox} = int ($self->{align} < 0 ? $self->{padding}
1405 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 1426 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
1406 : ($self->{w} - $tex->{w}) * 0.5; 1427 : ($self->{w} - $tex->{w}) * 0.5);
1407 1428
1408 $self->{oy} = int $self->{valign} < 0 ? $self->{padding} 1429 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding}
1409 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} 1430 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding}
1410 : ($self->{h} - $tex->{h}) * 0.5; 1431 : ($self->{h} - $tex->{h}) * 0.5);
1411 1432
1412 $tex 1433 $tex
1413 }; 1434 };
1414 1435
1415 glEnable GL_TEXTURE_2D; 1436 glEnable GL_TEXTURE_2D;
1470sub set_text { 1491sub set_text {
1471 my ($self, $text) = @_; 1492 my ($self, $text) = @_;
1472 1493
1473 $self->{cursor} = length $text; 1494 $self->{cursor} = length $text;
1474 $self->_set_text ($text); 1495 $self->_set_text ($text);
1496 $self->update;
1475 $self->check_size; 1497 $self->check_size;
1476 $self->update;
1477} 1498}
1478 1499
1479sub get_text { 1500sub get_text {
1480 $_[0]{text} 1501 $_[0]{text}
1481} 1502}
1521 substr $text, $self->{cursor}++, 0, chr $uni; 1542 substr $text, $self->{cursor}++, 0, chr $uni;
1522 } 1543 }
1523 1544
1524 $self->_set_text ($text); 1545 $self->_set_text ($text);
1525 $self->update; 1546 $self->update;
1547 $self->check_size;
1526} 1548}
1527 1549
1528sub focus_in { 1550sub focus_in {
1529 my ($self) = @_; 1551 my ($self) = @_;
1530 1552
1659 my $class = shift; 1681 my $class = shift;
1660 1682
1661 $class->SUPER::new ( 1683 $class->SUPER::new (
1662 padding => 4, 1684 padding => 4,
1663 fg => [1, 1, 1], 1685 fg => [1, 1, 1],
1664 bg => [1, 1, 1, 0.2],
1665 active_fg => [0, 0, 1], 1686 active_fg => [0, 0, 1],
1666 can_hover => 1, 1687 can_hover => 1,
1667 align => 0, 1688 align => 0,
1668 valign => 0, 1689 valign => 0,
1669 can_events => 1, 1690 can_events => 1,
1717 1738
1718 $class->SUPER::new ( 1739 $class->SUPER::new (
1719 padding => 2, 1740 padding => 2,
1720 fg => [1, 1, 1], 1741 fg => [1, 1, 1],
1721 active_fg => [1, 1, 0], 1742 active_fg => [1, 1, 0],
1743 bg => [0, 0, 0, 0.2],
1744 active_bg => [1, 1, 1, 0.5],
1722 state => 0, 1745 state => 0,
1723 can_hover => 1, 1746 can_hover => 1,
1724 @_ 1747 @_
1725 ) 1748 )
1726} 1749}
2018 # TODO: req_w/h are wrong with vertical 2041 # TODO: req_w/h are wrong with vertical
2019 # TODO: calculations are off 2042 # TODO: calculations are off
2020 my $self = $class->SUPER::new ( 2043 my $self = $class->SUPER::new (
2021 fg => [1, 1, 1], 2044 fg => [1, 1, 1],
2022 active_fg => [0, 0, 0], 2045 active_fg => [0, 0, 0],
2046 bg => [0, 0, 0, 0.2],
2047 active_bg => [1, 1, 1, 0.5],
2023 range => [0, 0, 100, 10], 2048 range => [0, 0, 100, 10],
2024 req_w => $::WIDTH / 80, 2049 req_w => $::WIDTH / 80,
2025 req_h => $::WIDTH / 80, 2050 req_h => $::WIDTH / 80,
2026 vertical => 0, 2051 vertical => 0,
2027 can_hover => 1, 2052 can_hover => 1,
2522 and $desc .= " *"; 2547 and $desc .= " *";
2523 2548
2524 my $self = $class->SUPER::new ( 2549 my $self = $class->SUPER::new (
2525 can_hover => 1, 2550 can_hover => 1,
2526 can_events => 1, 2551 can_events => 1,
2527 tooltip => (CFClient::UI::Label->escape ($desc) 2552 tooltip => ((CFClient::UI::Label::escape $desc)
2528 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), 2553 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"),
2529 connect_button_down => sub { 2554 connect_button_down => sub {
2530 my ($self, $ev, $x, $y) = @_; 2555 my ($self, $ev, $x, $y) = @_;
2531 2556
2532 # todo: maybe put examine on 1? but should just be a tooltip :( 2557 # todo: maybe put examine on 1? but should just be a tooltip :(

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines