| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -409,8 +409,6 @@ public void beginDraw() { | |||
| 409 | 409 | checkSettings(); | |
| 410 | 410 | resetMatrix(); // reset model matrix | |
| 411 | 411 | vertexCount = 0; | |
| 412 | - | ||
| 413 | - g2.scale(pixelDensity, pixelDensity); | ||
| 414 | 412 | } | |
| 415 | 413 | ||
| 416 | 414 | ||
@@ -1573,8 +1571,8 @@ protected void imageImpl(PImage who, | |||
| 1573 | 1571 | ||
| 1574 | 1572 | // Nuke the cache if the image was resized | |
| 1575 | 1573 | if (cash != null) { | |
| 1576 | - if (who.width != cash.image.getWidth() || | ||
| 1577 | - who.height != cash.image.getHeight()) { | ||
| 1574 | + if (who.pixelWidth != cash.image.getWidth() || | ||
| 1575 | + who.pixelHeight != cash.image.getHeight()) { | ||
| 1578 | 1576 | cash = null; | |
| 1579 | 1577 | } | |
| 1580 | 1578 | } | |
@@ -1601,12 +1599,17 @@ protected void imageImpl(PImage who, | |||
| 1601 | 1599 | // This might be a PGraphics that hasn't been drawn to yet. | |
| 1602 | 1600 | // Can't just bail because the cache has been created above. | |
| 1603 | 1601 | // https://github.com/processing/processing/issues/2208 | |
| 1604 | - who.pixels = new int[who.width * who.height]; | ||
| 1602 | + who.pixels = new int[who.pixelWidth * who.pixelHeight]; | ||
| 1605 | 1603 | } | |
| 1606 | 1604 | cash.update(who, tint, tintColor); | |
| 1607 | 1605 | who.setModified(false); | |
| 1608 | 1606 | } | |
| 1609 | 1607 | ||
| 1608 | + u1 *= who.pixelDensity; | ||
| 1609 | + v1 *= who.pixelDensity; | ||
| 1610 | + u2 *= who.pixelDensity; | ||
| 1611 | + v2 *= who.pixelDensity; | ||
| 1612 | + | ||
| 1610 | 1613 | g2.drawImage(((ImageCache) getCache(who)).image, | |
| 1611 | 1614 | (int) x1, (int) y1, (int) x2, (int) y2, | |
| 1612 | 1615 | u1, v1, u2, v2, null); | |
@@ -1674,14 +1677,14 @@ public void update(PImage source, boolean tint, int tintColor) { | |||
| 1674 | 1677 | // in the alpha channel when drawn to the screen. | |
| 1675 | 1678 | // https://github.com/processing/processing/issues/2030 | |
| 1676 | 1679 | if (image == null) { | |
| 1677 | - image = new BufferedImage(source.width, source.height, | ||
| 1680 | + image = new BufferedImage(source.pixelWidth, source.pixelHeight, | ||
| 1678 | 1681 | BufferedImage.TYPE_INT_ARGB); | |
| 1679 | 1682 | } | |
| 1680 | 1683 | ||
| 1681 | 1684 | WritableRaster wr = image.getRaster(); | |
| 1682 | 1685 | if (tint) { | |
| 1683 | - if (tintedTemp == null || tintedTemp.length != source.width) { | ||
| 1684 | - tintedTemp = new int[source.width]; | ||
| 1686 | + if (tintedTemp == null || tintedTemp.length != source.pixelWidth) { | ||
| 1687 | + tintedTemp = new int[source.pixelHeight]; | ||
| 1685 | 1688 | } | |
| 1686 | 1689 | int a2 = (tintColor >> 24) & 0xff; | |
| 1687 | 1690 | // System.out.println("tint color is " + a2); | |
@@ -1695,8 +1698,8 @@ public void update(PImage source, boolean tint, int tintColor) { | |||
| 1695 | 1698 | // The target image is opaque, meaning that the source image has no | |
| 1696 | 1699 | // alpha (is not ARGB), and the tint has no alpha. | |
| 1697 | 1700 | int index = 0; | |
| 1698 | - for (int y = 0; y < source.height; y++) { | ||
| 1699 | - for (int x = 0; x < source.width; x++) { | ||
| 1701 | + for (int y = 0; y < source.pixelHeight; y++) { | ||
| 1702 | + for (int x = 0; x < source.pixelWidth; x++) { | ||
| 1700 | 1703 | int argb1 = source.pixels[index++]; | |
| 1701 | 1704 | int r1 = (argb1 >> 16) & 0xff; | |
| 1702 | 1705 | int g1 = (argb1 >> 8) & 0xff; | |
@@ -1710,7 +1713,7 @@ public void update(PImage source, boolean tint, int tintColor) { | |||
| 1710 | 1713 | ((g2 * g1) & 0xff00) | | |
| 1711 | 1714 | (((b2 * b1) & 0xff00) >> 8); | |
| 1712 | 1715 | } | |
| 1713 | - wr.setDataElements(0, y, source.width, 1, tintedTemp); | ||
| 1716 | + wr.setDataElements(0, y, source.pixelWidth, 1, tintedTemp); | ||
| 1714 | 1717 | } | |
| 1715 | 1718 | // could this be any slower? | |
| 1716 | 1719 | // float[] scales = { tintR, tintG, tintB }; | |
@@ -1724,18 +1727,18 @@ public void update(PImage source, boolean tint, int tintColor) { | |||
| 1724 | 1727 | (tintColor & 0xffffff) == 0xffffff) { | |
| 1725 | 1728 | int hi = tintColor & 0xff000000; | |
| 1726 | 1729 | int index = 0; | |
| 1727 | - for (int y = 0; y < source.height; y++) { | ||
| 1728 | - for (int x = 0; x < source.width; x++) { | ||
| 1730 | + for (int y = 0; y < source.pixelHeight; y++) { | ||
| 1731 | + for (int x = 0; x < source.pixelWidth; x++) { | ||
| 1729 | 1732 | tintedTemp[x] = hi | (source.pixels[index++] & 0xFFFFFF); | |
| 1730 | 1733 | } | |
| 1731 | - wr.setDataElements(0, y, source.width, 1, tintedTemp); | ||
| 1734 | + wr.setDataElements(0, y, source.pixelWidth, 1, tintedTemp); | ||
| 1732 | 1735 | } | |
| 1733 | 1736 | } else { | |
| 1734 | 1737 | int index = 0; | |
| 1735 | - for (int y = 0; y < source.height; y++) { | ||
| 1738 | + for (int y = 0; y < source.pixelHeight; y++) { | ||
| 1736 | 1739 | if (source.format == RGB) { | |
| 1737 | 1740 | int alpha = tintColor & 0xFF000000; | |
| 1738 | - for (int x = 0; x < source.width; x++) { | ||
| 1741 | + for (int x = 0; x < source.pixelWidth; x++) { | ||
| 1739 | 1742 | int argb1 = source.pixels[index++]; | |
| 1740 | 1743 | int r1 = (argb1 >> 16) & 0xff; | |
| 1741 | 1744 | int g1 = (argb1 >> 8) & 0xff; | |
@@ -1746,7 +1749,7 @@ public void update(PImage source, boolean tint, int tintColor) { | |||
| 1746 | 1749 | (((b2 * b1) & 0xff00) >> 8); | |
| 1747 | 1750 | } | |
| 1748 | 1751 | } else if (source.format == ARGB) { | |
| 1749 | - for (int x = 0; x < source.width; x++) { | ||
| 1752 | + for (int x = 0; x < source.pixelWidth; x++) { | ||
| 1750 | 1753 | int argb1 = source.pixels[index++]; | |
| 1751 | 1754 | int a1 = (argb1 >> 24) & 0xff; | |
| 1752 | 1755 | int r1 = (argb1 >> 16) & 0xff; | |
@@ -1760,13 +1763,13 @@ public void update(PImage source, boolean tint, int tintColor) { | |||
| 1760 | 1763 | } | |
| 1761 | 1764 | } else if (source.format == ALPHA) { | |
| 1762 | 1765 | int lower = tintColor & 0xFFFFFF; | |
| 1763 | - for (int x = 0; x < source.width; x++) { | ||
| 1766 | + for (int x = 0; x < source.pixelWidth; x++) { | ||
| 1764 | 1767 | int a1 = source.pixels[index++]; | |
| 1765 | 1768 | tintedTemp[x] = | |
| 1766 | 1769 | (((a2 * a1) & 0xff00) << 16) | lower; | |
| 1767 | 1770 | } | |
| 1768 | 1771 | } | |
| 1769 | - wr.setDataElements(0, y, source.width, 1, tintedTemp); | ||
| 1772 | + wr.setDataElements(0, y, source.pixelWidth, 1, tintedTemp); | ||
| 1770 | 1773 | } | |
| 1771 | 1774 | } | |
| 1772 | 1775 | // Not sure why ARGB images take the scales in this order... | |
@@ -1786,7 +1789,7 @@ public void update(PImage source, boolean tint, int tintColor) { | |||
| 1786 | 1789 | // in a PImage and how the high bits will be set. | |
| 1787 | 1790 | } | |
| 1788 | 1791 | // If no tint, just shove the pixels on in there verbatim | |
| 1789 | - wr.setDataElements(0, 0, source.width, source.height, source.pixels); | ||
| 1792 | + wr.setDataElements(0, 0, source.pixelWidth, source.pixelHeight, source.pixels); | ||
| 1790 | 1793 | } | |
| 1791 | 1794 | this.tinted = tint; | |
| 1792 | 1795 | this.tintedColor = tintColor; | |
@@ -2232,6 +2235,7 @@ public void shearY(float angle) { | |||
| 2232 | 2235 | @Override | |
| 2233 | 2236 | public void resetMatrix() { | |
| 2234 | 2237 | g2.setTransform(new AffineTransform()); | |
| 2238 | + g2.scale(pixelDensity, pixelDensity); | ||
| 2235 | 2239 | } | |
| 2236 | 2240 | ||
| 2237 | 2241 | ||
@@ -2793,7 +2797,7 @@ public void updatePixels(int x, int y, int c, int d) { | |||
| 2793 | 2797 | if (pixels != null) { | |
| 2794 | 2798 | getRaster().setDataElements(0, 0, pixelWidth, pixelHeight, pixels); | |
| 2795 | 2799 | } | |
| 2796 | - modified = true; | ||
| 2800 | + modified = false; | ||
| 2797 | 2801 | } | |
| 2798 | 2802 | ||
| 2799 | 2803 | ||
@@ -2836,12 +2840,6 @@ public int get(int x, int y) { | |||
| 2836 | 2840 | //public PImage get(int x, int y, int w, int h) | |
| 2837 | 2841 | ||
| 2838 | 2842 | ||
| 2839 | - @Override | ||
| 2840 | - public PImage get() { | ||
| 2841 | - return get(0, 0, width, height); | ||
| 2842 | - } | ||
| 2843 | - | ||
| 2844 | - | ||
| 2845 | 2843 | @Override | |
| 2846 | 2844 | protected void getImpl(int sourceX, int sourceY, | |
| 2847 | 2845 | int sourceWidth, int sourceHeight, | |
@@ -2852,7 +2850,7 @@ protected void getImpl(int sourceX, int sourceY, | |||
| 2852 | 2850 | // ((BufferedImage) (useOffscreen && primarySurface ? offscreen : image)).getRaster(); | |
| 2853 | 2851 | WritableRaster raster = getRaster(); | |
| 2854 | 2852 | ||
| 2855 | - if (sourceWidth == target.width && sourceHeight == target.height) { | ||
| 2853 | + if (sourceWidth == target.pixelWidth && sourceHeight == target.pixelHeight) { | ||
| 2856 | 2854 | raster.getDataElements(sourceX, sourceY, sourceWidth, sourceHeight, target.pixels); | |
| 2857 | 2855 | // https://github.com/processing/processing/issues/2030 | |
| 2858 | 2856 | if (raster.getNumBands() == 3) { | |
@@ -2866,7 +2864,7 @@ protected void getImpl(int sourceX, int sourceY, | |||
| 2866 | 2864 | ||
| 2867 | 2865 | // Copy the temporary output pixels over to the outgoing image | |
| 2868 | 2866 | int sourceOffset = 0; | |
| 2869 | - int targetOffset = targetY*target.width + targetX; | ||
| 2867 | + int targetOffset = targetY*target.pixelWidth + targetX; | ||
| 2870 | 2868 | for (int y = 0; y < sourceHeight; y++) { | |
| 2871 | 2869 | if (raster.getNumBands() == 3) { | |
| 2872 | 2870 | for (int i = 0; i < sourceWidth; i++) { | |
@@ -2878,15 +2876,15 @@ protected void getImpl(int sourceX, int sourceY, | |||
| 2878 | 2876 | System.arraycopy(temp, sourceOffset, target.pixels, targetOffset, sourceWidth); | |
| 2879 | 2877 | } | |
| 2880 | 2878 | sourceOffset += sourceWidth; | |
| 2881 | - targetOffset += target.width; | ||
| 2879 | + targetOffset += target.pixelWidth; | ||
| 2882 | 2880 | } | |
| 2883 | 2881 | } | |
| 2884 | 2882 | } | |
| 2885 | 2883 | ||
| 2886 | 2884 | ||
| 2887 | 2885 | @Override | |
| 2888 | 2886 | public void set(int x, int y, int argb) { | |
| 2889 | - if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) return; | ||
| 2887 | + if ((x < 0) || (y < 0) || (x >= pixelWidth) || (y >= pixelHeight)) return; | ||
| 2890 | 2888 | // ((BufferedImage) image).setRGB(x, y, argb); | |
| 2891 | 2889 | getset[0] = argb; | |
| 2892 | 2890 | // WritableRaster raster = ((BufferedImage) (useOffscreen && primarySurface ? offscreen : image)).getRaster(); | |
@@ -2907,18 +2905,18 @@ protected void setImpl(PImage sourceImage, | |||
| 2907 | 2905 | // ((BufferedImage) (useOffscreen && primarySurface ? offscreen : image)).getRaster(); | |
| 2908 | 2906 | ||
| 2909 | 2907 | if ((sourceX == 0) && (sourceY == 0) && | |
| 2910 | - (sourceWidth == sourceImage.width) && | ||
| 2911 | - (sourceHeight == sourceImage.height)) { | ||
| 2908 | + (sourceWidth == sourceImage.pixelWidth) && | ||
| 2909 | + (sourceHeight == sourceImage.pixelHeight)) { | ||
| 2912 | 2910 | // System.out.format("%d %d %dx%d %d%n", targetX, targetY, | |
| 2913 | 2911 | // sourceImage.width, sourceImage.height, | |
| 2914 | 2912 | // sourceImage.pixels.length); | |
| 2915 | 2913 | raster.setDataElements(targetX, targetY, | |
| 2916 | - sourceImage.width, sourceImage.height, | ||
| 2914 | + sourceImage.pixelWidth, sourceImage.pixelHeight, | ||
| 2917 | 2915 | sourceImage.pixels); | |
| 2918 | 2916 | } else { | |
| 2919 | 2917 | // TODO optimize, incredibly inefficient to reallocate this much memory | |
| 2920 | 2918 | PImage temp = sourceImage.get(sourceX, sourceY, sourceWidth, sourceHeight); | |
| 2921 | - raster.setDataElements(targetX, targetY, temp.width, temp.height, temp.pixels); | ||
| 2919 | + raster.setDataElements(targetX, targetY, temp.pixelWidth, temp.pixelHeight, temp.pixels); | ||
| 2922 | 2920 | } | |
| 2923 | 2921 | } | |
| 2924 | 2922 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -90,6 +90,8 @@ public class PSurfaceAWT extends PSurfaceNone { | |||
| 90 | 90 | int sketchWidth; | |
| 91 | 91 | int sketchHeight; | |
| 92 | 92 | ||
| 93 | + int windowScaleFactor; | ||
| 94 | + | ||
| 93 | 95 | ||
| 94 | 96 | public PSurfaceAWT(PGraphics graphics) { | |
| 95 | 97 | //this.graphics = graphics; | |
@@ -224,7 +226,7 @@ public void validate() { | |||
| 224 | 226 | if (!oldSize.equals(newSize)) { | |
| 225 | 227 | // System.out.println("validate() render old=" + oldSize + " -> new=" + newSize); | |
| 226 | 228 | oldSize = newSize; | |
| 227 | - sketch.setSize(newSize.width, newSize.height); | ||
| 229 | + sketch.setSize(newSize.width / windowScaleFactor, newSize.height / windowScaleFactor); | ||
| 228 | 230 | // try { | |
| 229 | 231 | render(); | |
| 230 | 232 | // } catch (IllegalStateException ise) { | |
@@ -423,8 +425,11 @@ public void initFrame(final PApplet sketch) {/*, int backgroundColor, | |||
| 423 | 425 | sketch.displayWidth = screenRect.width; | |
| 424 | 426 | sketch.displayHeight = screenRect.height; | |
| 425 | 427 | ||
| 426 | - sketchWidth = sketch.sketchWidth(); | ||
| 427 | - sketchHeight = sketch.sketchHeight(); | ||
| 428 | + windowScaleFactor = PApplet.platform == PConstants.MACOSX ? | ||
| 429 | + 1 : sketch.pixelDensity; | ||
| 430 | + | ||
| 431 | + sketchWidth = sketch.sketchWidth() * windowScaleFactor; | ||
| 432 | + sketchHeight = sketch.sketchHeight() * windowScaleFactor; | ||
| 428 | 433 | ||
| 429 | 434 | boolean fullScreen = sketch.sketchFullScreen(); | |
| 430 | 435 | // Removing the section below because sometimes people want to do the | |
@@ -481,7 +486,7 @@ public void initFrame(final PApplet sketch) {/*, int backgroundColor, | |||
| 481 | 486 | // http://dev.processing.org/bugs/show_bug.cgi?id=908 | |
| 482 | 487 | ||
| 483 | 488 | frame.add(canvas); | |
| 484 | - setSize(sketchWidth, sketchHeight); | ||
| 489 | + setSize(sketchWidth / windowScaleFactor, sketchHeight / windowScaleFactor); | ||
| 485 | 490 | ||
| 486 | 491 | /* | |
| 487 | 492 | if (fullScreen) { | |
@@ -954,8 +959,8 @@ public void setSize(int wide, int high) { | |||
| 954 | 959 | return; // unchanged, don't rebuild everything | |
| 955 | 960 | } | |
| 956 | 961 | ||
| 957 | - sketchWidth = wide; | ||
| 958 | - sketchHeight = high; | ||
| 962 | + sketchWidth = wide * windowScaleFactor; | ||
| 963 | + sketchHeight = high * windowScaleFactor; | ||
| 959 | 964 | ||
| 960 | 965 | // canvas.setSize(wide, high); | |
| 961 | 966 | // frame.setSize(wide, high); | |
@@ -1142,8 +1147,9 @@ public void componentResized(ComponentEvent e) { | |||
| 1142 | 1147 | // overall size of the window. Perhaps JFrame sets its coord | |
| 1143 | 1148 | // system so that (0, 0) is always the upper-left of the content | |
| 1144 | 1149 | // area. Which seems nice, but breaks any f*ing AWT-based code. | |
| 1145 | - setSize(windowSize.width - currentInsets.left - currentInsets.right, | ||
| 1146 | - windowSize.height - currentInsets.top - currentInsets.bottom); | ||
| 1150 | + int w = windowSize.width - currentInsets.left - currentInsets.right; | ||
| 1151 | + int h = windowSize.height - currentInsets.top - currentInsets.bottom; | ||
| 1152 | + setSize(w / windowScaleFactor, h / windowScaleFactor); | ||
| 1147 | 1153 | ||
| 1148 | 1154 | // correct the location when inset size changes | |
| 1149 | 1155 | setLocation(x - currentInsets.left, y - currentInsets.top); | |
@@ -1312,7 +1318,8 @@ protected void nativeMouseEvent(java.awt.event.MouseEvent nativeEvent) { | |||
| 1312 | 1318 | ||
| 1313 | 1319 | sketch.postEvent(new MouseEvent(nativeEvent, nativeEvent.getWhen(), | |
| 1314 | 1320 | peAction, peModifiers, | |
| 1315 | - nativeEvent.getX(), nativeEvent.getY(), | ||
| 1321 | + nativeEvent.getX() / windowScaleFactor, | ||
| 1322 | + nativeEvent.getY() / windowScaleFactor, | ||
| 1316 | 1323 | peButton, | |
| 1317 | 1324 | peCount)); | |
| 1318 | 1325 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments