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.149 by root, Sat Apr 22 23:11:32 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 return unless $self->{parent}; 368 $self->{parent}
369 or return 1;
300 370
301 my ($w, $h) = $self->size_request; 371 my ($w, $h) = $self->{user_w} && $self->{user_h}
372 ? @$self{qw(user_w user_h)}
373 : $self->size_request;
302 374
303 if ($w != $self->{req_w} || $h != $self->{req_h}) { 375 if ($w != $self->{req_w} || $h != $self->{req_h}) {
304 $self->{req_w} = $w; 376 $self->{req_w} = $w;
305 $self->{req_h} = $h; 377 $self->{req_h} = $h;
306 378
307 $self->{parent}->check_size; 379 $self->{parent}->check_size
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
308 } 388 }
309} 389}
310 390
311sub update { 391sub update {
312 my ($self) = @_; 392 my ($self) = @_;
379 459
380package CFClient::UI::Empty; 460package CFClient::UI::Empty;
381 461
382our @ISA = CFClient::UI::Base::; 462our @ISA = CFClient::UI::Base::;
383 463
464sub new {
465 my ($class, %arg) = @_;
466 $class->SUPER::new (can_events => 0, %arg);
467}
468
384sub size_request { 469sub size_request {
385 (0, 0) 470 (0, 0)
386} 471}
387 472
388sub draw { } 473sub draw { }
396sub new { 481sub new {
397 my ($class, %arg) = @_; 482 my ($class, %arg) = @_;
398 483
399 my $children = delete $arg{children} || []; 484 my $children = delete $arg{children} || [];
400 485
401 my $self = $class->SUPER::new (children => [], %arg); 486 my $self = $class->SUPER::new (children => [], can_events => 0, %arg);
402 $self->add ($_) for @$children; 487 $self->add ($_) for @$children;
403 488
404 $self 489 $self
405} 490}
406 491
425 delete $child->{parent}; 510 delete $child->{parent};
426 511
427 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; 512 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
428 513
429 $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} = [];
430} 525}
431 526
432sub find_widget { 527sub find_widget {
433 my ($self, $x, $y) = @_; 528 my ($self, $x, $y) = @_;
434 529
594 border => 0.8, 689 border => 0.8,
595 @_ 690 @_
596 ); 691 );
597 692
598 $self 693 $self
599}
600
601sub set_size {
602 my ($self, $w, $h) = @_;
603 $self->{req_w} = $w;
604 $self->{req_h} = $h;
605 $self->check_size;
606}
607
608sub size_request {
609 my ($self) = @_;
610 ($self->{req_w}, $self->{req_h})
611}
612
613sub size_allocate {
614 my ($self, $w, $h) = @_;
615 $self->{w} = $w;
616 $self->{h} = $h;
617 $self->child->configure (0, 0, $w, $h);
618} 694}
619 695
620sub _draw { 696sub _draw {
621 my ($self) = @_; 697 my ($self) = @_;
622 698
660 736
661 my $self = $class->SUPER::new ( 737 my $self = $class->SUPER::new (
662 bg => [1, 1, 1, 1], 738 bg => [1, 1, 1, 1],
663 border_bg => [1, 1, 1, 1], 739 border_bg => [1, 1, 1, 1],
664 border => 0.8, 740 border => 0.8,
741 can_events => 1,
665 @_ 742 @_
666 ); 743 );
667 744
668 $self->{title} &&= new CFClient::UI::Label 745 $self->{title} &&= new CFClient::UI::Label
669 align => 0, 746 align => 0,
678 int $_[0]{border} * $::FONTSIZE 755 int $_[0]{border} * $::FONTSIZE
679} 756}
680 757
681sub size_request { 758sub size_request {
682 my ($self) = @_; 759 my ($self) = @_;
683
684 return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h};
685 760
686 my ($w, $h) = $self->SUPER::size_request; 761 my ($w, $h) = $self->SUPER::size_request;
687 762
688 ( 763 (
689 $w + $self->border * 2, 764 $w + $self->border * 2,
1056sub new { 1131sub new {
1057 my ($class, %arg) = @_; 1132 my ($class, %arg) = @_;
1058 1133
1059 my $self = $class->SUPER::new ( 1134 my $self = $class->SUPER::new (
1060 fg => [1, 1, 1], 1135 fg => [1, 1, 1],
1136 #font => default_font
1061 fontsize => 1, 1137 fontsize => 1,
1062 text => "", 1138 text => "",
1063 align => -1, 1139 align => -1,
1064 valign => -1, 1140 valign => -1,
1065 padding => 2, 1141 padding => 2,
1066 layout => new CFClient::Layout, 1142 layout => new CFClient::Layout,
1143 can_events => 0,
1067 %arg 1144 %arg
1068 ); 1145 );
1069 1146
1070 if (exists $self->{template}) { 1147 if (exists $self->{template}) {
1071 my $layout = new CFClient::Layout; 1148 my $layout = new CFClient::Layout;
1077 $self->set_markup (delete $self->{markup}) if exists $self->{markup}; 1154 $self->set_markup (delete $self->{markup}) if exists $self->{markup};
1078 1155
1079 $self 1156 $self
1080} 1157}
1081 1158
1082sub escape_text { 1159sub escape {
1083 local $_ = $_[1]; 1160 local $_ = $_[1];
1084 1161
1085 s/&/&amp;/g; 1162 s/&/&amp;/g;
1086 s/>/&gt;/g; 1163 s/>/&gt;/g;
1087 s/</&lt;/g; 1164 s/</&lt;/g;
1110} 1187}
1111 1188
1112sub size_request { 1189sub size_request {
1113 my ($self) = @_; 1190 my ($self) = @_;
1114 1191
1115 $self->{layout}->set_width; 1192 $self->{layout}->set_font ($self->{font}) if $self->{font};
1193 $self->{layout}->set_width ($self->{max_w} || -1);
1116 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1194 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1117 1195
1118 my ($w, $h) = $self->{layout}->size; 1196 my ($w, $h) = $self->{layout}->size;
1119 1197
1120 if (exists $self->{template}) { 1198 if (exists $self->{template}) {
1199 $self->{template}->set_font ($self->{font}) if $self->{font};
1121 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); 1200 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE);
1122 1201
1123 my ($w2, $h2) = $self->{template}->size; 1202 my ($w2, $h2) = $self->{template}->size;
1124 1203
1125 $w = List::Util::max $w, $w2; 1204 $w = List::Util::max $w, $w2;
1140 1219
1141sub set_fontsize { 1220sub set_fontsize {
1142 my ($self, $fontsize) = @_; 1221 my ($self, $fontsize) = @_;
1143 1222
1144 $self->{fontsize} = $fontsize; 1223 $self->{fontsize} = $fontsize;
1224 delete $self->{texture};
1145 $self->check_size; 1225 $self->check_size;
1226 $self->update;
1146} 1227}
1147 1228
1148sub _draw { 1229sub _draw {
1149 my ($self) = @_; 1230 my ($self) = @_;
1150 1231
1151 my $tex = $self->{texture} ||= do { 1232 my $tex = $self->{texture} ||= do {
1233 $self->{layout}->set_font ($self->{font}) if $self->{font};
1152 $self->{layout}->set_width ($self->{w}); 1234 $self->{layout}->set_width ($self->{w});
1153 $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);
1154 new_from_layout CFClient::Texture $self->{layout} 1236 new_from_layout CFClient::Texture $self->{layout}
1155 }; 1237 };
1156 1238
1196 active_bg => [1, 1, 1, 0.5], 1278 active_bg => [1, 1, 1, 0.5],
1197 active_fg => [0, 0, 0], 1279 active_fg => [0, 0, 0],
1198 can_hover => 1, 1280 can_hover => 1,
1199 can_focus => 1, 1281 can_focus => 1,
1200 valign => 0, 1282 valign => 0,
1283 can_events => 1,
1201 @_ 1284 @_
1202 ) 1285 )
1203} 1286}
1204 1287
1205sub _set_text { 1288sub _set_text {
1390 bg => [1, 1, 1, 0.2], 1473 bg => [1, 1, 1, 0.2],
1391 active_fg => [0, 0, 1], 1474 active_fg => [0, 0, 1],
1392 can_hover => 1, 1475 can_hover => 1,
1393 align => 0, 1476 align => 0,
1394 valign => 0, 1477 valign => 0,
1478 can_events => 1,
1395 @_ 1479 @_
1396 ) 1480 )
1397} 1481}
1398 1482
1399sub button_up { 1483sub button_up {
1504our %loaded_images; 1588our %loaded_images;
1505 1589
1506sub new { 1590sub new {
1507 my $class = shift; 1591 my $class = shift;
1508 1592
1509 my $self = $class->SUPER::new (@_); 1593 my $self = $class->SUPER::new (can_events => 0, @_);
1510 1594
1511 $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!";
1512 1596
1513 $loaded_images{$self->{image}} ||= 1597 $loaded_images{$self->{image}} ||=
1514 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;
1556############################################################################# 1640#############################################################################
1557 1641
1558package CFClient::UI::VGauge; 1642package CFClient::UI::VGauge;
1559 1643
1560our @ISA = CFClient::UI::Base::; 1644our @ISA = CFClient::UI::Base::;
1645
1646use List::Util qw(min max);
1561 1647
1562use CFClient::OpenGL; 1648use CFClient::OpenGL;
1563 1649
1564my %tex = ( 1650my %tex = (
1565 food => [ 1651 food => [
1566 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1652 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1567 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 1653 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1568 ], 1654 ],
1569 grace => [ 1655 grace => [
1570 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1656 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1571 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/
1572 ], 1658 ],
1573 hp => [ 1659 hp => [
1574 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1660 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1575 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 1661 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1576 ], 1662 ],
1577 mana => [ 1663 mana => [
1578 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1664 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1579 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/
1580 ], 1666 ],
1581); 1667);
1582 1668
1583# eg. VGauge->new (gauge => 'food'), default gauge: food 1669# eg. VGauge->new (gauge => 'food'), default gauge: food
1584sub new { 1670sub new {
1622 1708
1623sub _draw { 1709sub _draw {
1624 my ($self) = @_; 1710 my ($self) = @_;
1625 1711
1626 my $tex = $tex{$self->{type}}; 1712 my $tex = $tex{$self->{type}};
1713 my ($t1, $t2, $t3) = @$tex;
1627 1714
1628 my ($w, $h) = ($self->{w}, $self->{h}); 1715 my ($w, $h) = ($self->{w}, $self->{h});
1629 1716
1630 if ($self->{vertical}) { 1717 if ($self->{vertical}) {
1631 glRotate 90, 0, 0, 1; 1718 glRotate 90, 0, 0, 1;
1633 1720
1634 ($w, $h) = ($h, $w); 1721 ($w, $h) = ($h, $w);
1635 } 1722 }
1636 1723
1637 my $ycut = $self->{val} / ($self->{max_val} || 1); 1724 my $ycut = $self->{val} / ($self->{max_val} || 1);
1638 $ycut = 1 if $self->{val} > $self->{max_val};
1639 1725
1640 my $t1 = $tex->[0]; 1726 my $ycut1 = max 0, min 1, $ycut;
1641 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);
1642 1731
1643 glEnable GL_BLEND; 1732 glEnable GL_BLEND;
1644 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1733 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1645 glEnable GL_TEXTURE_2D; 1734 glEnable GL_TEXTURE_2D;
1646 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1735 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1647 1736
1648 my $h1 = $self->{h} - $ycut * $self->{h};
1649 my $h2 = $ycut * $self->{h};
1650
1651 glBindTexture GL_TEXTURE_2D, $t1->{name}; 1737 glBindTexture GL_TEXTURE_2D, $t1->{name};
1652 glBegin GL_QUADS; 1738 glBegin GL_QUADS;
1653 glTexCoord 0 , 0; glVertex 0 , 0; 1739 glTexCoord 0 , 0; glVertex 0 , 0;
1654 glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $h1; 1740 glTexCoord 0 , $t1->{t} * (1 - $ycut1); glVertex 0 , $h1;
1655 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex $w, $h1; 1741 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut1); glVertex $w, $h1;
1656 glTexCoord $t1->{s}, 0; glVertex $w, 0; 1742 glTexCoord $t1->{s}, 0; glVertex $w, 0;
1657 glEnd; 1743 glEnd;
1658 1744
1745 my $ycut1 = List::Util::min 1, $ycut;
1659 glBindTexture GL_TEXTURE_2D, $t2->{name}; 1746 glBindTexture GL_TEXTURE_2D, $t2->{name};
1660 glBegin GL_QUADS; 1747 glBegin GL_QUADS;
1661 glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $h1; 1748 glTexCoord 0 , $t2->{t} * (1 - $ycut1); glVertex 0 , $h1;
1662 glTexCoord 0 , $t2->{t}; glVertex 0 , $h1 + $h2; 1749 glTexCoord 0 , $t2->{t} * (1 - $ycut2); glVertex 0 , $h2;
1663 glTexCoord $t2->{s}, $t2->{t}; glVertex $w, $h1 + $h2; 1750 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut2); glVertex $w, $h2;
1664 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex $w, $h1; 1751 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut1); glVertex $w, $h1;
1665 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 }
1666 1763
1667 glDisable GL_BLEND; 1764 glDisable GL_BLEND;
1668 glDisable GL_TEXTURE_2D; 1765 glDisable GL_TEXTURE_2D;
1669} 1766}
1670 1767
1673package CFClient::UI::Gauge; 1770package CFClient::UI::Gauge;
1674 1771
1675our @ISA = CFClient::UI::VBox::; 1772our @ISA = CFClient::UI::VBox::;
1676 1773
1677sub new { 1774sub new {
1678 my ($class, %arg) = shift; 1775 my ($class, %arg) = @_;
1679 1776
1680 my $self = $class->SUPER::new ( 1777 my $self = $class->SUPER::new (
1681 @_, 1778 tooltip => $arg{type},
1779 can_events => 1,
1780 can_hover => 1,
1781 %arg,
1682 ); 1782 );
1683 1783
1684 $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");
1685 $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);
1686 $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");
1687 1787
1688 $self 1788 $self
1689} 1789}
1690 1790
1691sub set_fontsize { 1791sub set_fontsize {
1858sub new { 1958sub new {
1859 my $class = shift; 1959 my $class = shift;
1860 1960
1861 my $self = $class->SUPER::new ( 1961 my $self = $class->SUPER::new (
1862 fontsize => 1, 1962 fontsize => 1,
1963 #font => default_font
1863 @_, 1964 @_,
1864 1965
1865 layout => (new CFClient::Layout), 1966 layout => (new CFClient::Layout),
1866 par => [], 1967 par => [],
1867 height => 0, 1968 height => 0,
1907sub size_allocate { 2008sub size_allocate {
1908 my ($self, $w, $h) = @_; 2009 my ($self, $w, $h) = @_;
1909 2010
1910 $self->SUPER::size_allocate ($w, $h); 2011 $self->SUPER::size_allocate ($w, $h);
1911 2012
2013 $self->{layout}->set_font ($self->{font}) if $self->{font};
1912 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 2014 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1913 $self->{layout}->set_width ($self->{children}[0]{w}); 2015 $self->{layout}->set_width ($self->{children}[0]{w});
1914 2016
1915 $self->reflow; 2017 $self->reflow;
1916} 2018}
1968 my $y1 = $top + $self->{h}; 2070 my $y1 = $top + $self->{h};
1969 2071
1970 my $y = 0; 2072 my $y = 0;
1971 2073
1972 my $layout = $self->{layout}; 2074 my $layout = $self->{layout};
2075
2076 $layout->set_font ($self->{font}) if $self->{font};
1973 2077
1974 for my $par (@{$self->{par}}) { 2078 for my $par (@{$self->{par}}) {
1975 my $h = $par->[0]; 2079 my $h = $par->[0];
1976 2080
1977 if ($y0 < $y + $h && $y < $y1) { 2081 if ($y0 < $y + $h && $y < $y1) {
2057 my $class = shift; 2161 my $class = shift;
2058 2162
2059 my $self = $class->SUPER::new ( 2163 my $self = $class->SUPER::new (
2060 state => 0, 2164 state => 0,
2061 connect_activate => \&toggle_flopper, 2165 connect_activate => \&toggle_flopper,
2166 can_events => 1,
2062 @_ 2167 @_
2063 ); 2168 );
2064 2169
2065 if ($self->{state}) { 2170 if ($self->{state}) {
2066 $self->{state} = 0; 2171 $self->{state} = 0;
2086 $self->emit (changed => $self->{state}); 2191 $self->emit (changed => $self->{state});
2087} 2192}
2088 2193
2089############################################################################# 2194#############################################################################
2090 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
2091package CFClient::UI::Root; 2305package CFClient::UI::Root;
2092 2306
2093our @ISA = CFClient::UI::Container::; 2307our @ISA = CFClient::UI::Container::;
2094 2308
2095use CFClient::OpenGL; 2309use CFClient::OpenGL;
2170############################################################################# 2384#############################################################################
2171 2385
2172package CFClient::UI; 2386package CFClient::UI;
2173 2387
2174$ROOT = new CFClient::UI::Root; 2388$ROOT = new CFClient::UI::Root;
2389$TOOLTIP = new CFClient::UI::Tooltip;
2175 2390
21761 23911
2177 2392

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines