rubyx-debugger/app/main/lib/space_view.rb

96 lines
2.2 KiB
Ruby
Raw Normal View History

2015-07-09 15:34:02 +02:00
class SpaceView < PIXI::Graphics
include Sof::Util
2015-07-09 15:34:02 +02:00
def initialize
2015-07-09 15:34:02 +02:00
super()
space = Virtual.machine.space
# just a way to get the space into a list. objects is an id => occurence mapping.
# occurence.object is the object
objects = Sof::Members.new(space).objects
2015-07-09 15:34:02 +02:00
@objects = objects
# create a mapping from id to volt models
@view_objects = {}
2015-07-09 15:34:02 +02:00
@objects.each do |i , o|
view = Volt::Model.new
view._object = o
@view_objects[i] = view
at = PIXI::Point.new 100 , 100
name = PIXI::Text.new i.to_s
view._name = name
add_child name
end
2015-07-09 15:34:02 +02:00
end
# should almost be called draw by now
2015-07-09 15:34:02 +02:00
def update
update_positions
2015-07-09 15:34:02 +02:00
self.clear
prev = nil
@view_objects.each do |i , view|
if prev
self.lineStyle(4, 0xffd900, 2)
self.moveTo( prev._name.position.x , prev._name.position.y )
self.lineTo( view._name.position.x , view._name.position.y )
end
prev = view
end
end
def update_positions
@view_objects.each do |i , view|
view._name.position.x += 1
end
2015-07-09 15:34:02 +02:00
end
def fill_attributes
@view_objects.each do |i , view|
object = view._object
case object.class.name
when "Array" , "Parfait::List"
fill_array view
when "Hash" , "Parfait::Dictionary"
fill_hash view
else
# and recursively add attributes
attributes = attributes_for(object)
attributes.each do |a|
val = get_value( object , a)
if( @view_objects[vol.object_id])
#ref
end
view.set(a , val )
end
superclasses = [object.class.superclass.name]
if superclasses.include?( "Array") or superclasses.include?( "Parfait::List")
fill_array view
end
if superclasses.include?( "Hash") or superclasses.include?( "Parfait::Dictionary")
fill_hash view
end
view._object = nil
end
end
end
# and hash keys/values
def fill_hash hash
return
hash.each do |a,b|
next_level << a
next_level << b
end
end
# and array values
def fill_array array
return
array.each do |a|
next_level << a
end
end
2015-07-09 15:34:02 +02:00
end