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.334 by root, Sun Jul 23 16:11:12 2006 UTC vs.
Revision 1.340 by root, Sun Jul 30 13:16:44 2006 UTC

1package CFClient::UI; 1package CFPlus::UI;
2 2
3use utf8; 3use utf8;
4use strict; 4use strict;
5 5
6use Scalar::Util (); 6use Scalar::Util ();
7use List::Util (); 7use List::Util ();
8use Event; 8use Event;
9 9
10use CFClient; 10use CFPlus;
11use CFClient::Texture; 11use CFPlus::Texture;
12 12
13our ($FOCUS, $HOVER, $GRAB); # various widgets 13our ($FOCUS, $HOVER, $GRAB); # various widgets
14 14
15our $LAYOUT; 15our $LAYOUT;
16our $ROOT; 16our $ROOT;
96 96
97sub feed_sdl_button_down_event { 97sub feed_sdl_button_down_event {
98 my ($ev) = @_; 98 my ($ev) = @_;
99 my ($x, $y) = ($ev->{x}, $ev->{y}); 99 my ($x, $y) = ($ev->{x}, $ev->{y});
100 100
101 unless ($BUTTON_STATE) { 101 $BUTTON_STATE |= 1 << ($ev->{button} - 1);
102
103 unless ($GRAB) {
102 my $widget = $ROOT->find_widget ($x, $y); 104 my $widget = $ROOT->find_widget ($x, $y);
103 105
104 $GRAB = $widget; 106 $GRAB = $widget;
105 $GRAB->update if $GRAB; 107 $GRAB->update if $GRAB;
106 108
107 $TOOLTIP_WATCHER->cb->(); 109 $TOOLTIP_WATCHER->cb->();
108 } 110 }
109
110 $BUTTON_STATE |= 1 << ($ev->{button} - 1);
111 111
112 if ($GRAB) { 112 if ($GRAB) {
113 if ($ev->{button} == 4 || $ev->{button} == 5) { 113 if ($ev->{button} == 4 || $ev->{button} == 5) {
114 # mousewheel 114 # mousewheel
115 $ev->{dx} = 0; 115 $ev->{dx} = 0;
207 reconfigure_widgets; 207 reconfigure_widgets;
208} 208}
209 209
210############################################################################# 210#############################################################################
211 211
212package CFClient::UI::Event; 212package CFPlus::UI::Event;
213 213
214sub xy { 214sub xy {
215 $_[1]->coord2local ($_[0]{x}, $_[0]{y}) 215 $_[1]->coord2local ($_[0]{x}, $_[0]{y})
216} 216}
217 217
218############################################################################# 218#############################################################################
219 219
220package CFClient::UI::Base; 220package CFPlus::UI::Base;
221 221
222use strict; 222use strict;
223 223
224use CFClient::OpenGL; 224use CFPlus::OpenGL;
225 225
226sub new { 226sub new {
227 my $class = shift; 227 my $class = shift;
228 228
229 my $self = bless { 229 my $self = bless {
234 h => undef, 234 h => undef,
235 can_events => 1, 235 can_events => 1,
236 @_ 236 @_
237 }, $class; 237 }, $class;
238 238
239 Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self); 239 Scalar::Util::weaken ($CFPlus::UI::WIDGET{$self+0} = $self);
240 240
241 for (keys %$self) { 241 for (keys %$self) {
242 if (/^on_(.*)$/) { 242 if (/^on_(.*)$/) {
243 $self->connect ($1 => delete $self->{$_}); 243 $self->connect ($1 => delete $self->{$_});
244 } 244 }
245 } 245 }
246 246
247 if (my $layout = $CFClient::UI::LAYOUT->{$self->{name}}) { 247 if (my $layout = $CFPlus::UI::LAYOUT->{$self->{name}}) {
248 $self->{x} = $layout->{x} * $CFClient::UI::ROOT->{alloc_w} if exists $layout->{x}; 248 $self->{x} = $layout->{x} * $CFPlus::UI::ROOT->{alloc_w} if exists $layout->{x};
249 $self->{y} = $layout->{y} * $CFClient::UI::ROOT->{alloc_h} if exists $layout->{y}; 249 $self->{y} = $layout->{y} * $CFPlus::UI::ROOT->{alloc_h} if exists $layout->{y};
250 $self->{force_w} = $layout->{w} * $CFClient::UI::ROOT->{alloc_w} if exists $layout->{w}; 250 $self->{force_w} = $layout->{w} * $CFPlus::UI::ROOT->{alloc_w} if exists $layout->{w};
251 $self->{force_h} = $layout->{h} * $CFClient::UI::ROOT->{alloc_h} if exists $layout->{h}; 251 $self->{force_h} = $layout->{h} * $CFPlus::UI::ROOT->{alloc_h} if exists $layout->{h};
252 252
253 $self->{x} -= $self->{force_w} * 0.5 if exists $layout->{x}; 253 $self->{x} -= $self->{force_w} * 0.5 if exists $layout->{x};
254 $self->{y} -= $self->{force_h} * 0.5 if exists $layout->{y}; 254 $self->{y} -= $self->{force_h} * 0.5 if exists $layout->{y};
255 255
256 $self->show if $layout->{show}; 256 $self->show if $layout->{show};
269sub show { 269sub show {
270 my ($self) = @_; 270 my ($self) = @_;
271 271
272 return if $self->{parent}; 272 return if $self->{parent};
273 273
274 $CFClient::UI::ROOT->add ($self); 274 $CFPlus::UI::ROOT->add ($self);
275} 275}
276 276
277sub set_visible { 277sub set_visible {
278 my ($self) = @_; 278 my ($self) = @_;
279 279
300 delete $self->{root}; 300 delete $self->{root};
301 301
302 undef $GRAB if $GRAB == $self; 302 undef $GRAB if $GRAB == $self;
303 undef $HOVER if $HOVER == $self; 303 undef $HOVER if $HOVER == $self;
304 304
305 $CFClient::UI::TOOLTIP_WATCHER->cb->() 305 $CFPlus::UI::TOOLTIP_WATCHER->cb->()
306 if $TOOLTIP->{owner} == $self; 306 if $TOOLTIP->{owner} == $self;
307 307
308 $self->emit ("focus_out"); 308 $self->emit ("focus_out");
309 $self->emit (visibility_change => 0); 309 $self->emit (visibility_change => 0);
310} 310}
367 my ($self, $x, $y, $w, $h) = @_; 367 my ($self, $x, $y, $w, $h) = @_;
368 368
369 if ($self->{aspect}) { 369 if ($self->{aspect}) {
370 my ($ow, $oh) = ($w, $h); 370 my ($ow, $oh) = ($w, $h);
371 371
372 $w = List::Util::min $w, int $h * $self->{aspect}; 372 $w = List::Util::min $w, CFPlus::ceil $h * $self->{aspect};
373 $h = List::Util::min $h, int $w / $self->{aspect}; 373 $h = List::Util::min $h, CFPlus::ceil $w / $self->{aspect};
374 374
375 # use alignment to adjust x, y 375 # use alignment to adjust x, y
376 376
377 $x += int 0.5 * ($ow - $w); 377 $x += int 0.5 * ($ow - $w);
378 $y += int 0.5 * ($oh - $h); 378 $y += int 0.5 * ($oh - $h);
419 419
420 return if $self->{tooltip} eq $tooltip; 420 return if $self->{tooltip} eq $tooltip;
421 421
422 $self->{tooltip} = $tooltip; 422 $self->{tooltip} = $tooltip;
423 423
424 if ($CFClient::UI::TOOLTIP->{owner} == $self) { 424 if ($CFPlus::UI::TOOLTIP->{owner} == $self) {
425 delete $CFClient::UI::TOOLTIP->{owner}; 425 delete $CFPlus::UI::TOOLTIP->{owner};
426 $CFClient::UI::TOOLTIP_WATCHER->cb->(); 426 $CFPlus::UI::TOOLTIP_WATCHER->cb->();
427 } 427 }
428} 428}
429 429
430# translate global coordinates to local coordinate system 430# translate global coordinates to local coordinate system
431sub coord2local { 431sub coord2local {
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
2066package CFPlus::UI::CheckBox;
2067
2068our @ISA = CFPlus::UI::DrawBG::;
2069
2070my @tex =
2071 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2072 qw(c1_checkbox_bg.png c1_checkbox_active.png);
2073
2074use CFPlus::OpenGL;
2075
2076sub new {
2077 my $class = shift;
2078
2079 $class->SUPER::new (
2080 padding_x => 2,
2081 padding_y => 2,
2082 fg => [1, 1, 1],
2083 active_fg => [1, 1, 0],
2084 bg => [0, 0, 0, 0.2],
2085 active_bg => [1, 1, 1, 0.5],
2086 state => 0,
2087 can_hover => 1,
2088 @_
2089 )
2090}
2091
2092sub size_request {
2093 my ($self) = @_;
2094
2095 (6) x 2
2096}
2097
2098sub toggle {
2099 my ($self) = @_;
2100
2101 $self->{state} = !$self->{state};
2102 $self->emit (changed => $self->{state});
2103 $self->update;
2104}
2105
2106sub invoke_button_down {
2107 my ($self, $ev, $x, $y) = @_;
2108
2109 if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x}
2110 && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) {
2111 $self->toggle;
2112 } else {
2113 return 0
2114 }
2115
2116 1
2117}
2118
2119sub _draw {
2120 my ($self) = @_;
2121
2122 $self->SUPER::_draw;
2123
2124 glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0;
2125
2126 my ($w, $h) = @$self{qw(w h)};
2127
2128 my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2;
2129
2130 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} };
2131
2132 my $tex = $self->{state} ? $tex[1] : $tex[0];
2133
2134 glEnable GL_TEXTURE_2D;
2135 $tex->draw_quad_alpha (0, 0, $s, $s);
2136 glDisable GL_TEXTURE_2D;
2137}
2138
2139#############################################################################
2140
2141package CFPlus::UI::Image;
2142
2143our @ISA = CFPlus::UI::Base::;
2144
2145use CFPlus::OpenGL;
2146
2147our %texture_cache;
2148
2149sub new {
2150 my $class = shift;
2151
2152 my $self = $class->SUPER::new (
2153 can_events => 0,
2154 @_,
2155 );
2156
2157 $self->{path} || $self->{tex}
2158 or Carp::croak "'path' or 'tex' attributes required";
2159
2160 $self->{tex} ||= $texture_cache{$self->{path}} ||=
2161 new_from_file CFPlus::Texture CFPlus::find_rcfile $self->{path}, mipmap => 1;
2162
2163 Scalar::Util::weaken $texture_cache{$self->{path}};
2164
2165 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2166
2167 $self
2168}
2169
2170sub STORABLE_freeze {
2171 my ($self, $cloning) = @_;
2172
2173 $self->{path}
2174 or die "cannot serialise CFPlus::UI::Image on non-loadable images\n";
2175
2176 $self->{path}
2177}
2178
2179sub STORABLE_attach {
2180 my ($self, $cloning, $path) = @_;
2181
2182 $self->new (path => $path)
2183}
2184
2185sub size_request {
2186 my ($self) = @_;
2187
2188 ($self->{tex}{w}, $self->{tex}{h})
2189}
2190
2191sub _draw {
2192 my ($self) = @_;
2193
2194 my $tex = $self->{tex};
2195
2196 my ($w, $h) = ($self->{w}, $self->{h});
2197
2198 if ($self->{rot90}) {
2199 glRotate 90, 0, 0, 1;
2200 glTranslate 0, -$self->{w}, 0;
2201
2202 ($w, $h) = ($h, $w);
2203 }
2204
2205 glEnable GL_TEXTURE_2D;
2206 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2207
2208 $tex->draw_quad (0, 0, $w, $h);
2209
2210 glDisable GL_TEXTURE_2D;
2211}
2212
2213#############################################################################
2214
2058package CFClient::UI::ImageButton; 2215package CFPlus::UI::ImageButton;
2059 2216
2060our @ISA = CFClient::UI::Image::; 2217our @ISA = CFPlus::UI::Image::;
2061 2218
2062use CFClient::OpenGL; 2219use CFPlus::OpenGL;
2063 2220
2064my %textures; 2221my %textures;
2065 2222
2066sub new { 2223sub new {
2067 my $class = shift; 2224 my $class = shift;
2089 1 2246 1
2090} 2247}
2091 2248
2092############################################################################# 2249#############################################################################
2093 2250
2094package CFClient::UI::CheckBox;
2095
2096our @ISA = CFClient::UI::DrawBG::;
2097
2098my @tex =
2099 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
2100 qw(c1_checkbox_bg.png c1_checkbox_active.png);
2101
2102use CFClient::OpenGL;
2103
2104sub new {
2105 my $class = shift;
2106
2107 $class->SUPER::new (
2108 padding_x => 2,
2109 padding_y => 2,
2110 fg => [1, 1, 1],
2111 active_fg => [1, 1, 0],
2112 bg => [0, 0, 0, 0.2],
2113 active_bg => [1, 1, 1, 0.5],
2114 state => 0,
2115 can_hover => 1,
2116 @_
2117 )
2118}
2119
2120sub size_request {
2121 my ($self) = @_;
2122
2123 (6) x 2
2124}
2125
2126sub toggle {
2127 my ($self) = @_;
2128
2129 $self->{state} = !$self->{state};
2130 $self->emit (changed => $self->{state});
2131 $self->update;
2132}
2133
2134sub invoke_button_down {
2135 my ($self, $ev, $x, $y) = @_;
2136
2137 if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x}
2138 && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) {
2139 $self->toggle;
2140 } else {
2141 return 0
2142 }
2143
2144 1
2145}
2146
2147sub _draw {
2148 my ($self) = @_;
2149
2150 $self->SUPER::_draw;
2151
2152 glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0;
2153
2154 my ($w, $h) = @$self{qw(w h)};
2155
2156 my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2;
2157
2158 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} };
2159
2160 my $tex = $self->{state} ? $tex[1] : $tex[0];
2161
2162 glEnable GL_TEXTURE_2D;
2163 $tex->draw_quad_alpha (0, 0, $s, $s);
2164 glDisable GL_TEXTURE_2D;
2165}
2166
2167#############################################################################
2168
2169package CFClient::UI::Image; 2251package CFPlus::UI::VGauge;
2170 2252
2171our @ISA = CFClient::UI::Base::; 2253our @ISA = CFPlus::UI::Base::;
2172
2173use CFClient::OpenGL;
2174
2175our %texture_cache;
2176
2177sub new {
2178 my $class = shift;
2179
2180 my $self = $class->SUPER::new (
2181 can_events => 0,
2182 @_,
2183 );
2184
2185 $self->{path} || $self->{tex}
2186 or Carp::croak "'path' or 'tex' attributes required";
2187
2188 $self->{tex} ||= $texture_cache{$self->{path}} ||=
2189 new_from_file CFClient::Texture CFClient::find_rcfile $self->{path}, mipmap => 1;
2190
2191 Scalar::Util::weaken $texture_cache{$self->{path}};
2192
2193 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2194
2195 $self
2196}
2197
2198sub STORABLE_freeze {
2199 my ($self, $cloning) = @_;
2200
2201 warn "freeze<$self>\n";#d#
2202
2203 $self->{path}
2204 or die "cannot serialise CFClient::UI::Image on non-loadable images\n";
2205
2206 $self->{path}
2207}
2208
2209sub STORABLE_attach {
2210 my ($self, $cloning, $path) = @_;
2211 warn "attach<@_>\n";#d#
2212
2213 $self->new (path => $path)
2214}
2215
2216sub size_request {
2217 my ($self) = @_;
2218
2219 ($self->{tex}{w}, $self->{tex}{h})
2220}
2221
2222sub _draw {
2223 my ($self) = @_;
2224
2225 my $tex = $self->{tex};
2226
2227 my ($w, $h) = ($self->{w}, $self->{h});
2228
2229 if ($self->{rot90}) {
2230 glRotate 90, 0, 0, 1;
2231 glTranslate 0, -$self->{w}, 0;
2232
2233 ($w, $h) = ($h, $w);
2234 }
2235
2236 glEnable GL_TEXTURE_2D;
2237 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2238
2239 $tex->draw_quad (0, 0, $w, $h);
2240
2241 glDisable GL_TEXTURE_2D;
2242}
2243
2244#############################################################################
2245
2246package CFClient::UI::VGauge;
2247
2248our @ISA = CFClient::UI::Base::;
2249 2254
2250use List::Util qw(min max); 2255use List::Util qw(min max);
2251 2256
2252use CFClient::OpenGL; 2257use CFPlus::OpenGL;
2253 2258
2254my %tex = ( 2259my %tex = (
2255 food => [ 2260 food => [
2256 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2261 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2257 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 2262 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
2258 ], 2263 ],
2259 grace => [ 2264 grace => [
2260 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2265 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2261 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/
2262 ], 2267 ],
2263 hp => [ 2268 hp => [
2264 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2269 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2265 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 2270 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
2266 ], 2271 ],
2267 mana => [ 2272 mana => [
2268 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2273 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2269 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/
2270 ], 2275 ],
2271); 2276);
2272 2277
2273# eg. VGauge->new (gauge => 'food'), default gauge: food 2278# eg. VGauge->new (gauge => 'food'), default gauge: food
2376 glDisable GL_TEXTURE_2D; 2381 glDisable GL_TEXTURE_2D;
2377} 2382}
2378 2383
2379############################################################################# 2384#############################################################################
2380 2385
2381package CFClient::UI::Gauge; 2386package CFPlus::UI::Gauge;
2382 2387
2383our @ISA = CFClient::UI::VBox::; 2388our @ISA = CFPlus::UI::VBox::;
2384 2389
2385sub new { 2390sub new {
2386 my ($class, %arg) = @_; 2391 my ($class, %arg) = @_;
2387 2392
2388 my $self = $class->SUPER::new ( 2393 my $self = $class->SUPER::new (
2390 can_hover => 1, 2395 can_hover => 1,
2391 can_events => 1, 2396 can_events => 1,
2392 %arg, 2397 %arg,
2393 ); 2398 );
2394 2399
2395 $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");
2396 $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);
2397 $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");
2398 2403
2399 $self 2404 $self
2400} 2405}
2401 2406
2402sub set_fontsize { 2407sub set_fontsize {
2423 $self->{value}->set_text ($val); 2428 $self->{value}->set_text ($val);
2424} 2429}
2425 2430
2426############################################################################# 2431#############################################################################
2427 2432
2428package CFClient::UI::Slider; 2433package CFPlus::UI::Slider;
2429 2434
2430use strict; 2435use strict;
2431 2436
2432use CFClient::OpenGL; 2437use CFPlus::OpenGL;
2433 2438
2434our @ISA = CFClient::UI::DrawBG::; 2439our @ISA = CFPlus::UI::DrawBG::;
2435 2440
2436my @tex = 2441my @tex =
2437 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 2442 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_ }
2438 qw(s1_slider.png s1_slider_bg.png); 2443 qw(s1_slider.png s1_slider_bg.png);
2439 2444
2440sub new { 2445sub new {
2441 my $class = shift; 2446 my $class = shift;
2442 2447
2597 glDisable GL_TEXTURE_2D; 2602 glDisable GL_TEXTURE_2D;
2598} 2603}
2599 2604
2600############################################################################# 2605#############################################################################
2601 2606
2602package CFClient::UI::ValSlider; 2607package CFPlus::UI::ValSlider;
2603 2608
2604our @ISA = CFClient::UI::HBox::; 2609our @ISA = CFPlus::UI::HBox::;
2605 2610
2606sub new { 2611sub new {
2607 my ($class, %arg) = @_; 2612 my ($class, %arg) = @_;
2608 2613
2609 my $range = delete $arg{range}; 2614 my $range = delete $arg{range};
2610 2615
2611 my $self = $class->SUPER::new ( 2616 my $self = $class->SUPER::new (
2612 slider => (new CFClient::UI::Slider expand => 1, range => $range), 2617 slider => (new CFPlus::UI::Slider expand => 1, range => $range),
2613 entry => (new CFClient::UI::Label text => "", template => delete $arg{template}), 2618 entry => (new CFPlus::UI::Label text => "", template => delete $arg{template}),
2614 to_value => sub { shift }, 2619 to_value => sub { shift },
2615 from_value => sub { shift }, 2620 from_value => sub { shift },
2616 %arg, 2621 %arg,
2617 ); 2622 );
2618 2623
2638sub set_range { shift->{slider}->set_range (@_) } 2643sub set_range { shift->{slider}->set_range (@_) }
2639sub set_value { shift->{slider}->set_value (@_) } 2644sub set_value { shift->{slider}->set_value (@_) }
2640 2645
2641############################################################################# 2646#############################################################################
2642 2647
2643package CFClient::UI::TextScroller; 2648package CFPlus::UI::TextScroller;
2644 2649
2645our @ISA = CFClient::UI::HBox::; 2650our @ISA = CFPlus::UI::HBox::;
2646 2651
2647use CFClient::OpenGL; 2652use CFPlus::OpenGL;
2648 2653
2649sub new { 2654sub new {
2650 my $class = shift; 2655 my $class = shift;
2651 2656
2652 my $self = $class->SUPER::new ( 2657 my $self = $class->SUPER::new (
2654 can_events => 1, 2659 can_events => 1,
2655 indent => 0, 2660 indent => 0,
2656 #font => default_font 2661 #font => default_font
2657 @_, 2662 @_,
2658 2663
2659 layout => (new CFClient::Layout), 2664 layout => (new CFPlus::Layout),
2660 par => [], 2665 par => [],
2661 height => 0, 2666 height => 0,
2662 children => [ 2667 children => [
2663 (new CFClient::UI::Empty expand => 1), 2668 (new CFPlus::UI::Empty expand => 1),
2664 (new CFClient::UI::Slider vertical => 1), 2669 (new CFPlus::UI::Slider vertical => 1),
2665 ], 2670 ],
2666 ); 2671 );
2667 2672
2668 $self->{children}[1]->connect (changed => sub { $self->update }); 2673 $self->{children}[1]->connect (changed => sub { $self->update });
2669 2674
2758 $self->{height} = 0; 2763 $self->{height} = 0;
2759 $self->{children}[1]->set_range ([0, 0, 0, 1, 1]); 2764 $self->{children}[1]->set_range ([0, 0, 0, 1, 1]);
2760} 2765}
2761 2766
2762sub add_paragraph { 2767sub add_paragraph {
2763 my ($self, $color, $para, $indent) = @_; 2768 my $self = shift;
2764 2769
2765 my ($text, @w) = ref $para ? @$para : $para; 2770 for my $para (@_) {
2766
2767 $para = { 2771 $para = {
2772 fg => [1, 1, 1, 1],
2773 indent => 0,
2774 markup => "",
2775 widget => [],
2776 ref $para ? %$para : (markup => $para),
2768 w => 1e10, 2777 w => 1e10,
2769 wrapped => 1, 2778 wrapped => 1,
2770 fg => $color,
2771 indent => $indent,
2772 markup => $text,
2773 widget => \@w,
2774 }; 2779 };
2775 2780
2776 $self->add (@w) if @w; 2781 $self->add (@{ $para->{widget} }) if @{ $para->{widget} };
2777 push @{$self->{par}}, $para; 2782 push @{$self->{par}}, $para;
2783 }
2778 2784
2779 $self->{need_reflow}++; 2785 $self->{need_reflow}++;
2780 $self->update; 2786 $self->update;
2781} 2787}
2782 2788
2824 2830
2825 if (delete $self->{scroll_to_bottom}) { 2831 if (delete $self->{scroll_to_bottom}) {
2826 $self->{children}[1]->set_value (1e10); 2832 $self->{children}[1]->set_value (1e10);
2827 } 2833 }
2828 2834
2829 $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { 2835 $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub {
2830 glClearColor 0, 0, 0, 0; 2836 glClearColor 0, 0, 0, 0;
2831 glClear GL_COLOR_BUFFER_BIT; 2837 glClear GL_COLOR_BUFFER_BIT;
2832 2838
2833 my $top = int $self->{children}[1]{range}[0]; 2839 my $top = int $self->{children}[1]{range}[0];
2834 2840
2887 $self->{children}[1]->draw; 2893 $self->{children}[1]->draw;
2888} 2894}
2889 2895
2890############################################################################# 2896#############################################################################
2891 2897
2892package CFClient::UI::Animator; 2898package CFPlus::UI::Animator;
2893 2899
2894use CFClient::OpenGL; 2900use CFPlus::OpenGL;
2895 2901
2896our @ISA = CFClient::UI::Bin::; 2902our @ISA = CFPlus::UI::Bin::;
2897 2903
2898sub moveto { 2904sub moveto {
2899 my ($self, $x, $y) = @_; 2905 my ($self, $x, $y) = @_;
2900 2906
2901 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 2907 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
2929 glPopMatrix; 2935 glPopMatrix;
2930} 2936}
2931 2937
2932############################################################################# 2938#############################################################################
2933 2939
2934package CFClient::UI::Flopper; 2940package CFPlus::UI::Flopper;
2935 2941
2936our @ISA = CFClient::UI::Button::; 2942our @ISA = CFPlus::UI::Button::;
2937 2943
2938sub new { 2944sub new {
2939 my $class = shift; 2945 my $class = shift;
2940 2946
2941 my $self = $class->SUPER::new ( 2947 my $self = $class->SUPER::new (
2953 $self->{other}->toggle_visibility; 2959 $self->{other}->toggle_visibility;
2954} 2960}
2955 2961
2956############################################################################# 2962#############################################################################
2957 2963
2958package CFClient::UI::Tooltip; 2964package CFPlus::UI::Tooltip;
2959 2965
2960our @ISA = CFClient::UI::Bin::; 2966our @ISA = CFPlus::UI::Bin::;
2961 2967
2962use CFClient::OpenGL; 2968use CFPlus::OpenGL;
2963 2969
2964sub new { 2970sub new {
2965 my $class = shift; 2971 my $class = shift;
2966 2972
2967 $class->SUPER::new ( 2973 $class->SUPER::new (
2983 } 2989 }
2984 2990
2985 $tooltip =~ s/^\n+//; 2991 $tooltip =~ s/^\n+//;
2986 $tooltip =~ s/\n+$//; 2992 $tooltip =~ s/\n+$//;
2987 2993
2988 $self->add (new CFClient::UI::Label 2994 $self->add (new CFPlus::UI::Label
2989 markup => $tooltip, 2995 markup => $tooltip,
2990 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 2996 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
2991 fontsize => 0.8, 2997 fontsize => 0.8,
2992 fg => [0, 0, 0, 1], 2998 fg => [0, 0, 0, 1],
2993 ellipsise => 0, 2999 ellipsise => 0,
3059 $self->SUPER::_draw; 3065 $self->SUPER::_draw;
3060} 3066}
3061 3067
3062############################################################################# 3068#############################################################################
3063 3069
3064package CFClient::UI::Face; 3070package CFPlus::UI::Face;
3065 3071
3066our @ISA = CFClient::UI::Base::; 3072our @ISA = CFPlus::UI::DrawBG::;
3067 3073
3068use CFClient::OpenGL; 3074use CFPlus::OpenGL;
3069 3075
3070sub new { 3076sub new {
3071 my $class = shift; 3077 my $class = shift;
3072 3078
3073 my $self = $class->SUPER::new ( 3079 my $self = $class->SUPER::new (
3108sub _draw { 3114sub _draw {
3109 my ($self) = @_; 3115 my ($self) = @_;
3110 3116
3111 return unless $::CONN; 3117 return unless $::CONN;
3112 3118
3119 $self->SUPER::_draw;
3120
3113 my $face; 3121 my $face;
3114 3122
3115 if ($self->{frame}) { 3123 if ($self->{frame}) {
3116 my $anim = $::CONN->{anim}[$self->{anim}]; 3124 my $anim = $::CONN->{anim}[$self->{anim}];
3117 3125
3139 $self->SUPER::destroy; 3147 $self->SUPER::destroy;
3140} 3148}
3141 3149
3142############################################################################# 3150#############################################################################
3143 3151
3144package CFClient::UI::Buttonbar; 3152package CFPlus::UI::Buttonbar;
3145 3153
3146our @ISA = CFClient::UI::HBox::; 3154our @ISA = CFPlus::UI::HBox::;
3147 3155
3148# TODO: should actualyl wrap buttons and other goodies. 3156# TODO: should actualyl wrap buttons and other goodies.
3149 3157
3150############################################################################# 3158#############################################################################
3151 3159
3152package CFClient::UI::Menu; 3160package CFPlus::UI::Menu;
3153 3161
3154our @ISA = CFClient::UI::FancyFrame::; 3162our @ISA = CFPlus::UI::FancyFrame::;
3155 3163
3156use CFClient::OpenGL; 3164use CFPlus::OpenGL;
3157 3165
3158sub new { 3166sub new {
3159 my $class = shift; 3167 my $class = shift;
3160 3168
3161 my $self = $class->SUPER::new ( 3169 my $self = $class->SUPER::new (
3162 items => [], 3170 items => [],
3163 z => 100, 3171 z => 100,
3164 @_, 3172 @_,
3165 ); 3173 );
3166 3174
3167 $self->add ($self->{vbox} = new CFClient::UI::VBox); 3175 $self->add ($self->{vbox} = new CFPlus::UI::VBox);
3168 3176
3169 for my $item (@{ $self->{items} }) { 3177 for my $item (@{ $self->{items} }) {
3170 my ($widget, $cb, $tooltip) = @$item; 3178 my ($widget, $cb, $tooltip) = @$item;
3171 3179
3172 # handle various types of items, only text for now 3180 # handle various types of items, only text for now
3173 if (!ref $widget) { 3181 if (!ref $widget) {
3174 if ($widget =~ /\t/) { 3182 if ($widget =~ /\t/) {
3175 my ($left, $right) = split /\t/, $widget, 2; 3183 my ($left, $right) = split /\t/, $widget, 2;
3176 3184
3177 $widget = new CFClient::UI::HBox 3185 $widget = new CFPlus::UI::HBox
3178 can_hover => 1, 3186 can_hover => 1,
3179 can_events => 1, 3187 can_events => 1,
3180 tooltip => $tooltip, 3188 tooltip => $tooltip,
3181 children => [ 3189 children => [
3182 (new CFClient::UI::Label markup => $left, expand => 1), 3190 (new CFPlus::UI::Label markup => $left, expand => 1),
3183 (new CFClient::UI::Label markup => $right, align => +1), 3191 (new CFPlus::UI::Label markup => $right, align => +1),
3184 ], 3192 ],
3185 ; 3193 ;
3186 3194
3187 } else { 3195 } else {
3188 $widget = new CFClient::UI::Label 3196 $widget = new CFPlus::UI::Label
3189 can_hover => 1, 3197 can_hover => 1,
3190 can_events => 1, 3198 can_events => 1,
3191 markup => $widget, 3199 markup => $widget,
3192 tooltip => $tooltip; 3200 tooltip => $tooltip;
3193 } 3201 }
3241 1 3249 1
3242} 3250}
3243 3251
3244############################################################################# 3252#############################################################################
3245 3253
3246package CFClient::UI::Multiplexer; 3254package CFPlus::UI::Multiplexer;
3247 3255
3248our @ISA = CFClient::UI::Container::; 3256our @ISA = CFPlus::UI::Container::;
3249 3257
3250sub new { 3258sub new {
3251 my $class = shift; 3259 my $class = shift;
3252 3260
3253 my $self = $class->SUPER::new ( 3261 my $self = $class->SUPER::new (
3314 $self->{current}->draw; 3322 $self->{current}->draw;
3315} 3323}
3316 3324
3317############################################################################# 3325#############################################################################
3318 3326
3319package CFClient::UI::Notebook; 3327package CFPlus::UI::Notebook;
3320 3328
3321our @ISA = CFClient::UI::VBox::; 3329our @ISA = CFPlus::UI::VBox::;
3322 3330
3323sub new { 3331sub new {
3324 my $class = shift; 3332 my $class = shift;
3325 3333
3326 my $self = $class->SUPER::new ( 3334 my $self = $class->SUPER::new (
3327 buttonbar => (new CFClient::UI::Buttonbar), 3335 buttonbar => (new CFPlus::UI::Buttonbar),
3328 multiplexer => (new CFClient::UI::Multiplexer expand => 1), 3336 multiplexer => (new CFPlus::UI::Multiplexer expand => 1),
3329 # filter => # will be put between multiplexer and $self 3337 # filter => # will be put between multiplexer and $self
3330 @_, 3338 @_,
3331 ); 3339 );
3332 3340
3333 $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; 3341 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
3339sub add { 3347sub add {
3340 my ($self, $title, $widget, $tooltip) = @_; 3348 my ($self, $title, $widget, $tooltip) = @_;
3341 3349
3342 Scalar::Util::weaken $self; 3350 Scalar::Util::weaken $self;
3343 3351
3344 $self->{buttonbar}->add (new CFClient::UI::Button 3352 $self->{buttonbar}->add (new CFPlus::UI::Button
3345 markup => $title, 3353 markup => $title,
3346 tooltip => $tooltip, 3354 tooltip => $tooltip,
3347 on_activate => sub { $self->set_current_page ($widget) }, 3355 on_activate => sub { $self->set_current_page ($widget) },
3348 ); 3356 );
3349 3357
3363 $self->emit (page_changed => $self->{multiplexer}{current}); 3371 $self->emit (page_changed => $self->{multiplexer}{current});
3364} 3372}
3365 3373
3366############################################################################# 3374#############################################################################
3367 3375
3368package CFClient::UI::Combobox; 3376package CFPlus::UI::Selector;
3369 3377
3370use utf8; 3378use utf8;
3371 3379
3372our @ISA = CFClient::UI::Button::; 3380our @ISA = CFPlus::UI::Button::;
3373 3381
3374sub new { 3382sub new {
3375 my $class = shift; 3383 my $class = shift;
3376 3384
3377 my $self = $class->SUPER::new ( 3385 my $self = $class->SUPER::new (
3394 my ($value, $title, $tooltip) = @$_; 3402 my ($value, $title, $tooltip) = @$_;
3395 3403
3396 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }]; 3404 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }];
3397 } 3405 }
3398 3406
3399 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); 3407 CFPlus::UI::Menu->new (items => \@menu_items)->popup ($ev);
3400} 3408}
3401 3409
3402sub _set_value { 3410sub _set_value {
3403 my ($self, $value) = @_; 3411 my ($self, $value) = @_;
3404 3412
3419 $self->emit (changed => $value); 3427 $self->emit (changed => $value);
3420} 3428}
3421 3429
3422############################################################################# 3430#############################################################################
3423 3431
3424package CFClient::UI::Statusbox; 3432package CFPlus::UI::Statusbox;
3425 3433
3426our @ISA = CFClient::UI::VBox::; 3434our @ISA = CFPlus::UI::VBox::;
3427 3435
3428sub new { 3436sub new {
3429 my $class = shift; 3437 my $class = shift;
3430 3438
3431 my $self = $class->SUPER::new ( 3439 my $self = $class->SUPER::new (
3443sub reorder { 3451sub reorder {
3444 my ($self) = @_; 3452 my ($self) = @_;
3445 my $NOW = Time::HiRes::time; 3453 my $NOW = Time::HiRes::time;
3446 3454
3447 # freeze display when hovering over any label 3455 # freeze display when hovering over any label
3448 return if $CFClient::UI::TOOLTIP->{owner} 3456 return if $CFPlus::UI::TOOLTIP->{owner}
3449 && grep $CFClient::UI::TOOLTIP->{owner} == $_->{label}, 3457 && grep $CFPlus::UI::TOOLTIP->{owner} == $_->{label},
3450 values %{ $self->{item} }; 3458 values %{ $self->{item} };
3451 3459
3452 while (my ($k, $v) = each %{ $self->{item} }) { 3460 while (my ($k, $v) = each %{ $self->{item} }) {
3453 delete $self->{item}{$k} if $v->{timeout} < $NOW; 3461 delete $self->{item}{$k} if $v->{timeout} < $NOW;
3454 } 3462 }
3475 for ($short) { 3483 for ($short) {
3476 s/^\s+//; 3484 s/^\s+//;
3477 s/\s+/ /g; 3485 s/\s+/ /g;
3478 } 3486 }
3479 3487
3480 new CFClient::UI::Label 3488 new CFPlus::UI::Label
3481 markup => $short, 3489 markup => $short,
3482 tooltip => $item->{tooltip}, 3490 tooltip => $item->{tooltip},
3483 tooltip_font => $::FONT_PROP, 3491 tooltip_font => $::FONT_PROP,
3484 tooltip_width => 0.67, 3492 tooltip_width => 0.67,
3485 fontsize => $item->{fontsize} || $self->{fontsize}, 3493 fontsize => $item->{fontsize} || $self->{fontsize},
3564 $self->SUPER::destroy; 3572 $self->SUPER::destroy;
3565} 3573}
3566 3574
3567############################################################################# 3575#############################################################################
3568 3576
3569package CFClient::UI::Inventory; 3577package CFPlus::UI::Inventory;
3570 3578
3571our @ISA = CFClient::UI::Table::; 3579our @ISA = CFPlus::UI::Table::;
3572 3580
3573sub new { 3581sub new {
3574 my $class = shift; 3582 my $class = shift;
3575 3583
3576 my $self = $class->SUPER::new ( 3584 my $self = $class->SUPER::new (
3592 my @item = $self->{sort}->(@{ $self->{items} }); 3600 my @item = $self->{sort}->(@{ $self->{items} });
3593 3601
3594 my @adds; 3602 my @adds;
3595 my $row = 0; 3603 my $row = 0;
3596 for my $item ($self->{sort}->(@{ $self->{items} })) { 3604 for my $item ($self->{sort}->(@{ $self->{items} })) {
3597 CFClient::Item::update_widgets $item; 3605 CFPlus::Item::update_widgets $item;
3598 3606
3599 push @adds, 0, $row, $item->{face_widget}; 3607 push @adds, 0, $row, $item->{face_widget};
3600 push @adds, 1, $row, $item->{desc_widget}; 3608 push @adds, 1, $row, $item->{desc_widget};
3601 push @adds, 2, $row, $item->{weight_widget}; 3609 push @adds, 2, $row, $item->{weight_widget};
3602 3610
3626 $self->update_items; 3634 $self->update_items;
3627} 3635}
3628 3636
3629############################################################################# 3637#############################################################################
3630 3638
3631package CFClient::UI::SpellList; 3639package CFPlus::UI::SpellList;
3632 3640
3633our @ISA = CFClient::UI::Table::; 3641our @ISA = CFPlus::UI::Table::;
3634 3642
3635sub new { 3643sub new {
3636 my $class = shift; 3644 my $class = shift;
3637 3645
3638 my $self = $class->SUPER::new ( 3646 my $self = $class->SUPER::new (
3656 "<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");
3657 3665
3658sub rebuild_spell_list { 3666sub rebuild_spell_list {
3659 my ($self) = @_; 3667 my ($self) = @_;
3660 3668
3661 $CFClient::UI::ROOT->on_refresh ($self => sub { 3669 $CFPlus::UI::ROOT->on_refresh ($self => sub {
3662 $self->clear; 3670 $self->clear;
3663 3671
3664 return unless $::CONN; 3672 return unless $::CONN;
3665 3673
3666 $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);
3667 $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);
3668 $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);
3669 $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);
3670 $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);
3671 3679
3672 my $row = 0; 3680 my $row = 0;
3673 3681
3674 for (sort { $a cmp $b } keys %{ $self->{spell} }) { 3682 for (sort { $a cmp $b } keys %{ $self->{spell} }) {
3675 my $spell = $self->{spell}{$_}; 3683 my $spell = $self->{spell}{$_};
3682 if ($ev->{button} == 1) { 3690 if ($ev->{button} == 1) {
3683 $::CONN->user_send ("cast $spell->{name}"); 3691 $::CONN->user_send ("cast $spell->{name}");
3684 } elsif ($ev->{button} == 2) { 3692 } elsif ($ev->{button} == 2) {
3685 $::CONN->user_send ("invoke $spell->{name}"); 3693 $::CONN->user_send ("invoke $spell->{name}");
3686 } elsif ($ev->{button} == 3) { 3694 } elsif ($ev->{button} == 3) {
3687 (new CFClient::UI::Menu 3695 (new CFPlus::UI::Menu
3688 items => [ 3696 items => [
3689 ["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}"]) }],
3690 ["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}"]) }],
3691 ], 3699 ],
3692 )->popup ($ev); 3700 )->popup ($ev);
3698 }; 3706 };
3699 3707
3700 my $tooltip = "$spell->{message}$TOOLTIP_ALL"; 3708 my $tooltip = "$spell->{message}$TOOLTIP_ALL";
3701 3709
3702 #TODO: add path info to tooltip 3710 #TODO: add path info to tooltip
3703 #$self->add (6, $row, new CFClient::UI::Label text => $spell->{path}); 3711 #$self->add (6, $row, new CFPlus::UI::Label text => $spell->{path});
3704 3712
3705 $self->add (0, $row, new CFClient::UI::Face 3713 $self->add (0, $row, new CFPlus::UI::Face
3706 face => $spell->{face}, 3714 face => $spell->{face},
3707 can_hover => 1, 3715 can_hover => 1,
3708 can_events => 1, 3716 can_events => 1,
3709 tooltip => $tooltip, 3717 tooltip => $tooltip,
3710 on_button_down => $spell_cb, 3718 on_button_down => $spell_cb,
3711 ); 3719 );
3712 3720
3713 $self->add (1, $row, new CFClient::UI::Label 3721 $self->add (1, $row, new CFPlus::UI::Label
3714 expand => 1, 3722 expand => 1,
3715 text => $spell->{name}, 3723 text => $spell->{name},
3716 can_hover => 1, 3724 can_hover => 1,
3717 can_events => 1, 3725 can_events => 1,
3718 tooltip => $tooltip, 3726 tooltip => $tooltip,
3719 on_button_down => $spell_cb, 3727 on_button_down => $spell_cb,
3720 ); 3728 );
3721 3729
3722 $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);
3723 $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);
3724 $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);
3725 $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);
3726 } 3734 }
3727 }); 3735 });
3728} 3736}
3729 3737
3730sub add_spell { 3738sub add_spell {
3748 $self->rebuild_spell_list; 3756 $self->rebuild_spell_list;
3749} 3757}
3750 3758
3751############################################################################# 3759#############################################################################
3752 3760
3753package CFClient::UI::Root; 3761package CFPlus::UI::Root;
3754 3762
3755our @ISA = CFClient::UI::Container::; 3763our @ISA = CFPlus::UI::Container::;
3756 3764
3757use List::Util qw(min max); 3765use List::Util qw(min max);
3758 3766
3759use CFClient::OpenGL; 3767use CFPlus::OpenGL;
3760 3768
3761sub new { 3769sub new {
3762 my $class = shift; 3770 my $class = shift;
3763 3771
3764 my $self = $class->SUPER::new ( 3772 my $self = $class->SUPER::new (
3943 $h = 0 if $h < 0; 3951 $h = 0 if $h < 0;
3944 3952
3945 $w = max $widget->{min_w}, $w; 3953 $w = max $widget->{min_w}, $w;
3946 $h = max $widget->{min_h}, $h; 3954 $h = max $widget->{min_h}, $h;
3947 3955
3956# $w = min $self->{w} - $widget->{x}, $w if $self->{w};
3957# $h = min $self->{h} - $widget->{y}, $h if $self->{h};
3958
3948 $w = min $widget->{max_w}, $w if exists $widget->{max_w}; 3959 $w = min $widget->{max_w}, $w if exists $widget->{max_w};
3949 $h = min $widget->{max_h}, $h if exists $widget->{max_h}; 3960 $h = min $widget->{max_h}, $h if exists $widget->{max_h};
3950 3961
3951 $w = int $w + 0.5; 3962 $w = int $w + 0.5;
3952 $h = int $h + 0.5; 3963 $h = int $h + 0.5;
3978 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; 3989 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
3979 glMatrixMode GL_MODELVIEW; 3990 glMatrixMode GL_MODELVIEW;
3980 glLoadIdentity; 3991 glLoadIdentity;
3981 3992
3982 { 3993 {
3983 package CFClient::UI::Base; 3994 package CFPlus::UI::Base;
3984 3995
3985 ($draw_x, $draw_y, $draw_w, $draw_h) = 3996 ($draw_x, $draw_y, $draw_w, $draw_h) =
3986 (0, 0, $self->{w}, $self->{h}); 3997 (0, 0, $self->{w}, $self->{h});
3987 } 3998 }
3988 3999
3989 $self->_draw; 4000 $self->_draw;
3990} 4001}
3991 4002
3992############################################################################# 4003#############################################################################
3993 4004
3994package CFClient::UI; 4005package CFPlus::UI;
3995 4006
3996$ROOT = new CFClient::UI::Root; 4007$ROOT = new CFPlus::UI::Root;
3997$TOOLTIP = new CFClient::UI::Tooltip z => 900; 4008$TOOLTIP = new CFPlus::UI::Tooltip z => 900;
3998 4009
39991 40101
4000 4011

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines