Move match inside match_info in MatchHandler.
[kaya.git] / lib / board / square_tag.rb
blob8c8fd00235fa597a2f72b73bb5e38090929c79fc
1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 module TaggableSquares
9   TAGS_ZVALUE = -2
10   
11   module ClassMethods
12     def square_tag(name, element, opts = {})
13       define_method(name) do
14         instance_variable_get("@#{name}")
15       end
16       
17       define_method("#{name}=") do |val|
18         tag_pixmap = lambda { theme.board.send(element, unit) }
19         tag_reloader = lambda do |key, item|
20           item.pixmap = tag_pixmap[]
21           item.pos = to_real(val)
22         end
23         
24         instance_variable_set("@#{name}", val)
25         if val
26           options = { :pos => to_real(val),
27                       :z => TAGS_ZVALUE,
28                       :reloader => tag_reloader}.merge(opts)
29           item = square_tag_container.add_item(name, options)
30           item.reload(name)
31         else
32           square_tag_container.remove_item(name)
33         end
34       end
35     end
36   end
37   
38   def self.included(klass)
39     klass.extend ClassMethods
40   end
41   
42   alias :tag :send
43   
44   def set_tag(name, value)
45     send("#{name}=", value)
46   end
47   
48   def square_tag_container
49     self
50   end
51 end