HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Multiboard/Mouse related

05-29-2010, 08:16 PM#1
YourName
Didn't get a good idea for a thread-title that actually doesn't mislead to something strange.

So my problem is, I'm using RtC to get the position of the mouse when clicking anywhere, and I want to know which row and column is affected by that. I actually have no idea, I've tried out gambling a formula with playing around, but I didn't have any success in that. Probably someone got an idea.
05-29-2010, 09:21 PM#2
Ammorth
One thing to consider is that multiboards use 80% width for the full screen. I believe mouse relative position will corrolate with that already. Otherwise its just a bunch of experimenting with different widths and sizes and seeing where they end up on the screen.
06-04-2010, 02:18 PM#3
YourName
Okay so I came up with a quite simple formula, which, right now, only works if you use up all possible space for a multiboard.
x-position of the mouse/Window Width * column count
Collapse JASS:
    local integer column = GetMouseScreenX()/GetWindowWidth()*BOARD_COLUMNS
Although for some reason Warcraft always keeps returning 0 when calculating. BOARD_COLUMNS is set to 8, and the functions always return right values. I've checked them all through debug messages, only GetMouseScreenX()/GetWindowWidth() returns 0 in every case. Same when using a real instead.

Edit/ Okay, typically Warcraft.
Collapse JASS:
    local integer column = R2I(I2R(GetMouseScreenX())/I2R(GetWindowWidth())*BOARD_COLUMNS)
Works fine, although it rounds incorrect. Sigh.
06-04-2010, 02:32 PM#4
akolyt0r
Quote:
Originally Posted by YourName
Collapse JASS:
    local integer column = R2I(I2R(GetMouseScreenX())/I2R(GetWindowWidth())*BOARD_COLUMNS)
Works fine, although it rounds incorrect. Sigh.
Collapse JASS:
    local integer column = R2I(I2R(GetMouseScreenX())/I2R(GetWindowWidth())*BOARD_COLUMNS+0.5)
rounding fixed
06-04-2010, 02:38 PM#5
YourName
Quote:
Originally Posted by akolyt0r
Collapse JASS:
    local integer column = R2I(I2R(GetMouseScreenX())/I2R(GetWindowWidth())*BOARD_COLUMNS+0.5)
rounding fixed
Would still not fix it completely, because assuming the multiboard uses up as much space as it is able to, values under 0.5 would still be zero. I did this:

Collapse JASS:
    local integer column = Round(I2R(GetMouseScreenX())/I2R(GetWindowWidth())*BOARD_COLUMNS+.5)

With this being my Round function:
Collapse JASS:
function Round takes real r returns integer
    if r > 0 then
        return R2I(r+.5)
    endif
    return R2I(r-.5)
endfunction

I'm actually working on getting the row, although this is getting a bit more complicated because the multiboard doesn't start at the top of the screen.

edit/ It seems that the first row starts at 8.1% of the screens height. Gambling out a formula now D:
06-04-2010, 03:42 PM#6
akolyt0r
uh didnt know that GetMouseScreenX can return negative values ...my bad ...
good luck with that formula then ;)
06-04-2010, 04:01 PM#7
YourName
Well it's quite difficult to get one really good formula right now. I'm actually at that state:
Collapse JASS:
     set row = Round((R2I(GetMouseScreenY())-R2I(GetWindowHeight())*0.093+26)/R2I(R2I(GetWindowHeight())-R2I(GetWindowHeight()*0.093))*BOARD_ROWS)
Which works but isn't really accurate enough right now. Problem is that there's also a bit space left at the bottom of the screen.. meh.

Quote:
Originally Posted by akolyt0r
uh didnt know that GetMouseScreenX can return negative values ...my bad ...
It doesn't actually return negative values; the formula can just return values under 1.

Okay, so I played around with some values and came up with the result seen above. It is still somewhat inaccurate when you're fussy but does it's job as good as it's able to. Won't work with different column count/row count or column width than 8 columns, 39 rows and 10 width. Maybe someone is so intelligent and has too much freetime to make something that works with all cases. But this fits my needs so I'm happy.

Just as info: The first row starts at 8.1% of the screen height and the last row ends at screen height - 1.2%, just if anyone is interested.
06-05-2010, 12:49 PM#8
Ammorth
I would try using GetMouseRelativeX/Y. The GetMouseScreenX/Y will return different values for different resolutions, where the relative version is as it sounds, relative.
06-05-2010, 01:10 PM#9
YourName
There's no GetMouseRelativeX/Y in RtC at the moment, so I thought it would return a relative value. Could add my own natives for that then.

Ah okay, it does return the relative value when I interpreted the source code correctly.
Code:
Jass::real GetMouseScreenX() {
	if (MouseInfo) return RealMap(MouseInfo->MouseRelativeX);
	return 0;
}

Jass::real GetMouseScreenY() {
	if (MouseInfo) return RealMap(MouseInfo->MouseRelativeY);
	return 0;
}

edit2/ Btw: This is what I came up after playing around another 4 hours with it.

Collapse JASS:
            set RowWidth = Round(I2R(GetWindowHeight()) * 0.0234375)
            set ColumnWidth = Round(I2R(GetWindowWidth()) / 78.0 * BOARD_WIDTH)
            set TopSpace = Round(I2R(GetWindowHeight()) * 0.078125)
            set BotSpace = Round(I2R(GetWindowHeight()) - TopSpace - RowWidth * BOARD_ROWS)
            set RightSpace = Round(I2R(GetWindowWidth()) * 0.01475)
            set LeftSpace = Round(I2R(GetWindowWidth()) - RightSpace - BOARD_COLUMNS * ColumnWidth)
            set BoardHeight = Round(I2R(RowWidth) * BOARD_ROWS)
            set BoardWidth = Round(I2R(ColumnWidth) * BOARD_COLUMNS)

Collapse JASS:
            local integer column = Round((I2R(GetMouseScreenX()) - LeftSpace + RightSpace) / ColumnWidth)
            local integer row = Round(I2R(GetMouseScreenY() - TopSpace + BotSpace) / RowWidth)
Again, determination of the column only works with a width of 10. Sigh.
06-06-2010, 12:01 AM#10
Ammorth
I would take a screenshot of a multiboard with different widths and merge it with a grid of the values returns from the mouse function (screen positions). This will give you a good visual as to where the elements exist in relation to the mouse grid. From there, you should be able to measure colummn widths in regards to the mouse grid, and come up with a formula that gives you each column in terms of mouse size.

Once you get the conversion, you can do the same thing for rows and get 2 conversion functions. Since rows are of static width, the row conversion would convert MouseY directly to the row.

For the column, you would keep a list of all the column widths for each row, and loop through them all, until the width min and max of the cell contains the current mouse position.
06-06-2010, 02:42 PM#11
YourName
Well Blizzard made quite a huge mess out of their multiboard stuff. The formula works flawlessy with a maximum 0-2px deviation, but only at a width of 10. They seem to randomly scale the columns so it fits the screen, and if it doesn't match they just scale the last column down. I'm too pissed off of Blizzard's work to continue making a formula since it fits my needs as it is now.