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.272 by root, Sat Jun 3 01:47:14 2006 UTC vs.
Revision 1.278 by root, Sun Jun 4 23:05:06 2006 UTC

548 return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w) 548 return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w)
549 || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h); 549 || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h);
550 550
551 glPushMatrix; 551 glPushMatrix;
552 glTranslate $self->{x}, $self->{y}, 0; 552 glTranslate $self->{x}, $self->{y}, 0;
553 $self->_draw;
554 glPopMatrix;
555 553
556 if ($self == $HOVER && $self->{can_hover}) { 554 if ($self == $HOVER && $self->{can_hover}) {
557 my ($x, $y) = @$self{qw(x y)};
558
559 glColor 1, 0.8, 0.5, 0.2; 555 glColor 1*0.2, 0.8*0.2, 0.5*0.2, 0.2;
560 glEnable GL_BLEND; 556 glEnable GL_BLEND;
561 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 557 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
562 glBegin GL_QUADS; 558 glBegin GL_QUADS;
563 glVertex $x , $y; 559 glVertex 0 , 0;
564 glVertex $x + $self->{w}, $y; 560 glVertex $self->{w}, 0;
565 glVertex $x + $self->{w}, $y + $self->{h}; 561 glVertex $self->{w}, $self->{h};
566 glVertex $x , $y + $self->{h}; 562 glVertex 0 , $self->{h};
567 glEnd; 563 glEnd;
568 glDisable GL_BLEND; 564 glDisable GL_BLEND;
569 } 565 }
570 566
571 if ($ENV{CFPLUS_DEBUG} & 1) { 567 if ($ENV{CFPLUS_DEBUG} & 1) {
572 glPushMatrix; 568 glPushMatrix;
573 glColor 1, 1, 0, 1; 569 glColor 1, 1, 0, 1;
574 glTranslate $self->{x} + 0.375, $self->{y} + 0.375; 570 glTranslate 0.375, 0.375;
575 glBegin GL_LINE_LOOP; 571 glBegin GL_LINE_LOOP;
576 glVertex 0 , 0; 572 glVertex 0 , 0;
577 glVertex $self->{w} - 1, 0; 573 glVertex $self->{w} - 1, 0;
578 glVertex $self->{w} - 1, $self->{h} - 1; 574 glVertex $self->{w} - 1, $self->{h} - 1;
579 glVertex 0 , $self->{h} - 1; 575 glVertex 0 , $self->{h} - 1;
580 glEnd; 576 glEnd;
581 glPopMatrix; 577 glPopMatrix;
582 #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; 578 #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw;
583 } 579 }
580
581 $self->_draw;
582 glPopMatrix;
584} 583}
585 584
586sub _draw { 585sub _draw {
587 my ($self) = @_; 586 my ($self) = @_;
588 587
626 625
627 if ($color && (@$color < 4 || $color->[3])) { 626 if ($color && (@$color < 4 || $color->[3])) {
628 my ($w, $h) = @$self{qw(w h)}; 627 my ($w, $h) = @$self{qw(w h)};
629 628
630 glEnable GL_BLEND; 629 glEnable GL_BLEND;
631 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 630 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
632 glColor @$color; 631 glColor_premultiply @$color;
633 632
634 glBegin GL_QUADS; 633 glBegin GL_QUADS;
635 glVertex 0 , 0; 634 glVertex 0 , 0;
636 glVertex 0 , $h; 635 glVertex 0 , $h;
637 glVertex $w, $h; 636 glVertex $w, $h;
794 $self->{children}[0]->configure (0, 0, $w, $h); 793 $self->{children}[0]->configure (0, 0, $w, $h);
795} 794}
796 795
797############################################################################# 796#############################################################################
798 797
798# back-buffered drawing area
799
799package CFClient::UI::Window; 800package CFClient::UI::Window;
800 801
801our @ISA = CFClient::UI::Bin::; 802our @ISA = CFClient::UI::Bin::;
802 803
803use CFClient::OpenGL; 804use CFClient::OpenGL;
854 my $tex = $self->{texture} 855 my $tex = $self->{texture}
855 or return; 856 or return;
856 857
857 glEnable GL_TEXTURE_2D; 858 glEnable GL_TEXTURE_2D;
858 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 859 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
860 glEnable GL_BLEND;
861 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
859 glColor 1, 1, 1, 1; 862 glColor 0, 0, 0, 1;
860 863
861 $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); 864 $tex->draw_quad (0, 0, $w, $h);
862 865
866 glDisable GL_BLEND;
863 glDisable GL_TEXTURE_2D; 867 glDisable GL_TEXTURE_2D;
864} 868}
865 869
866############################################################################# 870#############################################################################
867 871
955package CFClient::UI::ScrolledWindow; 959package CFClient::UI::ScrolledWindow;
956 960
957our @ISA = CFClient::UI::HBox::; 961our @ISA = CFClient::UI::HBox::;
958 962
959sub new { 963sub new {
960 my $class = shift; 964 my ($class, %arg) = @_;
965
966 my $child = delete $arg{child};
961 967
962 my $self; 968 my $self;
963 969
964 my $slider = new CFClient::UI::Slider 970 my $slider = new CFClient::UI::Slider
965 vertical => 1, 971 vertical => 1,
970 ; 976 ;
971 977
972 $self = $class->SUPER::new ( 978 $self = $class->SUPER::new (
973 vp => (new CFClient::UI::ViewPort expand => 1), 979 vp => (new CFClient::UI::ViewPort expand => 1),
974 slider => $slider, 980 slider => $slider,
975 @_, 981 %arg,
976 ); 982 );
977 983
978 $self->{vp}->add ($self->{scrolled});
979 $self->add ($self->{vp});
980 $self->add ($self->{slider}); 984 $self->SUPER::add ($self->{vp}, $self->{slider});
985 $self->add ($child) if $child;
981 986
982 $self 987 $self
988}
989
990sub add {
991 my ($self, $widget) = @_;
992
993 $self->{vp}->add ($self->{child} = $widget);
983} 994}
984 995
985sub update { 996sub update {
986 my ($self) = @_; 997 my ($self) = @_;
987 998
1026 1037
1027 if ($self->{bg}) { 1038 if ($self->{bg}) {
1028 my ($w, $h) = @$self{qw(w h)}; 1039 my ($w, $h) = @$self{qw(w h)};
1029 1040
1030 glEnable GL_BLEND; 1041 glEnable GL_BLEND;
1031 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1042 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
1032 glColor @{ $self->{bg} }; 1043 glColor_premultiply @{ $self->{bg} };
1033 1044
1034 glBegin GL_QUADS; 1045 glBegin GL_QUADS;
1035 glVertex 0 , 0; 1046 glVertex 0 , 0;
1036 glVertex 0 , $h; 1047 glVertex 0 , $h;
1037 glVertex $w, $h; 1048 glVertex $w, $h;
1151 my $dy = $ev->{y} - $oy; 1162 my $dy = $ev->{y} - $oy;
1152 1163
1153 $self->{force_w} = $bw + $dx * ($mx ? -1 : 1); 1164 $self->{force_w} = $bw + $dx * ($mx ? -1 : 1);
1154 $self->{force_h} = $bh + $dy * ($my ? -1 : 1); 1165 $self->{force_h} = $bh + $dy * ($my ? -1 : 1);
1155 1166
1167 $self->move_abs ($wx + $dx * $mx, $wy + $dy * $my);
1156 $self->realloc; 1168 $self->realloc;
1157 $self->move_abs ($wx + $dx * $mx, $wy + $dy * $my);
1158 }; 1169 };
1159 1170
1160 } elsif ($lr ^ $td) { 1171 } elsif ($lr ^ $td) {
1161 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 1172 my ($ox, $oy) = ($ev->{x}, $ev->{y});
1162 my ($bx, $by) = ($self->{x}, $self->{y}); 1173 my ($bx, $by) = ($self->{x}, $self->{y});
1165 my ($ev, $x, $y) = @_; 1176 my ($ev, $x, $y) = @_;
1166 1177
1167 ($x, $y) = ($ev->{x}, $ev->{y}); 1178 ($x, $y) = ($ev->{x}, $ev->{y});
1168 1179
1169 $self->move_abs ($bx + $x - $ox, $by + $y - $oy); 1180 $self->move_abs ($bx + $x - $ox, $by + $y - $oy);
1181 # HACK: the next line is required to enforce placement
1182 $self->{parent}->size_allocate ($self->{parent}{w}, $self->{parent}{h});
1170 }; 1183 };
1171 } else { 1184 } else {
1172 return 0; 1185 return 0;
1173 } 1186 }
1174 1187
1667 1680
1668 delete $self->{cur_h}; 1681 delete $self->{cur_h};
1669 1682
1670 return if $self->{text} eq $text; 1683 return if $self->{text} eq $text;
1671 1684
1672 delete $self->{texture};
1673
1674 $self->{last_activity} = $::NOW; 1685 $self->{last_activity} = $::NOW;
1675 $self->{text} = $text; 1686 $self->{text} = $text;
1676 1687
1677 $text =~ s/./*/g if $self->{hidden}; 1688 $text =~ s/./*/g if $self->{hidden};
1678 $self->{layout}->set_text ("$text "); 1689 $self->{layout}->set_text ("$text ");
1679 1690
1680 $self->_emit (changed => $self->{text}); 1691 $self->_emit (changed => $self->{text});
1692 $self->update;
1681} 1693}
1682 1694
1683sub set_text { 1695sub set_text {
1684 my ($self, $text) = @_; 1696 my ($self, $text) = @_;
1685 1697
1774 my ($self) = @_; 1786 my ($self) = @_;
1775 1787
1776 local $self->{fg} = $self->{fg}; 1788 local $self->{fg} = $self->{fg};
1777 1789
1778 if ($FOCUS == $self) { 1790 if ($FOCUS == $self) {
1779 glColor @{$self->{active_bg}}; 1791 glColor_premultiply @{$self->{active_bg}};
1780 $self->{fg} = $self->{active_fg}; 1792 $self->{fg} = $self->{active_fg};
1781 } else { 1793 } else {
1782 glColor @{$self->{bg}}; 1794 glColor_premultiply @{$self->{bg}};
1783 } 1795 }
1784 1796
1785 glEnable GL_BLEND; 1797 glEnable GL_BLEND;
1786 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1798 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
1787 glBegin GL_QUADS; 1799 glBegin GL_QUADS;
1788 glVertex 0 , 0; 1800 glVertex 0 , 0;
1789 glVertex 0 , $self->{h}; 1801 glVertex 0 , $self->{h};
1790 glVertex $self->{w}, $self->{h}; 1802 glVertex $self->{w}, $self->{h};
1791 glVertex $self->{w}, 0; 1803 glVertex $self->{w}, 0;
2140 2152
2141 my $h1 = $self->{h} * (1 - $ycut1); 2153 my $h1 = $self->{h} * (1 - $ycut1);
2142 my $h2 = $self->{h} * (1 - $ycut2); 2154 my $h2 = $self->{h} * (1 - $ycut2);
2143 2155
2144 glEnable GL_BLEND; 2156 glEnable GL_BLEND;
2145 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 2157 glBlendFuncSeparate GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
2158 GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2146 glEnable GL_TEXTURE_2D; 2159 glEnable GL_TEXTURE_2D;
2147 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2160 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2148 2161
2149 glBindTexture GL_TEXTURE_2D, $t1->{name}; 2162 glBindTexture GL_TEXTURE_2D, $t1->{name};
2150 glBegin GL_QUADS; 2163 glBegin GL_QUADS;
2335} 2348}
2336 2349
2337sub update { 2350sub update {
2338 my ($self) = @_; 2351 my ($self) = @_;
2339 2352
2340 $CFClient::UI::ROOT->on_post_alloc ($self => sub { 2353 delete $self->{knob_w};
2354 $self->SUPER::update;
2355}
2356
2357sub _draw {
2358 my ($self) = @_;
2359
2360 unless ($self->{knob_w}) {
2341 $self->set_value ($self->{range}[0]); 2361 $self->set_value ($self->{range}[0]);
2342 2362
2343 my ($value, $lo, $hi, $page) = @{$self->{range}}; 2363 my ($value, $lo, $hi, $page) = @{$self->{range}};
2344 my $range = ($hi - $page - $lo) || 1e-100; 2364 my $range = ($hi - $page - $lo) || 1e-100;
2345 2365
2351 $value = ($value - $lo) / $range; 2371 $value = ($value - $lo) / $range;
2352 $value = $value * $self->{scale} + $self->{offset}; 2372 $value = $value * $self->{scale} + $self->{offset};
2353 2373
2354 $self->{knob_x} = $value - $knob_w * 0.5; 2374 $self->{knob_x} = $value - $knob_w * 0.5;
2355 $self->{knob_w} = $knob_w; 2375 $self->{knob_w} = $knob_w;
2356 }); 2376 }
2357
2358 $self->SUPER::update;
2359}
2360
2361sub _draw {
2362 my ($self) = @_;
2363 2377
2364 $self->SUPER::_draw (); 2378 $self->SUPER::_draw ();
2365 2379
2366 glScale $self->{w}, $self->{h}; 2380 glScale $self->{w}, $self->{h};
2367 2381
3022 my $class = shift; 3036 my $class = shift;
3023 3037
3024 my $self = $class->SUPER::new ( 3038 my $self = $class->SUPER::new (
3025 buttonbar => (new CFClient::UI::Buttonbar), 3039 buttonbar => (new CFClient::UI::Buttonbar),
3026 multiplexer => (new CFClient::UI::Multiplexer expand => 1), 3040 multiplexer => (new CFClient::UI::Multiplexer expand => 1),
3041 # filter => # will be put between multiplexer and $self
3027 @_, 3042 @_,
3028 ); 3043 );
3029 3044
3045 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
3030 $self->SUPER::add ($self->{buttonbar}, $self->{multiplexer}); 3046 $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer});
3031 3047
3032 $self 3048 $self
3033} 3049}
3034 3050
3035sub add { 3051sub add {
3171 3187
3172sub new { 3188sub new {
3173 my $class = shift; 3189 my $class = shift;
3174 3190
3175 my $self = $class->SUPER::new ( 3191 my $self = $class->SUPER::new (
3176 scrolled => (new CFClient::UI::Table col_expand => [0, 1, 0]), 3192 child => (new CFClient::UI::Table col_expand => [0, 1, 0]),
3177 @_, 3193 @_,
3178 ); 3194 );
3179 3195
3180 $self 3196 $self
3181} 3197}
3182 3198
3183sub set_items { 3199sub set_items {
3184 my ($self, $items) = @_; 3200 my ($self, $items) = @_;
3185 3201
3186 $self->{scrolled}->clear; 3202 $self->{child}->clear;
3187 return unless $items; 3203 return unless $items;
3188 3204
3189 my @items = sort { 3205 my @items = sort {
3190 ($a->{type} <=> $b->{type}) 3206 ($a->{type} <=> $b->{type})
3191 or ($a->{name} cmp $b->{name}) 3207 or ($a->{name} cmp $b->{name})
3195 3211
3196 my $row = 0; 3212 my $row = 0;
3197 for my $item (@items) { 3213 for my $item (@items) {
3198 CFClient::Item::update_widgets $item; 3214 CFClient::Item::update_widgets $item;
3199 3215
3200 $self->{scrolled}->add (0, $row, $item->{face_widget}); 3216 $self->{child}->add (0, $row, $item->{face_widget});
3201 $self->{scrolled}->add (1, $row, $item->{desc_widget}); 3217 $self->{child}->add (1, $row, $item->{desc_widget});
3202 $self->{scrolled}->add (2, $row, $item->{weight_widget}); 3218 $self->{child}->add (2, $row, $item->{weight_widget});
3203 3219
3204 $row++; 3220 $row++;
3205 } 3221 }
3206} 3222}
3207 3223
3404 3420
3405############################################################################# 3421#############################################################################
3406 3422
3407package CFClient::UI::SpellList; 3423package CFClient::UI::SpellList;
3408 3424
3409our @ISA = CFClient::UI::ScrolledWindow::; 3425our @ISA = CFClient::UI::Table::;
3410 3426
3411sub new { 3427sub new {
3412 my $class = shift; 3428 my $class = shift;
3413 3429
3414 my $self = $class->SUPER::new ( 3430 my $self = $class->SUPER::new (
3415 binding => [], 3431 binding => [],
3416 commands => [], 3432 commands => [],
3417 scrolled => (new CFClient::UI::Table),
3418 @_, 3433 @_,
3419 ) 3434 )
3420} 3435}
3421 3436
3422# XXX: Do sorting? Argl... 3437# XXX: Do sorting? Argl...
3423sub add_spell { 3438sub add_spell {
3424 my ($self, $spell) = @_; 3439 my ($self, $spell) = @_;
3425 $self->{spells}->{$spell->{name}} = $spell; 3440 $self->{spells}->{$spell->{name}} = $spell;
3426 3441
3427 $self->{scrolled}->add (0, $self->{tbl_idx}, new CFClient::UI::Face 3442 $self->add (0, $self->{tbl_idx}, new CFClient::UI::Face
3428 face => $spell->{face}, 3443 face => $spell->{face},
3429 can_hover => 1, 3444 can_hover => 1,
3430 can_events => 1, 3445 can_events => 1,
3431 tooltip => $spell->{message}); 3446 tooltip => $spell->{message});
3432 3447
3433 $self->{scrolled}->add (1, $self->{tbl_idx}, new CFClient::UI::Label 3448 $self->add (1, $self->{tbl_idx}, new CFClient::UI::Label
3434 text => $spell->{name}, 3449 text => $spell->{name},
3435 can_hover => 1, 3450 can_hover => 1,
3436 can_events => 1, 3451 can_events => 1,
3437 tooltip => $spell->{message}, 3452 tooltip => $spell->{message},
3438 expand => 1); 3453 expand => 1);
3439 3454
3440 $self->{scrolled}->add (2, $self->{tbl_idx}, new CFClient::UI::Label 3455 $self->add (2, $self->{tbl_idx}, new CFClient::UI::Label
3441 text => (sprintf "lvl: %2d sp: %2d dmg: %2d", 3456 text => (sprintf "lvl: %2d sp: %2d dmg: %2d",
3442 $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), 3457 $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}),
3443 expand => 1); 3458 expand => 1);
3444 3459
3445 $self->{scrolled}->add (3, $self->{tbl_idx}++, new CFClient::UI::Button 3460 $self->add (3, $self->{tbl_idx}++, new CFClient::UI::Button
3446 text => "bind to key", 3461 text => "bind to key",
3447 on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); 3462 on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) });
3448} 3463}
3449 3464
3450sub rebuild_spell_list { 3465sub rebuild_spell_list {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines