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.148 by elmex, Sat Apr 22 12:14:45 2006 UTC vs.
Revision 1.162 by root, Mon Apr 24 06:05:35 2006 UTC

8use CFClient; 8use CFClient;
9 9
10our ($FOCUS, $HOVER, $GRAB); # various widgets 10our ($FOCUS, $HOVER, $GRAB); # various widgets
11 11
12our $ROOT; 12our $ROOT;
13our $TOOLTIP;
13our $BUTTON_STATE; 14our $BUTTON_STATE;
15
16sub check_tooltip {
17 if (!$GRAB) {
18 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) {
19 if (length $widget->{tooltip}) {
20
21 if ($TOOLTIP->{owner} != $widget) {
22 $TOOLTIP->{owner} = $widget;
23
24 my $tip = $widget->{tooltip};
25
26 $tip = $tip->($widget) if CODE:: eq ref $tip;
27
28 $TOOLTIP->set_markup ($widget->{tooltip});
29 $TOOLTIP->move ($widget->coord2global ($widget->{w}, 0));
30 $TOOLTIP->show;
31 }
32
33 return;
34 }
35 }
36 }
37
38 $TOOLTIP->hide;
39 delete $TOOLTIP->{owner};
40}
14 41
15# class methods for events 42# class methods for events
16sub feed_sdl_key_down_event { 43sub feed_sdl_key_down_event {
17 $FOCUS->key_down ($_[0]) if $FOCUS; 44 $FOCUS->key_down ($_[0]) if $FOCUS;
18} 45}
28 if (!$BUTTON_STATE) { 55 if (!$BUTTON_STATE) {
29 my $widget = $ROOT->find_widget ($x, $y); 56 my $widget = $ROOT->find_widget ($x, $y);
30 57
31 $GRAB = $widget; 58 $GRAB = $widget;
32 $GRAB->update if $GRAB; 59 $GRAB->update if $GRAB;
60
61 check_tooltip;
33 } 62 }
34 63
35 $BUTTON_STATE |= 1 << ($ev->{button} - 1); 64 $BUTTON_STATE |= 1 << ($ev->{button} - 1);
36 65
37 $GRAB->button_down ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; 66 $GRAB->button_down ($ev, $GRAB->coord2local ($x, $y)) if $GRAB;
49 78
50 if (!$BUTTON_STATE) { 79 if (!$BUTTON_STATE) {
51 my $grab = $GRAB; undef $GRAB; 80 my $grab = $GRAB; undef $GRAB;
52 $grab->update if $grab; 81 $grab->update if $grab;
53 $GRAB->update if $GRAB; 82 $GRAB->update if $GRAB;
83
84 check_tooltip;
54 } 85 }
55} 86}
56 87
57sub feed_sdl_motion_event { 88sub feed_sdl_motion_event {
58 my ($ev) = @_; 89 my ($ev) = @_;
63 if ($widget != $HOVER) { 94 if ($widget != $HOVER) {
64 my $hover = $HOVER; $HOVER = $widget; 95 my $hover = $HOVER; $HOVER = $widget;
65 96
66 $hover->update if $hover && $hover->{can_hover}; 97 $hover->update if $hover && $hover->{can_hover};
67 $HOVER->update if $HOVER && $HOVER->{can_hover}; 98 $HOVER->update if $HOVER && $HOVER->{can_hover};
99
100 check_tooltip;
68 } 101 }
69 102
70 $HOVER->mouse_motion ($ev, $HOVER->coord2local ($x, $y)) if $HOVER; 103 $HOVER->mouse_motion ($ev, $HOVER->coord2local ($x, $y)) if $HOVER;
71} 104}
72 105
96 129
97 my $self = bless { 130 my $self = bless {
98 x => 0, 131 x => 0,
99 y => 0, 132 y => 0,
100 z => 0, 133 z => 0,
134 can_events => 1,
101 @_ 135 @_
102 }, $class; 136 }, $class;
103 137
104 for (keys %$self) { 138 for (keys %$self) {
105 if (/^connect_(.*)$/) { 139 if (/^connect_(.*)$/) {
108 } 142 }
109 143
110 $self 144 $self
111} 145}
112 146
147sub destroy {
148 my ($self) = @_;
149
150 $self->hide;
151 %$self = ();
152}
153
113sub show { 154sub show {
114 my ($self) = @_; 155 my ($self) = @_;
115 156
116 return if $self->{parent}; 157 return if $self->{parent};
117 158
134 $self->{z} = $z if defined $z; 175 $self->{z} = $z if defined $z;
135 176
136 $self->update; 177 $self->update;
137} 178}
138 179
139sub needs_redraw { 180sub set_size {
140 0 181 my ($self, $w, $h) = @_;
182
183 $self->{user_w} = $w;
184 $self->{user_h} = $h;
185
186 $self->check_size;
141} 187}
142 188
143sub size_request { 189sub size_request {
144 require Carp; 190 require Carp;
145 Carp::confess "size_request is abstract"; 191 Carp::confess "size_request is abstract";
175 } 221 }
176} 222}
177 223
178sub size_allocate { 224sub size_allocate {
179 # nothing to be done 225 # nothing to be done
226}
227
228sub set_max_size {
229 my ($self, $w, $h) = @_;
230
231 delete $self->{max_w}; $self->{max_w} = $w if $w;
232 delete $self->{max_h}; $self->{max_h} = $h if $h;
180} 233}
181 234
182# return top left coordinates 235# return top left coordinates
183sub _topleft { 236sub _topleft {
184 my ($self, $x, $y) = @_; 237 my ($self, $x, $y) = @_;
267 glVertex $x + $self->{w}, $y + $self->{h}; 320 glVertex $x + $self->{w}, $y + $self->{h};
268 glVertex $x , $y + $self->{h}; 321 glVertex $x , $y + $self->{h};
269 glEnd; 322 glEnd;
270 glDisable GL_BLEND; 323 glDisable GL_BLEND;
271 } 324 }
325
326 if ($ENV{PCLIENT_DEBUG}) {
327 glPushMatrix;
328 glColor 1, 1, 0, 1;
329 glTranslate $self->{x} + 0.375, $self->{y} + 0.375;
330 glBegin GL_LINE_LOOP;
331 glVertex 0 , 0;
332 glVertex $self->{w}, 0;
333 glVertex $self->{w}, $self->{h};
334 glVertex 0 , $self->{h};
335 glEnd;
336 glPopMatrix;
337 CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw;
338 }
272} 339}
273 340
274sub _draw { 341sub _draw {
275 my ($self) = @_; 342 my ($self) = @_;
276 343
277 warn "no draw defined for $self\n"; 344 warn "no draw defined for $self\n";
278} 345}
279 346
280sub find_widget { 347sub find_widget {
281 my ($self, $x, $y) = @_; 348 my ($self, $x, $y) = @_;
349
350 return () unless $self->{can_events};
282 351
283 return $self 352 return $self
284 if $x >= $self->{x} && $x < $self->{x} + $self->{w} 353 if $x >= $self->{x} && $x < $self->{x} + $self->{w}
285 && $y >= $self->{y} && $y < $self->{y} + $self->{h}; 354 && $y >= $self->{y} && $y < $self->{y} + $self->{h};
286 355
294} 363}
295 364
296sub check_size { 365sub check_size {
297 my ($self) = @_; 366 my ($self) = @_;
298 367
299 my ($w, $h) = $self->size_request; 368 $self->{parent}
369 or return 1;
300 370
371 my ($w, $h) = $self->{user_w} && $self->{user_h}
372 ? @$self{qw(user_w user_h)}
373 : $self->size_request;
374
301 if ($w != $self->{req_w} || $h != $self->{req_h}) { 375 if ($w != $self->{req_w} || $h != $self->{req_h}) {
302 $self->{req_w} = $w; 376 $self->{req_w} = $w;
303 $self->{req_h} = $h; 377 $self->{req_h} = $h;
304 378
305 $self->{parent}->check_size 379 $self->{parent}->check_size
306 if $self->{parent}; 380 or $self->size_allocate (
381 (List::Util::max $self->{w}, $w),
382 (List::Util::max $self->{h}, $h),
383 );
384
385 1
386 } else {
387 0
307 } 388 }
308} 389}
309 390
310sub update { 391sub update {
311 my ($self) = @_; 392 my ($self) = @_;
378 459
379package CFClient::UI::Empty; 460package CFClient::UI::Empty;
380 461
381our @ISA = CFClient::UI::Base::; 462our @ISA = CFClient::UI::Base::;
382 463
464sub new {
465 my ($class, %arg) = @_;
466 $class->SUPER::new (can_events => 0, %arg);
467}
468
383sub size_request { 469sub size_request {
384 (0, 0) 470 (0, 0)
385} 471}
386 472
387sub draw { } 473sub draw { }
395sub new { 481sub new {
396 my ($class, %arg) = @_; 482 my ($class, %arg) = @_;
397 483
398 my $children = delete $arg{children} || []; 484 my $children = delete $arg{children} || [];
399 485
400 my $self = $class->SUPER::new (children => [], %arg); 486 my $self = $class->SUPER::new (children => [], can_events => 0, %arg);
401 $self->add ($_) for @$children; 487 $self->add ($_) for @$children;
402 488
403 $self 489 $self
404} 490}
405 491
424 delete $child->{parent}; 510 delete $child->{parent};
425 511
426 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; 512 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
427 513
428 $self->check_size; 514 $self->check_size;
515 $self->update;
516}
517
518sub clear {
519 my ($self) = @_;
520
521 delete $_->{parent}
522 for @{ delete $self->{children} };
523
524 $self->{children} = [];
429} 525}
430 526
431sub find_widget { 527sub find_widget {
432 my ($self, $x, $y) = @_; 528 my ($self, $x, $y) = @_;
433 529
561sub new { die } 657sub new { die }
562 658
563sub size_request { 659sub size_request {
564 my ($self) = @_; 660 my ($self) = @_;
565 661
566 @$self{qw(child_w child_h)} = $self->child->size_request; 662 @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)};
567 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); 663 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)});
568 664
569 @$self{qw(child_w child_h)} 665 @$self{qw(child_w child_h)}
570} 666}
571 667
593 border => 0.8, 689 border => 0.8,
594 @_ 690 @_
595 ); 691 );
596 692
597 $self 693 $self
598}
599
600sub set_size {
601 my ($self, $w, $h) = @_;
602 $self->{req_w} = $w;
603 $self->{req_h} = $h;
604 $self->check_size;
605}
606
607sub size_request {
608 my ($self) = @_;
609 ($self->{req_w}, $self->{req_h})
610}
611
612sub size_allocate {
613 my ($self, $w, $h) = @_;
614 $self->{w} = $w;
615 $self->{h} = $h;
616 $self->child->configure (0, 0, $w, $h);
617} 694}
618 695
619sub _draw { 696sub _draw {
620 my ($self) = @_; 697 my ($self) = @_;
621 698
659 736
660 my $self = $class->SUPER::new ( 737 my $self = $class->SUPER::new (
661 bg => [1, 1, 1, 1], 738 bg => [1, 1, 1, 1],
662 border_bg => [1, 1, 1, 1], 739 border_bg => [1, 1, 1, 1],
663 border => 0.8, 740 border => 0.8,
741 can_events => 1,
664 @_ 742 @_
665 ); 743 );
666 744
667 $self->{title} &&= new CFClient::UI::Label 745 $self->{title} &&= new CFClient::UI::Label
668 align => 0, 746 align => 0,
678} 756}
679 757
680sub size_request { 758sub size_request {
681 my ($self) = @_; 759 my ($self) = @_;
682 760
683 return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h};
684
685 my ($w, $h) = $self->SUPER::size_request; 761 my ($w, $h) = $self->SUPER::size_request;
686 762
687 ( 763 (
688 $w + $self->border * 2, 764 $w + $self->border * 2,
689 $h + $self->border * 2, 765 $h + $self->border * 2,
837 or next; 913 or next;
838 914
839 for my $x (0 .. $#$row) { 915 for my $x (0 .. $#$row) {
840 my $widget = $row->[$x] 916 my $widget = $row->[$x]
841 or next; 917 or next;
842 my ($w, $h) = $widget->size_request; 918 my ($w, $h) = @$widget{qw(req_w req_h)};
843 919
844 $w[$x] = max $w[$x], $w; 920 $w[$x] = max $w[$x], $w;
845 $h[$y] = max $h[$y], $h; 921 $h[$y] = max $h[$y], $h;
846 } 922 }
847 } 923 }
952 1028
953 ($h, $w) = ($w, $h); 1029 ($h, $w) = ($w, $h);
954 1030
955 my $children = $self->{children}; 1031 my $children = $self->{children};
956 1032
957 my @h = map +($_->size_request)[0], @$children; 1033 my @h = map $_->{req_w}, @$children;
958 1034
959 my $req_h = List::Util::sum @h; 1035 my $req_h = List::Util::sum @h;
960 1036
961 if ($req_h > $h) { 1037 if ($req_h > $h) {
962 # ah well, not enough space 1038 # ah well, not enough space
1010sub size_allocate { 1086sub size_allocate {
1011 my ($self, $w, $h) = @_; 1087 my ($self, $w, $h) = @_;
1012 1088
1013 my $children = $self->{children}; 1089 my $children = $self->{children};
1014 1090
1015 my @h = map +($_->size_request)[1], @$children; 1091 my @h = map $_->{req_h}, @$children;
1016 1092
1017 my $req_h = List::Util::sum @h; 1093 my $req_h = List::Util::sum @h;
1018 1094
1019 if ($req_h > $h) { 1095 if ($req_h > $h) {
1020 # ah well, not enough space 1096 # ah well, not enough space
1055sub new { 1131sub new {
1056 my ($class, %arg) = @_; 1132 my ($class, %arg) = @_;
1057 1133
1058 my $self = $class->SUPER::new ( 1134 my $self = $class->SUPER::new (
1059 fg => [1, 1, 1], 1135 fg => [1, 1, 1],
1136 #font => default_font
1060 fontsize => 1, 1137 fontsize => 1,
1061 text => "", 1138 text => "",
1062 align => -1, 1139 align => -1,
1063 valign => -1, 1140 valign => -1,
1064 padding => 2, 1141 padding => 2,
1065 layout => new CFClient::Layout, 1142 layout => new CFClient::Layout,
1143 can_events => 0,
1066 %arg 1144 %arg
1067 ); 1145 );
1068 1146
1069 if (exists $self->{template}) { 1147 if (exists $self->{template}) {
1070 my $layout = new CFClient::Layout; 1148 my $layout = new CFClient::Layout;
1076 $self->set_markup (delete $self->{markup}) if exists $self->{markup}; 1154 $self->set_markup (delete $self->{markup}) if exists $self->{markup};
1077 1155
1078 $self 1156 $self
1079} 1157}
1080 1158
1081sub escape_text { 1159sub escape {
1082 local $_ = $_[1]; 1160 local $_ = $_[1];
1083 1161
1084 s/&/&amp;/g; 1162 s/&/&amp;/g;
1085 s/>/&gt;/g; 1163 s/>/&gt;/g;
1086 s/</&lt;/g; 1164 s/</&lt;/g;
1092 my ($self, $text) = @_; 1170 my ($self, $text) = @_;
1093 1171
1094 $self->{layout}->set_text ($text); 1172 $self->{layout}->set_text ($text);
1095 1173
1096 delete $self->{texture}; 1174 delete $self->{texture};
1175 $self->check_size;
1097 $self->update; 1176 $self->update;
1098} 1177}
1099 1178
1100sub set_markup { 1179sub set_markup {
1101 my ($self, $markup) = @_; 1180 my ($self, $markup) = @_;
1102 1181
1103 $self->{layout}->set_markup ($markup); 1182 $self->{layout}->set_markup ($markup);
1104 1183
1105 delete $self->{texture}; 1184 delete $self->{texture};
1185 $self->check_size;
1106 $self->update; 1186 $self->update;
1107} 1187}
1108 1188
1109sub size_request { 1189sub size_request {
1110 my ($self) = @_; 1190 my ($self) = @_;
1111 1191
1112 $self->{layout}->set_width; 1192 $self->{layout}->set_font ($self->{font}) if $self->{font};
1193 $self->{layout}->set_width ($self->{max_w} || -1);
1113 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1194 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1114 1195
1115 my ($w, $h) = $self->{layout}->size; 1196 my ($w, $h) = $self->{layout}->size;
1116 1197
1117 if (exists $self->{template}) { 1198 if (exists $self->{template}) {
1199 $self->{template}->set_font ($self->{font}) if $self->{font};
1118 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); 1200 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE);
1119 1201
1120 my ($w2, $h2) = $self->{template}->size; 1202 my ($w2, $h2) = $self->{template}->size;
1121 1203
1122 $w = List::Util::max $w, $w2; 1204 $w = List::Util::max $w, $w2;
1137 1219
1138sub set_fontsize { 1220sub set_fontsize {
1139 my ($self, $fontsize) = @_; 1221 my ($self, $fontsize) = @_;
1140 1222
1141 $self->{fontsize} = $fontsize; 1223 $self->{fontsize} = $fontsize;
1224 delete $self->{texture};
1142 $self->check_size; 1225 $self->check_size;
1226 $self->update;
1143} 1227}
1144 1228
1145sub _draw { 1229sub _draw {
1146 my ($self) = @_; 1230 my ($self) = @_;
1147 1231
1148 my $tex = $self->{texture} ||= do { 1232 my $tex = $self->{texture} ||= do {
1233 $self->{layout}->set_font ($self->{font}) if $self->{font};
1149 $self->{layout}->set_width ($self->{w}); 1234 $self->{layout}->set_width ($self->{w});
1150 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); 1235 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE);
1151 new_from_layout CFClient::Texture $self->{layout} 1236 new_from_layout CFClient::Texture $self->{layout}
1152 }; 1237 };
1153 1238
1193 active_bg => [1, 1, 1, 0.5], 1278 active_bg => [1, 1, 1, 0.5],
1194 active_fg => [0, 0, 0], 1279 active_fg => [0, 0, 0],
1195 can_hover => 1, 1280 can_hover => 1,
1196 can_focus => 1, 1281 can_focus => 1,
1197 valign => 0, 1282 valign => 0,
1283 can_events => 1,
1198 @_ 1284 @_
1199 ) 1285 )
1200} 1286}
1201 1287
1202sub _set_text { 1288sub _set_text {
1230} 1316}
1231 1317
1232sub size_allocate { 1318sub size_allocate {
1233 my ($self, $w, $h) = @_; 1319 my ($self, $w, $h) = @_;
1234 1320
1235 $self->_set_text ($self->{text}); 1321 $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text
1236} 1322}
1237 1323
1238sub set_text { 1324sub set_text {
1239 my ($self, $text) = @_; 1325 my ($self, $text) = @_;
1240 1326
1387 bg => [1, 1, 1, 0.2], 1473 bg => [1, 1, 1, 0.2],
1388 active_fg => [0, 0, 1], 1474 active_fg => [0, 0, 1],
1389 can_hover => 1, 1475 can_hover => 1,
1390 align => 0, 1476 align => 0,
1391 valign => 0, 1477 valign => 0,
1478 can_events => 1,
1392 @_ 1479 @_
1393 ) 1480 )
1394} 1481}
1395 1482
1396sub button_up { 1483sub button_up {
1501our %loaded_images; 1588our %loaded_images;
1502 1589
1503sub new { 1590sub new {
1504 my $class = shift; 1591 my $class = shift;
1505 1592
1506 my $self = $class->SUPER::new (@_); 1593 my $self = $class->SUPER::new (can_events => 0, @_);
1507 1594
1508 $self->{image} or confess "Image has 'image' not set. This is a fatal error!"; 1595 $self->{image} or confess "Image has 'image' not set. This is a fatal error!";
1509 1596
1510 $loaded_images{$self->{image}} ||= 1597 $loaded_images{$self->{image}} ||=
1511 new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1; 1598 new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1;
1553############################################################################# 1640#############################################################################
1554 1641
1555package CFClient::UI::VGauge; 1642package CFClient::UI::VGauge;
1556 1643
1557our @ISA = CFClient::UI::Base::; 1644our @ISA = CFClient::UI::Base::;
1645
1646use List::Util qw(min max);
1558 1647
1559use CFClient::OpenGL; 1648use CFClient::OpenGL;
1560 1649
1561my %tex = ( 1650my %tex = (
1562 food => [ 1651 food => [
1563 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1652 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1564 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 1653 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1565 ], 1654 ],
1566 grace => [ 1655 grace => [
1567 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1656 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1568 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ 1657 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/
1569 ], 1658 ],
1570 hp => [ 1659 hp => [
1571 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1660 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1572 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 1661 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1573 ], 1662 ],
1574 mana => [ 1663 mana => [
1575 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1664 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1576 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ 1665 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/
1577 ], 1666 ],
1578); 1667);
1579 1668
1580# eg. VGauge->new (gauge => 'food'), default gauge: food 1669# eg. VGauge->new (gauge => 'food'), default gauge: food
1581sub new { 1670sub new {
1619 1708
1620sub _draw { 1709sub _draw {
1621 my ($self) = @_; 1710 my ($self) = @_;
1622 1711
1623 my $tex = $tex{$self->{type}}; 1712 my $tex = $tex{$self->{type}};
1713 my ($t1, $t2, $t3) = @$tex;
1624 1714
1625 my ($w, $h) = ($self->{w}, $self->{h}); 1715 my ($w, $h) = ($self->{w}, $self->{h});
1626 1716
1627 if ($self->{vertical}) { 1717 if ($self->{vertical}) {
1628 glRotate 90, 0, 0, 1; 1718 glRotate 90, 0, 0, 1;
1630 1720
1631 ($w, $h) = ($h, $w); 1721 ($w, $h) = ($h, $w);
1632 } 1722 }
1633 1723
1634 my $ycut = $self->{val} / ($self->{max_val} || 1); 1724 my $ycut = $self->{val} / ($self->{max_val} || 1);
1635 $ycut = 1 if $self->{val} > $self->{max_val};
1636 1725
1637 my $t1 = $tex->[0]; 1726 my $ycut1 = max 0, min 1, $ycut;
1638 my $t2 = $tex->[1]; 1727 my $ycut2 = max 0, min 1, $ycut - 1;
1728
1729 my $h1 = $self->{h} * (1 - $ycut1);
1730 my $h2 = $self->{h} * (1 - $ycut2);
1639 1731
1640 glEnable GL_BLEND; 1732 glEnable GL_BLEND;
1641 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1733 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1642 glEnable GL_TEXTURE_2D; 1734 glEnable GL_TEXTURE_2D;
1643 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1735 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1644 1736
1645 my $h1 = $self->{h} - $ycut * $self->{h};
1646 my $h2 = $ycut * $self->{h};
1647
1648 glBindTexture GL_TEXTURE_2D, $t1->{name}; 1737 glBindTexture GL_TEXTURE_2D, $t1->{name};
1649 glBegin GL_QUADS; 1738 glBegin GL_QUADS;
1650 glTexCoord 0 , 0; glVertex 0 , 0; 1739 glTexCoord 0 , 0; glVertex 0 , 0;
1651 glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $h1; 1740 glTexCoord 0 , $t1->{t} * (1 - $ycut1); glVertex 0 , $h1;
1652 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex $w, $h1; 1741 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut1); glVertex $w, $h1;
1653 glTexCoord $t1->{s}, 0; glVertex $w, 0; 1742 glTexCoord $t1->{s}, 0; glVertex $w, 0;
1654 glEnd; 1743 glEnd;
1655 1744
1745 my $ycut1 = List::Util::min 1, $ycut;
1656 glBindTexture GL_TEXTURE_2D, $t2->{name}; 1746 glBindTexture GL_TEXTURE_2D, $t2->{name};
1657 glBegin GL_QUADS; 1747 glBegin GL_QUADS;
1658 glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $h1; 1748 glTexCoord 0 , $t2->{t} * (1 - $ycut1); glVertex 0 , $h1;
1659 glTexCoord 0 , $t2->{t}; glVertex 0 , $h1 + $h2; 1749 glTexCoord 0 , $t2->{t} * (1 - $ycut2); glVertex 0 , $h2;
1660 glTexCoord $t2->{s}, $t2->{t}; glVertex $w, $h1 + $h2; 1750 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut2); glVertex $w, $h2;
1661 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex $w, $h1; 1751 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut1); glVertex $w, $h1;
1662 glEnd; 1752 glEnd;
1753
1754 if ($t3) {
1755 glBindTexture GL_TEXTURE_2D, $t3->{name};
1756 glBegin GL_QUADS;
1757 glTexCoord 0 , $t3->{t} * (1 - $ycut2); glVertex 0 , $h2;
1758 glTexCoord 0 , $t3->{t}; glVertex 0 , $self->{h};
1759 glTexCoord $t3->{s}, $t3->{t}; glVertex $w, $self->{h};
1760 glTexCoord $t3->{s}, $t3->{t} * (1 - $ycut2); glVertex $w, $h2;
1761 glEnd;
1762 }
1663 1763
1664 glDisable GL_BLEND; 1764 glDisable GL_BLEND;
1665 glDisable GL_TEXTURE_2D; 1765 glDisable GL_TEXTURE_2D;
1666} 1766}
1667 1767
1670package CFClient::UI::Gauge; 1770package CFClient::UI::Gauge;
1671 1771
1672our @ISA = CFClient::UI::VBox::; 1772our @ISA = CFClient::UI::VBox::;
1673 1773
1674sub new { 1774sub new {
1675 my ($class, %arg) = shift; 1775 my ($class, %arg) = @_;
1676 1776
1677 my $self = $class->SUPER::new ( 1777 my $self = $class->SUPER::new (
1678 @_, 1778 tooltip => $arg{type},
1779 can_events => 1,
1780 can_hover => 1,
1781 %arg,
1679 ); 1782 );
1680 1783
1681 $self->add ($self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); 1784 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999");
1682 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1); 1785 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1);
1683 $self->add ($self->{max} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); 1786 $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999");
1684 1787
1685 $self 1788 $self
1686} 1789}
1687 1790
1688sub set_fontsize { 1791sub set_fontsize {
1855sub new { 1958sub new {
1856 my $class = shift; 1959 my $class = shift;
1857 1960
1858 my $self = $class->SUPER::new ( 1961 my $self = $class->SUPER::new (
1859 fontsize => 1, 1962 fontsize => 1,
1963 #font => default_font
1860 @_, 1964 @_,
1861 1965
1862 layout => (new CFClient::Layout), 1966 layout => (new CFClient::Layout),
1863 par => [], 1967 par => [],
1864 height => 0, 1968 height => 0,
1904sub size_allocate { 2008sub size_allocate {
1905 my ($self, $w, $h) = @_; 2009 my ($self, $w, $h) = @_;
1906 2010
1907 $self->SUPER::size_allocate ($w, $h); 2011 $self->SUPER::size_allocate ($w, $h);
1908 2012
2013 $self->{layout}->set_font ($self->{font}) if $self->{font};
1909 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 2014 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1910 $self->{layout}->set_width ($self->{children}[0]{w}); 2015 $self->{layout}->set_width ($self->{children}[0]{w});
1911 2016
1912 $self->reflow; 2017 $self->reflow;
1913} 2018}
1965 my $y1 = $top + $self->{h}; 2070 my $y1 = $top + $self->{h};
1966 2071
1967 my $y = 0; 2072 my $y = 0;
1968 2073
1969 my $layout = $self->{layout}; 2074 my $layout = $self->{layout};
2075
2076 $layout->set_font ($self->{font}) if $self->{font};
1970 2077
1971 for my $par (@{$self->{par}}) { 2078 for my $par (@{$self->{par}}) {
1972 my $h = $par->[0]; 2079 my $h = $par->[0];
1973 2080
1974 if ($y0 < $y + $h && $y < $y1) { 2081 if ($y0 < $y + $h && $y < $y1) {
2054 my $class = shift; 2161 my $class = shift;
2055 2162
2056 my $self = $class->SUPER::new ( 2163 my $self = $class->SUPER::new (
2057 state => 0, 2164 state => 0,
2058 connect_activate => \&toggle_flopper, 2165 connect_activate => \&toggle_flopper,
2166 can_events => 1,
2059 @_ 2167 @_
2060 ); 2168 );
2061 2169
2062 if ($self->{state}) { 2170 if ($self->{state}) {
2063 $self->{state} = 0; 2171 $self->{state} = 0;
2083 $self->emit (changed => $self->{state}); 2191 $self->emit (changed => $self->{state});
2084} 2192}
2085 2193
2086############################################################################# 2194#############################################################################
2087 2195
2196package CFClient::UI::Tooltip;
2197
2198our @ISA = CFClient::UI::Bin::;
2199
2200use CFClient::OpenGL;
2201
2202sub new {
2203 my $class = shift;
2204
2205 $class->SUPER::new (
2206 @_,
2207 can_events => 0,
2208 )
2209}
2210
2211sub set_markup {
2212 my ($self, $text) = @_;
2213
2214 $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0];
2215 $self->{label}->set_markup ($text);
2216 $self->add ($self->{label});
2217}
2218
2219sub size_request {
2220 my ($self) = @_;
2221
2222 $self->child->set_max_size ($::WIDTH * 0.3);
2223
2224 my ($w, $h) = @{$self->child}{qw(req_w req_h)};
2225
2226 ($w + 4, $h + 4)
2227}
2228
2229sub size_allocate {
2230 my ($self, $w, $h) = @_;
2231
2232 $self->SUPER::size_allocate ($w - 4, $h - 4);
2233}
2234
2235sub _draw {
2236 my ($self) = @_;
2237
2238 glPushMatrix;
2239 glTranslate 0.375, 0.375;
2240
2241 my ($w, $h) = @$self{qw(w h)};
2242
2243 glColor 1, 0.8, 0.4;
2244 glBegin GL_QUADS;
2245 glVertex 0 , 0;
2246 glVertex 0 , $h;
2247 glVertex $w, $h;
2248 glVertex $w, 0;
2249 glEnd;
2250
2251 glColor 0, 0, 0;
2252 glBegin GL_LINE_LOOP;
2253 glVertex 0 , 0;
2254 glVertex 0 , $h;
2255 glVertex $w, $h;
2256 glVertex $w, 0;
2257 glEnd;
2258
2259 glPopMatrix;
2260
2261 glTranslate 2, 2;
2262 $self->SUPER::_draw;
2263}
2264
2265#############################################################################
2266
2267package CFClient::UI::Face;
2268
2269our @ISA = CFClient::UI::Base::;
2270
2271use CFClient::OpenGL;
2272
2273sub new {
2274 my $class = shift;
2275
2276 $class->SUPER::new (
2277 aspect => 1,
2278 @_,
2279 )
2280}
2281
2282sub size_request {
2283 (32, 8)
2284}
2285
2286sub draw {
2287 my ($self) = @_;
2288
2289 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]];
2290
2291 if ($tex) {
2292 glEnable GL_BLEND;
2293 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
2294 glEnable GL_TEXTURE_2D;
2295 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2296 glColor 1, 1, 1, 1;
2297 $tex->draw_quad (0, 0, $self->{w}, $self->{h});
2298 glDisable GL_TEXTURE_2D;
2299 glDisable GL_BLEND;
2300 }
2301}
2302
2303#############################################################################
2304
2088package CFClient::UI::Root; 2305package CFClient::UI::Root;
2089 2306
2090our @ISA = CFClient::UI::Container::; 2307our @ISA = CFClient::UI::Container::;
2091 2308
2092use CFClient::OpenGL; 2309use CFClient::OpenGL;
2093 2310
2094sub check_size { 2311sub check_size {
2095 my ($self) = @_; 2312 my ($self) = @_;
2096 2313
2097 $self->configure (0, 0, $::WITH, $::HEIGHT); 2314 $self->configure (0, 0, $::WIDTH, $::HEIGHT);
2098} 2315}
2099 2316
2100sub size_request { 2317sub size_request {
2101 ($::WIDTH, $::HEIGHT) 2318 ($::WIDTH, $::HEIGHT)
2102} 2319}
2104sub configure { 2321sub configure {
2105 my ($self, $x, $y, $w, $h) = @_; 2322 my ($self, $x, $y, $w, $h) = @_;
2106 2323
2107 $self->SUPER::configure ($x, $y, $w, $h); 2324 $self->SUPER::configure ($x, $y, $w, $h);
2108 2325
2109 $_->configure ($_->{x}, $_->{y}, $_->size_request)
2110 for @{$self->{children}}; 2326 for my $child (@{$self->{children}}) {
2327 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)};
2328
2329 $X = List::Util::max 0, List::Util::min $w - $W, $X;
2330 $Y = List::Util::max 0, List::Util::min $h - $H, $Y;
2331 $child->configure ($X, $Y, $W,$H);
2332 }
2111} 2333}
2112 2334
2113sub _topleft { 2335sub _topleft {
2114 my ($self, $x, $y) = @_; 2336 my ($self, $x, $y) = @_;
2115 2337
2162############################################################################# 2384#############################################################################
2163 2385
2164package CFClient::UI; 2386package CFClient::UI;
2165 2387
2166$ROOT = new CFClient::UI::Root; 2388$ROOT = new CFClient::UI::Root;
2389$TOOLTIP = new CFClient::UI::Tooltip;
2167 2390
21681 23911
2169 2392

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines