./vdo_button_pc.lua

  1. ---------------------------------------------------------------------------  
  2. -- Vdo_button_pc 
  3. -- 
  4. -- A button designed specifically for use in the PC version only 
  5. -- The button handles only mouse inputs, not normal keyboard/gamepad inputs 
  6. -- The button's functionality can be modified to fit a few different needs: 
  7. --  * A standard button with text 
  8. --  * A standard button with an icon 
  9. --  * A toggle button with multiple possible values (2 or more) 
  10. --  * A slider with a min and max value 
  11. --------------------------------------------------------------------------- 
  12.  
  13. function vdo_button_pc_init() 
  14. end 
  15. function vdo_button_pc_cleanup() 
  16. end 
  17.  
  18. -- Inherited from Vdo_base_object 
  19. Vdo_button_pc = Vdo_base_object:new_base() 
  20.  
  21. -- Drawing sizes 
  22. local HEIGHT_ICON = 28.0 
  23. local HEIGHT_TEXT = 24.0 
  24. local HEIGHT_MINI = 16.0 
  25. local OFFSET_TEXT = 0.0 
  26. local OFFSET_BAR_VALUE = 0.0 
  27. local ARROW_PAD = 24.0 
  28.  
  29. -- Button types 
  30. PC_TYPE_NORMAL	= 1 
  31. PC_TYPE_ICON	= 2 
  32. PC_TYPE_TOGGLE	= 3 
  33. PC_TYPE_SLIDER	= 4 
  34.  
  35. -- Definitions for colors 
  36. -- NORMAL: Nothing special going on 
  37. -- HIGHLIGHT: Mouse over the button 
  38. -- ACTIVATE: Mouse click (NO LONGER USED) 
  39. -- INACTIVE: Button is visible but not clickable 
  40. -- OUTLINE: Slider outline 
  41. -- TEXT: Text and icon color 
  42. -- SOLID: Solid backdrop color 
  43. -- VALUE: Slider value color 
  44.  
  45. -- Colors 
  46. local COLOR_SLIDER_TEXT = {R = 230/255, G=230/255, B=230/255} 
  47.  
  48. local COLOR_TEXT_NORMAL = {R=160/255, G=160/255, B=160/255} 
  49. local COLOR_TEXT_HIGHLIGHT = {R=0/255, G=0/255, B=0/255} 
  50. local COLOR_TEXT_INACTIVE = {R=50/255, G=50/255, B=50/255} 
  51.  
  52. local COLOR_SOLID_NORMAL = {R=0/255, G=0/255, B=0/255} 
  53. local COLOR_SOLID_HIGHLIGHT = {R=148/255, G=0/255, B=197/255} 
  54. local COLOR_SOLID_INACTIVE = {R=0/255, G=0/255, B=0/255} 
  55.  
  56. local COLOR_VALUE_NORMAL = {R = 59/255, G = 54/255, B = 58/255} 
  57. local COLOR_VALUE_HIGHLIGHT = {R=90/255, G=90/255, B=90/255} 
  58. local COLOR_VALUE_INACTIVE = {R=30/255, G=27/255, B=29/255} 
  59.  
  60. local COLOR_ARROW_NORMAL = {R=0/255, G=0/255, B=0/255} -- If the arrows are hard to find on sliders, change this to dark gray 
  61. local COLOR_ARROW_NO_HIGHLIGHT = {R=118/255, G=0/255, B=157/255} 
  62.  
  63. -- Initialize the button 
  64. -- Sets it to the default state 
  65. function Vdo_button_pc:init()	 
  66. 	-- Components of the button 
  67. 	self.bar_solid = Vdo_base_object:new("bar_solid", self.handle, self.doc_handle) 
  68. 	self.bar_outline = Vdo_base_object:new("bar_outline", self.handle, self.doc_handle) 
  69. 	self.bar_value_l = Vdo_base_object:new("bar_value_l", self.handle, self.doc_handle) 
  70. 	self.bar_value_r = Vdo_base_object:new("bar_value_r", self.handle, self.doc_handle) 
  71. 	self.img_icon = Vdo_base_object:new("img_icon", self.handle, self.doc_handle) 
  72. 	self.text_label = Vdo_base_object:new("text_label", self.handle, self.doc_handle) 
  73. 	self.text_value = Vdo_base_object:new("text_value", self.handle, self.doc_handle) 
  74. 	self.img_left = Vdo_base_object:new("img_left", self.handle, self.doc_handle) 
  75. 	self.img_right = Vdo_base_object:new("img_right", self.handle, self.doc_handle) 
  76. 	 
  77. 	-- Important flags 
  78. 	self.type = PC_TYPE_TOGGLE 
  79. 	self.inactive = false 
  80. 		 
  81. 	-- Button widths and height 
  82. 	self.width_full = 216.0 
  83. 	self.width_value = 108.0 
  84. 	self.height = HEIGHT_TEXT 
  85.  
  86. 	-- Set the default colors 
  87. 	self:set_colors(false, false) 
  88. 		 
  89. 	-- Hide the icon 
  90. 	self:set_icon(0) 
  91. end 
  92.  
  93. -- Sets the label of the button 
  94. function Vdo_button_pc:set_label(new_label)	 
  95. 	if type(new_label) == "number" then 
  96. 		self.text_label:set_property("text_tag_crc", new_label) 
  97. 	else 
  98. 		self.text_label:set_property("text_tag", new_label) 
  99. 	end 
  100. end 
  101.  
  102. -- Sets the value of the button 
  103. function Vdo_button_pc:set_value(new_value) 
  104. 	-- if the parameter is a number, we must be using a crc instead of the actual string 
  105. 	if type(new_value) == "number" then 
  106. 		self.text_value:set_property("text_tag_crc", new_value) 
  107. 	else 
  108. 		self.text_value:set_property("text_tag", new_value) 
  109. 	end 
  110. end 
  111.  
  112. -- Create the button based on the data given 
  113. function Vdo_button_pc:create(data) 
  114. 	self.type = data.type 
  115. 	self.height = HEIGHT_TEXT -- Only need to override for icons 
  116. 	 
  117. 	-- Set the tooltip 
  118. 	self.tooltip = data.tooltip or "" 
  119. 	 
  120. 	-- Set the text (except for icon buttons) 
  121. 	if data.type == PC_TYPE_ICON then 
  122. 		self:set_label("") 
  123. 	else 
  124. 		self:set_label(data.label) 
  125. 	end 
  126. 	 
  127. 	-- Hide the unused elements, and collect extra data if needed, depending on the type 
  128. 	if data.type == PC_TYPE_NORMAL then 
  129. 		-- Normal buttons just show text, don't do anything special 
  130. 		self:hide_value_slider() 
  131. 		self:hide_arrows() 
  132. 		 
  133. 	elseif data.type == PC_TYPE_TOGGLE then 
  134. 		-- Toggle buttons have a list of options and a default option index 
  135. 		self:hide_value_slider() 
  136. 		 
  137. 		-- Get the list of options and the current option index 
  138. 		self.options = data.options 
  139. 		self.o_index = data.o_index 
  140. 		 
  141. 		-- Set the value text 
  142. 		self:set_value(self.options[self.o_index]) 
  143. 	elseif data.type == PC_TYPE_SLIDER then 
  144. 		-- Slider buttons have a min, max, step, snap, and value (all numbers) 
  145. 		self.s_min = data.s_min or 0 
  146. 		self.s_max = data.s_max or 100 
  147. 		self.s_step = data.s_step or 10 
  148. 		self.s_snap = data.s_snap or 5 
  149. 		self.s_value = data.s_value or 50 
  150. 		 
  151. 		-- Set the value text 
  152. 		self:set_value(""..self.s_value) -- Concatting ensures the value is displayed correctly 
  153. 		self.text_value:set_color(COLOR_SLIDER_TEXT) 
  154. 	elseif data.type == PC_TYPE_ICON then 
  155. 		self:hide_value_slider() 
  156. 		self:hide_arrows() 
  157. 		 
  158. 		-- Set up the icon and set the button height accordingly 
  159. 		self:set_icon(data.icon) 
  160. 		if data.mini then 
  161. 			self.height = HEIGHT_MINI 
  162. 		else 
  163. 			self.height = HEIGHT_ICON 
  164. 		end 
  165. 	end 
  166. end 
  167.  
  168. -- Hides the slider elements (but not the text/arrows) 
  169. function Vdo_button_pc:hide_value_slider() 
  170. 	self.bar_value_l:set_visible(false) 
  171. 	self.bar_value_r:set_visible(false) 
  172. 	self.bar_outline:set_visible(false) 
  173. 	 
  174. 	-- Set them all to 0 size and center them (to make sure mouse responds correctly) 
  175. 	self.bar_value_l:set_actual_size(0, 0) 
  176. 	self.bar_value_r:set_actual_size(0, 0) 
  177. 	self.bar_outline:set_actual_size(0, 0) 
  178. 	 
  179. 	self.bar_value_l:set_anchor(0, 0) 
  180. 	self.bar_value_r:set_anchor(0, 0) 
  181. 	self.bar_outline:set_anchor(0, 0) 
  182. end 
  183.  
  184. -- Hides the arrows and value text 
  185. function Vdo_button_pc:hide_arrows() 
  186. 	self.text_value:set_visible(false) 
  187. 	self.img_left:set_visible(false) 
  188. 	self.img_right:set_visible(false) 
  189. 	 
  190. 	-- Set the text to "", set the arrows to 0 size, and center them all (to make sure mouse responds correctly) 
  191. 	self:set_value("") 
  192. 	self.img_left:set_actual_size(0, 0) 
  193. 	self.img_right:set_actual_size(0, 0) 
  194. 	 
  195. 	self.text_value:set_anchor(0, 0) 
  196. 	self.img_left:set_anchor(0, 0) 
  197. 	self.img_right:set_anchor(0, 0) 
  198. end 
  199.  
  200. -- Sets the width of the button 
  201. -- IMPORTANT: This should ALWAYS be called after create() 
  202. function Vdo_button_pc:set_width(w_full, w_value) 
  203. 	self.width_full = w_full 
  204. 	self.width_value = w_value 
  205. 	 
  206. 	-- Main button backdrop 
  207. 	self.bar_solid:set_actual_size(self.width_full, self.height) 
  208. 	 
  209. 	-- For normal and icon buttons, set value text to "" so it doesn't affect mouse collision 
  210. 	if self.type == PC_TYPE_NORMAL or self.type == PC_TYPE_ICON then 
  211. 		self.text_value:set_text("") 
  212. 	end 
  213. 	 
  214. 	if self.type == PC_TYPE_SLIDER or self.type == PC_TYPE_TOGGLE then 
  215. 		-- Align label text to left 
  216. 		self.text_label:set_anchor(-(self.width_full / 2.0) + 2, OFFSET_TEXT) 
  217. 		self.text_label:set_property("auto_offset", "w") 
  218.  
  219. 		-- Align the arrows to the sides 
  220. 		self.img_left:set_anchor((self.width_full / 2.0) - ARROW_PAD * 2 - self.width_value, 0) 
  221. 		self.img_right:set_anchor((self.width_full / 2.0), 0) 
  222. 		 
  223. 		if self.type == PC_TYPE_SLIDER then 
  224. 			-- Align/resize slider backdrop 
  225. 			self.bar_outline:set_actual_size(self.width_value - 4, self.height - 4) 
  226. 			self.bar_outline:set_anchor(self.width_full / 2.0 - ARROW_PAD - 2, OFFSET_BAR_VALUE) 
  227. 			 
  228. 			-- Align the value bars (resizing occurs elsewhere) 
  229. 			self.bar_value_r:set_anchor(self.width_full / 2.0 - ARROW_PAD - 6, OFFSET_BAR_VALUE) 
  230. 			self.bar_value_l:set_anchor((self.width_full / 2.0) - ARROW_PAD - self.width_value + 6, 0) 
  231. 			 
  232. 			self:slider_scale_bar()	 
  233. 		 
  234. 		elseif self.type == PC_TYPE_TOGGLE then 
  235. 			-- Align the value text to the center of the value area 
  236. 			self.text_value:set_anchor(self.width_full / 2.0 - (self.width_value / 2.0) - ARROW_PAD, OFFSET_TEXT) 
  237. 		end 
  238. 	else 
  239. 		-- Label text, align to center 
  240. 		--self.text_label:set_anchor(-(self.width_full / 2.0) + 2, OFFSET_TEXT) 
  241. 		--self.text_label:set_property("auto_offset", "w") 
  242. 		self.text_label:set_anchor(0, OFFSET_TEXT) 
  243. 		self.text_label:set_property("auto_offset", "c") 
  244. 	end 
  245. end 
  246.  
  247. -- Increment the index by 1 and update the value text 
  248. function Vdo_button_pc:toggle_next() 
  249. 	self.o_index = self.o_index + 1 
  250. 	if self.o_index > #self.options then 
  251. 		self.o_index = 1 
  252. 	end 
  253. 	 
  254. 	self:set_value(self.options[self.o_index]) 
  255. end 
  256.  
  257. -- Decrement the index by 1 and update the value text 
  258. function Vdo_button_pc:toggle_prev() 
  259. 	self.o_index = self.o_index - 1 
  260. 	if self.o_index < 1 then 
  261. 		self.o_index = #self.options 
  262. 	end 
  263. 	 
  264. 	self:set_value(self.options[self.o_index]) 
  265. end 
  266.  
  267. -- Toggle the options 
  268. function Vdo_button_pc:toggle_dir(direction) 
  269. 	if direction == 0 then 
  270. 		self:toggle_next() 
  271. 	else 
  272. 		self:toggle_prev() 
  273. 	end 
  274. end 
  275.  
  276. -- Toggles between the ease types (changes the icon) 
  277. function Vdo_button_pc:toggle_ease() 
  278. 	self.icon_num = self.icon_num + 1 
  279. 	if self.icon_num > PC_ICON_EASE_BOTH then -- last ease icon 
  280. 		self.icon_num = PC_ICON_EASE_NONE -- first ease icon 
  281. 	end 
  282. 	 
  283. 	self:set_icon(self.icon_num) 
  284. end 
  285.  
  286. -- Scales the slider's images so it reflects the slider's value relative to the min/max value 
  287. -- Also positions the slider text 
  288. function Vdo_button_pc:slider_scale_bar() 
  289. 	local percent = (self.s_value - self.s_min) / (self.s_max - self.s_min) 
  290. 	 
  291. 	-- Set the size of the gray bars so they bracket the text 
  292. 	local TEXT_BUFFER = 50 
  293. 	local width = self.width_value - TEXT_BUFFER 
  294. 	self.bar_value_l:set_actual_size(max(0.01, width * percent), self.height - 12) 
  295. 	self.bar_value_r:set_actual_size(max(0.01, width * (1.0 - percent)), self.height - 12) 
  296. 	 
  297. 	-- Align the text 
  298. 	local text_offset = (self.width_full / 2.0) - ARROW_PAD - self.width_value -- The default position of the left side of the value bar 
  299. 	text_offset = text_offset + width * percent + TEXT_BUFFER * 0.5 - 1 -- Add the size of the left bar, plus center it (with a slight fudge factor) 
  300. 	self.text_value:set_anchor(text_offset, OFFSET_TEXT) 
  301. 	 
  302. 	-- Make the text skinny (if necessary) 
  303. 	if self.s_value < -99 then 
  304. 		self.text_value:set_scale(0.6667, 0.8) 
  305. 	else 
  306. 		self.text_value:set_scale(0.8, 0.8) 
  307. 	end 
  308. end 
  309.  
  310. function Vdo_button_pc:set_slider_value(value) 
  311. 	self.s_value = floor(value) 
  312. 	self:set_value(""..self.s_value) -- Concatting ensures the value is displayed correctly 
  313. 	self:slider_scale_bar() 
  314. end 
  315.  
  316. -- For slider buttons, set the value based on the mouse X coordinate 
  317. function Vdo_button_pc:mouse_set_slider(mouse_x) 
  318. 	if self.type == PC_TYPE_SLIDER then 
  319. 		-- Get the screen coordinates of the slider outline bar 
  320. 		local slider_x, slider_y = vint_get_global_anchor(self.bar_outline.handle, self.doc_handle) 
  321. 		local slider_width = element_get_actual_size(self.bar_outline.handle) 
  322. 		 
  323. 		local screen_w, screen_h = vint_get_screen_size() 
  324. 		if vint_is_std_res() then 
  325. 			mouse_x = (mouse_x * 640 / screen_w) 
  326. 			slider_width = slider_width * (0.666667) 
  327. 		else  
  328. 			mouse_x = (mouse_x * 1280 / screen_w) 
  329. 		end 
  330. 		 
  331. 		-- Compress the area we're comparing against (FYI: anchor's on the right) 
  332. 		local SIDE_OFFSET = 15 
  333. 		local min_x = slider_x - slider_width + SIDE_OFFSET 
  334. 		local max_x = slider_x - SIDE_OFFSET 
  335. 		 
  336. 		-- Convert the screen coordinates to a value 
  337. 		local new_value = ((mouse_x - min_x) / (max_x - min_x)) * (self.s_max - self.s_min) + self.s_min 
  338. 		 
  339. 		-- Clamp the slider if necessary 
  340. 		if new_value > self.s_max then 
  341. 			new_value = self.s_max 
  342. 		elseif new_value < self.s_min then 
  343. 			new_value = self.s_min 
  344. 		end 
  345.  
  346. 		-- Round the value to the nearest snap value (may want to round by more for certain sliders) 
  347. 		new_value = floor(new_value) 
  348. 		local over = new_value % self.s_snap 
  349. 		self.s_value = new_value - over 
  350.  
  351. 		-- Set the value and update the slider 
  352. 		self:set_value(""..self.s_value) -- Concatting ensures the value is displayed correctly 
  353. 		self:slider_scale_bar() 
  354. 		 
  355. 		-- Make the button stay highlighted (slight hack) 
  356. 		self:mouse_move() 
  357. 	end 
  358. end 
  359.  
  360. -- Move the button by x, y 
  361. function Vdo_button_pc:move(x, y) 
  362. 	local cur_x, cur_y = self:get_anchor() 
  363. 	self:set_anchor(cur_x + x, cur_y + y) 
  364. end 
  365.  
  366. -- Sets the button to inactive (it grays out, does not respond to input) 
  367. function Vdo_button_pc:set_inactive() 
  368. 	self.inactive = true 
  369. 	self:set_colors(false, false) 
  370. end 
  371.  
  372. -- Sets the button to active (it responds to mouse input) 
  373. function Vdo_button_pc:set_active() 
  374. 	self.inactive = false 
  375. 	self:set_colors(false, false) 
  376. end 
  377.  
  378. function Vdo_button_pc:is_active() 
  379. 	if (self.inactive) then 
  380. 		return false 
  381. 	else 
  382. 		return true 
  383. 	end 
  384. end 
  385.  
  386. -- Adds mouse input subscriptions to the input tracker 
  387. -- 
  388. -- @func_prefix		Name of the screen that is currently using the hint bar 
  389. -- @input_tracker		The input tracker to hold the mouse inputs events 
  390. -- @priority			The priority of the input event 
  391. function Vdo_button_pc:add_mouse_inputs(func_prefix, input_tracker, add_click, priority) 
  392. 	if func_prefix == nil then 
  393. 		return 
  394. 	end 
  395. 	 
  396. 	priority = priority or 50 
  397. 	 
  398. 	local mouse_click_function = func_prefix.."_mouse_click" 
  399. 	local mouse_move_function = func_prefix.."_mouse_move" 
  400.  
  401. 	if add_click == true then 
  402. 		input_tracker:add_mouse_input("mouse_click", mouse_click_function, priority, self.handle) 
  403. 	end 
  404. 	input_tracker:add_mouse_input("mouse_move", mouse_move_function, priority, self.handle) 
  405. 		 
  406. 	-- NOTE: Current implementation is not ideal for two reasons: 
  407. 	--  1) Click responds on mouse LMB up, meaning the activated coloring is currently the same as highlighting 
  408. 	--		 Note that the rest of the UI doesn't have separate coloring, so this is ok for now 
  409. 	--     Really need to have LMB down and LMB up events (up triggers action, down triggers activated coloring) 
  410. 	--  2) Need to add a backdrop item behind all the buttons that captures the move event 
  411. 	--     so the buttons don't stay highlighted after the mouse moves off 
  412. end 
  413.  
  414. -- Responds to mouse clicking on a slider arrow 
  415. -- NOTE: Not called automatically, call from the screen's input handler 
  416. function Vdo_button_pc:slider_arrow_click(left) 
  417. 	-- Increase/decrease the value by step, and cap it 
  418. 	if left == true then 
  419. 		self:set_colors(false, true) 
  420. 		self.s_value = self.s_value - self.s_step 
  421. 		if self.s_value < self.s_min then 
  422. 			self.s_value = self.s_min 
  423. 		end 
  424. 	else 
  425. 		self:set_colors(false, true) 
  426. 		self.s_value = self.s_value + self.s_step 
  427. 		if self.s_value > self.s_max then 
  428. 			self.s_value = self.s_max 
  429. 		end 
  430. 	end 
  431. 	 
  432. 	-- Update the visuals 
  433. 	self:set_value(""..self.s_value) -- Concatting ensures the value is displayed correctly 
  434. 	self:slider_scale_bar() 
  435. end 
  436.  
  437. -- Responds the mouse moving over an arrow 
  438. -- NOTE: Not called automatically, call from the screen's input handler 
  439. function Vdo_button_pc:slider_arrow_move(left) 
  440. 	if left == true then 
  441. 		self:set_colors(true, false) 
  442. 	else 
  443. 		self:set_colors(true, false) 
  444. 	end 
  445. end 
  446.  
  447. -- Responds to mouse over by setting the appropriate coloring 
  448. -- NOTE: Not called automatically, call from the screen's input handler 
  449. function Vdo_button_pc:mouse_move() 
  450. 	if self.type == PC_TYPE_SLIDER then 
  451. 		-- Sliders can't be clicked on normally, so they have special highlighting when not over an arrow 
  452. 		if self.inactive == false then 
  453. 			self.bar_solid:set_color(COLOR_SOLID_HIGHLIGHT) 
  454. 			self:set_fg_color(COLOR_TEXT_HIGHLIGHT)	 
  455. 			self:set_arrow_color(COLOR_ARROW_NO_HIGHLIGHT) 
  456. 			self:set_slider_bar_color(COLOR_VALUE_HIGHLIGHT) 
  457. 		end 
  458. 	else	 
  459. 		self:set_colors(true, false) 
  460. 	end 
  461. end 
  462.  
  463. -- Responds to mouse clicks by setting the appropriate coloring (see NOTE above about why this isn't ideal currently) 
  464. -- NOTE: Not called automatically, call from the screen's input handler 
  465. function Vdo_button_pc:mouse_click() 
  466. 	self:set_colors(false, true) 
  467. end 
  468.  
  469. -- Responds to mouse off by setting the appropriate coloring 
  470. function Vdo_button_pc:mouse_off() 
  471. 	self:set_colors(false, false) 
  472. end 
  473.  
  474. -- Find the width of the label's text 
  475. function Vdo_button_pc:get_label_width() 
  476. 	return self.text_label:get_actual_size() + 7 -- Add a little padding 
  477. end 
  478.  
  479. -- Get the width of the arrows in a toggle/slider button 
  480. function Vdo_button_pc:get_arrow_double_width() 
  481. 	return ARROW_PAD * 2 
  482. end 
  483.  
  484. -- Find the width of the current value's text 
  485. -- NOTE: If button has multiple values, you'll need to account for that 
  486. function Vdo_button_pc:get_value_width() 
  487. 	if self.type == PC_TYPE_SLIDER then 
  488. 		return 100 
  489. 	else 
  490. 		return self.text_value:get_actual_size() + 3 -- Add some padding 
  491. 	end 
  492. end 
  493.  
  494. -- Returns the current option index (only valid for toggles)  
  495. function Vdo_button_pc:get_option_index() 
  496. 	if self.type == PC_TYPE_TOGGLE then 
  497. 		return self.o_index 
  498. 	else 
  499. 		return 0 
  500. 	end 
  501. end 
  502.  
  503. -- Set the option index directly (and update the value text) 
  504. function Vdo_button_pc:set_option_index(idx) 
  505. 	if self.type == PC_TYPE_TOGGLE then 
  506. 		self.o_index = idx 
  507. 		self:set_value(self.options[self.o_index]) 
  508. 	end 
  509. end 
  510.  
  511. function Vdo_button_pc:get_tooltip() 
  512. 	return self.tooltip 
  513. end 
  514.  
  515. PC_ICON_PLAY = 1 
  516. PC_ICON_PLAY_SLOW = 2 
  517. PC_ICON_PLAY_FAST = 3 
  518. PC_ICON_PAUSE = 4  
  519. PC_ICON_REWIND = 5  
  520. PC_ICON_OPTIONS = 6  
  521. PC_ICON_AV_OPTIONS = 7  
  522. PC_ICON_SAVE = 8 
  523. PC_ICON_EXPORT = 9  
  524. PC_ICON_EXIT = 10  
  525. PC_ICON_LOCKED = 11  
  526. PC_ICON_UNLOCKED = 12  
  527. PC_ICON_EASE_NONE = 13 -- NOTE: Ease icons should be continuous in number (so cycling them will work) 
  528. PC_ICON_EASE_OUT = 14 
  529. PC_ICON_EASE_IN = 15 
  530. PC_ICON_EASE_BOTH = 16  
  531.  
  532. --	Sets the icon for the button 
  533. -- See the if-else below to find icon numbers 
  534. function Vdo_button_pc:set_icon(icon) 
  535. 	self.icon_num = icon 
  536. 	if icon == 0 then 
  537. 		self.img_icon:set_visible(false) 
  538. 		self.text_label:set_visible(true) 
  539. 		self.height = HEIGHT_TEXT 
  540. 	else 
  541. 		self.text_label:set_visible(false) 
  542. 		self.img_icon:set_visible(true) 
  543. 		self.height = HEIGHT_ICON 
  544. 		 
  545. 		-- Set the icon 
  546. 		if icon == PC_ICON_PLAY then				self.img_icon:set_image("ui_pc_icon_play") 
  547. 		elseif icon == PC_ICON_PLAY_SLOW then	self.img_icon:set_image("ui_pc_icon_play_slow") -- TODO: REPLACE THIS 
  548. 		elseif icon == PC_ICON_PLAY_FAST then	self.img_icon:set_image("ui_pc_icon_play_fast") -- TODO: REPLACE THIS 
  549. 		elseif icon == PC_ICON_PAUSE then		self.img_icon:set_image("ui_pc_icon_pause") 
  550. 		elseif icon == PC_ICON_REWIND then		self.img_icon:set_image("ui_pc_icon_rewind") 
  551. 		elseif icon == PC_ICON_OPTIONS then		self.img_icon:set_image("ui_pc_icon_options") 
  552. 		elseif icon == PC_ICON_AV_OPTIONS then	self.img_icon:set_image("ui_pc_icon_av_options") 
  553. 		elseif icon == PC_ICON_SAVE then			self.img_icon:set_image("ui_pc_icon_save") 
  554. 		elseif icon == PC_ICON_EXPORT then		self.img_icon:set_image("ui_pc_icon_export") 
  555. 		elseif icon == PC_ICON_EXIT then			self.img_icon:set_image("ui_pc_icon_exit") 
  556. 		elseif icon == PC_ICON_LOCKED then		self.img_icon:set_image("ui_pc_icon_locked") 
  557. 		elseif icon == PC_ICON_UNLOCKED then	self.img_icon:set_image("ui_pc_icon_unlocked") 
  558. 		elseif icon == PC_ICON_EASE_NONE then	self.img_icon:set_image("ui_pc_icon_ease_none") 
  559. 		elseif icon == PC_ICON_EASE_IN then		self.img_icon:set_image("ui_pc_icon_ease_in") 
  560. 		elseif icon == PC_ICON_EASE_OUT then	self.img_icon:set_image("ui_pc_icon_ease_out") 
  561. 		elseif icon == PC_ICON_EASE_BOTH then	self.img_icon:set_image("ui_pc_icon_ease_both") 
  562. 		end 
  563. 	end 
  564. end 
  565.  
  566. -- Set the offset of the icon 
  567. function Vdo_button_pc:set_icon_offset(x, y) 
  568. 	self.img_icon:set_anchor(x, y) 
  569. end 
  570.  
  571. -- Set the scale of the icon 
  572. function Vdo_button_pc:set_icon_scale(scale) 
  573. 	self.img_icon:set_scale(scale, scale) 
  574. end 
  575.  
  576. -- Make the button a normal size so it fits 
  577. function Vdo_button_pc:set_icon_mid() 
  578. 	self.height = HEIGHT_TEXT 
  579. end 
  580.  
  581. -- Make the button use the smallest height 
  582. -- Call before setting the width, since that actually resizes the button 
  583. function Vdo_button_pc:set_button_mini() 
  584. 	self.height = HEIGHT_MINI 
  585. end 
  586.  
  587. -- Sets the colors for all the button components based on the button's state 
  588. function Vdo_button_pc:set_colors(highlighted, activated) 
  589. 	if self.inactive then 
  590. 		self.bar_solid:set_color(COLOR_SOLID_INACTIVE) 
  591. 		self:set_fg_color(COLOR_TEXT_INACTIVE) 
  592. 		self:set_arrow_color(COLOR_SOLID_INACTIVE) 
  593. 		self:set_slider_bar_color(COLOR_VALUE_INACTIVE) 
  594. 	elseif highlighted or activated then 
  595. 		self.bar_solid:set_color(COLOR_SOLID_HIGHLIGHT) 
  596. 		self:set_fg_color(COLOR_TEXT_HIGHLIGHT)	 
  597. 		self:set_arrow_color(COLOR_TEXT_HIGHLIGHT) 
  598. 		self:set_slider_bar_color(COLOR_VALUE_HIGHLIGHT) 
  599. 	else 
  600. 		self.bar_solid:set_color(COLOR_SOLID_NORMAL) 
  601. 		self:set_fg_color(COLOR_TEXT_NORMAL) 
  602. 		-- Sliders and toggles have different rules for how the arrows highlight 
  603. 		if self.type == PC_TYPE_SLIDER then 
  604. 			self:set_arrow_color(COLOR_ARROW_NORMAL) 
  605. 		else  
  606. 			self:set_arrow_color(COLOR_SOLID_NORMAL) 
  607. 		end 
  608. 		self:set_slider_bar_color(COLOR_VALUE_NORMAL) 
  609. 	end 
  610. end 
  611.  
  612. -- Sets the color of all FG objects (text and images) 
  613. function Vdo_button_pc:set_fg_color(color) 
  614. 	self.img_icon:set_color(color) 
  615. 	self.text_label:set_color(color) 
  616. 	if self.type ~= PC_TYPE_SLIDER then 
  617. 		self.text_value:set_color(color) 
  618. 	else 
  619. 		-- Sliders darken their value text when inactive 
  620. 		if self.inactive then 
  621. 			self.text_value:set_color(COLOR_VALUE_HIGHLIGHT) 
  622. 		else  
  623. 			self.text_value:set_color(COLOR_SLIDER_TEXT) 
  624. 		end 
  625. 	end 
  626. end 
  627.  
  628. -- Set the color of the gray slider images on either side of the text 
  629. function Vdo_button_pc:set_slider_bar_color(color) 
  630. 	self.bar_value_l:set_color(color) 
  631. 	self.bar_value_r:set_color(color) 
  632. end 
  633.  
  634. -- Sets the color of the arrows 
  635. function Vdo_button_pc:set_arrow_color(color) 
  636. 	self.img_left:set_color(color) 
  637. 	self.img_right:set_color(color) 
  638. end