-- Object Tool Tip - adds a tool tip that hover above the object when the mouse is over it. -- Created by: Thor Alexander -- Created on: 4/15/2008 -- Revisions -- Custom UI Added - J.McNab 07/08/08 -- Listens for these triggers: -- attach() -- detach() -- Broadcasts these triggers: -- none window_w = 400 window_h = 300 empty_button = '12071:27' smart_object_thumb_winstyle = '0:2' tooltip_tail = {above = '12071:53', below = '12071:54', left = '12071:55', right = '12071:56'} SCRIPT_ID = '12071:7' Define Properties() -- Private Properties ui_label_tool_tip = 0 xPos = 1 yPos = 1 -- Script Parameters use_tool_tip = 1 ExposeProperty('use_tool_tip', 'Display a tooltip when mouse is over this object?', 'checkbox') SetPropRange('use_tool_tip', 0, 1) PersistProperty('use_tool_tip') smart_object_tool_tip_text = 'tool tip test' ExposeProperty('smart_object_tool_tip_text', 'Tool tip to display for this object?') PersistProperty('smart_object_tool_tip_text') delay = 500 ExposeProperty('delay', 'Delay to wait before popping up tool tip when mouse is over this object?') SetPropRange('delay', 0, 500) PersistProperty('delay') hint = 'above' ExposeProperty('hint', 'Hint for placement of tool tip?', 'list') PersistProperty('hint') hint_list = {'above', 'below', 'left', 'right'} fg_color = {red = 0, green = 0, blue = 0, alpha = 1} ExposeProperty('fg_color', 'What color do you want the tooltip text to be?', 'color') bg_color = {red = 255, green = 255, blue = 255, alpha = 0.9} ExposeProperty('bg_color', 'What color do you want the tooltip background to be?', 'color') width = 100 ExposeProperty('width', 'Width of the tooltip?') PersistProperty('width') font_size = 10 ExposeProperty('font_size', 'Font size for tooltip?', 'list') PersistProperty('font_size') font_size_list = {'10', '12', '14', '16'} script_description = 'Tooltip' script_long_description = 'Attach a tooltip to this object when users hover their mouse over it' script_icon = '12071:434' end Trigger attach() -- Tooltip support setup(self) end Trigger detach() cleanup(self) end Trigger enter() setup(self) end Trigger leave() clean(self) end Trigger set_script_param(user, user_id, script_id, param_name, value) -- Debug('%s recieved param changed %s %s', script_id, param_name, value) if script_id == SCRIPT_ID then SendTo(self, 'set_tool_tip', 100, user, self.id) end end Trigger set_tool_tip(user, object_id, tooltip) if(object_id == self.id) then if(tooltip ~= nil) then self.smart_object_tool_tip_text = tooltip end setup(self) end end -- Local functions function cleanup(self) if (self.ui_label_tool_tip ~= 0) then UiDelete(self.ui_label_tool_tip) self.ui_label_tool_tip = 0 end end function setup(self) Debug("Strating tooltip id: %s", self.ui_label_tool_tip) cleanup(self) Debug("Post Clean tooltip id: %s", self.ui_label_tool_tip) if self.use_tool_tip ~= 1 then return end local char_width = self.font_size * .45 local chars_per_line = math.ceil((self.width - 15)/char_width) local char_height = self.font_size * 1.2 local lines = math.ceil(string.len(self.smart_object_tool_tip_text)/chars_per_line) local height = lines * char_height + 15 local tooltip = UiElement(0, 'smart_object_tooltip', self.xPos, self.yPos) local tooltip_text = UiMultiLabel(tooltip, 'smart_object_tooltip', 0, 0, self.width, height, self.fg_color.red, self.fg_color.green, self.fg_color.blue, self.bg_color.red, self.bg_color.green, self.bg_color.blue, self.bg_color.alpha, 0, 0, 2) UiText(tooltip_text, string.format("%s", self.font_size, self.smart_object_tool_tip_text)) if(self.hint == 'above') then tail_w = 8 tail_h = 16 tail_x = self.width/2 - 4 tail_y = height end if(self.hint == 'below') then tail_w = 8 tail_h = 16 tail_x = self.width/2 - 4 tail_y = -16 end if(self.hint == 'left') then tail_w = 16 tail_h = 8 tail_x = self.width tail_y = height / 2 - 4 end if(self.hint == 'right') then tail_w = 16 tail_h = 8 tail_x = -16 tail_y = height/2 - 4 end local tail = UiImage(tooltip, 'tooltip_tail', tail_x, tail_y, tail_w, tail_h, tooltip_tail[self.hint]) UiColor(tail, self.bg_color.red, self.bg_color.green, self.bg_color.blue, self.bg_color.alpha) self.ui_label_tool_tip = tooltip UiHoverObject(self, self.ui_label_tool_tip, self.delay, self.hint) Debug("Tooltip text: %s", self.smart_object_tool_tip_text) Debug("Ending tooltip id: %s", self.ui_label_tool_tip) end