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.267 by root, Thu Jun 1 04:10:29 2006 UTC vs.
Revision 1.270 by elmex, Fri Jun 2 09:02:49 2006 UTC

171sub rescale_widgets { 171sub rescale_widgets {
172 my ($sx, $sy) = @_; 172 my ($sx, $sy) = @_;
173 173
174 for my $widget (values %WIDGET) { 174 for my $widget (values %WIDGET) {
175 if ($widget->{is_toplevel}) { 175 if ($widget->{is_toplevel}) {
176 $widget->{x} += $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; 176 $widget->{x} += int $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/;
177 $widget->{y} += $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; 177 $widget->{y} += int $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/;
178 178
179 $widget->{x} = int 0.5 + $widget->{x} * $sx if $widget->{x} =~ /^[0-9.]+$/; 179 $widget->{x} = int 0.5 + $widget->{x} * $sx if $widget->{x} =~ /^[0-9.]+$/;
180 $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; 180 $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w};
181 $widget->{force_w} = int 0.5 + $widget->{force_w} * $sx if exists $widget->{force_w}; 181 $widget->{force_w} = int 0.5 + $widget->{force_w} * $sx if exists $widget->{force_w};
182 $widget->{y} = int 0.5 + $widget->{y} * $sy if $widget->{y} =~ /^[0-9.]+$/; 182 $widget->{y} = int 0.5 + $widget->{y} * $sy if $widget->{y} =~ /^[0-9.]+$/;
183 $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h}; 183 $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h};
184 $widget->{force_h} = int 0.5 + $widget->{force_h} * $sy if exists $widget->{force_h}; 184 $widget->{force_h} = int 0.5 + $widget->{force_h} * $sy if exists $widget->{force_h};
185 185
186 $widget->{x} -= $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; 186 $widget->{x} -= int $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/;
187 $widget->{y} -= $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; 187 $widget->{y} -= int $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/;
188 188
189 } 189 }
190 } 190 }
191 191
192 reconfigure_widgets; 192 reconfigure_widgets;
529sub draw { 529sub draw {
530 my ($self) = @_; 530 my ($self) = @_;
531 531
532 return unless $self->{h} && $self->{w}; 532 return unless $self->{h} && $self->{w};
533 533
534 # update screen rectangle
534 local $draw_x = $draw_x + $self->{x}; 535 local $draw_x = $draw_x + $self->{x};
535 local $draw_y = $draw_y + $self->{y}; 536 local $draw_y = $draw_y + $self->{y};
537 local $draw_w = $draw_x + $self->{w};
538 local $draw_h = $draw_y + $self->{h};
536 539
537 return if $draw_x + $self->{w} < 0; 540 # skip widgets that are entirely outside the drawing area
538 return if $draw_x >= $draw_w; 541 return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w)
539 return if $draw_y + $self->{h} < 0; 542 || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h);
540 return if $draw_y >= $draw_h;
541 543
542 glPushMatrix; 544 glPushMatrix;
543 glTranslate $self->{x}, $self->{y}, 0; 545 glTranslate $self->{x}, $self->{y}, 0;
544 $self->_draw; 546 $self->_draw;
545 glPopMatrix; 547 glPopMatrix;
1048my @border = 1050my @border =
1049 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1051 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1050 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); 1052 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
1051 1053
1052sub new { 1054sub new {
1053 my $class = shift; 1055 my ($class, %arg) = @_;
1056
1057 my $title = delete $arg{title};
1054 1058
1055 my $self = $class->SUPER::new ( 1059 my $self = $class->SUPER::new (
1056 bg => [1, 1, 1, 1], 1060 bg => [1, 1, 1, 1],
1057 border_bg => [1, 1, 1, 1], 1061 border_bg => [1, 1, 1, 1],
1058 border => 0.6, 1062 border => 0.6,
1059 can_events => 1, 1063 can_events => 1,
1060 min_w => 16, 1064 min_w => 16,
1061 min_h => 16, 1065 min_h => 16,
1062 @_ 1066 %arg,
1063 ); 1067 );
1064 1068
1065 $self->{title} &&= new CFClient::UI::Label 1069 $self->{title} = new CFClient::UI::Label
1066 align => 0, 1070 align => 0,
1067 valign => 1, 1071 valign => 1,
1068 text => $self->{title}, 1072 text => $title,
1069 fontsize => $self->{border}; 1073 fontsize => $self->{border}
1074 if defined $title;
1070 1075
1071 $self 1076 $self
1077}
1078
1079sub add {
1080 my ($self, @widgets) = @_;
1081
1082 $self->SUPER::add (@widgets);
1083 $self->CFClient::UI::Container::add ($self->{title}) if $self->{title};
1072} 1084}
1073 1085
1074sub border { 1086sub border {
1075 int $_[0]{border} * $::FONTSIZE 1087 int $_[0]{border} * $::FONTSIZE
1076} 1088}
1077 1089
1078sub size_request { 1090sub size_request {
1079 my ($self) = @_; 1091 my ($self) = @_;
1092
1093 $self->{title}->size_request
1094 if $self->{title};
1080 1095
1081 my ($w, $h) = $self->SUPER::size_request; 1096 my ($w, $h) = $self->SUPER::size_request;
1082 1097
1083 ( 1098 (
1084 $w + $self->border * 2, 1099 $w + $self->border * 2,
1087} 1102}
1088 1103
1089sub size_allocate { 1104sub size_allocate {
1090 my ($self, $w, $h) = @_; 1105 my ($self, $w, $h) = @_;
1091 1106
1107 if ($self->{title}) {
1108 $self->{title}{w} = $w;
1109 $self->{title}{h} = $h;
1110 $self->{title}->size_allocate ($w, $h);
1111 }
1112
1113 my $border = $self->border;
1114
1092 $h -= List::Util::max 0, $self->border * 2; 1115 $h -= List::Util::max 0, $border * 2;
1093 $w -= List::Util::max 0, $self->border * 2; 1116 $w -= List::Util::max 0, $border * 2;
1094 1117
1095 $self->{title}->configure ($self->border, int $self->border - $::FONTSIZE * 2, $w, int $::FONTSIZE * 2)
1096 if $self->{title};
1097
1098 $self->child->configure ($self->border, $self->border, $w, $h); 1118 $self->child->configure ($border, $border, $w, $h);
1099} 1119}
1100 1120
1101sub button_down { 1121sub button_down {
1102 my ($self, $ev, $x, $y) = @_; 1122 my ($self, $ev, $x, $y) = @_;
1103 1123
1155} 1175}
1156 1176
1157sub _draw { 1177sub _draw {
1158 my ($self) = @_; 1178 my ($self) = @_;
1159 1179
1180 my $child = $self->{children}[0];
1181
1160 my ($w, $h ) = ($self->{w}, $self->{h}); 1182 my ($w, $h ) = ($self->{w}, $self->{h});
1161 my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); 1183 my ($cw, $ch) = ($child->{w}, $child->{h});
1162 1184
1163 glEnable GL_TEXTURE_2D; 1185 glEnable GL_TEXTURE_2D;
1164 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1186 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1165 1187
1166 my $border = $self->border; 1188 my $border = $self->border;
1181 $bg->draw_quad_alpha ($border, $border, $cw, $ch); 1203 $bg->draw_quad_alpha ($border, $border, $cw, $ch);
1182 } 1204 }
1183 1205
1184 glDisable GL_TEXTURE_2D; 1206 glDisable GL_TEXTURE_2D;
1185 1207
1186 $self->{title}->draw if $self->{title};
1187
1188 $self->child->draw; 1208 $child->draw;
1209
1210 if ($self->{title}) {
1211 glTranslate 0, $border - $self->{h};
1212 $self->{title}->_draw;
1213 }
1189} 1214}
1190 1215
1191############################################################################# 1216#############################################################################
1192 1217
1193package CFClient::UI::Table; 1218package CFClient::UI::Table;
1541} 1566}
1542 1567
1543sub size_allocate { 1568sub size_allocate {
1544 my ($self, $w, $h) = @_; 1569 my ($self, $w, $h) = @_;
1545 1570
1571 delete $self->{ox};
1572
1546 delete $self->{texture} 1573 delete $self->{texture}
1547 unless $w >= $self->{req_w} && $self->{old_w} >= $self->{req_w}; 1574 unless $w >= $self->{req_w} && $self->{old_w} >= $self->{req_w};
1548} 1575}
1549 1576
1550sub set_fontsize { 1577sub set_fontsize {
1567 $self->{layout}->set_width ($self->{w}); 1594 $self->{layout}->set_width ($self->{w});
1568 $self->{layout}->set_ellipsise ($self->{ellipsise}); 1595 $self->{layout}->set_ellipsise ($self->{ellipsise});
1569 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); 1596 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1570 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1597 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1571 1598
1572 my $tex = new_from_layout CFClient::Texture $self->{layout}; 1599 new_from_layout CFClient::Texture $self->{layout}
1600 };
1573 1601
1602 unless (exists $self->{ox}) {
1574 $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} 1603 $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x}
1575 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding_x} 1604 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding_x}
1576 : ($self->{w} - $tex->{w}) * 0.5); 1605 : ($self->{w} - $tex->{w}) * 0.5);
1577 1606
1578 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} 1607 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y}
1579 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y} 1608 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y}
1580 : ($self->{h} - $tex->{h}) * 0.5); 1609 : ($self->{h} - $tex->{h}) * 0.5);
1581
1582 $tex
1583 }; 1610 };
1584 1611
1585 glEnable GL_TEXTURE_2D; 1612 glEnable GL_TEXTURE_2D;
1586 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1613 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1587 1614
3124 $rec = $::CONN->stop_record if $::CONN; 3151 $rec = $::CONN->stop_record if $::CONN;
3125 return unless ref $rec eq 'ARRAY'; 3152 return unless ref $rec eq 'ARRAY';
3126 $self->set_command_list ($rec); 3153 $self->set_command_list ($rec);
3127} 3154}
3128 3155
3129# if $commit is true, the binding will be set after the user entered a key combo 3156
3157sub ask_for_bind_and_commit {
3158 my ($self) = @_;
3159 $self->ask_for_bind (1);
3160}
3161
3130sub ask_for_bind { 3162sub ask_for_bind {
3131 my ($self, $commit) = @_; 3163 my ($self, $commit) = @_;
3132 3164
3133 CFClient::Binder::open_binding_dialog (sub { 3165 CFClient::Binder::open_binding_dialog (sub {
3134 my ($mod, $sym) = @_; 3166 my ($mod, $sym) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines