some changes for android compatibility

This commit is contained in:
codeanticode
2013-09-19 11:35:03 -04:00
parent 3c4b6eea5b
commit 2f8af18ba6
4 changed files with 92 additions and 34 deletions
+20 -2
View File
@@ -24,6 +24,7 @@
package processing.opengl;
import processing.core.PApplet;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@@ -1882,6 +1883,23 @@ public abstract class PGL {
}
// TODO: the next three functions shouldn't be here...
protected int getFontAscent(Object font) {
return 0;
}
protected int getFontDescent(Object font) {
return 0;
}
protected int getTextWidth(Object font, char buffer[], int start, int stop) {
return 0;
}
///////////////////////////////////////////////////////////
// Tessellator interface
@@ -1912,7 +1930,7 @@ public abstract class PGL {
protected String tessError(int err) {
return "";
}
}
///////////////////////////////////////////////////////////
@@ -2424,7 +2442,7 @@ public abstract class PGL {
public abstract void linkProgram(int program);
public abstract void useProgram(int program);
public abstract void deleteProgram(int program);
public abstract String glGetActiveAttrib (int program, int index, IntBuffer size, IntBuffer type);
public abstract String getActiveAttrib(int program, int index, IntBuffer size, IntBuffer type);
public abstract int getAttribLocation(int program, String name);
public abstract void bindAttribLocation(int program, int index, String name);
public abstract int getUniformLocation(int program, String name);
+17 -30
View File
@@ -23,9 +23,6 @@
package processing.opengl;
import processing.core.*;
import java.awt.Font;
import java.awt.FontMetrics;
import java.net.URL;
import java.nio.*;
import java.util.*;
@@ -3254,43 +3251,33 @@ public class PGraphicsOpenGL extends PGraphics {
@Override
public float textAscent() {
if (textFont == null) {
defaultFontOrDeath("textAscent");
}
Font font = (Font) textFont.getNative();
if (font != null) {
FontMetrics metrics = parent.getFontMetrics(font);
return metrics.getAscent();
}
return super.textAscent();
if (textFont == null) defaultFontOrDeath("textAscent");
Object font = textFont.getNative();
float ascent = 0;
if (font != null) ascent = pgl.getFontAscent(font);
if (ascent == 0) ascent = super.textAscent();
return ascent;
}
@Override
public float textDescent() {
if (textFont == null) {
defaultFontOrDeath("textAscent");
}
Font font = (Font) textFont.getNative();
if (font != null) {
FontMetrics metrics = parent.getFontMetrics(font);
return metrics.getDescent();
}
return super.textDescent();
if (textFont == null) defaultFontOrDeath("textAscent");
Object font = textFont.getNative();
float descent = 0;
if (font != null) descent = pgl.getFontDescent(font);
if (descent == 0) descent = super.textDescent();
return descent;
}
@Override
protected float textWidthImpl(char buffer[], int start, int stop) {
Font font = (Font) textFont.getNative();
if (font != null) {
// maybe should use one of the newer/fancier functions for this?
int length = stop - start;
FontMetrics metrics = parent.getFontMetrics(font);
return metrics.charsWidth(buffer, start, length);
}
return super.textWidthImpl(buffer, start, stop);
Object font = textFont.getNative();
float twidth = 0;
if (font != null) twidth = pgl.getTextWidth(font, buffer, start, stop);
if (twidth == 0) twidth = super.textWidthImpl(buffer, start, stop);
return twidth;
}
+30 -1
View File
@@ -3,6 +3,7 @@ package processing.opengl;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.FontMetrics;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
@@ -941,6 +942,34 @@ public class PJOGL extends PGL {
}
///////////////////////////////////////////////////////////
// Utility functions
@Override
protected int getFontAscent(Object font) {
FontMetrics metrics = pg.parent.getFontMetrics((Font)font);
return metrics.getAscent();
}
@Override
protected int getFontDescent(Object font) {
FontMetrics metrics = pg.parent.getFontMetrics((Font)font);
return metrics.getDescent();
}
@Override
protected int getTextWidth(Object font, char buffer[], int start, int stop) {
// maybe should use one of the newer/fancier functions for this?
int length = stop - start;
FontMetrics metrics = pg.parent.getFontMetrics((Font)font);
return metrics.charsWidth(buffer, start, length);
}
///////////////////////////////////////////////////////////
// Tessellator
@@ -1816,7 +1845,7 @@ public class PJOGL extends PGL {
}
@Override
public String glGetActiveAttrib (int program, int index, IntBuffer size, IntBuffer type) {
public String getActiveAttrib(int program, int index, IntBuffer size, IntBuffer type) {
int[] tmp = {0, 0, 0};
byte[] namebuf = new byte[1024];
gl2.glGetActiveAttrib(program, index, 1024, tmp, 0, tmp, 1, tmp, 2, namebuf, 0);
@@ -27,6 +27,7 @@ import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.font.FontRenderContext;
@@ -332,6 +333,29 @@ public class PLWJGL extends PGL {
}
@Override
protected int getFontAscent(Object font) {
FontMetrics metrics = pg.parent.getFontMetrics((Font)font);
return metrics.getAscent();
}
@Override
protected int getFontDescent(Object font) {
FontMetrics metrics = pg.parent.getFontMetrics((Font)font);
return metrics.getDescent();
}
@Override
protected int getTextWidth(Object font, char buffer[], int start, int stop) {
// maybe should use one of the newer/fancier functions for this?
int length = stop - start;
FontMetrics metrics = pg.parent.getFontMetrics((Font)font);
return metrics.charsWidth(buffer, start, length);
}
///////////////////////////////////////////////////////////
// LWJGL event handling
@@ -1598,7 +1622,7 @@ public class PLWJGL extends PGL {
GL20.glDeleteProgram(program);
}
public String glGetActiveAttrib (int program, int index, IntBuffer size, IntBuffer type) {
public String getActiveAttrib (int program, int index, IntBuffer size, IntBuffer type) {
IntBuffer typeTmp = BufferUtils.createIntBuffer(2);
String name = GL20.glGetActiveAttrib(program, index, 256, typeTmp);
size.put(typeTmp.get(0));