Guages: a collection of styled "progress bars"

Share your scripts and packages with other Mudlet users.
Post Reply
User avatar
Greg
Posts: 3
Joined: Mon Jun 24, 2013 3:00 am

Guages: a collection of styled "progress bars"

Post by Greg »

Barbox is a collection of stylesheets for creating gradient "progress bars" that can be used in gauges. These are not functional gauges. This is merely a display rack to show off some bars that can be included in your own gauge constructor.

Here is some information from my experiments to create progress bars and the gradients and texts to fill them. There are many tools to help find codes for the chosen colors. One that I used was at color-hex. There are also online, Photoshop style, gradient editors that allow one to experiment with gradients and generate blocks of stylesheet information that can be edited to become QT stylesheets. One that I used was located at colorzilla. I specified information for the QT stylesheet gradients in both hexadecimal and rgba formats. It should be noted that there is a whitespace bug in the QT parsing routines. This has nothing to do with Mudlet. It occurs anywhere QT is used. Rgba color specifications suffer from this bug; while, hexadecimal color specifications do not. Thus, when using rgba, this code snippet works: “QLinearGradient(x1: 0, y1: 0, ....” While, this code snippet does not: “QLinearGradient( x1: 0, y1: 0, ....” (Note the space between the parenthesis and the x.) Once I had control of the whitespace bug, I was able to use rgba color specifications and control the opacity of my colors. Unfortunately, gumdrop style gradient bars and buttons required control of more than just the opacity. One must also control the shape of the reflections, and this was not possible with QT stylesheet gradients alone. Using x1 and y1, x2 and y2 one can turn the gradients 90° or flip them clear over. Last, I created some gradients that require three layers so as to give the illusion of liquid in glass.

Control of the textual element is available at different levels. Some levels supersede others making it difficult to see any results. I found that one could set the color and size of the text when one constructed the bar. I found that one could set some style elements like font-weight, font-family, bold and italics using the stylesheet, but these were not really as effective as other methods. Last, I found the most effective way to set text properties was to use XML font tags right at the point where one specified what text should be printed on the bar. Unfortunately, both QT stylesheet and XML font setting documentations seem to have features that have no effect. One thing I was unable to do was to set the text color of the back bar separately from the front bar. (For me, setting “color” in the style sheet had no effect on the text.) Since I am very green at this, perhaps there is a way, but I did not find it.

Below is an image (png) of the bars created by bar box. I would recommend creating a temporary profile and moving Mudlet's main window over 410 pixels. Then, you can look at and play with the bars, and extract the stylesheets and other information that create the bars for in your own constructions. I used several visual "tricks" that may be of interest to some, like liquid in glass tubes, no back bar, vertical bars. I've attached the script as a text file.
barbox.png
barbox.png (91.88 KiB) Viewed 7933 times
Attachments
BarBox.lua
A text file of Lua for Mudlet
(32.82 KiB) Downloaded 610 times

Jor'Mox
Posts: 1146
Joined: Wed Apr 03, 2013 2:19 am

Re: Guages: a collection of styled "progress bars"

Post by Jor'Mox »

I made an update to the built in gauges that should be included in the next release that, among other things, allows for vertical gauges, as well as gauges that fill backward (from right to left, or top to bottom). Also, I added a third top layer in which the text for the gauge is displayed, so as to avoid the strange text issues that were showing up in the previous version. If you are interested in using the newer gauges now, here is the script:
Code: [show] | [select all] lua
-- New Guage Script
-- 6/17/2013
-- 

function createGauge(gaugeName, width, height, x, y, gaugeText, r, g, b, orientation)
	gaugeText = gaugeText or ""
	if type(r) == "string" then
		orientation = g
		r,g,b = getRGB(r)
	elseif r == nil then
		orientation = g
		-- default colors
		r,g,b = 128,128,128
	end
	orientation = orientation or "horizontal"
	assert(table.contains({"horizontal","vertical","goofy","batty"},orientation), "createGauge: orientation must be horizontal, vertical, goofy, or batty")
	local tbl = {width = width, height = height, x = x, y = y, text = gaugeText, r = r, g = g, b = b, orientation = orientation, value = 1}
	createLabel(gaugeName .. "_back", 0,0,0,0,1)
	setBackgroundColor(gaugeName .. "_back", r, g, b, 100)
	
	createLabel(gaugeName .. "_front", 0,0,0,0,1)
	setBackgroundColor(gaugeName .. "_front", r, g, b, 255)
	
	createLabel(gaugeName .. "_text", 0,0,0,0,1)
	setBackgroundColor(gaugeName .. "_text", 0, 0, 0, 0)
	
	-- save new values in table
	gaugesTable[gaugeName] = tbl
	resizeGauge(gaugeName, tbl.width, tbl.height)
	moveGauge(gaugeName, tbl.x, tbl.y)
	setGaugeText(gaugeName, gaugeText, "black")
	showGauge(gaugeName)
end

function hideGauge(gaugeName)
	assert(gaugesTable[gaugeName], "hideGauge: no such gauge exists.")
	hideWindow(gaugeName .. "_back")
	hideWindow(gaugeName .. "_front")
	hideWindow(gaugeName .. "_text")
end

function showGauge(gaugeName)
	assert(gaugesTable[gaugeName], "showGauge: no such gauge exists.")
	showWindow(gaugeName .. "_back")
	showWindow(gaugeName .. "_front")
	showWindow(gaugeName .. "_text")
end

function resizeGauge(gaugeName, width, height)
	assert(gaugesTable[gaugeName], "resizeGauge: no such gauge exists.")
	assert(width and height, "resizeGauge: need to have both width and height.")
	resizeWindow(gaugeName .. "_back", width, height)
	resizeWindow(gaugeName .. "_text", width, height)
	-- save new values in table
	gaugesTable[gaugeName].width, gaugesTable[gaugeName].height = width, height
	setGauge(gaugeName, gaugesTable[gaugeName].value, 1)
end

function moveGauge(gaugeName, x, y)
	assert(gaugesTable[gaugeName], "moveGauge: no such gauge exists.")
	assert(x and y, "moveGauge: need to have both X and Y dimensions.")
	moveWindow(gaugeName .. "_back", x, y)
	moveWindow(gaugeName .. "_text", x, y)
	-- save new values in table
	gaugesTable[gaugeName].x, gaugesTable[gaugeName].y = x, y
	setGauge(gaugeName, gaugesTable[gaugeName].value, 1)
end

function setGaugeStyleSheet(gaugeName, css, cssback, csstext)
	if not setLabelStyleSheet then return end -- mudlet 1.0.5 and lower compatibility
	assert(gaugesTable[gaugeName], "setGaugeStyleSheet: no such gauge exists.")
	setLabelStyleSheet(gaugeName .. "_back", cssback or css)
	setLabelStyleSheet(gaugeName .. "_front", css)
	setLabelStyleSheet(gaugeName .. "_text", csstext or "")
end

function setGaugeText(gaugeName, gaugeText, r, g, b)
	assert(gaugesTable[gaugeName], "setGaugeText: no such gauge exists.")
	if r ~= nil then
		if g == nil then
			r,g,b = getRGB(r)
		end
	else
		r,g,b = 0,0,0
	end
	gaugeText = gaugeText or ""
	local echoString = [[<font color="#]] .. RGB2Hex(r,g,b) .. [[">]] .. gaugeText .. [[</font>]]
	echo(gaugeName .. "_text", echoString)
	-- save new values in table
	gaugesTable[gaugeName].text = echoString
end

function setGauge(gaugeName, currentValue, maxValue, gaugeText)
	assert(gaugesTable[gaugeName], "setGauge: no such gauge exists.")
	assert(currentValue and maxValue, "setGauge: need to have both current and max values.")
	local value = currentValue / maxValue
	-- save new values in table
	gaugesTable[gaugeName].value = value
	local info = gaugesTable[gaugeName]
	local x,y,w,h = info.x, info.y, info.width, info.height
	
	if info.orientation == "horizontal" then
	resizeWindow(gaugeName .. "_front", w * value, h)
	moveWindow(gaugeName .. "_front", x, y)
	elseif info.orientation == "vertical" then
	resizeWindow(gaugeName .. "_front", w, h * value)
	moveWindow(gaugeName .. "_front", x, y + h * (1 - value))
	elseif info.orientation == "goofy" then
	resizeWindow(gaugeName .. "_front", w * value, h)
	moveWindow(gaugeName .. "_front", x + w * (1 - value), y)
	elseif info.orientation == "batty" then
	resizeWindow(gaugeName .. "_front", w, h * value)
	moveWindow(gaugeName .. "_front", x, y)
	end
	if gaugeText then
		setGaugeText(gaugeName, gaugeText)
	end
end
Just paste it into a blank script and it will overwrite the old gauge functions with what should be coming in with the next update. If you have any questions or issues, just let me know. :)

Also, some of those look really slick.

User avatar
Greg
Posts: 3
Joined: Mon Jun 24, 2013 3:00 am

Re: Guages: a collection of styled "progress bars"

Post by Greg »

3 Layers Eh? Sounds great! can a transparent gradient be put on there with the text?

Jor'Mox
Posts: 1146
Joined: Wed Apr 03, 2013 2:19 am

Re: Guages: a collection of styled "progress bars"

Post by Jor'Mox »

Yes, you can style all three layers, including the one with the text. Just use it like this: setGaugeStyleSheet(gaugeName, cssfront, cssback, csstext)

Edit: I just looked at your script, and noticed you are using Geyser, which is where I got some of the ideas for functionality from. But Geyser builds its own gauges (rather than using the built in gauges). So there is something of a complication there from the perspective of your script as it is now.

Jor'Mox
Posts: 1146
Joined: Wed Apr 03, 2013 2:19 am

Re: Guages: a collection of styled "progress bars"

Post by Jor'Mox »

Personally, though, I use this: http://forums.mudlet.org/viewtopic.php?f=6&t=3529 to manage my GUI elements. As I find it simpler to use, and more flexible. And, you can use all the built in functions to interact with things, instead of using special functions like when you are using Mudlet.

Silvine
Posts: 142
Joined: Sat Oct 23, 2010 2:36 pm

Re: Guages: a collection of styled "progress bars"

Post by Silvine »

Love the style sheets!!! It took me forever to create something not nearly as pretty.

Daagar
Posts: 89
Joined: Fri Feb 19, 2010 2:42 am

Re: Guages: a collection of styled "progress bars"

Post by Daagar »

Very nice. It takes some amount of talent and/or skill to be able to use gauges. For me at least, it takes a completely different set of talent/skills to make something that ranks above stick-figure/crayon art (which is about the extent of my abilities, and even then I usually need to copy).

Jor'Mox
Posts: 1146
Joined: Wed Apr 03, 2013 2:19 am

Re: Guages: a collection of styled "progress bars"

Post by Jor'Mox »

I use these for my gauges. More simplistic than what he has, but I still think it is a decent look.
Code: [show] | [select all] lua
color_codes = {
	red = {"#FF0000","#BF0000","#7F0000"},
	vermilion = {"#FF3F00","#BF2F00","#7F1F00"},
	orange = {"#FF7F00","#BF5F00","#7F3F00"},
	amber = {"#FFBF00","#BF8F00","#7F5F00"},
	yellow = {"#FFFF00","#BFBF00","#7F7F00"},
	chartreuse = {"#BFFF00","#8FBF00","#5F7F00"},
	lime = {"#7FFF00","#5FBF00","#3F7F00"},
	emerald = {"#3FFF00","#2FBF00","#1F7F00"},
	green = {"#00FF00","#00BF00","#007F00"},
	aquamarine = {"#00FF3F","#00BF2F","#007F1F"},
	turquoise = {"#00FF7F","#00BF5F","#007F3F"},
	viridian = {"#00FFBF","#00BF8F","#007F5F"},
	cyan = {"#00FFFF","#00BFBF","#007F7F"},
	sky = {"#00BFFF","#008FBF","#005F7F"},
	cobalt = {"#007FFF","#005FBF","#003F7F"},
	ultramarine = {"#003FFF","#002FBF","#001F7F"},
	blue = {"#0000FF","#0000BF","#00007F"},
	indigo = {"#3F00FF","#2F00BF","#1F007F"},
	violet = {"#7F00FF","#5F00BF","#3F007F"},
	purple = {"#BF00FF","#8F00BF","#5F007F"},
	magenta = {"#FF00FF","#BF00BF","#7F007F"},
	lavender = {"#FF00BF","#BF008F","#7F005F"},
	crimson = {"#FF007F","#BF005F","#7F003F"},
	lake = {"#FF003F","#BF002F","#7F001F"},
	white = {"#FFFFFF","#BFBFBF","#7F7F7F"},
	silver = {"#BFBFBF","#8F8F8F","#5F5F5F"},
	gray = {"#7F7F7F","#5F5F5F","#3F3F3F"},
	black = {"#3F3F3F","#2F2F2F","#1F1F1F"}
}
	local orientation = "horizontal"
	local x, y, width, height = "10%", "10%", "20%", "5%"
	local origin = "topright"
	local gradstr
	if orientation == "horizontal" then
		gradstr = "x1: 0, y1: 0, x2: 0, y2: 1,"
	elseif orientation == "vertical" then
		gradstr = "x1: 0, y1: 0, x2: 1, y2: 0,"
	end
	
	createGauge("mygauge", 0, 0, 0, 0, nil, nil, orientation)
	windowManager.add("mygauge", "gauge", x, y, width, height, origin)
	local gauge_colors = color_codes["orange"]
	local align_str, padding_str = "", ""
	if orientation == "vertical" then
		align_str = [[ qproperty-alignment: 'AlignHCenter | AlignTop';]]
		padding_str = [[ padding-bottom: 5px;]]
	else
		align_str = [[ qproperty-alignment: 'AlignLeft | AlignVCenter';]]
		padding_str = [[ padding-left: 5px;]]
	end
	setGaugeStyleSheet("mygauge",[[background-color: QLinearGradient( ]] .. gradstr ..
		[[stop: 0]] .. gauge_colors[1] .. [[, stop: 0.2 ]] .. gauge_colors[1] .. [[, stop: 0.8 ]] .. gauge_colors[2] .. [[, stop: 1 ]] .. gauge_colors[2] .. [[);
		border-radius: 3;]],
		[[background-color: QLinearGradient( ]] .. gradstr ..
		[[stop: 0]] .. gauge_colors[2] .. [[, stop: 0.2 ]] .. gauge_colors[2] .. [[, stop: 0.8 ]] .. gauge_colors[3] .. [[, stop: 1 ]] .. gauge_colors[3] .. [[);
		border-radius: 3;]],
		padding_str .. [[ font-size: ]] .. configs.font_size .. [[; ]] .. align_str)
I took a while coming up with a good set of color codes to make a complete color wheel that actually looked decent.

Post Reply