It appears that the macro function getViewArea is return a string containing the Java object representation. If I do this:
[getViewArea(0)]
I get this returned:
java.awt.Rectangle[x=40,y=50,width=75,height=39]
Which I cannot do much with directly. I have to parse it somehow to extract the relevant values. It would be much preferable to have the method return a json object.
Edit: This is in 1.5.rc.4.
Worse than that, it doesn't have a default and so produces an error if no parameter is given.
java.lang.IndexOutOfBoundsException: Index 0 out-of-bounds for length 0 error executing expression getViewArea().
on it
setting the defaults to pixels if no parameter is given
Fixed. So this:
[r: getViewArea()]
[r: getViewArea(0)]
[r: getViewArea(1)]
[r: getViewArea(0, "json")]
[r: getViewArea(1, "json")]
[r: getViewArea(0, ",")]
[r: getViewArea(1, ";")]
results now to:
offsetX=0; offsetY=0; width=886; height=616
offsetX=0; offsetY=0; width=17; height=12
offsetX=0; offsetY=0; width=886; height=616
{"offsetX":0,"offsetY":0,"width":886,"height":616}
{"offsetX":0,"offsetY":0,"width":886,"height":616}
offsetX=0, offsetY=0, width=886, height=616
offsetX=0; offsetY=0; width=886; height=616
Fix is now correctly setting a default for pixels (true) if not given and allows to return Json or String property list with delimiter
Great — Good job!
Shouldn't there be an X and Y value, unless you never moved your viewport from the starting 0,0.
there is, called offsetX and offsetY?
Output Line 2 and 4 use "grid". Is the height and width in grid squares? I assumed "grid" was just for the offset and the height and width would always be in pixels. I guess grid would be okay for those too. Anyway, Line 4 seems to have pixels rather than grid values. Not sure which one is supposed to be right (2 or 4).
I did not change the calculation of the values, just the output format. But your right, some lines seem to be not using grid. Checking
Re the x,y thing above. If you redo your test output I recommend moving the viewport for some x,y contrast. ie offsetX pixel 0 is the same as offsetX grid 0.
Default pixels: [r: getViewArea()]
Cells: [r: getViewArea(0)]
Pixels: [r: getViewArea(1)]
Cells as JSON: [r: getViewArea(0, "json")]
Pixels as JSON: [r: getViewArea(1, "json")]
Cells as "," separated String properties: [r: getViewArea(0, ",")]
Pixels as ";" separated String properties: [r: getViewArea(1, ";")]
Results:
Default pixels: offsetX=133; offsetY=116; width=886; height=616
Cells: offsetX=2; offsetY=2; width=17; height=12
Pixels: offsetX=133; offsetY=116; width=886; height=616
Cells as JSON: {"offsetX":2,"offsetY":2,"width":17,"height":12}
Pixels as JSON: {"offsetX":133,"offsetY":116,"width":886,"height":616}
Cells as "," separated String properties: offsetX=2, offsetY=2, width=17, height=12
Pixels as ";" separated String properties: offsetX=133; offsetY=116; width=886; height=616
Most helpful comment
Default pixels: [r: getViewArea()]
Cells: [r: getViewArea(0)]
Pixels: [r: getViewArea(1)]
Cells as JSON: [r: getViewArea(0, "json")]
Pixels as JSON: [r: getViewArea(1, "json")]
Cells as "," separated String properties: [r: getViewArea(0, ",")]
Pixels as ";" separated String properties: [r: getViewArea(1, ";")]
Results:
Default pixels: offsetX=133; offsetY=116; width=886; height=616
Cells: offsetX=2; offsetY=2; width=17; height=12
Pixels: offsetX=133; offsetY=116; width=886; height=616
Cells as JSON: {"offsetX":2,"offsetY":2,"width":17,"height":12}
Pixels as JSON: {"offsetX":133,"offsetY":116,"width":886,"height":616}
Cells as "," separated String properties: offsetX=2, offsetY=2, width=17, height=12
Pixels as ";" separated String properties: offsetX=133; offsetY=116; width=886; height=616