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.362 by root, Sat Dec 9 21:26:46 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) {
1839 $self->{cursor} = 0; 1981 $self->{cursor} = 0;
1840 } elsif ($sym == CFClient::SDLK_END) { 1982 } elsif ($sym == CFPlus::SDLK_END) {
1841 $self->{cursor} = length $text; 1983 $self->{cursor} = length $text;
1984 } elsif ($uni == 21) { # ctrl-u
1985 $text = "";
1986 $self->{cursor} = 0;
1842 } elsif ($uni == 27) { 1987 } elsif ($uni == 27) {
1843 $self->emit ('escape'); 1988 $self->emit ('escape');
1844 } elsif ($uni) { 1989 } elsif ($uni >= 0x20 || $uni == 0x0d) {
1845 substr $text, $self->{cursor}++, 0, chr $uni; 1990 substr $text, $self->{cursor}++, 0, chr $uni;
1846 } else { 1991 } else {
1847 return 0; 1992 return 0;
1848 } 1993 }
1849 1994
1850 $self->_set_text ($text); 1995 $self->_set_text ($text);
1851 1996
1852 $self->realloc; 1997 $self->realloc;
1998 $self->update;
1853 1999
1854 1 2000 1
1855} 2001}
1856 2002
1857sub invoke_focus_in { 2003sub invoke_focus_in {
1919 utf8::encode $text; 2065 utf8::encode $text;
1920 2066
1921 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text) 2067 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text)
1922 } 2068 }
1923 2069
1924 glColor @{$self->{fg}};
1925 glBegin GL_LINES; 2070 glBegin GL_LINES;
1926 glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; 2071 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}; 2072 glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h};
1928 glEnd; 2073 glEnd;
1929 } 2074 }
1930} 2075}
1931 2076
2077#############################################################################
2078
1932package CFClient::UI::Entry; 2079package CFPlus::UI::Entry;
1933 2080
1934our @ISA = CFClient::UI::EntryBase::; 2081our @ISA = CFPlus::UI::EntryBase::;
1935 2082
1936use CFClient::OpenGL; 2083use CFPlus::OpenGL;
1937 2084
1938sub invoke_key_down { 2085sub invoke_key_down {
1939 my ($self, $ev) = @_; 2086 my ($self, $ev) = @_;
1940 2087
1941 my $sym = $ev->{sym}; 2088 my $sym = $ev->{sym};
1942 2089
1943 if ($sym == 13) { 2090 if ($ev->{uni} == 0x0d || $sym == 13) {
1944 unshift @{$self->{history}}, 2091 unshift @{$self->{history}},
1945 my $txt = $self->get_text; 2092 my $txt = $self->get_text;
1946 2093
1947 $self->{history_pointer} = -1; 2094 $self->{history_pointer} = -1;
1948 $self->{history_saveback} = ''; 2095 $self->{history_saveback} = '';
1949 $self->emit (activate => $txt); 2096 $self->emit (activate => $txt);
1950 $self->update; 2097 $self->update;
1951 2098
1952 } elsif ($sym == CFClient::SDLK_UP) { 2099 } elsif ($sym == CFPlus::SDLK_UP) {
1953 if ($self->{history_pointer} < 0) { 2100 if ($self->{history_pointer} < 0) {
1954 $self->{history_saveback} = $self->get_text; 2101 $self->{history_saveback} = $self->get_text;
1955 } 2102 }
1956 if (@{$self->{history} || []} > 0) { 2103 if (@{$self->{history} || []} > 0) {
1957 $self->{history_pointer}++; 2104 $self->{history_pointer}++;
1959 $self->{history_pointer} = @{$self->{history} || []} - 1; 2106 $self->{history_pointer} = @{$self->{history} || []} - 1;
1960 } 2107 }
1961 $self->set_text ($self->{history}->[$self->{history_pointer}]); 2108 $self->set_text ($self->{history}->[$self->{history_pointer}]);
1962 } 2109 }
1963 2110
1964 } elsif ($sym == CFClient::SDLK_DOWN) { 2111 } elsif ($sym == CFPlus::SDLK_DOWN) {
1965 $self->{history_pointer}--; 2112 $self->{history_pointer}--;
1966 $self->{history_pointer} = -1 if $self->{history_pointer} < 0; 2113 $self->{history_pointer} = -1 if $self->{history_pointer} < 0;
1967 2114
1968 if ($self->{history_pointer} >= 0) { 2115 if ($self->{history_pointer} >= 0) {
1969 $self->set_text ($self->{history}->[$self->{history_pointer}]); 2116 $self->set_text ($self->{history}->[$self->{history_pointer}]);
1978 1 2125 1
1979} 2126}
1980 2127
1981############################################################################# 2128#############################################################################
1982 2129
2130package CFPlus::UI::TextEdit;
2131
2132our @ISA = CFPlus::UI::EntryBase::;
2133
2134use CFPlus::OpenGL;
2135
2136sub move_cursor_ver {
2137 my ($self, $dy) = @_;
2138
2139 my ($y, $x) = $self->{layout}->index_to_line_x ($self->{cursor});
2140
2141 $y += $dy;
2142
2143 if (defined (my $index = $self->{layout}->line_x_to_index ($y, $x))) {
2144 $self->{cursor} = $index;
2145 delete $self->{cur_h};
2146 $self->update;
2147 return;
2148 }
2149}
2150
2151sub invoke_key_down {
2152 my ($self, $ev) = @_;
2153
2154 my $sym = $ev->{sym};
2155
2156 if ($sym == CFPlus::SDLK_UP) {
2157 $self->move_cursor_ver (-1);
2158 } elsif ($sym == CFPlus::SDLK_DOWN) {
2159 $self->move_cursor_ver (+1);
2160 } else {
2161 return $self->SUPER::invoke_key_down ($ev)
2162 }
2163
2164 1
2165}
2166
2167#############################################################################
2168
1983package CFClient::UI::Button; 2169package CFPlus::UI::Button;
1984 2170
1985our @ISA = CFClient::UI::Label::; 2171our @ISA = CFPlus::UI::Label::;
1986 2172
1987use CFClient::OpenGL; 2173use CFPlus::OpenGL;
1988 2174
1989my @tex = 2175my @tex =
1990 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2176 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
1991 qw(b1_button_active.png); 2177 qw(b1_button_active.png);
1992 2178
1993sub new { 2179sub new {
1994 my $class = shift; 2180 my $class = shift;
1995 2181
2032 $self->SUPER::_draw; 2218 $self->SUPER::_draw;
2033} 2219}
2034 2220
2035############################################################################# 2221#############################################################################
2036 2222
2223package CFPlus::UI::CheckBox;
2224
2225our @ISA = CFPlus::UI::DrawBG::;
2226
2227my @tex =
2228 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2229 qw(c1_checkbox_bg.png c1_checkbox_active.png);
2230
2231use CFPlus::OpenGL;
2232
2233sub new {
2234 my $class = shift;
2235
2236 $class->SUPER::new (
2237 padding_x => 2,
2238 padding_y => 2,
2239 fg => [1, 1, 1],
2240 active_fg => [1, 1, 0],
2241 bg => [0, 0, 0, 0.2],
2242 active_bg => [1, 1, 1, 0.5],
2243 state => 0,
2244 can_hover => 1,
2245 @_
2246 )
2247}
2248
2249sub size_request {
2250 my ($self) = @_;
2251
2252 (6) x 2
2253}
2254
2255sub toggle {
2256 my ($self) = @_;
2257
2258 $self->{state} = !$self->{state};
2259 $self->emit (changed => $self->{state});
2260 $self->update;
2261}
2262
2263sub invoke_button_down {
2264 my ($self, $ev, $x, $y) = @_;
2265
2266 if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x}
2267 && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) {
2268 $self->toggle;
2269 } else {
2270 return 0
2271 }
2272
2273 1
2274}
2275
2276sub _draw {
2277 my ($self) = @_;
2278
2279 $self->SUPER::_draw;
2280
2281 glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0;
2282
2283 my ($w, $h) = @$self{qw(w h)};
2284
2285 my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2;
2286
2287 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} };
2288
2289 my $tex = $self->{state} ? $tex[1] : $tex[0];
2290
2291 glEnable GL_TEXTURE_2D;
2292 $tex->draw_quad_alpha (0, 0, $s, $s);
2293 glDisable GL_TEXTURE_2D;
2294}
2295
2296#############################################################################
2297
2298package CFPlus::UI::Image;
2299
2300our @ISA = CFPlus::UI::Base::;
2301
2302use CFPlus::OpenGL;
2303
2304our %texture_cache;
2305
2306sub new {
2307 my $class = shift;
2308
2309 my $self = $class->SUPER::new (
2310 can_events => 0,
2311 @_,
2312 );
2313
2314 $self->{path} || $self->{tex}
2315 or Carp::croak "'path' or 'tex' attributes required";
2316
2317 $self->{tex} ||= $texture_cache{$self->{path}} ||=
2318 new_from_file CFPlus::Texture CFPlus::find_rcfile $self->{path}, mipmap => 1;
2319
2320 CFPlus::weaken $texture_cache{$self->{path}};
2321
2322 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2323
2324 $self
2325}
2326
2327sub STORABLE_freeze {
2328 my ($self, $cloning) = @_;
2329
2330 $self->{path}
2331 or die "cannot serialise CFPlus::UI::Image on non-loadable images\n";
2332
2333 $self->{path}
2334}
2335
2336sub STORABLE_attach {
2337 my ($self, $cloning, $path) = @_;
2338
2339 $self->new (path => $path)
2340}
2341
2342sub size_request {
2343 my ($self) = @_;
2344
2345 ($self->{tex}{w}, $self->{tex}{h})
2346}
2347
2348sub _draw {
2349 my ($self) = @_;
2350
2351 my $tex = $self->{tex};
2352
2353 my ($w, $h) = ($self->{w}, $self->{h});
2354
2355 if ($self->{rot90}) {
2356 glRotate 90, 0, 0, 1;
2357 glTranslate 0, -$self->{w}, 0;
2358
2359 ($w, $h) = ($h, $w);
2360 }
2361
2362 glEnable GL_TEXTURE_2D;
2363 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2364
2365 $tex->draw_quad (0, 0, $w, $h);
2366
2367 glDisable GL_TEXTURE_2D;
2368}
2369
2370#############################################################################
2371
2037package CFClient::UI::ImageButton; 2372package CFPlus::UI::ImageButton;
2038 2373
2039our @ISA = CFClient::UI::Image::; 2374our @ISA = CFPlus::UI::Image::;
2040 2375
2041use CFClient::OpenGL; 2376use CFPlus::OpenGL;
2042 2377
2043my %textures; 2378my %textures;
2044 2379
2045sub new { 2380sub new {
2046 my $class = shift; 2381 my $class = shift;
2068 1 2403 1
2069} 2404}
2070 2405
2071############################################################################# 2406#############################################################################
2072 2407
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; 2408package CFPlus::UI::VGauge;
2149 2409
2150our @ISA = CFClient::UI::Base::; 2410our @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 2411
2211use List::Util qw(min max); 2412use List::Util qw(min max);
2212 2413
2213use CFClient::OpenGL; 2414use CFPlus::OpenGL;
2214 2415
2215my %tex = ( 2416my %tex = (
2216 food => [ 2417 food => [
2217 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2418 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2218 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 2419 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
2219 ], 2420 ],
2220 grace => [ 2421 grace => [
2221 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2422 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/ 2423 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/
2223 ], 2424 ],
2224 hp => [ 2425 hp => [
2225 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2426 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2226 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 2427 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
2227 ], 2428 ],
2228 mana => [ 2429 mana => [
2229 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 2430 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/ 2431 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/
2231 ], 2432 ],
2232); 2433);
2233 2434
2234# eg. VGauge->new (gauge => 'food'), default gauge: food 2435# eg. VGauge->new (gauge => 'food'), default gauge: food
2337 glDisable GL_TEXTURE_2D; 2538 glDisable GL_TEXTURE_2D;
2338} 2539}
2339 2540
2340############################################################################# 2541#############################################################################
2341 2542
2342package CFClient::UI::Gauge; 2543package CFPlus::UI::Gauge;
2343 2544
2344our @ISA = CFClient::UI::VBox::; 2545our @ISA = CFPlus::UI::VBox::;
2345 2546
2346sub new { 2547sub new {
2347 my ($class, %arg) = @_; 2548 my ($class, %arg) = @_;
2348 2549
2349 my $self = $class->SUPER::new ( 2550 my $self = $class->SUPER::new (
2351 can_hover => 1, 2552 can_hover => 1,
2352 can_events => 1, 2553 can_events => 1,
2353 %arg, 2554 %arg,
2354 ); 2555 );
2355 2556
2356 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); 2557 $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); 2558 $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"); 2559 $self->add ($self->{max} = new CFPlus::UI::Label valign => -1, align => 0, template => "999");
2359 2560
2360 $self 2561 $self
2361} 2562}
2362 2563
2363sub set_fontsize { 2564sub set_fontsize {
2384 $self->{value}->set_text ($val); 2585 $self->{value}->set_text ($val);
2385} 2586}
2386 2587
2387############################################################################# 2588#############################################################################
2388 2589
2389package CFClient::UI::Slider; 2590package CFPlus::UI::Slider;
2390 2591
2391use strict; 2592use strict;
2392 2593
2393use CFClient::OpenGL; 2594use CFPlus::OpenGL;
2394 2595
2395our @ISA = CFClient::UI::DrawBG::; 2596our @ISA = CFPlus::UI::DrawBG::;
2396 2597
2397my @tex = 2598my @tex =
2398 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 2599 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_ }
2399 qw(s1_slider.png s1_slider_bg.png); 2600 qw(s1_slider.png s1_slider_bg.png);
2400 2601
2401sub new { 2602sub new {
2402 my $class = shift; 2603 my $class = shift;
2403 2604
2497sub invoke_mouse_wheel { 2698sub invoke_mouse_wheel {
2498 my ($self, $ev) = @_; 2699 my ($self, $ev) = @_;
2499 2700
2500 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; 2701 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx};
2501 2702
2502 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * 0.1); 2703 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * 0.2);
2503 2704
2504 ! ! $delta 2705 ! ! $delta
2505} 2706}
2506 2707
2507sub update { 2708sub update {
2558 glDisable GL_TEXTURE_2D; 2759 glDisable GL_TEXTURE_2D;
2559} 2760}
2560 2761
2561############################################################################# 2762#############################################################################
2562 2763
2563package CFClient::UI::ValSlider; 2764package CFPlus::UI::ValSlider;
2564 2765
2565our @ISA = CFClient::UI::HBox::; 2766our @ISA = CFPlus::UI::HBox::;
2566 2767
2567sub new { 2768sub new {
2568 my ($class, %arg) = @_; 2769 my ($class, %arg) = @_;
2569 2770
2570 my $range = delete $arg{range}; 2771 my $range = delete $arg{range};
2571 2772
2572 my $self = $class->SUPER::new ( 2773 my $self = $class->SUPER::new (
2573 slider => (new CFClient::UI::Slider expand => 1, range => $range), 2774 slider => (new CFPlus::UI::Slider expand => 1, range => $range),
2574 entry => (new CFClient::UI::Label text => "", template => delete $arg{template}), 2775 entry => (new CFPlus::UI::Label text => "", template => delete $arg{template}),
2575 to_value => sub { shift }, 2776 to_value => sub { shift },
2576 from_value => sub { shift }, 2777 from_value => sub { shift },
2577 %arg, 2778 %arg,
2578 ); 2779 );
2579 2780
2599sub set_range { shift->{slider}->set_range (@_) } 2800sub set_range { shift->{slider}->set_range (@_) }
2600sub set_value { shift->{slider}->set_value (@_) } 2801sub set_value { shift->{slider}->set_value (@_) }
2601 2802
2602############################################################################# 2803#############################################################################
2603 2804
2604package CFClient::UI::TextScroller; 2805package CFPlus::UI::TextScroller;
2605 2806
2606our @ISA = CFClient::UI::HBox::; 2807our @ISA = CFPlus::UI::HBox::;
2607 2808
2608use CFClient::OpenGL; 2809use CFPlus::OpenGL;
2609 2810
2610sub new { 2811sub new {
2611 my $class = shift; 2812 my $class = shift;
2612 2813
2613 my $self = $class->SUPER::new ( 2814 my $self = $class->SUPER::new (
2615 can_events => 1, 2816 can_events => 1,
2616 indent => 0, 2817 indent => 0,
2617 #font => default_font 2818 #font => default_font
2618 @_, 2819 @_,
2619 2820
2620 layout => (new CFClient::Layout), 2821 layout => (new CFPlus::Layout),
2621 par => [], 2822 par => [],
2622 height => 0, 2823 height => 0,
2623 children => [ 2824 children => [
2624 (new CFClient::UI::Empty expand => 1), 2825 (new CFPlus::UI::Empty expand => 1),
2625 (new CFClient::UI::Slider vertical => 1), 2826 (new CFPlus::UI::Slider vertical => 1),
2626 ], 2827 ],
2627 ); 2828 );
2628 2829
2629 $self->{children}[1]->connect (changed => sub { $self->update }); 2830 $self->{children}[1]->connect (changed => sub { $self->update });
2630 2831
2707 2908
2708 # todo: base offset on lines or so, not on pixels 2909 # todo: base offset on lines or so, not on pixels
2709 $self->{children}[1]->set_value ($offset); 2910 $self->{children}[1]->set_value ($offset);
2710} 2911}
2711 2912
2913sub current_paragraph {
2914 my ($self) = @_;
2915
2916 $self->{top_paragraph} - 1
2917}
2918
2919sub scroll_to {
2920 my ($self, $para) = @_;
2921
2922 $para = List::Util::max 0, List::Util::min $#{$self->{par}}, $para;
2923
2924 $self->{scroll_to} = $para;
2925 $self->update;
2926}
2927
2712sub clear { 2928sub clear {
2713 my ($self) = @_; 2929 my ($self) = @_;
2714 2930
2715 my (undef, undef, @other) = @{ $self->{children} }; 2931 my (undef, undef, @other) = @{ $self->{children} };
2716 $self->remove ($_) for @other; 2932 $self->remove ($_) for @other;
2719 $self->{height} = 0; 2935 $self->{height} = 0;
2720 $self->{children}[1]->set_range ([0, 0, 0, 1, 1]); 2936 $self->{children}[1]->set_range ([0, 0, 0, 1, 1]);
2721} 2937}
2722 2938
2723sub add_paragraph { 2939sub add_paragraph {
2724 my ($self, $color, $para, $indent) = @_; 2940 my $self = shift;
2725 2941
2726 my ($text, @w) = ref $para ? @$para : $para; 2942 for my $para (@_) {
2727
2728 $para = { 2943 $para = {
2944 fg => [1, 1, 1, 1],
2945 indent => 0,
2946 markup => "",
2947 widget => [],
2948 ref $para ? %$para : (markup => $para),
2729 w => 1e10, 2949 w => 1e10,
2730 wrapped => 1, 2950 wrapped => 1,
2731 fg => $color,
2732 indent => $indent,
2733 markup => $text,
2734 widget => \@w,
2735 }; 2951 };
2736 2952
2737 $self->add (@w) if @w; 2953 $self->add (@{ $para->{widget} }) if @{ $para->{widget} };
2738 push @{$self->{par}}, $para; 2954 push @{$self->{par}}, $para;
2955 }
2739 2956
2740 $self->{need_reflow}++; 2957 $self->{need_reflow}++;
2741 $self->update; 2958 $self->update;
2742} 2959}
2743 2960
2744sub scroll_to_bottom { 2961sub scroll_to_bottom {
2745 my ($self) = @_; 2962 my ($self) = @_;
2746 2963
2747 $self->{scroll_to_bottom} = 1; 2964 $self->{scroll_to} = $#{$self->{par}};
2748 $self->update; 2965 $self->update;
2749} 2966}
2750 2967
2968sub force_uptodate {
2969 my ($self) = @_;
2970
2971 if (delete $self->{need_reflow}) {
2972 my ($W, $H) = @{$self->{children}[0]}{qw(w h)};
2973
2974 my $height = 0;
2975
2976 for my $para (@{$self->{par}}) {
2977 if ($para->{w} != $W && ($para->{wrapped} || $para->{w} > $W)) {
2978 my $layout = $self->get_layout ($para);
2979 my ($w, $h) = $layout->size;
2980
2981 $para->{w} = $w + $para->{indent};
2982 $para->{h} = $h;
2983 $para->{wrapped} = $layout->has_wrapped;
2984 }
2985
2986 $para->{y} = $height;
2987 $height += $para->{h};
2988 }
2989
2990 $self->{height} = $height;
2991 $self->{children}[1]->set_range ([$self->{children}[1]{range}[0], 0, $height, $H, 1]);
2992
2993 delete $self->{texture};
2994 }
2995
2996 if (my $paridx = delete $self->{scroll_to}) {
2997 $self->{children}[1]->set_value ($self->{par}[$paridx]{y});
2998 }
2999}
3000
2751sub update { 3001sub update {
2752 my ($self) = @_; 3002 my ($self) = @_;
2753 3003
2754 $self->SUPER::update; 3004 $self->SUPER::update;
2755 3005
2756 return unless $self->{h} > 0; 3006 return unless $self->{h} > 0;
2757 3007
2758 delete $self->{texture}; 3008 delete $self->{texture};
2759 3009
2760 $ROOT->on_post_alloc ($self => sub { 3010 $ROOT->on_post_alloc ($self => sub {
3011 $self->force_uptodate;
3012
2761 my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; 3013 my ($W, $H) = @{$self->{children}[0]}{qw(w h)};
2762 3014
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 { 3015 $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub {
2791 glClearColor 0, 0, 0, 0; 3016 glClearColor 0, 0, 0, 0;
2792 glClear GL_COLOR_BUFFER_BIT; 3017 glClear GL_COLOR_BUFFER_BIT;
2793 3018
3019 package CFPlus::UI::Base;
3020 local ($draw_x, $draw_y, $draw_w, $draw_h) =
3021 (0, 0, $self->{w}, $self->{h});
3022
3023 my $top = int $self->{children}[1]{range}[0];
3024
3025 my $paridx = 0;
3026 my $top_paragraph;
2794 my $top = int $self->{children}[1]{range}[0]; 3027 my $top = int $self->{children}[1]{range}[0];
2795 3028
2796 my $y0 = $top; 3029 my $y0 = $top;
2797 my $y1 = $top + $H; 3030 my $y1 = $top + $H;
2798 3031
2799 my $y = 0;
2800
2801 for my $para (@{$self->{par}}) { 3032 for my $para (@{$self->{par}}) {
2802 my $h = $para->{h}; 3033 my $h = $para->{h};
3034 my $y = $para->{y};
2803 3035
2804 if ($y0 < $y + $h && $y < $y1) { 3036 if ($y0 < $y + $h && $y < $y1) {
2805
2806 my $layout = $self->get_layout ($para); 3037 my $layout = $self->get_layout ($para);
2807 3038
2808 $layout->render ($para->{indent}, $y - $y0); 3039 $layout->render ($para->{indent}, $y - $y0);
2809 3040
2810 if (my @w = @{ $para->{widget} }) { 3041 if (my @w = @{ $para->{widget} }) {
2819 $_->draw; 3050 $_->draw;
2820 } 3051 }
2821 } 3052 }
2822 } 3053 }
2823 3054
2824 $y += $h; 3055 $paridx++;
3056 $top_paragraph ||= $paridx if $y >= $top;
2825 } 3057 }
3058
3059 $self->{top_paragraph} = $top_paragraph;
2826 }; 3060 };
2827 }); 3061 });
2828} 3062}
2829 3063
2830sub reconfigure { 3064sub reconfigure {
2848 $self->{children}[1]->draw; 3082 $self->{children}[1]->draw;
2849} 3083}
2850 3084
2851############################################################################# 3085#############################################################################
2852 3086
2853package CFClient::UI::Animator; 3087package CFPlus::UI::Animator;
2854 3088
2855use CFClient::OpenGL; 3089use CFPlus::OpenGL;
2856 3090
2857our @ISA = CFClient::UI::Bin::; 3091our @ISA = CFPlus::UI::Bin::;
2858 3092
2859sub moveto { 3093sub moveto {
2860 my ($self, $x, $y) = @_; 3094 my ($self, $x, $y) = @_;
2861 3095
2862 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 3096 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
2890 glPopMatrix; 3124 glPopMatrix;
2891} 3125}
2892 3126
2893############################################################################# 3127#############################################################################
2894 3128
2895package CFClient::UI::Flopper; 3129package CFPlus::UI::Flopper;
2896 3130
2897our @ISA = CFClient::UI::Button::; 3131our @ISA = CFPlus::UI::Button::;
2898 3132
2899sub new { 3133sub new {
2900 my $class = shift; 3134 my $class = shift;
2901 3135
2902 my $self = $class->SUPER::new ( 3136 my $self = $class->SUPER::new (
2914 $self->{other}->toggle_visibility; 3148 $self->{other}->toggle_visibility;
2915} 3149}
2916 3150
2917############################################################################# 3151#############################################################################
2918 3152
2919package CFClient::UI::Tooltip; 3153package CFPlus::UI::Tooltip;
2920 3154
2921our @ISA = CFClient::UI::Bin::; 3155our @ISA = CFPlus::UI::Bin::;
2922 3156
2923use CFClient::OpenGL; 3157use CFPlus::OpenGL;
2924 3158
2925sub new { 3159sub new {
2926 my $class = shift; 3160 my $class = shift;
2927 3161
2928 $class->SUPER::new ( 3162 $class->SUPER::new (
2931 ) 3165 )
2932} 3166}
2933 3167
2934sub set_tooltip_from { 3168sub set_tooltip_from {
2935 my ($self, $widget) = @_; 3169 my ($self, $widget) = @_;
3170
3171 $widget->{tooltip} = CFPlus::Pod::section_label tooltip => $1
3172 if $widget->{tooltip} =~ /^#(.*)$/;
2936 3173
2937 my $tooltip = $widget->{tooltip}; 3174 my $tooltip = $widget->{tooltip};
2938 3175
2939 if ($ENV{CFPLUS_DEBUG} & 2) { 3176 if ($ENV{CFPLUS_DEBUG} & 2) {
2940 $tooltip .= "\n\n" . (ref $widget) . "\n" 3177 $tooltip .= "\n\n" . (ref $widget) . "\n"
2944 } 3181 }
2945 3182
2946 $tooltip =~ s/^\n+//; 3183 $tooltip =~ s/^\n+//;
2947 $tooltip =~ s/\n+$//; 3184 $tooltip =~ s/\n+$//;
2948 3185
2949 $self->add (new CFClient::UI::Label 3186 $self->add (new CFPlus::UI::Label
2950 markup => $tooltip, 3187 markup => $tooltip,
2951 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 3188 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
2952 fontsize => 0.8, 3189 fontsize => 0.8,
2953 fg => [0, 0, 0, 1], 3190 style => 1, # FLAG_INVERSE
2954 ellipsise => 0, 3191 ellipsise => 0,
2955 font => ($widget->{tooltip_font} || $::FONT_PROP), 3192 font => ($widget->{tooltip_font} || $::FONT_PROP),
2956 ); 3193 );
2957} 3194}
2958 3195
2977 3214
2978 $self->{root}->on_post_alloc ("move_$self" => sub { 3215 $self->{root}->on_post_alloc ("move_$self" => sub {
2979 my $widget = $self->{owner} 3216 my $widget = $self->{owner}
2980 or return; 3217 or return;
2981 3218
3219 if ($widget->{visible}) {
2982 my ($x, $y) = $widget->coord2global ($widget->{w}, 0); 3220 my ($x, $y) = $widget->coord2global ($widget->{w}, 0);
2983 3221
2984 ($x, $y) = $widget->coord2global (-$self->{w}, 0) 3222 ($x, $y) = $widget->coord2global (-$self->{w}, 0)
2985 if $x + $self->{w} > $self->{root}{w}; 3223 if $x + $self->{w} > $self->{root}{w};
2986 3224
2987 $self->move_abs ($x, $y); 3225 $self->move_abs ($x, $y);
3226 } else {
3227 $self->hide;
3228 }
2988 }); 3229 });
2989} 3230}
2990 3231
2991sub _draw { 3232sub _draw {
2992 my ($self) = @_; 3233 my ($self) = @_;
3016 $self->SUPER::_draw; 3257 $self->SUPER::_draw;
3017} 3258}
3018 3259
3019############################################################################# 3260#############################################################################
3020 3261
3021package CFClient::UI::Face; 3262package CFPlus::UI::Face;
3022 3263
3023our @ISA = CFClient::UI::Base::; 3264our @ISA = CFPlus::UI::DrawBG::;
3024 3265
3025use CFClient::OpenGL; 3266use CFPlus::OpenGL;
3026 3267
3027sub new { 3268sub new {
3028 my $class = shift; 3269 my $class = shift;
3029 3270
3030 my $self = $class->SUPER::new ( 3271 my $self = $class->SUPER::new (
3032 can_events => 0, 3273 can_events => 0,
3033 @_, 3274 @_,
3034 ); 3275 );
3035 3276
3036 if ($self->{anim} && $self->{animspeed}) { 3277 if ($self->{anim} && $self->{animspeed}) {
3037 Scalar::Util::weaken (my $widget = $self); 3278 CFPlus::weaken (my $widget = $self);
3038 3279
3039 $self->{timer} = Event->timer ( 3280 $self->{timer} = Event->timer (
3040 at => $self->{animspeed} * int $::NOW / $self->{animspeed}, 3281 at => $self->{animspeed} * int $::NOW / $self->{animspeed},
3041 hard => 1, 3282 hard => 1,
3042 interval => $self->{animspeed}, 3283 interval => $self->{animspeed},
3065sub _draw { 3306sub _draw {
3066 my ($self) = @_; 3307 my ($self) = @_;
3067 3308
3068 return unless $::CONN; 3309 return unless $::CONN;
3069 3310
3311 $self->SUPER::_draw;
3312
3070 my $face; 3313 my $face;
3071 3314
3072 if ($self->{frame}) { 3315 if ($self->{frame}) {
3073 my $anim = $::CONN->{anim}[$self->{anim}]; 3316 my $anim = $::CONN->{anim}[$self->{anim}];
3074 3317
3096 $self->SUPER::destroy; 3339 $self->SUPER::destroy;
3097} 3340}
3098 3341
3099############################################################################# 3342#############################################################################
3100 3343
3101package CFClient::UI::Buttonbar; 3344package CFPlus::UI::Buttonbar;
3102 3345
3103our @ISA = CFClient::UI::HBox::; 3346our @ISA = CFPlus::UI::HBox::;
3104 3347
3105# TODO: should actualyl wrap buttons and other goodies. 3348# TODO: should actually wrap buttons and other goodies.
3106 3349
3107############################################################################# 3350#############################################################################
3108 3351
3109package CFClient::UI::Menu; 3352package CFPlus::UI::Menu;
3110 3353
3111our @ISA = CFClient::UI::FancyFrame::; 3354our @ISA = CFPlus::UI::Toplevel::;
3112 3355
3113use CFClient::OpenGL; 3356use CFPlus::OpenGL;
3114 3357
3115sub new { 3358sub new {
3116 my $class = shift; 3359 my $class = shift;
3117 3360
3118 my $self = $class->SUPER::new ( 3361 my $self = $class->SUPER::new (
3119 items => [], 3362 items => [],
3120 z => 100, 3363 z => 100,
3121 @_, 3364 @_,
3122 ); 3365 );
3123 3366
3124 $self->add ($self->{vbox} = new CFClient::UI::VBox); 3367 $self->add ($self->{vbox} = new CFPlus::UI::VBox);
3125 3368
3126 for my $item (@{ $self->{items} }) { 3369 for my $item (@{ $self->{items} }) {
3127 my ($widget, $cb, $tooltip) = @$item; 3370 my ($widget, $cb, $tooltip) = @$item;
3128 3371
3129 # handle various types of items, only text for now 3372 # handle various types of items, only text for now
3130 if (!ref $widget) { 3373 if (!ref $widget) {
3131 if ($widget =~ /\t/) { 3374 if ($widget =~ /\t/) {
3132 my ($left, $right) = split /\t/, $widget, 2; 3375 my ($left, $right) = split /\t/, $widget, 2;
3133 3376
3134 $widget = new CFClient::UI::HBox 3377 $widget = new CFPlus::UI::HBox
3135 can_hover => 1, 3378 can_hover => 1,
3136 can_events => 1, 3379 can_events => 1,
3137 tooltip => $tooltip, 3380 tooltip => $tooltip,
3138 children => [ 3381 children => [
3139 (new CFClient::UI::Label markup => $left, expand => 1), 3382 (new CFPlus::UI::Label markup => $left, expand => 1),
3140 (new CFClient::UI::Label markup => $right, align => +1), 3383 (new CFPlus::UI::Label markup => $right, align => +1),
3141 ], 3384 ],
3142 ; 3385 ;
3143 3386
3144 } else { 3387 } else {
3145 $widget = new CFClient::UI::Label 3388 $widget = new CFPlus::UI::Label
3146 can_hover => 1, 3389 can_hover => 1,
3147 can_events => 1, 3390 can_events => 1,
3148 markup => $widget, 3391 markup => $widget,
3149 tooltip => $tooltip; 3392 tooltip => $tooltip;
3150 } 3393 }
3198 1 3441 1
3199} 3442}
3200 3443
3201############################################################################# 3444#############################################################################
3202 3445
3203package CFClient::UI::Multiplexer; 3446package CFPlus::UI::Multiplexer;
3204 3447
3205our @ISA = CFClient::UI::Container::; 3448our @ISA = CFPlus::UI::Container::;
3206 3449
3207sub new { 3450sub new {
3208 my $class = shift; 3451 my $class = shift;
3209 3452
3210 my $self = $class->SUPER::new ( 3453 my $self = $class->SUPER::new (
3271 $self->{current}->draw; 3514 $self->{current}->draw;
3272} 3515}
3273 3516
3274############################################################################# 3517#############################################################################
3275 3518
3276package CFClient::UI::Notebook; 3519package CFPlus::UI::Notebook;
3277 3520
3278our @ISA = CFClient::UI::VBox::; 3521our @ISA = CFPlus::UI::VBox::;
3279 3522
3280sub new { 3523sub new {
3281 my $class = shift; 3524 my $class = shift;
3282 3525
3283 my $self = $class->SUPER::new ( 3526 my $self = $class->SUPER::new (
3284 buttonbar => (new CFClient::UI::Buttonbar), 3527 buttonbar => (new CFPlus::UI::Buttonbar),
3285 multiplexer => (new CFClient::UI::Multiplexer expand => 1), 3528 multiplexer => (new CFPlus::UI::Multiplexer expand => 1),
3286 # filter => # will be put between multiplexer and $self 3529 # filter => # will be put between multiplexer and $self
3287 @_, 3530 @_,
3288 ); 3531 );
3289 3532
3290 $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; 3533 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
3294} 3537}
3295 3538
3296sub add { 3539sub add {
3297 my ($self, $title, $widget, $tooltip) = @_; 3540 my ($self, $title, $widget, $tooltip) = @_;
3298 3541
3299 Scalar::Util::weaken $self; 3542 CFPlus::weaken $self;
3300 3543
3301 $self->{buttonbar}->add (new CFClient::UI::Button 3544 $self->{buttonbar}->add (new CFPlus::UI::Button
3302 markup => $title, 3545 markup => $title,
3303 tooltip => $tooltip, 3546 tooltip => $tooltip,
3304 on_activate => sub { $self->set_current_page ($widget) }, 3547 on_activate => sub { $self->set_current_page ($widget) },
3305 ); 3548 );
3306 3549
3320 $self->emit (page_changed => $self->{multiplexer}{current}); 3563 $self->emit (page_changed => $self->{multiplexer}{current});
3321} 3564}
3322 3565
3323############################################################################# 3566#############################################################################
3324 3567
3325package CFClient::UI::Combobox; 3568package CFPlus::UI::Selector;
3326 3569
3327use utf8; 3570use utf8;
3328 3571
3329our @ISA = CFClient::UI::Button::; 3572our @ISA = CFPlus::UI::Button::;
3330 3573
3331sub new { 3574sub new {
3332 my $class = shift; 3575 my $class = shift;
3333 3576
3334 my $self = $class->SUPER::new ( 3577 my $self = $class->SUPER::new (
3351 my ($value, $title, $tooltip) = @$_; 3594 my ($value, $title, $tooltip) = @$_;
3352 3595
3353 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }]; 3596 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }];
3354 } 3597 }
3355 3598
3356 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); 3599 CFPlus::UI::Menu->new (items => \@menu_items)->popup ($ev);
3357} 3600}
3358 3601
3359sub _set_value { 3602sub _set_value {
3360 my ($self, $value) = @_; 3603 my ($self, $value) = @_;
3361 3604
3376 $self->emit (changed => $value); 3619 $self->emit (changed => $value);
3377} 3620}
3378 3621
3379############################################################################# 3622#############################################################################
3380 3623
3381package CFClient::UI::Statusbox; 3624package CFPlus::UI::Statusbox;
3382 3625
3383our @ISA = CFClient::UI::VBox::; 3626our @ISA = CFPlus::UI::VBox::;
3384 3627
3385sub new { 3628sub new {
3386 my $class = shift; 3629 my $class = shift;
3387 3630
3388 my $self = $class->SUPER::new ( 3631 my $self = $class->SUPER::new (
3389 fontsize => 0.8, 3632 fontsize => 0.8,
3390 @_, 3633 @_,
3391 ); 3634 );
3392 3635
3393 Scalar::Util::weaken (my $this = $self); 3636 CFPlus::weaken (my $this = $self);
3394 3637
3395 $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder }); 3638 $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder });
3396 3639
3397 $self 3640 $self
3398} 3641}
3400sub reorder { 3643sub reorder {
3401 my ($self) = @_; 3644 my ($self) = @_;
3402 my $NOW = Time::HiRes::time; 3645 my $NOW = Time::HiRes::time;
3403 3646
3404 # freeze display when hovering over any label 3647 # freeze display when hovering over any label
3405 return if $CFClient::UI::TOOLTIP->{owner} 3648 return if $CFPlus::UI::TOOLTIP->{owner}
3406 && grep $CFClient::UI::TOOLTIP->{owner} == $_->{label}, 3649 && grep $CFPlus::UI::TOOLTIP->{owner} == $_->{label},
3407 values %{ $self->{item} }; 3650 values %{ $self->{item} };
3408 3651
3409 while (my ($k, $v) = each %{ $self->{item} }) { 3652 while (my ($k, $v) = each %{ $self->{item} }) {
3410 delete $self->{item}{$k} if $v->{timeout} < $NOW; 3653 delete $self->{item}{$k} if $v->{timeout} < $NOW;
3411 } 3654 }
3432 for ($short) { 3675 for ($short) {
3433 s/^\s+//; 3676 s/^\s+//;
3434 s/\s+/ /g; 3677 s/\s+/ /g;
3435 } 3678 }
3436 3679
3437 new CFClient::UI::Label 3680 new CFPlus::UI::Label
3438 markup => $short, 3681 markup => $short,
3439 tooltip => $item->{tooltip}, 3682 tooltip => $item->{tooltip},
3440 tooltip_font => $::FONT_PROP, 3683 tooltip_font => $::FONT_PROP,
3441 tooltip_width => 0.67, 3684 tooltip_width => 0.67,
3442 fontsize => $item->{fontsize} || $self->{fontsize}, 3685 fontsize => $item->{fontsize} || $self->{fontsize},
3521 $self->SUPER::destroy; 3764 $self->SUPER::destroy;
3522} 3765}
3523 3766
3524############################################################################# 3767#############################################################################
3525 3768
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; 3769package CFPlus::UI::Root;
3691 3770
3692our @ISA = CFClient::UI::Container::; 3771our @ISA = CFPlus::UI::Container::;
3693 3772
3694use List::Util qw(min max); 3773use List::Util qw(min max);
3695 3774
3696use CFClient::OpenGL; 3775use CFPlus::OpenGL;
3697 3776
3698sub new { 3777sub new {
3699 my $class = shift; 3778 my $class = shift;
3700 3779
3701 my $self = $class->SUPER::new ( 3780 my $self = $class->SUPER::new (
3702 visible => 1, 3781 visible => 1,
3703 @_, 3782 @_,
3704 ); 3783 );
3705 3784
3706 Scalar::Util::weaken ($self->{root} = $self); 3785 CFPlus::weaken ($self->{root} = $self);
3707 3786
3708 $self 3787 $self
3709} 3788}
3710 3789
3711sub size_request { 3790sub size_request {
3880 $h = 0 if $h < 0; 3959 $h = 0 if $h < 0;
3881 3960
3882 $w = max $widget->{min_w}, $w; 3961 $w = max $widget->{min_w}, $w;
3883 $h = max $widget->{min_h}, $h; 3962 $h = max $widget->{min_h}, $h;
3884 3963
3964# $w = min $self->{w} - $widget->{x}, $w if $self->{w};
3965# $h = min $self->{h} - $widget->{y}, $h if $self->{h};
3966
3885 $w = min $widget->{max_w}, $w if exists $widget->{max_w}; 3967 $w = min $widget->{max_w}, $w if exists $widget->{max_w};
3886 $h = min $widget->{max_h}, $h if exists $widget->{max_h}; 3968 $h = min $widget->{max_h}, $h if exists $widget->{max_h};
3887 3969
3888 $w = int $w + 0.5; 3970 $w = int $w + 0.5;
3889 $h = int $h + 0.5; 3971 $h = int $h + 0.5;
3915 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; 3997 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
3916 glMatrixMode GL_MODELVIEW; 3998 glMatrixMode GL_MODELVIEW;
3917 glLoadIdentity; 3999 glLoadIdentity;
3918 4000
3919 { 4001 {
3920 package CFClient::UI::Base; 4002 package CFPlus::UI::Base;
3921 4003
3922 ($draw_x, $draw_y, $draw_w, $draw_h) = 4004 local ($draw_x, $draw_y, $draw_w, $draw_h) =
3923 (0, 0, $self->{w}, $self->{h}); 4005 (0, 0, $self->{w}, $self->{h});
3924 }
3925 4006
3926 $self->_draw; 4007 $self->_draw;
4008 }
3927} 4009}
3928 4010
3929############################################################################# 4011#############################################################################
3930 4012
3931package CFClient::UI; 4013package CFPlus::UI;
3932 4014
3933$ROOT = new CFClient::UI::Root; 4015$ROOT = new CFPlus::UI::Root;
3934$TOOLTIP = new CFClient::UI::Tooltip z => 900; 4016$TOOLTIP = new CFPlus::UI::Tooltip z => 900;
3935 4017
39361 40181
3937 4019

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines