I want to be able to drag an object, in it''s entirety. Right now, I am dragging objects by defining a to_s and card_from_str methods, but there are several subclasses of these objects and writing the string conversion methods is tedious for each one. Is there another way to drag an object? Sample of my code: imageView.connect(SEL_DND_REQUEST) do |sender, sel, event| if event.target == @image_drag_type imageView.setDNDData(FROM_DRAGNDROP, @image_drag_type, Fox.fxencodeStringData(card.to_s)) end end @DilemmaBottomButton.connect(SEL_DND_DROP) do data = @DilemmaBottomButton.getDNDData(FROM_DRAGNDROP, @image_drag_type) @DilemmaBottomButton.dropFinished data = Fox.fxdecodeStringData(data) unless data.nil? card = @game.players[@this_player].card_from_str(data) end
On 3/5/07, Raj Sahae <rajsahae at gmail.com> wrote:> I want to be able to drag an object, in it''s entirety. Right now, I am > dragging objects by defining a to_s and card_from_str methods, but there > are several subclasses of these objects and writing the string > conversion methods is tedious for each one. Is there another way to > drag an object?Well, there''s not another way to drag an object, but that doesn''t seem to be the problem in the first place. You''re wanting to know if there''s an easier way to specify the data that should be transferred whenever the user drags an object from one place to another, right? Have you considered using YAML to serialize (and deserialize) the objects? If you were to do that, it seems like you wouldn''t need to write class-specific to_str() and from_str() methods.
Lyle Johnson wrote:> On 3/5/07, Raj Sahae <rajsahae at gmail.com> wrote: > >> I want to be able to drag an object, in it''s entirety. Right now, I am >> dragging objects by defining a to_s and card_from_str methods, but there >> are several subclasses of these objects and writing the string >> conversion methods is tedious for each one. Is there another way to >> drag an object? > > Well, there''s not another way to drag an object, but that doesn''t seem > to be the problem in the first place. You''re wanting to know if > there''s an easier way to specify the data that should be transferred > whenever the user drags an object from one place to another, right? > Have you considered using YAML to serialize (and deserialize) the > objects? If you were to do that, it seems like you wouldn''t need to > write class-specific to_str() and from_str() methods.Follow Lyle''s advice. YAML rocks. Here''s a quick example with two classes (one spitting all attributes, another selectively spitting only one): require ''yaml'' class A attr_accessor :x def initialize @x = [2,3] end end a = A.new yaml_data = YAML::dump(a) p yaml_data b = YAML::load(yaml_data) p b class B attr_accessor :x, :y def initialize @x = ''spit'' @y = ''ignored'' end def to_yaml_properties [ ''@x'' ] end end c = B.new p YAML::dump(c) -- Gonzalo Garramu?o ggarra at advancedsl.com.ar AMD4400 - ASUS48N-E GeForce7300GT Kubuntu Edgy