-- Base object prototype
Vdo_base_object = {}
-- Base function to create a new vdo object
function Vdo_base_object:new_base(obj_handle, doc_handle, lua_filename, vdo_reference_name)
local obj = {
handle = obj_handle or INVALID_VDO_HANDLE,
doc_handle = doc_handle, -- Optional, is nil if not set
lua_filename = lua_filename, -- Optional, is nil if not set
vdo_reference_name = vdo_reference_name -- Optional, is nil if not set
}
setmetatable(obj, self)
self.__index = self
-- If it's got an init callback, invoke it
if obj.init ~= nil and type(obj.init) == "function" then
obj:init()
end
return obj
end
-- Creates a new vdo object after finding a vint object handle with the given name
--
-- obj_name: string name
-- parent_handle: (optional) handle of parent vint object, 0 is default.
-- doc_handle: (optional) handle of document with object, 0 is default.
-- lua_filename: (optional) filename of the base object.
-- vdo_reference_name: (optional) name of the reference object(String).
function Vdo_base_object:new(obj_name, parent_handle, doc_handle, lua_filename, vdo_reference_name )
local handle = vint_object_find(obj_name, parent_handle, doc_handle)
if handle == INVALID_VDO_HANDLE then
debug_print("vint", "VINT OBJECT WARNING: " .. obj_name .. " not found for Vdo_base_object:new()")
end
return self:new_base(handle, doc_handle, lua_filename, vdo_reference_name )
end
-- Used to pass a string in call a member function. This is facilitates passing vdo member functions to callbacks as strings.
--
-- func: string, name of function
function Vdo_base_object:call_func(func)
self[func](self)
end
function vdo_base_execute_callback(tween_handle, tween_event, doc, vdo, func)
local d = _DynamicGlobals[doc]
if d ~= nil then
local v = d[vdo]
if v ~= nil then
v:call_func(func)
end
end
end
--Packages tween callback string for VDO Tweens
--
-- @param callback_func String name of function for callback...
function Vdo_base_object:package_tween_callback(callback_func_name)
return self.lua_filename .. ":" .. self.vdo_reference_name .. ":" .. callback_func_name
end
-- Creates a clone of the object with the given vint handle
--
-- orig_handle: handle of original vint object
-- parent_handle: (optional) handle of parent vint object
function Vdo_base_object:clone(orig_handle, parent_handle, doc_handle, lua_filename, vdo_reference_name )
-- We definitely want to know if a clone fails!
local handle = vint_object_clone(orig_handle, parent_handle)
if handle == INVALID_VDO_HANDLE then
debug_print("VINT OBJECT WARNING: original handle " .. orig_handle .. " not cloned in Vdo_base_object:clone()")
end
return self:new_base( handle, doc_handle, lua_filename, vdo_reference_name )
end
function Vdo_base_object:object_destroy()
-- Saving object handle
local handle = self.handle
-- Invalidate the object's handles so we make sure we aren't using it later
self.handle = INVALID_VDO_HANDLE
self.doc_handle = nil
-- If it's got an on_destroy() callback, then invoke it
if self.on_destroy ~= nil and type(self.on_destroy) == "function" then
self:on_destroy()
end
-- Tail call
return vint_object_destroy(handle)
end
-- Finds a vint object handle that's a child of the vdo object
function Vdo_base_object:object_find(obj_name)
return vint_object_find(obj_name, self.handle)
end
-------------
-- GET/SET --
-------------
-- General
function Vdo_base_object:get_property(prop_name)
return vint_get_property(self.handle, prop_name)
end
function Vdo_base_object:set_property(prop_name, ...)
return vint_set_property(self.handle, prop_name, ...)
end
-- Depth
function Vdo_base_object:get_depth()
return self:get_property("depth")
end
function Vdo_base_object:set_depth(depth)
return self:set_property("depth", depth)
end
-- Alpha
function Vdo_base_object:get_alpha()
return self:get_property("alpha")
end
function Vdo_base_object:set_alpha(alpha)
return self:set_property("alpha", alpha)
end
-- Anchor
function Vdo_base_object:get_anchor()
return self:get_property("anchor")
end
function Vdo_base_object:set_anchor(x, y)
return self:set_property("anchor", x, y)
end
-- Color (tint)
function Vdo_base_object:get_color()
return self:get_property("tint")
end
function Vdo_base_object:set_color(r, g, b)
if type(r) == "number" then
return self:set_property("tint", r, g, b)
else
return self:set_property("tint", r.R, r.G, r.B)
end
end
-- Rotation
function Vdo_base_object:get_rotation()
return self:get_property("rotation")
end
function Vdo_base_object:set_rotation(rotation)
return self:set_property("rotation", rotation)
end
-- Scale
function Vdo_base_object:get_scale()
return self:get_property("scale")
end
function Vdo_base_object:set_scale(x, y)
return self:set_property("scale", x, y)
end
-- Screen size
function Vdo_base_object:get_screen_size()
return self:get_property("screen_size")
end
function Vdo_base_object:set_screen_size(w, h)
return self:set_property("screen_size", w, h)
end
-- Actual size
function Vdo_base_object:get_actual_size()
return element_get_actual_size(self.handle)
end
function Vdo_base_object:set_actual_size(w, h)
return element_set_actual_size(self.handle, w, h)
end
-- Visible
function Vdo_base_object:get_visible()
return self:get_property("visible")
end
function Vdo_base_object:set_visible(visible)
return self:set_property("visible", visible)
end
-- Blur
function Vdo_base_object:get_blur()
return self:get_property("blur")
end
function Vdo_base_object:set_blur(blur)
return self:set_property("blur", blur)
end
-- WARNING: these do not apply to all objects, but this is convenient, so...
-- We can pull these out into new inherited objects if necessary
-- Image
function Vdo_base_object:get_image()
return self:get_property("image")
end
function Vdo_base_object:set_image(image)
return self:set_property("image", image)
end
-- Text (tag)
function Vdo_base_object:get_text()
return self:get_property("text_tag")
end
function Vdo_base_object:set_text(text)
if type(text) == "string" then
return self:set_property("text_tag", text)
else
return self:set_property("text_tag_crc", text)
end
end
-- Text (crc)
function Vdo_base_object:get_text_crc()
return self:get_property("text_tag_crc")
end
function Vdo_base_object:set_text_crc(crc)
return self:set_property("text_tag_crc", crc)
end