./vdo_level_meter.lua

  1. function vdo_level_meter() 
  2. end 
  3.  
  4.  
  5. local Level_meter_frame_left_width = -1 
  6. local Level_meter_frame_left_height = -1 
  7. local Level_meter_fill_spacing_x = 3 
  8. local Level_meter_fill_spacing_y = 3 
  9.  
  10. -- Inherited from Vdo_base_object 
  11. Vdo_level_meter = Vdo_base_object:new_base() 
  12.  
  13. function Vdo_level_meter:init() 
  14. 	--Find base stuff, make base objects, store to self and hide... 
  15. 	self.level_text_obj = Vdo_base_object:new("level_text", self.handle) 
  16. 	self.left_frame_obj = Vdo_base_object:new("left_frame", self.handle) 
  17. 	self.right_frame_obj = Vdo_base_object:new("right_cap", self.handle) 
  18. 	self.fill_obj = Vdo_base_object:new("fill", self.handle) 
  19. 	self.left_frame_obj:set_visible(false) 
  20. 	self.fill_obj:set_visible(false) 
  21. 	 
  22. 	self.frame_objects = {} 
  23. 	 
  24. 	Level_meter_frame_left_width, Level_meter_frame_left_height = self.left_frame_obj:get_actual_size() 
  25. 	 
  26. 	--Subtract one because of extra padding... 
  27. 	Level_meter_frame_left_width = Level_meter_frame_left_width - 1 
  28. end 
  29.  
  30. -- Sets the level of the meter 
  31. -- This must be called for teh object to be initialized properly. 
  32. -- 
  33. -- @param	level				The current level of the meter 
  34. -- @param	max_level		How many empty spaces there will be in the meter. 
  35. -- @param	is_blinking		Is the last level in the meter blinking?  
  36. function Vdo_level_meter:set_level(level, max_level, is_blinking) 
  37.  
  38. 	--Clear out any existing frame objects... 
  39. 	for key, val in pairs(self.frame_objects) do 
  40. 		val:object_destroy() 
  41. 	end 
  42. 	self.frame_objects = {} 
  43. 	 
  44. 	local x = 48 
  45. 	local y = 0  
  46.  
  47. 	local object_count = 0 
  48. 	 
  49. 	if max_level == 0 then 
  50. 		--Hide meter if no levels... 
  51. 		self.level_text_obj:set_visible(false) 
  52. 		self.right_frame_obj:set_visible(false) 
  53. 		return 
  54. 	else 
  55. 		--Make sure meter is visible... 
  56. 		self.level_text_obj:set_visible(true) 
  57. 		self.right_frame_obj:set_visible(true) 
  58. 	end 
  59. 	 
  60. 	for i = 0, max_level - 1 do  
  61. 		--Clone  
  62. 		local left_frame = Vdo_base_object:clone(self.left_frame_obj.handle) 
  63. 		local fill = Vdo_base_object:clone(self.fill_obj.handle) 
  64. 		 
  65. 		--Position left frames 
  66. 		x = x + Level_meter_frame_left_width 
  67. 		left_frame:set_anchor(x, y) 
  68. 		left_frame:set_visible(true) 
  69. 		 
  70. 		--Fills 
  71. 		if i < level then 
  72. 			fill:set_anchor(x + Level_meter_fill_spacing_x, y + Level_meter_fill_spacing_y) 
  73. 			fill:set_visible(true) 
  74. 			 
  75. 			--If we are blinking and this is the last animations then play the pulsing on the final object... 
  76. 			if i == level - 1 and is_blinking then 
  77. 				--retarget tween... 
  78. 				local pulse_twn = Vdo_tween_object:new("pulse_twn", self.handle) 
  79. 				pulse_twn:set_target_handle(fill.handle) 
  80. 				--playback 
  81. 				local pulse_level_anim = Vdo_anim_object:new("pulse_level_anim", self.handle) 
  82. 				pulse_level_anim:play() 
  83. 			end 
  84. 		end 
  85. 		 
  86. 		--Store and reference objects... 
  87. 		self.frame_objects[ "obj_" .. object_count .. "_a"] = left_frame 
  88. 		self.frame_objects[ "obj_" .. object_count .. "_b"] = fill 
  89. 		object_count = object_count + 1 
  90. 	end 
  91. 	 
  92. 	--Move Right Cap 
  93. 	self.right_frame_obj:set_anchor(x + Level_meter_frame_left_width + 1) 
  94. end