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.330 by root, Sun Jul 23 04:37:51 2006 UTC vs.
Revision 1.340 by root, Sun Jul 30 13:16:44 2006 UTC

1package CFClient::UI; 1package CFPlus::UI;
2 2
3use utf8; 3use utf8;
4use strict; 4use strict;
5 5
6use Scalar::Util (); 6use Scalar::Util ();
7use List::Util (); 7use List::Util ();
8use Event; 8use Event;
9 9
10use CFClient; 10use CFPlus;
11use CFClient::Texture; 11use CFPlus::Texture;
12 12
13our ($FOCUS, $HOVER, $GRAB); # various widgets 13our ($FOCUS, $HOVER, $GRAB); # various widgets
14 14
15our $LAYOUT; 15our $LAYOUT;
16our $ROOT; 16our $ROOT;
96 96
97sub feed_sdl_button_down_event { 97sub feed_sdl_button_down_event {
98 my ($ev) = @_; 98 my ($ev) = @_;
99 my ($x, $y) = ($ev->{x}, $ev->{y}); 99 my ($x, $y) = ($ev->{x}, $ev->{y});
100 100
101 unless ($BUTTON_STATE) { 101 $BUTTON_STATE |= 1 << ($ev->{button} - 1);
102
103 unless ($GRAB) {
102 my $widget = $ROOT->find_widget ($x, $y); 104 my $widget = $ROOT->find_widget ($x, $y);
103 105
104 $GRAB = $widget; 106 $GRAB = $widget;
105 $GRAB->update if $GRAB; 107 $GRAB->update if $GRAB;
106 108
107 $TOOLTIP_WATCHER->cb->(); 109 $TOOLTIP_WATCHER->cb->();
108 } 110 }
109
110 $BUTTON_STATE |= 1 << ($ev->{button} - 1);
111 111
112 if ($GRAB) { 112 if ($GRAB) {
113 if ($ev->{button} == 4 || $ev->{button} == 5) { 113 if ($ev->{button} == 4 || $ev->{button} == 5) {
114 # mousewheel 114 # mousewheel
115 $ev->{dx} = 0; 115 $ev->{dx} = 0;
207 reconfigure_widgets; 207 reconfigure_widgets;
208} 208}
209 209
210############################################################################# 210#############################################################################
211 211
212package CFClient::UI::Event; 212package CFPlus::UI::Event;
213 213
214sub xy { 214sub xy {
215 $_[1]->coord2local ($_[0]{x}, $_[0]{y}) 215 $_[1]->coord2local ($_[0]{x}, $_[0]{y})
216} 216}
217 217
218############################################################################# 218#############################################################################
219 219
220package CFClient::UI::Base; 220package CFPlus::UI::Base;
221 221
222use strict; 222use strict;
223 223
224use CFClient::OpenGL; 224use CFPlus::OpenGL;
225 225
226sub new { 226sub new {
227 my $class = shift; 227 my $class = shift;
228 228
229 my $self = bless { 229 my $self = bless {
234 h => undef, 234 h => undef,
235 can_events => 1, 235 can_events => 1,
236 @_ 236 @_
237 }, $class; 237 }, $class;
238 238
239 Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self); 239 Scalar::Util::weaken ($CFPlus::UI::WIDGET{$self+0} = $self);
240 240
241 for (keys %$self) { 241 for (keys %$self) {
242 if (/^on_(.*)$/) { 242 if (/^on_(.*)$/) {
243 $self->connect ($1 => delete $self->{$_}); 243 $self->connect ($1 => delete $self->{$_});
244 } 244 }
245 } 245 }
246 246
247 if (my $layout = $CFClient::UI::LAYOUT->{$self->{name}}) { 247 if (my $layout = $CFPlus::UI::LAYOUT->{$self->{name}}) {
248 $self->{x} = $layout->{x} * $CFClient::UI::ROOT->{alloc_w} if exists $layout->{x}; 248 $self->{x} = $layout->{x} * $CFPlus::UI::ROOT->{alloc_w} if exists $layout->{x};
249 $self->{y} = $layout->{y} * $CFClient::UI::ROOT->{alloc_h} if exists $layout->{y}; 249 $self->{y} = $layout->{y} * $CFPlus::UI::ROOT->{alloc_h} if exists $layout->{y};
250 $self->{force_w} = $layout->{w} * $CFClient::UI::ROOT->{alloc_w} if exists $layout->{w}; 250 $self->{force_w} = $layout->{w} * $CFPlus::UI::ROOT->{alloc_w} if exists $layout->{w};
251 $self->{force_h} = $layout->{h} * $CFClient::UI::ROOT->{alloc_h} if exists $layout->{h}; 251 $self->{force_h} = $layout->{h} * $CFPlus::UI::ROOT->{alloc_h} if exists $layout->{h};
252 252
253 $self->{x} -= $self->{force_w} * 0.5 if exists $layout->{x}; 253 $self->{x} -= $self->{force_w} * 0.5 if exists $layout->{x};
254 $self->{y} -= $self->{force_h} * 0.5 if exists $layout->{y}; 254 $self->{y} -= $self->{force_h} * 0.5 if exists $layout->{y};
255 255
256 $self->show if $layout->{show}; 256 $self->show if $layout->{show};
269sub show { 269sub show {
270 my ($self) = @_; 270 my ($self) = @_;
271 271
272 return if $self->{parent}; 272 return if $self->{parent};
273 273
274 $CFClient::UI::ROOT->add ($self); 274 $CFPlus::UI::ROOT->add ($self);
275} 275}
276 276
277sub set_visible { 277sub set_visible {
278 my ($self) = @_; 278 my ($self) = @_;
279 279
300 delete $self->{root}; 300 delete $self->{root};
301 301
302 undef $GRAB if $GRAB == $self; 302 undef $GRAB if $GRAB == $self;
303 undef $HOVER if $HOVER == $self; 303 undef $HOVER if $HOVER == $self;
304 304
305 $CFClient::UI::TOOLTIP_WATCHER->cb->() 305 $CFPlus::UI::TOOLTIP_WATCHER->cb->()
306 if $TOOLTIP->{owner} == $self; 306 if $TOOLTIP->{owner} == $self;
307 307
308 $self->emit ("focus_out"); 308 $self->emit ("focus_out");
309 $self->emit (visibility_change => 0); 309 $self->emit (visibility_change => 0);
310} 310}
367 my ($self, $x, $y, $w, $h) = @_; 367 my ($self, $x, $y, $w, $h) = @_;
368 368
369 if ($self->{aspect}) { 369 if ($self->{aspect}) {
370 my ($ow, $oh) = ($w, $h); 370 my ($ow, $oh) = ($w, $h);
371 371
372 $w = List::Util::min $w, int $h * $self->{aspect}; 372 $w = List::Util::min $w, CFPlus::ceil $h * $self->{aspect};
373 $h = List::Util::min $h, int $w / $self->{aspect}; 373 $h = List::Util::min $h, CFPlus::ceil $w / $self->{aspect};
374 374
375 # use alignment to adjust x, y 375 # use alignment to adjust x, y
376 376
377 $x += int 0.5 * ($ow - $w); 377 $x += int 0.5 * ($ow - $w);
378 $y += int 0.5 * ($oh - $h); 378 $y += int 0.5 * ($oh - $h);
419 419
420 return if $self->{tooltip} eq $tooltip; 420 return if $self->{tooltip} eq $tooltip;
421 421
422 $self->{tooltip} = $tooltip; 422 $self->{tooltip} = $tooltip;
423 423
424 if ($CFClient::UI::TOOLTIP->{owner} == $self) { 424 if ($CFPlus::UI::TOOLTIP->{owner} == $self) {
425 delete $CFClient::UI::TOOLTIP->{owner}; 425 delete $CFPlus::UI::TOOLTIP->{owner};
426 $CFClient::UI::TOOLTIP_WATCHER->cb->(); 426 $CFPlus::UI::TOOLTIP_WATCHER->cb->();
427 } 427 }
428} 428}
429 429
430# translate global coordinates to local coordinate system 430# translate global coordinates to local coordinate system
431sub coord2local { 431sub coord2local {
432 my ($self, $x, $y) = @_; 432 my ($self, $x, $y) = @_;
433 433
434 Carp::confess unless $self->{parent};#d#
435
434 $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y}) 436 $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y})
435} 437}
436 438
437# translate local coordinates to global coordinate system 439# translate local coordinates to global coordinate system
438sub coord2global { 440sub coord2global {
439 my ($self, $x, $y) = @_; 441 my ($self, $x, $y) = @_;
442
443 Carp::confess unless $self->{parent};#d#
440 444
441 $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y}) 445 $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y})
442} 446}
443 447
444sub invoke_focus_in { 448sub invoke_focus_in {
492 496
493sub connect { 497sub connect {
494 my ($self, $signal, $cb) = @_; 498 my ($self, $signal, $cb) = @_;
495 499
496 push @{ $self->{signal_cb}{$signal} }, $cb; 500 push @{ $self->{signal_cb}{$signal} }, $cb;
501
502 defined wantarray and CFPlus::guard {
503 @{ $self->{signal_cb}{$signal} } = grep $_ != $cb,
504 @{ $self->{signal_cb}{$signal} };
505 }
497} 506}
507
508my %has_coords = (
509 button_down => 1,
510 button_up => 1,
511 mouse_motion => 1,
512 mouse_wheel => 1,
513);
498 514
499sub emit { 515sub emit {
500 my ($self, $signal, @args) = @_; 516 my ($self, $signal, @args) = @_;
501 517
518 # I do not really like this solution, but I dislike duplication
519 # and needlessly verbose code, too.
502 my @append 520 my @append
503 = ref $args[0] && $args[0]->isa ("CFClient::UI::Event") 521 = $has_coords{$signal}
504 ? $args[0]->xy ($self) 522 ? $args[0]->xy ($self)
505 : (); 523 : ();
506 524
507 #warn +(caller(1))[3] . "emit $signal on $self (parent $self->{parent})\n";#d# 525 #warn +(caller(1))[3] . "emit $signal on $self (parent $self->{parent})\n";#d#
508 526
601 glVertex $self->{w} - 1, 0; 619 glVertex $self->{w} - 1, 0;
602 glVertex $self->{w} - 1, $self->{h} - 1; 620 glVertex $self->{w} - 1, $self->{h} - 1;
603 glVertex 0 , $self->{h} - 1; 621 glVertex 0 , $self->{h} - 1;
604 glEnd; 622 glEnd;
605 glPopMatrix; 623 glPopMatrix;
606 #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; 624 #CFPlus::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw;
607 } 625 }
608 626
609 $self->_draw; 627 $self->_draw;
610 glPopMatrix; 628 glPopMatrix;
611} 629}
617} 635}
618 636
619sub DESTROY { 637sub DESTROY {
620 my ($self) = @_; 638 my ($self) = @_;
621 639
622 return if CFClient::in_destruct; 640 return if CFPlus::in_destruct;
623 641
624 delete $WIDGET{$self+0}; 642 delete $WIDGET{$self+0};
625 643
626 eval { $self->destroy }; 644 eval { $self->destroy };
627 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; 645 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/;
628} 646}
629 647
630############################################################################# 648#############################################################################
631 649
632package CFClient::UI::DrawBG; 650package CFPlus::UI::DrawBG;
633 651
634our @ISA = CFClient::UI::Base::; 652our @ISA = CFPlus::UI::Base::;
635 653
636use strict; 654use strict;
637use CFClient::OpenGL; 655use CFPlus::OpenGL;
638 656
639sub new { 657sub new {
640 my $class = shift; 658 my $class = shift;
641 659
642 # range [value, low, high, page] 660 # range [value, low, high, page]
673 } 691 }
674} 692}
675 693
676############################################################################# 694#############################################################################
677 695
678package CFClient::UI::Empty; 696package CFPlus::UI::Empty;
679 697
680our @ISA = CFClient::UI::Base::; 698our @ISA = CFPlus::UI::Base::;
681 699
682sub new { 700sub new {
683 my ($class, %arg) = @_; 701 my ($class, %arg) = @_;
684 $class->SUPER::new (can_events => 0, %arg); 702 $class->SUPER::new (can_events => 0, %arg);
685} 703}
692 710
693sub draw { } 711sub draw { }
694 712
695############################################################################# 713#############################################################################
696 714
697package CFClient::UI::Container; 715package CFPlus::UI::Container;
698 716
699our @ISA = CFClient::UI::Base::; 717our @ISA = CFPlus::UI::Base::;
700 718
701sub new { 719sub new {
702 my ($class, %arg) = @_; 720 my ($class, %arg) = @_;
703 721
704 my $children = delete $arg{children}; 722 my $children = delete $arg{children};
713 if $children; 731 if $children;
714 732
715 $self 733 $self
716} 734}
717 735
736sub realloc {
737 my ($self) = @_;
738
739 $self->{force_realloc} = 1;
740 $self->{force_size_alloc} = 1;
741 $self->SUPER::realloc;
742}
743
718sub add { 744sub add {
719 my ($self, @widgets) = @_; 745 my ($self, @widgets) = @_;
720 746
721 $_->set_parent ($self) 747 $_->set_parent ($self)
722 for @widgets; 748 for @widgets;
782 $_->draw for @{$self->{children}}; 808 $_->draw for @{$self->{children}};
783} 809}
784 810
785############################################################################# 811#############################################################################
786 812
787package CFClient::UI::Bin; 813package CFPlus::UI::Bin;
788 814
789our @ISA = CFClient::UI::Container::; 815our @ISA = CFPlus::UI::Container::;
790 816
791sub new { 817sub new {
792 my ($class, %arg) = @_; 818 my ($class, %arg) = @_;
793 819
794 my $child = (delete $arg{child}) || new CFClient::UI::Empty::; 820 my $child = (delete $arg{child}) || new CFPlus::UI::Empty::;
795 821
796 $class->SUPER::new (children => [$child], %arg) 822 $class->SUPER::new (children => [$child], %arg)
797} 823}
798 824
799sub add { 825sub add {
806sub remove { 832sub remove {
807 my ($self, $widget) = @_; 833 my ($self, $widget) = @_;
808 834
809 $self->SUPER::remove ($widget); 835 $self->SUPER::remove ($widget);
810 836
811 $self->{children} = [new CFClient::UI::Empty] 837 $self->{children} = [new CFPlus::UI::Empty]
812 unless @{$self->{children}}; 838 unless @{$self->{children}};
813} 839}
814 840
815sub child { $_[0]->{children}[0] } 841sub child { $_[0]->{children}[0] }
816 842
828 854
829############################################################################# 855#############################################################################
830 856
831# back-buffered drawing area 857# back-buffered drawing area
832 858
833package CFClient::UI::Window; 859package CFPlus::UI::Window;
834 860
835our @ISA = CFClient::UI::Bin::; 861our @ISA = CFPlus::UI::Bin::;
836 862
837use CFClient::OpenGL; 863use CFPlus::OpenGL;
838 864
839sub new { 865sub new {
840 my ($class, %arg) = @_; 866 my ($class, %arg) = @_;
841 867
842 my $self = $class->SUPER::new (%arg); 868 my $self = $class->SUPER::new (%arg);
864} 890}
865 891
866sub render_child { 892sub render_child {
867 my ($self) = @_; 893 my ($self) = @_;
868 894
869 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { 895 $self->{texture} = new_from_opengl CFPlus::Texture $self->{w}, $self->{h}, sub {
870 glClearColor 0, 0, 0, 0; 896 glClearColor 0, 0, 0, 0;
871 glClear GL_COLOR_BUFFER_BIT; 897 glClear GL_COLOR_BUFFER_BIT;
872 898
873 { 899 {
874 package CFClient::UI::Base; 900 package CFPlus::UI::Base;
875 901
876 ($draw_x, $draw_y, $draw_w, $draw_h) = 902 ($draw_x, $draw_y, $draw_w, $draw_h) =
877 (0, 0, $self->{w}, $self->{h}); 903 (0, 0, $self->{w}, $self->{h});
878 } 904 }
879 905
898 glDisable GL_TEXTURE_2D; 924 glDisable GL_TEXTURE_2D;
899} 925}
900 926
901############################################################################# 927#############################################################################
902 928
903package CFClient::UI::ViewPort; 929package CFPlus::UI::ViewPort;
904 930
905our @ISA = CFClient::UI::Window::; 931our @ISA = CFPlus::UI::Window::;
906 932
907sub new { 933sub new {
908 my $class = shift; 934 my $class = shift;
909 935
910 $class->SUPER::new ( 936 $class->SUPER::new (
970 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} 996 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w}
971 && $y >= $self->{y} && $y < $self->{y} + $self->{h} 997 && $y >= $self->{y} && $y < $self->{y} + $self->{h}
972 ) { 998 ) {
973 $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y}) 999 $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y})
974 } else { 1000 } else {
975 $self->CFClient::UI::Base::find_widget ($x, $y) 1001 $self->CFPlus::UI::Base::find_widget ($x, $y)
976 } 1002 }
977} 1003}
978 1004
979sub _render { 1005sub _render {
980 my ($self) = @_; 1006 my ($self) = @_;
981 1007
982 local $CFClient::UI::Base::draw_x = $CFClient::UI::Base::draw_x - $self->{view_x}; 1008 local $CFPlus::UI::Base::draw_x = $CFPlus::UI::Base::draw_x - $self->{view_x};
983 local $CFClient::UI::Base::draw_y = $CFClient::UI::Base::draw_y - $self->{view_y}; 1009 local $CFPlus::UI::Base::draw_y = $CFPlus::UI::Base::draw_y - $self->{view_y};
984 1010
985 CFClient::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; 1011 CFPlus::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y};
986 1012
987 $self->SUPER::_render; 1013 $self->SUPER::_render;
988} 1014}
989 1015
990############################################################################# 1016#############################################################################
991 1017
992package CFClient::UI::ScrolledWindow; 1018package CFPlus::UI::ScrolledWindow;
993 1019
994our @ISA = CFClient::UI::HBox::; 1020our @ISA = CFPlus::UI::HBox::;
995 1021
996sub new { 1022sub new {
997 my ($class, %arg) = @_; 1023 my ($class, %arg) = @_;
998 1024
999 my $child = delete $arg{child}; 1025 my $child = delete $arg{child};
1000 1026
1001 my $self; 1027 my $self;
1002 1028
1003 my $slider = new CFClient::UI::Slider 1029 my $slider = new CFPlus::UI::Slider
1004 vertical => 1, 1030 vertical => 1,
1005 range => [0, 0, 1, 0.01], # HACK fix 1031 range => [0, 0, 1, 0.01], # HACK fix
1006 on_changed => sub { 1032 on_changed => sub {
1007 $self->{vp}->set_offset (0, $_[1]); 1033 $self->{vp}->set_offset (0, $_[1]);
1008 }, 1034 },
1009 ; 1035 ;
1010 1036
1011 $self = $class->SUPER::new ( 1037 $self = $class->SUPER::new (
1012 vp => (new CFClient::UI::ViewPort expand => 1), 1038 vp => (new CFPlus::UI::ViewPort expand => 1),
1013 can_events => 1, 1039 can_events => 1,
1014 slider => $slider, 1040 slider => $slider,
1015 %arg, 1041 %arg,
1016 ); 1042 );
1017 1043
1061 $self->SUPER::invoke_size_allocate ($w, $h) 1087 $self->SUPER::invoke_size_allocate ($w, $h)
1062} 1088}
1063 1089
1064############################################################################# 1090#############################################################################
1065 1091
1066package CFClient::UI::Frame; 1092package CFPlus::UI::Frame;
1067 1093
1068our @ISA = CFClient::UI::Bin::; 1094our @ISA = CFPlus::UI::Bin::;
1069 1095
1070use CFClient::OpenGL; 1096use CFPlus::OpenGL;
1071 1097
1072sub new { 1098sub new {
1073 my $class = shift; 1099 my $class = shift;
1074 1100
1075 $class->SUPER::new ( 1101 $class->SUPER::new (
1101 $self->SUPER::_draw; 1127 $self->SUPER::_draw;
1102} 1128}
1103 1129
1104############################################################################# 1130#############################################################################
1105 1131
1106package CFClient::UI::FancyFrame; 1132package CFPlus::UI::FancyFrame;
1107 1133
1108our @ISA = CFClient::UI::Bin::; 1134our @ISA = CFPlus::UI::Bin::;
1109 1135
1110use CFClient::OpenGL; 1136use CFPlus::OpenGL;
1111 1137
1112my $bg = 1138my $bg =
1113 new_from_file CFClient::Texture CFClient::find_rcfile "d1_bg.png", 1139 new_from_file CFPlus::Texture CFPlus::find_rcfile "d1_bg.png",
1114 mipmap => 1, wrap => 1; 1140 mipmap => 1, wrap => 1;
1115 1141
1116my @border = 1142my @border =
1117 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1143 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
1118 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); 1144 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
1119 1145
1120sub new { 1146sub new {
1121 my ($class, %arg) = @_; 1147 my ($class, %arg) = @_;
1122 1148
1128 min_w => 64, 1154 min_w => 64,
1129 min_h => 32, 1155 min_h => 32,
1130 %arg, 1156 %arg,
1131 ); 1157 );
1132 1158
1133 $self->{title_widget} = new CFClient::UI::Label 1159 $self->{title_widget} = new CFPlus::UI::Label
1134 align => 0, 1160 align => 0,
1135 valign => 1, 1161 valign => 1,
1136 text => $self->{title}, 1162 text => $self->{title},
1137 fontsize => $self->{border}, 1163 fontsize => $self->{border},
1138 if exists $self->{title}; 1164 if exists $self->{title};
1139 1165
1140 if ($self->{has_close_button}) { 1166 if ($self->{has_close_button}) {
1141 $self->{close_button} = 1167 $self->{close_button} =
1142 new CFClient::UI::ImageButton 1168 new CFPlus::UI::ImageButton
1143 path => 'x1_close.png', 1169 path => 'x1_close.png',
1144 on_activate => sub { $self->emit ("delete") }; 1170 on_activate => sub { $self->emit ("delete") };
1145 1171
1146 $self->CFClient::UI::Container::add ($self->{close_button}); 1172 $self->CFPlus::UI::Container::add ($self->{close_button});
1147 } 1173 }
1148 1174
1149 $self 1175 $self
1150} 1176}
1151 1177
1152sub add { 1178sub add {
1153 my ($self, @widgets) = @_; 1179 my ($self, @widgets) = @_;
1154 1180
1155 $self->SUPER::add (@widgets); 1181 $self->SUPER::add (@widgets);
1156 $self->CFClient::UI::Container::add ($self->{close_button}) if $self->{close_button}; 1182 $self->CFPlus::UI::Container::add ($self->{close_button}) if $self->{close_button};
1157 $self->CFClient::UI::Container::add ($self->{title_widget}) if $self->{title_widget}; 1183 $self->CFPlus::UI::Container::add ($self->{title_widget}) if $self->{title_widget};
1158} 1184}
1159 1185
1160sub border { 1186sub border {
1161 int $_[0]{border} * $::FONTSIZE 1187 int $_[0]{border} * $::FONTSIZE
1162} 1188}
1270 $self->{motion}->($ev, $x, $y) if $self->{motion}; 1296 $self->{motion}->($ev, $x, $y) if $self->{motion};
1271 1297
1272 ! ! $self->{motion} 1298 ! ! $self->{motion}
1273} 1299}
1274 1300
1301sub invoke_visibility_change {
1302 my ($self, $visible) = @_;
1303
1304 delete $self->{motion} unless $visible;
1305
1306 0
1307}
1308
1275sub _draw { 1309sub _draw {
1276 my ($self) = @_; 1310 my ($self) = @_;
1277 1311
1278 my $child = $self->{children}[0]; 1312 my $child = $self->{children}[0];
1279 1313
1316 if $self->{close_button}; 1350 if $self->{close_button};
1317} 1351}
1318 1352
1319############################################################################# 1353#############################################################################
1320 1354
1321package CFClient::UI::Table; 1355package CFPlus::UI::Table;
1322 1356
1323our @ISA = CFClient::UI::Base::; 1357our @ISA = CFPlus::UI::Base::;
1324 1358
1325use List::Util qw(max sum); 1359use List::Util qw(max sum);
1326 1360
1327use CFClient::OpenGL; 1361use CFPlus::OpenGL;
1328 1362
1329sub new { 1363sub new {
1330 my $class = shift; 1364 my $class = shift;
1331 1365
1332 $class->SUPER::new ( 1366 $class->SUPER::new (
1338sub children { 1372sub children {
1339 grep $_, map @$_, grep $_, @{ $_[0]{children} } 1373 grep $_, map @$_, grep $_, @{ $_[0]{children} }
1340} 1374}
1341 1375
1342sub add { 1376sub add {
1343 my ($self, $x, $y, $child) = @_; 1377 my ($self) = shift;
1344 1378
1379 while (@_) {
1380 my ($x, $y, $child) = splice @_, 0, 3, ();
1345 $child->set_parent ($self); 1381 $child->set_parent ($self);
1346 $self->{children}[$y][$x] = $child; 1382 $self->{children}[$y][$x] = $child;
1383 }
1347 1384
1385 $self->{force_realloc} = 1;
1386 $self->{force_size_alloc} = 1;
1348 $self->realloc; 1387 $self->realloc;
1349} 1388}
1350 1389
1351sub remove { 1390sub remove {
1352 my ($self, $child) = @_; 1391 my ($self, $child) = @_;
1417 1456
1418 # linearly scale sizes 1457 # linearly scale sizes
1419 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; 1458 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws;
1420 $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs; 1459 $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs;
1421 1460
1422 CFClient::UI::harmonize $ws; 1461 CFPlus::UI::harmonize $ws;
1423 CFClient::UI::harmonize $hs; 1462 CFPlus::UI::harmonize $hs;
1424 1463
1425 my $y; 1464 my $y;
1426 1465
1427 for my $r (0 .. $#{$self->{children}}) { 1466 for my $r (0 .. $#{$self->{children}}) {
1428 my $row = $self->{children}[$r] 1467 my $row = $self->{children}[$r]
1471 } 1510 }
1472} 1511}
1473 1512
1474############################################################################# 1513#############################################################################
1475 1514
1476package CFClient::UI::Box; 1515package CFPlus::UI::Box;
1477 1516
1478our @ISA = CFClient::UI::Container::; 1517our @ISA = CFPlus::UI::Container::;
1479 1518
1480sub size_request { 1519sub size_request {
1481 my ($self) = @_; 1520 my ($self) = @_;
1482 1521
1483 $self->{vertical} 1522 $self->{vertical}
1516 $req[$_] += $space * $children[$_]{expand} 1555 $req[$_] += $space * $children[$_]{expand}
1517 for 0 .. $#children; 1556 for 0 .. $#children;
1518 } 1557 }
1519 } 1558 }
1520 1559
1521 CFClient::UI::harmonize \@req; 1560 CFPlus::UI::harmonize \@req;
1522 1561
1523 my $pos = 0; 1562 my $pos = 0;
1524 for (0 .. $#children) { 1563 for (0 .. $#children) {
1525 my $alloc = $req[$_]; 1564 my $alloc = $req[$_];
1526 $children[$_]->configure ($self->{vertical} ? (0, $pos, $w, $alloc) : ($pos, 0, $alloc, $h)); 1565 $children[$_]->configure ($self->{vertical} ? (0, $pos, $w, $alloc) : ($pos, 0, $alloc, $h));
1531 1 1570 1
1532} 1571}
1533 1572
1534############################################################################# 1573#############################################################################
1535 1574
1536package CFClient::UI::HBox; 1575package CFPlus::UI::HBox;
1537 1576
1538our @ISA = CFClient::UI::Box::; 1577our @ISA = CFPlus::UI::Box::;
1539 1578
1540sub new { 1579sub new {
1541 my $class = shift; 1580 my $class = shift;
1542 1581
1543 $class->SUPER::new ( 1582 $class->SUPER::new (
1546 ) 1585 )
1547} 1586}
1548 1587
1549############################################################################# 1588#############################################################################
1550 1589
1551package CFClient::UI::VBox; 1590package CFPlus::UI::VBox;
1552 1591
1553our @ISA = CFClient::UI::Box::; 1592our @ISA = CFPlus::UI::Box::;
1554 1593
1555sub new { 1594sub new {
1556 my $class = shift; 1595 my $class = shift;
1557 1596
1558 $class->SUPER::new ( 1597 $class->SUPER::new (
1561 ) 1600 )
1562} 1601}
1563 1602
1564############################################################################# 1603#############################################################################
1565 1604
1566package CFClient::UI::Label; 1605package CFPlus::UI::Label;
1567 1606
1568our @ISA = CFClient::UI::DrawBG::; 1607our @ISA = CFPlus::UI::DrawBG::;
1569 1608
1570use CFClient::OpenGL; 1609use CFPlus::OpenGL;
1571 1610
1572sub new { 1611sub new {
1573 my ($class, %arg) = @_; 1612 my ($class, %arg) = @_;
1574 1613
1575 my $self = $class->SUPER::new ( 1614 my $self = $class->SUPER::new (
1579 #font => default_font 1618 #font => default_font
1580 #text => initial text 1619 #text => initial text
1581 #markup => initial narkup 1620 #markup => initial narkup
1582 #max_w => maximum pixel width 1621 #max_w => maximum pixel width
1583 ellipsise => 3, # end 1622 ellipsise => 3, # end
1584 layout => (new CFClient::Layout), 1623 layout => (new CFPlus::Layout),
1585 fontsize => 1, 1624 fontsize => 1,
1586 align => -1, 1625 align => -1,
1587 valign => -1, 1626 valign => -1,
1588 padding_x => 2, 1627 padding_x => 2,
1589 padding_y => 2, 1628 padding_y => 2,
1590 can_events => 0, 1629 can_events => 0,
1591 %arg 1630 %arg
1592 ); 1631 );
1593 1632
1594 if (exists $self->{template}) { 1633 if (exists $self->{template}) {
1595 my $layout = new CFClient::Layout; 1634 my $layout = new CFPlus::Layout;
1596 $layout->set_text (delete $self->{template}); 1635 $layout->set_text (delete $self->{template});
1597 $self->{template} = $layout; 1636 $self->{template} = $layout;
1598 } 1637 }
1599 1638
1600 if (exists $self->{markup}) { 1639 if (exists $self->{markup}) {
1602 } else { 1641 } else {
1603 $self->set_text (delete $self->{text}); 1642 $self->set_text (delete $self->{text});
1604 } 1643 }
1605 1644
1606 $self 1645 $self
1607}
1608
1609sub escape($) {
1610 local $_ = $_[0];
1611
1612 s/&/&amp;/g;
1613 s/>/&gt;/g;
1614 s/</&lt;/g;
1615
1616 $_
1617} 1646}
1618 1647
1619sub update { 1648sub update {
1620 my ($self) = @_; 1649 my ($self) = @_;
1621 1650
1753 $self->{layout}->render ($self->{ox}, $self->{oy}); 1782 $self->{layout}->render ($self->{ox}, $self->{oy});
1754} 1783}
1755 1784
1756############################################################################# 1785#############################################################################
1757 1786
1758package CFClient::UI::EntryBase; 1787package CFPlus::UI::EntryBase;
1759 1788
1760our @ISA = CFClient::UI::Label::; 1789our @ISA = CFPlus::UI::Label::;
1761 1790
1762use CFClient::OpenGL; 1791use CFPlus::OpenGL;
1763 1792
1764sub new { 1793sub new {
1765 my $class = shift; 1794 my $class = shift;
1766 1795
1767 $class->SUPER::new ( 1796 $class->SUPER::new (
1829 1858
1830 if ($uni == 8) { 1859 if ($uni == 8) {
1831 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 1860 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
1832 } elsif ($uni == 127) { 1861 } elsif ($uni == 127) {
1833 substr $text, $self->{cursor}, 1, ""; 1862 substr $text, $self->{cursor}, 1, "";
1834 } elsif ($sym == CFClient::SDLK_LEFT) { 1863 } elsif ($sym == CFPlus::SDLK_LEFT) {
1835 --$self->{cursor} if $self->{cursor}; 1864 --$self->{cursor} if $self->{cursor};
1836 } elsif ($sym == CFClient::SDLK_RIGHT) { 1865 } elsif ($sym == CFPlus::SDLK_RIGHT) {
1837 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 1866 ++$self->{cursor} if $self->{cursor} < length $self->{text};
1838 } elsif ($sym == CFClient::SDLK_HOME) { 1867 } elsif ($sym == CFPlus::SDLK_HOME) {
1839 $self->{cursor} = 0; 1868 $self->{cursor} = 0;
1840 } elsif ($sym == CFClient::SDLK_END) { 1869 } elsif ($sym == CFPlus::SDLK_END) {
1841 $self->{cursor} = length $text; 1870 $self->{cursor} = length $text;
1842 } elsif ($uni == 27) { 1871 } elsif ($uni == 27) {
1843 $self->emit ('escape'); 1872 $self->emit ('escape');
1844 } elsif ($uni) { 1873 } elsif ($uni) {
1845 substr $text, $self->{cursor}++, 0, chr $uni; 1874 substr $text, $self->{cursor}++, 0, chr $uni;
1927 glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; 1956 glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h};
1928 glEnd; 1957 glEnd;
1929 } 1958 }
1930} 1959}
1931 1960
1932package CFClient::UI::Entry; 1961package CFPlus::UI::Entry;
1933 1962
1934our @ISA = CFClient::UI::EntryBase::; 1963our @ISA = CFPlus::UI::EntryBase::;
1935 1964
1936use CFClient::OpenGL; 1965use CFPlus::OpenGL;
1937 1966
1938sub invoke_key_down { 1967sub invoke_key_down {
1939 my ($self, $ev) = @_; 1968 my ($self, $ev) = @_;
1940 1969
1941 my $sym = $ev->{sym}; 1970 my $sym = $ev->{sym};
1947 $self->{history_pointer} = -1; 1976 $self->{history_pointer} = -1;
1948 $self->{history_saveback} = ''; 1977 $self->{history_saveback} = '';
1949 $self->emit (activate => $txt); 1978 $self->emit (activate => $txt);
1950 $self->update; 1979 $self->update;
1951 1980
1952 } elsif ($sym == CFClient::SDLK_UP) { 1981 } elsif ($sym == CFPlus::SDLK_UP) {
1953 if ($self->{history_pointer} < 0) { 1982 if ($self->{history_pointer} < 0) {
1954 $self->{history_saveback} = $self->get_text; 1983 $self->{history_saveback} = $self->get_text;
1955 } 1984 }
1956 if (@{$self->{history} || []} > 0) { 1985 if (@{$self->{history} || []} > 0) {
1957 $self->{history_pointer}++; 1986 $self->{history_pointer}++;
1959 $self->{history_pointer} = @{$self->{history} || []} - 1; 1988 $self->{history_pointer} = @{$self->{history} || []} - 1;
1960 } 1989 }
1961 $self->set_text ($self->{history}->[$self->{history_pointer}]); 1990 $self->set_text ($self->{history}->[$self->{history_pointer}]);
1962 } 1991 }
1963 1992
1964 } elsif ($sym == CFClient::SDLK_DOWN) { 1993 } elsif ($sym == CFPlus::SDLK_DOWN) {
1965 $self->{history_pointer}--; 1994 $self->{history_pointer}--;
1966 $self->{history_pointer} = -1 if $self->{history_pointer} < 0; 1995 $self->{history_pointer} = -1 if $self->{history_pointer} < 0;
1967 1996
1968 if ($self->{history_pointer} >= 0) { 1997 if ($self->{history_pointer} >= 0) {
1969 $self->set_text ($self->{history}->[$self->{history_pointer}]); 1998 $self->set_text ($self->{history}->[$self->{history_pointer}]);
1978 1 2007 1
1979} 2008}
1980 2009
1981############################################################################# 2010#############################################################################
1982 2011
1983package CFClient::UI::Button; 2012package CFPlus::UI::Button;
1984 2013
1985our @ISA = CFClient::UI::Label::; 2014our @ISA = CFPlus::UI::Label::;
1986 2015
1987use CFClient::OpenGL; 2016use CFPlus::OpenGL;
1988 2017
1989my @tex = 2018my @tex =
1990 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2019 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
1991 qw(b1_button_active.png); 2020 qw(b1_button_active.png);
1992 2021
1993sub new { 2022sub new {
1994 my $class = shift; 2023 my $class = shift;
1995 2024
2032 $self->SUPER::_draw; 2061 $self->SUPER::_draw;
2033} 2062}
2034 2063
2035############################################################################# 2064#############################################################################
2036 2065
2066package CFPlus::UI::CheckBox;
2067
2068our @ISA = CFPlus::UI::DrawBG::;
2069
2070my @tex =
2071 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2072 qw(c1_checkbox_bg.png c1_checkbox_active.png);
2073
2074use CFPlus::OpenGL;
2075
2076sub new {
2077 my $class = shift;
2078
2079 $class->SUPER::new (
2080 padding_x => 2,
2081 padding_y => 2,
2082 fg => [1, 1, 1],
2083 active_fg => [1, 1, 0],
2084 bg => [0, 0, 0, 0.2],
2085 active_bg => [1, 1, 1, 0.5],
2086 state => 0,
2087 can_hover => 1,
2088 @_
2089 )
2090}
2091
2092sub size_request {
2093 my ($self) = @_;
2094
2095 (6) x 2
2096}
2097
2098sub toggle {
2099 my ($self) = @_;
2100
2101 $self->{state} = !$self->{state};
2102 $self->emit (changed => $self->{state});
2103 $self->update;
2104}
2105
2106sub invoke_button_down {
2107 my ($self, $ev, $x, $y) = @_;
2108
2109 if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x}
2110 && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) {
2111 $self->toggle;
2112 } else {
2113 return 0
2114 }
2115
2116 1
2117}
2118
2119sub _draw {
2120 my ($self) = @_;
2121
2122 $self->SUPER::_draw;
2123
2124 glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0;
2125
2126 my ($w, $h) = @$self{qw(w h)};
2127
2128 my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2;
2129
2130 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} };
2131
2132 my $tex = $self->{state} ? $tex[1] : $tex[0];
2133
2134 glEnable GL_TEXTURE_2D;
2135 $tex->draw_quad_alpha (0, 0, $s, $s);
2136 glDisable GL_TEXTURE_2D;
2137}
2138
2139#############################################################################
2140
2141package CFPlus::UI::Image;
2142
2143our @ISA = CFPlus::UI::Base::;
2144
2145use CFPlus::OpenGL;
2146
2147our %texture_cache;
2148
2149sub new {
2150 my $class = shift;
2151
2152 my $self = $class->SUPER::new (
2153 can_events => 0,
2154 @_,
2155 );
2156
2157 $self->{path} || $self->{tex}
2158 or Carp::croak "'path' or 'tex' attributes required";
2159
2160 $self->{tex} ||= $texture_cache{$self->{path}} ||=
2161 new_from_file CFPlus::Texture CFPlus::find_rcfile $self->{path}, mipmap => 1;
2162
2163 Scalar::Util::weaken $texture_cache{$self->{path}};
2164
2165 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2166
2167 $self
2168}
2169
2170sub STORABLE_freeze {
2171 my ($self, $cloning) = @_;
2172
2173 $self->{path}
2174 or die "cannot serialise CFPlus::UI::Image on non-loadable images\n";
2175
2176 $self->{path}
2177}
2178
2179sub STORABLE_attach {
2180 my ($self, $cloning, $path) = @_;
2181
2182 $self->new (path => $path)
2183}
2184
2185sub size_request {
2186 my ($self) = @_;
2187
2188 ($self->{tex}{w}, $self->{tex}{h})
2189}
2190
2191sub _draw {
2192 my ($self) = @_;
2193
2194 my $tex = $self->{tex};
2195
2196 my ($w, $h) = ($self->{w}, $self->{h});
2197
2198 if ($self->{rot90}) {
2199 glRotate 90, 0, 0, 1;
2200 glTranslate 0, -$self->{w}, 0;
2201
2202 ($w, $h) = ($h, $w);
2203 }
2204
2205 glEnable GL_TEXTURE_2D;
2206 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2207
2208 $tex->draw_quad (0, 0, $w, $h);
2209
2210 glDisable GL_TEXTURE_2D;
2211}
2212
2213#############################################################################
2214
2037package CFClient::UI::ImageButton; 2215package CFPlus::UI::ImageButton;
2038 2216
2039our @ISA = CFClient::UI::Image::; 2217our @ISA = CFPlus::UI::Image::;
2040 2218
2041use CFClient::OpenGL; 2219use CFPlus::OpenGL;
2042 2220
2043my %textures; 2221my %textures;
2044 2222
2045sub new { 2223sub new {
2046 my $class = shift; 2224 my $class = shift;
2068 1 2246 1
2069} 2247}
2070 2248
2071############################################################################# 2249#############################################################################
2072 2250
2073package CFClient::UI::CheckBox;
2074
2075our @ISA = CFClient::UI::DrawBG::;
2076
2077my @tex =
2078 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
2079 qw(c1_checkbox_bg.png c1_checkbox_active.png);
2080
2081use CFClient::OpenGL;
2082
2083sub new {
2084 my $class = shift;
2085
2086 $class->SUPER::new (
2087 padding_x => 2,
2088 padding_y => 2,
2089 fg => [1, 1, 1],
2090 active_fg => [1, 1, 0],
2091 bg => [0, 0, 0, 0.2],
2092 active_bg => [1, 1, 1, 0.5],
2093 state => 0,
2094 can_hover => 1,
2095 @_
2096 )
2097}
2098
2099sub size_request {
2100 my ($self) = @_;
2101
2102 (6) x 2
2103}
2104
2105sub toggle {
2106 my ($self) = @_;
2107
2108 $self->{state} = !$self->{state};
2109 $self->emit (changed => $self->{state});
2110 $self->update;
2111}
2112
2113sub invoke_button_down {
2114 my ($self, $ev, $x, $y) = @_;
2115
2116 if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x}
2117 && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) {
2118 $self->toggle;
2119 } else {
2120 return 0
2121 }
2122
2123 1
2124}
2125
2126sub _draw {
2127 my ($self) = @_;
2128
2129 $self->SUPER::_draw;
2130
2131 glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0;
2132
2133 my ($w, $h) = @$self{qw(w h)};
2134
2135 my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2;
2136
2137 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} };
2138
2139 my $tex = $self->{state} ? $tex[1] : $tex[0];
2140
2141 glEnable GL_TEXTURE_2D;
2142 $tex->draw_quad_alpha (0, 0, $s, $s);
2143 glDisable GL_TEXTURE_2D;
2144}
2145
2146#############################################################################
2147
2148package CFClient::UI::Image; 2251package CFPlus::UI::VGauge;
2149 2252
2150our @ISA = CFClient::UI::Base::; 2253our @ISA = CFPlus::UI::Base::;
2151
2152use CFClient::OpenGL;
2153
2154our %texture_cache;
2155
2156sub new {
2157 my $class = shift;
2158
2159 my $self = $class->SUPER::new (
2160 can_events => 0,
2161 @_,
2162 );
2163
2164 $self->{path} || $self->{tex}
2165 or Carp::croak "'path' or 'tex' attributes required";
2166
2167 $self->{tex} ||= $texture_cache{$self->{path}} ||=
2168 new_from_file CFClient::Texture CFClient::find_rcfile $self->{path}, mipmap => 1;
2169
2170 Scalar::Util::weaken $texture_cache{$self->{path}};
2171
2172 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2173
2174 $self
2175}
2176
2177sub size_request {
2178 my ($self) = @_;
2179
2180 ($self->{tex}{w}, $self->{tex}{h})
2181}
2182
2183sub _draw {
2184 my ($self) = @_;
2185
2186 my $tex = $self->{tex};
2187
2188 my ($w, $h) = ($self->{w}, $self->{h});
2189
2190 if ($self->{rot90}) {
2191 glRotate 90, 0, 0, 1;
2192 glTranslate 0, -$self->{w}, 0;
2193
2194 ($w, $h) = ($h, $w);
2195 }
2196
2197 glEnable GL_TEXTURE_2D;
2198 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2199
2200 $tex->draw_quad_alpha (0, 0, $w, $h);
2201
2202 glDisable GL_TEXTURE_2D;
2203}
2204
2205#############################################################################
2206
2207package CFClient::UI::VGauge;
2208
2209our @ISA = CFClient::UI::Base::;
2210 2254
2211use List::Util qw(min max); 2255use List::Util qw(min max);
2212 2256
2213use CFClient::OpenGL; 2257use CFPlus::OpenGL;
2214 2258
2215my %tex = ( 2259my %tex = (
2216 food => [ 2260 food => [
2217 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2261 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2218 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 2262 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
2219 ], 2263 ],
2220 grace => [ 2264 grace => [
2221 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2265 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2222 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/ 2266 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/
2223 ], 2267 ],
2224 hp => [ 2268 hp => [
2225 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2269 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2226 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 2270 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
2227 ], 2271 ],
2228 mana => [ 2272 mana => [
2229 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2273 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2230 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/ 2274 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/
2231 ], 2275 ],
2232); 2276);
2233 2277
2234# eg. VGauge->new (gauge => 'food'), default gauge: food 2278# eg. VGauge->new (gauge => 'food'), default gauge: food
2337 glDisable GL_TEXTURE_2D; 2381 glDisable GL_TEXTURE_2D;
2338} 2382}
2339 2383
2340############################################################################# 2384#############################################################################
2341 2385
2342package CFClient::UI::Gauge; 2386package CFPlus::UI::Gauge;
2343 2387
2344our @ISA = CFClient::UI::VBox::; 2388our @ISA = CFPlus::UI::VBox::;
2345 2389
2346sub new { 2390sub new {
2347 my ($class, %arg) = @_; 2391 my ($class, %arg) = @_;
2348 2392
2349 my $self = $class->SUPER::new ( 2393 my $self = $class->SUPER::new (
2351 can_hover => 1, 2395 can_hover => 1,
2352 can_events => 1, 2396 can_events => 1,
2353 %arg, 2397 %arg,
2354 ); 2398 );
2355 2399
2356 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); 2400 $self->add ($self->{value} = new CFPlus::UI::Label valign => +1, align => 0, template => "999");
2357 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); 2401 $self->add ($self->{gauge} = new CFPlus::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1);
2358 $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999"); 2402 $self->add ($self->{max} = new CFPlus::UI::Label valign => -1, align => 0, template => "999");
2359 2403
2360 $self 2404 $self
2361} 2405}
2362 2406
2363sub set_fontsize { 2407sub set_fontsize {
2384 $self->{value}->set_text ($val); 2428 $self->{value}->set_text ($val);
2385} 2429}
2386 2430
2387############################################################################# 2431#############################################################################
2388 2432
2389package CFClient::UI::Slider; 2433package CFPlus::UI::Slider;
2390 2434
2391use strict; 2435use strict;
2392 2436
2393use CFClient::OpenGL; 2437use CFPlus::OpenGL;
2394 2438
2395our @ISA = CFClient::UI::DrawBG::; 2439our @ISA = CFPlus::UI::DrawBG::;
2396 2440
2397my @tex = 2441my @tex =
2398 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 2442 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_ }
2399 qw(s1_slider.png s1_slider_bg.png); 2443 qw(s1_slider.png s1_slider_bg.png);
2400 2444
2401sub new { 2445sub new {
2402 my $class = shift; 2446 my $class = shift;
2403 2447
2497sub invoke_mouse_wheel { 2541sub invoke_mouse_wheel {
2498 my ($self, $ev) = @_; 2542 my ($self, $ev) = @_;
2499 2543
2500 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; 2544 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx};
2501 2545
2502 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * 0.1); 2546 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * 0.2);
2503 2547
2504 ! ! $delta 2548 ! ! $delta
2505} 2549}
2506 2550
2507sub update { 2551sub update {
2558 glDisable GL_TEXTURE_2D; 2602 glDisable GL_TEXTURE_2D;
2559} 2603}
2560 2604
2561############################################################################# 2605#############################################################################
2562 2606
2563package CFClient::UI::ValSlider; 2607package CFPlus::UI::ValSlider;
2564 2608
2565our @ISA = CFClient::UI::HBox::; 2609our @ISA = CFPlus::UI::HBox::;
2566 2610
2567sub new { 2611sub new {
2568 my ($class, %arg) = @_; 2612 my ($class, %arg) = @_;
2569 2613
2570 my $range = delete $arg{range}; 2614 my $range = delete $arg{range};
2571 2615
2572 my $self = $class->SUPER::new ( 2616 my $self = $class->SUPER::new (
2573 slider => (new CFClient::UI::Slider expand => 1, range => $range), 2617 slider => (new CFPlus::UI::Slider expand => 1, range => $range),
2574 entry => (new CFClient::UI::Label text => "", template => delete $arg{template}), 2618 entry => (new CFPlus::UI::Label text => "", template => delete $arg{template}),
2575 to_value => sub { shift }, 2619 to_value => sub { shift },
2576 from_value => sub { shift }, 2620 from_value => sub { shift },
2577 %arg, 2621 %arg,
2578 ); 2622 );
2579 2623
2599sub set_range { shift->{slider}->set_range (@_) } 2643sub set_range { shift->{slider}->set_range (@_) }
2600sub set_value { shift->{slider}->set_value (@_) } 2644sub set_value { shift->{slider}->set_value (@_) }
2601 2645
2602############################################################################# 2646#############################################################################
2603 2647
2604package CFClient::UI::TextScroller; 2648package CFPlus::UI::TextScroller;
2605 2649
2606our @ISA = CFClient::UI::HBox::; 2650our @ISA = CFPlus::UI::HBox::;
2607 2651
2608use CFClient::OpenGL; 2652use CFPlus::OpenGL;
2609 2653
2610sub new { 2654sub new {
2611 my $class = shift; 2655 my $class = shift;
2612 2656
2613 my $self = $class->SUPER::new ( 2657 my $self = $class->SUPER::new (
2615 can_events => 1, 2659 can_events => 1,
2616 indent => 0, 2660 indent => 0,
2617 #font => default_font 2661 #font => default_font
2618 @_, 2662 @_,
2619 2663
2620 layout => (new CFClient::Layout), 2664 layout => (new CFPlus::Layout),
2621 par => [], 2665 par => [],
2622 height => 0, 2666 height => 0,
2623 children => [ 2667 children => [
2624 (new CFClient::UI::Empty expand => 1), 2668 (new CFPlus::UI::Empty expand => 1),
2625 (new CFClient::UI::Slider vertical => 1), 2669 (new CFPlus::UI::Slider vertical => 1),
2626 ], 2670 ],
2627 ); 2671 );
2628 2672
2629 $self->{children}[1]->connect (changed => sub { $self->update }); 2673 $self->{children}[1]->connect (changed => sub { $self->update });
2630 2674
2719 $self->{height} = 0; 2763 $self->{height} = 0;
2720 $self->{children}[1]->set_range ([0, 0, 0, 1, 1]); 2764 $self->{children}[1]->set_range ([0, 0, 0, 1, 1]);
2721} 2765}
2722 2766
2723sub add_paragraph { 2767sub add_paragraph {
2724 my ($self, $color, $para, $indent) = @_; 2768 my $self = shift;
2725 2769
2726 my ($text, @w) = ref $para ? @$para : $para; 2770 for my $para (@_) {
2727
2728 $para = { 2771 $para = {
2772 fg => [1, 1, 1, 1],
2773 indent => 0,
2774 markup => "",
2775 widget => [],
2776 ref $para ? %$para : (markup => $para),
2729 w => 1e10, 2777 w => 1e10,
2730 wrapped => 1, 2778 wrapped => 1,
2731 fg => $color,
2732 indent => $indent,
2733 markup => $text,
2734 widget => \@w,
2735 }; 2779 };
2736 2780
2737 $self->add (@w) if @w; 2781 $self->add (@{ $para->{widget} }) if @{ $para->{widget} };
2738 push @{$self->{par}}, $para; 2782 push @{$self->{par}}, $para;
2783 }
2739 2784
2740 $self->{need_reflow}++; 2785 $self->{need_reflow}++;
2741 $self->update; 2786 $self->update;
2742} 2787}
2743 2788
2785 2830
2786 if (delete $self->{scroll_to_bottom}) { 2831 if (delete $self->{scroll_to_bottom}) {
2787 $self->{children}[1]->set_value (1e10); 2832 $self->{children}[1]->set_value (1e10);
2788 } 2833 }
2789 2834
2790 $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { 2835 $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub {
2791 glClearColor 0, 0, 0, 0; 2836 glClearColor 0, 0, 0, 0;
2792 glClear GL_COLOR_BUFFER_BIT; 2837 glClear GL_COLOR_BUFFER_BIT;
2793 2838
2794 my $top = int $self->{children}[1]{range}[0]; 2839 my $top = int $self->{children}[1]{range}[0];
2795 2840
2848 $self->{children}[1]->draw; 2893 $self->{children}[1]->draw;
2849} 2894}
2850 2895
2851############################################################################# 2896#############################################################################
2852 2897
2853package CFClient::UI::Animator; 2898package CFPlus::UI::Animator;
2854 2899
2855use CFClient::OpenGL; 2900use CFPlus::OpenGL;
2856 2901
2857our @ISA = CFClient::UI::Bin::; 2902our @ISA = CFPlus::UI::Bin::;
2858 2903
2859sub moveto { 2904sub moveto {
2860 my ($self, $x, $y) = @_; 2905 my ($self, $x, $y) = @_;
2861 2906
2862 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 2907 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
2890 glPopMatrix; 2935 glPopMatrix;
2891} 2936}
2892 2937
2893############################################################################# 2938#############################################################################
2894 2939
2895package CFClient::UI::Flopper; 2940package CFPlus::UI::Flopper;
2896 2941
2897our @ISA = CFClient::UI::Button::; 2942our @ISA = CFPlus::UI::Button::;
2898 2943
2899sub new { 2944sub new {
2900 my $class = shift; 2945 my $class = shift;
2901 2946
2902 my $self = $class->SUPER::new ( 2947 my $self = $class->SUPER::new (
2914 $self->{other}->toggle_visibility; 2959 $self->{other}->toggle_visibility;
2915} 2960}
2916 2961
2917############################################################################# 2962#############################################################################
2918 2963
2919package CFClient::UI::Tooltip; 2964package CFPlus::UI::Tooltip;
2920 2965
2921our @ISA = CFClient::UI::Bin::; 2966our @ISA = CFPlus::UI::Bin::;
2922 2967
2923use CFClient::OpenGL; 2968use CFPlus::OpenGL;
2924 2969
2925sub new { 2970sub new {
2926 my $class = shift; 2971 my $class = shift;
2927 2972
2928 $class->SUPER::new ( 2973 $class->SUPER::new (
2944 } 2989 }
2945 2990
2946 $tooltip =~ s/^\n+//; 2991 $tooltip =~ s/^\n+//;
2947 $tooltip =~ s/\n+$//; 2992 $tooltip =~ s/\n+$//;
2948 2993
2949 $self->add (new CFClient::UI::Label 2994 $self->add (new CFPlus::UI::Label
2950 markup => $tooltip, 2995 markup => $tooltip,
2951 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 2996 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
2952 fontsize => 0.8, 2997 fontsize => 0.8,
2953 fg => [0, 0, 0, 1], 2998 fg => [0, 0, 0, 1],
2954 ellipsise => 0, 2999 ellipsise => 0,
2977 3022
2978 $self->{root}->on_post_alloc ("move_$self" => sub { 3023 $self->{root}->on_post_alloc ("move_$self" => sub {
2979 my $widget = $self->{owner} 3024 my $widget = $self->{owner}
2980 or return; 3025 or return;
2981 3026
3027 if ($widget->{visible}) {
2982 my ($x, $y) = $widget->coord2global ($widget->{w}, 0); 3028 my ($x, $y) = $widget->coord2global ($widget->{w}, 0);
2983 3029
2984 ($x, $y) = $widget->coord2global (-$self->{w}, 0) 3030 ($x, $y) = $widget->coord2global (-$self->{w}, 0)
2985 if $x + $self->{w} > $self->{root}{w}; 3031 if $x + $self->{w} > $self->{root}{w};
2986 3032
2987 $self->move_abs ($x, $y); 3033 $self->move_abs ($x, $y);
3034 } else {
3035 $self->hide;
3036 }
2988 }); 3037 });
2989} 3038}
2990 3039
2991sub _draw { 3040sub _draw {
2992 my ($self) = @_; 3041 my ($self) = @_;
3016 $self->SUPER::_draw; 3065 $self->SUPER::_draw;
3017} 3066}
3018 3067
3019############################################################################# 3068#############################################################################
3020 3069
3021package CFClient::UI::Face; 3070package CFPlus::UI::Face;
3022 3071
3023our @ISA = CFClient::UI::Base::; 3072our @ISA = CFPlus::UI::DrawBG::;
3024 3073
3025use CFClient::OpenGL; 3074use CFPlus::OpenGL;
3026 3075
3027sub new { 3076sub new {
3028 my $class = shift; 3077 my $class = shift;
3029 3078
3030 my $self = $class->SUPER::new ( 3079 my $self = $class->SUPER::new (
3065sub _draw { 3114sub _draw {
3066 my ($self) = @_; 3115 my ($self) = @_;
3067 3116
3068 return unless $::CONN; 3117 return unless $::CONN;
3069 3118
3119 $self->SUPER::_draw;
3120
3070 my $face; 3121 my $face;
3071 3122
3072 if ($self->{frame}) { 3123 if ($self->{frame}) {
3073 my $anim = $::CONN->{anim}[$self->{anim}]; 3124 my $anim = $::CONN->{anim}[$self->{anim}];
3074 3125
3096 $self->SUPER::destroy; 3147 $self->SUPER::destroy;
3097} 3148}
3098 3149
3099############################################################################# 3150#############################################################################
3100 3151
3101package CFClient::UI::Buttonbar; 3152package CFPlus::UI::Buttonbar;
3102 3153
3103our @ISA = CFClient::UI::HBox::; 3154our @ISA = CFPlus::UI::HBox::;
3104 3155
3105# TODO: should actualyl wrap buttons and other goodies. 3156# TODO: should actualyl wrap buttons and other goodies.
3106 3157
3107############################################################################# 3158#############################################################################
3108 3159
3109package CFClient::UI::Menu; 3160package CFPlus::UI::Menu;
3110 3161
3111our @ISA = CFClient::UI::FancyFrame::; 3162our @ISA = CFPlus::UI::FancyFrame::;
3112 3163
3113use CFClient::OpenGL; 3164use CFPlus::OpenGL;
3114 3165
3115sub new { 3166sub new {
3116 my $class = shift; 3167 my $class = shift;
3117 3168
3118 my $self = $class->SUPER::new ( 3169 my $self = $class->SUPER::new (
3119 items => [], 3170 items => [],
3120 z => 100, 3171 z => 100,
3121 @_, 3172 @_,
3122 ); 3173 );
3123 3174
3124 $self->add ($self->{vbox} = new CFClient::UI::VBox); 3175 $self->add ($self->{vbox} = new CFPlus::UI::VBox);
3125 3176
3126 for my $item (@{ $self->{items} }) { 3177 for my $item (@{ $self->{items} }) {
3127 my ($widget, $cb, $tooltip) = @$item; 3178 my ($widget, $cb, $tooltip) = @$item;
3128 3179
3129 # handle various types of items, only text for now 3180 # handle various types of items, only text for now
3130 if (!ref $widget) { 3181 if (!ref $widget) {
3131 if ($widget =~ /\t/) { 3182 if ($widget =~ /\t/) {
3132 my ($left, $right) = split /\t/, $widget, 2; 3183 my ($left, $right) = split /\t/, $widget, 2;
3133 3184
3134 $widget = new CFClient::UI::HBox 3185 $widget = new CFPlus::UI::HBox
3135 can_hover => 1, 3186 can_hover => 1,
3136 can_events => 1, 3187 can_events => 1,
3137 tooltip => $tooltip, 3188 tooltip => $tooltip,
3138 children => [ 3189 children => [
3139 (new CFClient::UI::Label markup => $left, expand => 1), 3190 (new CFPlus::UI::Label markup => $left, expand => 1),
3140 (new CFClient::UI::Label markup => $right, align => +1), 3191 (new CFPlus::UI::Label markup => $right, align => +1),
3141 ], 3192 ],
3142 ; 3193 ;
3143 3194
3144 } else { 3195 } else {
3145 $widget = new CFClient::UI::Label 3196 $widget = new CFPlus::UI::Label
3146 can_hover => 1, 3197 can_hover => 1,
3147 can_events => 1, 3198 can_events => 1,
3148 markup => $widget, 3199 markup => $widget,
3149 tooltip => $tooltip; 3200 tooltip => $tooltip;
3150 } 3201 }
3198 1 3249 1
3199} 3250}
3200 3251
3201############################################################################# 3252#############################################################################
3202 3253
3203package CFClient::UI::Multiplexer; 3254package CFPlus::UI::Multiplexer;
3204 3255
3205our @ISA = CFClient::UI::Container::; 3256our @ISA = CFPlus::UI::Container::;
3206 3257
3207sub new { 3258sub new {
3208 my $class = shift; 3259 my $class = shift;
3209 3260
3210 my $self = $class->SUPER::new ( 3261 my $self = $class->SUPER::new (
3271 $self->{current}->draw; 3322 $self->{current}->draw;
3272} 3323}
3273 3324
3274############################################################################# 3325#############################################################################
3275 3326
3276package CFClient::UI::Notebook; 3327package CFPlus::UI::Notebook;
3277 3328
3278our @ISA = CFClient::UI::VBox::; 3329our @ISA = CFPlus::UI::VBox::;
3279 3330
3280sub new { 3331sub new {
3281 my $class = shift; 3332 my $class = shift;
3282 3333
3283 my $self = $class->SUPER::new ( 3334 my $self = $class->SUPER::new (
3284 buttonbar => (new CFClient::UI::Buttonbar), 3335 buttonbar => (new CFPlus::UI::Buttonbar),
3285 multiplexer => (new CFClient::UI::Multiplexer expand => 1), 3336 multiplexer => (new CFPlus::UI::Multiplexer expand => 1),
3286 # filter => # will be put between multiplexer and $self 3337 # filter => # will be put between multiplexer and $self
3287 @_, 3338 @_,
3288 ); 3339 );
3289 3340
3290 $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; 3341 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
3296sub add { 3347sub add {
3297 my ($self, $title, $widget, $tooltip) = @_; 3348 my ($self, $title, $widget, $tooltip) = @_;
3298 3349
3299 Scalar::Util::weaken $self; 3350 Scalar::Util::weaken $self;
3300 3351
3301 $self->{buttonbar}->add (new CFClient::UI::Button 3352 $self->{buttonbar}->add (new CFPlus::UI::Button
3302 markup => $title, 3353 markup => $title,
3303 tooltip => $tooltip, 3354 tooltip => $tooltip,
3304 on_activate => sub { $self->set_current_page ($widget) }, 3355 on_activate => sub { $self->set_current_page ($widget) },
3305 ); 3356 );
3306 3357
3320 $self->emit (page_changed => $self->{multiplexer}{current}); 3371 $self->emit (page_changed => $self->{multiplexer}{current});
3321} 3372}
3322 3373
3323############################################################################# 3374#############################################################################
3324 3375
3325package CFClient::UI::Combobox; 3376package CFPlus::UI::Selector;
3326 3377
3327use utf8; 3378use utf8;
3328 3379
3329our @ISA = CFClient::UI::Button::; 3380our @ISA = CFPlus::UI::Button::;
3330 3381
3331sub new { 3382sub new {
3332 my $class = shift; 3383 my $class = shift;
3333 3384
3334 my $self = $class->SUPER::new ( 3385 my $self = $class->SUPER::new (
3351 my ($value, $title, $tooltip) = @$_; 3402 my ($value, $title, $tooltip) = @$_;
3352 3403
3353 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }]; 3404 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }];
3354 } 3405 }
3355 3406
3356 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); 3407 CFPlus::UI::Menu->new (items => \@menu_items)->popup ($ev);
3357} 3408}
3358 3409
3359sub _set_value { 3410sub _set_value {
3360 my ($self, $value) = @_; 3411 my ($self, $value) = @_;
3361 3412
3376 $self->emit (changed => $value); 3427 $self->emit (changed => $value);
3377} 3428}
3378 3429
3379############################################################################# 3430#############################################################################
3380 3431
3381package CFClient::UI::Statusbox; 3432package CFPlus::UI::Statusbox;
3382 3433
3383our @ISA = CFClient::UI::VBox::; 3434our @ISA = CFPlus::UI::VBox::;
3384 3435
3385sub new { 3436sub new {
3386 my $class = shift; 3437 my $class = shift;
3387 3438
3388 my $self = $class->SUPER::new ( 3439 my $self = $class->SUPER::new (
3400sub reorder { 3451sub reorder {
3401 my ($self) = @_; 3452 my ($self) = @_;
3402 my $NOW = Time::HiRes::time; 3453 my $NOW = Time::HiRes::time;
3403 3454
3404 # freeze display when hovering over any label 3455 # freeze display when hovering over any label
3405 return if $CFClient::UI::TOOLTIP->{owner} 3456 return if $CFPlus::UI::TOOLTIP->{owner}
3406 && grep $CFClient::UI::TOOLTIP->{owner} == $_->{label}, 3457 && grep $CFPlus::UI::TOOLTIP->{owner} == $_->{label},
3407 values %{ $self->{item} }; 3458 values %{ $self->{item} };
3408 3459
3409 while (my ($k, $v) = each %{ $self->{item} }) { 3460 while (my ($k, $v) = each %{ $self->{item} }) {
3410 delete $self->{item}{$k} if $v->{timeout} < $NOW; 3461 delete $self->{item}{$k} if $v->{timeout} < $NOW;
3411 } 3462 }
3432 for ($short) { 3483 for ($short) {
3433 s/^\s+//; 3484 s/^\s+//;
3434 s/\s+/ /g; 3485 s/\s+/ /g;
3435 } 3486 }
3436 3487
3437 new CFClient::UI::Label 3488 new CFPlus::UI::Label
3438 markup => $short, 3489 markup => $short,
3439 tooltip => $item->{tooltip}, 3490 tooltip => $item->{tooltip},
3440 tooltip_font => $::FONT_PROP, 3491 tooltip_font => $::FONT_PROP,
3441 tooltip_width => 0.67, 3492 tooltip_width => 0.67,
3442 fontsize => $item->{fontsize} || $self->{fontsize}, 3493 fontsize => $item->{fontsize} || $self->{fontsize},
3521 $self->SUPER::destroy; 3572 $self->SUPER::destroy;
3522} 3573}
3523 3574
3524############################################################################# 3575#############################################################################
3525 3576
3526package CFClient::UI::Inventory; 3577package CFPlus::UI::Inventory;
3527 3578
3528our @ISA = CFClient::UI::Table::; 3579our @ISA = CFPlus::UI::Table::;
3529 3580
3530sub new { 3581sub new {
3531 my $class = shift; 3582 my $class = shift;
3532 3583
3533 my $self = $class->SUPER::new ( 3584 my $self = $class->SUPER::new (
3534 col_expand => [0, 1, 0], 3585 col_expand => [0, 1, 0],
3586 items => [],
3535 @_, 3587 @_,
3536 ); 3588 );
3537 3589
3590 $self->set_sort_order (undef);
3591
3538 $self 3592 $self
3593}
3594
3595sub update_items {
3596 my ($self) = @_;
3597
3598 $self->clear;
3599
3600 my @item = $self->{sort}->(@{ $self->{items} });
3601
3602 my @adds;
3603 my $row = 0;
3604 for my $item ($self->{sort}->(@{ $self->{items} })) {
3605 CFPlus::Item::update_widgets $item;
3606
3607 push @adds, 0, $row, $item->{face_widget};
3608 push @adds, 1, $row, $item->{desc_widget};
3609 push @adds, 2, $row, $item->{weight_widget};
3610
3611 $row++;
3612 }
3613
3614 $self->add (@adds);
3615}
3616
3617sub set_sort_order {
3618 my ($self, $order) = @_;
3619
3620 $self->{sort} = $order ||= sub {
3621 sort {
3622 $a->{type} <=> $b->{type}
3623 or $a->{name} cmp $b->{name}
3624 } @_
3625 };
3626
3627 $self->update_items;
3539} 3628}
3540 3629
3541sub set_items { 3630sub set_items {
3542 my ($self, $items) = @_; 3631 my ($self, $items) = @_;
3543 3632
3544 $self->clear; 3633 $self->{items} = [$items ? values %$items : ()];
3545 return unless $items; 3634 $self->update_items;
3546
3547 my @items = sort {
3548 ($a->{type} <=> $b->{type})
3549 or ($a->{name} cmp $b->{name})
3550 } values %$items;
3551
3552 $self->{real_items} = \@items;
3553
3554 my $row = 0;
3555 for my $item (@items) {
3556 CFClient::Item::update_widgets $item;
3557
3558 $self->add (0, $row, $item->{face_widget});
3559 $self->add (1, $row, $item->{desc_widget});
3560 $self->add (2, $row, $item->{weight_widget});
3561
3562 $row++;
3563 }
3564} 3635}
3565 3636
3566############################################################################# 3637#############################################################################
3567 3638
3568package CFClient::UI::SpellList; 3639package CFPlus::UI::SpellList;
3569 3640
3570our @ISA = CFClient::UI::Table::; 3641our @ISA = CFPlus::UI::Table::;
3571 3642
3572sub new { 3643sub new {
3573 my $class = shift; 3644 my $class = shift;
3574 3645
3575 my $self = $class->SUPER::new ( 3646 my $self = $class->SUPER::new (
3593 "<b>Damage</b>. The amount of damage the spell deals when it hits.$TOOLTIP_ALL"); 3664 "<b>Damage</b>. The amount of damage the spell deals when it hits.$TOOLTIP_ALL");
3594 3665
3595sub rebuild_spell_list { 3666sub rebuild_spell_list {
3596 my ($self) = @_; 3667 my ($self) = @_;
3597 3668
3598 $CFClient::UI::ROOT->on_refresh ($self => sub { 3669 $CFPlus::UI::ROOT->on_refresh ($self => sub {
3599 $self->clear; 3670 $self->clear;
3600 3671
3601 return unless $::CONN; 3672 return unless $::CONN;
3602 3673
3603 $self->add (1, 0, new CFClient::UI::Label text => "Spell Name", @TOOLTIP_NAME); 3674 $self->add (1, 0, new CFPlus::UI::Label text => "Spell Name", @TOOLTIP_NAME);
3604 $self->add (2, 0, new CFClient::UI::Label text => "Skill", @TOOLTIP_SKILL); 3675 $self->add (2, 0, new CFPlus::UI::Label text => "Skill", @TOOLTIP_SKILL);
3605 $self->add (3, 0, new CFClient::UI::Label text => "Lvl" , @TOOLTIP_LVL); 3676 $self->add (3, 0, new CFPlus::UI::Label text => "Lvl" , @TOOLTIP_LVL);
3606 $self->add (4, 0, new CFClient::UI::Label text => "Sp/Gp", @TOOLTIP_SP); 3677 $self->add (4, 0, new CFPlus::UI::Label text => "Sp/Gp", @TOOLTIP_SP);
3607 $self->add (5, 0, new CFClient::UI::Label text => "Dmg" , @TOOLTIP_DMG); 3678 $self->add (5, 0, new CFPlus::UI::Label text => "Dmg" , @TOOLTIP_DMG);
3608 3679
3609 my $row = 0; 3680 my $row = 0;
3610 3681
3611 for (sort { $a cmp $b } keys %{ $self->{spell} }) { 3682 for (sort { $a cmp $b } keys %{ $self->{spell} }) {
3612 my $spell = $self->{spell}{$_}; 3683 my $spell = $self->{spell}{$_};
3619 if ($ev->{button} == 1) { 3690 if ($ev->{button} == 1) {
3620 $::CONN->user_send ("cast $spell->{name}"); 3691 $::CONN->user_send ("cast $spell->{name}");
3621 } elsif ($ev->{button} == 2) { 3692 } elsif ($ev->{button} == 2) {
3622 $::CONN->user_send ("invoke $spell->{name}"); 3693 $::CONN->user_send ("invoke $spell->{name}");
3623 } elsif ($ev->{button} == 3) { 3694 } elsif ($ev->{button} == 3) {
3624 (new CFClient::UI::Menu 3695 (new CFPlus::UI::Menu
3625 items => [ 3696 items => [
3626 ["bind <i>cast $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }], 3697 ["bind <i>cast $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }],
3627 ["bind <i>invoke $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["invoke $spell->{name}"]) }], 3698 ["bind <i>invoke $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["invoke $spell->{name}"]) }],
3628 ], 3699 ],
3629 )->popup ($ev); 3700 )->popup ($ev);
3635 }; 3706 };
3636 3707
3637 my $tooltip = "$spell->{message}$TOOLTIP_ALL"; 3708 my $tooltip = "$spell->{message}$TOOLTIP_ALL";
3638 3709
3639 #TODO: add path info to tooltip 3710 #TODO: add path info to tooltip
3640 #$self->add (6, $row, new CFClient::UI::Label text => $spell->{path}); 3711 #$self->add (6, $row, new CFPlus::UI::Label text => $spell->{path});
3641 3712
3642 $self->add (0, $row, new CFClient::UI::Face 3713 $self->add (0, $row, new CFPlus::UI::Face
3643 face => $spell->{face}, 3714 face => $spell->{face},
3644 can_hover => 1, 3715 can_hover => 1,
3645 can_events => 1, 3716 can_events => 1,
3646 tooltip => $tooltip, 3717 tooltip => $tooltip,
3647 on_button_down => $spell_cb, 3718 on_button_down => $spell_cb,
3648 ); 3719 );
3649 3720
3650 $self->add (1, $row, new CFClient::UI::Label 3721 $self->add (1, $row, new CFPlus::UI::Label
3651 expand => 1, 3722 expand => 1,
3652 text => $spell->{name}, 3723 text => $spell->{name},
3653 can_hover => 1, 3724 can_hover => 1,
3654 can_events => 1, 3725 can_events => 1,
3655 tooltip => $tooltip, 3726 tooltip => $tooltip,
3656 on_button_down => $spell_cb, 3727 on_button_down => $spell_cb,
3657 ); 3728 );
3658 3729
3659 $self->add (2, $row, new CFClient::UI::Label text => $::CONN->{skill_info}{$spell->{skill}}, @TOOLTIP_SKILL); 3730 $self->add (2, $row, new CFPlus::UI::Label text => $::CONN->{skill_info}{$spell->{skill}}, @TOOLTIP_SKILL);
3660 $self->add (3, $row, new CFClient::UI::Label text => $spell->{level}, @TOOLTIP_LVL); 3731 $self->add (3, $row, new CFPlus::UI::Label text => $spell->{level}, @TOOLTIP_LVL);
3661 $self->add (4, $row, new CFClient::UI::Label text => $spell->{mana} || $spell->{grace}, @TOOLTIP_SP); 3732 $self->add (4, $row, new CFPlus::UI::Label text => $spell->{mana} || $spell->{grace}, @TOOLTIP_SP);
3662 $self->add (5, $row, new CFClient::UI::Label text => $spell->{damage}, @TOOLTIP_DMG); 3733 $self->add (5, $row, new CFPlus::UI::Label text => $spell->{damage}, @TOOLTIP_DMG);
3663 } 3734 }
3664 }); 3735 });
3665} 3736}
3666 3737
3667sub add_spell { 3738sub add_spell {
3685 $self->rebuild_spell_list; 3756 $self->rebuild_spell_list;
3686} 3757}
3687 3758
3688############################################################################# 3759#############################################################################
3689 3760
3690package CFClient::UI::Root; 3761package CFPlus::UI::Root;
3691 3762
3692our @ISA = CFClient::UI::Container::; 3763our @ISA = CFPlus::UI::Container::;
3693 3764
3694use List::Util qw(min max); 3765use List::Util qw(min max);
3695 3766
3696use CFClient::OpenGL; 3767use CFPlus::OpenGL;
3697 3768
3698sub new { 3769sub new {
3699 my $class = shift; 3770 my $class = shift;
3700 3771
3701 my $self = $class->SUPER::new ( 3772 my $self = $class->SUPER::new (
3880 $h = 0 if $h < 0; 3951 $h = 0 if $h < 0;
3881 3952
3882 $w = max $widget->{min_w}, $w; 3953 $w = max $widget->{min_w}, $w;
3883 $h = max $widget->{min_h}, $h; 3954 $h = max $widget->{min_h}, $h;
3884 3955
3956# $w = min $self->{w} - $widget->{x}, $w if $self->{w};
3957# $h = min $self->{h} - $widget->{y}, $h if $self->{h};
3958
3885 $w = min $widget->{max_w}, $w if exists $widget->{max_w}; 3959 $w = min $widget->{max_w}, $w if exists $widget->{max_w};
3886 $h = min $widget->{max_h}, $h if exists $widget->{max_h}; 3960 $h = min $widget->{max_h}, $h if exists $widget->{max_h};
3887 3961
3888 $w = int $w + 0.5; 3962 $w = int $w + 0.5;
3889 $h = int $h + 0.5; 3963 $h = int $h + 0.5;
3915 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; 3989 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
3916 glMatrixMode GL_MODELVIEW; 3990 glMatrixMode GL_MODELVIEW;
3917 glLoadIdentity; 3991 glLoadIdentity;
3918 3992
3919 { 3993 {
3920 package CFClient::UI::Base; 3994 package CFPlus::UI::Base;
3921 3995
3922 ($draw_x, $draw_y, $draw_w, $draw_h) = 3996 ($draw_x, $draw_y, $draw_w, $draw_h) =
3923 (0, 0, $self->{w}, $self->{h}); 3997 (0, 0, $self->{w}, $self->{h});
3924 } 3998 }
3925 3999
3926 $self->_draw; 4000 $self->_draw;
3927} 4001}
3928 4002
3929############################################################################# 4003#############################################################################
3930 4004
3931package CFClient::UI; 4005package CFPlus::UI;
3932 4006
3933$ROOT = new CFClient::UI::Root; 4007$ROOT = new CFPlus::UI::Root;
3934$TOOLTIP = new CFClient::UI::Tooltip z => 900; 4008$TOOLTIP = new CFPlus::UI::Tooltip z => 900;
3935 4009
39361 40101
3937 4011

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines