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.337 by root, Mon Jul 24 04:24:43 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, 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}
1296 $self->{motion}->($ev, $x, $y) if $self->{motion}; 1296 $self->{motion}->($ev, $x, $y) if $self->{motion};
1297 1297
1298 ! ! $self->{motion} 1298 ! ! $self->{motion}
1299} 1299}
1300 1300
1301sub invoke_visibility_change {
1302 my ($self, $visible) = @_;
1303
1304 delete $self->{motion} unless $visible;
1305
1306 0
1307}
1308
1301sub _draw { 1309sub _draw {
1302 my ($self) = @_; 1310 my ($self) = @_;
1303 1311
1304 my $child = $self->{children}[0]; 1312 my $child = $self->{children}[0];
1305 1313
1342 if $self->{close_button}; 1350 if $self->{close_button};
1343} 1351}
1344 1352
1345############################################################################# 1353#############################################################################
1346 1354
1347package CFClient::UI::Table; 1355package CFPlus::UI::Table;
1348 1356
1349our @ISA = CFClient::UI::Base::; 1357our @ISA = CFPlus::UI::Base::;
1350 1358
1351use List::Util qw(max sum); 1359use List::Util qw(max sum);
1352 1360
1353use CFClient::OpenGL; 1361use CFPlus::OpenGL;
1354 1362
1355sub new { 1363sub new {
1356 my $class = shift; 1364 my $class = shift;
1357 1365
1358 $class->SUPER::new ( 1366 $class->SUPER::new (
1448 1456
1449 # linearly scale sizes 1457 # linearly scale sizes
1450 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; 1458 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws;
1451 $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs; 1459 $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs;
1452 1460
1453 CFClient::UI::harmonize $ws; 1461 CFPlus::UI::harmonize $ws;
1454 CFClient::UI::harmonize $hs; 1462 CFPlus::UI::harmonize $hs;
1455 1463
1456 my $y; 1464 my $y;
1457 1465
1458 for my $r (0 .. $#{$self->{children}}) { 1466 for my $r (0 .. $#{$self->{children}}) {
1459 my $row = $self->{children}[$r] 1467 my $row = $self->{children}[$r]
1502 } 1510 }
1503} 1511}
1504 1512
1505############################################################################# 1513#############################################################################
1506 1514
1507package CFClient::UI::Box; 1515package CFPlus::UI::Box;
1508 1516
1509our @ISA = CFClient::UI::Container::; 1517our @ISA = CFPlus::UI::Container::;
1510 1518
1511sub size_request { 1519sub size_request {
1512 my ($self) = @_; 1520 my ($self) = @_;
1513 1521
1514 $self->{vertical} 1522 $self->{vertical}
1547 $req[$_] += $space * $children[$_]{expand} 1555 $req[$_] += $space * $children[$_]{expand}
1548 for 0 .. $#children; 1556 for 0 .. $#children;
1549 } 1557 }
1550 } 1558 }
1551 1559
1552 CFClient::UI::harmonize \@req; 1560 CFPlus::UI::harmonize \@req;
1553 1561
1554 my $pos = 0; 1562 my $pos = 0;
1555 for (0 .. $#children) { 1563 for (0 .. $#children) {
1556 my $alloc = $req[$_]; 1564 my $alloc = $req[$_];
1557 $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));
1562 1 1570 1
1563} 1571}
1564 1572
1565############################################################################# 1573#############################################################################
1566 1574
1567package CFClient::UI::HBox; 1575package CFPlus::UI::HBox;
1568 1576
1569our @ISA = CFClient::UI::Box::; 1577our @ISA = CFPlus::UI::Box::;
1570 1578
1571sub new { 1579sub new {
1572 my $class = shift; 1580 my $class = shift;
1573 1581
1574 $class->SUPER::new ( 1582 $class->SUPER::new (
1577 ) 1585 )
1578} 1586}
1579 1587
1580############################################################################# 1588#############################################################################
1581 1589
1582package CFClient::UI::VBox; 1590package CFPlus::UI::VBox;
1583 1591
1584our @ISA = CFClient::UI::Box::; 1592our @ISA = CFPlus::UI::Box::;
1585 1593
1586sub new { 1594sub new {
1587 my $class = shift; 1595 my $class = shift;
1588 1596
1589 $class->SUPER::new ( 1597 $class->SUPER::new (
1592 ) 1600 )
1593} 1601}
1594 1602
1595############################################################################# 1603#############################################################################
1596 1604
1597package CFClient::UI::Label; 1605package CFPlus::UI::Label;
1598 1606
1599our @ISA = CFClient::UI::DrawBG::; 1607our @ISA = CFPlus::UI::DrawBG::;
1600 1608
1601use CFClient::OpenGL; 1609use CFPlus::OpenGL;
1602 1610
1603sub new { 1611sub new {
1604 my ($class, %arg) = @_; 1612 my ($class, %arg) = @_;
1605 1613
1606 my $self = $class->SUPER::new ( 1614 my $self = $class->SUPER::new (
1610 #font => default_font 1618 #font => default_font
1611 #text => initial text 1619 #text => initial text
1612 #markup => initial narkup 1620 #markup => initial narkup
1613 #max_w => maximum pixel width 1621 #max_w => maximum pixel width
1614 ellipsise => 3, # end 1622 ellipsise => 3, # end
1615 layout => (new CFClient::Layout), 1623 layout => (new CFPlus::Layout),
1616 fontsize => 1, 1624 fontsize => 1,
1617 align => -1, 1625 align => -1,
1618 valign => -1, 1626 valign => -1,
1619 padding_x => 2, 1627 padding_x => 2,
1620 padding_y => 2, 1628 padding_y => 2,
1621 can_events => 0, 1629 can_events => 0,
1622 %arg 1630 %arg
1623 ); 1631 );
1624 1632
1625 if (exists $self->{template}) { 1633 if (exists $self->{template}) {
1626 my $layout = new CFClient::Layout; 1634 my $layout = new CFPlus::Layout;
1627 $layout->set_text (delete $self->{template}); 1635 $layout->set_text (delete $self->{template});
1628 $self->{template} = $layout; 1636 $self->{template} = $layout;
1629 } 1637 }
1630 1638
1631 if (exists $self->{markup}) { 1639 if (exists $self->{markup}) {
1774 $self->{layout}->render ($self->{ox}, $self->{oy}); 1782 $self->{layout}->render ($self->{ox}, $self->{oy});
1775} 1783}
1776 1784
1777############################################################################# 1785#############################################################################
1778 1786
1779package CFClient::UI::EntryBase; 1787package CFPlus::UI::EntryBase;
1780 1788
1781our @ISA = CFClient::UI::Label::; 1789our @ISA = CFPlus::UI::Label::;
1782 1790
1783use CFClient::OpenGL; 1791use CFPlus::OpenGL;
1784 1792
1785sub new { 1793sub new {
1786 my $class = shift; 1794 my $class = shift;
1787 1795
1788 $class->SUPER::new ( 1796 $class->SUPER::new (
1850 1858
1851 if ($uni == 8) { 1859 if ($uni == 8) {
1852 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 1860 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
1853 } elsif ($uni == 127) { 1861 } elsif ($uni == 127) {
1854 substr $text, $self->{cursor}, 1, ""; 1862 substr $text, $self->{cursor}, 1, "";
1855 } elsif ($sym == CFClient::SDLK_LEFT) { 1863 } elsif ($sym == CFPlus::SDLK_LEFT) {
1856 --$self->{cursor} if $self->{cursor}; 1864 --$self->{cursor} if $self->{cursor};
1857 } elsif ($sym == CFClient::SDLK_RIGHT) { 1865 } elsif ($sym == CFPlus::SDLK_RIGHT) {
1858 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 1866 ++$self->{cursor} if $self->{cursor} < length $self->{text};
1859 } elsif ($sym == CFClient::SDLK_HOME) { 1867 } elsif ($sym == CFPlus::SDLK_HOME) {
1860 $self->{cursor} = 0; 1868 $self->{cursor} = 0;
1861 } elsif ($sym == CFClient::SDLK_END) { 1869 } elsif ($sym == CFPlus::SDLK_END) {
1862 $self->{cursor} = length $text; 1870 $self->{cursor} = length $text;
1863 } elsif ($uni == 27) { 1871 } elsif ($uni == 27) {
1864 $self->emit ('escape'); 1872 $self->emit ('escape');
1865 } elsif ($uni) { 1873 } elsif ($uni) {
1866 substr $text, $self->{cursor}++, 0, chr $uni; 1874 substr $text, $self->{cursor}++, 0, chr $uni;
1948 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};
1949 glEnd; 1957 glEnd;
1950 } 1958 }
1951} 1959}
1952 1960
1953package CFClient::UI::Entry; 1961package CFPlus::UI::Entry;
1954 1962
1955our @ISA = CFClient::UI::EntryBase::; 1963our @ISA = CFPlus::UI::EntryBase::;
1956 1964
1957use CFClient::OpenGL; 1965use CFPlus::OpenGL;
1958 1966
1959sub invoke_key_down { 1967sub invoke_key_down {
1960 my ($self, $ev) = @_; 1968 my ($self, $ev) = @_;
1961 1969
1962 my $sym = $ev->{sym}; 1970 my $sym = $ev->{sym};
1968 $self->{history_pointer} = -1; 1976 $self->{history_pointer} = -1;
1969 $self->{history_saveback} = ''; 1977 $self->{history_saveback} = '';
1970 $self->emit (activate => $txt); 1978 $self->emit (activate => $txt);
1971 $self->update; 1979 $self->update;
1972 1980
1973 } elsif ($sym == CFClient::SDLK_UP) { 1981 } elsif ($sym == CFPlus::SDLK_UP) {
1974 if ($self->{history_pointer} < 0) { 1982 if ($self->{history_pointer} < 0) {
1975 $self->{history_saveback} = $self->get_text; 1983 $self->{history_saveback} = $self->get_text;
1976 } 1984 }
1977 if (@{$self->{history} || []} > 0) { 1985 if (@{$self->{history} || []} > 0) {
1978 $self->{history_pointer}++; 1986 $self->{history_pointer}++;
1980 $self->{history_pointer} = @{$self->{history} || []} - 1; 1988 $self->{history_pointer} = @{$self->{history} || []} - 1;
1981 } 1989 }
1982 $self->set_text ($self->{history}->[$self->{history_pointer}]); 1990 $self->set_text ($self->{history}->[$self->{history_pointer}]);
1983 } 1991 }
1984 1992
1985 } elsif ($sym == CFClient::SDLK_DOWN) { 1993 } elsif ($sym == CFPlus::SDLK_DOWN) {
1986 $self->{history_pointer}--; 1994 $self->{history_pointer}--;
1987 $self->{history_pointer} = -1 if $self->{history_pointer} < 0; 1995 $self->{history_pointer} = -1 if $self->{history_pointer} < 0;
1988 1996
1989 if ($self->{history_pointer} >= 0) { 1997 if ($self->{history_pointer} >= 0) {
1990 $self->set_text ($self->{history}->[$self->{history_pointer}]); 1998 $self->set_text ($self->{history}->[$self->{history_pointer}]);
1999 1 2007 1
2000} 2008}
2001 2009
2002############################################################################# 2010#############################################################################
2003 2011
2004package CFClient::UI::Button; 2012package CFPlus::UI::Button;
2005 2013
2006our @ISA = CFClient::UI::Label::; 2014our @ISA = CFPlus::UI::Label::;
2007 2015
2008use CFClient::OpenGL; 2016use CFPlus::OpenGL;
2009 2017
2010my @tex = 2018my @tex =
2011 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2019 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2012 qw(b1_button_active.png); 2020 qw(b1_button_active.png);
2013 2021
2014sub new { 2022sub new {
2015 my $class = shift; 2023 my $class = shift;
2016 2024
2053 $self->SUPER::_draw; 2061 $self->SUPER::_draw;
2054} 2062}
2055 2063
2056############################################################################# 2064#############################################################################
2057 2065
2058package CFClient::UI::CheckBox; 2066package CFPlus::UI::CheckBox;
2059 2067
2060our @ISA = CFClient::UI::DrawBG::; 2068our @ISA = CFPlus::UI::DrawBG::;
2061 2069
2062my @tex = 2070my @tex =
2063 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2071 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2064 qw(c1_checkbox_bg.png c1_checkbox_active.png); 2072 qw(c1_checkbox_bg.png c1_checkbox_active.png);
2065 2073
2066use CFClient::OpenGL; 2074use CFPlus::OpenGL;
2067 2075
2068sub new { 2076sub new {
2069 my $class = shift; 2077 my $class = shift;
2070 2078
2071 $class->SUPER::new ( 2079 $class->SUPER::new (
2128 glDisable GL_TEXTURE_2D; 2136 glDisable GL_TEXTURE_2D;
2129} 2137}
2130 2138
2131############################################################################# 2139#############################################################################
2132 2140
2133package CFClient::UI::Image; 2141package CFPlus::UI::Image;
2134 2142
2135our @ISA = CFClient::UI::Base::; 2143our @ISA = CFPlus::UI::Base::;
2136 2144
2137use CFClient::OpenGL; 2145use CFPlus::OpenGL;
2138 2146
2139our %texture_cache; 2147our %texture_cache;
2140 2148
2141sub new { 2149sub new {
2142 my $class = shift; 2150 my $class = shift;
2148 2156
2149 $self->{path} || $self->{tex} 2157 $self->{path} || $self->{tex}
2150 or Carp::croak "'path' or 'tex' attributes required"; 2158 or Carp::croak "'path' or 'tex' attributes required";
2151 2159
2152 $self->{tex} ||= $texture_cache{$self->{path}} ||= 2160 $self->{tex} ||= $texture_cache{$self->{path}} ||=
2153 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;
2154 2162
2155 Scalar::Util::weaken $texture_cache{$self->{path}}; 2163 Scalar::Util::weaken $texture_cache{$self->{path}};
2156 2164
2157 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; 2165 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2158 2166
2161 2169
2162sub STORABLE_freeze { 2170sub STORABLE_freeze {
2163 my ($self, $cloning) = @_; 2171 my ($self, $cloning) = @_;
2164 2172
2165 $self->{path} 2173 $self->{path}
2166 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";
2167 2175
2168 $self->{path} 2176 $self->{path}
2169} 2177}
2170 2178
2171sub STORABLE_attach { 2179sub STORABLE_attach {
2202 glDisable GL_TEXTURE_2D; 2210 glDisable GL_TEXTURE_2D;
2203} 2211}
2204 2212
2205############################################################################# 2213#############################################################################
2206 2214
2207package CFClient::UI::ImageButton; 2215package CFPlus::UI::ImageButton;
2208 2216
2209our @ISA = CFClient::UI::Image::; 2217our @ISA = CFPlus::UI::Image::;
2210 2218
2211use CFClient::OpenGL; 2219use CFPlus::OpenGL;
2212 2220
2213my %textures; 2221my %textures;
2214 2222
2215sub new { 2223sub new {
2216 my $class = shift; 2224 my $class = shift;
2238 1 2246 1
2239} 2247}
2240 2248
2241############################################################################# 2249#############################################################################
2242 2250
2243package CFClient::UI::VGauge; 2251package CFPlus::UI::VGauge;
2244 2252
2245our @ISA = CFClient::UI::Base::; 2253our @ISA = CFPlus::UI::Base::;
2246 2254
2247use List::Util qw(min max); 2255use List::Util qw(min max);
2248 2256
2249use CFClient::OpenGL; 2257use CFPlus::OpenGL;
2250 2258
2251my %tex = ( 2259my %tex = (
2252 food => [ 2260 food => [
2253 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2261 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2254 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 2262 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
2255 ], 2263 ],
2256 grace => [ 2264 grace => [
2257 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2265 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2258 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/
2259 ], 2267 ],
2260 hp => [ 2268 hp => [
2261 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2269 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2262 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 2270 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
2263 ], 2271 ],
2264 mana => [ 2272 mana => [
2265 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2273 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2266 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/
2267 ], 2275 ],
2268); 2276);
2269 2277
2270# eg. VGauge->new (gauge => 'food'), default gauge: food 2278# eg. VGauge->new (gauge => 'food'), default gauge: food
2373 glDisable GL_TEXTURE_2D; 2381 glDisable GL_TEXTURE_2D;
2374} 2382}
2375 2383
2376############################################################################# 2384#############################################################################
2377 2385
2378package CFClient::UI::Gauge; 2386package CFPlus::UI::Gauge;
2379 2387
2380our @ISA = CFClient::UI::VBox::; 2388our @ISA = CFPlus::UI::VBox::;
2381 2389
2382sub new { 2390sub new {
2383 my ($class, %arg) = @_; 2391 my ($class, %arg) = @_;
2384 2392
2385 my $self = $class->SUPER::new ( 2393 my $self = $class->SUPER::new (
2387 can_hover => 1, 2395 can_hover => 1,
2388 can_events => 1, 2396 can_events => 1,
2389 %arg, 2397 %arg,
2390 ); 2398 );
2391 2399
2392 $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");
2393 $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);
2394 $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");
2395 2403
2396 $self 2404 $self
2397} 2405}
2398 2406
2399sub set_fontsize { 2407sub set_fontsize {
2420 $self->{value}->set_text ($val); 2428 $self->{value}->set_text ($val);
2421} 2429}
2422 2430
2423############################################################################# 2431#############################################################################
2424 2432
2425package CFClient::UI::Slider; 2433package CFPlus::UI::Slider;
2426 2434
2427use strict; 2435use strict;
2428 2436
2429use CFClient::OpenGL; 2437use CFPlus::OpenGL;
2430 2438
2431our @ISA = CFClient::UI::DrawBG::; 2439our @ISA = CFPlus::UI::DrawBG::;
2432 2440
2433my @tex = 2441my @tex =
2434 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 2442 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_ }
2435 qw(s1_slider.png s1_slider_bg.png); 2443 qw(s1_slider.png s1_slider_bg.png);
2436 2444
2437sub new { 2445sub new {
2438 my $class = shift; 2446 my $class = shift;
2439 2447
2594 glDisable GL_TEXTURE_2D; 2602 glDisable GL_TEXTURE_2D;
2595} 2603}
2596 2604
2597############################################################################# 2605#############################################################################
2598 2606
2599package CFClient::UI::ValSlider; 2607package CFPlus::UI::ValSlider;
2600 2608
2601our @ISA = CFClient::UI::HBox::; 2609our @ISA = CFPlus::UI::HBox::;
2602 2610
2603sub new { 2611sub new {
2604 my ($class, %arg) = @_; 2612 my ($class, %arg) = @_;
2605 2613
2606 my $range = delete $arg{range}; 2614 my $range = delete $arg{range};
2607 2615
2608 my $self = $class->SUPER::new ( 2616 my $self = $class->SUPER::new (
2609 slider => (new CFClient::UI::Slider expand => 1, range => $range), 2617 slider => (new CFPlus::UI::Slider expand => 1, range => $range),
2610 entry => (new CFClient::UI::Label text => "", template => delete $arg{template}), 2618 entry => (new CFPlus::UI::Label text => "", template => delete $arg{template}),
2611 to_value => sub { shift }, 2619 to_value => sub { shift },
2612 from_value => sub { shift }, 2620 from_value => sub { shift },
2613 %arg, 2621 %arg,
2614 ); 2622 );
2615 2623
2635sub set_range { shift->{slider}->set_range (@_) } 2643sub set_range { shift->{slider}->set_range (@_) }
2636sub set_value { shift->{slider}->set_value (@_) } 2644sub set_value { shift->{slider}->set_value (@_) }
2637 2645
2638############################################################################# 2646#############################################################################
2639 2647
2640package CFClient::UI::TextScroller; 2648package CFPlus::UI::TextScroller;
2641 2649
2642our @ISA = CFClient::UI::HBox::; 2650our @ISA = CFPlus::UI::HBox::;
2643 2651
2644use CFClient::OpenGL; 2652use CFPlus::OpenGL;
2645 2653
2646sub new { 2654sub new {
2647 my $class = shift; 2655 my $class = shift;
2648 2656
2649 my $self = $class->SUPER::new ( 2657 my $self = $class->SUPER::new (
2651 can_events => 1, 2659 can_events => 1,
2652 indent => 0, 2660 indent => 0,
2653 #font => default_font 2661 #font => default_font
2654 @_, 2662 @_,
2655 2663
2656 layout => (new CFClient::Layout), 2664 layout => (new CFPlus::Layout),
2657 par => [], 2665 par => [],
2658 height => 0, 2666 height => 0,
2659 children => [ 2667 children => [
2660 (new CFClient::UI::Empty expand => 1), 2668 (new CFPlus::UI::Empty expand => 1),
2661 (new CFClient::UI::Slider vertical => 1), 2669 (new CFPlus::UI::Slider vertical => 1),
2662 ], 2670 ],
2663 ); 2671 );
2664 2672
2665 $self->{children}[1]->connect (changed => sub { $self->update }); 2673 $self->{children}[1]->connect (changed => sub { $self->update });
2666 2674
2755 $self->{height} = 0; 2763 $self->{height} = 0;
2756 $self->{children}[1]->set_range ([0, 0, 0, 1, 1]); 2764 $self->{children}[1]->set_range ([0, 0, 0, 1, 1]);
2757} 2765}
2758 2766
2759sub add_paragraph { 2767sub add_paragraph {
2760 my ($self, $color, $para, $indent) = @_; 2768 my $self = shift;
2761 2769
2762 my ($text, @w) = ref $para ? @$para : $para; 2770 for my $para (@_) {
2763
2764 $para = { 2771 $para = {
2772 fg => [1, 1, 1, 1],
2773 indent => 0,
2774 markup => "",
2775 widget => [],
2776 ref $para ? %$para : (markup => $para),
2765 w => 1e10, 2777 w => 1e10,
2766 wrapped => 1, 2778 wrapped => 1,
2767 fg => $color,
2768 indent => $indent,
2769 markup => $text,
2770 widget => \@w,
2771 }; 2779 };
2772 2780
2773 $self->add (@w) if @w; 2781 $self->add (@{ $para->{widget} }) if @{ $para->{widget} };
2774 push @{$self->{par}}, $para; 2782 push @{$self->{par}}, $para;
2783 }
2775 2784
2776 $self->{need_reflow}++; 2785 $self->{need_reflow}++;
2777 $self->update; 2786 $self->update;
2778} 2787}
2779 2788
2821 2830
2822 if (delete $self->{scroll_to_bottom}) { 2831 if (delete $self->{scroll_to_bottom}) {
2823 $self->{children}[1]->set_value (1e10); 2832 $self->{children}[1]->set_value (1e10);
2824 } 2833 }
2825 2834
2826 $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { 2835 $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub {
2827 glClearColor 0, 0, 0, 0; 2836 glClearColor 0, 0, 0, 0;
2828 glClear GL_COLOR_BUFFER_BIT; 2837 glClear GL_COLOR_BUFFER_BIT;
2829 2838
2830 my $top = int $self->{children}[1]{range}[0]; 2839 my $top = int $self->{children}[1]{range}[0];
2831 2840
2884 $self->{children}[1]->draw; 2893 $self->{children}[1]->draw;
2885} 2894}
2886 2895
2887############################################################################# 2896#############################################################################
2888 2897
2889package CFClient::UI::Animator; 2898package CFPlus::UI::Animator;
2890 2899
2891use CFClient::OpenGL; 2900use CFPlus::OpenGL;
2892 2901
2893our @ISA = CFClient::UI::Bin::; 2902our @ISA = CFPlus::UI::Bin::;
2894 2903
2895sub moveto { 2904sub moveto {
2896 my ($self, $x, $y) = @_; 2905 my ($self, $x, $y) = @_;
2897 2906
2898 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 2907 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
2926 glPopMatrix; 2935 glPopMatrix;
2927} 2936}
2928 2937
2929############################################################################# 2938#############################################################################
2930 2939
2931package CFClient::UI::Flopper; 2940package CFPlus::UI::Flopper;
2932 2941
2933our @ISA = CFClient::UI::Button::; 2942our @ISA = CFPlus::UI::Button::;
2934 2943
2935sub new { 2944sub new {
2936 my $class = shift; 2945 my $class = shift;
2937 2946
2938 my $self = $class->SUPER::new ( 2947 my $self = $class->SUPER::new (
2950 $self->{other}->toggle_visibility; 2959 $self->{other}->toggle_visibility;
2951} 2960}
2952 2961
2953############################################################################# 2962#############################################################################
2954 2963
2955package CFClient::UI::Tooltip; 2964package CFPlus::UI::Tooltip;
2956 2965
2957our @ISA = CFClient::UI::Bin::; 2966our @ISA = CFPlus::UI::Bin::;
2958 2967
2959use CFClient::OpenGL; 2968use CFPlus::OpenGL;
2960 2969
2961sub new { 2970sub new {
2962 my $class = shift; 2971 my $class = shift;
2963 2972
2964 $class->SUPER::new ( 2973 $class->SUPER::new (
2980 } 2989 }
2981 2990
2982 $tooltip =~ s/^\n+//; 2991 $tooltip =~ s/^\n+//;
2983 $tooltip =~ s/\n+$//; 2992 $tooltip =~ s/\n+$//;
2984 2993
2985 $self->add (new CFClient::UI::Label 2994 $self->add (new CFPlus::UI::Label
2986 markup => $tooltip, 2995 markup => $tooltip,
2987 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 2996 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
2988 fontsize => 0.8, 2997 fontsize => 0.8,
2989 fg => [0, 0, 0, 1], 2998 fg => [0, 0, 0, 1],
2990 ellipsise => 0, 2999 ellipsise => 0,
3056 $self->SUPER::_draw; 3065 $self->SUPER::_draw;
3057} 3066}
3058 3067
3059############################################################################# 3068#############################################################################
3060 3069
3061package CFClient::UI::Face; 3070package CFPlus::UI::Face;
3062 3071
3063our @ISA = CFClient::UI::DrawBG::; 3072our @ISA = CFPlus::UI::DrawBG::;
3064 3073
3065use CFClient::OpenGL; 3074use CFPlus::OpenGL;
3066 3075
3067sub new { 3076sub new {
3068 my $class = shift; 3077 my $class = shift;
3069 3078
3070 my $self = $class->SUPER::new ( 3079 my $self = $class->SUPER::new (
3138 $self->SUPER::destroy; 3147 $self->SUPER::destroy;
3139} 3148}
3140 3149
3141############################################################################# 3150#############################################################################
3142 3151
3143package CFClient::UI::Buttonbar; 3152package CFPlus::UI::Buttonbar;
3144 3153
3145our @ISA = CFClient::UI::HBox::; 3154our @ISA = CFPlus::UI::HBox::;
3146 3155
3147# TODO: should actualyl wrap buttons and other goodies. 3156# TODO: should actualyl wrap buttons and other goodies.
3148 3157
3149############################################################################# 3158#############################################################################
3150 3159
3151package CFClient::UI::Menu; 3160package CFPlus::UI::Menu;
3152 3161
3153our @ISA = CFClient::UI::FancyFrame::; 3162our @ISA = CFPlus::UI::FancyFrame::;
3154 3163
3155use CFClient::OpenGL; 3164use CFPlus::OpenGL;
3156 3165
3157sub new { 3166sub new {
3158 my $class = shift; 3167 my $class = shift;
3159 3168
3160 my $self = $class->SUPER::new ( 3169 my $self = $class->SUPER::new (
3161 items => [], 3170 items => [],
3162 z => 100, 3171 z => 100,
3163 @_, 3172 @_,
3164 ); 3173 );
3165 3174
3166 $self->add ($self->{vbox} = new CFClient::UI::VBox); 3175 $self->add ($self->{vbox} = new CFPlus::UI::VBox);
3167 3176
3168 for my $item (@{ $self->{items} }) { 3177 for my $item (@{ $self->{items} }) {
3169 my ($widget, $cb, $tooltip) = @$item; 3178 my ($widget, $cb, $tooltip) = @$item;
3170 3179
3171 # handle various types of items, only text for now 3180 # handle various types of items, only text for now
3172 if (!ref $widget) { 3181 if (!ref $widget) {
3173 if ($widget =~ /\t/) { 3182 if ($widget =~ /\t/) {
3174 my ($left, $right) = split /\t/, $widget, 2; 3183 my ($left, $right) = split /\t/, $widget, 2;
3175 3184
3176 $widget = new CFClient::UI::HBox 3185 $widget = new CFPlus::UI::HBox
3177 can_hover => 1, 3186 can_hover => 1,
3178 can_events => 1, 3187 can_events => 1,
3179 tooltip => $tooltip, 3188 tooltip => $tooltip,
3180 children => [ 3189 children => [
3181 (new CFClient::UI::Label markup => $left, expand => 1), 3190 (new CFPlus::UI::Label markup => $left, expand => 1),
3182 (new CFClient::UI::Label markup => $right, align => +1), 3191 (new CFPlus::UI::Label markup => $right, align => +1),
3183 ], 3192 ],
3184 ; 3193 ;
3185 3194
3186 } else { 3195 } else {
3187 $widget = new CFClient::UI::Label 3196 $widget = new CFPlus::UI::Label
3188 can_hover => 1, 3197 can_hover => 1,
3189 can_events => 1, 3198 can_events => 1,
3190 markup => $widget, 3199 markup => $widget,
3191 tooltip => $tooltip; 3200 tooltip => $tooltip;
3192 } 3201 }
3240 1 3249 1
3241} 3250}
3242 3251
3243############################################################################# 3252#############################################################################
3244 3253
3245package CFClient::UI::Multiplexer; 3254package CFPlus::UI::Multiplexer;
3246 3255
3247our @ISA = CFClient::UI::Container::; 3256our @ISA = CFPlus::UI::Container::;
3248 3257
3249sub new { 3258sub new {
3250 my $class = shift; 3259 my $class = shift;
3251 3260
3252 my $self = $class->SUPER::new ( 3261 my $self = $class->SUPER::new (
3313 $self->{current}->draw; 3322 $self->{current}->draw;
3314} 3323}
3315 3324
3316############################################################################# 3325#############################################################################
3317 3326
3318package CFClient::UI::Notebook; 3327package CFPlus::UI::Notebook;
3319 3328
3320our @ISA = CFClient::UI::VBox::; 3329our @ISA = CFPlus::UI::VBox::;
3321 3330
3322sub new { 3331sub new {
3323 my $class = shift; 3332 my $class = shift;
3324 3333
3325 my $self = $class->SUPER::new ( 3334 my $self = $class->SUPER::new (
3326 buttonbar => (new CFClient::UI::Buttonbar), 3335 buttonbar => (new CFPlus::UI::Buttonbar),
3327 multiplexer => (new CFClient::UI::Multiplexer expand => 1), 3336 multiplexer => (new CFPlus::UI::Multiplexer expand => 1),
3328 # filter => # will be put between multiplexer and $self 3337 # filter => # will be put between multiplexer and $self
3329 @_, 3338 @_,
3330 ); 3339 );
3331 3340
3332 $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; 3341 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
3338sub add { 3347sub add {
3339 my ($self, $title, $widget, $tooltip) = @_; 3348 my ($self, $title, $widget, $tooltip) = @_;
3340 3349
3341 Scalar::Util::weaken $self; 3350 Scalar::Util::weaken $self;
3342 3351
3343 $self->{buttonbar}->add (new CFClient::UI::Button 3352 $self->{buttonbar}->add (new CFPlus::UI::Button
3344 markup => $title, 3353 markup => $title,
3345 tooltip => $tooltip, 3354 tooltip => $tooltip,
3346 on_activate => sub { $self->set_current_page ($widget) }, 3355 on_activate => sub { $self->set_current_page ($widget) },
3347 ); 3356 );
3348 3357
3362 $self->emit (page_changed => $self->{multiplexer}{current}); 3371 $self->emit (page_changed => $self->{multiplexer}{current});
3363} 3372}
3364 3373
3365############################################################################# 3374#############################################################################
3366 3375
3367package CFClient::UI::Selector; 3376package CFPlus::UI::Selector;
3368 3377
3369use utf8; 3378use utf8;
3370 3379
3371our @ISA = CFClient::UI::Button::; 3380our @ISA = CFPlus::UI::Button::;
3372 3381
3373sub new { 3382sub new {
3374 my $class = shift; 3383 my $class = shift;
3375 3384
3376 my $self = $class->SUPER::new ( 3385 my $self = $class->SUPER::new (
3393 my ($value, $title, $tooltip) = @$_; 3402 my ($value, $title, $tooltip) = @$_;
3394 3403
3395 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }]; 3404 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }];
3396 } 3405 }
3397 3406
3398 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); 3407 CFPlus::UI::Menu->new (items => \@menu_items)->popup ($ev);
3399} 3408}
3400 3409
3401sub _set_value { 3410sub _set_value {
3402 my ($self, $value) = @_; 3411 my ($self, $value) = @_;
3403 3412
3418 $self->emit (changed => $value); 3427 $self->emit (changed => $value);
3419} 3428}
3420 3429
3421############################################################################# 3430#############################################################################
3422 3431
3423package CFClient::UI::Statusbox; 3432package CFPlus::UI::Statusbox;
3424 3433
3425our @ISA = CFClient::UI::VBox::; 3434our @ISA = CFPlus::UI::VBox::;
3426 3435
3427sub new { 3436sub new {
3428 my $class = shift; 3437 my $class = shift;
3429 3438
3430 my $self = $class->SUPER::new ( 3439 my $self = $class->SUPER::new (
3442sub reorder { 3451sub reorder {
3443 my ($self) = @_; 3452 my ($self) = @_;
3444 my $NOW = Time::HiRes::time; 3453 my $NOW = Time::HiRes::time;
3445 3454
3446 # freeze display when hovering over any label 3455 # freeze display when hovering over any label
3447 return if $CFClient::UI::TOOLTIP->{owner} 3456 return if $CFPlus::UI::TOOLTIP->{owner}
3448 && grep $CFClient::UI::TOOLTIP->{owner} == $_->{label}, 3457 && grep $CFPlus::UI::TOOLTIP->{owner} == $_->{label},
3449 values %{ $self->{item} }; 3458 values %{ $self->{item} };
3450 3459
3451 while (my ($k, $v) = each %{ $self->{item} }) { 3460 while (my ($k, $v) = each %{ $self->{item} }) {
3452 delete $self->{item}{$k} if $v->{timeout} < $NOW; 3461 delete $self->{item}{$k} if $v->{timeout} < $NOW;
3453 } 3462 }
3474 for ($short) { 3483 for ($short) {
3475 s/^\s+//; 3484 s/^\s+//;
3476 s/\s+/ /g; 3485 s/\s+/ /g;
3477 } 3486 }
3478 3487
3479 new CFClient::UI::Label 3488 new CFPlus::UI::Label
3480 markup => $short, 3489 markup => $short,
3481 tooltip => $item->{tooltip}, 3490 tooltip => $item->{tooltip},
3482 tooltip_font => $::FONT_PROP, 3491 tooltip_font => $::FONT_PROP,
3483 tooltip_width => 0.67, 3492 tooltip_width => 0.67,
3484 fontsize => $item->{fontsize} || $self->{fontsize}, 3493 fontsize => $item->{fontsize} || $self->{fontsize},
3563 $self->SUPER::destroy; 3572 $self->SUPER::destroy;
3564} 3573}
3565 3574
3566############################################################################# 3575#############################################################################
3567 3576
3568package CFClient::UI::Inventory; 3577package CFPlus::UI::Inventory;
3569 3578
3570our @ISA = CFClient::UI::Table::; 3579our @ISA = CFPlus::UI::Table::;
3571 3580
3572sub new { 3581sub new {
3573 my $class = shift; 3582 my $class = shift;
3574 3583
3575 my $self = $class->SUPER::new ( 3584 my $self = $class->SUPER::new (
3591 my @item = $self->{sort}->(@{ $self->{items} }); 3600 my @item = $self->{sort}->(@{ $self->{items} });
3592 3601
3593 my @adds; 3602 my @adds;
3594 my $row = 0; 3603 my $row = 0;
3595 for my $item ($self->{sort}->(@{ $self->{items} })) { 3604 for my $item ($self->{sort}->(@{ $self->{items} })) {
3596 CFClient::Item::update_widgets $item; 3605 CFPlus::Item::update_widgets $item;
3597 3606
3598 push @adds, 0, $row, $item->{face_widget}; 3607 push @adds, 0, $row, $item->{face_widget};
3599 push @adds, 1, $row, $item->{desc_widget}; 3608 push @adds, 1, $row, $item->{desc_widget};
3600 push @adds, 2, $row, $item->{weight_widget}; 3609 push @adds, 2, $row, $item->{weight_widget};
3601 3610
3625 $self->update_items; 3634 $self->update_items;
3626} 3635}
3627 3636
3628############################################################################# 3637#############################################################################
3629 3638
3630package CFClient::UI::SpellList; 3639package CFPlus::UI::SpellList;
3631 3640
3632our @ISA = CFClient::UI::Table::; 3641our @ISA = CFPlus::UI::Table::;
3633 3642
3634sub new { 3643sub new {
3635 my $class = shift; 3644 my $class = shift;
3636 3645
3637 my $self = $class->SUPER::new ( 3646 my $self = $class->SUPER::new (
3655 "<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");
3656 3665
3657sub rebuild_spell_list { 3666sub rebuild_spell_list {
3658 my ($self) = @_; 3667 my ($self) = @_;
3659 3668
3660 $CFClient::UI::ROOT->on_refresh ($self => sub { 3669 $CFPlus::UI::ROOT->on_refresh ($self => sub {
3661 $self->clear; 3670 $self->clear;
3662 3671
3663 return unless $::CONN; 3672 return unless $::CONN;
3664 3673
3665 $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);
3666 $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);
3667 $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);
3668 $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);
3669 $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);
3670 3679
3671 my $row = 0; 3680 my $row = 0;
3672 3681
3673 for (sort { $a cmp $b } keys %{ $self->{spell} }) { 3682 for (sort { $a cmp $b } keys %{ $self->{spell} }) {
3674 my $spell = $self->{spell}{$_}; 3683 my $spell = $self->{spell}{$_};
3681 if ($ev->{button} == 1) { 3690 if ($ev->{button} == 1) {
3682 $::CONN->user_send ("cast $spell->{name}"); 3691 $::CONN->user_send ("cast $spell->{name}");
3683 } elsif ($ev->{button} == 2) { 3692 } elsif ($ev->{button} == 2) {
3684 $::CONN->user_send ("invoke $spell->{name}"); 3693 $::CONN->user_send ("invoke $spell->{name}");
3685 } elsif ($ev->{button} == 3) { 3694 } elsif ($ev->{button} == 3) {
3686 (new CFClient::UI::Menu 3695 (new CFPlus::UI::Menu
3687 items => [ 3696 items => [
3688 ["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}"]) }],
3689 ["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}"]) }],
3690 ], 3699 ],
3691 )->popup ($ev); 3700 )->popup ($ev);
3697 }; 3706 };
3698 3707
3699 my $tooltip = "$spell->{message}$TOOLTIP_ALL"; 3708 my $tooltip = "$spell->{message}$TOOLTIP_ALL";
3700 3709
3701 #TODO: add path info to tooltip 3710 #TODO: add path info to tooltip
3702 #$self->add (6, $row, new CFClient::UI::Label text => $spell->{path}); 3711 #$self->add (6, $row, new CFPlus::UI::Label text => $spell->{path});
3703 3712
3704 $self->add (0, $row, new CFClient::UI::Face 3713 $self->add (0, $row, new CFPlus::UI::Face
3705 face => $spell->{face}, 3714 face => $spell->{face},
3706 can_hover => 1, 3715 can_hover => 1,
3707 can_events => 1, 3716 can_events => 1,
3708 tooltip => $tooltip, 3717 tooltip => $tooltip,
3709 on_button_down => $spell_cb, 3718 on_button_down => $spell_cb,
3710 ); 3719 );
3711 3720
3712 $self->add (1, $row, new CFClient::UI::Label 3721 $self->add (1, $row, new CFPlus::UI::Label
3713 expand => 1, 3722 expand => 1,
3714 text => $spell->{name}, 3723 text => $spell->{name},
3715 can_hover => 1, 3724 can_hover => 1,
3716 can_events => 1, 3725 can_events => 1,
3717 tooltip => $tooltip, 3726 tooltip => $tooltip,
3718 on_button_down => $spell_cb, 3727 on_button_down => $spell_cb,
3719 ); 3728 );
3720 3729
3721 $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);
3722 $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);
3723 $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);
3724 $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);
3725 } 3734 }
3726 }); 3735 });
3727} 3736}
3728 3737
3729sub add_spell { 3738sub add_spell {
3747 $self->rebuild_spell_list; 3756 $self->rebuild_spell_list;
3748} 3757}
3749 3758
3750############################################################################# 3759#############################################################################
3751 3760
3752package CFClient::UI::Root; 3761package CFPlus::UI::Root;
3753 3762
3754our @ISA = CFClient::UI::Container::; 3763our @ISA = CFPlus::UI::Container::;
3755 3764
3756use List::Util qw(min max); 3765use List::Util qw(min max);
3757 3766
3758use CFClient::OpenGL; 3767use CFPlus::OpenGL;
3759 3768
3760sub new { 3769sub new {
3761 my $class = shift; 3770 my $class = shift;
3762 3771
3763 my $self = $class->SUPER::new ( 3772 my $self = $class->SUPER::new (
3980 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; 3989 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
3981 glMatrixMode GL_MODELVIEW; 3990 glMatrixMode GL_MODELVIEW;
3982 glLoadIdentity; 3991 glLoadIdentity;
3983 3992
3984 { 3993 {
3985 package CFClient::UI::Base; 3994 package CFPlus::UI::Base;
3986 3995
3987 ($draw_x, $draw_y, $draw_w, $draw_h) = 3996 ($draw_x, $draw_y, $draw_w, $draw_h) =
3988 (0, 0, $self->{w}, $self->{h}); 3997 (0, 0, $self->{w}, $self->{h});
3989 } 3998 }
3990 3999
3991 $self->_draw; 4000 $self->_draw;
3992} 4001}
3993 4002
3994############################################################################# 4003#############################################################################
3995 4004
3996package CFClient::UI; 4005package CFPlus::UI;
3997 4006
3998$ROOT = new CFClient::UI::Root; 4007$ROOT = new CFPlus::UI::Root;
3999$TOOLTIP = new CFClient::UI::Tooltip z => 900; 4008$TOOLTIP = new CFPlus::UI::Tooltip z => 900;
4000 4009
40011 40101
4002 4011

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines