./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. 	_DynamicGlobals[doc][vdo]:call_func(func) 
  50. end 
  51.  
  52. --Packages tween callback string for VDO Tweens 
  53. --  
  54. -- @param callback_func		String name of function for callback... 
  55. function Vdo_base_object:package_tween_callback(callback_func_name) 
  56. 	return self.lua_filename .. ":" .. self.vdo_reference_name .. ":" .. callback_func_name 
  57. end 
  58.  
  59. -- Creates a clone of the object with the given vint handle 
  60. -- 
  61. -- orig_handle: handle of original vint object 
  62. -- parent_handle: (optional) handle of parent vint object 
  63. function Vdo_base_object:clone(orig_handle, parent_handle, doc_handle, lua_filename, vdo_reference_name ) 
  64.  
  65. 	-- We definitely want to know if a clone fails! 
  66. 	local handle = vint_object_clone(orig_handle, parent_handle) 
  67. 	if handle == INVALID_VDO_HANDLE then 
  68. 		debug_print("VINT OBJECT WARNING: original handle " .. orig_handle .. " not cloned in Vdo_base_object:clone()") 
  69. 	end 
  70.  
  71. 	return self:new_base( handle, doc_handle, lua_filename, vdo_reference_name ) 
  72. end 
  73.  
  74. function Vdo_base_object:object_destroy() 
  75. 	-- Saving object handle 
  76. 	local handle = self.handle 
  77.  
  78. 	-- Invalidate the object's handles so we make sure we aren't using it later 
  79. 	self.handle = INVALID_VDO_HANDLE 
  80. 	self.doc_handle = nil 
  81.  
  82. 	-- If it's got an on_destroy() callback, then invoke it 
  83. 	if self.on_destroy ~= nil and type(self.on_destroy) == "function" then 
  84. 		self:on_destroy() 
  85. 	end 
  86. 	 
  87. 	-- Tail call 
  88. 	return vint_object_destroy(handle) 
  89. end 
  90.  
  91. -- Finds a vint object handle that's a child of the vdo object 
  92. function Vdo_base_object:object_find(obj_name) 
  93. 	return vint_object_find(obj_name, self.handle) 
  94. end 
  95.  
  96. ------------- 
  97. -- GET/SET -- 
  98. ------------- 
  99.  
  100. -- General 
  101. function Vdo_base_object:get_property(prop_name) 
  102. 	return vint_get_property(self.handle, prop_name) 
  103. end 
  104.  
  105. function Vdo_base_object:set_property(prop_name, ...) 
  106. 	return vint_set_property(self.handle, prop_name, ...) 
  107. end 
  108.  
  109. -- Depth 
  110. function Vdo_base_object:get_depth() 
  111. 	return self:get_property("depth") 
  112. end 
  113.  
  114. function Vdo_base_object:set_depth(depth) 
  115. 	return self:set_property("depth", depth) 
  116. end 
  117.  
  118. -- Alpha 
  119. function Vdo_base_object:get_alpha() 
  120. 	return self:get_property("alpha") 
  121. end 
  122.  
  123. function Vdo_base_object:set_alpha(alpha) 
  124. 	return self:set_property("alpha", alpha) 
  125. end 
  126.  
  127. -- Anchor 
  128. function Vdo_base_object:get_anchor() 
  129. 	return self:get_property("anchor") 
  130. end 
  131.  
  132. function Vdo_base_object:set_anchor(x, y) 
  133. 	return self:set_property("anchor", x, y) 
  134. end 
  135.  
  136. -- Color (tint) 
  137. function Vdo_base_object:get_color() 
  138. 	return self:get_property("tint") 
  139. end 
  140.  
  141. function Vdo_base_object:set_color(r, g, b) 
  142. 	if type(r) == "number" then 
  143. 		return self:set_property("tint", r, g, b) 
  144. 	else 
  145. 		return self:set_property("tint", r.R, r.G, r.B) 
  146. 	end 
  147. end 
  148.  
  149. -- Rotation 
  150. function Vdo_base_object:get_rotation() 
  151. 	return self:get_property("rotation") 
  152. end 
  153.  
  154. function Vdo_base_object:set_rotation(rotation) 
  155. 	return self:set_property("rotation", rotation) 
  156. end 
  157.  
  158. -- Scale 
  159. function Vdo_base_object:get_scale() 
  160. 	return self:get_property("scale") 
  161. end 
  162.  
  163. function Vdo_base_object:set_scale(x, y) 
  164. 	return self:set_property("scale", x, y) 
  165. end 
  166.  
  167. -- Screen size 
  168. function Vdo_base_object:get_screen_size() 
  169. 	return self:get_property("screen_size") 
  170. end 
  171.  
  172. function Vdo_base_object:set_screen_size(w, h) 
  173. 	return self:set_property("screen_size", w, h) 
  174. end 
  175.  
  176. -- Actual size 
  177. function Vdo_base_object:get_actual_size() 
  178. 	return element_get_actual_size(self.handle) 
  179. end 
  180.  
  181. function Vdo_base_object:set_actual_size(w, h) 
  182. 	return element_set_actual_size(self.handle, w, h) 
  183. end 
  184.  
  185. -- Visible 
  186. function Vdo_base_object:get_visible() 
  187. 	return self:get_property("visible") 
  188. end 
  189.  
  190. function Vdo_base_object:set_visible(visible) 
  191. 	return self:set_property("visible", visible) 
  192. end 
  193.  
  194. -- Blur 
  195. function Vdo_base_object:get_blur() 
  196. 	return self:get_property("blur") 
  197. end 
  198.  
  199. function Vdo_base_object:set_blur(blur) 
  200. 	return self:set_property("blur", blur) 
  201. end 
  202.  
  203. -- WARNING: these do not apply to all objects, but this is convenient, so...  
  204. -- We can pull these out into new inherited objects if necessary 
  205.  
  206. -- Image 
  207. function Vdo_base_object:get_image() 
  208. 	return self:get_property("image") 
  209. end 
  210.  
  211. function Vdo_base_object:set_image(image) 
  212. 	return self:set_property("image", image) 
  213. end 
  214.  
  215. -- Text (tag) 
  216. function Vdo_base_object:get_text() 
  217. 	return self:get_property("text_tag") 
  218. end 
  219.  
  220. function Vdo_base_object:set_text(text, is_crc) 
  221. 	if is_crc == true then 
  222. 		return self:set_property("text_tag_crc", text) 
  223. 	else 
  224. 		return self:set_property("text_tag", text) 
  225. 	end			 
  226. end 
  227.  
  228. -- Text (crc) 
  229. function Vdo_base_object:get_text_crc() 
  230. 	return self:get_property("text_tag_crc") 
  231. end 
  232.  
  233. function Vdo_base_object:set_text_crc(crc) 
  234. 	return self:set_property("text_tag_crc", crc) 
  235. end 
  236.