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.72 by root, Tue Apr 11 18:00:45 2006 UTC vs.
Revision 1.73 by root, Tue Apr 11 18:06:53 2006 UTC

1package CFClient::Widget; 1package CFClient::UI;
2 2
3use strict; 3use strict;
4 4
5use Scalar::Util; 5use Scalar::Util;
6
7use SDL::OpenGL;
8use SDL::OpenGL::Constants;
9 6
10use CFClient; 7use CFClient;
11 8
12our ($FOCUS, $HOVER, $GRAB); # various widgets 9our ($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
74package CFClient::UI::Base;
75
76use strict;
77
78use SDL::OpenGL;
74 79
75sub new { 80sub 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
245package CFClient::Widget::DrawBG; 250package CFClient::UI::DrawBG;
246 251
247our @ISA = CFClient::Widget::; 252our @ISA = CFClient::UI::Base::;
248 253
249use strict; 254use strict;
250use SDL::OpenGL; 255use SDL::OpenGL;
251 256
252sub new { 257sub new {
275 glEnd; 280 glEnd;
276} 281}
277 282
278############################################################################# 283#############################################################################
279 284
280package CFClient::Widget::Empty; 285package CFClient::UI::Empty;
281 286
282our @ISA = CFClient::Widget::; 287our @ISA = CFClient::UI::Base::;
283 288
284sub size_request { 289sub size_request {
285 (0, 0) 290 (0, 0)
286} 291}
287 292
288sub draw { } 293sub draw { }
289 294
290############################################################################# 295#############################################################################
291 296
292package CFClient::Widget::Container; 297package CFClient::UI::Container;
293 298
294our @ISA = CFClient::Widget::; 299our @ISA = CFClient::UI::Base::;
295 300
296sub new { 301sub 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
354package CFClient::Widget::Bin; 359package CFClient::UI::Bin;
355 360
356our @ISA = CFClient::Widget::Container::; 361our @ISA = CFClient::UI::Container::;
357 362
358sub new { 363sub 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
366sub add { 371sub add {
374sub remove { 379sub 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
383sub child { $_[0]->{children}[0] } 388sub 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
400package CFClient::Widget::Window; 405package CFClient::UI::Window;
401 406
402our @ISA = CFClient::Widget::Bin::; 407our @ISA = CFClient::UI::Bin::;
403 408
404use SDL::OpenGL; 409use SDL::OpenGL;
405 410
406sub new { 411sub 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
462package CFClient::Widget::Frame; 467package CFClient::UI::Frame;
463 468
464our @ISA = CFClient::Widget::Bin::; 469our @ISA = CFClient::UI::Bin::;
465 470
466use SDL::OpenGL; 471use SDL::OpenGL;
467 472
468sub size_request { 473sub size_request {
469 my ($self) = @_; 474 my ($self) = @_;
505 $chld->draw; 510 $chld->draw;
506} 511}
507 512
508############################################################################# 513#############################################################################
509 514
510package CFClient::Widget::FancyFrame; 515package CFClient::UI::FancyFrame;
511 516
512our @ISA = CFClient::Widget::Bin::; 517our @ISA = CFClient::UI::Bin::;
513 518
514use SDL::OpenGL; 519use SDL::OpenGL;
515 520
516my @tex = 521my @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
597package CFClient::Widget::Table; 602package CFClient::UI::Table;
598 603
599our @ISA = CFClient::Widget::; 604our @ISA = CFClient::UI::Base::;
600 605
601use SDL::OpenGL; 606use SDL::OpenGL;
602 607
603sub add { 608sub add {
604 my ($self, $x, $y, $chld) = @_; 609 my ($self, $x, $y, $chld) = @_;
679 } 684 }
680} 685}
681 686
682############################################################################# 687#############################################################################
683 688
684package CFClient::Widget::VBox; 689package CFClient::UI::VBox;
685 690
686our @ISA = CFClient::Widget::Container::; 691our @ISA = CFClient::UI::Container::;
687 692
688use SDL::OpenGL; 693use SDL::OpenGL;
689 694
690sub size_request { 695sub size_request {
691 my ($self) = @_; 696 my ($self) = @_;
743 } 748 }
744} 749}
745 750
746############################################################################# 751#############################################################################
747 752
748package CFClient::Widget::Label; 753package CFClient::UI::Label;
749 754
750our @ISA = CFClient::Widget::; 755our @ISA = CFClient::UI::Base::;
751 756
752use SDL::OpenGL; 757use SDL::OpenGL;
753 758
754sub new { 759sub 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
859package CFClient::Widget::Entry; 864package CFClient::UI::Entry;
860 865
861our @ISA = CFClient::Widget::Label::; 866our @ISA = CFClient::UI::Label::;
862 867
863use SDL; 868use SDL;
864use SDL::OpenGL; 869use SDL::OpenGL;
865 870
866sub new { 871sub new {
1006 } 1011 }
1007} 1012}
1008 1013
1009############################################################################# 1014#############################################################################
1010 1015
1011package CFClient::Widget::Slider; 1016package CFClient::UI::Slider;
1012 1017
1013use strict; 1018use strict;
1014 1019
1015use SDL::OpenGL; 1020use SDL::OpenGL;
1016use SDL::OpenGL::Constants; 1021use SDL::OpenGL::Constants;
1017 1022
1018our @ISA = CFClient::Widget::DrawBG::; 1023our @ISA = CFClient::UI::DrawBG::;
1019 1024
1020sub size_request { 1025sub 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
1125package CFClient::Widget::MapWidget; 1130package CFClient::UI::MapWidget;
1126 1131
1127use strict; 1132use strict;
1128 1133
1129use List::Util qw(min max); 1134use List::Util qw(min max);
1130 1135
1131use SDL; 1136use SDL;
1132use SDL::OpenGL; 1137use SDL::OpenGL;
1133use SDL::OpenGL::Constants; 1138use SDL::OpenGL::Constants;
1134 1139
1135our @ISA = CFClient::Widget::; 1140our @ISA = CFClient::UI::Base::;
1136 1141
1137sub new { 1142sub 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
1311package CFClient::Widget::Animator; 1316package CFClient::UI::Animator;
1312 1317
1313use SDL::OpenGL; 1318use SDL::OpenGL;
1314 1319
1315our @ISA = CFClient::Widget::Bin::; 1320our @ISA = CFClient::UI::Bin::;
1316 1321
1317sub moveto { 1322sub 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
1353package CFClient::Widget::Toplevel; 1358package CFClient::UI::Toplevel;
1354 1359
1355our @ISA = CFClient::Widget::Container::; 1360our @ISA = CFClient::UI::Container::;
1356 1361
1357sub size_request { 1362sub 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
1399package CFClient::Widget; 1404package CFClient::UI;
1400 1405
1401$TOPLEVEL = new CFClient::Widget::Toplevel; 1406$TOPLEVEL = new CFClient::UI::Toplevel;
1402 1407
14031 14081
1404 1409

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines