yellowstonegames / SquidLib

Useful tools for roguelike, role-playing, strategy, and other grid-based games in Java. Feedback is welcome!
Other
448 stars 46 forks source link

SquidMouse.java has unclear documentation (or implementation maybe?) #179

Closed SquidPony closed 7 years ago

SquidPony commented 7 years ago
   /**
     * Sets the size of the cell so that all mouse input can be evaluated as
     * relative to the grid. Offsets can be specified for x and y if the grid
     * is displayed at a position other than the full screen. Specify the
     * width and height in grid cells of the area to receive input, as well as
     * the offsets from the bottom and left edges also measured in grid cells.
     * All input is passed to the provided InputProcessor once it's had its
     * coordinates translated to grid coordinates.
     *
     * If the input is not within the bounds of the grid as determined by
     * gridWidth, gridHeight, offsetX, and offsetY, the input will be clamped.
     *
     * @param cellWidth
     * @param cellHeight
     * @param gridWidth
     * @param gridHeight
     * @param offsetX
     * @param offsetY
     * @param processor an InputProcessor that implements some of touchUp(), touchDown(), touchDragged(), mouseMoved(), or scrolled().
     */
    public SquidMouse(float cellWidth, float cellHeight, float gridWidth, float gridHeight, int offsetX, int offsetY, InputProcessor processor) {
        this.cellWidth = cellWidth;
        this.cellHeight = cellHeight;
        this.processor = processor;
        this.offsetX = offsetX;
        this.offsetY = offsetY;
        this.gridWidth = gridWidth;
        this.gridHeight = gridHeight;
    }

I think the offsets are actually in screen pixels and not grid cells, but I'm not sure.

If it is in grid cells then are those sized by the input size? If so then a user would have to do some math to figure out the correct offset to send in when they have panels with different size cells working in the same game.

Additionally the doc says "the offsets from the bottom and left edges" but I think it means "top and left edges". If it's not top and left that's weird since pretty much everything else has the origin at the top left I think.

tommyettinger commented 7 years ago

Offsets are in screen pixels, docs are wrong. I'm pretty sure the offsets are applied from bottom and left due to unfortunate weirdness with scene2d.ui and viewports. Will fix the docs re: pixel measurement.