Does G4P GWindow support pixelDensity() for retina display?

edited January 2018 in Library Questions

The text in a GWindow (using the G4P library) does render as well as the Processing window. This is the same problem we had before the pixelDensity() function was introduced. As pixelDensity() has to be called in setup() following size(), I cannot see how to call it when creating a GWindow. I've tried the P2D renderer for GWindow.getWindow and the results are even worse. Here's the example output of the Processing and G4P windows, screen shots scaled up by a factor of 2. processing window G4P window

The sketch which generated these is as follows

` /* * compares text of different sizes drawn in the Processing window using pixelDensity() (as on a Mac retina display) * and also in a GWindow from G4P * limits the drawing in both windows to once to avoid overplotting */

import g4p_controls.*; 

GWindow G4P_Window;
boolean drawn = false;
PFont font16;

void setup() {
  size(250, 100);
  pixelDensity(displayDensity());  //for retina display
  font16 = createFont("Dialog", 36, true);
  G4P_Window = GWindow.getWindow(this, "G4P Window", 100, 50, 250, 100, JAVA2D);  //even worse with P2D renderer
  G4P_Window.addDrawHandler(this, "G4P_WindowDraw");
  noLoop();
}

void draw() {
  background(0);
  fill(255);
  textFont(font16);
  textSize(8);
  text("This is in 8 point Dialog", 40, 20);
  textSize(10);
  text("This is in 10 point Dialog", 40, 40);
  textSize(12);
  text("This is in 12 point Dialog", 40, 60);
  textSize(14);
  text("This is in 14 point Dialog", 40, 80);
}

void G4P_WindowDraw(PApplet app, GWinData data) {
  if (!drawn) {
    app.background(0);
    app.fill(255);
    app.textFont(font16);
    app.textSize(8);
    app.text("This is in 8 point Dialog", 40, 20);
    app.textSize(10);
    app.text("This is in 10 point Dialog", 40, 40);
    app.textSize(12);
    app.text("This is in 12 point Dialog", 40, 60);
    app.textSize(14);
    app.text("This is in 14 point Dialog", 40, 80);
    drawn = true;  //limit to once only to avoid overplotting
  }
}

`

Answers

  • Answer ✓

    To correctly display a code block you need to make sure there is a blank line before and after the block. Then highlight the code and click on the C button or press cmd+O to indent the code. You can do this by editing your post, click on the 'gear wheel' and select edit.

    My iMac is too old to have a retina display so I can't test your code but I will take your word for it.

    You say the pixelDensity(...) has to be called in setup so can be done in the main sketch window. Unfortunately it can't be done in the GWindow because there is no setup method.

    Processing has never had native support for multiple windows so you have to rely on contributed libraries. G4P has provided multiple windows since Processing V1.5.1 but the event handling and renderers have changed significantly in P2 and then in P3 and G4P has been virtually rewritten to keep up to date.

    If you search the forum you will find ways of creating your own secondary window with P3, not as powerful as GWIndow but you maybe able to modify one of these to include pixelDensity.

    Without a Retina display I can't be sure if this will work but can you not increase the font size to compensate?

    HTH

  • Thanks. I'll try to create a secondary window. I've indented the code!

  • Found a solution at here and "Hiding a PApplet" in this Forum is also useful.

Sign In or Register to comment.