./vdo_base_object.lua

  1. -- Base object prototype 
  2. Vdo_base_object = {} 
  3.  
  4. -- Base function to create a new vdo object 
  5. function Vdo_base_object:new_base(obj_handle, doc_handle, lua_filename, vdo_reference_name) 
  6. 	local obj = { 
  7. 		handle = obj_handle or INVALID_VDO_HANDLE, 
  8. 		doc_handle = doc_handle,		-- Optional, is nil if not set 
  9. 		lua_filename = lua_filename,	-- Optional, is nil if not set 
  10. 		vdo_reference_name = vdo_reference_name -- Optional, is nil if not set 
  11. 	} 
  12.  
  13. 	setmetatable(obj, self) 
  14. 	self.__index = self 
  15.  
  16. 	-- If it's got an init callback, invoke it 
  17. 	if obj.init ~= nil and type(obj.init) == "function" then 
  18. 		obj:init() 
  19. 	end 
  20.  
  21. 	return obj 
  22. end 
  23.  
  24. -- Creates a new vdo object after finding a vint object handle with the given name 
  25. -- 
  26. -- obj_name: string name 
  27. -- parent_handle: (optional) handle of parent vint object, 0 is default. 
  28. -- doc_handle: (optional) handle of document with object, 0 is default. 
  29. -- lua_filename: (optional) filename of the base object. 
  30. -- vdo_reference_name: (optional) name of the reference object(String).  
  31. function Vdo_base_object:new(obj_name, parent_handle, doc_handle, lua_filename, vdo_reference_name ) 
  32.  
  33. 	local handle = vint_object_find(obj_name, parent_handle, doc_handle) 
  34. 	if handle == INVALID_VDO_HANDLE then 
  35. 		debug_print("vint", "VINT OBJECT WARNING: " .. obj_name .. " not found for Vdo_base_object:new()") 
  36. 	end 
  37.  
  38. 	return self:new_base(handle, doc_handle, lua_filename, vdo_reference_name ) 
  39. end 
  40.  
  41. -- Used to pass a string in call a member function.  This is facilitates passing vdo member functions to callbacks as strings. 
  42. -- 
  43. -- func: string, name of function 
  44. function Vdo_base_object:call_func(func) 
  45. 	self[func](self) 
  46. end 
  47.  
  48. function vdo_base_execute_callback(tween_handle, tween_event, doc, vdo, func) 
  49. 	local d = _DynamicGlobals[doc] 
  50. 	if d ~= nil then 
  51. 		local v = d[vdo] 
  52. 		if v ~= nil then 
  53. 			v:call_func(func) 
  54. 		end 
  55. 	end 
  56. end 
  57.  
  58. --Packages tween callback string for VDO Tweens 
  59. --  
  60. -- @param callback_func		String name of function for callback... 
  61. function Vdo_base_object:package_tween_callback(callback_func_name) 
  62. 	return self.lua_filename .. ":" .. self.vdo_reference_name .. ":" .. callback_func_name 
  63. end 
  64.  
  65. -- Creates a clone of the object with the given vint handle 
  66. -- 
  67. -- orig_handle: handle of original vint object 
  68. -- parent_handle: (optional) handle of parent vint object 
  69. function Vdo_base_object:clone(orig_handle, parent_handle, doc_handle, lua_filename, vdo_reference_name ) 
  70.  
  71. 	-- We definitely want to know if a clone fails! 
  72. 	local handle = vint_object_clone(orig_handle, parent_handle) 
  73. 	if handle == INVALID_VDO_HANDLE then 
  74. 		debug_print("VINT OBJECT WARNING: original handle " .. orig_handle .. " not cloned in Vdo_base_object:clone()") 
  75. 	end 
  76.  
  77. 	return self:new_base( handle, doc_handle, lua_filename, vdo_reference_name ) 
  78. end 
  79.  
  80. function Vdo_base_object:object_destroy() 
  81. 	-- Saving object handle 
  82. 	local handle = self.handle 
  83.  
  84. 	-- Invalidate the object's handles so we make sure we aren't using it later 
  85. 	self.handle = INVALID_VDO_HANDLE 
  86. 	self.doc_handle = nil 
  87.  
  88. 	-- If it's got an on_destroy() callback, then invoke it 
  89. 	if self.on_destroy ~= nil and type(self.on_destroy) == "function" then 
  90. 		self:on_destroy() 
  91. 	end 
  92. 	 
  93. 	-- Tail call 
  94. 	return vint_object_destroy(handle) 
  95. end 
  96.  
  97. -- Finds a vint object handle that's a child of the vdo object 
  98. function Vdo_base_object:object_find(obj_name) 
  99. 	return vint_object_find(obj_name, self.handle) 
  100. end 
  101.  
  102. ------------- 
  103. -- GET/SET -- 
  104. ------------- 
  105.  
  106. -- General 
  107. function Vdo_base_object:get_property(prop_name) 
  108. 	return vint_get_property(self.handle, prop_name) 
  109. end 
  110.  
  111. function Vdo_base_object:set_property(prop_name, ...) 
  112. 	return vint_set_property(self.handle, prop_name, ...) 
  113. end 
  114.  
  115. -- Depth 
  116. function Vdo_base_object:get_depth() 
  117. 	return self:get_property("depth") 
  118. end 
  119.  
  120. function Vdo_base_object:set_depth(depth) 
  121. 	return self:set_property("depth", depth) 
  122. end 
  123.  
  124. -- Alpha 
  125. function Vdo_base_object:get_alpha() 
  126. 	return self:get_property("alpha") 
  127. end 
  128.  
  129. function Vdo_base_object:set_alpha(alpha) 
  130. 	return self:set_property("alpha", alpha) 
  131. end 
  132.  
  133. -- Anchor 
  134. function Vdo_base_object:get_anchor() 
  135. 	return self:get_property("anchor") 
  136. end 
  137.  
  138. function Vdo_base_object:set_anchor(x, y) 
  139. 	return self:set_property("anchor", x, y) 
  140. end 
  141.  
  142. -- Color (tint) 
  143. function Vdo_base_object:get_color() 
  144. 	return self:get_property("tint") 
  145. end 
  146.  
  147. function Vdo_base_object:set_color(r, g, b) 
  148. 	if type(r) == "number" then 
  149. 		return self:set_property("tint", r, g, b) 
  150. 	else 
  151. 		return self:set_property("tint", r.R, r.G, r.B) 
  152. 	end 
  153. end 
  154.  
  155. -- Rotation 
  156. function Vdo_base_object:get_rotation() 
  157. 	return self:get_property("rotation") 
  158. end 
  159.  
  160. function Vdo_base_object:set_rotation(rotation) 
  161. 	return self:set_property("rotation", rotation) 
  162. end 
  163.  
  164. -- Scale 
  165. function Vdo_base_object:get_scale() 
  166. 	return self:get_property("scale") 
  167. end 
  168.  
  169. function Vdo_base_object:set_scale(x, y) 
  170. 	return self:set_property("scale", x, y) 
  171. end 
  172.  
  173. -- Screen size 
  174. function Vdo_base_object:get_screen_size() 
  175. 	return self:get_property("screen_size") 
  176. end 
  177.  
  178. function Vdo_base_object:set_screen_size(w, h) 
  179. 	return self:set_property("screen_size", w, h) 
  180. end 
  181.  
  182. -- Actual size 
  183. function Vdo_base_object:get_actual_size() 
  184. 	return element_get_actual_size(self.handle) 
  185. end 
  186.  
  187. function Vdo_base_object:set_actual_size(w, h) 
  188. 	return element_set_actual_size(self.handle, w, h) 
  189. end 
  190.  
  191. -- Visible 
  192. function Vdo_base_object:get_visible() 
  193. 	return self:get_property("visible") 
  194. end 
  195.  
  196. function Vdo_base_object:set_visible(visible) 
  197. 	return self:set_property("visible", visible) 
  198. end 
  199.  
  200. -- Blur 
  201. function Vdo_base_object:get_blur() 
  202. 	return self:get_property("blur") 
  203. end 
  204.  
  205. function Vdo_base_object:set_blur(blur) 
  206. 	return self:set_property("blur", blur) 
  207. end 
  208.  
  209. -- WARNING: these do not apply to all objects, but this is convenient, so...  
  210. -- We can pull these out into new inherited objects if necessary 
  211.  
  212. -- Image 
  213. function Vdo_base_object:get_image() 
  214. 	return self:get_property("image") 
  215. end 
  216.  
  217. function Vdo_base_object:set_image(image) 
  218. 	return self:set_property("image", image) 
  219. end 
  220.  
  221. -- Text (tag) 
  222. function Vdo_base_object:get_text() 
  223. 	return self:get_property("text_tag") 
  224. end 
  225.  
  226. function Vdo_base_object:set_text(text) 
  227. 	if type(text) == "string" then 
  228. 		return self:set_property("text_tag", text) 
  229. 	else 
  230. 		return self:set_property("text_tag_crc", text) 
  231. 	end 
  232. end 
  233.  
  234. -- Text (crc) 
  235. function Vdo_base_object:get_text_crc() 
  236. 	return self:get_property("text_tag_crc") 
  237. end 
  238.  
  239. function Vdo_base_object:set_text_crc(crc) 
  240. 	return self:set_property("text_tag_crc", crc) 
  241. end 
  242.