./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. 			if game_get_platform() == "PC" and game_is_active_input_gamepad() ~= true then 
  103. 				x = 0 
  104. 			else 
  105. 				x = 15 
  106. 			end 
  107. 		else 
  108. 			if self.columns[idx - 1].alignment == ALIGN_LEFT then 
  109. 				if alignment == ALIGN_LEFT then 
  110. 					prev_width = arg[idx - 1] 
  111. 					x = x + prev_width 
  112. 				else 
  113. 					prev_width = arg[idx - 1] 
  114. 					new_width = arg[idx] 
  115. 					x = x + prev_width + new_width 
  116. 				end 
  117. 			else 
  118. 				--previous item is align right 
  119. 				 
  120. 				if alignment == ALIGN_LEFT then 
  121. 					prev_width = arg[idx - 1] 
  122. 					x = x 
  123. 				else 
  124. 					--this item is align right... 
  125. 					new_width = arg[idx] 
  126. 					x = x + new_width 
  127. 				end 
  128. 			end 
  129. 			--Add spacing... 
  130. 			x = x + PAUSE_ROW_ITEM_MIN_SPACING 
  131. 		end 
  132.  
  133. 		self.columns[idx].x = x 
  134. 		vint_set_property(h, "anchor", x, original_y) 
  135. 		if idx == 1 then 
  136. 			--move this one back now 
  137. 			x = 0 
  138. 		end 
  139. 	end 
  140. 	 
  141. 	--make sure we include the indenting in our final width... 
  142. 	self.width = x + 45 
  143. end 
  144.  
  145. ------------------------------------------------------------------------------- 
  146. -- Returns column widths of pause row 
  147. -- @return	width of col_1 
  148. -- @return	width of col_2 
  149. -- @return	width of col_3 
  150. -- @return	width of col_4 
  151. ------------------------------------------------------------------------------- 
  152. function Vdo_row:get_column_widths() 
  153. 	return self.columns[1].width, self.columns[2].width, self.columns[3].width, self.columns[4].width 
  154. end 
  155.  
  156.  
  157. ------------------------------------------------------------------------------- 
  158. -- Returns the column positions of each element... 
  159. -- 
  160. function Vdo_row:get_column_positions() 
  161. 	return self.columns[1].x, self.columns[2].x, self.columns[3].x, self.columns[4].x 
  162. end 
  163.  
  164. ------------------------------------------------------------------------------- 
  165. -- Returns the width stored from when we formated the row. 
  166. -- 
  167. function Vdo_row:get_width() 
  168. 	return self.width 
  169. end 
  170.  
  171.  
  172. ------------------------------------------------------------------------------- 
  173. -- Sets the max width that the row could be, so we can stretch really wide 
  174. -- if the list requests it. 
  175. -- 
  176. function Vdo_row:set_max_width(max_width) 
  177. 	self.max_width = max_width 
  178. end 
  179.  
  180. -- Sets the highlighted state of the slider to on or off (will eventually have grayed out here too) 
  181. function Vdo_row:set_highlight(is_highlighted) 
  182. 	if is_highlighted then 
  183. 		for idx, val in pairs(self.columns) do 
  184. 			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) 
  185. 			vint_set_property(val.h, "scale", SELECTED_SCALE, SELECTED_SCALE) 
  186. 		end 
  187. 	else 
  188. 		for idx, val in pairs(self.columns) do 
  189. 			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) 
  190. 			vint_set_property(val.h, "scale", UNSELECTED_SCALE, UNSELECTED_SCALE) 
  191. 		end 
  192. 	end 
  193. end 
  194.  
  195. -- Sets the alignment for the columns 
  196. -- arg1 = column 1, ALIGN_LEFT or ALIGN_RIGHT 
  197. function Vdo_row:set_alignment(...) 
  198. 	for idx, val in pairs(self.columns) do 
  199. 		local alignment = arg[idx] 
  200. 		 
  201. 		local auto_offset = "w" 
  202. 		if alignment == ALIGN_RIGHT then 
  203. 			auto_offset = "e" 
  204. 		end 
  205. 		 
  206. 		vint_set_property(val.h, "auto_offset", auto_offset) 
  207. 		val.alignment = alignment 
  208. 	end 
  209. end 
  210.  
  211. ------------------------------------------------------------------------------- 
  212. -- Sets the number of columns used in the mewnu... 
  213. -- @param	#of columns 
  214. -- 
  215. function Vdo_row:set_column_count(column_count) 
  216. 	self.column_count = column_count 
  217. end