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.302 by root, Mon Jun 12 13:26:14 2006 UTC vs.
Revision 1.304 by elmex, Tue Jun 13 11:01:04 2006 UTC

1090 valign => 1, 1090 valign => 1,
1091 text => $self->{title}, 1091 text => $self->{title},
1092 fontsize => $self->{border}, 1092 fontsize => $self->{border},
1093 if exists $self->{title}; 1093 if exists $self->{title};
1094 1094
1095 unless ($self->{no_close_button}) {
1096 $self->{close_btn} =
1097 new CFClient::UI::ImageButton
1098 image => 'x1_close.png',
1099 on_activate => sub { $self->hide };
1100
1101 $self->CFClient::UI::Container::add ($self->{close_btn});
1102 }
1103
1095 $self 1104 $self
1096} 1105}
1097 1106
1098sub add { 1107sub add {
1099 my ($self, @widgets) = @_; 1108 my ($self, @widgets) = @_;
1100 1109
1101 $self->SUPER::add (@widgets); 1110 $self->SUPER::add (@widgets);
1111 $self->CFClient::UI::Container::add ($self->{close_btn}) if $self->{close_btn};
1102 $self->CFClient::UI::Container::add ($self->{title_widget}) if $self->{title_widget}; 1112 $self->CFClient::UI::Container::add ($self->{title_widget}) if $self->{title_widget};
1103} 1113}
1104 1114
1105sub border { 1115sub border {
1106 int $_[0]{border} * $::FONTSIZE 1116 int $_[0]{border} * $::FONTSIZE
1109sub size_request { 1119sub size_request {
1110 my ($self) = @_; 1120 my ($self) = @_;
1111 1121
1112 $self->{title_widget}->size_request 1122 $self->{title_widget}->size_request
1113 if $self->{title_widget}; 1123 if $self->{title_widget};
1124
1125 $self->{close_btn}->size_request
1126 if $self->{close_btn};
1114 1127
1115 my ($w, $h) = $self->SUPER::size_request; 1128 my ($w, $h) = $self->SUPER::size_request;
1116 1129
1117 ( 1130 (
1118 $w + $self->border * 2, 1131 $w + $self->border * 2,
1131 1144
1132 my $border = $self->border; 1145 my $border = $self->border;
1133 1146
1134 $h -= List::Util::max 0, $border * 2; 1147 $h -= List::Util::max 0, $border * 2;
1135 $w -= List::Util::max 0, $border * 2; 1148 $w -= List::Util::max 0, $border * 2;
1136 1149
1137 $self->child->configure ($border, $border, $w, $h); 1150 $self->child->configure ($border, $border, $w, $h);
1151
1152 $self->{close_btn}->configure ($self->{w} - (2 * $border), 0, $border, $border)
1153 if $self->{close_btn};
1138} 1154}
1139 1155
1140sub button_down { 1156sub button_down {
1141 my ($self, $ev, $x, $y) = @_; 1157 my ($self, $ev, $x, $y) = @_;
1142 1158
1188} 1204}
1189 1205
1190sub button_up { 1206sub button_up {
1191 my ($self, $ev, $x, $y) = @_; 1207 my ($self, $ev, $x, $y) = @_;
1192 1208
1209 $self->{close_btn}->button_up ($ev, $x, $y)
1210 if $self->{close_btn};
1211
1193 !!delete $self->{motion} 1212 !!delete $self->{motion}
1194} 1213}
1195 1214
1196sub mouse_motion { 1215sub mouse_motion {
1197 my ($self, $ev, $x, $y) = @_; 1216 my ($self, $ev, $x, $y) = @_;
1235 $child->draw; 1254 $child->draw;
1236 1255
1237 if ($self->{title_widget}) { 1256 if ($self->{title_widget}) {
1238 glTranslate 0, $border - $self->{h}; 1257 glTranslate 0, $border - $self->{h};
1239 $self->{title_widget}->_draw; 1258 $self->{title_widget}->_draw;
1259
1260 glTranslate 0, - ($border - $self->{h});
1240 } 1261 }
1262
1263 $self->{close_btn}->draw
1264 if $self->{close_btn};
1241} 1265}
1242 1266
1243############################################################################# 1267#############################################################################
1244 1268
1245package CFClient::UI::Table; 1269package CFClient::UI::Table;
1956 $tex[0]->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); 1980 $tex[0]->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
1957 1981
1958 glDisable GL_TEXTURE_2D; 1982 glDisable GL_TEXTURE_2D;
1959 1983
1960 $self->SUPER::_draw; 1984 $self->SUPER::_draw;
1985}
1986
1987#############################################################################
1988
1989package CFClient::UI::ImageButton;
1990
1991our @ISA = CFClient::UI::Image::;
1992
1993use CFClient::OpenGL;
1994
1995my %textures;
1996
1997sub new {
1998 my $class = shift;
1999
2000 my $self = $class->SUPER::new (
2001 padding_x => 4,
2002 padding_y => 4,
2003 fg => [1, 1, 1],
2004 active_fg => [0, 0, 1],
2005 can_hover => 1,
2006 align => 0,
2007 valign => 0,
2008 can_events => 1,
2009 @_
2010 );
2011}
2012
2013sub activate { }
2014
2015sub button_up {
2016 my ($self, $ev, $x, $y) = @_;
2017
2018 $self->emit ("activate")
2019 if $x >= 0 && $x < $self->{w}
2020 && $y >= 0 && $y < $self->{h};
2021
2022 1
1961} 2023}
1962 2024
1963############################################################################# 2025#############################################################################
1964 2026
1965package CFClient::UI::CheckBox; 2027package CFClient::UI::CheckBox;
3456 my ($self) = @_; 3518 my ($self) = @_;
3457 $self->ask_for_bind (1); 3519 $self->ask_for_bind (1);
3458} 3520}
3459 3521
3460sub ask_for_bind { 3522sub ask_for_bind {
3461 my ($self, $commit) = @_; 3523 my ($self, $commit, $end_cb) = @_;
3462 3524
3463 CFClient::Binder::open_binding_dialog (sub { 3525 CFClient::Binder::open_binding_dialog (sub {
3464 my ($mod, $sym) = @_; 3526 my ($mod, $sym) = @_;
3465 $self->{binding} = [$mod, $sym]; # XXX: how to stop that memleak? 3527 $self->{binding} = [$mod, $sym]; # XXX: how to stop that memleak?
3466 $self->update_binding_widgets; 3528 $self->update_binding_widgets;
3467 $self->commit if $commit; 3529 $self->commit if $commit;
3530 $end_cb->() if $end_cb;
3468 }); 3531 });
3469} 3532}
3470 3533
3471# $mod and $sym are the modifiers and key symbol 3534# $mod and $sym are the modifiers and key symbol
3472# $cmds is a array ref of strings (the commands) 3535# $cmds is a array ref of strings (the commands)
3490} 3553}
3491 3554
3492# this is a shortcut method that asks for a binding 3555# this is a shortcut method that asks for a binding
3493# and then just binds it. 3556# and then just binds it.
3494sub do_quick_binding { 3557sub do_quick_binding {
3495 my ($self, $cmds) = @_; 3558 my ($self, $cmds, $end_cb) = @_;
3496 $self->set_binding (undef, undef, $cmds, sub { 3559 $self->set_binding (undef, undef, $cmds, sub {
3497 $::CFG->{bindings}->{$_[0]}->{$_[1]} = $_[2]; 3560 $::CFG->{bindings}->{$_[0]}->{$_[1]} = $_[2];
3498 }); 3561 });
3499 $self->ask_for_bind (1); 3562 $self->ask_for_bind (1, $end_cb);
3500} 3563}
3501 3564
3502sub update_binding_widgets { 3565sub update_binding_widgets {
3503 my ($self) = @_; 3566 my ($self) = @_;
3504 my ($mod, $sym, $cmds) = $self->get_binding; 3567 my ($mod, $sym, $cmds) = $self->get_binding;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines