./vdo_toggle.lua

  1. function vdo_toggle_init() 
  2. end 
  3.  
  4. function vdo_toggle_cleanup() 
  5. end 
  6.  
  7. -- Inherited from Vdo_base_object 
  8. Vdo_toggle = Vdo_base_object:new_base() 
  9.  
  10. COLOR_PAUSE_BUTTON_TOGGLE_TEXT_UNSELECTED = {R = 194/255, G = 201/255; B = 204/255} 
  11. COLOR_PAUSE_BUTTON_TOGGLE_TEXT_SELECTED = {R = 0/255, G = 0/255; B = 0/255} 
  12. local TOGGLE_TEXT_PAD = 3 
  13.  
  14. --Init Toggle 
  15. function Vdo_toggle:init() 
  16. 	self.value_txt_h = vint_object_find("value", self.handle) 
  17. 	 
  18. 	--Default highlight color... 
  19. 	self.highlight_color = COLOR_PAUSE_BUTTON_TOGGLE_TEXT_SELECTED 
  20. 	 
  21. 	--Defaults... 
  22. 	self.is_disabled = false 
  23. 	self.arrows_hidden = false 
  24. end 
  25.  
  26. ------------------------------------------------------------------------------- 
  27. -- Sets the value of the toggle object 
  28. -- @param	value		value you want to set... 
  29. ------------------------------------------------------------------------------- 
  30. function Vdo_toggle:set_value(value) 
  31. 	vint_set_property(self.value_txt_h, "text_tag", value) 
  32. end 
  33.  
  34. ------------------------------------------------------------------------------- 
  35. -- sets the width based on the values in the options. 
  36. -- @param	options	Table with the options. options = {"option_1", "option_2"} 
  37. ------------------------------------------------------------------------------- 
  38. function Vdo_toggle:set_width_based_on_values(options) 
  39. 	--Find largest text string and size component to it... 
  40. 	local width = 0 
  41. 	local max_width = 0 
  42. 	for i = 1, #options do 
  43. 		vint_set_property(self.value_txt_h, "text_tag", options[i]) 
  44. 		width = element_get_actual_size(self.value_txt_h) 
  45. 		max_width = max(max_width, width) 
  46. 	end 
  47. 	 
  48. 	self:set_width(max_width) 
  49. end 
  50.  
  51. ------------------------------------------------------------------------------- 
  52. -- Returns the width of the current value in the toggle. 
  53. ------------------------------------------------------------------------------- 
  54. function Vdo_toggle:get_value_width() 
  55. 	local width, height = element_get_actual_size(self.value_txt_h) 
  56. 	return width 
  57. end 
  58.  
  59. ------------------------------------------------------------------------------- 
  60. -- Set width 
  61. -- @param	width		 
  62. ------------------------------------------------------------------------------- 
  63. function Vdo_toggle:set_width(width) 
  64.  
  65. 	-- Reposition Right Arrow 
  66. 	local a_right_h = vint_object_find("arrow_right", self.handle) 
  67. 	local x, y = vint_get_property(a_right_h, "anchor") 
  68. 	local arrow_width, arrow_height = element_get_actual_size(a_right_h) 
  69. 	x = width + arrow_width + 4  
  70. 	vint_set_property(a_right_h, "anchor", x, y) 
  71. 	 
  72. 	-- Center text in toggle. 
  73. 	local value_x, value_y = vint_get_property(self.value_txt_h, "anchor") 
  74. 	value_x = width/2 + (arrow_width) 
  75. 	vint_set_property(self.value_txt_h, "anchor", value_x, value_y) 
  76. 	 
  77. 	self.width = x + arrow_width 
  78. end 
  79.  
  80. ------------------------------------------------------------------------------- 
  81. -- Returns the width the the vdo from left arrow to right arrow. 
  82. ------------------------------------------------------------------------------- 
  83. function Vdo_toggle:get_width() 
  84. 	return self.width 
  85. end 
  86.  
  87. ------------------------------------------------------------------------------- 
  88. -- Sets the highlighted state of the slider to on or off  
  89. -- (will eventually have grayed out here too) 
  90. -- 
  91. function Vdo_toggle:set_highlight(is_highlighted) 
  92.  
  93. 	local arrow_left_h = vint_object_find("arrow_left", self.handle, self.doc_handle) 
  94. 	local arrow_right_h = vint_object_find("arrow_right", self.handle, self.doc_handle) 
  95.  
  96. 	if is_highlighted then 
  97. 		--Set color 
  98. 		vint_set_property(self.value_txt_h, "tint", 0, 0, 0) 
  99. 		 
  100. 		--Show Arrows only if we are not disabled.  
  101. 		vint_set_property(arrow_left_h, "visible", true) 
  102. 		vint_set_property(arrow_right_h, "visible", true) 
  103. 	else 
  104. 		--Set Color 
  105. 		vint_set_property(self.value_txt_h, "tint", COLOR_PAUSE_BUTTON_TOGGLE_TEXT_UNSELECTED.R, COLOR_PAUSE_BUTTON_TOGGLE_TEXT_UNSELECTED.G, COLOR_PAUSE_BUTTON_TOGGLE_TEXT_UNSELECTED.B) 
  106. 		 
  107. 		--Hide Arrows 
  108. 		vint_set_property(arrow_left_h, "visible", false) 
  109. 		vint_set_property(arrow_right_h, "visible", false) 
  110. 	end 
  111. 	 
  112. end 
  113.  
  114. function Vdo_toggle:set_highlight_color(new_color) 
  115. 	self.highlight_color = new_color 
  116. end 
  117.  
  118.  
  119.  
  120. ------------------------------------------------------------------------------- 
  121. -- Sets the scale for the text items... 
  122. -- (will eventually have grayed out here too) 
  123. -- 
  124. function Vdo_toggle:set_text_scale(scale) 
  125. 	vint_set_property(self.value_txt_h, "scale", scale, scale) 
  126. end 
  127.  
  128. function Vdo_toggle:set_disabled(is_disabled) 
  129. 	 
  130. 	local arrow_left_h = vint_object_find("arrow_left", self.handle, self.doc_handle) 
  131. 	local arrow_right_h = vint_object_find("arrow_right", self.handle, self.doc_handle) 
  132. 	 
  133. 	--Hide Arrows 
  134. 	if is_disabled == true then 
  135. 		vint_set_property(arrow_left_h, 		"alpha", 0) 
  136. 		vint_set_property(arrow_right_h, 	"alpha", 0) 
  137. 		vint_set_property(self.value_txt_h, "alpha", .5) 
  138. 	else 
  139. 		vint_set_property(arrow_left_h, 		"alpha", 1.0) 
  140. 		vint_set_property(arrow_right_h, 	"alpha", 1.0) 
  141. 		vint_set_property(self.value_txt_h, "alpha", 1.0) 
  142. 	end 
  143. 	self.is_disabled = is_disabled 
  144. end