… | |
… | |
1381 | |
1381 | |
1382 | $tex->draw_quad (0, 0, $s, $s); |
1382 | $tex->draw_quad (0, 0, $s, $s); |
1383 | |
1383 | |
1384 | glDisable GL_TEXTURE_2D; |
1384 | glDisable GL_TEXTURE_2D; |
1385 | glDisable GL_BLEND; |
1385 | glDisable GL_BLEND; |
|
|
1386 | } |
|
|
1387 | |
|
|
1388 | ############################################################################# |
|
|
1389 | |
|
|
1390 | package CFClient::UI::VGauge; |
|
|
1391 | |
|
|
1392 | our @ISA = CFClient::UI::Base::; |
|
|
1393 | |
|
|
1394 | use SDL::OpenGL; |
|
|
1395 | |
|
|
1396 | my %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 |
|
|
1416 | sub new { |
|
|
1417 | my $class = shift; |
|
|
1418 | |
|
|
1419 | my $self = $class->SUPER::new (gauge => 'food', @_); |
|
|
1420 | |
|
|
1421 | $self |
|
|
1422 | } |
|
|
1423 | |
|
|
1424 | sub size_request { |
|
|
1425 | my ($self) = @_; |
|
|
1426 | |
|
|
1427 | ($self->{w}, $self->{h}) |
|
|
1428 | } |
|
|
1429 | |
|
|
1430 | sub set_max { |
|
|
1431 | my ($self, $max) = @_; |
|
|
1432 | $self->{max_val} = $max; |
|
|
1433 | } |
|
|
1434 | |
|
|
1435 | sub 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 | |
|
|
1447 | sub _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; |
1386 | } |
1490 | } |
1387 | |
1491 | |
1388 | ############################################################################# |
1492 | ############################################################################# |
1389 | |
1493 | |
1390 | package CFClient::UI::Slider; |
1494 | package CFClient::UI::Slider; |