| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -810,6 +810,7 @@ public void init() { | |||
| 810 | 810 | boolean fullScreen; | |
| 811 | 811 | int display = -1; // use default | |
| 812 | 812 | GraphicsDevice[] displayDevices; | |
| 813 | + int pixelDensity = 1; | ||
| 813 | 814 | ||
| 814 | 815 | String outputPath; | |
| 815 | 816 | OutputStream outputStream; | |
@@ -967,6 +968,14 @@ final public int sketchWindowColor() { | |||
| 967 | 968 | } | |
| 968 | 969 | ||
| 969 | 970 | ||
| 971 | + final public int sketchPixelDensity() { | ||
| 972 | + return pixelDensity; | ||
| 973 | + } | ||
| 974 | + | ||
| 975 | + | ||
| 976 | + // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | ||
| 977 | + | ||
| 978 | + | ||
| 970 | 979 | public int displayDensity() { | |
| 971 | 980 | if (display == SPAN) { | |
| 972 | 981 | // walk through all displays, use lowest common denominator | |
@@ -1029,6 +1038,15 @@ static public int displayDensity(int display) { | |||
| 1029 | 1038 | } | |
| 1030 | 1039 | ||
| 1031 | 1040 | ||
| 1041 | + public void pixelDensity(int density) { | ||
| 1042 | + if (density != this.pixelDensity) { | ||
| 1043 | + if (insideSettings("pixelDensity", density)) { | ||
| 1044 | + this.pixelDensity = density; | ||
| 1045 | + } | ||
| 1046 | + } | ||
| 1047 | + } | ||
| 1048 | + | ||
| 1049 | + | ||
| 1032 | 1050 | // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | |
| 1033 | 1051 | ||
| 1034 | 1052 | ||
@@ -5237,7 +5255,7 @@ public void run() { | |||
| 5237 | 5255 | ||
| 5238 | 5256 | vessel.pixelWidth = actual.width; | |
| 5239 | 5257 | vessel.pixelHeight = actual.height; | |
| 5240 | - vessel.pixelFactor = 1; | ||
| 5258 | + vessel.pixelDensity = 1; | ||
| 5241 | 5259 | } | |
| 5242 | 5260 | requestImageCount--; | |
| 5243 | 5261 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -698,9 +698,11 @@ public PGraphics() { | |||
| 698 | 698 | ||
| 699 | 699 | public void setParent(PApplet parent) { // ignore | |
| 700 | 700 | this.parent = parent; | |
| 701 | + | ||
| 701 | 702 | // Some renderers (OpenGL) need to know what smoothing level will be used | |
| 702 | 703 | // before the rendering surface is even created. | |
| 703 | 704 | smooth = parent.sketchSmooth(); | |
| 705 | + pixelDensity = parent.sketchPixelDensity(); | ||
| 704 | 706 | } | |
| 705 | 707 | ||
| 706 | 708 | ||
@@ -747,8 +749,8 @@ public void setSize(int w, int h) { // ignore | |||
| 747 | 749 | height = h; | |
| 748 | 750 | ||
| 749 | 751 | /** {@link PImage.pixelFactor} set in {@link PImage#PImage()} */ | |
| 750 | - pixelWidth = width * pixelFactor; | ||
| 751 | - pixelHeight = height * pixelFactor; | ||
| 752 | + pixelWidth = width * pixelDensity; | ||
| 753 | + pixelHeight = height * pixelDensity; | ||
| 752 | 754 | ||
| 753 | 755 | // if (surface != null) { | |
| 754 | 756 | // allocate(); | |
@@ -8064,6 +8066,6 @@ public boolean isGL() { // ignore | |||
| 8064 | 8066 | ||
| 8065 | 8067 | ||
| 8066 | 8068 | public boolean is2X() { | |
| 8067 | - return pixelFactor == 2; | ||
| 8069 | + return pixelDensity == 2; | ||
| 8068 | 8070 | } | |
| 8069 | 8071 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1900,8 +1900,8 @@ public void backgroundImpl() { | |||
| 1900 | 1900 | @Override | |
| 1901 | 1901 | public void loadPixels() { | |
| 1902 | 1902 | // pixelFactor = 2; | |
| 1903 | - int wide = width * pixelFactor; | ||
| 1904 | - int high = height * pixelFactor; | ||
| 1903 | + int wide = width * pixelDensity; | ||
| 1904 | + int high = height * pixelDensity; | ||
| 1905 | 1905 | ||
| 1906 | 1906 | if ((pixels == null) || (pixels.length != wide*high)) { | |
| 1907 | 1907 | pixels = new int[wide * high]; | |
@@ -1917,7 +1917,7 @@ public void loadPixels() { | |||
| 1917 | 1917 | // } | |
| 1918 | 1918 | // } | |
| 1919 | 1919 | SnapshotParameters sp = new SnapshotParameters(); | |
| 1920 | - if (pixelFactor == 2) { | ||
| 1920 | + if (pixelDensity == 2) { | ||
| 1921 | 1921 | sp.setTransform(Transform.scale(2, 2)); | |
| 1922 | 1922 | } | |
| 1923 | 1923 | WritableImage wi = ((PSurfaceFX) surface).canvas.snapshot(sp, null); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,6 +25,6 @@ | |||
| 25 | 25 | ||
| 26 | 26 | public class PGraphicsFX2D2X extends PGraphics { | |
| 27 | 27 | public PGraphicsFX2D2X() { | |
| 28 | - pixelFactor = 2; | ||
| 28 | + pixelDensity = 2; | ||
| 29 | 29 | } | |
| 30 | 30 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -272,8 +272,8 @@ public boolean canDraw() { | |||
| 272 | 272 | ||
| 273 | 273 | public Graphics2D checkImage() { | |
| 274 | 274 | if (image == null || | |
| 275 | - ((BufferedImage) image).getWidth() != width*pixelFactor || | ||
| 276 | - ((BufferedImage) image).getHeight() != height*pixelFactor) { | ||
| 275 | + ((BufferedImage) image).getWidth() != width*pixelDensity || | ||
| 276 | + ((BufferedImage) image).getHeight() != height*pixelDensity) { | ||
| 277 | 277 | // ((VolatileImage) image).getWidth() != width || | |
| 278 | 278 | // ((VolatileImage) image).getHeight() != height) { | |
| 279 | 279 | // image = new BufferedImage(width * pixelFactor, height * pixelFactor | |
@@ -299,8 +299,8 @@ public Graphics2D checkImage() { | |||
| 299 | 299 | ||
| 300 | 300 | // Formerly this was broken into separate versions based on offscreen or | |
| 301 | 301 | // not, but we may as well create a compatible image; it won't hurt, right? | |
| 302 | - int wide = width * pixelFactor; | ||
| 303 | - int high = height * pixelFactor; | ||
| 302 | + int wide = width * pixelDensity; | ||
| 303 | + int high = height * pixelDensity; | ||
| 304 | 304 | // System.out.println("re-creating image"); | |
| 305 | 305 | image = gc.createCompatibleImage(wide, high); | |
| 306 | 306 | // image = gc.createCompatibleVolatileImage(wide, high); | |
@@ -375,6 +375,8 @@ public void beginDraw() { | |||
| 375 | 375 | checkSettings(); | |
| 376 | 376 | resetMatrix(); // reset model matrix | |
| 377 | 377 | vertexCount = 0; | |
| 378 | + | ||
| 379 | + g2.scale(pixelDensity, pixelDensity); | ||
| 378 | 380 | } | |
| 379 | 381 | ||
| 380 | 382 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,7 +13,7 @@ public class PGraphicsJava2D2X extends PGraphicsJava2D { | |||
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | 15 | public PGraphicsJava2D2X() { | |
| 16 | - pixelFactor = 2; | ||
| 16 | + pixelDensity = 2; | ||
| 17 | 17 | // retina = new PImage(); | |
| 18 | 18 | // retina.format = RGB; | |
| 19 | 19 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -95,7 +95,7 @@ public class PImage implements PConstants, Cloneable { | |||
| 95 | 95 | public int[] pixels; | |
| 96 | 96 | ||
| 97 | 97 | /** 1 for most images, 2 for hi-dpi/retina */ | |
| 98 | - public int pixelFactor; | ||
| 98 | + public int pixelDensity = 1; | ||
| 99 | 99 | ||
| 100 | 100 | /** Actual dimensions of pixels array, taking into account the 2x setting. */ | |
| 101 | 101 | public int pixelWidth; | |
@@ -210,7 +210,7 @@ public class PImage implements PConstants, Cloneable { | |||
| 210 | 210 | */ | |
| 211 | 211 | public PImage() { | |
| 212 | 212 | format = ARGB; // default to ARGB images for release 0116 | |
| 213 | - pixelFactor = 1; | ||
| 213 | + pixelDensity = 1; | ||
| 214 | 214 | } | |
| 215 | 215 | ||
| 216 | 216 | ||
@@ -266,10 +266,10 @@ public void init(int width, int height, int format, int factor) { // ignore | |||
| 266 | 266 | this.width = width; | |
| 267 | 267 | this.height = height; | |
| 268 | 268 | this.format = format; | |
| 269 | - this.pixelFactor = factor; | ||
| 269 | + this.pixelDensity = factor; | ||
| 270 | 270 | ||
| 271 | - pixelWidth = width * pixelFactor; | ||
| 272 | - pixelHeight = height * pixelFactor; | ||
| 271 | + pixelWidth = width * pixelDensity; | ||
| 272 | + pixelHeight = height * pixelDensity; | ||
| 273 | 273 | this.pixels = new int[pixelWidth * pixelHeight]; | |
| 274 | 274 | } | |
| 275 | 275 | ||
@@ -330,7 +330,7 @@ public PImage(Image img) { | |||
| 330 | 330 | pg.grabPixels(); | |
| 331 | 331 | } catch (InterruptedException e) { } | |
| 332 | 332 | } | |
| 333 | - pixelFactor = 1; | ||
| 333 | + pixelDensity = 1; | ||
| 334 | 334 | pixelWidth = width; | |
| 335 | 335 | pixelHeight = height; | |
| 336 | 336 | } | |
@@ -632,7 +632,7 @@ public void resize(int w, int h) { // ignore | |||
| 632 | 632 | } | |
| 633 | 633 | ||
| 634 | 634 | BufferedImage img = | |
| 635 | - shrinkImage((BufferedImage) getNative(), w*pixelFactor, h*pixelFactor); | ||
| 635 | + shrinkImage((BufferedImage) getNative(), w*pixelDensity, h*pixelDensity); | ||
| 636 | 636 | ||
| 637 | 637 | PImage temp = new PImage(img); | |
| 638 | 638 | this.pixelWidth = temp.width; | |
@@ -641,8 +641,8 @@ public void resize(int w, int h) { // ignore | |||
| 641 | 641 | // Get the resized pixel array | |
| 642 | 642 | this.pixels = temp.pixels; | |
| 643 | 643 | ||
| 644 | - this.width = pixelWidth / pixelFactor; | ||
| 645 | - this.height = pixelHeight / pixelFactor; | ||
| 644 | + this.width = pixelWidth / pixelDensity; | ||
| 645 | + this.height = pixelHeight / pixelDensity; | ||
| 646 | 646 | ||
| 647 | 647 | // Mark the pixels array as altered | |
| 648 | 648 | updatePixels(); | |
@@ -858,9 +858,9 @@ public PImage get(int x, int y, int w, int h) { | |||
| 858 | 858 | targetFormat = ARGB; | |
| 859 | 859 | } | |
| 860 | 860 | ||
| 861 | - PImage target = new PImage(targetWidth / pixelFactor, | ||
| 862 | - targetHeight / pixelFactor, | ||
| 863 | - targetFormat, pixelFactor); | ||
| 861 | + PImage target = new PImage(targetWidth / pixelDensity, | ||
| 862 | + targetHeight / pixelDensity, | ||
| 863 | + targetFormat, pixelDensity); | ||
| 864 | 864 | target.parent = parent; // parent may be null so can't use createImage() | |
| 865 | 865 | if (w > 0 && h > 0) { | |
| 866 | 866 | getImpl(x, y, w, h, target, targetX, targetY); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,6 +26,6 @@ public class PGraphics2D2X extends PGraphics2D { | |||
| 26 | 26 | ||
| 27 | 27 | public PGraphics2D2X() { | |
| 28 | 28 | super(); | |
| 29 | - pixelFactor = 2; | ||
| 29 | + pixelDensity = 2; | ||
| 30 | 30 | } | |
| 31 | 31 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,6 +26,6 @@ public class PGraphics3D2X extends PGraphics3D { | |||
| 26 | 26 | ||
| 27 | 27 | public PGraphics3D2X() { | |
| 28 | 28 | super(); | |
| 29 | - pixelFactor = 2; | ||
| 29 | + pixelDensity = 2; | ||
| 30 | 30 | } | |
| 31 | 31 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -706,7 +706,7 @@ public void removeCache(PImage image) { | |||
| 706 | 706 | ||
| 707 | 707 | ||
| 708 | 708 | public float getPixelScale() { | |
| 709 | - if (surfaceJOGL == null) return pixelFactor; | ||
| 709 | + if (surfaceJOGL == null) return pixelDensity; | ||
| 710 | 710 | else return surfaceJOGL.getPixelScale(); | |
| 711 | 711 | } | |
| 712 | 712 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments