@@ -73,7 +73,7 @@ namespace JuceDummyNamespace {} | |||
*/ | |||
#define JUCE_MAJOR_VERSION 1 | |||
#define JUCE_MINOR_VERSION 53 | |||
#define JUCE_BUILDNUMBER 34 | |||
#define JUCE_BUILDNUMBER 35 | |||
/** Current Juce version number. | |||
@@ -10010,14 +10010,14 @@ public: | |||
treated as empty strings | |||
@param numberOfStrings how many items there are in the array | |||
*/ | |||
StringArray (const juce_wchar* const* strings, int numberOfStrings); | |||
StringArray (const char* const* strings, int numberOfStrings); | |||
/** Creates a copy of an array of string literals. | |||
@param strings an array of strings to add. Null pointers in the array will be | |||
treated as empty strings | |||
@param numberOfStrings how many items there are in the array | |||
/** Creates a copy of a null-terminated array of string literals. | |||
Each item from the array passed-in is added, until it encounters a null pointer, | |||
at which point it stops. | |||
*/ | |||
StringArray (const char* const* strings, int numberOfStrings); | |||
explicit StringArray (const char* const* strings); | |||
/** Creates a copy of a null-terminated array of string literals. | |||
Each item from the array passed-in is added, until it encounters a null pointer, | |||
@@ -10025,12 +10025,27 @@ public: | |||
*/ | |||
explicit StringArray (const juce_wchar* const* strings); | |||
/** Creates a copy of a null-terminated array of string literals. | |||
/** Creates a copy of an array of string literals. | |||
@param strings an array of strings to add. Null pointers in the array will be | |||
treated as empty strings | |||
@param numberOfStrings how many items there are in the array | |||
*/ | |||
StringArray (const juce_wchar* const* strings, int numberOfStrings); | |||
#if ! JUCE_NATIVE_WCHAR_IS_UTF32 | |||
/** Creates a copy of a null-terminated array of string literals. | |||
Each item from the array passed-in is added, until it encounters a null pointer, | |||
at which point it stops. | |||
*/ | |||
explicit StringArray (const char* const* strings); | |||
explicit StringArray (const wchar_t* const* strings); | |||
/** Creates a copy of an array of string literals. | |||
@param strings an array of strings to add. Null pointers in the array will be | |||
treated as empty strings | |||
@param numberOfStrings how many items there are in the array | |||
*/ | |||
StringArray (const wchar_t* const* strings, int numberOfStrings); | |||
#endif | |||
/** Destructor. */ | |||
~StringArray(); | |||
@@ -25870,6 +25885,7 @@ private: | |||
/*** End of inlined file: juce_Path.h ***/ | |||
class Font; | |||
class EdgeTable; | |||
/** A typeface represents a size-independent font. | |||
@@ -25944,6 +25960,9 @@ public: | |||
*/ | |||
virtual bool getOutlineForGlyph (int glyphNumber, Path& path) = 0; | |||
/** Returns a new EdgeTable that contains the path for the givem glyph, with the specified transform applied. */ | |||
virtual EdgeTable* getEdgeTableForGlyph (int glyphNumber, const AffineTransform& transform) = 0; | |||
/** Returns true if the typeface uses hinting. */ | |||
virtual bool isHinted() const { return false; } | |||
@@ -26039,6 +26058,7 @@ public: | |||
float getStringWidth (const String& text); | |||
void getGlyphPositions (const String& text, Array <int>& glyphs, Array<float>& xOffsets); | |||
bool getOutlineForGlyph (int glyphNumber, Path& path); | |||
EdgeTable* getEdgeTableForGlyph (int glyphNumber, const AffineTransform& transform); | |||
int getGlyphForCharacter (juce_wchar character); | |||
protected: | |||
@@ -33,7 +33,7 @@ | |||
*/ | |||
#define JUCE_MAJOR_VERSION 1 | |||
#define JUCE_MINOR_VERSION 53 | |||
#define JUCE_BUILDNUMBER 34 | |||
#define JUCE_BUILDNUMBER 35 | |||
/** Current Juce version number. | |||
@@ -2405,23 +2405,14 @@ public: | |||
font = newFont; | |||
snapToIntegerCoordinate = newFont.getTypeface()->isHinted(); | |||
glyph = glyphNumber; | |||
edgeTable = 0; | |||
Path glyphPath; | |||
font.getTypeface()->getOutlineForGlyph (glyphNumber, glyphPath); | |||
if (! glyphPath.isEmpty()) | |||
{ | |||
const float fontHeight = font.getHeight(); | |||
const AffineTransform transform (AffineTransform::scale (fontHeight * font.getHorizontalScale(), fontHeight) | |||
#if JUCE_MAC || JUCE_IOS | |||
.translated (0.0f, -0.5f) | |||
#endif | |||
); | |||
edgeTable = new EdgeTable (glyphPath.getBoundsTransformed (transform).getSmallestIntegerContainer().expanded (1, 0), | |||
glyphPath, transform); | |||
} | |||
const float fontHeight = font.getHeight(); | |||
edgeTable = font.getTypeface()->getEdgeTableForGlyph (glyphNumber, | |||
AffineTransform::scale (fontHeight * font.getHorizontalScale(), fontHeight) | |||
#if JUCE_MAC || JUCE_IOS | |||
.translated (0.0f, -0.5f) | |||
#endif | |||
); | |||
} | |||
Font font; | |||
@@ -2531,9 +2522,12 @@ void LowLevelGraphicsSoftwareRenderer::drawGlyph (int glyphNumber, const AffineT | |||
} | |||
else | |||
{ | |||
Path p; | |||
f.getTypeface()->getOutlineForGlyph (glyphNumber, p); | |||
fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight()).followedBy (transform)); | |||
const float fontHeight = f.getHeight(); | |||
const ScopedPointer<EdgeTable> et (f.getTypeface()->getEdgeTableForGlyph (glyphNumber, | |||
AffineTransform::scale (fontHeight * f.getHorizontalScale(), fontHeight) | |||
.followedBy (transform))); | |||
if (et != 0) | |||
currentState->fillEdgeTable (*et, 0.0f, 0); | |||
} | |||
} | |||
@@ -29,6 +29,7 @@ BEGIN_JUCE_NAMESPACE | |||
#include "juce_Typeface.h" | |||
#include "juce_Font.h" | |||
#include "../contexts/juce_EdgeTable.h" | |||
#include "../../../io/streams/juce_GZIPDecompressorInputStream.h" | |||
#include "../../../io/streams/juce_GZIPCompressorOutputStream.h" | |||
#include "../../../io/streams/juce_BufferedInputStream.h" | |||
@@ -52,6 +53,7 @@ const Typeface::Ptr Typeface::getFallbackTypeface() | |||
return t; | |||
} | |||
//============================================================================== | |||
class CustomTypeface::GlyphInfo | |||
{ | |||
@@ -412,4 +414,24 @@ bool CustomTypeface::getOutlineForGlyph (int glyphNumber, Path& path) | |||
return false; | |||
} | |||
EdgeTable* CustomTypeface::getEdgeTableForGlyph (int glyphNumber, const AffineTransform& transform) | |||
{ | |||
const GlyphInfo* const glyph = findGlyph ((juce_wchar) glyphNumber, true); | |||
if (glyph == 0 && ! isFallbackFont) | |||
{ | |||
const Typeface::Ptr fallbackTypeface (Typeface::getFallbackTypeface()); | |||
if (fallbackTypeface != 0) | |||
return fallbackTypeface->getEdgeTableForGlyph (glyphNumber, transform); | |||
} | |||
if (glyph != 0 && ! glyph->path.isEmpty()) | |||
return new EdgeTable (glyph->path.getBoundsTransformed (transform).getSmallestIntegerContainer().expanded (1, 0), | |||
glyph->path, transform); | |||
return 0; | |||
} | |||
END_JUCE_NAMESPACE |
@@ -32,6 +32,7 @@ | |||
#include "../../../io/streams/juce_OutputStream.h" | |||
#include "../geometry/juce_Path.h" | |||
class Font; | |||
class EdgeTable; | |||
//============================================================================== | |||
@@ -111,6 +112,9 @@ public: | |||
*/ | |||
virtual bool getOutlineForGlyph (int glyphNumber, Path& path) = 0; | |||
/** Returns a new EdgeTable that contains the path for the givem glyph, with the specified transform applied. */ | |||
virtual EdgeTable* getEdgeTableForGlyph (int glyphNumber, const AffineTransform& transform) = 0; | |||
/** Returns true if the typeface uses hinting. */ | |||
virtual bool isHinted() const { return false; } | |||
@@ -210,6 +214,7 @@ public: | |||
float getStringWidth (const String& text); | |||
void getGlyphPositions (const String& text, Array <int>& glyphs, Array<float>& xOffsets); | |||
bool getOutlineForGlyph (int glyphNumber, Path& path); | |||
EdgeTable* getEdgeTableForGlyph (int glyphNumber, const AffineTransform& transform); | |||
int getGlyphForCharacter (juce_wchar character); | |||
protected: | |||
@@ -32,6 +32,12 @@ import android.view.ViewGroup; | |||
import android.view.Display; | |||
import android.view.WindowManager; | |||
import android.graphics.Paint; | |||
import android.graphics.Canvas; | |||
import android.graphics.Path; | |||
import android.graphics.Bitmap; | |||
import android.graphics.Matrix; | |||
import android.graphics.RectF; | |||
import android.graphics.Rect; | |||
import android.text.ClipboardManager; | |||
import com.juce.ComponentPeerView; | |||
@@ -153,95 +159,37 @@ public final class JuceAppActivity extends Activity | |||
} | |||
//============================================================================== | |||
/*class PathGrabber extends Path | |||
public final int[] renderGlyph (char glyph, Paint paint, Matrix matrix, Rect bounds) | |||
{ | |||
public PathGrabber() | |||
{ | |||
pathString = new StringBuilder(); | |||
} | |||
Path p = new Path(); | |||
paint.getTextPath (String.valueOf (glyph), 0, 1, 0.0f, 0.0f, p); | |||
@Override | |||
public void addPath (Path src) | |||
{ | |||
} | |||
RectF boundsF = new RectF(); | |||
p.computeBounds (boundsF, true); | |||
matrix.mapRect (boundsF); | |||
@Override | |||
public void addPath (Path src, float dx, float dy) | |||
{ | |||
} | |||
boundsF.roundOut (bounds); | |||
bounds.left--; | |||
bounds.right++; | |||
@Override | |||
public void close() | |||
{ | |||
pathString.append ('c'); | |||
} | |||
final int w = bounds.width(); | |||
final int h = bounds.height(); | |||
@Override | |||
public void moveTo (float x, float y) | |||
{ | |||
pathString.append ('m'); | |||
pathString.append (String.valueOf (x)); | |||
pathString.append (String.valueOf (y)); | |||
} | |||
Bitmap bm = Bitmap.createBitmap (w, h, Bitmap.Config.ARGB_8888); | |||
@Override | |||
public void lineTo (float x, float y) | |||
{ | |||
pathString.append ('l'); | |||
pathString.append (String.valueOf (x)); | |||
pathString.append (String.valueOf (y)); | |||
} | |||
Canvas c = new Canvas (bm); | |||
matrix.postTranslate (-bounds.left, -bounds.top); | |||
c.setMatrix (matrix); | |||
c.drawPath (p, paint); | |||
@Override | |||
public void quadTo (float x1, float y1, float x2, float y2) | |||
{ | |||
pathString.append ('q'); | |||
pathString.append (String.valueOf (x1)); | |||
pathString.append (String.valueOf (y1)); | |||
pathString.append (String.valueOf (x2)); | |||
pathString.append (String.valueOf (y2)); | |||
} | |||
int sizeNeeded = w * h; | |||
if (cachedRenderArray.length < sizeNeeded) | |||
cachedRenderArray = new int [sizeNeeded]; | |||
@Override | |||
public void cubicTo (float x1, float y1, float x2, float y2, float x3, float y3) | |||
{ | |||
pathString.append ('b'); | |||
pathString.append (String.valueOf (x1)); | |||
pathString.append (String.valueOf (y1)); | |||
pathString.append (String.valueOf (x2)); | |||
pathString.append (String.valueOf (y2)); | |||
pathString.append (String.valueOf (x3)); | |||
pathString.append (String.valueOf (y3)); | |||
} | |||
@Override | |||
public void reset() | |||
{ | |||
rewind(); | |||
} | |||
@Override | |||
public void rewind() | |||
{ | |||
pathString.setLength (0); | |||
} | |||
public String getJucePath() | |||
{ | |||
if (getFillType() == FillType.EVEN_ODD) | |||
return "z" + pathString.toString(); | |||
else | |||
return "n" + pathString.toString(); | |||
} | |||
private StringBuilder pathString; | |||
}*/ | |||
public String createPathForGlyph (Paint paint, char c) | |||
{ | |||
/*PathGrabber pg = new PathGrabber(); | |||
paint.getTextPath (String.valueOf (c), 0, 1, 0, 0, pg); | |||
return pg.getJucePath();*/ | |||
return ""; | |||
bm.getPixels (cachedRenderArray, 0, w, 0, 0, w, h); | |||
bm.recycle(); | |||
return cachedRenderArray; | |||
} | |||
private int[] cachedRenderArray = new int [256]; | |||
} |
@@ -63,14 +63,18 @@ public: | |||
if (font.isBold()) flags = 1; | |||
if (font.isItalic()) flags += 2; | |||
JNIEnv* env = getEnv(); | |||
File fontFile (File ("/system/fonts").getChildFile (name).withFileExtension (".ttf")); | |||
if (fontFile.exists()) | |||
typeface = GlobalRef (getEnv()->CallStaticObjectMethod (android.typefaceClass, android.createFromFile, | |||
javaString (fontFile.getFullPathName()).get())); | |||
typeface = GlobalRef (env->CallStaticObjectMethod (android.typefaceClass, android.createFromFile, | |||
javaString (fontFile.getFullPathName()).get())); | |||
else | |||
typeface = GlobalRef (getEnv()->CallStaticObjectMethod (android.typefaceClass, android.create, | |||
javaString (getName()).get(), flags)); | |||
typeface = GlobalRef (env->CallStaticObjectMethod (android.typefaceClass, android.create, | |||
javaString (getName()).get(), flags)); | |||
rect = GlobalRef (env->NewObject (android.rectClass, android.rectConstructor, 0, 0, 0, 0)); | |||
paint = GlobalRef (android.createPaint (Graphics::highResamplingQuality)); | |||
const LocalRef<jobject> ignored (paint.callObjectMethod (android.setTypeface, typeface.get())); | |||
@@ -81,7 +85,7 @@ public: | |||
descent = paint.callFloatMethod (android.descent) / standardSize; | |||
const float height = ascent + descent; | |||
unitsToHeightScaleFactor = 1.0f / (height * standardSize); | |||
unitsToHeightScaleFactor = 1.0f / 256.0f;//(height * standardSize); | |||
} | |||
float getAscent() const { return ascent; } | |||
@@ -131,19 +135,54 @@ public: | |||
} | |||
} | |||
bool getOutlineForGlyph (int glyphNumber, Path& destPath) | |||
bool getOutlineForGlyph (int /*glyphNumber*/, Path& /*destPath*/) | |||
{ | |||
LocalRef<jstring> s ((jstring) android.activity.callObjectMethod (android.createPathForGlyph, paint.get(), (jchar) glyphNumber)); | |||
return false; | |||
} | |||
EdgeTable* getEdgeTableForGlyph (int glyphNumber, const AffineTransform& t) | |||
{ | |||
JNIEnv* env = getEnv(); | |||
jobject matrix = android.createMatrix (env, AffineTransform::scale (unitsToHeightScaleFactor, unitsToHeightScaleFactor).followedBy (t)); | |||
jintArray maskData = (jintArray) android.activity.callObjectMethod (android.renderGlyph, (jchar) glyphNumber, paint.get(), matrix, rect.get()); | |||
env->DeleteLocalRef (matrix); | |||
if (s == 0) | |||
return false; | |||
const int left = env->GetIntField (rect.get(), android.rectLeft); | |||
const int top = env->GetIntField (rect.get(), android.rectTop); | |||
const int right = env->GetIntField (rect.get(), android.rectRight); | |||
const int bottom = env->GetIntField (rect.get(), android.rectBottom); | |||
const Rectangle<int> bounds (left, top, right - left, bottom - top); | |||
if (bounds.isEmpty()) | |||
return 0; | |||
jint* const maskDataElements = env->GetIntArrayElements (maskData, 0); | |||
EdgeTable* et = new EdgeTable (bounds); | |||
const jint* mask = maskDataElements; | |||
for (int y = top; y < bottom; ++y) | |||
{ | |||
#if JUCE_LITTLE_ENDIAN | |||
const uint8* const lineBytes = ((const uint8*) mask) + 3; | |||
#else | |||
const uint8* const lineBytes = (const uint8*) mask; | |||
#endif | |||
et->clipLineToMask (left, y, lineBytes, 4, bounds.getWidth()); | |||
mask += bounds.getWidth(); | |||
} | |||
const String ourString (juceString (s)); | |||
destPath.restoreFromString (ourString); | |||
return ourString.isNotEmpty(); | |||
env->ReleaseIntArrayElements (maskData, maskDataElements, 0); | |||
env->DeleteLocalRef (maskData); | |||
return et; | |||
} | |||
GlobalRef typeface, paint; | |||
GlobalRef typeface, paint, rect; | |||
float ascent, descent, unitsToHeightScaleFactor; | |||
private: | |||
@@ -27,18 +27,16 @@ | |||
// compiled on its own). | |||
#if JUCE_INCLUDED_FILE | |||
#if USE_ANDROID_CANVAS | |||
//============================================================================== | |||
class AndroidImage : public Image::SharedImage | |||
{ | |||
public: | |||
//============================================================================== | |||
AndroidImage (const int width_, const int height_, const bool clearImage) | |||
: Image::SharedImage (Image::ARGB, width_, height_) | |||
: Image::SharedImage (Image::ARGB, width_, height_), | |||
bitmap (createBitmap (width_, height_, false)) | |||
{ | |||
JNIEnv* env = getEnv(); | |||
jobject mode = env->GetStaticObjectField (android.bitmapConfigClass, android.ARGB_8888); | |||
bitmap = GlobalRef (env->CallStaticObjectMethod (android.bitmapClass, android.createBitmap, width_, height_, mode)); | |||
env->DeleteLocalRef (mode); | |||
} | |||
AndroidImage (const int width_, const int height_, const GlobalRef& bitmap_) | |||
@@ -49,7 +47,8 @@ public: | |||
~AndroidImage() | |||
{ | |||
bitmap.callVoidMethod (android.recycle); | |||
if (bitmap != 0) | |||
bitmap.callVoidMethod (android.recycle); | |||
} | |||
Image::ImageType getType() const { return Image::NativeImage; } | |||
@@ -73,6 +72,15 @@ public: | |||
return new AndroidImage (width, height, newCopy); | |||
} | |||
static jobject createBitmap (int width, int height, bool asSingleChannel) | |||
{ | |||
JNIEnv* env = getEnv(); | |||
jobject mode = env->GetStaticObjectField (android.bitmapConfigClass, asSingleChannel ? android.ALPHA_8 : android.ARGB_8888); | |||
jobject result = env->CallStaticObjectMethod (android.bitmapClass, android.createBitmap, width, height, mode); | |||
env->DeleteLocalRef (mode); | |||
return result; | |||
} | |||
//============================================================================== | |||
GlobalRef bitmap; | |||
@@ -142,37 +150,49 @@ private: | |||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AndroidImage); | |||
}; | |||
#endif | |||
Image::SharedImage* Image::SharedImage::createNativeImage (PixelFormat format, int width, int height, bool clearImage) | |||
{ | |||
if (format == Image::SingleChannel) | |||
return createSoftwareImage (format, width, height, clearImage); | |||
else | |||
#if USE_ANDROID_CANVAS | |||
if (format != Image::SingleChannel) | |||
return new AndroidImage (width, height, clearImage); | |||
#endif | |||
return createSoftwareImage (format, width, height, clearImage); | |||
} | |||
#if USE_ANDROID_CANVAS | |||
//============================================================================== | |||
class AndroidLowLevelGraphicsContext : public LowLevelGraphicsContext | |||
{ | |||
public: | |||
AndroidLowLevelGraphicsContext (jobject canvas_) | |||
: canvas (canvas_), | |||
currentState (new SavedState()) | |||
: originalCanvas (canvas_), | |||
currentState (new SavedState (canvas_)) | |||
{ | |||
setFill (Colours::black); | |||
} | |||
~AndroidLowLevelGraphicsContext() | |||
{ | |||
while (stateStack.size() > 0) | |||
restoreState(); | |||
currentState->flattenImageClippingLayer (originalCanvas); | |||
} | |||
bool isVectorDevice() const { return false; } | |||
//============================================================================== | |||
void setOrigin (int x, int y) | |||
{ | |||
canvas.callVoidMethod (android.translate, (float) x, (float) y); | |||
getCanvas().callVoidMethod (android.translate, (float) x, (float) y); | |||
} | |||
void addTransform (const AffineTransform& transform) | |||
{ | |||
canvas.callVoidMethod (android.concat, createMatrix (getEnv(), transform).get()); | |||
getCanvas().callVoidMethod (android.concat, createMatrixRef (getEnv(), transform).get()); | |||
} | |||
float getScaleFactor() | |||
@@ -182,7 +202,7 @@ public: | |||
bool clipToRectangle (const Rectangle<int>& r) | |||
{ | |||
return canvas.callBooleanMethod (android.clipRect, (float) r.getX(), (float) r.getY(), (float) r.getRight(), (float) r.getBottom()); | |||
return getCanvas().callBooleanMethod (android.clipRect, (float) r.getX(), (float) r.getY(), (float) r.getRight(), (float) r.getBottom()); | |||
} | |||
bool clipToRectangleList (const RectangleList& clipRegion) | |||
@@ -198,18 +218,51 @@ public: | |||
void excludeClipRectangle (const Rectangle<int>& r) | |||
{ | |||
android.activity.callVoidMethod (android.excludeClipRegion, canvas.get(), | |||
android.activity.callVoidMethod (android.excludeClipRegion, getCanvas().get(), | |||
(float) r.getX(), (float) r.getY(), (float) r.getRight(), (float) r.getBottom()); | |||
} | |||
void clipToPath (const Path& path, const AffineTransform& transform) | |||
{ | |||
(void) canvas.callBooleanMethod (android.clipPath, createPath (getEnv(), path, transform).get()); | |||
(void) getCanvas().callBooleanMethod (android.clipPath, createPath (getEnv(), path, transform).get()); | |||
} | |||
void clipToImageAlpha (const Image& sourceImage, const AffineTransform& transform) | |||
{ | |||
// TODO xxx | |||
// XXX couldn't get image clipping to work... | |||
JNIEnv* env = getEnv(); | |||
{ | |||
Path p; | |||
p.addRectangle (sourceImage.getBounds().toFloat()); | |||
clipToPath (p, transform); | |||
} | |||
Rectangle<int> bounds (getClipBounds()); | |||
jobject temporaryLayerBitmap = AndroidImage::createBitmap (bounds.getWidth(), bounds.getHeight(), false); | |||
jobject temporaryCanvas = env->NewObject (android.canvasClass, android.canvasBitmapConstructor, temporaryLayerBitmap); | |||
setFill (Colours::red); | |||
env->CallVoidMethod (temporaryCanvas, android.drawRect, | |||
(jfloat) 20, (jfloat) 20, (jfloat) 300, (jfloat) 200, | |||
getCurrentPaint()); | |||
env->CallVoidMethod (temporaryCanvas, android.translate, | |||
(jfloat) -bounds.getX(), (jfloat) -bounds.getY()); | |||
Image maskImage (Image::SingleChannel, bounds.getWidth(), bounds.getHeight(), true); | |||
{ | |||
Graphics g (maskImage); | |||
g.setOrigin (-bounds.getWidth(), -bounds.getHeight()); | |||
g.drawImageTransformed (sourceImage, transform); | |||
} | |||
SavedState* const top = stateStack.getLast(); | |||
currentState->clipToImage (top != 0 ? top->canvas.get() : originalCanvas, | |||
temporaryCanvas, temporaryLayerBitmap, maskImage, | |||
bounds.getX(), bounds.getY()); | |||
} | |||
bool clipRegionIntersects (const Rectangle<int>& r) | |||
@@ -220,7 +273,7 @@ public: | |||
const Rectangle<int> getClipBounds() const | |||
{ | |||
JNIEnv* env = getEnv(); | |||
jobject rect = canvas.callObjectMethod (android.getClipBounds2); | |||
jobject rect = getCanvas().callObjectMethod (android.getClipBounds2); | |||
const int left = env->GetIntField (rect, android.rectLeft); | |||
const int top = env->GetIntField (rect, android.rectTop); | |||
@@ -234,7 +287,7 @@ public: | |||
bool isClipEmpty() const | |||
{ | |||
LocalRef<jobject> tempRect (getEnv()->NewObject (android.rectClass, android.rectConstructor, 0, 0, 0, 0)); | |||
return ! canvas.callBooleanMethod (android.getClipBounds, tempRect.get()); | |||
return ! getCanvas().callBooleanMethod (android.getClipBounds, tempRect.get()); | |||
} | |||
//============================================================================== | |||
@@ -256,15 +309,15 @@ public: | |||
//============================================================================== | |||
void fillRect (const Rectangle<int>& r, bool replaceExistingContents) | |||
{ | |||
canvas.callVoidMethod (android.drawRect, | |||
(float) r.getX(), (float) r.getY(), (float) r.getRight(), (float) r.getBottom(), | |||
getCurrentPaint()); | |||
getCanvas().callVoidMethod (android.drawRect, | |||
(float) r.getX(), (float) r.getY(), (float) r.getRight(), (float) r.getBottom(), | |||
getCurrentPaint()); | |||
} | |||
void fillPath (const Path& path, const AffineTransform& transform) | |||
{ | |||
canvas.callVoidMethod (android.drawPath, createPath (getEnv(), path, transform).get(), | |||
getCurrentPaint()); | |||
getCanvas().callVoidMethod (android.drawPath, createPath (getEnv(), path, transform).get(), | |||
getCurrentPaint()); | |||
} | |||
void drawImage (const Image& sourceImage, const AffineTransform& transform, bool fillEntireClipAsTiles) | |||
@@ -274,8 +327,8 @@ public: | |||
if (androidImage != 0) | |||
{ | |||
JNIEnv* env = getEnv(); | |||
canvas.callVoidMethod (android.drawBitmap, androidImage->bitmap.get(), | |||
createMatrix (env, transform).get(), getImagePaint()); | |||
getCanvas().callVoidMethod (android.drawBitmap, androidImage->bitmap.get(), | |||
createMatrixRef (env, transform).get(), getImagePaint()); | |||
} | |||
else | |||
{ | |||
@@ -307,11 +360,11 @@ public: | |||
dstLine += bm.width; | |||
} | |||
canvas.callVoidMethod (android.drawMemoryBitmap, imageData, 0, bm.width, | |||
transform.getTranslationX(), transform.getTranslationY(), | |||
bm.width, bm.height, true, getImagePaint()); | |||
env->ReleaseIntArrayElements (imageData, dest, 0); | |||
getCanvas().callVoidMethod (android.drawMemoryBitmap, imageData, 0, bm.width, | |||
transform.getTranslationX(), transform.getTranslationY(), | |||
bm.width, bm.height, true, getImagePaint()); | |||
env->DeleteLocalRef (imageData); | |||
} | |||
} | |||
@@ -327,19 +380,18 @@ public: | |||
void drawLine (const Line <float>& line) | |||
{ | |||
canvas.callVoidMethod (android.drawLine, line.getStartX(), line.getStartY(), | |||
line.getEndX(), line.getEndY(), | |||
getCurrentPaint()); | |||
getCanvas().callVoidMethod (android.drawLine, line.getStartX(), line.getStartY(), | |||
line.getEndX(), line.getEndY(), getCurrentPaint()); | |||
} | |||
void drawVerticalLine (int x, float top, float bottom) | |||
{ | |||
canvas.callVoidMethod (android.drawRect, (float) x, top, x + 1.0f, bottom, getCurrentPaint()); | |||
getCanvas().callVoidMethod (android.drawRect, (float) x, top, x + 1.0f, bottom, getCurrentPaint()); | |||
} | |||
void drawHorizontalLine (int y, float left, float right) | |||
{ | |||
canvas.callVoidMethod (android.drawRect, left, (float) y, right, y + 1.0f, getCurrentPaint()); | |||
getCanvas().callVoidMethod (android.drawRect, left, (float) y, right, y + 1.0f, getCurrentPaint()); | |||
} | |||
void setFont (const Font& newFont) | |||
@@ -360,9 +412,9 @@ public: | |||
{ | |||
if (transform.isOnlyTranslation()) | |||
{ | |||
canvas.callVoidMethod (android.drawText, javaStringFromChar ((juce_wchar) glyphNumber).get(), | |||
transform.getTranslationX(), transform.getTranslationY(), | |||
currentState->getPaintForTypeface()); | |||
getCanvas().callVoidMethod (android.drawText, javaStringFromChar ((juce_wchar) glyphNumber).get(), | |||
transform.getTranslationX(), transform.getTranslationY(), | |||
currentState->getPaintForTypeface()); | |||
} | |||
else | |||
{ | |||
@@ -376,18 +428,18 @@ public: | |||
//============================================================================== | |||
void saveState() | |||
{ | |||
(void) canvas.callIntMethod (android.save); | |||
(void) getCanvas().callIntMethod (android.save); | |||
stateStack.add (new SavedState (*currentState)); | |||
} | |||
void restoreState() | |||
{ | |||
canvas.callVoidMethod (android.restore); | |||
SavedState* const top = stateStack.getLast(); | |||
if (top != 0) | |||
{ | |||
currentState->flattenImageClippingLayer (top->canvas); | |||
currentState = top; | |||
stateStack.removeLast (1, false); | |||
} | |||
@@ -395,19 +447,21 @@ public: | |||
{ | |||
jassertfalse; // trying to pop with an empty stack! | |||
} | |||
getCanvas().callVoidMethod (android.restore); | |||
} | |||
void beginTransparencyLayer (float opacity) | |||
{ | |||
Rectangle<int> clip (getClipBounds()); | |||
(void) canvas.callIntMethod (android.saveLayerAlpha, | |||
(float) clip.getX(), | |||
(float) clip.getY(), | |||
(float) clip.getRight(), | |||
(float) clip.getBottom(), | |||
jlimit (0, 255, roundToInt (opacity * 255.0f)), | |||
31 /*ALL_SAVE_FLAG*/); | |||
(void) getCanvas().callIntMethod (android.saveLayerAlpha, | |||
(float) clip.getX(), | |||
(float) clip.getY(), | |||
(float) clip.getRight(), | |||
(float) clip.getBottom(), | |||
jlimit (0, 255, roundToInt (opacity * 255.0f)), | |||
31 /*ALL_SAVE_FLAG*/); | |||
stateStack.add (new SavedState (*currentState)); | |||
} | |||
@@ -417,18 +471,19 @@ public: | |||
restoreState(); | |||
} | |||
//============================================================================== | |||
class SavedState | |||
{ | |||
public: | |||
SavedState() | |||
: font (1.0f), quality (Graphics::highResamplingQuality), | |||
SavedState (jobject canvas_) | |||
: canvas (canvas_), font (1.0f), quality (Graphics::highResamplingQuality), | |||
fillNeedsUpdate (true), typefaceNeedsUpdate (true) | |||
{ | |||
} | |||
SavedState (const SavedState& other) | |||
: fillType (other.fillType), font (other.font), quality (other.quality), | |||
fillNeedsUpdate (true), typefaceNeedsUpdate (true) | |||
: canvas (other.canvas), fillType (other.fillType), font (other.font), | |||
quality (other.quality), fillNeedsUpdate (true), typefaceNeedsUpdate (true) | |||
{ | |||
} | |||
@@ -517,14 +572,14 @@ public: | |||
env->DeleteLocalRef (coloursArray); | |||
env->DeleteLocalRef (positionsArray); | |||
env->CallVoidMethod (shader, android.setLocalMatrix, createMatrix (env, fillType.transform).get()); | |||
env->CallVoidMethod (shader, android.setLocalMatrix, createMatrixRef (env, fillType.transform).get()); | |||
env->DeleteLocalRef (paint.callObjectMethod (android.setShader, shader)); | |||
env->DeleteLocalRef (shader); | |||
} | |||
else | |||
{ | |||
// TODO xxx | |||
} | |||
} | |||
@@ -567,19 +622,101 @@ public: | |||
return p; | |||
} | |||
void flattenImageClippingLayer (jobject previousCanvas) | |||
{ | |||
// XXX couldn't get image clipping to work... | |||
if (temporaryLayerBitmap != 0) | |||
{ | |||
JNIEnv* env = getEnv(); | |||
jobject tileMode = env->GetStaticObjectField (android.shaderTileModeClass, android.clampMode); | |||
jobject shader = env->NewObject (android.bitmapShaderClass, android.bitmapShaderConstructor, | |||
temporaryLayerBitmap.get(), tileMode, tileMode); | |||
env->DeleteLocalRef (tileMode); | |||
jobject compositingPaint = android.createPaint (quality); | |||
env->CallObjectMethod (compositingPaint, android.setShader, shader); | |||
env->DeleteLocalRef (shader); | |||
LocalRef<jobject> maskBitmap (createAlphaBitmap (env, maskImage)); | |||
maskImage = Image::null; | |||
env->CallVoidMethod (previousCanvas, android.drawBitmapAt, | |||
maskBitmap.get(), (jfloat) maskLayerX, (jfloat) maskLayerY, compositingPaint); | |||
env->DeleteLocalRef (compositingPaint); | |||
canvas = GlobalRef (previousCanvas); | |||
env->CallVoidMethod (temporaryLayerBitmap.get(), android.recycle); | |||
env->CallVoidMethod (maskBitmap.get(), android.recycle); | |||
temporaryLayerBitmap.clear(); | |||
} | |||
} | |||
void clipToImage (jobject previousCanvas, | |||
jobject temporaryCanvas, jobject temporaryLayerBitmap_, | |||
const Image& maskImage_, | |||
int maskLayerX_, int maskLayerY_) | |||
{ | |||
// XXX couldn't get image clipping to work... | |||
flattenImageClippingLayer (previousCanvas); | |||
maskLayerX = maskLayerX_; | |||
maskLayerY = maskLayerY_; | |||
canvas = GlobalRef (temporaryCanvas); | |||
temporaryLayerBitmap = GlobalRef (temporaryLayerBitmap_); | |||
maskImage = maskImage_; | |||
} | |||
static jobject createAlphaBitmap (JNIEnv* env, const Image& image) | |||
{ | |||
Image::BitmapData bm (image, Image::BitmapData::readOnly); | |||
jobject bitmap = AndroidImage::createBitmap (bm.width, bm.height, true); | |||
jintArray intArray = env->NewIntArray (bm.width * bm.height); | |||
jint* const dest = env->GetIntArrayElements (intArray, 0); | |||
for (int yy = 0; yy < bm.height; ++yy) | |||
{ | |||
PixelAlpha* src = (PixelAlpha*) bm.getLinePointer (yy); | |||
jint* destLine = dest + yy * bm.width; | |||
for (int xx = 0; xx < bm.width; ++xx) | |||
{ | |||
destLine[xx] = src->getAlpha(); | |||
src = addBytesToPointer (src, bm.pixelStride); | |||
} | |||
} | |||
env->ReleaseIntArrayElements (intArray, (jint*) dest, 0); | |||
env->CallVoidMethod (bitmap, android.setPixels, intArray, 0, bm.width, 0, 0, bm.width, bm.height); | |||
env->DeleteLocalRef (intArray); | |||
return bitmap; | |||
} | |||
GlobalRef canvas, temporaryLayerBitmap; | |||
FillType fillType; | |||
Font font; | |||
GlobalRef paint; | |||
bool fillNeedsUpdate, typefaceNeedsUpdate; | |||
Graphics::ResamplingQuality quality; | |||
Image maskImage; | |||
int maskLayerX, maskLayerY; | |||
}; | |||
private: | |||
GlobalRef canvas; | |||
//============================================================================== | |||
GlobalRef originalCanvas; | |||
ScopedPointer <SavedState> currentState; | |||
OwnedArray <SavedState> stateStack; | |||
GlobalRef& getCanvas() const throw() { return currentState->canvas; } | |||
jobject getCurrentPaint() const { return currentState->getPaint(); } | |||
jobject getImagePaint() const { return currentState->getImagePaint(); } | |||
@@ -615,21 +752,9 @@ private: | |||
return createPath (env, tempPath); | |||
} | |||
static const LocalRef<jobject> createMatrix (JNIEnv* env, const AffineTransform& t) | |||
static const LocalRef<jobject> createMatrixRef (JNIEnv* env, const AffineTransform& t) | |||
{ | |||
jobject m = env->NewObject (android.matrixClass, android.matrixClassConstructor); | |||
jfloat values[9] = { t.mat00, t.mat01, t.mat02, | |||
t.mat10, t.mat11, t.mat12, | |||
0.0f, 0.0f, 1.0f }; | |||
jfloatArray javaArray = env->NewFloatArray (9); | |||
env->SetFloatArrayRegion (javaArray, 0, 9, values); | |||
env->CallVoidMethod (m, android.setValues, javaArray); | |||
env->DeleteLocalRef (javaArray); | |||
return LocalRef<jobject> (m); | |||
return LocalRef<jobject> (android.createMatrix (*env, t)); | |||
} | |||
static const LocalRef<jobject> createRect (JNIEnv* env, const Rectangle<int>& r) | |||
@@ -673,6 +798,6 @@ LowLevelGraphicsContext* AndroidImage::createLowLevelContext() | |||
jobject canvas = getEnv()->NewObject (android.canvasClass, android.canvasBitmapConstructor, bitmap.get()); | |||
return new AndroidLowLevelGraphicsContext (canvas); | |||
} | |||
#endif | |||
#endif |
@@ -90,32 +90,47 @@ BEGIN_JUCE_NAMESPACE | |||
#include "../../containers/juce_ScopedValueSetter.h" | |||
#include "../common/juce_MidiDataConcatenator.h" | |||
#define USE_ANDROID_CANVAS 0 | |||
//============================================================================== | |||
#define JUCE_JNI_CALLBACK(className, methodName, returnType, params) \ | |||
extern "C" __attribute__ ((visibility("default"))) returnType Java_com_juce_ ## className ## _ ## methodName params | |||
//============================================================================== | |||
#define JUCE_JNI_CLASSES(JAVACLASS) \ | |||
// List of basic required classes | |||
#define JUCE_JNI_CLASSES_ESSENTIAL(JAVACLASS) \ | |||
JAVACLASS (activityClass, "com/juce/JuceAppActivity") \ | |||
JAVACLASS (componentPeerViewClass, "com/juce/ComponentPeerView") \ | |||
JAVACLASS (fileClass, "java/io/File") \ | |||
JAVACLASS (contextClass, "android/content/Context") \ | |||
JAVACLASS (canvasClass, "android/graphics/Canvas") \ | |||
JAVACLASS (paintClass, "android/graphics/Paint") \ | |||
JAVACLASS (pathClass, "android/graphics/Path") \ | |||
JAVACLASS (bitmapClass, "android/graphics/Bitmap") \ | |||
JAVACLASS (bitmapConfigClass, "android/graphics/Bitmap$Config") \ | |||
JAVACLASS (matrixClass, "android/graphics/Matrix") \ | |||
JAVACLASS (rectClass, "android/graphics/Rect") \ | |||
JAVACLASS (typefaceClass, "android/graphics/Typeface") \ | |||
//============================================================================== | |||
// List of extra classes needed when USE_ANDROID_CANVAS is enabled | |||
#if ! USE_ANDROID_CANVAS | |||
#define JUCE_JNI_CLASSES(JAVACLASS) JUCE_JNI_CLASSES_ESSENTIAL(JAVACLASS); | |||
#else | |||
#define JUCE_JNI_CLASSES(JAVACLASS) JUCE_JNI_CLASSES_ESSENTIAL(JAVACLASS); \ | |||
JAVACLASS (pathClass, "android/graphics/Path") \ | |||
JAVACLASS (regionClass, "android/graphics/Region") \ | |||
JAVACLASS (bitmapClass, "android/graphics/Bitmap") \ | |||
JAVACLASS (bitmapConfigClass, "android/graphics/Bitmap$Config") \ | |||
JAVACLASS (bitmapShaderClass, "android/graphics/BitmapShader") \ | |||
JAVACLASS (shaderClass, "android/graphics/Shader") \ | |||
JAVACLASS (typefaceClass, "android/graphics/Typeface") \ | |||
JAVACLASS (shaderTileModeClass, "android/graphics/Shader$TileMode") \ | |||
JAVACLASS (linearGradientClass, "android/graphics/LinearGradient") \ | |||
JAVACLASS (radialGradientClass, "android/graphics/RadialGradient") \ | |||
#endif | |||
//============================================================================== | |||
#define JUCE_JNI_METHODS(METHOD, STATICMETHOD, FIELD, STATICFIELD) \ | |||
// List of required methods | |||
#define JUCE_JNI_METHODS_ESSENTIAL(METHOD, STATICMETHOD, FIELD, STATICFIELD) \ | |||
\ | |||
STATICMETHOD (activityClass, printToConsole, "printToConsole", "(Ljava/lang/String;)V") \ | |||
METHOD (activityClass, createNewView, "createNewView", "(Z)Lcom/juce/ComponentPeerView;") \ | |||
@@ -125,7 +140,7 @@ BEGIN_JUCE_NAMESPACE | |||
METHOD (activityClass, getClipboardContent, "getClipboardContent", "()Ljava/lang/String;") \ | |||
METHOD (activityClass, setClipboardContent, "setClipboardContent", "(Ljava/lang/String;)V") \ | |||
METHOD (activityClass, excludeClipRegion, "excludeClipRegion", "(Landroid/graphics/Canvas;FFFF)V") \ | |||
METHOD (activityClass, createPathForGlyph, "createPathForGlyph", "(Landroid/graphics/Paint;C)Ljava/lang/String;") \ | |||
METHOD (activityClass, renderGlyph, "renderGlyph", "(CLandroid/graphics/Paint;Landroid/graphics/Matrix;Landroid/graphics/Rect;)[I") \ | |||
\ | |||
METHOD (fileClass, fileExists, "exists", "()Z") \ | |||
\ | |||
@@ -144,64 +159,79 @@ BEGIN_JUCE_NAMESPACE | |||
METHOD (componentPeerViewClass, invalidate, "invalidate", "(IIII)V") \ | |||
METHOD (componentPeerViewClass, containsPoint, "containsPoint", "(II)Z") \ | |||
\ | |||
METHOD (canvasClass, canvasBitmapConstructor, "<init>", "(Landroid/graphics/Bitmap;)V") \ | |||
METHOD (canvasClass, drawRect, "drawRect", "(FFFFLandroid/graphics/Paint;)V") \ | |||
METHOD (canvasClass, translate, "translate", "(FF)V") \ | |||
METHOD (canvasClass, clipPath, "clipPath", "(Landroid/graphics/Path;)Z") \ | |||
METHOD (canvasClass, clipRect, "clipRect", "(FFFF)Z") \ | |||
METHOD (canvasClass, clipRegion, "clipRegion", "(Landroid/graphics/Region;)Z") \ | |||
METHOD (canvasClass, concat, "concat", "(Landroid/graphics/Matrix;)V") \ | |||
METHOD (canvasClass, drawBitmap, "drawBitmap", "(Landroid/graphics/Bitmap;Landroid/graphics/Matrix;Landroid/graphics/Paint;)V") \ | |||
METHOD (canvasClass, drawMemoryBitmap, "drawBitmap", "([IIIFFIIZLandroid/graphics/Paint;)V") \ | |||
METHOD (canvasClass, drawLine, "drawLine", "(FFFFLandroid/graphics/Paint;)V") \ | |||
METHOD (canvasClass, drawPath, "drawPath", "(Landroid/graphics/Path;Landroid/graphics/Paint;)V") \ | |||
METHOD (canvasClass, drawText, "drawText", "(Ljava/lang/String;FFLandroid/graphics/Paint;)V") \ | |||
METHOD (canvasClass, getClipBounds, "getClipBounds", "(Landroid/graphics/Rect;)Z") \ | |||
METHOD (canvasClass, getClipBounds2, "getClipBounds", "()Landroid/graphics/Rect;") \ | |||
METHOD (canvasClass, getMatrix, "getMatrix", "()Landroid/graphics/Matrix;") \ | |||
METHOD (canvasClass, save, "save", "()I") \ | |||
METHOD (canvasClass, restore, "restore", "()V") \ | |||
METHOD (canvasClass, saveLayerAlpha, "saveLayerAlpha", "(FFFFII)I") \ | |||
\ | |||
METHOD (paintClass, paintClassConstructor, "<init>", "(I)V") \ | |||
METHOD (paintClass, setColor, "setColor", "(I)V") \ | |||
METHOD (paintClass, setAlpha, "setAlpha", "(I)V") \ | |||
METHOD (paintClass, setShader, "setShader", "(Landroid/graphics/Shader;)Landroid/graphics/Shader;") \ | |||
METHOD (paintClass, setTypeface, "setTypeface", "(Landroid/graphics/Typeface;)Landroid/graphics/Typeface;") \ | |||
METHOD (paintClass, ascent, "ascent", "()F") \ | |||
METHOD (paintClass, descent, "descent", "()F") \ | |||
METHOD (paintClass, setTextSize, "setTextSize", "(F)V") \ | |||
METHOD (paintClass, getTextWidths, "getTextWidths", "(Ljava/lang/String;[F)I") \ | |||
METHOD (paintClass, setTextScaleX, "setTextScaleX", "(F)V") \ | |||
METHOD (paintClass, getTextPath, "getTextPath", "(Ljava/lang/String;IIFFLandroid/graphics/Path;)V") \ | |||
\ | |||
METHOD (shaderClass, setLocalMatrix, "setLocalMatrix", "(Landroid/graphics/Matrix;)V") \ | |||
STATICFIELD (shaderTileModeClass, clampMode, "CLAMP", "Landroid/graphics/Shader$TileMode;") \ | |||
METHOD (matrixClass, matrixClassConstructor, "<init>", "()V") \ | |||
METHOD (matrixClass, setValues, "setValues", "([F)V") \ | |||
\ | |||
STATICMETHOD (typefaceClass, create, "create", "(Ljava/lang/String;I)Landroid/graphics/Typeface;") \ | |||
STATICMETHOD (typefaceClass, createFromFile, "createFromFile", "(Ljava/lang/String;)Landroid/graphics/Typeface;") \ | |||
\ | |||
METHOD (rectClass, rectConstructor, "<init>", "(IIII)V") \ | |||
FIELD (rectClass, rectLeft, "left", "I") \ | |||
FIELD (rectClass, rectRight, "right", "I") \ | |||
FIELD (rectClass, rectTop, "top", "I") \ | |||
FIELD (rectClass, rectBottom, "bottom", "I") \ | |||
//============================================================================== | |||
// List of extra methods needed when USE_ANDROID_CANVAS is enabled | |||
#if ! USE_ANDROID_CANVAS | |||
#define JUCE_JNI_METHODS(METHOD, STATICMETHOD, FIELD, STATICFIELD) JUCE_JNI_METHODS_ESSENTIAL(METHOD, STATICMETHOD, FIELD, STATICFIELD) | |||
#else | |||
#define JUCE_JNI_METHODS(METHOD, STATICMETHOD, FIELD, STATICFIELD) JUCE_JNI_METHODS_ESSENTIAL(METHOD, STATICMETHOD, FIELD, STATICFIELD) \ | |||
METHOD (pathClass, pathClassConstructor, "<init>", "()V") \ | |||
METHOD (pathClass, moveTo, "moveTo", "(FF)V") \ | |||
METHOD (pathClass, lineTo, "lineTo", "(FF)V") \ | |||
METHOD (pathClass, quadTo, "quadTo", "(FFFF)V") \ | |||
METHOD (pathClass, cubicTo, "cubicTo", "(FFFFFF)V") \ | |||
METHOD (pathClass, closePath, "close", "()V") \ | |||
METHOD (pathClass, computeBounds, "computeBounds", "(Landroid/graphics/RectF;Z)V") \ | |||
\ | |||
STATICMETHOD (bitmapClass, createBitmap, "createBitmap", "(IILandroid/graphics/Bitmap$Config;)Landroid/graphics/Bitmap;") \ | |||
STATICFIELD (bitmapConfigClass, ARGB_8888, "ARGB_8888", "Landroid/graphics/Bitmap$Config;") \ | |||
STATICFIELD (bitmapConfigClass, ALPHA_8, "ALPHA_8", "Landroid/graphics/Bitmap$Config;") \ | |||
METHOD (bitmapClass, bitmapCopy, "copy", "(Landroid/graphics/Bitmap$Config;Z)Landroid/graphics/Bitmap;") \ | |||
METHOD (bitmapClass, getPixels, "getPixels", "([IIIIIII)V") \ | |||
METHOD (bitmapClass, setPixels, "setPixels", "([IIIIIII)V") \ | |||
METHOD (bitmapClass, recycle, "recycle", "()V") \ | |||
\ | |||
METHOD (matrixClass, matrixClassConstructor, "<init>", "()V") \ | |||
METHOD (matrixClass, setValues, "setValues", "([F)V") \ | |||
METHOD (shaderClass, setLocalMatrix, "setLocalMatrix", "(Landroid/graphics/Matrix;)V") \ | |||
STATICFIELD (shaderTileModeClass, clampMode, "CLAMP", "Landroid/graphics/Shader$TileMode;") \ | |||
\ | |||
STATICMETHOD (typefaceClass, create, "create", "(Ljava/lang/String;I)Landroid/graphics/Typeface;") \ | |||
STATICMETHOD (typefaceClass, createFromFile, "createFromFile", "(Ljava/lang/String;)Landroid/graphics/Typeface;") \ | |||
METHOD (bitmapShaderClass, bitmapShaderConstructor, "<init>", "(Landroid/graphics/Bitmap;Landroid/graphics/Shader$TileMode;Landroid/graphics/Shader$TileMode;)V") \ | |||
\ | |||
METHOD (rectClass, rectConstructor, "<init>", "(IIII)V") \ | |||
FIELD (rectClass, rectLeft, "left", "I") \ | |||
FIELD (rectClass, rectRight, "right", "I") \ | |||
FIELD (rectClass, rectTop, "top", "I") \ | |||
FIELD (rectClass, rectBottom, "bottom", "I") \ | |||
METHOD (paintClass, setShader, "setShader", "(Landroid/graphics/Shader;)Landroid/graphics/Shader;") \ | |||
\ | |||
METHOD (canvasClass, canvasBitmapConstructor, "<init>", "(Landroid/graphics/Bitmap;)V") \ | |||
METHOD (canvasClass, drawRect, "drawRect", "(FFFFLandroid/graphics/Paint;)V") \ | |||
METHOD (canvasClass, translate, "translate", "(FF)V") \ | |||
METHOD (canvasClass, clipPath, "clipPath", "(Landroid/graphics/Path;)Z") \ | |||
METHOD (canvasClass, clipRect, "clipRect", "(FFFF)Z") \ | |||
METHOD (canvasClass, clipRegion, "clipRegion", "(Landroid/graphics/Region;)Z") \ | |||
METHOD (canvasClass, concat, "concat", "(Landroid/graphics/Matrix;)V") \ | |||
METHOD (canvasClass, drawBitmap, "drawBitmap", "(Landroid/graphics/Bitmap;Landroid/graphics/Matrix;Landroid/graphics/Paint;)V") \ | |||
METHOD (canvasClass, drawBitmapAt, "drawBitmap", "(Landroid/graphics/Bitmap;FFLandroid/graphics/Paint;)V") \ | |||
METHOD (canvasClass, drawLine, "drawLine", "(FFFFLandroid/graphics/Paint;)V") \ | |||
METHOD (canvasClass, drawPath, "drawPath", "(Landroid/graphics/Path;Landroid/graphics/Paint;)V") \ | |||
METHOD (canvasClass, drawText, "drawText", "(Ljava/lang/String;FFLandroid/graphics/Paint;)V") \ | |||
METHOD (canvasClass, getClipBounds, "getClipBounds", "(Landroid/graphics/Rect;)Z") \ | |||
METHOD (canvasClass, getMatrix, "getMatrix", "()Landroid/graphics/Matrix;") \ | |||
METHOD (canvasClass, save, "save", "()I") \ | |||
METHOD (canvasClass, restore, "restore", "()V") \ | |||
METHOD (canvasClass, saveLayerAlpha, "saveLayerAlpha", "(FFFFII)I") \ | |||
\ | |||
METHOD (linearGradientClass, linearGradientConstructor, "<init>", "(FFFF[I[FLandroid/graphics/Shader$TileMode;)V") \ | |||
\ | |||
@@ -210,6 +240,8 @@ BEGIN_JUCE_NAMESPACE | |||
METHOD (regionClass, regionConstructor, "<init>", "()V"); \ | |||
METHOD (regionClass, regionUnion, "union", "(Landroid/graphics/Rect;)Z"); \ | |||
#endif | |||
//============================================================================== | |||
class ThreadLocalJNIEnvHolder | |||
@@ -460,7 +492,6 @@ static const LocalRef<jstring> javaStringFromChar (const juce_wchar c) | |||
return LocalRef<jstring> (getEnv()->NewStringUTF (utf8)); | |||
} | |||
//============================================================================== | |||
class AndroidJavaCallbacks | |||
{ | |||
@@ -533,6 +564,23 @@ public: | |||
return getEnv()->NewObject (paintClass, paintClassConstructor, constructorFlags); | |||
} | |||
const jobject createMatrix (JNIEnv* env, const AffineTransform& t) | |||
{ | |||
jobject m = env->NewObject (matrixClass, matrixClassConstructor); | |||
jfloat values[9] = { t.mat00, t.mat01, t.mat02, | |||
t.mat10, t.mat11, t.mat12, | |||
0.0f, 0.0f, 1.0f }; | |||
jfloatArray javaArray = env->NewFloatArray (9); | |||
env->SetFloatArrayRegion (javaArray, 0, 9, values); | |||
env->CallVoidMethod (m, setValues, javaArray); | |||
env->DeleteLocalRef (javaArray); | |||
return m; | |||
} | |||
//============================================================================== | |||
#define DECLARE_JNI_CLASS(className, path) jclass className; | |||
JUCE_JNI_CLASSES (DECLARE_JNI_CLASS); | |||
@@ -35,7 +35,8 @@ public: | |||
//============================================================================== | |||
AndroidComponentPeer (Component* const component, const int windowStyleFlags) | |||
: ComponentPeer (component, windowStyleFlags), | |||
view (android.activity.callObjectMethod (android.createNewView, component->isOpaque())) | |||
view (android.activity.callObjectMethod (android.createNewView, component->isOpaque())), | |||
usingAndroidGraphics (false), sizeAllocated (0) | |||
{ | |||
if (isFocused()) | |||
handleFocusGain(); | |||
@@ -43,7 +44,33 @@ public: | |||
~AndroidComponentPeer() | |||
{ | |||
android.activity.callVoidMethod (android.deleteView, view.get()); | |||
if (MessageManager::getInstance()->isThisTheMessageThread()) | |||
{ | |||
android.activity.callVoidMethod (android.deleteView, view.get()); | |||
} | |||
else | |||
{ | |||
class ViewDeleter : public CallbackMessage | |||
{ | |||
public: | |||
ViewDeleter (const GlobalRef& view_) | |||
: view (view_) | |||
{ | |||
post(); | |||
} | |||
void messageCallback() | |||
{ | |||
android.activity.callVoidMethod (android.deleteView, view.get()); | |||
} | |||
private: | |||
GlobalRef view; | |||
}; | |||
new ViewDeleter (view); | |||
} | |||
view.clear(); | |||
} | |||
@@ -54,7 +81,33 @@ public: | |||
void setVisible (bool shouldBeVisible) | |||
{ | |||
view.callVoidMethod (android.setVisible, shouldBeVisible); | |||
if (MessageManager::getInstance()->isThisTheMessageThread()) | |||
{ | |||
view.callVoidMethod (android.setVisible, shouldBeVisible); | |||
} | |||
else | |||
{ | |||
class VisibilityChanger : public CallbackMessage | |||
{ | |||
public: | |||
VisibilityChanger (const GlobalRef& view_, bool shouldBeVisible_) | |||
: view (view_), shouldBeVisible (shouldBeVisible_) | |||
{ | |||
post(); | |||
} | |||
void messageCallback() | |||
{ | |||
view.callVoidMethod (android.setVisible, shouldBeVisible); | |||
} | |||
private: | |||
GlobalRef view; | |||
bool shouldBeVisible; | |||
}; | |||
new VisibilityChanger (view, shouldBeVisible); | |||
} | |||
} | |||
void setTitle (const String& title) | |||
@@ -76,7 +129,33 @@ public: | |||
void setBounds (int x, int y, int w, int h, bool isNowFullScreen) | |||
{ | |||
view.callVoidMethod (android.layout, x, y, x + w, y + h); | |||
if (MessageManager::getInstance()->isThisTheMessageThread()) | |||
{ | |||
view.callVoidMethod (android.layout, x, y, x + w, y + h); | |||
} | |||
else | |||
{ | |||
class ViewMover : public CallbackMessage | |||
{ | |||
public: | |||
ViewMover (const GlobalRef& view_, int x_, int y_, int w_, int h_) | |||
: view (view_), x (x_), y (y_), w (w_), h (h_) | |||
{ | |||
post(); | |||
} | |||
void messageCallback() | |||
{ | |||
view.callVoidMethod (android.layout, x, y, x + w, y + h); | |||
} | |||
private: | |||
GlobalRef view; | |||
int x, y, w, h; | |||
}; | |||
new ViewMover (view, x, y, w, h); | |||
} | |||
} | |||
const Rectangle<int> getBounds() const | |||
@@ -89,17 +168,6 @@ public: | |||
const Point<int> getScreenPosition() const | |||
{ | |||
/*JNIEnv* const env = getEnv(); | |||
jintArray pos = env->NewIntArray (2); | |||
view.callVoidMethod (android.getLocationOnScreen, pos); | |||
jint coords[2]; | |||
env->GetIntArrayRegion (pos, 0, 2, coords); | |||
env->DeleteLocalRef (pos); | |||
return Point<int> (coords[0], coords[1]);*/ | |||
return Point<int> (view.callIntMethod (android.getLeft), | |||
view.callIntMethod (android.getTop)); | |||
} | |||
@@ -224,13 +292,85 @@ public: | |||
//============================================================================== | |||
void handlePaintCallback (JNIEnv* env, jobject canvas) | |||
{ | |||
AndroidLowLevelGraphicsContext g (canvas); | |||
handlePaint (g); | |||
#if USE_ANDROID_CANVAS | |||
if (usingAndroidGraphics) | |||
{ | |||
AndroidLowLevelGraphicsContext g (canvas); | |||
handlePaint (g); | |||
} | |||
else | |||
#endif | |||
{ | |||
jobject rect = env->CallObjectMethod (canvas, android.getClipBounds2); | |||
const int left = env->GetIntField (rect, android.rectLeft); | |||
const int top = env->GetIntField (rect, android.rectTop); | |||
const int right = env->GetIntField (rect, android.rectRight); | |||
const int bottom = env->GetIntField (rect, android.rectBottom); | |||
env->DeleteLocalRef (rect); | |||
const Rectangle<int> clip (left, top, right - left, bottom - top); | |||
const int sizeNeeded = clip.getWidth() * clip.getHeight(); | |||
if (sizeAllocated < sizeNeeded) | |||
{ | |||
buffer.clear(); | |||
sizeAllocated = sizeNeeded; | |||
buffer = GlobalRef (env->NewIntArray (sizeNeeded)); | |||
} | |||
jint* dest = env->GetIntArrayElements ((jintArray) buffer.get(), 0); | |||
if (dest != 0) | |||
{ | |||
{ | |||
Image temp (new PreallocatedImage (clip.getWidth(), clip.getHeight(), | |||
dest, ! component->isOpaque())); | |||
{ | |||
LowLevelGraphicsSoftwareRenderer g (temp); | |||
g.setOrigin (-clip.getX(), -clip.getY()); | |||
handlePaint (g); | |||
} | |||
} | |||
env->ReleaseIntArrayElements ((jintArray) buffer.get(), dest, 0); | |||
env->CallVoidMethod (canvas, android.drawMemoryBitmap, (jintArray) buffer.get(), 0, clip.getWidth(), | |||
(jfloat) clip.getX(), (jfloat) clip.getY(), | |||
clip.getWidth(), clip.getHeight(), true, (jobject) 0); | |||
} | |||
} | |||
} | |||
void repaint (const Rectangle<int>& area) | |||
{ | |||
view.callVoidMethod (android.invalidate, area.getX(), area.getY(), area.getRight(), area.getBottom()); | |||
if (MessageManager::getInstance()->isThisTheMessageThread()) | |||
{ | |||
view.callVoidMethod (android.invalidate, area.getX(), area.getY(), area.getRight(), area.getBottom()); | |||
} | |||
else | |||
{ | |||
class ViewRepainter : public CallbackMessage | |||
{ | |||
public: | |||
ViewRepainter (const GlobalRef& view_, const Rectangle<int>& area_) | |||
: view (view_), area (area_) | |||
{ | |||
post(); | |||
} | |||
void messageCallback() | |||
{ | |||
view.callVoidMethod (android.invalidate, area.getX(), area.getY(), area.getRight(), area.getBottom()); | |||
} | |||
private: | |||
GlobalRef view; | |||
const Rectangle<int>& area; | |||
}; | |||
new ViewRepainter (view, area); | |||
} | |||
} | |||
void performAnyPendingRepaintsNow() | |||
@@ -243,6 +383,29 @@ public: | |||
// TODO | |||
} | |||
const StringArray getAvailableRenderingEngines() | |||
{ | |||
StringArray s (ComponentPeer::getAvailableRenderingEngines()); | |||
s.add ("Android Canvas Renderer"); | |||
return s; | |||
} | |||
#if USE_ANDROID_CANVAS | |||
int getCurrentRenderingEngine() throw() | |||
{ | |||
return usingAndroidGraphics ? 1 : 0; | |||
} | |||
void setCurrentRenderingEngine (int index) | |||
{ | |||
if (usingAndroidGraphics != (index > 0)) | |||
{ | |||
usingAndroidGraphics = index > 0; | |||
component->repaint(); | |||
} | |||
} | |||
#endif | |||
//============================================================================== | |||
static AndroidComponentPeer* findPeerForJavaView (jobject viewToFind) | |||
{ | |||
@@ -264,6 +427,63 @@ public: | |||
private: | |||
//============================================================================== | |||
GlobalRef view; | |||
GlobalRef buffer; | |||
bool usingAndroidGraphics; | |||
int sizeAllocated; | |||
class PreallocatedImage : public Image::SharedImage | |||
{ | |||
public: | |||
//============================================================================== | |||
PreallocatedImage (const int width_, const int height_, jint* data_, bool hasAlpha_) | |||
: Image::SharedImage (Image::ARGB, width_, height_), data (data_), hasAlpha (hasAlpha_) | |||
{ | |||
if (hasAlpha_) | |||
zeromem (data_, width * height * sizeof (jint)); | |||
} | |||
~PreallocatedImage() | |||
{ | |||
if (hasAlpha) | |||
{ | |||
PixelARGB* pix = (PixelARGB*) data; | |||
for (int i = width * height; --i >= 0;) | |||
{ | |||
pix->unpremultiply(); | |||
++pix; | |||
} | |||
} | |||
} | |||
Image::ImageType getType() const { return Image::SoftwareImage; } | |||
LowLevelGraphicsContext* createLowLevelContext() { return new LowLevelGraphicsSoftwareRenderer (Image (this)); } | |||
void initialiseBitmapData (Image::BitmapData& bm, int x, int y, Image::BitmapData::ReadWriteMode mode) | |||
{ | |||
bm.lineStride = width * sizeof (jint); | |||
bm.pixelStride = sizeof (jint); | |||
bm.pixelFormat = Image::ARGB; | |||
bm.data = (uint8*) (data + x + y * width); | |||
} | |||
SharedImage* clone() | |||
{ | |||
PreallocatedImage* s = new PreallocatedImage (width, height, 0, hasAlpha); | |||
s->allocatedData.malloc (sizeof (jint) * width * height); | |||
s->data = s->allocatedData; | |||
memcpy (s->data, data, sizeof (jint) * width * height); | |||
return s; | |||
} | |||
//============================================================================== | |||
private: | |||
jint* data; | |||
HeapBlock<jint> allocatedData; | |||
bool hasAlpha; | |||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PreallocatedImage); | |||
}; | |||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AndroidComponentPeer); | |||
}; | |||
@@ -49,7 +49,6 @@ | |||
return true; | |||
Logger::writeToLog ("CoreAudio error: " + String (lineNum) + " - " + String::toHexString ((int) err)); | |||
jassertfalse; | |||
return false; | |||
} | |||
@@ -287,6 +287,17 @@ public: | |||
#endif | |||
} | |||
EdgeTable* getEdgeTableForGlyph (int glyphNumber, const AffineTransform& transform) | |||
{ | |||
Path path; | |||
if (getOutlineForGlyph (glyphNumber, path) && ! path.isEmpty()) | |||
return new EdgeTable (path.getBoundsTransformed (transform).getSmallestIntegerContainer().expanded (1, 0), | |||
path, transform); | |||
return 0; | |||
} | |||
bool getOutlineForGlyph (int glyphNumber, Path& path) | |||
{ | |||
#if JUCE_IOS | |||
@@ -67,6 +67,7 @@ BEGIN_JUCE_NAMESPACE | |||
#include "../../events/juce_MessageManager.h" | |||
#include "../../containers/juce_ReferenceCountedArray.h" | |||
#include "../../gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.h" | |||
#include "../../gui/graphics/contexts/juce_EdgeTable.h" | |||
#include "../../gui/graphics/imaging/juce_ImageFileFormat.h" | |||
#include "../../gui/graphics/imaging/juce_CameraDevice.h" | |||
#include "../../gui/components/windows/juce_AlertWindow.h" | |||
@@ -45,35 +45,55 @@ StringArray::StringArray (const String& firstValue) | |||
strings.add (firstValue); | |||
} | |||
StringArray::StringArray (const juce_wchar* const* const initialStrings, | |||
const int numberOfStrings) | |||
namespace StringArrayHelpers | |||
{ | |||
for (int i = 0; i < numberOfStrings; ++i) | |||
strings.add (initialStrings [i]); | |||
template <typename CharType> | |||
void addArray (Array<String>& dest, const CharType* const* strings) | |||
{ | |||
if (strings != 0) | |||
while (*strings != 0) | |||
dest.add (*strings++); | |||
} | |||
template <typename CharType> | |||
void addArray (Array<String>& dest, const CharType* const* const strings, const int numberOfStrings) | |||
{ | |||
for (int i = 0; i < numberOfStrings; ++i) | |||
dest.add (strings [i]); | |||
} | |||
} | |||
StringArray::StringArray (const char* const* const initialStrings) | |||
{ | |||
StringArrayHelpers::addArray (strings, initialStrings); | |||
} | |||
StringArray::StringArray (const char* const* const initialStrings, | |||
const int numberOfStrings) | |||
StringArray::StringArray (const char* const* const initialStrings, const int numberOfStrings) | |||
{ | |||
for (int i = 0; i < numberOfStrings; ++i) | |||
strings.add (initialStrings [i]); | |||
StringArrayHelpers::addArray (strings, initialStrings, numberOfStrings); | |||
} | |||
StringArray::StringArray (const juce_wchar* const* const initialStrings) | |||
{ | |||
int i = 0; | |||
StringArrayHelpers::addArray (strings, initialStrings); | |||
} | |||
while (initialStrings[i] != 0) | |||
strings.add (initialStrings [i++]); | |||
StringArray::StringArray (const juce_wchar* const* const initialStrings, const int numberOfStrings) | |||
{ | |||
StringArrayHelpers::addArray (strings, initialStrings, numberOfStrings); | |||
} | |||
StringArray::StringArray (const char* const* const initialStrings) | |||
#if ! JUCE_NATIVE_WCHAR_IS_UTF32 | |||
StringArray::StringArray (const wchar_t* const* const initialStrings) | |||
{ | |||
int i = 0; | |||
StringArrayHelpers::addArray (strings, initialStrings); | |||
} | |||
while (initialStrings[i] != 0) | |||
strings.add (initialStrings [i++]); | |||
StringArray::StringArray (const wchar_t* const* const initialStrings, const int numberOfStrings) | |||
{ | |||
StringArrayHelpers::addArray (strings, initialStrings, numberOfStrings); | |||
} | |||
#endif | |||
StringArray& StringArray::operator= (const StringArray& other) | |||
{ | |||
@@ -54,14 +54,14 @@ public: | |||
treated as empty strings | |||
@param numberOfStrings how many items there are in the array | |||
*/ | |||
StringArray (const juce_wchar* const* strings, int numberOfStrings); | |||
StringArray (const char* const* strings, int numberOfStrings); | |||
/** Creates a copy of an array of string literals. | |||
@param strings an array of strings to add. Null pointers in the array will be | |||
treated as empty strings | |||
@param numberOfStrings how many items there are in the array | |||
/** Creates a copy of a null-terminated array of string literals. | |||
Each item from the array passed-in is added, until it encounters a null pointer, | |||
at which point it stops. | |||
*/ | |||
StringArray (const char* const* strings, int numberOfStrings); | |||
explicit StringArray (const char* const* strings); | |||
/** Creates a copy of a null-terminated array of string literals. | |||
Each item from the array passed-in is added, until it encounters a null pointer, | |||
@@ -69,12 +69,27 @@ public: | |||
*/ | |||
explicit StringArray (const juce_wchar* const* strings); | |||
/** Creates a copy of a null-terminated array of string literals. | |||
/** Creates a copy of an array of string literals. | |||
@param strings an array of strings to add. Null pointers in the array will be | |||
treated as empty strings | |||
@param numberOfStrings how many items there are in the array | |||
*/ | |||
StringArray (const juce_wchar* const* strings, int numberOfStrings); | |||
#if ! JUCE_NATIVE_WCHAR_IS_UTF32 | |||
/** Creates a copy of a null-terminated array of string literals. | |||
Each item from the array passed-in is added, until it encounters a null pointer, | |||
at which point it stops. | |||
*/ | |||
explicit StringArray (const char* const* strings); | |||
explicit StringArray (const wchar_t* const* strings); | |||
/** Creates a copy of an array of string literals. | |||
@param strings an array of strings to add. Null pointers in the array will be | |||
treated as empty strings | |||
@param numberOfStrings how many items there are in the array | |||
*/ | |||
StringArray (const wchar_t* const* strings, int numberOfStrings); | |||
#endif | |||
/** Destructor. */ | |||
~StringArray(); | |||