ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.330 by root, Sun Jul 23 04:37:51 2006 UTC vs.
Revision 1.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 {
432 my ($self, $x, $y) = @_; 433 my ($self, $x, $y) = @_;
433 434
435 Carp::confess unless $self->{parent};#d#
436
434 $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y}) 437 $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y})
435} 438}
436 439
437# translate local coordinates to global coordinate system 440# translate local coordinates to global coordinate system
438sub coord2global { 441sub coord2global {
439 my ($self, $x, $y) = @_; 442 my ($self, $x, $y) = @_;
443
444 Carp::confess unless $self->{parent};#d#
440 445
441 $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y}) 446 $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y})
442} 447}
443 448
444sub invoke_focus_in { 449sub invoke_focus_in {
492 497
493sub connect { 498sub connect {
494 my ($self, $signal, $cb) = @_; 499 my ($self, $signal, $cb) = @_;
495 500
496 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 }
497} 507}
508
509sub disconnect_all {
510 my ($self, $signal) = @_;
511
512 delete $self->{signal_cb}{$signal};
513}
514
515my %has_coords = (
516 button_down => 1,
517 button_up => 1,
518 mouse_motion => 1,
519 mouse_wheel => 1,
520);
498 521
499sub emit { 522sub emit {
500 my ($self, $signal, @args) = @_; 523 my ($self, $signal, @args) = @_;
501 524
525 # I do not really like this solution, but I do not like duplication
526 # and needlessly verbose code, either.
502 my @append 527 my @append
503 = ref $args[0] && $args[0]->isa ("CFClient::UI::Event") 528 = $has_coords{$signal}
504 ? $args[0]->xy ($self) 529 ? $args[0]->xy ($self)
505 : (); 530 : ();
506 531
507 #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#
508 533
509 #d##TODO# stop propagating at first true, do not use sum 534 for my $cb (
510 (List::Util::sum map $_->($self, @args, @append), @{$self->{signal_cb}{$signal} || []}) # before 535 @{$self->{signal_cb}{$signal} || []}, # before
511 || ($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
512 || ($self->{parent} && $self->{parent}->emit ($signal, @args)) # parent 542 $self->{parent} && $self->{parent}->emit ($signal, @args)
513} 543}
514 544
515sub find_widget { 545sub find_widget {
516 my ($self, $x, $y) = @_; 546 my ($self, $x, $y) = @_;
517 547
525} 555}
526 556
527sub set_parent { 557sub set_parent {
528 my ($self, $parent) = @_; 558 my ($self, $parent) = @_;
529 559
530 Scalar::Util::weaken ($self->{parent} = $parent); 560 CFPlus::weaken ($self->{parent} = $parent);
531 $self->set_visible if $parent->{visible}; 561 $self->set_visible if $parent->{visible};
532} 562}
533 563
534sub realloc { 564sub realloc {
535 my ($self) = @_; 565 my ($self) = @_;
601 glVertex $self->{w} - 1, 0; 631 glVertex $self->{w} - 1, 0;
602 glVertex $self->{w} - 1, $self->{h} - 1; 632 glVertex $self->{w} - 1, $self->{h} - 1;
603 glVertex 0 , $self->{h} - 1; 633 glVertex 0 , $self->{h} - 1;
604 glEnd; 634 glEnd;
605 glPopMatrix; 635 glPopMatrix;
606 #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;
607 } 637 }
608 638
609 $self->_draw; 639 $self->_draw;
610 glPopMatrix; 640 glPopMatrix;
611} 641}
614 my ($self) = @_; 644 my ($self) = @_;
615 645
616 warn "no draw defined for $self\n"; 646 warn "no draw defined for $self\n";
617} 647}
618 648
649my $cntx;#d#
619sub DESTROY { 650sub DESTROY {
620 my ($self) = @_; 651 my ($self) = @_;
621 652
622 return if CFClient::in_destruct; 653 return if CFPlus::in_destruct;
623
624 delete $WIDGET{$self+0};
625 654
626 eval { $self->destroy }; 655 eval { $self->destroy };
627 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};
628} 659}
629 660
630############################################################################# 661#############################################################################
631 662
632package CFClient::UI::DrawBG; 663package CFPlus::UI::DrawBG;
633 664
634our @ISA = CFClient::UI::Base::; 665our @ISA = CFPlus::UI::Base::;
635 666
636use strict; 667use strict;
637use CFClient::OpenGL; 668use CFPlus::OpenGL;
638 669
639sub new { 670sub new {
640 my $class = shift; 671 my $class = shift;
641 672
642 # range [value, low, high, page] 673 # range [value, low, high, page]
673 } 704 }
674} 705}
675 706
676############################################################################# 707#############################################################################
677 708
678package CFClient::UI::Empty; 709package CFPlus::UI::Empty;
679 710
680our @ISA = CFClient::UI::Base::; 711our @ISA = CFPlus::UI::Base::;
681 712
682sub new { 713sub new {
683 my ($class, %arg) = @_; 714 my ($class, %arg) = @_;
684 $class->SUPER::new (can_events => 0, %arg); 715 $class->SUPER::new (can_events => 0, %arg);
685} 716}
692 723
693sub draw { } 724sub draw { }
694 725
695############################################################################# 726#############################################################################
696 727
697package CFClient::UI::Container; 728package CFPlus::UI::Container;
698 729
699our @ISA = CFClient::UI::Base::; 730our @ISA = CFPlus::UI::Base::;
700 731
701sub new { 732sub new {
702 my ($class, %arg) = @_; 733 my ($class, %arg) = @_;
703 734
704 my $children = delete $arg{children}; 735 my $children = delete $arg{children};
713 if $children; 744 if $children;
714 745
715 $self 746 $self
716} 747}
717 748
749sub realloc {
750 my ($self) = @_;
751
752 $self->{force_realloc} = 1;
753 $self->{force_size_alloc} = 1;
754 $self->SUPER::realloc;
755}
756
718sub add { 757sub add {
719 my ($self, @widgets) = @_; 758 my ($self, @widgets) = @_;
720 759
721 $_->set_parent ($self) 760 $_->set_parent ($self)
722 for @widgets; 761 for @widgets;
782 $_->draw for @{$self->{children}}; 821 $_->draw for @{$self->{children}};
783} 822}
784 823
785############################################################################# 824#############################################################################
786 825
787package CFClient::UI::Bin; 826package CFPlus::UI::Bin;
788 827
789our @ISA = CFClient::UI::Container::; 828our @ISA = CFPlus::UI::Container::;
790 829
791sub new { 830sub new {
792 my ($class, %arg) = @_; 831 my ($class, %arg) = @_;
793 832
794 my $child = (delete $arg{child}) || new CFClient::UI::Empty::; 833 my $child = (delete $arg{child}) || new CFPlus::UI::Empty::;
795 834
796 $class->SUPER::new (children => [$child], %arg) 835 $class->SUPER::new (children => [$child], %arg)
797} 836}
798 837
799sub add { 838sub add {
806sub remove { 845sub remove {
807 my ($self, $widget) = @_; 846 my ($self, $widget) = @_;
808 847
809 $self->SUPER::remove ($widget); 848 $self->SUPER::remove ($widget);
810 849
811 $self->{children} = [new CFClient::UI::Empty] 850 $self->{children} = [new CFPlus::UI::Empty]
812 unless @{$self->{children}}; 851 unless @{$self->{children}};
813} 852}
814 853
815sub child { $_[0]->{children}[0] } 854sub child { $_[0]->{children}[0] }
816 855
828 867
829############################################################################# 868#############################################################################
830 869
831# back-buffered drawing area 870# back-buffered drawing area
832 871
833package CFClient::UI::Window; 872package CFPlus::UI::Window;
834 873
835our @ISA = CFClient::UI::Bin::; 874our @ISA = CFPlus::UI::Bin::;
836 875
837use CFClient::OpenGL; 876use CFPlus::OpenGL;
838 877
839sub new { 878sub new {
840 my ($class, %arg) = @_; 879 my ($class, %arg) = @_;
841 880
842 my $self = $class->SUPER::new (%arg); 881 my $self = $class->SUPER::new (%arg);
864} 903}
865 904
866sub render_child { 905sub render_child {
867 my ($self) = @_; 906 my ($self) = @_;
868 907
869 $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 {
870 glClearColor 0, 0, 0, 0; 909 glClearColor 0, 0, 0, 0;
871 glClear GL_COLOR_BUFFER_BIT; 910 glClear GL_COLOR_BUFFER_BIT;
872 911
873 { 912 {
874 package CFClient::UI::Base; 913 package CFPlus::UI::Base;
875 914
876 ($draw_x, $draw_y, $draw_w, $draw_h) = 915 local ($draw_x, $draw_y, $draw_w, $draw_h) =
877 (0, 0, $self->{w}, $self->{h}); 916 (0, 0, $self->{w}, $self->{h});
917
918 $self->_render;
878 } 919 }
879
880 $self->_render;
881 }; 920 };
882} 921}
883 922
884sub _draw { 923sub _draw {
885 my ($self) = @_; 924 my ($self) = @_;
886
887 my ($w, $h) = @$self{qw(w h)};
888 925
889 my $tex = $self->{texture} 926 my $tex = $self->{texture}
890 or return; 927 or return;
891 928
892 glEnable GL_TEXTURE_2D; 929 glEnable GL_TEXTURE_2D;
893 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 930 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
894 glColor 0, 0, 0, 1; 931 glColor 0, 0, 0, 1;
895 932
896 $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); 933 $tex->draw_quad_alpha_premultiplied (0, 0);
897 934
898 glDisable GL_TEXTURE_2D; 935 glDisable GL_TEXTURE_2D;
899} 936}
900 937
901############################################################################# 938#############################################################################
902 939
903package CFClient::UI::ViewPort; 940package CFPlus::UI::ViewPort;
904 941
905our @ISA = CFClient::UI::Window::; 942our @ISA = CFPlus::UI::Window::;
906 943
907sub new { 944sub new {
908 my $class = shift; 945 my $class = shift;
909 946
910 $class->SUPER::new ( 947 $class->SUPER::new (
970 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} 1007 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w}
971 && $y >= $self->{y} && $y < $self->{y} + $self->{h} 1008 && $y >= $self->{y} && $y < $self->{y} + $self->{h}
972 ) { 1009 ) {
973 $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})
974 } else { 1011 } else {
975 $self->CFClient::UI::Base::find_widget ($x, $y) 1012 $self->CFPlus::UI::Base::find_widget ($x, $y)
976 } 1013 }
977} 1014}
978 1015
979sub _render { 1016sub _render {
980 my ($self) = @_; 1017 my ($self) = @_;
981 1018
982 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};
983 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};
984 1021
985 CFClient::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; 1022 CFPlus::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y};
986 1023
987 $self->SUPER::_render; 1024 $self->SUPER::_render;
988} 1025}
989 1026
990############################################################################# 1027#############################################################################
991 1028
992package CFClient::UI::ScrolledWindow; 1029package CFPlus::UI::ScrolledWindow;
993 1030
994our @ISA = CFClient::UI::HBox::; 1031our @ISA = CFPlus::UI::HBox::;
995 1032
996sub new { 1033sub new {
997 my ($class, %arg) = @_; 1034 my ($class, %arg) = @_;
998 1035
999 my $child = delete $arg{child}; 1036 my $child = delete $arg{child};
1000 1037
1001 my $self; 1038 my $self;
1002 1039
1003 my $slider = new CFClient::UI::Slider 1040 my $slider = new CFPlus::UI::Slider
1004 vertical => 1, 1041 vertical => 1,
1005 range => [0, 0, 1, 0.01], # HACK fix 1042 range => [0, 0, 1, 0.01], # HACK fix
1006 on_changed => sub { 1043 on_changed => sub {
1007 $self->{vp}->set_offset (0, $_[1]); 1044 $self->{vp}->set_offset (0, $_[1]);
1008 }, 1045 },
1009 ; 1046 ;
1010 1047
1011 $self = $class->SUPER::new ( 1048 $self = $class->SUPER::new (
1012 vp => (new CFClient::UI::ViewPort expand => 1), 1049 vp => (new CFPlus::UI::ViewPort expand => 1),
1013 can_events => 1, 1050 can_events => 1,
1014 slider => $slider, 1051 slider => $slider,
1015 %arg, 1052 %arg,
1016 ); 1053 );
1017 1054
1061 $self->SUPER::invoke_size_allocate ($w, $h) 1098 $self->SUPER::invoke_size_allocate ($w, $h)
1062} 1099}
1063 1100
1064############################################################################# 1101#############################################################################
1065 1102
1066package CFClient::UI::Frame; 1103package CFPlus::UI::Frame;
1067 1104
1068our @ISA = CFClient::UI::Bin::; 1105our @ISA = CFPlus::UI::Bin::;
1069 1106
1070use CFClient::OpenGL; 1107use CFPlus::OpenGL;
1071 1108
1072sub new { 1109sub new {
1073 my $class = shift; 1110 my $class = shift;
1074 1111
1075 $class->SUPER::new ( 1112 $class->SUPER::new (
1101 $self->SUPER::_draw; 1138 $self->SUPER::_draw;
1102} 1139}
1103 1140
1104############################################################################# 1141#############################################################################
1105 1142
1106package CFClient::UI::FancyFrame; 1143package CFPlus::UI::FancyFrame;
1107 1144
1108our @ISA = CFClient::UI::Bin::; 1145our @ISA = CFPlus::UI::Bin::;
1109 1146
1110use 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;
1111 1248
1112my $bg = 1249my $bg =
1113 new_from_file CFClient::Texture CFClient::find_rcfile "d1_bg.png", 1250 new_from_file CFPlus::Texture CFPlus::find_rcfile "d1_bg.png",
1114 mipmap => 1, wrap => 1; 1251 mipmap => 1, wrap => 1;
1115 1252
1116my @border = 1253my @border =
1117 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1254 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
1118 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); 1255 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
1119 1256
1120sub new { 1257sub new {
1121 my ($class, %arg) = @_; 1258 my ($class, %arg) = @_;
1122 1259
1128 min_w => 64, 1265 min_w => 64,
1129 min_h => 32, 1266 min_h => 32,
1130 %arg, 1267 %arg,
1131 ); 1268 );
1132 1269
1133 $self->{title_widget} = new CFClient::UI::Label 1270 $self->{title_widget} = new CFPlus::UI::Label
1134 align => 0, 1271 align => 0,
1135 valign => 1, 1272 valign => 1,
1136 text => $self->{title}, 1273 text => $self->{title},
1137 fontsize => $self->{border}, 1274 fontsize => $self->{border},
1138 if exists $self->{title}; 1275 if exists $self->{title};
1139 1276
1140 if ($self->{has_close_button}) { 1277 if ($self->{has_close_button}) {
1141 $self->{close_button} = 1278 $self->{close_button} =
1142 new CFClient::UI::ImageButton 1279 new CFPlus::UI::ImageButton
1143 path => 'x1_close.png', 1280 path => 'x1_close.png',
1144 on_activate => sub { $self->emit ("delete") }; 1281 on_activate => sub { $self->emit ("delete") };
1145 1282
1146 $self->CFClient::UI::Container::add ($self->{close_button}); 1283 $self->CFPlus::UI::Container::add ($self->{close_button});
1147 } 1284 }
1148 1285
1149 $self 1286 $self
1150} 1287}
1151 1288
1152sub add { 1289sub add {
1153 my ($self, @widgets) = @_; 1290 my ($self, @widgets) = @_;
1154 1291
1155 $self->SUPER::add (@widgets); 1292 $self->SUPER::add (@widgets);
1156 $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};
1157 $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};
1158} 1295}
1159 1296
1160sub border { 1297sub border {
1161 int $_[0]{border} * $::FONTSIZE 1298 int $_[0]{border} * $::FONTSIZE
1162} 1299}
1270 $self->{motion}->($ev, $x, $y) if $self->{motion}; 1407 $self->{motion}->($ev, $x, $y) if $self->{motion};
1271 1408
1272 ! ! $self->{motion} 1409 ! ! $self->{motion}
1273} 1410}
1274 1411
1412sub invoke_visibility_change {
1413 my ($self, $visible) = @_;
1414
1415 delete $self->{motion} unless $visible;
1416
1417 0
1418}
1419
1275sub _draw { 1420sub _draw {
1276 my ($self) = @_; 1421 my ($self) = @_;
1277 1422
1278 my $child = $self->{children}[0]; 1423 my $child = $self->{children}[0];
1279 1424
1316 if $self->{close_button}; 1461 if $self->{close_button};
1317} 1462}
1318 1463
1319############################################################################# 1464#############################################################################
1320 1465
1321package CFClient::UI::Table; 1466package CFPlus::UI::Table;
1322 1467
1323our @ISA = CFClient::UI::Base::; 1468our @ISA = CFPlus::UI::Base::;
1324 1469
1325use List::Util qw(max sum); 1470use List::Util qw(max sum);
1326 1471
1327use CFClient::OpenGL; 1472use CFPlus::OpenGL;
1328 1473
1329sub new { 1474sub new {
1330 my $class = shift; 1475 my $class = shift;
1331 1476
1332 $class->SUPER::new ( 1477 $class->SUPER::new (
1338sub children { 1483sub children {
1339 grep $_, map @$_, grep $_, @{ $_[0]{children} } 1484 grep $_, map @$_, grep $_, @{ $_[0]{children} }
1340} 1485}
1341 1486
1342sub add { 1487sub add {
1343 my ($self, $x, $y, $child) = @_; 1488 my ($self) = shift;
1344 1489
1490 while (@_) {
1491 my ($x, $y, $child) = splice @_, 0, 3, ();
1345 $child->set_parent ($self); 1492 $child->set_parent ($self);
1346 $self->{children}[$y][$x] = $child; 1493 $self->{children}[$y][$x] = $child;
1494 }
1347 1495
1496 $self->{force_realloc} = 1;
1497 $self->{force_size_alloc} = 1;
1348 $self->realloc; 1498 $self->realloc;
1349} 1499}
1350 1500
1351sub remove { 1501sub remove {
1352 my ($self, $child) = @_; 1502 my ($self, $child) = @_;
1417 1567
1418 # linearly scale sizes 1568 # linearly scale sizes
1419 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; 1569 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws;
1420 $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs; 1570 $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs;
1421 1571
1422 CFClient::UI::harmonize $ws; 1572 CFPlus::UI::harmonize $ws;
1423 CFClient::UI::harmonize $hs; 1573 CFPlus::UI::harmonize $hs;
1424 1574
1425 my $y; 1575 my $y;
1426 1576
1427 for my $r (0 .. $#{$self->{children}}) { 1577 for my $r (0 .. $#{$self->{children}}) {
1428 my $row = $self->{children}[$r] 1578 my $row = $self->{children}[$r]
1471 } 1621 }
1472} 1622}
1473 1623
1474############################################################################# 1624#############################################################################
1475 1625
1476package CFClient::UI::Box; 1626package CFPlus::UI::Box;
1477 1627
1478our @ISA = CFClient::UI::Container::; 1628our @ISA = CFPlus::UI::Container::;
1479 1629
1480sub size_request { 1630sub size_request {
1481 my ($self) = @_; 1631 my ($self) = @_;
1482 1632
1483 $self->{vertical} 1633 $self->{vertical}
1516 $req[$_] += $space * $children[$_]{expand} 1666 $req[$_] += $space * $children[$_]{expand}
1517 for 0 .. $#children; 1667 for 0 .. $#children;
1518 } 1668 }
1519 } 1669 }
1520 1670
1521 CFClient::UI::harmonize \@req; 1671 CFPlus::UI::harmonize \@req;
1522 1672
1523 my $pos = 0; 1673 my $pos = 0;
1524 for (0 .. $#children) { 1674 for (0 .. $#children) {
1525 my $alloc = $req[$_]; 1675 my $alloc = $req[$_];
1526 $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));
1531 1 1681 1
1532} 1682}
1533 1683
1534############################################################################# 1684#############################################################################
1535 1685
1536package CFClient::UI::HBox; 1686package CFPlus::UI::HBox;
1537 1687
1538our @ISA = CFClient::UI::Box::; 1688our @ISA = CFPlus::UI::Box::;
1539 1689
1540sub new { 1690sub new {
1541 my $class = shift; 1691 my $class = shift;
1542 1692
1543 $class->SUPER::new ( 1693 $class->SUPER::new (
1546 ) 1696 )
1547} 1697}
1548 1698
1549############################################################################# 1699#############################################################################
1550 1700
1551package CFClient::UI::VBox; 1701package CFPlus::UI::VBox;
1552 1702
1553our @ISA = CFClient::UI::Box::; 1703our @ISA = CFPlus::UI::Box::;
1554 1704
1555sub new { 1705sub new {
1556 my $class = shift; 1706 my $class = shift;
1557 1707
1558 $class->SUPER::new ( 1708 $class->SUPER::new (
1561 ) 1711 )
1562} 1712}
1563 1713
1564############################################################################# 1714#############################################################################
1565 1715
1566package CFClient::UI::Label; 1716package CFPlus::UI::Label;
1567 1717
1568our @ISA = CFClient::UI::DrawBG::; 1718our @ISA = CFPlus::UI::DrawBG::;
1569 1719
1570use CFClient::OpenGL; 1720use CFPlus::OpenGL;
1571 1721
1572sub new { 1722sub new {
1573 my ($class, %arg) = @_; 1723 my ($class, %arg) = @_;
1574 1724
1575 my $self = $class->SUPER::new ( 1725 my $self = $class->SUPER::new (
1578 #active_bg => none 1728 #active_bg => none
1579 #font => default_font 1729 #font => default_font
1580 #text => initial text 1730 #text => initial text
1581 #markup => initial narkup 1731 #markup => initial narkup
1582 #max_w => maximum pixel width 1732 #max_w => maximum pixel width
1733 #style => 0, # render flags
1583 ellipsise => 3, # end 1734 ellipsise => 3, # end
1584 layout => (new CFClient::Layout), 1735 layout => (new CFPlus::Layout),
1585 fontsize => 1, 1736 fontsize => 1,
1586 align => -1, 1737 align => -1,
1587 valign => -1, 1738 valign => -1,
1588 padding_x => 2, 1739 padding_x => 2,
1589 padding_y => 2, 1740 padding_y => 2,
1590 can_events => 0, 1741 can_events => 0,
1591 %arg 1742 %arg
1592 ); 1743 );
1593 1744
1594 if (exists $self->{template}) { 1745 if (exists $self->{template}) {
1595 my $layout = new CFClient::Layout; 1746 my $layout = new CFPlus::Layout;
1596 $layout->set_text (delete $self->{template}); 1747 $layout->set_text (delete $self->{template});
1597 $self->{template} = $layout; 1748 $self->{template} = $layout;
1598 } 1749 }
1599 1750
1600 if (exists $self->{markup}) { 1751 if (exists $self->{markup}) {
1602 } else { 1753 } else {
1603 $self->set_text (delete $self->{text}); 1754 $self->set_text (delete $self->{text});
1604 } 1755 }
1605 1756
1606 $self 1757 $self
1607}
1608
1609sub escape($) {
1610 local $_ = $_[0];
1611
1612 s/&/&amp;/g;
1613 s/>/&gt;/g;
1614 s/</&lt;/g;
1615
1616 $_
1617} 1758}
1618 1759
1619sub update { 1760sub update {
1620 my ($self) = @_; 1761 my ($self) = @_;
1621 1762
1748 }; 1889 };
1749 1890
1750 my $w = List::Util::min $self->{w} + 4, $size->[0]; 1891 my $w = List::Util::min $self->{w} + 4, $size->[0];
1751 my $h = List::Util::min $self->{h} + 2, $size->[1]; 1892 my $h = List::Util::min $self->{h} + 2, $size->[1];
1752 1893
1753 $self->{layout}->render ($self->{ox}, $self->{oy}); 1894 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
1754} 1895}
1755 1896
1756############################################################################# 1897#############################################################################
1757 1898
1758package CFClient::UI::EntryBase; 1899package CFPlus::UI::EntryBase;
1759 1900
1760our @ISA = CFClient::UI::Label::; 1901our @ISA = CFPlus::UI::Label::;
1761 1902
1762use CFClient::OpenGL; 1903use CFPlus::OpenGL;
1763 1904
1764sub new { 1905sub new {
1765 my $class = shift; 1906 my $class = shift;
1766 1907
1767 $class->SUPER::new ( 1908 $class->SUPER::new (
1771 active_fg => [0, 0, 0], 1912 active_fg => [0, 0, 0],
1772 can_hover => 1, 1913 can_hover => 1,
1773 can_focus => 1, 1914 can_focus => 1,
1774 valign => 0, 1915 valign => 0,
1775 can_events => 1, 1916 can_events => 1,
1917 ellipsise => 0,
1776 #text => ... 1918 #text => ...
1777 #hidden => "*", 1919 #hidden => "*",
1778 @_ 1920 @_
1779 ) 1921 )
1780} 1922}
1829 1971
1830 if ($uni == 8) { 1972 if ($uni == 8) {
1831 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 1973 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
1832 } elsif ($uni == 127) { 1974 } elsif ($uni == 127) {
1833 substr $text, $self->{cursor}, 1, ""; 1975 substr $text, $self->{cursor}, 1, "";
1834 } elsif ($sym == CFClient::SDLK_LEFT) { 1976 } elsif ($sym == CFPlus::SDLK_LEFT) {
1835 --$self->{cursor} if $self->{cursor}; 1977 --$self->{cursor} if $self->{cursor};
1836 } elsif ($sym == CFClient::SDLK_RIGHT) { 1978 } elsif ($sym == CFPlus::SDLK_RIGHT) {
1837 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 1979 ++$self->{cursor} if $self->{cursor} < length $self->{text};
1838 } 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 = "";
1839 $self->{cursor} = 0; 1994 $self->{cursor} = 0;
1840 } elsif ($sym == CFClient::SDLK_END) {
1841 $self->{cursor} = length $text;
1842 } elsif ($uni == 27) { 1995 } elsif ($uni == 27) {
1843 $self->emit ('escape'); 1996 $self->emit ('escape');
1844 } elsif ($uni) { 1997 } elsif ($uni == 0x0d) {
1998 substr $text, $self->{cursor}++, 0, "\012";
1999 } elsif ($uni >= 0x20) {
1845 substr $text, $self->{cursor}++, 0, chr $uni; 2000 substr $text, $self->{cursor}++, 0, chr $uni;
1846 } else { 2001 } else {
1847 return 0; 2002 return 0;
1848 } 2003 }
1849 2004
1850 $self->_set_text ($text); 2005 $self->_set_text ($text);
1851 2006
1852 $self->realloc; 2007 $self->realloc;
2008 $self->update;
1853 2009
1854 1 2010 1
1855} 2011}
1856 2012
1857sub invoke_focus_in { 2013sub invoke_focus_in {
1919 utf8::encode $text; 2075 utf8::encode $text;
1920 2076
1921 @$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)
1922 } 2078 }
1923 2079
1924 glColor @{$self->{fg}};
1925 glBegin GL_LINES; 2080 glBegin GL_LINES;
1926 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};
1927 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};
1928 glEnd; 2083 glEnd;
1929 } 2084 }
1930} 2085}
1931 2086
2087#############################################################################
2088
1932package CFClient::UI::Entry; 2089package CFPlus::UI::Entry;
1933 2090
1934our @ISA = CFClient::UI::EntryBase::; 2091our @ISA = CFPlus::UI::EntryBase::;
1935 2092
1936use CFClient::OpenGL; 2093use CFPlus::OpenGL;
1937 2094
1938sub invoke_key_down { 2095sub invoke_key_down {
1939 my ($self, $ev) = @_; 2096 my ($self, $ev) = @_;
1940 2097
1941 my $sym = $ev->{sym}; 2098 my $sym = $ev->{sym};
1942 2099
1943 if ($sym == 13) { 2100 if ($ev->{uni} == 0x0d || $sym == 13) {
1944 unshift @{$self->{history}}, 2101 unshift @{$self->{history}},
1945 my $txt = $self->get_text; 2102 my $txt = $self->get_text;
1946 2103
1947 $self->{history_pointer} = -1; 2104 $self->{history_pointer} = -1;
1948 $self->{history_saveback} = ''; 2105 $self->{history_saveback} = '';
1949 $self->emit (activate => $txt); 2106 $self->emit (activate => $txt);
1950 $self->update; 2107 $self->update;
1951 2108
1952 } elsif ($sym == CFClient::SDLK_UP) { 2109 } elsif ($sym == CFPlus::SDLK_UP) {
1953 if ($self->{history_pointer} < 0) { 2110 if ($self->{history_pointer} < 0) {
1954 $self->{history_saveback} = $self->get_text; 2111 $self->{history_saveback} = $self->get_text;
1955 } 2112 }
1956 if (@{$self->{history} || []} > 0) { 2113 if (@{$self->{history} || []} > 0) {
1957 $self->{history_pointer}++; 2114 $self->{history_pointer}++;
1959 $self->{history_pointer} = @{$self->{history} || []} - 1; 2116 $self->{history_pointer} = @{$self->{history} || []} - 1;
1960 } 2117 }
1961 $self->set_text ($self->{history}->[$self->{history_pointer}]); 2118 $self->set_text ($self->{history}->[$self->{history_pointer}]);
1962 } 2119 }
1963 2120
1964 } elsif ($sym == CFClient::SDLK_DOWN) { 2121 } elsif ($sym == CFPlus::SDLK_DOWN) {
1965 $self->{history_pointer}--; 2122 $self->{history_pointer}--;
1966 $self->{history_pointer} = -1 if $self->{history_pointer} < 0; 2123 $self->{history_pointer} = -1 if $self->{history_pointer} < 0;
1967 2124
1968 if ($self->{history_pointer} >= 0) { 2125 if ($self->{history_pointer} >= 0) {
1969 $self->set_text ($self->{history}->[$self->{history_pointer}]); 2126 $self->set_text ($self->{history}->[$self->{history_pointer}]);
1978 1 2135 1
1979} 2136}
1980 2137
1981############################################################################# 2138#############################################################################
1982 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
1983package CFClient::UI::Button; 2179package CFPlus::UI::Button;
1984 2180
1985our @ISA = CFClient::UI::Label::; 2181our @ISA = CFPlus::UI::Label::;
1986 2182
1987use CFClient::OpenGL; 2183use CFPlus::OpenGL;
1988 2184
1989my @tex = 2185my @tex =
1990 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2186 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
1991 qw(b1_button_active.png); 2187 qw(b1_button_active.png);
1992 2188
1993sub new { 2189sub new {
1994 my $class = shift; 2190 my $class = shift;
1995 2191
2032 $self->SUPER::_draw; 2228 $self->SUPER::_draw;
2033} 2229}
2034 2230
2035############################################################################# 2231#############################################################################
2036 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
2037package CFClient::UI::ImageButton; 2382package CFPlus::UI::ImageButton;
2038 2383
2039our @ISA = CFClient::UI::Image::; 2384our @ISA = CFPlus::UI::Image::;
2040 2385
2041use CFClient::OpenGL; 2386use CFPlus::OpenGL;
2042 2387
2043my %textures; 2388my %textures;
2044 2389
2045sub new { 2390sub new {
2046 my $class = shift; 2391 my $class = shift;
2068 1 2413 1
2069} 2414}
2070 2415
2071############################################################################# 2416#############################################################################
2072 2417
2073package CFClient::UI::CheckBox;
2074
2075our @ISA = CFClient::UI::DrawBG::;
2076
2077my @tex =
2078 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
2079 qw(c1_checkbox_bg.png c1_checkbox_active.png);
2080
2081use CFClient::OpenGL;
2082
2083sub new {
2084 my $class = shift;
2085
2086 $class->SUPER::new (
2087 padding_x => 2,
2088 padding_y => 2,
2089 fg => [1, 1, 1],
2090 active_fg => [1, 1, 0],
2091 bg => [0, 0, 0, 0.2],
2092 active_bg => [1, 1, 1, 0.5],
2093 state => 0,
2094 can_hover => 1,
2095 @_
2096 )
2097}
2098
2099sub size_request {
2100 my ($self) = @_;
2101
2102 (6) x 2
2103}
2104
2105sub toggle {
2106 my ($self) = @_;
2107
2108 $self->{state} = !$self->{state};
2109 $self->emit (changed => $self->{state});
2110 $self->update;
2111}
2112
2113sub invoke_button_down {
2114 my ($self, $ev, $x, $y) = @_;
2115
2116 if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x}
2117 && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) {
2118 $self->toggle;
2119 } else {
2120 return 0
2121 }
2122
2123 1
2124}
2125
2126sub _draw {
2127 my ($self) = @_;
2128
2129 $self->SUPER::_draw;
2130
2131 glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0;
2132
2133 my ($w, $h) = @$self{qw(w h)};
2134
2135 my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2;
2136
2137 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} };
2138
2139 my $tex = $self->{state} ? $tex[1] : $tex[0];
2140
2141 glEnable GL_TEXTURE_2D;
2142 $tex->draw_quad_alpha (0, 0, $s, $s);
2143 glDisable GL_TEXTURE_2D;
2144}
2145
2146#############################################################################
2147
2148package CFClient::UI::Image; 2418package CFPlus::UI::VGauge;
2149 2419
2150our @ISA = CFClient::UI::Base::; 2420our @ISA = CFPlus::UI::Base::;
2151
2152use CFClient::OpenGL;
2153
2154our %texture_cache;
2155
2156sub new {
2157 my $class = shift;
2158
2159 my $self = $class->SUPER::new (
2160 can_events => 0,
2161 @_,
2162 );
2163
2164 $self->{path} || $self->{tex}
2165 or Carp::croak "'path' or 'tex' attributes required";
2166
2167 $self->{tex} ||= $texture_cache{$self->{path}} ||=
2168 new_from_file CFClient::Texture CFClient::find_rcfile $self->{path}, mipmap => 1;
2169
2170 Scalar::Util::weaken $texture_cache{$self->{path}};
2171
2172 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2173
2174 $self
2175}
2176
2177sub size_request {
2178 my ($self) = @_;
2179
2180 ($self->{tex}{w}, $self->{tex}{h})
2181}
2182
2183sub _draw {
2184 my ($self) = @_;
2185
2186 my $tex = $self->{tex};
2187
2188 my ($w, $h) = ($self->{w}, $self->{h});
2189
2190 if ($self->{rot90}) {
2191 glRotate 90, 0, 0, 1;
2192 glTranslate 0, -$self->{w}, 0;
2193
2194 ($w, $h) = ($h, $w);
2195 }
2196
2197 glEnable GL_TEXTURE_2D;
2198 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2199
2200 $tex->draw_quad_alpha (0, 0, $w, $h);
2201
2202 glDisable GL_TEXTURE_2D;
2203}
2204
2205#############################################################################
2206
2207package CFClient::UI::VGauge;
2208
2209our @ISA = CFClient::UI::Base::;
2210 2421
2211use List::Util qw(min max); 2422use List::Util qw(min max);
2212 2423
2213use CFClient::OpenGL; 2424use CFPlus::OpenGL;
2214 2425
2215my %tex = ( 2426my %tex = (
2216 food => [ 2427 food => [
2217 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2428 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2218 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 2429 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
2219 ], 2430 ],
2220 grace => [ 2431 grace => [
2221 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2432 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2222 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/ 2433 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/
2223 ], 2434 ],
2224 hp => [ 2435 hp => [
2225 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2436 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2226 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 2437 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
2227 ], 2438 ],
2228 mana => [ 2439 mana => [
2229 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2440 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2230 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/ 2441 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/
2231 ], 2442 ],
2232); 2443);
2233 2444
2234# eg. VGauge->new (gauge => 'food'), default gauge: food 2445# eg. VGauge->new (gauge => 'food'), default gauge: food
2337 glDisable GL_TEXTURE_2D; 2548 glDisable GL_TEXTURE_2D;
2338} 2549}
2339 2550
2340############################################################################# 2551#############################################################################
2341 2552
2342package CFClient::UI::Gauge; 2553package CFPlus::UI::Gauge;
2343 2554
2344our @ISA = CFClient::UI::VBox::; 2555our @ISA = CFPlus::UI::VBox::;
2345 2556
2346sub new { 2557sub new {
2347 my ($class, %arg) = @_; 2558 my ($class, %arg) = @_;
2348 2559
2349 my $self = $class->SUPER::new ( 2560 my $self = $class->SUPER::new (
2351 can_hover => 1, 2562 can_hover => 1,
2352 can_events => 1, 2563 can_events => 1,
2353 %arg, 2564 %arg,
2354 ); 2565 );
2355 2566
2356 $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");
2357 $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);
2358 $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");
2359 2570
2360 $self 2571 $self
2361} 2572}
2362 2573
2363sub set_fontsize { 2574sub set_fontsize {
2384 $self->{value}->set_text ($val); 2595 $self->{value}->set_text ($val);
2385} 2596}
2386 2597
2387############################################################################# 2598#############################################################################
2388 2599
2389package CFClient::UI::Slider; 2600package CFPlus::UI::Slider;
2390 2601
2391use strict; 2602use strict;
2392 2603
2393use CFClient::OpenGL; 2604use CFPlus::OpenGL;
2394 2605
2395our @ISA = CFClient::UI::DrawBG::; 2606our @ISA = CFPlus::UI::DrawBG::;
2396 2607
2397my @tex = 2608my @tex =
2398 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 2609 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_ }
2399 qw(s1_slider.png s1_slider_bg.png); 2610 qw(s1_slider.png s1_slider_bg.png);
2400 2611
2401sub new { 2612sub new {
2402 my $class = shift; 2613 my $class = shift;
2403 2614
2497sub invoke_mouse_wheel { 2708sub invoke_mouse_wheel {
2498 my ($self, $ev) = @_; 2709 my ($self, $ev) = @_;
2499 2710
2500 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; 2711 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx};
2501 2712
2713 my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2;
2714
2502 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * 0.1); 2715 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart);
2503 2716
2504 ! ! $delta 2717 ! ! $delta
2505} 2718}
2506 2719
2507sub update { 2720sub update {
2558 glDisable GL_TEXTURE_2D; 2771 glDisable GL_TEXTURE_2D;
2559} 2772}
2560 2773
2561############################################################################# 2774#############################################################################
2562 2775
2563package CFClient::UI::ValSlider; 2776package CFPlus::UI::ValSlider;
2564 2777
2565our @ISA = CFClient::UI::HBox::; 2778our @ISA = CFPlus::UI::HBox::;
2566 2779
2567sub new { 2780sub new {
2568 my ($class, %arg) = @_; 2781 my ($class, %arg) = @_;
2569 2782
2570 my $range = delete $arg{range}; 2783 my $range = delete $arg{range};
2571 2784
2572 my $self = $class->SUPER::new ( 2785 my $self = $class->SUPER::new (
2573 slider => (new CFClient::UI::Slider expand => 1, range => $range), 2786 slider => (new CFPlus::UI::Slider expand => 1, range => $range),
2574 entry => (new CFClient::UI::Label text => "", template => delete $arg{template}), 2787 entry => (new CFPlus::UI::Label text => "", template => delete $arg{template}),
2575 to_value => sub { shift }, 2788 to_value => sub { shift },
2576 from_value => sub { shift }, 2789 from_value => sub { shift },
2577 %arg, 2790 %arg,
2578 ); 2791 );
2579 2792
2599sub set_range { shift->{slider}->set_range (@_) } 2812sub set_range { shift->{slider}->set_range (@_) }
2600sub set_value { shift->{slider}->set_value (@_) } 2813sub set_value { shift->{slider}->set_value (@_) }
2601 2814
2602############################################################################# 2815#############################################################################
2603 2816
2604package CFClient::UI::TextScroller; 2817package CFPlus::UI::TextScroller;
2605 2818
2606our @ISA = CFClient::UI::HBox::; 2819our @ISA = CFPlus::UI::HBox::;
2607 2820
2608use CFClient::OpenGL; 2821use CFPlus::OpenGL;
2609 2822
2610sub new { 2823sub new {
2611 my $class = shift; 2824 my $class = shift;
2612 2825
2613 my $self = $class->SUPER::new ( 2826 my $self = $class->SUPER::new (
2615 can_events => 1, 2828 can_events => 1,
2616 indent => 0, 2829 indent => 0,
2617 #font => default_font 2830 #font => default_font
2618 @_, 2831 @_,
2619 2832
2620 layout => (new CFClient::Layout), 2833 layout => (new CFPlus::Layout),
2621 par => [], 2834 par => [],
2622 height => 0, 2835 height => 0,
2623 children => [ 2836 children => [
2624 (new CFClient::UI::Empty expand => 1), 2837 (new CFPlus::UI::Empty expand => 1),
2625 (new CFClient::UI::Slider vertical => 1), 2838 (new CFPlus::UI::Slider vertical => 1),
2626 ], 2839 ],
2627 ); 2840 );
2628 2841
2629 $self->{children}[1]->connect (changed => sub { $self->update }); 2842 $self->{children}[1]->connect (changed => sub { $self->update });
2630 2843
2707 2920
2708 # todo: base offset on lines or so, not on pixels 2921 # todo: base offset on lines or so, not on pixels
2709 $self->{children}[1]->set_value ($offset); 2922 $self->{children}[1]->set_value ($offset);
2710} 2923}
2711 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
2712sub clear { 2940sub clear {
2713 my ($self) = @_; 2941 my ($self) = @_;
2714 2942
2715 my (undef, undef, @other) = @{ $self->{children} }; 2943 my (undef, undef, @other) = @{ $self->{children} };
2716 $self->remove ($_) for @other; 2944 $self->remove ($_) for @other;
2719 $self->{height} = 0; 2947 $self->{height} = 0;
2720 $self->{children}[1]->set_range ([0, 0, 0, 1, 1]); 2948 $self->{children}[1]->set_range ([0, 0, 0, 1, 1]);
2721} 2949}
2722 2950
2723sub add_paragraph { 2951sub add_paragraph {
2724 my ($self, $color, $para, $indent) = @_; 2952 my $self = shift;
2725 2953
2726 my ($text, @w) = ref $para ? @$para : $para; 2954 for my $para (@_) {
2727
2728 $para = { 2955 $para = {
2956 fg => [1, 1, 1, 1],
2957 indent => 0,
2958 markup => "",
2959 widget => [],
2960 ref $para ? %$para : (markup => $para),
2729 w => 1e10, 2961 w => 1e10,
2730 wrapped => 1, 2962 wrapped => 1,
2731 fg => $color,
2732 indent => $indent,
2733 markup => $text,
2734 widget => \@w,
2735 }; 2963 };
2736 2964
2737 $self->add (@w) if @w; 2965 $self->add (@{ $para->{widget} }) if @{ $para->{widget} };
2738 push @{$self->{par}}, $para; 2966 push @{$self->{par}}, $para;
2967 }
2739 2968
2740 $self->{need_reflow}++; 2969 $self->{need_reflow}++;
2741 $self->update; 2970 $self->update;
2742} 2971}
2743 2972
2744sub scroll_to_bottom { 2973sub scroll_to_bottom {
2745 my ($self) = @_; 2974 my ($self) = @_;
2746 2975
2747 $self->{scroll_to_bottom} = 1; 2976 $self->{scroll_to} = $#{$self->{par}};
2748 $self->update; 2977 $self->update;
2749} 2978}
2750 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
2751sub update { 3013sub update {
2752 my ($self) = @_; 3014 my ($self) = @_;
2753 3015
2754 $self->SUPER::update; 3016 $self->SUPER::update;
2755 3017
2756 return unless $self->{h} > 0; 3018 return unless $self->{h} > 0;
2757 3019
2758 delete $self->{texture}; 3020 delete $self->{texture};
2759 3021
2760 $ROOT->on_post_alloc ($self => sub { 3022 $ROOT->on_post_alloc ($self => sub {
3023 $self->force_uptodate;
3024
2761 my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; 3025 my ($W, $H) = @{$self->{children}[0]}{qw(w h)};
2762 3026
2763 if (delete $self->{need_reflow}) {
2764 my $height = 0;
2765
2766 for my $para (@{$self->{par}}) {
2767 if ($para->{w} != $W && ($para->{wrapped} || $para->{w} > $W)) {
2768 my $layout = $self->get_layout ($para);
2769 my ($w, $h) = $layout->size;
2770
2771 $para->{w} = $w + $para->{indent};
2772 $para->{h} = $h;
2773 $para->{wrapped} = $layout->has_wrapped;
2774 }
2775
2776 $height += $para->{h};
2777 }
2778
2779 $self->{height} = $height;
2780
2781 $self->{children}[1]->set_range ([$self->{children}[1]{range}[0], 0, $height, $H, 1]);
2782
2783 delete $self->{texture};
2784 }
2785
2786 if (delete $self->{scroll_to_bottom}) {
2787 $self->{children}[1]->set_value (1e10);
2788 }
2789
2790 $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { 3027 $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub {
2791 glClearColor 0, 0, 0, 0; 3028 glClearColor 0, 0, 0, 0;
2792 glClear GL_COLOR_BUFFER_BIT; 3029 glClear GL_COLOR_BUFFER_BIT;
2793 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;
2794 my $top = int $self->{children}[1]{range}[0]; 3039 my $top = int $self->{children}[1]{range}[0];
2795 3040
2796 my $y0 = $top; 3041 my $y0 = $top;
2797 my $y1 = $top + $H; 3042 my $y1 = $top + $H;
2798 3043
2799 my $y = 0;
2800
2801 for my $para (@{$self->{par}}) { 3044 for my $para (@{$self->{par}}) {
2802 my $h = $para->{h}; 3045 my $h = $para->{h};
3046 my $y = $para->{y};
2803 3047
2804 if ($y0 < $y + $h && $y < $y1) { 3048 if ($y0 < $y + $h && $y < $y1) {
2805
2806 my $layout = $self->get_layout ($para); 3049 my $layout = $self->get_layout ($para);
2807 3050
2808 $layout->render ($para->{indent}, $y - $y0); 3051 $layout->render ($para->{indent}, $y - $y0);
2809 3052
2810 if (my @w = @{ $para->{widget} }) { 3053 if (my @w = @{ $para->{widget} }) {
2819 $_->draw; 3062 $_->draw;
2820 } 3063 }
2821 } 3064 }
2822 } 3065 }
2823 3066
2824 $y += $h; 3067 $paridx++;
3068 $top_paragraph ||= $paridx if $y >= $top;
2825 } 3069 }
3070
3071 $self->{top_paragraph} = $top_paragraph;
2826 }; 3072 };
2827 }); 3073 });
2828} 3074}
2829 3075
2830sub reconfigure { 3076sub reconfigure {
2848 $self->{children}[1]->draw; 3094 $self->{children}[1]->draw;
2849} 3095}
2850 3096
2851############################################################################# 3097#############################################################################
2852 3098
2853package CFClient::UI::Animator; 3099package CFPlus::UI::Animator;
2854 3100
2855use CFClient::OpenGL; 3101use CFPlus::OpenGL;
2856 3102
2857our @ISA = CFClient::UI::Bin::; 3103our @ISA = CFPlus::UI::Bin::;
2858 3104
2859sub moveto { 3105sub moveto {
2860 my ($self, $x, $y) = @_; 3106 my ($self, $x, $y) = @_;
2861 3107
2862 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 3108 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
2890 glPopMatrix; 3136 glPopMatrix;
2891} 3137}
2892 3138
2893############################################################################# 3139#############################################################################
2894 3140
2895package CFClient::UI::Flopper; 3141package CFPlus::UI::Flopper;
2896 3142
2897our @ISA = CFClient::UI::Button::; 3143our @ISA = CFPlus::UI::Button::;
2898 3144
2899sub new { 3145sub new {
2900 my $class = shift; 3146 my $class = shift;
2901 3147
2902 my $self = $class->SUPER::new ( 3148 my $self = $class->SUPER::new (
2914 $self->{other}->toggle_visibility; 3160 $self->{other}->toggle_visibility;
2915} 3161}
2916 3162
2917############################################################################# 3163#############################################################################
2918 3164
2919package CFClient::UI::Tooltip; 3165package CFPlus::UI::Tooltip;
2920 3166
2921our @ISA = CFClient::UI::Bin::; 3167our @ISA = CFPlus::UI::Bin::;
2922 3168
2923use CFClient::OpenGL; 3169use CFPlus::OpenGL;
2924 3170
2925sub new { 3171sub new {
2926 my $class = shift; 3172 my $class = shift;
2927 3173
2928 $class->SUPER::new ( 3174 $class->SUPER::new (
2931 ) 3177 )
2932} 3178}
2933 3179
2934sub set_tooltip_from { 3180sub set_tooltip_from {
2935 my ($self, $widget) = @_; 3181 my ($self, $widget) = @_;
3182
3183 $widget->{tooltip} = CFPlus::Pod::section_label tooltip => $1
3184 if $widget->{tooltip} =~ /^#(.*)$/;
2936 3185
2937 my $tooltip = $widget->{tooltip}; 3186 my $tooltip = $widget->{tooltip};
2938 3187
2939 if ($ENV{CFPLUS_DEBUG} & 2) { 3188 if ($ENV{CFPLUS_DEBUG} & 2) {
2940 $tooltip .= "\n\n" . (ref $widget) . "\n" 3189 $tooltip .= "\n\n" . (ref $widget) . "\n"
2944 } 3193 }
2945 3194
2946 $tooltip =~ s/^\n+//; 3195 $tooltip =~ s/^\n+//;
2947 $tooltip =~ s/\n+$//; 3196 $tooltip =~ s/\n+$//;
2948 3197
2949 $self->add (new CFClient::UI::Label 3198 $self->add (new CFPlus::UI::Label
2950 markup => $tooltip, 3199 markup => $tooltip,
2951 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 3200 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
2952 fontsize => 0.8, 3201 fontsize => 0.8,
2953 fg => [0, 0, 0, 1], 3202 style => 1, # FLAG_INVERSE
2954 ellipsise => 0, 3203 ellipsise => 0,
2955 font => ($widget->{tooltip_font} || $::FONT_PROP), 3204 font => ($widget->{tooltip_font} || $::FONT_PROP),
2956 ); 3205 );
2957} 3206}
2958 3207
2977 3226
2978 $self->{root}->on_post_alloc ("move_$self" => sub { 3227 $self->{root}->on_post_alloc ("move_$self" => sub {
2979 my $widget = $self->{owner} 3228 my $widget = $self->{owner}
2980 or return; 3229 or return;
2981 3230
3231 if ($widget->{visible}) {
2982 my ($x, $y) = $widget->coord2global ($widget->{w}, 0); 3232 my ($x, $y) = $widget->coord2global ($widget->{w}, 0);
2983 3233
2984 ($x, $y) = $widget->coord2global (-$self->{w}, 0) 3234 ($x, $y) = $widget->coord2global (-$self->{w}, 0)
2985 if $x + $self->{w} > $self->{root}{w}; 3235 if $x + $self->{w} > $self->{root}{w};
2986 3236
2987 $self->move_abs ($x, $y); 3237 $self->move_abs ($x, $y);
3238 } else {
3239 $self->hide;
3240 }
2988 }); 3241 });
2989} 3242}
2990 3243
2991sub _draw { 3244sub _draw {
2992 my ($self) = @_; 3245 my ($self) = @_;
3016 $self->SUPER::_draw; 3269 $self->SUPER::_draw;
3017} 3270}
3018 3271
3019############################################################################# 3272#############################################################################
3020 3273
3021package CFClient::UI::Face; 3274package CFPlus::UI::Face;
3022 3275
3023our @ISA = CFClient::UI::Base::; 3276our @ISA = CFPlus::UI::DrawBG::;
3024 3277
3025use CFClient::OpenGL; 3278use CFPlus::OpenGL;
3026 3279
3027sub new { 3280sub new {
3028 my $class = shift; 3281 my $class = shift;
3029 3282
3030 my $self = $class->SUPER::new ( 3283 my $self = $class->SUPER::new (
3032 can_events => 0, 3285 can_events => 0,
3033 @_, 3286 @_,
3034 ); 3287 );
3035 3288
3036 if ($self->{anim} && $self->{animspeed}) { 3289 if ($self->{anim} && $self->{animspeed}) {
3037 Scalar::Util::weaken (my $widget = $self); 3290 CFPlus::weaken (my $widget = $self);
3038 3291
3039 $self->{timer} = Event->timer ( 3292 $self->{timer} = Event->timer (
3040 at => $self->{animspeed} * int $::NOW / $self->{animspeed}, 3293 at => $self->{animspeed} * int $::NOW / $self->{animspeed},
3041 hard => 1, 3294 hard => 1,
3042 interval => $self->{animspeed}, 3295 interval => $self->{animspeed},
3065sub _draw { 3318sub _draw {
3066 my ($self) = @_; 3319 my ($self) = @_;
3067 3320
3068 return unless $::CONN; 3321 return unless $::CONN;
3069 3322
3323 $self->SUPER::_draw;
3324
3070 my $face; 3325 my $face;
3071 3326
3072 if ($self->{frame}) { 3327 if ($self->{frame}) {
3073 my $anim = $::CONN->{anim}[$self->{anim}]; 3328 my $anim = $::CONN->{anim}[$self->{anim}];
3074 3329
3096 $self->SUPER::destroy; 3351 $self->SUPER::destroy;
3097} 3352}
3098 3353
3099############################################################################# 3354#############################################################################
3100 3355
3101package CFClient::UI::Buttonbar; 3356package CFPlus::UI::Buttonbar;
3102 3357
3103our @ISA = CFClient::UI::HBox::; 3358our @ISA = CFPlus::UI::HBox::;
3104 3359
3105# TODO: should actualyl wrap buttons and other goodies. 3360# TODO: should actually wrap buttons and other goodies.
3106 3361
3107############################################################################# 3362#############################################################################
3108 3363
3109package CFClient::UI::Menu; 3364package CFPlus::UI::Menu;
3110 3365
3111our @ISA = CFClient::UI::FancyFrame::; 3366our @ISA = CFPlus::UI::Toplevel::;
3112 3367
3113use CFClient::OpenGL; 3368use CFPlus::OpenGL;
3114 3369
3115sub new { 3370sub new {
3116 my $class = shift; 3371 my $class = shift;
3117 3372
3118 my $self = $class->SUPER::new ( 3373 my $self = $class->SUPER::new (
3119 items => [], 3374 items => [],
3120 z => 100, 3375 z => 100,
3121 @_, 3376 @_,
3122 ); 3377 );
3123 3378
3124 $self->add ($self->{vbox} = new CFClient::UI::VBox); 3379 $self->add ($self->{vbox} = new CFPlus::UI::VBox);
3125 3380
3126 for my $item (@{ $self->{items} }) { 3381 for my $item (@{ $self->{items} }) {
3127 my ($widget, $cb, $tooltip) = @$item; 3382 my ($widget, $cb, $tooltip) = @$item;
3128 3383
3129 # handle various types of items, only text for now 3384 # handle various types of items, only text for now
3130 if (!ref $widget) { 3385 if (!ref $widget) {
3131 if ($widget =~ /\t/) { 3386 if ($widget =~ /\t/) {
3132 my ($left, $right) = split /\t/, $widget, 2; 3387 my ($left, $right) = split /\t/, $widget, 2;
3133 3388
3134 $widget = new CFClient::UI::HBox 3389 $widget = new CFPlus::UI::HBox
3135 can_hover => 1, 3390 can_hover => 1,
3136 can_events => 1, 3391 can_events => 1,
3137 tooltip => $tooltip, 3392 tooltip => $tooltip,
3138 children => [ 3393 children => [
3139 (new CFClient::UI::Label markup => $left, expand => 1), 3394 (new CFPlus::UI::Label markup => $left, expand => 1),
3140 (new CFClient::UI::Label markup => $right, align => +1), 3395 (new CFPlus::UI::Label markup => $right, align => +1),
3141 ], 3396 ],
3142 ; 3397 ;
3143 3398
3144 } else { 3399 } else {
3145 $widget = new CFClient::UI::Label 3400 $widget = new CFPlus::UI::Label
3146 can_hover => 1, 3401 can_hover => 1,
3147 can_events => 1, 3402 can_events => 1,
3148 markup => $widget, 3403 markup => $widget,
3149 tooltip => $tooltip; 3404 tooltip => $tooltip;
3150 } 3405 }
3198 1 3453 1
3199} 3454}
3200 3455
3201############################################################################# 3456#############################################################################
3202 3457
3203package CFClient::UI::Multiplexer; 3458package CFPlus::UI::Multiplexer;
3204 3459
3205our @ISA = CFClient::UI::Container::; 3460our @ISA = CFPlus::UI::Container::;
3206 3461
3207sub new { 3462sub new {
3208 my $class = shift; 3463 my $class = shift;
3209 3464
3210 my $self = $class->SUPER::new ( 3465 my $self = $class->SUPER::new (
3271 $self->{current}->draw; 3526 $self->{current}->draw;
3272} 3527}
3273 3528
3274############################################################################# 3529#############################################################################
3275 3530
3276package CFClient::UI::Notebook; 3531package CFPlus::UI::Notebook;
3277 3532
3278our @ISA = CFClient::UI::VBox::; 3533our @ISA = CFPlus::UI::VBox::;
3279 3534
3280sub new { 3535sub new {
3281 my $class = shift; 3536 my $class = shift;
3282 3537
3283 my $self = $class->SUPER::new ( 3538 my $self = $class->SUPER::new (
3284 buttonbar => (new CFClient::UI::Buttonbar), 3539 buttonbar => (new CFPlus::UI::Buttonbar),
3285 multiplexer => (new CFClient::UI::Multiplexer expand => 1), 3540 multiplexer => (new CFPlus::UI::Multiplexer expand => 1),
3286 # filter => # will be put between multiplexer and $self 3541 # filter => # will be put between multiplexer and $self
3287 @_, 3542 @_,
3288 ); 3543 );
3289 3544
3290 $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; 3545 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
3294} 3549}
3295 3550
3296sub add { 3551sub add {
3297 my ($self, $title, $widget, $tooltip) = @_; 3552 my ($self, $title, $widget, $tooltip) = @_;
3298 3553
3299 Scalar::Util::weaken $self; 3554 CFPlus::weaken $self;
3300 3555
3301 $self->{buttonbar}->add (new CFClient::UI::Button 3556 $self->{buttonbar}->add (new CFPlus::UI::Button
3302 markup => $title, 3557 markup => $title,
3303 tooltip => $tooltip, 3558 tooltip => $tooltip,
3304 on_activate => sub { $self->set_current_page ($widget) }, 3559 on_activate => sub { $self->set_current_page ($widget) },
3305 ); 3560 );
3306 3561
3320 $self->emit (page_changed => $self->{multiplexer}{current}); 3575 $self->emit (page_changed => $self->{multiplexer}{current});
3321} 3576}
3322 3577
3323############################################################################# 3578#############################################################################
3324 3579
3325package CFClient::UI::Combobox; 3580package CFPlus::UI::Selector;
3326 3581
3327use utf8; 3582use utf8;
3328 3583
3329our @ISA = CFClient::UI::Button::; 3584our @ISA = CFPlus::UI::Button::;
3330 3585
3331sub new { 3586sub new {
3332 my $class = shift; 3587 my $class = shift;
3333 3588
3334 my $self = $class->SUPER::new ( 3589 my $self = $class->SUPER::new (
3351 my ($value, $title, $tooltip) = @$_; 3606 my ($value, $title, $tooltip) = @$_;
3352 3607
3353 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }]; 3608 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }];
3354 } 3609 }
3355 3610
3356 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); 3611 CFPlus::UI::Menu->new (items => \@menu_items)->popup ($ev);
3357} 3612}
3358 3613
3359sub _set_value { 3614sub _set_value {
3360 my ($self, $value) = @_; 3615 my ($self, $value) = @_;
3361 3616
3376 $self->emit (changed => $value); 3631 $self->emit (changed => $value);
3377} 3632}
3378 3633
3379############################################################################# 3634#############################################################################
3380 3635
3381package CFClient::UI::Statusbox; 3636package CFPlus::UI::Statusbox;
3382 3637
3383our @ISA = CFClient::UI::VBox::; 3638our @ISA = CFPlus::UI::VBox::;
3384 3639
3385sub new { 3640sub new {
3386 my $class = shift; 3641 my $class = shift;
3387 3642
3388 my $self = $class->SUPER::new ( 3643 my $self = $class->SUPER::new (
3389 fontsize => 0.8, 3644 fontsize => 0.8,
3390 @_, 3645 @_,
3391 ); 3646 );
3392 3647
3393 Scalar::Util::weaken (my $this = $self); 3648 CFPlus::weaken (my $this = $self);
3394 3649
3395 $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 });
3396 3651
3397 $self 3652 $self
3398} 3653}
3400sub reorder { 3655sub reorder {
3401 my ($self) = @_; 3656 my ($self) = @_;
3402 my $NOW = Time::HiRes::time; 3657 my $NOW = Time::HiRes::time;
3403 3658
3404 # freeze display when hovering over any label 3659 # freeze display when hovering over any label
3405 return if $CFClient::UI::TOOLTIP->{owner} 3660 return if $CFPlus::UI::TOOLTIP->{owner}
3406 && grep $CFClient::UI::TOOLTIP->{owner} == $_->{label}, 3661 && grep $CFPlus::UI::TOOLTIP->{owner} == $_->{label},
3407 values %{ $self->{item} }; 3662 values %{ $self->{item} };
3408 3663
3409 while (my ($k, $v) = each %{ $self->{item} }) { 3664 while (my ($k, $v) = each %{ $self->{item} }) {
3410 delete $self->{item}{$k} if $v->{timeout} < $NOW; 3665 delete $self->{item}{$k} if $v->{timeout} < $NOW;
3411 } 3666 }
3432 for ($short) { 3687 for ($short) {
3433 s/^\s+//; 3688 s/^\s+//;
3434 s/\s+/ /g; 3689 s/\s+/ /g;
3435 } 3690 }
3436 3691
3437 new CFClient::UI::Label 3692 new CFPlus::UI::Label
3438 markup => $short, 3693 markup => $short,
3439 tooltip => $item->{tooltip}, 3694 tooltip => $item->{tooltip},
3440 tooltip_font => $::FONT_PROP, 3695 tooltip_font => $::FONT_PROP,
3441 tooltip_width => 0.67, 3696 tooltip_width => 0.67,
3442 fontsize => $item->{fontsize} || $self->{fontsize}, 3697 fontsize => $item->{fontsize} || $self->{fontsize},
3521 $self->SUPER::destroy; 3776 $self->SUPER::destroy;
3522} 3777}
3523 3778
3524############################################################################# 3779#############################################################################
3525 3780
3526package CFClient::UI::Inventory;
3527
3528our @ISA = CFClient::UI::Table::;
3529
3530sub new {
3531 my $class = shift;
3532
3533 my $self = $class->SUPER::new (
3534 col_expand => [0, 1, 0],
3535 @_,
3536 );
3537
3538 $self
3539}
3540
3541sub set_items {
3542 my ($self, $items) = @_;
3543
3544 $self->clear;
3545 return unless $items;
3546
3547 my @items = sort {
3548 ($a->{type} <=> $b->{type})
3549 or ($a->{name} cmp $b->{name})
3550 } values %$items;
3551
3552 $self->{real_items} = \@items;
3553
3554 my $row = 0;
3555 for my $item (@items) {
3556 CFClient::Item::update_widgets $item;
3557
3558 $self->add (0, $row, $item->{face_widget});
3559 $self->add (1, $row, $item->{desc_widget});
3560 $self->add (2, $row, $item->{weight_widget});
3561
3562 $row++;
3563 }
3564}
3565
3566#############################################################################
3567
3568package CFClient::UI::SpellList;
3569
3570our @ISA = CFClient::UI::Table::;
3571
3572sub new {
3573 my $class = shift;
3574
3575 my $self = $class->SUPER::new (
3576 binding => [],
3577 commands => [],
3578 @_,
3579 )
3580}
3581
3582my $TOOLTIP_ALL = "\n\n<small>Left click - ready spell\nMiddle click - invoke spell\nRight click - further options</small>";
3583
3584my @TOOLTIP_NAME = (align => -1, can_events => 1, can_hover => 1, tooltip =>
3585 "<b>Name</b>. The name of the spell.$TOOLTIP_ALL");
3586my @TOOLTIP_SKILL = (align => -1, can_events => 1, can_hover => 1, tooltip =>
3587 "<b>Skill</b>. The skill (or magic school) required to be able to attempt casting this spell.$TOOLTIP_ALL");
3588my @TOOLTIP_LVL = (align => 1, can_events => 1, can_hover => 1, tooltip =>
3589 "<b>Level</b>. Minimum level the caster needs in the associated skill to be able to attempt casting this spell.$TOOLTIP_ALL");
3590my @TOOLTIP_SP = (align => 1, can_events => 1, can_hover => 1, tooltip =>
3591 "<b>Spell points / Grace points</b>. Amount of spell or grace points used by each invocation.$TOOLTIP_ALL");
3592my @TOOLTIP_DMG = (align => 1, can_events => 1, can_hover => 1, tooltip =>
3593 "<b>Damage</b>. The amount of damage the spell deals when it hits.$TOOLTIP_ALL");
3594
3595sub rebuild_spell_list {
3596 my ($self) = @_;
3597
3598 $CFClient::UI::ROOT->on_refresh ($self => sub {
3599 $self->clear;
3600
3601 return unless $::CONN;
3602
3603 $self->add (1, 0, new CFClient::UI::Label text => "Spell Name", @TOOLTIP_NAME);
3604 $self->add (2, 0, new CFClient::UI::Label text => "Skill", @TOOLTIP_SKILL);
3605 $self->add (3, 0, new CFClient::UI::Label text => "Lvl" , @TOOLTIP_LVL);
3606 $self->add (4, 0, new CFClient::UI::Label text => "Sp/Gp", @TOOLTIP_SP);
3607 $self->add (5, 0, new CFClient::UI::Label text => "Dmg" , @TOOLTIP_DMG);
3608
3609 my $row = 0;
3610
3611 for (sort { $a cmp $b } keys %{ $self->{spell} }) {
3612 my $spell = $self->{spell}{$_};
3613
3614 $row++;
3615
3616 my $spell_cb = sub {
3617 my ($widget, $ev) = @_;
3618
3619 if ($ev->{button} == 1) {
3620 $::CONN->user_send ("cast $spell->{name}");
3621 } elsif ($ev->{button} == 2) {
3622 $::CONN->user_send ("invoke $spell->{name}");
3623 } elsif ($ev->{button} == 3) {
3624 (new CFClient::UI::Menu
3625 items => [
3626 ["bind <i>cast $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }],
3627 ["bind <i>invoke $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["invoke $spell->{name}"]) }],
3628 ],
3629 )->popup ($ev);
3630 } else {
3631 return 0;
3632 }
3633
3634 1
3635 };
3636
3637 my $tooltip = "$spell->{message}$TOOLTIP_ALL";
3638
3639 #TODO: add path info to tooltip
3640 #$self->add (6, $row, new CFClient::UI::Label text => $spell->{path});
3641
3642 $self->add (0, $row, new CFClient::UI::Face
3643 face => $spell->{face},
3644 can_hover => 1,
3645 can_events => 1,
3646 tooltip => $tooltip,
3647 on_button_down => $spell_cb,
3648 );
3649
3650 $self->add (1, $row, new CFClient::UI::Label
3651 expand => 1,
3652 text => $spell->{name},
3653 can_hover => 1,
3654 can_events => 1,
3655 tooltip => $tooltip,
3656 on_button_down => $spell_cb,
3657 );
3658
3659 $self->add (2, $row, new CFClient::UI::Label text => $::CONN->{skill_info}{$spell->{skill}}, @TOOLTIP_SKILL);
3660 $self->add (3, $row, new CFClient::UI::Label text => $spell->{level}, @TOOLTIP_LVL);
3661 $self->add (4, $row, new CFClient::UI::Label text => $spell->{mana} || $spell->{grace}, @TOOLTIP_SP);
3662 $self->add (5, $row, new CFClient::UI::Label text => $spell->{damage}, @TOOLTIP_DMG);
3663 }
3664 });
3665}
3666
3667sub add_spell {
3668 my ($self, $spell) = @_;
3669
3670 $self->{spell}->{$spell->{name}} = $spell;
3671 $self->rebuild_spell_list;
3672}
3673
3674sub remove_spell {
3675 my ($self, $spell) = @_;
3676
3677 delete $self->{spell}->{$spell->{name}};
3678 $self->rebuild_spell_list;
3679}
3680
3681sub clear_spells {
3682 my ($self) = @_;
3683
3684 $self->{spell} = {};
3685 $self->rebuild_spell_list;
3686}
3687
3688#############################################################################
3689
3690package CFClient::UI::Root; 3781package CFPlus::UI::Root;
3691 3782
3692our @ISA = CFClient::UI::Container::; 3783our @ISA = CFPlus::UI::Container::;
3693 3784
3694use List::Util qw(min max); 3785use List::Util qw(min max);
3695 3786
3696use CFClient::OpenGL; 3787use CFPlus::OpenGL;
3697 3788
3698sub new { 3789sub new {
3699 my $class = shift; 3790 my $class = shift;
3700 3791
3701 my $self = $class->SUPER::new ( 3792 my $self = $class->SUPER::new (
3702 visible => 1, 3793 visible => 1,
3703 @_, 3794 @_,
3704 ); 3795 );
3705 3796
3706 Scalar::Util::weaken ($self->{root} = $self); 3797 CFPlus::weaken ($self->{root} = $self);
3707 3798
3708 $self 3799 $self
3709} 3800}
3710 3801
3711sub size_request { 3802sub size_request {
3880 $h = 0 if $h < 0; 3971 $h = 0 if $h < 0;
3881 3972
3882 $w = max $widget->{min_w}, $w; 3973 $w = max $widget->{min_w}, $w;
3883 $h = max $widget->{min_h}, $h; 3974 $h = max $widget->{min_h}, $h;
3884 3975
3976# $w = min $self->{w} - $widget->{x}, $w if $self->{w};
3977# $h = min $self->{h} - $widget->{y}, $h if $self->{h};
3978
3885 $w = min $widget->{max_w}, $w if exists $widget->{max_w}; 3979 $w = min $widget->{max_w}, $w if exists $widget->{max_w};
3886 $h = min $widget->{max_h}, $h if exists $widget->{max_h}; 3980 $h = min $widget->{max_h}, $h if exists $widget->{max_h};
3887 3981
3888 $w = int $w + 0.5; 3982 $w = int $w + 0.5;
3889 $h = int $h + 0.5; 3983 $h = int $h + 0.5;
3915 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; 4009 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
3916 glMatrixMode GL_MODELVIEW; 4010 glMatrixMode GL_MODELVIEW;
3917 glLoadIdentity; 4011 glLoadIdentity;
3918 4012
3919 { 4013 {
3920 package CFClient::UI::Base; 4014 package CFPlus::UI::Base;
3921 4015
3922 ($draw_x, $draw_y, $draw_w, $draw_h) = 4016 local ($draw_x, $draw_y, $draw_w, $draw_h) =
3923 (0, 0, $self->{w}, $self->{h}); 4017 (0, 0, $self->{w}, $self->{h});
3924 }
3925 4018
3926 $self->_draw; 4019 $self->_draw;
4020 }
3927} 4021}
3928 4022
3929############################################################################# 4023#############################################################################
3930 4024
3931package CFClient::UI; 4025package CFPlus::UI;
3932 4026
3933$ROOT = new CFClient::UI::Root; 4027$ROOT = new CFPlus::UI::Root;
3934$TOOLTIP = new CFClient::UI::Tooltip z => 900; 4028$TOOLTIP = new CFPlus::UI::Tooltip z => 900;
3935 4029
39361 40301
3937 4031

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines