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.331 by root, Sun Jul 23 04:46:02 2006 UTC vs.
Revision 1.364 by root, Sat Dec 23 10:18:27 2006 UTC

1package CFClient::UI; 1package CFPlus::UI;
2 2
3use utf8; 3use utf8;
4use strict; 4use strict;
5 5
6use Scalar::Util ();
7use List::Util (); 6use List::Util ();
8use Event; 7use Event;
9 8
10use CFClient; 9use CFPlus;
10use CFPlus::Pod;
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 CFPlus::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};
261 261
262sub destroy { 262sub destroy {
263 my ($self) = @_; 263 my ($self) = @_;
264 264
265 $self->hide; 265 $self->hide;
266 $self->emit ("destroy");
266 %$self = (); 267 %$self = ();
267} 268}
268 269
269sub show { 270sub show {
270 my ($self) = @_; 271 my ($self) = @_;
271 272
272 return if $self->{parent}; 273 return if $self->{parent};
273 274
274 $CFClient::UI::ROOT->add ($self); 275 $CFPlus::UI::ROOT->add ($self);
275} 276}
276 277
277sub set_visible { 278sub set_visible {
278 my ($self) = @_; 279 my ($self) = @_;
279 280
300 delete $self->{root}; 301 delete $self->{root};
301 302
302 undef $GRAB if $GRAB == $self; 303 undef $GRAB if $GRAB == $self;
303 undef $HOVER if $HOVER == $self; 304 undef $HOVER if $HOVER == $self;
304 305
305 $CFClient::UI::TOOLTIP_WATCHER->cb->() 306 $CFPlus::UI::TOOLTIP_WATCHER->cb->()
306 if $TOOLTIP->{owner} == $self; 307 if $TOOLTIP->{owner} == $self;
307 308
308 $self->emit ("focus_out"); 309 $self->emit ("focus_out");
309 $self->emit (visibility_change => 0); 310 $self->emit (visibility_change => 0);
310} 311}
367 my ($self, $x, $y, $w, $h) = @_; 368 my ($self, $x, $y, $w, $h) = @_;
368 369
369 if ($self->{aspect}) { 370 if ($self->{aspect}) {
370 my ($ow, $oh) = ($w, $h); 371 my ($ow, $oh) = ($w, $h);
371 372
372 $w = List::Util::min $w, int $h * $self->{aspect}; 373 $w = List::Util::min $w, CFPlus::ceil $h * $self->{aspect};
373 $h = List::Util::min $h, int $w / $self->{aspect}; 374 $h = List::Util::min $h, CFPlus::ceil $w / $self->{aspect};
374 375
375 # use alignment to adjust x, y 376 # use alignment to adjust x, y
376 377
377 $x += int 0.5 * ($ow - $w); 378 $x += int 0.5 * ($ow - $w);
378 $y += int 0.5 * ($oh - $h); 379 $y += int 0.5 * ($oh - $h);
419 420
420 return if $self->{tooltip} eq $tooltip; 421 return if $self->{tooltip} eq $tooltip;
421 422
422 $self->{tooltip} = $tooltip; 423 $self->{tooltip} = $tooltip;
423 424
424 if ($CFClient::UI::TOOLTIP->{owner} == $self) { 425 if ($CFPlus::UI::TOOLTIP->{owner} == $self) {
425 delete $CFClient::UI::TOOLTIP->{owner}; 426 delete $CFPlus::UI::TOOLTIP->{owner};
426 $CFClient::UI::TOOLTIP_WATCHER->cb->(); 427 $CFPlus::UI::TOOLTIP_WATCHER->cb->();
427 } 428 }
428} 429}
429 430
430# translate global coordinates to local coordinate system 431# translate global coordinates to local coordinate system
431sub coord2local { 432sub coord2local {
437} 438}
438 439
439# translate local coordinates to global coordinate system 440# translate local coordinates to global coordinate system
440sub coord2global { 441sub coord2global {
441 my ($self, $x, $y) = @_; 442 my ($self, $x, $y) = @_;
443
444 Carp::confess unless $self->{parent};#d#
442 445
443 $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y}) 446 $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y})
444} 447}
445 448
446sub invoke_focus_in { 449sub invoke_focus_in {
494 497
495sub connect { 498sub connect {
496 my ($self, $signal, $cb) = @_; 499 my ($self, $signal, $cb) = @_;
497 500
498 push @{ $self->{signal_cb}{$signal} }, $cb; 501 push @{ $self->{signal_cb}{$signal} }, $cb;
502
503 defined wantarray and CFPlus::guard {
504 @{ $self->{signal_cb}{$signal} } = grep $_ != $cb,
505 @{ $self->{signal_cb}{$signal} };
506 }
507}
508
509sub disconnect_all {
510 my ($self, $signal) = @_;
511
512 delete $self->{signal_cb}{$signal};
499} 513}
500 514
501my %has_coords = ( 515my %has_coords = (
502 button_down => 1, 516 button_down => 1,
503 button_up => 1, 517 button_up => 1,
506); 520);
507 521
508sub emit { 522sub emit {
509 my ($self, $signal, @args) = @_; 523 my ($self, $signal, @args) = @_;
510 524
525 # I do not really like this solution, but I do not like duplication
526 # and needlessly verbose code, either.
511 my @append 527 my @append
512 = $has_coords{$signal} 528 = $has_coords{$signal}
513 ? $args[0]->xy ($self) 529 ? $args[0]->xy ($self)
514 : (); 530 : ();
515 531
516 #warn +(caller(1))[3] . "emit $signal on $self (parent $self->{parent})\n";#d# 532 #warn +(caller(1))[3] . "emit $signal on $self (parent $self->{parent})\n";#d#
517 533
518 #d##TODO# stop propagating at first true, do not use sum 534 for my $cb (
519 (List::Util::sum map $_->($self, @args, @append), @{$self->{signal_cb}{$signal} || []}) # before 535 @{$self->{signal_cb}{$signal} || []}, # before
520 || ($self->can ("invoke_$signal") || sub { 1 })->($self, @args, @append) # closure 536 ($self->can ("invoke_$signal") || sub { 1 }), # closure
537 ) {
538 return $cb->($self, @args, @append) || next;
539 }
540
541 # parent
521 || ($self->{parent} && $self->{parent}->emit ($signal, @args)) # parent 542 $self->{parent} && $self->{parent}->emit ($signal, @args)
522} 543}
523 544
524sub find_widget { 545sub find_widget {
525 my ($self, $x, $y) = @_; 546 my ($self, $x, $y) = @_;
526 547
534} 555}
535 556
536sub set_parent { 557sub set_parent {
537 my ($self, $parent) = @_; 558 my ($self, $parent) = @_;
538 559
539 Scalar::Util::weaken ($self->{parent} = $parent); 560 CFPlus::weaken ($self->{parent} = $parent);
540 $self->set_visible if $parent->{visible}; 561 $self->set_visible if $parent->{visible};
541} 562}
542 563
543sub realloc { 564sub realloc {
544 my ($self) = @_; 565 my ($self) = @_;
610 glVertex $self->{w} - 1, 0; 631 glVertex $self->{w} - 1, 0;
611 glVertex $self->{w} - 1, $self->{h} - 1; 632 glVertex $self->{w} - 1, $self->{h} - 1;
612 glVertex 0 , $self->{h} - 1; 633 glVertex 0 , $self->{h} - 1;
613 glEnd; 634 glEnd;
614 glPopMatrix; 635 glPopMatrix;
615 #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; 636 #CFPlus::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw;
616 } 637 }
617 638
618 $self->_draw; 639 $self->_draw;
619 glPopMatrix; 640 glPopMatrix;
620} 641}
623 my ($self) = @_; 644 my ($self) = @_;
624 645
625 warn "no draw defined for $self\n"; 646 warn "no draw defined for $self\n";
626} 647}
627 648
649my $cntx;#d#
628sub DESTROY { 650sub DESTROY {
629 my ($self) = @_; 651 my ($self) = @_;
630 652
631 return if CFClient::in_destruct; 653 return if CFPlus::in_destruct;
632
633 delete $WIDGET{$self+0};
634 654
635 eval { $self->destroy }; 655 eval { $self->destroy };
636 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; 656 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/;
657
658 delete $WIDGET{$self+0};
637} 659}
638 660
639############################################################################# 661#############################################################################
640 662
641package CFClient::UI::DrawBG; 663package CFPlus::UI::DrawBG;
642 664
643our @ISA = CFClient::UI::Base::; 665our @ISA = CFPlus::UI::Base::;
644 666
645use strict; 667use strict;
646use CFClient::OpenGL; 668use CFPlus::OpenGL;
647 669
648sub new { 670sub new {
649 my $class = shift; 671 my $class = shift;
650 672
651 # range [value, low, high, page] 673 # range [value, low, high, page]
682 } 704 }
683} 705}
684 706
685############################################################################# 707#############################################################################
686 708
687package CFClient::UI::Empty; 709package CFPlus::UI::Empty;
688 710
689our @ISA = CFClient::UI::Base::; 711our @ISA = CFPlus::UI::Base::;
690 712
691sub new { 713sub new {
692 my ($class, %arg) = @_; 714 my ($class, %arg) = @_;
693 $class->SUPER::new (can_events => 0, %arg); 715 $class->SUPER::new (can_events => 0, %arg);
694} 716}
701 723
702sub draw { } 724sub draw { }
703 725
704############################################################################# 726#############################################################################
705 727
706package CFClient::UI::Container; 728package CFPlus::UI::Container;
707 729
708our @ISA = CFClient::UI::Base::; 730our @ISA = CFPlus::UI::Base::;
709 731
710sub new { 732sub new {
711 my ($class, %arg) = @_; 733 my ($class, %arg) = @_;
712 734
713 my $children = delete $arg{children}; 735 my $children = delete $arg{children};
722 if $children; 744 if $children;
723 745
724 $self 746 $self
725} 747}
726 748
749sub realloc {
750 my ($self) = @_;
751
752 $self->{force_realloc} = 1;
753 $self->{force_size_alloc} = 1;
754 $self->SUPER::realloc;
755}
756
727sub add { 757sub add {
728 my ($self, @widgets) = @_; 758 my ($self, @widgets) = @_;
729 759
730 $_->set_parent ($self) 760 $_->set_parent ($self)
731 for @widgets; 761 for @widgets;
791 $_->draw for @{$self->{children}}; 821 $_->draw for @{$self->{children}};
792} 822}
793 823
794############################################################################# 824#############################################################################
795 825
796package CFClient::UI::Bin; 826package CFPlus::UI::Bin;
797 827
798our @ISA = CFClient::UI::Container::; 828our @ISA = CFPlus::UI::Container::;
799 829
800sub new { 830sub new {
801 my ($class, %arg) = @_; 831 my ($class, %arg) = @_;
802 832
803 my $child = (delete $arg{child}) || new CFClient::UI::Empty::; 833 my $child = (delete $arg{child}) || new CFPlus::UI::Empty::;
804 834
805 $class->SUPER::new (children => [$child], %arg) 835 $class->SUPER::new (children => [$child], %arg)
806} 836}
807 837
808sub add { 838sub add {
815sub remove { 845sub remove {
816 my ($self, $widget) = @_; 846 my ($self, $widget) = @_;
817 847
818 $self->SUPER::remove ($widget); 848 $self->SUPER::remove ($widget);
819 849
820 $self->{children} = [new CFClient::UI::Empty] 850 $self->{children} = [new CFPlus::UI::Empty]
821 unless @{$self->{children}}; 851 unless @{$self->{children}};
822} 852}
823 853
824sub child { $_[0]->{children}[0] } 854sub child { $_[0]->{children}[0] }
825 855
837 867
838############################################################################# 868#############################################################################
839 869
840# back-buffered drawing area 870# back-buffered drawing area
841 871
842package CFClient::UI::Window; 872package CFPlus::UI::Window;
843 873
844our @ISA = CFClient::UI::Bin::; 874our @ISA = CFPlus::UI::Bin::;
845 875
846use CFClient::OpenGL; 876use CFPlus::OpenGL;
847 877
848sub new { 878sub new {
849 my ($class, %arg) = @_; 879 my ($class, %arg) = @_;
850 880
851 my $self = $class->SUPER::new (%arg); 881 my $self = $class->SUPER::new (%arg);
873} 903}
874 904
875sub render_child { 905sub render_child {
876 my ($self) = @_; 906 my ($self) = @_;
877 907
878 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { 908 $self->{texture} = new_from_opengl CFPlus::Texture $self->{w}, $self->{h}, sub {
879 glClearColor 0, 0, 0, 0; 909 glClearColor 0, 0, 0, 0;
880 glClear GL_COLOR_BUFFER_BIT; 910 glClear GL_COLOR_BUFFER_BIT;
881 911
882 { 912 {
883 package CFClient::UI::Base; 913 package CFPlus::UI::Base;
884 914
885 ($draw_x, $draw_y, $draw_w, $draw_h) = 915 local ($draw_x, $draw_y, $draw_w, $draw_h) =
886 (0, 0, $self->{w}, $self->{h}); 916 (0, 0, $self->{w}, $self->{h});
917
918 $self->_render;
887 } 919 }
888
889 $self->_render;
890 }; 920 };
891} 921}
892 922
893sub _draw { 923sub _draw {
894 my ($self) = @_; 924 my ($self) = @_;
895
896 my ($w, $h) = @$self{qw(w h)};
897 925
898 my $tex = $self->{texture} 926 my $tex = $self->{texture}
899 or return; 927 or return;
900 928
901 glEnable GL_TEXTURE_2D; 929 glEnable GL_TEXTURE_2D;
902 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 930 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
903 glColor 0, 0, 0, 1; 931 glColor 0, 0, 0, 1;
904 932
905 $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); 933 $tex->draw_quad_alpha_premultiplied (0, 0);
906 934
907 glDisable GL_TEXTURE_2D; 935 glDisable GL_TEXTURE_2D;
908} 936}
909 937
910############################################################################# 938#############################################################################
911 939
912package CFClient::UI::ViewPort; 940package CFPlus::UI::ViewPort;
913 941
914our @ISA = CFClient::UI::Window::; 942our @ISA = CFPlus::UI::Window::;
915 943
916sub new { 944sub new {
917 my $class = shift; 945 my $class = shift;
918 946
919 $class->SUPER::new ( 947 $class->SUPER::new (
979 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} 1007 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w}
980 && $y >= $self->{y} && $y < $self->{y} + $self->{h} 1008 && $y >= $self->{y} && $y < $self->{y} + $self->{h}
981 ) { 1009 ) {
982 $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y}) 1010 $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y})
983 } else { 1011 } else {
984 $self->CFClient::UI::Base::find_widget ($x, $y) 1012 $self->CFPlus::UI::Base::find_widget ($x, $y)
985 } 1013 }
986} 1014}
987 1015
988sub _render { 1016sub _render {
989 my ($self) = @_; 1017 my ($self) = @_;
990 1018
991 local $CFClient::UI::Base::draw_x = $CFClient::UI::Base::draw_x - $self->{view_x}; 1019 local $CFPlus::UI::Base::draw_x = $CFPlus::UI::Base::draw_x - $self->{view_x};
992 local $CFClient::UI::Base::draw_y = $CFClient::UI::Base::draw_y - $self->{view_y}; 1020 local $CFPlus::UI::Base::draw_y = $CFPlus::UI::Base::draw_y - $self->{view_y};
993 1021
994 CFClient::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; 1022 CFPlus::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y};
995 1023
996 $self->SUPER::_render; 1024 $self->SUPER::_render;
997} 1025}
998 1026
999############################################################################# 1027#############################################################################
1000 1028
1001package CFClient::UI::ScrolledWindow; 1029package CFPlus::UI::ScrolledWindow;
1002 1030
1003our @ISA = CFClient::UI::HBox::; 1031our @ISA = CFPlus::UI::HBox::;
1004 1032
1005sub new { 1033sub new {
1006 my ($class, %arg) = @_; 1034 my ($class, %arg) = @_;
1007 1035
1008 my $child = delete $arg{child}; 1036 my $child = delete $arg{child};
1009 1037
1010 my $self; 1038 my $self;
1011 1039
1012 my $slider = new CFClient::UI::Slider 1040 my $slider = new CFPlus::UI::Slider
1013 vertical => 1, 1041 vertical => 1,
1014 range => [0, 0, 1, 0.01], # HACK fix 1042 range => [0, 0, 1, 0.01], # HACK fix
1015 on_changed => sub { 1043 on_changed => sub {
1016 $self->{vp}->set_offset (0, $_[1]); 1044 $self->{vp}->set_offset (0, $_[1]);
1017 }, 1045 },
1018 ; 1046 ;
1019 1047
1020 $self = $class->SUPER::new ( 1048 $self = $class->SUPER::new (
1021 vp => (new CFClient::UI::ViewPort expand => 1), 1049 vp => (new CFPlus::UI::ViewPort expand => 1),
1022 can_events => 1, 1050 can_events => 1,
1023 slider => $slider, 1051 slider => $slider,
1024 %arg, 1052 %arg,
1025 ); 1053 );
1026 1054
1070 $self->SUPER::invoke_size_allocate ($w, $h) 1098 $self->SUPER::invoke_size_allocate ($w, $h)
1071} 1099}
1072 1100
1073############################################################################# 1101#############################################################################
1074 1102
1075package CFClient::UI::Frame; 1103package CFPlus::UI::Frame;
1076 1104
1077our @ISA = CFClient::UI::Bin::; 1105our @ISA = CFPlus::UI::Bin::;
1078 1106
1079use CFClient::OpenGL; 1107use CFPlus::OpenGL;
1080 1108
1081sub new { 1109sub new {
1082 my $class = shift; 1110 my $class = shift;
1083 1111
1084 $class->SUPER::new ( 1112 $class->SUPER::new (
1110 $self->SUPER::_draw; 1138 $self->SUPER::_draw;
1111} 1139}
1112 1140
1113############################################################################# 1141#############################################################################
1114 1142
1115package CFClient::UI::FancyFrame; 1143package CFPlus::UI::FancyFrame;
1116 1144
1117our @ISA = CFClient::UI::Bin::; 1145our @ISA = CFPlus::UI::Bin::;
1118 1146
1119use CFClient::OpenGL; 1147use CFPlus::OpenGL;
1148
1149sub new {
1150 my ($class, %arg) = @_;
1151
1152 if ((exists $arg{label}) && !ref $arg{label}) {
1153 $arg{label} = new CFPlus::UI::Label
1154 align => 1,
1155 valign => 0,
1156 text => $arg{label},
1157 fontsize => ($arg{border} || 0.8) * 0.75;
1158 }
1159
1160 my $self = $class->SUPER::new (
1161 # label => "",
1162 fg => [0.6, 0.3, 0.1],
1163 border => 0.8,
1164 style => 'single',
1165 %arg,
1166 );
1167
1168 $self
1169}
1170
1171sub add {
1172 my ($self, @widgets) = @_;
1173
1174 $self->SUPER::add (@widgets);
1175 $self->CFPlus::UI::Container::add ($self->{label}) if $self->{label};
1176}
1177
1178sub border {
1179 int $_[0]{border} * $::FONTSIZE
1180}
1181
1182sub size_request {
1183 my ($self) = @_;
1184
1185 ($self->{label_w}, undef) = $self->{label}->size_request
1186 if $self->{label};
1187
1188 my ($w, $h) = $self->SUPER::size_request;
1189
1190 (
1191 $w + $self->border * 2,
1192 $h + $self->border * 2,
1193 )
1194}
1195
1196sub invoke_size_allocate {
1197 my ($self, $w, $h) = @_;
1198
1199 my $border = $self->border;
1200
1201 $w -= List::Util::max 0, $border * 2;
1202 $h -= List::Util::max 0, $border * 2;
1203
1204 if (my $label = $self->{label}) {
1205 $label->{w} = List::Util::max 0, List::Util::min $self->{label_w}, $w - $border * 2;
1206 $label->{h} = List::Util::min $h, $border;
1207 $label->invoke_size_allocate ($label->{w}, $label->{h});
1208 }
1209
1210 $self->child->configure ($border, $border, $w, $h);
1211
1212 1
1213}
1214
1215sub _draw {
1216 my ($self) = @_;
1217
1218 my $child = $self->{children}[0];
1219
1220 my $border = $self->border;
1221 my ($w, $h) = ($self->{w}, $self->{h});
1222
1223 $child->draw;
1224
1225 glColor @{$self->{fg}};
1226 glBegin GL_LINE_STRIP;
1227 glVertex $border * 1.5 , $border * 0.5 + 0.5;
1228 glVertex $border * 0.5 + 0.5, $border * 0.5 + 0.5;
1229 glVertex $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5;
1230 glVertex $w - $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5;
1231 glVertex $w - $border * 0.5 + 0.5, $border * 0.5 + 0.5;
1232 glVertex $self->{label} ? $border * 2 + $self->{label}{w} : $border * 1.5, $border * 0.5 + 0.5;
1233 glEnd;
1234
1235 if ($self->{label}) {
1236 glTranslate $border * 2, 0;
1237 $self->{label}->_draw;
1238 }
1239}
1240
1241#############################################################################
1242
1243package CFPlus::UI::Toplevel;
1244
1245our @ISA = CFPlus::UI::Bin::;
1246
1247use CFPlus::OpenGL;
1120 1248
1121my $bg = 1249my $bg =
1122 new_from_file CFClient::Texture CFClient::find_rcfile "d1_bg.png", 1250 new_from_file CFPlus::Texture CFPlus::find_rcfile "d1_bg.png",
1123 mipmap => 1, wrap => 1; 1251 mipmap => 1, wrap => 1;
1124 1252
1125my @border = 1253my @border =
1126 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1254 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
1127 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); 1255 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
1128 1256
1129sub new { 1257sub new {
1130 my ($class, %arg) = @_; 1258 my ($class, %arg) = @_;
1131 1259
1137 min_w => 64, 1265 min_w => 64,
1138 min_h => 32, 1266 min_h => 32,
1139 %arg, 1267 %arg,
1140 ); 1268 );
1141 1269
1142 $self->{title_widget} = new CFClient::UI::Label 1270 $self->{title_widget} = new CFPlus::UI::Label
1143 align => 0, 1271 align => 0,
1144 valign => 1, 1272 valign => 1,
1145 text => $self->{title}, 1273 text => $self->{title},
1146 fontsize => $self->{border}, 1274 fontsize => $self->{border},
1147 if exists $self->{title}; 1275 if exists $self->{title};
1148 1276
1149 if ($self->{has_close_button}) { 1277 if ($self->{has_close_button}) {
1150 $self->{close_button} = 1278 $self->{close_button} =
1151 new CFClient::UI::ImageButton 1279 new CFPlus::UI::ImageButton
1152 path => 'x1_close.png', 1280 path => 'x1_close.png',
1153 on_activate => sub { $self->emit ("delete") }; 1281 on_activate => sub { $self->emit ("delete") };
1154 1282
1155 $self->CFClient::UI::Container::add ($self->{close_button}); 1283 $self->CFPlus::UI::Container::add ($self->{close_button});
1156 } 1284 }
1157 1285
1158 $self 1286 $self
1159} 1287}
1160 1288
1161sub add { 1289sub add {
1162 my ($self, @widgets) = @_; 1290 my ($self, @widgets) = @_;
1163 1291
1164 $self->SUPER::add (@widgets); 1292 $self->SUPER::add (@widgets);
1165 $self->CFClient::UI::Container::add ($self->{close_button}) if $self->{close_button}; 1293 $self->CFPlus::UI::Container::add ($self->{close_button}) if $self->{close_button};
1166 $self->CFClient::UI::Container::add ($self->{title_widget}) if $self->{title_widget}; 1294 $self->CFPlus::UI::Container::add ($self->{title_widget}) if $self->{title_widget};
1167} 1295}
1168 1296
1169sub border { 1297sub border {
1170 int $_[0]{border} * $::FONTSIZE 1298 int $_[0]{border} * $::FONTSIZE
1171} 1299}
1279 $self->{motion}->($ev, $x, $y) if $self->{motion}; 1407 $self->{motion}->($ev, $x, $y) if $self->{motion};
1280 1408
1281 ! ! $self->{motion} 1409 ! ! $self->{motion}
1282} 1410}
1283 1411
1412sub invoke_visibility_change {
1413 my ($self, $visible) = @_;
1414
1415 delete $self->{motion} unless $visible;
1416
1417 0
1418}
1419
1284sub _draw { 1420sub _draw {
1285 my ($self) = @_; 1421 my ($self) = @_;
1286 1422
1287 my $child = $self->{children}[0]; 1423 my $child = $self->{children}[0];
1288 1424
1325 if $self->{close_button}; 1461 if $self->{close_button};
1326} 1462}
1327 1463
1328############################################################################# 1464#############################################################################
1329 1465
1330package CFClient::UI::Table; 1466package CFPlus::UI::Table;
1331 1467
1332our @ISA = CFClient::UI::Base::; 1468our @ISA = CFPlus::UI::Base::;
1333 1469
1334use List::Util qw(max sum); 1470use List::Util qw(max sum);
1335 1471
1336use CFClient::OpenGL; 1472use CFPlus::OpenGL;
1337 1473
1338sub new { 1474sub new {
1339 my $class = shift; 1475 my $class = shift;
1340 1476
1341 $class->SUPER::new ( 1477 $class->SUPER::new (
1347sub children { 1483sub children {
1348 grep $_, map @$_, grep $_, @{ $_[0]{children} } 1484 grep $_, map @$_, grep $_, @{ $_[0]{children} }
1349} 1485}
1350 1486
1351sub add { 1487sub add {
1352 my ($self, $x, $y, $child) = @_; 1488 my ($self) = shift;
1353 1489
1490 while (@_) {
1491 my ($x, $y, $child) = splice @_, 0, 3, ();
1354 $child->set_parent ($self); 1492 $child->set_parent ($self);
1355 $self->{children}[$y][$x] = $child; 1493 $self->{children}[$y][$x] = $child;
1494 }
1356 1495
1496 $self->{force_realloc} = 1;
1497 $self->{force_size_alloc} = 1;
1357 $self->realloc; 1498 $self->realloc;
1358} 1499}
1359 1500
1360sub remove { 1501sub remove {
1361 my ($self, $child) = @_; 1502 my ($self, $child) = @_;
1426 1567
1427 # linearly scale sizes 1568 # linearly scale sizes
1428 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; 1569 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws;
1429 $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs; 1570 $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs;
1430 1571
1431 CFClient::UI::harmonize $ws; 1572 CFPlus::UI::harmonize $ws;
1432 CFClient::UI::harmonize $hs; 1573 CFPlus::UI::harmonize $hs;
1433 1574
1434 my $y; 1575 my $y;
1435 1576
1436 for my $r (0 .. $#{$self->{children}}) { 1577 for my $r (0 .. $#{$self->{children}}) {
1437 my $row = $self->{children}[$r] 1578 my $row = $self->{children}[$r]
1480 } 1621 }
1481} 1622}
1482 1623
1483############################################################################# 1624#############################################################################
1484 1625
1485package CFClient::UI::Box; 1626package CFPlus::UI::Box;
1486 1627
1487our @ISA = CFClient::UI::Container::; 1628our @ISA = CFPlus::UI::Container::;
1488 1629
1489sub size_request { 1630sub size_request {
1490 my ($self) = @_; 1631 my ($self) = @_;
1491 1632
1492 $self->{vertical} 1633 $self->{vertical}
1525 $req[$_] += $space * $children[$_]{expand} 1666 $req[$_] += $space * $children[$_]{expand}
1526 for 0 .. $#children; 1667 for 0 .. $#children;
1527 } 1668 }
1528 } 1669 }
1529 1670
1530 CFClient::UI::harmonize \@req; 1671 CFPlus::UI::harmonize \@req;
1531 1672
1532 my $pos = 0; 1673 my $pos = 0;
1533 for (0 .. $#children) { 1674 for (0 .. $#children) {
1534 my $alloc = $req[$_]; 1675 my $alloc = $req[$_];
1535 $children[$_]->configure ($self->{vertical} ? (0, $pos, $w, $alloc) : ($pos, 0, $alloc, $h)); 1676 $children[$_]->configure ($self->{vertical} ? (0, $pos, $w, $alloc) : ($pos, 0, $alloc, $h));
1540 1 1681 1
1541} 1682}
1542 1683
1543############################################################################# 1684#############################################################################
1544 1685
1545package CFClient::UI::HBox; 1686package CFPlus::UI::HBox;
1546 1687
1547our @ISA = CFClient::UI::Box::; 1688our @ISA = CFPlus::UI::Box::;
1548 1689
1549sub new { 1690sub new {
1550 my $class = shift; 1691 my $class = shift;
1551 1692
1552 $class->SUPER::new ( 1693 $class->SUPER::new (
1555 ) 1696 )
1556} 1697}
1557 1698
1558############################################################################# 1699#############################################################################
1559 1700
1560package CFClient::UI::VBox; 1701package CFPlus::UI::VBox;
1561 1702
1562our @ISA = CFClient::UI::Box::; 1703our @ISA = CFPlus::UI::Box::;
1563 1704
1564sub new { 1705sub new {
1565 my $class = shift; 1706 my $class = shift;
1566 1707
1567 $class->SUPER::new ( 1708 $class->SUPER::new (
1570 ) 1711 )
1571} 1712}
1572 1713
1573############################################################################# 1714#############################################################################
1574 1715
1575package CFClient::UI::Label; 1716package CFPlus::UI::Label;
1576 1717
1577our @ISA = CFClient::UI::DrawBG::; 1718our @ISA = CFPlus::UI::DrawBG::;
1578 1719
1579use CFClient::OpenGL; 1720use CFPlus::OpenGL;
1580 1721
1581sub new { 1722sub new {
1582 my ($class, %arg) = @_; 1723 my ($class, %arg) = @_;
1583 1724
1584 my $self = $class->SUPER::new ( 1725 my $self = $class->SUPER::new (
1587 #active_bg => none 1728 #active_bg => none
1588 #font => default_font 1729 #font => default_font
1589 #text => initial text 1730 #text => initial text
1590 #markup => initial narkup 1731 #markup => initial narkup
1591 #max_w => maximum pixel width 1732 #max_w => maximum pixel width
1733 #style => 0, # render flags
1592 ellipsise => 3, # end 1734 ellipsise => 3, # end
1593 layout => (new CFClient::Layout), 1735 layout => (new CFPlus::Layout),
1594 fontsize => 1, 1736 fontsize => 1,
1595 align => -1, 1737 align => -1,
1596 valign => -1, 1738 valign => -1,
1597 padding_x => 2, 1739 padding_x => 2,
1598 padding_y => 2, 1740 padding_y => 2,
1599 can_events => 0, 1741 can_events => 0,
1600 %arg 1742 %arg
1601 ); 1743 );
1602 1744
1603 if (exists $self->{template}) { 1745 if (exists $self->{template}) {
1604 my $layout = new CFClient::Layout; 1746 my $layout = new CFPlus::Layout;
1605 $layout->set_text (delete $self->{template}); 1747 $layout->set_text (delete $self->{template});
1606 $self->{template} = $layout; 1748 $self->{template} = $layout;
1607 } 1749 }
1608 1750
1609 if (exists $self->{markup}) { 1751 if (exists $self->{markup}) {
1611 } else { 1753 } else {
1612 $self->set_text (delete $self->{text}); 1754 $self->set_text (delete $self->{text});
1613 } 1755 }
1614 1756
1615 $self 1757 $self
1616}
1617
1618sub escape($) {
1619 local $_ = $_[0];
1620
1621 s/&/&amp;/g;
1622 s/>/&gt;/g;
1623 s/</&lt;/g;
1624
1625 $_
1626} 1758}
1627 1759
1628sub update { 1760sub update {
1629 my ($self) = @_; 1761 my ($self) = @_;
1630 1762
1757 }; 1889 };
1758 1890
1759 my $w = List::Util::min $self->{w} + 4, $size->[0]; 1891 my $w = List::Util::min $self->{w} + 4, $size->[0];
1760 my $h = List::Util::min $self->{h} + 2, $size->[1]; 1892 my $h = List::Util::min $self->{h} + 2, $size->[1];
1761 1893
1762 $self->{layout}->render ($self->{ox}, $self->{oy}); 1894 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
1763} 1895}
1764 1896
1765############################################################################# 1897#############################################################################
1766 1898
1767package CFClient::UI::EntryBase; 1899package CFPlus::UI::EntryBase;
1768 1900
1769our @ISA = CFClient::UI::Label::; 1901our @ISA = CFPlus::UI::Label::;
1770 1902
1771use CFClient::OpenGL; 1903use CFPlus::OpenGL;
1772 1904
1773sub new { 1905sub new {
1774 my $class = shift; 1906 my $class = shift;
1775 1907
1776 $class->SUPER::new ( 1908 $class->SUPER::new (
1780 active_fg => [0, 0, 0], 1912 active_fg => [0, 0, 0],
1781 can_hover => 1, 1913 can_hover => 1,
1782 can_focus => 1, 1914 can_focus => 1,
1783 valign => 0, 1915 valign => 0,
1784 can_events => 1, 1916 can_events => 1,
1917 ellipsise => 0,
1785 #text => ... 1918 #text => ...
1786 #hidden => "*", 1919 #hidden => "*",
1787 @_ 1920 @_
1788 ) 1921 )
1789} 1922}
1838 1971
1839 if ($uni == 8) { 1972 if ($uni == 8) {
1840 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 1973 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
1841 } elsif ($uni == 127) { 1974 } elsif ($uni == 127) {
1842 substr $text, $self->{cursor}, 1, ""; 1975 substr $text, $self->{cursor}, 1, "";
1843 } elsif ($sym == CFClient::SDLK_LEFT) { 1976 } elsif ($sym == CFPlus::SDLK_LEFT) {
1844 --$self->{cursor} if $self->{cursor}; 1977 --$self->{cursor} if $self->{cursor};
1845 } elsif ($sym == CFClient::SDLK_RIGHT) { 1978 } elsif ($sym == CFPlus::SDLK_RIGHT) {
1846 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 1979 ++$self->{cursor} if $self->{cursor} < length $self->{text};
1847 } elsif ($sym == CFClient::SDLK_HOME) { 1980 } elsif ($sym == CFPlus::SDLK_HOME) {
1981 # what a hack
1982 $self->{cursor} =
1983 (substr $self->{text}, 0, $self->{cursor}) =~ /^(.*\012)/
1984 ? length $1
1985 : 0;
1986 } elsif ($sym == CFPlus::SDLK_END) {
1987 # uh, again
1988 $self->{cursor} =
1989 (substr $self->{text}, $self->{cursor}) =~ /^([^\012]*)\012/
1990 ? $self->{cursor} + length $1
1991 : length $self->{text};
1992 } elsif ($uni == 21) { # ctrl-u
1993 $text = "";
1848 $self->{cursor} = 0; 1994 $self->{cursor} = 0;
1849 } elsif ($sym == CFClient::SDLK_END) {
1850 $self->{cursor} = length $text;
1851 } elsif ($uni == 27) { 1995 } elsif ($uni == 27) {
1852 $self->emit ('escape'); 1996 $self->emit ('escape');
1853 } elsif ($uni) { 1997 } elsif ($uni == 0x0d) {
1998 substr $text, $self->{cursor}++, 0, "\012";
1999 } elsif ($uni >= 0x20) {
1854 substr $text, $self->{cursor}++, 0, chr $uni; 2000 substr $text, $self->{cursor}++, 0, chr $uni;
1855 } else { 2001 } else {
1856 return 0; 2002 return 0;
1857 } 2003 }
1858 2004
1859 $self->_set_text ($text); 2005 $self->_set_text ($text);
1860 2006
1861 $self->realloc; 2007 $self->realloc;
2008 $self->update;
1862 2009
1863 1 2010 1
1864} 2011}
1865 2012
1866sub invoke_focus_in { 2013sub invoke_focus_in {
1928 utf8::encode $text; 2075 utf8::encode $text;
1929 2076
1930 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text) 2077 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text)
1931 } 2078 }
1932 2079
1933 glColor @{$self->{fg}};
1934 glBegin GL_LINES; 2080 glBegin GL_LINES;
1935 glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; 2081 glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy};
1936 glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; 2082 glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h};
1937 glEnd; 2083 glEnd;
1938 } 2084 }
1939} 2085}
1940 2086
2087#############################################################################
2088
1941package CFClient::UI::Entry; 2089package CFPlus::UI::Entry;
1942 2090
1943our @ISA = CFClient::UI::EntryBase::; 2091our @ISA = CFPlus::UI::EntryBase::;
1944 2092
1945use CFClient::OpenGL; 2093use CFPlus::OpenGL;
1946 2094
1947sub invoke_key_down { 2095sub invoke_key_down {
1948 my ($self, $ev) = @_; 2096 my ($self, $ev) = @_;
1949 2097
1950 my $sym = $ev->{sym}; 2098 my $sym = $ev->{sym};
1951 2099
1952 if ($sym == 13) { 2100 if ($ev->{uni} == 0x0d || $sym == 13) {
1953 unshift @{$self->{history}}, 2101 unshift @{$self->{history}},
1954 my $txt = $self->get_text; 2102 my $txt = $self->get_text;
1955 2103
1956 $self->{history_pointer} = -1; 2104 $self->{history_pointer} = -1;
1957 $self->{history_saveback} = ''; 2105 $self->{history_saveback} = '';
1958 $self->emit (activate => $txt); 2106 $self->emit (activate => $txt);
1959 $self->update; 2107 $self->update;
1960 2108
1961 } elsif ($sym == CFClient::SDLK_UP) { 2109 } elsif ($sym == CFPlus::SDLK_UP) {
1962 if ($self->{history_pointer} < 0) { 2110 if ($self->{history_pointer} < 0) {
1963 $self->{history_saveback} = $self->get_text; 2111 $self->{history_saveback} = $self->get_text;
1964 } 2112 }
1965 if (@{$self->{history} || []} > 0) { 2113 if (@{$self->{history} || []} > 0) {
1966 $self->{history_pointer}++; 2114 $self->{history_pointer}++;
1968 $self->{history_pointer} = @{$self->{history} || []} - 1; 2116 $self->{history_pointer} = @{$self->{history} || []} - 1;
1969 } 2117 }
1970 $self->set_text ($self->{history}->[$self->{history_pointer}]); 2118 $self->set_text ($self->{history}->[$self->{history_pointer}]);
1971 } 2119 }
1972 2120
1973 } elsif ($sym == CFClient::SDLK_DOWN) { 2121 } elsif ($sym == CFPlus::SDLK_DOWN) {
1974 $self->{history_pointer}--; 2122 $self->{history_pointer}--;
1975 $self->{history_pointer} = -1 if $self->{history_pointer} < 0; 2123 $self->{history_pointer} = -1 if $self->{history_pointer} < 0;
1976 2124
1977 if ($self->{history_pointer} >= 0) { 2125 if ($self->{history_pointer} >= 0) {
1978 $self->set_text ($self->{history}->[$self->{history_pointer}]); 2126 $self->set_text ($self->{history}->[$self->{history_pointer}]);
1987 1 2135 1
1988} 2136}
1989 2137
1990############################################################################# 2138#############################################################################
1991 2139
2140package CFPlus::UI::TextEdit;
2141
2142our @ISA = CFPlus::UI::EntryBase::;
2143
2144use CFPlus::OpenGL;
2145
2146sub move_cursor_ver {
2147 my ($self, $dy) = @_;
2148
2149 my ($y, $x) = $self->{layout}->index_to_line_x ($self->{cursor});
2150
2151 $y += $dy;
2152
2153 if (defined (my $index = $self->{layout}->line_x_to_index ($y, $x))) {
2154 $self->{cursor} = $index;
2155 delete $self->{cur_h};
2156 $self->update;
2157 return;
2158 }
2159}
2160
2161sub invoke_key_down {
2162 my ($self, $ev) = @_;
2163
2164 my $sym = $ev->{sym};
2165
2166 if ($sym == CFPlus::SDLK_UP) {
2167 $self->move_cursor_ver (-1);
2168 } elsif ($sym == CFPlus::SDLK_DOWN) {
2169 $self->move_cursor_ver (+1);
2170 } else {
2171 return $self->SUPER::invoke_key_down ($ev)
2172 }
2173
2174 1
2175}
2176
2177#############################################################################
2178
1992package CFClient::UI::Button; 2179package CFPlus::UI::Button;
1993 2180
1994our @ISA = CFClient::UI::Label::; 2181our @ISA = CFPlus::UI::Label::;
1995 2182
1996use CFClient::OpenGL; 2183use CFPlus::OpenGL;
1997 2184
1998my @tex = 2185my @tex =
1999 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2186 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2000 qw(b1_button_active.png); 2187 qw(b1_button_active.png);
2001 2188
2002sub new { 2189sub new {
2003 my $class = shift; 2190 my $class = shift;
2004 2191
2041 $self->SUPER::_draw; 2228 $self->SUPER::_draw;
2042} 2229}
2043 2230
2044############################################################################# 2231#############################################################################
2045 2232
2233package CFPlus::UI::CheckBox;
2234
2235our @ISA = CFPlus::UI::DrawBG::;
2236
2237my @tex =
2238 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2239 qw(c1_checkbox_bg.png c1_checkbox_active.png);
2240
2241use CFPlus::OpenGL;
2242
2243sub new {
2244 my $class = shift;
2245
2246 $class->SUPER::new (
2247 padding_x => 2,
2248 padding_y => 2,
2249 fg => [1, 1, 1],
2250 active_fg => [1, 1, 0],
2251 bg => [0, 0, 0, 0.2],
2252 active_bg => [1, 1, 1, 0.5],
2253 state => 0,
2254 can_hover => 1,
2255 @_
2256 )
2257}
2258
2259sub size_request {
2260 my ($self) = @_;
2261
2262 (6) x 2
2263}
2264
2265sub toggle {
2266 my ($self) = @_;
2267
2268 $self->{state} = !$self->{state};
2269 $self->emit (changed => $self->{state});
2270 $self->update;
2271}
2272
2273sub invoke_button_down {
2274 my ($self, $ev, $x, $y) = @_;
2275
2276 if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x}
2277 && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) {
2278 $self->toggle;
2279 } else {
2280 return 0
2281 }
2282
2283 1
2284}
2285
2286sub _draw {
2287 my ($self) = @_;
2288
2289 $self->SUPER::_draw;
2290
2291 glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0;
2292
2293 my ($w, $h) = @$self{qw(w h)};
2294
2295 my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2;
2296
2297 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} };
2298
2299 my $tex = $self->{state} ? $tex[1] : $tex[0];
2300
2301 glEnable GL_TEXTURE_2D;
2302 $tex->draw_quad_alpha (0, 0, $s, $s);
2303 glDisable GL_TEXTURE_2D;
2304}
2305
2306#############################################################################
2307
2308package CFPlus::UI::Image;
2309
2310our @ISA = CFPlus::UI::Base::;
2311
2312use CFPlus::OpenGL;
2313
2314our %texture_cache;
2315
2316sub new {
2317 my $class = shift;
2318
2319 my $self = $class->SUPER::new (
2320 can_events => 0,
2321 @_,
2322 );
2323
2324 $self->{path} || $self->{tex}
2325 or Carp::croak "'path' or 'tex' attributes required";
2326
2327 $self->{tex} ||= $texture_cache{$self->{path}} ||=
2328 new_from_file CFPlus::Texture CFPlus::find_rcfile $self->{path}, mipmap => 1;
2329
2330 CFPlus::weaken $texture_cache{$self->{path}};
2331
2332 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2333
2334 $self
2335}
2336
2337sub STORABLE_freeze {
2338 my ($self, $cloning) = @_;
2339
2340 $self->{path}
2341 or die "cannot serialise CFPlus::UI::Image on non-loadable images\n";
2342
2343 $self->{path}
2344}
2345
2346sub STORABLE_attach {
2347 my ($self, $cloning, $path) = @_;
2348
2349 $self->new (path => $path)
2350}
2351
2352sub size_request {
2353 my ($self) = @_;
2354
2355 ($self->{tex}{w}, $self->{tex}{h})
2356}
2357
2358sub _draw {
2359 my ($self) = @_;
2360
2361 my $tex = $self->{tex};
2362
2363 my ($w, $h) = ($self->{w}, $self->{h});
2364
2365 if ($self->{rot90}) {
2366 glRotate 90, 0, 0, 1;
2367 glTranslate 0, -$self->{w}, 0;
2368
2369 ($w, $h) = ($h, $w);
2370 }
2371
2372 glEnable GL_TEXTURE_2D;
2373 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2374
2375 $tex->draw_quad (0, 0, $w, $h);
2376
2377 glDisable GL_TEXTURE_2D;
2378}
2379
2380#############################################################################
2381
2046package CFClient::UI::ImageButton; 2382package CFPlus::UI::ImageButton;
2047 2383
2048our @ISA = CFClient::UI::Image::; 2384our @ISA = CFPlus::UI::Image::;
2049 2385
2050use CFClient::OpenGL; 2386use CFPlus::OpenGL;
2051 2387
2052my %textures; 2388my %textures;
2053 2389
2054sub new { 2390sub new {
2055 my $class = shift; 2391 my $class = shift;
2077 1 2413 1
2078} 2414}
2079 2415
2080############################################################################# 2416#############################################################################
2081 2417
2082package CFClient::UI::CheckBox;
2083
2084our @ISA = CFClient::UI::DrawBG::;
2085
2086my @tex =
2087 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
2088 qw(c1_checkbox_bg.png c1_checkbox_active.png);
2089
2090use CFClient::OpenGL;
2091
2092sub new {
2093 my $class = shift;
2094
2095 $class->SUPER::new (
2096 padding_x => 2,
2097 padding_y => 2,
2098 fg => [1, 1, 1],
2099 active_fg => [1, 1, 0],
2100 bg => [0, 0, 0, 0.2],
2101 active_bg => [1, 1, 1, 0.5],
2102 state => 0,
2103 can_hover => 1,
2104 @_
2105 )
2106}
2107
2108sub size_request {
2109 my ($self) = @_;
2110
2111 (6) x 2
2112}
2113
2114sub toggle {
2115 my ($self) = @_;
2116
2117 $self->{state} = !$self->{state};
2118 $self->emit (changed => $self->{state});
2119 $self->update;
2120}
2121
2122sub invoke_button_down {
2123 my ($self, $ev, $x, $y) = @_;
2124
2125 if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x}
2126 && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) {
2127 $self->toggle;
2128 } else {
2129 return 0
2130 }
2131
2132 1
2133}
2134
2135sub _draw {
2136 my ($self) = @_;
2137
2138 $self->SUPER::_draw;
2139
2140 glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0;
2141
2142 my ($w, $h) = @$self{qw(w h)};
2143
2144 my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2;
2145
2146 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} };
2147
2148 my $tex = $self->{state} ? $tex[1] : $tex[0];
2149
2150 glEnable GL_TEXTURE_2D;
2151 $tex->draw_quad_alpha (0, 0, $s, $s);
2152 glDisable GL_TEXTURE_2D;
2153}
2154
2155#############################################################################
2156
2157package CFClient::UI::Image; 2418package CFPlus::UI::VGauge;
2158 2419
2159our @ISA = CFClient::UI::Base::; 2420our @ISA = CFPlus::UI::Base::;
2160
2161use CFClient::OpenGL;
2162
2163our %texture_cache;
2164
2165sub new {
2166 my $class = shift;
2167
2168 my $self = $class->SUPER::new (
2169 can_events => 0,
2170 @_,
2171 );
2172
2173 $self->{path} || $self->{tex}
2174 or Carp::croak "'path' or 'tex' attributes required";
2175
2176 $self->{tex} ||= $texture_cache{$self->{path}} ||=
2177 new_from_file CFClient::Texture CFClient::find_rcfile $self->{path}, mipmap => 1;
2178
2179 Scalar::Util::weaken $texture_cache{$self->{path}};
2180
2181 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2182
2183 $self
2184}
2185
2186sub size_request {
2187 my ($self) = @_;
2188
2189 ($self->{tex}{w}, $self->{tex}{h})
2190}
2191
2192sub _draw {
2193 my ($self) = @_;
2194
2195 my $tex = $self->{tex};
2196
2197 my ($w, $h) = ($self->{w}, $self->{h});
2198
2199 if ($self->{rot90}) {
2200 glRotate 90, 0, 0, 1;
2201 glTranslate 0, -$self->{w}, 0;
2202
2203 ($w, $h) = ($h, $w);
2204 }
2205
2206 glEnable GL_TEXTURE_2D;
2207 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2208
2209 $tex->draw_quad_alpha (0, 0, $w, $h);
2210
2211 glDisable GL_TEXTURE_2D;
2212}
2213
2214#############################################################################
2215
2216package CFClient::UI::VGauge;
2217
2218our @ISA = CFClient::UI::Base::;
2219 2421
2220use List::Util qw(min max); 2422use List::Util qw(min max);
2221 2423
2222use CFClient::OpenGL; 2424use CFPlus::OpenGL;
2223 2425
2224my %tex = ( 2426my %tex = (
2225 food => [ 2427 food => [
2226 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2428 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2227 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 2429 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
2228 ], 2430 ],
2229 grace => [ 2431 grace => [
2230 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2432 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2231 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/ 2433 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/
2232 ], 2434 ],
2233 hp => [ 2435 hp => [
2234 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2436 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2235 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 2437 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
2236 ], 2438 ],
2237 mana => [ 2439 mana => [
2238 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2440 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2239 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/ 2441 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/
2240 ], 2442 ],
2241); 2443);
2242 2444
2243# eg. VGauge->new (gauge => 'food'), default gauge: food 2445# eg. VGauge->new (gauge => 'food'), default gauge: food
2346 glDisable GL_TEXTURE_2D; 2548 glDisable GL_TEXTURE_2D;
2347} 2549}
2348 2550
2349############################################################################# 2551#############################################################################
2350 2552
2351package CFClient::UI::Gauge; 2553package CFPlus::UI::Gauge;
2352 2554
2353our @ISA = CFClient::UI::VBox::; 2555our @ISA = CFPlus::UI::VBox::;
2354 2556
2355sub new { 2557sub new {
2356 my ($class, %arg) = @_; 2558 my ($class, %arg) = @_;
2357 2559
2358 my $self = $class->SUPER::new ( 2560 my $self = $class->SUPER::new (
2360 can_hover => 1, 2562 can_hover => 1,
2361 can_events => 1, 2563 can_events => 1,
2362 %arg, 2564 %arg,
2363 ); 2565 );
2364 2566
2365 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); 2567 $self->add ($self->{value} = new CFPlus::UI::Label valign => +1, align => 0, template => "999");
2366 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); 2568 $self->add ($self->{gauge} = new CFPlus::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1);
2367 $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999"); 2569 $self->add ($self->{max} = new CFPlus::UI::Label valign => -1, align => 0, template => "999");
2368 2570
2369 $self 2571 $self
2370} 2572}
2371 2573
2372sub set_fontsize { 2574sub set_fontsize {
2393 $self->{value}->set_text ($val); 2595 $self->{value}->set_text ($val);
2394} 2596}
2395 2597
2396############################################################################# 2598#############################################################################
2397 2599
2398package CFClient::UI::Slider; 2600package CFPlus::UI::Slider;
2399 2601
2400use strict; 2602use strict;
2401 2603
2402use CFClient::OpenGL; 2604use CFPlus::OpenGL;
2403 2605
2404our @ISA = CFClient::UI::DrawBG::; 2606our @ISA = CFPlus::UI::DrawBG::;
2405 2607
2406my @tex = 2608my @tex =
2407 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 2609 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_ }
2408 qw(s1_slider.png s1_slider_bg.png); 2610 qw(s1_slider.png s1_slider_bg.png);
2409 2611
2410sub new { 2612sub new {
2411 my $class = shift; 2613 my $class = shift;
2412 2614
2506sub invoke_mouse_wheel { 2708sub invoke_mouse_wheel {
2507 my ($self, $ev) = @_; 2709 my ($self, $ev) = @_;
2508 2710
2509 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; 2711 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx};
2510 2712
2713 my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2;
2714
2511 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * 0.1); 2715 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart);
2512 2716
2513 ! ! $delta 2717 ! ! $delta
2514} 2718}
2515 2719
2516sub update { 2720sub update {
2567 glDisable GL_TEXTURE_2D; 2771 glDisable GL_TEXTURE_2D;
2568} 2772}
2569 2773
2570############################################################################# 2774#############################################################################
2571 2775
2572package CFClient::UI::ValSlider; 2776package CFPlus::UI::ValSlider;
2573 2777
2574our @ISA = CFClient::UI::HBox::; 2778our @ISA = CFPlus::UI::HBox::;
2575 2779
2576sub new { 2780sub new {
2577 my ($class, %arg) = @_; 2781 my ($class, %arg) = @_;
2578 2782
2579 my $range = delete $arg{range}; 2783 my $range = delete $arg{range};
2580 2784
2581 my $self = $class->SUPER::new ( 2785 my $self = $class->SUPER::new (
2582 slider => (new CFClient::UI::Slider expand => 1, range => $range), 2786 slider => (new CFPlus::UI::Slider expand => 1, range => $range),
2583 entry => (new CFClient::UI::Label text => "", template => delete $arg{template}), 2787 entry => (new CFPlus::UI::Label text => "", template => delete $arg{template}),
2584 to_value => sub { shift }, 2788 to_value => sub { shift },
2585 from_value => sub { shift }, 2789 from_value => sub { shift },
2586 %arg, 2790 %arg,
2587 ); 2791 );
2588 2792
2608sub set_range { shift->{slider}->set_range (@_) } 2812sub set_range { shift->{slider}->set_range (@_) }
2609sub set_value { shift->{slider}->set_value (@_) } 2813sub set_value { shift->{slider}->set_value (@_) }
2610 2814
2611############################################################################# 2815#############################################################################
2612 2816
2613package CFClient::UI::TextScroller; 2817package CFPlus::UI::TextScroller;
2614 2818
2615our @ISA = CFClient::UI::HBox::; 2819our @ISA = CFPlus::UI::HBox::;
2616 2820
2617use CFClient::OpenGL; 2821use CFPlus::OpenGL;
2618 2822
2619sub new { 2823sub new {
2620 my $class = shift; 2824 my $class = shift;
2621 2825
2622 my $self = $class->SUPER::new ( 2826 my $self = $class->SUPER::new (
2624 can_events => 1, 2828 can_events => 1,
2625 indent => 0, 2829 indent => 0,
2626 #font => default_font 2830 #font => default_font
2627 @_, 2831 @_,
2628 2832
2629 layout => (new CFClient::Layout), 2833 layout => (new CFPlus::Layout),
2630 par => [], 2834 par => [],
2631 height => 0, 2835 height => 0,
2632 children => [ 2836 children => [
2633 (new CFClient::UI::Empty expand => 1), 2837 (new CFPlus::UI::Empty expand => 1),
2634 (new CFClient::UI::Slider vertical => 1), 2838 (new CFPlus::UI::Slider vertical => 1),
2635 ], 2839 ],
2636 ); 2840 );
2637 2841
2638 $self->{children}[1]->connect (changed => sub { $self->update }); 2842 $self->{children}[1]->connect (changed => sub { $self->update });
2639 2843
2716 2920
2717 # todo: base offset on lines or so, not on pixels 2921 # todo: base offset on lines or so, not on pixels
2718 $self->{children}[1]->set_value ($offset); 2922 $self->{children}[1]->set_value ($offset);
2719} 2923}
2720 2924
2925sub current_paragraph {
2926 my ($self) = @_;
2927
2928 $self->{top_paragraph} - 1
2929}
2930
2931sub scroll_to {
2932 my ($self, $para) = @_;
2933
2934 $para = List::Util::max 0, List::Util::min $#{$self->{par}}, $para;
2935
2936 $self->{scroll_to} = $para;
2937 $self->update;
2938}
2939
2721sub clear { 2940sub clear {
2722 my ($self) = @_; 2941 my ($self) = @_;
2723 2942
2724 my (undef, undef, @other) = @{ $self->{children} }; 2943 my (undef, undef, @other) = @{ $self->{children} };
2725 $self->remove ($_) for @other; 2944 $self->remove ($_) for @other;
2728 $self->{height} = 0; 2947 $self->{height} = 0;
2729 $self->{children}[1]->set_range ([0, 0, 0, 1, 1]); 2948 $self->{children}[1]->set_range ([0, 0, 0, 1, 1]);
2730} 2949}
2731 2950
2732sub add_paragraph { 2951sub add_paragraph {
2733 my ($self, $color, $para, $indent) = @_; 2952 my $self = shift;
2734 2953
2735 my ($text, @w) = ref $para ? @$para : $para; 2954 for my $para (@_) {
2736
2737 $para = { 2955 $para = {
2956 fg => [1, 1, 1, 1],
2957 indent => 0,
2958 markup => "",
2959 widget => [],
2960 ref $para ? %$para : (markup => $para),
2738 w => 1e10, 2961 w => 1e10,
2739 wrapped => 1, 2962 wrapped => 1,
2740 fg => $color,
2741 indent => $indent,
2742 markup => $text,
2743 widget => \@w,
2744 }; 2963 };
2745 2964
2746 $self->add (@w) if @w; 2965 $self->add (@{ $para->{widget} }) if @{ $para->{widget} };
2747 push @{$self->{par}}, $para; 2966 push @{$self->{par}}, $para;
2967 }
2748 2968
2749 $self->{need_reflow}++; 2969 $self->{need_reflow}++;
2750 $self->update; 2970 $self->update;
2751} 2971}
2752 2972
2753sub scroll_to_bottom { 2973sub scroll_to_bottom {
2754 my ($self) = @_; 2974 my ($self) = @_;
2755 2975
2756 $self->{scroll_to_bottom} = 1; 2976 $self->{scroll_to} = $#{$self->{par}};
2757 $self->update; 2977 $self->update;
2758} 2978}
2759 2979
2980sub force_uptodate {
2981 my ($self) = @_;
2982
2983 if (delete $self->{need_reflow}) {
2984 my ($W, $H) = @{$self->{children}[0]}{qw(w h)};
2985
2986 my $height = 0;
2987
2988 for my $para (@{$self->{par}}) {
2989 if ($para->{w} != $W && ($para->{wrapped} || $para->{w} > $W)) {
2990 my $layout = $self->get_layout ($para);
2991 my ($w, $h) = $layout->size;
2992
2993 $para->{w} = $w + $para->{indent};
2994 $para->{h} = $h;
2995 $para->{wrapped} = $layout->has_wrapped;
2996 }
2997
2998 $para->{y} = $height;
2999 $height += $para->{h};
3000 }
3001
3002 $self->{height} = $height;
3003 $self->{children}[1]->set_range ([$self->{children}[1]{range}[0], 0, $height, $H, 1]);
3004
3005 delete $self->{texture};
3006 }
3007
3008 if (my $paridx = delete $self->{scroll_to}) {
3009 $self->{children}[1]->set_value ($self->{par}[$paridx]{y});
3010 }
3011}
3012
2760sub update { 3013sub update {
2761 my ($self) = @_; 3014 my ($self) = @_;
2762 3015
2763 $self->SUPER::update; 3016 $self->SUPER::update;
2764 3017
2765 return unless $self->{h} > 0; 3018 return unless $self->{h} > 0;
2766 3019
2767 delete $self->{texture}; 3020 delete $self->{texture};
2768 3021
2769 $ROOT->on_post_alloc ($self => sub { 3022 $ROOT->on_post_alloc ($self => sub {
3023 $self->force_uptodate;
3024
2770 my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; 3025 my ($W, $H) = @{$self->{children}[0]}{qw(w h)};
2771 3026
2772 if (delete $self->{need_reflow}) {
2773 my $height = 0;
2774
2775 for my $para (@{$self->{par}}) {
2776 if ($para->{w} != $W && ($para->{wrapped} || $para->{w} > $W)) {
2777 my $layout = $self->get_layout ($para);
2778 my ($w, $h) = $layout->size;
2779
2780 $para->{w} = $w + $para->{indent};
2781 $para->{h} = $h;
2782 $para->{wrapped} = $layout->has_wrapped;
2783 }
2784
2785 $height += $para->{h};
2786 }
2787
2788 $self->{height} = $height;
2789
2790 $self->{children}[1]->set_range ([$self->{children}[1]{range}[0], 0, $height, $H, 1]);
2791
2792 delete $self->{texture};
2793 }
2794
2795 if (delete $self->{scroll_to_bottom}) {
2796 $self->{children}[1]->set_value (1e10);
2797 }
2798
2799 $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { 3027 $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub {
2800 glClearColor 0, 0, 0, 0; 3028 glClearColor 0, 0, 0, 0;
2801 glClear GL_COLOR_BUFFER_BIT; 3029 glClear GL_COLOR_BUFFER_BIT;
2802 3030
3031 package CFPlus::UI::Base;
3032 local ($draw_x, $draw_y, $draw_w, $draw_h) =
3033 (0, 0, $self->{w}, $self->{h});
3034
3035 my $top = int $self->{children}[1]{range}[0];
3036
3037 my $paridx = 0;
3038 my $top_paragraph;
2803 my $top = int $self->{children}[1]{range}[0]; 3039 my $top = int $self->{children}[1]{range}[0];
2804 3040
2805 my $y0 = $top; 3041 my $y0 = $top;
2806 my $y1 = $top + $H; 3042 my $y1 = $top + $H;
2807 3043
2808 my $y = 0;
2809
2810 for my $para (@{$self->{par}}) { 3044 for my $para (@{$self->{par}}) {
2811 my $h = $para->{h}; 3045 my $h = $para->{h};
3046 my $y = $para->{y};
2812 3047
2813 if ($y0 < $y + $h && $y < $y1) { 3048 if ($y0 < $y + $h && $y < $y1) {
2814
2815 my $layout = $self->get_layout ($para); 3049 my $layout = $self->get_layout ($para);
2816 3050
2817 $layout->render ($para->{indent}, $y - $y0); 3051 $layout->render ($para->{indent}, $y - $y0);
2818 3052
2819 if (my @w = @{ $para->{widget} }) { 3053 if (my @w = @{ $para->{widget} }) {
2828 $_->draw; 3062 $_->draw;
2829 } 3063 }
2830 } 3064 }
2831 } 3065 }
2832 3066
2833 $y += $h; 3067 $paridx++;
3068 $top_paragraph ||= $paridx if $y >= $top;
2834 } 3069 }
3070
3071 $self->{top_paragraph} = $top_paragraph;
2835 }; 3072 };
2836 }); 3073 });
2837} 3074}
2838 3075
2839sub reconfigure { 3076sub reconfigure {
2857 $self->{children}[1]->draw; 3094 $self->{children}[1]->draw;
2858} 3095}
2859 3096
2860############################################################################# 3097#############################################################################
2861 3098
2862package CFClient::UI::Animator; 3099package CFPlus::UI::Animator;
2863 3100
2864use CFClient::OpenGL; 3101use CFPlus::OpenGL;
2865 3102
2866our @ISA = CFClient::UI::Bin::; 3103our @ISA = CFPlus::UI::Bin::;
2867 3104
2868sub moveto { 3105sub moveto {
2869 my ($self, $x, $y) = @_; 3106 my ($self, $x, $y) = @_;
2870 3107
2871 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 3108 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
2899 glPopMatrix; 3136 glPopMatrix;
2900} 3137}
2901 3138
2902############################################################################# 3139#############################################################################
2903 3140
2904package CFClient::UI::Flopper; 3141package CFPlus::UI::Flopper;
2905 3142
2906our @ISA = CFClient::UI::Button::; 3143our @ISA = CFPlus::UI::Button::;
2907 3144
2908sub new { 3145sub new {
2909 my $class = shift; 3146 my $class = shift;
2910 3147
2911 my $self = $class->SUPER::new ( 3148 my $self = $class->SUPER::new (
2923 $self->{other}->toggle_visibility; 3160 $self->{other}->toggle_visibility;
2924} 3161}
2925 3162
2926############################################################################# 3163#############################################################################
2927 3164
2928package CFClient::UI::Tooltip; 3165package CFPlus::UI::Tooltip;
2929 3166
2930our @ISA = CFClient::UI::Bin::; 3167our @ISA = CFPlus::UI::Bin::;
2931 3168
2932use CFClient::OpenGL; 3169use CFPlus::OpenGL;
2933 3170
2934sub new { 3171sub new {
2935 my $class = shift; 3172 my $class = shift;
2936 3173
2937 $class->SUPER::new ( 3174 $class->SUPER::new (
2940 ) 3177 )
2941} 3178}
2942 3179
2943sub set_tooltip_from { 3180sub set_tooltip_from {
2944 my ($self, $widget) = @_; 3181 my ($self, $widget) = @_;
3182
3183 $widget->{tooltip} = CFPlus::Pod::section_label tooltip => $1
3184 if $widget->{tooltip} =~ /^#(.*)$/;
2945 3185
2946 my $tooltip = $widget->{tooltip}; 3186 my $tooltip = $widget->{tooltip};
2947 3187
2948 if ($ENV{CFPLUS_DEBUG} & 2) { 3188 if ($ENV{CFPLUS_DEBUG} & 2) {
2949 $tooltip .= "\n\n" . (ref $widget) . "\n" 3189 $tooltip .= "\n\n" . (ref $widget) . "\n"
2953 } 3193 }
2954 3194
2955 $tooltip =~ s/^\n+//; 3195 $tooltip =~ s/^\n+//;
2956 $tooltip =~ s/\n+$//; 3196 $tooltip =~ s/\n+$//;
2957 3197
2958 $self->add (new CFClient::UI::Label 3198 $self->add (new CFPlus::UI::Label
2959 markup => $tooltip, 3199 markup => $tooltip,
2960 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 3200 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
2961 fontsize => 0.8, 3201 fontsize => 0.8,
2962 fg => [0, 0, 0, 1], 3202 style => 1, # FLAG_INVERSE
2963 ellipsise => 0, 3203 ellipsise => 0,
2964 font => ($widget->{tooltip_font} || $::FONT_PROP), 3204 font => ($widget->{tooltip_font} || $::FONT_PROP),
2965 ); 3205 );
2966} 3206}
2967 3207
2986 3226
2987 $self->{root}->on_post_alloc ("move_$self" => sub { 3227 $self->{root}->on_post_alloc ("move_$self" => sub {
2988 my $widget = $self->{owner} 3228 my $widget = $self->{owner}
2989 or return; 3229 or return;
2990 3230
3231 if ($widget->{visible}) {
2991 my ($x, $y) = $widget->coord2global ($widget->{w}, 0); 3232 my ($x, $y) = $widget->coord2global ($widget->{w}, 0);
2992 3233
2993 ($x, $y) = $widget->coord2global (-$self->{w}, 0) 3234 ($x, $y) = $widget->coord2global (-$self->{w}, 0)
2994 if $x + $self->{w} > $self->{root}{w}; 3235 if $x + $self->{w} > $self->{root}{w};
2995 3236
2996 $self->move_abs ($x, $y); 3237 $self->move_abs ($x, $y);
3238 } else {
3239 $self->hide;
3240 }
2997 }); 3241 });
2998} 3242}
2999 3243
3000sub _draw { 3244sub _draw {
3001 my ($self) = @_; 3245 my ($self) = @_;
3025 $self->SUPER::_draw; 3269 $self->SUPER::_draw;
3026} 3270}
3027 3271
3028############################################################################# 3272#############################################################################
3029 3273
3030package CFClient::UI::Face; 3274package CFPlus::UI::Face;
3031 3275
3032our @ISA = CFClient::UI::Base::; 3276our @ISA = CFPlus::UI::DrawBG::;
3033 3277
3034use CFClient::OpenGL; 3278use CFPlus::OpenGL;
3035 3279
3036sub new { 3280sub new {
3037 my $class = shift; 3281 my $class = shift;
3038 3282
3039 my $self = $class->SUPER::new ( 3283 my $self = $class->SUPER::new (
3041 can_events => 0, 3285 can_events => 0,
3042 @_, 3286 @_,
3043 ); 3287 );
3044 3288
3045 if ($self->{anim} && $self->{animspeed}) { 3289 if ($self->{anim} && $self->{animspeed}) {
3046 Scalar::Util::weaken (my $widget = $self); 3290 CFPlus::weaken (my $widget = $self);
3047 3291
3048 $self->{timer} = Event->timer ( 3292 $self->{timer} = Event->timer (
3049 at => $self->{animspeed} * int $::NOW / $self->{animspeed}, 3293 at => $self->{animspeed} * int $::NOW / $self->{animspeed},
3050 hard => 1, 3294 hard => 1,
3051 interval => $self->{animspeed}, 3295 interval => $self->{animspeed},
3074sub _draw { 3318sub _draw {
3075 my ($self) = @_; 3319 my ($self) = @_;
3076 3320
3077 return unless $::CONN; 3321 return unless $::CONN;
3078 3322
3323 $self->SUPER::_draw;
3324
3079 my $face; 3325 my $face;
3080 3326
3081 if ($self->{frame}) { 3327 if ($self->{frame}) {
3082 my $anim = $::CONN->{anim}[$self->{anim}]; 3328 my $anim = $::CONN->{anim}[$self->{anim}];
3083 3329
3105 $self->SUPER::destroy; 3351 $self->SUPER::destroy;
3106} 3352}
3107 3353
3108############################################################################# 3354#############################################################################
3109 3355
3110package CFClient::UI::Buttonbar; 3356package CFPlus::UI::Buttonbar;
3111 3357
3112our @ISA = CFClient::UI::HBox::; 3358our @ISA = CFPlus::UI::HBox::;
3113 3359
3114# TODO: should actualyl wrap buttons and other goodies. 3360# TODO: should actually wrap buttons and other goodies.
3115 3361
3116############################################################################# 3362#############################################################################
3117 3363
3118package CFClient::UI::Menu; 3364package CFPlus::UI::Menu;
3119 3365
3120our @ISA = CFClient::UI::FancyFrame::; 3366our @ISA = CFPlus::UI::Toplevel::;
3121 3367
3122use CFClient::OpenGL; 3368use CFPlus::OpenGL;
3123 3369
3124sub new { 3370sub new {
3125 my $class = shift; 3371 my $class = shift;
3126 3372
3127 my $self = $class->SUPER::new ( 3373 my $self = $class->SUPER::new (
3128 items => [], 3374 items => [],
3129 z => 100, 3375 z => 100,
3130 @_, 3376 @_,
3131 ); 3377 );
3132 3378
3133 $self->add ($self->{vbox} = new CFClient::UI::VBox); 3379 $self->add ($self->{vbox} = new CFPlus::UI::VBox);
3134 3380
3135 for my $item (@{ $self->{items} }) { 3381 for my $item (@{ $self->{items} }) {
3136 my ($widget, $cb, $tooltip) = @$item; 3382 my ($widget, $cb, $tooltip) = @$item;
3137 3383
3138 # handle various types of items, only text for now 3384 # handle various types of items, only text for now
3139 if (!ref $widget) { 3385 if (!ref $widget) {
3140 if ($widget =~ /\t/) { 3386 if ($widget =~ /\t/) {
3141 my ($left, $right) = split /\t/, $widget, 2; 3387 my ($left, $right) = split /\t/, $widget, 2;
3142 3388
3143 $widget = new CFClient::UI::HBox 3389 $widget = new CFPlus::UI::HBox
3144 can_hover => 1, 3390 can_hover => 1,
3145 can_events => 1, 3391 can_events => 1,
3146 tooltip => $tooltip, 3392 tooltip => $tooltip,
3147 children => [ 3393 children => [
3148 (new CFClient::UI::Label markup => $left, expand => 1), 3394 (new CFPlus::UI::Label markup => $left, expand => 1),
3149 (new CFClient::UI::Label markup => $right, align => +1), 3395 (new CFPlus::UI::Label markup => $right, align => +1),
3150 ], 3396 ],
3151 ; 3397 ;
3152 3398
3153 } else { 3399 } else {
3154 $widget = new CFClient::UI::Label 3400 $widget = new CFPlus::UI::Label
3155 can_hover => 1, 3401 can_hover => 1,
3156 can_events => 1, 3402 can_events => 1,
3157 markup => $widget, 3403 markup => $widget,
3158 tooltip => $tooltip; 3404 tooltip => $tooltip;
3159 } 3405 }
3207 1 3453 1
3208} 3454}
3209 3455
3210############################################################################# 3456#############################################################################
3211 3457
3212package CFClient::UI::Multiplexer; 3458package CFPlus::UI::Multiplexer;
3213 3459
3214our @ISA = CFClient::UI::Container::; 3460our @ISA = CFPlus::UI::Container::;
3215 3461
3216sub new { 3462sub new {
3217 my $class = shift; 3463 my $class = shift;
3218 3464
3219 my $self = $class->SUPER::new ( 3465 my $self = $class->SUPER::new (
3280 $self->{current}->draw; 3526 $self->{current}->draw;
3281} 3527}
3282 3528
3283############################################################################# 3529#############################################################################
3284 3530
3285package CFClient::UI::Notebook; 3531package CFPlus::UI::Notebook;
3286 3532
3287our @ISA = CFClient::UI::VBox::; 3533our @ISA = CFPlus::UI::VBox::;
3288 3534
3289sub new { 3535sub new {
3290 my $class = shift; 3536 my $class = shift;
3291 3537
3292 my $self = $class->SUPER::new ( 3538 my $self = $class->SUPER::new (
3293 buttonbar => (new CFClient::UI::Buttonbar), 3539 buttonbar => (new CFPlus::UI::Buttonbar),
3294 multiplexer => (new CFClient::UI::Multiplexer expand => 1), 3540 multiplexer => (new CFPlus::UI::Multiplexer expand => 1),
3295 # filter => # will be put between multiplexer and $self 3541 # filter => # will be put between multiplexer and $self
3296 @_, 3542 @_,
3297 ); 3543 );
3298 3544
3299 $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; 3545 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
3303} 3549}
3304 3550
3305sub add { 3551sub add {
3306 my ($self, $title, $widget, $tooltip) = @_; 3552 my ($self, $title, $widget, $tooltip) = @_;
3307 3553
3308 Scalar::Util::weaken $self; 3554 CFPlus::weaken $self;
3309 3555
3310 $self->{buttonbar}->add (new CFClient::UI::Button 3556 $self->{buttonbar}->add (new CFPlus::UI::Button
3311 markup => $title, 3557 markup => $title,
3312 tooltip => $tooltip, 3558 tooltip => $tooltip,
3313 on_activate => sub { $self->set_current_page ($widget) }, 3559 on_activate => sub { $self->set_current_page ($widget) },
3314 ); 3560 );
3315 3561
3329 $self->emit (page_changed => $self->{multiplexer}{current}); 3575 $self->emit (page_changed => $self->{multiplexer}{current});
3330} 3576}
3331 3577
3332############################################################################# 3578#############################################################################
3333 3579
3334package CFClient::UI::Combobox; 3580package CFPlus::UI::Selector;
3335 3581
3336use utf8; 3582use utf8;
3337 3583
3338our @ISA = CFClient::UI::Button::; 3584our @ISA = CFPlus::UI::Button::;
3339 3585
3340sub new { 3586sub new {
3341 my $class = shift; 3587 my $class = shift;
3342 3588
3343 my $self = $class->SUPER::new ( 3589 my $self = $class->SUPER::new (
3360 my ($value, $title, $tooltip) = @$_; 3606 my ($value, $title, $tooltip) = @$_;
3361 3607
3362 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }]; 3608 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }];
3363 } 3609 }
3364 3610
3365 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); 3611 CFPlus::UI::Menu->new (items => \@menu_items)->popup ($ev);
3366} 3612}
3367 3613
3368sub _set_value { 3614sub _set_value {
3369 my ($self, $value) = @_; 3615 my ($self, $value) = @_;
3370 3616
3385 $self->emit (changed => $value); 3631 $self->emit (changed => $value);
3386} 3632}
3387 3633
3388############################################################################# 3634#############################################################################
3389 3635
3390package CFClient::UI::Statusbox; 3636package CFPlus::UI::Statusbox;
3391 3637
3392our @ISA = CFClient::UI::VBox::; 3638our @ISA = CFPlus::UI::VBox::;
3393 3639
3394sub new { 3640sub new {
3395 my $class = shift; 3641 my $class = shift;
3396 3642
3397 my $self = $class->SUPER::new ( 3643 my $self = $class->SUPER::new (
3398 fontsize => 0.8, 3644 fontsize => 0.8,
3399 @_, 3645 @_,
3400 ); 3646 );
3401 3647
3402 Scalar::Util::weaken (my $this = $self); 3648 CFPlus::weaken (my $this = $self);
3403 3649
3404 $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder }); 3650 $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder });
3405 3651
3406 $self 3652 $self
3407} 3653}
3409sub reorder { 3655sub reorder {
3410 my ($self) = @_; 3656 my ($self) = @_;
3411 my $NOW = Time::HiRes::time; 3657 my $NOW = Time::HiRes::time;
3412 3658
3413 # freeze display when hovering over any label 3659 # freeze display when hovering over any label
3414 return if $CFClient::UI::TOOLTIP->{owner} 3660 return if $CFPlus::UI::TOOLTIP->{owner}
3415 && grep $CFClient::UI::TOOLTIP->{owner} == $_->{label}, 3661 && grep $CFPlus::UI::TOOLTIP->{owner} == $_->{label},
3416 values %{ $self->{item} }; 3662 values %{ $self->{item} };
3417 3663
3418 while (my ($k, $v) = each %{ $self->{item} }) { 3664 while (my ($k, $v) = each %{ $self->{item} }) {
3419 delete $self->{item}{$k} if $v->{timeout} < $NOW; 3665 delete $self->{item}{$k} if $v->{timeout} < $NOW;
3420 } 3666 }
3441 for ($short) { 3687 for ($short) {
3442 s/^\s+//; 3688 s/^\s+//;
3443 s/\s+/ /g; 3689 s/\s+/ /g;
3444 } 3690 }
3445 3691
3446 new CFClient::UI::Label 3692 new CFPlus::UI::Label
3447 markup => $short, 3693 markup => $short,
3448 tooltip => $item->{tooltip}, 3694 tooltip => $item->{tooltip},
3449 tooltip_font => $::FONT_PROP, 3695 tooltip_font => $::FONT_PROP,
3450 tooltip_width => 0.67, 3696 tooltip_width => 0.67,
3451 fontsize => $item->{fontsize} || $self->{fontsize}, 3697 fontsize => $item->{fontsize} || $self->{fontsize},
3530 $self->SUPER::destroy; 3776 $self->SUPER::destroy;
3531} 3777}
3532 3778
3533############################################################################# 3779#############################################################################
3534 3780
3535package CFClient::UI::Inventory;
3536
3537our @ISA = CFClient::UI::Table::;
3538
3539sub new {
3540 my $class = shift;
3541
3542 my $self = $class->SUPER::new (
3543 col_expand => [0, 1, 0],
3544 @_,
3545 );
3546
3547 $self
3548}
3549
3550sub set_items {
3551 my ($self, $items) = @_;
3552
3553 $self->clear;
3554 return unless $items;
3555
3556 my @items = sort {
3557 ($a->{type} <=> $b->{type})
3558 or ($a->{name} cmp $b->{name})
3559 } values %$items;
3560
3561 $self->{real_items} = \@items;
3562
3563 my $row = 0;
3564 for my $item (@items) {
3565 CFClient::Item::update_widgets $item;
3566
3567 $self->add (0, $row, $item->{face_widget});
3568 $self->add (1, $row, $item->{desc_widget});
3569 $self->add (2, $row, $item->{weight_widget});
3570
3571 $row++;
3572 }
3573}
3574
3575#############################################################################
3576
3577package CFClient::UI::SpellList;
3578
3579our @ISA = CFClient::UI::Table::;
3580
3581sub new {
3582 my $class = shift;
3583
3584 my $self = $class->SUPER::new (
3585 binding => [],
3586 commands => [],
3587 @_,
3588 )
3589}
3590
3591my $TOOLTIP_ALL = "\n\n<small>Left click - ready spell\nMiddle click - invoke spell\nRight click - further options</small>";
3592
3593my @TOOLTIP_NAME = (align => -1, can_events => 1, can_hover => 1, tooltip =>
3594 "<b>Name</b>. The name of the spell.$TOOLTIP_ALL");
3595my @TOOLTIP_SKILL = (align => -1, can_events => 1, can_hover => 1, tooltip =>
3596 "<b>Skill</b>. The skill (or magic school) required to be able to attempt casting this spell.$TOOLTIP_ALL");
3597my @TOOLTIP_LVL = (align => 1, can_events => 1, can_hover => 1, tooltip =>
3598 "<b>Level</b>. Minimum level the caster needs in the associated skill to be able to attempt casting this spell.$TOOLTIP_ALL");
3599my @TOOLTIP_SP = (align => 1, can_events => 1, can_hover => 1, tooltip =>
3600 "<b>Spell points / Grace points</b>. Amount of spell or grace points used by each invocation.$TOOLTIP_ALL");
3601my @TOOLTIP_DMG = (align => 1, can_events => 1, can_hover => 1, tooltip =>
3602 "<b>Damage</b>. The amount of damage the spell deals when it hits.$TOOLTIP_ALL");
3603
3604sub rebuild_spell_list {
3605 my ($self) = @_;
3606
3607 $CFClient::UI::ROOT->on_refresh ($self => sub {
3608 $self->clear;
3609
3610 return unless $::CONN;
3611
3612 $self->add (1, 0, new CFClient::UI::Label text => "Spell Name", @TOOLTIP_NAME);
3613 $self->add (2, 0, new CFClient::UI::Label text => "Skill", @TOOLTIP_SKILL);
3614 $self->add (3, 0, new CFClient::UI::Label text => "Lvl" , @TOOLTIP_LVL);
3615 $self->add (4, 0, new CFClient::UI::Label text => "Sp/Gp", @TOOLTIP_SP);
3616 $self->add (5, 0, new CFClient::UI::Label text => "Dmg" , @TOOLTIP_DMG);
3617
3618 my $row = 0;
3619
3620 for (sort { $a cmp $b } keys %{ $self->{spell} }) {
3621 my $spell = $self->{spell}{$_};
3622
3623 $row++;
3624
3625 my $spell_cb = sub {
3626 my ($widget, $ev) = @_;
3627
3628 if ($ev->{button} == 1) {
3629 $::CONN->user_send ("cast $spell->{name}");
3630 } elsif ($ev->{button} == 2) {
3631 $::CONN->user_send ("invoke $spell->{name}");
3632 } elsif ($ev->{button} == 3) {
3633 (new CFClient::UI::Menu
3634 items => [
3635 ["bind <i>cast $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }],
3636 ["bind <i>invoke $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["invoke $spell->{name}"]) }],
3637 ],
3638 )->popup ($ev);
3639 } else {
3640 return 0;
3641 }
3642
3643 1
3644 };
3645
3646 my $tooltip = "$spell->{message}$TOOLTIP_ALL";
3647
3648 #TODO: add path info to tooltip
3649 #$self->add (6, $row, new CFClient::UI::Label text => $spell->{path});
3650
3651 $self->add (0, $row, new CFClient::UI::Face
3652 face => $spell->{face},
3653 can_hover => 1,
3654 can_events => 1,
3655 tooltip => $tooltip,
3656 on_button_down => $spell_cb,
3657 );
3658
3659 $self->add (1, $row, new CFClient::UI::Label
3660 expand => 1,
3661 text => $spell->{name},
3662 can_hover => 1,
3663 can_events => 1,
3664 tooltip => $tooltip,
3665 on_button_down => $spell_cb,
3666 );
3667
3668 $self->add (2, $row, new CFClient::UI::Label text => $::CONN->{skill_info}{$spell->{skill}}, @TOOLTIP_SKILL);
3669 $self->add (3, $row, new CFClient::UI::Label text => $spell->{level}, @TOOLTIP_LVL);
3670 $self->add (4, $row, new CFClient::UI::Label text => $spell->{mana} || $spell->{grace}, @TOOLTIP_SP);
3671 $self->add (5, $row, new CFClient::UI::Label text => $spell->{damage}, @TOOLTIP_DMG);
3672 }
3673 });
3674}
3675
3676sub add_spell {
3677 my ($self, $spell) = @_;
3678
3679 $self->{spell}->{$spell->{name}} = $spell;
3680 $self->rebuild_spell_list;
3681}
3682
3683sub remove_spell {
3684 my ($self, $spell) = @_;
3685
3686 delete $self->{spell}->{$spell->{name}};
3687 $self->rebuild_spell_list;
3688}
3689
3690sub clear_spells {
3691 my ($self) = @_;
3692
3693 $self->{spell} = {};
3694 $self->rebuild_spell_list;
3695}
3696
3697#############################################################################
3698
3699package CFClient::UI::Root; 3781package CFPlus::UI::Root;
3700 3782
3701our @ISA = CFClient::UI::Container::; 3783our @ISA = CFPlus::UI::Container::;
3702 3784
3703use List::Util qw(min max); 3785use List::Util qw(min max);
3704 3786
3705use CFClient::OpenGL; 3787use CFPlus::OpenGL;
3706 3788
3707sub new { 3789sub new {
3708 my $class = shift; 3790 my $class = shift;
3709 3791
3710 my $self = $class->SUPER::new ( 3792 my $self = $class->SUPER::new (
3711 visible => 1, 3793 visible => 1,
3712 @_, 3794 @_,
3713 ); 3795 );
3714 3796
3715 Scalar::Util::weaken ($self->{root} = $self); 3797 CFPlus::weaken ($self->{root} = $self);
3716 3798
3717 $self 3799 $self
3718} 3800}
3719 3801
3720sub size_request { 3802sub size_request {
3889 $h = 0 if $h < 0; 3971 $h = 0 if $h < 0;
3890 3972
3891 $w = max $widget->{min_w}, $w; 3973 $w = max $widget->{min_w}, $w;
3892 $h = max $widget->{min_h}, $h; 3974 $h = max $widget->{min_h}, $h;
3893 3975
3976# $w = min $self->{w} - $widget->{x}, $w if $self->{w};
3977# $h = min $self->{h} - $widget->{y}, $h if $self->{h};
3978
3894 $w = min $widget->{max_w}, $w if exists $widget->{max_w}; 3979 $w = min $widget->{max_w}, $w if exists $widget->{max_w};
3895 $h = min $widget->{max_h}, $h if exists $widget->{max_h}; 3980 $h = min $widget->{max_h}, $h if exists $widget->{max_h};
3896 3981
3897 $w = int $w + 0.5; 3982 $w = int $w + 0.5;
3898 $h = int $h + 0.5; 3983 $h = int $h + 0.5;
3924 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; 4009 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
3925 glMatrixMode GL_MODELVIEW; 4010 glMatrixMode GL_MODELVIEW;
3926 glLoadIdentity; 4011 glLoadIdentity;
3927 4012
3928 { 4013 {
3929 package CFClient::UI::Base; 4014 package CFPlus::UI::Base;
3930 4015
3931 ($draw_x, $draw_y, $draw_w, $draw_h) = 4016 local ($draw_x, $draw_y, $draw_w, $draw_h) =
3932 (0, 0, $self->{w}, $self->{h}); 4017 (0, 0, $self->{w}, $self->{h});
3933 }
3934 4018
3935 $self->_draw; 4019 $self->_draw;
4020 }
3936} 4021}
3937 4022
3938############################################################################# 4023#############################################################################
3939 4024
3940package CFClient::UI; 4025package CFPlus::UI;
3941 4026
3942$ROOT = new CFClient::UI::Root; 4027$ROOT = new CFPlus::UI::Root;
3943$TOOLTIP = new CFClient::UI::Tooltip z => 900; 4028$TOOLTIP = new CFPlus::UI::Tooltip z => 900;
3944 4029
39451 40301
3946 4031

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines