1 | package CFClient::Widget; |
1 | package CFClient::UI; |
2 | |
2 | |
3 | use strict; |
3 | use strict; |
4 | |
4 | |
5 | use Scalar::Util; |
5 | use Scalar::Util; |
6 | |
|
|
7 | use SDL::OpenGL; |
|
|
8 | use SDL::OpenGL::Constants; |
|
|
9 | |
6 | |
10 | use CFClient; |
7 | use CFClient; |
11 | |
8 | |
12 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
9 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
13 | |
10 | |
… | |
… | |
69 | $HOVER->update if $HOVER; |
66 | $HOVER->update if $HOVER; |
70 | } |
67 | } |
71 | |
68 | |
72 | $HOVER->mouse_motion ($ev, $HOVER->translate ($x, $y)) if $HOVER; |
69 | $HOVER->mouse_motion ($ev, $HOVER->translate ($x, $y)) if $HOVER; |
73 | } |
70 | } |
|
|
71 | |
|
|
72 | ############################################################################# |
|
|
73 | |
|
|
74 | package CFClient::UI::Base; |
|
|
75 | |
|
|
76 | use strict; |
|
|
77 | |
|
|
78 | use SDL::OpenGL; |
74 | |
79 | |
75 | sub new { |
80 | sub new { |
76 | my $class = shift; |
81 | my $class = shift; |
77 | |
82 | |
78 | bless { |
83 | bless { |
… | |
… | |
158 | glTranslate $self->{x}, $self->{y}, 0; |
163 | glTranslate $self->{x}, $self->{y}, 0; |
159 | $self->_draw; |
164 | $self->_draw; |
160 | glPopMatrix; |
165 | glPopMatrix; |
161 | |
166 | |
162 | if ($self == $HOVER) { |
167 | if ($self == $HOVER) { |
163 | my ($x, $y) = @$self->{qw(x y)}; |
168 | my ($x, $y) = @$self{qw(x y)}; |
164 | |
169 | |
165 | glColor 1, 1, 1, 0.1; |
170 | glColor 1, 1, 1, 0.1; |
166 | glEnable GL_BLEND; |
171 | glEnable GL_BLEND; |
167 | glBegin GL_QUADS; |
172 | glBegin GL_QUADS; |
168 | glVertex $x , $y; |
173 | glVertex $x , $y; |
… | |
… | |
240 | #$self->deactivate; |
245 | #$self->deactivate; |
241 | } |
246 | } |
242 | |
247 | |
243 | ############################################################################# |
248 | ############################################################################# |
244 | |
249 | |
245 | package CFClient::Widget::DrawBG; |
250 | package CFClient::UI::DrawBG; |
246 | |
251 | |
247 | our @ISA = CFClient::Widget::; |
252 | our @ISA = CFClient::UI::Base::; |
248 | |
253 | |
249 | use strict; |
254 | use strict; |
250 | use SDL::OpenGL; |
255 | use SDL::OpenGL; |
251 | |
256 | |
252 | sub new { |
257 | sub new { |
… | |
… | |
275 | glEnd; |
280 | glEnd; |
276 | } |
281 | } |
277 | |
282 | |
278 | ############################################################################# |
283 | ############################################################################# |
279 | |
284 | |
280 | package CFClient::Widget::Empty; |
285 | package CFClient::UI::Empty; |
281 | |
286 | |
282 | our @ISA = CFClient::Widget::; |
287 | our @ISA = CFClient::UI::Base::; |
283 | |
288 | |
284 | sub size_request { |
289 | sub size_request { |
285 | (0, 0) |
290 | (0, 0) |
286 | } |
291 | } |
287 | |
292 | |
288 | sub draw { } |
293 | sub draw { } |
289 | |
294 | |
290 | ############################################################################# |
295 | ############################################################################# |
291 | |
296 | |
292 | package CFClient::Widget::Container; |
297 | package CFClient::UI::Container; |
293 | |
298 | |
294 | our @ISA = CFClient::Widget::; |
299 | our @ISA = CFClient::UI::Base::; |
295 | |
300 | |
296 | sub new { |
301 | sub new { |
297 | my ($class, %arg) = @_; |
302 | my ($class, %arg) = @_; |
298 | |
303 | |
299 | my $children = delete $arg{children} || []; |
304 | my $children = delete $arg{children} || []; |
… | |
… | |
349 | $_->draw for @{$self->{children}}; |
354 | $_->draw for @{$self->{children}}; |
350 | } |
355 | } |
351 | |
356 | |
352 | ############################################################################# |
357 | ############################################################################# |
353 | |
358 | |
354 | package CFClient::Widget::Bin; |
359 | package CFClient::UI::Bin; |
355 | |
360 | |
356 | our @ISA = CFClient::Widget::Container::; |
361 | our @ISA = CFClient::UI::Container::; |
357 | |
362 | |
358 | sub new { |
363 | sub new { |
359 | my ($class, %arg) = @_; |
364 | my ($class, %arg) = @_; |
360 | |
365 | |
361 | my $child = (delete $arg{child}) || new CFClient::Widget::Empty::; |
366 | my $child = (delete $arg{child}) || new CFClient::UI::Empty::; |
362 | |
367 | |
363 | $class->SUPER::new (children => [$child], %arg) |
368 | $class->SUPER::new (children => [$child], %arg) |
364 | } |
369 | } |
365 | |
370 | |
366 | sub add { |
371 | sub add { |
… | |
… | |
374 | sub remove { |
379 | sub remove { |
375 | my ($self, $widget) = @_; |
380 | my ($self, $widget) = @_; |
376 | |
381 | |
377 | $self->SUPER::remove ($widget); |
382 | $self->SUPER::remove ($widget); |
378 | |
383 | |
379 | $self->{children} = [new CFClient::Widget::Empty] |
384 | $self->{children} = [new CFClient::UI::Empty] |
380 | unless @{$self->{children}}; |
385 | unless @{$self->{children}}; |
381 | } |
386 | } |
382 | |
387 | |
383 | sub child { $_[0]->{children}[0] } |
388 | sub child { $_[0]->{children}[0] } |
384 | |
389 | |
… | |
… | |
395 | $self->{children}[0]->size_allocate ($w, $h); |
400 | $self->{children}[0]->size_allocate ($w, $h); |
396 | } |
401 | } |
397 | |
402 | |
398 | ############################################################################# |
403 | ############################################################################# |
399 | |
404 | |
400 | package CFClient::Widget::Window; |
405 | package CFClient::UI::Window; |
401 | |
406 | |
402 | our @ISA = CFClient::Widget::Bin::; |
407 | our @ISA = CFClient::UI::Bin::; |
403 | |
408 | |
404 | use SDL::OpenGL; |
409 | use SDL::OpenGL; |
405 | |
410 | |
406 | sub new { |
411 | sub new { |
407 | my ($class, %arg) = @_; |
412 | my ($class, %arg) = @_; |
… | |
… | |
457 | glDisable GL_TEXTURE_2D; |
462 | glDisable GL_TEXTURE_2D; |
458 | } |
463 | } |
459 | |
464 | |
460 | ############################################################################# |
465 | ############################################################################# |
461 | |
466 | |
462 | package CFClient::Widget::Frame; |
467 | package CFClient::UI::Frame; |
463 | |
468 | |
464 | our @ISA = CFClient::Widget::Bin::; |
469 | our @ISA = CFClient::UI::Bin::; |
465 | |
470 | |
466 | use SDL::OpenGL; |
471 | use SDL::OpenGL; |
467 | |
472 | |
468 | sub size_request { |
473 | sub size_request { |
469 | my ($self) = @_; |
474 | my ($self) = @_; |
… | |
… | |
505 | $chld->draw; |
510 | $chld->draw; |
506 | } |
511 | } |
507 | |
512 | |
508 | ############################################################################# |
513 | ############################################################################# |
509 | |
514 | |
510 | package CFClient::Widget::FancyFrame; |
515 | package CFClient::UI::FancyFrame; |
511 | |
516 | |
512 | our @ISA = CFClient::Widget::Bin::; |
517 | our @ISA = CFClient::UI::Bin::; |
513 | |
518 | |
514 | use SDL::OpenGL; |
519 | use SDL::OpenGL; |
515 | |
520 | |
516 | my @tex = |
521 | my @tex = |
517 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
522 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
… | |
… | |
592 | |
597 | |
593 | } |
598 | } |
594 | |
599 | |
595 | ############################################################################# |
600 | ############################################################################# |
596 | |
601 | |
597 | package CFClient::Widget::Table; |
602 | package CFClient::UI::Table; |
598 | |
603 | |
599 | our @ISA = CFClient::Widget::; |
604 | our @ISA = CFClient::UI::Base::; |
600 | |
605 | |
601 | use SDL::OpenGL; |
606 | use SDL::OpenGL; |
602 | |
607 | |
603 | sub add { |
608 | sub add { |
604 | my ($self, $x, $y, $chld) = @_; |
609 | my ($self, $x, $y, $chld) = @_; |
… | |
… | |
679 | } |
684 | } |
680 | } |
685 | } |
681 | |
686 | |
682 | ############################################################################# |
687 | ############################################################################# |
683 | |
688 | |
684 | package CFClient::Widget::VBox; |
689 | package CFClient::UI::VBox; |
685 | |
690 | |
686 | our @ISA = CFClient::Widget::Container::; |
691 | our @ISA = CFClient::UI::Container::; |
687 | |
692 | |
688 | use SDL::OpenGL; |
693 | use SDL::OpenGL; |
689 | |
694 | |
690 | sub size_request { |
695 | sub size_request { |
691 | my ($self) = @_; |
696 | my ($self) = @_; |
… | |
… | |
743 | } |
748 | } |
744 | } |
749 | } |
745 | |
750 | |
746 | ############################################################################# |
751 | ############################################################################# |
747 | |
752 | |
748 | package CFClient::Widget::Label; |
753 | package CFClient::UI::Label; |
749 | |
754 | |
750 | our @ISA = CFClient::Widget::; |
755 | our @ISA = CFClient::UI::Base::; |
751 | |
756 | |
752 | use SDL::OpenGL; |
757 | use SDL::OpenGL; |
753 | |
758 | |
754 | sub new { |
759 | sub new { |
755 | my ($class, %arg) = @_; |
760 | my ($class, %arg) = @_; |
… | |
… | |
854 | glDisable GL_TEXTURE_2D; |
859 | glDisable GL_TEXTURE_2D; |
855 | } |
860 | } |
856 | |
861 | |
857 | ############################################################################# |
862 | ############################################################################# |
858 | |
863 | |
859 | package CFClient::Widget::Entry; |
864 | package CFClient::UI::Entry; |
860 | |
865 | |
861 | our @ISA = CFClient::Widget::Label::; |
866 | our @ISA = CFClient::UI::Label::; |
862 | |
867 | |
863 | use SDL; |
868 | use SDL; |
864 | use SDL::OpenGL; |
869 | use SDL::OpenGL; |
865 | |
870 | |
866 | sub new { |
871 | sub new { |
… | |
… | |
1006 | } |
1011 | } |
1007 | } |
1012 | } |
1008 | |
1013 | |
1009 | ############################################################################# |
1014 | ############################################################################# |
1010 | |
1015 | |
1011 | package CFClient::Widget::Slider; |
1016 | package CFClient::UI::Slider; |
1012 | |
1017 | |
1013 | use strict; |
1018 | use strict; |
1014 | |
1019 | |
1015 | use SDL::OpenGL; |
1020 | use SDL::OpenGL; |
1016 | use SDL::OpenGL::Constants; |
1021 | use SDL::OpenGL::Constants; |
1017 | |
1022 | |
1018 | our @ISA = CFClient::Widget::DrawBG::; |
1023 | our @ISA = CFClient::UI::DrawBG::; |
1019 | |
1024 | |
1020 | sub size_request { |
1025 | sub size_request { |
1021 | my ($self) = @_; |
1026 | my ($self) = @_; |
1022 | |
1027 | |
1023 | my $w = 50; |
1028 | my $w = 50; |
… | |
… | |
1120 | glEnd; |
1125 | glEnd; |
1121 | } |
1126 | } |
1122 | |
1127 | |
1123 | ############################################################################# |
1128 | ############################################################################# |
1124 | |
1129 | |
1125 | package CFClient::Widget::MapWidget; |
1130 | package CFClient::UI::MapWidget; |
1126 | |
1131 | |
1127 | use strict; |
1132 | use strict; |
1128 | |
1133 | |
1129 | use List::Util qw(min max); |
1134 | use List::Util qw(min max); |
1130 | |
1135 | |
1131 | use SDL; |
1136 | use SDL; |
1132 | use SDL::OpenGL; |
1137 | use SDL::OpenGL; |
1133 | use SDL::OpenGL::Constants; |
1138 | use SDL::OpenGL::Constants; |
1134 | |
1139 | |
1135 | our @ISA = CFClient::Widget::; |
1140 | our @ISA = CFClient::UI::Base::; |
1136 | |
1141 | |
1137 | sub new { |
1142 | sub new { |
1138 | my $class = shift; |
1143 | my $class = shift; |
1139 | |
1144 | |
1140 | $class->SUPER::new ( |
1145 | $class->SUPER::new ( |
… | |
… | |
1306 | } |
1311 | } |
1307 | } |
1312 | } |
1308 | |
1313 | |
1309 | ############################################################################# |
1314 | ############################################################################# |
1310 | |
1315 | |
1311 | package CFClient::Widget::Animator; |
1316 | package CFClient::UI::Animator; |
1312 | |
1317 | |
1313 | use SDL::OpenGL; |
1318 | use SDL::OpenGL; |
1314 | |
1319 | |
1315 | our @ISA = CFClient::Widget::Bin::; |
1320 | our @ISA = CFClient::UI::Bin::; |
1316 | |
1321 | |
1317 | sub moveto { |
1322 | sub moveto { |
1318 | my ($self, $x, $y) = @_; |
1323 | my ($self, $x, $y) = @_; |
1319 | |
1324 | |
1320 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
1325 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
… | |
… | |
1348 | glPopMatrix; |
1353 | glPopMatrix; |
1349 | } |
1354 | } |
1350 | |
1355 | |
1351 | ############################################################################# |
1356 | ############################################################################# |
1352 | |
1357 | |
1353 | package CFClient::Widget::Toplevel; |
1358 | package CFClient::UI::Toplevel; |
1354 | |
1359 | |
1355 | our @ISA = CFClient::Widget::Container::; |
1360 | our @ISA = CFClient::UI::Container::; |
1356 | |
1361 | |
1357 | sub size_request { |
1362 | sub size_request { |
1358 | ($::WIDTH, $::HEIGHT) |
1363 | ($::WIDTH, $::HEIGHT) |
1359 | } |
1364 | } |
1360 | |
1365 | |
… | |
… | |
1394 | $self->_draw; |
1399 | $self->_draw; |
1395 | } |
1400 | } |
1396 | |
1401 | |
1397 | ############################################################################# |
1402 | ############################################################################# |
1398 | |
1403 | |
1399 | package CFClient::Widget; |
1404 | package CFClient::UI; |
1400 | |
1405 | |
1401 | $TOPLEVEL = new CFClient::Widget::Toplevel; |
1406 | $TOPLEVEL = new CFClient::UI::Toplevel; |
1402 | |
1407 | |
1403 | 1 |
1408 | 1 |
1404 | |
1409 | |