ID:909426
 
Window & Window Object Resolution Functions

Recently Dj Dovus posted a tutorial on how to get the player's resolution. It quite openly exposed that no one has defined a way to get the x and y values of a window or objects within a window. These three functions will let you get the resolution of any window or object in a window from your interface. Please note this is for people who use an interface file (.DMF). Also, you only need to know how to use the 3 functions. The actual code doing the work doesn't need to be worried about.

The Functions

getWinX(String Value) - Returns the X only.
getWinY(String Value) - Returns the Y only.
getWinRes(String Value) - Returns both as a list. Example : res[1] or res[2]

Examples

getWinX("default")
getWinY("default.output1")
getWinRes("window1")


The Code

I was able to do this using Deadron's Text Handling library and using a modification of one of his processes. The major changes are switching the return to an integer, correcting some inconsistencies and error proofing it.

mob
Login()

src << "Window X: [getWinX("default")], Window Y: [getWinY("default")]"


proc

getWinX(window)

var/res = getWinRes(window)
if(res)
return res[1]
else return


getWinY(window)

var/res = getWinRes(window)
if(res)
return res[2]
else return


getWinRes(window)

if(!window) return
var/size = winget(src,"[window]","size")
if(size) return text2List(size,"x")
else return


text2List(text, separator) // Written By Deadron | Modified By Red Hall Dev

if(!text || !separator) return

var/textLength = lentext(text)
var/separatorLength = lentext(separator)
var/list/numList = new /list()
var/searchPosition = 1
var/findPosition = 1
var/buggyText
var/loopForever = 1

while(loopForever)
findPosition = findtextEx(text, separator, searchPosition, 0)
buggyText = text2num(copytext(text, searchPosition, findPosition)) // Everything from searchPosition to findPosition goes into a list element.
numList += buggyText // Working around weird problem where "text" != "text" after this copytext().
searchPosition = findPosition + separatorLength // Skip over separator.
if (findPosition == 0) // Didn't find anything at end of string so stop here.
return numList
else
if (searchPosition > textLength) // Found separator at very end of string.
numList += "" // So add empty element.
return numList