ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/Macro.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/Macro.pm (file contents):
Revision 1.3 by root, Sat Dec 9 22:06:51 2006 UTC vs.
Revision 1.6 by elmex, Sat Dec 16 16:14:34 2006 UTC

157 $window->grab_focus; 157 $window->grab_focus;
158 $window->show; 158 $window->show;
159} 159}
160 160
161# find macro by event 161# find macro by event
162# maybe return multiple results?
163sub match_event($) { 162sub match_event($) {
164 my ($ev) = @_; 163 my ($ev) = @_;
165 164
166 for my $macro (@{ $::PROFILE->{macro} || [] }) { 165 grep {
167 my $key = $macro->{accelkey} 166 if (my $key = $_->{accelkey}) {
168 or next;
169
170 $key->[1] == $ev->{sym} 167 $key->[1] == $ev->{sym}
171 && $key->[0] == ($ev->{mod} & $MODIFIER_MASK) 168 && $key->[0] == ($ev->{mod} & $MODIFIER_MASK)
172 && return $macro; 169 } else {
173 } 170 0
174 171 }
175 () 172 } @{ $::PROFILE->{macro} || [] }
176} 173}
177 174
178sub keyboard_setup { 175sub keyboard_setup {
179 my $kbd_setup = new CFPlus::UI::VBox; 176 my $kbd_setup = new CFPlus::UI::VBox;
180 177
195 0 192 0
196 }, 193 },
197 ); 194 );
198 195
199 $list->add (new CFPlus::UI::FancyFrame 196 $list->add (new CFPlus::UI::FancyFrame
200 label => "Bindings", 197 label => "Macros",
201 child => (my $macros = new CFPlus::UI::Table), 198 child => (my $macros = new CFPlus::UI::VBox),
202 ); 199 );
203 200
204 my $refresh; 201 my $refresh;
205 202
206 my $tooltip_common = "\n\n<small>Left click - edit macro\nMiddle click - invoke macro\nRight click - further options</small>"; 203 my $tooltip_common = "\n\n<small>Left click - edit macro\nMiddle click - invoke macro\nRight click - further options</small>";
272 my ($widget) = @_; 269 my ($widget) = @_;
273 270
274 $recording = $::CONN && !$recording; 271 $recording = $::CONN && !$recording;
275 if ($recording) { 272 if ($recording) {
276 $widget->set_text ("Stop Recording"); 273 $widget->set_text ("Stop Recording");
277 my $action = $macro->{action} ||= [];
278 $::CONN->record (sub { 274 $::CONN->record (sub {
279 push @$action, $_[0]; 275 push @{ $macro->{action} }, $_[0];
280 $textedit->set_text (macro_to_text $macro); 276 $textedit->set_text (macro_to_text $macro);
281 }) if $::CONN; 277 }) if $::CONN;
282 } else { 278 } else {
283 $widget->set_text ("Start Recording"); 279 $widget->set_text ("Start Recording");
284 $::CONN->record if $::CONN; 280 $::CONN->record if $::CONN;
285 } 281 }
286 }, 282 },
287 ); 283 );
288 }; 284 };
289 285
286 $macros->add (new CFPlus::UI::Button
287 text => "New Macro",
288 tooltip => "Creates a new, empty, macro you can edit.",
289 on_activate => sub {
290 my $macro = { };
291 push @{ $::PROFILE->{macro} }, $macro;
292 $edit_macro->($macro);
293 },
294 );
295
296 $macros->add (my $macrolist = new CFPlus::UI::Table col_expand => [0, 1]);
297
290 $REFRESH_MACRO_LIST = $refresh = sub { 298 $REFRESH_MACRO_LIST = $refresh = sub {
291 $macros->clear; 299 $macrolist->clear;
292 300
293 $macros->add (0, 0, new CFPlus::UI::Label 301 $macrolist->add (0, 1, new CFPlus::UI::Label
294 text => "Trigger", 302 text => "Trigger",
295 align => 0, 303 align => 0,
296 tooltip => $tooltip_trigger . $tooltip_common, 304 tooltip => $tooltip_trigger . $tooltip_common,
297 ); 305 );
298 $macros->add (1, 0, new CFPlus::UI::Label 306 $macrolist->add (1, 1, new CFPlus::UI::Label
299 text => "Commands", 307 text => "Commands",
300 tooltip => $tooltip_commands . $tooltip_common, 308 tooltip => $tooltip_commands . $tooltip_common,
301 ); 309 );
302 310
303 for my $idx (0 .. $#{$::PROFILE->{macro} || []}) { 311 for my $idx (0 .. $#{$::PROFILE->{macro} || []}) {
304 my $macro = $::PROFILE->{macro}[$idx]; 312 my $macro = $::PROFILE->{macro}[$idx];
305 my $y = $idx + 1; 313 my $y = $idx + 2;
306 314
307 my $macro_cb = sub { 315 my $macro_cb = sub {
308 my ($widget, $ev) = @_; 316 my ($widget, $ev) = @_;
309 317
310 if ($ev->{button} == 1) { 318 if ($ev->{button} == 1) {
328 } 336 }
329 337
330 1 338 1
331 }; 339 };
332 340
333 $macros->add (0, $y, new CFPlus::UI::Label 341 $macrolist->add (0, $y, new CFPlus::UI::Label
334 text => trigger_to_string $macro, 342 text => trigger_to_string $macro,
335 tooltip => $tooltip_trigger . $tooltip_common, 343 tooltip => $tooltip_trigger . $tooltip_common,
336 align => 0, 344 align => 0,
337 can_hover => 1, 345 can_hover => 1,
338 can_events => 1, 346 can_events => 1,
339 on_button_down => $macro_cb, 347 on_button_down => $macro_cb,
340 ); 348 );
341 349
342 $macros->add (1, $y, new CFPlus::UI::Label 350 $macrolist->add (1, $y, new CFPlus::UI::Label
343 text => (join "; ", @{ $macro->{action} || [] }), 351 text => (join "; ", @{ $macro->{action} || [] }),
344 tooltip => $tooltip_commands . $tooltip_common, 352 tooltip => $tooltip_commands . $tooltip_common,
345 expand => 1, 353 expand => 1,
346 ellipsise => 3, 354 ellipsise => 3,
347 can_hover => 1, 355 can_hover => 1,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines