Quantcast
Download
(3 Kb)
Download
Updated: 12/29/14 06:24 AM
Pictures
File Info
Compatibility:
Update 7 (1.7.0)
Updated:12/29/14 06:24 AM
Created:10/31/14 02:56 PM
Monthly downloads:49
Total downloads:1,252
Favorites:7
MD5:
LibMsgWin
Version: 1.0_R8
by: sirinsidiator [More]
What does it do?
Allows the easy creation/use of a simple message window that mimics the look of the regular chat window, is scrollable, handles link clicks, and slaps an easy access AddText(..), ChangeFade(..), & ClearText() function on it. It also has a label at the top you can assign a value to if you wish to label your window. The fade is only for the text, the background does not fade, but still useful if you want to hide the background & set the text to fade out.

I wrote this just to use for debugging messages & other random things and thought someone else might be interested in having a message window they can add messages to...that they don't have to write themselves...so here it is.

Function...yeah there is only one
Lua Code:
  1. -- Requires a unique control name for your chat window
  2. -- (optional) Text for the heading label - if left nil the label control will not be created
  3. -- (optional) FadeDelay & FadeTime - if left nil text will not fade
  4. -- Returns a TopLevelControl (which contains your chat window)
  5. libmw:CreateMsgWindow(string UniqueName, string LabelText, integer FadeDelay, integer FadeTime)

For ease of use, the TopLevelControl returned by libmw:CreateMsgWindow(...) has the following functions:
Lua Code:
  1. -- Add a message to your chat window, with colors:
  2. myMsgWindow:AddText("Heres a chat message", Red, Green, Blue)
  3.  
  4. -- Change the text fadeDelay & fadeDuration:
  5. myMsgWindow:ChangeTextFade(integer FadeDelay, integer FadeDuration)
  6.  
  7. -- Change the window fadeDelay & fadeDuration:
  8. myMsgWindow:ChangeWinFade(_FadeDelay, _FadeTime)
  9.  
  10. -- Clear all of the text from the textBuffer (clears the text in the window)
  11. myMsgWindow:ClearText()


Instructions
Install the LibMsgWin-1.0 folder & LibStub folder in your libs folder (or wherever) & add a reference to it in your addon.txt file:
Lua Code:
  1. -- <Your Addon> --> <libs> --> <LibMsgWin-1.0>
  2. -- <Your Addon> --> <libs> --> <LibStub>
  3. -- Add a reference to the LibStub.lua file
  4. libs\LibStub\LibStub.lua
  5. -- and
  6. -- Add a reference to the LibMsgWin-1.0.lua file
  7. libs\LibMsgWin-1.0\LibMsgWin-1.0.lua

Add this line to the top of every code file you want to use it in:
Lua Code:
  1. local LIBMW = LibStub:GetLibrary("LibMsgWin-1.0")
Start using it.

Examples of Use:
Lua Code:
  1. -- Don't forget to grab the library at the top of every code file your trying to use this in:    
  2. local LIBMW = LibStub:GetLibrary("LibMsgWin-1.0")
  3.  
  4. -- After a 25 second delay the text will start to fade.
  5. -- Once it starts fading it will take 4 seconds to completely fade
  6. local myMsgWindow = LIBMW:CreateMsgWindow("UberAddonChatWindow", "Window Header Label", 25, 4)
  7.  
  8. -- To prevent the text from fading Use 0, 0 for the fade delay & duration
  9. local myMsgWindow = LIBMW:CreateMsgWindow("UberAddonChatWindow", "Window Header Label", 0, 0)
  10.  
  11. -- Or just leave them nil
  12. local myMsgWindow = LIBMW:CreateMsgWindow("UberAddonChatWindow", "Window Header Label")
  13.  
  14. -- Then call one of the controls built in functions:
  15. myMsgWindow:AddText("Heres a chat message in red", 1, 0, 0)
  16. myMsgWindow:ChangeTextFade(0, 0)
  17. myMsgWindow:ChangeWinFade(2000, 3000)
  18. myMsgWindow:ClearText()
Version 1.0_R8 -- Requested Feature

Window Fade Added the ability to fade the window. It defaults to the same FadeDelay & FadeTime you were passing in for the text fade (so their the same) and will also default to 0 (no fade) if no values are passed in. But if you want them to have different fadeDelay/fadeTime's you can change it by using:
Lua Code:
  1. function tlw:ChangeWinFade(_FadeDelay, _FadeTime)
Accessible from the control returned to you when you create the window. All times are in milliseconds.

Text Fade Change Due to the addition of the window fading option/function I thought it would be best to clarify the function used to change the text fade so I changed its name, it is now called:
Lua Code:
  1. function tlw:ChangeTextFade(_FadeDelay, _FadeTime)
All times are in milliseconds.

Fade In Not an animation, but the window & text will both automatically reset to an alpha value of 1:
When text is added to the window using
Lua Code:
  1. function tlw:AddText(_Message, _Red, _Green, _Blue)
or OnMouseEnter for the text buffer control (the window)

The window & text will both begin their fadeDelay then fadeTime as soon as the text has been entered or OnMouseExit of the text buffer control (window).

Time Storage In case you need to access the fadeDelay/fadeTime for the window or text I stored it in the control that is returned to you when you create the window for easy access:
Lua Code:
  1. local myDebugWin = LIBMW:CreateMsgWindow("JunkItDebugWindow", "JunkIt Debug Window", 4000, 3000)
  2. --[[ So they are stored here:
  3.    myDebugWin.fadeDelayWindow
  4.    myDebugWin.fadeTimeWindow
  5.  
  6.    myDebugWin.fadeDelayTextLines
  7.    myDebugWin.fadeTimeTextLines
  8. --]]
Version 1.0_R7 -- Oops

A Default Color Would Be Nice: I forgot to set a default color if one was not passed in, caught it as soon as I uploaded R6.
Version 1.0_R6 -- Requested Change

Code Change: Small code change for how the slider starts to move when the buffer is full & text is added to the window. Changed it from a hard coded 200 (the default number of MaxHistoryLines) to grabbing the current maxHistoryLines which will allow users to change the default number of MaxHistoryLines if they wish.
Lua Code:
  1. -- changed this:
  2.     elseif numHistoryLines == 200 then
  3. -- to this:
  4.     elseif numHistoryLines == self:GetNamedChild("Buffer"):GetMaxHistoryLines() then
Version 1.0_R5 -- Requested Feature

Text In Color: Added parameters to the AddText function to allow you to pass through colors for the text:
Lua Code:
  1. function tlw:AddText(Message, Red, Green, Blue)

Version 1.0_R4 --
Reverse Scroll: Apparently the window scrolled in the wrong direction. It scrolled the opposite direction of the original chat window. It has been fixed.
Scroll Visiblity: Fixed the slider so it now only becomes visible when there are enough lines of text to scroll off of the screen.
Known Issue: If you resize the window and there becomes enough space for all lines of text the slider does not hide itself until the user scrolls the window or another line of text is added to the window (instead of hiding itself immediately upon resizing). I can not get the OnResizeStop handler to work, will fix as soon as I figure it out, or find a way around using OnResizeStop.
Version 1.0_R3 --
Window Heading Label: I Added a label control to the window that can be used to add text to the top of the window.
WARNING: Due to adding the window heading label I needed to add an extra parameter to the function. It is the second parameter and the fade parameters are now third & fourth.
Lua Code:
  1. libmw:CreateMsgWindow(_UniqueName, _LabelText, _FadeDelay, _FadeTime)


Version 1.0_R2B --
Added LibStub: I forgot to include LibStub in the previous update zip file. It is now included, no other changes.
Version 1.0_R2 --
cntrl:ClearText(): Added an easily accessible ClearText() function to clear the text from the buffer, so you don't have to mess with getting the buffer control. You can just call it on the main control returned by CreateMsgWindow(..), Yeah I'm that lazy.
Archived Files (7)
File Name
Version
Size
Author
Date
1.0_R7
4kB
circonian
11/23/14 08:14 PM
1.0_R6
4kB
circonian
11/23/14 08:05 PM
1.0_R4
4kB
circonian
11/22/14 11:40 PM
1.0_R3
3kB
circonian
11/22/14 12:36 AM
1.0_R2B
3kB
circonian
11/03/14 10:30 PM
1.0_R2
2kB
circonian
11/03/14 07:18 AM
1.0_R1
2kB
circonian
10/31/14 02:56 PM


Post A Reply Comment Options
Unread 07/31/15, 12:29 PM  
merlight
AddOn Author - Click to view AddOns

Forum posts: 645
File comments: 208
Uploads: 12
As per request
## ReverseDependsOn: merUndefinedGlobalsCatcher
Report comment to moderator  
Reply With Quote
Unread 03/28/15, 11:50 PM  
circonian
AddOn Author - Click to view AddOns

Forum posts: 648
File comments: 804
Uploads: 27
Re: Hello

Originally Posted by awesomebilly
You've done a great job with this addon.
I'm looking to replace Unicorn & List in a few of my addons. Would you mind if I follow your code as an example?

I need to re-write a few pieces to fit my needs.. but I wanted to check if it's ok with you?

Thanks,
AB
Thats fine, if you have any questions about it just let me know.
__________________
My Addons: JunkIt, FilterIt, WaypointIt, LootIt, TweakIt, ChatIt, SortIt
My Libs & Other Developer Stuff: Click4Info, LibNeed4Research, LibMsgWin, LibFilterIt, LibItemInfo
Other Files & Works In Progress can be found on my Dropbox: ESO Dropbox
Report comment to moderator  
Reply With Quote
Unread 03/28/15, 10:04 PM  
awesomebilly
AddOn Author - Click to view AddOns

Forum posts: 24
File comments: 231
Uploads: 8
Hello

You've done a great job with this addon.

I'm looking to replace Unicorn & List in a few of my addons. Would you mind if I follow your code as an example?

I need to re-write a few pieces to fit my needs.. but I wanted to check if it's ok with you?


Thanks,
AB
Report comment to moderator  
Reply With Quote
Unread 11/26/14, 08:11 AM  
merlight
AddOn Author - Click to view AddOns

Forum posts: 645
File comments: 208
Uploads: 12
Originally Posted by circonian
ColorId 5th Parameter? I thought that was for a category (like guild, yell, tell, exc...) for the main chat window. Is it different for a user created buffer or am I looking at the wrong thing in the eso files?
Lua Code:
  1. window.buffer:AddMessage(message, r, g, b, category)
The buffer doesn't know anything about chat system, it's the other way round - chat system uses chat category as the colorId.

h3. TextBufferControl
* SetColorById(*integer* _colorId_, *number* _r_, *number* _g_, *number* _b_)

When you change chat category color in game settings, two things happen:
- CHAT_SYSTEM:SetChannelCategoryColor calls SetColorById on each buffer to change the color of existing messages
- SetChatCategoryColor sets the color for future messages (r, g, b passed to AddMessage)
Report comment to moderator  
Reply With Quote
Unread 11/23/14, 08:28 PM  
circonian
AddOn Author - Click to view AddOns

Forum posts: 648
File comments: 804
Uploads: 27
Out of Town

I am signing off & will be out of town for about a week for thanksgiving. I will try to check in when I can to see if there are any problems or questions.
Report comment to moderator  
Reply With Quote
Unread 11/23/14, 08:19 PM  
circonian
AddOn Author - Click to view AddOns

Forum posts: 648
File comments: 804
Uploads: 27
Originally Posted by merlight
Originally Posted by circonian
Well are you really wanting to set a "default" color for all text? or are you wanting to change the color of "A LINE OF TEXT" when you add it with AddText()
Because if you want a "default" color for all text it would be better off going somewhere else. I could add some kind of SetColor() to the tlw like I did with the AddText.
Different color for each line. I'm adding different types of messages - note/warning/error - so the color goes with each line. Then there's the fifth parameter to AddMessage, colorId, which is useful if you want to change the color of previously added lines. The again, it's just for private debugging, no big deal

I suggested varargs because it's short and generic, and might even be faster (if I'm not mistaken, "..." is one push on stack while "r, g, b, ..." are four).
Ahh, well I just uploaded it with: r, g, b.
ColorId 5th Parameter? I thought that was for a category (like guild, yell, tell, exc...) for the main chat window. Is it different for a user created buffer or am I looking at the wrong thing in the eso files?
Lua Code:
  1. window.buffer:AddMessage(message, r, g, b, category)
Report comment to moderator  
Reply With Quote
Unread 11/23/14, 08:11 PM  
merlight
AddOn Author - Click to view AddOns

Forum posts: 645
File comments: 208
Uploads: 12
Originally Posted by circonian
Well are you really wanting to set a "default" color for all text? or are you wanting to change the color of "A LINE OF TEXT" when you add it with AddText()
Because if you want a "default" color for all text it would be better off going somewhere else. I could add some kind of SetColor() to the tlw like I did with the AddText.
Different color for each line. I'm adding different types of messages - note/warning/error - so the color goes with each line. Then there's the fifth parameter to AddMessage, colorId, which is useful if you want to change the color of previously added lines. The again, it's just for private debugging, no big deal

I suggested varargs because it's short and generic, and might even be faster (if I'm not mistaken, "..." is one push on stack while "r, g, b, ..." are four).
Report comment to moderator  
Reply With Quote
Unread 11/23/14, 07:42 PM  
circonian
AddOn Author - Click to view AddOns

Forum posts: 648
File comments: 804
Uploads: 27
Originally Posted by merlight
* Can you please add tail args to AddText, and pass them down to AddMessage? I'd like to set the default text color (without markup)
Lua Code:
  1. function tlw:AddText(_Message, ...)
  2. ...
  3.         self.buffer:AddMessage(_Message, ...)
  4. ...

Are you just wanting arguments for: r,g,b?
Lua Code:
  1. function tlw:AddText(_Message, r, g, b)
Thats a good idea I will go ahead and add that, and if you need more changes (the question below) let me know.

Are you also literally wanting variable arguments for some reason?
Lua Code:
  1. function tlw:AddText(_Message, r, g, b, ...)

P.S. I'm leaving soon for a week, but will keep an eye on posts when I can. I went ahead and added the color parameters so you could have it to use now. If you have any other code suggestions or feature change requests just let me know & I'll get to it when I can or when I get back in a week.


Oh and since you like helping
Your a bit more knowledgeable than me you got any ideas about this known problem:
The only thing that I know that does not work is that if you resize the window to make room for all of the lines of text the scroll bar does not dissappear. I was trying to check whether or not the scroll bar should be visible as a user resizes the window like the real chat window does, but I could not get the "OnResizeStop" to work for some reason...see here: OnReszieStop Post
Any ideas? I don't doubt Garkins knowledge, but I'de really hate to have to rewrite it all to XML just to get it to work.
Last edited by circonian : 11/23/14 at 07:56 PM.
Report comment to moderator  
Reply With Quote
Unread 11/23/14, 02:53 PM  
circonian
AddOn Author - Click to view AddOns

Forum posts: 648
File comments: 804
Uploads: 27
Originally Posted by Khrill
Thanks for this!
Very useful
I'm using it in some of my addons
Nice to know, glad someone found it useful.
Report comment to moderator  
Reply With Quote
Unread 11/23/14, 02:37 PM  
circonian
AddOn Author - Click to view AddOns

Forum posts: 648
File comments: 804
Uploads: 27
Originally Posted by merlight
* You can store children as members in the window control, so you don't have to call GetNamedChild all the time:
Lua Code:
  1. tlw.buffer = tlw:CreateControl("$(parent)Buffer", CT_TEXTBUFFER)
... and so on.
Ah yeah good idea. At the time I just wanted something for debug messages & was just concerned with getting it to work :P


Originally Posted by merlight
* Can you please add tail args to AddText, and pass them down to AddMessage? I'd like to set the default text color (without markup)
Lua Code:
  1. function tlw:AddText(_Message, ...)
  2. ...
  3.         self.buffer:AddMessage(_Message, ...)
  4. ...
Well are you really wanting to set a "default" color for all text? or are you wanting to change the color of "A LINE OF TEXT" when you add it with AddText()
Because if you want a "default" color for all text it would be better off going somewhere else. I could add some kind of SetColor() to the tlw like I did with the AddText.
Report comment to moderator  
Reply With Quote
Unread 11/23/14, 09:41 AM  
Khrill
 
Khrill's Avatar
AddOn Author - Click to view AddOns

Forum posts: 0
File comments: 137
Uploads: 15
Thanks for this!
Very useful
I'm using it in some of my addons
Report comment to moderator  
Reply With Quote
Unread 11/23/14, 07:56 AM  
merlight
AddOn Author - Click to view AddOns

Forum posts: 645
File comments: 208
Uploads: 12
Thanks. In the 3rd point I meant the mouse wheel and slider were connected - both scrolling the text in the wrong direction - I turn the wheel "down", slider moved down, and text moved down, while I expected the text to move up Scrolling works ok now (edit: again my stupid with the slider, sry)

* You can store children as members in the window control, so you don't have to call GetNamedChild all the time:
Lua Code:
  1. tlw.buffer = tlw:CreateControl("$(parent)Buffer", CT_TEXTBUFFER)
... and so on.

* In local function AdjustSlider(self):
Lua Code:
  1. elseif numHistoryLines == self.buffer:GetMaxHistoryLines() then -- instead of fixed 200

* Can you please add tail args to AddText, and pass them down to AddMessage? I'd like to set the default text color (without markup)
Lua Code:
  1. function tlw:AddText(_Message, ...)
  2. ...
  3.         self.buffer:AddMessage(_Message, ...)
  4. ...
Last edited by merlight : 11/23/14 at 08:01 AM.
Report comment to moderator  
Reply With Quote
Unread 11/22/14, 11:42 PM  
circonian
AddOn Author - Click to view AddOns

Forum posts: 648
File comments: 804
Uploads: 27
Scroll Direction

I fixed it.
Report comment to moderator  
Reply With Quote
Unread 11/22/14, 05:40 PM  
circonian
AddOn Author - Click to view AddOns

Forum posts: 648
File comments: 804
Uploads: 27
Originally Posted by merlight
Finally got to try this out, and found a few issues:
1) mouse wheel scrolls in the opposite direction
2) one-line up/down buttons on the side work ok, but the scroll-to-bottom actually scrolls to top, so that only the first line is visible
edit: 3) was my stupidity, I added text to the buffer directly with AddMessage, not via AddText. The slider shows silly mouse cursors, but that's minor, it moves. But it's reversed just like mouse wheel.
1 & 2) I actually thought it was going in the right direction. But yeah, I see it now, the slider moves in the correct direction when scrolled and the text goes in the same direction, but the text is actually supposed to go in the opposite direction of the slider. I didn't notice that.

Originally Posted by merlight
Finally got to try this out, and found a few issues:
edit: 3) was my stupidity, I added text to the buffer directly with AddMessage, not via AddText. The slider shows silly mouse cursors, but that's minor, it moves. But it's reversed just like mouse wheel.
Oh yeah that silly mouse cursor is from the SetResizeHandleSize..Ha I dont know why I put that on the slider.

Originally Posted by merlight
Finally got to try this out, and found a few issues:
edit: 3) was my stupidity, I added text to the buffer directly with AddMessage, not via AddText. The slider shows silly mouse cursors, but that's minor, it moves. But it's reversed just like mouse wheel.
Am I missing something. I don't see anything wrong with the sliders OnMouseWheel. When you scroll up the slider bar moves up, when you scroll down the slider bar moves down. Its supposed to go those directions?
Report comment to moderator  
Reply With Quote
Unread 11/22/14, 03:26 PM  
merlight
AddOn Author - Click to view AddOns

Forum posts: 645
File comments: 208
Uploads: 12
Finally got to try this out, and found a few issues:
1) mouse wheel scrolls in the opposite direction
2) one-line up/down buttons on the side work ok, but the scroll-to-bottom actually scrolls to top, so that only the first line is visible
edit: 3) was my stupidity, I added text to the buffer directly with AddMessage, not via AddText. The slider shows silly mouse cursors, but that's minor, it moves. But it's reversed just like mouse wheel.
Last edited by merlight : 11/22/14 at 03:42 PM.
Report comment to moderator  
Reply With Quote
Post A Reply



Category Jump: