Changeset 16764 in josm for trunk/test/unit/org


Ignore:
Timestamp:
2020-07-14T19:50:11+02:00 (4 years ago)
Author:
simon04
Message:

see #13173 - Fix cursor hotspot for HiDPI (patch by johsin18, modified)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/tools/ImageProviderTest.java

    r16486 r16764  
    194194    }
    195195
    196     public static final int ORIGINAL_CURSOR_SIZE = 32;
    197 
    198196    /**
    199197     * Test getting an image for a crosshair cursor.
     
    215213    @Test
    216214    public void testGetCursorImageWithOverlay() {
     215        testCursorImageWithOverlay(1.0f);  // normal case
     216        testCursorImageWithOverlay(1.5f);  // user has configured a GUI scale of 1.5 in the JOSM advanced preferences
     217    }
     218
     219    private void testCursorImageWithOverlay(float guiScale) {
    217220        if (GraphicsEnvironment.isHeadless()) {
    218221            // TODO mock Toolkit.getDefaultToolkit().getBestCursorSize()
    219222            return;
    220223        }
     224        GuiSizesHelper.setPixelDensity(guiScale);
    221225        Point hotSpot = new Point();
    222226        Image image = ImageProvider.getCursorImage("normal", "selection", hotSpot);
     
    237241
    238242    private void assertCursorDimensionsCorrect(Point.Double originalHotspot, Image image, Point hotSpot) {
    239         Dimension bestCursorSize = Toolkit.getDefaultToolkit().getBestCursorSize(ORIGINAL_CURSOR_SIZE, ORIGINAL_CURSOR_SIZE);
     243        int originalCursorSize = ImageProvider.CURSOR_SIZE_HOTSPOT_IS_RELATIVE_TO;
     244        Dimension bestCursorSize = Toolkit.getDefaultToolkit().getBestCursorSize(originalCursorSize, originalCursorSize);
    240245        Image bestCursorImage = HiDPISupport.getResolutionVariant(image, bestCursorSize.width, bestCursorSize.height);
    241246        int bestCursorImageWidth = bestCursorImage.getWidth(null);
     
    243248        int bestCursorImageHeight = bestCursorImage.getHeight(null);
    244249        assertEquals((int) Math.round(bestCursorSize.getHeight()), bestCursorImageHeight);
    245         assertEquals(originalHotspot.x / ORIGINAL_CURSOR_SIZE * bestCursorImageWidth, hotSpot.x, 1 /* at worst one pixel off */);
    246         assertEquals(originalHotspot.y / ORIGINAL_CURSOR_SIZE * bestCursorImageHeight, hotSpot.y, 1 /* at worst one pixel off */);
     250        assertEquals(originalHotspot.x / originalCursorSize * bestCursorImageWidth, hotSpot.x, 1 /* at worst one pixel off */);
     251        assertEquals(originalHotspot.y / originalCursorSize * bestCursorImageHeight, hotSpot.y, 1 /* at worst one pixel off */);
    247252    }
    248253
Note: See TracChangeset for help on using the changeset viewer.