./cinema_clip_editor_timeline.lua

  1. -- Zones 
  2. Num_zones = 0 
  3. Zones = {} 
  4.  
  5. --[[ Format for Zones 
  6. EDITOR DATA 
  7. .UID			-- Unique ID (used by code) 
  8. .index		-- Number (constant, should not change after init) 
  9. .time_start	-- Starting time 
  10. .time_end	-- Ending time 
  11. .solid 		-- Base object: solid fill (can be a gradient, see blend_next below) 
  12. .lock 		-- Base object: export lock icon (can be locked/unlocked, for display only) 
  13. .splitter 	-- Base object: splitter for zone (after current zone, disabled for last zone) 
  14. .text 		-- Base object: text for time display 
  15. .inactive 	-- Flag for whether the camera position can be edited (always true on all but one zone) 
  16. .highlight 	-- Flag for whether the current zone is selected (by the timeline marker) 
  17. .blend_next -- Flag for whether the next zone's type is set to Blend (affects the zone's solid image) 
  18. .x .y .w .h -- Coordinates/sizes for the zone (anchored left-center) 
  19. .right 		-- Final coordinates for right side of the zone (including the splitter), used in alignment 
  20. ]]-- Zones 
  21.  
  22. local MAX_ZONES = 32 
  23.  
  24. -- The timeline object that handles mouse movements 
  25. Timeline_bg = {} 
  26.  
  27. -- Marker objects 
  28. Marker_timeline = {} 
  29. Marker_playback = {} 
  30. Marker_select = {} 
  31.  
  32. -- Marker subobjects (shouldn't need to access from outside this file) 
  33. local Mtl_text = nil 
  34. local Mtl_text_bg = nil 
  35. local Mtl_prev = nil 
  36. local Mtl_next = nil 
  37. local Mtl_bg_prev = nil 
  38. local Mtl_bg_next = nil 
  39.  
  40. local Mpb_text = nil 
  41. local Mpb_text_bg = nil 
  42. local Mpb_play_to_arrow = nil 
  43. local Mpb_play_to_end = nil 
  44. local Mpb_play_to_line = nil 
  45.  
  46. -- General timeline properties 
  47. Timeline_time_end = 30 
  48. Marker_time_timeline = 0 
  49. Marker_time_playback = 0 
  50. Marker_time_playback_goal = -1 
  51.  
  52. -- State of playback/etc 
  53. Playback_disabled = false 
  54. Rewinding = false 
  55.  
  56. -- Other flags/properties 
  57. Dragging_splitter = false 
  58. Drag_splitter_id = 0 
  59.  
  60. -- Base elements 
  61. local Base_zone_solid = nil 
  62. local Base_zone_lock = nil 
  63. local Base_zone_splitter = nil 
  64. local Base_zone_text = nil 
  65.  
  66. -- Color defines 
  67. local COLOR_TEXT_NORMAL = {R=160/255, G=160/255, B=160/255} 
  68. local COLOR_TEXT_HIGHLIGHT = {R=0/255, G=0/255, B=0/255} 
  69. local COLOR_TEXT_INACTIVE_NORMAL = {R=50/255, G=50/255, B=50/255} 
  70. local COLOR_TEXT_INACTIVE_HIGHLIGHT = {R=118/255, G=0/255, B=157/255} 
  71. local COLOR_SOLID_NORMAL = {R=0/255, G=0/255, B=0/255} 
  72. local COLOR_SOLID_HIGHLIGHT = {R=148/255, G=0/255, B=197/255} 
  73. local COLOR_LOCK_NORMAL = {R=60/255, G=60/255, B=60/255} 
  74. local COLOR_LOCK_HIGHLIGHT = {R=118/255, G=0/255, B=157/255} 
  75. local COLOR_SPLITTER_NORMAL = {R=60/255, G=0/255, B=80/255} 
  76. local COLOR_SPLITTER_HIGHLIGHT = {R=178/255, G=0/255, B=237/255} 
  77.  
  78. -- Size defines 
  79. local TIMELINE_WIDTH = 1120 
  80. local TIMELINE_HEIGHT = 28 
  81. local TIMELINE_X = 640 
  82. if vint_is_std_res() then 
  83. 	TIMELINE_WIDTH = TIMELINE_WIDTH * 0.75 
  84. 	TIMELINE_X = TIMELINE_X * 0.75 
  85. end 
  86. local TIMELINE_Y = 60 
  87. local TIMELINE_BORDER = 0 
  88. local SPLITTER_WIDTH = 4 
  89. local ZONE_MIN_WIDTH = 2 
  90. local TIMELINE_LEFT -- Set in init 
  91. local TIMELINE_RIGHT -- Set in init 
  92.  
  93. -- Minimum time for a zone when resizing 
  94. local ZONE_MIN_TIME = 0.05 
  95.  
  96. function cinema_clip_editor_timeline_init() 
  97. 	-- Initialize the background element 
  98. 	Timeline_bg = Vdo_base_object:new("timeline_bg", 0, Cinema_clip_editor_doc_handle) 
  99. 	Timeline_bg:set_actual_size(TIMELINE_WIDTH, TIMELINE_HEIGHT) 
  100. 	Timeline_bg:set_anchor(TIMELINE_X, TIMELINE_Y) 
  101. 	TIMELINE_LEFT = TIMELINE_X - TIMELINE_WIDTH * 0.5 + TIMELINE_BORDER * 0.5 
  102. 	TIMELINE_RIGHT = TIMELINE_X + TIMELINE_WIDTH * 0.5 - TIMELINE_BORDER * 0.5 
  103. 	 
  104. 	-- Get the marker objects 
  105. 	Marker_select = Vdo_base_object:new("timeline_carat", 0, Cinema_clip_editor_doc_handle) 
  106. 	 
  107. 	Marker_timeline = Vdo_base_object:new("marker_timeline_grp", 0, Cinema_clip_editor_doc_handle) 
  108. 	Mtl_text = Vdo_base_object:new("mtl_text", 0, Cinema_clip_editor_doc_handle) 
  109. 	Mtl_text_bg = Vdo_base_object:new("mtl_bg", 0, Cinema_clip_editor_doc_handle) 
  110. 	Mtl_prev = Vdo_base_object:new("mtl_arrow_left", 0, Cinema_clip_editor_doc_handle) 
  111. 	Mtl_next = Vdo_base_object:new("mtl_arrow_right", 0, Cinema_clip_editor_doc_handle) 
  112. 	Mtl_bg_prev = Vdo_base_object:new("mtl_arrow_bg_left", 0, Cinema_clip_editor_doc_handle) 
  113. 	Mtl_bg_next = Vdo_base_object:new("mtl_arrow_bg_right", 0, Cinema_clip_editor_doc_handle) 
  114. 	 
  115. 	Marker_playback = Vdo_base_object:new("marker_playback_grp", 0, Cinema_clip_editor_doc_handle) 
  116. 	Mpb_text = Vdo_base_object:new("mpb_text", 0, Cinema_clip_editor_doc_handle) 
  117. 	Mpb_text_bg = Vdo_base_object:new("mpb_bg", 0, Cinema_clip_editor_doc_handle) 
  118. 	Mpb_play_to_arrow = Vdo_base_object:new("mpb_play_to_arrow", 0, Cinema_clip_editor_doc_handle) 
  119. 	Mpb_play_to_end = Vdo_base_object:new("mpb_play_to_line", 0, Cinema_clip_editor_doc_handle) 
  120. 	Mpb_play_to_line = Vdo_base_object:new("mpb_play_to_end", 0, Cinema_clip_editor_doc_handle) 
  121. 	 
  122. 	-- Get the base objects 
  123. 	Base_zone_solid = Vdo_base_object:new("zone_solid", 0, Cinema_clip_editor_doc_handle) 
  124. 	Base_zone_lock = Vdo_base_object:new("zone_lock", 0, Cinema_clip_editor_doc_handle) 
  125. 	Base_zone_splitter = Vdo_base_object:new("zone_splitter", 0, Cinema_clip_editor_doc_handle) 
  126. 	Base_zone_text = Vdo_base_object:new("zone_text", 0, Cinema_clip_editor_doc_handle) 
  127. 	 
  128. 	-- Fill options (updates Timeline_time_end) 
  129. 	vint_dataresponder_request("cinema_editor_dr", "cinema_clip_editor_update_options", 0) 
  130. 	 
  131. 	-- Set up the default zone data 
  132. 	for i = 1, MAX_ZONES do 
  133. 		Zones[i] = {} 
  134. 		cinema_clip_editor_zone_init(Zones[i], i) 
  135. 	end 
  136. 	Num_zones = 0 
  137. 	 
  138. 	cinema_clip_editor_load_zones() 
  139. 	 
  140. 	-- Reset marker objects 
  141. 	cinema_clip_editor_timeline_marker_set(TIMELINE_LEFT) 
  142. 	cinema_clip_editor_zone_update_highlight() 
  143. 	cinema_clip_editor_playback_marker_set(0) 
  144. 	 
  145. 	-- Hide base objects 
  146. 	Base_zone_solid:set_visible(false) 
  147. 	Base_zone_lock:set_visible(false) 
  148. 	Base_zone_splitter:set_visible(false) 
  149. 	Base_zone_text:set_visible(false) 
  150. 	 
  151. 	-- Subscribe to playback marker updates 
  152. 	vint_dataitem_add_subscription("playback_caret_di", "update", "cinema_clip_editor_playback_marker_update_di") 
  153. end 
  154.  
  155. -- Update the playback marker from code 
  156. function cinema_clip_editor_playback_marker_update_di(di_h) 
  157. 	local marker_time = vint_dataitem_get(di_h) 
  158. 	cinema_clip_editor_playback_marker_set(marker_time) 
  159. 	if CCE_option_beginner_mode == true then 
  160. 		cinema_clip_editor_timeline_marker_set_time(marker_time) 
  161. 	end 
  162. 	 
  163. 	-- Set play/pause buttons to disabled if the marker is done 
  164. 	if marker_time >= Timeline_time_end then 
  165. 		cinema_clip_editor_disable_play_pause() 
  166. 	end 
  167. end 
  168.  
  169. function cinema_clip_editor_disable_play_pause() 
  170. 	if Rewinding == false then 
  171. 		CCE_free_buttons[BTN_FREE_PAUSE].button:set_inactive() 
  172. 		CCE_free_buttons[BTN_FREE_PLAY_SLOW].button:set_inactive() 
  173. 		CCE_free_buttons[BTN_FREE_PLAY].button:set_inactive() 
  174. 		CCE_free_buttons[BTN_FREE_PLAY_FAST].button:set_inactive() 
  175. 		Playback_disabled = true 
  176. 	end 
  177. end 
  178.  
  179. function cinema_clip_editor_load_zones() 
  180. 	-- Get zones from the game, if they exist 
  181. 	vint_dataresponder_request("camera_zone_dr", "cinema_clip_editor_get_zones", MAX_ZONES) 
  182. 	 
  183. 	-- No zones, so create one 
  184. 	if Num_zones == 0 then 
  185. 		-- Create the default zone 
  186. 		Zones[1].UID = cinema_editor_create_camera_zone(0.0) 
  187. 		Num_zones = 1 
  188. 	 
  189. 		-- Set up data responder query for default zone 
  190. 		vint_dataresponder_request("camera_zone_dr", "cinema_clip_editor_update_zone", 1, Zones[1].UID) 
  191. 	end 
  192. 	 
  193. 	cinema_clip_editor_zone_update_times() 
  194. 	cinema_clip_editor_zone_update_all() 
  195. end 
  196.  
  197. function cinema_clip_editor_get_zones(uid, start, z_type, mode, desc, dof_mode, x_lock, slomo, fov, fov_bl, tilt, tilt_bl, hcam, hcam_bl, ddist, ddist_bl, dfocal, dfocal_bl, pos_bl, rot_bl, slomo_bl) 
  198. 	-- Check if this zone id already exists 
  199. 	for i = 1, Num_zones do 
  200. 		if Zones[i].UID == uid then 
  201. 			return 
  202. 		end 
  203. 	end 
  204. 	 
  205. 	-- Check if we support this many zones 
  206. 	if Num_zones == MAX_ZONES then 
  207. 		return 
  208. 	end 
  209. 	 
  210. 	Num_zones = Num_zones + 1 
  211. 	local zone = Zones[Num_zones] 
  212. 	 
  213. 	zone.UID = uid 
  214. 	zone.time_start = start 
  215. 	zone.time_end = Timeline_time_end 
  216. 	zone.blend_next = false 
  217. 	 
  218. 	-- And now the rest of the data 
  219. 	zone.zone_type = z_type 
  220. 	zone.camera_mode = mode 
  221. 	zone.dof_mode = dof_mode 
  222. 	zone.export_lock = x_lock 
  223. 	zone.slow_mo = slomo 
  224. 	zone.slow_mo_blend = slomo_bl -- Added later, so it comes after pos_bl in the parameters 
  225. 	zone.fov = fov 
  226. 	zone.fov_blend = fov_bl 
  227. 	zone.tilt = tilt 
  228. 	zone.tilt_blend = tilt_bl 
  229. 	zone.handycam = hcam 
  230. 	zone.handycam_blend = hcam_bl 
  231. 	zone.dof_dist = ddist 
  232. 	zone.dof_dist_blend = ddist_bl 
  233. 	zone.dof_focal = dfocal 
  234. 	zone.dof_focal_blend = dfocal_bl 
  235. 	zone.camera_blend = pos_bl -- This should always be the same as rot_bl 
  236. end 
  237.  
  238. -- Update the zone (data responder) 
  239. function cinema_clip_editor_update_zone(uid, start, z_type, mode, desc, dof_mode, x_lock, slomo, fov, fov_bl, tilt, tilt_bl, hcam, hcam_bl, ddist, ddist_bl, dfocal, dfocal_bl, pos_bl, rot_bl, slomo_bl) 
  240. 	-- Find the correct camera zone 
  241. 	local this_zone = -1 
  242. 	for i = 1, Num_zones do 
  243. 		if Zones[i].UID == uid then 
  244. 			this_zone = i 
  245. 		end 
  246. 	end 
  247. 	 
  248. 	local i = this_zone 
  249. 	-- Update the zone data and visuals 
  250. 	if i > -1 then 
  251. 		-- Times and visual flags first 
  252. 		Zones[i].time_start = start 
  253. 		Zones[i].time_end = Timeline_time_end 
  254. 		Zones[i].blend_next = false 
  255. 		 
  256. 		-- Update stuff that depends on the next zone (if valid) 
  257. 		if Num_zones > i then 
  258. 			Zones[i].time_end = Zones[i + 1].time_start 
  259. 			if Zones[i + 1].zone_type == 0 then 
  260. 				Zones[i].blend_next = false 
  261. 			else 
  262. 				Zones[i].blend_next = true 
  263. 			end 
  264. 		end 
  265. 		 
  266. 		-- And now the rest of the data 
  267. 		Zones[i].zone_type = z_type 
  268. 		Zones[i].camera_mode = mode 
  269. 		Zones[i].dof_mode = dof_mode 
  270. 		Zones[i].export_lock = x_lock 
  271. 		Zones[i].slow_mo = slomo 
  272. 		Zones[i].slow_mo_blend = slomo_bl -- Added later, so it comes after pos_bl in the parameters 
  273. 		Zones[i].fov = fov 
  274. 		Zones[i].fov_blend = fov_bl 
  275. 		Zones[i].tilt = tilt 
  276. 		Zones[i].tilt_blend = tilt_bl 
  277. 		Zones[i].handycam = hcam 
  278. 		Zones[i].handycam_blend = hcam_bl 
  279. 		Zones[i].dof_dist = ddist 
  280. 		Zones[i].dof_dist_blend = ddist_bl 
  281. 		Zones[i].dof_focal = dfocal 
  282. 		Zones[i].dof_focal_blend = dfocal_bl 
  283. 		Zones[i].camera_blend = pos_bl -- This should always be the same as rot_bl 
  284. 	end 
  285. end 
  286.  
  287. -- Convert a number to a 2 decimal string 
  288. function cinema_clip_editor_num_to_string_2_decimal(num) 
  289. 	local whole = floor(num) 
  290. 	local decimal = floor(num * 100) - whole * 100 
  291. 	if decimal < 10 then 
  292. 		return (whole..".0"..decimal) 
  293. 	else 
  294. 		return (whole.."."..decimal) 
  295. 	end 
  296. end 
  297.  
  298. -- Convert a number into one with two decimals (5.6423438 -> 5.64) 
  299. function cinema_clip_editor_num_round_2_decimal(num) 
  300. 	local whole = floor(num) 
  301. 	local decimal = floor(num * 100) - whole * 100 
  302. 	return whole + (decimal * 0.01) 
  303. end 
  304.  
  305. -------------------------------------------------------------------------- 
  306. -- Zone functions 
  307. -------------------------------------------------------------------------- 
  308.  
  309. -- Insert a new zone at zone_time (likely Marker_time_timeline) 
  310. function cinema_clip_editor_zone_insert(zone_time, copy_current) 
  311. 	-- Make sure we don't run out of zones 
  312. 	if Num_zones == MAX_ZONES then 
  313. 		return 
  314. 	end 
  315. 	 
  316. 	-- Find which number we're inserting 
  317. 	local cur_zone = cinema_clip_editor_zone_highlight() 
  318. 	 
  319. 	local zone_to_copy = cur_zone 
  320. 	if copy_current == false then 
  321. 		if cur_zone < Num_zones then 
  322. 			-- By the time we tell the game about this, it will be copied to the next slot 
  323. 			zone_to_copy = cur_zone + 2 
  324. 		end 
  325. 	end 
  326. 		 
  327. 	-- Increase the number of zones 
  328. 	Num_zones = Num_zones + 1 
  329. 	 
  330. 	-- Save the newest zone off 
  331. 	local temp_zone = {} 
  332. 	cinema_clip_editor_zone_copy(temp_zone, Zones[Num_zones]) 
  333. 	 
  334. 	-- Copy zone data (starting with the last one) to the prev index 
  335. 	for i = Num_zones, cur_zone + 2, -1 do 
  336. 		cinema_clip_editor_zone_copy(Zones[i], Zones[i - 1]) 
  337. 	end 
  338. 	 
  339. 	-- Copy temp zone data to the new zone 
  340. 	cinema_clip_editor_zone_copy(Zones[cur_zone + 1], temp_zone) 
  341. 	 
  342. 	-- Set the times for the new zone 
  343. 	cinema_clip_editor_zone_set_times(Zones[cur_zone + 1], zone_time, Zones[cur_zone].time_end) 
  344. 	 
  345. 	-- Tell the game about the new zone (copy the current or next one) 
  346. 	Zones[cur_zone + 1].UID = cinema_editor_create_camera_zone(zone_time, Zones[zone_to_copy].UID) 
  347. 	-- Get additional data from the game about the new zone 
  348. 	vint_dataresponder_request("camera_zone_dr", "cinema_clip_editor_update_zone", 1, Zones[cur_zone + 1].UID) 
  349. 	 
  350. 	-- Cut down the previous zones end time 
  351. 	Zones[cur_zone].time_end = zone_time 
  352. 	 
  353. 	-- Update everything 
  354. 	cinema_clip_editor_zone_update_all() 
  355. 	cinema_clip_editor_zone_update_highlight() 
  356. 	cinema_clip_editor_zone_update_inactive() 
  357. end 
  358.  
  359. -- Deletes the currently highlighted zone 
  360. function cinema_clip_editor_zone_delete_current() 
  361. 	if Num_zones == 1 then 
  362. 		return 
  363. 	end 
  364. 	 
  365. 	-- Find which number we're deleting 
  366. 	local cur_zone = cinema_clip_editor_zone_highlight() 
  367. 	 
  368. 	-- Save off that zone 
  369. 	local temp_zone = {} 
  370. 	cinema_clip_editor_zone_copy(temp_zone, Zones[cur_zone]) 
  371.  
  372. 	-- Tell the game that the zone is deleted 
  373. 	vint_dataresponder_post("camera_zone_dr", "delete", Zones[cur_zone].UID) 
  374. 	 
  375. 	-- Reduce the number of zones 
  376. 	Num_zones = Num_zones - 1 
  377.  
  378. 	if cur_zone == 1 then 
  379. 		-- If we're deleting the first zone, change the start of the second zone 
  380. 		cinema_clip_editor_zone_set_times(Zones[2], Zones[1].time_start, Zones[2].time_end) 
  381. 	else 
  382. 		-- Otherwise change the end time of the previous zone 
  383. 		Zones[cur_zone - 1].time_end = Zones[cur_zone].time_end 
  384. 	end 
  385. 	 
  386. 	-- Copy zone data to the previous index 
  387. 	for i = cur_zone, Num_zones do 
  388. 		cinema_clip_editor_zone_copy(Zones[i], Zones[i + 1]) 
  389. 	end 
  390. 	 
  391. 	-- Copy temp zone data to an invalid one (and hide that zone) 
  392. 	cinema_clip_editor_zone_copy(Zones[Num_zones + 1], temp_zone) 
  393. 	cinema_clip_editor_zone_set_visibility(Zones[Num_zones + 1], false) 
  394. 	 
  395. 	-- Update everything 
  396. 	cinema_clip_editor_zone_update_all() 
  397. 	cinema_clip_editor_zone_update_highlight() 
  398. 	cinema_clip_editor_zone_update_inactive() 
  399. end 
  400.  
  401. -- Copies editor data from the src to the dest 
  402. function cinema_clip_editor_zone_copy(zone_dest, zone_src) 
  403. 	zone_dest.solid = zone_src.solid 
  404. 	zone_dest.lock = zone_src.lock 
  405. 	zone_dest.splitter = zone_src.splitter 
  406. 	zone_dest.text = zone_src.text 
  407. 	zone_dest.inactive = zone_src.inactive 
  408. 	zone_dest.highlight = zone_src.highlight 
  409. 	zone_dest.cut = zone_src.cut 
  410. 	zone_dest.blend_next = zone_src.blend_next 
  411. 	zone_dest.x = zone_src.x 
  412. 	zone_dest.y = zone_src.y 
  413. 	zone_dest.w = zone_src.w 
  414. 	zone_dest.h = zone_src.h 
  415. 	zone_dest.right = zone_src.right 
  416. 	zone_dest.time_start = zone_src.time_start 
  417. 	zone_dest.time_end = zone_src.time_end 
  418. 	 
  419. 	zone_dest.UID = zone_src.UID 
  420. 	zone_dest.zone_type = zone_src.zone_type 
  421. 	zone_dest.camera_mode = zone_src.camera_mode 
  422. 	zone_dest.dof_mode = zone_src.dof_mode 
  423. 	zone_dest.export_lock = zone_src.export_lock 
  424. 	zone_dest.slow_mo = zone_src.slow_mo 
  425. 	zone_dest.fov = zone_src.fov 
  426. 	zone_dest.fov_blend = zone_src.fov_blend 
  427. 	zone_dest.tilt = zone_src.tilt 
  428. 	zone_dest.tilt_blend = zone_src.tilt_blend 
  429. 	zone_dest.handycam = zone_src.handycam 
  430. 	zone_dest.handycam_blend = zone_src.handycam_blend 
  431. 	zone_dest.dof_dist = zone_src.dof_dist 
  432. 	zone_dest.dof_dist_blend = zone_src.dof_dist_blend 
  433. 	zone_dest.dof_focal = zone_src.dof_focal 
  434. 	zone_dest.dof_focal_blend = zone_src.dof_focal_blend 
  435. 	zone_dest.camera_blend = zone_src.camera_blend 
  436. end 
  437.  
  438. -- Set the start and end times of a zone (and update the display text) 
  439. function cinema_clip_editor_zone_set_times(zone, t1, t2) 
  440. 	zone.time_start = t1 
  441. 	zone.time_end = t2 
  442. 	zone.text:set_text(cinema_clip_editor_num_to_string_2_decimal(t1)) 
  443. end 
  444.  
  445. -- Set the colors of a zone (based on its flags) 
  446. function cinema_clip_editor_zone_set_colors(zone) 
  447. 	if zone.inactive and zone.highlight then 
  448. 		zone.solid:set_color(COLOR_SOLID_HIGHLIGHT) 
  449. 		zone.text:set_color(COLOR_TEXT_INACTIVE_HIGHLIGHT) 
  450. 		zone.lock:set_color(COLOR_LOCK_HIGHLIGHT) 
  451. 	elseif zone.inactive and zone.highlight == false then 
  452. 		zone.solid:set_color(COLOR_SOLID_NORMAL) 
  453. 		zone.text:set_color(COLOR_TEXT_INACTIVE_NORMAL) 
  454. 		zone.lock:set_color(COLOR_LOCK_NORMAL) 
  455. 	elseif zone.inactive == false and zone.highlight == false then 
  456. 		zone.solid:set_color(COLOR_SOLID_NORMAL) 
  457. 		zone.text:set_color(COLOR_TEXT_NORMAL) 
  458. 		zone.lock:set_color(COLOR_LOCK_NORMAL) 
  459. 	elseif zone.inactive == false and zone.highlight then 
  460. 		zone.solid:set_color(COLOR_SOLID_HIGHLIGHT) 
  461. 		zone.text:set_color(COLOR_TEXT_HIGHLIGHT) 
  462. 		zone.lock:set_color(COLOR_LOCK_HIGHLIGHT) 
  463. 	end 
  464. end 
  465.  
  466. -- Update the visuals of a zone in the timeline, speficially the images for blending and export lock 
  467. function cinema_clip_editor_zone_update_visuals(zone) 
  468. 	if zone.export_lock == 1 then 
  469. 		zone.lock:set_image("ui_pc_icon_locked") 
  470. 	else 
  471. 		zone.lock:set_image("ui_pc_icon_unlocked") 
  472. 	end 
  473. 	local w,h = zone.solid:get_actual_size() 
  474. 	if zone.blend_next then 
  475. 		zone.solid:set_image("ui_pc_gradient_256") 
  476. 	else 
  477. 		zone.solid:set_image("ui_blank") 
  478. 	end 
  479. 	zone.solid:set_actual_size(w, h) 
  480. end 
  481.  
  482. -- Update the blend_next flag for all zones 
  483. function cinema_clip_editor_zone_update_blend_next() 
  484. 	for i = 1, Num_zones - 1 do 
  485. 		if Zones[i + 1].zone_type == 0 then 
  486. 			Zones[i].blend_next = false 
  487. 		else 
  488. 			Zones[i].blend_next = true 
  489. 		end 
  490. 	end 
  491. end 
  492.  
  493. -- Initialize a zone's elements and relevant flags 
  494. function cinema_clip_editor_zone_init(zone, idx) 
  495. 	zone.UID = -1 
  496. 	zone.index = idx 
  497. 	zone.solid = Vdo_base_object:clone(Base_zone_solid.handle) 
  498. 	zone.lock = Vdo_base_object:clone(Base_zone_lock.handle) 
  499. 	zone.splitter = Vdo_base_object:clone(Base_zone_splitter.handle) 
  500. 	zone.text = Vdo_base_object:clone(Base_zone_text.handle) 
  501. 	zone.inactive = false 
  502. 	zone.highlight = false 
  503. 	zone.cut = true 
  504. 	zone.blend_next = false 
  505. 	zone.right = TIMELINE_RIGHT 
  506. 	 
  507. 	zone.zone_type = 0 
  508. 	zone.camera_mode = 0 
  509. 	zone.dof_mode = 0 
  510. 	zone.export_lock = 1 
  511. 	zone.slow_mo = 0 
  512. 	zone.slow_mo_blend = 0 
  513. 	zone.fov = 50 
  514. 	zone.fov_blend = 0 
  515. 	zone.tilt = 0 
  516. 	zone.tilt_blend = 0 
  517. 	zone.handycam = 0 
  518. 	zone.handycam_blend = 0 
  519. 	zone.dof_dist = 50 
  520. 	zone.dof_dist_blend = 0 
  521. 	zone.dof_focal = 50 
  522. 	zone.dof_focal_blend = 0 
  523. 	zone.camera_blend = 0 
  524. 	 
  525. 	cinema_clip_editor_zone_set_visibility(zone, false) 
  526. end 
  527.  
  528. -- Set the visibility of a zone 
  529. function cinema_clip_editor_zone_set_visibility(zone, visible) 
  530. 	zone.solid:set_visible(visible) 
  531. 	zone.text:set_visible(visible) 
  532. 	zone.lock:set_visible(visible) 
  533. 	zone.splitter:set_visible(visible) 
  534. end 
  535.  
  536. -- Resize the zone using its time_start and time_end 
  537. function cinema_clip_editor_zone_update_size(zone, last, prev_zone_right) 
  538. 	-- Calculate my coordinates and size 
  539. 	local frac_start = zone.time_start / Timeline_time_end 
  540. 	local frac_end = (zone.time_end - zone.time_start) / Timeline_time_end 
  541. 	local min_x = prev_zone_right or 0 
  542. 	 
  543. 	zone.x = TIMELINE_LEFT + frac_start * (TIMELINE_WIDTH - TIMELINE_BORDER) 
  544. 	 
  545. 	-- Make the zone start at the border of the previous zone (only a problem with really squished zones) 
  546. 	local prev_fix = 0 
  547. 	if zone.x < min_x then 
  548. 		prev_fix = min_x - zone.x 
  549. 		zone.x = min_x 
  550. 	end 
  551. 	 
  552. 	zone.w = frac_end * (TIMELINE_WIDTH - TIMELINE_BORDER) - prev_fix 
  553. 	zone.y = TIMELINE_Y 
  554. 	zone.h = TIMELINE_HEIGHT - TIMELINE_BORDER 
  555. 	 
  556. 	-- Reduce the width if this is not the last zone (to make room for the splitter) 
  557. 	if last == false then 
  558. 		zone.w = zone.w - SPLITTER_WIDTH 
  559. 		if zone.w < ZONE_MIN_WIDTH then 
  560. 			zone.w = ZONE_MIN_WIDTH 
  561. 		end 
  562. 	end 
  563. 	 
  564. 	-- Arrange the elements 
  565. 	zone.solid:set_anchor(zone.x, zone.y) 
  566. 	zone.text:set_anchor(zone.x, zone.y) 
  567. 	zone.lock:set_anchor(zone.x + zone.w, zone.y) 
  568. 	zone.splitter:set_anchor(zone.x + zone.w, zone.y) 
  569. 	 
  570. 	-- Resize the elements (scale them up, measure, and cap) 
  571. 	zone.solid:set_actual_size(zone.w, zone.h) 
  572. 	zone.text:set_scale(0.8, 0.8) 
  573. 	local temp_w, temp_h = zone.text:get_actual_size() 
  574. 	if temp_w > zone.w then 
  575. 		zone.text:set_actual_size(zone.w, temp_h) 
  576. 	end 
  577. 	zone.lock:set_scale(1.0, 1.0) 
  578. 	temp_w, temp_h = zone.lock:get_actual_size() 
  579. 	if temp_w > zone.w then 
  580. 		zone.lock:set_actual_size(zone.w, temp_h) 
  581. 	end 
  582. 	 
  583. 	-- Save the right side coordinates (including splitter, even if it's turned off) 
  584. 	zone.right = zone.x + zone.w + SPLITTER_WIDTH 
  585. 	 
  586. 	-- Show the splitter (as long as it's not the last zone) 
  587. 	if last then 
  588. 		zone.splitter:set_actual_size(0, 0) 
  589. 	else 
  590. 		zone.splitter:set_actual_size(SPLITTER_WIDTH, zone.h) 
  591. 	end 
  592. end 
  593.  
  594. -- Move the current splitter and update the zones 
  595. function cinema_clip_editor_zone_splitter_move(zone_id, mouse_x) 
  596. 	-- Constrain the time to the current zone's start and next zone's end 
  597. 	local t = cinema_clip_editor_mouse_to_time(mouse_x) 
  598. 	if t < Zones[zone_id].time_start + ZONE_MIN_TIME then 
  599. 		t = Zones[zone_id].time_start + ZONE_MIN_TIME 
  600. 	elseif t > Zones[zone_id + 1].time_end - ZONE_MIN_TIME then 
  601. 		t = Zones[zone_id + 1].time_end - ZONE_MIN_TIME 
  602. 	end 
  603. 	t = cinema_clip_editor_num_round_2_decimal(t) 
  604. 	 
  605. 	-- Set the start/end times for the zones 
  606. 	cinema_clip_editor_zone_set_times(Zones[zone_id], Zones[zone_id].time_start, t ) 
  607. 	cinema_clip_editor_zone_set_times(Zones[zone_id + 1], t, Zones[zone_id + 1].time_end) 
  608. 	 
  609. 	-- Let the code know about the new time 
  610. 	vint_dataresponder_post("camera_zone_dr", "set_time", Zones[zone_id + 1].UID, t) 
  611. 	 
  612. 	cinema_clip_editor_zone_update_all() 
  613. 	cinema_clip_editor_zone_update_highlight() 
  614. 	cinema_clip_editor_zone_update_inactive() 
  615. end 
  616.  
  617. -- Update all the zone times 
  618. function cinema_clip_editor_zone_update_times() 
  619. 	for i = 1, Num_zones - 1 do 
  620. 		cinema_clip_editor_zone_set_times(Zones[i], Zones[i].time_start, Zones[i + 1].time_start) 
  621. 	end 
  622. end 
  623.  
  624. -- Resize all the zones (after calculating some required elements) 
  625. function cinema_clip_editor_zone_update_all() 
  626. 	local right = 0 
  627. 	local last = false 
  628. 	 
  629. 	for i = 1, Num_zones do 
  630. 		if i > 1 then 
  631. 			right = Zones[i - 1].right 
  632. 		end 
  633. 		if i == Num_zones then 
  634. 			last = true 
  635. 		end 
  636. 		cinema_clip_editor_zone_update_size(Zones[i], last, right) 
  637. 		cinema_clip_editor_zone_set_visibility(Zones[i], true) 
  638. 		 
  639. 		-- Data fixup/restrictions 
  640. 		-- First zone: can't be blend 
  641. 		if i == 1 then 
  642. 			Zones[i].zone_type = 0 
  643. 		end 
  644. 		 
  645. 		-- Last zone: can't have blend_next 
  646. 		if i == Num_zones then 
  647. 			Zones[i].blend_next = false 
  648. 		end 
  649. 		 
  650. 		-- Not last zone: update blend_next flag and other data if applicable 
  651. 		if Num_zones > i then 
  652. 			if Zones[i + 1].zone_type == 0 then 
  653. 				Zones[i].blend_next = false 
  654. 			else 
  655. 				Zones[i].blend_next = true 
  656. 				-- Copy some data from the current zone 
  657. 				Zones[i + 1].camera_mode = Zones[i].camera_mode 
  658. 				Zones[i + 1].export_lock = Zones[i].export_lock 
  659. 				Zones[i + 1].slow_mo = Zones[i].slow_mo 
  660. 				Zones[i + 1].dof_mode = Zones[i].dof_mode 
  661. 			end 
  662. 		end 
  663. 		 
  664. 		cinema_clip_editor_zone_update_visuals(Zones[i]) 
  665. 	end 
  666. end 
  667.  
  668. -- Convert an X coordinate to a time 
  669. function cinema_clip_editor_mouse_to_time(mouse_x) 
  670. 	local frac = (mouse_x - TIMELINE_LEFT) / TIMELINE_WIDTH 
  671. 	local t = frac * Timeline_time_end 
  672. 	return t 
  673. end 
  674.  
  675. -- Find the zone that should be highlighted and do it 
  676. function cinema_clip_editor_zone_update_highlight() 
  677. 	local used = false 
  678. 	-- Loop through all zones, find the one that has timeline marker, highlight it (and update the colors) 
  679. 	for i = 1, Num_zones do 
  680. 		if Zones[i].time_end > Marker_time_timeline and used == false then 
  681. 			Zones[i].highlight = true 
  682. 			used = true 
  683. 		else 
  684. 			Zones[i].highlight = false 
  685. 		end 
  686. 		cinema_clip_editor_zone_set_colors(Zones[i]) 
  687. 	end 
  688. 	 
  689. 	-- Make sure something is highlighted 
  690. 	if Num_zones > 0 then 
  691. 		if used == false then 
  692. 			Zones[Num_zones].highlight = true 
  693. 			cinema_clip_editor_zone_set_colors(Zones[Num_zones]) 
  694. 		end 
  695. 		 
  696. 		-- Update the properties dialog 
  697. 		local cur_zone = cinema_clip_editor_zone_get_current() 
  698. 		cinema_clip_editor_prop_dialog_fill_data(cur_zone) 
  699. 	end 
  700. end 
  701.  
  702. -- Update the inactive flag for all zones (one will always be active) 
  703. function cinema_clip_editor_zone_update_inactive() 
  704. 	local used = false 
  705. 	-- Loop through all zones, find the one that has timeline marker, highlight it (and update the colors) 
  706. 	for i = 1, Num_zones do 
  707. 		if Zones[i].time_end > Marker_time_playback and used == false then 
  708. 			Zones[i].inactive = false 
  709. 			used = true 
  710. 		else 
  711. 			Zones[i].inactive = true 
  712. 		end 
  713. 		cinema_clip_editor_zone_set_colors(Zones[i]) 
  714. 	end 
  715.  
  716. 	-- Make sure something is active 
  717. 	if Num_zones > 0 then 
  718. 		if used == false then 
  719. 			Zones[Num_zones].inactive = false 
  720. 			cinema_clip_editor_zone_set_colors(Zones[Num_zones]) 
  721. 		end 
  722. 	end 
  723. 	 
  724. 	-- Adjust the play_to elements 
  725. 	-- Find the anchor and other measurements 
  726. 	local x, y = Marker_playback:get_anchor() 
  727. 	local w, h = Mpb_text_bg:get_actual_size() 
  728. 	 
  729. 	-- Right side of the text bg 
  730. 	local min_x = w * 0.5 
  731.  
  732. 	-- Get the x coordinate (Marker_playback-relative) of the zone border 
  733. 	local active_zone = cinema_clip_editor_zone_active() 
  734. 	local border_x = Zones[active_zone].right - x 
  735.  
  736. 	-- Get the anchor of the arrow (Y value will be used below) 
  737. 	x, y = Mpb_play_to_arrow:get_anchor() 
  738. 	 
  739. 	-- Find the actual location of the right side play_to elements 
  740. 	x = max(border_x, min_x + 12) 
  741. 	 
  742. 	-- Move/resize the elements 
  743. 	Mpb_play_to_line:set_anchor(x, y) 
  744. 	Mpb_play_to_end:set_anchor(x, y) 
  745. 	Mpb_play_to_end:set_actual_size(x - min_x - 2, h) 
  746. end 
  747.  
  748. -- Get the currently active zone id 
  749. function cinema_clip_editor_zone_active() 
  750. 	for i = 1, Num_zones do 
  751. 		if Zones[i].inactive == false then 
  752. 			return i 
  753. 		end 
  754. 	end 
  755. 	return 1 
  756. end 
  757.  
  758. -- Get the currently highlighted zone id 
  759. function cinema_clip_editor_zone_highlight() 
  760. 	for i = 1, Num_zones do 
  761. 		if Zones[i].highlight == true then 
  762. 			return i 
  763. 		end 
  764. 	end 
  765. 	return 1 
  766. end 
  767.  
  768. function cinema_clip_editor_zone_get_current() 
  769. 	local highlight = cinema_clip_editor_zone_highlight() 
  770. 	if highlight > 0 then 
  771. 		return Zones[highlight] 
  772. 	else 
  773. 		return nil 
  774. 	end 
  775. end 
  776.  
  777. function cinema_clip_editor_zone_get_previous() 
  778. 	local highlight = cinema_clip_editor_zone_highlight() 
  779. 	if highlight - 1 > 0 then 
  780. 		return Zones[highlight - 1] 
  781. 	else 
  782. 		return nil 
  783. 	end 
  784. end 
  785.  
  786.  
  787. -------------------------------------------------------------------------- 
  788. -- Mouse input functions 
  789. -------------------------------------------------------------------------- 
  790.  
  791. -- MOUSE OVERVIEW 
  792. -- Mouse_move_always: Highlighted the appropriate item (splitter), move the select marker 
  793. -- Mouse_drag: If highlighting splitter: Move the splitter (do not update highlight, set drag flag) 
  794. -- 	If highlighting zone: Update highlight, set timeline marker 
  795. -- Mouse_click: Set timeline marker 
  796. -- Mouse_drag_release: If dragging splitter, unset drag flag (else nothing) 
  797.  
  798. -- Add mouse inputs 
  799. function cinema_clip_editor_timeline_add_mouse_inputs(input_tracker) 
  800. 	-- Timeline background (primary input) 
  801. 	input_tracker:add_mouse_input("mouse_down", "cinema_clip_editor_mouse_down_timeline", 0, Timeline_bg.handle) 
  802. 	input_tracker:add_mouse_input("mouse_click", "cinema_clip_editor_mouse_click_timeline", 0, Timeline_bg.handle) 
  803. 	input_tracker:add_mouse_input("mouse_drag", "cinema_clip_editor_mouse_drag_timeline", 0, Timeline_bg.handle) 
  804. 	input_tracker:add_mouse_input("mouse_drag_release", "cinema_clip_editor_mouse_drag_release_timeline", 0, Timeline_bg.handle) 
  805. 	input_tracker:add_mouse_input("mouse_move_always", "cinema_clip_editor_mouse_move_always_timeline", 0, Timeline_bg.handle) 
  806. 	 
  807. 	-- Marker buttons 
  808. 	input_tracker:add_mouse_input("mouse_click", "cinema_clip_editor_mouse_click_playback_marker", 0, Mpb_play_to_arrow.handle) 
  809. 	input_tracker:add_mouse_input("mouse_move", "cinema_clip_editor_mouse_move_playback_marker", 0, Mpb_play_to_arrow.handle) 
  810. 	input_tracker:add_mouse_input("mouse_click", "cinema_clip_editor_mouse_click_timeline_marker_next", 0, Mtl_next.handle) 
  811. 	input_tracker:add_mouse_input("mouse_move", "cinema_clip_editor_mouse_move_timeline_marker_next", 0, Mtl_next.handle) 
  812. 	input_tracker:add_mouse_input("mouse_click", "cinema_clip_editor_mouse_click_timeline_marker_prev", 0, Mtl_prev.handle) 
  813. 	input_tracker:add_mouse_input("mouse_move", "cinema_clip_editor_mouse_move_timeline_marker_prev", 0, Mtl_prev.handle) 
  814. 	input_tracker:add_mouse_input("mouse_click", "cinema_clip_editor_mouse_click_timeline_marker", 0, Mtl_text_bg.handle) 
  815. 	input_tracker:add_mouse_input("mouse_move", "cinema_clip_editor_mouse_move_timeline_marker", 0, Mtl_text_bg.handle) 
  816. end 
  817.  
  818. function cinema_clip_editor_convert_mouse_screen_coordinates(mouse_x, mouse_y) 
  819. 	local screen_w, screen_h = vint_get_screen_size() 
  820. 	if vint_is_std_res() then 
  821. 		if (screen_w / screen_h) < 1.333 then 
  822. 			local offset_x = (screen_h * 1.333 - screen_w) * 0.5 
  823. 			mouse_x = offset_x + mouse_x * ((screen_w / screen_h) / 1.333) 
  824. 		end 
  825. 		mouse_x = (mouse_x * 640 / screen_w) * 1.5 
  826. 		mouse_y = ((mouse_y - (screen_h - 480 * screen_w / 640) / 2) * 640 / screen_w) * 1.5 
  827. 	else  
  828. 		if (screen_w / screen_h) < 1.777 then 
  829. 			local offset_x = (screen_h * 1.777 - screen_w) * 0.5 
  830. 			mouse_x = offset_x + mouse_x * ((screen_w / screen_h) / 1.777) 
  831. 		end 
  832. 		mouse_x = (mouse_x * 1280 / screen_w) 
  833. 		mouse_y = ((mouse_y - (screen_h - 720 * screen_w / 1280) / 2) * 1280 / screen_w) 
  834. 	end 
  835. 	 
  836. 	return mouse_x, mouse_y 
  837. end 
  838.  
  839. -- Dummy event to make mouse_drag work 
  840. function cinema_clip_editor_mouse_click_timeline(event, target_handle, mouse_x, mouse_y) 
  841. end 
  842.  
  843. -- When first pressing the mouse: Start dragging a splitter or update the timeline marker 
  844. function cinema_clip_editor_mouse_down_timeline(event, target_handle, mouse_x, mouse_y) 
  845. 	mouse_x, mouse_y = cinema_clip_editor_convert_mouse_screen_coordinates(mouse_x, mouse_y) 
  846. 	 
  847. 	local splitter = cinema_clip_editor_mouse_select_splitter(mouse_x) 
  848. 	if splitter > 0 then 
  849. 		Drag_splitter_id = splitter 
  850. 		Dragging_splitter = true 
  851. 	else 
  852. 		cinema_clip_editor_timeline_marker_set(mouse_x) 
  853. 		cinema_clip_editor_zone_update_highlight() 
  854. 		Marker_select:set_visible(false) 
  855. 	end 
  856. end 
  857.  
  858. -- When dragging the mouse: Move the current splitter or update the timeline marker 
  859. function cinema_clip_editor_mouse_drag_timeline(event, target_handle, mouse_x, mouse_y) 
  860. 	mouse_x, mouse_y = cinema_clip_editor_convert_mouse_screen_coordinates(mouse_x, mouse_y) 
  861. 	 
  862. 	if Dragging_splitter == true then 
  863. 		cinema_clip_editor_zone_splitter_move(Drag_splitter_id, mouse_x) 
  864. 	else 
  865. 		cinema_clip_editor_timeline_marker_set(mouse_x) 
  866. 		cinema_clip_editor_zone_update_highlight() 
  867. 		Marker_select:set_visible(false) 
  868. 	end 
  869. end 
  870.  
  871. function cinema_clip_editor_mouse_drag_release_timeline(event, target_handle, mouse_x, mouse_y) 
  872. 	mouse_x, mouse_y = cinema_clip_editor_convert_mouse_screen_coordinates(mouse_x, mouse_y) 
  873. 	 
  874. 	if Dragging_splitter == true then 
  875. 		Dragging_splitter = false 
  876. 	end 
  877. end 
  878.  
  879. -- When moving the mouse: Highlight a splitter or move the selection marker 
  880. function cinema_clip_editor_mouse_move_always_timeline(event, target_handle, mouse_x, mouse_y) 
  881. 	mouse_x, mouse_y = cinema_clip_editor_convert_mouse_screen_coordinates(mouse_x, mouse_y) 
  882. 	 
  883. 	-- Is the mouse over a splitter 
  884. 	local splitter = cinema_clip_editor_mouse_select_splitter(mouse_x) 
  885. 	if splitter > 0 then 
  886. 		-- Highlight the splitter (and hide the selection marker) 
  887. 		cinema_clip_editor_splitter_highlight(splitter, true) 
  888. 		 
  889. 		Marker_select:set_visible(false) 
  890. 	else 
  891. 		cinema_clip_editor_splitter_unhighlight_all() 
  892. 		 
  893. 		-- Update the selection markers position (and make it visible) 
  894. 		Marker_select:set_anchor(mouse_x, TIMELINE_Y) 
  895. 		Marker_select:set_visible(true) 
  896. 	end 
  897. 	 
  898. 	cinema_clip_editor_timeline_unhighlight_mini_buttons() 
  899. end 
  900.  
  901. -- Returns the zone id of the splitter under the mouse (or 0 if none) 
  902. function cinema_clip_editor_mouse_select_splitter(mouse_x) 
  903. 	-- Don't scale mouse for resolution because it's scaled prior to this 
  904. 	 
  905. 	-- Go thru zones, find which one we're in 
  906. 	local cur_zone = 0 
  907. 	for i = 1, Num_zones do 
  908. 		if mouse_x > Zones[i].x and mouse_x <= Zones[i].right then 
  909. 			cur_zone = i 
  910. 		end 
  911. 	end 
  912. 	 
  913. 	-- Make sure we're in a zone (but not the last one, which has no splitter) 
  914. 	if cur_zone > 0 and cur_zone < Num_zones then 
  915. 		-- Check if the mouse is over the splitter 
  916. 		if mouse_x >= (Zones[cur_zone].right - SPLITTER_WIDTH) then 
  917. 			return cur_zone 
  918. 		end 
  919. 	end 
  920. 	 
  921. 	return 0 
  922. end 
  923.  
  924. -- Unhighlight all splitters 
  925. function cinema_clip_editor_splitter_unhighlight_all() 
  926. 	for i = 1, Num_zones do 
  927. 		cinema_clip_editor_splitter_highlight(i, false) 
  928. 	end 
  929. end 
  930.  
  931. -- Highlight the given splitter (referenced by zone id) 
  932. function cinema_clip_editor_splitter_highlight(s_zone, highlight) 
  933. 	if highlight == true then 
  934. 		Zones[s_zone].splitter:set_color(COLOR_SPLITTER_HIGHLIGHT) 
  935. 	else 
  936. 		Zones[s_zone].splitter:set_color(COLOR_SPLITTER_NORMAL) 
  937. 	end 
  938. end 
  939.  
  940. -- Called from other mouse_move events (in main cinema_clip_editor file) 
  941. function cinema_clip_editor_timeline_mouse_off() 
  942. 	Marker_select:set_visible(false) 
  943. 	cinema_clip_editor_timeline_unhighlight_mini_buttons() 
  944. end 
  945.  
  946. -- Marker mini-button mouse functions 
  947.  
  948. -- When clicking the marker's arrow button: Move the playback marker forward (sort of) 
  949. function cinema_clip_editor_mouse_click_playback_marker(event, target_handle) 
  950. 	if Playback_disabled == false then 
  951. 		Rewinding = false 
  952. 		cinema_clip_editor_playback_marker_jump() 
  953. 	end 
  954. end 
  955.  
  956. -- When moving the mouse over the button: Highlight its elements 
  957. function cinema_clip_editor_mouse_move_playback_marker(event, target_handle) 
  958. 	if Playback_disabled == false then 
  959. 		cinema_clip_editor_timeline_unhighlight_mini_buttons() 
  960. 		cinema_clip_editor_double_highlight(true, Mpb_play_to_arrow, Mpb_play_to_end) 
  961. 	end 
  962. end 
  963.  
  964. -- When clicking the marker's right arrow button: Move the timeline marker forward 
  965. function cinema_clip_editor_mouse_click_timeline_marker_next(event, target_handle) 
  966. 	cinema_clip_editor_timeline_marker_next() 
  967. end 
  968.  
  969. -- When moving the mouse over the button: Highlight its elements 
  970. function cinema_clip_editor_mouse_move_timeline_marker_next(event, target_handle) 
  971. 	cinema_clip_editor_timeline_unhighlight_mini_buttons() 
  972. 	cinema_clip_editor_double_highlight(true, Mtl_next, Mtl_bg_next) 
  973. end 
  974.  
  975. -- When clicking the marker's left arrow button: Move the timeline marker backward 
  976. function cinema_clip_editor_mouse_click_timeline_marker_prev(event, target_handle) 
  977. 	cinema_clip_editor_timeline_marker_prev() 
  978. end 
  979.  
  980. -- When moving the mouse over the button: Highlight its elements 
  981. function cinema_clip_editor_mouse_move_timeline_marker_prev(event, target_handle) 
  982. 	cinema_clip_editor_timeline_unhighlight_mini_buttons() 
  983. 	cinema_clip_editor_double_highlight(true, Mtl_prev, Mtl_bg_prev) 
  984. end 
  985.  
  986. -- When clicking the marker's time, open the basic dialog 
  987. function cinema_clip_editor_mouse_click_timeline_marker(event, target_handle) 
  988. 	local x, y = Marker_timeline:get_anchor() 
  989. 	cinema_clip_editor_dialog_camera_zone_slide(x) 
  990. end 
  991.  
  992. -- When moving the mouse over the button: Highlight its elements 
  993. function cinema_clip_editor_mouse_move_timeline_marker(event, target_handle) 
  994. 	cinema_clip_editor_timeline_unhighlight_mini_buttons() 
  995. 	cinema_clip_editor_double_highlight(true, Mtl_text, Mtl_text_bg) 
  996. end 
  997.  
  998. -- Remove highlighting from all the small marker buttons 
  999. function cinema_clip_editor_timeline_unhighlight_mini_buttons() 
  1000. 	cinema_clip_editor_double_highlight(false, Mpb_play_to_arrow, Mpb_play_to_end) 
  1001. 	cinema_clip_editor_double_highlight(false, Mtl_next, Mtl_bg_next) 
  1002. 	cinema_clip_editor_double_highlight(false, Mtl_prev, Mtl_bg_prev) 
  1003. 	cinema_clip_editor_double_highlight(false, Mtl_text, Mtl_text_bg) 
  1004. end 
  1005.  
  1006. -- Sets the img/bg colors based on the highlight (used for mini buttons) 
  1007. function cinema_clip_editor_double_highlight(highlight, img, bg) 
  1008. 	if highlight == true then 
  1009. 		img:set_color(COLOR_TEXT_HIGHLIGHT) 
  1010. 		bg:set_color(COLOR_SOLID_HIGHLIGHT) 
  1011. 	else 
  1012. 		img:set_color(COLOR_TEXT_NORMAL) 
  1013. 		bg:set_color(COLOR_SOLID_NORMAL) 
  1014. 	end 
  1015. end 
  1016.  
  1017. -------------------------------------------------------------------------- 
  1018. -- Marker functions 
  1019. -------------------------------------------------------------------------- 
  1020.  
  1021. -- Set the timeline marker based on a screen value (can also just send 0 to reset it) 
  1022. function cinema_clip_editor_timeline_marker_set(mouse_x) 
  1023. 	local x = mouse_x 
  1024. 	local min_x = TIMELINE_X - TIMELINE_WIDTH * 0.5 + TIMELINE_BORDER * 0.5 
  1025. 	local max_x = TIMELINE_X + TIMELINE_WIDTH * 0.5 - TIMELINE_BORDER * 0.5 
  1026. 	 
  1027. 	-- Limit x to the extents of the timeline 
  1028. 	x = min(x, max_x) 
  1029. 	x = max(x, min_x) 
  1030. 		 
  1031. 	Marker_timeline:set_anchor(x, TIMELINE_Y + TIMELINE_HEIGHT * 0.5) 
  1032. 	 
  1033. 	-- Translate the coordinates to a time, and set it 
  1034. 	local frac = (x - min_x) / (max_x - min_x) 
  1035. 	Marker_time_timeline = frac * Timeline_time_end 
  1036. 	Mtl_text:set_text(cinema_clip_editor_num_to_string_2_decimal(Marker_time_timeline)) 
  1037. 	 
  1038. 	cinema_clip_editor_zone_update_highlight() 
  1039. 	cinema_clip_editor_dialog_camera_zone_slide(x) 
  1040. end 
  1041.  
  1042. -- Sets the timeline marker using a time 
  1043. function cinema_clip_editor_timeline_marker_set_time(t) 
  1044. 	local frac = min(1, t / Timeline_time_end) 
  1045. 	local x1 = TIMELINE_LEFT 
  1046. 	local x2 = (TIMELINE_WIDTH - TIMELINE_BORDER) * frac 
  1047. 	local x = x1 + x2 
  1048. 	 
  1049. 	Marker_timeline:set_anchor(x, TIMELINE_Y + TIMELINE_HEIGHT * 0.5) 
  1050. 	 
  1051. 	-- Set the text 
  1052. 	Marker_time_timeline = min(t, Timeline_time_end) 
  1053. 	Mtl_text:set_text(cinema_clip_editor_num_to_string_2_decimal(Marker_time_timeline)) 
  1054. 	 
  1055. 	cinema_clip_editor_zone_update_highlight() 
  1056. 	cinema_clip_editor_dialog_camera_zone_slide(x) 
  1057. end 
  1058.  
  1059. -- Set the playback marker based on a time value 
  1060. function cinema_clip_editor_playback_marker_set(t) 
  1061. 	local frac = min(1, t / Timeline_time_end) 
  1062. 	local x1 = TIMELINE_LEFT 
  1063. 	local x2 = (TIMELINE_WIDTH - TIMELINE_BORDER) * frac 
  1064. 	local x = x1 + x2 
  1065. 	 
  1066. 	Marker_playback:set_anchor(x, TIMELINE_Y - TIMELINE_HEIGHT * 0.5) 
  1067. 	 
  1068. 	-- Set the text 
  1069. 	Marker_time_playback = min(t, Timeline_time_end) 
  1070. 	Mpb_text:set_text(cinema_clip_editor_num_to_string_2_decimal(Marker_time_playback)) 
  1071. 	 
  1072. 	cinema_clip_editor_zone_update_inactive() 
  1073. end 
  1074.  
  1075. -- Set the playback goal time to the current zone's end time 
  1076. function cinema_clip_editor_playback_marker_jump() 
  1077. 	local active_zone = cinema_clip_editor_zone_active() 
  1078. 	 
  1079. 	if active_zone == Num_zones then 
  1080. 		Marker_time_playback_goal = Timeline_time_end 
  1081. 	else 
  1082. 		Marker_time_playback_goal = Zones[active_zone].time_end 
  1083. 	end 
  1084. 	 
  1085. 	vint_dataresponder_post("cinema_editor_dr", "play_to_time", Marker_time_playback_goal) 
  1086. 	cinema_clip_editor_playback_buttons(true) 
  1087. 	CCE_free_buttons[BTN_FREE_PAUSE].button:set_active() 
  1088. end 
  1089.  
  1090. -- Set the timeline marker to the end of the current zone (aka the beginning of the next zone) 
  1091. function cinema_clip_editor_timeline_marker_next() 
  1092. 	local highlight_zone = cinema_clip_editor_zone_highlight() 
  1093. 	 
  1094. 	cinema_clip_editor_timeline_marker_set(Zones[highlight_zone].right + 0.1) 
  1095. 	cinema_clip_editor_zone_update_highlight() 
  1096. end 
  1097.  
  1098. -- Set the timeline marker to the beginning of the current zone (or previous zone if at the beginning) 
  1099. function cinema_clip_editor_timeline_marker_prev() 
  1100. 	local highlight_zone = cinema_clip_editor_zone_highlight() 
  1101. 	 
  1102. 	-- Check for being at the beginning of the current zone 
  1103. 	if abs(Marker_time_timeline - Zones[highlight_zone].time_start) < 0.01 then 
  1104. 		-- Go back a zone (if possible) 
  1105. 		if highlight_zone > 1 then 
  1106. 			highlight_zone = highlight_zone - 1 
  1107. 		end 
  1108. 	end 
  1109. 	 
  1110. 	cinema_clip_editor_timeline_marker_set(Zones[highlight_zone].x + 0.1) 
  1111. 	cinema_clip_editor_zone_update_highlight() 
  1112. end 
  1113.  
  1114.