Leser: 1
6 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
#!/usr/bin/perl
use strict;
use warnings 'all';
use Tk;
my $mw = tkinit;
my $c = $mw->Canvas(-background => "white")->pack;
$c->Tk::bind("<Button-1>", [sub { shift; print "Pos: @_\n" }, Ev("x"), Ev("y")]);
MainLoop;
1
2
3
4
5
6
7
8
9
10
11
12
print "Jetzt werden die Bindings hinzugefuegt...\n";
$c -> Tk::bind ("<Button-1>", [
sub {
shift;
my @op = @{$r->{pos}};
my @np = getXY(@_);
print " OP: @op\n NP: @np\n";
newpos($r, [$np[0]-$op[0], $np[1]-$op[1]]);
}, Ev("x"), Ev("y") ]);
Jetzt werden die Bindings hinzugefuegt...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/perl
use strict;
use warnings 'all';
use Tk;
my $mw = tkinit;
my $c = $mw->Canvas(-background => "white")->pack;
print "Jetzt werden die Bindings hinzugefuegt...\n";
$c -> Tk::bind ("<Button-1>", [
sub {
shift;
# my @op = @{$r->{pos}};
my @np = getXY(@_);
print " OP: \@op\n NP: @np\n";
# newpos($r, [$np[0]-$op[0], $np[1]-$op[1]]);
}, Ev("x"), Ev("y") ]);
MainLoop;
sub getXY{
return @_;
}
1
2
3
4
5
6
7
sub getXY
{
my($xp, $yp) = @_;
($xp, $yp) = (int(($xp+1)/20), int(($yp+1)/20));
return ($xp, $yp);
} # getXY
1
2
3
4
5
6
7
8
9
10
11
12
13
print "Jetzt werden die Bindings hinzugefuegt...\n";
$c -> Tk::bind ("<Button-1>", [
sub {
shift;
my @op = @{$r->{pos}};
my @np = @_;
print " OP: @op\n NP: @np\n";
newpos($r, [$np[0]-$op[0], $np[1]-$op[1]]);
@{$r->{pos}} = (getXY(@_));
}, Ev("x"), Ev("y") ]);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#
# change the Roboter Map
#
sub arbfeld_aendern
{
my $self = shift;
$self->{robot}->einschalten;
$self->{stop} = 1;
$self->{map_is_renewed} = 0;
my $i = 0;
my $tl = $self->{mw} -> Toplevel (-title => "Roboter Map verändern");
foreach (qw/Blickrichtung: Material:/)
{
$tl -> Label (-text => $_,
-font => "{Arial} 9 {bold}",
-justify => "left",
-anchor => "w")->grid
(-column => 0,
-row => $i++,
-sticky => "ew");
}
$tl
-> Label (-text => "Auf der Map positionieren:",
-font => "{Arial} 9 {bold}",
-justify => "left",
-anchor => "w")->grid
(-column => 0,
-columnspan => 2,
-row => $i,
-sticky => "ew");
$i = 0;
my $update =
sub {
updateInfo($self);
};
$tl
-> Optionmenu (-options => [["rechts", 0],
["unten", 90],
["links", 180],
["oben", 270]],
-variable => \$self->{robot}->{rot},
-command => sub { $self->{robot}->newlook; &$update })->grid
(-column => 1,
-row => $i++,
-sticky => "ew");
$tl
-> Scale (-from => 0,
-to => 100,
-orient => "horizontal",
-variable => \$self->{robot}->{material}->[0],
-command => $update)->grid
(-column => 1,
-row => $i++,
-sticky => "ew");
my $mode = "wiki";
foreach ([qw/Wiki wiki/], [qw/Wände wall/], [qw/Gegenstände item/])
{
$tl -> Radiobutton (-text => $_->[0],
-value => $_->[1],
-variable => \$mode,
-anchor => "w",
-command => sub { bind_map($self, $mode) })->grid
(-column => 1,
-row => ++$i,
-sticky => "ew");
}
$tl
-> Button (-text => "Abbrechen",
-font => "{Arial} 9 {bold}",
-command => sub { bind_map($self, "no"); $tl->destroy })->grid
(-column => 0,
-row => $i+2,
-sticky => "ew");
$tl
-> Button (-text => "OK",
-font => "{Arial} 9 {bold}",
-command => sub {})->grid
(-column => 1,
-row => $i+2,
-sticky => "ew");
my($cols, $rows) = $tl->gridSize();
for $i (1..$cols) {
$tl->gridColumnconfigure($i-1, -weight => 1);
}
for $i (1..$rows) {
$tl->gridRowconfigure($i-1, -weight => 1);
}
} # arbfeld_aendern
#
# bind some special events, defined by $mode, to the Roboter Map
#
sub bind_map
{
my($self, $mode) = @_;
my $r = $self->{robot};
my $c = $r->{c};
if ($mode =~ "no")
{
$c -> Tk::bind ("<Button-1>", "NoOp");
$c -> Tk::bind ("<Button-3>", "NoOp");
}
elsif ($mode =~ "wiki")
{
print "Jetzt werden die Bindings hinzugefuegt...\n";
$c -> Tk::bind ("<Button-1>", [
sub {
shift;
my @op = @{$r->{pos}};
my @np = @_;
print " OP: @op\n NP: @np\n";
newpos($r, [$np[0]-$op[0], $np[1]-$op[1]]);
@{$r->{pos}} = (getXY(@_));
}, Ev("x"), Ev("y") ]);
}
} # bind_map
6 Einträge, 1 Seite |