./vdo_scrolling_text.lua

  1. function vdo_scrolling_text_init() 
  2. end 
  3.  
  4. function vdo_scrolling_text_cleanup() 
  5. end 
  6.  
  7. -- Inherited from Vdo_base_object 
  8. Vdo_scrolling_text = Vdo_base_object:new_base() 
  9.  
  10. function Vdo_scrolling_text:set_wrap_width(new_width) 
  11. 	local text_graphic = Vdo_base_object:new("text_graphic", self.handle) 
  12. 	text_graphic:set_property("wrap_width",new_width) 
  13. end 
  14.  
  15. function Vdo_scrolling_text:set_font(new_font, new_size_x, new_size_y) 
  16. 	--check if text scale x is valid 
  17. 	if new_size_x == nil then 
  18. 		new_size_x = 1.0 
  19. 	end 
  20. 	--check if text scale y is valid 
  21. 	if new_size_y == nil then 
  22. 		new_size_y = new_size_x 
  23. 	end 
  24. 	local text_graphic = Vdo_base_object:new("text_graphic", self.handle) 
  25. 	--set the font face and the text scale 
  26. 	text_graphic:set_property("font", new_font) 
  27. 	text_graphic:set_property("text_scale", new_size_x, new_size_y) 
  28. end 
  29.  
  30. function Vdo_scrolling_text:force_case(case) 
  31. 	--check if text scale x is valid 
  32.  
  33. 	local text_graphic = Vdo_base_object:new("text_graphic", self.handle) 
  34. 	--set the font face and the text scale 
  35. 	text_graphic:set_property("force_case", case) 
  36. end 
  37.  
  38. function Vdo_scrolling_text:set_auto_offset(compass) 
  39. 	--check if text scale x is valid 
  40.  
  41. 	local text_graphic = Vdo_base_object:new("text_graphic", self.handle) 
  42. 	--set the font face and the text scale 
  43. 	text_graphic:set_property("auto_offset", compass) 
  44. end 
  45.  
  46. function Vdo_scrolling_text:run_text(new_text, new_speed, is_loop, time_delay, start_delay) 
  47. 	--are we already running a thread? 
  48. 	if self.thread ~= nil then 
  49. 		thread_kill(self.thread) 
  50. 	end 
  51. 	 
  52. 	if start_delay == nil then 
  53. 		start_delay = 0 
  54. 	end 
  55. 	 
  56. 	-- If we fed a table into this thing, then split it into lines and make a huge string out of it	 
  57. 	if type(new_text) == "table" then 
  58. 		local holder_string = "" 
  59. 		for idx, val in pairs(new_text) do 
  60. 			holder_string = holder_string .. new_text[idx] .. "\n" 
  61. 		end 
  62. 		 
  63. 		new_text = holder_string 
  64. 	else 
  65. 		local temp_text = get_localized_string_for_tag(new_text) 
  66. 		--this has a localized tag 
  67. 		if temp_text ~= "" then  
  68. 			self.thread = thread_new("vdo_scrolling_text_localized_tag_thread", new_text, new_speed, is_loop, time_delay, start_delay, self.handle) 
  69. 			return 
  70. 		end 
  71. 	end 
  72. 	 
  73. 	-- Run the thread 
  74. 	self.thread = thread_new("vdo_scrolling_text_number_thread", new_text, new_speed, is_loop, time_delay, start_delay, self.handle) 
  75. end 
  76.  
  77. function vdo_scrolling_text_number_thread(new_text, new_speed, is_loop, time_delay, start_delay, handle) 
  78. 	local count = 0 
  79. 	local new_string = "" 
  80. 	local char = "" 
  81. 	local text_graphic = Vdo_base_object:new("text_graphic", handle) 
  82. 	 
  83. 	-- use a start_delay if one exists 
  84. 	delay(start_delay) 
  85. 	 
  86. 	repeat 
  87. 		-- Run through the text 
  88. 		while true do  
  89. 			char = get_char_in_string(new_text, count) 
  90. 			if char == nil then 
  91. 				break 
  92. 			end 
  93. 			new_string = set_char_in_string(new_string, count, char) 
  94. 			text_graphic:set_text(new_string) 
  95. 			count = count + 1 
  96. 			delay(new_speed) 
  97. 		end 
  98. 		text_graphic:set_text(new_string) 
  99. 		-- Reset and ready to loop through again 
  100. 		count = 0 
  101. 		new_string = "" 
  102. 		char = "" 
  103. 		 
  104. 		if is_loop then 
  105. 			-- Default delay to 1 
  106. 			time_delay = time_delay or 1 
  107. 			delay(time_delay) 
  108. 		end 
  109. 	until not is_loop 
  110. end 
  111.  
  112. function vdo_scrolling_text_localized_tag_thread(tag, speed, is_loop, time_delay, start_delay, handle) 
  113.  
  114. 	local current_end = 0 
  115. 	local current_string = "" 
  116.  
  117. 	local text_graphic = Vdo_base_object:new("text_graphic", handle) 
  118. 	 
  119. 	-- use a start_delay if one exists 
  120. 	delay(start_delay) 
  121. 	 
  122. 	repeat 
  123. 		-- Run through the text 
  124. 		-- while true do	 
  125. 			-- delay(speed) 
  126. 			-- local new_string = get_localized_substring_for_tag(tag, 0, current_end) 
  127. 				-- if new_string == current_string then 
  128. 				-- break 
  129. 			-- end 
  130. 			-- text_graphic:set_text(new_string) 
  131. 			-- current_end = current_end + 1 
  132. 			-- current_string = new_string 
  133. 			-- delay(speed) 
  134. 		-- end 
  135. 		 
  136. 		-- Reset and ready to loop through again 
  137. 		current_end = 0 
  138. 		current_string = "" 
  139. 		 
  140. 		if is_loop then 
  141. 			-- Default delay to 1 
  142. 			time_delay = time_delay or 1 
  143. 			delay(time_delay) 
  144. 		end 
  145. 	until not is_loop 
  146. end 
  147.  
  148. function Vdo_scrolling_text:object_destroy() 
  149. 	thread_kill(self.thread) 
  150. 	return vint_object_destroy(self.handle) 
  151. end 
  152.