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.74 by root, Tue Apr 11 19:31:18 2006 UTC

1package CFClient::Widget; 1package CFClient::UI;
2 2
3use strict; 3use strict;
4 4
5use Scalar::Util; 5use Scalar::Util ();
6 6use List::Util ();
7use SDL::OpenGL;
8use SDL::OpenGL::Constants;
9 7
10use CFClient; 8use CFClient;
11 9
12our ($FOCUS, $HOVER, $GRAB); # various widgets 10our ($FOCUS, $HOVER, $GRAB); # various widgets
13 11
69 $HOVER->update if $HOVER; 67 $HOVER->update if $HOVER;
70 } 68 }
71 69
72 $HOVER->mouse_motion ($ev, $HOVER->translate ($x, $y)) if $HOVER; 70 $HOVER->mouse_motion ($ev, $HOVER->translate ($x, $y)) if $HOVER;
73} 71}
72
73#############################################################################
74
75package CFClient::UI::Base;
76
77use strict;
78
79use SDL::OpenGL;
74 80
75sub new { 81sub new {
76 my $class = shift; 82 my $class = shift;
77 83
78 bless { 84 bless {
158 glTranslate $self->{x}, $self->{y}, 0; 164 glTranslate $self->{x}, $self->{y}, 0;
159 $self->_draw; 165 $self->_draw;
160 glPopMatrix; 166 glPopMatrix;
161 167
162 if ($self == $HOVER) { 168 if ($self == $HOVER) {
163 my ($x, $y) = @$self->{qw(x y)}; 169 my ($x, $y) = @$self{qw(x y)};
164 170
165 glColor 1, 1, 1, 0.1; 171 glColor 1, 1, 1, 0.1;
166 glEnable GL_BLEND; 172 glEnable GL_BLEND;
173 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
167 glBegin GL_QUADS; 174 glBegin GL_QUADS;
168 glVertex $x , $y; 175 glVertex $x , $y;
169 glVertex $x + $self->{w}, $y; 176 glVertex $x + $self->{w}, $y;
170 glVertex $x + $self->{w}, $y + $self->{h}; 177 glVertex $x + $self->{w}, $y + $self->{h};
171 glVertex $x , $y + $self->{h}; 178 glVertex $x , $y + $self->{h};
240 #$self->deactivate; 247 #$self->deactivate;
241} 248}
242 249
243############################################################################# 250#############################################################################
244 251
245package CFClient::Widget::DrawBG; 252package CFClient::UI::DrawBG;
246 253
247our @ISA = CFClient::Widget::; 254our @ISA = CFClient::UI::Base::;
248 255
249use strict; 256use strict;
250use SDL::OpenGL; 257use SDL::OpenGL;
251 258
252sub new { 259sub new {
275 glEnd; 282 glEnd;
276} 283}
277 284
278############################################################################# 285#############################################################################
279 286
280package CFClient::Widget::Empty; 287package CFClient::UI::Empty;
281 288
282our @ISA = CFClient::Widget::; 289our @ISA = CFClient::UI::Base::;
283 290
284sub size_request { 291sub size_request {
285 (0, 0) 292 (0, 0)
286} 293}
287 294
288sub draw { } 295sub draw { }
289 296
290############################################################################# 297#############################################################################
291 298
292package CFClient::Widget::Container; 299package CFClient::UI::Container;
293 300
294our @ISA = CFClient::Widget::; 301our @ISA = CFClient::UI::Base::;
295 302
296sub new { 303sub new {
297 my ($class, %arg) = @_; 304 my ($class, %arg) = @_;
298 305
299 my $children = delete $arg{children} || []; 306 my $children = delete $arg{children} || [];
349 $_->draw for @{$self->{children}}; 356 $_->draw for @{$self->{children}};
350} 357}
351 358
352############################################################################# 359#############################################################################
353 360
354package CFClient::Widget::Bin; 361package CFClient::UI::Bin;
355 362
356our @ISA = CFClient::Widget::Container::; 363our @ISA = CFClient::UI::Container::;
357 364
358sub new { 365sub new {
359 my ($class, %arg) = @_; 366 my ($class, %arg) = @_;
360 367
361 my $child = (delete $arg{child}) || new CFClient::Widget::Empty::; 368 my $child = (delete $arg{child}) || new CFClient::UI::Empty::;
362 369
363 $class->SUPER::new (children => [$child], %arg) 370 $class->SUPER::new (children => [$child], %arg)
364} 371}
365 372
366sub add { 373sub add {
374sub remove { 381sub remove {
375 my ($self, $widget) = @_; 382 my ($self, $widget) = @_;
376 383
377 $self->SUPER::remove ($widget); 384 $self->SUPER::remove ($widget);
378 385
379 $self->{children} = [new CFClient::Widget::Empty] 386 $self->{children} = [new CFClient::UI::Empty]
380 unless @{$self->{children}}; 387 unless @{$self->{children}};
381} 388}
382 389
383sub child { $_[0]->{children}[0] } 390sub child { $_[0]->{children}[0] }
384 391
395 $self->{children}[0]->size_allocate ($w, $h); 402 $self->{children}[0]->size_allocate ($w, $h);
396} 403}
397 404
398############################################################################# 405#############################################################################
399 406
400package CFClient::Widget::Window; 407package CFClient::UI::Window;
401 408
402our @ISA = CFClient::Widget::Bin::; 409our @ISA = CFClient::UI::Bin::;
403 410
404use SDL::OpenGL; 411use SDL::OpenGL;
405 412
406sub new { 413sub new {
407 my ($class, %arg) = @_; 414 my ($class, %arg) = @_;
446 453
447 my $tex = $self->{texture} 454 my $tex = $self->{texture}
448 or return; 455 or return;
449 456
450 glEnable GL_BLEND; 457 glEnable GL_BLEND;
458 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
451 glEnable GL_TEXTURE_2D; 459 glEnable GL_TEXTURE_2D;
452 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 460 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
453 461
454 $tex->draw_quad (0, 0, $w, $h); 462 $tex->draw_quad (0, 0, $w, $h);
455 463
457 glDisable GL_TEXTURE_2D; 465 glDisable GL_TEXTURE_2D;
458} 466}
459 467
460############################################################################# 468#############################################################################
461 469
462package CFClient::Widget::Frame; 470package CFClient::UI::Frame;
463 471
464our @ISA = CFClient::Widget::Bin::; 472our @ISA = CFClient::UI::Bin::;
465 473
466use SDL::OpenGL; 474use SDL::OpenGL;
467 475
468sub size_request { 476sub size_request {
469 my ($self) = @_; 477 my ($self) = @_;
505 $chld->draw; 513 $chld->draw;
506} 514}
507 515
508############################################################################# 516#############################################################################
509 517
510package CFClient::Widget::FancyFrame; 518package CFClient::UI::FancyFrame;
511 519
512our @ISA = CFClient::Widget::Bin::; 520our @ISA = CFClient::UI::Bin::;
513 521
514use SDL::OpenGL; 522use SDL::OpenGL;
515 523
516my @tex = 524my @tex =
517 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 525 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
556 564
557 my ($w, $h) = ($self->{w}, $self->{h}); 565 my ($w, $h) = ($self->{w}, $self->{h});
558 my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); 566 my ($cw, $ch) = ($self->child->{w}, $self->child->{h});
559 567
560 glEnable GL_BLEND; 568 glEnable GL_BLEND;
569 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
561 glEnable GL_TEXTURE_2D; 570 glEnable GL_TEXTURE_2D;
562 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
563 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 571 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
564 572
565 my $top = $tex[1]; 573 my $top = $tex[1];
566 $top->draw_quad (0, 0, $w, $top->{h}); 574 $top->draw_quad (0, 0, $w, $top->{h});
567 575
592 600
593} 601}
594 602
595############################################################################# 603#############################################################################
596 604
597package CFClient::Widget::Table; 605package CFClient::UI::Table;
598 606
599our @ISA = CFClient::Widget::; 607our @ISA = CFClient::UI::Base::;
600 608
601use SDL::OpenGL; 609use SDL::OpenGL;
602 610
603sub add { 611sub add {
604 my ($self, $x, $y, $chld) = @_; 612 my ($self, $x, $y, $chld) = @_;
679 } 687 }
680} 688}
681 689
682############################################################################# 690#############################################################################
683 691
684package CFClient::Widget::VBox; 692package CFClient::UI::VBox;
685 693
686our @ISA = CFClient::Widget::Container::; 694our @ISA = CFClient::UI::Container::;
687 695
688use SDL::OpenGL; 696use SDL::OpenGL;
689 697
690sub size_request { 698sub size_request {
691 my ($self) = @_; 699 my ($self) = @_;
743 } 751 }
744} 752}
745 753
746############################################################################# 754#############################################################################
747 755
748package CFClient::Widget::Label; 756package CFClient::UI::Label;
749 757
750our @ISA = CFClient::Widget::; 758our @ISA = CFClient::UI::Base::;
751 759
752use SDL::OpenGL; 760use SDL::OpenGL;
753 761
754sub new { 762sub new {
755 my ($class, %arg) = @_; 763 my ($class, %arg) = @_;
831sub _draw { 839sub _draw {
832 my ($self) = @_; 840 my ($self) = @_;
833 841
834 my $tex = $self->{texture} ||= do { 842 my $tex = $self->{texture} ||= do {
835 $self->{layout}->set_width ($self->{w}); 843 $self->{layout}->set_width ($self->{w});
836 new_from_layout CFClient::Texture $self->{layout}; 844 new_from_layout CFClient::Texture $self->{layout}
837 }; 845 };
838 846
839 glEnable GL_BLEND; 847 glEnable GL_BLEND;
848 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
840 glEnable GL_TEXTURE_2D; 849 glEnable GL_TEXTURE_2D;
841 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
842 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 850 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
843 851
844 glColor @{$self->{fg}}; 852 glColor @{$self->{fg}};
845 853
846 my $x = 854 my $x =
847 $self->{align} < 0 ? 0 855 $self->{align} < 0 ? 0
848 : $self->{align} > 0 ? $self->{w} - $self->{texture}{w} 856 : $self->{align} > 0 ? $self->{w} - $tex->{w}
849 : ($self->{w} + $self->{texture}{w}) * 0.5; 857 : ($self->{w} - $tex->{w}) * 0.5;
850 858
851 $tex->draw_quad ($x, 0); 859 $tex->draw_quad ($x, 0);
852 860
861 glDisable GL_TEXTURE_2D;
853 glDisable GL_BLEND; 862 glDisable GL_BLEND;
854 glDisable GL_TEXTURE_2D; 863 glGetError and die;
855} 864}
856 865
857############################################################################# 866#############################################################################
858 867
859package CFClient::Widget::Entry; 868package CFClient::UI::Entry;
860 869
861our @ISA = CFClient::Widget::Label::; 870our @ISA = CFClient::UI::Label::;
862 871
863use SDL; 872use SDL;
864use SDL::OpenGL; 873use SDL::OpenGL;
865 874
866sub new { 875sub new {
1006 } 1015 }
1007} 1016}
1008 1017
1009############################################################################# 1018#############################################################################
1010 1019
1011package CFClient::Widget::Slider; 1020package CFClient::UI::Slider;
1012 1021
1013use strict; 1022use strict;
1014 1023
1015use SDL::OpenGL; 1024use SDL::OpenGL;
1016use SDL::OpenGL::Constants;
1017 1025
1018our @ISA = CFClient::Widget::DrawBG::; 1026our @ISA = CFClient::UI::DrawBG::;
1019 1027
1020sub size_request { 1028sub size_request {
1021 my ($self) = @_; 1029 my ($self) = @_;
1022 1030
1023 my $w = 50; 1031 my $w = 50;
1120 glEnd; 1128 glEnd;
1121} 1129}
1122 1130
1123############################################################################# 1131#############################################################################
1124 1132
1125package CFClient::Widget::MapWidget; 1133package CFClient::UI::MapWidget;
1126 1134
1127use strict; 1135use strict;
1128 1136
1129use List::Util qw(min max); 1137use List::Util qw(min max);
1130 1138
1131use SDL; 1139use SDL;
1132use SDL::OpenGL; 1140use SDL::OpenGL;
1133use SDL::OpenGL::Constants;
1134 1141
1135our @ISA = CFClient::Widget::; 1142our @ISA = CFClient::UI::Base::;
1136 1143
1137sub new { 1144sub new {
1138 my $class = shift; 1145 my $class = shift;
1139 1146
1140 $class->SUPER::new ( 1147 $class->SUPER::new (
1160 1167
1161sub update { 1168sub update {
1162 my ($self) = @_; 1169 my ($self) = @_;
1163 1170
1164 $self->{need_update} = 1; 1171 $self->{need_update} = 1;
1172 $self->SUPER::update;
1165} 1173}
1166 1174
1167sub _draw { 1175sub _draw {
1168 my ($self) = @_; 1176 my ($self) = @_;
1169 1177
1192 $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs}; 1200 $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs};
1193 } 1201 }
1194 1202
1195 glEnable GL_TEXTURE_2D; 1203 glEnable GL_TEXTURE_2D;
1196 glEnable GL_BLEND; 1204 glEnable GL_BLEND;
1205 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1197 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1206 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1198 1207
1199 my $sw4 = ($sw + 3) & ~3; 1208 my $sw4 = ($sw + 3) & ~3;
1200 my $darkness = "\x00" x ($sw4 * $sh); 1209 my $darkness = "\x00" x ($sw4 * $sh);
1201 1210
1231# 1240#
1232# $lighting = $pb->get_pixels; 1241# $lighting = $pb->get_pixels;
1233# $lighting =~ s/(.)../$1/gs; 1242# $lighting =~ s/(.)../$1/gs;
1234# } 1243# }
1235 1244
1236 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1237 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1245 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1238 1246
1239 $darkness = new CFClient::Texture 1247 $darkness = new CFClient::Texture
1240 width => $sw4, 1248 w => $sw4,
1241 height => $sh, 1249 h => $sh,
1242 data => $darkness, 1250 data => $darkness,
1243 internalformat => GL_ALPHA, 1251 internalformat => GL_ALPHA,
1244 format => GL_ALPHA; 1252 format => GL_ALPHA;
1245 1253
1246 glColor 0.45, 0.45, 0.45, 1; 1254 glColor 0.45, 0.45, 0.45, 1;
1306 } 1314 }
1307} 1315}
1308 1316
1309############################################################################# 1317#############################################################################
1310 1318
1311package CFClient::Widget::Animator; 1319package CFClient::UI::Animator;
1312 1320
1313use SDL::OpenGL; 1321use SDL::OpenGL;
1314 1322
1315our @ISA = CFClient::Widget::Bin::; 1323our @ISA = CFClient::UI::Bin::;
1316 1324
1317sub moveto { 1325sub moveto {
1318 my ($self, $x, $y) = @_; 1326 my ($self, $x, $y) = @_;
1319 1327
1320 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 1328 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
1348 glPopMatrix; 1356 glPopMatrix;
1349} 1357}
1350 1358
1351############################################################################# 1359#############################################################################
1352 1360
1353package CFClient::Widget::Toplevel; 1361package CFClient::UI::Toplevel;
1354 1362
1355our @ISA = CFClient::Widget::Container::; 1363our @ISA = CFClient::UI::Container::;
1356 1364
1357sub size_request { 1365sub size_request {
1358 ($::WIDTH, $::HEIGHT) 1366 ($::WIDTH, $::HEIGHT)
1359} 1367}
1360 1368
1394 $self->_draw; 1402 $self->_draw;
1395} 1403}
1396 1404
1397############################################################################# 1405#############################################################################
1398 1406
1399package CFClient::Widget; 1407package CFClient::UI;
1400 1408
1401$TOPLEVEL = new CFClient::Widget::Toplevel; 1409$TOPLEVEL = new CFClient::UI::Toplevel;
1402 1410
14031 14111
1404 1412

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines