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.146 by elmex, Fri Apr 21 15:03:46 2006 UTC vs.
Revision 1.148 by elmex, Sat Apr 22 12:14:45 2006 UTC

140 0 140 0
141} 141}
142 142
143sub size_request { 143sub size_request {
144 require Carp; 144 require Carp;
145 Carp::confess "size_request is abtract"; 145 Carp::confess "size_request is abstract";
146} 146}
147 147
148sub configure { 148sub configure {
149 my ($self, $x, $y, $w, $h) = @_; 149 my ($self, $x, $y, $w, $h) = @_;
150 150
152 my $w2 = List::Util::min $w, int $h * $self->{aspect}; 152 my $w2 = List::Util::min $w, int $h * $self->{aspect};
153 my $h2 = List::Util::min $h, int $w / $self->{aspect}; 153 my $h2 = List::Util::min $h, int $w / $self->{aspect};
154 154
155 # use alignment to adjust x, y 155 # use alignment to adjust x, y
156 156
157 $x += ($w - $w2) * 0.5; 157 $x += int +($w - $w2) * 0.5;
158 $y += ($h - $h2) * 0.5; 158 $y += int +($h - $h2) * 0.5;
159 159
160 ($w, $h) = ($w2, $h2); 160 ($w, $h) = ($w2, $h2);
161 } 161 }
162 162
163 if ($self->{x} != $x || $self->{y} != $y) { 163 if ($self->{x} != $x || $self->{y} != $y) {
582 582
583our @ISA = CFClient::UI::Bin::; 583our @ISA = CFClient::UI::Bin::;
584 584
585use CFClient::OpenGL; 585use CFClient::OpenGL;
586 586
587sub new {
588 my $class = shift;
589
590 my $self = $class->SUPER::new (
591 bg => [1, 1, 1, 1],
592 border_bg => [1, 1, 1, 1],
593 border => 0.8,
594 @_
595 );
596
597 $self
598}
599
600sub set_size {
601 my ($self, $w, $h) = @_;
602 $self->{req_w} = $w;
603 $self->{req_h} = $h;
604 $self->check_size;
605}
606
587sub size_request { 607sub size_request {
588 my ($self) = @_; 608 my ($self) = @_;
589 my $chld = $self->child 609 ($self->{req_w}, $self->{req_h})
590 or return (0, 0);
591
592 $chld->move (2, 2);
593
594 map { $_ + 4 } $chld->size_request;
595} 610}
596 611
597sub size_allocate { 612sub size_allocate {
598 my ($self, $x, $y, $w, $h) = @_; 613 my ($self, $w, $h) = @_;
599 614 $self->{w} = $w;
615 $self->{h} = $h;
600 $self->child->configure (2, 2, $w - 4, $h - 4); 616 $self->child->configure (0, 0, $w, $h);
601} 617}
602 618
603sub _draw { 619sub _draw {
604 my ($self) = @_; 620 my ($self) = @_;
605 621
606 my $chld = $self->child; 622 my ($w, $h) = ($self->{w}, $self->{h});
607 623
608 my ($w, $h) = $chld->size_request; 624 glEnable GL_BLEND;
625 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
626 glEnable GL_TEXTURE_2D;
627 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
609 628
610 glBegin GL_QUADS; 629# glBegin GL_QUADS;
611 glColor 0, 0, 0; 630# glColor 0, 0, 0, 0;
612 glVertex 0 , 0; 631# glVertex 0 , 0;
613 glVertex 0 , $h + 4; 632# glVertex 0 , $h;
614 glVertex $w + 4 , $h + 4; 633# glVertex $w, $h;
615 glVertex $w + 4 , 0; 634# glVertex $w, 0;
616 glEnd; 635# glEnd;
617 636
637
618 $chld->draw; 638 $self->child->draw;
639 glDisable GL_BLEND;
640 glDisable GL_TEXTURE_2D;
619} 641}
620 642
621############################################################################# 643#############################################################################
622 644
623package CFClient::UI::FancyFrame; 645package CFClient::UI::FancyFrame;
1115 1137
1116sub set_fontsize { 1138sub set_fontsize {
1117 my ($self, $fontsize) = @_; 1139 my ($self, $fontsize) = @_;
1118 1140
1119 $self->{fontsize} = $fontsize; 1141 $self->{fontsize} = $fontsize;
1120 $self->update; 1142 $self->check_size;
1121} 1143}
1122 1144
1123sub _draw { 1145sub _draw {
1124 my ($self) = @_; 1146 my ($self) = @_;
1125 1147
1487 1509
1488 $loaded_images{$self->{image}} ||= 1510 $loaded_images{$self->{image}} ||=
1489 new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1; 1511 new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1;
1490 1512
1491 my $tex = $self->{tex} = $loaded_images{$self->{image}}; 1513 my $tex = $self->{tex} = $loaded_images{$self->{image}};
1514
1515 Scalar::Util::weaken $loaded_images{$self->{image}};
1492 1516
1493 $self->{aspect} = $tex->{w} / $tex->{h}; 1517 $self->{aspect} = $tex->{w} / $tex->{h};
1494 1518
1495 $self 1519 $self
1496} 1520}
1664sub set_fontsize { 1688sub set_fontsize {
1665 my ($self, $fsize) = @_; 1689 my ($self, $fsize) = @_;
1666 1690
1667 $self->{value}->set_fontsize ($fsize); 1691 $self->{value}->set_fontsize ($fsize);
1668 $self->{max} ->set_fontsize ($fsize); 1692 $self->{max} ->set_fontsize ($fsize);
1669 $self->update;
1670} 1693}
1671 1694
1672sub set_value { 1695sub set_value {
1673 my ($self, $val, $max) = @_; 1696 my ($self, $val, $max) = @_;
1674 1697

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines