1 | use utf8; |
1 | use utf8; |
|
|
2 | |
|
|
3 | use Scalar::Util (); |
2 | |
4 | |
3 | package game::goclock; |
5 | package game::goclock; |
4 | |
6 | |
5 | # Lo and Behold! I admit it! The rounding stuff etc.. in goclock |
7 | # Lo and Behold! I admit it! The rounding stuff etc.. in goclock |
6 | # is completely borked. |
8 | # is completely borked. |
7 | |
9 | |
8 | use Time::HiRes (); |
10 | use Time::HiRes (); |
9 | |
11 | |
10 | use KGS::Constants; |
12 | use KGS::Constants; |
11 | |
13 | |
12 | use base gtk::widget; |
14 | use Glib::Object::Subclass |
|
|
15 | Gtk2::Label; |
13 | |
16 | |
14 | sub new { |
17 | sub INIT_INSTANCE { |
15 | my $class = shift; |
18 | my $self = shift; |
16 | my $self = $class->SUPER::new(@_); |
|
|
17 | |
|
|
18 | $self->{widget} = new Gtk2::Label; |
|
|
19 | |
19 | |
20 | $self->{set} = sub { }; |
20 | $self->{set} = sub { }; |
21 | $self->{format} = sub { "ERROR" }; |
21 | $self->{format} = sub { "ERROR" }; |
|
|
22 | } |
22 | |
23 | |
|
|
24 | sub FINALIZE_INSTANCE { |
|
|
25 | my ($self) = @_; |
|
|
26 | print "finalize(clock)\n";#d# |
23 | $self; |
27 | $self->stop; |
24 | } |
28 | } |
25 | |
29 | |
26 | sub configure { |
30 | sub configure { |
27 | my ($self, $timesys, $main, $interval, $count) = @_; |
31 | my ($self, $timesys, $main, $interval, $count) = @_; |
28 | |
32 | |
… | |
… | |
75 | my $timer = $self->{time} + $self->{start} - $timestamp; |
79 | my $timer = $self->{time} + $self->{start} - $timestamp; |
76 | |
80 | |
77 | # we round the timer value slightly... the protocol isn't exact anyways, |
81 | # we round the timer value slightly... the protocol isn't exact anyways, |
78 | # and this gives smoother timers ;) |
82 | # and this gives smoother timers ;) |
79 | my @format = $self->{format}->(int ($timer + 0.4)); |
83 | my @format = $self->{format}->(int ($timer + 0.4)); |
80 | $self->{widget}->set_text ($self->{format}->(int ($timer + 0.4))); |
84 | $self->set_text ($self->{format}->(int ($timer + 0.4))); |
81 | |
85 | |
82 | $timer - int $timer; |
86 | $timer - int $timer; |
83 | } |
87 | } |
84 | |
88 | |
85 | sub set_time { |
89 | sub set_time { |
… | |
… | |
118 | my ($self) = @_; |
122 | my ($self) = @_; |
119 | |
123 | |
120 | remove Glib::Source delete $self->{timeout} if $self->{timeout}; |
124 | remove Glib::Source delete $self->{timeout} if $self->{timeout}; |
121 | } |
125 | } |
122 | |
126 | |
123 | sub destroy { |
|
|
124 | my ($self) = @_; |
|
|
125 | $self->stop; |
|
|
126 | $self->SUPER::destroy; |
|
|
127 | } |
|
|
128 | |
|
|
129 | package game::userpanel; |
127 | package game::userpanel; |
130 | |
128 | |
131 | use base gtk::widget; |
129 | use Glib::Object::Subclass |
|
|
130 | Gtk2::HBox, |
|
|
131 | properties => [ |
|
|
132 | Glib::ParamSpec->IV ("colour", "colour", "User Colour", 0, 1, 0, [qw(construct-only writable)]), |
|
|
133 | ]; |
132 | |
134 | |
133 | sub new { |
135 | sub INIT_INSTANCE { |
134 | my $class = shift; |
136 | my ($self) = @_; |
135 | my $self = $class->SUPER::new(@_); |
|
|
136 | |
137 | |
137 | $self->{widget} = new Gtk2::HBox; |
|
|
138 | |
|
|
139 | $self->{widget}->add (my $vbox = new Gtk2::VBox); |
138 | $self->add (my $vbox = new Gtk2::VBox); |
140 | |
139 | |
141 | $vbox->add ($self->{name} = new Gtk2::Label $self->{name}); |
140 | $vbox->add ($self->{name} = new Gtk2::Label $self->{name}); |
142 | $vbox->add ($self->{info} = new Gtk2::Label ""); |
141 | $vbox->add ($self->{info} = new Gtk2::Label ""); |
143 | $vbox->add (($self->{clock} = new game::goclock)->widget); |
142 | $vbox->add ($self->{clock} = new game::goclock); Scalar::Util::weaken $self->{clock}; |
144 | |
143 | |
145 | $vbox->add ($self->{imagebox} = new Gtk2::VBox); |
144 | $vbox->add ($self->{imagebox} = new Gtk2::VBox); |
146 | |
145 | |
147 | $self; |
146 | $self; |
148 | } |
147 | } |
… | |
… | |
263 | $sw->add(($self->{userlist} = new userlist)->widget); |
262 | $sw->add(($self->{userlist} = new userlist)->widget); |
264 | |
263 | |
265 | $self->{vpane}->add(my $vbox = new Gtk2::VBox); |
264 | $self->{vpane}->add(my $vbox = new Gtk2::VBox); |
266 | |
265 | |
267 | $vbox->pack_start((my $hbox = new Gtk2::HBox 1), 0, 1, 0); |
266 | $vbox->pack_start((my $hbox = new Gtk2::HBox 1), 0, 1, 0); |
|
|
267 | |
|
|
268 | for (COLOUR_WHITE, COLOUR_BLACK) { |
268 | $hbox->add (($self->{userpanel}[COLOUR_WHITE] = new game::userpanel colour => COLOUR_WHITE)->widget); |
269 | $hbox->add ($self->{userpanel}[$_] = new game::userpanel colour => $_); |
269 | $hbox->add (($self->{userpanel}[COLOUR_BLACK] = new game::userpanel colour => COLOUR_BLACK)->widget); |
270 | Scalar::Util::weaken $self->{userpanel}[$_]; |
|
|
271 | } |
270 | |
272 | |
271 | $vbox->pack_start(($self->{chat} = new chat), 1, 1, 0); |
273 | $vbox->pack_start(($self->{chat} = new chat), 1, 1, 0); |
272 | |
274 | |
273 | $self->{chat}->signal_connect(command => sub { |
275 | $self->{chat}->signal_connect(command => sub { |
274 | my ($chat, $cmd, $arg) = @_; |
276 | my ($chat, $cmd, $arg) = @_; |
… | |
… | |
549 | |
551 | |
550 | sub destroy { |
552 | sub destroy { |
551 | my ($self) = @_; |
553 | my ($self) = @_; |
552 | |
554 | |
553 | delete $self->{app}{gamelist}{game}{$self->{channel}}; |
555 | delete $self->{app}{gamelist}{game}{$self->{channel}}; |
554 | $self->{userpanel}[$_] && (delete $self->{userpanel}[$_])->destroy |
|
|
555 | for COLOUR_BLACK, COLOUR_WHITE; |
|
|
556 | $self->SUPER::destroy; |
556 | $self->SUPER::destroy; |
557 | } |
557 | } |
558 | |
558 | |
559 | 1; |
559 | 1; |
560 | |
560 | |