Java Code Examples for com.intellij.util.ui.UIUtil#isJreHiDPIEnabled()

The following examples show how to use com.intellij.util.ui.UIUtil#isJreHiDPIEnabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShadowPainter.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void fill(Graphics g, Icon pattern, int x, int y, int from, int to, boolean horizontally) {
  double scale = JBUI.sysScale((Graphics2D)g);
  if (UIUtil.isJreHiDPIEnabled() && Math.ceil(scale) > scale) {
    // Direct painting for fractional scale
    BufferedImage img = ImageUtil.toBufferedImage(IconUtil.toImage(pattern));
    int patternSize = horizontally ? img.getWidth() : img.getHeight();
    Graphics2D g2d = (Graphics2D)g.create();
    try {
      g2d.scale(1 / scale, 1 / scale);
      g2d.translate(x * scale, y * scale);
      for (int at = (int)Math.floor(from * scale); at < to * scale; at += patternSize) {
        if (horizontally) {
          g2d.drawImage(img, at, 0, null);
        }
        else {
          g2d.drawImage(img, 0, at, null);
        }
      }
    }
    finally {
      g2d.dispose();
    }
  }
  else {
    for (int at = from; at < to; at++) {
      if (horizontally) {
        pattern.paintIcon(null, g, x + at, y);
      }
      else {
        pattern.paintIcon(null, g, x, y + at);
      }
    }
  }
}
 
Example 2
Source File: SystemHealthMonitor.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void checkHiDPIMode() {
  // if switched from JRE-HiDPI to IDE-HiDPI
  boolean switchedHiDPIMode = SystemInfo.isJetBrainsJvm && "true".equalsIgnoreCase(System.getProperty("sun.java2d.uiScale.enabled")) && !UIUtil.isJreHiDPIEnabled();
  if (SystemInfo.isWindows && ((switchedHiDPIMode && JBUI.isHiDPI(JBUI.sysScale())) || RemoteDesktopService.isRemoteSession())) {
    showNotification(new KeyHyperlinkAdapter("ide.set.hidpi.mode"));
  }
}
 
Example 3
Source File: DesktopWindowManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean shouldConvert() {
  if (SystemInfo.isLinux || // JRE-managed HiDPI mode is not yet implemented (pending)
      SystemInfo.isMac)     // JRE-managed HiDPI mode is permanent
  {
    return false;
  }
  if (!UIUtil.isJreHiDPIEnabled()) return false; // device space equals user space
  return true;
}
 
Example 4
Source File: LinePainter2D.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Draws a polygon.
 *
 * @param g           the graphics
 * @param xPoints     the x polygon points
 * @param yPoints     the y polygon points
 * @param nPoints     the number of points
 * @param strokeType  the stroke type
 * @param strokeWidth the stroke width
 * @param valueAA     overrides current {@link RenderingHints#KEY_ANTIALIASING} to {@code valueAA}
 */
public static void paintPolygon(@Nonnull Graphics2D g, double[] xPoints, double[] yPoints, int nPoints, StrokeType strokeType, double strokeWidth, @Nonnull Object valueAA) {
  double x1, x2, y1, y2;
  boolean thickPixel = UIUtil.isJreHiDPIEnabled() && PaintUtil.devValue(strokeWidth, g) > 1;
  boolean prevStraight = nPoints <= 1 || isStraightLine(xPoints, yPoints, nPoints, nPoints);

  for (int p = 0; p < nPoints; p++) {
    x1 = xPoints[p];
    y1 = yPoints[p];
    x2 = xPoints[(p + 1) % nPoints];
    y2 = yPoints[(p + 1) % nPoints];
    boolean thisStraight = x1 == x2 || y1 == y2;
    // [tav] todo: mind the angle, the strokeWidth and the strokeType
    if (thickPixel && !thisStraight) {
      if (prevStraight) {
        x1 += 0.5;
        y1 += 0.5;
      }
      if (isStraightLine(xPoints, yPoints, p + 1, nPoints)) {
        x2 += 0.5;
        y2 += 0.5;
      }
    }
    prevStraight = thisStraight;
    paint(g, x1, y1, x2, y2, strokeType, strokeWidth, valueAA);
  }
}
 
Example 5
Source File: DimensionService.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * @return Pair(key, scale) where:
 * key is the HiDPI-aware key,
 * scale is the HiDPI-aware factor to transform size metrics.
 */
@Nonnull
private static Pair<String, Float> keyPair(String key, @Nullable Project project) {
  GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
  if (env.isHeadlessInstance()) {
    return new Pair<>(key + ".headless", 1f);
  }

  consulo.ui.Window uiWindow = null;
  final Component owner = IdeFocusManager.findInstance().getFocusOwner();
  if (owner != null) {
    uiWindow = TargetAWT.from(UIUtil.getParentOfType(JFrame.class, owner));
  }
  if (uiWindow == null) {
    uiWindow = WindowManager.getInstance().findVisibleWindow();
  }

  if (project != null && (uiWindow == null || (uiWindow.getUserData(IdeFrame.KEY) != null && project != uiWindow.getUserData(IdeFrame.KEY).getProject()))) {
    uiWindow = WindowManager.getInstance().getWindow(project);
  }

  Rectangle screen = new Rectangle(0, 0, 0, 0);
  GraphicsDevice gd = null;
  if (uiWindow != null) {
    Window awtWindow = TargetAWT.to(uiWindow);
    final Point topLeft = awtWindow.getLocation();
    Point center = new Point(topLeft.x + awtWindow.getWidth() / 2, topLeft.y + awtWindow.getHeight() / 2);
    for (GraphicsDevice device : env.getScreenDevices()) {
      Rectangle bounds = device.getDefaultConfiguration().getBounds();
      if (bounds.contains(center)) {
        screen = bounds;
        gd = device;
        break;
      }
    }
  }
  if (gd == null) {
    gd = env.getDefaultScreenDevice();
    screen = gd.getDefaultConfiguration().getBounds();
  }
  float scale = 1f;
  if (UIUtil.isJreHiDPIEnabled()) {
    scale = JBUIScale.sysScale(gd.getDefaultConfiguration());
    // normalize screen bounds
    screen.setBounds((int)Math.floor(screen.x * scale), (int)Math.floor(screen.y * scale), (int)Math.ceil(screen.width * scale), (int)Math.ceil(screen.height * scale));
  }
  String realKey = key + '.' + screen.x + '.' + screen.y + '.' + screen.width + '.' + screen.height;
  if (JBUI.isPixHiDPI(gd.getDefaultConfiguration())) {
    int dpi = ((int)(96 * JBUI.pixScale(gd.getDefaultConfiguration())));
    realKey += "@" + dpi + "dpi";
  }
  return new Pair<>(realKey, scale);
}
 
Example 6
Source File: UISettings.java    From consulo with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the default font scale, which depends on the HiDPI mode (see JBUI#ScaleType).
 * <p>
 * The font is represented:
 * - in relative (dpi-independent) points in the JRE-managed HiDPI mode, so the method returns 1.0f
 * - in absolute (dpi-dependent) points in the IDE-managed HiDPI mode, so the method returns the default screen scale
 *
 * @return the system font scale
 */
public static float getDefFontScale() {
  return UIUtil.isJreHiDPIEnabled() ? 1f : JBUI.sysScale();
}