./vdo_shadow.lua

  1. ---------------------------------------------------------------------------  
  2. -- Vdo_shadow 
  3. -- 
  4. -- Drop shadow designed to drop behind a rectangluar image. 
  5. -- Used to draw a rectangular shadow behind any object 
  6. -- Requires the use of 3 types of bitmaps: 
  7. -- Center 	: "ui_blank" 
  8. -- Side 		: "ui_dialog_shadow_side" 
  9. -- Corner 	: "ui_dialog_shadow_corner" 
  10. --------------------------------------------------------------------------- 
  11.  
  12. -- Inherited from Vdo_base_object 
  13. Vdo_shadow = Vdo_base_object:new_base() 
  14.  
  15. function vdo_button_pc_init() 
  16. end 
  17.  
  18. function vdo_button_pc_cleanup() 
  19. end 
  20.  
  21. function Vdo_shadow:init() 
  22. 	--Store references to shadow... 
  23. 	self.c_h		= vint_object_find("shadow_c", self.handle) 
  24. 	self.nw_h	= vint_object_find("shadow_nw", self.handle) 
  25. 	self.n_h		= vint_object_find("shadow_n", self.handle) 
  26. 	self.ne_h	= vint_object_find("shadow_ne", self.handle) 
  27. 	self.e_h 	= vint_object_find("shadow_e", self.handle) 
  28. 	self.se_h 	= vint_object_find("shadow_se", self.handle) 
  29. 	self.s_h 	= vint_object_find("shadow_s", self.handle) 
  30. 	self.sw_h 	= vint_object_find("shadow_sw", self.handle) 
  31. 	self.w_h 	= vint_object_find("shadow_w", self.handle) 
  32. end 
  33.  
  34. function Vdo_shadow:set_props(x, y, show_center, shadow_size) 
  35. 	x = x or 100 
  36. 	y = y or 100 
  37. 	show_center = show_center or false 
  38. 	shadow_size = shadow_size or 19	--default... 
  39. 	 
  40. 	self:set_size(x,y) 
  41. 	self:show_center(show_center) 
  42. 	self:set_spread(shadow_size) 
  43. end 
  44.  
  45. -- Set size of the triangle. 
  46. function Vdo_shadow:set_size(x, y) 
  47. 	-- Find shadow objects 
  48. 	 
  49. 	--Top left Corner 
  50. 	local start_x = 0 
  51. 	local start_y = 0 
  52.  
  53. 	local width 	= x 
  54. 	local height 	= y 
  55. 	 
  56. 	local sides_width, sides_height = element_get_actual_size(self.n_h) 
  57. 	 
  58. 	--N 
  59. 	element_set_actual_size(self.n_h, width, sides_height) 
  60. 	 
  61. 	--NE 
  62. 	vint_set_property(self.ne_h, "anchor", width + start_x, start_y) 
  63. 	 
  64. 	--E 
  65. 	vint_set_property(self.e_h, "anchor", width + start_x, start_y) 
  66. 	element_set_actual_size(self.e_h, height, sides_height) 
  67. 	 
  68. 	--SE 
  69. 	vint_set_property(self.se_h, "anchor", width + start_x, height + start_y) 
  70. 	 
  71. 	--S 
  72. 	vint_set_property(self.s_h, "anchor", start_x, height + start_y) 
  73. 	element_set_actual_size(self.s_h, width, -sides_height) 
  74. 	 
  75. 	--SW 
  76. 	vint_set_property(self.sw_h, "anchor", start_x, height + start_y) 
  77. 	--element_set_actual_size(sw_h, width, sides_height) 
  78. 	 
  79. 	--W 
  80. 	element_set_actual_size(self.w_h, height, sides_height) 
  81. 	 
  82. 	--C 
  83. 	element_set_actual_size(self.c_h, width, height) 
  84. 	 
  85. 	self.width = x 
  86. 	self.height = y 
  87. end 
  88.  
  89. function Vdo_shadow:set_offset(x, y) 
  90. 	local shadow_h = vint_object_find("shadow_grp", self.handle) 
  91. 	vint_set_property(shadow_h, "anchor", x, y) 
  92. end 
  93.  
  94. function Vdo_shadow:show_center(show_center) 
  95. 	vint_set_property(self.c_h, "visible", show_center) 
  96. end 
  97.  
  98. function Vdo_shadow:set_spread(spread_px) 
  99. 	 
  100. 	local sides_width, sides_height = element_get_actual_size(self.ne_h) 
  101. 	 
  102. 	--have to flip the bitmaps, so this is how we keep track of the flipping 
  103. 	local corners = { 
  104. 		{self.nw_h, 	1, 	1},	--object_h,		x,		y 
  105. 		{self.ne_h, 	-1, 	1}, 
  106. 		{self.se_h, 	-1, 	-1}, 
  107. 		{self.sw_h, 	1,		-1}, 
  108. 	} 
  109. 	 
  110. 	local sides = { 
  111. 		{self.n_h, 1,1}, 
  112. 		{self.e_h, 1,1}, 
  113. 		{self.s_h, 1,-1}, 
  114. 		{self.w_h, 1,1}, 
  115. 	} 
  116. 	 
  117. 	for idx, corner in pairs(corners) do 
  118. 		element_set_actual_size(corner[1], abs(spread_px) * corner[2], abs(spread_px) * corner[3]) 
  119. 	end 
  120. 	 
  121. 	for idx, side in pairs(sides) do 
  122. 		local width, height = element_get_actual_size(side[1]) 
  123. 		element_set_actual_size(side[1], abs(width) * side[2], abs(spread_px) * side[3]) 
  124. 	end 
  125. end 
  126.  
  127.