./vdo_row.lua

  1. function vdo_row_init() 
  2. end 
  3.  
  4. function vdo_row_cleanup() 
  5. end 
  6.  
  7. -- Inherited from Vdo_base_object 
  8. Vdo_row = 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.  
  13. local SELECTED_SCALE = 1.0 
  14. local UNSELECTED_SCALE = 1.0 
  15. PAUSE_ROW_ITEM_MIN_SPACING = 40 		--Spacing between columns 
  16.  
  17. function Vdo_row:init() 
  18. 	self.columns = { 
  19. 		{h = vint_object_find("row_item_1", self.handle), x = 0, width = 0, enabled = true, alignment = ALIGN_LEFT}, 
  20. 		{h = vint_object_find("row_item_2", self.handle), x = 0, width = 0, enabled = true, alignment = ALIGN_LEFT}, 
  21. 		{h = vint_object_find("row_item_3", self.handle), x = 0, width = 0, enabled = true, alignment = ALIGN_LEFT}, 
  22. 		{h = vint_object_find("row_item_4", self.handle), x = 0, width = 0, enabled = true, alignment = ALIGN_LEFT}, 
  23. 	} 
  24. 	--default column count... 
  25. 	self.column_count = 4 
  26. end 
  27.  
  28. -------------------------------------------------------------------------------- 
  29. -- Set font scale of entire row. 
  30. -- 
  31. function Vdo_row:set_font_scale(font_scale) 
  32. 	for idx, val in pairs(self.columns) do 
  33. 		vint_set_property(val.h, "text_scale", font_scale, font_scale) 
  34. 	end 
  35. end 
  36. 	 
  37.  
  38. -------------------------------------------------------------------------------- 
  39. -- Sets the text value of each column 
  40. -- only supports 4 arguments for 4 columsn 
  41. function Vdo_row:set_value(...) 
  42. 	for idx = 1, #self.columns do 
  43. 		local label = arg[idx] 
  44. 		local h = self.columns[idx].h 
  45. 		local col = self.columns[idx] 
  46. 		if label ~= nil and label ~= "" and idx <= self.column_count then 
  47. 			vint_set_property(h, "text_tag", label) 
  48. 			vint_set_property(h, "visible", true) 
  49. 			col.width = floor(element_get_actual_size(h)) 
  50. 		else 
  51. 			debug_print("vint", "idx: " .. idx .. "\n") 
  52. 			vint_set_property(h, "visible", false) 
  53. 			col.width = 0 
  54. 		end 
  55. 	end 
  56. end 
  57.  
  58. ------------------------------------------------------------------------------- 
  59. -- Sets the position of col_2, col_3, and col_4 
  60. --	@param col_1	largest width of column 1 
  61. --	@param col_2	largest width of column 2 
  62. --	@param col_3	largest width of column 3 
  63. --	@param col_4	largest width of column 4 
  64. ------------------------------------------------------------------------------- 
  65. function Vdo_row:format_columns(...) 
  66. 	local x = 0 
  67. 	local total_width = 0 
  68. 	local count = 0 
  69. 	 
  70. 	for idx = 1, self.column_count do 
  71. 		local col_width = arg[idx] 
  72. 		--this could be different depending on what come up with below, alignment means different width... 
  73. 		total_width = total_width + col_width 
  74. 		if idx > 1 then 
  75. 			total_width = total_width + PAUSE_ROW_ITEM_MIN_SPACING 
  76. 		end 
  77. 	end 
  78.  
  79. 	--Hardcoding size of indent from left side... and an extra 5 for padding... 
  80. 	total_width  = total_width + 45 
  81.  
  82. 	if total_width < self.max_width then 
  83. 		local extra_width = self.max_width - total_width 
  84. 		local extra_width_per_item = extra_width / (self.column_count) 
  85. 		for idx = 1, self.column_count do 
  86. 			local col = arg[idx] 
  87. 			arg[idx] = floor(col + extra_width_per_item) 
  88. 		end 
  89. 	end 
  90.  
  91. 	for idx = 1, self.column_count do 
  92. 		local label = arg[idx] 
  93. 		local h = self.columns[idx].h 
  94. 		local alignment = self.columns[idx].alignment  
  95. 		local new_width = 0 
  96. 		local prev_width = 0 
  97.  
  98. 		local original_x, original_y = vint_get_property(h, "anchor") 
  99. 		 
  100. 		if idx == 1 then 
  101. 			--first item is always left aligned... 
  102. 			x = 0 
  103. 		else 
  104. 			if self.columns[idx - 1].alignment == ALIGN_LEFT then 
  105. 				if alignment == ALIGN_LEFT then 
  106. 					prev_width = arg[idx - 1] 
  107. 					x = x + prev_width 
  108. 				else 
  109. 					prev_width = arg[idx - 1] 
  110. 					new_width = arg[idx] 
  111. 					x = x + prev_width + new_width 
  112. 				end 
  113. 			else 
  114. 				--previous item is align right 
  115. 				 
  116. 				if alignment == ALIGN_LEFT then 
  117. 					prev_width = arg[idx - 1] 
  118. 					x = x 
  119. 				else 
  120. 					--this item is align right... 
  121. 					new_width = arg[idx] 
  122. 					x = x + new_width 
  123. 				end 
  124. 			end 
  125. 			--Add spacing... 
  126. 			x = x + PAUSE_ROW_ITEM_MIN_SPACING 
  127. 		end 
  128.  
  129. 		 self.columns[idx].x = x 
  130. 		vint_set_property(h, "anchor", x, original_y) 
  131. 	end 
  132. 	 
  133. 	--make sure we include the indenting in our final width... 
  134. 	self.width = x + 45 
  135. end 
  136.  
  137. ------------------------------------------------------------------------------- 
  138. -- Returns column widths of pause row 
  139. -- @return	width of col_1 
  140. -- @return	width of col_2 
  141. -- @return	width of col_3 
  142. -- @return	width of col_4 
  143. ------------------------------------------------------------------------------- 
  144. function Vdo_row:get_column_widths() 
  145. 	return self.columns[1].width, self.columns[2].width, self.columns[3].width, self.columns[4].width 
  146. end 
  147.  
  148.  
  149. ------------------------------------------------------------------------------- 
  150. -- Returns the column positions of each element... 
  151. -- 
  152. function Vdo_row:get_column_positions() 
  153. 	return self.columns[1].x, self.columns[2].x, self.columns[3].x, self.columns[4].x 
  154. end 
  155.  
  156. ------------------------------------------------------------------------------- 
  157. -- Returns the width stored from when we formated the row. 
  158. -- 
  159. function Vdo_row:get_width() 
  160. 	return self.width 
  161. end 
  162.  
  163.  
  164. ------------------------------------------------------------------------------- 
  165. -- Sets the max width that the row could be, so we can stretch really wide 
  166. -- if the list requests it. 
  167. -- 
  168. function Vdo_row:set_max_width(max_width) 
  169. 	self.max_width = max_width 
  170. end 
  171.  
  172. -- Sets the highlighted state of the slider to on or off (will eventually have grayed out here too) 
  173. function Vdo_row:set_highlight(is_highlighted) 
  174. 	if is_highlighted then 
  175. 		for idx, val in pairs(self.columns) do 
  176. 			vint_set_property(val.h, "tint", COLOR_PAUSE_BUTTON_TOGGLE_TEXT_SELECTED.R, COLOR_PAUSE_BUTTON_TOGGLE_TEXT_SELECTED.G, COLOR_PAUSE_BUTTON_TOGGLE_TEXT_SELECTED.B) 
  177. 			vint_set_property(val.h, "scale", SELECTED_SCALE, SELECTED_SCALE) 
  178. 		end 
  179. 	else 
  180. 		for idx, val in pairs(self.columns) do 
  181. 			vint_set_property(val.h, "tint", COLOR_PAUSE_BUTTON_TOGGLE_TEXT_UNSELECTED.R, COLOR_PAUSE_BUTTON_TOGGLE_TEXT_UNSELECTED.G, COLOR_PAUSE_BUTTON_TOGGLE_TEXT_UNSELECTED.B) 
  182. 			vint_set_property(val.h, "scale", UNSELECTED_SCALE, UNSELECTED_SCALE) 
  183. 		end 
  184. 	end 
  185. end 
  186.  
  187. -- Sets the alignment for the columns 
  188. -- arg1 = column 1, ALIGN_LEFT or ALIGN_RIGHT 
  189. function Vdo_row:set_alignment(...) 
  190. 	for idx, val in pairs(self.columns) do 
  191. 		local alignment = arg[idx] 
  192. 		 
  193. 		local auto_offset = "w" 
  194. 		if alignment == ALIGN_RIGHT then 
  195. 			auto_offset = "e" 
  196. 		end 
  197. 		 
  198. 		vint_set_property(val.h, "auto_offset", auto_offset) 
  199. 		val.alignment = alignment 
  200. 	end 
  201. end 
  202.  
  203. ------------------------------------------------------------------------------- 
  204. -- Sets the number of columns used in the mewnu... 
  205. -- @param	#of columns 
  206. -- 
  207. function Vdo_row:set_column_count(column_count) 
  208. 	self.column_count = column_count 
  209. end