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.339 by root, Sun Jul 30 12:15:19 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;
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, CFClient::ceil $h * $self->{aspect}; 372 $w = List::Util::min $w, CFPlus::ceil $h * $self->{aspect};
373 $h = List::Util::min $h, CFClient::ceil $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 {
497sub connect { 497sub connect {
498 my ($self, $signal, $cb) = @_; 498 my ($self, $signal, $cb) = @_;
499 499
500 push @{ $self->{signal_cb}{$signal} }, $cb; 500 push @{ $self->{signal_cb}{$signal} }, $cb;
501 501
502 defined wantarray and CFClient::guard { 502 defined wantarray and CFPlus::guard {
503 @{ $self->{signal_cb}{$signal} } = grep $_ != $cb, 503 @{ $self->{signal_cb}{$signal} } = grep $_ != $cb,
504 @{ $self->{signal_cb}{$signal} }; 504 @{ $self->{signal_cb}{$signal} };
505 } 505 }
506} 506}
507 507
619 glVertex $self->{w} - 1, 0; 619 glVertex $self->{w} - 1, 0;
620 glVertex $self->{w} - 1, $self->{h} - 1; 620 glVertex $self->{w} - 1, $self->{h} - 1;
621 glVertex 0 , $self->{h} - 1; 621 glVertex 0 , $self->{h} - 1;
622 glEnd; 622 glEnd;
623 glPopMatrix; 623 glPopMatrix;
624 #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;
625 } 625 }
626 626
627 $self->_draw; 627 $self->_draw;
628 glPopMatrix; 628 glPopMatrix;
629} 629}
635} 635}
636 636
637sub DESTROY { 637sub DESTROY {
638 my ($self) = @_; 638 my ($self) = @_;
639 639
640 return if CFClient::in_destruct; 640 return if CFPlus::in_destruct;
641 641
642 delete $WIDGET{$self+0}; 642 delete $WIDGET{$self+0};
643 643
644 eval { $self->destroy }; 644 eval { $self->destroy };
645 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; 645 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/;
646} 646}
647 647
648############################################################################# 648#############################################################################
649 649
650package CFClient::UI::DrawBG; 650package CFPlus::UI::DrawBG;
651 651
652our @ISA = CFClient::UI::Base::; 652our @ISA = CFPlus::UI::Base::;
653 653
654use strict; 654use strict;
655use CFClient::OpenGL; 655use CFPlus::OpenGL;
656 656
657sub new { 657sub new {
658 my $class = shift; 658 my $class = shift;
659 659
660 # range [value, low, high, page] 660 # range [value, low, high, page]
691 } 691 }
692} 692}
693 693
694############################################################################# 694#############################################################################
695 695
696package CFClient::UI::Empty; 696package CFPlus::UI::Empty;
697 697
698our @ISA = CFClient::UI::Base::; 698our @ISA = CFPlus::UI::Base::;
699 699
700sub new { 700sub new {
701 my ($class, %arg) = @_; 701 my ($class, %arg) = @_;
702 $class->SUPER::new (can_events => 0, %arg); 702 $class->SUPER::new (can_events => 0, %arg);
703} 703}
710 710
711sub draw { } 711sub draw { }
712 712
713############################################################################# 713#############################################################################
714 714
715package CFClient::UI::Container; 715package CFPlus::UI::Container;
716 716
717our @ISA = CFClient::UI::Base::; 717our @ISA = CFPlus::UI::Base::;
718 718
719sub new { 719sub new {
720 my ($class, %arg) = @_; 720 my ($class, %arg) = @_;
721 721
722 my $children = delete $arg{children}; 722 my $children = delete $arg{children};
808 $_->draw for @{$self->{children}}; 808 $_->draw for @{$self->{children}};
809} 809}
810 810
811############################################################################# 811#############################################################################
812 812
813package CFClient::UI::Bin; 813package CFPlus::UI::Bin;
814 814
815our @ISA = CFClient::UI::Container::; 815our @ISA = CFPlus::UI::Container::;
816 816
817sub new { 817sub new {
818 my ($class, %arg) = @_; 818 my ($class, %arg) = @_;
819 819
820 my $child = (delete $arg{child}) || new CFClient::UI::Empty::; 820 my $child = (delete $arg{child}) || new CFPlus::UI::Empty::;
821 821
822 $class->SUPER::new (children => [$child], %arg) 822 $class->SUPER::new (children => [$child], %arg)
823} 823}
824 824
825sub add { 825sub add {
832sub remove { 832sub remove {
833 my ($self, $widget) = @_; 833 my ($self, $widget) = @_;
834 834
835 $self->SUPER::remove ($widget); 835 $self->SUPER::remove ($widget);
836 836
837 $self->{children} = [new CFClient::UI::Empty] 837 $self->{children} = [new CFPlus::UI::Empty]
838 unless @{$self->{children}}; 838 unless @{$self->{children}};
839} 839}
840 840
841sub child { $_[0]->{children}[0] } 841sub child { $_[0]->{children}[0] }
842 842
854 854
855############################################################################# 855#############################################################################
856 856
857# back-buffered drawing area 857# back-buffered drawing area
858 858
859package CFClient::UI::Window; 859package CFPlus::UI::Window;
860 860
861our @ISA = CFClient::UI::Bin::; 861our @ISA = CFPlus::UI::Bin::;
862 862
863use CFClient::OpenGL; 863use CFPlus::OpenGL;
864 864
865sub new { 865sub new {
866 my ($class, %arg) = @_; 866 my ($class, %arg) = @_;
867 867
868 my $self = $class->SUPER::new (%arg); 868 my $self = $class->SUPER::new (%arg);
890} 890}
891 891
892sub render_child { 892sub render_child {
893 my ($self) = @_; 893 my ($self) = @_;
894 894
895 $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 {
896 glClearColor 0, 0, 0, 0; 896 glClearColor 0, 0, 0, 0;
897 glClear GL_COLOR_BUFFER_BIT; 897 glClear GL_COLOR_BUFFER_BIT;
898 898
899 { 899 {
900 package CFClient::UI::Base; 900 package CFPlus::UI::Base;
901 901
902 ($draw_x, $draw_y, $draw_w, $draw_h) = 902 ($draw_x, $draw_y, $draw_w, $draw_h) =
903 (0, 0, $self->{w}, $self->{h}); 903 (0, 0, $self->{w}, $self->{h});
904 } 904 }
905 905
924 glDisable GL_TEXTURE_2D; 924 glDisable GL_TEXTURE_2D;
925} 925}
926 926
927############################################################################# 927#############################################################################
928 928
929package CFClient::UI::ViewPort; 929package CFPlus::UI::ViewPort;
930 930
931our @ISA = CFClient::UI::Window::; 931our @ISA = CFPlus::UI::Window::;
932 932
933sub new { 933sub new {
934 my $class = shift; 934 my $class = shift;
935 935
936 $class->SUPER::new ( 936 $class->SUPER::new (
996 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} 996 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w}
997 && $y >= $self->{y} && $y < $self->{y} + $self->{h} 997 && $y >= $self->{y} && $y < $self->{y} + $self->{h}
998 ) { 998 ) {
999 $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})
1000 } else { 1000 } else {
1001 $self->CFClient::UI::Base::find_widget ($x, $y) 1001 $self->CFPlus::UI::Base::find_widget ($x, $y)
1002 } 1002 }
1003} 1003}
1004 1004
1005sub _render { 1005sub _render {
1006 my ($self) = @_; 1006 my ($self) = @_;
1007 1007
1008 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};
1009 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};
1010 1010
1011 CFClient::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; 1011 CFPlus::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y};
1012 1012
1013 $self->SUPER::_render; 1013 $self->SUPER::_render;
1014} 1014}
1015 1015
1016############################################################################# 1016#############################################################################
1017 1017
1018package CFClient::UI::ScrolledWindow; 1018package CFPlus::UI::ScrolledWindow;
1019 1019
1020our @ISA = CFClient::UI::HBox::; 1020our @ISA = CFPlus::UI::HBox::;
1021 1021
1022sub new { 1022sub new {
1023 my ($class, %arg) = @_; 1023 my ($class, %arg) = @_;
1024 1024
1025 my $child = delete $arg{child}; 1025 my $child = delete $arg{child};
1026 1026
1027 my $self; 1027 my $self;
1028 1028
1029 my $slider = new CFClient::UI::Slider 1029 my $slider = new CFPlus::UI::Slider
1030 vertical => 1, 1030 vertical => 1,
1031 range => [0, 0, 1, 0.01], # HACK fix 1031 range => [0, 0, 1, 0.01], # HACK fix
1032 on_changed => sub { 1032 on_changed => sub {
1033 $self->{vp}->set_offset (0, $_[1]); 1033 $self->{vp}->set_offset (0, $_[1]);
1034 }, 1034 },
1035 ; 1035 ;
1036 1036
1037 $self = $class->SUPER::new ( 1037 $self = $class->SUPER::new (
1038 vp => (new CFClient::UI::ViewPort expand => 1), 1038 vp => (new CFPlus::UI::ViewPort expand => 1),
1039 can_events => 1, 1039 can_events => 1,
1040 slider => $slider, 1040 slider => $slider,
1041 %arg, 1041 %arg,
1042 ); 1042 );
1043 1043
1087 $self->SUPER::invoke_size_allocate ($w, $h) 1087 $self->SUPER::invoke_size_allocate ($w, $h)
1088} 1088}
1089 1089
1090############################################################################# 1090#############################################################################
1091 1091
1092package CFClient::UI::Frame; 1092package CFPlus::UI::Frame;
1093 1093
1094our @ISA = CFClient::UI::Bin::; 1094our @ISA = CFPlus::UI::Bin::;
1095 1095
1096use CFClient::OpenGL; 1096use CFPlus::OpenGL;
1097 1097
1098sub new { 1098sub new {
1099 my $class = shift; 1099 my $class = shift;
1100 1100
1101 $class->SUPER::new ( 1101 $class->SUPER::new (
1127 $self->SUPER::_draw; 1127 $self->SUPER::_draw;
1128} 1128}
1129 1129
1130############################################################################# 1130#############################################################################
1131 1131
1132package CFClient::UI::FancyFrame; 1132package CFPlus::UI::FancyFrame;
1133 1133
1134our @ISA = CFClient::UI::Bin::; 1134our @ISA = CFPlus::UI::Bin::;
1135 1135
1136use CFClient::OpenGL; 1136use CFPlus::OpenGL;
1137 1137
1138my $bg = 1138my $bg =
1139 new_from_file CFClient::Texture CFClient::find_rcfile "d1_bg.png", 1139 new_from_file CFPlus::Texture CFPlus::find_rcfile "d1_bg.png",
1140 mipmap => 1, wrap => 1; 1140 mipmap => 1, wrap => 1;
1141 1141
1142my @border = 1142my @border =
1143 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1143 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
1144 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);
1145 1145
1146sub new { 1146sub new {
1147 my ($class, %arg) = @_; 1147 my ($class, %arg) = @_;
1148 1148
1154 min_w => 64, 1154 min_w => 64,
1155 min_h => 32, 1155 min_h => 32,
1156 %arg, 1156 %arg,
1157 ); 1157 );
1158 1158
1159 $self->{title_widget} = new CFClient::UI::Label 1159 $self->{title_widget} = new CFPlus::UI::Label
1160 align => 0, 1160 align => 0,
1161 valign => 1, 1161 valign => 1,
1162 text => $self->{title}, 1162 text => $self->{title},
1163 fontsize => $self->{border}, 1163 fontsize => $self->{border},
1164 if exists $self->{title}; 1164 if exists $self->{title};
1165 1165
1166 if ($self->{has_close_button}) { 1166 if ($self->{has_close_button}) {
1167 $self->{close_button} = 1167 $self->{close_button} =
1168 new CFClient::UI::ImageButton 1168 new CFPlus::UI::ImageButton
1169 path => 'x1_close.png', 1169 path => 'x1_close.png',
1170 on_activate => sub { $self->emit ("delete") }; 1170 on_activate => sub { $self->emit ("delete") };
1171 1171
1172 $self->CFClient::UI::Container::add ($self->{close_button}); 1172 $self->CFPlus::UI::Container::add ($self->{close_button});
1173 } 1173 }
1174 1174
1175 $self 1175 $self
1176} 1176}
1177 1177
1178sub add { 1178sub add {
1179 my ($self, @widgets) = @_; 1179 my ($self, @widgets) = @_;
1180 1180
1181 $self->SUPER::add (@widgets); 1181 $self->SUPER::add (@widgets);
1182 $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};
1183 $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};
1184} 1184}
1185 1185
1186sub border { 1186sub border {
1187 int $_[0]{border} * $::FONTSIZE 1187 int $_[0]{border} * $::FONTSIZE
1188} 1188}
1350 if $self->{close_button}; 1350 if $self->{close_button};
1351} 1351}
1352 1352
1353############################################################################# 1353#############################################################################
1354 1354
1355package CFClient::UI::Table; 1355package CFPlus::UI::Table;
1356 1356
1357our @ISA = CFClient::UI::Base::; 1357our @ISA = CFPlus::UI::Base::;
1358 1358
1359use List::Util qw(max sum); 1359use List::Util qw(max sum);
1360 1360
1361use CFClient::OpenGL; 1361use CFPlus::OpenGL;
1362 1362
1363sub new { 1363sub new {
1364 my $class = shift; 1364 my $class = shift;
1365 1365
1366 $class->SUPER::new ( 1366 $class->SUPER::new (
1456 1456
1457 # linearly scale sizes 1457 # linearly scale sizes
1458 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; 1458 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws;
1459 $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs; 1459 $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs;
1460 1460
1461 CFClient::UI::harmonize $ws; 1461 CFPlus::UI::harmonize $ws;
1462 CFClient::UI::harmonize $hs; 1462 CFPlus::UI::harmonize $hs;
1463 1463
1464 my $y; 1464 my $y;
1465 1465
1466 for my $r (0 .. $#{$self->{children}}) { 1466 for my $r (0 .. $#{$self->{children}}) {
1467 my $row = $self->{children}[$r] 1467 my $row = $self->{children}[$r]
1510 } 1510 }
1511} 1511}
1512 1512
1513############################################################################# 1513#############################################################################
1514 1514
1515package CFClient::UI::Box; 1515package CFPlus::UI::Box;
1516 1516
1517our @ISA = CFClient::UI::Container::; 1517our @ISA = CFPlus::UI::Container::;
1518 1518
1519sub size_request { 1519sub size_request {
1520 my ($self) = @_; 1520 my ($self) = @_;
1521 1521
1522 $self->{vertical} 1522 $self->{vertical}
1555 $req[$_] += $space * $children[$_]{expand} 1555 $req[$_] += $space * $children[$_]{expand}
1556 for 0 .. $#children; 1556 for 0 .. $#children;
1557 } 1557 }
1558 } 1558 }
1559 1559
1560 CFClient::UI::harmonize \@req; 1560 CFPlus::UI::harmonize \@req;
1561 1561
1562 my $pos = 0; 1562 my $pos = 0;
1563 for (0 .. $#children) { 1563 for (0 .. $#children) {
1564 my $alloc = $req[$_]; 1564 my $alloc = $req[$_];
1565 $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));
1570 1 1570 1
1571} 1571}
1572 1572
1573############################################################################# 1573#############################################################################
1574 1574
1575package CFClient::UI::HBox; 1575package CFPlus::UI::HBox;
1576 1576
1577our @ISA = CFClient::UI::Box::; 1577our @ISA = CFPlus::UI::Box::;
1578 1578
1579sub new { 1579sub new {
1580 my $class = shift; 1580 my $class = shift;
1581 1581
1582 $class->SUPER::new ( 1582 $class->SUPER::new (
1585 ) 1585 )
1586} 1586}
1587 1587
1588############################################################################# 1588#############################################################################
1589 1589
1590package CFClient::UI::VBox; 1590package CFPlus::UI::VBox;
1591 1591
1592our @ISA = CFClient::UI::Box::; 1592our @ISA = CFPlus::UI::Box::;
1593 1593
1594sub new { 1594sub new {
1595 my $class = shift; 1595 my $class = shift;
1596 1596
1597 $class->SUPER::new ( 1597 $class->SUPER::new (
1600 ) 1600 )
1601} 1601}
1602 1602
1603############################################################################# 1603#############################################################################
1604 1604
1605package CFClient::UI::Label; 1605package CFPlus::UI::Label;
1606 1606
1607our @ISA = CFClient::UI::DrawBG::; 1607our @ISA = CFPlus::UI::DrawBG::;
1608 1608
1609use CFClient::OpenGL; 1609use CFPlus::OpenGL;
1610 1610
1611sub new { 1611sub new {
1612 my ($class, %arg) = @_; 1612 my ($class, %arg) = @_;
1613 1613
1614 my $self = $class->SUPER::new ( 1614 my $self = $class->SUPER::new (
1618 #font => default_font 1618 #font => default_font
1619 #text => initial text 1619 #text => initial text
1620 #markup => initial narkup 1620 #markup => initial narkup
1621 #max_w => maximum pixel width 1621 #max_w => maximum pixel width
1622 ellipsise => 3, # end 1622 ellipsise => 3, # end
1623 layout => (new CFClient::Layout), 1623 layout => (new CFPlus::Layout),
1624 fontsize => 1, 1624 fontsize => 1,
1625 align => -1, 1625 align => -1,
1626 valign => -1, 1626 valign => -1,
1627 padding_x => 2, 1627 padding_x => 2,
1628 padding_y => 2, 1628 padding_y => 2,
1629 can_events => 0, 1629 can_events => 0,
1630 %arg 1630 %arg
1631 ); 1631 );
1632 1632
1633 if (exists $self->{template}) { 1633 if (exists $self->{template}) {
1634 my $layout = new CFClient::Layout; 1634 my $layout = new CFPlus::Layout;
1635 $layout->set_text (delete $self->{template}); 1635 $layout->set_text (delete $self->{template});
1636 $self->{template} = $layout; 1636 $self->{template} = $layout;
1637 } 1637 }
1638 1638
1639 if (exists $self->{markup}) { 1639 if (exists $self->{markup}) {
1782 $self->{layout}->render ($self->{ox}, $self->{oy}); 1782 $self->{layout}->render ($self->{ox}, $self->{oy});
1783} 1783}
1784 1784
1785############################################################################# 1785#############################################################################
1786 1786
1787package CFClient::UI::EntryBase; 1787package CFPlus::UI::EntryBase;
1788 1788
1789our @ISA = CFClient::UI::Label::; 1789our @ISA = CFPlus::UI::Label::;
1790 1790
1791use CFClient::OpenGL; 1791use CFPlus::OpenGL;
1792 1792
1793sub new { 1793sub new {
1794 my $class = shift; 1794 my $class = shift;
1795 1795
1796 $class->SUPER::new ( 1796 $class->SUPER::new (
1858 1858
1859 if ($uni == 8) { 1859 if ($uni == 8) {
1860 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 1860 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
1861 } elsif ($uni == 127) { 1861 } elsif ($uni == 127) {
1862 substr $text, $self->{cursor}, 1, ""; 1862 substr $text, $self->{cursor}, 1, "";
1863 } elsif ($sym == CFClient::SDLK_LEFT) { 1863 } elsif ($sym == CFPlus::SDLK_LEFT) {
1864 --$self->{cursor} if $self->{cursor}; 1864 --$self->{cursor} if $self->{cursor};
1865 } elsif ($sym == CFClient::SDLK_RIGHT) { 1865 } elsif ($sym == CFPlus::SDLK_RIGHT) {
1866 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 1866 ++$self->{cursor} if $self->{cursor} < length $self->{text};
1867 } elsif ($sym == CFClient::SDLK_HOME) { 1867 } elsif ($sym == CFPlus::SDLK_HOME) {
1868 $self->{cursor} = 0; 1868 $self->{cursor} = 0;
1869 } elsif ($sym == CFClient::SDLK_END) { 1869 } elsif ($sym == CFPlus::SDLK_END) {
1870 $self->{cursor} = length $text; 1870 $self->{cursor} = length $text;
1871 } elsif ($uni == 27) { 1871 } elsif ($uni == 27) {
1872 $self->emit ('escape'); 1872 $self->emit ('escape');
1873 } elsif ($uni) { 1873 } elsif ($uni) {
1874 substr $text, $self->{cursor}++, 0, chr $uni; 1874 substr $text, $self->{cursor}++, 0, chr $uni;
1956 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};
1957 glEnd; 1957 glEnd;
1958 } 1958 }
1959} 1959}
1960 1960
1961package CFClient::UI::Entry; 1961package CFPlus::UI::Entry;
1962 1962
1963our @ISA = CFClient::UI::EntryBase::; 1963our @ISA = CFPlus::UI::EntryBase::;
1964 1964
1965use CFClient::OpenGL; 1965use CFPlus::OpenGL;
1966 1966
1967sub invoke_key_down { 1967sub invoke_key_down {
1968 my ($self, $ev) = @_; 1968 my ($self, $ev) = @_;
1969 1969
1970 my $sym = $ev->{sym}; 1970 my $sym = $ev->{sym};
1976 $self->{history_pointer} = -1; 1976 $self->{history_pointer} = -1;
1977 $self->{history_saveback} = ''; 1977 $self->{history_saveback} = '';
1978 $self->emit (activate => $txt); 1978 $self->emit (activate => $txt);
1979 $self->update; 1979 $self->update;
1980 1980
1981 } elsif ($sym == CFClient::SDLK_UP) { 1981 } elsif ($sym == CFPlus::SDLK_UP) {
1982 if ($self->{history_pointer} < 0) { 1982 if ($self->{history_pointer} < 0) {
1983 $self->{history_saveback} = $self->get_text; 1983 $self->{history_saveback} = $self->get_text;
1984 } 1984 }
1985 if (@{$self->{history} || []} > 0) { 1985 if (@{$self->{history} || []} > 0) {
1986 $self->{history_pointer}++; 1986 $self->{history_pointer}++;
1988 $self->{history_pointer} = @{$self->{history} || []} - 1; 1988 $self->{history_pointer} = @{$self->{history} || []} - 1;
1989 } 1989 }
1990 $self->set_text ($self->{history}->[$self->{history_pointer}]); 1990 $self->set_text ($self->{history}->[$self->{history_pointer}]);
1991 } 1991 }
1992 1992
1993 } elsif ($sym == CFClient::SDLK_DOWN) { 1993 } elsif ($sym == CFPlus::SDLK_DOWN) {
1994 $self->{history_pointer}--; 1994 $self->{history_pointer}--;
1995 $self->{history_pointer} = -1 if $self->{history_pointer} < 0; 1995 $self->{history_pointer} = -1 if $self->{history_pointer} < 0;
1996 1996
1997 if ($self->{history_pointer} >= 0) { 1997 if ($self->{history_pointer} >= 0) {
1998 $self->set_text ($self->{history}->[$self->{history_pointer}]); 1998 $self->set_text ($self->{history}->[$self->{history_pointer}]);
2007 1 2007 1
2008} 2008}
2009 2009
2010############################################################################# 2010#############################################################################
2011 2011
2012package CFClient::UI::Button; 2012package CFPlus::UI::Button;
2013 2013
2014our @ISA = CFClient::UI::Label::; 2014our @ISA = CFPlus::UI::Label::;
2015 2015
2016use CFClient::OpenGL; 2016use CFPlus::OpenGL;
2017 2017
2018my @tex = 2018my @tex =
2019 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2019 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2020 qw(b1_button_active.png); 2020 qw(b1_button_active.png);
2021 2021
2022sub new { 2022sub new {
2023 my $class = shift; 2023 my $class = shift;
2024 2024
2061 $self->SUPER::_draw; 2061 $self->SUPER::_draw;
2062} 2062}
2063 2063
2064############################################################################# 2064#############################################################################
2065 2065
2066package CFClient::UI::CheckBox; 2066package CFPlus::UI::CheckBox;
2067 2067
2068our @ISA = CFClient::UI::DrawBG::; 2068our @ISA = CFPlus::UI::DrawBG::;
2069 2069
2070my @tex = 2070my @tex =
2071 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2071 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2072 qw(c1_checkbox_bg.png c1_checkbox_active.png); 2072 qw(c1_checkbox_bg.png c1_checkbox_active.png);
2073 2073
2074use CFClient::OpenGL; 2074use CFPlus::OpenGL;
2075 2075
2076sub new { 2076sub new {
2077 my $class = shift; 2077 my $class = shift;
2078 2078
2079 $class->SUPER::new ( 2079 $class->SUPER::new (
2136 glDisable GL_TEXTURE_2D; 2136 glDisable GL_TEXTURE_2D;
2137} 2137}
2138 2138
2139############################################################################# 2139#############################################################################
2140 2140
2141package CFClient::UI::Image; 2141package CFPlus::UI::Image;
2142 2142
2143our @ISA = CFClient::UI::Base::; 2143our @ISA = CFPlus::UI::Base::;
2144 2144
2145use CFClient::OpenGL; 2145use CFPlus::OpenGL;
2146 2146
2147our %texture_cache; 2147our %texture_cache;
2148 2148
2149sub new { 2149sub new {
2150 my $class = shift; 2150 my $class = shift;
2156 2156
2157 $self->{path} || $self->{tex} 2157 $self->{path} || $self->{tex}
2158 or Carp::croak "'path' or 'tex' attributes required"; 2158 or Carp::croak "'path' or 'tex' attributes required";
2159 2159
2160 $self->{tex} ||= $texture_cache{$self->{path}} ||= 2160 $self->{tex} ||= $texture_cache{$self->{path}} ||=
2161 new_from_file CFClient::Texture CFClient::find_rcfile $self->{path}, mipmap => 1; 2161 new_from_file CFPlus::Texture CFPlus::find_rcfile $self->{path}, mipmap => 1;
2162 2162
2163 Scalar::Util::weaken $texture_cache{$self->{path}}; 2163 Scalar::Util::weaken $texture_cache{$self->{path}};
2164 2164
2165 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; 2165 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2166 2166
2169 2169
2170sub STORABLE_freeze { 2170sub STORABLE_freeze {
2171 my ($self, $cloning) = @_; 2171 my ($self, $cloning) = @_;
2172 2172
2173 $self->{path} 2173 $self->{path}
2174 or die "cannot serialise CFClient::UI::Image on non-loadable images\n"; 2174 or die "cannot serialise CFPlus::UI::Image on non-loadable images\n";
2175 2175
2176 $self->{path} 2176 $self->{path}
2177} 2177}
2178 2178
2179sub STORABLE_attach { 2179sub STORABLE_attach {
2210 glDisable GL_TEXTURE_2D; 2210 glDisable GL_TEXTURE_2D;
2211} 2211}
2212 2212
2213############################################################################# 2213#############################################################################
2214 2214
2215package CFClient::UI::ImageButton; 2215package CFPlus::UI::ImageButton;
2216 2216
2217our @ISA = CFClient::UI::Image::; 2217our @ISA = CFPlus::UI::Image::;
2218 2218
2219use CFClient::OpenGL; 2219use CFPlus::OpenGL;
2220 2220
2221my %textures; 2221my %textures;
2222 2222
2223sub new { 2223sub new {
2224 my $class = shift; 2224 my $class = shift;
2246 1 2246 1
2247} 2247}
2248 2248
2249############################################################################# 2249#############################################################################
2250 2250
2251package CFClient::UI::VGauge; 2251package CFPlus::UI::VGauge;
2252 2252
2253our @ISA = CFClient::UI::Base::; 2253our @ISA = CFPlus::UI::Base::;
2254 2254
2255use List::Util qw(min max); 2255use List::Util qw(min max);
2256 2256
2257use CFClient::OpenGL; 2257use CFPlus::OpenGL;
2258 2258
2259my %tex = ( 2259my %tex = (
2260 food => [ 2260 food => [
2261 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2261 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2262 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 2262 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
2263 ], 2263 ],
2264 grace => [ 2264 grace => [
2265 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2265 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2266 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/
2267 ], 2267 ],
2268 hp => [ 2268 hp => [
2269 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2269 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2270 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 2270 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
2271 ], 2271 ],
2272 mana => [ 2272 mana => [
2273 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2273 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2274 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/
2275 ], 2275 ],
2276); 2276);
2277 2277
2278# eg. VGauge->new (gauge => 'food'), default gauge: food 2278# eg. VGauge->new (gauge => 'food'), default gauge: food
2381 glDisable GL_TEXTURE_2D; 2381 glDisable GL_TEXTURE_2D;
2382} 2382}
2383 2383
2384############################################################################# 2384#############################################################################
2385 2385
2386package CFClient::UI::Gauge; 2386package CFPlus::UI::Gauge;
2387 2387
2388our @ISA = CFClient::UI::VBox::; 2388our @ISA = CFPlus::UI::VBox::;
2389 2389
2390sub new { 2390sub new {
2391 my ($class, %arg) = @_; 2391 my ($class, %arg) = @_;
2392 2392
2393 my $self = $class->SUPER::new ( 2393 my $self = $class->SUPER::new (
2395 can_hover => 1, 2395 can_hover => 1,
2396 can_events => 1, 2396 can_events => 1,
2397 %arg, 2397 %arg,
2398 ); 2398 );
2399 2399
2400 $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");
2401 $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);
2402 $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");
2403 2403
2404 $self 2404 $self
2405} 2405}
2406 2406
2407sub set_fontsize { 2407sub set_fontsize {
2428 $self->{value}->set_text ($val); 2428 $self->{value}->set_text ($val);
2429} 2429}
2430 2430
2431############################################################################# 2431#############################################################################
2432 2432
2433package CFClient::UI::Slider; 2433package CFPlus::UI::Slider;
2434 2434
2435use strict; 2435use strict;
2436 2436
2437use CFClient::OpenGL; 2437use CFPlus::OpenGL;
2438 2438
2439our @ISA = CFClient::UI::DrawBG::; 2439our @ISA = CFPlus::UI::DrawBG::;
2440 2440
2441my @tex = 2441my @tex =
2442 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 2442 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_ }
2443 qw(s1_slider.png s1_slider_bg.png); 2443 qw(s1_slider.png s1_slider_bg.png);
2444 2444
2445sub new { 2445sub new {
2446 my $class = shift; 2446 my $class = shift;
2447 2447
2602 glDisable GL_TEXTURE_2D; 2602 glDisable GL_TEXTURE_2D;
2603} 2603}
2604 2604
2605############################################################################# 2605#############################################################################
2606 2606
2607package CFClient::UI::ValSlider; 2607package CFPlus::UI::ValSlider;
2608 2608
2609our @ISA = CFClient::UI::HBox::; 2609our @ISA = CFPlus::UI::HBox::;
2610 2610
2611sub new { 2611sub new {
2612 my ($class, %arg) = @_; 2612 my ($class, %arg) = @_;
2613 2613
2614 my $range = delete $arg{range}; 2614 my $range = delete $arg{range};
2615 2615
2616 my $self = $class->SUPER::new ( 2616 my $self = $class->SUPER::new (
2617 slider => (new CFClient::UI::Slider expand => 1, range => $range), 2617 slider => (new CFPlus::UI::Slider expand => 1, range => $range),
2618 entry => (new CFClient::UI::Label text => "", template => delete $arg{template}), 2618 entry => (new CFPlus::UI::Label text => "", template => delete $arg{template}),
2619 to_value => sub { shift }, 2619 to_value => sub { shift },
2620 from_value => sub { shift }, 2620 from_value => sub { shift },
2621 %arg, 2621 %arg,
2622 ); 2622 );
2623 2623
2643sub set_range { shift->{slider}->set_range (@_) } 2643sub set_range { shift->{slider}->set_range (@_) }
2644sub set_value { shift->{slider}->set_value (@_) } 2644sub set_value { shift->{slider}->set_value (@_) }
2645 2645
2646############################################################################# 2646#############################################################################
2647 2647
2648package CFClient::UI::TextScroller; 2648package CFPlus::UI::TextScroller;
2649 2649
2650our @ISA = CFClient::UI::HBox::; 2650our @ISA = CFPlus::UI::HBox::;
2651 2651
2652use CFClient::OpenGL; 2652use CFPlus::OpenGL;
2653 2653
2654sub new { 2654sub new {
2655 my $class = shift; 2655 my $class = shift;
2656 2656
2657 my $self = $class->SUPER::new ( 2657 my $self = $class->SUPER::new (
2659 can_events => 1, 2659 can_events => 1,
2660 indent => 0, 2660 indent => 0,
2661 #font => default_font 2661 #font => default_font
2662 @_, 2662 @_,
2663 2663
2664 layout => (new CFClient::Layout), 2664 layout => (new CFPlus::Layout),
2665 par => [], 2665 par => [],
2666 height => 0, 2666 height => 0,
2667 children => [ 2667 children => [
2668 (new CFClient::UI::Empty expand => 1), 2668 (new CFPlus::UI::Empty expand => 1),
2669 (new CFClient::UI::Slider vertical => 1), 2669 (new CFPlus::UI::Slider vertical => 1),
2670 ], 2670 ],
2671 ); 2671 );
2672 2672
2673 $self->{children}[1]->connect (changed => sub { $self->update }); 2673 $self->{children}[1]->connect (changed => sub { $self->update });
2674 2674
2830 2830
2831 if (delete $self->{scroll_to_bottom}) { 2831 if (delete $self->{scroll_to_bottom}) {
2832 $self->{children}[1]->set_value (1e10); 2832 $self->{children}[1]->set_value (1e10);
2833 } 2833 }
2834 2834
2835 $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { 2835 $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub {
2836 glClearColor 0, 0, 0, 0; 2836 glClearColor 0, 0, 0, 0;
2837 glClear GL_COLOR_BUFFER_BIT; 2837 glClear GL_COLOR_BUFFER_BIT;
2838 2838
2839 my $top = int $self->{children}[1]{range}[0]; 2839 my $top = int $self->{children}[1]{range}[0];
2840 2840
2893 $self->{children}[1]->draw; 2893 $self->{children}[1]->draw;
2894} 2894}
2895 2895
2896############################################################################# 2896#############################################################################
2897 2897
2898package CFClient::UI::Animator; 2898package CFPlus::UI::Animator;
2899 2899
2900use CFClient::OpenGL; 2900use CFPlus::OpenGL;
2901 2901
2902our @ISA = CFClient::UI::Bin::; 2902our @ISA = CFPlus::UI::Bin::;
2903 2903
2904sub moveto { 2904sub moveto {
2905 my ($self, $x, $y) = @_; 2905 my ($self, $x, $y) = @_;
2906 2906
2907 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 2907 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
2935 glPopMatrix; 2935 glPopMatrix;
2936} 2936}
2937 2937
2938############################################################################# 2938#############################################################################
2939 2939
2940package CFClient::UI::Flopper; 2940package CFPlus::UI::Flopper;
2941 2941
2942our @ISA = CFClient::UI::Button::; 2942our @ISA = CFPlus::UI::Button::;
2943 2943
2944sub new { 2944sub new {
2945 my $class = shift; 2945 my $class = shift;
2946 2946
2947 my $self = $class->SUPER::new ( 2947 my $self = $class->SUPER::new (
2959 $self->{other}->toggle_visibility; 2959 $self->{other}->toggle_visibility;
2960} 2960}
2961 2961
2962############################################################################# 2962#############################################################################
2963 2963
2964package CFClient::UI::Tooltip; 2964package CFPlus::UI::Tooltip;
2965 2965
2966our @ISA = CFClient::UI::Bin::; 2966our @ISA = CFPlus::UI::Bin::;
2967 2967
2968use CFClient::OpenGL; 2968use CFPlus::OpenGL;
2969 2969
2970sub new { 2970sub new {
2971 my $class = shift; 2971 my $class = shift;
2972 2972
2973 $class->SUPER::new ( 2973 $class->SUPER::new (
2989 } 2989 }
2990 2990
2991 $tooltip =~ s/^\n+//; 2991 $tooltip =~ s/^\n+//;
2992 $tooltip =~ s/\n+$//; 2992 $tooltip =~ s/\n+$//;
2993 2993
2994 $self->add (new CFClient::UI::Label 2994 $self->add (new CFPlus::UI::Label
2995 markup => $tooltip, 2995 markup => $tooltip,
2996 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 2996 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
2997 fontsize => 0.8, 2997 fontsize => 0.8,
2998 fg => [0, 0, 0, 1], 2998 fg => [0, 0, 0, 1],
2999 ellipsise => 0, 2999 ellipsise => 0,
3065 $self->SUPER::_draw; 3065 $self->SUPER::_draw;
3066} 3066}
3067 3067
3068############################################################################# 3068#############################################################################
3069 3069
3070package CFClient::UI::Face; 3070package CFPlus::UI::Face;
3071 3071
3072our @ISA = CFClient::UI::DrawBG::; 3072our @ISA = CFPlus::UI::DrawBG::;
3073 3073
3074use CFClient::OpenGL; 3074use CFPlus::OpenGL;
3075 3075
3076sub new { 3076sub new {
3077 my $class = shift; 3077 my $class = shift;
3078 3078
3079 my $self = $class->SUPER::new ( 3079 my $self = $class->SUPER::new (
3147 $self->SUPER::destroy; 3147 $self->SUPER::destroy;
3148} 3148}
3149 3149
3150############################################################################# 3150#############################################################################
3151 3151
3152package CFClient::UI::Buttonbar; 3152package CFPlus::UI::Buttonbar;
3153 3153
3154our @ISA = CFClient::UI::HBox::; 3154our @ISA = CFPlus::UI::HBox::;
3155 3155
3156# TODO: should actualyl wrap buttons and other goodies. 3156# TODO: should actualyl wrap buttons and other goodies.
3157 3157
3158############################################################################# 3158#############################################################################
3159 3159
3160package CFClient::UI::Menu; 3160package CFPlus::UI::Menu;
3161 3161
3162our @ISA = CFClient::UI::FancyFrame::; 3162our @ISA = CFPlus::UI::FancyFrame::;
3163 3163
3164use CFClient::OpenGL; 3164use CFPlus::OpenGL;
3165 3165
3166sub new { 3166sub new {
3167 my $class = shift; 3167 my $class = shift;
3168 3168
3169 my $self = $class->SUPER::new ( 3169 my $self = $class->SUPER::new (
3170 items => [], 3170 items => [],
3171 z => 100, 3171 z => 100,
3172 @_, 3172 @_,
3173 ); 3173 );
3174 3174
3175 $self->add ($self->{vbox} = new CFClient::UI::VBox); 3175 $self->add ($self->{vbox} = new CFPlus::UI::VBox);
3176 3176
3177 for my $item (@{ $self->{items} }) { 3177 for my $item (@{ $self->{items} }) {
3178 my ($widget, $cb, $tooltip) = @$item; 3178 my ($widget, $cb, $tooltip) = @$item;
3179 3179
3180 # handle various types of items, only text for now 3180 # handle various types of items, only text for now
3181 if (!ref $widget) { 3181 if (!ref $widget) {
3182 if ($widget =~ /\t/) { 3182 if ($widget =~ /\t/) {
3183 my ($left, $right) = split /\t/, $widget, 2; 3183 my ($left, $right) = split /\t/, $widget, 2;
3184 3184
3185 $widget = new CFClient::UI::HBox 3185 $widget = new CFPlus::UI::HBox
3186 can_hover => 1, 3186 can_hover => 1,
3187 can_events => 1, 3187 can_events => 1,
3188 tooltip => $tooltip, 3188 tooltip => $tooltip,
3189 children => [ 3189 children => [
3190 (new CFClient::UI::Label markup => $left, expand => 1), 3190 (new CFPlus::UI::Label markup => $left, expand => 1),
3191 (new CFClient::UI::Label markup => $right, align => +1), 3191 (new CFPlus::UI::Label markup => $right, align => +1),
3192 ], 3192 ],
3193 ; 3193 ;
3194 3194
3195 } else { 3195 } else {
3196 $widget = new CFClient::UI::Label 3196 $widget = new CFPlus::UI::Label
3197 can_hover => 1, 3197 can_hover => 1,
3198 can_events => 1, 3198 can_events => 1,
3199 markup => $widget, 3199 markup => $widget,
3200 tooltip => $tooltip; 3200 tooltip => $tooltip;
3201 } 3201 }
3249 1 3249 1
3250} 3250}
3251 3251
3252############################################################################# 3252#############################################################################
3253 3253
3254package CFClient::UI::Multiplexer; 3254package CFPlus::UI::Multiplexer;
3255 3255
3256our @ISA = CFClient::UI::Container::; 3256our @ISA = CFPlus::UI::Container::;
3257 3257
3258sub new { 3258sub new {
3259 my $class = shift; 3259 my $class = shift;
3260 3260
3261 my $self = $class->SUPER::new ( 3261 my $self = $class->SUPER::new (
3322 $self->{current}->draw; 3322 $self->{current}->draw;
3323} 3323}
3324 3324
3325############################################################################# 3325#############################################################################
3326 3326
3327package CFClient::UI::Notebook; 3327package CFPlus::UI::Notebook;
3328 3328
3329our @ISA = CFClient::UI::VBox::; 3329our @ISA = CFPlus::UI::VBox::;
3330 3330
3331sub new { 3331sub new {
3332 my $class = shift; 3332 my $class = shift;
3333 3333
3334 my $self = $class->SUPER::new ( 3334 my $self = $class->SUPER::new (
3335 buttonbar => (new CFClient::UI::Buttonbar), 3335 buttonbar => (new CFPlus::UI::Buttonbar),
3336 multiplexer => (new CFClient::UI::Multiplexer expand => 1), 3336 multiplexer => (new CFPlus::UI::Multiplexer expand => 1),
3337 # filter => # will be put between multiplexer and $self 3337 # filter => # will be put between multiplexer and $self
3338 @_, 3338 @_,
3339 ); 3339 );
3340 3340
3341 $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; 3341 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
3347sub add { 3347sub add {
3348 my ($self, $title, $widget, $tooltip) = @_; 3348 my ($self, $title, $widget, $tooltip) = @_;
3349 3349
3350 Scalar::Util::weaken $self; 3350 Scalar::Util::weaken $self;
3351 3351
3352 $self->{buttonbar}->add (new CFClient::UI::Button 3352 $self->{buttonbar}->add (new CFPlus::UI::Button
3353 markup => $title, 3353 markup => $title,
3354 tooltip => $tooltip, 3354 tooltip => $tooltip,
3355 on_activate => sub { $self->set_current_page ($widget) }, 3355 on_activate => sub { $self->set_current_page ($widget) },
3356 ); 3356 );
3357 3357
3371 $self->emit (page_changed => $self->{multiplexer}{current}); 3371 $self->emit (page_changed => $self->{multiplexer}{current});
3372} 3372}
3373 3373
3374############################################################################# 3374#############################################################################
3375 3375
3376package CFClient::UI::Selector; 3376package CFPlus::UI::Selector;
3377 3377
3378use utf8; 3378use utf8;
3379 3379
3380our @ISA = CFClient::UI::Button::; 3380our @ISA = CFPlus::UI::Button::;
3381 3381
3382sub new { 3382sub new {
3383 my $class = shift; 3383 my $class = shift;
3384 3384
3385 my $self = $class->SUPER::new ( 3385 my $self = $class->SUPER::new (
3402 my ($value, $title, $tooltip) = @$_; 3402 my ($value, $title, $tooltip) = @$_;
3403 3403
3404 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }]; 3404 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }];
3405 } 3405 }
3406 3406
3407 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); 3407 CFPlus::UI::Menu->new (items => \@menu_items)->popup ($ev);
3408} 3408}
3409 3409
3410sub _set_value { 3410sub _set_value {
3411 my ($self, $value) = @_; 3411 my ($self, $value) = @_;
3412 3412
3427 $self->emit (changed => $value); 3427 $self->emit (changed => $value);
3428} 3428}
3429 3429
3430############################################################################# 3430#############################################################################
3431 3431
3432package CFClient::UI::Statusbox; 3432package CFPlus::UI::Statusbox;
3433 3433
3434our @ISA = CFClient::UI::VBox::; 3434our @ISA = CFPlus::UI::VBox::;
3435 3435
3436sub new { 3436sub new {
3437 my $class = shift; 3437 my $class = shift;
3438 3438
3439 my $self = $class->SUPER::new ( 3439 my $self = $class->SUPER::new (
3451sub reorder { 3451sub reorder {
3452 my ($self) = @_; 3452 my ($self) = @_;
3453 my $NOW = Time::HiRes::time; 3453 my $NOW = Time::HiRes::time;
3454 3454
3455 # freeze display when hovering over any label 3455 # freeze display when hovering over any label
3456 return if $CFClient::UI::TOOLTIP->{owner} 3456 return if $CFPlus::UI::TOOLTIP->{owner}
3457 && grep $CFClient::UI::TOOLTIP->{owner} == $_->{label}, 3457 && grep $CFPlus::UI::TOOLTIP->{owner} == $_->{label},
3458 values %{ $self->{item} }; 3458 values %{ $self->{item} };
3459 3459
3460 while (my ($k, $v) = each %{ $self->{item} }) { 3460 while (my ($k, $v) = each %{ $self->{item} }) {
3461 delete $self->{item}{$k} if $v->{timeout} < $NOW; 3461 delete $self->{item}{$k} if $v->{timeout} < $NOW;
3462 } 3462 }
3483 for ($short) { 3483 for ($short) {
3484 s/^\s+//; 3484 s/^\s+//;
3485 s/\s+/ /g; 3485 s/\s+/ /g;
3486 } 3486 }
3487 3487
3488 new CFClient::UI::Label 3488 new CFPlus::UI::Label
3489 markup => $short, 3489 markup => $short,
3490 tooltip => $item->{tooltip}, 3490 tooltip => $item->{tooltip},
3491 tooltip_font => $::FONT_PROP, 3491 tooltip_font => $::FONT_PROP,
3492 tooltip_width => 0.67, 3492 tooltip_width => 0.67,
3493 fontsize => $item->{fontsize} || $self->{fontsize}, 3493 fontsize => $item->{fontsize} || $self->{fontsize},
3572 $self->SUPER::destroy; 3572 $self->SUPER::destroy;
3573} 3573}
3574 3574
3575############################################################################# 3575#############################################################################
3576 3576
3577package CFClient::UI::Inventory; 3577package CFPlus::UI::Inventory;
3578 3578
3579our @ISA = CFClient::UI::Table::; 3579our @ISA = CFPlus::UI::Table::;
3580 3580
3581sub new { 3581sub new {
3582 my $class = shift; 3582 my $class = shift;
3583 3583
3584 my $self = $class->SUPER::new ( 3584 my $self = $class->SUPER::new (
3600 my @item = $self->{sort}->(@{ $self->{items} }); 3600 my @item = $self->{sort}->(@{ $self->{items} });
3601 3601
3602 my @adds; 3602 my @adds;
3603 my $row = 0; 3603 my $row = 0;
3604 for my $item ($self->{sort}->(@{ $self->{items} })) { 3604 for my $item ($self->{sort}->(@{ $self->{items} })) {
3605 CFClient::Item::update_widgets $item; 3605 CFPlus::Item::update_widgets $item;
3606 3606
3607 push @adds, 0, $row, $item->{face_widget}; 3607 push @adds, 0, $row, $item->{face_widget};
3608 push @adds, 1, $row, $item->{desc_widget}; 3608 push @adds, 1, $row, $item->{desc_widget};
3609 push @adds, 2, $row, $item->{weight_widget}; 3609 push @adds, 2, $row, $item->{weight_widget};
3610 3610
3634 $self->update_items; 3634 $self->update_items;
3635} 3635}
3636 3636
3637############################################################################# 3637#############################################################################
3638 3638
3639package CFClient::UI::SpellList; 3639package CFPlus::UI::SpellList;
3640 3640
3641our @ISA = CFClient::UI::Table::; 3641our @ISA = CFPlus::UI::Table::;
3642 3642
3643sub new { 3643sub new {
3644 my $class = shift; 3644 my $class = shift;
3645 3645
3646 my $self = $class->SUPER::new ( 3646 my $self = $class->SUPER::new (
3664 "<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");
3665 3665
3666sub rebuild_spell_list { 3666sub rebuild_spell_list {
3667 my ($self) = @_; 3667 my ($self) = @_;
3668 3668
3669 $CFClient::UI::ROOT->on_refresh ($self => sub { 3669 $CFPlus::UI::ROOT->on_refresh ($self => sub {
3670 $self->clear; 3670 $self->clear;
3671 3671
3672 return unless $::CONN; 3672 return unless $::CONN;
3673 3673
3674 $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);
3675 $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);
3676 $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);
3677 $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);
3678 $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);
3679 3679
3680 my $row = 0; 3680 my $row = 0;
3681 3681
3682 for (sort { $a cmp $b } keys %{ $self->{spell} }) { 3682 for (sort { $a cmp $b } keys %{ $self->{spell} }) {
3683 my $spell = $self->{spell}{$_}; 3683 my $spell = $self->{spell}{$_};
3690 if ($ev->{button} == 1) { 3690 if ($ev->{button} == 1) {
3691 $::CONN->user_send ("cast $spell->{name}"); 3691 $::CONN->user_send ("cast $spell->{name}");
3692 } elsif ($ev->{button} == 2) { 3692 } elsif ($ev->{button} == 2) {
3693 $::CONN->user_send ("invoke $spell->{name}"); 3693 $::CONN->user_send ("invoke $spell->{name}");
3694 } elsif ($ev->{button} == 3) { 3694 } elsif ($ev->{button} == 3) {
3695 (new CFClient::UI::Menu 3695 (new CFPlus::UI::Menu
3696 items => [ 3696 items => [
3697 ["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}"]) }],
3698 ["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}"]) }],
3699 ], 3699 ],
3700 )->popup ($ev); 3700 )->popup ($ev);
3706 }; 3706 };
3707 3707
3708 my $tooltip = "$spell->{message}$TOOLTIP_ALL"; 3708 my $tooltip = "$spell->{message}$TOOLTIP_ALL";
3709 3709
3710 #TODO: add path info to tooltip 3710 #TODO: add path info to tooltip
3711 #$self->add (6, $row, new CFClient::UI::Label text => $spell->{path}); 3711 #$self->add (6, $row, new CFPlus::UI::Label text => $spell->{path});
3712 3712
3713 $self->add (0, $row, new CFClient::UI::Face 3713 $self->add (0, $row, new CFPlus::UI::Face
3714 face => $spell->{face}, 3714 face => $spell->{face},
3715 can_hover => 1, 3715 can_hover => 1,
3716 can_events => 1, 3716 can_events => 1,
3717 tooltip => $tooltip, 3717 tooltip => $tooltip,
3718 on_button_down => $spell_cb, 3718 on_button_down => $spell_cb,
3719 ); 3719 );
3720 3720
3721 $self->add (1, $row, new CFClient::UI::Label 3721 $self->add (1, $row, new CFPlus::UI::Label
3722 expand => 1, 3722 expand => 1,
3723 text => $spell->{name}, 3723 text => $spell->{name},
3724 can_hover => 1, 3724 can_hover => 1,
3725 can_events => 1, 3725 can_events => 1,
3726 tooltip => $tooltip, 3726 tooltip => $tooltip,
3727 on_button_down => $spell_cb, 3727 on_button_down => $spell_cb,
3728 ); 3728 );
3729 3729
3730 $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);
3731 $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);
3732 $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);
3733 $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);
3734 } 3734 }
3735 }); 3735 });
3736} 3736}
3737 3737
3738sub add_spell { 3738sub add_spell {
3756 $self->rebuild_spell_list; 3756 $self->rebuild_spell_list;
3757} 3757}
3758 3758
3759############################################################################# 3759#############################################################################
3760 3760
3761package CFClient::UI::Root; 3761package CFPlus::UI::Root;
3762 3762
3763our @ISA = CFClient::UI::Container::; 3763our @ISA = CFPlus::UI::Container::;
3764 3764
3765use List::Util qw(min max); 3765use List::Util qw(min max);
3766 3766
3767use CFClient::OpenGL; 3767use CFPlus::OpenGL;
3768 3768
3769sub new { 3769sub new {
3770 my $class = shift; 3770 my $class = shift;
3771 3771
3772 my $self = $class->SUPER::new ( 3772 my $self = $class->SUPER::new (
3989 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; 3989 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
3990 glMatrixMode GL_MODELVIEW; 3990 glMatrixMode GL_MODELVIEW;
3991 glLoadIdentity; 3991 glLoadIdentity;
3992 3992
3993 { 3993 {
3994 package CFClient::UI::Base; 3994 package CFPlus::UI::Base;
3995 3995
3996 ($draw_x, $draw_y, $draw_w, $draw_h) = 3996 ($draw_x, $draw_y, $draw_w, $draw_h) =
3997 (0, 0, $self->{w}, $self->{h}); 3997 (0, 0, $self->{w}, $self->{h});
3998 } 3998 }
3999 3999
4000 $self->_draw; 4000 $self->_draw;
4001} 4001}
4002 4002
4003############################################################################# 4003#############################################################################
4004 4004
4005package CFClient::UI; 4005package CFPlus::UI;
4006 4006
4007$ROOT = new CFClient::UI::Root; 4007$ROOT = new CFPlus::UI::Root;
4008$TOOLTIP = new CFClient::UI::Tooltip z => 900; 4008$TOOLTIP = new CFPlus::UI::Tooltip z => 900;
4009 4009
40101 40101
4011 4011

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines