Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ MUSHclient ➜ Miniwindows ➜ Setting Miniwindows to Scroll?

Setting Miniwindows to Scroll?

It is now over 60 days since the last post. This thread is closed.     Refresh page


Pages: 1 2  

Posted by Natasi   (79 posts)  Bio
Date Tue 14 Apr 2009 02:45 AM (UTC)
Message
Hi, I finally got a Channel Capture working, that grabs certain channels from the mud I play and displays them in a miniwindow. Right now I have it set so when it reaches 12 lines of text it resets and clears the window and starts over, but I would like to set it to instead scroll as more entries are input. Would anyone know how this can be achieved, to have a scrollbar on a miniwindow?

I can post code if needed, thanks for any help!
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #1 on Tue 14 Apr 2009 03:05 AM (UTC)
Message
I'm not sure about a scrollbar, but for the moment, as a stopgap measure, you could try this. Store each line in a table with table.insert(). When you reach 13 lines, table.remove() the oldest. It emulates a scrolling display, but it doesn't actually have a scrollbar.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Nick Gammon   Australia  (23,068 posts)  Bio   Forum Administrator
Date Reply #2 on Tue 14 Apr 2009 04:04 AM (UTC)
Message
Exactly. I did something similar in a plugin that shows trace information in a scrolling window:

http://www.gammon.com.au/forum/?id=9218

The function that does the displaying does exactly what Twisol said, it removes from a table if you have exceeded the maximum lines, and then adds the new line to the back.

It also uses WindowRectOp to clear the window prior to drawing or you would have text everywhere.

The relevant lines are here:



-- display one line
function Display_Line (line, text)

  local left = TEXT_INSET
  local top = (line - 1) * font_height
  
  WindowText (win, "f", text, left, top, WINDOW_WIDTH - TEXT_INSET, 0, WINDOW_TEXT_COLOUR)
  
end -- Display_Line


-- here on trace
function OnPluginTrace (line)

  -- blank existing window contents
  WindowRectOp (win, 2, 0, 0, 0, 0, WINDOW_BACKGROUND_COLOUR)
  
  -- remove first line if filled up
  if #lines >= max_lines then
    table.remove (lines, 1)
  end -- if 

  -- add new line, time-stamped
  table.insert (lines, os.date ("%H:%M:%S ") .. line)
  
  -- display all lines
  for k, v in ipairs (lines) do
    Display_Line (k, v)
  end -- for
  
  -- force window redisplay
  WindowShow (win,  true)  -- show it 
  
end -- end OnPluginTrace



- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Tboydston   (14 posts)  Bio
Date Reply #3 on Tue 14 Apr 2009 11:28 PM (UTC)
Message
Here comes my first, useful post!

I went ahead and wrote up a script that starts with a table of 15 strings, which represent the output from your MUD, and then it writes the first 10 of those lines to a white Miniwindow.

There are two invisible hotspots which are each 10 pixels x 100 pixels and on the far right side of the Miniwindow situated on top of each other. If you click the top one it'll scroll your text up (provided you're not on the first line) and down (provided you're not out of lines).

What you'll want to work on to suit your needs is changing out the table with MUD's output. I have no idea how many lines you can fit in that table without having any memory/speed issues, so you might want to use Twisol's suggestion and keep it around 100 lines or whatever.

Also! This works off of MouseUp, which means you have to remove your finger from the mouse. You can only get one scroll per click as a consequence. You can easily change:
function MouseUp(flags, hotspot_id)
	scrollbar(hotspot_id)
end

to not have anything in it, and move
scrollbar(hotspot_id)

to
the function MouseDown(). If you do that, you'll want to cancel the scrollbar stuff on CancelMouseDown or it'll keep going no matter where your mouse was after the click.

Here's what is between the script tags in the XML plugin:

text = {
	"1:  This is a line of text",
	"2:  This is a line of text",
	"3:  This is a line of text",
	"4:  This is a line of text",
	"5:  This is a line of text",
	"6:  This is a line of text",
	"7:  This is a line of text",
	"8:  This is a line of text",
	"9:  This is a line of text",
	"10: This is a line of text",
	"11: This is a line of text",
	"12: This is a line of text",
	"13: This is a line of text",
	"14: This is a line of text",
	"15: This is a line of text"
}

lineStart = 1
lineEnd = 10
SBWin = "ScrollbarWindow"..GetPluginID()

function OnPluginInstall()
	init()
end

function init()
	WindowCreate(SBWin, 2, 2, 200, 200, 4, 2, ColourNameToRGB("white"))
	WindowAddHotspot(SBWin, "upHotspot", 190, 0, 0, 100, "MouseOver", "CancelMouseOver", "MouseDown", "CancelMouseDown", "MouseUp", "Scroll up?", 1, 0)
	WindowAddHotspot(SBWin, "downHotspot", 190, 100, 0, 0, "MouseOver", "CancelMouseOver", "MouseDown", "CancelMouseDown", "MouseUp", "Scroll down?", 1, 0)
	WindowFont(SBWin, "font"..SBWin, "Trebuchet MS", 12, true, false, false, false)
	WindowShow(SBWin, true)
	writeLines()
end

function writeLines()
	spacing = 0
	for count = lineStart, lineEnd do
		WindowText(SBWin, "font"..SBWin, text[count], 5, spacing * 15, 0, 0, ColourNameToRGB("black"), false)
		spacing = spacing + 1
	end
end

function refresh()
	WindowRectOp(SBWin, 2, 0, 0, 0, 0, ColourNameToRGB("white"), ColourNameToRGB("white"))
	WindowShow(SBWin, true)

	writeLines()
end

function scrollbar(calledBy)
	if calledBy == "upHotspot" then
		if (lineStart > 1) then
			lineStart = lineStart - 1
			lineEnd = lineEnd - 1
		end
	elseif calledBy == "downHotspot" then
		if (lineEnd < #text) then
			lineStart = lineStart + 1
			lineEnd = lineEnd + 1
		end
	end
	refresh()
end

function MouseOver(flags, hotspot_id)
end

function CancelMouseOver(flags, hotspot_id)
end

function MouseDown(flags, hotspot_id)
end

function CancelMouseDown(flags, hotspot_id)
end

function MouseUp(flags, hotspot_id)
	scrollbar(hotspot_id)
end
Top

Posted by Tboydston   (14 posts)  Bio
Date Reply #4 on Tue 14 Apr 2009 11:51 PM (UTC)
Message
Sorry, I judged the mouse functions incorrectly. I'd recomment moving the scrollbar(hotspot_id) to MouseDown. It's an -on- MouseDown rather than a -while- MouseDown, so it still only moves the scrolling text one line.
Top

Posted by Natasi   (79 posts)  Bio
Date Reply #5 on Wed 15 Apr 2009 12:48 AM (UTC)
Message
Ahh, thanks everyone, this should get me to where I need to be!
Top

Posted by Natasi   (79 posts)  Bio
Date Reply #6 on Wed 15 Apr 2009 02:42 AM (UTC)
Message
Ok, going a bit insane trying to figure this out. I'm not a Lua person and this is the first thing I've done with it, building off multiple scripts Nick and others have posted up here.

Below I have posted the code, triggers and the script, and if anyone would be kind enough to explain how to integrate this into Tboydston's suggestion or even the Tables as Nick suggested I would greatly appreciate it.

Here goes:

<triggers>
<trigger
enabled="y"
keep_evaluating="y"
match="^\((.*?)\)\:\s(.*?)$"
script=""
send_to="14"
regexp="y"
>
<send>
world.Execute ("channelText (%1): %2")
</send>
</trigger>
</triggers>

<!-- Aliases -->


<aliases>
<alias
script="channelText"
match="channelText *"
enabled="y"
sequence="100"
>
</alias>

<alias
script="reset_window"
match="resetw"
enabled="y"
sequence="100"
>
</alias>
<alias
script="start_window"
match="startw"
enabled="y"
sequence="100"
>
</alias>
<alias
script="stop_window"
match="stopw"
enabled="y"
sequence="100"
>
</alias>
</aliases>

<!-- Script -->


<script>
<![CDATA[
-- test text

-- window and font info

win = GetPluginID ()
local width = 870
local height = 200
local font = "f2"

-- make window

WindowCreate (win, 0, 0, width, height, 4, 0, ColourNameToRGB("black"))

-- show border so we can see what we are doing

WindowRectOp (win, 1, 1, 1, -1, -1, ColourNameToRGB("#553333"))

-- set up our font

WindowFont (win, font, "Arial", 9)

-- how far in to draw

local left_margin = 5
local right_margin = 5

-- derive stuff from font

local space_width = WindowTextWidth (win, font, " ")
local line_height = WindowFontInfo (win, font, 1)

-- starting point

local x = left_margin
local y = 0


local counter = 0
-- do each word
function channelText (name, line, wildcards)

if counter > 11 then
WindowCreate (win, 0, 0, width, height, 4, 0, ColourNameToRGB("black"))
WindowRectOp (win, 1, 1, 1, -1, -1, ColourNameToRGB("#553333"))
y = 0
x = 0
WindowShow (win, true)
counter = 0
end

message = wildcards [1]
y = y + line_height
x = left_margin
counter = counter + 1
for word in string.gmatch (message, "%S+") do

local word_width = WindowTextWidth (win, font, word)

-- time to start a new line?

if (word_width + x) > (width - right_margin) and (x > left_margin) then
y = y + line_height
x = left_margin
counter = counter + 1
end -- if

-- draw the text

WindowText (win, font, word, x, y, 0, 0, ColourNameToRGB("white"))

-- advance past the word and a single space

x = x + word_width + space_width

end -- for loop
end

WindowShow (win, true)

function reset_window (name, line, wildcards)
WindowCreate (win, 0, 0, width, height, 4, 0, ColourNameToRGB("black"))
WindowRectOp (win, 1, 1, 1, -1, -1, ColourNameToRGB("#553333"))
y = 0
x = 0
counter = 0
WindowShow (win, true)
end
function start_window (name, line, wildcards)
WindowShow (win, true)
end
function stop_window (name, line, wildcards)
WindowShow (win, false)
end

]]>
</script>
Top

Posted by Tboydston   (14 posts)  Bio
Date Reply #7 on Wed 15 Apr 2009 07:07 AM (UTC)
Message
This is in your channelText function:
-- draw the text
WindowText (win, font, word, x, y, 0, 0, ColourNameToRGB("white"))


You're instantly drawing the text after you receive it in the function that waits for text. Instead of drawing the text, insert it into a table.
table.insert(tableForYourMessages, lineToInsert)

Every time you add to the table go ahead and refresh your window.

You can do this with a separate function that will write all the visible lines of text by running through an appropriate point in the table of text. I made the variables lineStart and lineEnd to keep track of my location. You'll want to draw the background over the table (I just draw a white rectangle over the entire thing) before you write the text or all of your lines will get jumbled up.

I think you'd be able to copy+paste my code directly into your plugin and use it immediately. All you'd really need to add is a way to modify the table text (which I suggested earlier). It'd make more sense to write text = {} instead of how I did it for the example. Of course, if you do that you're going to want to change out the miniwindow information to suit your own needs.

Good luck!
Top

Posted by Natasi   (79 posts)  Bio
Date Reply #8 on Wed 15 Apr 2009 11:51 AM (UTC)
Message
I was able to copy/paste yours in, but whenever it refreshed, it overwrote, but I wasn't able to get the tables to work correctly and thus it as just a blank miniwindow and nothing wrote to it anymore.
Top

Posted by Tboydston   (14 posts)  Bio
Date Reply #9 on Wed 15 Apr 2009 06:51 PM (UTC)

Amended on Sun 30 Aug 2009 09:46 AM (UTC) by Nick Gammon

Message
Why don't you paste the full script now that you're trying to implement the scroll?

It sounds like you might be drawing the white rectangle at the wrong time, so it'd help to see where exactly things are going wrong.

Also, if you put the script inside a pair of [code][/code] tags it'll preserve indentation. Just click the "Check this if you want to use 'forum codes'" button.
Top

Posted by Tboydston   (14 posts)  Bio
Date Reply #10 on Wed 15 Apr 2009 06:52 PM (UTC)
Message
Erm, sorry, I tried typing the forum code tags without thinking they'd be evaulated. It's just code and /code inside of square brackets.
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #11 on Wed 15 Apr 2009 10:20 PM (UTC)
Message
[code] <code goes here> [\code].

Tboydston: Add a backslash before the brackets to make it appear literal. Also don't forget that there's an Edit button to the right of the date. ;)

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Natasi   (79 posts)  Bio
Date Reply #12 on Thu 16 Apr 2009 01:57 AM (UTC)
Message
Here is the full plugin:


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>

<!-- MuClient version 4.37 -->

<muclient>
<plugin
   name="ChannelText"
   author="Nick Gammon"
   id="4de91eaa2624f202c4bb6835"
   language="Lua"
   purpose="Shows message"
   date_written="2009-02-08 14:00"
   requires="4.37"
   version="1.0"
   >

</plugin>

<triggers>
  <trigger
   enabled="y"
   keep_evaluating="y"
   match="^\((.*?)\)\:\s(.*?)$"
   script=""
   send_to="14"
   regexp="y"
  >
  <send>
  	world.Execute ("channelText (%1): %2")
  </send>
  </trigger>
</triggers>

<!--  Aliases  -->


<aliases>
  <alias
   script="channelText"
   match="channelText *"
   enabled="y"
   sequence="100"
  >
  </alias>
  
  <alias
   script="reset_window"
   match="resetw"
   enabled="y"
   sequence="100"
  >
  </alias>
  <alias
   script="start_window"
   match="startw"
   enabled="y"
   sequence="100"
  >
  </alias>
   <alias
   script="stop_window"
   match="stopw"
   enabled="y"
   sequence="100"
  >
  </alias>
</aliases>

<!--  Script  -->


<script>
<![CDATA[
-- test text

-- window and font info

win = GetPluginID ()
local width = 870
local height = 200
local font = "f2"

-- make window

WindowCreate (win, 0, 0, width, height, 4, 0, ColourNameToRGB("black"))

-- show border so we can see what we are doing

WindowRectOp (win, 1, 1, 1, -1, -1, ColourNameToRGB("#553333")) 

-- set up our font

WindowFont (win, font, "Arial", 9)

-- how far in to draw

local left_margin = 5
local right_margin = 5

-- derive stuff from font

local space_width = WindowTextWidth (win, font, " ")
local line_height = WindowFontInfo (win, font, 1)

-- starting point

local x = left_margin 
local y = 0


local counter = 0
-- do each word
function channelText (name, line, wildcards)

	if counter > 11 then
		WindowCreate (win, 0, 0, width, height, 4, 0, ColourNameToRGB("black"))
		WindowRectOp (win, 1, 1, 1, -1, -1, ColourNameToRGB("#553333")) 
		y = 0
		x = 0
		WindowShow (win, true)
		counter = 0
	end

  message = wildcards [1]
   y = y + line_height
   x = left_margin
   counter = counter + 1
for word in string.gmatch (message, "%S+") do

  local word_width = WindowTextWidth (win, font, word)

  -- time to start a new line?

  if (word_width + x) > (width - right_margin) and (x > left_margin) then
    y = y + line_height
    x = left_margin
    counter = counter + 1
  end -- if

  -- draw the text

  WindowText (win, font, word, x, y, 0, 0, ColourNameToRGB("white"))
  
  -- advance past the word and a single space
  
  x = x + word_width + space_width 

end -- for loop
end

WindowShow (win, true)

function reset_window (name, line, wildcards)
	WindowCreate (win, 0, 0, width, height, 4, 0, ColourNameToRGB("black"))
	WindowRectOp (win, 1, 1, 1, -1, -1, ColourNameToRGB("#553333")) 
	y = 0
	x = 0
	counter = 0
	WindowShow (win, true)
end
function start_window (name, line, wildcards)
	WindowShow (win, true)
end
function stop_window (name, line, wildcards)
	WindowShow (win, false)
end

]]>
</script>

</muclient>

Top

Posted by Natasi   (79 posts)  Bio
Date Reply #13 on Sun 19 Apr 2009 12:06 AM (UTC)
Message
Thanks for all the help, was finally able to piece it all together this morning!

Though, are you able to put multiple miniwindows into one plugin or should they all be seperate?
Top

Posted by Worstje   Netherlands  (899 posts)  Bio
Date Reply #14 on Sun 19 Apr 2009 03:24 AM (UTC)
Message
You can put multiple miniwindows in a single plugin. The names used to identify need to differ (and be unique for the entire world - e.g. if PluginA uses the miniwindow 'test', and PluginB uses the miniwindow 'test', then they will clash and operate on the same miniwindow).
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


78,459 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.