Advertisement
Guest User

Chat_Capture_Miniwindow.xml

a guest
May 25th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 29.54 KB | None | 0 0
  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <!DOCTYPE muclient>
  3.  
  4. <!-- Bits of this plugin and ideas were borrowed and remixed from the MUSHclient community. http://www.gammon.com.au/forum/?id=9385 and others. -->
  5. <!-- Modifications for Aardwolf and extra awesome sauce added by Fiendish with help from Orogan -->
  6. <!-- Adapated by Nick Gammon for Smaug and similar MUDs -->
  7.  
  8. <muclient>
  9.     <plugin
  10.     name="Chat_Capture_Miniwindow"
  11.     author="Fiendish"
  12.     id="565dae21eb816a2fdb8d50f9"
  13.     language="Lua"
  14.     purpose="Move chats to a miniwindow"
  15.     date_written="2010-04-04"
  16.     date_modified="2011-01-05"
  17.     requires="4.52"
  18.     version="2.4"
  19.     save_state="y"
  20.     >
  21.    
  22. <description trim="y">
  23. USAGE:
  24.  
  25.   chats echo on    : echo chats in main window
  26.   chats echo off   : do not echo chats
  27.   chats show       : show chats window
  28.   chats hide       : hide chats window
  29.  
  30.   LH-click a line to copy it to the clipboard
  31.   RH-click main window to see menu of options
  32.  
  33.   Click title bar to drag window.
  34. </description>
  35.  
  36. </plugin>
  37.  
  38. <triggers>
  39.     <trigger
  40.     enabled="y"
  41.     match="[Public] *"
  42.     script="chats"
  43.     omit_from_output="y"
  44.     sequence="100"
  45.     ></trigger>
  46.  
  47.     <trigger
  48.     enabled="y"
  49.     match="[Info] *"
  50.     script="chats"
  51.     omit_from_output="y"
  52.     sequence="100"
  53.     ></trigger>
  54.  
  55.     <trigger
  56.     enabled="y"
  57.     match="[Guest] *"
  58.     script="chats"
  59.     omit_from_output="y"
  60.     sequence="100"
  61.     ></trigger>
  62.    
  63.     <trigger
  64.     enabled="y"
  65.     match="[Events] *"
  66.     script="chats"
  67.     omit_from_output="y"
  68.     sequence="100"
  69.     ></trigger>
  70.  
  71.     <trigger
  72.     enabled="y"
  73.     match="[History] *"
  74.     script="chats"
  75.     omit_from_output="y"
  76.     sequence="100"
  77.     ></trigger>
  78.    
  79. </triggers>
  80.  
  81. <aliases>
  82.     <alias
  83.     script="chat_echo"
  84.     match="^chats echo( on| off)?$"
  85.     enabled="y"
  86.     regexp="y"
  87.     sequence="100"
  88.     ignore_case="y"
  89.     ></alias>
  90.  
  91.     <alias
  92.     script="chat_show"
  93.     match="chats show"
  94.     enabled="y"
  95.     sequence="100"
  96.     ignore_case="y"
  97.     ></alias>
  98.  
  99.     <alias
  100.     script="chat_hide"
  101.     match="chats hide"
  102.     enabled="y"
  103.     sequence="100"
  104.     ignore_case="y"
  105.     ></alias>
  106.        
  107. </aliases>
  108.  
  109. <script>
  110. <![CDATA[
  111.  
  112. require "movewindow"  -- load the movewindow.lua module
  113. require "copytable"
  114.  
  115. BODY_FONT_NAME = "Fixedsys"
  116. BODY_FONT_SIZE = 9
  117. SCROLL_BAR_WIDTH = 15
  118. MAX_LINES = 10000 -- how many lines to store in scrollback
  119.  
  120. -- date_format = "[%d %b %H:%M:%S] "        -- [30 Aug 13:29:49]   date and time 24 hour
  121. -- date_format = "[%d %b %I:%M:%S%p] "  -- [30 Aug 01:20:12PM]     date and time 12 hour
  122. -- date_format = "[%H:%M:%S] "          -- [13:29:08]          time 24 hour
  123. -- date_format = "[%X] "                  -- [1:22:06 PM]            time 12 hour
  124.  
  125. TIMESTAMP_TEXT_COLOUR = "white"
  126. TIMESTAMP_BACK_COLOUR = "black"
  127.  
  128. -- doing it this way makes them default to true the first time around
  129. timestamp = not (GetVariable("timestamp") == "false")
  130. echo = not (GetVariable("echo") == "false")
  131.  
  132. date_format = GetVariable("date_format")
  133. WINDOW_WIDTH = tonumber(GetVariable("WINDOW_WIDTH"))
  134. WINDOW_HEIGHT = tonumber(GetVariable("WINDOW_HEIGHT"))
  135.  
  136. -- offset of text from edge
  137. TEXT_INSET = 5
  138.  
  139. -- where to store the chat line
  140. lines = {}  -- table of recent chat lines
  141. rawlines = {}
  142.  
  143. lineStart = ""
  144. lineEnd = ""
  145. WINDOW_COLUMNS = ""
  146. WINDOW_LINES = ""
  147.  
  148. theme = {
  149.     WINDOW_BACKGROUND = ColourNameToRGB ("#000000"), -- for miniwindow body
  150.     WINDOW_BORDER = ColourNameToRGB("#E8E8E8"), -- for miniwindow body
  151.    
  152.     HIGHLIGHT=ColourNameToRGB("#FFFFFF"), -- for 3D surfaces
  153.     FACE=ColourNameToRGB("#D4D0C8"), -- for 3D surfaces
  154.     INNERSHADOW=ColourNameToRGB("#808080"), -- for 3D surfaces
  155.     OUTERSHADOW = ColourNameToRGB("#404040"), -- for 3D surfaces
  156.    
  157.     BACK_FACE = ColourNameToRGB ("#E8E8E8"), -- for contrasting details
  158.     DETAIL = ColourNameToRGB ("#000000"), -- for contrasting details
  159.  
  160.     TITLE_HEIGHT = 17, -- for miniwindow title area
  161.     SUBTITLE_HEIGHT = 17, -- for miniwindow title area
  162.     TITLE_FONT_NAME = "Dina", -- for miniwindow title area
  163.     TITLE_FONT_SIZE = 8 -- for miniwindow title area
  164. }  -- end theme table
  165.  
  166.  
  167. -- replacement for WindowRectOp action 5, which allows for a 3D look while maintaining color theme
  168. -- Requires global theme.HIGHLIGHT, theme.FACE, theme.INNERSHADOW, and theme.OUTERSHADOW rgb colors to be set.
  169. function DrawThemed3DRect(Window, left, top, right, bottom)
  170.     WindowRectOp(Window, miniwin.rect_fill, left, top, right, bottom, theme.FACE)
  171.     WindowLine(Window, left, top, right, top, theme.HIGHLIGHT,
  172.                 miniwin.pen_solid + miniwin.pen_endcap_flat, 1)
  173.     WindowLine(Window, left, top, left, bottom, theme.HIGHLIGHT,
  174.                 miniwin.pen_solid + miniwin.pen_endcap_flat, 1)
  175.     WindowLine(Window, left, bottom-2, right, bottom-2, theme.INNERSHADOW,
  176.                 miniwin.pen_solid + miniwin.pen_endcap_flat, 1)
  177.     WindowLine(Window, right-2, top, right-2, bottom-2, theme.INNERSHADOW,
  178.                 miniwin.pen_solid + miniwin.pen_endcap_flat, 1)
  179.     WindowLine(Window, left, bottom-1, right, bottom-1, theme.OUTERSHADOW,
  180.                 miniwin.pen_solid + miniwin.pen_endcap_flat, 1)
  181.     WindowLine(Window, right-1, top, right-1, bottom-1, theme.OUTERSHADOW,
  182.                 miniwin.pen_solid + miniwin.pen_endcap_flat, 1)    
  183. end
  184.  
  185. function DrawThemedResizeTag(Window, x1, y1, size)
  186.     local x2, y2 = x1+size, y1+size
  187.     DrawThemed3DRect(Window, x1, y1, x2, y2)
  188.     local m = 2
  189.     local n = 2
  190.     while (x1+m+2 <= x2-3 and y1+n+1 <= y2-4) do
  191.         WindowLine(Window, x1+m+1, y2-4, x2-3, y1+n, theme.HIGHLIGHT,
  192.                     miniwin.pen_solid, 1)
  193.         WindowLine(Window, x1+m+2, y2-4, x2-3, y1+n+1, theme.INNERSHADOW,
  194.                     miniwin.pen_solid, 1)
  195.         m = m+3
  196.         n = n+3
  197.     end
  198. end  -- function DrawThemedResizeTag
  199.  
  200.  
  201. Win = GetPluginID()
  202. font_height = ""
  203. line_height = ""
  204. windowinfo = ""
  205. startx = ""
  206. starty = ""
  207.  
  208. function ResizeMoveCallback()
  209.     posx, posy = WindowInfo (Win, 17), WindowInfo (Win, 18)
  210.     if (WindowTextWidth(Win, "titlefont"..Win, "WWWCOMMUNICATION")+2*SCROLL_BAR_WIDTH <= WINDOW_WIDTH+posx-startx) then
  211.         WINDOW_WIDTH = WINDOW_WIDTH+posx-startx
  212.         startx = posx
  213.     end  -- if
  214.     if (3*SCROLL_BAR_WIDTH+10+line_height+theme.TITLE_HEIGHT <= WINDOW_HEIGHT+posy-starty) then
  215.         WINDOW_HEIGHT = WINDOW_HEIGHT+posy-starty
  216.         starty = posy
  217.     end -- if
  218.     init(false)
  219. end -- function ResizeMoveCallback
  220.  
  221. function ResizeReleaseCallback()
  222.     WINDOW_HEIGHT = theme.TITLE_HEIGHT+(line_height*(WINDOW_LINES-1))+3
  223.     init(true)
  224. end  -- ResizeReleaseCallback
  225.  
  226. function OnPluginInstall()
  227.     -- Dummy window to get font characteristics
  228.     check (WindowCreate (Win, 0, 0, 1, 1, 0, 0, theme.WINDOW_BACKGROUND) )
  229.     check (WindowFont(Win, "bodyfont"..Win, BODY_FONT_NAME, BODY_FONT_SIZE))
  230.     check (WindowFont(Win, "titlefont"..Win, theme.TITLE_FONT_NAME, theme.TITLE_FONT_SIZE))
  231.     font_height = WindowFontInfo (Win, "bodyfont"..Win, 1) -  WindowFontInfo (Win, "bodyfont"..Win, 4) + 1
  232.     line_height = font_height+1
  233.     font_width = WindowTextWidth (Win, "bodyfont"..Win, "W")
  234.    
  235.     -- install the window movement handler, get back the window position
  236.     windowinfo = movewindow.install (Win, miniwin.pos_top_right, miniwin.create_absolute_location, true)
  237.  
  238.     -- check for Echo/Timestamp/date_format/window size (in pixels) variables, if not there, set them
  239.     if date_format == nil then
  240.         date_format = "[%d %b %H:%M:%S] "
  241.     end -- if
  242.     if WINDOW_WIDTH == nil then
  243.         WINDOW_WIDTH = (font_width*80)+SCROLL_BAR_WIDTH -- 80 columns
  244.     end
  245.     if WINDOW_HEIGHT == nil then
  246.         WINDOW_HEIGHT = theme.TITLE_HEIGHT+(line_height*6)+2 -- 6 lines
  247.     end -- if
  248.     init(true)
  249.     OnPluginEnable ()  -- do initialization stuff
  250. end -- function OnPluginInstall
  251.  
  252. function init(firstTime)
  253.     -- how many lines and columns will fit?
  254.     WINDOW_LINES = math.ceil((WINDOW_HEIGHT-theme.TITLE_HEIGHT)/line_height)
  255.     WINDOW_COLUMNS = math.ceil((WINDOW_WIDTH-SCROLL_BAR_WIDTH)/font_width)
  256.  
  257.     if firstTime then
  258.         WindowCreate(Win, windowinfo.window_left, windowinfo.window_top, WINDOW_WIDTH, WINDOW_HEIGHT, windowinfo.window_mode, windowinfo.window_flags, theme.WINDOW_BACKGROUND)
  259.  
  260.         -- catch for right-click menu and line selection
  261.         WindowAddHotspot(Win, "textarea", 0, theme.TITLE_HEIGHT, WINDOW_WIDTH-SCROLL_BAR_WIDTH,0,
  262.             "", "", "MouseDown", "CancelMouseDown", "MouseUp", "",
  263.             miniwin.cursor_ibeam, 0)
  264.         -- add the drag handler so they can move the window around
  265.         movewindow.add_drag_handler (Win, 0, 0, 0, theme.TITLE_HEIGHT)
  266.        
  267.         -- scroll bar up/down buttons
  268.         WindowAddHotspot(Win, "up", WINDOW_WIDTH-SCROLL_BAR_WIDTH, theme.TITLE_HEIGHT, 0, theme.TITLE_HEIGHT+SCROLL_BAR_WIDTH,
  269.             "MouseOver", "CancelMouseOver", "MouseDown", "CancelMouseDown", "MouseUp", "",
  270.             miniwin.cursor_hand, 0)
  271.         WindowAddHotspot(Win, "down", WINDOW_WIDTH-SCROLL_BAR_WIDTH, WINDOW_HEIGHT-(2*SCROLL_BAR_WIDTH), 0, WINDOW_HEIGHT-SCROLL_BAR_WIDTH,
  272.             "MouseOver", "CancelMouseOver", "MouseDown", "CancelMouseDown", "MouseUp", "",
  273.             miniwin.cursor_hand, 0)
  274.  
  275.         -- add the resize widget hotspot
  276.         WindowAddHotspot(Win, "resizer", WINDOW_WIDTH-SCROLL_BAR_WIDTH, WINDOW_HEIGHT-SCROLL_BAR_WIDTH, WINDOW_WIDTH, WINDOW_HEIGHT,
  277.             "MouseOver", "CancelMouseOver", "MouseDown", "CancelMouseDown", "MouseUp", "",
  278.             miniwin.cursor_nw_se_arrow, 0)
  279.         WindowDragHandler(Win, "resizer", "ResizeMoveCallback", "ResizeReleaseCallback", 0)    
  280.     else
  281.         WindowResize(Win, WINDOW_WIDTH, WINDOW_HEIGHT, theme.WINDOW_BACKGROUND)
  282.         WindowMoveHotspot(Win, "textarea", 0, theme.TITLE_HEIGHT, WINDOW_WIDTH-SCROLL_BAR_WIDTH, 0)
  283.         WindowMoveHotspot(Win, "up", WINDOW_WIDTH-SCROLL_BAR_WIDTH, theme.TITLE_HEIGHT, 0, theme.TITLE_HEIGHT+SCROLL_BAR_WIDTH)
  284.         WindowMoveHotspot(Win, "down", WINDOW_WIDTH-SCROLL_BAR_WIDTH, WINDOW_HEIGHT-(2*SCROLL_BAR_WIDTH), 0, WINDOW_HEIGHT-SCROLL_BAR_WIDTH)
  285.         WindowMoveHotspot(Win, "resizer", WINDOW_WIDTH-SCROLL_BAR_WIDTH, WINDOW_HEIGHT-SCROLL_BAR_WIDTH, WINDOW_WIDTH, 0)
  286.     end -- if
  287.     WindowShow(Win, true)
  288.    
  289.     if (firstTime == true) then
  290.         lines = {}
  291.         for _,styles in ipairs(rawlines) do
  292.             fillBuffer(styles)
  293.         end  -- for each line
  294.     end -- if
  295.  
  296.     lineStart = math.max(1, #lines-WINDOW_LINES+2)
  297.     lineEnd = math.max(1, #lines)
  298.     refresh()
  299. end  -- function init
  300.  
  301. function OnPluginClose ()
  302.     -- if enabled
  303.     if GetPluginInfo (GetPluginID(), 17) then
  304.         OnPluginDisable()
  305.     end -- if enabled
  306. end -- function OnPluginClose
  307.  
  308. function OnPluginEnable ()
  309.     WindowShow (Win, true)
  310. end -- function OnPluginEnable
  311.  
  312. function OnPluginSaveState ()
  313.     -- save window current location for next time  
  314.     SetVariable ("enabled", tostring (GetPluginInfo (GetPluginID(), 17)))
  315.     movewindow.save_state (Win)
  316.     -- save echo/timestamp status
  317.     SetVariable ("echo", tostring (echo))
  318.     SetVariable ("timestamp", tostring (timestamp))
  319.     SetVariable("date_format", date_format)
  320.     SetVariable("WINDOW_WIDTH", WINDOW_WIDTH)
  321.     SetVariable("WINDOW_HEIGHT", WINDOW_HEIGHT)
  322. end -- function OnPluginSaveState
  323.  
  324. function OnPluginDisable ()
  325.     WindowShow( Win, false )
  326. end -- function OnPluginDisable
  327.  
  328. -- display one line
  329. function Display_Line (line, styles)
  330.  
  331.   local left    = TEXT_INSET
  332.   local top     = theme.TITLE_HEIGHT + (line * line_height) + 1
  333.   local bottom  = top + line_height
  334.   local font    = "bodyfont" .. Win
  335.  
  336.   if backfill then
  337.       WindowRectOp (Win, miniwin.rect_fill, 1, top, WINDOW_WIDTH - SCROLL_BAR_WIDTH, bottom, ColourNameToRGB("#333333"))
  338.   end -- backfill
  339.  
  340.   if (styles) then
  341.     for _, style in ipairs (styles) do
  342.       local width = WindowTextWidth (Win, font, style.text) -- get width of text
  343.       local right = left + width
  344.       WindowRectOp (Win, miniwin.rect_fill, left, top, right, bottom, style.backcolour)  -- draw background
  345.       WindowText (Win, font, style.text, left, top, 0, 0, style.textcolour)  -- draw text
  346.       left = left + width  -- advance horizontally
  347.     end -- for each style run        
  348.   end -- if  styles
  349.  
  350. end -- Display_Line
  351.  
  352.  
  353. -- display all visible lines
  354. function writeLines()
  355.     for count = lineStart, lineEnd do
  356.         Display_Line( count-lineStart, lines[count][1], false )
  357.     end  -- for each line
  358.     Redraw()
  359.  
  360. end  -- function writeLines
  361.  
  362. -- clear and redraw
  363. function refresh()
  364.     WindowRectOp(Win, miniwin.rect_fill, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, theme.WINDOW_BACKGROUND)
  365.     drawStuff()
  366. end  -- function refresh
  367.  
  368. barPos = ""
  369. barSize = ""
  370. totalSteps = ""
  371.  
  372. function drawStuff()
  373.     -- draw border
  374.     WindowRectOp (Win, miniwin.rect_frame, 0, 0, 0, 0, theme.WINDOW_BORDER)
  375.    
  376.     -- Title bar
  377.     DrawThemed3DRect(Win, 0, 0, WINDOW_WIDTH, theme.TITLE_HEIGHT)
  378.  
  379.     -- Title text
  380.     WindowText(Win, "titlefont"..Win, "COMMUNICATION", ((WINDOW_WIDTH)-(7.5*line_height))/2, (theme.TITLE_HEIGHT-line_height)/2, WINDOW_WIDTH, theme.TITLE_HEIGHT, theme.DETAIL, false)
  381.  
  382.     if #lines >= 1 then
  383.         writeLines()
  384.     end -- if
  385.        
  386.     -- Scrollbar base
  387.     WindowRectOp(Win, miniwin.rect_fill, WINDOW_WIDTH-SCROLL_BAR_WIDTH, theme.TITLE_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT, theme.BACK_FACE) -- scroll bar background
  388.     WindowRectOp(Win, miniwin.rect_frame, WINDOW_WIDTH-SCROLL_BAR_WIDTH+1, SCROLL_BAR_WIDTH+theme.TITLE_HEIGHT+1, WINDOW_WIDTH-1, WINDOW_HEIGHT-(2*SCROLL_BAR_WIDTH)-1, theme.DETAIL) -- scroll bar background inset rectangle
  389.     DrawThemed3DRect(Win, WINDOW_WIDTH-SCROLL_BAR_WIDTH, theme.TITLE_HEIGHT, WINDOW_WIDTH, theme.TITLE_HEIGHT+SCROLL_BAR_WIDTH) -- top scroll button
  390.     DrawThemed3DRect(Win, WINDOW_WIDTH-SCROLL_BAR_WIDTH, WINDOW_HEIGHT-(SCROLL_BAR_WIDTH*2), WINDOW_WIDTH, WINDOW_HEIGHT-SCROLL_BAR_WIDTH) -- bottom scroll button
  391.    
  392.     -- draw triangle in up button
  393.     points = string.format ("%i,%i,%i,%i,%i,%i", (WINDOW_WIDTH-SCROLL_BAR_WIDTH)+2, theme.TITLE_HEIGHT+8,(WINDOW_WIDTH-SCROLL_BAR_WIDTH)+6, theme.TITLE_HEIGHT+4,(WINDOW_WIDTH-SCROLL_BAR_WIDTH)+10, theme.TITLE_HEIGHT+8)
  394.     WindowPolygon (Win, points,
  395.         theme.DETAIL, miniwin.pen_solid, 1,   -- pen (solid, width 1)
  396.         theme.DETAIL, miniwin.brush_solid, --brush (solid)
  397.         true, --close
  398.         false)  --alt fill
  399.  
  400.     -- draw triangle in down button    
  401.     points = string.format ("%i,%i,%i,%i,%i,%i", (WINDOW_WIDTH-SCROLL_BAR_WIDTH)+2, (WINDOW_HEIGHT-SCROLL_BAR_WIDTH)-10,(WINDOW_WIDTH-SCROLL_BAR_WIDTH)+6, (WINDOW_HEIGHT-SCROLL_BAR_WIDTH)-6, (WINDOW_WIDTH-SCROLL_BAR_WIDTH)+10,(WINDOW_HEIGHT-SCROLL_BAR_WIDTH)-10)
  402.     WindowPolygon (Win, points,
  403.         theme.DETAIL, miniwin.pen_solid, 1,   -- pen (solid, width 1)
  404.         theme.DETAIL, miniwin.brush_solid, --brush (solid)
  405.         true, --close
  406.         false) --alt fill
  407.    
  408.     -- The scrollbar position indicator
  409.     totalSteps = #lines
  410.     if (totalSteps <= WINDOW_LINES-1) then totalSteps = 1 end
  411.     SCROLL_BAR_HEIGHT = (WINDOW_HEIGHT-(3*SCROLL_BAR_WIDTH)-theme.TITLE_HEIGHT)
  412.     if (not dragscrolling) then
  413.         stepNum = lineStart-1
  414.         barPos = SCROLL_BAR_WIDTH +theme.TITLE_HEIGHT+ ((SCROLL_BAR_HEIGHT/totalSteps) * stepNum)
  415.         barSize = (SCROLL_BAR_HEIGHT/math.max(WINDOW_LINES-1,totalSteps)) * (WINDOW_LINES-1)
  416.         if barSize < 10 then
  417.             barSize = 10
  418.         end
  419.         if barPos+barSize > SCROLL_BAR_WIDTH+theme.TITLE_HEIGHT+SCROLL_BAR_HEIGHT then
  420.             barPos = SCROLL_BAR_WIDTH+theme.TITLE_HEIGHT+SCROLL_BAR_HEIGHT - barSize
  421.         end
  422.         WindowAddHotspot(Win, "scroller", (WINDOW_WIDTH-SCROLL_BAR_WIDTH), barPos, WINDOW_WIDTH, barPos+barSize,
  423.                         "MouseOver", "CancelMouseOver", "MouseDown", "CancelMouseDown", "MouseUp", "",
  424.                         miniwin.cursor_hand, 0)
  425.         WindowDragHandler(Win, "scroller", "ScrollerMoveCallback", "ScrollerReleaseCallback", 0)
  426.     end  -- if
  427.     DrawThemed3DRect(Win, WINDOW_WIDTH-SCROLL_BAR_WIDTH, barPos, WINDOW_WIDTH, barPos+barSize)
  428.    
  429.     -- resizer tag
  430.     DrawThemedResizeTag(Win, WINDOW_WIDTH-SCROLL_BAR_WIDTH, WINDOW_HEIGHT-SCROLL_BAR_WIDTH, SCROLL_BAR_WIDTH)
  431.    
  432.     Redraw()
  433. end  -- function drawStuff
  434.  
  435. function ScrollerMoveCallback(flags, hotspot_id)
  436.     mouseposy = WindowInfo(Win, 18)
  437.     windowtop = WindowInfo(Win, 2)
  438.     barPos = math.max(mouseposy-windowtop+clickdelta, SCROLL_BAR_WIDTH+theme.TITLE_HEIGHT)
  439.     if barPos > WINDOW_HEIGHT-(SCROLL_BAR_WIDTH*2)-barSize then
  440.         barPos = WINDOW_HEIGHT-(SCROLL_BAR_WIDTH*2)-barSize
  441.         lineStart = math.max(1,#lines-WINDOW_LINES+2)
  442.         lineEnd = #lines
  443.     else
  444.         lineStart = math.floor((barPos-SCROLL_BAR_WIDTH-theme.TITLE_HEIGHT)/(SCROLL_BAR_HEIGHT/totalSteps)+1)
  445.         lineEnd = math.min(lineStart + WINDOW_LINES-2, #lines)
  446.     end -- if
  447.     refresh()
  448. end  -- function ScrollerMoveCallback
  449.  
  450. function ScrollerReleaseCallback(flags, hotspot_id)
  451.     dragscrolling = false
  452.     refresh()
  453. end  -- function ScrollerReleaseCallback
  454.  
  455. function fillBuffer(rawstyles)
  456.     local avail = 0
  457.     local line_styles
  458.     local beginning = true
  459.     -- keep pulling out styles and trying to fit them on the current line
  460.     local styles = copytable.deep (rawstyles)
  461.     local remove = table.remove
  462.     local insert = table.insert
  463.     while #styles > 0 do
  464.         if avail <= 0 then -- no room available? start new line
  465.             -- remove first line if filled up
  466.             if #lines >= MAX_LINES then
  467.                 remove (lines, 1)
  468.             end -- if
  469.             avail = WINDOW_WIDTH - (TEXT_INSET * 2) - 9
  470.             line_styles = {}
  471.             add_line( line_styles, beginning )
  472.             beginning = false
  473.         end -- line full
  474.  
  475.         -- get next style, work out how long it is
  476.         local style = remove (styles, 1)
  477.         local width = WindowTextWidth (Win, "bodyfont"..Win, style.text)
  478.  
  479.         -- if it fits, copy whole style in
  480.         if width <= avail then
  481.             insert (line_styles, style)
  482.             avail = avail - width
  483.         else -- otherwise, have to split style  
  484.             -- look for trailing space (work backwards). remember where space is
  485.             local col = style.length - 1
  486.             local split_col
  487.             -- keep going until out of columns
  488.             while col > 1 do
  489.                 width = WindowTextWidth (Win, "bodyfont"..Win, style.text:sub (1, col))
  490.                 if width <= avail then
  491.                     if not split_col then
  492.                         split_col = col  -- in case no space found, this is where we can split
  493.                     end -- if
  494.                     -- see if space here
  495.                     if style.text:sub (col, col) == " " then
  496.                         split_col = col
  497.                         break
  498.                     end -- if space
  499.                 end -- if will now fit
  500.                 col = col - 1
  501.             end -- while
  502.          
  503.             -- if we found a place to split, use old style, and make it shorter. Also make a copy and put the rest in that
  504.             if split_col then
  505.                 insert (line_styles, style)
  506.                 local style_copy = copytable.shallow (style)
  507.                 style.text = style.text:sub (1, split_col)
  508.                 style.length = split_col
  509.                 style_copy.text = style_copy.text:sub (split_col + 1)
  510.                 style_copy.length = #style_copy.text
  511.                 insert (styles, 1, style_copy)
  512.             elseif next (line_styles) == nil then
  513.                 insert (line_styles, style)
  514.             else
  515.                 insert (styles, 1, style)
  516.             end -- if    
  517.             avail = 0  -- now we need to wrap    
  518.         end -- if could not fit whole thing in
  519.     end -- while we still have styles over
  520. end  -- function fillBuffer
  521.  
  522. -- Main capture routine
  523. function chats (name, line, wildcards, styles)
  524.    
  525.     -- echo in this world as well if the user wants
  526.     if echo then
  527.         for _, v in ipairs (styles) do
  528.             ColourTell (RGBColourToName (v.textcolour),RGBColourToName (v.backcolour),v.text)
  529.         end -- for each style run
  530.         Note ("")  -- wrap up line
  531.     end -- echo wanted
  532.  
  533.     -- inject timestamp if wanted
  534.     if timestamp then
  535.         local tstamp = os.date (date_format)
  536.         table.insert (styles, 1, {
  537.           text = tstamp,
  538.           textcolour  = ColourNameToRGB (TIMESTAMP_TEXT_COLOUR),
  539.           backcolour = ColourNameToRGB (TIMESTAMP_BACK_COLOUR),
  540.           length = string.len (tstamp),
  541.           style = 0,
  542.         } )
  543.     end -- if
  544.    
  545.     -- store the raw lines for use during resizing
  546.     if #rawlines >= MAX_LINES then
  547.         table.remove(rawlines, 1)
  548.     end
  549.     table.insert(rawlines, styles)
  550.    
  551.     fillBuffer(styles)
  552.     refresh( )
  553. end -- function chats
  554.  
  555. function add_line ( line, is_beginning_of_message )
  556.     -- add new line
  557.     table.insert (lines, {line, false} )
  558.     lines[#lines][2] = is_beginning_of_message
  559.  
  560.     -- advance the count
  561.     if #lines >= WINDOW_LINES then
  562.         lineStart = lineStart + 1
  563.     end -- if
  564.        
  565.     if #lines > 1 then
  566.         lineEnd = lineEnd + 1
  567.     end -- if
  568. end -- function add_line
  569.  
  570. keepscrolling = false
  571. require "wait"
  572.  
  573. function scrollbar(calledBy)
  574.     wait.make (function()
  575.         while keepscrolling == true do
  576.             if calledBy == "up" then
  577.                 if (lineStart > 1) then
  578.                     lineStart = lineStart - 1
  579.                     lineEnd = lineEnd - 1
  580.                     WindowRectOp(Win, miniwin.rect_draw_edge, (WINDOW_WIDTH-SCROLL_BAR_WIDTH), theme.TITLE_HEIGHT, 0, theme.TITLE_HEIGHT+SCROLL_BAR_WIDTH,
  581.                         miniwin.rect_edge_sunken,  miniwin.rect_edge_at_all + miniwin.rect_option_fill_middle) -- up arrow pushed
  582.                     points = string.format ("%i,%i,%i,%i,%i,%i", (WINDOW_WIDTH-SCROLL_BAR_WIDTH)+3, theme.TITLE_HEIGHT+9,(WINDOW_WIDTH-SCROLL_BAR_WIDTH)+7, theme.TITLE_HEIGHT+5,(WINDOW_WIDTH-SCROLL_BAR_WIDTH)+11, theme.TITLE_HEIGHT+9)
  583.                     WindowPolygon (Win, points,
  584.                         theme.DETAIL, miniwin.pen_solid, 1, -- pen (solid, width 1)
  585.                         theme.DETAIL, miniwin.brush_solid, -- brush (solid)
  586.                         true, -- close
  587.                         false) -- alt fill
  588.                 else
  589.                     keepscrolling = false
  590.                 end
  591.             elseif calledBy == "down" then
  592.                 if (lineEnd < #lines) then
  593.                     lineStart = lineStart + 1
  594.                     lineEnd = lineEnd + 1
  595.                 WindowRectOp(Win, miniwin.rect_draw_edge, (WINDOW_WIDTH-SCROLL_BAR_WIDTH), WINDOW_HEIGHT-(SCROLL_BAR_WIDTH*2), 0, WINDOW_HEIGHT-SCROLL_BAR_WIDTH-1,
  596.                     miniwin.rect_edge_sunken,  miniwin.rect_edge_at_all + miniwin.rect_option_fill_middle) -- down arrow pushed
  597.                 points = string.format ("%i,%i,%i,%i,%i,%i", (WINDOW_WIDTH-SCROLL_BAR_WIDTH)+3, (WINDOW_HEIGHT-SCROLL_BAR_WIDTH)-11,(WINDOW_WIDTH-SCROLL_BAR_WIDTH)+7, (WINDOW_HEIGHT-SCROLL_BAR_WIDTH)-7, (WINDOW_WIDTH-SCROLL_BAR_WIDTH)+11,(WINDOW_HEIGHT-SCROLL_BAR_WIDTH)-11) -- draw triangle in up button
  598.                 WindowPolygon (Win, points,
  599.                     theme.DETAIL, miniwin.pen_solid, 1, -- pen (solid, width 1)
  600.                     theme.DETAIL, miniwin.brush_solid, -- brush (solid)
  601.                     true, -- close
  602.                     false) -- alt fill
  603.                 else
  604.                     keepscrolling = false
  605.                 end
  606.             end -- if
  607.             wait.time(0.1)
  608.             refresh()
  609.         end -- while keepscrolling
  610.     end)  -- wait.make
  611. end  -- function scrollbar
  612.  
  613. function GetLineText (styles)
  614.   local t = {}
  615.   for _, style in ipairs (styles) do
  616.     table.insert (t, style.text)
  617.   end -- for
  618.   return table.concat (t)
  619. end -- function GetLineText
  620.  
  621. function GetAllBufferedMessages()
  622.     local t = {}
  623.     for _,styles in ipairs(rawlines) do
  624.       table.insert (t, GetLineText (styles))
  625.     end -- for
  626.     SetClipboard(table.concat(t,"\r\n"))
  627. end -- function GetAllBufferedMessages
  628.  
  629. function GetBufferedMessage(xpos, ypos)
  630.     windowline = math.floor(((ypos-theme.TITLE_HEIGHT)/line_height)+1)-1
  631.     text = ""
  632.     if (#lines > windowline) then
  633.         local line = windowline+lineStart
  634.         -- go to beginning of message
  635.         while lines[line][2] ~= true and line > 1 do
  636.             line = line - 1
  637.         end -- while
  638.         -- first line
  639.         local styles = copytable.deep(lines[line][1])
  640.         if (line-lineStart+1 > 0) then
  641.             Display_Line (line-lineStart, styles, true)
  642.         end -- if
  643.         text = GetLineText (styles)
  644.         -- remaining lines
  645.         line = line + 1
  646.         while line <= #lines and lines[line][2] ~= true do
  647.             local styles = copytable.deep(lines[line][1])
  648.             if (line-lineStart+1 > 0 and line-lineStart < WINDOW_LINES) then
  649.                 Display_Line (line-lineStart, styles, true)
  650.             end
  651.             text = text.. GetLineText (styles)
  652.             line = line + 1
  653.         end -- while
  654.         SetClipboard(text)
  655.     end -- if
  656.     Redraw()
  657.    
  658. end  -- function GetBufferedMessage
  659.  
  660. function MouseOver(flags, hotspot_id)
  661.     keepscrolling = false
  662. end  -- function MouseOver
  663.  
  664. function CancelMouseOver(flags, hotspot_id)
  665.     keepscrolling = false
  666. end  -- function CancelMouseOver
  667.  
  668. function MouseDown(flags, hotspot_id)
  669.     if (hotspot_id == "resizer") then
  670.         startx, starty = WindowInfo (Win, 17), WindowInfo (Win, 18)
  671.     elseif (hotspot_id == "scroller") then
  672.         clickdelta = WindowHotspotInfo(Win, "scroller", 2)-WindowInfo (Win, 15)
  673.         dragscrolling = true
  674.     elseif (hotspot_id == "textarea" and flags == miniwin.hotspot_got_lh_mouse) then
  675.         GetBufferedMessage(WindowInfo(Win, 14), WindowInfo(Win,15))
  676.     else
  677.         keepscrolling = true
  678.         scrollbar(hotspot_id)
  679.     end -- if
  680. end  -- function MouseDown
  681.  
  682. function CancelMouseDown(flags, hotspot_id)
  683.     keepscrolling = false
  684.     refresh()
  685. end  -- function CancelMouseDown
  686.  
  687. function MouseUp(flags, hotspot_id)
  688.     if (hotspot_id == "textarea" and flags == miniwin.hotspot_got_rh_mouse) then
  689.         -- build menu for current state
  690.         right_click_menu()
  691.     else
  692.         refresh()
  693.     end -- if
  694.     keepscrolling = false
  695. end  -- function MouseUp
  696.  
  697. function chat_echo (name, line, wildcards)
  698.     if wildcards [1] == false then
  699.       echo = not echo  -- toggle
  700.     else
  701.       echo = wildcards [1]:lower () == " on"
  702.     end -- if
  703.  
  704.     if echo then
  705.         ColourNote ("yellow", "", "Echoing chats in main window ENABLED.")
  706.     else
  707.         ColourNote ("yellow", "", "Echoing chats in main window DISABLED.")
  708.     end -- if
  709. end -- function chat_echo
  710.  
  711. function chat_show (name, line, wildcards)
  712.    WindowShow( Win, true )
  713.    ColourNote ("yellow", "", "Chats window now shown. Type 'chats hide' to hide it.")
  714. end -- function chat_show
  715.  
  716. function chat_hide (name, line, wildcards)
  717.    WindowShow( Win, false )
  718.    ColourNote ("yellow", "", "Chats window now hidden. Type 'chats show' to see it again.")
  719. end -- function chat_hide
  720.  
  721. -- right click menu
  722. function right_click_menu ()
  723.     menustring ="Copy All To Clipboard|Change Font|Turn Echo "
  724.    
  725.     if echo then
  726.         menustring = menustring .. "Off"
  727.     else
  728.         menustring = menustring .. "On"
  729.     end -- if
  730.    
  731.     menustring = menustring.."|>Timestamp|No Timestamps|30 Aug 13:29:49|30 Aug 01:20:12PM|13:29:08|1:22:06 PM"
  732.     result = WindowMenu (Win,
  733.         WindowInfo (Win, 14),  -- x position
  734.         WindowInfo (Win, 15),   -- y position
  735.         menustring) -- content
  736.     if result == "Copy All To Clipboard" then
  737.         GetAllBufferedMessages()
  738.         ColourNote ("yellow", "", "All buffered messages copied to clipboard.")
  739.     elseif result == "Change Font" then
  740.         wanted_font = utils.fontpicker (BODY_FONT_NAME, BODY_FONT_SIZE) --font dialog
  741.         if wanted_font then
  742.             BODY_FONT_NAME = wanted_font.name
  743.             BODY_FONT_SIZE = wanted_font.size
  744.             SetVariable ("bodyfont", BODY_FONT_NAME)
  745.             SetVariable ("font_size", BODY_FONT_SIZE)
  746.             OnPluginInstall()
  747.         end
  748.     elseif result == "Turn Echo Off" then
  749.         echo = false
  750.         ColourNote ("yellow", "", "Echoing chats in main window DISABLED.")
  751.     elseif result == "Turn Echo On" then
  752.         echo = true
  753.         ColourNote ("yellow", "", "Echoing chats in main window ENABLED.")
  754.     elseif result == "No Timestamps" then
  755.         timestamp = false
  756.         ColourNote ("yellow", "", "Timestamps in communication window DISABLED.")
  757.     elseif result == "30 Aug 13:29:49" then
  758.         timestamp = true
  759.         date_format = "[%d %b %H:%M:%S] "
  760.         ColourNote ("yellow", "", "Timestamps in communication window ENABLED using format like '30 Aug 13:29:49'.")
  761.     elseif result == "30 Aug 01:20:12PM" then
  762.         timestamp = true
  763.         date_format = "[%d %b %I:%M:%S%p] "
  764.         ColourNote ("yellow", "", "Timestamps in communication window ENABLED using format like '30 Aug 01:20:12PM'.")
  765.     elseif result == "13:29:08" then
  766.         timestamp = true
  767.         date_format = "[%H:%M:%S] "
  768.         ColourNote ("yellow", "", "Timestamps in communication window ENABLED using format like '13:29:08'.")
  769.     elseif result == "1:22:06 PM" then
  770.         timestamp = true
  771.         date_format = "[%I:%M:%S%p] "
  772.         ColourNote ("yellow", "", "Timestamps in communication window ENABLED using format like '1:22:06 PM'.")
  773.     end -- if
  774. end -- function right_click_menu
  775. ]]>
  776. </script>
  777. </muclient>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement